rlc_rrc.c 30.9 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
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
 */
Lionel Gauthier's avatar
Lionel Gauthier committed
21

22 23 24 25 26
/*
                                rlc_rrc.c
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
Lionel Gauthier's avatar
Lionel Gauthier committed
27
  EMAIL   : Lionel.Gauthier at eurecom dot fr
28 29 30 31 32 33 34
*/

#define RLC_RRC_C
#include "rlc.h"
#include "rlc_am.h"
#include "rlc_um.h"
#include "rlc_tm.h"
35
#include "common/utils/LOG/log.h"
36 37 38 39 40 41
#include "RLC-Config.h"
#include "DRB-ToAddMod.h"
#include "DRB-ToAddModList.h"
#include "SRB-ToAddMod.h"
#include "SRB-ToAddModList.h"
#include "DL-UM-RLC.h"
42
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
43 44 45
#include "PMCH-InfoList-r9.h"
#endif

46
#include "LAYER2/MAC/mac_extern.h"
47
#include "assertions.h"
48
//-----------------------------------------------------------------------------
49
rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP,
50 51 52
    const SRB_ToAddModList_t   * const srb2add_listP,
    const DRB_ToAddModList_t   * const drb2add_listP,
    const DRB_ToReleaseList_t  * const drb2release_listP
53
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
54
    ,const PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP
55 56
    ,const uint32_t sourceL2Id
    ,const uint32_t destinationL2Id
Lionel Gauthier's avatar
Lionel Gauthier committed
57
#endif
58 59
                                        )
{
Lionel Gauthier's avatar
Lionel Gauthier committed
60 61 62 63 64 65
  //-----------------------------------------------------------------------------
  rb_id_t                rb_id           = 0;
  logical_chan_id_t      lc_id           = 0;
  DRB_Identity_t         drb_id          = 0;
  DRB_Identity_t*        pdrb_id         = NULL;
  long int               cnt             = 0;
66 67 68
  const SRB_ToAddMod_t  *srb_toaddmod_p  = NULL;
  const DRB_ToAddMod_t  *drb_toaddmod_p  = NULL;
  rlc_union_t           *rlc_union_p     = NULL;
69
  hash_key_t             key             = HASHTABLE_NOT_A_KEY_VALUE;
70
  hashtable_rc_t         h_rc;
71
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
Lionel Gauthier's avatar
Lionel Gauthier committed
72 73 74 75
  int                        i, j;
  MBMS_SessionInfoList_r9_t *mbms_SessionInfoList_r9_p = NULL;
  MBMS_SessionInfo_r9_t     *MBMS_SessionInfo_p        = NULL;
  mbms_session_id_t          mbms_session_id;
76
  mbms_service_id_t          mbms_service_id;
Lionel Gauthier's avatar
Lionel Gauthier committed
77
  DL_UM_RLC_t                dl_um_rlc;
78 79


80
#endif
81

Cedric Roux's avatar
Cedric Roux committed
82 83 84 85 86
  /* for no gcc warnings */
  (void)rlc_union_p;
  (void)key;
  (void)h_rc;

87 88
  LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ ASN1 \n",
        PROTOCOL_CTXT_ARGS(ctxt_pP));
89

