rlc_rrc.c 25.5 KB
Newer Older
Lionel Gauthier's avatar
Lionel Gauthier committed
1
/*******************************************************************************
Lionel Gauthier's avatar
Lionel Gauthier committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
Lionel Gauthier's avatar
Lionel Gauthier committed
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
Lionel Gauthier's avatar
Lionel Gauthier committed
27 28

 *******************************************************************************/
29 30 31 32 33
/*
                                rlc_rrc.c
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
Lionel Gauthier's avatar
Lionel Gauthier committed
34
  EMAIL   : Lionel.Gauthier at eurecom dot fr
35 36 37 38 39 40 41 42
*/

#define RLC_RRC_C
#include "rlc.h"
#include "rlc_am.h"
#include "rlc_um.h"
#include "rlc_tm.h"
#include "UTIL/LOG/log.h"
43 44 45
#ifdef OAI_EMU
#include "UTIL/OCG/OCG_vars.h"
#endif
46 47 48 49 50 51 52 53 54 55 56
#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"
#ifdef Rel10
#include "PMCH-InfoList-r9.h"
#endif

#include "LAYER2/MAC/extern.h"
57
#include "assertions.h"
58
//-----------------------------------------------------------------------------
59
rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP,
60 61 62
    const SRB_ToAddModList_t   * const srb2add_listP,
    const DRB_ToAddModList_t   * const drb2add_listP,
    const DRB_ToReleaseList_t  * const drb2release_listP
Lionel Gauthier's avatar
Lionel Gauthier committed
63
#if defined(Rel10)
64
    ,const PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP
Lionel Gauthier's avatar
Lionel Gauthier committed
65
#endif
66 67
                                        )
{
Lionel Gauthier's avatar
Lionel Gauthier committed
68 69 70 71 72 73
  //-----------------------------------------------------------------------------
  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;
74 75 76
  const SRB_ToAddMod_t  *srb_toaddmod_p  = NULL;
  const DRB_ToAddMod_t  *drb_toaddmod_p  = NULL;
  rlc_union_t           *rlc_union_p     = NULL;
77
  hash_key_t             key             = HASHTABLE_NOT_A_KEY_VALUE;
78
  hashtable_rc_t         h_rc;
Lionel Gauthier's avatar
Lionel Gauthier committed
79 80 81 82 83
#if defined(Rel10)
  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;
84
  mbms_service_id_t          mbms_service_id;
Lionel Gauthier's avatar
Lionel Gauthier committed
85
  DL_UM_RLC_t                dl_um_rlc;
86 87


88
#endif
89

Cedric Roux's avatar
Cedric Roux committed
90 91 92 93 94
  /* for no gcc warnings */
  (void)rlc_union_p;
  (void)key;
  (void)h_rc;

95 96
  LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ ASN1 \n",
        PROTOCOL_CTXT_ARGS(ctxt_pP));
97 98

#ifdef OAI_EMU
99

100
  CHECK_CTXT_ARGS(ctxt_pP)
101

102
#endif
103

104
  if (srb2add_listP != NULL) {
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
    for (cnt=0; cnt<srb2add_listP->list.count; cnt++) {
      rb_id = srb2add_listP->list.array[cnt]->srb_Identity;
      lc_id  = rb_id + 2;

      LOG_D(RLC, "Adding SRB %d, rb_id %d\n",srb2add_listP->list.array[cnt]->srb_Identity,rb_id);
      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:
            if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_AM) != NULL) {
              config_req_rlc_am_asn1 (
                ctxt_pP,
                SRB_FLAG_YES,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am,
                rb_id);
            } else {
130 131
              LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                    PROTOCOL_CTXT_ARGS(ctxt_pP),
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
                    rb_id);
            }

            break;

          case RLC_Config_PR_um_Bi_Directional:
            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,
                &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,
                rb_id);
            } 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 157 158 159 160 161 162 163 164 165 166 167
                    rb_id);
            }

            break;

          case RLC_Config_PR_um_Uni_Directional_UL:
            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,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_UL.ul_UM_RLC,
                NULL,
                rb_id);
            } else {
168 169
              LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                    PROTOCOL_CTXT_ARGS(ctxt_pP),
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
                    rb_id);
            }

            break;

          case RLC_Config_PR_um_Uni_Directional_DL:
            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,
                &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_DL.dl_UM_RLC,
                rb_id);
            } else {
187 188
              LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                    PROTOCOL_CTXT_ARGS(ctxt_pP),
189 190 191 192 193 194
                    rb_id);
            }

            break;

          default:
