eNB_scheduler_ulsch.c 71.6 KB
Newer Older
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
Cedric Roux's avatar
Cedric Roux committed
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * 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
 */
nikaeinn's avatar
nikaeinn committed
21
22
23

/*! \file eNB_scheduler_ulsch.c
 * \brief eNB procedures for the ULSCH transport channel
24
25
26
 * \author Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
 * \email: navid.nikaein@eurecom.fr
nikaeinn's avatar
nikaeinn committed
27
 * \version 1.0
28
29
30
31
 * @ingroup _mac

 */

32
33
/* indented with: indent -kr eNB_scheduler_RA.c */

34
35


36
37
38
#include "LAYER2/MAC/mac.h"
#include "LAYER2/MAC/mac_proto.h"
#include "LAYER2/MAC/mac_extern.h"
39
40
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
41
42
43
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"
Cedric Roux's avatar
Cedric Roux committed
44
#include "PHY/LTE_TRANSPORT/transport_common_proto.h"
45

46
#include "RRC/LTE/rrc_extern.h"
47
48
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

49
#include "assertions.h"
50
51
52
53
//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"

#if defined(ENABLE_ITTI)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
54
  #include "intertask_interface.h"
55
56
#endif

57
58
59
60
61
#include "ENB_APP/flexran_agent_defs.h"
#include "flexran_agent_ran_api.h"
#include "header.pb-c.h"
#include "flexran.pb-c.h"
#include "flexran_agent_mac.h"
62
#include <dlfcn.h>
63

Cedric Roux's avatar
Cedric Roux committed
64
65
#include "T.h"

66
67
68
#include "common/ran_context.h"
extern RAN_CONTEXT_t RC;

69
#define ENABLE_MAC_PAYLOAD_DEBUG
70
71
#define DEBUG_eNB_SCHEDULER 1

72
73
74
75
76
77
extern int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req);
extern void add_subframe(uint16_t *frameP, uint16_t *subframeP, int offset);
extern uint16_t sfnsf_add_subframe(uint16_t frameP, uint16_t subframeP, int offset);
extern int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req);
extern uint8_t nfapi_mode;

78
// This table holds the allowable PRB sizes for ULSCH transmissions
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
79
80
81
82
uint8_t rb_table[34] = {
  1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32,
  36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100
};
83

Xu Bo's avatar
Xu Bo committed
84
extern mui_t    rrc_eNB_mui;
85

86
87
88
89
90
91
void
rx_sdu(const module_id_t enb_mod_idP,
       const int CC_idP,
       const frame_t frameP,
       const sub_frame_t subframeP,
       const rnti_t rntiP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
92
       uint8_t *sduP,
93
       const uint16_t sdu_lenP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
94
       const uint16_t timing_advance, const uint8_t ul_cqi) {
knopp's avatar
knopp committed
95
96
97
98
99
100
101
102
103
104
  int current_rnti = rntiP;
  unsigned char rx_ces[MAX_NUM_CE], num_ce, num_sdu, i, *payload_ptr;
  unsigned char rx_lcids[NB_RB_MAX];
  unsigned short rx_lengths[NB_RB_MAX];
  int UE_id = find_UE_id(enb_mod_idP, current_rnti);
  int RA_id;
  int ii, j;
  eNB_MAC_INST *mac = RC.mac[enb_mod_idP];
  int harq_pid =
    subframe2harqpid(&mac->common_channels[CC_idP], frameP, subframeP);
105
  int lcgid_updated[4] = {0, 0, 0, 0};
knopp's avatar
knopp committed
106
107
108
109
110
  UE_list_t *UE_list = &mac->UE_list;
  int crnti_rx = 0;
  RA_t *ra =
    (RA_t *) & RC.mac[enb_mod_idP]->common_channels[CC_idP].ra[0];
  int first_rb = 0;
111
  rrc_eNB_ue_context_t *ue_contextP = NULL;
knopp's avatar
knopp committed
112
113
  start_meas(&mac->rx_ulsch_sdu);

knopp's avatar
knopp committed
114
  if ((UE_id > MAX_MOBILES_PER_ENB) || (UE_id == -1))
knopp's avatar
knopp committed
115
116
117
118
119
    for (ii = 0; ii < NB_RB_MAX; ii++) {
      rx_lengths[ii] = 0;
    }

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
120
121
  (VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 1);

knopp's avatar
knopp committed
122
  if (opt_enabled == 1) {
Thomas Laurent's avatar
fix 344    
Thomas Laurent committed
123
    trace_pdu(DIRECTION_UPLINK, sduP, sdu_lenP, 0, WS_C_RNTI, current_rnti, frameP, subframeP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
124
              0, 0);
knopp's avatar
knopp committed
125
    LOG_D(OPT, "[eNB %d][ULSCH] Frame %d  rnti %x  with size %d\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
126
          enb_mod_idP, frameP, current_rnti, sdu_lenP);
knopp's avatar
knopp committed
127
128
129
  }

  if (UE_id != -1) {
130
    LOG_D(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
131
132
133
134
          "[eNB %d][PUSCH %d] CC_id %d %d.%d Received ULSCH sdu round %d from PHY (rnti %x, UE_id %d) ul_cqi %d\n",
          enb_mod_idP, harq_pid, CC_idP,frameP,subframeP,
          UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
          current_rnti, UE_id, ul_cqi);
knopp's avatar
knopp committed
135
    AssertFatal(UE_list->UE_sched_ctrl[UE_id].
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
136
137
                round_UL[CC_idP][harq_pid] < 8, "round >= 8\n");

knopp's avatar
knopp committed
138
139
140
141
142
143
144
145
146
    if (sduP != NULL) {
      UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0;
      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
      UE_list->UE_sched_ctrl[UE_id].ul_scheduled &= (~(1 << harq_pid));
      /* Update with smoothing: 3/4 of old value and 1/4 of new.
       * This is the logic that was done in the function
       * lte_est_timing_advance_pusch, maybe it's not necessary?
       * maybe it's even not correct at all?
       */
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
147
      UE_list->UE_sched_ctrl[UE_id].ta_update = (UE_list->UE_sched_ctrl[UE_id].ta_update * 3 + timing_advance) / 4;
knopp's avatar
knopp committed
148
149
150
151
152
      UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi;
      UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors = 0;
      first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid];

      if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
153
154
155
156
        UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
        mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP,
                               subframeP, UE_RNTI(enb_mod_idP,
                                   UE_id));
knopp's avatar
knopp committed
157
      }
