flexran_agent_ran_api.c 44.4 KB
Newer Older
shahab's avatar
shahab committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */ 

/*! \file flexran_agent_ran_api.c
 * \brief FlexRAN RAN API abstraction 
Robert Schmidt's avatar
Robert Schmidt committed
24
 * \author N. Nikaein, X. Foukas, S. SHARIAT BAGHERI and R. Schmidt
shahab's avatar
shahab committed
25
26
27
28
29
30
 * \date 2017
 * \version 0.1
 */

#include "flexran_agent_ran_api.h"

31
32
33
34
static inline int phy_is_present(mid_t mod_id, uint8_t cc_id)
{
  return RC.eNB && RC.eNB[mod_id] && RC.eNB[mod_id][cc_id];
}
shahab's avatar
shahab committed
35

36
37
38
39
40
41
42
43
static inline int mac_is_present(mid_t mod_id)
{
  return RC.mac && RC.mac[mod_id];
}

static inline int rrc_is_present(mid_t mod_id)
{
  return RC.rrc && RC.rrc[mod_id];
44
}
45

Robert Schmidt's avatar
Robert Schmidt committed
46
uint32_t flexran_get_current_time_ms(mid_t mod_id, int subframe_flag)
47
{
48
  if (!mac_is_present(mod_id)) return 0;
Robert Schmidt's avatar
Robert Schmidt committed
49
  if (subframe_flag == 1)
50
    return RC.mac[mod_id]->frame*10 + RC.mac[mod_id]->subframe;
Robert Schmidt's avatar
Robert Schmidt committed
51
  else
52
    return RC.mac[mod_id]->frame*10;
shahab's avatar
shahab committed
53
54
}

Robert Schmidt's avatar
Robert Schmidt committed
55
56
frame_t flexran_get_current_frame(mid_t mod_id)
{
57
  if (!mac_is_present(mod_id)) return 0;
shahab's avatar
shahab committed
58
  //  #warning "SFN will not be in [0-1023] when oaisim is used"
59
  return RC.mac[mod_id]->frame;
shahab's avatar
shahab committed
60
61
}

Robert Schmidt's avatar
Robert Schmidt committed
62
63
64
frame_t flexran_get_current_system_frame_num(mid_t mod_id)
{
  return flexran_get_current_frame(mod_id) % 1024;
shahab's avatar
shahab committed
65
66
}

Robert Schmidt's avatar
Robert Schmidt committed
67
68
sub_frame_t flexran_get_current_subframe(mid_t mod_id)
{
69
70
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->subframe;
shahab's avatar
shahab committed
71
72
}

Robert Schmidt's avatar
Robert Schmidt committed
73
74
75
76
77
/* Why uint16_t, frame_t and sub_frame_t are defined as uint32_t? */
uint16_t flexran_get_sfn_sf(mid_t mod_id)
{
  frame_t frame = flexran_get_current_system_frame_num(mod_id);
  sub_frame_t subframe = flexran_get_current_subframe(mod_id);
shahab's avatar
shahab committed
78
  uint16_t sfn_sf, frame_mask, sf_mask;
Robert Schmidt's avatar
Robert Schmidt committed
79
80
81

  frame_mask = (1 << 12) - 1;
  sf_mask = (1 << 4) - 1;
shahab's avatar
shahab committed
82
  sfn_sf = (subframe & sf_mask) | ((frame & frame_mask) << 4);
Robert Schmidt's avatar
Robert Schmidt committed
83

shahab's avatar
shahab committed
84
85
86
  return sfn_sf;
}

Robert Schmidt's avatar
Robert Schmidt committed
87
88
89
90
uint16_t flexran_get_future_sfn_sf(mid_t mod_id, int ahead_of_time)
{
  frame_t frame = flexran_get_current_system_frame_num(mod_id);
  sub_frame_t subframe = flexran_get_current_subframe(mod_id);
shahab's avatar
shahab committed
91
  uint16_t sfn_sf, frame_mask, sf_mask;
Robert Schmidt's avatar
Robert Schmidt committed
92
  int additional_frames;
shahab's avatar
shahab committed
93

Robert Schmidt's avatar
Robert Schmidt committed
94
95
96
  subframe = (subframe + ahead_of_time) % 10;

  if (subframe < flexran_get_current_subframe(mod_id))
shahab's avatar
shahab committed
97
    frame = (frame + 1) % 1024;
Robert Schmidt's avatar
Robert Schmidt committed
98
99

  additional_frames = ahead_of_time / 10;
shahab's avatar
shahab committed
100
  frame = (frame + additional_frames) % 1024;
Robert Schmidt's avatar
Robert Schmidt committed
101
102
103

  frame_mask = (1 << 12) - 1;
  sf_mask = (1 << 4) - 1;
shahab's avatar
shahab committed
104
  sfn_sf = (subframe & sf_mask) | ((frame & frame_mask) << 4);
Robert Schmidt's avatar
Robert Schmidt committed
105

shahab's avatar
shahab committed
106
107
108
  return sfn_sf;
}

Robert Schmidt's avatar
Robert Schmidt committed
109
110
int flexran_get_num_ues(mid_t mod_id)
{
111
112
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.num_UEs;
shahab's avatar
shahab committed
113
114
}

Robert Schmidt's avatar
Robert Schmidt committed
115
116
117
rnti_t flexran_get_ue_crnti(mid_t mod_id, mid_t ue_id)
{
  return UE_RNTI(mod_id, ue_id);
shahab's avatar
shahab committed
118
119
}

120
int flexran_get_ue_bsr_ul_buffer_info(mid_t mod_id, mid_t ue_id, lcid_t lcid)
Robert Schmidt's avatar
Robert Schmidt committed
121
{
122
123
  if (!mac_is_present(mod_id)) return -1;
  return RC.mac[mod_id]->UE_list.UE_template[UE_PCCID(mod_id, ue_id)][ue_id].ul_buffer_info[lcid];
shahab's avatar
shahab committed
124
125
}

