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

/* from openair */
#include "rlc.h"
#include "pdcp.h"

/* from nr rlc module */
#include "asn1_utils.h"
#include "nr_rlc_ue_manager.h"
#include "nr_rlc_entity.h"
30
#include "nr_rlc_oai_api.h"
knopp's avatar
knopp committed
31
32
33
34
35
36
37
#include "NR_RLC-BearerConfig.h"
#include "NR_DRB-ToAddMod.h"
#include "NR_DRB-ToAddModList.h"
#include "NR_SRB-ToAddModList.h"
#include "NR_DRB-ToReleaseList.h"
#include "NR_CellGroupConfig.h"
#include "NR_RLC-Config.h"
Xue Song's avatar
Xue Song committed
38
#include "common/ran_context.h"
Xue Song's avatar
Xue Song committed
39
40
41
42
#include "NR_UL-CCCH-Message.h"

#include "openair2/F1AP/f1ap_du_rrc_message_transfer.h"

Xue Song's avatar
Xue Song committed
43
44
#include "openair2/LAYER2/PROTO_AGENT/proto_agent.h"

Xue Song's avatar
Xue Song committed
45
extern RAN_CONTEXT_t RC;
Cedric Roux's avatar
Cedric Roux committed
46
47
48

#include <stdint.h>

Eurecom's avatar
Eurecom committed
49
#include <executables/softmodem-common.h>
50

Cedric Roux's avatar
Cedric Roux committed
51
52
53
54
55
56
57
static nr_rlc_ue_manager_t *nr_rlc_ue_manager;

/* TODO: handle time a bit more properly */
static uint64_t nr_rlc_current_time;
static int      nr_rlc_current_time_last_frame;
static int      nr_rlc_current_time_last_subframe;

58

59
void nr_rlc_bearer_init(NR_RLC_BearerConfig_t *RLC_BearerConfig, NR_RLC_BearerConfig__servedRadioBearer_PR rb_type){
60
61
62
63
64
65
66

  RLC_BearerConfig->servedRadioBearer                      = calloc(1, sizeof(*RLC_BearerConfig->servedRadioBearer));
  RLC_BearerConfig->reestablishRLC                         = calloc(1, sizeof(*RLC_BearerConfig->reestablishRLC));
  RLC_BearerConfig->rlc_Config                             = calloc(1, sizeof(*RLC_BearerConfig->rlc_Config));
  RLC_BearerConfig->mac_LogicalChannelConfig               = calloc(1, sizeof(*RLC_BearerConfig->mac_LogicalChannelConfig));

  *RLC_BearerConfig->reestablishRLC                        = NR_RLC_BearerConfig__reestablishRLC_true;
67
68
69
70
71
72
73
74
75
76
  if(rb_type == NR_RLC_BearerConfig__servedRadioBearer_PR_drb_Identity){
    RLC_BearerConfig->logicalChannelIdentity                 = 4;
    RLC_BearerConfig->servedRadioBearer->present             = NR_RLC_BearerConfig__servedRadioBearer_PR_drb_Identity;
    RLC_BearerConfig->servedRadioBearer->choice.drb_Identity = 1;
  }
  else{
    RLC_BearerConfig->logicalChannelIdentity                 = 1;
    RLC_BearerConfig->servedRadioBearer->present             = NR_RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
    RLC_BearerConfig->servedRadioBearer->choice.srb_Identity = 1;
  }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

}

void nr_rlc_bearer_init_ul_spec(struct NR_LogicalChannelConfig *mac_LogicalChannelConfig){

  mac_LogicalChannelConfig->ul_SpecificParameters                              = calloc(1, sizeof(*mac_LogicalChannelConfig->ul_SpecificParameters));
  mac_LogicalChannelConfig->ul_SpecificParameters->priority                    = 1;
  mac_LogicalChannelConfig->ul_SpecificParameters->prioritisedBitRate          = NR_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  mac_LogicalChannelConfig->ul_SpecificParameters->bucketSizeDuration          = NR_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
  mac_LogicalChannelConfig->ul_SpecificParameters->allowedServingCells         = NULL;
  mac_LogicalChannelConfig->ul_SpecificParameters->allowedSCS_List             = NULL;
  mac_LogicalChannelConfig->ul_SpecificParameters->maxPUSCH_Duration           = NULL;
  mac_LogicalChannelConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULL;

  mac_LogicalChannelConfig->ul_SpecificParameters->logicalChannelGroup                = calloc(1,sizeof(*mac_LogicalChannelConfig->ul_SpecificParameters->logicalChannelGroup));
  *mac_LogicalChannelConfig->ul_SpecificParameters->logicalChannelGroup               = 1;
Imad's avatar
Imad committed
93
94
  mac_LogicalChannelConfig->ul_SpecificParameters->schedulingRequestID                = calloc(1,sizeof(*mac_LogicalChannelConfig->ul_SpecificParameters->schedulingRequestID));
  *mac_LogicalChannelConfig->ul_SpecificParameters->schedulingRequestID               = 0;
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  mac_LogicalChannelConfig->ul_SpecificParameters->logicalChannelSR_Mask              = false;
  mac_LogicalChannelConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
  mac_LogicalChannelConfig->ul_SpecificParameters->bitRateQueryProhibitTimer          = NULL;

}