90
  if (srb2add_listP != NULL) {
91 92
    for (cnt=0; cnt<srb2add_listP->list.count; cnt++) {
      rb_id = srb2add_listP->list.array[cnt]->srb_Identity;
93
      lc_id = rb_id;
94

Cedric Roux's avatar
Cedric Roux committed
95
      LOG_D(RLC, "Adding SRB %ld, rb_id %d\n",srb2add_listP->list.array[cnt]->srb_Identity,rb_id);
96 97 98 99 100 101 102 103 104 105 106 107 108
      srb_toaddmod_p = srb2add_listP->list.array[cnt];

      if (srb_toaddmod_p->rlc_Config) {
        switch (srb_toaddmod_p->rlc_Config->present) {
        case SRB_ToAddMod__rlc_Config_PR_NOTHING:
          break;

        case SRB_ToAddMod__rlc_Config_PR_explicitValue:
          switch (srb_toaddmod_p->rlc_Config->choice.explicitValue.present) {
          case RLC_Config_PR_NOTHING:
            break;

          case RLC_Config_PR_am:
109
            if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_AM
110
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
111 112 113 114
                                ,0,
                                0
#endif
                  ) != NULL) {
115 116 117 118
              config_req_rlc_am_asn1 (
                ctxt_pP,
                SRB_FLAG_YES,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am,
119
                rb_id, lc_id);
120
            } else {
121 122
              LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                    PROTOCOL_CTXT_ARGS(ctxt_pP),
123 124 125 126 127 128
                    rb_id);
            }

            break;

          case RLC_Config_PR_um_Bi_Directional:
129
            if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM
130
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
131 132 133 134
                                ,0,
                                0
#endif
            ) != NULL) {
135 136 137 138 139 140 141 142
              config_req_rlc_um_asn1(
                ctxt_pP,
                SRB_FLAG_YES,
                MBMS_FLAG_NO,
                UNUSED_PARAM_MBMS_SESSION_ID,
                UNUSED_PARAM_MBMS_SERVICE_ID,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Bi_Directional.ul_UM_RLC,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Bi_Directional.dl_UM_RLC,
143
                rb_id, lc_id
144
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
145 146 147
               ,0, 0
#endif
               );
148
            } else {
149 150
              LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                    PROTOCOL_CTXT_ARGS(ctxt_pP),
151 152 153 154 155 156
                    rb_id);
            }

            break;

          case RLC_Config_PR_um_Uni_Directional_UL:
157
            if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM
158
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
159 160 161 162
                                 ,0,
                                 0
#endif
                  ) != NULL) {
163 164 165 166 167 168 169 170
              config_req_rlc_um_asn1(
                ctxt_pP,
                SRB_FLAG_YES,
                MBMS_FLAG_NO,
                UNUSED_PARAM_MBMS_SESSION_ID,
                UNUSED_PARAM_MBMS_SERVICE_ID,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_UL.ul_UM_RLC,
                NULL,
171
                rb_id, lc_id
172
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
173 174 175
               ,0, 0
#endif
               );
176
            } else {
177 178
              LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                    PROTOCOL_CTXT_ARGS(ctxt_pP),
179 180 181 182 183 184
                    rb_id);
            }

            break;

          case RLC_Config_PR_um_Uni_Directional_DL:
185
            if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM
186
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
187 188 189 190
                                 ,0,
                                 0
#endif
                                 ) != NULL) {
191 192 193 194 195 196 197 198
              config_req_rlc_um_asn1(
                ctxt_pP,
                SRB_FLAG_YES,
                MBMS_FLAG_NO,
                UNUSED_PARAM_MBMS_SESSION_ID,
                UNUSED_PARAM_MBMS_SERVICE_ID,
                NULL,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_DL.dl_UM_RLC,
199
                rb_id, lc_id
200
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
201 202 203
               ,0, 0
#endif
               );
204
            } else {
205 206
              LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                    PROTOCOL_CTXT_ARGS(ctxt_pP),
207 208 209 210 211 212
                    rb_id);
            }

            break;

          default:
213 214
            LOG_E(RLC, PROTOCOL_CTXT_FMT" UNKNOWN RLC CONFIG %d \n",
                  PROTOCOL_CTXT_ARGS(ctxt_pP),
215 216 217 218 219 220 221
                  srb_toaddmod_p->rlc_Config->choice.explicitValue.present);
            break;
          }

          break;

        case SRB_ToAddMod__rlc_Config_PR_defaultValue:
222
//#warning TO DO SRB_ToAddMod__rlc_Config_PR_defaultValue
223 224 225 226 227 228 229 230 231
          LOG_I(RRC, "RLC SRB1 is default value !!\n");
          struct RLC_Config__am  *  config_am_pP = &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am;
          config_am_pP->dl_AM_RLC.t_Reordering     = T_Reordering_ms35;
          config_am_pP->dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms0;
          config_am_pP->ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms45;
          config_am_pP->ul_AM_RLC.pollPDU          = PollPDU_pInfinity;
          config_am_pP->ul_AM_RLC.pollByte         = PollByte_kBinfinity;
          config_am_pP->ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t4;

232
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_AM
233
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
234 235 236 237
                               ,0,
                               0
#endif
                               ) != NULL) {
238 239 240 241
            config_req_rlc_am_asn1 (
              ctxt_pP,
              SRB_FLAG_YES,
              &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am,
242
              rb_id,lc_id);
243 244 245 246 247 248
          } else {
            LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                  PROTOCOL_CTXT_ARGS(ctxt_pP),
                  rb_id);
          }
