//-----------------------------------------------------------------------------
void config_req_rlc_um (
    const module_id_t     enb_module_idP,
    const module_id_t     ue_module_idP,
    const frame_t         frameP,
    const eNB_flag_t      eNB_flagP,
    const srb_flag_t      srb_flagP,
    const rlc_um_info_t  * const config_um_pP,
    const rb_id_t         rb_idP)
{
  //-----------------------------------------------------------------------------
  rlc_union_t     *rlc_union_p  = NULL;
  rlc_um_entity_t *rlc_p        = NULL;
  hash_key_t       key          = RLC_COLL_KEY_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, rb_idP, srb_flagP);
  hashtable_rc_t   h_rc;

  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
  if (h_rc == HASH_TABLE_OK) {
      rlc_p = &rlc_union_p->rlc.um;
      LOG_D(RLC, "[FRAME %05d][%s][RRC][MOD %u/%u][][--- CONFIG_REQ timer_reordering=%d sn_field_length=%d is_mXch=%d --->][RLC_UM][MOD %u/%u][RB %u]    \n",
          frameP,
          (eNB_flagP) ? "eNB" : "UE",
          enb_module_idP,
          ue_module_idP,
          config_um_pP->timer_reordering,
          config_um_pP->sn_field_length,
          config_um_pP->is_mXch,
          enb_module_idP,
          ue_module_idP,
          rb_idP);

      rlc_um_init(rlc_p);
      if (rlc_um_fsm_notify_event (rlc_p, RLC_UM_RECEIVE_CRLC_CONFIG_REQ_ENTER_DATA_TRANSFER_READY_STATE_EVENT)) {
          rlc_um_set_debug_infos(rlc_p, enb_module_idP, ue_module_idP, frameP, eNB_flagP, srb_flagP, rb_idP);
          rlc_um_configure(rlc_p,
              frameP,
              config_um_pP->timer_reordering,
              config_um_pP->sn_field_length,
              config_um_pP->sn_field_length,
              config_um_pP->is_mXch);
      }
  } else {
      LOG_E(RLC, "[FRAME %05d][%s][RRC][MOD %u/%u][][--- CONFIG_REQ --->][RLC_UM][MOD %u/%u][RB %u]  RLC NOT FOUND\n",
          frameP,
          (eNB_flagP) ? "eNB" : "UE",
          enb_module_idP,
          ue_module_idP,
          enb_module_idP,
          ue_module_idP,
          rb_idP);  }
}
//-----------------------------------------------------------------------------
void config_req_rlc_um (
  const protocol_ctxt_t* const ctxt_pP,
  const srb_flag_t      srb_flagP,
  const rlc_um_info_t  * const config_um_pP,
  const rb_id_t         rb_idP)
{
  rlc_union_t     *rlc_union_p  = NULL;
  rlc_um_entity_t *rlc_p        = NULL;
  hash_key_t       key          = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
  hashtable_rc_t   h_rc;

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

  if (h_rc == HASH_TABLE_OK) {
    rlc_p = &rlc_union_p->rlc.um;
    LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" CONFIG_REQ timer_reordering=%d sn_field_length=%d is_mXch=%d RB %u\n",
          PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
          config_um_pP->timer_reordering,
          config_um_pP->sn_field_length,
          config_um_pP->is_mXch,
          rb_idP);

    rlc_um_init(ctxt_pP, rlc_p);

    if (rlc_um_fsm_notify_event (ctxt_pP, rlc_p, RLC_UM_RECEIVE_CRLC_CONFIG_REQ_ENTER_DATA_TRANSFER_READY_STATE_EVENT)) {
      rlc_um_set_debug_infos(ctxt_pP, rlc_p, srb_flagP, rb_idP);
      rlc_um_configure(
        ctxt_pP,
        rlc_p,
        config_um_pP->timer_reordering,
        config_um_pP->sn_field_length,
        config_um_pP->sn_field_length,
        config_um_pP->is_mXch);
    }
  } else {
    LOG_E(RLC, PROTOCOL_RLC_UM_CTXT_FMT"  CONFIG_REQ RB %u  RLC UM NOT FOUND\n",
          PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
          rb_idP);
  }
}
void config_req_rlc_um_asn1 (
    const module_id_t         enb_module_idP,
    const module_id_t         ue_module_idP,
    const frame_t             frameP,
    const eNB_flag_t          eNB_flagP,
    const srb_flag_t          srb_flagP,
    const MBMS_flag_t         mbms_flagP,
    const mbms_session_id_t   mbms_session_idP,
    const mbms_service_id_t   mbms_service_idP,
    const UL_UM_RLC_t       * const ul_rlc_pP,
    const DL_UM_RLC_t       * const dl_rlc_pP,
    const rb_id_t             rb_idP)
{
  uint32_t         ul_sn_FieldLength   = 0;
  uint32_t         dl_sn_FieldLength   = 0;
  uint32_t         t_Reordering        = 0;
  rlc_union_t     *rlc_union_p         = NULL;
  rlc_um_entity_t *rlc_p               = NULL;
  hash_key_t       key                 = RLC_COLL_KEY_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, rb_idP, srb_flagP);
  hashtable_rc_t   h_rc;

