rlc.c 24.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 21
 * 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
 */

gauthier's avatar
gauthier committed
22 23 24 25 26 27 28
/*
                                rlc.c
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
  EMAIL   : Lionel.Gauthier at eurecom dot fr
*/
29 30 31 32 33
#define RLC_C
#include "rlc.h"
#include "mem_block.h"
#include "../MAC/extern.h"
#include "UTIL/LOG/log.h"
gauthier's avatar
gauthier committed
34
#include "UTIL/OCG/OCG_vars.h"
35
#include "UTIL/LOG/vcd_signal_dumper.h"
36 37 38

#include "assertions.h"

39
extern boolean_t pdcp_data_ind(
40 41 42 43 44 45
  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 sdu_size_t sdu_buffer_sizeP,
  mem_block_t* const sdu_buffer_pP);
46

47
#define DEBUG_RLC_PDCP_INTERFACE 1
48
//#define TRACE_RLC_PAYLOAD 1
gauthier's avatar
gauthier committed
49
#define DEBUG_RLC_DATA_REQ 1
50 51

//-----------------------------------------------------------------------------
52
void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, const signed long sizeP)
53 54 55 56 57 58 59 60 61
//-----------------------------------------------------------------------------
{
  unsigned long octet_index = 0;

  if (dataP == NULL) {
    return;
  }


62 63 64 65 66


  LOG_T(componentP, "+-----+-------------------------------------------------+\n");
  LOG_T(componentP, "|     |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
  LOG_T(componentP, "+-----+-------------------------------------------------+\n");
67

68
  for (octet_index = 0; octet_index < sizeP; octet_index++) {
69
    if ((octet_index % 16) == 0) {
70
      if (octet_index != 0) {
71
        LOG_T(componentP, " |\n");
72
      }
73

Cedric Roux's avatar
Cedric Roux committed
74
      LOG_T(componentP, " %04lu |", octet_index);
75
    }
76

77 78 79 80 81 82 83 84 85 86 87 88 89
    /*
     * Print every single octet in hexadecimal form
     */
    LOG_T(componentP, " %02x", dataP[octet_index]);
    /*
     * Align newline and pipes according to the octets in groups of 2
     */
  }

  /*
   * Append enough spaces and put final pipe
   */
  unsigned char index;
90

91
  for (index = octet_index; index < 16; ++index) {
92
    LOG_T(componentP, "   ");
93
  }
94

95 96
  LOG_T(componentP, " |\n");
}
97

98
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
99
rlc_op_status_t rlc_stat_req     (
100
  const protocol_ctxt_t* const ctxt_pP,
101 102
  const srb_flag_t    srb_flagP,
  const rb_id_t       rb_idP,
103
  unsigned int* stat_rlc_mode,
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
  unsigned int* stat_tx_pdcp_sdu,
  unsigned int* stat_tx_pdcp_bytes,
  unsigned int* stat_tx_pdcp_sdu_discarded,
  unsigned int* stat_tx_pdcp_bytes_discarded,
  unsigned int* stat_tx_data_pdu,
  unsigned int* stat_tx_data_bytes,
  unsigned int* stat_tx_retransmit_pdu_by_status,
  unsigned int* stat_tx_retransmit_bytes_by_status,
  unsigned int* stat_tx_retransmit_pdu,
  unsigned int* stat_tx_retransmit_bytes,
  unsigned int* stat_tx_control_pdu,
  unsigned int* stat_tx_control_bytes,
  unsigned int* stat_rx_pdcp_sdu,
  unsigned int* stat_rx_pdcp_bytes,
  unsigned int* stat_rx_data_pdus_duplicate,
  unsigned int* stat_rx_data_bytes_duplicate,
  unsigned int* stat_rx_data_pdu,
  unsigned int* stat_rx_data_bytes,
  unsigned int* stat_rx_data_pdu_dropped,
  unsigned int* stat_rx_data_bytes_dropped,
  unsigned int* stat_rx_data_pdu_out_of_window,
  unsigned int* stat_rx_data_bytes_out_of_window,
  unsigned int* stat_rx_control_pdu,
  unsigned int* stat_rx_control_bytes,
  unsigned int* stat_timer_reordering_timed_out,
  unsigned int* stat_timer_poll_retransmit_timed_out,
  unsigned int* stat_timer_status_prohibit_timed_out)
{
  //-----------------------------------------------------------------------------
  rlc_mode_t             rlc_mode        = RLC_MODE_NONE;
  rlc_union_t           *rlc_union_p     = NULL;
135
  hash_key_t             key             = HASHTABLE_NOT_A_KEY_VALUE;
136
  hashtable_rc_t         h_rc;
gauthier's avatar
gauthier committed
137 138

#ifdef OAI_EMU
139

140
  CHECK_CTXT_ARGS(ctxt_pP)
141

gauthier's avatar
gauthier committed
142
#endif
143
  AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
144
  key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
145 146 147 148 149
  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);

  if (h_rc == HASH_TABLE_OK) {
    rlc_mode = rlc_union_p->mode;
  }
150
  *stat_rlc_mode                     = rlc_mode;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
  switch (rlc_mode) {
  case RLC_MODE_NONE:
    *stat_tx_pdcp_sdu                     = 0;
    *stat_tx_pdcp_bytes                   = 0;
    *stat_tx_pdcp_sdu_discarded           = 0;
    *stat_tx_pdcp_bytes_discarded         = 0;
    *stat_tx_data_pdu                     = 0;
    *stat_tx_data_bytes                   = 0;
    *stat_tx_retransmit_pdu_by_status     = 0;
    *stat_tx_retransmit_bytes_by_status   = 0;
    *stat_tx_retransmit_pdu               = 0;
    *stat_tx_retransmit_bytes             = 0;
    *stat_tx_control_pdu                  = 0;
    *stat_tx_control_bytes                = 0;
    *stat_rx_pdcp_sdu                     = 0;
    *stat_rx_pdcp_bytes                   = 0;
    *stat_rx_data_pdus_duplicate          = 0;
    *stat_rx_data_bytes_duplicate         = 0;
    *stat_rx_data_pdu                     = 0;
    *stat_rx_data_bytes                   = 0;
    *stat_rx_data_pdu_dropped             = 0;
    *stat_rx_data_bytes_dropped           = 0;
    *stat_rx_data_pdu_out_of_window       = 0;
    *stat_rx_data_bytes_out_of_window     = 0;
    *stat_rx_control_pdu                  = 0;
    *stat_rx_control_bytes                = 0;
    *stat_timer_reordering_timed_out      = 0;
    *stat_timer_poll_retransmit_timed_out = 0;
    *stat_timer_status_prohibit_timed_out = 0;
    return RLC_OP_STATUS_BAD_PARAMETER;
    break;

  case RLC_MODE_AM:
184
    rlc_am_stat_req(ctxt_pP,
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
                    &rlc_union_p->rlc.am,
                    stat_tx_pdcp_sdu,
                    stat_tx_pdcp_bytes,
                    stat_tx_pdcp_sdu_discarded,
                    stat_tx_pdcp_bytes_discarded,
                    stat_tx_data_pdu,
                    stat_tx_data_bytes,
                    stat_tx_retransmit_pdu_by_status,
                    stat_tx_retransmit_bytes_by_status,
                    stat_tx_retransmit_pdu,
                    stat_tx_retransmit_bytes,
                    stat_tx_control_pdu,
                    stat_tx_control_bytes,
                    stat_rx_pdcp_sdu,
                    stat_rx_pdcp_bytes,
                    stat_rx_data_pdus_duplicate,
                    stat_rx_data_bytes_duplicate,
                    stat_rx_data_pdu,
                    stat_rx_data_bytes,
                    stat_rx_data_pdu_dropped,
                    stat_rx_data_bytes_dropped,
                    stat_rx_data_pdu_out_of_window,
                    stat_rx_data_bytes_out_of_window,
                    stat_rx_control_pdu,
                    stat_rx_control_bytes,
                    stat_timer_reordering_timed_out,
                    stat_timer_poll_retransmit_timed_out,
                    stat_timer_status_prohibit_timed_out);
    return RLC_OP_STATUS_OK;
    break;

  case RLC_MODE_UM:
    *stat_tx_retransmit_pdu_by_status     = 0;
    *stat_tx_retransmit_bytes_by_status   = 0;
    *stat_tx_retransmit_pdu               = 0;
    *stat_tx_retransmit_bytes             = 0;
    *stat_tx_control_pdu                  = 0;
    *stat_tx_control_bytes                = 0;
    *stat_rx_data_pdu_dropped             = 0;
    *stat_rx_data_bytes_dropped           = 0;
    *stat_rx_data_pdu_out_of_window       = 0;
    *stat_rx_data_bytes_out_of_window     = 0;
    *stat_timer_poll_retransmit_timed_out = 0;
    *stat_timer_status_prohibit_timed_out = 0;
229
    rlc_um_stat_req (ctxt_pP,
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
                     &rlc_union_p->rlc.um,
                     stat_tx_pdcp_sdu,
                     stat_tx_pdcp_bytes,
                     stat_tx_pdcp_sdu_discarded,
                     stat_tx_pdcp_bytes_discarded,
                     stat_tx_data_pdu,
                     stat_tx_data_bytes,
                     stat_rx_pdcp_sdu,
                     stat_rx_pdcp_bytes,
                     stat_rx_data_pdus_duplicate,
                     stat_rx_data_bytes_duplicate,
                     stat_rx_data_pdu,
                     stat_rx_data_bytes,
                     stat_rx_data_pdu_dropped,
                     stat_rx_data_bytes_dropped,
                     stat_rx_data_pdu_out_of_window,
                     stat_rx_data_bytes_out_of_window,
                     stat_timer_reordering_timed_out);
    return RLC_OP_STATUS_OK;
    break;

  case RLC_MODE_TM:
    *stat_tx_pdcp_sdu                     = 0;
    *stat_tx_pdcp_bytes                   = 0;
    *stat_tx_pdcp_sdu_discarded           = 0;
    *stat_tx_pdcp_bytes_discarded         = 0;
    *stat_tx_data_pdu                     = 0;
    *stat_tx_data_bytes                   = 0;
    *stat_tx_retransmit_pdu_by_status     = 0;
    *stat_tx_retransmit_bytes_by_status   = 0;
    *stat_tx_retransmit_pdu               = 0;
    *stat_tx_retransmit_bytes             = 0;
    *stat_tx_control_pdu                  = 0;
    *stat_tx_control_bytes                = 0;
    *stat_rx_pdcp_sdu                     = 0;
    *stat_rx_pdcp_bytes                   = 0;
    *stat_rx_data_pdus_duplicate          = 0;
    *stat_rx_data_bytes_duplicate         = 0;
    *stat_rx_data_pdu                     = 0;
    *stat_rx_data_bytes                   = 0;
    *stat_rx_data_pdu_dropped             = 0;
    *stat_rx_data_bytes_dropped           = 0;
    *stat_rx_data_pdu_out_of_window       = 0;
    *stat_rx_data_bytes_out_of_window     = 0;
    *stat_rx_control_pdu                  = 0;
    *stat_rx_control_bytes                = 0;
    *stat_timer_reordering_timed_out      = 0;
    *stat_timer_poll_retransmit_timed_out = 0;
    *stat_timer_status_prohibit_timed_out = 0;
    return RLC_OP_STATUS_BAD_PARAMETER;
    break;

  default:
    *stat_tx_pdcp_sdu                     = 0;
    *stat_tx_pdcp_bytes                   = 0;
    *stat_tx_pdcp_sdu_discarded           = 0;
    *stat_tx_pdcp_bytes_discarded         = 0;
    *stat_tx_data_pdu                     = 0;
    *stat_tx_data_bytes                   = 0;
    *stat_tx_retransmit_pdu_by_status     = 0;
    *stat_tx_retransmit_bytes_by_status   = 0;
    *stat_tx_retransmit_pdu               = 0;
    *stat_tx_retransmit_bytes             = 0;
    *stat_tx_control_pdu                  = 0;
    *stat_tx_control_bytes                = 0;
    *stat_rx_pdcp_sdu                     = 0;
    *stat_rx_pdcp_bytes                   = 0;
    *stat_rx_data_pdus_duplicate          = 0;
    *stat_rx_data_bytes_duplicate         = 0;
    *stat_rx_data_pdu                     = 0;
    *stat_rx_data_bytes                   = 0;
    *stat_rx_data_pdu_dropped             = 0;
    *stat_rx_data_bytes_dropped           = 0;
    *stat_rx_data_pdu_out_of_window       = 0;
    *stat_rx_data_bytes_out_of_window     = 0;
    *stat_rx_control_pdu                  = 0;
    *stat_rx_control_bytes                = 0;

    *stat_timer_poll_retransmit_timed_out = 0;
    *stat_timer_status_prohibit_timed_out = 0;
    return RLC_OP_STATUS_BAD_PARAMETER;
  }
312
}
313