/*
249 250 251 252 253 254 255 256 257
          if (rrc_rlc_add_rlc   (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM) != NULL) {
            config_req_rlc_um_asn1(
              ctxt_pP,
              SRB_FLAG_YES,
              MBMS_FLAG_NO,
              UNUSED_PARAM_MBMS_SESSION_ID,
              UNUSED_PARAM_MBMS_SERVICE_ID,
              NULL, // TO DO DEFAULT CONFIG
              NULL, // TO DO DEFAULT CONFIG
258
              rb_id, lc_id);
259
          } else {
260 261
            LOG_D(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                  PROTOCOL_CTXT_ARGS(ctxt_pP),
262
                  rb_id);
263
          }
264
          */
265 266 267 268 269 270

          break;

        default:
          ;
        }
271
      }
272
    }
273
  }
274

275
  if (drb2add_listP != NULL) {
276 277 278 279
    for (cnt=0; cnt<drb2add_listP->list.count; cnt++) {
      drb_toaddmod_p = drb2add_listP->list.array[cnt];

      drb_id = drb_toaddmod_p->drb_Identity;
280 281 282 283 284 285 286 287 288 289 290 291
      if (drb_toaddmod_p->logicalChannelIdentity) {
        lc_id = *drb_toaddmod_p->logicalChannelIdentity;
      } else {
        LOG_E(RLC, PROTOCOL_CTXT_FMT" logicalChannelIdentity is missing from drb-ToAddMod information element!\n", PROTOCOL_CTXT_ARGS(ctxt_pP));
        continue;
      }

      if (lc_id == 1 || lc_id == 2) {
        LOG_E(RLC, PROTOCOL_CTXT_FMT" logicalChannelIdentity = %d is invalid in RRC message when adding DRB!\n", PROTOCOL_CTXT_ARGS(ctxt_pP), lc_id);
        continue;
      }

Cedric Roux's avatar
Cedric Roux committed
292
      LOG_D(RLC, "Adding DRB %ld, lc_id %d\n",drb_id,lc_id);
293 294 295 296 297 298 299 300

      if (drb_toaddmod_p->rlc_Config) {

        switch (drb_toaddmod_p->rlc_Config->present) {
        case RLC_Config_PR_NOTHING:
          break;

        case RLC_Config_PR_am:
301
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_AM
302
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
303 304 305 306
                               ,0,
                               0
#endif
            ) != NULL) {
307 308 309 310
            config_req_rlc_am_asn1 (
              ctxt_pP,
              SRB_FLAG_NO,
              &drb_toaddmod_p->rlc_Config->choice.am,
311
              drb_id, lc_id);
312 313 314 315 316
          }

          break;

        case RLC_Config_PR_um_Bi_Directional:
317
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM
318
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
319 320 321 322
                               ,sourceL2Id,
                               destinationL2Id
#endif
              ) != NULL) {
323 324 325 326 327 328 329 330
            config_req_rlc_um_asn1(
              ctxt_pP,
              SRB_FLAG_NO,
              MBMS_FLAG_NO,
              UNUSED_PARAM_MBMS_SESSION_ID,
              UNUSED_PARAM_MBMS_SERVICE_ID,
              &drb_toaddmod_p->rlc_Config->choice.um_Bi_Directional.ul_UM_RLC,
              &drb_toaddmod_p->rlc_Config->choice.um_Bi_Directional.dl_UM_RLC,
331
              drb_id, lc_id
332
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
333 334 335 336
              ,sourceL2Id,
              destinationL2Id
#endif
              );
337 338 339 340 341
          }

          break;

        case RLC_Config_PR_um_Uni_Directional_UL:
342
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM
343
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
344 345 346 347
                              ,0,
                               0
#endif
             ) != NULL) {
348 349 350 351 352 353 354 355
            config_req_rlc_um_asn1(
              ctxt_pP,
              SRB_FLAG_NO,
              MBMS_FLAG_NO,
              UNUSED_PARAM_MBMS_SESSION_ID,
              UNUSED_PARAM_MBMS_SERVICE_ID,
              &drb_toaddmod_p->rlc_Config->choice.um_Uni_Directional_UL.ul_UM_RLC,
              NULL,
356
              drb_id, lc_id
357
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
358 359 360
               ,0, 0
#endif
               );
361 362 363 364 365
          }

          break;

        case RLC_Config_PR_um_Uni_Directional_DL:
366
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM
367
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
368 369 370 371
                              ,0,
                               0
#endif
                               ) != NULL) {
372 373 374 375 376 377 378 379
            config_req_rlc_um_asn1(
              ctxt_pP,
              SRB_FLAG_NO,
              MBMS_FLAG_NO,
              UNUSED_PARAM_MBMS_SESSION_ID,
              UNUSED_PARAM_MBMS_SERVICE_ID,
              NULL,
              &drb_toaddmod_p->rlc_Config->choice.um_Uni_Directional_DL.dl_UM_RLC,
380
              drb_id, lc_id
381
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
382 383 384
               ,0, 0
#endif
               );
385
          }
386 387 388 389

          break;

        default:
Cedric Roux's avatar
Cedric Roux committed
390
          LOG_W(RLC, PROTOCOL_CTXT_FMT"[RB %ld] unknown drb_toaddmod_p->rlc_Config->present \n",
391
                PROTOCOL_CTXT_ARGS(ctxt_pP),
392 393
                drb_id);
        }
394
      }
395
    }
396
  }
397

398
  if (drb2release_listP != NULL) {
399 400 401 402 403 404 405 406
    for (cnt=0; cnt<drb2release_listP->list.count; cnt++) {
      pdrb_id = drb2release_listP->list.array[cnt];
      rrc_rlc_remove_rlc(
        ctxt_pP,
        SRB_FLAG_NO,
        MBMS_FLAG_NO,
        *pdrb_id);
    }
407 408
  }

409
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
410

Lionel Gauthier's avatar
Lionel Gauthier committed
411
  if (pmch_InfoList_r9_pP != NULL) {
412 413 414 415 416
    for (i=0; i<pmch_InfoList_r9_pP->list.count; i++) {
      mbms_SessionInfoList_r9_p = &(pmch_InfoList_r9_pP->list.array[i]->mbms_SessionInfoList_r9);

      for (j=0; j<mbms_SessionInfoList_r9_p->list.count; j++) {
        MBMS_SessionInfo_p = mbms_SessionInfoList_r9_p->list.array[j];
417 418 419 420
        if (MBMS_SessionInfo_p->sessionId_r9)
          mbms_session_id  = MBMS_SessionInfo_p->sessionId_r9->buf[0];
        else
          mbms_session_id  = MBMS_SessionInfo_p->logicalChannelIdentity_r9;
421 422
        lc_id              = mbms_session_id;
        mbms_service_id    = MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2]; //serviceId is 3-octet string
423
//        mbms_service_id    = j;
424 425 426 427

        // can set the mch_id = i
        if (ctxt_pP->enb_flag) {
          rb_id =  (mbms_service_id * maxSessionPerPMCH ) + mbms_session_id;//+ (maxDRB + 3) * MAX_MOBILES_PER_ENB; // 1
428 429 430
          rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lc_id].service_id                     = mbms_service_id;
          rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lc_id].session_id                     = mbms_session_id;
          rlc_mbms_enb_set_lcid_by_rb_id(ctxt_pP->module_id,rb_id,lc_id);
431 432 433

        } else {
          rb_id =  (mbms_service_id * maxSessionPerPMCH ) + mbms_session_id; // + (maxDRB + 3); // 15
434 435 436
          rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lc_id].service_id                    = mbms_service_id;
          rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lc_id].session_id                    = mbms_session_id;
          rlc_mbms_ue_set_lcid_by_rb_id(ctxt_pP->module_id,rb_id,lc_id);
437 438
        }

439
        key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->module_id, ctxt_pP->enb_flag, mbms_service_id, mbms_session_id);
440 441 442 443 444 445 446 447 448 449

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

        if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) {
          rlc_union_p = rrc_rlc_add_rlc   (
                          ctxt_pP,
                          SRB_FLAG_NO,
                          MBMS_FLAG_YES,
                          rb_id,
                          lc_id,
450
                          RLC_MODE_UM, 0, 0);
teramoto.genki's avatar
teramoto.genki committed
451
          //AssertFatal(rlc_union_p != NULL, "ADD MBMS RLC UM FAILED");
452 453 454
          if(rlc_union_p == NULL){
            LOG_E(RLC, "ADD MBMS RLC UM FAILED\n");
          }
455 456
        }