195 196
            LOG_E(RLC, PROTOCOL_CTXT_FMT" UNKNOWN RLC CONFIG %d \n",
                  PROTOCOL_CTXT_ARGS(ctxt_pP),
197 198 199 200 201 202 203
                  srb_toaddmod_p->rlc_Config->choice.explicitValue.present);
            break;
          }

          break;

        case SRB_ToAddMod__rlc_Config_PR_defaultValue:
204
//#warning TO DO SRB_ToAddMod__rlc_Config_PR_defaultValue
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
          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;

          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_AM) != NULL) {
            config_req_rlc_am_asn1 (
              ctxt_pP,
              SRB_FLAG_YES,
              &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am,
              rb_id);
          } else {
            LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                  PROTOCOL_CTXT_ARGS(ctxt_pP),
                  rb_id);
          }
/*
226 227 228 229 230 231 232 233 234 235 236
          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
              rb_id);
          } else {
237 238
            LOG_D(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n",
                  PROTOCOL_CTXT_ARGS(ctxt_pP),
239
                  rb_id);
240
          }
241
          */
242 243 244 245 246 247

          break;

        default:
          ;
        }
248
      }
249
    }
250
  }
251

252
  if (drb2add_listP != NULL) {
253 254 255 256 257 258
    for (cnt=0; cnt<drb2add_listP->list.count; cnt++) {
      drb_toaddmod_p = drb2add_listP->list.array[cnt];

      drb_id = drb_toaddmod_p->drb_Identity;
      lc_id  = drb_id + 2;

259
      LOG_I(RLC, "Adding DRB %d, lc_id %d\n",drb_id,lc_id);
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 312 313 314 315 316 317 318 319


      if (drb_toaddmod_p->rlc_Config) {

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

        case RLC_Config_PR_am:
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_AM) != NULL) {
            config_req_rlc_am_asn1 (
              ctxt_pP,
              SRB_FLAG_NO,
              &drb_toaddmod_p->rlc_Config->choice.am,
              drb_id);
          }

          break;

        case RLC_Config_PR_um_Bi_Directional:
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM) != NULL) {
            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,
              drb_id);
          }

          break;

        case RLC_Config_PR_um_Uni_Directional_UL:
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM) != NULL) {
            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,
              drb_id);
          }

          break;

        case RLC_Config_PR_um_Uni_Directional_DL:
          if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM) != NULL) {
            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,
              drb_id);
320
          }
321 322 323 324

          break;

        default:
325 326
          LOG_W(RLC, PROTOCOL_CTXT_FMT"[RB %u] unknown drb_toaddmod_p->rlc_Config->present \n",
                PROTOCOL_CTXT_ARGS(ctxt_pP),
327 328
                drb_id);
        }
329
      }
330
    }
331
  }
332

333
  if (drb2release_listP != NULL) {
334 335 336 337 338 339 340 341
    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);
    }
342 343
  }

Lionel Gauthier's avatar
Lionel Gauthier committed
344
#if defined(Rel10)
345

Lionel Gauthier's avatar
Lionel Gauthier committed
346
  if (pmch_InfoList_r9_pP != NULL) {
347 348 349 350 351 352 353 354 355 356 357 358
    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];
        mbms_session_id    = MBMS_SessionInfo_p->sessionId_r9->buf[0];
        lc_id              = mbms_session_id;
        mbms_service_id    = MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2]; //serviceId is 3-octet string

        // 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
359 360 361
          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);
362 363 364

        } else {
          rb_id =  (mbms_service_id * maxSessionPerPMCH ) + mbms_session_id; // + (maxDRB + 3); // 15
365 366 367
          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);
368 369
        }

370
        key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->module_id, ctxt_pP->enb_flag, mbms_service_id, mbms_session_id);
371 372 373 374 375 376 377 378 379 380 381 382 383 384

        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,
                          RLC_MODE_UM);
          AssertFatal(rlc_union_p != NULL, "ADD MBMS RLC UM FAILED");
        }

385 386
        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),
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
              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,
          rb_id);
404
      }
405
    }
406
  }
407

408
#endif
409

410 411
  LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ ASN1 END \n",
        PROTOCOL_CTXT_ARGS(ctxt_pP));
412 413 414
  return RLC_OP_STATUS_OK;
}
//-----------------------------------------------------------------------------
415
void
416
rb_free_rlc_union (
417
  void *rlcu_pP)
418
{
419
  //-----------------------------------------------------------------------------
420
  rlc_union_t * rlcu_p;
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444

  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;
445
    }
446
  }
447
}
448

Lionel Gauthier's avatar
 