Robert Schmidt's avatar
Robert Schmidt committed
126
127
int8_t flexran_get_ue_phr(mid_t mod_id, mid_t ue_id)
{
128
129
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.UE_template[UE_PCCID(mod_id, ue_id)][ue_id].phr_info;
shahab's avatar
shahab committed
130
131
}

Robert Schmidt's avatar
Robert Schmidt committed
132
133
uint8_t flexran_get_ue_wcqi(mid_t mod_id, mid_t ue_id)
{
134
135
  if (!phy_is_present(mod_id, 0)) return 0;
  return RC.eNB[mod_id][0]->UE_stats[ue_id].DL_cqi[0];
shahab's avatar
shahab committed
136
137
}

Robert Schmidt's avatar
Robert Schmidt committed
138
139
140
141
142
rlc_buffer_occupancy_t flexran_get_tx_queue_size(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
{
  rnti_t rnti = flexran_get_ue_crnti(mod_id, ue_id);
  frame_t frame = flexran_get_current_frame(mod_id);
  sub_frame_t subframe = flexran_get_current_subframe(mod_id);
143
  mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(mod_id,rnti, mod_id, frame, subframe, ENB_FLAG_YES,MBMS_FLAG_NO, channel_id, 0);
shahab's avatar
shahab committed
144
  return rlc_status.bytes_in_buffer;
shahab's avatar
shahab committed
145
146
}

Robert Schmidt's avatar
Robert Schmidt committed
147
148
rlc_buffer_occupancy_t flexran_get_num_pdus_buffer(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
{
149
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
Robert Schmidt's avatar
Robert Schmidt committed
150
151
  frame_t frame = flexran_get_current_frame(mod_id);
  sub_frame_t subframe = flexran_get_current_subframe(mod_id);
152
153
154
155
  mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(mod_id,rnti, mod_id, frame, subframe, ENB_FLAG_YES,MBMS_FLAG_NO, channel_id, 0);
  return rlc_status.pdus_in_buffer;
}

Robert Schmidt's avatar
Robert Schmidt committed
156
157
frame_t flexran_get_hol_delay(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
{
shahab's avatar
shahab committed
158
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
Robert Schmidt's avatar
Robert Schmidt committed
159
160
  frame_t frame = flexran_get_current_frame(mod_id);
  sub_frame_t subframe = flexran_get_current_subframe(mod_id);
161
  mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(mod_id, rnti, mod_id, frame, subframe, ENB_FLAG_YES, MBMS_FLAG_NO, channel_id, 0);
shahab's avatar
shahab committed
162
163
164
  return rlc_status.head_sdu_creation_time;
}

Robert Schmidt's avatar
Robert Schmidt committed
165
166
int32_t flexran_get_TA(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
167
  if (!phy_is_present(mod_id, cc_id)) return 0;
shahab's avatar
shahab committed
168

169
  int32_t tau = RC.eNB[mod_id][cc_id]->UE_stats[ue_id].timing_advance_update;
Robert Schmidt's avatar
Robert Schmidt committed
170
  switch (flexran_get_N_RB_DL(mod_id, cc_id)) {
shahab's avatar
shahab committed
171
  case 6:
Robert Schmidt's avatar
Robert Schmidt committed
172
    return tau;
shahab's avatar
shahab committed
173
  case 15:
Robert Schmidt's avatar
Robert Schmidt committed
174
    return tau / 2;
shahab's avatar
shahab committed
175
  case 25:
Robert Schmidt's avatar
Robert Schmidt committed
176
    return tau / 4;
shahab's avatar
shahab committed
177
  case 50:
Robert Schmidt's avatar
Robert Schmidt committed
178
    return tau / 8;
shahab's avatar
shahab committed
179
  case 75:
Robert Schmidt's avatar
Robert Schmidt committed
180
    return tau / 12;
shahab's avatar
shahab committed
181
  case 100:
Robert Schmidt's avatar
Robert Schmidt committed
182
183
184
185
    if (flexran_get_threequarter_fs(mod_id, cc_id) == 0)
      return tau / 16;
    else
      return tau / 12;
shahab's avatar
shahab committed
186
187
188
189
190
  default:
    return 0;
  }
}

Robert Schmidt's avatar
Robert Schmidt committed
191
192
uint8_t flexran_get_ue_wpmi(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
193
194
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.UE_sched_ctrl[ue_id].periodic_wideband_pmi[cc_id];
shahab's avatar
shahab committed
195
196
}

Robert Schmidt's avatar
Robert Schmidt committed
197
198
199
200
/* TODO needs to be revised */
void flexran_update_TA(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
/*
shahab's avatar
shahab committed
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
  UE_list_t *UE_list=&eNB_mac_inst[mod_id].UE_list;
  UE_sched_ctrl *ue_sched_ctl = &UE_list->UE_sched_ctrl[ue_id];

  if (ue_sched_ctl->ta_timer == 0) {
    
    // WE SHOULD PROTECT the eNB_UE_stats with a mutex here ...                                                                         
    //    LTE_eNB_UE_stats		*eNB_UE_stats = mac_xface->get_eNB_UE_stats(mod_id, CC_id, rnti);
    //ue_sched_ctl->ta_timer		      = 20;	// wait 20 subframes before taking TA measurement from PHY                                         
    ue_sched_ctl->ta_update = flexran_get_TA(mod_id, ue_id, CC_id);

    // clear the update in case PHY does not have a new measurement after timer expiry                                               
    //    eNB_UE_stats->timing_advance_update	      = 0;
  } else {
    ue_sched_ctl->ta_timer--;
    ue_sched_ctl->ta_update		      = 0;	// don't trigger a timing advance command      
  }
Robert Schmidt's avatar
Robert Schmidt committed
217
218
*/
#warning "Implement flexran_update_TA() in RAN API"
shahab's avatar
shahab committed
219
220
}

Robert Schmidt's avatar
Robert Schmidt committed
221
222
223
224
/* TODO needs to be revised, looks suspicious: why do we need UE stats? */
int flexran_get_MAC_CE_bitmap_TA(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
#warning "Implement flexran_get_MAC_CE_bitmap_TA() in RAN API"
225
  if (!phy_is_present(mod_id, cc_id)) return 0;
226

Robert Schmidt's avatar
Robert Schmidt committed
227
  /* UE_stats can not be null, they are an array in RC
shahab's avatar
shahab committed
228
229
230
231
232
  LTE_eNB_UE_stats *eNB_UE_stats = mac_xface->get_eNB_UE_stats(mod_id,CC_id,rnti);
  
  if (eNB_UE_stats == NULL) {
    return 0;
  }
Robert Schmidt's avatar
Robert Schmidt committed
233
  */
shahab's avatar
shahab committed
234

Robert Schmidt's avatar
Robert Schmidt committed
235
  if (flexran_get_TA(mod_id, ue_id, cc_id) != 0) {
shahab's avatar
shahab committed
236
237
238
239
240
241
    return PROTOCOL__FLEX_CE_TYPE__FLPCET_TA;
  } else {
    return 0;
  }
}

Robert Schmidt's avatar
Robert Schmidt committed
242
243
int flexran_get_active_CC(mid_t mod_id, mid_t ue_id)
{
244
245
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.numactiveCCs[ue_id];
shahab's avatar
shahab committed
246
247
}

Robert Schmidt's avatar
Robert Schmidt committed
248
249
uint8_t flexran_get_current_RI(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
250
251
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->UE_stats[ue_id].rank;
shahab's avatar
shahab committed
252
253
}

Robert Schmidt's avatar
Robert Schmidt committed
254
255
int flexran_get_tpc(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
256
  if (!phy_is_present(mod_id, cc_id)) return 0;
Robert Schmidt's avatar
Robert Schmidt committed
257
258
259
260

  /* before: tested that UL_rssi != NULL and set parameter ([0]), but it is a
   * static array -> target_rx_power is useless in old ifs?! */
  int pCCid = UE_PCCID(mod_id,ue_id);
261
262
  int32_t target_rx_power = RC.eNB[mod_id][pCCid]->frame_parms.ul_power_control_config_common.p0_NominalPUSCH;
  int32_t normalized_rx_power = RC.eNB[mod_id][cc_id]->UE_stats[ue_id].UL_rssi[0];
Robert Schmidt's avatar
Robert Schmidt committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

  int tpc;
  if (normalized_rx_power > target_rx_power + 1)
    tpc = 0;	//-1
  else if (normalized_rx_power < target_rx_power - 1)
    tpc = 2;	//+1
  else
    tpc = 1;	//0
  return tpc;
}

int flexran_get_harq(mid_t       mod_id,
                     uint8_t     cc_id,
                     mid_t       ue_id,
                     frame_t     frame,
                     sub_frame_t subframe,
                     uint8_t    *pid,
                     uint8_t    *round,
                     uint8_t     harq_flag)
{
  /* TODO: Add int TB in function parameters to get the status of the second
   * TB. This can be done to by editing in get_ue_active_harq_pid function in
   * line 272 file: phy_procedures_lte_eNB.c to add DLSCH_ptr =
   * PHY_vars_eNB_g[Mod_id][CC_id]->dlsch_eNB[(uint32_t)UE_id][1];*/
shahab's avatar
shahab committed
287

Robert Schmidt's avatar
Robert Schmidt committed
288
289
  /* TODO IMPLEMENT */
  /*
shahab's avatar
shahab committed
290
291
292
  uint8_t harq_pid;
  uint8_t harq_round;
  
293
  if (mac_xface_not_ready()) return 0 ;
shahab's avatar
shahab committed
294
295

  uint16_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
shahab's avatar
shahab committed
296
  if (harq_flag == openair_harq_DL){
shahab's avatar
shahab committed
297

shahab's avatar
shahab committed
298
      mac_xface->get_ue_active_harq_pid(mod_id,CC_id,rnti,frame,subframe,&harq_pid,&harq_round,openair_harq_DL);
shahab's avatar
shahab committed
299

shahab's avatar
shahab committed
300
301
   } else if (harq_flag == openair_harq_UL){

shahab's avatar
shahab committed
302
     mac_xface->get_ue_active_harq_pid(mod_id,CC_id,rnti,frame,subframe,&harq_pid,round,openair_harq_UL);    
shahab's avatar
shahab committed
303
304
305
306
307
308
309
310
   }
   else {

      LOG_W(FLEXRAN_AGENT,"harq_flag is not recongnized");
   }


  *pid = harq_pid;
Robert Schmidt's avatar
Robert Schmidt committed
311
  *round = harq_round;*/
shahab's avatar
shahab committed
312
313
314
315
316
  /* if (round > 0) { */
  /*   *status = 1; */
  /* } else { */
  /*   *status = 0; */
  /* } */
Robert Schmidt's avatar
Robert Schmidt committed
317
318
319
  /*return *round;*/
#warning "Implement flexran_get_harq() in RAN API"
  return 0;
shahab's avatar
shahab committed
320
321
}

Robert Schmidt's avatar
Robert Schmidt committed
322
323
int32_t flexran_get_p0_pucch_dbm(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
324
325
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->UE_stats[ue_id].Po_PUCCH_dBm;
shahab's avatar
shahab committed
326
327
}

Robert Schmidt's avatar
Robert Schmidt committed
328
329
int8_t flexran_get_p0_nominal_pucch(mid_t mod_id, uint8_t cc_id)
{
330
331
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.ul_power_control_config_common.p0_NominalPUCCH;
shahab's avatar
shahab committed
332
333
}

Robert Schmidt's avatar
Robert Schmidt committed
334
335
int32_t flexran_get_p0_pucch_status(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
336
337
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->UE_stats[ue_id].Po_PUCCH_update;
shahab's avatar
shahab committed
338
339
}

Robert Schmidt's avatar
Robert Schmidt committed
340
341
int flexran_update_p0_pucch(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
342
343
  if (!phy_is_present(mod_id, cc_id)) return 0;
  RC.eNB[mod_id][cc_id]->UE_stats[ue_id].Po_PUCCH_update = 0;
shahab's avatar
shahab committed
344
345
346
347
348
349
350
351
352
  return 0;
}


/*
 * ************************************
 * Get Messages for eNB Configuration Reply
 * ************************************
 */
Robert Schmidt's avatar
Robert Schmidt committed
353
354
uint8_t flexran_get_threequarter_fs(mid_t mod_id, uint8_t cc_id)
{
355
356
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.threequarter_fs;
357
358
}

shahab's avatar
shahab committed
359

Robert Schmidt's avatar
Robert Schmidt committed
360
361
uint8_t flexran_get_hopping_offset(mid_t mod_id, uint8_t cc_id)
{
362
363
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pusch_config_common.pusch_HoppingOffset;
shahab's avatar
shahab committed
364
365
}

Robert Schmidt's avatar
Robert Schmidt committed
366
367
PUSCH_HOPPING_t flexran_get_hopping_mode(mid_t mod_id, uint8_t cc_id)
{
368
369
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pusch_config_common.hoppingMode;
shahab's avatar
shahab committed
370
371
}

Robert Schmidt's avatar
Robert Schmidt committed
372
373
uint8_t flexran_get_n_SB(mid_t mod_id, uint8_t cc_id)
{
374
375
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pusch_config_common.n_SB;
shahab's avatar
shahab committed
376
377
}

Robert Schmidt's avatar
Robert Schmidt committed
378
379
uint8_t flexran_get_enable64QAM(mid_t mod_id, uint8_t cc_id)
{
380
381
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pusch_config_common.enable64QAM;
shahab's avatar
shahab committed
382
383
}

Robert Schmidt's avatar
Robert Schmidt committed
384
385
PHICH_DURATION_t flexran_get_phich_duration(mid_t mod_id, uint8_t cc_id)
{
386
387
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.phich_config_common.phich_duration;
shahab's avatar
shahab committed
388
389
}

Robert Schmidt's avatar
Robert Schmidt committed
390
391
int flexran_get_phich_resource(mid_t mod_id, uint8_t cc_id)
{
392
393
  if (!phy_is_present(mod_id, cc_id)) return 0;
  switch (RC.eNB[mod_id][cc_id]->frame_parms.phich_config_common.phich_resource) {
Robert Schmidt's avatar
Robert Schmidt committed
394
395
396
397
398
399
400
401
402
403
404
  case oneSixth:
    return 0;
  case half:
    return 1;
  case one:
    return 2;
  case two:
    return 3;
  default:
    return -1;
  }
shahab's avatar
shahab committed
405
406
}

Robert Schmidt's avatar
Robert Schmidt committed
407
408
uint16_t flexran_get_n1pucch_an(mid_t mod_id, uint8_t cc_id)
{
409
410
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pucch_config_common.n1PUCCH_AN;
shahab's avatar
shahab committed
411
412
}

Robert Schmidt's avatar
Robert Schmidt committed
413
414
uint8_t flexran_get_nRB_CQI(mid_t mod_id, uint8_t cc_id)
{
415
416
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pucch_config_common.nRB_CQI;
shahab's avatar
shahab committed
417
418
}

Robert Schmidt's avatar
Robert Schmidt committed
419
420
uint8_t flexran_get_deltaPUCCH_Shift(mid_t mod_id, uint8_t cc_id)
{
421
422
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pucch_config_common.deltaPUCCH_Shift;
shahab's avatar
shahab committed
423
424
}

Robert Schmidt's avatar
Robert Schmidt committed
425
426
uint8_t flexran_get_prach_ConfigIndex(mid_t mod_id, uint8_t cc_id)
{
427
428
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex;
shahab's avatar
shahab committed
429
430
}

Robert Schmidt's avatar
Robert Schmidt committed
431
432
uint8_t flexran_get_prach_FreqOffset(mid_t mod_id, uint8_t cc_id)
{
433
434
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset;
shahab's avatar
shahab committed
435
436
}

Robert Schmidt's avatar
Robert Schmidt committed
437
438
uint8_t flexran_get_maxHARQ_Msg3Tx(mid_t mod_id, uint8_t cc_id)
{
439
440
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.maxHARQ_Msg3Tx;
shahab's avatar
shahab committed
441
442
}

Robert Schmidt's avatar
Robert Schmidt committed
443
444
lte_prefix_type_t flexran_get_ul_cyclic_prefix_length(mid_t mod_id, uint8_t cc_id)
{
445
446
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.Ncp_UL;
shahab's avatar
shahab committed
447
448
}

Robert Schmidt's avatar
Robert Schmidt committed
449
450
lte_prefix_type_t flexran_get_dl_cyclic_prefix_length(mid_t mod_id, uint8_t cc_id)
{
451
452
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.Ncp;
shahab's avatar
shahab committed
453
454
}

Robert Schmidt's avatar
Robert Schmidt committed
455
456
uint16_t flexran_get_cell_id(mid_t mod_id, uint8_t cc_id)
{
457
458
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.Nid_cell;
shahab's avatar
shahab committed
459
460
}

Robert Schmidt's avatar
Robert Schmidt committed
461
462
uint8_t flexran_get_srs_BandwidthConfig(mid_t mod_id, uint8_t cc_id)
{
463
464
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.soundingrs_ul_config_common.srs_BandwidthConfig;
shahab's avatar
shahab committed
465
466
}

Robert Schmidt's avatar
Robert Schmidt committed
467
468
uint8_t flexran_get_srs_SubframeConfig(mid_t mod_id, uint8_t cc_id)
{
469
470
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.soundingrs_ul_config_common.srs_SubframeConfig;
shahab's avatar
shahab committed
471
472
}

Robert Schmidt's avatar
Robert Schmidt committed
473
474
uint8_t flexran_get_srs_MaxUpPts(mid_t mod_id, uint8_t cc_id)
{
475
476
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.soundingrs_ul_config_common.srs_MaxUpPts;
shahab's avatar
shahab committed
477
478
}

Robert Schmidt's avatar
Robert Schmidt committed
479
480
uint8_t flexran_get_N_RB_DL(mid_t mod_id, uint8_t cc_id)
{
481
482
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.N_RB_DL;
shahab's avatar
shahab committed
483
484
}

Robert Schmidt's avatar
Robert Schmidt committed
485
486
uint8_t flexran_get_N_RB_UL(mid_t mod_id, uint8_t cc_id)
{
487
488
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.N_RB_UL;
shahab's avatar
shahab committed
489
490
}

Robert Schmidt's avatar
Robert Schmidt committed
491
492
uint8_t flexran_get_N_RBG(mid_t mod_id, uint8_t cc_id)
{
493
494
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.N_RBG;
shahab's avatar
shahab committed
495
496
}

Robert Schmidt's avatar
Robert Schmidt committed
497
498
uint8_t flexran_get_subframe_assignment(mid_t mod_id, uint8_t cc_id)
{
499
500
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.tdd_config;
shahab's avatar
shahab committed
501
502
}

Robert Schmidt's avatar
Robert Schmidt committed
503
504
uint8_t flexran_get_special_subframe_assignment(mid_t mod_id, uint8_t cc_id)
{
505
506
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.tdd_config_S;
shahab's avatar
shahab committed
507
508
}

Robert Schmidt's avatar
Robert Schmidt committed
509
510
long flexran_get_ra_ResponseWindowSize(mid_t mod_id, uint8_t cc_id)
{
511
512
  if (!rrc_is_present(mod_id)) return 0;
  return RC.rrc[mod_id]->configuration.rach_raResponseWindowSize[cc_id];
shahab's avatar
shahab committed
513
514
}

Robert Schmidt's avatar
Robert Schmidt committed
515
516
long flexran_get_mac_ContentionResolutionTimer(mid_t mod_id, uint8_t cc_id)
{
517
518
  if (!rrc_is_present(mod_id)) return 0;
  return RC.rrc[mod_id]->configuration.rach_macContentionResolutionTimer[cc_id];
shahab's avatar
shahab committed
519
520
}

Robert Schmidt's avatar
Robert Schmidt committed
521
522
Protocol__FlexDuplexMode flexran_get_duplex_mode(mid_t mod_id, uint8_t cc_id)
{
523
524
  if (!phy_is_present(mod_id, cc_id)) return 0;
  switch (RC.eNB[mod_id][cc_id]->frame_parms.frame_type) {
Robert Schmidt's avatar
Robert Schmidt committed
525
526
527
528
529
530
531
  case TDD:
    return PROTOCOL__FLEX_DUPLEX_MODE__FLDM_TDD;
  case FDD:
    return PROTOCOL__FLEX_DUPLEX_MODE__FLDM_FDD;
  default:
    return -1;
  }
shahab's avatar
shahab committed
532
533
}

Robert Schmidt's avatar
Robert Schmidt committed
534
535
long flexran_get_si_window_length(mid_t mod_id, uint8_t cc_id)
{
536
537
  if (!rrc_is_present(mod_id) || !RC.rrc[mod_id]->carrier[cc_id].sib1) return 0;
  return RC.rrc[mod_id]->carrier[cc_id].sib1->si_WindowLength;
shahab's avatar
shahab committed
538
539
}

Robert Schmidt's avatar
Robert Schmidt committed
540
541
uint8_t flexran_get_sib1_length(mid_t mod_id, uint8_t cc_id)
{
542
543
  if (!rrc_is_present(mod_id)) return 0;
  return RC.rrc[mod_id]->carrier[cc_id].sizeof_SIB1;
shahab's avatar
shahab committed
544
545
}

546
547
uint8_t flexran_get_num_pdcch_symb(mid_t mod_id, uint8_t cc_id)
{
548
549
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->pdcch_vars[0].num_pdcch_symbols;
shahab's avatar
shahab committed
550
551
552
553
554
555
556
557
558
559
560
}



/*
 * ************************************
 * Get Messages for UE Configuration Reply
 * ************************************
 */


Robert Schmidt's avatar
Robert Schmidt committed
561
562
TimeAlignmentTimer_t flexran_get_time_alignment_timer(mid_t mod_id, mid_t ue_id)
{
563
  if (!rrc_is_present(mod_id)) return -1;
564

Robert Schmidt's avatar
Robert Schmidt committed
565
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
566
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
shahab's avatar
shahab committed
567

Robert Schmidt's avatar
Robert Schmidt committed
568
569
570
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig) return -1;
  return ue_context_p->ue_context.mac_MainConfig->timeAlignmentTimerDedicated;
shahab's avatar
shahab committed
571
572
}

Robert Schmidt's avatar
Robert Schmidt committed
573
574
Protocol__FlexMeasGapConfigPattern flexran_get_meas_gap_config(mid_t mod_id, mid_t ue_id)
{
575
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
576

Robert Schmidt's avatar
Robert Schmidt committed
577
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
578
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
579
580
581
582
583
584
585
586
587
588
589

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.measGapConfig) return -1;
  if (ue_context_p->ue_context.measGapConfig->present != MeasGapConfig_PR_setup) return -1;
  switch (ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.present) {
  case MeasGapConfig__setup__gapOffset_PR_gp0:
    return PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_GP1;
  case MeasGapConfig__setup__gapOffset_PR_gp1:
    return PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_GP2;
  default:
    return PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_OFF;
shahab's avatar
shahab committed
590
591
592
  }
}

shahab's avatar
shahab committed
593

Robert Schmidt's avatar
Robert Schmidt committed
594
595
long flexran_get_meas_gap_config_offset(mid_t mod_id, mid_t ue_id)
{
596
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
597

Robert Schmidt's avatar
Robert Schmidt committed
598
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
599
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
600
601
602
603
604
605
606
607
608
609
610
611
612

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.measGapConfig) return -1;
  if (ue_context_p->ue_context.measGapConfig->present != MeasGapConfig_PR_setup) return -1;
  switch (ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.present) {
  case MeasGapConfig__setup__gapOffset_PR_gp0:
    return ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.choice.gp0;
  case MeasGapConfig__setup__gapOffset_PR_gp1:
    return ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.choice.gp1;
  default:
    return -1;
  }
}
613

