5G-MAG Reference Tools - MBMS Modem
Phy.h
Go to the documentation of this file.
1 // 5G-MAG Reference Tools
2 // MBMS Modem Process
3 //
4 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Affero General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Affero General Public License for more details.
15 //
16 // You should have received a copy of the GNU Affero General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #pragma once
21 
22 #include <functional>
23 #include <cstdint>
24 #include <string>
25 #include <map>
26 #include <vector>
27 #include <thread>
28 #include <libconfig.h++>
29 
30 #include "srsran/srsran.h"
31 #include "srsran/interfaces/rrc_interface_types.h"
32 #include "srsran/common/gen_mch_tables.h"
33 #include "srsran/phy/common/phy_common.h"
34 
35 constexpr unsigned int MAX_PRB = 100;
36 
42 class Phy {
43  public:
47  typedef std::function<int(cf_t* data[SRSRAN_MAX_CHANNELS], uint32_t nsamples, srsran_timestamp_t* rx_time)> get_samples_t;
48 
57  Phy(const libconfig::Config& cfg, get_samples_t cb, uint8_t cs_nof_prb, int8_t override_nof_prb, uint8_t rx_channels);
58 
62  virtual ~Phy();
63 
67  bool init();
68 
74  bool cell_search();
75 
81  bool synchronize_subframe();
82 
86  bool get_next_frame(cf_t** buffer, uint32_t size);
87 
91  srsran_cell_t cell() {
92  return _cell;
93  }
94 
98  unsigned nr_prb() { return _cell.nof_prb; }
99 
103  uint32_t tti() { return _tti; }
104 
108  float cfo() { return srsran_ue_sync_get_cfo(&_ue_sync);}
109 
113  void set_cfo_from_channel_estimation(float cfo) { srsran_ue_sync_set_cfo_ref(&_ue_sync, cfo); }
114 
118  void set_mch_scheduling_info(const srsran::sib13_t& sib13);
119 
123  void set_mbsfn_config(const srsran::mcch_msg_t& mcch);
124 
128  void reset() { _mcch_configured = _mch_configured = false; }
129 
134 
138  uint8_t mbsfn_area_id() { return _sib13.mbsfn_area_info_list[0].mbsfn_area_id; }
139 
143  srsran_mbsfn_cfg_t mbsfn_config_for_tti(uint32_t tti, unsigned& area);
144 
148  void set_decode_mcch(bool d) { _decode_mcch = d; }
149 
153  uint8_t nof_mbsfn_prb() { return _cell.mbsfn_prb; }
154 
158  void set_nof_mbsfn_prb(uint8_t prb) { _cell.mbsfn_prb = prb; }
159 
160  void set_cell();
161 
162  bool is_cas_subframe(unsigned tti);
163  bool is_mbsfn_subframe(unsigned tti);
164 
165  typedef struct {
166  std::string tmgi;
167  std::string dest;
168  int lcid;
169  } mtch_info_t;
170  typedef struct {
171  int mcs;
172  std::vector< mtch_info_t > mtchs;
173  } mch_info_t;
174 
175  const std::vector< mch_info_t>& mch_info() { return _mch_info; }
176 
177  void set_dest_for_lcid(uint32_t mch_idx, int lcid, std::string dest) { _dests[mch_idx][lcid] = dest; }
178 
179  enum class SubcarrierSpacing {
180  df_15kHz,
181  df_7kHz5,
182  df_1kHz25
183  };
184 
186  if (_cell.mbms_dedicated) {
187  switch (_sib13.mbsfn_area_info_list[0].subcarrier_spacing) {
188  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_1dot25: return SubcarrierSpacing::df_1kHz25;
189  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_7dot5: return SubcarrierSpacing::df_7kHz5;
190  default: return SubcarrierSpacing::df_15kHz;
191  }
192  } else {
194  }
195  }
196 
198  if (_cell.mbms_dedicated) {
199  switch (_sib13.mbsfn_area_info_list[0].subcarrier_spacing) {
200  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_1dot25: return 1.25;
201  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_7dot5: return 7.5;
202  default: return 15;
203  }
204  } else {
205  return 15;
206  }
207  }
208 
209  srsran::mcch_msg_t& mcch() { return _mcch; }
210 
211  int _mcs = 0;
213 
214  private:
215  const libconfig::Config& _cfg;
216  srsran_ue_sync_t _ue_sync = {};
217  srsran_ue_cellsearch_t _cell_search = {};
218  srsran_ue_mib_sync_t _mib_sync = {};
219  srsran_ue_mib_t _mib = {};
220  srsran_cell_t _cell = {};
221 
222  bool _decode_mcch = false;
223 
224  cf_t* _mib_buffer[SRSRAN_MAX_CHANNELS] = {};
225  uint32_t _buffer_max_samples = 0;
226  uint32_t _tti = 0;
227 
228  uint8_t _mcch_table[10] = {};
229  bool _mcch_configured = false;
230  srsran::sib13_t _sib13 = {};
231  srsran::mcch_msg_t _mcch = {};
232 
233  bool _mch_configured = false;
234 
235  uint8_t _cs_nof_prb;
236 
237  std::vector< mch_info_t > _mch_info;
238 
239  std::map< uint32_t, std::map< int, std::string >> _dests;
240 
242  uint8_t _rx_channels;
243  bool _search_extended_cp = true;
244 };
constexpr unsigned int MAX_PRB
Definition: Phy.h:35
The PHY component.
Definition: Phy.h:42
srsran_mbsfn_cfg_t mbsfn_config_for_tti(uint32_t tti, unsigned &area)
Returns the MBSFN configuration (MCS, etc) for the subframe with the passed TTI.
Definition: Phy.cpp:324
void set_cfo_from_channel_estimation(float cfo)
Set the CFO value from channel estimation.
Definition: Phy.h:113
int _mcs
Definition: Phy.h:211
std::function< int(cf_t *data[SRSRAN_MAX_CHANNELS], uint32_t nsamples, srsran_timestamp_t *rx_time)> get_samples_t
Definition of the callback function used to fetch samples from the SDR.
Definition: Phy.h:47
std::map< uint32_t, std::map< int, std::string > > _dests
Definition: Phy.h:239
bool mcch_configured()
Return true if MCCH has been configured.
Definition: Phy.h:133
SubcarrierSpacing mbsfn_subcarrier_spacing()
Definition: Phy.h:185
unsigned nr_prb()
Get the current number of PRB.
Definition: Phy.h:98
uint8_t mbsfn_area_id()
Returns the current MBSFN area ID.
Definition: Phy.h:138
void set_decode_mcch(bool d)
Enable MCCH decoding.
Definition: Phy.h:148
const std::vector< mch_info_t > & mch_info()
Definition: Phy.h:175
void set_mch_scheduling_info(const srsran::sib13_t &sib13)
Set the values received in SIB13.
Definition: Phy.cpp:224
uint8_t _cs_nof_prb
Definition: Phy.h:235
std::vector< mch_info_t > _mch_info
Definition: Phy.h:237
SubcarrierSpacing
Definition: Phy.h:179
cf_t * _mib_buffer[SRSRAN_MAX_CHANNELS]
Definition: Phy.h:224
bool get_next_frame(cf_t **buffer, uint32_t size)
Get the sample data for the next subframe.
Definition: Phy.cpp:220
srsran_cell_t cell()
Get the current cell (with params adjusted for MBSFN)
Definition: Phy.h:91
bool synchronize_subframe()
Synchronizes PSS/SSS and tries to deocode the MIB.
Definition: Phy.cpp:59
bool _mcch_configured
Definition: Phy.h:229
uint8_t _mcch_table[10]
Definition: Phy.h:228
bool _search_extended_cp
Definition: Phy.h:243
const libconfig::Config & _cfg
Definition: Phy.h:215
uint8_t nof_mbsfn_prb()
Get number of PRB in MBSFN/PMCH.
Definition: Phy.h:153
void set_cell()
Definition: Phy.cpp:183
srsran_ue_cellsearch_t _cell_search
Definition: Phy.h:217
void reset()
Clear configuration values.
Definition: Phy.h:128
bool is_cas_subframe(unsigned tti)
Definition: Phy.cpp:303
srsran::mcch_msg_t _mcch
Definition: Phy.h:231
uint32_t tti()
Get the current subframe TTI.
Definition: Phy.h:103
srsran_ue_sync_t _ue_sync
Definition: Phy.h:216
srsran_cell_t _cell
Definition: Phy.h:220
uint8_t _rx_channels
Definition: Phy.h:242
bool _mch_configured
Definition: Phy.h:233
bool init()
Initialize the underlying components.
Definition: Phy.cpp:192
float mbsfn_subcarrier_spacing_khz()
Definition: Phy.h:197
bool cell_search()
Search for a cell.
Definition: Phy.cpp:91
virtual ~Phy()
Default destructor.
Definition: Phy.cpp:54
bool _decode_mcch
Definition: Phy.h:222
uint32_t _buffer_max_samples
Definition: Phy.h:225
void set_nof_mbsfn_prb(uint8_t prb)
Override number of PRB in MBSFN/PMCH.
Definition: Phy.h:158
srsran_ue_mib_t _mib
Definition: Phy.h:219
void set_dest_for_lcid(uint32_t mch_idx, int lcid, std::string dest)
Definition: Phy.h:177
get_samples_t _sample_cb
Definition: Phy.h:212
srsran::sib13_t _sib13
Definition: Phy.h:230
srsran::mcch_msg_t & mcch()
Definition: Phy.h:209
bool is_mbsfn_subframe(unsigned tti)
Definition: Phy.cpp:314
void set_mbsfn_config(const srsran::mcch_msg_t &mcch)
Set MBSFN configuration values.
Definition: Phy.cpp:260
int8_t _override_nof_prb
Definition: Phy.h:241
uint32_t _tti
Definition: Phy.h:226
float cfo()
Get the current CFO value.
Definition: Phy.h:108
srsran_ue_mib_sync_t _mib_sync
Definition: Phy.h:218
Phy(const libconfig::Config &cfg, get_samples_t cb, uint8_t cs_nof_prb, int8_t override_nof_prb, uint8_t rx_channels)
Default constructor.
Definition: Phy.cpp:42
static Config cfg
Global configuration object.
Definition: main.cpp:165
std::vector< mtch_info_t > mtchs
Definition: Phy.h:172
std::string dest
Definition: Phy.h:167
std::string tmgi
Definition: Phy.h:166