flexran_agent_ran_api.c 43.6 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
}

Robert Schmidt's avatar
Robert Schmidt committed
120
121
uint8_t flexran_get_ue_bsr(mid_t mod_id, mid_t ue_id, lcid_t lcid)
{
122
123
  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].bsr_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
  if (!phy_is_present(mod_id, cc_id)) return 0;
Robert Schmidt's avatar
Robert Schmidt committed
393
  /* TODO why don't we return phich_resource? */
394
  switch (RC.eNB[mod_id][cc_id]->frame_parms.phich_config_common.phich_resource) {
Robert Schmidt's avatar
Robert Schmidt committed
395
396
397
398
399
400
401
402
403
404
405
  case oneSixth:
    return 0;
  case half:
    return 1;
  case one:
    return 2;
  case two:
    return 3;
  default:
    return -1;
  }
shahab's avatar
shahab committed
406
407
}

Robert Schmidt's avatar
Robert Schmidt committed
408
409
uint16_t flexran_get_n1pucch_an(mid_t mod_id, uint8_t cc_id)
{
410
411
  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
412
413
}

Robert Schmidt's avatar
Robert Schmidt committed
414
415
uint8_t flexran_get_nRB_CQI(mid_t mod_id, uint8_t cc_id)
{
416
417
  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
418
419
}

Robert Schmidt's avatar
Robert Schmidt committed
420
421
uint8_t flexran_get_deltaPUCCH_Shift(mid_t mod_id, uint8_t cc_id)
{
422
423
  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
424
425
}

Robert Schmidt's avatar
Robert Schmidt committed
426
427
uint8_t flexran_get_prach_ConfigIndex(mid_t mod_id, uint8_t cc_id)
{
428
429
  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
430
431
}

Robert Schmidt's avatar
Robert Schmidt committed
432
433
uint8_t flexran_get_prach_FreqOffset(mid_t mod_id, uint8_t cc_id)
{
434
435
  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
436
437
}

Robert Schmidt's avatar
Robert Schmidt committed
438
439
uint8_t flexran_get_maxHARQ_Msg3Tx(mid_t mod_id, uint8_t cc_id)
{
440
441
  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
442
443
}

Robert Schmidt's avatar
Robert Schmidt committed
444
445
lte_prefix_type_t flexran_get_ul_cyclic_prefix_length(mid_t mod_id, uint8_t cc_id)
{
446
447
  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
448
449
}

Robert Schmidt's avatar
Robert Schmidt committed
450
451
lte_prefix_type_t flexran_get_dl_cyclic_prefix_length(mid_t mod_id, uint8_t cc_id)
{
452
453
  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
454
455
}

Robert Schmidt's avatar
Robert Schmidt committed
456
457
uint16_t flexran_get_cell_id(mid_t mod_id, uint8_t cc_id)
{
458
459
  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
460
461
}

Robert Schmidt's avatar
Robert Schmidt committed
462
463
uint8_t flexran_get_srs_BandwidthConfig(mid_t mod_id, uint8_t cc_id)
{
464
465
  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
466
467
}

Robert Schmidt's avatar
Robert Schmidt committed
468
469
uint8_t flexran_get_srs_SubframeConfig(mid_t mod_id, uint8_t cc_id)
{
470
471
  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
472
473
}

Robert Schmidt's avatar
Robert Schmidt committed
474
475
uint8_t flexran_get_srs_MaxUpPts(mid_t mod_id, uint8_t cc_id)
{
476
477
  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
478
479
}

Robert Schmidt's avatar
Robert Schmidt committed
480
481
uint8_t flexran_get_N_RB_DL(mid_t mod_id, uint8_t cc_id)
{
482
483
  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
484
485
}

Robert Schmidt's avatar
Robert Schmidt committed
486
487
uint8_t flexran_get_N_RB_UL(mid_t mod_id, uint8_t cc_id)
{
488
489
  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
490
491
}

Robert Schmidt's avatar
Robert Schmidt committed
492
493
uint8_t flexran_get_N_RBG(mid_t mod_id, uint8_t cc_id)
{
494
495
  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
496
497
}

Robert Schmidt's avatar
Robert Schmidt committed
498
499
uint8_t flexran_get_subframe_assignment(mid_t mod_id, uint8_t cc_id)
{
500
501
  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
502
503
}

Robert Schmidt's avatar
Robert Schmidt committed
504
505
uint8_t flexran_get_special_subframe_assignment(mid_t mod_id, uint8_t cc_id)
{
506
507
  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
508
509
}

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

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