614
uint8_t flexran_get_rrc_status(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
615
{
616
  if (!rrc_is_present(mod_id)) return 0;
shahab's avatar
shahab committed
617

618
  rnti_t rnti = flexran_get_ue_crnti(mod_id, ue_id);
619
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
shahab's avatar
shahab committed
620

Robert Schmidt's avatar
Robert Schmidt committed
621
622
  if (!ue_context_p) return RRC_INACTIVE;
  return ue_context_p->ue_context.Status;
shahab's avatar
shahab committed
623
624
}

Robert Schmidt's avatar
Robert Schmidt committed
625
626
uint64_t flexran_get_ue_aggregated_max_bitrate_dl(mid_t mod_id, mid_t ue_id)
{
627
628
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.UE_sched_ctrl[ue_id].ue_AggregatedMaximumBitrateDL;
shahab's avatar
shahab committed
629
630
}

Robert Schmidt's avatar
Robert Schmidt committed
631
632
uint64_t flexran_get_ue_aggregated_max_bitrate_ul(mid_t mod_id, mid_t ue_id)
{
633
634
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.UE_sched_ctrl[ue_id].ue_AggregatedMaximumBitrateUL;
shahab's avatar
shahab committed
635
636
}

637
638
639
640
641
642
643
644
645
646
647
648
649
int flexran_get_half_duplex(mid_t mod_id, mid_t ue_id)
{
  if (!rrc_is_present(mod_id)) return -1;

  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.UE_Capability) return -1;
  SupportedBandListEUTRA_t *bands = &ue_context_p->ue_context.UE_Capability->rf_Parameters.supportedBandListEUTRA;
  for (int i = 0; i < bands->list.count; i++) {
    if (bands->list.array[i]->halfDuplex > 0) return 1;
  }
shahab's avatar
shahab committed
650
651
652
  return 0;
}