void nr_drb_config(struct NR_RLC_Config *rlc_Config, NR_RLC_Config_PR rlc_config_pr){

  switch (rlc_config_pr){
    case NR_RLC_Config_PR_um_Bi_Directional:
      // RLC UM Bi-directional Bearer configuration
      rlc_Config->choice.um_Bi_Directional                            = calloc(1, sizeof(*rlc_Config->choice.um_Bi_Directional));
      rlc_Config->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength  = calloc(1, sizeof(*rlc_Config->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength));
      *rlc_Config->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NR_SN_FieldLengthUM_size12;
      rlc_Config->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength  = calloc(1, sizeof(*rlc_Config->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength));
      *rlc_Config->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NR_SN_FieldLengthUM_size12;
      rlc_Config->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly    = NR_T_Reassembly_ms15;
      break;
    case NR_RLC_Config_PR_am:
      // RLC AM Bearer configuration
      rlc_Config->choice.am                             = calloc(1, sizeof(*rlc_Config->choice.am));
      rlc_Config->choice.am->ul_AM_RLC.sn_FieldLength   = calloc(1, sizeof(*rlc_Config->choice.am->ul_AM_RLC.sn_FieldLength));
      *rlc_Config->choice.am->ul_AM_RLC.sn_FieldLength  = NR_SN_FieldLengthAM_size18;
      rlc_Config->choice.am->ul_AM_RLC.t_PollRetransmit = NR_T_PollRetransmit_ms45;
      rlc_Config->choice.am->ul_AM_RLC.pollPDU          = NR_PollPDU_p64;
      rlc_Config->choice.am->ul_AM_RLC.pollByte         = NR_PollByte_kB500;
      rlc_Config->choice.am->ul_AM_RLC.maxRetxThreshold = NR_UL_AM_RLC__maxRetxThreshold_t32;
      rlc_Config->choice.am->dl_AM_RLC.sn_FieldLength   = calloc(1, sizeof(*rlc_Config->choice.am->dl_AM_RLC.sn_FieldLength));
      *rlc_Config->choice.am->dl_AM_RLC.sn_FieldLength  = NR_SN_FieldLengthAM_size18;
      rlc_Config->choice.am->dl_AM_RLC.t_Reassembly     = NR_T_Reassembly_ms15;
      rlc_Config->choice.am->dl_AM_RLC.t_StatusProhibit = NR_T_StatusProhibit_ms15;
      break;
    default:
      LOG_E (RLC, "Error in %s: RLC config type %d is not handled\n", __FUNCTION__, rlc_config_pr);
      break;
    }

  rlc_Config->present = rlc_config_pr;

}

Cedric Roux's avatar
Cedric Roux committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
void mac_rlc_data_ind     (
  const module_id_t         module_idP,
  const rnti_t              rntiP,
  const eNB_index_t         eNB_index,
  const frame_t             frameP,
  const eNB_flag_t          enb_flagP,
  const MBMS_flag_t         MBMS_flagP,
  const logical_chan_id_t   channel_idP,
  char                     *buffer_pP,
  const tb_size_t           tb_sizeP,
  num_tb_t                  num_tbP,
  crc_t                    *crcs_pP)
{
  nr_rlc_ue_t *ue;
  nr_rlc_entity_t *rb;

  if (module_idP != 0 || eNB_index != 0 || /*enb_flagP != 1 ||*/ MBMS_flagP != 0) {
    LOG_E(RLC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  if (enb_flagP)
    T(T_ENB_RLC_MAC_UL, T_INT(module_idP), T_INT(rntiP),
      T_INT(channel_idP), T_INT(tb_sizeP));

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP);

164
165
166
  if(ue == NULL)
	  LOG_I(RLC, "RLC instance for the given UE was not found \n");

Cedric Roux's avatar
Cedric Roux committed
167
  switch (channel_idP) {
168
  case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
169
  case 4 ... 8: rb = ue->drb[channel_idP - 4]; break;
Cedric Roux's avatar
Cedric Roux committed
170
171
172
173
  default:      rb = NULL;                     break;
  }

  if (rb != NULL) {
174
	LOG_D(RLC, "RB found! (channel ID %d) \n", channel_idP);
Cedric Roux's avatar
Cedric Roux committed
175
176
177
178
179
    rb->set_time(rb, nr_rlc_current_time);
    rb->recv_pdu(rb, buffer_pP, tb_sizeP);
  } else {
    LOG_E(RLC, "%s:%d:%s: fatal: no RB found (channel ID %d)\n",
          __FILE__, __LINE__, __FUNCTION__, channel_idP);
180
    // exit(1);
Cedric Roux's avatar
Cedric Roux committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  }

  nr_rlc_manager_unlock(nr_rlc_ue_manager);
}

tbs_size_t mac_rlc_data_req(
  const module_id_t       module_idP,
  const rnti_t            rntiP,
  const eNB_index_t       eNB_index,
  const frame_t           frameP,
  const eNB_flag_t        enb_flagP,
  const MBMS_flag_t       MBMS_flagP,
  const logical_chan_id_t channel_idP,
  const tb_size_t         tb_sizeP,
195
196
197
  char             *buffer_pP,
  const uint32_t sourceL2Id,
  const uint32_t destinationL2Id
Cedric Roux's avatar
Cedric Roux committed
198
199
200
201
202
203
204
205
206
207
208
   )
{
  int ret;
  nr_rlc_ue_t *ue;
  nr_rlc_entity_t *rb;
  int maxsize;

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP);

  switch (channel_idP) {
209
  case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
210
  case 4 ... 8: rb = ue->drb[channel_idP - 4]; break;
Cedric Roux's avatar
Cedric Roux committed
211
212
213
214
215
  default:      rb = NULL;                     break;
  }

  if (rb != NULL) {
    rb->set_time(rb, nr_rlc_current_time);
216
    maxsize = tb_sizeP;
Cedric Roux's avatar
Cedric Roux committed
217
218
    ret = rb->generate_pdu(rb, buffer_pP, maxsize);
  } else {
219
220
221
222
    // Laurent: the query loop was checking all possible RB, but by  mac_rlc_get_buffer_occupancy_ind
    // so it is more straitforward to try to get data
    //LOG_E(RLC, "%s:%d:%s: fatal: data req for unknown RB, channel_idP: %d\n", __FILE__, __LINE__, __FUNCTION__, channel_idP);
    //exit(1);
Cedric Roux's avatar
Cedric Roux committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    ret = 0;
  }

  nr_rlc_manager_unlock(nr_rlc_ue_manager);

  if (enb_flagP)
    T(T_ENB_RLC_MAC_DL, T_INT(module_idP), T_INT(rntiP),
      T_INT(channel_idP), T_INT(ret));

  return ret;
}

