flexran_agent_ran_api.c 49.1 KB
Newer Older
shahab's avatar
shahab committed
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
shahab's avatar
shahab committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * 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
  if (!mac_is_present(mod_id)) return 0;
shahab's avatar
shahab committed
135
  return RC.mac[mod_id]->UE_list.UE_sched_ctrl[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
144
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
145 146 147
                                                    ,0, 0
#endif
                                                    );
shahab's avatar
shahab committed
148
  return rlc_status.bytes_in_buffer;
shahab's avatar
shahab committed
149 150
}

Robert Schmidt's avatar
Robert Schmidt committed
151 152
rlc_buffer_occupancy_t flexran_get_num_pdus_buffer(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
{
153
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
Robert Schmidt's avatar
Robert Schmidt committed
154 155
  frame_t frame = flexran_get_current_frame(mod_id);
  sub_frame_t subframe = flexran_get_current_subframe(mod_id);
156
  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
157
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
158 159 160
                                                    ,0, 0
#endif
                                                    );
161 162 163
  return rlc_status.pdus_in_buffer;
}

Robert Schmidt's avatar
Robert Schmidt committed
164 165
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
166
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
Robert Schmidt's avatar
Robert Schmidt committed
167 168
  frame_t frame = flexran_get_current_frame(mod_id);
  sub_frame_t subframe = flexran_get_current_subframe(mod_id);
169
  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
170
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
171 172 173
                                                    ,0, 0
#endif
                                                    );
shahab's avatar
shahab committed
174 175 176
  return rlc_status.head_sdu_creation_time;
}

Robert Schmidt's avatar
Robert Schmidt committed
177 178
int32_t flexran_get_TA(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
179
  if (!phy_is_present(mod_id, cc_id)) return 0;
shahab's avatar
shahab committed
180

181
  int32_t tau = RC.eNB[mod_id][cc_id]->UE_stats[ue_id].timing_advance_update;
Robert Schmidt's avatar
Robert Schmidt committed
182
  switch (flexran_get_N_RB_DL(mod_id, cc_id)) {
shahab's avatar
shahab committed
183
  case 6:
Robert Schmidt's avatar
Robert Schmidt committed
184
    return tau;
shahab's avatar
shahab committed
185
  case 15:
Robert Schmidt's avatar
Robert Schmidt committed
186
    return tau / 2;
shahab's avatar
shahab committed
187
  case 25:
Robert Schmidt's avatar
Robert Schmidt committed
188
    return tau / 4;
shahab's avatar
shahab committed
189
  case 50:
Robert Schmidt's avatar
Robert Schmidt committed
190
    return tau / 8;
shahab's avatar
shahab committed
191
  case 75:
Robert Schmidt's avatar
Robert Schmidt committed
192
    return tau / 12;
shahab's avatar
shahab committed
193
  case 100:
Robert Schmidt's avatar
Robert Schmidt committed
194 195 196 197
    if (flexran_get_threequarter_fs(mod_id, cc_id) == 0)
      return tau / 16;
    else
      return tau / 12;
shahab's avatar
shahab committed
198 199 200 201 202
  default:
    return 0;
  }
}

203 204
uint32_t flexran_get_total_size_dl_mac_sdus(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
205 206 207 208
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].total_sdu_bytes;
}

209 210 211
uint32_t flexran_get_total_size_ul_mac_sdus(mid_t mod_id, mid_t ue_id, int cc_id)
{
  if (!mac_is_present(mod_id)) return 0;
shahab's avatar
shahab committed
212 213 214
  return RC.mac[mod_id]->eNB_stats[cc_id].total_ulsch_bytes_rx;
}

215 216
uint32_t flexran_get_TBS_dl(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
217 218 219 220
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].TBS;
}

221 222
uint32_t flexran_get_TBS_ul(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
223 224 225 226
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].ulsch_TBS;
}

227 228 229 230
uint16_t flexran_get_num_prb_retx_dl_per_ue(mid_t mod_id, mid_t ue_id, int cc_id)
{
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].rbs_used_retx;
shahab's avatar
shahab committed
231 232
}

233 234
uint32_t flexran_get_num_prb_retx_ul_per_ue(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
235 236 237 238
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].rbs_used_retx_rx;
}