653
int flexran_get_intra_sf_hopping(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
654
{
655
656
657
658
659
660
661
662
663
664
665
666
667
668
  if (!rrc_is_present(mod_id)) return -1;

  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.UE_Capability) return -1;
  if (!ue_context_p->ue_context.UE_Capability->featureGroupIndicators) return -1;
  /* According to TS 36.331 Annex B.1, Intra SF Hopping is bit 1 (leftmost bit)
   * in this bitmap, i.e. the eighth bit (from right) in the first bye (from
   * left) */
  BIT_STRING_t *fgi = ue_context_p->ue_context.UE_Capability->featureGroupIndicators;
  uint8_t buf = fgi->buf[0];
  return (buf >> 7) & 1;
shahab's avatar
shahab committed
669
670
}

671
int flexran_get_type2_sb_1(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
672
{
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
  if (!rrc_is_present(mod_id)) return -1;

  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.UE_Capability) return -1;
  if (!ue_context_p->ue_context.UE_Capability->featureGroupIndicators) return -1;
  /* According to TS 36.331 Annex B.1, Predefined intra- and inter-sf or
   * predfined inter-sf frequency hopping for PUSCH with N_sb>1 is bit 21 (bit
   * 1 is leftmost bit) in this bitmap, i.e. the fourth bit (from right) in the
   * third byte (from left) */
  BIT_STRING_t *fgi = ue_context_p->ue_context.UE_Capability->featureGroupIndicators;
  uint8_t buf = fgi->buf[2];
  return (buf >> 3) & 1;
shahab's avatar
shahab committed
688
689
}