158
159
160

      /* update scheduled bytes */
      UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes -= UE_list->UE_template[CC_idP][UE_id].TBS_UL[harq_pid];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
161

162
163
      if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0)
        UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes = 0;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
164
    } else {    // we've got an error
knopp's avatar
knopp committed
165
      LOG_I(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
166
167
168
169
            "[eNB %d][PUSCH %d] CC_id %d %d.%d ULSCH in error in round %d, ul_cqi %d\n",
            enb_mod_idP, harq_pid, CC_idP,frameP,subframeP,
            UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
            ul_cqi);
knopp's avatar
knopp committed
170

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
171
      if(ul_cqi>200) { // too high energy pattern
172
173
174
        UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi;
      }

knopp's avatar
knopp committed
175
176
      //      AssertFatal(1==0,"ulsch in error\n");
      if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] == 3) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
177
178
179
180
181
        UE_list->UE_sched_ctrl[UE_id].ul_scheduled &= (~(1 << harq_pid));
        UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0;

        if (UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors++ == 10)
          UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1;
182
183
184

        /* update scheduled bytes */
        UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes -= UE_list->UE_template[CC_idP][UE_id].TBS_UL[harq_pid];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
185

186
187
        if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0)
          UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes = 0;
188
189

        if (find_RA_id(enb_mod_idP, CC_idP, current_rnti) != -1)
190
          cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
knopp's avatar
knopp committed
191
      } else
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
192
        UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid]++;
193
194
195
196

      first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid];
      // Program NACK for PHICH
      LOG_D(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
197
198
            "Programming PHICH NACK for rnti %x harq_pid %d (first_rb %d)\n",
            current_rnti, harq_pid, first_rb);
Wu Jing's avatar
Wu Jing committed
199
      nfapi_hi_dci0_request_t *hi_dci0_req;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
200
      uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP);
Wu Jing's avatar
Wu Jing committed
201
      hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10];
202
203
204
205
206
207
208
209
210
211
212
213
214
      nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body;
      nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu =
        &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi];
      memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t));
      hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE;
      hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu);
      hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG;
      hi_dci0_pdu->hi_pdu.hi_pdu_rel8.resource_block_start = first_rb;
      hi_dci0_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = 0;
      hi_dci0_pdu->hi_pdu.hi_pdu_rel8.hi_value = 0;
      hi_dci0_req_body->number_of_hi++;
      hi_dci0_req_body->sfnsf = sfnsf_add_subframe(frameP,subframeP, 0);
      hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
215
      hi_dci0_req->sfn_sf = sfnsf_add_subframe(frameP,subframeP, sf_ahead_dl);
216
      hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;
knopp's avatar
knopp committed
217
      return;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
218
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
219
  } else if ((RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti)) != -1) { // Check if this is an RA process for the rnti
knopp's avatar
knopp committed
220
    AssertFatal(mac->common_channels[CC_idP].
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
221
222
223
224
225
226
                radioResourceConfigCommon->rach_ConfigCommon.
                maxHARQ_Msg3Tx > 1,
                "maxHARQ %d should be greater than 1\n",
                (int) mac->common_channels[CC_idP].
                radioResourceConfigCommon->rach_ConfigCommon.
                maxHARQ_Msg3Tx);
knopp's avatar
knopp committed
227
    LOG_D(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
228
229
230
          "[eNB %d][PUSCH %d] CC_id %d [RAPROC Msg3] Received ULSCH sdu round %d from PHY (rnti %x, RA_id %d) ul_cqi %d\n",
          enb_mod_idP, harq_pid, CC_idP, ra[RA_id].msg3_round,
          current_rnti, RA_id, ul_cqi);
knopp's avatar
knopp committed
231
232
    first_rb = ra->msg3_first_rb;

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
233
    if (sduP == NULL) { // we've got an error on Msg3
knopp's avatar
knopp committed
234
      LOG_D(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
235
236
237
238
239
240
            "[eNB %d] CC_id %d, RA %d ULSCH in error in round %d/%d\n",
            enb_mod_idP, CC_idP, RA_id,
            ra[RA_id].msg3_round,
            (int) mac->common_channels[CC_idP].
            radioResourceConfigCommon->rach_ConfigCommon.
            maxHARQ_Msg3Tx);
knopp's avatar
knopp committed
241

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
242
243
244
245
246
247
      if (ra[RA_id].msg3_round >= mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx - 1) {
        cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
      } else {
        first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid];
        ra[RA_id].msg3_round++;
        // prepare handling of retransmission
248
        get_Msg3allocret(&mac->common_channels[CC_idP],
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
249
250
251
                         ra[RA_id].Msg3_subframe, ra[RA_id].Msg3_frame,
                         &ra[RA_id].Msg3_frame, &ra[RA_id].Msg3_subframe);
        add_msg3(enb_mod_idP, CC_idP, &ra[RA_id], frameP, subframeP);
knopp's avatar
knopp committed
252
      }
253
254

      /* TODO: program NACK for PHICH? */
knopp's avatar
knopp committed
255
256
257
258
      return;
    }
  } else {
    LOG_W(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
259
260
          "Cannot find UE or RA corresponding to ULSCH rnti %x, dropping it\n",
          current_rnti);
knopp's avatar
knopp committed
261
262
    return;
  }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
263

knopp's avatar
knopp committed
264
265
  payload_ptr = parse_ulsch_header(sduP, &num_ce, &num_sdu, rx_ces, rx_lcids, rx_lengths, sdu_lenP);

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
266
267
268
269
  if(payload_ptr == NULL) {
    LOG_E(MAC,"[eNB %d][PUSCH %d] CC_id %d ulsch header unknown lcid(rnti %x, UE_id %d)\n",
          enb_mod_idP, harq_pid, CC_idP,current_rnti, UE_id);
    return;
270
271
  }