239 240 241 242
uint16_t flexran_get_num_prb_dl_tx_per_ue(mid_t mod_id, mid_t ue_id, int cc_id)
{
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].rbs_used;
shahab's avatar
shahab committed
243 244
}

245 246 247 248
uint16_t flexran_get_num_prb_ul_rx_per_ue(mid_t mod_id, mid_t ue_id, int cc_id)
{
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].rbs_used_rx;
shahab's avatar
shahab committed
249 250
}

Robert Schmidt's avatar
Robert Schmidt committed
251 252
uint8_t flexran_get_ue_wpmi(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
253 254
  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
255 256
}

257 258
uint8_t flexran_get_mcs1_dl(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
259 260 261 262
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].dlsch_mcs1;
}

263 264
uint8_t flexran_get_mcs2_dl(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
265 266 267 268
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].dlsch_mcs2;
}

269 270
uint8_t flexran_get_mcs1_ul(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
271 272 273 274
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].ulsch_mcs1;
}

275 276
uint8_t flexran_get_mcs2_ul(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
277 278 279 280
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].ulsch_mcs2;
}

281 282
uint32_t flexran_get_total_prb_dl_tx_per_ue(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
283 284 285 286
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].total_rbs_used;
}

287 288
uint32_t flexran_get_total_prb_ul_rx_per_ue(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
289 290 291 292
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].total_rbs_used_rx;
}

293 294
uint32_t flexran_get_total_num_pdu_dl(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
295 296 297 298
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].total_num_pdus;
}

299 300
uint32_t flexran_get_total_num_pdu_ul(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
301 302 303 304
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].total_num_pdus_rx;
}

305 306
uint64_t flexran_get_total_TBS_dl(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
307 308 309 310
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].total_pdu_bytes;
}

311 312
uint64_t flexran_get_total_TBS_ul(mid_t mod_id, mid_t ue_id, int cc_id)
{
shahab's avatar
shahab committed
313 314 315 316
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].total_ulsch_TBS;
}

317 318
int flexran_get_harq_round(mid_t mod_id, uint8_t cc_id, mid_t ue_id)
{
shahab's avatar
shahab committed
319 320 321 322
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].harq_round;
}

323 324 325 326
uint32_t flexran_get_num_mac_sdu_tx(mid_t mod_id, mid_t ue_id, int cc_id)
{
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].num_mac_sdu_tx;
shahab's avatar
shahab committed
327 328
}

329 330
unsigned char flexran_get_mac_sdu_lcid_index(mid_t mod_id, mid_t ue_id, int cc_id, int index)
{
shahab's avatar
shahab committed
331 332 333 334
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].lcid_sdu[index];
}

335 336
uint32_t flexran_get_mac_sdu_size(mid_t mod_id, mid_t ue_id, int cc_id, int lcid)
{
shahab's avatar
shahab committed
337 338 339 340 341
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.eNB_UE_stats[cc_id][ue_id].sdu_length_tx[lcid];
}


Robert Schmidt's avatar
Robert Schmidt committed
342 343 344 345
/* 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
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
  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
362 363
*/
#warning "Implement flexran_update_TA() in RAN API"
shahab's avatar
shahab committed
364 365
}

Robert Schmidt's avatar
Robert Schmidt committed
366 367 368 369
/* 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"
370
  if (!phy_is_present(mod_id, cc_id)) return 0;
371

Robert Schmidt's avatar
Robert Schmidt committed
372
  /* UE_stats can not be null, they are an array in RC
shahab's avatar
shahab committed
373 374 375 376 377
  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
378
  */
shahab's avatar
shahab committed
379

Robert Schmidt's avatar
Robert Schmidt committed
380
  if (flexran_get_TA(mod_id, ue_id, cc_id) != 0) {
shahab's avatar
shahab committed
381 382 383 384 385 386
    return PROTOCOL__FLEX_CE_TYPE__FLPCET_TA;
  } else {
    return 0;
  }
}

Robert Schmidt's avatar
Robert Schmidt committed
387 388
int flexran_get_active_CC(mid_t mod_id, mid_t ue_id)
{
389 390
  if (!mac_is_present(mod_id)) return 0;
  return RC.mac[mod_id]->UE_list.numactiveCCs[ue_id];
shahab's avatar
shahab committed
391 392
}