690
long flexran_get_ue_category(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
691
{
692
693
694
695
696
697
698
699
  if (!rrc_is_present(mod_id)) return -1;

  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.UE_Capability) return -1;
  return ue_context_p->ue_context.UE_Capability->ue_Category;
shahab's avatar
shahab committed
700
701
}

702
int flexran_get_res_alloc_type1(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
703
{
704
705
706
707
708
709
710
711
712
713
714
715
716
717
  if (!rrc_is_present(mod_id)) return -1;

  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.UE_Capability) return -1;
  if (!ue_context_p->ue_context.UE_Capability->featureGroupIndicators) return -1;
  /* According to TS 36.331 Annex B.1, Resource allocation type 1 for PDSCH is
   * bit 2 (bit 1 is leftmost bit) in this bitmap, i.e. the seventh bit (from
   * right) in the first byte (from left) */
  BIT_STRING_t *fgi = ue_context_p->ue_context.UE_Capability->featureGroupIndicators;
  uint8_t buf = fgi->buf[0];
  return (buf >> 6) & 1;
shahab's avatar
shahab committed
718
719
}

Robert Schmidt's avatar
Robert Schmidt committed
720
721
long flexran_get_ue_transmission_mode(mid_t mod_id, mid_t ue_id)
{
722
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
723

Robert Schmidt's avatar
Robert Schmidt committed
724
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
725
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
726

Robert Schmidt's avatar
Robert Schmidt committed
727
728
729
730
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->antennaInfo) return -1;
  return ue_context_p->ue_context.physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode;