Robert Schmidt's avatar
Robert Schmidt committed
522
523
Protocol__FlexDuplexMode flexran_get_duplex_mode(mid_t mod_id, uint8_t cc_id)
{
524
525
  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
526
527
528
529
530
531
532
  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
533
534
}

Robert Schmidt's avatar
Robert Schmidt committed
535
536
long flexran_get_si_window_length(mid_t mod_id, uint8_t cc_id)
{
537
538
  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
539
540
}

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

Robert Schmidt's avatar
Robert Schmidt committed
547
548
549
uint8_t flexran_get_num_pdcch_symb(mid_t mod_id, uint8_t cc_id) {
  /* TODO: This should return the number of PDCCH symbols initially used by the
   * cell cc_id -> is the correction right? */
550
551
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->pdcch_vars[0].num_pdcch_symbols;
Robert Schmidt's avatar
Robert Schmidt committed
552
  //(PHY_vars_UE_g[mod_id][cc_id]->lte_ue_pdcch_vars[mod_id]->num_pdcch_symbols);
shahab's avatar
shahab committed
553
554
555
556
557
558
559
560
561
562
563
}



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


Robert Schmidt's avatar
Robert Schmidt committed
564
565
TimeAlignmentTimer_t flexran_get_time_alignment_timer(mid_t mod_id, mid_t ue_id)
{
566
  if (!rrc_is_present(mod_id)) return -1;
567

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

Robert Schmidt's avatar
Robert Schmidt committed
571
572
573
  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
574
575
}

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

Robert Schmidt's avatar
Robert Schmidt committed
580
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
581
  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
582
583
584
585
586
587
588
589
590
591
592

  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
593
594
595
  }
}

shahab's avatar
shahab committed
596

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

Robert Schmidt's avatar
Robert Schmidt committed
601
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
602
  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
603
604
605
606
607
608
609
610
611
612
613
614
615

  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;
  }
}
616

Robert Schmidt's avatar
Robert Schmidt committed
617
618
619
620
/* TODO is there a reason we take the RNTI and not the UE ID? */
/* TODO return type is unsigned, so we cannot return -1 in case of error! */
uint8_t flexran_get_rrc_status(mid_t mod_id, rnti_t rnti)
{
621
  if (!rrc_is_present(mod_id)) return 0;
shahab's avatar
shahab committed
622

623
  struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
shahab's avatar
shahab committed
624

Robert Schmidt's avatar
Robert Schmidt committed
625
626
  if (!ue_context_p) return RRC_INACTIVE;
  return ue_context_p->ue_context.Status;
shahab's avatar
shahab committed
627
628
}

Robert Schmidt's avatar
Robert Schmidt committed
629
630
uint64_t flexran_get_ue_aggregated_max_bitrate_dl(mid_t mod_id, mid_t ue_id)
{
631
632
  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
633
634
}

Robert Schmidt's avatar
Robert Schmidt committed
635
636
uint64_t flexran_get_ue_aggregated_max_bitrate_ul(mid_t mod_id, mid_t ue_id)
{
637
638
  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
639
640
}

641
642
643
644
645
646
647
648
649
650
651
652
653
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
654
655
656
  return 0;
}