Lionel Gauthier committed
449 450
//-----------------------------------------------------------------------------
rlc_op_status_t rrc_rlc_remove_ue (
451 452 453 454
  const protocol_ctxt_t* const ctxt_pP)
{
  //-----------------------------------------------------------------------------
  rb_id_t                rb_id;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
455

456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
  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
471 472
}

473
//-----------------------------------------------------------------------------
474
rlc_op_status_t rrc_rlc_remove_rlc   (
475 476 477 478 479 480 481
  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;
482
  hash_key_t             key             = HASHTABLE_NOT_A_KEY_VALUE;
483 484
  hashtable_rc_t         h_rc;
  rlc_union_t           *rlc_union_p = NULL;
485
#ifdef Rel10
486
  rlc_mbms_id_t         *mbms_id_p  = NULL;
487
#endif
488
#ifdef OAI_EMU
489
  CHECK_CTXT_ARGS(ctxt_pP)
490

491
#endif
492

Cedric Roux's avatar
Cedric Roux committed
493 494 495
  /* for no gcc warnings */
  (void)lcid;

496
#ifdef Rel10
497

498
  if (MBMS_flagP == TRUE) {
499
    if (ctxt_pP->enb_flag) {
500 501 502 503 504
      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;
505 506

    } else {
507 508 509 510 511
      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;
512 513
    }

514
    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);
515 516 517
  } else
#endif
  {
518
    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
519 520 521
  }


522
  AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
523

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

526 527
  if (h_rc == HASH_TABLE_OK) {
    h_rc = hashtable_remove(rlc_coll_p, key);
528 529
    LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u] RELEASED %s\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
530 531 532 533
          (srb_flagP) ? "SRB" : "DRB",
          rb_idP,
          (srb_flagP) ? "SRB" : "DRB");
  } else if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) {
534 535
    LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u] RELEASE : RLC NOT FOUND %s\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
536 537 538 539
          (srb_flagP) ? "SRB" : "DRB",
          rb_idP,
          (srb_flagP) ? "SRB" : "DRB");
  } else {
540 541
    LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] RELEASE : INTERNAL ERROR %s\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
542 543 544 545 546 547
          (srb_flagP) ? "SRB" : "DRB",
          rb_idP,
          (srb_flagP) ? "SRB" : "DRB");
  }

  return RLC_OP_STATUS_OK;
548 549
}
//-----------------------------------------------------------------------------
550
rlc_union_t* rrc_rlc_add_rlc   (
551 552 553 554 555 556 557 558
  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,
  const rlc_mode_t        rlc_modeP)
{
  //-----------------------------------------------------------------------------
559
  hash_key_t             key         = HASHTABLE_NOT_A_KEY_VALUE;
560 561 562
  hashtable_rc_t         h_rc;
  rlc_union_t           *rlc_union_p = NULL;
#ifdef Rel10
563 564
  rlc_mbms_id_t         *mbms_id_p  = NULL;
  logical_chan_id_t      lcid            = 0;
565
#endif
566

567
#ifdef OAI_EMU
568

569
  CHECK_CTXT_ARGS(ctxt_pP)
570

571
#endif
572 573 574 575 576

  if (MBMS_flagP == FALSE) {
    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);
  }
577

578
#ifdef Rel10
579

580
  if (MBMS_flagP == TRUE) {
581
    if (ctxt_pP->enb_flag) {
582 583 584 585 586
      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;
587 588

    } else {
589 590 591 592 593
      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;
594 595
    }

596
    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);
597 598 599
  } else
#endif
  {
600
    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
601 602 603
  }

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

605
  if (h_rc == HASH_TABLE_OK) {
606 607
    LOG_W(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc , already exist %s\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
608 609 610
          (srb_flagP) ? "SRB" : "DRB",
          rb_idP,
          (srb_flagP) ? "SRB" : "DRB");
611 612
    AssertFatal(rlc_union_p->mode == rlc_modeP, "Error rrc_rlc_add_rlc , already exist but RLC mode differ");
    return rlc_union_p;
613
  } else if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) {
614 615 616 617
    rlc_union_p = calloc(1, sizeof(rlc_union_t));
    h_rc = hashtable_insert(rlc_coll_p, key, rlc_union_p);

    if (h_rc == HASH_TABLE_OK) {
Lionel Gauthier's avatar
Lionel Gauthier committed
618
#ifdef Rel10
619 620

      if (MBMS_flagP == TRUE) {
621 622
        LOG_I(RLC, PROTOCOL_CTXT_FMT" RLC service id %u session id %u rrc_rlc_add_rlc\n",
              PROTOCOL_CTXT_ARGS(ctxt_pP),
623 624 625
              mbms_id_p->service_id,
              mbms_id_p->session_id);
      } else
Lionel Gauthier's avatar
Lionel Gauthier committed
626
#endif
627
      {
628 629
        LOG_I(RLC, PROTOCOL_CTXT_FMT" [%s %u] rrc_rlc_add_rlc  %s\n",
              PROTOCOL_CTXT_ARGS(ctxt_pP),
630 631 632 633
              (srb_flagP) ? "SRB" : "DRB",
              rb_idP,
              (srb_flagP) ? "SRB" : "DRB");
      }
634 635 636 637

      rlc_union_p->mode = rlc_modeP;
      return rlc_union_p;
    } else {
638 639
      LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc  FAILED %s\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
640 641 642 643 644 645 646
            (srb_flagP) ? "SRB" : "DRB",
            rb_idP,
            (srb_flagP) ? "SRB" : "DRB");
      free(rlc_union_p);
      rlc_union_p = NULL;
      return NULL;
    }