shahab's avatar
shahab committed
731
732
}

Robert Schmidt's avatar
Robert Schmidt committed
733
734
BOOLEAN_t flexran_get_tti_bundling(mid_t mod_id, mid_t ue_id)
{
735
  if (!rrc_is_present(mod_id)) return -1;
736

Robert Schmidt's avatar
Robert Schmidt committed
737
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
738
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
739
740
741
742
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig->ul_SCH_Config) return -1;
  return ue_context_p->ue_context.mac_MainConfig->ul_SCH_Config->ttiBundling;
shahab's avatar
shahab committed
743
744
}

Robert Schmidt's avatar
Robert Schmidt committed
745
746
long flexran_get_maxHARQ_TX(mid_t mod_id, mid_t ue_id)
{
747
  if (!rrc_is_present(mod_id)) return -1;
748

Robert Schmidt's avatar
Robert Schmidt committed
749
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
750
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
751
752
753
754
755

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig->ul_SCH_Config) return -1;
  return *(ue_context_p->ue_context.mac_MainConfig->ul_SCH_Config->maxHARQ_Tx);
shahab's avatar
shahab committed
756
757
}

Robert Schmidt's avatar
Robert Schmidt committed
758
759
long flexran_get_beta_offset_ack_index(mid_t mod_id, mid_t ue_id)
{
760
  if (!rrc_is_present(mod_id)) return -1;
761

Robert Schmidt's avatar
Robert Schmidt committed
762
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
763
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
764
765
766
767
768

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->pusch_ConfigDedicated) return -1;
  return ue_context_p->ue_context.physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_ACK_Index;