457 458
        LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ MBMS ASN1 LC ID %u RB ID %u SESSION ID %u SERVICE ID %u\n",
              PROTOCOL_CTXT_ARGS(ctxt_pP),
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
              lc_id,
              rb_id,
              mbms_session_id,
              mbms_service_id
             );
        dl_um_rlc.sn_FieldLength = SN_FieldLength_size5;
        dl_um_rlc.t_Reordering   = T_Reordering_ms0;

        config_req_rlc_um_asn1 (
          ctxt_pP,
          SRB_FLAG_NO,
          MBMS_FLAG_YES,
          mbms_session_id,
          mbms_service_id,
          NULL,
          &dl_um_rlc,
475
          rb_id, lc_id
476
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
477 478 479
          ,0, 0
#endif
               );
480
      }
481
    }
482
  }
483

484
#endif
485

486 487
  LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ ASN1 END \n",
        PROTOCOL_CTXT_ARGS(ctxt_pP));
488 489 490
  return RLC_OP_STATUS_OK;
}
//-----------------------------------------------------------------------------
491
void
492
rb_free_rlc_union (
493
  void *rlcu_pP)
494
{
495
  //-----------------------------------------------------------------------------
496
  rlc_union_t * rlcu_p;
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520

  if (rlcu_pP) {
    rlcu_p = (rlc_union_t *)(rlcu_pP);
    LOG_D(RLC,"%s %p \n",__FUNCTION__,rlcu_pP);

    switch (rlcu_p->mode) {
    case RLC_MODE_AM:
      rlc_am_cleanup(&rlcu_p->rlc.am);
      break;

    case RLC_MODE_UM:
      rlc_um_cleanup(&rlcu_p->rlc.um);
      break;

    case RLC_MODE_TM:
      rlc_tm_cleanup(&rlcu_p->rlc.tm);
      break;

    default:
      LOG_W(RLC,
            "%s %p unknown RLC type\n",
            __FUNCTION__,
            rlcu_pP);
      break;
521
    }
522
  }
523
}
524

Lionel Gauthier's avatar
 
Lionel Gauthier committed
525 526
//-----------------------------------------------------------------------------
rlc_op_status_t rrc_rlc_remove_ue (
527 528 529 530
  const protocol_ctxt_t* const ctxt_pP)
{
  //-----------------------------------------------------------------------------
  rb_id_t                rb_id;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
531

532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
  for (rb_id = 1; rb_id <= 2; rb_id++) {
    rrc_rlc_remove_rlc(ctxt_pP,
                       SRB_FLAG_YES,
                       MBMS_FLAG_NO,
                       rb_id);
  }

  for (rb_id = 1; rb_id <= maxDRB; rb_id++) {
    rrc_rlc_remove_rlc(ctxt_pP,
                       SRB_FLAG_NO,
                       MBMS_FLAG_NO,
                       rb_id);
  }

  return RLC_OP_STATUS_OK;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
547 548
}

549
//-----------------------------------------------------------------------------
550
rlc_op_status_t rrc_rlc_remove_rlc   (
551 552 553 554 555 556 557
  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)
{
  //-----------------------------------------------------------------------------
  logical_chan_id_t      lcid            = 0;
558
  hash_key_t             key             = HASHTABLE_NOT_A_KEY_VALUE;
559
  hashtable_rc_t         h_rc;
560 561
  hash_key_t             key_lcid        = HASHTABLE_NOT_A_KEY_VALUE;
  hashtable_rc_t         h_lcid_rc;
562
  rlc_union_t           *rlc_union_p = NULL;
563
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
564
  rlc_mbms_id_t         *mbms_id_p  = NULL;
565
#endif
566

Cedric Roux's avatar
Cedric Roux committed
567 568 569
  /* for no gcc warnings */
  (void)lcid;

570
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
571

572
  if (MBMS_flagP == TRUE) {
573
    if (ctxt_pP->enb_flag) {
574 575 576 577 578
      lcid = 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][lcid];
      rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0;
      rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0;
      rlc_mbms_rbid2lcid_ue[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED;
579 580

    } else {
581 582 583 584 585
      lcid = rlc_mbms_ue_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP);
      mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lcid];
      rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0;
      rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0;
      rlc_mbms_rbid2lcid_ue[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED;
586 587
    }

588
    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);