mac_rlc_status_resp_t mac_rlc_status_ind(
  const module_id_t       module_idP,
  const rnti_t            rntiP,
  const eNB_index_t       eNB_index,
  const frame_t           frameP,
  const sub_frame_t       subframeP,
  const eNB_flag_t        enb_flagP,
  const MBMS_flag_t       MBMS_flagP,
  const logical_chan_id_t channel_idP,
244
245
  const uint32_t sourceL2Id,
  const uint32_t destinationL2Id
Cedric Roux's avatar
Cedric Roux committed
246
247
248
249
250
251
252
253
254
255
  )
{
  nr_rlc_ue_t *ue;
  mac_rlc_status_resp_t ret;
  nr_rlc_entity_t *rb;

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP);

  switch (channel_idP) {
256
  case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
257
  case 4 ... 8: rb = ue->drb[channel_idP - 4]; break;
Cedric Roux's avatar
Cedric Roux committed
258
259
260
261
262
263
  default:      rb = NULL;                     break;
  }

  if (rb != NULL) {
    nr_rlc_entity_buffer_status_t buf_stat;
    rb->set_time(rb, nr_rlc_current_time);
264
265
    /* 38.321 deals with BSR values up to 81338368 bytes, after what it
     * reports '> 81338368' (table 6.1.3.1-2). Passing 100000000 is thus
Cedric Roux's avatar
Cedric Roux committed
266
267
     * more than enough.
     */
268
269
    // Fix me: temproary reduction meanwhile cpu cost of this computation is optimized
    buf_stat = rb->buffer_status(rb, 1000*1000);
Cedric Roux's avatar
Cedric Roux committed
270
271
272
273
    ret.bytes_in_buffer = buf_stat.status_size
                        + buf_stat.retx_size
                        + buf_stat.tx_size;
  } else {
274
275
    if (!(frameP%128)) //to supress this warning message
      LOG_W(RLC, "[%s] Radio Bearer (channel ID %d) is NULL for UE with rntiP %x\n", __FUNCTION__, channel_idP, rntiP);
Cedric Roux's avatar
Cedric Roux committed
276
277
278
279
280
281
282
283
284
285
286
287
288
    ret.bytes_in_buffer = 0;
  }

  nr_rlc_manager_unlock(nr_rlc_ue_manager);

  ret.pdus_in_buffer = 0;
  /* TODO: creation time may be important (unit: frame, as it seems) */
  ret.head_sdu_creation_time = 0;
  ret.head_sdu_remaining_size_to_send = 0;
  ret.head_sdu_is_segmented = 0;
  return ret;
}

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind(
  const module_id_t       module_idP,
  const rnti_t            rntiP,
  const eNB_index_t       eNB_index,
  const frame_t           frameP,
  const sub_frame_t       subframeP,
  const eNB_flag_t        enb_flagP,
  const logical_chan_id_t channel_idP)
{
  nr_rlc_ue_t *ue;
  rlc_buffer_occupancy_t ret;
  nr_rlc_entity_t *rb;

  if (enb_flagP) {
    LOG_E(RLC, "Tx mac_rlc_get_buffer_occupancy_ind function is not implemented for eNB LcId=%u\n", channel_idP);
    exit(1);
  }

  /* TODO: handle time a bit more properly */
  if (nr_rlc_current_time_last_frame != frameP ||
      nr_rlc_current_time_last_subframe != subframeP) {
    nr_rlc_current_time++;
    nr_rlc_current_time_last_frame = frameP;
    nr_rlc_current_time_last_subframe = subframeP;
  }

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP);

  switch (channel_idP) {
319
  case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
320
  case 4 ... 8: rb = ue->drb[channel_idP - 4]; break;
321
322
323
324
325
326
327
328
329
330
  default:      rb = NULL;                     break;
  }

  if (rb != NULL) {
    nr_rlc_entity_buffer_status_t buf_stat;
    rb->set_time(rb, nr_rlc_current_time);
    /* 38.321 deals with BSR values up to 81338368 bytes, after what it
     * reports '> 81338368' (table 6.1.3.1-2). Passing 100000000 is thus
     * more than enough.
     */
331
    // Fixme : Laurent reduced size for CPU saving
332
333
    // Fix me: temproary reduction meanwhile cpu cost of this computation is optimized
    buf_stat = rb->buffer_status(rb, 1000*1000);
334
335
336
337
338
339
340
341
342
343
344
345
    ret = buf_stat.status_size
        + buf_stat.retx_size
        + buf_stat.tx_size;
  } else {
    ret = 0;
  }

  nr_rlc_manager_unlock(nr_rlc_ue_manager);

  return ret;
}

Cedric Roux's avatar
Cedric Roux committed
346
347
348
349
350
351
352
353