314
//-----------------------------------------------------------------------------
315
rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
316 317 318 319
                                  const srb_flag_t   srb_flagP,
                                  const MBMS_flag_t  MBMS_flagP,
                                  const rb_id_t      rb_idP,
                                  const mui_t        muiP,
320 321
                                  confirm_t    confirmP,
                                  sdu_size_t   sdu_sizeP,
322 323 324
                                  mem_block_t *sdu_pP)
{
  //-----------------------------------------------------------------------------
325
  mem_block_t           *new_sdu_p    = NULL;
gauthier's avatar
gauthier committed
326
  rlc_mode_t             rlc_mode     = RLC_MODE_NONE;
327
  rlc_union_t           *rlc_union_p = NULL;
328
  hash_key_t             key         = HASHTABLE_NOT_A_KEY_VALUE;
329 330
  hashtable_rc_t         h_rc;

Cedric Roux's avatar
Cedric Roux committed
331
#if defined(Rel10) || defined(Rel14)
332 333
  rlc_mbms_id_t         *mbms_id_p  = NULL;
  logical_chan_id_t      log_ch_id  = 0;
334 335
#endif
#ifdef DEBUG_RLC_DATA_REQ
Cedric Roux's avatar
typo  
Cedric Roux committed
336
  LOG_D(RLC,PROTOCOL_CTXT_FMT"rlc_data_req:  rb_id %u (MAX %d), muip %d, confirmP %d, sdu_sizeP %d, sdu_pP %p\n",
337
        PROTOCOL_CTXT_ARGS(ctxt_pP),
gauthier's avatar
gauthier committed
338 339 340 341 342 343
        rb_idP,
        NB_RAB_MAX,
        muiP,
        confirmP,
        sdu_sizeP,
        sdu_pP);
344
#endif
Cedric Roux's avatar
Cedric Roux committed
345
#if defined(Rel10) || defined(Rel14)
346
#else
gauthier's avatar
gauthier committed
347
  AssertFatal(MBMS_flagP == 0, "MBMS_flagP %u", MBMS_flagP);
348
#endif
gauthier's avatar
gauthier committed
349
#ifdef OAI_EMU
350

351
  CHECK_CTXT_ARGS(ctxt_pP)
352

gauthier's avatar
gauthier committed
353
#endif
354

Cedric Roux's avatar
Cedric Roux committed
355 356 357 358 359
#if T_TRACER
  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));