Robert Schmidt's avatar
Robert Schmidt committed
393 394
uint8_t flexran_get_current_RI(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
395 396
  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
397 398
}

Robert Schmidt's avatar
Robert Schmidt committed
399 400
int flexran_get_tpc(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
401
  if (!phy_is_present(mod_id, cc_id)) return 0;
Robert Schmidt's avatar
Robert Schmidt committed
402 403 404 405

  /* 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);
406 407
  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
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431

  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
432

Robert Schmidt's avatar
Robert Schmidt committed
433 434
  /* TODO IMPLEMENT */
  /*
shahab's avatar
shahab committed
435 436 437
  uint8_t harq_pid;
  uint8_t harq_round;
  
438
  if (mac_xface_not_ready()) return 0 ;
shahab's avatar
shahab committed
439 440

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

shahab's avatar
shahab committed
443
      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
444

shahab's avatar
shahab committed
445 446
   } else if (harq_flag == openair_harq_UL){

shahab's avatar
shahab committed
447
     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
448 449 450 451 452 453 454 455
   }
   else {

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


  *pid = harq_pid;
Robert Schmidt's avatar
Robert Schmidt committed
456
  *round = harq_round;*/
shahab's avatar
shahab committed
457 458 459 460 461
  /* if (round > 0) { */
  /*   *status = 1; */
  /* } else { */
  /*   *status = 0; */
  /* } */
Robert Schmidt's avatar
Robert Schmidt committed
462 463 464
  /*return *round;*/
#warning "Implement flexran_get_harq() in RAN API"
  return 0;
shahab's avatar
shahab committed
465 466
}

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

Robert Schmidt's avatar
Robert Schmidt committed
473 474
int8_t flexran_get_p0_nominal_pucch(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.ul_power_control_config_common.p0_NominalPUCCH;
shahab's avatar
shahab committed
477 478
}

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

Robert Schmidt's avatar
Robert Schmidt committed
485 486
int flexran_update_p0_pucch(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
{
487 488
  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
489 490 491 492 493 494 495 496 497
  return 0;
}


/*
 * ************************************
 * Get Messages for eNB Configuration Reply
 * ************************************
 */
Robert Schmidt's avatar
Robert Schmidt committed
498 499
uint8_t flexran_get_threequarter_fs(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.threequarter_fs;
502 503
}

shahab's avatar
shahab committed
504

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

Robert Schmidt's avatar
Robert Schmidt committed
511 512
PUSCH_HOPPING_t flexran_get_hopping_mode(mid_t mod_id, uint8_t cc_id)
{
513 514
  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
515 516
}

Robert Schmidt's avatar
Robert Schmidt committed
517 518
uint8_t flexran_get_n_SB(mid_t mod_id, uint8_t cc_id)
{
519 520
  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
521 522
}

Robert Schmidt's avatar
Robert Schmidt committed
523 524
uint8_t flexran_get_enable64QAM(mid_t mod_id, uint8_t cc_id)
{
525 526
  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
527 528
}

Robert Schmidt's avatar
Robert Schmidt committed
529 530
PHICH_DURATION_t flexran_get_phich_duration(mid_t mod_id, uint8_t cc_id)
{
531 532
  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
533 534
}

Robert Schmidt's avatar
Robert Schmidt committed
535 536
int flexran_get_phich_resource(mid_t mod_id, uint8_t cc_id)
{
537 538
  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
539 540 541 542 543 544 545 546 547 548 549
  case oneSixth:
    return 0;
  case half:
    return 1;
  case one:
    return 2;
  case two:
    return 3;
  default:
    return -1;
  }
shahab's avatar
shahab committed
550 551
}

Robert Schmidt's avatar
Robert Schmidt committed
552 553
uint16_t flexran_get_n1pucch_an(mid_t mod_id, uint8_t cc_id)
{
554 555
  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
556 557
}

Robert Schmidt's avatar
Robert Schmidt committed
558 559
uint8_t flexran_get_nRB_CQI(mid_t mod_id, uint8_t cc_id)
{
560 561
  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
562 563
}

Robert Schmidt's avatar
Robert Schmidt committed
564 565
uint8_t flexran_get_deltaPUCCH_Shift(mid_t mod_id, uint8_t cc_id)
{
566 567
  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
568 569
}