589 590 591
  } else
#endif
  {
592
    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
593 594 595
  }


teramoto.genki's avatar
teramoto.genki committed
596 597 598 599 600
  //AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
	if(rb_idP >= NB_RB_MAX){
		LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
		return RLC_OP_STATUS_BAD_PARAMETER;
	}
601

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

604
  if (h_rc == HASH_TABLE_OK) {
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
    // also remove the hash-key created by LC-id
    switch (rlc_union_p->mode) {
    case RLC_MODE_AM:
      lcid = rlc_union_p->rlc.am.channel_id;
      break;
    case RLC_MODE_UM:
      lcid = rlc_union_p->rlc.um.channel_id;
      break;
    case RLC_MODE_TM:
      lcid = rlc_union_p->rlc.tm.channel_id;
      break;
    default:
      LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] RLC mode is unknown!\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
            (srb_flagP) ? "SRB" : "DRB",
            rb_idP);
    }
    key_lcid = RLC_COLL_KEY_LCID_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, lcid, srb_flagP);
    h_lcid_rc = hashtable_get(rlc_coll_p, key_lcid, (void**)&rlc_union_p);
  } else {
    h_lcid_rc = HASH_TABLE_KEY_NOT_EXISTS;
  }

  if ((h_rc == HASH_TABLE_OK) && (h_lcid_rc == HASH_TABLE_OK)) {
    h_lcid_rc = hashtable_remove(rlc_coll_p, key_lcid);
630
    h_rc = hashtable_remove(rlc_coll_p, key);
631
    LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u LCID %d] RELEASED %s\n",
632
          PROTOCOL_CTXT_ARGS(ctxt_pP),
633
          (srb_flagP) ? "SRB" : "DRB",
634
          rb_idP, lcid,
635
          (srb_flagP) ? "SRB" : "DRB");
636 637
  } else if ((h_rc == HASH_TABLE_KEY_NOT_EXISTS) || (h_lcid_rc == HASH_TABLE_KEY_NOT_EXISTS)) {
    LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u LCID %d] RELEASE : RLC NOT FOUND %s, by RB-ID=%d, by LC-ID=%d\n",
638
          PROTOCOL_CTXT_ARGS(ctxt_pP),
639
          (srb_flagP) ? "SRB" : "DRB",
640 641 642
          rb_idP, lcid,
          (srb_flagP) ? "SRB" : "DRB",
          h_rc, h_lcid_rc);
643
  } else {
644
    LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u LCID %d] RELEASE : INTERNAL ERROR %s\n",
645
          PROTOCOL_CTXT_ARGS(ctxt_pP),
646
          (srb_flagP) ? "SRB" : "DRB",
647
          rb_idP, lcid,
648 649 650 651
          (srb_flagP) ? "SRB" : "DRB");
  }

  return RLC_OP_STATUS_OK;
652 653
}
//-----------------------------------------------------------------------------
654
rlc_union_t* rrc_rlc_add_rlc   (
655 656 657 658 659
  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 logical_chan_id_t chan_idP,
660
  const rlc_mode_t        rlc_modeP
661
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
662 663 664 665
  ,const uint32_t sourceL2Id,
  const uint32_t  destinationL2Id
#endif
)
666
{
667

668
  //-----------------------------------------------------------------------------
669
  hash_key_t             key         = HASHTABLE_NOT_A_KEY_VALUE;
670
  hashtable_rc_t         h_rc;
671 672
  hash_key_t             key_lcid    = HASHTABLE_NOT_A_KEY_VALUE;
  hashtable_rc_t         h_lcid_rc;
673
  rlc_union_t           *rlc_union_p = NULL;
674
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
675 676
  rlc_mbms_id_t         *mbms_id_p  = NULL;
  logical_chan_id_t      lcid            = 0;
677
#endif
678

679

680
  if (MBMS_flagP == FALSE) {
teramoto.genki's avatar
teramoto.genki committed
681 682 683 684 685 686 687 688 689 690 691
    //AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
    //AssertFatal (chan_idP < RLC_MAX_LC, "LC id is too high (%u/%d)!\n", chan_idP, RLC_MAX_LC);
  	if(rb_idP >= NB_RB_MAX){
  		LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
  		return NULL;
  	}
  	if(chan_idP >= RLC_MAX_LC){
  		LOG_E(RLC, "LC id is too high (%u/%d)!\n", chan_idP, RLC_MAX_LC);
  		return NULL;
  	}

692
  }
693

694
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
695

696
  if (MBMS_flagP == TRUE) {
697
    if (ctxt_pP->enb_flag) {
698 699 700 701 702
      lcid = 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][lcid];
      //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0;
      //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0;
      //LG 2014-04-15rlc_mbms_rbid2lcid_eNB[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED;
703 704

    } else {
705 706 707 708 709
      lcid = rlc_mbms_ue_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP);
      mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lcid];
      //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0;
      //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0;
      //LG 2014-04-15rlc_mbms_rbid2lcid_ue[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED;