knopp's avatar
knopp committed
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
  T(T_ENB_MAC_UE_UL_PDU, T_INT(enb_mod_idP), T_INT(CC_idP),
    T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
    T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu));
  T(T_ENB_MAC_UE_UL_PDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP),
    T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
    T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu),
    T_BUFFER(sduP, sdu_lenP));
  mac->eNB_stats[CC_idP].ulsch_bytes_rx = sdu_lenP;
  mac->eNB_stats[CC_idP].total_ulsch_bytes_rx += sdu_lenP;
  mac->eNB_stats[CC_idP].total_ulsch_pdus_rx += 1;
  UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0;

  // control element
  for (i = 0; i < num_ce; i++) {
    T(T_ENB_MAC_UE_UL_CE, T_INT(enb_mod_idP), T_INT(CC_idP),
      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
      T_INT(rx_ces[i]));
289

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
290
291
292
293
294
    switch (rx_ces[i]) {  // implement and process BSR + CRNTI +
      case POWER_HEADROOM:
        if (UE_id != -1) {
          UE_list->UE_template[CC_idP][UE_id].phr_info =
            (payload_ptr[0] & 0x3f) - PHR_MAPPING_OFFSET + (int8_t)(hundred_times_log10_NPRB[UE_list->UE_template[CC_idP][UE_id].nb_rb_ul[harq_pid]-1]/100);
knopp's avatar
knopp committed
295

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
          if(UE_list->UE_template[CC_idP][UE_id].phr_info > 40)
            UE_list->UE_template[CC_idP][UE_id].phr_info = 40;

          LOG_D(MAC,
                "[eNB %d] CC_id %d MAC CE_LCID %d : Received PHR PH = %d (db)\n",
                enb_mod_idP, CC_idP, rx_ces[i],
                UE_list->UE_template[CC_idP][UE_id].phr_info);
          UE_list->UE_template[CC_idP][UE_id].phr_info_configured =
            1;
          UE_list->UE_sched_ctrl[UE_id].phr_received = 1;
        }

        payload_ptr += sizeof(POWER_HEADROOM_CMD);
        break;

      case CRNTI: {
        int old_rnti =
          (((uint16_t) payload_ptr[0]) << 8) + payload_ptr[1];
        int old_UE_id = find_UE_id(enb_mod_idP, old_rnti);
        LOG_D(MAC,
              "[eNB %d] Frame %d, Subframe %d CC_id %d MAC CE_LCID %d (ce %d/%d): CRNTI %x (UE_id %d) in Msg3\n",
              enb_mod_idP, frameP, subframeP, CC_idP, rx_ces[i], i,
              num_ce, old_rnti, old_UE_id);

        /* receiving CRNTI means that the current rnti has to go away */
        //cancel_ra_proc(enb_mod_idP, CC_idP, frameP,
        //         current_rnti);
        if (old_UE_id != -1) {
          /* TODO: if the UE did random access (followed by a MAC uplink with
           * CRNTI) because none of its scheduling request was granted, then
           * according to 36.321 5.4.4 the UE's MAC will notify RRC to release
           * PUCCH/SRS. According to 36.331 5.3.13 the UE will then apply
           * default configuration for CQI reporting and scheduling requests,
           * which basically means that the CQI requests won't work anymore and
           * that the UE won't do any scheduling request anymore as long as the
           * eNB doesn't reconfigure the UE.
           * We have to take care of this. As the code is, nothing is done and
           * the UE state in the eNB is wrong.
           */
Xu Bo's avatar
Xu Bo committed
335
336
          for (ii = 0; ii < NB_RA_PROC_MAX; ii++) {
            ra = &mac->common_channels[CC_idP].ra[ii];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
337

Xu Bo's avatar
Xu Bo committed
338
            if ((ra->rnti == current_rnti) && (ra->state != IDLE)) {
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
              mac_rrc_data_ind(enb_mod_idP,
                               CC_idP,
                               frameP, subframeP,
                               old_rnti,
                               DCCH,
                               (uint8_t *) payload_ptr,
                               rx_lengths[i],
                               0);
              // prepare transmission of Msg4(RRCConnectionReconfiguration)
              ra->state = MSGCRNTI;
              LOG_I(MAC,
                    "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) RRCConnectionReconfiguration(Msg4)\n",
                    enb_mod_idP, frameP, subframeP, CC_idP, old_rnti, old_UE_id);
              UE_id = old_UE_id;
              current_rnti = old_rnti;
              ra->rnti = old_rnti;
              ra->crnti_rrc_mui = rrc_eNB_mui-1;
              ra->crnti_harq_pid = -1;
              //clear timer
              UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
              UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0;
              UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
361

362
363
364
365
              if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) {
                UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
                mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP,
                                       subframeP, old_rnti);
Xu Bo's avatar
Xu Bo committed
366
              }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
367

368
369
370
371
              UE_list->UE_template[CC_idP][UE_id].ul_SR = 1;
              UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 1;
              break;
            }
Xu Bo's avatar
Xu Bo committed
372
          }
373
        } else {
Xu Bo's avatar
Xu Bo committed
374
375
          cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti);
        }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
376
377
378
379

        crnti_rx = 1;
        payload_ptr += 2;
        break;
knopp's avatar
knopp committed
380
381
      }

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
382
383
384
385
386
387
388
389
      case TRUNCATED_BSR:
      case SHORT_BSR: {
        uint8_t lcgid;
        lcgid = (payload_ptr[0] >> 6);
        LOG_D(MAC,
              "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n",
              enb_mod_idP, CC_idP, rx_ces[i], lcgid,
              payload_ptr[0] & 0x3f);
390

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
391
392
393
394
395
        if (crnti_rx == 1)
          LOG_D(MAC,
                "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n",
                enb_mod_idP, CC_idP, rx_ces[i], lcgid,
                payload_ptr[0] & 0x3f);
396

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
397
398
399
        if (UE_id != -1) {
          int bsr = payload_ptr[0] & 0x3f;
          lcgid_updated[lcgid] = 1;
400
401
402
          // update buffer info
          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid] = BSR_TABLE[bsr];
          UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
403
404
405
406
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] +
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] +
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] +
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3];
407
          //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