Robert Schmidt's avatar
Robert Schmidt committed
570 571
uint8_t flexran_get_prach_ConfigIndex(mid_t mod_id, uint8_t cc_id)
{
572 573
  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
574 575
}

Robert Schmidt's avatar
Robert Schmidt committed
576 577
uint8_t flexran_get_prach_FreqOffset(mid_t mod_id, uint8_t cc_id)
{
578 579
  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
580 581
}

Robert Schmidt's avatar
Robert Schmidt committed
582 583
uint8_t flexran_get_maxHARQ_Msg3Tx(mid_t mod_id, uint8_t cc_id)
{
584 585
  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
586 587
}

Robert Schmidt's avatar
Robert Schmidt committed
588 589
lte_prefix_type_t flexran_get_ul_cyclic_prefix_length(mid_t mod_id, uint8_t cc_id)
{
590 591
  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
592 593
}

Robert Schmidt's avatar
Robert Schmidt committed
594 595
lte_prefix_type_t flexran_get_dl_cyclic_prefix_length(mid_t mod_id, uint8_t cc_id)
{
596 597
  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
598 599
}

Robert Schmidt's avatar
Robert Schmidt committed
600 601
uint16_t flexran_get_cell_id(mid_t mod_id, uint8_t cc_id)
{
602 603
  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
604 605
}

Robert Schmidt's avatar
Robert Schmidt committed
606 607
uint8_t flexran_get_srs_BandwidthConfig(mid_t mod_id, uint8_t cc_id)
{
608 609
  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
610 611
}

Robert Schmidt's avatar
Robert Schmidt committed
612 613
uint8_t flexran_get_srs_SubframeConfig(mid_t mod_id, uint8_t cc_id)
{
614 615
  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
616 617
}

Robert Schmidt's avatar
Robert Schmidt committed
618 619
uint8_t flexran_get_srs_MaxUpPts(mid_t mod_id, uint8_t cc_id)
{
620 621
  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
622 623
}

Robert Schmidt's avatar
Robert Schmidt committed
624 625
uint8_t flexran_get_N_RB_DL(mid_t mod_id, uint8_t cc_id)
{
626 627
  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
628 629
}

Robert Schmidt's avatar
Robert Schmidt committed
630 631
uint8_t flexran_get_N_RB_UL(mid_t mod_id, uint8_t cc_id)
{
632 633
  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
634 635
}

Robert Schmidt's avatar
Robert Schmidt committed
636 637
uint8_t flexran_get_N_RBG(mid_t mod_id, uint8_t cc_id)
{
638 639
  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
640 641
}

Robert Schmidt's avatar
Robert Schmidt committed
642 643
uint8_t flexran_get_subframe_assignment(mid_t mod_id, uint8_t cc_id)
{
644 645
  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
646 647
}

Robert Schmidt's avatar
Robert Schmidt committed
648 649
uint8_t flexran_get_special_subframe_assignment(mid_t mod_id, uint8_t cc_id)
{
650 651
  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
652 653
}

Robert Schmidt's avatar
Robert Schmidt committed
654 655
long flexran_get_ra_ResponseWindowSize(mid_t mod_id, uint8_t cc_id)
{
656 657
  if (!rrc_is_present(mod_id)) return 0;
  return RC.rrc[mod_id]->configuration.rach_raResponseWindowSize[cc_id];
shahab's avatar
shahab committed
658 659
}

Robert Schmidt's avatar
Robert Schmidt committed
660 661
long flexran_get_mac_ContentionResolutionTimer(mid_t mod_id, uint8_t cc_id)
{
662 663
  if (!rrc_is_present(mod_id)) return 0;
  return RC.rrc[mod_id]->configuration.rach_macContentionResolutionTimer[cc_id];
shahab's avatar
shahab committed
664 665
}

Robert Schmidt's avatar
Robert Schmidt committed
666 667
Protocol__FlexDuplexMode flexran_get_duplex_mode(mid_t mod_id, uint8_t cc_id)
{
668 669
  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
670 671 672 673 674 675 676
  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
677 678
}