shahab's avatar
shahab committed
769
770
}

Robert Schmidt's avatar
Robert Schmidt committed
771
772
long flexran_get_beta_offset_ri_index(mid_t mod_id, mid_t ue_id)
{
773
  if (!rrc_is_present(mod_id)) return -1;
774

Robert Schmidt's avatar
Robert Schmidt committed
775
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
776
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
777
778
779
780
781

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->pusch_ConfigDedicated) return -1;
  return ue_context_p->ue_context.physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_RI_Index;
shahab's avatar
shahab committed
782
783
}

Robert Schmidt's avatar
Robert Schmidt committed
784
785
long flexran_get_beta_offset_cqi_index(mid_t mod_id, mid_t ue_id)
{
786
  if (!rrc_is_present(mod_id)) return -1;
Robert Schmidt's avatar
Robert Schmidt committed
787
788

  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
789
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
790

Robert Schmidt's avatar
Robert Schmidt committed
791
792
793
794
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->pusch_ConfigDedicated) return -1;
  return ue_context_p->ue_context.physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_CQI_Index;
shahab's avatar
shahab committed
795
796
}

Robert Schmidt's avatar
Robert Schmidt committed
797
798
BOOLEAN_t flexran_get_simultaneous_ack_nack_cqi(mid_t mod_id, mid_t ue_id)
{
799
  if (!rrc_is_present(mod_id)) return -1;
800

Robert Schmidt's avatar
Robert Schmidt committed
801
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
802
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
803

Robert Schmidt's avatar
Robert Schmidt committed
804
805
806
807
808
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->cqi_ReportConfig) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic) return -1;
  return ue_context_p->ue_context.physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.simultaneousAckNackAndCQI;
shahab's avatar
shahab committed
809
810
}

Robert Schmidt's avatar
Robert Schmidt committed
811
812
BOOLEAN_t flexran_get_ack_nack_simultaneous_trans(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
813
814
815
  if (!rrc_is_present(mod_id)) return -1;
  if (!RC.rrc[mod_id]->carrier[cc_id].sib2) return -1;
  return RC.rrc[mod_id]->carrier[cc_id].sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission;
Robert Schmidt's avatar
Robert Schmidt committed
816
}
817

Robert Schmidt's avatar
Robert Schmidt committed
818
819
CQI_ReportModeAperiodic_t flexran_get_aperiodic_cqi_rep_mode(mid_t mod_id,mid_t ue_id)
{
820
  if (!rrc_is_present(mod_id)) return -1;
821

Robert Schmidt's avatar
Robert Schmidt committed
822
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
823
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
824
825
826
827
828

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->cqi_ReportConfig) return -1;
  return *ue_context_p->ue_context.physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic;
shahab's avatar
shahab committed
829
830
}

Robert Schmidt's avatar
Robert Schmidt committed
831
832
long flexran_get_tdd_ack_nack_feedback_mode(mid_t mod_id, mid_t ue_id)
{
833
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
834

Robert Schmidt's avatar
Robert Schmidt committed
835
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
836
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
837

Robert Schmidt's avatar
Robert Schmidt committed
838
839
840
841
842
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->pucch_ConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode) return -1;
  return *(ue_context_p->ue_context.physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode);
shahab's avatar
shahab committed
843
844
}

Robert Schmidt's avatar
Robert Schmidt committed
845
846
long flexran_get_ack_nack_repetition_factor(mid_t mod_id, mid_t ue_id)
{
847
  if (!rrc_is_present(mod_id)) return -1;
848

Robert Schmidt's avatar
Robert Schmidt committed
849
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
850
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Robert Schmidt's avatar
Robert Schmidt committed
851
852
853
854
855

  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->pucch_ConfigDedicated) return -1;
  return ue_context_p->ue_context.physicalConfigDedicated->pucch_ConfigDedicated->ackNackRepetition.choice.setup.repetitionFactor;
shahab's avatar
shahab committed
856
857
}

Robert Schmidt's avatar
Robert Schmidt committed
858
859
long flexran_get_extended_bsr_size(mid_t mod_id, mid_t ue_id)
{
860
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
861

Robert Schmidt's avatar
Robert Schmidt committed
862
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
863
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
864

Robert Schmidt's avatar
Robert Schmidt committed
865
866
867
868
869
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig->ext2) return -1;
  if (!ue_context_p->ue_context.mac_MainConfig->ext2->mac_MainConfig_v1020) return -1;
  return *(ue_context_p->ue_context.mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10);
shahab's avatar
shahab committed
870
871
}

Robert Schmidt's avatar
Robert Schmidt committed
872
873
int flexran_get_ue_transmission_antenna(mid_t mod_id, mid_t ue_id)
{
874
  if (!rrc_is_present(mod_id)) return -1;
875

Robert Schmidt's avatar
Robert Schmidt committed
876
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
877
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
878

Robert Schmidt's avatar
Robert Schmidt committed
879
880
881
882
883
884
885
886
887
888
  if (!ue_context_p) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
  if (!ue_context_p->ue_context.physicalConfigDedicated->antennaInfo) return -1;
  switch (ue_context_p->ue_context.physicalConfigDedicated->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.setup) {
  case AntennaInfoDedicated__ue_TransmitAntennaSelection__setup_closedLoop:
    return 2;
  case AntennaInfoDedicated__ue_TransmitAntennaSelection__setup_openLoop:
    return 1;
  default:
    return 0;
shahab's avatar
shahab committed
889
890
891
  }
}