408
          RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr[UE_id][(frameP * 10) + subframeP] = (payload_ptr[0] & 0x3f);
409

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
          if (UE_id == UE_list->head)
            VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,
                                                    RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr
                                                    [UE_id][(frameP * 10) + subframeP]);

          if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = frameP;
          }

          if (mac_eNB_get_rrc_status(enb_mod_idP,UE_RNTI(enb_mod_idP, UE_id)) < RRC_CONNECTED)
            LOG_D(MAC,
                  "[eNB %d] CC_id %d MAC CE_LCID %d : estimated_ul_buffer = %d (lcg increment %d)\n",
                  enb_mod_idP, CC_idP, rx_ces[i],
                  UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer,
                  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid]);
        } else {
        }

        payload_ptr += 1; //sizeof(SHORT_BSR); // fixme
knopp's avatar
knopp committed
429
430
431
      }
      break;

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
      case LONG_BSR:
        if (UE_id != -1) {
          int bsr0 = (payload_ptr[0] & 0xFC) >> 2;
          int bsr1 = ((payload_ptr[0] & 0x03) << 4) | ((payload_ptr[1] & 0xF0) >> 4);
          int bsr2 = ((payload_ptr[1] & 0x0F) << 2) | ((payload_ptr[2] & 0xC0) >> 6);
          int bsr3 = payload_ptr[2] & 0x3F;
          lcgid_updated[LCGID0] = 1;
          lcgid_updated[LCGID1] = 1;
          lcgid_updated[LCGID2] = 1;
          lcgid_updated[LCGID3] = 1;
          // update buffer info
          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] = BSR_TABLE[bsr0];
          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] = BSR_TABLE[bsr1];
          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] = BSR_TABLE[bsr2];
          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3] = BSR_TABLE[bsr3];
          UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
Niccolò Iardella's avatar
Niccolò Iardella committed
448
449
450
451
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] +
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] +
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] +
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
452
          //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
453
454
          LOG_D(MAC,
                "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = "
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
455
456
                "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP, CC_idP,
                rx_ces[i],
457
458
459
460
461
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0],
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1],
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2],
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]);

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
          if (crnti_rx == 1)
            LOG_D(MAC,
                  "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = "
                  "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP,
                  CC_idP, rx_ces[i],
                  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0],
                  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1],
                  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2],
                  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]);

          if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] = 0;
          } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] = frameP;
          }
knopp's avatar
knopp committed
477

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
478
479
480
481
482
          if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] = 0;
          } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] = frameP;
          }
knopp's avatar
knopp committed
483

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
          if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] = 0;
          } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] = frameP;
          }

          if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] = 0;
          } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] == 0) {
            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] = frameP;
          }
        }

        payload_ptr += 3; ////sizeof(LONG_BSR);
        break;

      default:
        LOG_E(MAC,
              "[eNB %d] CC_id %d Received unknown MAC header (0x%02x)\n",
              enb_mod_idP, CC_idP, rx_ces[i]);
        break;
505
    }
knopp's avatar
knopp committed
506
  }
507

knopp's avatar
knopp committed
508
509
  for (i = 0; i < num_sdu; i++) {
    LOG_D(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
510
          i, rx_lcids[i], rx_lengths[i]);
knopp's avatar
knopp committed
511
    T(T_ENB_MAC_UE_UL_SDU, T_INT(enb_mod_idP), T_INT(CC_idP),
512
      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
knopp's avatar
knopp committed
513
514
      T_INT(rx_lcids[i]), T_INT(rx_lengths[i]));
    T(T_ENB_MAC_UE_UL_SDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP),
515
      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
knopp's avatar
knopp committed
516
      T_INT(rx_lcids[i]), T_INT(rx_lengths[i]), T_BUFFER(payload_ptr,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
517
518
          rx_lengths
          [i]));
knopp's avatar
knopp committed
519
520

    switch (rx_lcids[i]) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
      case CCCH:
        if (rx_lengths[i] > CCCH_PAYLOAD_SIZE_MAX) {
          LOG_E(MAC,
                "[eNB %d/%d] frame %d received CCCH of size %d (too big, maximum allowed is %d, sdu_len %d), dropping packet\n",
                enb_mod_idP, CC_idP, frameP, rx_lengths[i],
                CCCH_PAYLOAD_SIZE_MAX, sdu_lenP);
          break;
        }

        LOG_D(MAC,
              "[eNB %d][RAPROC] CC_id %d Frame %d, Received CCCH:  %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n",
              enb_mod_idP, CC_idP, frameP, payload_ptr[0],
              payload_ptr[1], payload_ptr[2], payload_ptr[3],
              payload_ptr[4], payload_ptr[5], current_rnti);
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 1);
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 0);

        for (ii = 0; ii < NB_RA_PROC_MAX; ii++) {
          RA_t *ra = &mac->common_channels[CC_idP].ra[ii];
          LOG_D(MAC,
                "[mac %d][RAPROC] CC_id %d Checking proc %d : rnti (%x, %x), state %d\n",
                enb_mod_idP, CC_idP, ii, ra->rnti,
                current_rnti, ra->state);

          if ((ra->rnti == current_rnti) && (ra->state != IDLE)) {
            //payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len);
            if (UE_id < 0) {
              memcpy(&ra->cont_res_id[0], payload_ptr, 6);
              LOG_D(MAC,
                    "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3: length %d, offset %ld\n",
                    enb_mod_idP, CC_idP, frameP, rx_lengths[i],
                    payload_ptr - sduP);

              if ((UE_id = add_new_ue(enb_mod_idP, CC_idP,
                                      mac->common_channels[CC_idP].
                                      ra[ii].rnti, harq_pid
557
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
558
559
560
                                      ,
                                      mac->common_channels[CC_idP].
                                      ra[ii].rach_resource_type
561
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
                                     )) == -1) {
                LOG_E(MAC,"[MAC][eNB] Max user count reached\n");
                cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti);
                break;
                // kill RA procedure
              } else
                LOG_D(MAC,
                      "[eNB %d][RAPROC] CC_id %d Frame %d Added user with rnti %x => UE %d\n",
                      enb_mod_idP, CC_idP, frameP, ra->rnti,
                      UE_id);
            } else {
              LOG_D(MAC,
                    "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3 from already registered UE %d: length %d, offset %ld\n",
                    enb_mod_idP, CC_idP, frameP, UE_id,
                    rx_lengths[i], payload_ptr - sduP);
              // kill RA procedure
578
            }
knopp's avatar
knopp committed
579

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
580
581
582
583
584
585
586
587
588
589
590
591
            mac_rrc_data_ind(enb_mod_idP,
                             CC_idP,
                             frameP, subframeP,
                             current_rnti,
                             CCCH,
                             (uint8_t *) payload_ptr,
                             rx_lengths[i],
                             0);

            if (num_ce > 0) { // handle msg3 which is not RRCConnectionRequest
              //  process_ra_message(msg3,num_ce,rx_lcids,rx_ces);
            }
592

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
593
594
            // prepare transmission of Msg4
            ra->state = MSG4;
595

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
596
597
598
599
600
601
            if(mac->common_channels[CC_idP].tdd_Config!=NULL) {
              switch(mac->common_channels[CC_idP].tdd_Config->subframeAssignment) {
                case 1:
                  ra->Msg4_frame = frameP + ((subframeP > 2) ? 1 : 0);
                  ra->Msg4_subframe = (subframeP + 7) % 10;
                  break;
602

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
603
604
605
606
607
608
609
610
611
612
                default:
                  printf("%s:%d: TODO\n", __FILE__, __LINE__);
                  abort();
                  // TODO need to be complete for other tdd configs.
              }
            } else {
              // Program Msg4 PDCCH+DLSCH/MPDCCH transmission 4 subframes from now, // Check if this is ok for BL/CE, or if the rule is different
              ra->Msg4_frame = frameP + ((subframeP > 5) ? 1 : 0);
              ra->Msg4_subframe = (subframeP + 4) % 10;
            }
613

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
614
615
616
            UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
          }   // if process is active
        }     // loop on RA processes