#if defined(Rel10)
  if (mbms_flagP) {
      AssertFatal(dl_rlc_pP, "No RLC UM DL config");
      AssertFatal(ul_rlc_pP == NULL, "RLC UM UL config present");
      key = RLC_COLL_KEY_MBMS_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, mbms_service_idP, mbms_session_idP);
      h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
      AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u ue id %i enb flag %u service id %u, session id %u",
          enb_module_idP,
          ue_module_idP,
          eNB_flagP,
          mbms_service_idP,
          mbms_session_idP);
      rlc_p = &rlc_union_p->rlc.um;
  }
  else
#endif
  {
      key  = RLC_COLL_KEY_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, rb_idP, srb_flagP);
      h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
      AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u ue id %i enb flag %u rb id %u, srb flag %u",
          enb_module_idP,
          ue_module_idP,
          eNB_flagP,
          rb_idP,
          srb_flagP);
      rlc_p = &rlc_union_p->rlc.um;
  }

  //-----------------------------------------------------------------------------
  LOG_D(RLC, "[FRAME %05d][%s][RRC][MOD %u/%u][][--- CONFIG_REQ timer_reordering=%dms sn_field_length=  --->][RLC_UM][MOD %u/%u][RB %u]    \n",
      frameP,
      (eNB_flagP) ? "eNB" : "UE",
      enb_module_idP,
      ue_module_idP,
      (dl_rlc_pP->t_Reordering<31)?t_Reordering_tab[dl_rlc_pP->t_Reordering]:-1,
      enb_module_idP,
      ue_module_idP,
      rb_idP);

  rlc_um_init(rlc_p);
  if (rlc_um_fsm_notify_event (rlc_p, RLC_UM_RECEIVE_CRLC_CONFIG_REQ_ENTER_DATA_TRANSFER_READY_STATE_EVENT)) {
      rlc_um_set_debug_infos(rlc_p, enb_module_idP, ue_module_idP, frameP, eNB_flagP, srb_flagP, rb_idP);
      if (ul_rlc_pP != NULL) {
          switch (ul_rlc_pP->sn_FieldLength) {
          case SN_FieldLength_size5:
            ul_sn_FieldLength = 5;
            break;
          case SN_FieldLength_size10:
            ul_sn_FieldLength = 10;
            break;
          default:
            LOG_E(RLC,"[FRAME %05d][%s][RLC_UM][MOD %u/%u][RB %u][CONFIGURE] INVALID Uplink sn_FieldLength %d, RLC NOT CONFIGURED\n",
                frameP,
                (rlc_p->is_enb) ? "eNB" : "UE",
                    rlc_p->enb_module_id,
                    rlc_p->ue_module_id,
                    rlc_p->rb_id,
                    ul_rlc_pP->sn_FieldLength);
            return;
          }
      }

      if (dl_rlc_pP != NULL) {
          switch (dl_rlc_pP->sn_FieldLength) {
          case SN_FieldLength_size5:
            dl_sn_FieldLength = 5;
            break;
          case SN_FieldLength_size10:
            dl_sn_FieldLength = 10;
            break;
          default:
            LOG_E(RLC,"[FRAME %05d][%s][RLC_UM][MOD %u/%u][RB %u][CONFIGURE] INVALID Downlink sn_FieldLength %d, RLC NOT CONFIGURED\n",
                frameP,
                (rlc_p->is_enb) ? "eNB" : "UE",
                    rlc_p->enb_module_id,
                    rlc_p->ue_module_id,
                    rlc_p->rb_id,
                    dl_rlc_pP->sn_FieldLength);
            return;
          }
          if (dl_rlc_pP->t_Reordering<T_Reordering_spare1) {
              t_Reordering = t_Reordering_tab[dl_rlc_pP->t_Reordering];
          } else {
              LOG_E(RLC,"[FRAME %05d][%s][RLC_UM][MOD %u/%u][RB %u][CONFIGURE] INVALID T_Reordering %d, RLC NOT CONFIGURED\n",
                  frameP,
                  (rlc_p->is_enb) ? "eNB" : "UE",
                      rlc_p->enb_module_id,
                      rlc_p->ue_module_id,
                      rlc_p->rb_id,
                      dl_rlc_pP->t_Reordering);
              return;
          }
      }
      if (eNB_flagP > 0) {
          rlc_um_configure(rlc_p,
              frameP,
              t_Reordering,
              ul_sn_FieldLength,
              dl_sn_FieldLength,
              mbms_flagP);
      } else {
          rlc_um_configure(rlc_p,
              frameP,
              t_Reordering,
              dl_sn_FieldLength,
              ul_sn_FieldLength,
              mbms_flagP);
      }
  }
}
void config_req_rlc_um_asn1 (
  const protocol_ctxt_t* const ctxt_pP,
  const srb_flag_t          srb_flagP,
  const MBMS_flag_t         mbms_flagP,
  const mbms_session_id_t   mbms_session_idP,
  const mbms_service_id_t   mbms_service_idP,
  const UL_UM_RLC_t       * const ul_rlc_pP,
  const DL_UM_RLC_t       * const dl_rlc_pP,
  const rb_id_t             rb_idP)
{
  uint32_t         ul_sn_FieldLength   = 0;
  uint32_t         dl_sn_FieldLength   = 0;
  uint32_t         t_Reordering        = 0;
  rlc_union_t     *rlc_union_p         = NULL;
  rlc_um_entity_t *rlc_p               = NULL;
  hash_key_t       key                 = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
  hashtable_rc_t   h_rc;

#if Rel10

  if (mbms_flagP) {
    AssertFatal(dl_rlc_pP, "No RLC UM DL config");
    AssertFatal(ul_rlc_pP == NULL, "RLC UM UL config present");
    key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_service_idP, mbms_session_idP);
    h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
    AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u rnti %i enb flag %u service id %u, session id %u",
                 ctxt_pP->module_id,
                 ctxt_pP->rnti,
                 ctxt_pP->enb_flag,
                 mbms_service_idP,
                 mbms_session_idP);
    rlc_p = &rlc_union_p->rlc.um;
  } else