#endif

360
  if (MBMS_flagP) {
361
    AssertFatal (rb_idP < NB_RB_MBMS_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MBMS_MAX);
362
  } else {
363
    AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
364
  }
365

gauthier's avatar
gauthier committed
366
  DevAssert(sdu_pP != NULL);
367 368
  DevCheck(sdu_sizeP > 0, sdu_sizeP, 0, 0);

Cedric Roux's avatar
Cedric Roux committed
369
#if !defined(Rel10) && !defined(Rel14)
370 371 372
  DevCheck(MBMS_flagP == 0, MBMS_flagP, 0, 0);
#endif

gauthier's avatar
gauthier committed
373
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_IN);
374

Cedric Roux's avatar
Cedric Roux committed
375
#if defined(Rel10) || defined(Rel14)
376

377
  if (MBMS_flagP == TRUE) {
378 379 380
    if (ctxt_pP->enb_flag) {
      log_ch_id = rlc_mbms_enb_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP);
      mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][log_ch_id];
381
    } else {
382 383
      log_ch_id = rlc_mbms_ue_get_lcid_by_rb_id(ctxt_pP->rnti,rb_idP);
      mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ctxt_pP->rnti][log_ch_id];
384 385
    }

386
    key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_id_p->service_id, mbms_id_p->session_id);