617

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
618
        break;
gauthier's avatar
   
gauthier committed
619

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
620
621
622
      case DCCH:
      case DCCH1:
        //      if(eNB_mac_inst[module_idP][CC_idP].Dcch_lchan[UE_id].Active==1){
knopp's avatar
   
knopp committed
623
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
624
625
        LOG_T(MAC, "offset: %d\n",
              (unsigned char) ((unsigned char *) payload_ptr - sduP));
626

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
627
628
629
        for (j = 0; j < 32; j++) {
          LOG_T(MAC, "%x ", payload_ptr[j]);
        }
630

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
631
632
        LOG_T(MAC, "\n");
#endif
knopp's avatar
knopp committed
633

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
634
        if (UE_id != -1) {
635
          if (lcgid_updated[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] == 0) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
636
637
            // adjust buffer occupancy of the correponding logical channel group
            if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] >= rx_lengths[i])
638
              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] -= rx_lengths[i];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
639
640
            else
              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] = 0;
641
642

            UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
643
644
645
646
              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[0] +
              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[1] +
              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[2] +
              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[3];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
647
            //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
648
649
          }

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
650
651
652
653
654
655
656
657
          LOG_D(MAC,
                "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DCCH, received %d bytes form UE %d on LCID %d \n",
                enb_mod_idP, CC_idP, frameP, rx_lengths[i], UE_id,
                rx_lcids[i]);
          mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);  //(unsigned int*)crc_status);
          UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]] += 1;
          UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i];
        }
658

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
659
660
661
        /* UE_id != -1 */
        // }
        break;
662

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
663
664
665
666
667
668
      // all the DRBS
      case DTCH:
      default:
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
        LOG_T(MAC, "offset: %d\n",
              (unsigned char) ((unsigned char *) payload_ptr - sduP));
669

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
670
671
672
        for (j = 0; j < 32; j++) {
          LOG_T(MAC, "%x ", payload_ptr[j]);
        }
673

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
674
675
        LOG_T(MAC, "\n");
#endif
676

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
        if (rx_lcids[i] < NB_RB_MAX) {
          LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d\n",
                enb_mod_idP,
                CC_idP,
                frameP,
                rx_lengths[i],
                UE_id,
                rx_lcids[i]);

          if (UE_id != -1) {
            // adjust buffer occupancy of the correponding logical channel group
            LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d, removing from LCGID %ld, %d\n",
                  enb_mod_idP,
                  CC_idP,
                  frameP,
                  rx_lengths[i],
                  UE_id,
                  rx_lcids[i],
                  UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]],
                  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]]);

            if (lcgid_updated[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] == 0) {
              if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] >= rx_lengths[i]) {
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] -= rx_lengths[i];
              } else {
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] = 0;
              }
704

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
705
706
707
708
709
710
711
712
713
714
715
716
717
718
              UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[0] +
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[1] +
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[2] +
                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[3];
            }

            if ((rx_lengths[i] < SCH_PAYLOAD_SIZE_MAX) && (rx_lengths[i] > 0)) {  // MAX SIZE OF transport block
              mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);
              UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]] += 1;
              UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i];
              //clear uplane_inactivity_timer
              UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
              // reset RRC inactivity timer after uplane activity
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
719
720
721
722
723
724
725
726
727
              ue_contextP = rrc_eNB_get_ue_context(RC.rrc[enb_mod_idP], current_rnti);
              if (ue_contextP != NULL) {
                ue_contextP->ue_context.ue_rrc_inactivity_timer = 1;
              } else {
                LOG_E(MAC, "[eNB %d] CC_id %d Couldn't find the context associated to UE (RNTI %d) and reset RRC inactivity timer\n",
                      enb_mod_idP,
                      CC_idP,
                      current_rnti);
              }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
            } else {  /* rx_length[i] */
              UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1;
              LOG_E(MAC, "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ",
                    enb_mod_idP,
                    CC_idP,
                    frameP,
                    rx_lcids[i],
                    UE_id);
            }
          } else {  // end if (UE_id != -1)
            LOG_E(MAC,"[eNB %d] CC_id %d Frame %d : received unsupported or unknown LCID %d from UE %d ",
                  enb_mod_idP,
                  CC_idP,
                  frameP,
                  rx_lcids[i],
                  UE_id);
          }
        }

        break;