710 711
    }

712
    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);
713 714 715 716
  }
  if ((sourceL2Id > 0) && (destinationL2Id > 0) ){
     key = RLC_COLL_KEY_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, sourceL2Id, destinationL2Id, srb_flagP);
     key_lcid = RLC_COLL_KEY_LCID_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, chan_idP, sourceL2Id, destinationL2Id, srb_flagP);
717 718 719
  } else
#endif
  {
720
    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
721
    key_lcid = RLC_COLL_KEY_LCID_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, chan_idP, srb_flagP);
722 723 724
  }

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

726
  if (h_rc == HASH_TABLE_OK) {
727 728
    LOG_W(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc , already exist %s\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
729 730 731
          (srb_flagP) ? "SRB" : "DRB",
          rb_idP,
          (srb_flagP) ? "SRB" : "DRB");
teramoto.genki's avatar
teramoto.genki committed
732 733 734 735 736 737
    //AssertFatal(rlc_union_p->mode == rlc_modeP, "Error rrc_rlc_add_rlc , already exist but RLC mode differ");
  	if(rlc_union_p->mode != rlc_modeP){
  		LOG_E(RLC, "Error rrc_rlc_add_rlc , already exist but RLC mode differ\n");
  		return NULL;
  	}
  	return rlc_union_p;
738
  } else if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) {
739 740
    rlc_union_p = calloc(1, sizeof(rlc_union_t));
    h_rc = hashtable_insert(rlc_coll_p, key, rlc_union_p);
741
    h_lcid_rc = hashtable_insert(rlc_coll_p, key_lcid, rlc_union_p);
742

743
    if ((h_rc == HASH_TABLE_OK) && (h_lcid_rc == HASH_TABLE_OK)) {
744
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
745 746

      if (MBMS_flagP == TRUE) {
747 748
        LOG_I(RLC, PROTOCOL_CTXT_FMT" RLC service id %u session id %u rrc_rlc_add_rlc\n",
              PROTOCOL_CTXT_ARGS(ctxt_pP),
749 750 751
              mbms_id_p->service_id,
              mbms_id_p->session_id);
      } else
Lionel Gauthier's avatar
Lionel Gauthier committed
752
#endif
753
      {
754 755
        LOG_I(RLC, PROTOCOL_CTXT_FMT" [%s %u] rrc_rlc_add_rlc  %s\n",
              PROTOCOL_CTXT_ARGS(ctxt_pP),
756 757 758 759
              (srb_flagP) ? "SRB" : "DRB",
              rb_idP,
              (srb_flagP) ? "SRB" : "DRB");
      }
760 761 762 763

      rlc_union_p->mode = rlc_modeP;
      return rlc_union_p;
    } else {
764
      LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc FAILED %s (add by RB_id=%d; add by LC_id=%d)\n",
765
            PROTOCOL_CTXT_ARGS(ctxt_pP),
766 767
            (srb_flagP) ? "SRB" : "DRB",
            rb_idP,
768 769
            (srb_flagP) ? "SRB" : "DRB",
            h_rc, h_lcid_rc);
770 771 772 773
      free(rlc_union_p);
      rlc_union_p = NULL;
      return NULL;
    }
774
  } else {
775 776
    LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc , INTERNAL ERROR %s\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
777 778 779 780 781
          (srb_flagP) ? "SRB" : "DRB",
          rb_idP,
          (srb_flagP) ? "SRB" : "DRB");
  }
  return NULL;