657
int flexran_get_intra_sf_hopping(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
658
{
659
660
661
662
663
664
665
666
667
668
669
670
671
672
  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
673
674
}

675
int flexran_get_type2_sb_1(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
676
{
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
  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
692
693
}

694
long flexran_get_ue_category(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
695
{
696
697
698
699
700
701
702
703
  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
704
705
}

706
int flexran_get_res_alloc_type1(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
707
{
708
709
710
711
712
713
714
715
716
717
718
719
720
721
  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
722
723
}

Robert Schmidt's avatar
Robert Schmidt committed
724
725
long flexran_get_ue_transmission_mode(mid_t mod_id, mid_t ue_id)
{
726
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
727

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

Robert Schmidt's avatar
Robert Schmidt committed
731
732
733
734
  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
735
736
}

Robert Schmidt's avatar
Robert Schmidt committed
737
738
BOOLEAN_t flexran_get_tti_bundling(mid_t mod_id, mid_t ue_id)
{
739
  if (!rrc_is_present(mod_id)) return -1;
740

Robert Schmidt's avatar
Robert Schmidt committed
741
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
742
  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
743
744
745
746
  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
747
748
}

Robert Schmidt's avatar
Robert Schmidt committed
749
750
long flexran_get_maxHARQ_TX(mid_t mod_id, mid_t ue_id)
{
751
  if (!rrc_is_present(mod_id)) return -1;
752

Robert Schmidt's avatar
Robert Schmidt committed
753
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
754
  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
755
756
757
758
759

  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
760
761
}

Robert Schmidt's avatar
Robert Schmidt committed
762
763
long flexran_get_beta_offset_ack_index(mid_t mod_id, mid_t ue_id)
{
764
  if (!rrc_is_present(mod_id)) return -1;
765

Robert Schmidt's avatar
Robert Schmidt committed
766
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
767
  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
768
769
770
771
772

  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
773
774
}

Robert Schmidt's avatar
Robert Schmidt committed
775
776
long flexran_get_beta_offset_ri_index(mid_t mod_id, mid_t ue_id)
{
777
  if (!rrc_is_present(mod_id)) return -1;
778

Robert Schmidt's avatar
Robert Schmidt committed
779
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
780
  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
781
782
783
784
785

  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
786
787
}

Robert Schmidt's avatar
Robert Schmidt committed
788
789
long flexran_get_beta_offset_cqi_index(mid_t mod_id, mid_t ue_id)
{
790
  if (!rrc_is_present(mod_id)) return -1;
Robert Schmidt's avatar
Robert Schmidt committed
791
792

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

Robert Schmidt's avatar
Robert Schmidt committed
795
796
797
798
  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
799
800
}

Robert Schmidt's avatar
Robert Schmidt committed
801
802
BOOLEAN_t flexran_get_simultaneous_ack_nack_cqi(mid_t mod_id, mid_t ue_id)
{
803
  if (!rrc_is_present(mod_id)) return -1;
804

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

Robert Schmidt's avatar
Robert Schmidt committed
808
809
810
811
812
  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
813
814
}

Robert Schmidt's avatar
Robert Schmidt committed
815
816
BOOLEAN_t flexran_get_ack_nack_simultaneous_trans(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
817
818
819
  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
820
}
821

Robert Schmidt's avatar
Robert Schmidt committed
822
823
CQI_ReportModeAperiodic_t flexran_get_aperiodic_cqi_rep_mode(mid_t mod_id,mid_t ue_id)
{
824
  if (!rrc_is_present(mod_id)) return -1;
825

Robert Schmidt's avatar
Robert Schmidt committed
826
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
827
  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
828
829
830
831
832

  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
833
834
}

Robert Schmidt's avatar
Robert Schmidt committed
835
836
long flexran_get_tdd_ack_nack_feedback_mode(mid_t mod_id, mid_t ue_id)
{
837
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
838

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

Robert Schmidt's avatar
Robert Schmidt committed
842
843
844
845
846
  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
847
848
}

Robert Schmidt's avatar
Robert Schmidt committed
849
850
long flexran_get_ack_nack_repetition_factor(mid_t mod_id, mid_t ue_id)
{
851
  if (!rrc_is_present(mod_id)) return -1;
852

Robert Schmidt's avatar
Robert Schmidt committed
853
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
854
  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
855
856
857
858
859

  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
860
861
}

Robert Schmidt's avatar
Robert Schmidt committed
862
863
long flexran_get_extended_bsr_size(mid_t mod_id, mid_t ue_id)
{
864
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
865

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

Robert Schmidt's avatar
Robert Schmidt committed
869
870
871
872
873
  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
874
875
}

Robert Schmidt's avatar
Robert Schmidt committed
876
877
int flexran_get_ue_transmission_antenna(mid_t mod_id, mid_t ue_id)
{
878
  if (!rrc_is_present(mod_id)) return -1;
879

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

Robert Schmidt's avatar
Robert Schmidt committed
883
884
885
886
887
888
889
890
891
892
  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
893
894
895
  }
}

Robert Schmidt's avatar
Robert Schmidt committed
896
/* TODO Navid: Get the same for eNB */
Robert Schmidt's avatar
Robert Schmidt committed
897
898
899
900
901
902
903
long flexran_get_lcg(mid_t ue_id, mid_t lc_id)
{
  if (!UE_mac_inst) return -1;
  if (!UE_mac_inst[ue_id].logicalChannelConfig[lc_id]) return -1;
  if (!UE_mac_inst[ue_id].logicalChannelConfig[lc_id]->ul_SpecificParameters) return -1;
  if (!UE_mac_inst[ue_id].logicalChannelConfig[lc_id]->ul_SpecificParameters->logicalChannelGroup) return -1;
  return *(UE_mac_inst[ue_id].logicalChannelConfig[lc_id]->ul_SpecificParameters->logicalChannelGroup);
shahab's avatar
shahab committed
904
905
}

Robert Schmidt's avatar
Robert Schmidt committed
906
/* TODO Navid: needs to be revised */
Robert Schmidt's avatar
Robert Schmidt committed
907
908
909
910
911
int flexran_get_direction(mid_t ue_id, mid_t lc_id)
{
  switch (lc_id) {
  case DCCH:
  case DCCH1:
shahab's avatar
shahab committed
912
    return 2;
Robert Schmidt's avatar
Robert Schmidt committed
913
  case DTCH:
shahab's avatar
shahab committed
914
    return 1;
Robert Schmidt's avatar
Robert Schmidt committed
915
  default:
shahab's avatar
shahab committed
916
917
918
919
    return -1;
  }
}

Robert Schmidt's avatar
Robert Schmidt committed
920
921
uint8_t flexran_get_antenna_ports(mid_t mod_id, uint8_t cc_id)
{
922
923
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.nb_antenna_ports_eNB;
924
}
shahab's avatar
shahab committed
925

Robert Schmidt's avatar
Robert Schmidt committed
926
927
928
/* TODO better give real value (without division)? */
uint32_t flexran_agent_get_operating_dl_freq(mid_t mod_id, uint8_t cc_id)
{
929
930
  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
931
932
}

Robert Schmidt's avatar
Robert Schmidt committed
933
934
935
/* TODO better give real value (without division)? */
uint32_t flexran_agent_get_operating_ul_freq(mid_t mod_id, uint8_t cc_id)
{
936
937
  if (!phy_is_present(mod_id, cc_id)) return 0;
  return RC.eNB[mod_id][cc_id]->frame_parms.ul_CarrierFreq / 1000000;
938
939
}

Robert Schmidt's avatar
Robert Schmidt committed
940
941
uint8_t flexran_agent_get_operating_eutra_band(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.eutra_band;
944
}
Robert Schmidt's avatar
Robert Schmidt committed
945
946
947

int8_t flexran_agent_get_operating_pdsch_refpower(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.pdsch_config_common.referenceSignalPower;
950
951
}

Robert Schmidt's avatar
Robert Schmidt committed
952
953
long flexran_agent_get_operating_pusch_p0(mid_t mod_id, uint8_t cc_id)
{
954
955
  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
956
}
957

Robert Schmidt's avatar
Robert Schmidt committed
958
959
void flexran_agent_set_operating_dl_freq(mid_t mod_id, uint8_t cc_id, uint32_t dl_freq_mhz)
{
960
961
962
963
  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
964
  }
965
966
967
968
  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
969
  }
970
971
}

Robert Schmidt's avatar
Robert Schmidt committed
972
973
void flexran_agent_set_operating_ul_freq(mid_t mod_id, uint8_t cc_id, int32_t ul_freq_mhz_offset)
{
974
  if (phy_is_present(mod_id, cc_id)) {
Robert Schmidt's avatar
Robert Schmidt committed
975
    uint32_t new_ul_freq_mhz = flexran_agent_get_operating_dl_freq(mod_id, cc_id) + ul_freq_mhz_offset;
976
977
978
    RC.eNB[mod_id][cc_id]->frame_parms.ul_CarrierFreq = new_ul_freq_mhz * 1000000;
  } else {
    LOG_E(FLEXRAN_AGENT, "can not set ul_CarrierFreq using offset %d MHz in PHY: PHY is not present\n", ul_freq_mhz_offset);
Robert Schmidt's avatar
Robert Schmidt committed
979
  }
980
981
982
983
  if (rrc_is_present(mod_id)) {
    RC.rrc[mod_id]->configuration.uplink_frequency_offset[cc_id] = ul_freq_mhz_offset;
  } else {
    LOG_E(FLEXRAN_AGENT, "can not set uplink_frequency_offset to %d MHz in RRC: RRC is not present\n", ul_freq_mhz_offset);
Robert Schmidt's avatar
Robert Schmidt committed
984
  }
985
}
Robert Schmidt's avatar
Robert Schmidt committed
986
987
988

void flexran_agent_set_operating_eutra_band(mid_t mod_id, uint8_t cc_id, uint8_t eutra_band)
{