knopp's avatar
   
knopp committed
748
    }
Cedric Roux's avatar
Cedric Roux committed
749

knopp's avatar
knopp committed
750
751
752
753
754
    payload_ptr += rx_lengths[i];
  }

  // Program ACK for PHICH
  LOG_D(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
755
756
        "Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n",
        current_rnti, harq_pid, first_rb);
757
  nfapi_hi_dci0_request_t *hi_dci0_req;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
758
  uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP);
759
  hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10];
knopp's avatar
knopp committed
760
761
762
763
764
765
766
767
768
769
770
771
772
  nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body;
  nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu =
    &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi];
  memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t));
  hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE;
  hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu);
  hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG;
  hi_dci0_pdu->hi_pdu.hi_pdu_rel8.resource_block_start = first_rb;
  hi_dci0_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = 0;
  hi_dci0_pdu->hi_pdu.hi_pdu_rel8.hi_value = 1;
  hi_dci0_req_body->number_of_hi++;
  hi_dci0_req_body->sfnsf = sfnsf_add_subframe(frameP,subframeP, 0);
  hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
773
  hi_dci0_req->sfn_sf = sfnsf_add_subframe(frameP,subframeP, sf_ahead_dl);
knopp's avatar
knopp committed
774
775
776
777
778
779
  hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;

  /* NN--> FK: we could either check the payload, or use a phy helper to detect a false msg3 */
  if ((num_sdu == 0) && (num_ce == 0)) {
    if (UE_id != -1)
      UE_list->eNB_UE_stats[CC_idP][UE_id].total_num_errors_rx += 1;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
780

knopp's avatar
knopp committed
781
782
783
    /*
      if (msg3_flagP != NULL) {
      if( *msg3_flagP == 1 ) {
784
      LOG_I(MAC,"[eNB %d] CC_id %d frame %d : false msg3 detection: signal phy to canceling RA and remove the UE\n", enb_mod_idP, CC_idP, frameP);
knopp's avatar
knopp committed
785
786
787
788
789
790
791
792
      *msg3_flagP=0;
      }
      } */
  } else {
    if (UE_id != -1) {
      UE_list->eNB_UE_stats[CC_idP][UE_id].pdu_bytes_rx        = sdu_lenP;
      UE_list->eNB_UE_stats[CC_idP][UE_id].total_pdu_bytes_rx += sdu_lenP;
      UE_list->eNB_UE_stats[CC_idP][UE_id].total_num_pdus_rx  += 1;
roux's avatar
roux committed
793
    }
knopp's avatar
knopp committed
794
  }
795

knopp's avatar
knopp committed
796
797
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 0);
  stop_meas(&mac->rx_ulsch_sdu);
knopp's avatar
   
knopp committed
798
799
}

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
800
uint32_t bytes_to_bsr_index(int32_t nbytes) {
knopp's avatar
knopp committed
801
  uint32_t i = 0;
802

knopp's avatar
knopp committed
803
804
805
  if (nbytes < 0) {
    return (0);
  }
806

knopp's avatar
knopp committed
807
808
809
  while ((i < BSR_TABLE_SIZE) && (BSR_TABLE[i] <= nbytes)) {
    i++;
  }
810

knopp's avatar
knopp committed
811
  return (i - 1);
812
813
}

814
815
void
add_ue_ulsch_info(module_id_t module_idP, int CC_id, int UE_id,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
816
                  sub_frame_t subframeP, UE_ULSCH_STATUS status) {
knopp's avatar
knopp committed
817
818
819
820
  eNB_ulsch_info[module_idP][CC_id][UE_id].rnti     = UE_RNTI(module_idP, UE_id);
  eNB_ulsch_info[module_idP][CC_id][UE_id].subframe = subframeP;
  eNB_ulsch_info[module_idP][CC_id][UE_id].status   = status;
  eNB_ulsch_info[module_idP][CC_id][UE_id].serving_num++;
821
822
823
}