782 783
}
//-----------------------------------------------------------------------------
784
rlc_op_status_t rrc_rlc_config_req   (
785 786 787 788 789 790 791 792
  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)
{
  //-----------------------------------------------------------------------------
793
  //rlc_op_status_t status;
794

795 796
  LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG_REQ for RAB %u\n",
        PROTOCOL_CTXT_ARGS(ctxt_pP),
797 798
        rb_idP);

teramoto.genki's avatar
teramoto.genki committed
799 800 801 802 803
  //AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
	if(rb_idP >= NB_RB_MAX){
		LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
		return RLC_OP_STATUS_BAD_PARAMETER;
	}
804 805 806 807

  switch (actionP) {

  case CONFIG_ACTION_ADD:
808
    if (rrc_rlc_add_rlc(ctxt_pP, srb_flagP, MBMS_FLAG_NO, rb_idP, rb_idP, rlc_infoP.rlc_mode
809
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
810 811 812 813
                        ,0,
                        0
#endif
    ) != NULL) {
814 815 816 817 818 819 820
      return RLC_OP_STATUS_INTERNAL_ERROR;
    }

    // no break, fall to next case
  case CONFIG_ACTION_MODIFY:
    switch (rlc_infoP.rlc_mode) {
    case RLC_MODE_AM:
821 822
      LOG_I(RLC, PROTOCOL_CTXT_FMT"[RB %u] MODIFY RB AM\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
823 824
            rb_idP);

825 826 827 828
      config_req_rlc_am(
        ctxt_pP,
        srb_flagP,
        &rlc_infoP.rlc.rlc_am_info,
829
        rb_idP, rb_idP);
830 831 832
      break;

    case RLC_MODE_UM:
833 834
      LOG_I(RLC, PROTOCOL_CTXT_FMT"[RB %u] MODIFY RB UM\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
835 836 837 838 839
            rb_idP);
      config_req_rlc_um(
        ctxt_pP,
        srb_flagP,
        &rlc_infoP.rlc.rlc_um_info,
840
        rb_idP, rb_idP);
841 842 843
      break;

    case RLC_MODE_TM:
844 845
      LOG_I(RLC, PROTOCOL_CTXT_FMT"[RB %u] MODIFY RB TM\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
846 847 848 849 850
            rb_idP);
      config_req_rlc_tm(
        ctxt_pP,
        srb_flagP,
        &rlc_infoP.rlc.rlc_tm_info,
851
        rb_idP, rb_idP);
852 853 854 855
      break;

    default:
      return RLC_OP_STATUS_BAD_PARAMETER;
856
    }
857

858
    break;
859

860 861 862
  case CONFIG_ACTION_REMOVE:
    return rrc_rlc_remove_rlc(ctxt_pP, srb_flagP, mbms_flagP, rb_idP);
    break;
863

864 865 866 867 868
  default:
    return RLC_OP_STATUS_BAD_PARAMETER;
  }

  return RLC_OP_STATUS_OK;
869 870
}
//-----------------------------------------------------------------------------
871
rlc_op_status_t rrc_rlc_data_req     (
872 873 874 875 876 877 878 879 880
  const protocol_ctxt_t* const ctxt_pP,
  const MBMS_flag_t MBMS_flagP,
  const rb_id_t     rb_idP,
  const mui_t       muiP,
  const confirm_t   confirmP,
  const sdu_size_t  sdu_sizeP,
  char* sduP)
{
  //-----------------------------------------------------------------------------
881 882
  mem_block_t*   sdu;

883
  sdu = get_free_mem_block(sdu_sizeP, __func__);
884

885 886
  if (sdu != NULL) {
    memcpy (sdu->data, sduP, sdu_sizeP);
887
    return rlc_data_req(ctxt_pP, SRB_FLAG_YES, MBMS_flagP, rb_idP, muiP, confirmP, sdu_sizeP, sdu
888
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
889 890 891
                        ,NULL, NULL
#endif
                        );
892 893 894 895 896 897
  } else {
    return RLC_OP_STATUS_INTERNAL_ERROR;
  }
}

//-----------------------------------------------------------------------------
898 899 900 901 902
void rrc_rlc_register_rrc (rrc_data_ind_cb_t rrc_data_indP, rrc_data_conf_cb_t rrc_data_confP)
{
  //-----------------------------------------------------------------------------
  rlc_rrc_data_ind  = rrc_data_indP;
  rlc_rrc_data_conf = rrc_data_confP;
903 904
}