387 388 389
  } else
#endif
  {
390
    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
391 392 393
  }

  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
394

395
  if (h_rc == HASH_TABLE_OK) {
396
    rlc_mode = rlc_union_p->mode;
397
  } else {
398 399
    rlc_mode = RLC_MODE_NONE;
    AssertFatal (0 , "RLC not configured key %ju\n", key);
gauthier's avatar
gauthier committed
400 401
  }

402
  if (MBMS_flagP == 0) {
403 404
    LOG_D(RLC, PROTOCOL_CTXT_FMT"[RB %u] Display of rlc_data_req:\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
gauthier's avatar
gauthier committed
405
          rb_idP);
406
#if defined(TRACE_RLC_PAYLOAD)
407
    rlc_util_print_hex_octets(RLC, (unsigned char*)sdu_pP->data, sdu_sizeP);
408
#endif
409 410

#ifdef DEBUG_RLC_DATA_REQ
Cedric Roux's avatar
typo  
Cedric Roux committed
411
    LOG_D(RLC,"RLC_TYPE : %d\n", rlc_mode);
412
#endif
413 414 415

    switch (rlc_mode) {
    case RLC_MODE_NONE:
416
      free_mem_block(sdu_pP, __func__);
417 418
      LOG_E(RLC, PROTOCOL_CTXT_FMT" Received RLC_MODE_NONE as rlc_type for rb_id %u\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
419
            rb_idP);
gauthier's avatar
gauthier committed
420
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
421 422 423
      return RLC_OP_STATUS_BAD_PARAMETER;

    case RLC_MODE_AM:
424
#ifdef DEBUG_RLC_DATA_REQ
425
      LOG_D(RLC,"RLC_MODE_AM\n");
426
#endif
427
      new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_am_data_req_alloc), __func__);