#endif
  {
    key  = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
    h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
    AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u ue id %i enb flag %u rb id %u, srb flag %u",
                 ctxt_pP->module_id,
                 ctxt_pP->rnti,
                 ctxt_pP->enb_flag,
                 rb_idP,
                 srb_flagP);
    rlc_p = &rlc_union_p->rlc.um;
  }

  //-----------------------------------------------------------------------------
  LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT"  CONFIG_REQ timer_reordering=%dms sn_field_length=   RB %u \n",
        PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
        (dl_rlc_pP && dl_rlc_pP->t_Reordering<31)?t_Reordering_tab[dl_rlc_pP->t_Reordering]:-1,
        rb_idP);

  rlc_um_init(ctxt_pP, rlc_p);


  if (rlc_um_fsm_notify_event (ctxt_pP, rlc_p, RLC_UM_RECEIVE_CRLC_CONFIG_REQ_ENTER_DATA_TRANSFER_READY_STATE_EVENT)) {
    rlc_um_set_debug_infos(ctxt_pP,rlc_p, srb_flagP, rb_idP);

    if (ul_rlc_pP != NULL) {
      switch (ul_rlc_pP->sn_FieldLength) {
      case SN_FieldLength_size5:
        ul_sn_FieldLength = 5;
        break;

      case SN_FieldLength_size10:
        ul_sn_FieldLength = 10;
        break;

      default:
        LOG_E(RLC,PROTOCOL_RLC_UM_CTXT_FMT" [CONFIGURE] RB %u INVALID UL sn_FieldLength %d, RLC NOT CONFIGURED\n",
              PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
              rlc_p->rb_id,
              ul_rlc_pP->sn_FieldLength);
        MSC_LOG_RX_DISCARDED_MESSAGE(
      	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
      	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE,
      	    NULL,
      	    0,
      	    MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ UL sn_FieldLength %u",
      	    MSC_AS_TIME_ARGS(ctxt_pP),
      	    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p),
      	    ul_rlc_pP->sn_FieldLength);
        return;
      }
    }

    if (dl_rlc_pP != NULL) {
      switch (dl_rlc_pP->sn_FieldLength) {
      case SN_FieldLength_size5:
        dl_sn_FieldLength = 5;
        break;

      case SN_FieldLength_size10:
        dl_sn_FieldLength = 10;
        break;

      default:
        LOG_E(RLC,PROTOCOL_RLC_UM_CTXT_FMT" [CONFIGURE] RB %u INVALID DL sn_FieldLength %d, RLC NOT CONFIGURED\n",
              PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
              rlc_p->rb_id,
              dl_rlc_pP->sn_FieldLength);
        MSC_LOG_RX_DISCARDED_MESSAGE(
      	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
      	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE,
      	    NULL,
      	    0,
      	    MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ DL sn_FieldLength %u",
      	    MSC_AS_TIME_ARGS(ctxt_pP),
      	    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p),
      	    dl_rlc_pP->sn_FieldLength);
        return;
      }

      if (dl_rlc_pP->t_Reordering<T_Reordering_spare1) {
        t_Reordering = t_Reordering_tab[dl_rlc_pP->t_Reordering];
      } else {
        LOG_E(RLC,PROTOCOL_RLC_UM_CTXT_FMT" [CONFIGURE] RB %u INVALID T_Reordering %d, RLC NOT CONFIGURED\n",
              PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
              rlc_p->rb_id,
              dl_rlc_pP->t_Reordering);

        MSC_LOG_RX_DISCARDED_MESSAGE(
      	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
      	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE,
      	    NULL,
      	    0,
      	    MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ t_Reord %u",
      	    MSC_AS_TIME_ARGS(ctxt_pP),
      	    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p),
      	    dl_rlc_pP->t_Reordering);
        return;
      }
    }

    if (ctxt_pP->enb_flag > 0) {
      rlc_um_configure(ctxt_pP,rlc_p,
                       t_Reordering,
                       ul_sn_FieldLength,
                       dl_sn_FieldLength,
                       mbms_flagP);
      MSC_LOG_RX_MESSAGE(
    	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
    	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE,
    	    NULL,
    	    0,
    	    MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ t_Reord %u rx snfl %u tx snfl %u",
    	    MSC_AS_TIME_ARGS(ctxt_pP),
    	    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p),
    	    t_Reordering,
    	    ul_sn_FieldLength,
    	    dl_sn_FieldLength);
    } else {

      rlc_um_configure(ctxt_pP,rlc_p,
                       t_Reordering,
                       dl_sn_FieldLength,
                       ul_sn_FieldLength,
                       mbms_flagP);
      MSC_LOG_RX_MESSAGE(
    	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
    	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE,
    	    NULL,
    	    0,
    	    MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ t_Reord %u rx snfl %u tx snfl %u",
    	    MSC_AS_TIME_ARGS(ctxt_pP),
    	    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p),
    	    t_Reordering,
    	    dl_sn_FieldLength,
    	    ul_sn_FieldLength);
    }
  }
}