892
893
uint64_t flexran_get_ue_imsi(mid_t mod_id, mid_t ue_id)
{
894
  uint64_t imsi;
895
  if (!rrc_is_present(mod_id)) return 0;
896
897
898
899

  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);

900
  if (!ue_context_p) return 0;
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917

  imsi  = ue_context_p->ue_context.imsi.digit15;
  imsi += ue_context_p->ue_context.imsi.digit14 * 10;              // pow(10, 1)
  imsi += ue_context_p->ue_context.imsi.digit13 * 100;             // pow(10, 2)
  imsi += ue_context_p->ue_context.imsi.digit12 * 1000;            // pow(10, 3)
  imsi += ue_context_p->ue_context.imsi.digit11 * 10000;           // pow(10, 4)
  imsi += ue_context_p->ue_context.imsi.digit10 * 100000;          // pow(10, 5)
  imsi += ue_context_p->ue_context.imsi.digit9  * 1000000;         // pow(10, 6)
  imsi += ue_context_p->ue_context.imsi.digit8  * 10000000;        // pow(10, 7)
  imsi += ue_context_p->ue_context.imsi.digit7  * 100000000;       // pow(10, 8)
  imsi += ue_context_p->ue_context.imsi.digit6  * 1000000000;      // pow(10, 9)
  imsi += ue_context_p->ue_context.imsi.digit5  * 10000000000;     // pow(10, 10)
  imsi += ue_context_p->ue_context.imsi.digit4  * 100000000000;    // pow(10, 11)
  imsi += ue_context_p->ue_context.imsi.digit3  * 1000000000000;   // pow(10, 12)
  imsi += ue_context_p->ue_context.imsi.digit2  * 10000000000000;  // pow(10, 13)
  imsi += ue_context_p->ue_context.imsi.digit1  * 100000000000000; // pow(10, 14)
  return imsi;
918
919
}

920
long flexran_get_lcg(mid_t mod_id, mid_t ue_id, mid_t lc_id)
Robert Schmidt's avatar
Robert Schmidt committed
921
{
922
923
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.UE_template[UE_PCCID(mod_id, ue_id)][ue_id].lcgidmap[lc_id];
shahab's avatar
shahab committed
924
925
}

Robert Schmidt's avatar
Robert Schmidt committed
926
/* TODO Navid: needs to be revised */
Robert Schmidt's avatar
Robert Schmidt committed
927
928
929
930
931
int flexran_get_direction(mid_t ue_id, mid_t lc_id)
{
  switch (lc_id) {
  case DCCH:
  case DCCH1:
shahab's avatar
shahab committed
932
    return 2;
Robert Schmidt's avatar
Robert Schmidt committed
933
  case DTCH:
shahab's avatar
shahab committed
934
    return 1;
Robert Schmidt's avatar
Robert Schmidt committed
935
  default:
shahab's avatar
shahab committed
936
937
938
939
    return -1;
  }
}

Robert Schmidt's avatar
Robert Schmidt committed
940
941
uint8_t flexran_get_antenna_ports(mid_t mod_id, uint8_t cc_id)
{
942
943
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.nb_antenna_ports_eNB;
944
}
shahab's avatar
shahab committed
945

Robert Schmidt's avatar
Robert Schmidt committed
946
947
uint32_t flexran_agent_get_operating_dl_freq(mid_t mod_id, uint8_t cc_id)
{
948
949
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.dl_CarrierFreq / 1000000;
shahab's avatar
shahab committed
950
951
}

Robert Schmidt's avatar
Robert Schmidt committed
952
953
uint32_t flexran_agent_get_operating_ul_freq(mid_t mod_id, uint8_t cc_id)
{
954
955
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.ul_CarrierFreq / 1000000;
956
957
}

Robert Schmidt's avatar
Robert Schmidt committed
958
959
uint8_t flexran_agent_get_operating_eutra_band(mid_t mod_id, uint8_t cc_id)
{
960
961
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.eutra_band;
962
}
Robert Schmidt's avatar
Robert Schmidt committed
963
964
965

int8_t flexran_agent_get_operating_pdsch_refpower(mid_t mod_id, uint8_t cc_id)
{
966
967
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.pdsch_config_common.referenceSignalPower;
968
969
}

Robert Schmidt's avatar
Robert Schmidt committed
970
971
long flexran_agent_get_operating_pusch_p0(mid_t mod_id, uint8_t cc_id)
{
972
973
  if (!rrc_is_present(mod_id)) return 0;
  return RC.rrc[mod_id]->configuration.pusch_p0_Nominal[cc_id];
Robert Schmidt's avatar
Robert Schmidt committed
974
}
975

Robert Schmidt's avatar
Robert Schmidt committed
976
977
void flexran_agent_set_operating_dl_freq(mid_t mod_id, uint8_t cc_id, uint32_t dl_freq_mhz)
{
978
979
980
981
  if (phy_is_present(mod_id, cc_id)) {
    RC.eNB[mod_id][cc_id]->frame_parms.dl_CarrierFreq = dl_freq_mhz * 1000000;
  } else {
    LOG_E(FLEXRAN_AGENT, "can not set dl_CarrierFreq to %d MHz in PHY: PHY is not present\n", dl_freq_mhz);
Robert Schmidt's avatar
Robert Schmidt committed
982
  }
983
984
985
986
  if (rrc_is_present(mod_id)) {
    RC.rrc[mod_id]->configuration.downlink_frequency[cc_id] = dl_freq_mhz * 1000000;
  } else {
    LOG_E(FLEXRAN_AGENT, "can not set downlink_frequency to %d MHz in RRC: RRC is not present\n", dl_freq_mhz);
Robert Schmidt's avatar
Robert Schmidt committed
987
  }