Robert Schmidt's avatar
Robert Schmidt committed
679 680
long flexran_get_si_window_length(mid_t mod_id, uint8_t cc_id)
{
681 682
  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
683 684
}

Robert Schmidt's avatar
Robert Schmidt committed
685 686
uint8_t flexran_get_sib1_length(mid_t mod_id, uint8_t cc_id)
{
687 688
  if (!rrc_is_present(mod_id)) return 0;
  return RC.rrc[mod_id]->carrier[cc_id].sizeof_SIB1;
shahab's avatar
shahab committed
689 690
}

691 692
uint8_t flexran_get_num_pdcch_symb(mid_t mod_id, uint8_t cc_id)
{
693 694
  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
695 696 697 698 699 700 701 702 703 704 705
}



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


Robert Schmidt's avatar
Robert Schmidt committed
706 707
TimeAlignmentTimer_t flexran_get_time_alignment_timer(mid_t mod_id, mid_t ue_id)
{
708
  if (!rrc_is_present(mod_id)) return -1;
709

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

Robert Schmidt's avatar
Robert Schmidt committed
713 714 715
  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
716 717
}

Robert Schmidt's avatar
Robert Schmidt committed
718 719
Protocol__FlexMeasGapConfigPattern flexran_get_meas_gap_config(mid_t mod_id, mid_t ue_id)
{
720
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
721

Robert Schmidt's avatar
Robert Schmidt committed
722
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
723
  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
724 725 726 727 728 729 730 731 732 733 734

  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
735 736 737
  }
}

shahab's avatar
shahab committed
738

Robert Schmidt's avatar
Robert Schmidt committed
739 740
long flexran_get_meas_gap_config_offset(mid_t mod_id, mid_t ue_id)
{
741
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
742

Robert Schmidt's avatar
Robert Schmidt committed
743
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
744
  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
745 746 747 748 749 750 751 752 753 754 755 756 757

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

759
uint8_t flexran_get_rrc_status(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
760
{
761
  if (!rrc_is_present(mod_id)) return 0;
shahab's avatar
shahab committed
762

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

Robert Schmidt's avatar
Robert Schmidt committed
766 767
  if (!ue_context_p) return RRC_INACTIVE;
  return ue_context_p->ue_context.Status;
shahab's avatar
shahab committed
768 769
}

Robert Schmidt's avatar
Robert Schmidt committed
770 771
uint64_t flexran_get_ue_aggregated_max_bitrate_dl(mid_t mod_id, mid_t ue_id)
{
772 773
  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
774 775
}

Robert Schmidt's avatar
Robert Schmidt committed
776 777
uint64_t flexran_get_ue_aggregated_max_bitrate_ul(mid_t mod_id, mid_t ue_id)
{
778 779
  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
780 781
}

782 783 784 785 786 787 788 789 790 791 792 793 794
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
795 796 797
  return 0;
}

798
int flexran_get_intra_sf_hopping(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
799
{
800 801 802 803 804 805 806 807 808 809 810 811 812 813
  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
814 815
}

816
int flexran_get_type2_sb_1(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
817
{
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
  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
833 834
}

835
long flexran_get_ue_category(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
836
{
837 838 839 840 841 842 843 844
  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
845 846
}

847
int flexran_get_res_alloc_type1(mid_t mod_id, mid_t ue_id)
Robert Schmidt's avatar
Robert Schmidt committed
848
{
849 850 851 852 853 854 855 856 857 858 859 860 861 862
  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
863 864
}

Robert Schmidt's avatar
Robert Schmidt committed
865 866
long flexran_get_ue_transmission_mode(mid_t mod_id, mid_t ue_id)
{
867
  if (!rrc_is_present(mod_id)) return -1;
shahab's avatar
shahab committed
868

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

Robert Schmidt's avatar
Robert Schmidt committed
872 873 874 875
  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
876 877
}

Robert Schmidt's avatar
Robert Schmidt committed
878 879
BOOLEAN_t flexran_get_tti_bundling(mid_t mod_id, mid_t ue_id)
{
880
  if (!rrc_is_present(mod_id)) return -1;
881

Robert Schmidt's avatar
Robert Schmidt committed
882
  rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
883
  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
884 885 886 887
  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
888 889
}

Robert Schmidt's avatar
Robert Schmidt committed
890 891