428 429 430 431 432 433 434 435 436 437

      if (new_sdu_p != NULL) {
        // PROCESS OF COMPRESSION HERE:
        memset (new_sdu_p->data, 0, sizeof (struct rlc_am_data_req_alloc));
        memcpy (&new_sdu_p->data[sizeof (struct rlc_am_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);

        ((struct rlc_am_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
        ((struct rlc_am_data_req *) (new_sdu_p->data))->conf = confirmP;
        ((struct rlc_am_data_req *) (new_sdu_p->data))->mui  = muiP;
        ((struct rlc_am_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_am_data_req_alloc);
438
        free_mem_block(sdu_pP, __func__);
439
        rlc_am_data_req(ctxt_pP, &rlc_union_p->rlc.am, new_sdu_p);
gauthier's avatar
gauthier committed
440
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
441 442
        return RLC_OP_STATUS_OK;
      } else {
gauthier's avatar
gauthier committed
443
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
444
        free_mem_block(sdu_pP, __func__);
445 446 447 448 449 450
        return RLC_OP_STATUS_INTERNAL_ERROR;
      }

      break;

    case RLC_MODE_UM:
451
      new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc), __func__);
452 453 454 455 456 457 458 459

      if (new_sdu_p != NULL) {
        // PROCESS OF COMPRESSION HERE:
        memset (new_sdu_p->data, 0, sizeof (struct rlc_um_data_req_alloc));
        memcpy (&new_sdu_p->data[sizeof (struct rlc_um_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);

        ((struct rlc_um_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
        ((struct rlc_um_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
460
        free_mem_block(sdu_pP, __func__);
461

462
        rlc_um_data_req(ctxt_pP, &rlc_union_p->rlc.um, new_sdu_p);
463

464
        //free_mem_block(new_sdu, __func__);
gauthier's avatar
gauthier committed
465
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
466 467
        return RLC_OP_STATUS_OK;
      } else {
gauthier's avatar
gauthier committed
468
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
469
        free_mem_block(sdu_pP, __func__);
470 471
        return RLC_OP_STATUS_INTERNAL_ERROR;
      }
gauthier's avatar
gauthier committed
472

473 474 475
      break;

    case RLC_MODE_TM:
476
      new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_tm_data_req_alloc), __func__);
477 478 479 480 481 482 483 484

      if (new_sdu_p != NULL) {
        // PROCESS OF COMPRESSION HERE:
        memset (new_sdu_p->data, 0, sizeof (struct rlc_tm_data_req_alloc));
        memcpy (&new_sdu_p->data[sizeof (struct rlc_tm_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);

        ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
        ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_tm_data_req_alloc);
485
        free_mem_block(sdu_pP, __func__);
486
        rlc_tm_data_req(ctxt_pP, &rlc_union_p->rlc.tm, new_sdu_p);
gauthier's avatar
gauthier committed
487
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
488 489 490
        return RLC_OP_STATUS_OK;
      } else {
        //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : out of memory\n", __FILE__, __LINE__);
gauthier's avatar
gauthier committed
491
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
492
        free_mem_block(sdu_pP, __func__);
493
        return RLC_OP_STATUS_INTERNAL_ERROR;
gauthier's avatar
gauthier committed
494
      }
495

496 497 498
      break;

    default:
499
      free_mem_block(sdu_pP, __func__);
gauthier's avatar
gauthier committed
500
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
501 502 503 504
      return RLC_OP_STATUS_INTERNAL_ERROR;

    }

Cedric Roux's avatar
Cedric Roux committed
505
#if defined(Rel10) || defined(Rel14)
506
  } else { /* MBMS_flag != 0 */
507 508 509 510
    //  LOG_I(RLC,"DUY rlc_data_req: mbms_rb_id in RLC instant is: %d\n", mbms_rb_id);
    if (sdu_pP != NULL) {
      if (sdu_sizeP > 0) {
        LOG_I(RLC,"received a packet with size %d for MBMS \n", sdu_sizeP);
511
        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc), __func__);
512 513 514 515 516 517 518

        if (new_sdu_p != NULL) {
          // PROCESS OF COMPRESSION HERE:
          memset (new_sdu_p->data, 0, sizeof (struct rlc_um_data_req_alloc));
          memcpy (&new_sdu_p->data[sizeof (struct rlc_um_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
519
          free_mem_block(sdu_pP, __func__);
520
          rlc_um_data_req(ctxt_pP, &rlc_union_p->rlc.um, new_sdu_p);
521

522
          //free_mem_block(new_sdu, __func__);
gauthier's avatar
gauthier committed
523
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
524 525
          return RLC_OP_STATUS_OK;
        } else {
gauthier's avatar
gauthier committed
526
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
527
          free_mem_block(sdu_pP, __func__);
528 529 530
          return RLC_OP_STATUS_BAD_PARAMETER;
        }
      } else {
gauthier's avatar
gauthier committed
531
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
532 533 534
        return RLC_OP_STATUS_BAD_PARAMETER;
      }
    } else {
gauthier's avatar
gauthier committed
535
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
536 537
      return RLC_OP_STATUS_BAD_PARAMETER;
    }
538
  }
539

540
#else
541 542 543
  }
  else  /* MBMS_flag != 0 */
  {
544
    free_mem_block(sdu_pP, __func__);
Cedric Roux's avatar
Cedric Roux committed
545
    LOG_E(RLC, "MBMS_flag != 0 while Rel10/Rel14 is not defined...\n");
546
    //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : parameter module_id out of bounds :%d\n", __FILE__, __LINE__, module_idP);
gauthier's avatar
gauthier committed
547
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
548
    return RLC_OP_STATUS_BAD_PARAMETER;
549
  }
550

551
#endif
552 553 554
}

//-----------------------------------------------------------------------------
555
void rlc_data_ind     (
556
  const protocol_ctxt_t* const ctxt_pP,
557 558 559 560 561 562 563
  const srb_flag_t  srb_flagP,
  const MBMS_flag_t MBMS_flagP,
  const rb_id_t     rb_idP,
  const sdu_size_t  sdu_sizeP,
  mem_block_t      *sdu_pP)
{
  //-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
564 565


566 567 568
#if defined(TRACE_RLC_PAYLOAD)
  LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u] Display of rlc_data_ind: size %u\n",
        PROTOCOL_CTXT_ARGS(ctxt_pP),
569
        (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
570 571 572 573
        rb_idP,
        sdu_sizeP);

  rlc_util_print_hex_octets(RLC, (unsigned char*)sdu_pP->data, sdu_sizeP);
574
#endif
575

Cedric Roux's avatar
Cedric Roux committed
576 577 578 579 580 581
#if T_TRACER
  if (ctxt_pP->enb_flag)
    T(T_ENB_RLC_UL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_sizeP));
#endif


582
  pdcp_data_ind (
583
    ctxt_pP,
584 585 586 587 588
    srb_flagP,
    MBMS_flagP,
    rb_idP,
    sdu_sizeP,
    sdu_pP);
589 590
}
//-----------------------------------------------------------------------------
591
void rlc_data_conf     (const protocol_ctxt_t* const ctxt_pP,
592 593 594
                        const srb_flag_t      srb_flagP,
                        const rb_id_t         rb_idP,
                        const mui_t           muiP,
595 596 597 598 599 600
                        const rlc_tx_status_t statusP)
{
  //-----------------------------------------------------------------------------

  if (srb_flagP) {
    if (rlc_rrc_data_conf != NULL) {
601
      rlc_rrc_data_conf (ctxt_pP, rb_idP , muiP, statusP);
602
    }
603
  }
604 605 606
}
//-----------------------------------------------------------------------------
int
607
rlc_module_init (void)
608
{
609 610 611
  //-----------------------------------------------------------------------------
  int          k;
  module_id_t  module_id1;
gauthier's avatar
gauthier committed
612

Cedric Roux's avatar
Cedric Roux committed
613 614 615
  /* for no gcc warnings */
  (void)k;

616 617 618
  LOG_D(RLC, "MODULE INIT\n");
  rlc_rrc_data_ind  = NULL;
  rlc_rrc_data_conf = NULL;
gauthier's avatar
gauthier committed
619

620 621
  rlc_coll_p = hashtable_create ((maxDRB + 2) * 16, NULL, rb_free_rlc_union);
  AssertFatal(rlc_coll_p != NULL, "UNRECOVERABLE error, RLC hashtable_create failed");
gauthier's avatar
gauthier committed
622

623
  for (module_id1=0; module_id1 < NUMBER_OF_UE_MAX; module_id1++) {
Cedric Roux's avatar
Cedric Roux committed
624
#if defined(Rel10) || defined(Rel14)
625 626 627 628 629 630 631

    for (k=0; k < RLC_MAX_MBMS_LC; k++) {
      rlc_mbms_lcid2service_session_id_ue[module_id1][k].service_id = 0;
      rlc_mbms_lcid2service_session_id_ue[module_id1][k].session_id = 0;
    }

    for (k=0; k < NB_RB_MBMS_MAX; k++) {
632
      rlc_mbms_rbid2lcid_ue[module_id1][k] = RLC_LC_UNALLOCATED;
633 634
    }

gauthier's avatar
gauthier committed
635
#endif
636
  }
gauthier's avatar
gauthier committed
637

638
  for (module_id1=0; module_id1 < NUMBER_OF_eNB_MAX; module_id1++) {
Cedric Roux's avatar
Cedric Roux committed
639
#if defined(Rel10) || defined(Rel14)
640 641 642 643 644 645 646

    for (k=0; k < RLC_MAX_MBMS_LC; k++) {
      rlc_mbms_lcid2service_session_id_eNB[module_id1][k].service_id = 0;
      rlc_mbms_lcid2service_session_id_eNB[module_id1][k].session_id = 0;
    }

    for (k=0; k < NB_RB_MBMS_MAX; k++) {
647
      rlc_mbms_rbid2lcid_eNB[module_id1][k] = RLC_LC_UNALLOCATED;
648 649
    }

gauthier's avatar
gauthier committed
650
#endif
651
  }
gauthier's avatar
gauthier committed
652

653
  pool_buffer_init();
654

655
  return(0);
656 657 658
}
//-----------------------------------------------------------------------------
void
659
rlc_module_cleanup (void)
660 661
//-----------------------------------------------------------------------------
{
662
  hashtable_destroy(rlc_coll_p);
663 664 665
}
//-----------------------------------------------------------------------------
void
666
rlc_layer_init (void)
667
{
668
  //-----------------------------------------------------------------------------
669 670 671
}
//-----------------------------------------------------------------------------
void
672
rlc_layer_cleanup (void)
673 674 675 676
//-----------------------------------------------------------------------------
{
}