unsigned char *parse_ulsch_header(unsigned char *mac_header,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
824
825
826
827
828
829
                                  unsigned char *num_ce,
                                  unsigned char *num_sdu,
                                  unsigned char *rx_ces,
                                  unsigned char *rx_lcids,
                                  unsigned short *rx_lengths,
                                  unsigned short tb_length) {
knopp's avatar
knopp committed
830
  unsigned char not_done = 1, num_ces = 0, num_sdus =
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
831
                                          0, lcid, num_sdu_cnt;
knopp's avatar
knopp committed
832
833
  unsigned char *mac_header_ptr = mac_header;
  unsigned short length, ce_len = 0;
834

knopp's avatar
knopp committed
835
836
837
838
  while (not_done == 1) {
    if (((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E == 0) {
      not_done = 0;
    }
839

knopp's avatar
knopp committed
840
    lcid = ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->LCID;
841

knopp's avatar
knopp committed
842
    if (lcid < EXTENDED_POWER_HEADROOM) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
843
844
845
846
847
848
849
850
      if (not_done == 0) {  // last MAC SDU, length is implicit
        mac_header_ptr++;
        length = tb_length - (mac_header_ptr - mac_header) - ce_len;

        for (num_sdu_cnt = 0; num_sdu_cnt < num_sdus;
             num_sdu_cnt++) {
          length -= rx_lengths[num_sdu_cnt];
        }
knopp's avatar
knopp committed
851
      } else {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
852
853
854
855
856
857
858
859
860
861
        if (((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F == 0) {
          length = ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L;
          mac_header_ptr += 2;  //sizeof(SCH_SUBHEADER_SHORT);
        } else {  // F = 1
          length =
            ((((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB &
              0x7f) << 8) | (((SCH_SUBHEADER_LONG *)
                              mac_header_ptr)->L_LSB & 0xff);
          mac_header_ptr += 3;  //sizeof(SCH_SUBHEADER_LONG);
        }
knopp's avatar
knopp committed
862
863
864
      }

      LOG_D(MAC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
865
866
867
            "[eNB] sdu %d lcid %d tb_length %d length %d (offset now %ld)\n",
            num_sdus, lcid, tb_length, length,
            mac_header_ptr - mac_header);
knopp's avatar
knopp committed
868
869
870
      rx_lcids[num_sdus] = lcid;
      rx_lengths[num_sdus] = length;
      num_sdus++;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
871
    } else {    // This is a control element subheader POWER_HEADROOM, BSR and CRNTI
knopp's avatar
knopp committed
872
      if (lcid == SHORT_PADDING) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
873
        mac_header_ptr++;
knopp's avatar
knopp committed
874
      } else {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
        rx_ces[num_ces] = lcid;
        num_ces++;
        mac_header_ptr++;

        if (lcid == LONG_BSR) {
          ce_len += 3;
        } else if (lcid == CRNTI) {
          ce_len += 2;
        } else if ((lcid == POWER_HEADROOM)
                   || (lcid == TRUNCATED_BSR)
                   || (lcid == SHORT_BSR)) {
          ce_len++;
        } else {
          LOG_E(MAC, "unknown CE %d \n", lcid);
          //AssertFatal(1 == 0, "unknown CE");
890
          return NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
891
        }
knopp's avatar
knopp committed
892
      }
knopp's avatar
   
knopp committed
893
    }
knopp's avatar
knopp committed
894
  }
895

knopp's avatar
knopp committed
896
897
898
  *num_ce = num_ces;
  *num_sdu = num_sdus;
  return (mac_header_ptr);
899
900
}

901
902
903
904
905
/* This function is called by PHY layer when it schedules some
 * uplink for a random access message 3.
 * The MAC scheduler has to skip the RBs used by this message 3
 * (done below in schedule_ulsch).
 */
906
void
907
set_msg3_subframe(module_id_t mod_id,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
908
909
910
911
                  int CC_id,
                  int frame,
                  int subframe, int rnti, int Msg3_frame,
                  int Msg3_subframe) {
912
  eNB_MAC_INST *mac = RC.mac[mod_id];
knopp's avatar
knopp committed
913
  int i;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
914

knopp's avatar
knopp committed
915
916
  for (i = 0; i < NB_RA_PROC_MAX; i++) {
    if (mac->common_channels[CC_id].ra[i].state != IDLE &&
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
917
        mac->common_channels[CC_id].ra[i].rnti == rnti) {
knopp's avatar
knopp committed
918
      mac->common_channels[CC_id].ra[i].Msg3_subframe =
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
919
        Msg3_subframe;
knopp's avatar
knopp committed
920
      break;
921
    }
knopp's avatar
knopp committed
922
  }
923
}
924

925
926
void
schedule_ulsch(module_id_t module_idP, frame_t frameP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
927
               sub_frame_t subframeP) {
Niccolò Iardella's avatar
Niccolò Iardella committed
928
  uint16_t first_rb[NFAPI_CC_MAX], i;
knopp's avatar
knopp committed
929
930
  int CC_id;
  eNB_MAC_INST *mac = RC.mac[module_idP];
931
  slice_info_t *sli = &RC.mac[module_idP]->slice_info;
knopp's avatar
knopp committed
932
933
  COMMON_channels_t *cc;
  start_meas(&mac->schedule_ulsch);
934
  int sched_frame=frameP;
knopp's avatar
knopp committed
935
936
937
  int sched_subframe = (subframeP + 4) % 10;
  cc = &mac->common_channels[0];
  int tdd_sfa;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
938

knopp's avatar
knopp committed
939
940
941
  // for TDD: check subframes where we have to act and return if nothing should be done now
  if (cc->tdd_Config) {
    tdd_sfa = cc->tdd_Config->subframeAssignment;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
942

knopp's avatar
knopp committed
943
    switch (subframeP) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
      case 0:
        if ((tdd_sfa == 0) || (tdd_sfa == 3))
          sched_subframe = 4;
        else if (tdd_sfa == 6)
          sched_subframe = 7;
        else
          return;

        break;

      case 1:
        if ((tdd_sfa == 0) || (tdd_sfa == 1))
          sched_subframe = 7;
        else if (tdd_sfa == 6)
          sched_subframe = 8;
        else
          return;

        break;

      default:
965
        return;
knopp's avatar
knopp committed
966

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
967
      case 2:   // Don't schedule UL in subframe 2 for TDD
968
        return;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006

      case 3:
        if (tdd_sfa == 2)
          sched_subframe = 7;
        else
          return;

        break;

      case 4:
        if (tdd_sfa == 1)
          sched_subframe = 8;
        else
          return;

        break;

      case 5:
        if (tdd_sfa == 0)
          sched_subframe = 9;
        else if (tdd_sfa == 6)
          sched_subframe = 2;
        else
          return;

        break;

      case 6:
        if (tdd_sfa == 0 || tdd_sfa == 1)
          sched_subframe = 2;
        else if (tdd_sfa == 6)
          sched_subframe = 3;
        else
          return;

        break;

      case 7:
1007
        return;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025

      case 8:
        if ((tdd_sfa >= 2) && (tdd_sfa <= 5))
          sched_subframe = 2;
        else
          return;

        break;

      case 9:
        if ((tdd_sfa == 1) || (tdd_sfa == 3) || (tdd_sfa == 4))
          sched_subframe = 3;
        else if (tdd_sfa == 6)
          sched_subframe = 4;
        else
          return;

        break;
1026
    }
knopp's avatar
knopp committed
1027
  }
1028

1029
  if (sched_subframe < subframeP) sched_frame++;
1030

1031
  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
knopp's avatar
knopp committed
1032
1033
    //leave out first RB for PUCCH
    first_rb[CC_id] = 1;
gauthier's avatar
   
gauthier committed
1034

knopp's avatar
knopp committed
1035
1036
1037
1038
    // UE data info;
    // check which UE has data to transmit
    // function to decide the scheduling
    // e.g. scheduling_rslt = Greedy(granted_UEs, nb_RB)
gauthier's avatar
   
gauthier committed
1039

knopp's avatar
knopp committed
1040
1041
    // default function for default scheduling
    //
gauthier's avatar
   
gauthier committed
1042

knopp's avatar
knopp committed
1043
1044
1045
1046
    // output of scheduling, the UE numbers in RBs, where it is in the code???
    // check if RA (Msg3) is active in this subframeP, if so skip the PRBs used for Msg3
    // Msg3 is using 1 PRB so we need to increase first_rb accordingly
    // not sure about the break (can there be more than 1 active RA procedure?)
gauthier's avatar
   
gauthier committed
1047

knopp's avatar
knopp committed
1048
1049
    for (i = 0; i < NB_RA_PROC_MAX; i++) {
      if ((cc->ra[i].state == WAITMSG3) &&
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1050
          (cc->ra[i].Msg3_subframe == sched_subframe)) {
1051
1052
        if (first_rb[CC_id] < cc->ra[i].msg3_first_rb + cc->ra[i].msg3_nb_rb)
          first_rb[CC_id] = cc->ra[i].msg3_first_rb + cc->ra[i].msg3_nb_rb;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1053
1054
1055

        //    cc->ray[i].Msg3_subframe = -1;
        break;
knopp's avatar
knopp committed
1056
      }
knopp's avatar
   
knopp committed
1057
    }
knopp's avatar
knopp committed
1058
  }
1059

1060
  for (i = 0; i < sli->n_ul; i++) {
1061
    // Run each enabled slice-specific schedulers one by one
1062
    sli->ul[i].sched_cb(module_idP, i, frameP, subframeP, sched_subframe, first_rb);
1063
  }
gauthier's avatar
   
gauthier committed
1064

knopp's avatar
knopp committed
1065
  stop_meas(&mac->schedule_ulsch);
1066
1067
}

1068
1069
void
schedule_ulsch_rnti(module_id_t module_idP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1070
1071
1072
1073
                    int slice_idx,
                    frame_t frameP,
                    sub_frame_t subframeP,
                    unsigned char sched_subframeP, uint16_t *first_rb) {
knopp's avatar
knopp committed
1074
1075
1076
1077
1078
1079
1080
1081
  int UE_id;
  uint8_t aggregation = 2;
  rnti_t rnti = -1;
  uint8_t round = 0;
  uint8_t harq_pid = 0;
  uint8_t status = 0;
  uint8_t rb_table_index = -1;
  uint32_t cqi_req, cshift, ndi, tpc;
1082
  int32_t normalized_rx_power, target_rx_power;
knopp's avatar
knopp committed
1083
1084
1085
1086
1087
1088
1089
1090
  static int32_t tpc_accumulated = 0;
  int n;
  int CC_id = 0;
  int drop_ue = 0;
  int N_RB_UL;
  eNB_MAC_INST *mac = RC.mac[module_idP];
  COMMON_channels_t *cc = mac->common_channels;
  UE_list_t *UE_list = &mac->UE_list;
1091
  slice_info_t *sli = &RC.mac[module_idP]->slice_info;
knopp's avatar
knopp committed
1092
1093
1094
1095
  UE_TEMPLATE *UE_template;
  UE_sched_ctrl *UE_sched_ctrl;
  int sched_frame = frameP;
  int rvidx_tab[4] = { 0, 2, 3, 1 };
1096
1097
  uint16_t          ul_req_index;
  uint8_t           dlsch_flag;
Niccolò Iardella's avatar
Niccolò Iardella committed
1098
  int first_rb_slice[NFAPI_CC_MAX];
knopp's avatar
knopp committed
1099
1100

  if (sched_subframeP < subframeP)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1101
    sched_frame++;
knopp's avatar
knopp committed
1102

1103
  nfapi_hi_dci0_request_t        *hi_dci0_req = &mac->HI_DCI0_req[CC_id][subframeP];
knopp's avatar
knopp committed
1104
1105
1106
1107
  nfapi_hi_dci0_request_body_t   *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body;
  nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu;
  nfapi_ul_config_request_t *ul_req_tmp            = &mac->UL_req_tmp[CC_id][sched_subframeP];
  nfapi_ul_config_request_body_t *ul_req_tmp_body  = &ul_req_tmp->ul_config_request_body;
1108
  nfapi_ul_config_ulsch_harq_information *ulsch_harq_information;
Niccolò Iardella's avatar
Niccolò Iardella committed
1109

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1110
  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; ++CC_id) {
Niccolò Iardella's avatar
Niccolò Iardella committed
1111
    N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1112
1113
    UE_list->first_rb_offset[CC_id][slice_idx] = cmin(N_RB_UL, sli->ul[slice_idx].first_rb);
  }
Niccolò Iardella's avatar
Niccolò Iardella committed
1114

knopp's avatar
knopp committed
1115
  //LOG_D(MAC, "entering ulsch preprocesor\n");
1116
  ulsch_scheduler_pre_processor(module_idP, slice_idx, frameP, subframeP, sched_subframeP, first_rb);
knopp's avatar
knopp committed
1117

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1118
  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; ++CC_id) {
1119
    first_rb_slice[CC_id] = first_rb[CC_id] + UE_list->first_rb_offset[CC_id][slice_idx];
Niccolò Iardella's avatar
Niccolò Iardella committed
1120
  }
knopp's avatar
knopp committed
1121

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1122
  //LOG_D(MAC, "exiting ulsch preprocesor\n");
knopp's avatar
knopp committed
1123
1124
1125
1126
1127
  hi_dci0_req->sfn_sf = (frameP << 4) + subframeP;

  // loop over all active UEs
  for (UE_id = UE_list->head_ul; UE_id >= 0;
       UE_id = UE_list->next_ul[UE_id]) {
1128
    if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1129
      continue;
1130

knopp's avatar
knopp committed
1131
1132
    // don't schedule if Msg4 is not received yet
    if (UE_list->UE_template[UE_PCCID(module_idP, UE_id)][UE_id].
1133
        configured == FALSE) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1134
1135
1136
1137
      LOG_D(MAC,
            "[eNB %d] frame %d subfarme %d, UE %d: not configured, skipping UE scheduling \n",
            module_idP, frameP, subframeP, UE_id);
      continue;
knopp's avatar
knopp committed
1138
    }
1139

knopp's avatar
knopp committed
1140
    rnti = UE_RNTI(module_idP, UE_id);