rlc_op_status_t rlc_data_req     (const protocol_ctxt_t *const ctxt_pP,
                                  const srb_flag_t   srb_flagP,
                                  const MBMS_flag_t  MBMS_flagP,
                                  const rb_id_t      rb_idP,
                                  const mui_t        muiP,
                                  confirm_t    confirmP,
                                  sdu_size_t   sdu_sizeP,
354
355
356
                                  mem_block_t *sdu_pP,
  const uint32_t *const sourceL2Id,
  const uint32_t *const destinationL2Id
Cedric Roux's avatar
Cedric Roux committed
357
358
359
360
361
362
                                 )
{
  int rnti = ctxt_pP->rnti;
  nr_rlc_ue_t *ue;
  nr_rlc_entity_t *rb;

363
  LOG_D(RLC, "%s rnti %d srb_flag %d rb_id %ld mui %d confirm %d sdu_size %d MBMS_flag %d\n",
Cedric Roux's avatar
Cedric Roux committed
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
        __FUNCTION__, rnti, srb_flagP, rb_idP, muiP, confirmP, sdu_sizeP,
        MBMS_flagP);

  if (ctxt_pP->enb_flag)
    T(T_ENB_RLC_DL, T_INT(ctxt_pP->module_id),
      T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_sizeP));

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);

  rb = NULL;

  if (srb_flagP) {
    if (rb_idP >= 1 && rb_idP <= 2)
      rb = ue->srb[rb_idP - 1];
  } else {
    if (rb_idP >= 1 && rb_idP <= 5)
      rb = ue->drb[rb_idP - 1];
  }

  if (rb != NULL) {
    rb->set_time(rb, nr_rlc_current_time);
    rb->recv_sdu(rb, (char *)sdu_pP->data, sdu_sizeP, muiP);
  } else {
    LOG_E(RLC, "%s:%d:%s: fatal: SDU sent to unknown RB\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  nr_rlc_manager_unlock(nr_rlc_ue_manager);

  free_mem_block(sdu_pP, __func__);

  return RLC_OP_STATUS_OK;
}

int rlc_module_init(int enb_flag)
{
  static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  static int inited = 0;

  if (pthread_mutex_lock(&lock)) abort();

  if (inited) {
    LOG_E(RLC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  inited = 1;

  nr_rlc_ue_manager = new_nr_rlc_ue_manager(enb_flag);

  if (pthread_mutex_unlock(&lock)) abort();

  return 0;
}

void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char *dataP, const signed long sizeP)
{
}

static void deliver_sdu(void *_ue, nr_rlc_entity_t *entity, char *buf, int size)
{
  nr_rlc_ue_t *ue = _ue;
  int is_srb;
  int rb_id;
  protocol_ctxt_t ctx;
  mem_block_t *memblock;
  int i;
  int is_enb;

  /* is it SRB? */
Thomas Laurent's avatar
Thomas Laurent committed
435
  for (i = 0; i < sizeofArray(ue->srb); i++) {
Cedric Roux's avatar
Cedric Roux committed
436
437
438
439
440
441
442
443
    if (entity == ue->srb[i]) {
      is_srb = 1;
      rb_id = i+1;
      goto rb_found;
    }
  }

  /* maybe DRB? */
Thomas Laurent's avatar
Thomas Laurent committed
444
  for (i = 0; i < sizeofArray(ue->drb) ; i++) {
Cedric Roux's avatar
Cedric Roux committed
445
446
447
448
449
450
451
452
453
454
455
456
    if (entity == ue->drb[i]) {
      is_srb = 0;
      rb_id = i+1;
      goto rb_found;
    }
  }

  LOG_E(RLC, "%s:%d:%s: fatal, no RB found for ue %d\n",
        __FILE__, __LINE__, __FUNCTION__, ue->rnti);
  exit(1);

rb_found:
Roberto Louro Magueta's avatar
Roberto Louro Magueta committed
457
  LOG_D(RLC, "%s:%d:%s: delivering SDU (rnti %d is_srb %d rb_id %d) size %d",
Cedric Roux's avatar
Cedric Roux committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
        __FILE__, __LINE__, __FUNCTION__, ue->rnti, is_srb, rb_id, size);

  memblock = get_free_mem_block(size, __func__);
  if (memblock == NULL) {
    LOG_E(RLC, "%s:%d:%s: ERROR: get_free_mem_block failed\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }
  memcpy(memblock->data, buf, size);

  /* unused fields? */
  ctx.instance = 0;
  ctx.frame = 0;
  ctx.subframe = 0;
  ctx.eNB_index = 0;
  ctx.configured = 1;
  ctx.brOption = 0;

  /* used fields? */
  ctx.module_id = 0;
  ctx.rnti = ue->rnti;

  is_enb = nr_rlc_manager_get_enb_flag(nr_rlc_ue_manager);
  ctx.enb_flag = is_enb;

  if (is_enb) {
    T(T_ENB_RLC_UL,
      T_INT(0 /*ctxt_pP->module_id*/),
      T_INT(ue->rnti), T_INT(rb_id), T_INT(size));
Xue Song's avatar
Xue Song committed
486
487
488
489
490

    const ngran_node_t type = RC.nrrrc[0 /*ctxt_pP->module_id*/]->node_type;
    AssertFatal(type != ngran_eNB_CU && type != ngran_ng_eNB_CU && type != ngran_gNB_CU,
                "Can't be CU, bad node type %d\n", type);

Xue Song's avatar
Xue Song committed
491
492
493
494
495
496
    // if (NODE_IS_DU(type) && is_srb == 0) {
    //   LOG_D(RLC, "call proto_agent_send_pdcp_data_ind() \n");
    //   proto_agent_send_pdcp_data_ind(&ctx, is_srb, 0, rb_id, size, memblock);
    //   return;
    // }

Xue Song's avatar
Xue Song committed
497
    if (NODE_IS_DU(type) && is_srb == 1) {
498
      MessageDef *msg;
499
      msg = itti_alloc_new_message(TASK_RLC_ENB, 0, F1AP_UL_RRC_MESSAGE);
Xue Song's avatar
Xue Song committed
500
501
502
503
504
505
506
      F1AP_UL_RRC_MESSAGE(msg).rnti = ue->rnti;
      F1AP_UL_RRC_MESSAGE(msg).srb_id = rb_id;
      F1AP_UL_RRC_MESSAGE(msg).rrc_container = (unsigned char *)buf;
      F1AP_UL_RRC_MESSAGE(msg).rrc_container_length = size;
      itti_send_msg_to_task(TASK_DU_F1, ENB_MODULE_ID_TO_INSTANCE(0 /*ctxt_pP->module_id*/), msg);
      return;
    }
Cedric Roux's avatar
Cedric Roux committed
507
508
509
510
511
512
513
514
515
516
517
518
519
520
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
  }

  if (!pdcp_data_ind(&ctx, is_srb, 0, rb_id, size, memblock)) {
    LOG_E(RLC, "%s:%d:%s: ERROR: pdcp_data_ind failed\n", __FILE__, __LINE__, __FUNCTION__);
    /* what to do in case of failure? for the moment: nothing */
  }
}

static void successful_delivery(void *_ue, nr_rlc_entity_t *entity, int sdu_id)
{
  nr_rlc_ue_t *ue = _ue;
  int i;
  int is_srb;
  int rb_id;
#if 0
  MessageDef *msg;
#endif
  int is_enb;

  /* is it SRB? */
  for (i = 0; i < 2; i++) {
    if (entity == ue->srb[i]) {
      is_srb = 1;
      rb_id = i+1;
      goto rb_found;
    }
  }

  /* maybe DRB? */
  for (i = 0; i < 5; i++) {
    if (entity == ue->drb[i]) {
      is_srb = 0;
      rb_id = i+1;
      goto rb_found;
    }
  }

  LOG_E(RLC, "%s:%d:%s: fatal, no RB found for ue %d\n",
        __FILE__, __LINE__, __FUNCTION__, ue->rnti);
  exit(1);

rb_found:
  LOG_D(RLC, "sdu %d was successfully delivered on %s %d\n",
        sdu_id,
        is_srb ? "SRB" : "DRB",
        rb_id);

  /* TODO: do something for DRBs? */
  if (is_srb == 0)
    return;

  is_enb = nr_rlc_manager_get_enb_flag(nr_rlc_ue_manager);
  if (!is_enb)
    return;

#if 0
  msg = itti_alloc_new_message(TASK_RLC_ENB, RLC_SDU_INDICATION);
  RLC_SDU_INDICATION(msg).rnti          = ue->rnti;
  RLC_SDU_INDICATION(msg).is_successful = 1;
  RLC_SDU_INDICATION(msg).srb_id        = rb_id;
  RLC_SDU_INDICATION(msg).message_id    = sdu_id;
  /* TODO: accept more than 1 instance? here we send to instance id 0 */
  itti_send_msg_to_task(TASK_RRC_ENB, 0, msg);
#endif
}

static void max_retx_reached(void *_ue, nr_rlc_entity_t *entity)
{
  nr_rlc_ue_t *ue = _ue;
  int i;
  int is_srb;
  int rb_id;
#if 0
  MessageDef *msg;
#endif
  int is_enb;

  /* is it SRB? */
  for (i = 0; i < 2; i++) {
    if (entity == ue->srb[i]) {
      is_srb = 1;
      rb_id = i+1;
      goto rb_found;
    }
  }

  /* maybe DRB? */
  for (i = 0; i < 5; i++) {
    if (entity == ue->drb[i]) {
      is_srb = 0;
      rb_id = i+1;
      goto rb_found;
    }
  }

  LOG_E(RLC, "%s:%d:%s: fatal, no RB found for ue %d\n",
        __FILE__, __LINE__, __FUNCTION__, ue->rnti);
  exit(1);

rb_found:
607
  LOG_E(RLC, "max RETX reached on %s %d\n",
Cedric Roux's avatar
Cedric Roux committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
        is_srb ? "SRB" : "DRB",
        rb_id);

  /* TODO: do something for DRBs? */
  if (is_srb == 0)
    return;

  is_enb = nr_rlc_manager_get_enb_flag(nr_rlc_ue_manager);
  if (!is_enb)
    return;

#if 0
  msg = itti_alloc_new_message(TASK_RLC_ENB, RLC_SDU_INDICATION);
  RLC_SDU_INDICATION(msg).rnti          = ue->rnti;
  RLC_SDU_INDICATION(msg).is_successful = 0;
  RLC_SDU_INDICATION(msg).srb_id        = rb_id;
  RLC_SDU_INDICATION(msg).message_id    = -1;
  /* TODO: accept more than 1 instance? here we send to instance id 0 */
  itti_send_msg_to_task(TASK_RRC_ENB, 0, msg);
#endif
}

630
static void add_rlc_srb(int rnti, struct NR_SRB_ToAddMod *s, NR_RLC_BearerConfig_t *rlc_BearerConfig)
Cedric Roux's avatar
Cedric Roux committed
631
632
633
634
{
  nr_rlc_entity_t            *nr_rlc_am;
  nr_rlc_ue_t                *ue;

635
636
  struct NR_RLC_Config *r = rlc_BearerConfig->rlc_Config;
  struct NR_LogicalChannelConfig *l = rlc_BearerConfig->mac_LogicalChannelConfig;
Cedric Roux's avatar
Cedric Roux committed
637
  int srb_id = s->srb_Identity;
638
  int channel_id = rlc_BearerConfig->logicalChannelIdentity;
Cedric Roux's avatar
Cedric Roux committed
639
640
641
642
643
644
645
646
647
648
  int logical_channel_group;

  int t_status_prohibit;
  int t_poll_retransmit;
  int poll_pdu;
  int poll_byte;
  int max_retx_threshold;
  int t_reassembly;
  int sn_field_length;

Roberto Louro Magueta's avatar
Roberto Louro Magueta committed
649
  LOG_D(RLC,"Trying to add SRB %d\n",srb_id);
Cedric Roux's avatar
Cedric Roux committed
650
651
  if (srb_id != 1 && srb_id != 2) {
    LOG_E(RLC, "%s:%d:%s: fatal, bad srb id %d\n",
652
        __FILE__, __LINE__, __FUNCTION__, srb_id);
Cedric Roux's avatar
Cedric Roux committed
653
654
655
    exit(1);
  }

656
657
658
  if (channel_id != srb_id) {
    LOG_E(RLC, "%s:%d:%s: todo, remove this limitation\n",
          __FILE__, __LINE__, __FUNCTION__);
Cedric Roux's avatar
Cedric Roux committed
659
660
661
    exit(1);
  }

662
  logical_channel_group = *l->ul_SpecificParameters->logicalChannelGroup;
Cedric Roux's avatar
Cedric Roux committed
663
664
665
666
667
668
669
670

  /* TODO: accept other values? */
  if (logical_channel_group != 0) {
    LOG_E(RLC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  switch (r->present) {
671
672
673
674
  case NR_RLC_Config_PR_am: {
    struct NR_RLC_Config__am *am;
    am = r->choice.am;
    t_reassembly       = decode_t_reassembly(am->dl_AM_RLC.t_Reassembly);
Cedric Roux's avatar
Cedric Roux committed
675
676
677
678
679
    t_status_prohibit  = decode_t_status_prohibit(am->dl_AM_RLC.t_StatusProhibit);
    t_poll_retransmit  = decode_t_poll_retransmit(am->ul_AM_RLC.t_PollRetransmit);
    poll_pdu           = decode_poll_pdu(am->ul_AM_RLC.pollPDU);
    poll_byte          = decode_poll_byte(am->ul_AM_RLC.pollByte);
    max_retx_threshold = decode_max_retx_threshold(am->ul_AM_RLC.maxRetxThreshold);
680
681
682
683
684
    if (*am->dl_AM_RLC.sn_FieldLength != *am->ul_AM_RLC.sn_FieldLength) {
      LOG_E(RLC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
      exit(1);
    }
    sn_field_length    = decode_sn_field_length_am(*am->dl_AM_RLC.sn_FieldLength);
Cedric Roux's avatar
Cedric Roux committed
685
686
687
688
689
690
691
692
693
694
    break;
  }
  default:
    LOG_E(RLC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);
  if (ue->srb[srb_id-1] != NULL) {
695
    LOG_W(RLC, "%s:%d:%s: SRB %d already exists for UE with RNTI 0x%x, do nothing\n", __FILE__, __LINE__, __FUNCTION__, srb_id, rnti);
Cedric Roux's avatar
Cedric Roux committed
696
697
698
699
700
701
702
703
704
  } else {
    /* hack: hardcode values for NR */
    t_poll_retransmit = 45;
    t_reassembly = 35;
    t_status_prohibit = 0;
    poll_pdu = -1;
    poll_byte = -1;
    max_retx_threshold = 8;
    sn_field_length = 12;
705
706
    nr_rlc_am = new_nr_rlc_entity_am(10000000,
                                     10000000,
Cedric Roux's avatar
Cedric Roux committed
707
708
709
710
711
712
713
714
715
                                     deliver_sdu, ue,
                                     successful_delivery, ue,
                                     max_retx_reached, ue,
                                     t_poll_retransmit,
                                     t_reassembly, t_status_prohibit,
                                     poll_pdu, poll_byte, max_retx_threshold,
                                     sn_field_length);
    nr_rlc_ue_add_srb_rlc_entity(ue, srb_id, nr_rlc_am);

Roberto Louro Magueta's avatar
Roberto Louro Magueta committed
716
    LOG_D(RLC, "%s:%d:%s: added srb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, srb_id, rnti);
Cedric Roux's avatar
Cedric Roux committed
717
718
719
720
  }
  nr_rlc_manager_unlock(nr_rlc_ue_manager);
}

knopp's avatar
knopp committed
721
static void add_drb_am(int rnti, struct NR_DRB_ToAddMod *s, NR_RLC_BearerConfig_t *rlc_BearerConfig)
Cedric Roux's avatar
Cedric Roux committed
722
723
724
725
{
  nr_rlc_entity_t            *nr_rlc_am;
  nr_rlc_ue_t                *ue;

knopp's avatar
knopp committed
726
727
  struct NR_RLC_Config *r = rlc_BearerConfig->rlc_Config;
  struct NR_LogicalChannelConfig *l = rlc_BearerConfig->mac_LogicalChannelConfig;
Cedric Roux's avatar
Cedric Roux committed
728
  int drb_id = s->drb_Identity;
knopp's avatar
knopp committed
729
  int channel_id = rlc_BearerConfig->logicalChannelIdentity;
Cedric Roux's avatar
Cedric Roux committed
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
  int logical_channel_group;

  int t_status_prohibit;
  int t_poll_retransmit;
  int poll_pdu;
  int poll_byte;
  int max_retx_threshold;
  int t_reassembly;
  int sn_field_length;

  if (!(drb_id >= 1 && drb_id <= 5)) {
    LOG_E(RLC, "%s:%d:%s: fatal, bad srb id %d\n",
          __FILE__, __LINE__, __FUNCTION__, drb_id);
    exit(1);
  }

746
  if (channel_id != drb_id + 3) {
Cedric Roux's avatar
Cedric Roux committed
747
748
749
750
751
752
753
754
755
756
    LOG_E(RLC, "%s:%d:%s: todo, remove this limitation\n",
          __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  logical_channel_group = *l->ul_SpecificParameters->logicalChannelGroup;

  /* TODO: accept other values? */
  if (logical_channel_group != 1) {
    LOG_E(RLC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__);
757
    //exit(1);
Cedric Roux's avatar
Cedric Roux committed
758
759
760
  }

  switch (r->present) {
knopp's avatar
knopp committed
761
762
763
  case NR_RLC_Config_PR_am: {
    struct NR_RLC_Config__am *am;
    am = r->choice.am;
Cedric Roux's avatar
Cedric Roux committed
764
    t_reassembly       = decode_t_reassembly(am->dl_AM_RLC.t_Reassembly);
Cedric Roux's avatar
Cedric Roux committed
765
766
767
768
769
    t_status_prohibit  = decode_t_status_prohibit(am->dl_AM_RLC.t_StatusProhibit);
    t_poll_retransmit  = decode_t_poll_retransmit(am->ul_AM_RLC.t_PollRetransmit);
    poll_pdu           = decode_poll_pdu(am->ul_AM_RLC.pollPDU);
    poll_byte          = decode_poll_byte(am->ul_AM_RLC.pollByte);
    max_retx_threshold = decode_max_retx_threshold(am->ul_AM_RLC.maxRetxThreshold);
Cedric Roux's avatar
Cedric Roux committed
770
771
772
773
774
    if (*am->dl_AM_RLC.sn_FieldLength != *am->ul_AM_RLC.sn_FieldLength) {
      LOG_E(RLC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
      exit(1);
    }
    sn_field_length    = decode_sn_field_length_am(*am->dl_AM_RLC.sn_FieldLength);
Cedric Roux's avatar
Cedric Roux committed
775
776
777
778
779
780
781
782
783
784
    break;
  }
  default:
    LOG_E(RLC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);
  if (ue->drb[drb_id-1] != NULL) {
785
    LOG_W(RLC, "%s:%d:%s: DRB %d already exists for UE with RNTI %d, do nothing\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti);
Cedric Roux's avatar
Cedric Roux committed
786
  } else {
787
788
    nr_rlc_am = new_nr_rlc_entity_am(10000000,
                                     10000000,
Cedric Roux's avatar
Cedric Roux committed
789
790
791
792
793
794
795
796
797
                                     deliver_sdu, ue,
                                     successful_delivery, ue,
                                     max_retx_reached, ue,
                                     t_poll_retransmit,
                                     t_reassembly, t_status_prohibit,
                                     poll_pdu, poll_byte, max_retx_threshold,
                                     sn_field_length);
    nr_rlc_ue_add_drb_rlc_entity(ue, drb_id, nr_rlc_am);

798
    LOG_D(RLC, "%s:%d:%s: added drb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti);
Cedric Roux's avatar
Cedric Roux committed
799
800
801
802
  }
  nr_rlc_manager_unlock(nr_rlc_ue_manager);
}

knopp's avatar
knopp committed
803
static void add_drb_um(int rnti, struct NR_DRB_ToAddMod *s, NR_RLC_BearerConfig_t *rlc_BearerConfig)
Cedric Roux's avatar
Cedric Roux committed
804
805
806
807
{
  nr_rlc_entity_t            *nr_rlc_um;
  nr_rlc_ue_t                *ue;

knopp's avatar
knopp committed
808
809
  struct NR_RLC_Config *r = rlc_BearerConfig->rlc_Config;
  struct NR_LogicalChannelConfig *l = rlc_BearerConfig->mac_LogicalChannelConfig;
Cedric Roux's avatar
Cedric Roux committed
810
  int drb_id = s->drb_Identity;
knopp's avatar
knopp committed
811
  int channel_id = rlc_BearerConfig->logicalChannelIdentity;
Cedric Roux's avatar
Cedric Roux committed
812
813
814
815
816
817
818
819
820
821
822
  int logical_channel_group;

  int sn_field_length;
  int t_reassembly;

  if (!(drb_id >= 1 && drb_id <= 5)) {
    LOG_E(RLC, "%s:%d:%s: fatal, bad srb id %d\n",
          __FILE__, __LINE__, __FUNCTION__, drb_id);
    exit(1);
  }

823
  if (channel_id != drb_id + 3) {
Cedric Roux's avatar
Cedric Roux committed
824
825
826
827
828
829
830
831
832
833
834
835
836
837
    LOG_E(RLC, "%s:%d:%s: todo, remove this limitation\n",
          __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  logical_channel_group = *l->ul_SpecificParameters->logicalChannelGroup;

  /* TODO: accept other values? */
  if (logical_channel_group != 1) {
    LOG_E(RLC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  switch (r->present) {
knopp's avatar
knopp committed
838
839
840
  case NR_RLC_Config_PR_um_Bi_Directional: {
    struct NR_RLC_Config__um_Bi_Directional *um;
    um = r->choice.um_Bi_Directional;
Cedric Roux's avatar
Cedric Roux committed
841
    t_reassembly = decode_t_reassembly(um->dl_UM_RLC.t_Reassembly);
842
    if (*um->dl_UM_RLC.sn_FieldLength != *um->ul_UM_RLC.sn_FieldLength) {
Cedric Roux's avatar
Cedric Roux committed
843
844
845
      LOG_E(RLC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
      exit(1);
    }
Cedric Roux's avatar
Cedric Roux committed
846
    sn_field_length = decode_sn_field_length_um(*um->dl_UM_RLC.sn_FieldLength);
Cedric Roux's avatar
Cedric Roux committed
847
848
849
850
851
852
853
854
855
856
    break;
  }
  default:
    LOG_E(RLC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }

  nr_rlc_manager_lock(nr_rlc_ue_manager);
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);
  if (ue->drb[drb_id-1] != NULL) {
857
    LOG_W(RLC, "DEBUG add_drb_um %s:%d:%s: warning DRB %d already exist for ue %d, do nothing\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti);
Cedric Roux's avatar
Cedric Roux committed
858
  } else {
859
860
    nr_rlc_um = new_nr_rlc_entity_um(100000000,
                                     100000000,
Cedric Roux's avatar
Cedric Roux committed
861
862
863
864
865
                                     deliver_sdu, ue,
                                     t_reassembly,
                                     sn_field_length);
    nr_rlc_ue_add_drb_rlc_entity(ue, drb_id, nr_rlc_um);

866
    LOG_D(RLC, "%s:%d:%s: added drb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti);
Cedric Roux's avatar
Cedric Roux committed
867
868
869
870
  }
  nr_rlc_manager_unlock(nr_rlc_ue_manager);
}

Cedric Roux's avatar
Cedric Roux committed
871
static void add_drb(int rnti, struct NR_DRB_ToAddMod *s, struct NR_RLC_BearerConfig *rlc_BearerConfig)
Cedric Roux's avatar
Cedric Roux committed
872
{
knopp's avatar
knopp committed
873
874
875
  switch (rlc_BearerConfig->rlc_Config->present) {
  case NR_RLC_Config_PR_am:
    add_drb_am(rnti, s, rlc_BearerConfig);
Cedric Roux's avatar
Cedric Roux committed
876
    break;
knopp's avatar
knopp committed
877
878
  case NR_RLC_Config_PR_um_Bi_Directional:
    add_drb_um(rnti, s, rlc_BearerConfig);
Cedric Roux's avatar
Cedric Roux committed
879
880
881
882
883
884
    break;
  default:
    LOG_E(RLC, "%s:%d:%s: fatal: unhandled DRB type\n",
          __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }
885
  LOG_I(RLC, "%s:%s:%d: added DRB to UE with RNTI 0x%x\n", __FILE__, __FUNCTION__, __LINE__, rnti);
Cedric Roux's avatar
Cedric Roux committed
886
887
}

888
/* Dummy function due to dependency from LTE libraries */
Cedric Roux's avatar
Cedric Roux committed
889
890
891
rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP,
    const LTE_SRB_ToAddModList_t   * const srb2add_listP,
    const LTE_DRB_ToAddModList_t   * const drb2add_listP,
892
893
894
895
    const LTE_DRB_ToReleaseList_t  * const drb2release_listP,
    const LTE_PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP,
    const uint32_t sourceL2Id,
    const uint32_t destinationL2Id)
Cedric Roux's avatar
Cedric Roux committed
896
{
897
  return 0;
Cedric Roux's avatar
Cedric Roux committed
898
899
}

knopp's avatar
knopp committed
900
rlc_op_status_t nr_rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP,
901
    const NR_SRB_ToAddModList_t   * const srb2add_listP,
knopp's avatar
knopp committed
902
903
904
    const NR_DRB_ToAddModList_t   * const drb2add_listP,
    const NR_DRB_ToReleaseList_t  * const drb2release_listP,
    const LTE_PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP,
905
    struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_bearer2add_list)
knopp's avatar
knopp committed
906
907
908
{
  int rnti = ctxt_pP->rnti;
  int i;
909
  int j;
knopp's avatar
knopp committed
910
911
912
913

  if (/*ctxt_pP->enb_flag != 1 ||*/ ctxt_pP->module_id != 0 /*||
      ctxt_pP->instance != 0 || ctxt_pP->eNB_index != 0 ||
      ctxt_pP->configured != 1 || ctxt_pP->brOption != 0 */) {
914
    LOG_E(RLC, "%s: ctxt_pP not handled (%d %d %ld %d %d %d)\n", __FUNCTION__,
knopp's avatar
knopp committed
915
916
917
918
919
920
921
922
923
924
925
926
          ctxt_pP->enb_flag , ctxt_pP->module_id, ctxt_pP->instance,
          ctxt_pP->eNB_index, ctxt_pP->configured, ctxt_pP->brOption);
    exit(1);
  }

  if (pmch_InfoList_r9_pP != NULL) {
    LOG_E(RLC, "%s: pmch_InfoList_r9_pP not handled\n", __FUNCTION__);
    exit(1);
  }

  if (drb2release_listP != NULL) {
    LOG_E(RLC, "%s:%d:%s: TODO\n", __FILE__, __LINE__, __FUNCTION__);
927
    //exit(1);
knopp's avatar
knopp committed
928
929
930
931
  }

  if (srb2add_listP != NULL) {
    for (i = 0; i < srb2add_listP->list.count; i++) {
Wang He's avatar
Wang He committed
932
      if (rlc_bearer2add_list != NULL) {
Roberto Louro Magueta's avatar
Add SRB    
Roberto Louro Magueta committed
933
934
935
936
937
938
        for(j = 0; j < rlc_bearer2add_list->list.count; j++){
          if(rlc_bearer2add_list->list.array[j]->servedRadioBearer != NULL){
            if(rlc_bearer2add_list->list.array[j]->servedRadioBearer->present == NR_RLC_BearerConfig__servedRadioBearer_PR_srb_Identity){
              if(srb2add_listP->list.array[i]->srb_Identity == rlc_bearer2add_list->list.array[j]->servedRadioBearer->choice.srb_Identity){
                add_rlc_srb(rnti, srb2add_listP->list.array[i], rlc_bearer2add_list->list.array[j]);
              }
939
            }
Roberto Louro Magueta's avatar
Add SRB    
Roberto Louro Magueta committed
940
          }
941
942
943
        }
      }

knopp's avatar
knopp committed
944
945
946
    }
  }

Fang WANG's avatar
Fang WANG committed
947
  if ((drb2add_listP != NULL) && (rlc_bearer2add_list != NULL)) {
knopp's avatar
knopp committed
948
    for (i = 0; i < drb2add_listP->list.count; i++) {
Wang He's avatar
Wang He committed
949
      if (rlc_bearer2add_list != NULL) {
950
951
952
953
954
955
956
957
958
      for(j = 0; j < rlc_bearer2add_list->list.count; j++){
        if(rlc_bearer2add_list->list.array[j]->servedRadioBearer != NULL){
          if(rlc_bearer2add_list->list.array[j]->servedRadioBearer->present == NR_RLC_BearerConfig__servedRadioBearer_PR_drb_Identity){
            if(drb2add_listP->list.array[i]->drb_Identity == rlc_bearer2add_list->list.array[j]->servedRadioBearer->choice.drb_Identity){
              add_drb(rnti, drb2add_listP->list.array[i], rlc_bearer2add_list->list.array[j]);
            }
          }  
        }
      }
Wang He's avatar
Wang He committed
959
      }
knopp's avatar
knopp committed
960
961
962
963
964
965
    }
  }

  return RLC_OP_STATUS_OK;
}

Cedric Roux's avatar
Cedric Roux committed
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
rlc_op_status_t rrc_rlc_config_req   (
  const protocol_ctxt_t* const ctxt_pP,
  const srb_flag_t      srb_flagP,
  const MBMS_flag_t     mbms_flagP,
  const config_action_t actionP,
  const rb_id_t         rb_idP,
  const rlc_info_t      rlc_infoP)
{
  nr_rlc_ue_t *ue;
  int      i;

  if (mbms_flagP) {
    LOG_E(RLC, "%s:%d:%s: todo (MBMS NOT supported)\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }
  if (actionP != CONFIG_ACTION_REMOVE) {
    LOG_E(RLC, "%s:%d:%s: todo (only CONFIG_ACTION_REMOVE supported)\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }
  if (ctxt_pP->module_id) {
    LOG_E(RLC, "%s:%d:%s: todo (only module_id 0 supported)\n", __FILE__, __LINE__, __FUNCTION__);
    exit(1);
  }
  if ((srb_flagP && !(rb_idP >= 1 && rb_idP <= 2)) ||
      (!srb_flagP && !(rb_idP >= 1 && rb_idP <= 5))) {
991
    LOG_E(RLC, "%s:%d:%s: bad rb_id (%ld) (is_srb %d)\n", __FILE__, __LINE__, __FUNCTION__, rb_idP, srb_flagP);
Cedric Roux's avatar
Cedric Roux committed
992
993
994
    exit(1);
  }
  nr_rlc_manager_lock(nr_rlc_ue_manager);
995
  LOG_D(RLC, "%s:%d:%s: remove rb %ld (is_srb %d) for UE RNTI %x\n", __FILE__, __LINE__, __FUNCTION__, rb_idP, srb_flagP, ctxt_pP->rnti);
Cedric Roux's avatar
Cedric Roux committed
996
997
998
999
1000
1001
  ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, ctxt_pP->rnti);
  if (srb_flagP) {
    if (ue->srb[rb_idP-1] != NULL) {
      ue->srb[rb_idP-1]->delete(ue->srb[rb_idP-1]);
      ue->srb[rb_idP-1] = NULL;
    } else
1002
      LOG_W(RLC, "removing non allocated SRB %ld, do nothing\n", rb_idP);
Cedric Roux's avatar
Cedric Roux committed
1003
1004
1005
1006
1007
  } else {
    if (ue->drb[rb_idP-1] != NULL) {
      ue->drb[rb_idP-1]->delete(ue->drb[rb_idP-1]);
      ue->drb[rb_idP-1] = NULL;
    } else
1008
      LOG_W(RLC, "removing non allocated DRB %ld, do nothing\n", rb_idP);
Cedric Roux's avatar
Cedric Roux committed
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
  }
  /* remove UE if it has no more RB configured */
  for (i = 0; i < 2; i++)
    if (ue->srb[i] != NULL)
      break;
  if (i == 2) {
    for (i = 0; i < 5; i++)
      if (ue->drb[i] != NULL)
        break;
    if (i == 5)
      nr_rlc_manager_remove_ue(nr_rlc_ue_manager, ctxt_pP->rnti);
  }
  nr_rlc_manager_unlock(nr_rlc_ue_manager);
  return RLC_OP_STATUS_OK;
}

void rrc_rlc_register_rrc (rrc_data_ind_cb_t rrc_data_indP, rrc_data_conf_cb_t rrc_data_confP)
{
  /* nothing to do */
}

rlc_op_status_t rrc_rlc_remove_ue (const protocol_ctxt_t* const x)
{
  LOG_D(RLC, "%s:%d:%s: remove UE %d\n", __FILE__, __LINE__, __FUNCTION__, x->rnti);
  nr_rlc_manager_lock(nr_rlc_ue_manager);
  nr_rlc_manager_remove_ue(nr_rlc_ue_manager, x->rnti);
  nr_rlc_manager_unlock(nr_rlc_ue_manager);

  return RLC_OP_STATUS_OK;
}
1039
1040
1041
1042

void nr_rlc_tick(int frame, int subframe)
{
  if (frame != nr_rlc_current_time_last_frame ||
1043
1044
1045
      subframe != nr_rlc_current_time_last_subframe) {
    nr_rlc_current_time_last_frame = frame;
    nr_rlc_current_time_last_subframe = subframe;
1046
    nr_rlc_current_time++;
1047
  }
1048
}
Cedric Roux's avatar
Cedric Roux committed
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

/* This is a hack, to compile the gNB.
 * TODO: remove it. The solution is to cleanup cmake_targets/CMakeLists.txt
 */
void rlc_tick(int a, int b)
{
  LOG_E(RLC, "%s:%d:%s: this code should not be reached\n",
        __FILE__, __LINE__, __FUNCTION__);
  exit(1);
}