647
  } else {
648 649
    LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc , INTERNAL ERROR %s\n",
          PROTOCOL_CTXT_ARGS(ctxt_pP),
650 651 652 653
          (srb_flagP) ? "SRB" : "DRB",
          rb_idP,
          (srb_flagP) ? "SRB" : "DRB");
  }
654

655
  return NULL;
656 657
}
//-----------------------------------------------------------------------------
658
rlc_op_status_t rrc_rlc_config_req   (
659 660 661 662 663 664 665 666
  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)
{
  //-----------------------------------------------------------------------------
667
  //rlc_op_status_t status;
668

669 670
  LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG_REQ for RAB %u\n",
        PROTOCOL_CTXT_ARGS(ctxt_pP),
671 672 673
        rb_idP);

#ifdef OAI_EMU
674

675
  CHECK_CTXT_ARGS(ctxt_pP)
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690

#endif
  AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);

  switch (actionP) {

  case CONFIG_ACTION_ADD:
    if (rrc_rlc_add_rlc(ctxt_pP, srb_flagP, MBMS_FLAG_NO, rb_idP, rb_idP, rlc_infoP.rlc_mode) != NULL) {
      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:
691 692
      LOG_I(RLC, PROTOCOL_CTXT_FMT"[RB %u] MODIFY RB AM\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
693 694
            rb_idP);

695 696 697 698 699 700 701 702
      config_req_rlc_am(
        ctxt_pP,
        srb_flagP,
        &rlc_infoP.rlc.rlc_am_info,
        rb_idP);
      break;

    case RLC_MODE_UM:
703 704
      LOG_I(RLC, PROTOCOL_CTXT_FMT"[RB %u] MODIFY RB UM\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
705 706 707 708 709 710 711 712 713
            rb_idP);
      config_req_rlc_um(
        ctxt_pP,
        srb_flagP,
        &rlc_infoP.rlc.rlc_um_info,
        rb_idP);
      break;

    case RLC_MODE_TM:
714 715
      LOG_I(RLC, PROTOCOL_CTXT_FMT"[RB %u] MODIFY RB TM\n",
            PROTOCOL_CTXT_ARGS(ctxt_pP),
716 717 718 719 720 721 722 723 724 725
            rb_idP);
      config_req_rlc_tm(
        ctxt_pP,
        srb_flagP,
        &rlc_infoP.rlc.rlc_tm_info,
        rb_idP);
      break;

    default:
      return RLC_OP_STATUS_BAD_PARAMETER;
726
    }
727

728
    break;
729

730 731 732
  case CONFIG_ACTION_REMOVE:
    return rrc_rlc_remove_rlc(ctxt_pP, srb_flagP, mbms_flagP, rb_idP);
    break;
733

734 735 736 737 738
  default:
    return RLC_OP_STATUS_BAD_PARAMETER;
  }

  return RLC_OP_STATUS_OK;
739 740
}
//-----------------------------------------------------------------------------
741
rlc_op_status_t rrc_rlc_data_req     (
742 743 744 745 746 747 748 749 750
  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)
{
  //-----------------------------------------------------------------------------
751 752 753
  mem_block_t*   sdu;

  sdu = get_free_mem_block(sdu_sizeP);
754

755 756
  if (sdu != NULL) {
    memcpy (sdu->data, sduP, sdu_sizeP);
757
    return rlc_data_req(ctxt_pP, SRB_FLAG_YES, MBMS_flagP, rb_idP, muiP, confirmP, sdu_sizeP, sdu);
758 759 760 761 762 763
  } else {
    return RLC_OP_STATUS_INTERNAL_ERROR;
  }
}

//-----------------------------------------------------------------------------
764 765 766 767 768
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;
769 770
}