diff --git a/openair2/LAYER2/MAC/defs_NB_IoT.h b/openair2/LAYER2/MAC/defs_NB_IoT.h
index a427de5b2cfdf37fc5f9cd7df40144f893b0c3e0..77c0828b283076bd4edce975379dfe99f4bbd321 100644
--- a/openair2/LAYER2/MAC/defs_NB_IoT.h
+++ b/openair2/LAYER2/MAC/defs_NB_IoT.h
@@ -1,543 +1,543 @@
-
-/*! \file defs_NB_IoT.c
- * \brief MAC layer structures
- * \author  NTUST BMW Lab./
- * \date 2017
- * \email: 
- * \version 1.0
- *
- */
-#ifndef __LAYER2_MAC_DEFS_NB_IOT_H__
-#define __LAYER2_MAC_DEFS_NB_IOT_H__
-#ifdef USER_MODE
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#endif
-//#include "COMMON/openair_defs.h"
-#include "COMMON/platform_constants.h"
-#include "COMMON/mac_rrc_primitives.h"
-#include "PHY/LTE_TRANSPORT/defs_NB_IoT.h"
-//#include "PHY/defs.h"
-#include "PHY/defs_L1_NB_IoT.h"
-#include "openair2/PHY_INTERFACE/IF_Module_NB_IoT.h"
-#include "config_NB_IoT.h"
-//  MAC definition
-#define MAX_FRAME 0xfffff
-#define NUM_FRAME 0x100000
-#define MAX_SUBFRAME 10485760
-
-#define MAX(a, b) (((a)>(b))?(a):(b))
-
-//  RA-RNTI: 1+SFN_id>>2
-#define RA_RNTI_LOW   0x0001  //  SFN_id = 0
-#define RA_RNTI_HIGH  0x0100  //  SFN_id = 1023
-#define C_RNTI_LOW  0x0101
-#define C_RNTI_HIGH 
-
-// ULSCH LCHAN IDs
-/*!\brief LCID of extended power headroom for ULSCH */
-#define EXTENDED_POWER_HEADROOM 25
-/*!\brief LCID of power headroom for ULSCH */
-#define POWER_HEADROOM 26
-/*!\brief LCID of CRNTI for ULSCH */
-#define CRNTI 27
-/*!\brief LCID of truncated BSR for ULSCH */
-#define TRUNCATED_BSR 28
-/*!\brief LCID of short BSR for ULSCH */
-#define SHORT_BSR 29
-/*!\brief LCID of long BSR for ULSCH */
-#define LONG_BSR 30
-/*! \brief Values of CCCH LCID for DLSCH */ 
-#define CCCH_LCHANID 0
-/*!\brief Values of BCCH logical channel */
-#define BCCH 3  // SI 
-/*!\brief Values of PCCH logical channel */
-#define PCCH 4  // Paging 
-/*!\brief Value of CCCH / SRB0 logical channel */
-#define CCCH 0  // srb0
-/*!\brief DCCH / SRB1 logical channel */
-#define DCCH 1  // srb1
-/*!\brief DCCH1 / SRB2  logical channel */
-#define DCCH1 2 // srb2
-/*!\brief DTCH DRB1  logical channel */
-#define DTCH 3 // LCID
-/*!\brief MCCH logical channel */
-#define MCCH 4 
-/*!\brief MTCH logical channel */
-#define MTCH 1 
-// DLSCH LCHAN ID
-/*!\brief LCID of UE contention resolution identity for DLSCH*/
-#define UE_CONT_RES 28
-/*!\brief LCID of timing advance for DLSCH */
-#define TIMING_ADV_CMD 29
-/*!\brief LCID of discontinous reception mode for DLSCH */
-#define DRX_CMD 30
-/*!\brief LCID of padding LCID for DLSCH */
-#define SHORT_PADDING 31
-
-
-typedef enum tone_type_e
-{
-  sixtone = 0,
-  threetone,
-  singletone1,
-  singletone2,
-  singletone3
-}tone_type_t;
-
-typedef enum channel_NB_IoT_e
-{
-  NPDCCH = 0,
-  NPUSCH,
-  NPDSCH
-}channel_NB_IoT_t;
-
-typedef enum{
-  UL = 0,
-  DL
-}message_direction_t;
-
-#define MAX_NUMBER_OF_UE_MAX_NB_IoT 20
-#define SCH_PAYLOAD_SIZE_MAX_NB_IoT 320
-#define MAX_NUMBER_OF_SIBs_NB_IoT 16
-
-/*!\brief Values of BCCH0 logical channel for MIB*/
-#define BCCH0_NB_IoT 11 // MIB-NB_IoT
-/*!\brief Values of BCCH1 logical channel for SIBs */
-#define BCCH1_NB_IoT 12 // SI-SIB-NB_IoTs
-/*!\brief Values of PCCH logical channel */
-#define PCCH_NB_IoT 13  // Paging XXX not used for the moment
-#define MCCH_NB_IoT 14
-/*!\brief Value of CCCH / SRB0 logical channel */
-#define CCCH_NB_IoT 0  // srb0 ---> XXX exactly the same as in LTE (commented for compilation purposes)
-/*!\brief DCCH0 / SRB1bis logical channel */
-#define DCCH0_NB_IoT 3  // srb1bis
-/*!\brief DCCH1 / SRB1  logical channel */
-#define DCCH1_NB_IoT 1 // srb1 //XXX we redefine it for the SRB1
-/*!\brief DTCH0 DRB0  logical channel */
-#define DTCH0_NB_IoT 4 // DRB0
-/*!\brief DTCH1 DRB1  logical channel */
-#define DTCH1_NB_IoT 5 // DRB1
-/*Index of UE contention resoulution logical channel*/
-#define UE_CONTENTION_RESOLUTION 28
-/*Index of TIMING_ADVANCE logical channel*/
-#define TIMING_ADVANCE 29
-/*Index of DRX_COMMAND logical channel*/
-#define DRX_COMMAND 30
-/*Index of PADDING logical channel*/
-#define PADDING 31
-
-
-/// NPRACH-ParametersList-NB_IoT-r13 from 36.331 RRC spec defined in PHY
-/*typedef struct NPRACH_Parameters_NB_IoT{
-
-    /// the period time for nprach
-    int nprach_Periodicity;
-    /// for the start time for the NPRACH resource from 40ms-2560ms
-    int nprach_StartTime;
-    /// for the subcarrier of set to the NPRACH preamble from n0 - n34
-    int nprach_SubcarrierOffset;
-    ///number of subcarriers in a NPRACH resource allowed values (n12,n24,n36,n48)
-    int nprach_NumSubcarriers;
-    /// where is the region that in NPRACH resource to indicate if this UE support MSG3 for multi-tone or not. from 0 - 1
-    int nprach_SubcarrierMSG3_RangeStart;
-    /// The max preamble transmission attempt for the CE level from 1 - 128
-    int maxNumPreambleAttemptCE;
-    /// Number of NPRACH repetitions per attempt for each NPRACH resource
-    int numRepetitionsPerPreambleAttempt;
-    /// The number of the repetition for DCI use in RAR/MSG3/MSG4 from 1 - 2048 (Rmax)
-    int npdcch_NumRepetitions_RA;
-    /// Starting subframe for NPDCCH Common searching space for (RAR/MSG3/MSG4)
-    int npdcch_StartSF_CSS_RA;
-    /// Fractional period offset of starting subframe for NPDCCH common search space
-    int npdcch_Offset_RA;
-
-} nprach_parameters_NB_IoT_t;*/
-
-/*! \brief Downlink SCH PDU Structure */
-typedef struct {
-  uint8_t payload[SCH_PAYLOAD_SIZE_MAX_NB_IoT];
-  uint32_t pdu_size;
-} __attribute__ ((__packed__)) DLSCH_PDU_NB_IoT;
-
-/*! \brief eNB template for UE context information  */
-typedef struct {
-    // C-RNTI of UE
-  rnti_t rnti;
-  // UE CE level
-  int CE_level;
-  // Direction of transmission(DL:0\UL:1\NONE:-1)
-  int32_t direction;
-  // DCI Reptition
-  uint32_t R_dci;
-  // MAX repetition
-  uint32_t R_max;
-
-  // HARQ round
-  uint32_t HARQ_round;
-  /*Downlink information*/
-
-  /// DLSCH pdu
-  DLSCH_PDU_NB_IoT DLSCH_pdu;
-  // PDU size
-  uint32_t DLSCH_pdu_size;
-  // Data Reptition
-  uint32_t R_dl;
-  // MCS index
-  uint32_t I_mcs_dl;
-  // total downlink buffer DCCH0_NB_IoT
-  uint32_t dl_buffer_DCCH0_NB_IoT;
-  // NDI
-  int oldNDI_DL;
-  //HARQ ACK/NACK repetition
-  uint32_t R_harq;
-
-  /*Uplink information*/
-  int oldNDI_UL;
-  // Uplink data repeat, now just follow the rach repeat number
-  uint32_t R_ul;
-  // PHR value (0-3)
-  uint32_t PHR;
-  // The uplink data size from BSR or DVI
-  uint32_t ul_total_buffer;
-  // Determine if this UE support multi-tone transmission or not
-  int multi_tone;
-  // Next UE_template ID
-  int next;
-  // Previous UE_template ID
-  int prev;
-  // MSG4 complete
-  int RRC_connected;
-  // UE active flag
-  int active;
-
-} UE_TEMPLATE_NB_IoT;
-
-/*36331 NPDCCH-ConfigDedicated-NB_IoT*/
-typedef struct{
-  //npdcch-NumRepetitions-r13
-  uint32_t R_max;
-  //npdcch-StartSF-USS-r13
-  double G;
-  //npdcch-Offset-USS-r13
-  double a_offset;
-  //NPDCCH period
-  uint32_t T;
-  //Starting subfrane of Search Space which is mod T
-  uint32_t ss_start_uss;
-}NPDCCH_config_dedicated_NB_IoT_t;
-
-
-/*! \brief UE list used by eNB to order UEs/CC for scheduling*/
-typedef struct {
-
-  /// DCI template and MAC connection parameters for UEs
-  UE_TEMPLATE_NB_IoT UE_template_NB_IoT[MAX_NUMBER_OF_UE_MAX_NB_IoT];
-
-  /// NPDCCH Period and searching space info
-  NPDCCH_config_dedicated_NB_IoT_t NPDCCH_config_dedicated;
-  //int next[MAX_NUMBER_OF_UE_MAX_NB_IoT];
-  // -1:No UE in list
-  int head;
-  // -1:No UE in list
-  int tail;
-  int num_UEs;
-  //boolean_t active[MAX_NUMBER_OF_UE_MAX_NB_IoT];
-
-} UE_list_NB_IoT_t;
-
-
-typedef struct{
-
-  // flag to indicate scheduing MIB-NB_IoT
-  uint8_t flag_MIB;
-  // flag to indicate scheduling SIB1-NB_IoT
-  uint8_t flag_SIB1;
-  // flag to indicate scheduling SIBs-NB_IoT
-  uint8_t flag_SIBs[MAX_NUMBER_OF_SIBs_NB_IoT];
-  // flag to indicate scheduling type2 NPDCCH CSS with different CE level
-  uint8_t flag_type2_css[3];
-  // flag to indicate scheduling type1 NPDCCH CSS with different CE level
-  uint8_t flag_type1_css[3];
-  // flag to indicate scheduling NPDCCH USS with UE list
-  uint8_t flag_uss[MAX_NUMBER_OF_UE_MAX_NB_IoT];
-  // flag to indicate scheduling sib1/MIB
-  uint8_t flag_fix_scheduling;
-  // number of the type2 css to schedule in this period
-  uint8_t num_type2_css_run;
-  // number of the type1 css to schedule in this period
-  uint8_t num_type1_css_run;
-  // number of the uss to schedule in this period
-  uint8_t num_uss_run;
-
-}scheduling_flag_t;
-
-typedef struct available_resource_UL_s{
-
-    ///Resource start subframe
-    uint32_t start_subframe;
-    ///Resource end subframe
-    uint32_t end_subframe;
-    // pointer to next node
-    struct available_resource_UL_s *next, *prev;
-
-}available_resource_UL_t;
-
-typedef struct available_resource_DL_s{
-  uint32_t start_subframe;
-  uint32_t end_subframe;
-
-  struct available_resource_DL_s *next, *prev;
-}available_resource_DL_t;
-
-/*Structure used for scheduling*/
-typedef struct{
-  //resource position info.
-  uint32_t sf_end,sf_start;
-  //resource position info. separate by HyperSF, Frame, Subframe
-  uint32_t start_h, end_h;
-  uint32_t start_f, end_f;
-  uint32_t start_sf, end_sf;
-  //whcih available resource node is used
-  available_resource_DL_t *node;
-}sched_temp_DL_NB_IoT_t;
-
-/*!\brief  MAC subheader short with 7bit Length field */
-typedef struct {
-  uint8_t LCID:5;  // octet 1 LSB
-  uint8_t E:1;
-  uint8_t F2:1;
-  uint8_t R:1;     // octet 1 MSB
-  uint8_t L:7;     // octet 2 LSB
-  uint8_t F:1;     // octet 2 MSB
-} __attribute__((__packed__))SCH_SUBHEADER_SHORT_NB_IoT;
-typedef struct {
-  uint8_t LCID:5;   // octet 1 LSB
-  uint8_t E:1;
-  uint8_t F2:1;
-  uint8_t R:1;      // octet 1 MSB
-  uint8_t L_MSB:7;
-  uint8_t F:1;      // octet 2 MSB
-  uint8_t L_LSB:8;
-} __attribute__((__packed__))SCH_SUBHEADER_LONG_NB_IoT;
-typedef struct {
-  uint8_t LCID:5;   // octet 1 LSB
-  uint8_t E:1;
-  uint8_t F2:1;
-  uint8_t R:1;      // octet 1 MSB
-  uint8_t L_MSB:8;      // octet 2 MSB
-  uint8_t L_LSB:8;
-} __attribute__((__packed__))SCH_SUBHEADER_LONG_EXTEND_NB_IoT;
-/*!\brief MAC subheader short without length field */
-typedef struct {
-  uint8_t LCID:5;
-  uint8_t F2:1;
-  uint8_t E:1;
-  uint8_t R:1;
-} __attribute__((__packed__))SCH_SUBHEADER_FIXED_NB_IoT;
-
-
-/*! \brief Uplink SCH PDU Structure */
-typedef struct {
-  int8_t payload[SCH_PAYLOAD_SIZE_MAX_NB_IoT];         /*!< \brief SACH payload */
-  uint16_t Pdu_size;
-} __attribute__ ((__packed__)) ULSCH_PDU_NB_IoT;
-
-typedef struct {
-  uint8_t PH:6;
-  uint8_t R:2;
-} __attribute__((__packed__))POWER_HEADROOM_CMD_NB_IoT;
-
-typedef struct {
-  uint8_t RAPID:6;
-  uint8_t T:1;
-  uint8_t E:1;
-} __attribute__((__packed__))RA_HEADER_RAPID_NB_IoT;
-
-/*Structure used for UL scheduling*/
-typedef struct{
-  //resource position info.
-  uint32_t sf_end, sf_start;
-  //resource position info. separate by HyperSF, Frame, Subframe
-  //uint32_t start_h, end_h;
-  //uint32_t start_f, end_f;
-  //uint32_t start_sf, end_sf;
-  // information for allocating the resource
-  int tone;
-  int scheduling_delay;
-  int subcarrier_indication;
-  int ACK_NACK_resource_field;
-  available_resource_UL_t *node;
-}sched_temp_UL_NB_IoT_t;
-
-typedef struct Available_available_resource_DL{
-
-    ///Available Resoruce for sixtone
-    available_resource_UL_t *sixtone_Head;//, *sixtone_npusch_frame;
-  uint32_t sixtone_end_subframe;
-    ///Available Resoruce for threetone
-    available_resource_UL_t *threetone_Head;//, *threetone_npusch_frame;
-  uint32_t threetone_end_subframe;
-    ///Available Resoruce for singletone1
-    available_resource_UL_t *singletone1_Head;//, *singletone1_npusch_frame;
-  uint32_t singletone1_end_subframe;
-    ///Available Resoruce for singletone2
-    available_resource_UL_t *singletone2_Head;//, *singletone2_npusch_frame;
-    uint32_t singletone2_end_subframe;
-  ///Available Resoruce for singletone3
-    available_resource_UL_t *singletone3_Head;//, *singletone3_npusch_frame;
-  uint32_t singletone3_end_subframe;
-  
-}available_resource_tones_UL_t;
-
-typedef struct schedule_result{
-  // The subframe read by output handler
-  uint32_t output_subframe;
-  // SDU length
-  uint32_t sdu_length;
-  // MAC PDU
-  uint8_t *DLSCH_pdu;
-  // The data direction indicated by this DCI
-  uint8_t direction;
-  // pointer to DCI
-  void *DCI_pdu;
-  // when all the procedure related to this DCI, enable this flag
-  boolean_t DCI_release;
-  // Indicate the channel which to transmit
-  channel_NB_IoT_t channel;
-  // rnti
-  rnti_t rnti;
-  // 0 = TC-RNTI , 1 = RA-RNTI, 2 = P-RNTI, 3 = others
-  uint8_t rnti_type;
-  // 0 = data, 1 = ACK/NACK
-  uint8_t npusch_format;
-  //HARQ ACK/NACK repetition
-  uint32_t R_harq;
-  // pointer to next node
-  struct schedule_result *next;
-
-  uint32_t end_subframe;
-  
-  uint8_t *rar_buffer;
-
-}schedule_result_t;
-
-/*Flag structure used for trigger each scheduler*/
-typedef struct{
-  scheduling_flag_t scheduling_flag;
-  //sched_temp_DL_NB_IoT_t sched_result_DL;
-  //resource grid for Uplink
-  available_resource_tones_UL_t *UL_resource;
-  //scheduling result read by output handler
-  schedule_result_t *schedule_result_list_UL;
-  schedule_result_t *schedule_result_list_DL;
-}SCHEDULE_NB_IoT_t;
-
-typedef struct{
-  uint32_t num_dlsf_per_period;
-  uint16_t *sf_to_dlsf_table;
-  uint16_t *dlsf_to_sf_table;
-}DLSF_INFO_t;
-
-typedef enum ce_level_e{
-  ce0=0,
-  ce1,
-  ce2,
-  ce_level_total
-}ce_level_t;
-
-
-
-/*! \brief eNB template for the Random access information */
-typedef struct RA_TEMPLATE_NB_IoT_s{
-
-  boolean_t active;
-  uint32_t msg3_retransmit_count;
-  uint32_t msg4_retransmit_count;
-  uint16_t ta;
-  uint8_t preamble_index;
-  ce_level_t ce_level;
-  rnti_t ue_rnti;
-  rnti_t ra_rnti;
-  struct RA_TEMPLATE_NB_IoT_s *next, *prev;
-  boolean_t wait_msg4_ack;
-  boolean_t wait_msg3_ack;
-  uint8_t rar_buffer[7];
-
-} RA_TEMPLATE_NB_IoT;
-
-typedef struct RA_template_list_s{
-  RA_TEMPLATE_NB_IoT *head;
-  RA_TEMPLATE_NB_IoT *tail;
-}RA_template_list_t;
-
-
-/*! \brief top level eNB MAC structure */
-typedef struct eNB_MAC_INST_NB_IoT_s {
-  /// Ethernet parameters for northbound midhaul interface
-  eth_params_t         eth_params_n;
-  /// Ethernet parameters for fronthaul interface
-  eth_params_t         eth_params_s;
-
-  uint8_t Mod_id;
-  //  System
-  uint32_t hyper_system_frame;
-  uint32_t system_frame;
-  uint32_t sub_frame;
-
-  uint32_t current_subframe;
-  /// Pointer to IF module instance for PHY
-  IF_Module_t *if_inst;
-  //  RA
-  RA_template_list_t RA_msg2_list;
-  RA_template_list_t RA_msg3_list;
-  RA_template_list_t RA_msg4_list;
-
-  RA_TEMPLATE_NB_IoT RA_template[MAX_NUMBER_OF_UE_MAX_NB_IoT];
-
-  //int32_t last_tx_subframe;
-
-  //  for tool
-  int32_t sib1_flag[64];
-  int32_t sib1_count[64];
-  int32_t sib1_period;
-  uint16_t dlsf_table[64];
-  int32_t sibs_table[256];
-
-  //  channel config
-
-  //USS list
-  //Number of USS period is used
-  int num_uss_list;
-  UE_list_NB_IoT_t *UE_list_spec;
-
-  scheduling_flag_t scheduling_flag;
-
-  uint32_t schedule_subframe_DL;
-  uint32_t schedule_subframe_UL;
-
-  rrc_config_NB_IoT_t rrc_config;
-
-  nfapi_config_request_t config;
-
-   IF_Module_NB_IoT_t            *if_inst_NB_IoT;
-} eNB_MAC_INST_NB_IoT;
-
-// actually not here, but for now put it here
-typedef  struct {
-  uint32_t       bytes_in_buffer; /*!< \brief Bytes buffered in RLC protocol instance. */
-  uint32_t       pdus_in_buffer;  /*!< \brief Number of PDUs buffered in RLC protocol instance (OBSOLETE). */
-  uint32_t       head_sdu_creation_time;           /*!< \brief Head SDU creation time. */
-  uint32_t       head_sdu_remaining_size_to_send;  /*!< \brief remaining size of sdu: could be the total size or the remaining size of already segmented sdu */
-  boolean_t      head_sdu_is_segmented;     /*!< \brief 0 if head SDU has not been segmented, 1 if already segmented */
-} mac_rlc_status_resp_NB_IoT_t;
-
-// global variables
-
-nprach_parameters_NB_IoT_t nprach_list[3];
-
-//DLSF Table
-DLSF_INFO_t DLSF_information;
-
-#endif /*__LAYER2_MAC_DEFS_NB_IoT_H__ */
+
+/*! \file defs_NB_IoT.c
+ * \brief MAC layer structures
+ * \author  NTUST BMW Lab./
+ * \date 2017
+ * \email: 
+ * \version 1.0
+ *
+ */
+#ifndef __LAYER2_MAC_DEFS_NB_IOT_H__
+#define __LAYER2_MAC_DEFS_NB_IOT_H__
+#ifdef USER_MODE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#endif
+//#include "COMMON/openair_defs.h"
+#include "COMMON/platform_constants.h"
+#include "COMMON/mac_rrc_primitives.h"
+#include "PHY/LTE_TRANSPORT/defs_NB_IoT.h"
+//#include "PHY/defs.h"
+#include "PHY/defs_L1_NB_IoT.h"
+#include "openair2/PHY_INTERFACE/IF_Module_NB_IoT.h"
+#include "config_NB_IoT.h"
+//  MAC definition
+#define MAX_FRAME 0xfffff
+#define NUM_FRAME 0x100000
+#define MAX_SUBFRAME 10485760
+
+#define MAX(a, b) (((a)>(b))?(a):(b))
+
+//  RA-RNTI: 1+SFN_id>>2
+#define RA_RNTI_LOW   0x0001  //  SFN_id = 0
+#define RA_RNTI_HIGH  0x0100  //  SFN_id = 1023
+#define C_RNTI_LOW  0x0101
+#define C_RNTI_HIGH 
+
+// ULSCH LCHAN IDs
+/*!\brief LCID of extended power headroom for ULSCH */
+#define EXTENDED_POWER_HEADROOM 25
+/*!\brief LCID of power headroom for ULSCH */
+#define POWER_HEADROOM 26
+/*!\brief LCID of CRNTI for ULSCH */
+#define CRNTI 27
+/*!\brief LCID of truncated BSR for ULSCH */
+#define TRUNCATED_BSR 28
+/*!\brief LCID of short BSR for ULSCH */
+#define SHORT_BSR 29
+/*!\brief LCID of long BSR for ULSCH */
+#define LONG_BSR 30
+/*! \brief Values of CCCH LCID for DLSCH */ 
+#define CCCH_LCHANID 0
+/*!\brief Values of BCCH logical channel */
+#define BCCH 3  // SI 
+/*!\brief Values of PCCH logical channel */
+#define PCCH 4  // Paging 
+/*!\brief Value of CCCH / SRB0 logical channel */
+#define CCCH 0  // srb0
+/*!\brief DCCH / SRB1 logical channel */
+#define DCCH 1  // srb1
+/*!\brief DCCH1 / SRB2  logical channel */
+#define DCCH1 2 // srb2
+/*!\brief DTCH DRB1  logical channel */
+#define DTCH 3 // LCID
+/*!\brief MCCH logical channel */
+#define MCCH 4 
+/*!\brief MTCH logical channel */
+#define MTCH 1 
+// DLSCH LCHAN ID
+/*!\brief LCID of UE contention resolution identity for DLSCH*/
+#define UE_CONT_RES 28
+/*!\brief LCID of timing advance for DLSCH */
+#define TIMING_ADV_CMD 29
+/*!\brief LCID of discontinous reception mode for DLSCH */
+#define DRX_CMD 30
+/*!\brief LCID of padding LCID for DLSCH */
+#define SHORT_PADDING 31
+
+
+typedef enum tone_type_e
+{
+  sixtone = 0,
+  threetone,
+  singletone1,
+  singletone2,
+  singletone3
+}tone_type_t;
+
+typedef enum channel_NB_IoT_e
+{
+  NPDCCH = 0,
+  NPUSCH,
+  NPDSCH
+}channel_NB_IoT_t;
+
+typedef enum{
+  UL = 0,
+  DL
+}message_direction_t;
+
+#define MAX_NUMBER_OF_UE_MAX_NB_IoT 20
+#define SCH_PAYLOAD_SIZE_MAX_NB_IoT 320
+#define MAX_NUMBER_OF_SIBs_NB_IoT 16
+
+/*!\brief Values of BCCH0 logical channel for MIB*/
+#define BCCH0_NB_IoT 11 // MIB-NB_IoT
+/*!\brief Values of BCCH1 logical channel for SIBs */
+#define BCCH1_NB_IoT 12 // SI-SIB-NB_IoTs
+/*!\brief Values of PCCH logical channel */
+#define PCCH_NB_IoT 13  // Paging XXX not used for the moment
+#define MCCH_NB_IoT 14
+/*!\brief Value of CCCH / SRB0 logical channel */
+#define CCCH_NB_IoT 0  // srb0 ---> XXX exactly the same as in LTE (commented for compilation purposes)
+/*!\brief DCCH0 / SRB1bis logical channel */
+#define DCCH0_NB_IoT 3  // srb1bis
+/*!\brief DCCH1 / SRB1  logical channel */
+#define DCCH1_NB_IoT 1 // srb1 //XXX we redefine it for the SRB1
+/*!\brief DTCH0 DRB0  logical channel */
+#define DTCH0_NB_IoT 4 // DRB0
+/*!\brief DTCH1 DRB1  logical channel */
+#define DTCH1_NB_IoT 5 // DRB1
+/*Index of UE contention resoulution logical channel*/
+#define UE_CONTENTION_RESOLUTION 28
+/*Index of TIMING_ADVANCE logical channel*/
+#define TIMING_ADVANCE 29
+/*Index of DRX_COMMAND logical channel*/
+#define DRX_COMMAND 30
+/*Index of PADDING logical channel*/
+#define PADDING 31
+
+
+/// NPRACH-ParametersList-NB_IoT-r13 from 36.331 RRC spec defined in PHY
+/*typedef struct NPRACH_Parameters_NB_IoT{
+
+    /// the period time for nprach
+    int nprach_Periodicity;
+    /// for the start time for the NPRACH resource from 40ms-2560ms
+    int nprach_StartTime;
+    /// for the subcarrier of set to the NPRACH preamble from n0 - n34
+    int nprach_SubcarrierOffset;
+    ///number of subcarriers in a NPRACH resource allowed values (n12,n24,n36,n48)
+    int nprach_NumSubcarriers;
+    /// where is the region that in NPRACH resource to indicate if this UE support MSG3 for multi-tone or not. from 0 - 1
+    int nprach_SubcarrierMSG3_RangeStart;
+    /// The max preamble transmission attempt for the CE level from 1 - 128
+    int maxNumPreambleAttemptCE;
+    /// Number of NPRACH repetitions per attempt for each NPRACH resource
+    int numRepetitionsPerPreambleAttempt;
+    /// The number of the repetition for DCI use in RAR/MSG3/MSG4 from 1 - 2048 (Rmax)
+    int npdcch_NumRepetitions_RA;
+    /// Starting subframe for NPDCCH Common searching space for (RAR/MSG3/MSG4)
+    int npdcch_StartSF_CSS_RA;
+    /// Fractional period offset of starting subframe for NPDCCH common search space
+    int npdcch_Offset_RA;
+
+} nprach_parameters_NB_IoT_t;*/
+
+/*! \brief Downlink SCH PDU Structure */
+typedef struct {
+  uint8_t payload[SCH_PAYLOAD_SIZE_MAX_NB_IoT];
+  uint32_t pdu_size;
+} __attribute__ ((__packed__)) DLSCH_PDU_NB_IoT;
+
+/*! \brief eNB template for UE context information  */
+typedef struct {
+    // C-RNTI of UE
+  rnti_t rnti;
+  // UE CE level
+  int CE_level;
+  // Direction of transmission(DL:0\UL:1\NONE:-1)
+  int32_t direction;
+  // DCI Reptition
+  uint32_t R_dci;
+  // MAX repetition
+  uint32_t R_max;
+
+  // HARQ round
+  uint32_t HARQ_round;
+  /*Downlink information*/
+
+  /// DLSCH pdu
+  DLSCH_PDU_NB_IoT DLSCH_pdu;
+  // PDU size
+  uint32_t DLSCH_pdu_size;
+  // Data Reptition
+  uint32_t R_dl;
+  // MCS index
+  uint32_t I_mcs_dl;
+  // total downlink buffer DCCH0_NB_IoT
+  uint32_t dl_buffer_DCCH0_NB_IoT;
+  // NDI
+  int oldNDI_DL;
+  //HARQ ACK/NACK repetition
+  uint32_t R_harq;
+
+  /*Uplink information*/
+  int oldNDI_UL;
+  // Uplink data repeat, now just follow the rach repeat number
+  uint32_t R_ul;
+  // PHR value (0-3)
+  uint32_t PHR;
+  // The uplink data size from BSR or DVI
+  uint32_t ul_total_buffer;
+  // Determine if this UE support multi-tone transmission or not
+  int multi_tone;
+  // Next UE_template ID
+  int next;
+  // Previous UE_template ID
+  int prev;
+  // MSG4 complete
+  int RRC_connected;
+  // UE active flag
+  int active;
+
+} UE_TEMPLATE_NB_IoT;
+
+/*36331 NPDCCH-ConfigDedicated-NB_IoT*/
+typedef struct{
+  //npdcch-NumRepetitions-r13
+  uint32_t R_max;
+  //npdcch-StartSF-USS-r13
+  double G;
+  //npdcch-Offset-USS-r13
+  double a_offset;
+  //NPDCCH period
+  uint32_t T;
+  //Starting subfrane of Search Space which is mod T
+  uint32_t ss_start_uss;
+}NPDCCH_config_dedicated_NB_IoT_t;
+
+
+/*! \brief UE list used by eNB to order UEs/CC for scheduling*/
+typedef struct {
+
+  /// DCI template and MAC connection parameters for UEs
+  UE_TEMPLATE_NB_IoT UE_template_NB_IoT[MAX_NUMBER_OF_UE_MAX_NB_IoT];
+
+  /// NPDCCH Period and searching space info
+  NPDCCH_config_dedicated_NB_IoT_t NPDCCH_config_dedicated;
+  //int next[MAX_NUMBER_OF_UE_MAX_NB_IoT];
+  // -1:No UE in list
+  int head;
+  // -1:No UE in list
+  int tail;
+  int num_UEs;
+  //boolean_t active[MAX_NUMBER_OF_UE_MAX_NB_IoT];
+
+} UE_list_NB_IoT_t;
+
+
+typedef struct{
+
+  // flag to indicate scheduing MIB-NB_IoT
+  uint8_t flag_MIB;
+  // flag to indicate scheduling SIB1-NB_IoT
+  uint8_t flag_SIB1;
+  // flag to indicate scheduling SIBs-NB_IoT
+  uint8_t flag_SIBs[MAX_NUMBER_OF_SIBs_NB_IoT];
+  // flag to indicate scheduling type2 NPDCCH CSS with different CE level
+  uint8_t flag_type2_css[3];
+  // flag to indicate scheduling type1 NPDCCH CSS with different CE level
+  uint8_t flag_type1_css[3];
+  // flag to indicate scheduling NPDCCH USS with UE list
+  uint8_t flag_uss[MAX_NUMBER_OF_UE_MAX_NB_IoT];
+  // flag to indicate scheduling sib1/MIB
+  uint8_t flag_fix_scheduling;
+  // number of the type2 css to schedule in this period
+  uint8_t num_type2_css_run;
+  // number of the type1 css to schedule in this period
+  uint8_t num_type1_css_run;
+  // number of the uss to schedule in this period
+  uint8_t num_uss_run;
+
+}scheduling_flag_t;
+
+typedef struct available_resource_UL_s{
+
+    ///Resource start subframe
+    uint32_t start_subframe;
+    ///Resource end subframe
+    uint32_t end_subframe;
+    // pointer to next node
+    struct available_resource_UL_s *next, *prev;
+
+}available_resource_UL_t;
+
+typedef struct available_resource_DL_s{
+  uint32_t start_subframe;
+  uint32_t end_subframe;
+
+  struct available_resource_DL_s *next, *prev;
+}available_resource_DL_t;
+
+/*Structure used for scheduling*/
+typedef struct{
+  //resource position info.
+  uint32_t sf_end,sf_start;
+  //resource position info. separate by HyperSF, Frame, Subframe
+  uint32_t start_h, end_h;
+  uint32_t start_f, end_f;
+  uint32_t start_sf, end_sf;
+  //whcih available resource node is used
+  available_resource_DL_t *node;
+}sched_temp_DL_NB_IoT_t;
+
+/*!\brief  MAC subheader short with 7bit Length field */
+typedef struct {
+  uint8_t LCID:5;  // octet 1 LSB
+  uint8_t E:1;
+  uint8_t F2:1;
+  uint8_t R:1;     // octet 1 MSB
+  uint8_t L:7;     // octet 2 LSB
+  uint8_t F:1;     // octet 2 MSB
+} __attribute__((__packed__))SCH_SUBHEADER_SHORT_NB_IoT;
+typedef struct {
+  uint8_t LCID:5;   // octet 1 LSB
+  uint8_t E:1;
+  uint8_t F2:1;
+  uint8_t R:1;      // octet 1 MSB
+  uint8_t L_MSB:7;
+  uint8_t F:1;      // octet 2 MSB
+  uint8_t L_LSB:8;
+} __attribute__((__packed__))SCH_SUBHEADER_LONG_NB_IoT;
+typedef struct {
+  uint8_t LCID:5;   // octet 1 LSB
+  uint8_t E:1;
+  uint8_t F2:1;
+  uint8_t R:1;      // octet 1 MSB
+  uint8_t L_MSB:8;      // octet 2 MSB
+  uint8_t L_LSB:8;
+} __attribute__((__packed__))SCH_SUBHEADER_LONG_EXTEND_NB_IoT;
+/*!\brief MAC subheader short without length field */
+typedef struct {
+  uint8_t LCID:5;
+  uint8_t F2:1;
+  uint8_t E:1;
+  uint8_t R:1;
+} __attribute__((__packed__))SCH_SUBHEADER_FIXED_NB_IoT;
+
+
+/*! \brief Uplink SCH PDU Structure */
+typedef struct {
+  int8_t payload[SCH_PAYLOAD_SIZE_MAX_NB_IoT];         /*!< \brief SACH payload */
+  uint16_t Pdu_size;
+} __attribute__ ((__packed__)) ULSCH_PDU_NB_IoT;
+
+typedef struct {
+  uint8_t PH:6;
+  uint8_t R:2;
+} __attribute__((__packed__))POWER_HEADROOM_CMD_NB_IoT;
+
+typedef struct {
+  uint8_t RAPID:6;
+  uint8_t T:1;
+  uint8_t E:1;
+} __attribute__((__packed__))RA_HEADER_RAPID_NB_IoT;
+
+/*Structure used for UL scheduling*/
+typedef struct{
+  //resource position info.
+  uint32_t sf_end, sf_start;
+  //resource position info. separate by HyperSF, Frame, Subframe
+  //uint32_t start_h, end_h;
+  //uint32_t start_f, end_f;
+  //uint32_t start_sf, end_sf;
+  // information for allocating the resource
+  int tone;
+  int scheduling_delay;
+  int subcarrier_indication;
+  int ACK_NACK_resource_field;
+  available_resource_UL_t *node;
+}sched_temp_UL_NB_IoT_t;
+
+typedef struct Available_available_resource_DL{
+
+    ///Available Resoruce for sixtone
+    available_resource_UL_t *sixtone_Head;//, *sixtone_npusch_frame;
+  uint32_t sixtone_end_subframe;
+    ///Available Resoruce for threetone
+    available_resource_UL_t *threetone_Head;//, *threetone_npusch_frame;
+  uint32_t threetone_end_subframe;
+    ///Available Resoruce for singletone1
+    available_resource_UL_t *singletone1_Head;//, *singletone1_npusch_frame;
+  uint32_t singletone1_end_subframe;
+    ///Available Resoruce for singletone2
+    available_resource_UL_t *singletone2_Head;//, *singletone2_npusch_frame;
+    uint32_t singletone2_end_subframe;
+  ///Available Resoruce for singletone3
+    available_resource_UL_t *singletone3_Head;//, *singletone3_npusch_frame;
+  uint32_t singletone3_end_subframe;
+  
+}available_resource_tones_UL_t;
+
+typedef struct schedule_result{
+  // The subframe read by output handler
+  uint32_t output_subframe;
+  // SDU length
+  uint32_t sdu_length;
+  // MAC PDU
+  uint8_t *DLSCH_pdu;
+  // The data direction indicated by this DCI
+  uint8_t direction;
+  // pointer to DCI
+  void *DCI_pdu;
+  // when all the procedure related to this DCI, enable this flag
+  boolean_t DCI_release;
+  // Indicate the channel which to transmit
+  channel_NB_IoT_t channel;
+  // rnti
+  rnti_t rnti;
+  // 0 = TC-RNTI , 1 = RA-RNTI, 2 = P-RNTI, 3 = others
+  uint8_t rnti_type;
+  // 0 = data, 1 = ACK/NACK
+  uint8_t npusch_format;
+  //HARQ ACK/NACK repetition
+  uint32_t R_harq;
+  // pointer to next node
+  struct schedule_result *next;
+
+  uint32_t end_subframe;
+  
+  uint8_t *rar_buffer;
+
+}schedule_result_t;
+
+/*Flag structure used for trigger each scheduler*/
+typedef struct{
+  scheduling_flag_t scheduling_flag;
+  //sched_temp_DL_NB_IoT_t sched_result_DL;
+  //resource grid for Uplink
+  available_resource_tones_UL_t *UL_resource;
+  //scheduling result read by output handler
+  schedule_result_t *schedule_result_list_UL;
+  schedule_result_t *schedule_result_list_DL;
+}SCHEDULE_NB_IoT_t;
+
+typedef struct{
+  uint32_t num_dlsf_per_period;
+  uint16_t *sf_to_dlsf_table;
+  uint16_t *dlsf_to_sf_table;
+}DLSF_INFO_t;
+
+typedef enum ce_level_e{
+  ce0=0,
+  ce1,
+  ce2,
+  ce_level_total
+}ce_level_t;
+
+
+
+/*! \brief eNB template for the Random access information */
+typedef struct RA_TEMPLATE_NB_IoT_s{
+
+  boolean_t active;
+  uint32_t msg3_retransmit_count;
+  uint32_t msg4_retransmit_count;
+  uint16_t ta;
+  uint8_t preamble_index;
+  ce_level_t ce_level;
+  rnti_t ue_rnti;
+  rnti_t ra_rnti;
+  struct RA_TEMPLATE_NB_IoT_s *next, *prev;
+  boolean_t wait_msg4_ack;
+  boolean_t wait_msg3_ack;
+  uint8_t rar_buffer[7];
+
+} RA_TEMPLATE_NB_IoT;
+
+typedef struct RA_template_list_s{
+  RA_TEMPLATE_NB_IoT *head;
+  RA_TEMPLATE_NB_IoT *tail;
+}RA_template_list_t;
+
+
+/*! \brief top level eNB MAC structure */
+typedef struct eNB_MAC_INST_NB_IoT_s {
+  /// Ethernet parameters for northbound midhaul interface
+  eth_params_t         eth_params_n;
+  /// Ethernet parameters for fronthaul interface
+  eth_params_t         eth_params_s;
+
+  uint8_t Mod_id;
+  //  System
+  uint32_t hyper_system_frame;
+  uint32_t system_frame;
+  uint32_t sub_frame;
+
+  uint32_t current_subframe;
+  /// Pointer to IF module instance for PHY
+  IF_Module_t *if_inst;
+  //  RA
+  RA_template_list_t RA_msg2_list;
+  RA_template_list_t RA_msg3_list;
+  RA_template_list_t RA_msg4_list;
+
+  RA_TEMPLATE_NB_IoT RA_template[MAX_NUMBER_OF_UE_MAX_NB_IoT];
+
+  //int32_t last_tx_subframe;
+
+  //  for tool
+  int32_t sib1_flag[64];
+  int32_t sib1_count[64];
+  int32_t sib1_period;
+  uint16_t dlsf_table[64];
+  int32_t sibs_table[256];
+
+  //  channel config
+
+  //USS list
+  //Number of USS period is used
+  int num_uss_list;
+  UE_list_NB_IoT_t *UE_list_spec;
+
+  scheduling_flag_t scheduling_flag;
+
+  uint32_t schedule_subframe_DL;
+  uint32_t schedule_subframe_UL;
+
+  rrc_config_NB_IoT_t rrc_config;
+
+  nfapi_config_request_t config;
+
+   IF_Module_NB_IoT_t            *if_inst_NB_IoT;
+} eNB_MAC_INST_NB_IoT;
+
+// actually not here, but for now put it here
+typedef  struct {
+  uint32_t       bytes_in_buffer; /*!< \brief Bytes buffered in RLC protocol instance. */
+  uint32_t       pdus_in_buffer;  /*!< \brief Number of PDUs buffered in RLC protocol instance (OBSOLETE). */
+  uint32_t       head_sdu_creation_time;           /*!< \brief Head SDU creation time. */
+  uint32_t       head_sdu_remaining_size_to_send;  /*!< \brief remaining size of sdu: could be the total size or the remaining size of already segmented sdu */
+  boolean_t      head_sdu_is_segmented;     /*!< \brief 0 if head SDU has not been segmented, 1 if already segmented */
+} mac_rlc_status_resp_NB_IoT_t;
+
+// global variables
+
+nprach_parameters_NB_IoT_t nprach_list[3];
+
+//DLSF Table
+DLSF_INFO_t DLSF_information;
+
+#endif /*__LAYER2_MAC_DEFS_NB_IoT_H__ */
diff --git a/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.c b/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.c
index 80dcfd405395c6b9e89c9f22a5ed29393a0137bc..43721bbfd55f0ee6d03f2c90e618dcf92571e63d 100644
--- a/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.c
+++ b/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.c
@@ -1,1417 +1,1417 @@
-/* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*! \file asn1_msg.c
-* \brief primitives to build the asn1 messages
-* \author Raymond Knopp, Navid Nikaein and Michele Paffetti
-* \date 2011, 2017
-* \version 1.0
-* \company Eurecom
-* \email: raymond.knopp@eurecom.fr, navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
-*/
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h> /* for atoi(3) */
-#include <unistd.h> /* for getopt(3) */
-#include <string.h> /* for strerror(3) */
-#include <sysexits.h> /* for EX_* exit codes */
-#include <errno.h>  /* for errno */
-#include "UTIL/LOG/log.h"
-#include <asn_application.h>
-#include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
-#include <per_encoder.h>
-#include "asn1_msg.h"
-
-
-
-//#include for NB-IoT-------------------
-#include "RRCConnectionRequest-NB.h"
-#include "BCCH-DL-SCH-Message-NB.h"
-#include "UL-CCCH-Message-NB.h"
-#include "UL-DCCH-Message-NB.h"
-#include "DL-CCCH-Message-NB.h"
-#include "DL-DCCH-Message-NB.h"
-#include "EstablishmentCause-NB-r13.h"
-#include "RRCConnectionSetup-NB.h"
-#include "SRB-ToAddModList-NB-r13.h"
-#include "DRB-ToAddModList-NB-r13.h"
-#include "RRC/LITE/defs_NB_IoT.h"
-#include "RRCConnectionSetupComplete-NB.h"
-#include "RRCConnectionReconfigurationComplete-NB.h"
-#include "RRCConnectionReconfiguration-NB.h"
-#include "MasterInformationBlock-NB.h"
-#include "SystemInformation-NB.h"
-#include "SystemInformationBlockType1.h"
-#include "SIB-Type-NB-r13.h"
-#include "RRCConnectionResume-NB.h"
-#include "RRCConnectionReestablishment-NB.h"
-#include "../defs_NB_IoT.h"
-//----------------------------------------
-
-//#include "PHY/defs.h"
-#include "enb_config.h"
-
-#if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
-#endif
-
-
-
-
-/*do_MIB_NB_NB_IoT*/
-uint8_t do_MIB_NB_IoT(
-		rrc_eNB_carrier_data_NB_IoT_t *carrier,
-		uint16_t N_RB_DL,//may not needed--> for NB_IoT only 1 PRB is used
-		uint32_t frame,
-    uint32_t hyper_frame)
-{
-  asn_enc_rval_t enc_rval;
-  BCCH_BCH_Message_NB_t *mib_NB_IoT = &(carrier->mib_NB_IoT);
-
-  /*
-   * systemFrameNumber-MSB: (TS 36.331 pag 576)
-   * define the 4 MSB of the SFN (10 bits). The last significant 6 bits will be acquired implicitly by decoding the NPBCH
-   * NOTE: 6 LSB will be used for counting the 64 radio frames in the TTI period (640 ms) that is exactly the MIB period
-   *
-   * hyperSFN-LSB:
-   * indicates the 2 least significant bits of the HSFN. The remaining 8 bits are present in SIB1-NB
-   * NOTE: with the 2 bits we count the 4 HSFN (is 1 SIB1-Nb modification period) while the other 6 count the number of modification periods
-   *
-   *
-   * NOTE: in OAI never modify the SIB messages!!??
-   */
-
-  //XXX check if correct the bit assignment
-  uint8_t sfn_MSB = (uint8_t)((frame>>6) & 0x0f); // all the 4 bits are set to 1
-  uint8_t hsfn_LSB = (uint8_t)(hyper_frame & 0x03); //2 bits set to 1 (0x3 = 0011)
-  uint16_t spare=0; //11 bits --> use uint16
-
-  mib_NB_IoT->message.systemFrameNumber_MSB_r13.buf = &sfn_MSB;
-  mib_NB_IoT->message.systemFrameNumber_MSB_r13.size = 1; //if expressed in byte
-  mib_NB_IoT->message.systemFrameNumber_MSB_r13.bits_unused = 4; //is byte based (so how many bits you don't use of the 8 bits of a bite
-
-  mib_NB_IoT->message.hyperSFN_LSB_r13.buf= &hsfn_LSB;
-  mib_NB_IoT->message.hyperSFN_LSB_r13.size= 1;
-  mib_NB_IoT->message.hyperSFN_LSB_r13.bits_unused = 6;
-
-  //XXX to be set??
-  mib_NB_IoT->message.spare.buf = (uint8_t *)&spare;
-  mib_NB_IoT->message.spare.size = 2;
-  mib_NB_IoT->message.spare.bits_unused = 5;
-
-  //decide how to set it
-  mib_NB_IoT->message.schedulingInfoSIB1_r13 =11; //see TS 36.213-->tables 16.4.1.3-3 ecc...
-  mib_NB_IoT->message.systemInfoValueTag_r13= 0;
-  mib_NB_IoT->message.ab_Enabled_r13 = 0;
-
-  //to be decided
-  mib_NB_IoT->message.operationModeInfo_r13.present = MasterInformationBlock_NB__operationModeInfo_r13_PR_inband_SamePCI_r13;
-  mib_NB_IoT->message.operationModeInfo_r13.choice.inband_SamePCI_r13.eutra_CRS_SequenceInfo_r13 = 0;
-
-  printf("[MIB] Initialization of frame information,sfn_MSB %x, hsfn_LSB %x\n",
-         (uint32_t)sfn_MSB,
-		 (uint32_t)hsfn_LSB);
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message_NB,
-                                   (void*)mib_NB_IoT,
-                                   carrier->MIB_NB_IoT,
-                                   100);
-  if(enc_rval.encoded <= 0) {
-      LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-  }
-
-  if (enc_rval.encoded==-1) {
-    return(-1);
-  }
-
-  return((enc_rval.encoded+7)/8);
-
-}
-
-/*do_SIB1_NB*/
-uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
-				rrc_eNB_carrier_data_NB_IoT_t *carrier,
-                NbIoTRrcConfigurationReq *configuration,
-				uint32_t frame
-               )
-{
-  BCCH_DL_SCH_Message_NB_t *bcch_message= &(carrier->siblock1_NB_IoT);
-  SystemInformationBlockType1_NB_t **sib1_NB_IoT= &(carrier->sib1_NB_IoT);
-  
-
-  asn_enc_rval_t enc_rval;
-
-  PLMN_IdentityInfo_NB_r13_t PLMN_identity_info_NB_IoT;
-  MCC_MNC_Digit_t dummy_mcc[3],dummy_mnc[3];
-  SchedulingInfo_NB_r13_t *schedulingInfo_NB_IoT;
-  SIB_Type_NB_r13_t *sib_type_NB_IoT;
-
-
-  long* attachWithoutPDN_Connectivity = NULL;
-  attachWithoutPDN_Connectivity = CALLOC(1,sizeof(long));
-  long *nrs_CRS_PowerOffset=NULL;
-  nrs_CRS_PowerOffset = CALLOC(1, sizeof(long));
-  long *eutraControlRegionSize=NULL; //this parameter should be set only if we are considering in-band operating mode (samePCI or differentPCI)
-   eutraControlRegionSize = CALLOC(1,sizeof(long));
-  long systemInfoValueTagSI = 0;
-
-  memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
-  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
-  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformationBlockType1_r13;
-
-  //allocation
-  *sib1_NB_IoT = &bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13;
-
-
-  /*TS 36.331 v14.2.0 pag 589
-   * hyperSFN-MSB
-   * Indicates the 8 most significant bits of the hyper-SFN. Together with the hyper-LSB in MIB-NB the complete HSFN is build up
-   */
-  //FIXME see if correct
-  uint8_t hyperSFN_MSB = (uint8_t) ((frame>>2)& 0xff);
-
-  //XXX to be checked
-  (*sib1_NB_IoT)->hyperSFN_MSB_r13.buf = &hyperSFN_MSB;
-  (*sib1_NB_IoT)->hyperSFN_MSB_r13.size = 1;
-  (*sib1_NB_IoT)->hyperSFN_MSB_r13.bits_unused = 0;
-
-  memset(&PLMN_identity_info_NB_IoT,0,sizeof(PLMN_IdentityInfo_NB_r13_t));
-
-  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc = CALLOC(1,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
-  memset(PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc,0,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
-
-  asn_set_empty(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list);//.size=0;
-
-  //left as it is???
-#if defined(ENABLE_ITTI)
-  dummy_mcc[0] = (configuration->mcc / 100) % 10;
-  dummy_mcc[1] = (configuration->mcc / 10) % 10;
-  dummy_mcc[2] = (configuration->mcc / 1) % 10;
-#else
-  dummy_mcc[0] = 0;
-  dummy_mcc[1] = 0;
-  dummy_mcc[2] = 1;
-#endif
-  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[0]);
-  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[1]);
-  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[2]);
-
-  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.size=0;
-  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.count=0;
-
-
-#if defined(ENABLE_ITTI)
-
-  if (configuration->mnc >= 100) {
-    dummy_mnc[0] = (configuration->mnc / 100) % 10;
-    dummy_mnc[1] = (configuration->mnc / 10) % 10;
-    dummy_mnc[2] = (configuration->mnc / 1) % 10;
-  } else {
-    if (configuration->mnc_digit_length == 2) {
-      dummy_mnc[0] = (configuration->mnc / 10) % 10;
-      dummy_mnc[1] = (configuration->mnc / 1) % 10;
-      dummy_mnc[2] = 0xf;
-    } else {
-      dummy_mnc[0] = (configuration->mnc / 100) % 100;
-      dummy_mnc[1] = (configuration->mnc / 10) % 10;
-      dummy_mnc[2] = (configuration->mnc / 1) % 10;
-    }
-  }
-
-#else
-  dummy_mnc[0] = 0;
-  dummy_mnc[1] = 1;
-  dummy_mnc[2] = 0xf;
-#endif
-  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[0]);
-  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[1]);
-
-  if (dummy_mnc[2] != 0xf) {
-    ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[2]);
-  }
-
-  //still set to "notReserved" as in the previous case
-  PLMN_identity_info_NB_IoT.cellReservedForOperatorUse_r13=PLMN_IdentityInfo_NB_r13__cellReservedForOperatorUse_r13_notReserved;
-
-  *attachWithoutPDN_Connectivity = 0;
-  PLMN_identity_info_NB_IoT.attachWithoutPDN_Connectivity_r13 = attachWithoutPDN_Connectivity;
-
-  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->cellAccessRelatedInfo_r13.plmn_IdentityList_r13.list,&PLMN_identity_info_NB_IoT);
-
-  // 16 bits = 2 byte
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf = MALLOC(2); //MALLOC works in byte
-
-  //lefts as it is?
-#if defined(ENABLE_ITTI)
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = (configuration->tac >> 8) & 0xff;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = (configuration->tac >> 0) & 0xff;
-#else
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = 0x00;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = 0x01;
-#endif
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.size=2;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.bits_unused=0;
-
-  // 28 bits --> i have to use 32 bits = 4 byte
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf = MALLOC(8); // why allocate 8 byte?
-#if defined(ENABLE_ITTI)
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = (configuration->cell_identity >> 20) & 0xff;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = (configuration->cell_identity >> 12) & 0xff;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = (configuration->cell_identity >>  4) & 0xff;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = (configuration->cell_identity <<  4) & 0xf0;
-#else
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = 0x00;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = 0x00;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = 0x00;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = 0x10;
-#endif
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.size=4;
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.bits_unused=4;
-
-  //Still set to "notBarred" as in the previous case
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellBarred_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__cellBarred_r13_notBarred;
-
-  //Still Set to "notAllowed" like in the previous case
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.intraFreqReselection_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__intraFreqReselection_r13_notAllowed;
-
-
-  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_RxLevMin_r13=-65; //which value?? TS 36.331 V14.2.1 pag. 589
-  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_QualMin_r13 = 0; //FIXME new parameter for SIB1-NB, not present in SIB1 (for cell reselection but if not used the UE should apply the default value)
-
-  (*sib1_NB_IoT)->p_Max_r13 = CALLOC(1, sizeof(P_Max_t));
-  *((*sib1_NB_IoT)->p_Max_r13) = 23;
-
-  //FIXME
-  (*sib1_NB_IoT)->freqBandIndicator_r13 =
-#if defined(ENABLE_ITTI)
-    configuration->eutra_band;
-#else
-    5; //if not configured we use band 5 (UL: 824 MHz - 849MHz / DL: 869 MHz - 894 MHz  FDD mode)
-#endif
-
-    //OPTIONAL new parameters, to be used?
-      /*
-       * freqBandInfo_r13
-       * multiBandInfoList_r13
-       * nrs_CRS_PowerOffset_r13
-       * sib1_NB_IoT->downlinkBitmap_r13.choice.subframePattern10_r13 =(is a BIT_STRING)
-       */
-
-
-   (*sib1_NB_IoT)->downlinkBitmap_r13 = CALLOC(1, sizeof(struct DL_Bitmap_NB_r13));
-   ((*sib1_NB_IoT)->downlinkBitmap_r13)->present= DL_Bitmap_NB_r13_PR_NOTHING;
-
-   *eutraControlRegionSize = 1;
-   (*sib1_NB_IoT)->eutraControlRegionSize_r13 = eutraControlRegionSize;
-
-
-   *nrs_CRS_PowerOffset= 0;
-   (*sib1_NB_IoT)->nrs_CRS_PowerOffset_r13 = nrs_CRS_PowerOffset;
-
-   schedulingInfo_NB_IoT = (SchedulingInfo_NB_r13_t*) malloc (3*sizeof(SchedulingInfo_NB_r13_t));
-   sib_type_NB_IoT = (SIB_Type_NB_r13_t *) malloc (3*sizeof(SIB_Type_NB_r13_t));
-
-  memset(&schedulingInfo_NB_IoT[0],0,sizeof(SchedulingInfo_NB_r13_t));
-  memset(&schedulingInfo_NB_IoT[1],0,sizeof(SchedulingInfo_NB_r13_t));
-  memset(&schedulingInfo_NB_IoT[2],0,sizeof(SchedulingInfo_NB_r13_t));    
-  memset(&sib_type_NB_IoT[0],0,sizeof(SIB_Type_NB_r13_t));
-  memset(&sib_type_NB_IoT[1],0,sizeof(SIB_Type_NB_r13_t));
-  memset(&sib_type_NB_IoT[2],0,sizeof(SIB_Type_NB_r13_t));
-
-
-  // Now, follow the scheduler SIB configuration
-  // There is only one sib2+sib3 common setting
-  schedulingInfo_NB_IoT[0].si_Periodicity_r13=SchedulingInfo_NB_r13__si_Periodicity_r13_rf4096;
-  schedulingInfo_NB_IoT[0].si_RepetitionPattern_r13=SchedulingInfo_NB_r13__si_RepetitionPattern_r13_every2ndRF; //This Indicates the starting radio frames within the SI window used for SI message transmission.
-  schedulingInfo_NB_IoT[0].si_TB_r13= SchedulingInfo_NB_r13__si_TB_r13_b680;//208 bits
-  
-
-  // This is for SIB2/3
-  /*SIB3 --> There is no mapping information of SIB2 since it is always present
-    *  in the first SystemInformation message
-    * listed in the schedulingInfoList list.
-    * */
-  sib_type_NB_IoT[0]=SIB_Type_NB_r13_sibType3_NB_r13;
-
-  ASN_SEQUENCE_ADD(&schedulingInfo_NB_IoT[0].sib_MappingInfo_r13.list,&sib_type_NB_IoT[0]);
-  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->schedulingInfoList_r13.list,&schedulingInfo_NB_IoT[0]);
-
-  //printf("[ASN Debug] SI P: %ld\n",(*sib1_NB_IoT)->schedulingInfoList_r13.list.array[0]->si_Periodicity_r13);
-
-#if defined(ENABLE_ITTI)
-
-  if (configuration->frame_type == TDD)
-#endif
-  {
-	//FIXME in NB-IoT mandatory to be FDD --> so must give an error
-	  LOG_E(RRC,"[NB-IoT %d] Frame Type is TDD --> not supported by NB-IoT, exiting\n", Mod_id); //correct?
-	  exit(-1);
-  }
-
-  //FIXME which value chose for the following parameter
-  (*sib1_NB_IoT)->si_WindowLength_r13=SystemInformationBlockType1_NB__si_WindowLength_r13_ms160;
-  (*sib1_NB_IoT)->si_RadioFrameOffset_r13= 0;
-
-  /*In Nb-IoT change/update of specific SI message can additionally be indicated by a SI message specific value tag
-   * systemInfoValueTagSI (there is no SystemInfoValueTag in SIB1-NB but only in MIB-NB)
-   *contained in systemInfoValueTagList_r13
-   **/
-  //FIXME correct?
-  (*sib1_NB_IoT)->systemInfoValueTagList_r13 = CALLOC(1, sizeof(struct SystemInfoValueTagList_NB_r13));
-  asn_set_empty(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list);
-  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list,&systemInfoValueTagSI);
-
-
-#ifdef XER_PRINT //generate xml files
-  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
-#endif
-
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
-                                   (void*)bcch_message,
-                                   carrier->SIB1_NB_IoT,
-                                   100);
-
-  if (enc_rval.encoded > 0){ 
-       LOG_F(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-  }
-
-
-#ifdef USER_MODE
-  LOG_D(RRC,"[NB-IoT] SystemInformationBlockType1-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-#endif
-
-  if (enc_rval.encoded==-1) {
-    return(-1);
-  }
-
-  return((enc_rval.encoded+7)/8);
-}
-
-/*SIB23_NB_IoT*/
-//to be clarified is it is possible to carry SIB2 and SIB3  in the same SI message for NB-IoT?
-uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
-                        int CC_id,
-                        rrc_eNB_carrier_data_NB_IoT_t *carrier,//MP: this is already a carrier[CC_id]
-                        NbIoTRrcConfigurationReq *configuration ) //openair2/COMMON/rrc_messages_types.h
-{
-  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib2_NB_part;
-  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib3_NB_part;
-
-  BCCH_DL_SCH_Message_NB_t *bcch_message = &(carrier->systemInformation_NB_IoT); //is the systeminformation-->BCCH_DL_SCH_Message_NB
-  SystemInformationBlockType2_NB_r13_t *sib2_NB_IoT;
-  SystemInformationBlockType3_NB_r13_t *sib3_NB_IoT;
-
-  asn_enc_rval_t enc_rval;
-  RACH_Info_NB_r13_t rach_Info_NB_IoT;
-  NPRACH_Parameters_NB_r13_t *nprach_parameters;
-
-  //optional
-  long *connEstFailOffset = NULL;
-  connEstFailOffset = CALLOC(1, sizeof(long));
-
-//  RSRP_ThresholdsNPRACH_InfoList_NB_r13_t *rsrp_ThresholdsPrachInfoList;
-//  RSRP_Range_t rsrp_range;
-
-  ACK_NACK_NumRepetitions_NB_r13_t ack_nack_repetition;
-  struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13 *dmrs_config;
-  struct DL_GapConfig_NB_r13	*dl_Gap;
-
-  long *srs_SubframeConfig;
-  srs_SubframeConfig= CALLOC(1, sizeof(long));
-
-
-  if (bcch_message) {
-    memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
-  } else {
-    LOG_E(RRC,"[NB-IoT %d] BCCH_MESSAGE_NB is null, exiting\n", Mod_id);
-    exit(-1);
-  }
-
-  //before schould be allocated memory somewhere?
-//  if (!carrier->sib2_NB_IoT) {
-//    LOG_E(RRC,"[NB-IoT %d] sib2_NB_IoT is null, exiting\n", Mod_id);
-//    exit(-1);
-//  }
-//
-//  if (!carrier->sib3_NB_IoT) {
-//    LOG_E(RRC,"[NB-IoT %d] sib3_NB_IoT is null, exiting\n", Mod_id);
-//    exit(-1);
-//  }
-
-
-  LOG_I(RRC,"[NB-IoT %d] Configuration SIB2/3\n", Mod_id);
-
-  sib2_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-  sib3_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-  memset(sib2_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-  memset(sib3_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-
-  sib2_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib2_r13;
-  sib3_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib3_r13;
-
-  //may bug if not correct allocation of memory
-  carrier->sib2_NB_IoT = &sib2_NB_part->choice.sib2_r13;
-  carrier->sib3_NB_IoT = &sib3_NB_part->choice.sib3_r13;
-  sib2_NB_IoT = carrier->sib2_NB_IoT;
-  sib3_NB_IoT = carrier->sib3_NB_IoT;
-
-  nprach_parameters = (NPRACH_Parameters_NB_r13_t *) malloc (3*sizeof(NPRACH_Parameters_NB_r13_t));
-
-  memset(&nprach_parameters[0],0,sizeof(NPRACH_Parameters_NB_r13_t));
-  memset(&nprach_parameters[1],0,sizeof(NPRACH_Parameters_NB_r13_t));
-  memset(&nprach_parameters[2],0,sizeof(NPRACH_Parameters_NB_r13_t));
-
-/// SIB2-NB-----------------------------------------
-
-  //Barring is manage by ab-Enabled in MIB-NB (but is not a struct as ac-BarringInfo in LTE legacy)
-
-  //RACH Config. Common--------------------------------------------------------------
-  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.preambleTransMax_CE_r13 =
-   		  configuration->rach_preambleTransMax_CE_NB;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.powerRampingStep =
-	configuration->rach_powerRampingStep_NB;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.preambleInitialReceivedTargetPower =
-    configuration->rach_preambleInitialReceivedTargetPower_NB;
-
-  rach_Info_NB_IoT.ra_ResponseWindowSize_r13 = configuration->rach_raResponseWindowSize_NB;
-  rach_Info_NB_IoT.mac_ContentionResolutionTimer_r13 = configuration-> rach_macContentionResolutionTimer_NB;
-  //rach_infoList max size = maxNPRACH-Resources-NB-r13 = 3
-  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.rach_InfoList_r13.list,&rach_Info_NB_IoT);
-
-  //TS 36.331 pag 614 --> if not present the value to infinity sould be used
-  *connEstFailOffset = 0;
-  
-  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.connEstFailOffset_r13 = connEstFailOffset; /*OPTIONAL*/
-
-
-  // BCCH-Config-NB-IoT----------------------------------------------------------------
-  sib2_NB_IoT->radioResourceConfigCommon_r13.bcch_Config_r13.modificationPeriodCoeff_r13
-    = configuration->bcch_modificationPeriodCoeff_NB;
-
-  // PCCH-Config-NB-IoT-----------------------------------------------------------------
-  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.defaultPagingCycle_r13
-    = configuration->pcch_defaultPagingCycle_NB;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.nB_r13 = configuration->pcch_nB_NB;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.npdcch_NumRepetitionPaging_r13 = configuration-> pcch_npdcch_NumRepetitionPaging_NB;
-
-  //NPRACH-Config-NB-IoT-----------------------------------------------------------------
-
-  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13 = NULL; 
-  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_CP_Length_r13 = configuration->nprach_CP_Length;
-  /*OPTIONAL*/
-//   =CALLOC(1, sizeof(struct RSRP_ThresholdsNPRACH_InfoList_NB_r13)); //fatto uguale dopo
-//   rsrp_ThresholdsPrachInfoList = sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13;
-//   rsrp_range = configuration->nprach_rsrp_range_NB;
-//   ASN_SEQUENCE_ADD(&rsrp_ThresholdsPrachInfoList->list,rsrp_range);
-
-  // According configuration to set the 3 CE level configuration setting
-
-  nprach_parameters[0].nprach_Periodicity_r13               = configuration->nprach_Periodicity[0];
-  nprach_parameters[0].nprach_StartTime_r13                 = configuration->nprach_StartTime[0];
-  nprach_parameters[0].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[0];
-  nprach_parameters[0].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[0];
-  nprach_parameters[0].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[0];
-  nprach_parameters[0].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart;
-  nprach_parameters[0].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB;
-  nprach_parameters[0].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[0];
-  nprach_parameters[0].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[0];
-  nprach_parameters[0].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[0];
-
-  nprach_parameters[1].nprach_Periodicity_r13               = configuration->nprach_Periodicity[1];
-  nprach_parameters[1].nprach_StartTime_r13                 = configuration->nprach_StartTime[1];
-  nprach_parameters[1].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[1];
-  nprach_parameters[1].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[1];
-  nprach_parameters[1].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[1];
-  nprach_parameters[1].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart;
-  nprach_parameters[1].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB;
-  nprach_parameters[1].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[1];
-  nprach_parameters[1].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[1];
-  nprach_parameters[1].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[1];
-
-  nprach_parameters[2].nprach_Periodicity_r13               = configuration->nprach_Periodicity[2];
-  nprach_parameters[2].nprach_StartTime_r13                 = configuration->nprach_StartTime[2];
-  nprach_parameters[2].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[2];
-  nprach_parameters[2].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[2];
-  nprach_parameters[2].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[2];
-  nprach_parameters[2].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart;
-  nprach_parameters[2].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB;
-  nprach_parameters[2].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[2];
-  nprach_parameters[2].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[2];
-  nprach_parameters[2].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[2];
-
-
-  //nprach_parameterList have a max size of 3 possible nprach configuration (see maxNPRACH_Resources_NB_r13)
-  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[0]);
-  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[1]);
-  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[2]);
-  
-  // NPDSCH-Config NB-IOT
-  sib2_NB_IoT->radioResourceConfigCommon_r13.npdsch_ConfigCommon_r13.nrs_Power_r13= configuration->npdsch_nrs_Power;
-
-
-  //NPUSCH-Config NB-IoT----------------------------------------------------------------
-  //list of size 3 (see maxNPRACH_Resources_NB_r13)
-  ack_nack_repetition = configuration-> npusch_ack_nack_numRepetitions_NB; //is an enumerative
-  ASN_SEQUENCE_ADD(&(sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ack_NACK_NumRepetitions_Msg4_r13.list) ,&ack_nack_repetition);
-
-  *srs_SubframeConfig = configuration->npusch_srs_SubframeConfig_NB;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.srs_SubframeConfig_r13= srs_SubframeConfig; /*OPTIONAL*/
-
-
-  /*OPTIONAL*/
-  dmrs_config = CALLOC(1,sizeof(struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13));
-  dmrs_config->threeTone_CyclicShift_r13 = configuration->npusch_threeTone_CyclicShift_r13;
-  dmrs_config->sixTone_CyclicShift_r13 = configuration->npusch_sixTone_CyclicShift_r13;
-
-  /*OPTIONAL
-   * -define the base sequence for a DMRS sequence in a cell with multi tone transmission (3,6,12) see TS 36.331 NPUSCH-Config-NB
-   * -if not defined will be calculated based on the cellID once we configure the phy layer (rrc_mac_config_req) through the config_sib2 */
-  dmrs_config->threeTone_BaseSequence_r13 = NULL;
-  dmrs_config->sixTone_BaseSequence_r13 = NULL;
-  dmrs_config->twelveTone_BaseSequence_r13 = NULL;
-
-  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.dmrs_Config_r13 = dmrs_config;
-
-  //ulReferenceSignalsNPUSCH
-  /*Reference Signal (RS) for UL in NB-IoT is called DRS (Demodulation Reference Signal)
-   * sequence-group hopping can be enabled or disabled by means of the cell-specific parameter groupHoppingEnabled_r13
-   * sequence-group hopping can be disabled for certain specific UE through the parameter groupHoppingDisabled (physicalConfigDedicated)
-   * groupAssignmentNPUSCH--> is used for generate the sequence-shift pattern
-   */
-  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupHoppingEnabled_r13= configuration->npusch_groupHoppingEnabled;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupAssignmentNPUSCH_r13 =configuration->npusch_groupAssignmentNPUSCH_r13;
-
-
-  //dl_GAP---------------------------------------------------------------------------------/*OPTIONAL*/
-  dl_Gap = CALLOC(1,sizeof(struct DL_GapConfig_NB_r13));
-  dl_Gap->dl_GapDurationCoeff_r13= configuration-> dl_GapDurationCoeff_NB;
-  dl_Gap->dl_GapPeriodicity_r13= configuration->dl_GapPeriodicity_NB;
-  dl_Gap->dl_GapThreshold_r13= configuration->dl_GapThreshold_NB;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.dl_Gap_r13 = dl_Gap;
-
-
-  // uplinkPowerControlCommon - NB-IoT------------------------------------------------------
-  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.p0_NominalNPUSCH_r13 = configuration->npusch_p0_NominalNPUSCH;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.deltaPreambleMsg3_r13 = configuration->deltaPreambleMsg3;
-  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.alpha_r13 = configuration->npusch_alpha;
-  //no deltaFlist_PUCCH and no UL cyclic prefix
-
-  // UE Timers and Constants -NB-IoT--------------------------------------------------------
-  sib2_NB_IoT->ue_TimersAndConstants_r13.t300_r13 = configuration-> ue_TimersAndConstants_t300_NB;
-  sib2_NB_IoT->ue_TimersAndConstants_r13.t301_r13 = configuration-> ue_TimersAndConstants_t301_NB;
-  sib2_NB_IoT->ue_TimersAndConstants_r13.t310_r13 = configuration-> ue_TimersAndConstants_t310_NB;
-  sib2_NB_IoT->ue_TimersAndConstants_r13.t311_r13 = configuration-> ue_TimersAndConstants_t311_NB;
-  sib2_NB_IoT->ue_TimersAndConstants_r13.n310_r13 = configuration-> ue_TimersAndConstants_n310_NB;
-  sib2_NB_IoT->ue_TimersAndConstants_r13.n311_r13 = configuration-> ue_TimersAndConstants_n311_NB;
-
-  //other SIB2-NB Parameters--------------------------------------------------------------------------------
-  sib2_NB_IoT->freqInfo_r13.additionalSpectrumEmission_r13 = 1;
-  sib2_NB_IoT->freqInfo_r13.ul_CarrierFreq_r13 = NULL; /*OPTIONAL*/
-
-  sib2_NB_IoT->timeAlignmentTimerCommon_r13=TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
-
-  /*OPTIONAL*/
-  sib2_NB_IoT->multiBandInfoList_r13 = NULL;
-
-/// SIB3-NB-------------------------------------------------------
-
-  sib3_NB_IoT->cellReselectionInfoCommon_r13.q_Hyst_r13=SystemInformationBlockType3_NB_r13__cellReselectionInfoCommon_r13__q_Hyst_r13_dB4;
-  sib3_NB_IoT->cellReselectionServingFreqInfo_r13.s_NonIntraSearch_r13=0; //or define in configuration?
-
-  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_RxLevMin_r13 = -70;
-  //new
-  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13 = CALLOC(1,sizeof(*sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13));
-  *(sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13)= 10; //a caso
-
-  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.p_Max_r13 = NULL;
-  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.s_IntraSearchP_r13 = 31; // s_intraSearch --> s_intraSearchP!!! (they call in a different way)
-  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.t_Reselection_r13=1;
-
-  //how to manage?
-  sib3_NB_IoT->freqBandInfo_r13 = NULL;
-  sib3_NB_IoT->multiBandInfoList_r13 = NULL;
-
-
-///BCCH message (generate the SI message)
-  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
-  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformation_r13;
-
-  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.present = SystemInformation_NB__criticalExtensions_PR_systemInformation_r13;
-  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list.count=0;
-
-  ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
-                   sib2_NB_part);
-  ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
-                   sib3_NB_part);
-
-#ifdef XER_PRINT
-  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
-#endif
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
-                                   (void*)bcch_message,
-                                   carrier->SIB23_NB_IoT,
-                                   900);
-//  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
-//               enc_rval.failed_type->name, enc_rval.encoded);
-
-//#if defined(ENABLE_ITTI).....
-
-
-#ifdef USER_MODE
-  LOG_D(RRC,"[NB-IoT] SystemInformation-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-#endif
-
-  if (enc_rval.encoded==-1) {
-    msg("[RRC] ASN1 : SI-NB encoding failed for SIB23_NB_IoT\n");
-    return(-1);
-  }
-
-  carrier->sib2_NB_IoT = sib2_NB_IoT;
-  carrier->sib3_NB_IoT = sib3_NB_IoT;
-
-  return((enc_rval.encoded+7)/8);
-}
-
-/*do_RRCConnectionSetup_NB_IoT--> the aim is to establish SRB1 and SRB1bis(implicitly)*/
-uint8_t do_RRCConnectionSetup_NB_IoT(
-  const protocol_ctxt_t*     const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*      const ue_context_pP,
-  int                              CC_id,
-  uint8_t*                   const buffer, //Srb0.Tx_buffer.Payload
-  const uint8_t                    Transaction_id,
-  const NB_IoT_DL_FRAME_PARMS* const frame_parms, // maybe not used
-  SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT, //for both SRB1bis and SRB1
-  struct PhysicalConfigDedicated_NB_r13** physicalConfigDedicated_NB_IoT
-)
-
-{
-
- asn_enc_rval_t enc_rval;
-
-
- //MP:logical channel group not defined for Nb-IoT
-
- //MP: logical channel priority pag 605 (is 1 for SRB1 and for SRB1bis should be the same)
- //long* prioritySRB1 = NULL;
- long* prioritySRB1bis = NULL;
- BOOLEAN_t* logicalChannelSR_Prohibit =NULL; //pag 605
- BOOLEAN_t* npusch_AllSymbols= NULL;
-
-// struct SRB_ToAddMod_NB_r13* SRB1_config_NB = NULL;
-// struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1_rlc_config_NB = NULL;
-// struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1_lchan_config_NB = NULL;
-
- struct SRB_ToAddMod_NB_r13* SRB1bis_config_NB_IoT = NULL;
- struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1bis_rlc_config_NB_IoT = NULL;
- struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1bis_lchan_config_NB_IoT = NULL;
-
- //No UL_specific parameters for NB-IoT in LogicalChanelConfig-NB
-
- PhysicalConfigDedicated_NB_r13_t* physicalConfigDedicated2_NB_IoT = NULL;
- DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
- RRCConnectionSetup_NB_t* rrcConnectionSetup_NB_IoT = NULL;
-
- memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
- dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
- dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionSetup_r13;
- rrcConnectionSetup_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionSetup_r13;
-
-
- if (*SRB_configList_NB_IoT) {
-   free(*SRB_configList_NB_IoT);
- }
- *SRB_configList_NB_IoT = CALLOC(1,sizeof(SRB_ToAddModList_NB_r13_t));
-
-/// SRB1--------------------
- {
-// SRB1_config_NB = CALLOC(1,sizeof(*SRB1_config_NB));
-//
-// //no srb_Identity in SRB_ToAddMod_NB
-//
-// SRB1_rlc_config_NB = CALLOC(1,sizeof(*SRB1_rlc_config_NB));
-// SRB1_config_NB->rlc_Config_r13   = SRB1_rlc_config_NB;
-//
-// SRB1_rlc_config_NB->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
-// SRB1_rlc_config_NB->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//the only possible in NB_IoT
-//
-//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_timer_poll_retransmit_r13;
-//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_max_retx_threshold_r13;
-//// //(musT be disabled--> SRB1 config pag 640 specs )
-//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
-//
-//
-// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
-// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
-// //(musT be disabled--> SRB1 config pag 640 specs )
-// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 = NULL;
-//
-// SRB1_lchan_config_NB = CALLOC(1,sizeof(*SRB1_lchan_config_NB));
-// SRB1_config_NB->logicalChannelConfig_r13  = SRB1_lchan_config_NB;
-//
-// SRB1_lchan_config_NB->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
-//
-//
-// prioritySRB1 = CALLOC(1, sizeof(long));
-// *prioritySRB1 = 1;
-// SRB1_lchan_config_NB->choice.explicitValue.priority_r13 = prioritySRB1;
-//
-// logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
-// *logicalChannelSR_Prohibit = 1;
-// //schould be set to TRUE (specs pag 641)
-// SRB1_lchan_config_NB->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
-//
-// //ADD SRB1
-// ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1_config_NB);
- }
-
-///SRB1bis (The configuration for SRB1 and SRB1bis is the same) the only difference is the logical channel identity = 3 but not set here
-
-		 SRB1bis_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_config_NB_IoT));
-
-		 //no srb_Identity in SRB_ToAddMod_NB
-		 SRB1bis_rlc_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_rlc_config_NB_IoT));
-		 SRB1bis_config_NB_IoT->rlc_Config_r13   = SRB1bis_rlc_config_NB_IoT;
-
-		 SRB1bis_rlc_config_NB_IoT->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//MP: the only possible RLC config in NB_IoT
-
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
-		 //(musT be disabled--> SRB1 config pag 640 specs )
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
-
-		 SRB1bis_lchan_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_lchan_config_NB_IoT));
-		 SRB1bis_config_NB_IoT->logicalChannelConfig_r13  = SRB1bis_lchan_config_NB_IoT;
-
-		 SRB1bis_lchan_config_NB_IoT->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
-
-		 prioritySRB1bis = CALLOC(1, sizeof(long));
-		 *prioritySRB1bis = 1; //same as SRB1?
-		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = prioritySRB1bis;
-
-		 logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
-		 *logicalChannelSR_Prohibit = 1; //schould be set to TRUE (specs pag 641)
-		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
-
-		 //ADD SRB1bis
-		 //MP: Actually there is no way to distinguish SRB1 and SRB1bis once put in the list
-		 //MP: SRB_ToAddModList_NB_r13_t size = 1
-		 ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1bis_config_NB_IoT);
-
-
- // PhysicalConfigDedicated (NPDCCH, NPUSCH, CarrierConfig, UplinkPowerControl)
-
- physicalConfigDedicated2_NB_IoT = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT));
- *physicalConfigDedicated_NB_IoT = physicalConfigDedicated2_NB_IoT;
-
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13= CALLOC(1, sizeof(*physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13));
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13));
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13));
- physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13));
-
- //no tpc, no cqi and no pucch, no pdsch, no soundingRS, no AntennaInfo, no scheduling request config
-
- /*
-  * NB-IoT supports the operation with either one or two antenna ports, AP0 and AP1.
-  * For the latter case, Space Frequency Block Coding (SFBC) is applied.
-  * Once selected, the same transmission scheme applies to NPBCH, NPDCCH, and NPDSCH.
-  * */
-
- //FIXME: MP: CarrierConfigDedicated check the set values ----------------------------------------------
-
-  //DL
-
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_CarrierFreq_r13.carrierFreq_r13=0;//random value set
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13= CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13));
-		 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13->present=
-				 	 	 	 	 	 	 	 	 DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13_PR_useNoBitmap_r13;
-
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13 = CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13));
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13->present =
-		  	  	  	  	  	  	  	  	  	  	  DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13_PR_useNoGap_r13;
-
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.inbandCarrierInfo_r13= NULL;
-
-  //UL
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->ul_CarrierConfig_r13.ul_CarrierFreq_r13= NULL;
-
- // NPDCCH
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_NumRepetitions_r13 =0;
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_Offset_USS_r13 =0;
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_StartSF_USS_r13=0;
-
- // NPUSCH //(specs TS 36.331 v14.2.1 pag 643) /* OPTIONAL */
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->ack_NACK_NumRepetitions_r13= NULL;
- npusch_AllSymbols= CALLOC(1, sizeof(BOOLEAN_t));
- *npusch_AllSymbols= 1; //TRUE
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->npusch_AllSymbols_r13= npusch_AllSymbols; /* OPTIONAL */
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->groupHoppingDisabled_r13=NULL; /* OPTIONAL */
-
- // UplinkPowerControlDedicated
- physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13->p0_UE_NPUSCH_r13 = 0; // 0 dB (specs TS36.331 v14.2.1 pag 643)
-
-
- //Fill the rrcConnectionSetup-NB message
- rrcConnectionSetup_NB_IoT->rrc_TransactionIdentifier = Transaction_id; //input value
- rrcConnectionSetup_NB_IoT->criticalExtensions.present = RRCConnectionSetup_NB__criticalExtensions_PR_c1;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionSetup_NB__criticalExtensions__c1_PR_rrcConnectionSetup_r13 ;
- //MP: carry only SRB1bis at the moment and phyConfigDedicated
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = *SRB_configList_NB_IoT;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13 = NULL;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = physicalConfigDedicated2_NB_IoT;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13 = NULL;
-
-#ifdef XER_PRINT
- xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
-#endif
- enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
-                                  (void*)&dl_ccch_msg_NB_IoT,
-                                  buffer,
-                                  100);
-
- if (enc_rval.encoded <= 0) {
-     LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-              enc_rval.failed_type->name, enc_rval.encoded);
- }
-
-#ifdef USER_MODE
- LOG_D(RRC,"RRCConnectionSetup-NB Encoded %zd bits (%zd bytes), ecause %d\n",
-       enc_rval.encoded,(enc_rval.encoded+7)/8,ecause);
-#endif
-
- return((enc_rval.encoded+7)/8);
-}
-
-/*do_SecurityModeCommand - exactly the same as previous implementation*/
-uint8_t do_SecurityModeCommand_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* const buffer,
-  const uint8_t Transaction_id,
-  const uint8_t cipheringAlgorithm,
-  const uint8_t integrityProtAlgorithm)
-{
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-  asn_enc_rval_t enc_rval;
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_securityModeCommand_r13;
-
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.rrc_TransactionIdentifier = Transaction_id;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
-
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.present =
-		  SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;
-
-  // the two following information could be based on the mod_id
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm
-    = (CipheringAlgorithm_r12_t)cipheringAlgorithm; //bug solved
-
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm
-    = (e_SecurityAlgorithmConfig__integrityProtAlgorithm)integrityProtAlgorithm;
-
-//only changed "asn_DEF_DL_DCCH_Message_NB"
-#ifdef XER_PRINT
-  xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
-#endif
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
-                                   (void*)&dl_dcch_msg_NB_IoT,
-                                   buffer,
-                                   100);
-  if (enc_rval.encoded <= 0) {
-      LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-  }
-
-
-//#if defined(ENABLE_ITTI)
-//# if !defined(DISABLE_XER_SPRINT)....
-
-#ifdef USER_MODE
-  LOG_D(RRC,"[NB-IoT %d] securityModeCommand-NB for UE %x Encoded %zd bits (%zd bytes)\n",
-        ctxt_pP->module_id,
-        ctxt_pP->rnti,
-        enc_rval.encoded,
-        (enc_rval.encoded+7)/8);
-#endif
-
-  if (enc_rval.encoded==-1) {
-    LOG_E(RRC,"[NB-IoT %d] ASN1 : securityModeCommand-NB encoding failed for UE %x\n",
-          ctxt_pP->module_id,
-          ctxt_pP->rnti);
-    return(-1);
-  }
-
-  return((enc_rval.encoded+7)/8);
-}
-
-/*do_UECapabilityEnquiry_NB_IoT - very similar to legacy lte*/
-uint8_t do_UECapabilityEnquiry_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t*               const buffer,
-  const uint8_t                Transaction_id
-)
-
-{
-
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-  //no RAT type in NB-IoT
-  asn_enc_rval_t enc_rval;
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_ueCapabilityEnquiry_r13;
-
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.rrc_TransactionIdentifier = Transaction_id;
-
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.present = UECapabilityEnquiry_NB__criticalExtensions_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.choice.c1.present =
-		  UECapabilityEnquiry_NB__criticalExtensions__c1_PR_ueCapabilityEnquiry_r13;
-
-  //no ue_CapabilityRequest (list of RAT_Type)
-
-//only changed "asn_DEF_DL_DCCH_Message_NB"
-#ifdef XER_PRINT
-  xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
-#endif
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
-                                   (void*)&dl_dcch_msg_NB_IoT,
-                                   buffer,
-                                   100);
-  if (enc_rval.encoded <= 0) {
-     LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-    }
-
-//#if defined(ENABLE_ITTI)
-//# if !defined(DISABLE_XER_SPRINT)....
-
-#ifdef USER_MODE
-  LOG_D(RRC,"[NB-IoT %d] UECapabilityEnquiry-NB for UE %x Encoded %zd bits (%zd bytes)\n",
-        ctxt_pP->module_id,
-        ctxt_pP->rnti,
-        enc_rval.encoded,
-        (enc_rval.encoded+7)/8);
-#endif
-
-  if (enc_rval.encoded==-1) {
-    LOG_E(RRC,"[NB-IoT %d] ASN1 : UECapabilityEnquiry-NB encoding failed for UE %x\n",
-          ctxt_pP->module_id,
-          ctxt_pP->rnti);
-    return(-1);
-  }
-
-  return((enc_rval.encoded+7)/8);
-}
-
-/*do_RRCConnectionReconfiguration_NB_IoT-->may convey information for resource configuration
- * (including RBs, MAC main configuration and physical channel configuration)
- * including any associated dedicated NAS information.*/
-uint16_t do_RRCConnectionReconfiguration_NB_IoT(
-  const protocol_ctxt_t*        const ctxt_pP,
-    uint8_t                            *buffer,
-    uint8_t                             Transaction_id,
-    SRB_ToAddModList_NB_r13_t          *SRB1_list_NB, //SRB_ConfigList2 (default)--> only SRB1
-    DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT, //DRB_ConfigList (default)
-    DRB_ToReleaseList_NB_r13_t         *DRB_list2_NB_IoT, //is NULL when passed
-    struct PhysicalConfigDedicated_NB_r13     *physicalConfigDedicated_NB_IoT,
-	MAC_MainConfig_NB_r13_t                   *mac_MainConfig_NB_IoT,
-  struct RRCConnectionReconfiguration_NB_r13_IEs__dedicatedInfoNASList_r13* dedicatedInfoNASList_NB_IoT)
-
-{
-
- //check on DRB_list if contains more than 2 DRB?
-
-  asn_enc_rval_t enc_rval;
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-  RRCConnectionReconfiguration_NB_t *rrcConnectionReconfiguration_NB;
-
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionReconfiguration_r13;
-  rrcConnectionReconfiguration_NB          = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReconfiguration_r13;
-
-  // RRCConnectionReconfiguration
-  rrcConnectionReconfiguration_NB->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionReconfiguration_NB->criticalExtensions.present = RRCConnectionReconfiguration_NB__criticalExtensions_PR_c1;
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.present =RRCConnectionReconfiguration_NB__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r13 ;
-
-  //RAdioResourceconfigDedicated
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13 =
-		  CALLOC(1,sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13));
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->srb_ToAddModList_r13 = SRB1_list_NB; //only SRB1
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToAddModList_r13 = DRB_list_NB_IoT;
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToReleaseList_r13 = DRB_list2_NB_IoT; //NULL
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->physicalConfigDedicated_r13 = physicalConfigDedicated_NB_IoT;
-  //FIXME may not used now
-  //rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->rlf_TimersAndConstants_r13
-
-  if (mac_MainConfig_NB_IoT!=NULL) {
-    rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13 =
-    		CALLOC(1, sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13));
-    rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->present
-      =RadioResourceConfigDedicated_NB_r13__mac_MainConfig_r13_PR_explicitValue_r13;
-   //why memcopy only this one?
-    memcpy(&rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->choice.explicitValue_r13,
-           mac_MainConfig_NB_IoT, sizeof(*mac_MainConfig_NB_IoT));
-
-  } else {
-	  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13=NULL;
-  }
-
-  //no measConfig, measIDlist
-  //no mobilityControlInfo
-
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.dedicatedInfoNASList_r13 = dedicatedInfoNASList_NB_IoT;
-  //mainly used for cell-reselection/handover purposes??
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.fullConfig_r13 = NULL;
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
-                                   (void*)&dl_dcch_msg_NB_IoT,
-                                   buffer,
-                                   RRC_BUF_SIZE);
-  if (enc_rval.encoded <= 0) {
-     LOG_F(RRC, "ASN1 message encoding failed %s, %li\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-  }
-
-  //changed only asn_DEF_DL_DCCH_Message_NB
-#ifdef XER_PRINT
-  xer_fprint(stdout,&asn_DEF_DL_DCCH_Message_NB,(void*)&dl_dcch_msg_NB_IoT);
-#endif
-
-//#if defined(ENABLE_ITTI)
-//# if !defined(DISABLE_XER_SPRINT)...
-
-
-  LOG_I(RRC,"RRCConnectionReconfiguration-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-
-  return((enc_rval.encoded+7)/8);
-}
-
-/*do_RRCConnectionReestablishmentReject - exactly the same as legacy LTE*/
-uint8_t do_RRCConnectionReestablishmentReject_NB_IoT(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer)
-{
-
-  asn_enc_rval_t enc_rval;
-
-  DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
-  RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;
-
-  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
-  dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
-  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishmentReject_r13;
-  rrcConnectionReestablishmentReject    = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishmentReject_r13;
-
-  // RRCConnectionReestablishmentReject //exactly the same as LTE
-  rrcConnectionReestablishmentReject->criticalExtensions.present = RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;
-
-  //Only change in "asn_DEF_DL_CCCH_Message_NB"
-#ifdef XER_PRINT
-  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg_NB_IoT);
-#endif
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
-                                   (void*)&dl_ccch_msg_NB_IoT,
-                                   buffer,
-                                   100);
-  if (enc_rval.encoded <= 0) {
-     LOG_F(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-  }
-
-  //Only change in "asn_DEF_DL_CCCH_Message_NB"
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
-#ifdef USER_MODE
-  LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %zd bits (%zd bytes)\n",
-        enc_rval.encoded,(enc_rval.encoded+7)/8);
-#endif
-
-  return((enc_rval.encoded+7)/8);
-}
-
-/*do_RRCConnectionReject_NB_IoT*/
-uint8_t do_RRCConnectionReject_NB_IoT(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer)
-
-{
-
-  asn_enc_rval_t enc_rval;
-
-  DL_CCCH_Message_NB_t          dl_ccch_msg_NB_IoT;
-  RRCConnectionReject_NB_t      *rrcConnectionReject_NB_IoT;
-
-  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
-  dl_ccch_msg_NB_IoT.message.present           = DL_CCCH_MessageType_NB_PR_c1;
-  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReject_r13;
-  rrcConnectionReject_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReject_r13;
-
-  // RRCConnectionReject-NB_IoT
-  rrcConnectionReject_NB_IoT->criticalExtensions.present = RRCConnectionReject_NB__criticalExtensions_PR_c1;
-  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReject_NB__criticalExtensions__c1_PR_rrcConnectionReject_r13;
-  /* let's put an extended wait time of 1s for the moment */
-  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.extendedWaitTime_r13 = 1;
-  //new-use of suspend indication
-  //If present, this field indicates that the UE should remain suspended and not release its stored context.
-  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13=
-		  CALLOC(1, sizeof(long));
-  *(rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13)=
-		  RRCConnectionReject_NB_r13_IEs__rrc_SuspendIndication_r13_true;
-
-  //Only Modified "asn_DEF_DL_CCCH_Message_NB"
-#ifdef XER_PRINT
-  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg);
-#endif
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
-                                   (void*)&dl_ccch_msg_NB_IoT,
-                                   buffer,
-                                   100);
-  if (enc_rval.encoded <= 0) {
-     LOG_F(RRC, "ASN1 message encoding failed (%s, %ld)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-  }
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
-#ifdef USER_MODE
-  LOG_D(RRC,"RRCConnectionReject-NB Encoded %zd bits (%zd bytes)\n",
-        enc_rval.encoded,(enc_rval.encoded+7)/8);
-#endif
-
-  return((enc_rval.encoded+7)/8);
-}
-
-
-//no do_MBSFNAreaConfig(..) in NB-IoT
-//no do_MeasurementReport(..) in NB-IoT
-
-/*do_DLInformationTransfer_NB*/
-uint8_t do_DLInformationTransfer_NB_IoT(
-		uint8_t Mod_id,
-		uint8_t **buffer,
-		uint8_t transaction_id,
-		uint32_t pdu_length,
-		uint8_t *pdu_buffer)
-
-{
-  ssize_t encoded;
-
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-
-  memset(&dl_dcch_msg_NB_IoT, 0, sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_dlInformationTransfer_r13;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.rrc_TransactionIdentifier = transaction_id;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.present = DLInformationTransfer_NB__criticalExtensions_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.present = DLInformationTransfer_NB__criticalExtensions__c1_PR_dlInformationTransfer_r13;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.size = pdu_length;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.buf = pdu_buffer;
-
-  encoded = uper_encode_to_new_buffer (&asn_DEF_DL_DCCH_Message_NB, NULL, (void*) &dl_dcch_msg_NB_IoT, (void **) buffer);
-
-  //only change in "asn_DEF_DL_DCCH_Message_NB"
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[10000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message_NB, (void *)&dl_dcch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
-  return encoded;
-}
-
-/*do_ULInformationTransfer*/
-//for the moment is not needed (UE-SIDE)
-
-/*OAI_UECapability_t *fill_ue_capability*/
-
-/*do_RRCConnectionReestablishment_NB-->used to re-establish SRB1*/ //which parameter to use?
-uint8_t do_RRCConnectionReestablishment_NB_IoT(
-		uint8_t Mod_id,
-		uint8_t* const buffer,
-		const uint8_t     Transaction_id,
-		const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed
-		SRB_ToAddModList_NB_r13_t*      SRB_list_NB_IoT) //should contain SRB1 already configured?
-{
-
-	asn_enc_rval_t enc_rval;
-	DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
-	RRCConnectionReestablishment_NB_t* rrcConnectionReestablishment_NB_IoT;
-
-	memset(&dl_ccch_msg_NB_IoT, 0, sizeof(DL_CCCH_Message_NB_t));
-
-	dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
-	dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishment_r13;
-	rrcConnectionReestablishment_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishment_r13;
-
-	//rrcConnectionReestablishment_NB
-	rrcConnectionReestablishment_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.present = RRCConnectionReestablishment_NB__criticalExtensions_PR_c1;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReestablishment_NB__criticalExtensions__c1_PR_rrcConnectionReestablishment_r13;
-
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = SRB_list_NB_IoT;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13= NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13= NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = NULL;
-
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.nextHopChainingCount_r13=0;
-
-	enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
-	                                   (void*)&dl_ccch_msg_NB_IoT,
-	                                   buffer,
-	                                   RRC_BUF_SIZE);
-
-	if (enc_rval.encoded <= 0) {
-           LOG_F(RRC, "ASN1 message encoding failed (%s, %li)!\n",
-	               enc_rval.failed_type->name, enc_rval.encoded);
-        }
-
-#ifdef XER_PRINT
-  xer_fprint(stdout,&asn_DEF_DL_CCCH_Message_NB,(void*)&dl_ccch_msg_NB_IoT);
-#endif
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[30000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
-  LOG_I(RRC,"RRCConnectionReestablishment-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-  return 0;
-}
-
-/*do_RRCConnectionRelease_NB--> is used to command the release of an RRC connection*/
-uint8_t do_RRCConnectionRelease_NB_IoT(
-  uint8_t                             Mod_id,
-  uint8_t                            *buffer,
- const uint8_t                             Transaction_id)
-{
-
-  asn_enc_rval_t enc_rval;
-
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-  RRCConnectionRelease_NB_t *rrcConnectionRelease_NB_IoT;
-
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionRelease_r13;
-  rrcConnectionRelease_NB_IoT                  = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionRelease_r13;
-
-  // RRCConnectionRelease
-  rrcConnectionRelease_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionRelease_NB_IoT->criticalExtensions.present = RRCConnectionRelease_NB__criticalExtensions_PR_c1;
-  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionRelease_NB__criticalExtensions__c1_PR_rrcConnectionRelease_r13 ;
-
-  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.releaseCause_r13 = ReleaseCause_NB_r13_other;
-  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.redirectedCarrierInfo_r13 = NULL;
-  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.extendedWaitTime_r13 = NULL;
-
-  //Why allocate memory for non critical extension?
-  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension=CALLOC(1,
-      sizeof(*rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension));
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
-                                   (void*)&dl_dcch_msg_NB_IoT,
-                                   buffer,
-                                   RRC_BUF_SIZE);//check
-
-  return((enc_rval.encoded+7)/8);
-}
-
-
-
-
+/* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file asn1_msg.c
+* \brief primitives to build the asn1 messages
+* \author Raymond Knopp, Navid Nikaein and Michele Paffetti
+* \date 2011, 2017
+* \version 1.0
+* \company Eurecom
+* \email: raymond.knopp@eurecom.fr, navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
+*/
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdlib.h> /* for atoi(3) */
+#include <unistd.h> /* for getopt(3) */
+#include <string.h> /* for strerror(3) */
+#include <sysexits.h> /* for EX_* exit codes */
+#include <errno.h>  /* for errno */
+#include "UTIL/LOG/log.h"
+#include <asn_application.h>
+#include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
+#include <per_encoder.h>
+#include "asn1_msg.h"
+
+
+
+//#include for NB-IoT-------------------
+#include "RRCConnectionRequest-NB.h"
+#include "BCCH-DL-SCH-Message-NB.h"
+#include "UL-CCCH-Message-NB.h"
+#include "UL-DCCH-Message-NB.h"
+#include "DL-CCCH-Message-NB.h"
+#include "DL-DCCH-Message-NB.h"
+#include "EstablishmentCause-NB-r13.h"
+#include "RRCConnectionSetup-NB.h"
+#include "SRB-ToAddModList-NB-r13.h"
+#include "DRB-ToAddModList-NB-r13.h"
+#include "RRC/LITE/defs_NB_IoT.h"
+#include "RRCConnectionSetupComplete-NB.h"
+#include "RRCConnectionReconfigurationComplete-NB.h"
+#include "RRCConnectionReconfiguration-NB.h"
+#include "MasterInformationBlock-NB.h"
+#include "SystemInformation-NB.h"
+#include "SystemInformationBlockType1.h"
+#include "SIB-Type-NB-r13.h"
+#include "RRCConnectionResume-NB.h"
+#include "RRCConnectionReestablishment-NB.h"
+#include "../defs_NB_IoT.h"
+//----------------------------------------
+
+//#include "PHY/defs.h"
+#include "enb_config.h"
+
+#if defined(ENABLE_ITTI)
+# include "intertask_interface.h"
+#endif
+
+
+
+
+/*do_MIB_NB_NB_IoT*/
+uint8_t do_MIB_NB_IoT(
+		rrc_eNB_carrier_data_NB_IoT_t *carrier,
+		uint16_t N_RB_DL,//may not needed--> for NB_IoT only 1 PRB is used
+		uint32_t frame,
+    uint32_t hyper_frame)
+{
+  asn_enc_rval_t enc_rval;
+  BCCH_BCH_Message_NB_t *mib_NB_IoT = &(carrier->mib_NB_IoT);
+
+  /*
+   * systemFrameNumber-MSB: (TS 36.331 pag 576)
+   * define the 4 MSB of the SFN (10 bits). The last significant 6 bits will be acquired implicitly by decoding the NPBCH
+   * NOTE: 6 LSB will be used for counting the 64 radio frames in the TTI period (640 ms) that is exactly the MIB period
+   *
+   * hyperSFN-LSB:
+   * indicates the 2 least significant bits of the HSFN. The remaining 8 bits are present in SIB1-NB
+   * NOTE: with the 2 bits we count the 4 HSFN (is 1 SIB1-Nb modification period) while the other 6 count the number of modification periods
+   *
+   *
+   * NOTE: in OAI never modify the SIB messages!!??
+   */
+
+  //XXX check if correct the bit assignment
+  uint8_t sfn_MSB = (uint8_t)((frame>>6) & 0x0f); // all the 4 bits are set to 1
+  uint8_t hsfn_LSB = (uint8_t)(hyper_frame & 0x03); //2 bits set to 1 (0x3 = 0011)
+  uint16_t spare=0; //11 bits --> use uint16
+
+  mib_NB_IoT->message.systemFrameNumber_MSB_r13.buf = &sfn_MSB;
+  mib_NB_IoT->message.systemFrameNumber_MSB_r13.size = 1; //if expressed in byte
+  mib_NB_IoT->message.systemFrameNumber_MSB_r13.bits_unused = 4; //is byte based (so how many bits you don't use of the 8 bits of a bite
+
+  mib_NB_IoT->message.hyperSFN_LSB_r13.buf= &hsfn_LSB;
+  mib_NB_IoT->message.hyperSFN_LSB_r13.size= 1;
+  mib_NB_IoT->message.hyperSFN_LSB_r13.bits_unused = 6;
+
+  //XXX to be set??
+  mib_NB_IoT->message.spare.buf = (uint8_t *)&spare;
+  mib_NB_IoT->message.spare.size = 2;
+  mib_NB_IoT->message.spare.bits_unused = 5;
+
+  //decide how to set it
+  mib_NB_IoT->message.schedulingInfoSIB1_r13 =11; //see TS 36.213-->tables 16.4.1.3-3 ecc...
+  mib_NB_IoT->message.systemInfoValueTag_r13= 0;
+  mib_NB_IoT->message.ab_Enabled_r13 = 0;
+
+  //to be decided
+  mib_NB_IoT->message.operationModeInfo_r13.present = MasterInformationBlock_NB__operationModeInfo_r13_PR_inband_SamePCI_r13;
+  mib_NB_IoT->message.operationModeInfo_r13.choice.inband_SamePCI_r13.eutra_CRS_SequenceInfo_r13 = 0;
+
+  printf("[MIB] Initialization of frame information,sfn_MSB %x, hsfn_LSB %x\n",
+         (uint32_t)sfn_MSB,
+		 (uint32_t)hsfn_LSB);
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message_NB,
+                                   (void*)mib_NB_IoT,
+                                   carrier->MIB_NB_IoT,
+                                   100);
+  if(enc_rval.encoded <= 0) {
+      LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  }
+
+  if (enc_rval.encoded==-1) {
+    return(-1);
+  }
+
+  return((enc_rval.encoded+7)/8);
+
+}
+
+/*do_SIB1_NB*/
+uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
+				rrc_eNB_carrier_data_NB_IoT_t *carrier,
+                NbIoTRrcConfigurationReq *configuration,
+				uint32_t frame
+               )
+{
+  BCCH_DL_SCH_Message_NB_t *bcch_message= &(carrier->siblock1_NB_IoT);
+  SystemInformationBlockType1_NB_t **sib1_NB_IoT= &(carrier->sib1_NB_IoT);
+  
+
+  asn_enc_rval_t enc_rval;
+
+  PLMN_IdentityInfo_NB_r13_t PLMN_identity_info_NB_IoT;
+  MCC_MNC_Digit_t dummy_mcc[3],dummy_mnc[3];
+  SchedulingInfo_NB_r13_t *schedulingInfo_NB_IoT;
+  SIB_Type_NB_r13_t *sib_type_NB_IoT;
+
+
+  long* attachWithoutPDN_Connectivity = NULL;
+  attachWithoutPDN_Connectivity = CALLOC(1,sizeof(long));
+  long *nrs_CRS_PowerOffset=NULL;
+  nrs_CRS_PowerOffset = CALLOC(1, sizeof(long));
+  long *eutraControlRegionSize=NULL; //this parameter should be set only if we are considering in-band operating mode (samePCI or differentPCI)
+   eutraControlRegionSize = CALLOC(1,sizeof(long));
+  long systemInfoValueTagSI = 0;
+
+  memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
+  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
+  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformationBlockType1_r13;
+
+  //allocation
+  *sib1_NB_IoT = &bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13;
+
+
+  /*TS 36.331 v14.2.0 pag 589
+   * hyperSFN-MSB
+   * Indicates the 8 most significant bits of the hyper-SFN. Together with the hyper-LSB in MIB-NB the complete HSFN is build up
+   */
+  //FIXME see if correct
+  uint8_t hyperSFN_MSB = (uint8_t) ((frame>>2)& 0xff);
+
+  //XXX to be checked
+  (*sib1_NB_IoT)->hyperSFN_MSB_r13.buf = &hyperSFN_MSB;
+  (*sib1_NB_IoT)->hyperSFN_MSB_r13.size = 1;
+  (*sib1_NB_IoT)->hyperSFN_MSB_r13.bits_unused = 0;
+
+  memset(&PLMN_identity_info_NB_IoT,0,sizeof(PLMN_IdentityInfo_NB_r13_t));
+
+  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc = CALLOC(1,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
+  memset(PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc,0,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
+
+  asn_set_empty(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list);//.size=0;
+
+  //left as it is???
+#if defined(ENABLE_ITTI)
+  dummy_mcc[0] = (configuration->mcc / 100) % 10;
+  dummy_mcc[1] = (configuration->mcc / 10) % 10;
+  dummy_mcc[2] = (configuration->mcc / 1) % 10;
+#else
+  dummy_mcc[0] = 0;
+  dummy_mcc[1] = 0;
+  dummy_mcc[2] = 1;
+#endif
+  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[0]);
+  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[1]);
+  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[2]);
+
+  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.size=0;
+  PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.count=0;
+
+
+#if defined(ENABLE_ITTI)
+
+  if (configuration->mnc >= 100) {
+    dummy_mnc[0] = (configuration->mnc / 100) % 10;
+    dummy_mnc[1] = (configuration->mnc / 10) % 10;
+    dummy_mnc[2] = (configuration->mnc / 1) % 10;
+  } else {
+    if (configuration->mnc_digit_length == 2) {
+      dummy_mnc[0] = (configuration->mnc / 10) % 10;
+      dummy_mnc[1] = (configuration->mnc / 1) % 10;
+      dummy_mnc[2] = 0xf;
+    } else {
+      dummy_mnc[0] = (configuration->mnc / 100) % 100;
+      dummy_mnc[1] = (configuration->mnc / 10) % 10;
+      dummy_mnc[2] = (configuration->mnc / 1) % 10;
+    }
+  }
+
+#else
+  dummy_mnc[0] = 0;
+  dummy_mnc[1] = 1;
+  dummy_mnc[2] = 0xf;
+#endif
+  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[0]);
+  ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[1]);
+
+  if (dummy_mnc[2] != 0xf) {
+    ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[2]);
+  }
+
+  //still set to "notReserved" as in the previous case
+  PLMN_identity_info_NB_IoT.cellReservedForOperatorUse_r13=PLMN_IdentityInfo_NB_r13__cellReservedForOperatorUse_r13_notReserved;
+
+  *attachWithoutPDN_Connectivity = 0;
+  PLMN_identity_info_NB_IoT.attachWithoutPDN_Connectivity_r13 = attachWithoutPDN_Connectivity;
+
+  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->cellAccessRelatedInfo_r13.plmn_IdentityList_r13.list,&PLMN_identity_info_NB_IoT);
+
+  // 16 bits = 2 byte
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf = MALLOC(2); //MALLOC works in byte
+
+  //lefts as it is?
+#if defined(ENABLE_ITTI)
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = (configuration->tac >> 8) & 0xff;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = (configuration->tac >> 0) & 0xff;
+#else
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = 0x00;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = 0x01;
+#endif
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.size=2;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.bits_unused=0;
+
+  // 28 bits --> i have to use 32 bits = 4 byte
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf = MALLOC(8); // why allocate 8 byte?
+#if defined(ENABLE_ITTI)
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = (configuration->cell_identity >> 20) & 0xff;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = (configuration->cell_identity >> 12) & 0xff;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = (configuration->cell_identity >>  4) & 0xff;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = (configuration->cell_identity <<  4) & 0xf0;
+#else
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = 0x00;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = 0x00;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = 0x00;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = 0x10;
+#endif
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.size=4;
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.bits_unused=4;
+
+  //Still set to "notBarred" as in the previous case
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellBarred_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__cellBarred_r13_notBarred;
+
+  //Still Set to "notAllowed" like in the previous case
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.intraFreqReselection_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__intraFreqReselection_r13_notAllowed;
+
+
+  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_RxLevMin_r13=-65; //which value?? TS 36.331 V14.2.1 pag. 589
+  (*sib1_NB_IoT)->cellSelectionInfo_r13.q_QualMin_r13 = 0; //FIXME new parameter for SIB1-NB, not present in SIB1 (for cell reselection but if not used the UE should apply the default value)
+
+  (*sib1_NB_IoT)->p_Max_r13 = CALLOC(1, sizeof(P_Max_t));
+  *((*sib1_NB_IoT)->p_Max_r13) = 23;
+
+  //FIXME
+  (*sib1_NB_IoT)->freqBandIndicator_r13 =
+#if defined(ENABLE_ITTI)
+    configuration->eutra_band;
+#else
+    5; //if not configured we use band 5 (UL: 824 MHz - 849MHz / DL: 869 MHz - 894 MHz  FDD mode)
+#endif
+
+    //OPTIONAL new parameters, to be used?
+      /*
+       * freqBandInfo_r13
+       * multiBandInfoList_r13
+       * nrs_CRS_PowerOffset_r13
+       * sib1_NB_IoT->downlinkBitmap_r13.choice.subframePattern10_r13 =(is a BIT_STRING)
+       */
+
+
+   (*sib1_NB_IoT)->downlinkBitmap_r13 = CALLOC(1, sizeof(struct DL_Bitmap_NB_r13));
+   ((*sib1_NB_IoT)->downlinkBitmap_r13)->present= DL_Bitmap_NB_r13_PR_NOTHING;
+
+   *eutraControlRegionSize = 1;
+   (*sib1_NB_IoT)->eutraControlRegionSize_r13 = eutraControlRegionSize;
+
+
+   *nrs_CRS_PowerOffset= 0;
+   (*sib1_NB_IoT)->nrs_CRS_PowerOffset_r13 = nrs_CRS_PowerOffset;
+
+   schedulingInfo_NB_IoT = (SchedulingInfo_NB_r13_t*) malloc (3*sizeof(SchedulingInfo_NB_r13_t));
+   sib_type_NB_IoT = (SIB_Type_NB_r13_t *) malloc (3*sizeof(SIB_Type_NB_r13_t));
+
+  memset(&schedulingInfo_NB_IoT[0],0,sizeof(SchedulingInfo_NB_r13_t));
+  memset(&schedulingInfo_NB_IoT[1],0,sizeof(SchedulingInfo_NB_r13_t));
+  memset(&schedulingInfo_NB_IoT[2],0,sizeof(SchedulingInfo_NB_r13_t));    
+  memset(&sib_type_NB_IoT[0],0,sizeof(SIB_Type_NB_r13_t));
+  memset(&sib_type_NB_IoT[1],0,sizeof(SIB_Type_NB_r13_t));
+  memset(&sib_type_NB_IoT[2],0,sizeof(SIB_Type_NB_r13_t));
+
+
+  // Now, follow the scheduler SIB configuration
+  // There is only one sib2+sib3 common setting
+  schedulingInfo_NB_IoT[0].si_Periodicity_r13=SchedulingInfo_NB_r13__si_Periodicity_r13_rf4096;
+  schedulingInfo_NB_IoT[0].si_RepetitionPattern_r13=SchedulingInfo_NB_r13__si_RepetitionPattern_r13_every2ndRF; //This Indicates the starting radio frames within the SI window used for SI message transmission.
+  schedulingInfo_NB_IoT[0].si_TB_r13= SchedulingInfo_NB_r13__si_TB_r13_b680;//208 bits
+  
+
+  // This is for SIB2/3
+  /*SIB3 --> There is no mapping information of SIB2 since it is always present
+    *  in the first SystemInformation message
+    * listed in the schedulingInfoList list.
+    * */
+  sib_type_NB_IoT[0]=SIB_Type_NB_r13_sibType3_NB_r13;
+
+  ASN_SEQUENCE_ADD(&schedulingInfo_NB_IoT[0].sib_MappingInfo_r13.list,&sib_type_NB_IoT[0]);
+  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->schedulingInfoList_r13.list,&schedulingInfo_NB_IoT[0]);
+
+  //printf("[ASN Debug] SI P: %ld\n",(*sib1_NB_IoT)->schedulingInfoList_r13.list.array[0]->si_Periodicity_r13);
+
+#if defined(ENABLE_ITTI)
+
+  if (configuration->frame_type == TDD)
+#endif
+  {
+	//FIXME in NB-IoT mandatory to be FDD --> so must give an error
+	  LOG_E(RRC,"[NB-IoT %d] Frame Type is TDD --> not supported by NB-IoT, exiting\n", Mod_id); //correct?
+	  exit(-1);
+  }
+
+  //FIXME which value chose for the following parameter
+  (*sib1_NB_IoT)->si_WindowLength_r13=SystemInformationBlockType1_NB__si_WindowLength_r13_ms160;
+  (*sib1_NB_IoT)->si_RadioFrameOffset_r13= 0;
+
+  /*In Nb-IoT change/update of specific SI message can additionally be indicated by a SI message specific value tag
+   * systemInfoValueTagSI (there is no SystemInfoValueTag in SIB1-NB but only in MIB-NB)
+   *contained in systemInfoValueTagList_r13
+   **/
+  //FIXME correct?
+  (*sib1_NB_IoT)->systemInfoValueTagList_r13 = CALLOC(1, sizeof(struct SystemInfoValueTagList_NB_r13));
+  asn_set_empty(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list);
+  ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list,&systemInfoValueTagSI);
+
+
+#ifdef XER_PRINT //generate xml files
+  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
+#endif
+
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
+                                   (void*)bcch_message,
+                                   carrier->SIB1_NB_IoT,
+                                   100);
+
+  if (enc_rval.encoded > 0){ 
+       LOG_F(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  }
+
+
+#ifdef USER_MODE
+  LOG_D(RRC,"[NB-IoT] SystemInformationBlockType1-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
+#endif
+
+  if (enc_rval.encoded==-1) {
+    return(-1);
+  }
+
+  return((enc_rval.encoded+7)/8);
+}
+
+/*SIB23_NB_IoT*/
+//to be clarified is it is possible to carry SIB2 and SIB3  in the same SI message for NB-IoT?
+uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
+                        int CC_id,
+                        rrc_eNB_carrier_data_NB_IoT_t *carrier,//MP: this is already a carrier[CC_id]
+                        NbIoTRrcConfigurationReq *configuration ) //openair2/COMMON/rrc_messages_types.h
+{
+  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib2_NB_part;
+  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib3_NB_part;
+
+  BCCH_DL_SCH_Message_NB_t *bcch_message = &(carrier->systemInformation_NB_IoT); //is the systeminformation-->BCCH_DL_SCH_Message_NB
+  SystemInformationBlockType2_NB_r13_t *sib2_NB_IoT;
+  SystemInformationBlockType3_NB_r13_t *sib3_NB_IoT;
+
+  asn_enc_rval_t enc_rval;
+  RACH_Info_NB_r13_t rach_Info_NB_IoT;
+  NPRACH_Parameters_NB_r13_t *nprach_parameters;
+
+  //optional
+  long *connEstFailOffset = NULL;
+  connEstFailOffset = CALLOC(1, sizeof(long));
+
+//  RSRP_ThresholdsNPRACH_InfoList_NB_r13_t *rsrp_ThresholdsPrachInfoList;
+//  RSRP_Range_t rsrp_range;
+
+  ACK_NACK_NumRepetitions_NB_r13_t ack_nack_repetition;
+  struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13 *dmrs_config;
+  struct DL_GapConfig_NB_r13	*dl_Gap;
+
+  long *srs_SubframeConfig;
+  srs_SubframeConfig= CALLOC(1, sizeof(long));
+
+
+  if (bcch_message) {
+    memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
+  } else {
+    LOG_E(RRC,"[NB-IoT %d] BCCH_MESSAGE_NB is null, exiting\n", Mod_id);
+    exit(-1);
+  }
+
+  //before schould be allocated memory somewhere?
+//  if (!carrier->sib2_NB_IoT) {
+//    LOG_E(RRC,"[NB-IoT %d] sib2_NB_IoT is null, exiting\n", Mod_id);
+//    exit(-1);
+//  }
+//
+//  if (!carrier->sib3_NB_IoT) {
+//    LOG_E(RRC,"[NB-IoT %d] sib3_NB_IoT is null, exiting\n", Mod_id);
+//    exit(-1);
+//  }
+
+
+  LOG_I(RRC,"[NB-IoT %d] Configuration SIB2/3\n", Mod_id);
+
+  sib2_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+  sib3_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+  memset(sib2_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+  memset(sib3_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+
+  sib2_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib2_r13;
+  sib3_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib3_r13;
+
+  //may bug if not correct allocation of memory
+  carrier->sib2_NB_IoT = &sib2_NB_part->choice.sib2_r13;
+  carrier->sib3_NB_IoT = &sib3_NB_part->choice.sib3_r13;
+  sib2_NB_IoT = carrier->sib2_NB_IoT;
+  sib3_NB_IoT = carrier->sib3_NB_IoT;
+
+  nprach_parameters = (NPRACH_Parameters_NB_r13_t *) malloc (3*sizeof(NPRACH_Parameters_NB_r13_t));
+
+  memset(&nprach_parameters[0],0,sizeof(NPRACH_Parameters_NB_r13_t));
+  memset(&nprach_parameters[1],0,sizeof(NPRACH_Parameters_NB_r13_t));
+  memset(&nprach_parameters[2],0,sizeof(NPRACH_Parameters_NB_r13_t));
+
+/// SIB2-NB-----------------------------------------
+
+  //Barring is manage by ab-Enabled in MIB-NB (but is not a struct as ac-BarringInfo in LTE legacy)
+
+  //RACH Config. Common--------------------------------------------------------------
+  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.preambleTransMax_CE_r13 =
+   		  configuration->rach_preambleTransMax_CE_NB;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.powerRampingStep =
+	configuration->rach_powerRampingStep_NB;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.preambleInitialReceivedTargetPower =
+    configuration->rach_preambleInitialReceivedTargetPower_NB;
+
+  rach_Info_NB_IoT.ra_ResponseWindowSize_r13 = configuration->rach_raResponseWindowSize_NB;
+  rach_Info_NB_IoT.mac_ContentionResolutionTimer_r13 = configuration-> rach_macContentionResolutionTimer_NB;
+  //rach_infoList max size = maxNPRACH-Resources-NB-r13 = 3
+  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.rach_InfoList_r13.list,&rach_Info_NB_IoT);
+
+  //TS 36.331 pag 614 --> if not present the value to infinity sould be used
+  *connEstFailOffset = 0;
+  
+  sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.connEstFailOffset_r13 = connEstFailOffset; /*OPTIONAL*/
+
+
+  // BCCH-Config-NB-IoT----------------------------------------------------------------
+  sib2_NB_IoT->radioResourceConfigCommon_r13.bcch_Config_r13.modificationPeriodCoeff_r13
+    = configuration->bcch_modificationPeriodCoeff_NB;
+
+  // PCCH-Config-NB-IoT-----------------------------------------------------------------
+  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.defaultPagingCycle_r13
+    = configuration->pcch_defaultPagingCycle_NB;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.nB_r13 = configuration->pcch_nB_NB;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.npdcch_NumRepetitionPaging_r13 = configuration-> pcch_npdcch_NumRepetitionPaging_NB;
+
+  //NPRACH-Config-NB-IoT-----------------------------------------------------------------
+
+  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13 = NULL; 
+  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_CP_Length_r13 = configuration->nprach_CP_Length;
+  /*OPTIONAL*/
+//   =CALLOC(1, sizeof(struct RSRP_ThresholdsNPRACH_InfoList_NB_r13)); //fatto uguale dopo
+//   rsrp_ThresholdsPrachInfoList = sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13;
+//   rsrp_range = configuration->nprach_rsrp_range_NB;
+//   ASN_SEQUENCE_ADD(&rsrp_ThresholdsPrachInfoList->list,rsrp_range);
+
+  // According configuration to set the 3 CE level configuration setting
+
+  nprach_parameters[0].nprach_Periodicity_r13               = configuration->nprach_Periodicity[0];
+  nprach_parameters[0].nprach_StartTime_r13                 = configuration->nprach_StartTime[0];
+  nprach_parameters[0].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[0];
+  nprach_parameters[0].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[0];
+  nprach_parameters[0].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[0];
+  nprach_parameters[0].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart;
+  nprach_parameters[0].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB;
+  nprach_parameters[0].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[0];
+  nprach_parameters[0].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[0];
+  nprach_parameters[0].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[0];
+
+  nprach_parameters[1].nprach_Periodicity_r13               = configuration->nprach_Periodicity[1];
+  nprach_parameters[1].nprach_StartTime_r13                 = configuration->nprach_StartTime[1];
+  nprach_parameters[1].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[1];
+  nprach_parameters[1].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[1];
+  nprach_parameters[1].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[1];
+  nprach_parameters[1].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart;
+  nprach_parameters[1].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB;
+  nprach_parameters[1].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[1];
+  nprach_parameters[1].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[1];
+  nprach_parameters[1].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[1];
+
+  nprach_parameters[2].nprach_Periodicity_r13               = configuration->nprach_Periodicity[2];
+  nprach_parameters[2].nprach_StartTime_r13                 = configuration->nprach_StartTime[2];
+  nprach_parameters[2].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[2];
+  nprach_parameters[2].nprach_NumSubcarriers_r13            = configuration->nprach_NumSubcarriers[2];
+  nprach_parameters[2].numRepetitionsPerPreambleAttempt_r13 = configuration->numRepetitionsPerPreambleAttempt_NB[2];
+  nprach_parameters[2].nprach_SubcarrierMSG3_RangeStart_r13 = configuration->nprach_SubcarrierMSG3_RangeStart;
+  nprach_parameters[2].maxNumPreambleAttemptCE_r13          = configuration->maxNumPreambleAttemptCE_NB;
+  nprach_parameters[2].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[2];
+  nprach_parameters[2].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[2];
+  nprach_parameters[2].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[2];
+
+
+  //nprach_parameterList have a max size of 3 possible nprach configuration (see maxNPRACH_Resources_NB_r13)
+  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[0]);
+  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[1]);
+  ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[2]);
+  
+  // NPDSCH-Config NB-IOT
+  sib2_NB_IoT->radioResourceConfigCommon_r13.npdsch_ConfigCommon_r13.nrs_Power_r13= configuration->npdsch_nrs_Power;
+
+
+  //NPUSCH-Config NB-IoT----------------------------------------------------------------
+  //list of size 3 (see maxNPRACH_Resources_NB_r13)
+  ack_nack_repetition = configuration-> npusch_ack_nack_numRepetitions_NB; //is an enumerative
+  ASN_SEQUENCE_ADD(&(sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ack_NACK_NumRepetitions_Msg4_r13.list) ,&ack_nack_repetition);
+
+  *srs_SubframeConfig = configuration->npusch_srs_SubframeConfig_NB;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.srs_SubframeConfig_r13= srs_SubframeConfig; /*OPTIONAL*/
+
+
+  /*OPTIONAL*/
+  dmrs_config = CALLOC(1,sizeof(struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13));
+  dmrs_config->threeTone_CyclicShift_r13 = configuration->npusch_threeTone_CyclicShift_r13;
+  dmrs_config->sixTone_CyclicShift_r13 = configuration->npusch_sixTone_CyclicShift_r13;
+
+  /*OPTIONAL
+   * -define the base sequence for a DMRS sequence in a cell with multi tone transmission (3,6,12) see TS 36.331 NPUSCH-Config-NB
+   * -if not defined will be calculated based on the cellID once we configure the phy layer (rrc_mac_config_req) through the config_sib2 */
+  dmrs_config->threeTone_BaseSequence_r13 = NULL;
+  dmrs_config->sixTone_BaseSequence_r13 = NULL;
+  dmrs_config->twelveTone_BaseSequence_r13 = NULL;
+
+  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.dmrs_Config_r13 = dmrs_config;
+
+  //ulReferenceSignalsNPUSCH
+  /*Reference Signal (RS) for UL in NB-IoT is called DRS (Demodulation Reference Signal)
+   * sequence-group hopping can be enabled or disabled by means of the cell-specific parameter groupHoppingEnabled_r13
+   * sequence-group hopping can be disabled for certain specific UE through the parameter groupHoppingDisabled (physicalConfigDedicated)
+   * groupAssignmentNPUSCH--> is used for generate the sequence-shift pattern
+   */
+  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupHoppingEnabled_r13= configuration->npusch_groupHoppingEnabled;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupAssignmentNPUSCH_r13 =configuration->npusch_groupAssignmentNPUSCH_r13;
+
+
+  //dl_GAP---------------------------------------------------------------------------------/*OPTIONAL*/
+  dl_Gap = CALLOC(1,sizeof(struct DL_GapConfig_NB_r13));
+  dl_Gap->dl_GapDurationCoeff_r13= configuration-> dl_GapDurationCoeff_NB;
+  dl_Gap->dl_GapPeriodicity_r13= configuration->dl_GapPeriodicity_NB;
+  dl_Gap->dl_GapThreshold_r13= configuration->dl_GapThreshold_NB;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.dl_Gap_r13 = dl_Gap;
+
+
+  // uplinkPowerControlCommon - NB-IoT------------------------------------------------------
+  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.p0_NominalNPUSCH_r13 = configuration->npusch_p0_NominalNPUSCH;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.deltaPreambleMsg3_r13 = configuration->deltaPreambleMsg3;
+  sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.alpha_r13 = configuration->npusch_alpha;
+  //no deltaFlist_PUCCH and no UL cyclic prefix
+
+  // UE Timers and Constants -NB-IoT--------------------------------------------------------
+  sib2_NB_IoT->ue_TimersAndConstants_r13.t300_r13 = configuration-> ue_TimersAndConstants_t300_NB;
+  sib2_NB_IoT->ue_TimersAndConstants_r13.t301_r13 = configuration-> ue_TimersAndConstants_t301_NB;
+  sib2_NB_IoT->ue_TimersAndConstants_r13.t310_r13 = configuration-> ue_TimersAndConstants_t310_NB;
+  sib2_NB_IoT->ue_TimersAndConstants_r13.t311_r13 = configuration-> ue_TimersAndConstants_t311_NB;
+  sib2_NB_IoT->ue_TimersAndConstants_r13.n310_r13 = configuration-> ue_TimersAndConstants_n310_NB;
+  sib2_NB_IoT->ue_TimersAndConstants_r13.n311_r13 = configuration-> ue_TimersAndConstants_n311_NB;
+
+  //other SIB2-NB Parameters--------------------------------------------------------------------------------
+  sib2_NB_IoT->freqInfo_r13.additionalSpectrumEmission_r13 = 1;
+  sib2_NB_IoT->freqInfo_r13.ul_CarrierFreq_r13 = NULL; /*OPTIONAL*/
+
+  sib2_NB_IoT->timeAlignmentTimerCommon_r13=TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
+
+  /*OPTIONAL*/
+  sib2_NB_IoT->multiBandInfoList_r13 = NULL;
+
+/// SIB3-NB-------------------------------------------------------
+
+  sib3_NB_IoT->cellReselectionInfoCommon_r13.q_Hyst_r13=SystemInformationBlockType3_NB_r13__cellReselectionInfoCommon_r13__q_Hyst_r13_dB4;
+  sib3_NB_IoT->cellReselectionServingFreqInfo_r13.s_NonIntraSearch_r13=0; //or define in configuration?
+
+  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_RxLevMin_r13 = -70;
+  //new
+  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13 = CALLOC(1,sizeof(*sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13));
+  *(sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13)= 10; //a caso
+
+  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.p_Max_r13 = NULL;
+  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.s_IntraSearchP_r13 = 31; // s_intraSearch --> s_intraSearchP!!! (they call in a different way)
+  sib3_NB_IoT->intraFreqCellReselectionInfo_r13.t_Reselection_r13=1;
+
+  //how to manage?
+  sib3_NB_IoT->freqBandInfo_r13 = NULL;
+  sib3_NB_IoT->multiBandInfoList_r13 = NULL;
+
+
+///BCCH message (generate the SI message)
+  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
+  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformation_r13;
+
+  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.present = SystemInformation_NB__criticalExtensions_PR_systemInformation_r13;
+  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list.count=0;
+
+  ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
+                   sib2_NB_part);
+  ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
+                   sib3_NB_part);
+
+#ifdef XER_PRINT
+  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
+                                   (void*)bcch_message,
+                                   carrier->SIB23_NB_IoT,
+                                   900);
+//  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+//               enc_rval.failed_type->name, enc_rval.encoded);
+
+//#if defined(ENABLE_ITTI).....
+
+
+#ifdef USER_MODE
+  LOG_D(RRC,"[NB-IoT] SystemInformation-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
+#endif
+
+  if (enc_rval.encoded==-1) {
+    msg("[RRC] ASN1 : SI-NB encoding failed for SIB23_NB_IoT\n");
+    return(-1);
+  }
+
+  carrier->sib2_NB_IoT = sib2_NB_IoT;
+  carrier->sib3_NB_IoT = sib3_NB_IoT;
+
+  return((enc_rval.encoded+7)/8);
+}
+
+/*do_RRCConnectionSetup_NB_IoT--> the aim is to establish SRB1 and SRB1bis(implicitly)*/
+uint8_t do_RRCConnectionSetup_NB_IoT(
+  const protocol_ctxt_t*     const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*      const ue_context_pP,
+  int                              CC_id,
+  uint8_t*                   const buffer, //Srb0.Tx_buffer.Payload
+  const uint8_t                    Transaction_id,
+  const NB_IoT_DL_FRAME_PARMS* const frame_parms, // maybe not used
+  SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT, //for both SRB1bis and SRB1
+  struct PhysicalConfigDedicated_NB_r13** physicalConfigDedicated_NB_IoT
+)
+
+{
+
+ asn_enc_rval_t enc_rval;
+
+
+ //MP:logical channel group not defined for Nb-IoT
+
+ //MP: logical channel priority pag 605 (is 1 for SRB1 and for SRB1bis should be the same)
+ //long* prioritySRB1 = NULL;
+ long* prioritySRB1bis = NULL;
+ BOOLEAN_t* logicalChannelSR_Prohibit =NULL; //pag 605
+ BOOLEAN_t* npusch_AllSymbols= NULL;
+
+// struct SRB_ToAddMod_NB_r13* SRB1_config_NB = NULL;
+// struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1_rlc_config_NB = NULL;
+// struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1_lchan_config_NB = NULL;
+
+ struct SRB_ToAddMod_NB_r13* SRB1bis_config_NB_IoT = NULL;
+ struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1bis_rlc_config_NB_IoT = NULL;
+ struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1bis_lchan_config_NB_IoT = NULL;
+
+ //No UL_specific parameters for NB-IoT in LogicalChanelConfig-NB
+
+ PhysicalConfigDedicated_NB_r13_t* physicalConfigDedicated2_NB_IoT = NULL;
+ DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
+ RRCConnectionSetup_NB_t* rrcConnectionSetup_NB_IoT = NULL;
+
+ memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
+ dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
+ dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionSetup_r13;
+ rrcConnectionSetup_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionSetup_r13;
+
+
+ if (*SRB_configList_NB_IoT) {
+   free(*SRB_configList_NB_IoT);
+ }
+ *SRB_configList_NB_IoT = CALLOC(1,sizeof(SRB_ToAddModList_NB_r13_t));
+
+/// SRB1--------------------
+ {
+// SRB1_config_NB = CALLOC(1,sizeof(*SRB1_config_NB));
+//
+// //no srb_Identity in SRB_ToAddMod_NB
+//
+// SRB1_rlc_config_NB = CALLOC(1,sizeof(*SRB1_rlc_config_NB));
+// SRB1_config_NB->rlc_Config_r13   = SRB1_rlc_config_NB;
+//
+// SRB1_rlc_config_NB->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
+// SRB1_rlc_config_NB->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//the only possible in NB_IoT
+//
+//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_timer_poll_retransmit_r13;
+//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_max_retx_threshold_r13;
+//// //(musT be disabled--> SRB1 config pag 640 specs )
+//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
+//
+//
+// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
+// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
+// //(musT be disabled--> SRB1 config pag 640 specs )
+// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 = NULL;
+//
+// SRB1_lchan_config_NB = CALLOC(1,sizeof(*SRB1_lchan_config_NB));
+// SRB1_config_NB->logicalChannelConfig_r13  = SRB1_lchan_config_NB;
+//
+// SRB1_lchan_config_NB->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
+//
+//
+// prioritySRB1 = CALLOC(1, sizeof(long));
+// *prioritySRB1 = 1;
+// SRB1_lchan_config_NB->choice.explicitValue.priority_r13 = prioritySRB1;
+//
+// logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
+// *logicalChannelSR_Prohibit = 1;
+// //schould be set to TRUE (specs pag 641)
+// SRB1_lchan_config_NB->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
+//
+// //ADD SRB1
+// ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1_config_NB);
+ }
+
+///SRB1bis (The configuration for SRB1 and SRB1bis is the same) the only difference is the logical channel identity = 3 but not set here
+
+		 SRB1bis_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_config_NB_IoT));
+
+		 //no srb_Identity in SRB_ToAddMod_NB
+		 SRB1bis_rlc_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_rlc_config_NB_IoT));
+		 SRB1bis_config_NB_IoT->rlc_Config_r13   = SRB1bis_rlc_config_NB_IoT;
+
+		 SRB1bis_rlc_config_NB_IoT->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
+		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//MP: the only possible RLC config in NB_IoT
+
+		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
+		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
+		 //(musT be disabled--> SRB1 config pag 640 specs )
+		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
+
+		 SRB1bis_lchan_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_lchan_config_NB_IoT));
+		 SRB1bis_config_NB_IoT->logicalChannelConfig_r13  = SRB1bis_lchan_config_NB_IoT;
+
+		 SRB1bis_lchan_config_NB_IoT->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
+
+		 prioritySRB1bis = CALLOC(1, sizeof(long));
+		 *prioritySRB1bis = 1; //same as SRB1?
+		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = prioritySRB1bis;
+
+		 logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
+		 *logicalChannelSR_Prohibit = 1; //schould be set to TRUE (specs pag 641)
+		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
+
+		 //ADD SRB1bis
+		 //MP: Actually there is no way to distinguish SRB1 and SRB1bis once put in the list
+		 //MP: SRB_ToAddModList_NB_r13_t size = 1
+		 ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1bis_config_NB_IoT);
+
+
+ // PhysicalConfigDedicated (NPDCCH, NPUSCH, CarrierConfig, UplinkPowerControl)
+
+ physicalConfigDedicated2_NB_IoT = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT));
+ *physicalConfigDedicated_NB_IoT = physicalConfigDedicated2_NB_IoT;
+
+ physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13= CALLOC(1, sizeof(*physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13));
+ physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13));
+ physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13));
+ physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13));
+
+ //no tpc, no cqi and no pucch, no pdsch, no soundingRS, no AntennaInfo, no scheduling request config
+
+ /*
+  * NB-IoT supports the operation with either one or two antenna ports, AP0 and AP1.
+  * For the latter case, Space Frequency Block Coding (SFBC) is applied.
+  * Once selected, the same transmission scheme applies to NPBCH, NPDCCH, and NPDSCH.
+  * */
+
+ //FIXME: MP: CarrierConfigDedicated check the set values ----------------------------------------------
+
+  //DL
+
+ physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_CarrierFreq_r13.carrierFreq_r13=0;//random value set
+ physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13= CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13));
+		 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13->present=
+				 	 	 	 	 	 	 	 	 DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13_PR_useNoBitmap_r13;
+
+ physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13 = CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13));
+ physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13->present =
+		  	  	  	  	  	  	  	  	  	  	  DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13_PR_useNoGap_r13;
+
+ physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.inbandCarrierInfo_r13= NULL;
+
+  //UL
+ physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->ul_CarrierConfig_r13.ul_CarrierFreq_r13= NULL;
+
+ // NPDCCH
+ physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_NumRepetitions_r13 =0;
+ physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_Offset_USS_r13 =0;
+ physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_StartSF_USS_r13=0;
+
+ // NPUSCH //(specs TS 36.331 v14.2.1 pag 643) /* OPTIONAL */
+ physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->ack_NACK_NumRepetitions_r13= NULL;
+ npusch_AllSymbols= CALLOC(1, sizeof(BOOLEAN_t));
+ *npusch_AllSymbols= 1; //TRUE
+ physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->npusch_AllSymbols_r13= npusch_AllSymbols; /* OPTIONAL */
+ physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->groupHoppingDisabled_r13=NULL; /* OPTIONAL */
+
+ // UplinkPowerControlDedicated
+ physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13->p0_UE_NPUSCH_r13 = 0; // 0 dB (specs TS36.331 v14.2.1 pag 643)
+
+
+ //Fill the rrcConnectionSetup-NB message
+ rrcConnectionSetup_NB_IoT->rrc_TransactionIdentifier = Transaction_id; //input value
+ rrcConnectionSetup_NB_IoT->criticalExtensions.present = RRCConnectionSetup_NB__criticalExtensions_PR_c1;
+ rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionSetup_NB__criticalExtensions__c1_PR_rrcConnectionSetup_r13 ;
+ //MP: carry only SRB1bis at the moment and phyConfigDedicated
+ rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = *SRB_configList_NB_IoT;
+ rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
+ rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
+ rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13 = NULL;
+ rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = physicalConfigDedicated2_NB_IoT;
+ rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13 = NULL;
+
+#ifdef XER_PRINT
+ xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
+#endif
+ enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
+                                  (void*)&dl_ccch_msg_NB_IoT,
+                                  buffer,
+                                  100);
+
+ if (enc_rval.encoded <= 0) {
+     LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+              enc_rval.failed_type->name, enc_rval.encoded);
+ }
+
+#ifdef USER_MODE
+ LOG_D(RRC,"RRCConnectionSetup-NB Encoded %zd bits (%zd bytes), ecause %d\n",
+       enc_rval.encoded,(enc_rval.encoded+7)/8,ecause);
+#endif
+
+ return((enc_rval.encoded+7)/8);
+}
+
+/*do_SecurityModeCommand - exactly the same as previous implementation*/
+uint8_t do_SecurityModeCommand_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  uint8_t* const buffer,
+  const uint8_t Transaction_id,
+  const uint8_t cipheringAlgorithm,
+  const uint8_t integrityProtAlgorithm)
+{
+  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  asn_enc_rval_t enc_rval;
+
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
+
+  dl_dcch_msg_NB_IoT.message.present = DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_securityModeCommand_r13;
+
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.rrc_TransactionIdentifier = Transaction_id;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
+
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.present =
+		  SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;
+
+  // the two following information could be based on the mod_id
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm
+    = (CipheringAlgorithm_r12_t)cipheringAlgorithm; //bug solved
+
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm
+    = (e_SecurityAlgorithmConfig__integrityProtAlgorithm)integrityProtAlgorithm;
+
+//only changed "asn_DEF_DL_DCCH_Message_NB"
+#ifdef XER_PRINT
+  xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   buffer,
+                                   100);
+  if (enc_rval.encoded <= 0) {
+      LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  }
+
+
+//#if defined(ENABLE_ITTI)
+//# if !defined(DISABLE_XER_SPRINT)....
+
+#ifdef USER_MODE
+  LOG_D(RRC,"[NB-IoT %d] securityModeCommand-NB for UE %x Encoded %zd bits (%zd bytes)\n",
+        ctxt_pP->module_id,
+        ctxt_pP->rnti,
+        enc_rval.encoded,
+        (enc_rval.encoded+7)/8);
+#endif
+
+  if (enc_rval.encoded==-1) {
+    LOG_E(RRC,"[NB-IoT %d] ASN1 : securityModeCommand-NB encoding failed for UE %x\n",
+          ctxt_pP->module_id,
+          ctxt_pP->rnti);
+    return(-1);
+  }
+
+  return((enc_rval.encoded+7)/8);
+}
+
+/*do_UECapabilityEnquiry_NB_IoT - very similar to legacy lte*/
+uint8_t do_UECapabilityEnquiry_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  uint8_t*               const buffer,
+  const uint8_t                Transaction_id
+)
+
+{
+
+  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  //no RAT type in NB-IoT
+  asn_enc_rval_t enc_rval;
+
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
+
+  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_ueCapabilityEnquiry_r13;
+
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.rrc_TransactionIdentifier = Transaction_id;
+
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.present = UECapabilityEnquiry_NB__criticalExtensions_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.choice.c1.present =
+		  UECapabilityEnquiry_NB__criticalExtensions__c1_PR_ueCapabilityEnquiry_r13;
+
+  //no ue_CapabilityRequest (list of RAT_Type)
+
+//only changed "asn_DEF_DL_DCCH_Message_NB"
+#ifdef XER_PRINT
+  xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   buffer,
+                                   100);
+  if (enc_rval.encoded <= 0) {
+     LOG_F(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+    }
+
+//#if defined(ENABLE_ITTI)
+//# if !defined(DISABLE_XER_SPRINT)....
+
+#ifdef USER_MODE
+  LOG_D(RRC,"[NB-IoT %d] UECapabilityEnquiry-NB for UE %x Encoded %zd bits (%zd bytes)\n",
+        ctxt_pP->module_id,
+        ctxt_pP->rnti,
+        enc_rval.encoded,
+        (enc_rval.encoded+7)/8);
+#endif
+
+  if (enc_rval.encoded==-1) {
+    LOG_E(RRC,"[NB-IoT %d] ASN1 : UECapabilityEnquiry-NB encoding failed for UE %x\n",
+          ctxt_pP->module_id,
+          ctxt_pP->rnti);
+    return(-1);
+  }
+
+  return((enc_rval.encoded+7)/8);
+}
+
+/*do_RRCConnectionReconfiguration_NB_IoT-->may convey information for resource configuration
+ * (including RBs, MAC main configuration and physical channel configuration)
+ * including any associated dedicated NAS information.*/
+uint16_t do_RRCConnectionReconfiguration_NB_IoT(
+  const protocol_ctxt_t*        const ctxt_pP,
+    uint8_t                            *buffer,
+    uint8_t                             Transaction_id,
+    SRB_ToAddModList_NB_r13_t          *SRB1_list_NB, //SRB_ConfigList2 (default)--> only SRB1
+    DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT, //DRB_ConfigList (default)
+    DRB_ToReleaseList_NB_r13_t         *DRB_list2_NB_IoT, //is NULL when passed
+    struct PhysicalConfigDedicated_NB_r13     *physicalConfigDedicated_NB_IoT,
+	MAC_MainConfig_NB_r13_t                   *mac_MainConfig_NB_IoT,
+  struct RRCConnectionReconfiguration_NB_r13_IEs__dedicatedInfoNASList_r13* dedicatedInfoNASList_NB_IoT)
+
+{
+
+ //check on DRB_list if contains more than 2 DRB?
+
+  asn_enc_rval_t enc_rval;
+  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  RRCConnectionReconfiguration_NB_t *rrcConnectionReconfiguration_NB;
+
+
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
+
+  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionReconfiguration_r13;
+  rrcConnectionReconfiguration_NB          = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReconfiguration_r13;
+
+  // RRCConnectionReconfiguration
+  rrcConnectionReconfiguration_NB->rrc_TransactionIdentifier = Transaction_id;
+  rrcConnectionReconfiguration_NB->criticalExtensions.present = RRCConnectionReconfiguration_NB__criticalExtensions_PR_c1;
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.present =RRCConnectionReconfiguration_NB__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r13 ;
+
+  //RAdioResourceconfigDedicated
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13 =
+		  CALLOC(1,sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13));
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->srb_ToAddModList_r13 = SRB1_list_NB; //only SRB1
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToAddModList_r13 = DRB_list_NB_IoT;
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToReleaseList_r13 = DRB_list2_NB_IoT; //NULL
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->physicalConfigDedicated_r13 = physicalConfigDedicated_NB_IoT;
+  //FIXME may not used now
+  //rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->rlf_TimersAndConstants_r13
+
+  if (mac_MainConfig_NB_IoT!=NULL) {
+    rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13 =
+    		CALLOC(1, sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13));
+    rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->present
+      =RadioResourceConfigDedicated_NB_r13__mac_MainConfig_r13_PR_explicitValue_r13;
+   //why memcopy only this one?
+    memcpy(&rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->choice.explicitValue_r13,
+           mac_MainConfig_NB_IoT, sizeof(*mac_MainConfig_NB_IoT));
+
+  } else {
+	  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13=NULL;
+  }
+
+  //no measConfig, measIDlist
+  //no mobilityControlInfo
+
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.dedicatedInfoNASList_r13 = dedicatedInfoNASList_NB_IoT;
+  //mainly used for cell-reselection/handover purposes??
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.fullConfig_r13 = NULL;
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   buffer,
+                                   RRC_BUF_SIZE);
+  if (enc_rval.encoded <= 0) {
+     LOG_F(RRC, "ASN1 message encoding failed %s, %li\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  }
+
+  //changed only asn_DEF_DL_DCCH_Message_NB
+#ifdef XER_PRINT
+  xer_fprint(stdout,&asn_DEF_DL_DCCH_Message_NB,(void*)&dl_dcch_msg_NB_IoT);
+#endif
+
+//#if defined(ENABLE_ITTI)
+//# if !defined(DISABLE_XER_SPRINT)...
+
+
+  LOG_I(RRC,"RRCConnectionReconfiguration-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
+
+  return((enc_rval.encoded+7)/8);
+}
+
+/*do_RRCConnectionReestablishmentReject - exactly the same as legacy LTE*/
+uint8_t do_RRCConnectionReestablishmentReject_NB_IoT(
+    uint8_t                    Mod_id,
+    uint8_t*                   const buffer)
+{
+
+  asn_enc_rval_t enc_rval;
+
+  DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
+  RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;
+
+  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
+  dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
+  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishmentReject_r13;
+  rrcConnectionReestablishmentReject    = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishmentReject_r13;
+
+  // RRCConnectionReestablishmentReject //exactly the same as LTE
+  rrcConnectionReestablishmentReject->criticalExtensions.present = RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;
+
+  //Only change in "asn_DEF_DL_CCCH_Message_NB"
+#ifdef XER_PRINT
+  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg_NB_IoT);
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
+                                   (void*)&dl_ccch_msg_NB_IoT,
+                                   buffer,
+                                   100);
+  if (enc_rval.encoded <= 0) {
+     LOG_F(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  }
+
+  //Only change in "asn_DEF_DL_CCCH_Message_NB"
+#if defined(ENABLE_ITTI)
+# if !defined(DISABLE_XER_SPRINT)
+  {
+    char        message_string[20000];
+    size_t      message_string_size;
+
+    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
+      MessageDef *msg_p;
+
+      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
+      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
+      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
+
+      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
+    }
+  }
+# endif
+#endif
+
+#ifdef USER_MODE
+  LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %zd bits (%zd bytes)\n",
+        enc_rval.encoded,(enc_rval.encoded+7)/8);
+#endif
+
+  return((enc_rval.encoded+7)/8);
+}
+
+/*do_RRCConnectionReject_NB_IoT*/
+uint8_t do_RRCConnectionReject_NB_IoT(
+    uint8_t                    Mod_id,
+    uint8_t*                   const buffer)
+
+{
+
+  asn_enc_rval_t enc_rval;
+
+  DL_CCCH_Message_NB_t          dl_ccch_msg_NB_IoT;
+  RRCConnectionReject_NB_t      *rrcConnectionReject_NB_IoT;
+
+  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
+  dl_ccch_msg_NB_IoT.message.present           = DL_CCCH_MessageType_NB_PR_c1;
+  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReject_r13;
+  rrcConnectionReject_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReject_r13;
+
+  // RRCConnectionReject-NB_IoT
+  rrcConnectionReject_NB_IoT->criticalExtensions.present = RRCConnectionReject_NB__criticalExtensions_PR_c1;
+  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReject_NB__criticalExtensions__c1_PR_rrcConnectionReject_r13;
+  /* let's put an extended wait time of 1s for the moment */
+  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.extendedWaitTime_r13 = 1;
+  //new-use of suspend indication
+  //If present, this field indicates that the UE should remain suspended and not release its stored context.
+  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13=
+		  CALLOC(1, sizeof(long));
+  *(rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13)=
+		  RRCConnectionReject_NB_r13_IEs__rrc_SuspendIndication_r13_true;
+
+  //Only Modified "asn_DEF_DL_CCCH_Message_NB"
+#ifdef XER_PRINT
+  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg);
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
+                                   (void*)&dl_ccch_msg_NB_IoT,
+                                   buffer,
+                                   100);
+  if (enc_rval.encoded <= 0) {
+     LOG_F(RRC, "ASN1 message encoding failed (%s, %ld)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  }
+
+#if defined(ENABLE_ITTI)
+# if !defined(DISABLE_XER_SPRINT)
+  {
+    char        message_string[20000];
+    size_t      message_string_size;
+
+    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
+      MessageDef *msg_p;
+
+      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
+      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
+      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
+
+      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
+    }
+  }
+# endif
+#endif
+
+#ifdef USER_MODE
+  LOG_D(RRC,"RRCConnectionReject-NB Encoded %zd bits (%zd bytes)\n",
+        enc_rval.encoded,(enc_rval.encoded+7)/8);
+#endif
+
+  return((enc_rval.encoded+7)/8);
+}
+
+
+//no do_MBSFNAreaConfig(..) in NB-IoT
+//no do_MeasurementReport(..) in NB-IoT
+
+/*do_DLInformationTransfer_NB*/
+uint8_t do_DLInformationTransfer_NB_IoT(
+		uint8_t Mod_id,
+		uint8_t **buffer,
+		uint8_t transaction_id,
+		uint32_t pdu_length,
+		uint8_t *pdu_buffer)
+
+{
+  ssize_t encoded;
+
+  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+
+  memset(&dl_dcch_msg_NB_IoT, 0, sizeof(DL_DCCH_Message_NB_t));
+
+  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_dlInformationTransfer_r13;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.rrc_TransactionIdentifier = transaction_id;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.present = DLInformationTransfer_NB__criticalExtensions_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.present = DLInformationTransfer_NB__criticalExtensions__c1_PR_dlInformationTransfer_r13;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.size = pdu_length;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.buf = pdu_buffer;
+
+  encoded = uper_encode_to_new_buffer (&asn_DEF_DL_DCCH_Message_NB, NULL, (void*) &dl_dcch_msg_NB_IoT, (void **) buffer);
+
+  //only change in "asn_DEF_DL_DCCH_Message_NB"
+#if defined(ENABLE_ITTI)
+# if !defined(DISABLE_XER_SPRINT)
+  {
+    char        message_string[10000];
+    size_t      message_string_size;
+
+    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message_NB, (void *)&dl_dcch_msg_NB_IoT)) > 0) {
+      MessageDef *msg_p;
+
+      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
+      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
+      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
+
+      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
+    }
+  }
+# endif
+#endif
+
+  return encoded;
+}
+
+/*do_ULInformationTransfer*/
+//for the moment is not needed (UE-SIDE)
+
+/*OAI_UECapability_t *fill_ue_capability*/
+
+/*do_RRCConnectionReestablishment_NB-->used to re-establish SRB1*/ //which parameter to use?
+uint8_t do_RRCConnectionReestablishment_NB_IoT(
+		uint8_t Mod_id,
+		uint8_t* const buffer,
+		const uint8_t     Transaction_id,
+		const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed
+		SRB_ToAddModList_NB_r13_t*      SRB_list_NB_IoT) //should contain SRB1 already configured?
+{
+
+	asn_enc_rval_t enc_rval;
+	DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
+	RRCConnectionReestablishment_NB_t* rrcConnectionReestablishment_NB_IoT;
+
+	memset(&dl_ccch_msg_NB_IoT, 0, sizeof(DL_CCCH_Message_NB_t));
+
+	dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
+	dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishment_r13;
+	rrcConnectionReestablishment_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishment_r13;
+
+	//rrcConnectionReestablishment_NB
+	rrcConnectionReestablishment_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.present = RRCConnectionReestablishment_NB__criticalExtensions_PR_c1;
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReestablishment_NB__criticalExtensions__c1_PR_rrcConnectionReestablishment_r13;
+
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = SRB_list_NB_IoT;
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13= NULL;
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13= NULL;
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = NULL;
+
+	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.nextHopChainingCount_r13=0;
+
+	enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
+	                                   (void*)&dl_ccch_msg_NB_IoT,
+	                                   buffer,
+	                                   RRC_BUF_SIZE);
+
+	if (enc_rval.encoded <= 0) {
+           LOG_F(RRC, "ASN1 message encoding failed (%s, %li)!\n",
+	               enc_rval.failed_type->name, enc_rval.encoded);
+        }
+
+#ifdef XER_PRINT
+  xer_fprint(stdout,&asn_DEF_DL_CCCH_Message_NB,(void*)&dl_ccch_msg_NB_IoT);
+#endif
+
+#if defined(ENABLE_ITTI)
+# if !defined(DISABLE_XER_SPRINT)
+  {
+    char        message_string[30000];
+    size_t      message_string_size;
+
+    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
+      MessageDef *msg_p;
+
+      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
+      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
+      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
+
+      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
+    }
+  }
+# endif
+#endif
+
+  LOG_I(RRC,"RRCConnectionReestablishment-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
+  return 0;
+}
+
+/*do_RRCConnectionRelease_NB--> is used to command the release of an RRC connection*/
+uint8_t do_RRCConnectionRelease_NB_IoT(
+  uint8_t                             Mod_id,
+  uint8_t                            *buffer,
+ const uint8_t                             Transaction_id)
+{
+
+  asn_enc_rval_t enc_rval;
+
+  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  RRCConnectionRelease_NB_t *rrcConnectionRelease_NB_IoT;
+
+
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
+
+  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionRelease_r13;
+  rrcConnectionRelease_NB_IoT                  = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionRelease_r13;
+
+  // RRCConnectionRelease
+  rrcConnectionRelease_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
+  rrcConnectionRelease_NB_IoT->criticalExtensions.present = RRCConnectionRelease_NB__criticalExtensions_PR_c1;
+  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionRelease_NB__criticalExtensions__c1_PR_rrcConnectionRelease_r13 ;
+
+  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.releaseCause_r13 = ReleaseCause_NB_r13_other;
+  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.redirectedCarrierInfo_r13 = NULL;
+  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.extendedWaitTime_r13 = NULL;
+
+  //Why allocate memory for non critical extension?
+  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension=CALLOC(1,
+      sizeof(*rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension));
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   buffer,
+                                   RRC_BUF_SIZE);//check
+
+  return((enc_rval.encoded+7)/8);
+}
+
+
+
+
diff --git a/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.h b/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.h
index e88bdadbd9d87116c4997c5f6fa66e78c4dfec2e..6fb073f80de30638aad1208c52a0af79edc42250 100644
--- a/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.h
+++ b/openair2/RRC/LITE/MESSAGES/asn1_msg_NB_IoT.h
@@ -1,293 +1,293 @@
-/*
- * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*! \file asn1_msg.h
-* \brief primitives to build the asn1 messages
-* \author Raymond Knopp, Navid Nikaein and Michele Paffetti
-* \date 2011, 2017
-* \version 1.0
-* \company Eurecom
-* \email: raymond.knopp@eurecom.fr ,navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
-*/
-
-#ifdef USER_MODE
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h> /* for atoi(3) */
-#include <unistd.h> /* for getopt(3) */
-#include <string.h> /* for strerror(3) */
-#include <sysexits.h> /* for EX_* exit codes */
-#include <errno.h>  /* for errno */
-#else
-#include <linux/module.h>  /* Needed by all modules */
-#endif
-
-#include <asn_application.h>
-#include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
-
-
-#include "RRC/LITE/defs_NB_IoT.h"
-
-/*
- * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
- * output into the chosen string buffer.
- * RETURN VALUES:
- *       0: The structure is printed.
- *      -1: Problem printing the structure.
- * WARNING: No sensible error value is returned.
- */
-
-
-/**
-\brief Generate configuration for SIB1 (eNB).
-@param carrier pointer to Carrier information
-@param N_RB_DL Number of downlink PRBs
-@param frame radio frame number
-@return size of encoded bit stream in bytes*/
-uint8_t do_MIB_NB_IoT(
-		rrc_eNB_carrier_data_NB_IoT_t *carrier,
-		uint32_t N_RB_DL,
-		uint32_t frame,
-    uint32_t hyper_frame);
-
-
-/**
-\brief Generate a default configuration for SIB1-NB (eNB).
-@param Mod_id Instance of eNB
-@param CC_id Component carrier to configure
-@param carrier pointer to Carrier information
-@param configuration Pointer Configuration Request structure
-@return size of encoded bit stream in bytes*/
-
-uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, 
-                       int CC_id,
-				               rrc_eNB_carrier_data_NB_IoT_t *carrier,
-                       NbIoTRrcConfigurationReq *configuration,
-				               uint32_t frame
-                      );
-
-/**
-\brief Generate a default configuration for SIB2/SIB3-NB in one System Information PDU (eNB).
-@param Mod_id Index of eNB (used to derive some parameters)
-@param buffer Pointer to PER-encoded ASN.1 description of SI-NB PDU
-@param systemInformation_NB_IoT Pointer to asn1c C representation of SI-NB PDU
-@param sib2_NB Pointer (returned) to sib2_NB component withing SI-NB PDU
-@param sib3_NB Pointer (returned) to sib3_NB component withing SI-NB PDU
-@return size of encoded bit stream in bytes*/
-
-uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
-                        int CC_id,
-                        rrc_eNB_carrier_data_NB_IoT_t *carrier,
-                        NbIoTRrcConfigurationReq *configuration
-                        );
-
-/**(UE-SIDE)
-\brief Generate an RRCConnectionRequest-NB UL-CCCH-Message (UE) based on random string or S-TMSI.  This
-routine only generates an mo-data establishment cause.
-@param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
-@param rv 5 byte random string or S-TMSI
-@param Mod_id
-@returns Size of encoded bit stream in bytes*/
-
-uint8_t do_RRCConnectionRequest_NB_IoT(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv);
-
-
-/**(UE -SIDE)
-\brief Generate an RRCConnectionSetupComplete-NB UL-DCCH-Message (UE)
-@param Mod_id
-@param Transaction_id
-@param dedicatedInfoNASLength
-@param dedicatedInfoNAS
-@param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
-@returns Size of encoded bit stream in bytes*/
-
-uint8_t do_RRCConnectionSetupComplete_NB_IoT(uint8_t Mod_id, uint8_t* buffer, const uint8_t Transaction_id, const int dedicatedInfoNASLength,
-                                             const char* dedicatedInfoNAS);
-
-/** (UE-SIDE)
-\brief Generate an RRCConnectionReconfigurationComplete-NB UL-DCCH-Message (UE)
-@param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
-@param ctxt_pP
-@param Transaction_id
-@returns Size of encoded bit stream in bytes*/
-
-uint8_t do_RRCConnectionReconfigurationComplete_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* buffer,
-  const uint8_t Transaction_id
-);
-
-/**
-\brief Generate an RRCConnectionSetup-NB DL-CCCH-Message (eNB).  This routine configures SRB_ToAddMod (SRB1/SRB1bis-NB) and
-PhysicalConfigDedicated-NB IEs.
-@param ctxt_pP Running context
-@param ue_context_pP UE context
-@param CC_id         Component Carrier ID
-@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
-@param transmission_mode Transmission mode for UE (1-9)
-@param UE_id UE index for this message
-@param Transaction_id Transaction_ID for this message
-@param SRB_configList Pointer (returned) to SRB1_config/SRB1bis_config(later) IEs for this UE
-@param physicalConfigDedicated_NB Pointer (returned) to PhysicalConfigDedicated-NB IE for this UE
-@returns Size of encoded bit stream in bytes*/
-
-uint8_t do_RRCConnectionSetup_NB_IoT(
-  const protocol_ctxt_t*     const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*      const ue_context_pP,
-  int                              CC_id,
-  uint8_t*                   const buffer, //carrier[CC_id].Srb0.Tx_buffer.Payload
-  const uint8_t                    Transaction_id,
-  const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed but not deleted
-  SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT, //in order to be configured--> stanno puntando alla SRB_configlist dell ue_context
-  struct PhysicalConfigDedicated_NB_r13** physicalConfigDedicated_NB_IoT //in order to be configured--> stanno puntando alla physicalConfigDedicated dell ue_context
-);
-
-
-/**
- * For which SRB is used in NB-IoT??
-\brief Generate an RRCConnectionReconfiguration-NB DL-DCCH-Message (eNB).  This routine configures SRBToAddMod-NB (SRB1) and one DRBToAddMod-NB
-(DRB3).  PhysicalConfigDedicated-NB is not updated.
-@param ctxt_pP Running context
-@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
-@param Transaction_id Transaction_ID for this message
-@param SRB_list_NB Pointer to SRB List to be added/modified (NULL if no additions/modifications)
-@param DRB_list_NB Pointer to DRB List to be added/modified (NULL if no additions/modifications)
-@param DRB_list2_NB Pointer to DRB List to be released      (NULL if none to be released)
-//sps not supported by NB-IoT
-@param physicalConfigDedicated_NB Pointer to PhysicalConfigDedicated-NB to be modified (NULL if no modifications)
-//measurement not supported by NB-IoT
-@param mac_MainConfig Pointer to Mac_MainConfig(NULL if no modifications)
-//no CBA functionalities
-@returns Size of encoded bit stream in bytes*/
-
-uint16_t
-do_RRCConnectionReconfiguration_NB_IoT(
-  const protocol_ctxt_t*        const ctxt_pP,
-    uint8_t                            *buffer,
-    uint8_t                             Transaction_id,
-    SRB_ToAddModList_NB_r13_t          *SRB_list_NB_IoT,
-    DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT,
-    DRB_ToReleaseList_NB_r13_t         *DRB_list2_NB_IoT,
-    struct PhysicalConfigDedicated_NB_r13     *physicalConfigDedicated,
-    MAC_MainConfig_t                   *mac_MainConfig,
-  struct RRCConnectionReconfiguration_NB_r13_IEs__dedicatedInfoNASList_r13* dedicatedInfoNASList_NB_IoT);
-
-/**
- * E-UTRAN applies the procedure as follows: when only for NB-IoT SRB1 and SRB1bis is established
- \brief Generate a SecurityModeCommand
- @param ctxt_pP Running context
- @param buffer Pointer to PER-encoded ASN.1 description
- @param Transaction_id Transaction_ID for this message
- @param cipheringAlgorithm
- @param integrityProtAlgorithm
- */
-
-uint8_t do_SecurityModeCommand_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* const buffer,
-  const uint8_t Transaction_id,
-  const uint8_t cipheringAlgorithm,
-  const uint8_t integrityProtAlgorithm);
-
-/**
- * E-UTRAN applies the procedure as follows: when only for NB-IoT SRB1 and SRB1bis is established
- \brief Generate a SecurityModeCommand
- @param ctxt_pP Running context
- @param buffer Pointer to PER-encoded ASN.1 description
- @param Transaction_id Transaction_ID for this message
- */
-
-uint8_t do_UECapabilityEnquiry_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t*               const buffer,
-  const uint8_t                Transaction_id
-);
-
-
-/**
- * There is nothing new in this type of message for NB-IoT (only change in some nomenclature)
-\brief Generate an RRCConnectionReestablishmentReject DL-CCCH-Message (eNB).
-@param Mod_id Module ID of eNB
-@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
-@returns Size of encoded bit stream in bytes*/
-
-uint8_t
-do_RRCConnectionReestablishmentReject_NB_IoT(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer);
-
-
-/**
-\brief Generate an RRCConnectionReject-NB DL-CCCH-Message (eNB).
-@param Mod_id Module ID of eNB
-@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
-@returns Size of encoded bit stream in bytes*/
-uint8_t
-do_RRCConnectionReject_NB_IoT(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer);
-
-
-/**
-\brief Generate an RRCConnectionRelease-NB DL-DCCH-Message
-@param Mod_id Module ID of eNB
-@param buffer Pointer to PER-encoded ASN.1 description
-@param transaction_id Transaction index
-@returns Size of encoded bit stream in bytes*/
-
-uint8_t do_RRCConnectionRelease_NB_IoT(uint8_t Mod_id, uint8_t *buffer,int Transaction_id);
-
-
-uint8_t do_DLInformationTransfer_NB_IoT(
-		uint8_t Mod_id,
-		uint8_t **buffer,
-		uint8_t transaction_id,
-		uint32_t pdu_length,
-		uint8_t *pdu_buffer);
-
-//for now not implemented since UE side
-//uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer);
-
-//for now not implemented since UE side???
-//OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
-
-/**
-\brief Generate an RRCConnectionReestablishment-NB DL-CCCH Message
- *@param
- *
- */
-
-uint8_t do_RRCConnectionReestablishment_NB_IoT(
-		uint8_t Mod_id,
-		uint8_t* const buffer,
-		const uint8_t     Transaction_id,
-		const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed
-		SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT
-		 );
-
-/**
-\brief Generate an RRCConnectionRelease-NB DL-DCCH-Message (eNB)
-@param Mod_id Module ID of eNB
-@param buffer Pointer to PER-encoded ASN.1 description of DL-DCCH-Message PDU
-@param transaction_id Transaction index
-@returns Size of encoded bit stream in bytes*/
-
-//uint8_t do_RRCConnectionRelease_NB_IoT(uint8_t Mod_id, uint8_t *buffer,int Transaction_id);
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file asn1_msg.h
+* \brief primitives to build the asn1 messages
+* \author Raymond Knopp, Navid Nikaein and Michele Paffetti
+* \date 2011, 2017
+* \version 1.0
+* \company Eurecom
+* \email: raymond.knopp@eurecom.fr ,navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
+*/
+
+#ifdef USER_MODE
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdlib.h> /* for atoi(3) */
+#include <unistd.h> /* for getopt(3) */
+#include <string.h> /* for strerror(3) */
+#include <sysexits.h> /* for EX_* exit codes */
+#include <errno.h>  /* for errno */
+#else
+#include <linux/module.h>  /* Needed by all modules */
+#endif
+
+#include <asn_application.h>
+#include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
+
+
+#include "RRC/LITE/defs_NB_IoT.h"
+
+/*
+ * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
+ * output into the chosen string buffer.
+ * RETURN VALUES:
+ *       0: The structure is printed.
+ *      -1: Problem printing the structure.
+ * WARNING: No sensible error value is returned.
+ */
+
+
+/**
+\brief Generate configuration for SIB1 (eNB).
+@param carrier pointer to Carrier information
+@param N_RB_DL Number of downlink PRBs
+@param frame radio frame number
+@return size of encoded bit stream in bytes*/
+uint8_t do_MIB_NB_IoT(
+		rrc_eNB_carrier_data_NB_IoT_t *carrier,
+		uint32_t N_RB_DL,
+		uint32_t frame,
+    uint32_t hyper_frame);
+
+
+/**
+\brief Generate a default configuration for SIB1-NB (eNB).
+@param Mod_id Instance of eNB
+@param CC_id Component carrier to configure
+@param carrier pointer to Carrier information
+@param configuration Pointer Configuration Request structure
+@return size of encoded bit stream in bytes*/
+
+uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, 
+                       int CC_id,
+				               rrc_eNB_carrier_data_NB_IoT_t *carrier,
+                       NbIoTRrcConfigurationReq *configuration,
+				               uint32_t frame
+                      );
+
+/**
+\brief Generate a default configuration for SIB2/SIB3-NB in one System Information PDU (eNB).
+@param Mod_id Index of eNB (used to derive some parameters)
+@param buffer Pointer to PER-encoded ASN.1 description of SI-NB PDU
+@param systemInformation_NB_IoT Pointer to asn1c C representation of SI-NB PDU
+@param sib2_NB Pointer (returned) to sib2_NB component withing SI-NB PDU
+@param sib3_NB Pointer (returned) to sib3_NB component withing SI-NB PDU
+@return size of encoded bit stream in bytes*/
+
+uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
+                        int CC_id,
+                        rrc_eNB_carrier_data_NB_IoT_t *carrier,
+                        NbIoTRrcConfigurationReq *configuration
+                        );
+
+/**(UE-SIDE)
+\brief Generate an RRCConnectionRequest-NB UL-CCCH-Message (UE) based on random string or S-TMSI.  This
+routine only generates an mo-data establishment cause.
+@param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
+@param rv 5 byte random string or S-TMSI
+@param Mod_id
+@returns Size of encoded bit stream in bytes*/
+
+uint8_t do_RRCConnectionRequest_NB_IoT(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv);
+
+
+/**(UE -SIDE)
+\brief Generate an RRCConnectionSetupComplete-NB UL-DCCH-Message (UE)
+@param Mod_id
+@param Transaction_id
+@param dedicatedInfoNASLength
+@param dedicatedInfoNAS
+@param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
+@returns Size of encoded bit stream in bytes*/
+
+uint8_t do_RRCConnectionSetupComplete_NB_IoT(uint8_t Mod_id, uint8_t* buffer, const uint8_t Transaction_id, const int dedicatedInfoNASLength,
+                                             const char* dedicatedInfoNAS);
+
+/** (UE-SIDE)
+\brief Generate an RRCConnectionReconfigurationComplete-NB UL-DCCH-Message (UE)
+@param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
+@param ctxt_pP
+@param Transaction_id
+@returns Size of encoded bit stream in bytes*/
+
+uint8_t do_RRCConnectionReconfigurationComplete_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  uint8_t* buffer,
+  const uint8_t Transaction_id
+);
+
+/**
+\brief Generate an RRCConnectionSetup-NB DL-CCCH-Message (eNB).  This routine configures SRB_ToAddMod (SRB1/SRB1bis-NB) and
+PhysicalConfigDedicated-NB IEs.
+@param ctxt_pP Running context
+@param ue_context_pP UE context
+@param CC_id         Component Carrier ID
+@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
+@param transmission_mode Transmission mode for UE (1-9)
+@param UE_id UE index for this message
+@param Transaction_id Transaction_ID for this message
+@param SRB_configList Pointer (returned) to SRB1_config/SRB1bis_config(later) IEs for this UE
+@param physicalConfigDedicated_NB Pointer (returned) to PhysicalConfigDedicated-NB IE for this UE
+@returns Size of encoded bit stream in bytes*/
+
+uint8_t do_RRCConnectionSetup_NB_IoT(
+  const protocol_ctxt_t*     const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*      const ue_context_pP,
+  int                              CC_id,
+  uint8_t*                   const buffer, //carrier[CC_id].Srb0.Tx_buffer.Payload
+  const uint8_t                    Transaction_id,
+  const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed but not deleted
+  SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT, //in order to be configured--> stanno puntando alla SRB_configlist dell ue_context
+  struct PhysicalConfigDedicated_NB_r13** physicalConfigDedicated_NB_IoT //in order to be configured--> stanno puntando alla physicalConfigDedicated dell ue_context
+);
+
+
+/**
+ * For which SRB is used in NB-IoT??
+\brief Generate an RRCConnectionReconfiguration-NB DL-DCCH-Message (eNB).  This routine configures SRBToAddMod-NB (SRB1) and one DRBToAddMod-NB
+(DRB3).  PhysicalConfigDedicated-NB is not updated.
+@param ctxt_pP Running context
+@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
+@param Transaction_id Transaction_ID for this message
+@param SRB_list_NB Pointer to SRB List to be added/modified (NULL if no additions/modifications)
+@param DRB_list_NB Pointer to DRB List to be added/modified (NULL if no additions/modifications)
+@param DRB_list2_NB Pointer to DRB List to be released      (NULL if none to be released)
+//sps not supported by NB-IoT
+@param physicalConfigDedicated_NB Pointer to PhysicalConfigDedicated-NB to be modified (NULL if no modifications)
+//measurement not supported by NB-IoT
+@param mac_MainConfig Pointer to Mac_MainConfig(NULL if no modifications)
+//no CBA functionalities
+@returns Size of encoded bit stream in bytes*/
+
+uint16_t
+do_RRCConnectionReconfiguration_NB_IoT(
+  const protocol_ctxt_t*        const ctxt_pP,
+    uint8_t                            *buffer,
+    uint8_t                             Transaction_id,
+    SRB_ToAddModList_NB_r13_t          *SRB_list_NB_IoT,
+    DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT,
+    DRB_ToReleaseList_NB_r13_t         *DRB_list2_NB_IoT,
+    struct PhysicalConfigDedicated_NB_r13     *physicalConfigDedicated,
+    MAC_MainConfig_t                   *mac_MainConfig,
+  struct RRCConnectionReconfiguration_NB_r13_IEs__dedicatedInfoNASList_r13* dedicatedInfoNASList_NB_IoT);
+
+/**
+ * E-UTRAN applies the procedure as follows: when only for NB-IoT SRB1 and SRB1bis is established
+ \brief Generate a SecurityModeCommand
+ @param ctxt_pP Running context
+ @param buffer Pointer to PER-encoded ASN.1 description
+ @param Transaction_id Transaction_ID for this message
+ @param cipheringAlgorithm
+ @param integrityProtAlgorithm
+ */
+
+uint8_t do_SecurityModeCommand_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  uint8_t* const buffer,
+  const uint8_t Transaction_id,
+  const uint8_t cipheringAlgorithm,
+  const uint8_t integrityProtAlgorithm);
+
+/**
+ * E-UTRAN applies the procedure as follows: when only for NB-IoT SRB1 and SRB1bis is established
+ \brief Generate a SecurityModeCommand
+ @param ctxt_pP Running context
+ @param buffer Pointer to PER-encoded ASN.1 description
+ @param Transaction_id Transaction_ID for this message
+ */
+
+uint8_t do_UECapabilityEnquiry_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  uint8_t*               const buffer,
+  const uint8_t                Transaction_id
+);
+
+
+/**
+ * There is nothing new in this type of message for NB-IoT (only change in some nomenclature)
+\brief Generate an RRCConnectionReestablishmentReject DL-CCCH-Message (eNB).
+@param Mod_id Module ID of eNB
+@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
+@returns Size of encoded bit stream in bytes*/
+
+uint8_t
+do_RRCConnectionReestablishmentReject_NB_IoT(
+    uint8_t                    Mod_id,
+    uint8_t*                   const buffer);
+
+
+/**
+\brief Generate an RRCConnectionReject-NB DL-CCCH-Message (eNB).
+@param Mod_id Module ID of eNB
+@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
+@returns Size of encoded bit stream in bytes*/
+uint8_t
+do_RRCConnectionReject_NB_IoT(
+    uint8_t                    Mod_id,
+    uint8_t*                   const buffer);
+
+
+/**
+\brief Generate an RRCConnectionRelease-NB DL-DCCH-Message
+@param Mod_id Module ID of eNB
+@param buffer Pointer to PER-encoded ASN.1 description
+@param transaction_id Transaction index
+@returns Size of encoded bit stream in bytes*/
+
+uint8_t do_RRCConnectionRelease_NB_IoT(uint8_t Mod_id, uint8_t *buffer,int Transaction_id);
+
+
+uint8_t do_DLInformationTransfer_NB_IoT(
+		uint8_t Mod_id,
+		uint8_t **buffer,
+		uint8_t transaction_id,
+		uint32_t pdu_length,
+		uint8_t *pdu_buffer);
+
+//for now not implemented since UE side
+//uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer);
+
+//for now not implemented since UE side???
+//OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
+
+/**
+\brief Generate an RRCConnectionReestablishment-NB DL-CCCH Message
+ *@param
+ *
+ */
+
+uint8_t do_RRCConnectionReestablishment_NB_IoT(
+		uint8_t Mod_id,
+		uint8_t* const buffer,
+		const uint8_t     Transaction_id,
+		const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed
+		SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT
+		 );
+
+/**
+\brief Generate an RRCConnectionRelease-NB DL-DCCH-Message (eNB)
+@param Mod_id Module ID of eNB
+@param buffer Pointer to PER-encoded ASN.1 description of DL-DCCH-Message PDU
+@param transaction_id Transaction index
+@returns Size of encoded bit stream in bytes*/
+
+//uint8_t do_RRCConnectionRelease_NB_IoT(uint8_t Mod_id, uint8_t *buffer,int Transaction_id);
diff --git a/openair2/RRC/LITE/defs_NB_IoT.h b/openair2/RRC/LITE/defs_NB_IoT.h
index a5fdbb702e42bb24e53abdc54525a6e633c48db7..376b66c79a1e5c61ccedad1aca00806137da49bc 100644
--- a/openair2/RRC/LITE/defs_NB_IoT.h
+++ b/openair2/RRC/LITE/defs_NB_IoT.h
@@ -1,570 +1,570 @@
-/* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*! \file RRC/LITE/defs_NB_IoT.h
-* \brief NB-IoT RRC struct definitions and function prototypes
-* \author Navid Nikaein, Raymond Knopp and Michele Paffetti
-* \date 2010 - 2014, 2017
-* \version 1.0
-* \company Eurecom
-* \email: navid.nikaein@eurecom.fr, raymond.knopp@eurecom.fr, michele.paffetti@studio.unibo.it
-*/
-
-#ifndef __OPENAIR_RRC_DEFS_NB_IOT_H__
-#define __OPENAIR_RRC_DEFS_NB_IOT_H__
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "collection/tree.h"
-#include "rrc_types_NB_IoT.h"
-#include "COMMON/platform_constants.h"
-#include "COMMON/platform_types.h"
-#include "targets/COMMON/openairinterface5g_limits.h"
-
-#include "COMMON/mac_rrc_primitives.h"
-
-//-----NB-IoT #include files-------
-
-//#include "SystemInformationBlockType1-NB.h"
-//#include "SystemInformation-NB.h"
-#include "RRCConnectionReconfiguration-NB.h"
-#include "RRCConnectionReconfigurationComplete-NB.h"
-#include "RRCConnectionSetup-NB.h"
-#include "RRCConnectionSetupComplete-NB.h"
-#include "RRCConnectionRequest-NB.h"
-#include "RRCConnectionReestablishmentRequest-NB.h"
-#include "BCCH-DL-SCH-Message-NB.h"
-#include "BCCH-BCH-Message-NB.h"
-#include "AS-Config-NB.h"
-#include "AS-Context-NB.h"
-#include "UE-Capability-NB-r13.h" //equivalent of UE-EUTRA-Capability.h
-//-------------------
-
-#if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
-#endif
-
-/* TODO: be sure this include is correct.
- * It solves a problem of compilation of the RRH GW,
- * issue #186.
- */
-#if !defined(ENABLE_ITTI)
-# include "as_message.h"
-#endif
-
-#if defined(ENABLE_USE_MME)
-# include "commonDef.h"
-#endif
-
-#if ENABLE_RAL
-# include "collection/hashtable/obj_hashtable.h"
-#endif
-
-
-
-/*I will change the name of the structure for compile purposes--> hope not to undo this process*/
-
-typedef unsigned int uid_NB_IoT_t;
-#define UID_LINEAR_ALLOCATOR_BITMAP_SIZE_NB_IoT (((NUMBER_OF_UE_MAX_NB_IoT/8)/sizeof(unsigned int)) + 1)
-
-typedef struct uid_linear_allocator_NB_IoT_s {
-  unsigned int   bitmap[UID_LINEAR_ALLOCATOR_BITMAP_SIZE_NB_IoT];
-} uid_allocator_NB_IoT_t;
-
-
-#define PROTOCOL_RRC_CTXT_UE_FMT           PROTOCOL_CTXT_FMT
-#define PROTOCOL_RRC_CTXT_UE_ARGS(CTXT_Pp) PROTOCOL_CTXT_ARGS(CTXT_Pp)
-
-#define PROTOCOL_RRC_CTXT_FMT           PROTOCOL_CTXT_FMT
-#define PROTOCOL_RRC_CTXT_ARGS(CTXT_Pp) PROTOCOL_CTXT_ARGS(CTXT_Pp)
-
-
-//left as they are --> used in LAYER2/epenair2_proc.c and UE side
-typedef enum UE_STATE_NB_IoT_e {
- RRC_INACTIVE_NB_IoT=0,
- RRC_IDLE_NB_IoT,
- RRC_SI_RECEIVED_NB_IoT,
- RRC_CONNECTED_NB_IoT,
- RRC_RECONFIGURED_NB_IoT,
- RRC_HO_EXECUTION_NB_IoT //maybe not needed?
-} UE_STATE_NB_IoT_t;
-
-
-/** @defgroup _rrc RRC
- * @ingroup _oai2
- * @{
- */
-typedef struct UE_RRC_INFO_NB_IoT_s {
-  UE_STATE_NB_IoT_t State;
-  uint8_t SIB1systemInfoValueTag;
-  uint32_t SIStatus;
-  uint32_t SIcnt;
-#if defined(Rel10) || defined(Rel14)
-  uint8_t MCCHStatus[8]; // MAX_MBSFN_AREA
-#endif
-  uint8_t SIwindowsize; //!< Corresponds to the SIB1 si-WindowLength parameter. The unit is ms. Possible values are (final): 1,2,5,10,15,20,40
-  uint8_t handoverTarget;
-  //HO_STATE_t ho_state;
-  uint16_t SIperiod; //!< Corresponds to the SIB1 si-Periodicity parameter (multiplied by 10). Possible values are (final): 80,160,320,640,1280,2560,5120
-  unsigned short UE_index;
-  uint32_t T300_active;
-  uint32_t T300_cnt;
-  uint32_t T304_active;
-  uint32_t T304_cnt;
-  uint32_t T310_active;
-  uint32_t T310_cnt;
-  uint32_t N310_cnt;
-  uint32_t N311_cnt;
-  rnti_t   rnti;
-} __attribute__ ((__packed__)) UE_RRC_INFO_NB_IoT;
-
-//#define NUM_PRECONFIGURED_LCHAN (NB_CH_CX*2)  //BCCH, CCCH
-
-#define UE_MODULE_INVALID ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!!
-#define UE_INDEX_INVALID  ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!! used to be -1
-
-
-
-// HO_STATE is not supported by NB-IoT
-
-//#define NUMBER_OF_UE_MAX MAX_MOBILES_PER_RG
-#define RRM_FREE(p)       if ( (p) != NULL) { free(p) ; p=NULL ; }
-#define RRM_MALLOC(t,n)   (t *) malloc16( sizeof(t) * n )
-#define RRM_CALLOC(t,n)   (t *) malloc16( sizeof(t) * n)
-#define RRM_CALLOC2(t,s)  (t *) malloc16( s )
-
-//Measurement Report not supported in NB-IoT
-
-#define PAYLOAD_SIZE_MAX 1024
-#define RRC_BUF_SIZE 255
-#define UNDEF_SECURITY_MODE 0xff
-#define NO_SECURITY_MODE 0x20
-
-/* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */
-#define RRC_TRANSACTION_IDENTIFIER_NUMBER  3
-
-typedef struct UE_S_TMSI_NB_IoT_s {
-  boolean_t  presence;
-  mme_code_t mme_code;
-  m_tmsi_t   m_tmsi;
-} __attribute__ ((__packed__)) UE_S_TMSI_NB_IoT;
-
-
-typedef enum e_rab_satus_NB_IoT_e {
-  E_RAB_STATUS_NEW_NB_IoT,
-  E_RAB_STATUS_DONE_NB_IoT, // from the eNB perspective
-  E_RAB_STATUS_ESTABLISHED_NB_IoT, // get the reconfigurationcomplete form UE
-  E_RAB_STATUS_FAILED_NB_IoT,
-} e_rab_status_NB_IoT_t;
-
-typedef struct e_rab_param_NB_IoT_s {
-  e_rab_t param;
-  uint8_t status;
-  uint8_t xid; // transaction_id
-} __attribute__ ((__packed__)) e_rab_param_NB_IoT_t;
-
-
-//HANDOVER_INFO not implemented in NB-IoT delete
-
-
-#define RRC_HEADER_SIZE_MAX 64
-#define RRC_BUFFER_SIZE_MAX 1024
-
-typedef struct {
-  char Payload[RRC_BUFFER_SIZE_MAX];
-  char Header[RRC_HEADER_SIZE_MAX];
-  char payload_size;
-} RRC_BUFFER_NB_IoT;
-
-#define RRC_BUFFER_SIZE_NB_IoT sizeof(RRC_BUFFER_NB_IoT)
-
-
-typedef struct RB_INFO_NB_IoT_s {
-  uint16_t Rb_id;  //=Lchan_id
-  //LCHAN_DESC Lchan_desc[2]; no more used
-  //MAC_MEAS_REQ_ENTRY *Meas_entry; //may not needed for NB-IoT
-} RB_INFO_NB_IoT;
-
-typedef struct SRB_INFO_NB_IoT_s {
-  uint16_t Srb_id;  //=Lchan_id---> useful for distinguish between SRB1 and SRB1bis?
-  RRC_BUFFER_NB_IoT Rx_buffer;
-  RRC_BUFFER_NB_IoT Tx_buffer;
-  //LCHAN_DESC Lchan_desc[2]; no more used
-  unsigned int Trans_id;
-  uint8_t Active;
-} SRB_INFO_NB_IoT;
-
-
-typedef struct RB_INFO_TABLE_ENTRY_NB_IoT_s {
-  RB_INFO_NB_IoT Rb_info;
-  uint8_t Active;
-  uint32_t Next_check_frame;
-  uint8_t Status;
-} RB_INFO_TABLE_ENTRY_NB_IoT;
-
-typedef struct SRB_INFO_TABLE_ENTRY_NB_IoT_s {
-  SRB_INFO_NB_IoT Srb_info;
-  uint8_t Active;
-  uint8_t Status;
-  uint32_t Next_check_frame;
-} SRB_INFO_TABLE_ENTRY_NB_IoT;
-
-//MEAS_REPORT_LIST_s not implemented in NB-IoT but is used at UE side
-//HANDOVER_INFO_UE not implemented in NB-IoT
-typedef struct HANDOVER_INFO_UE_NB_IoT_s {
-  PhysCellId_t targetCellId;
-  uint8_t measFlag;
-} HANDOVER_INFO_UE_NB_IoT;
-
-//NB-IoT eNB_RRC_UE_NB_IoT_s--(used as a context in eNB --> ue_context in rrc_eNB_ue_context)------
-typedef struct eNB_RRC_UE_NB_IoT_s {
-
-  EstablishmentCause_t               establishment_cause;
-  uint8_t                            primaryCC_id;
-  //in NB-IoT only SRB0, SRB1 and SRB1bis (until AS security activation) exist
-
-  /*MP: Concept behind List and List2
-   *
-   * SRB_configList --> is used for the actual list of SRBs that is managed/that should be send over the RRC message
-   * SRB_configList2--> refers to all the SRBs configured for that specific transaction identifier
-   * 					this because in a single transaction one or more SRBs could be established
-   * 					and you want to keep memory on what happen for every transaction
-   * Transaction ID (xid): is used to associate the proper RRC....Complete message received by the UE to the corresponding
-   * 					   message previously sent by the eNB (e.g. RRCConnectionSetup -- RRCConnectionSetupComplete)
-   * 					   this because it could happen that more messages are transmitted at the same time
-   */
-  SRB_ToAddModList_NB_r13_t*                SRB_configList;//for SRB1 and SRB1bis
-  SRB_ToAddModList_NB_r13_t*                SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
-  DRB_ToAddModList_NB_r13_t*                DRB_configList; //for all the DRBs
-  DRB_ToAddModList_NB_r13_t*                DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER]; //for the configured DRBs of a xid
-  uint8_t                            		DRB_active[2];//in LTE was 8 --> at most 2 for NB-IoT
-
-  struct PhysicalConfigDedicated_NB_r13*    physicalConfigDedicated_NB_IoT;
-  MAC_MainConfig_NB_r13_t*           mac_MainConfig_NB_IoT;
-
-  //No SPS(semi-persistent scheduling) in NB-IoT
-  //No Measurement report in NB-IoT
-
-  SRB_INFO_NB_IoT                           SI;
-  SRB_INFO_NB_IoT                           Srb0;
-  SRB_INFO_TABLE_ENTRY_NB_IoT               Srb1;
-  SRB_INFO_TABLE_ENTRY_NB_IoT               Srb1bis;
-
-#if defined(ENABLE_SECURITY)
-  /* KeNB as derived from KASME received from EPC */
-  uint8_t kenb[32];
-#endif
-
-  /* Used integrity/ciphering algorithms--> maintained the same for NB-IoT */
-  e_CipheringAlgorithm_r12     ciphering_algorithm; //Specs. TS 36.331 V14.1.0 pag 432 Change position of chipering enumerative w.r.t previous version
-  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
-
-  uint8_t                            Status;
-  rnti_t                             rnti;
-  uint64_t                           random_ue_identity;
-
-
-
-  /* Information from UE RRC ConnectionRequest-NB-r13_IE--> NB-IoT */
-  UE_S_TMSI_NB_IoT                          Initialue_identity_s_TMSI;
-  EstablishmentCause_NB_r13_t               establishment_cause_NB_IoT; //different set for NB-IoT
-
-  /* Information from UE RRC ConnectionReestablishmentRequest-NB--> NB-IoT */
-  ReestablishmentCause_NB_r13_t             reestablishment_cause_NB_IoT; //different set for NB_IoT
-
-  /* UE id for initial connection to S1AP */
-  uint16_t                           ue_initial_id;
-
-  /* Information from S1AP initial_context_setup_req */
-  uint32_t                           eNB_ue_s1ap_id :24;
-
-  security_capabilities_t            security_capabilities;
-
-  /* Total number of e_rab already setup in the list */ //NAS list?
-  uint8_t                           setup_e_rabs;
-  /* Number of e_rab to be setup in the list */ //NAS list?
-  uint8_t                            nb_of_e_rabs;
-  /* list of e_rab to be setup by RRC layers */
-  e_rab_param_NB_IoT_t                      e_rab[NB_RB_MAX_NB_IOT];//[S1AP_MAX_E_RAB];
-
-  // LG: For GTPV1 TUNNELS
-  uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
-  transport_layer_addr_t             enb_gtp_addrs[S1AP_MAX_E_RAB];
-  rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
-
- //Which timers are referring to?
-  uint32_t                           ul_failure_timer;
-  uint32_t                           ue_release_timer;
-  //threshold of the release timer--> set in RRCConnectionRelease
-  uint32_t                           ue_release_timer_thres;
-} eNB_RRC_UE_NB_IoT_t;
-//--------------------------------------------------------------------------------
-
-typedef uid_NB_IoT_t ue_uid_t;
-
-
-//generally variable called: ue_context_pP
-typedef struct rrc_eNB_ue_context_NB_IoT_s {
-
-  /* Tree related data */
-  RB_ENTRY(rrc_eNB_ue_context_NB_IoT_s) entries;
-
-  /* Uniquely identifies the UE between MME and eNB within the eNB.
-   * This id is encoded on 24bits.
-   */
-  rnti_t         ue_id_rnti;
-
-  // another key for protocol layers but should not be used as a key for RB tree
-  ue_uid_t       local_uid;
-
-  /* UE id for initial connection to S1AP */
-  struct eNB_RRC_UE_NB_IoT_s   ue_context; //context of ue in the e-nB
-
-} rrc_eNB_ue_context_NB_IoT_t;
-
-
-
-//---NB-IoT (completely changed)-------------------------------
-//called "carrier"--> data from PHY layer
-typedef struct {
-
-  // buffer that contains the encoded messages
-  uint8_t							*MIB_NB_IoT;
-  uint8_t							sizeof_MIB_NB_IoT;
-
-  uint8_t                           *SIB1_NB_IoT;
-  uint8_t                           sizeof_SIB1_NB_IoT;
-  uint8_t                         	*SIB23_NB_IoT;
-  uint8_t                        	sizeof_SIB23_NB_IoT;
-
-
-  //not actually implemented in OAI
-  uint8_t                           *SIB4_NB_IoT;
-  uint8_t                           sizeof_SIB4_NB_IoT;
-  uint8_t                           *SIB5_NB_IoT;
-  uint8_t                           sizeof_SIB5_NB_IoT;
-  uint8_t                           *SIB14_NB_IoT;
-  uint8_t                           sizeof_SIB14_NB_IoT;
-  uint8_t                           *SIB16_NB_IoT;
-  uint8_t                           sizeof_SIB16_NB_IoT;
-
-  //TS 36.331 V14.2.1
-//  uint8_t                           *SIB15_NB;
-//  uint8_t                           sizeof_SIB15_NB;
-//  uint8_t                           *SIB20_NB;
-//  uint8_t                           sizeof_SIB20_NB;
-//  uint8_t                           *SIB22_NB;
-//  uint8_t                           sizeof_SIB22_NB;
-
-  //implicit parameters needed
-  int                               Ncp; //cyclic prefix for DL
-  int								Ncp_UL; //cyclic prefix for UL
-  int                               p_eNB; //number of tx antenna port
-  int								p_rx_eNB; //number of receiving antenna ports
-  uint32_t                          dl_CarrierFreq; //detected by the UE
-  uint32_t                          ul_CarrierFreq; //detected by the UE
-  uint16_t                          physCellId; //not stored in the MIB-NB but is getting through NPSS/NSSS
-
-  //are the only static one (memory has been already allocated)
-  BCCH_BCH_Message_NB_t                mib_NB_IoT;
-  BCCH_DL_SCH_Message_NB_t             siblock1_NB_IoT; //SIB1-NB
-  BCCH_DL_SCH_Message_NB_t             systemInformation_NB_IoT; //SI
-
-  SystemInformationBlockType1_NB_t     		*sib1_NB_IoT;
-  SystemInformationBlockType2_NB_r13_t   	*sib2_NB_IoT;
-  SystemInformationBlockType3_NB_r13_t   	*sib3_NB_IoT;
-  //not implemented yet
-  SystemInformationBlockType4_NB_r13_t    	*sib4_NB_IoT;
-  SystemInformationBlockType5_NB_r13_t     	*sib5_NB_IoT;
-  SystemInformationBlockType14_NB_r13_t     *sib14_NB_IoT;
-  SystemInformationBlockType16_NB_r13_t     *sib16_NB_IoT;
-
-
-  SRB_INFO_NB_IoT                          SI;
-  SRB_INFO_NB_IoT                          Srb0;
-
-  uint8_t                           **MCCH_MESSAGE; //  probably not needed , but added to remove errors
-  uint8_t                           sizeof_MCCH_MESSAGE[8];// but added to remove errors
-  SRB_INFO_NB_IoT                          MCCH_MESS[8];// MAX_MBSFN_AREA
-  /*future implementation TS 36.331 V14.2.1
-  SystemInformationBlockType15_NB_r14_t     *sib15;
-  SystemInformationBlockType20_NB_r14_t     *sib20;
-  SystemInformationBlockType22_NB_r14_t     *sib22;
-
-  uint8_t							SCPTM_flag;
-  uint8_t							sizeof_SC_MCHH_MESS[];
-  SC_MCCH_Message_NB_t				scptm;*/
-
-
-} rrc_eNB_carrier_data_NB_IoT_t;
-//---------------------------------------------------
-
-
-
-//---NB-IoT---(completely change)---------------------
-typedef struct eNB_RRC_INST_NB_IoT_s {
-
-  rrc_eNB_carrier_data_NB_IoT_t          carrier[MAX_NUM_CCs];
-
-  uid_allocator_NB_IoT_t                    uid_allocator; // for rrc_ue_head
-  RB_HEAD(rrc_ue_tree_NB_IoT_s, rrc_eNB_ue_context_NB_IoT_s)     rrc_ue_head; // ue_context tree key search by rnti
-
-  uint8_t                           Nb_ue;
-
-  hash_table_t                      *initial_id2_s1ap_ids; // key is    content is rrc_ue_s1ap_ids_t
-  hash_table_t                      *s1ap_id2_s1ap_ids   ; // key is    content is rrc_ue_s1ap_ids_t
-
-  //RRC configuration
-  RrcConfigurationReq configuration; //rrc_messages_types.h
-
-  // other PLMN parameters
-  /// Mobile country code
-  int mcc;
-  /// Mobile network code
-  int mnc;
-  /// number of mnc digits
-  int mnc_digit_length;
-
-  // other RAN parameters //FIXME: to be checked--> depends on APP layer
-  int srb1_timer_poll_retransmit;
-  int srb1_max_retx_threshold;
-  int srb1_timer_reordering;
-  int srb1_timer_status_prohibit;
-  int srs_enable[MAX_NUM_CCs];
-
-
-} eNB_RRC_INST_NB_IoT;
-
-#define RRC_HEADER_SIZE_MAX_NB_IoT 64
-#define MAX_UE_CAPABILITY_SIZE_NB_IoT 255
-
-//not needed for the moment
-typedef struct OAI_UECapability_NB_IoT_s {
- uint8_t sdu[MAX_UE_CAPABILITY_SIZE_NB_IoT];
- uint8_t sdu_size;
-////NB-IoT------
-  UE_Capability_NB_r13_t  UE_Capability_NB_IoT; //replace the UE_EUTRA_Capability of LTE
-} OAI_UECapability_NB_IoT_t;
-
-#define RRC_BUFFER_SIZE_MAX_NB_IoT 1024
-
-
-
-typedef struct UE_RRC_INST_NB_IoT_s {
-  Rrc_State_NB_IoT_t     RrcState;
-  Rrc_Sub_State_NB_IoT_t RrcSubState;
-# if defined(ENABLE_USE_MME)
-  plmn_t          plmnID;
-  Byte_t          rat;
-  as_nas_info_t   initialNasMsg;
-# endif
-  OAI_UECapability_NB_IoT_t *UECap;
-  uint8_t *UECapability;
-  uint8_t UECapability_size;
-
-  UE_RRC_INFO_NB_IoT Info[NB_SIG_CNX_UE];
-  
-  SRB_INFO_NB_IoT                 Srb0[NB_SIG_CNX_UE];
-  SRB_INFO_TABLE_ENTRY_NB_IoT     Srb1[NB_CNX_UE];
-  SRB_INFO_TABLE_ENTRY_NB_IoT     Srb2[NB_CNX_UE];
-  HANDOVER_INFO_UE_NB_IoT         HandoverInfoUe;
-  /*
-  uint8_t *SIB1[NB_CNX_UE];
-  uint8_t sizeof_SIB1[NB_CNX_UE];
-  uint8_t *SI[NB_CNX_UE];
-  uint8_t sizeof_SI[NB_CNX_UE];
-  uint8_t SIB1Status[NB_CNX_UE];
-  uint8_t SIStatus[NB_CNX_UE];
-  SystemInformationBlockType1_t *sib1[NB_CNX_UE];
-  SystemInformation_t *si[NB_CNX_UE]; //!< Temporary storage for an SI message. Decoding happens in decode_SI().
-  */
-  SystemInformationBlockType2_t *sib2[NB_CNX_UE];
-  /*
-  SystemInformationBlockType3_t *sib3[NB_CNX_UE];
-  SystemInformationBlockType4_t *sib4[NB_CNX_UE];
-  SystemInformationBlockType5_t *sib5[NB_CNX_UE];
-  SystemInformationBlockType6_t *sib6[NB_CNX_UE];
-  SystemInformationBlockType7_t *sib7[NB_CNX_UE];
-  SystemInformationBlockType8_t *sib8[NB_CNX_UE];
-  SystemInformationBlockType9_t *sib9[NB_CNX_UE];
-  SystemInformationBlockType10_t *sib10[NB_CNX_UE];
-  SystemInformationBlockType11_t *sib11[NB_CNX_UE];
-
-#if defined(Rel10) || defined(Rel14)
-  uint8_t                           MBMS_flag;
-  uint8_t *MCCH_MESSAGE[NB_CNX_UE];
-  uint8_t sizeof_MCCH_MESSAGE[NB_CNX_UE];
-  uint8_t MCCH_MESSAGEStatus[NB_CNX_UE];
-  MBSFNAreaConfiguration_r9_t       *mcch_message[NB_CNX_UE];
-  SystemInformationBlockType12_r9_t *sib12[NB_CNX_UE];
-  SystemInformationBlockType13_r9_t *sib13[NB_CNX_UE];
-#endif
-#ifdef CBA
-  uint8_t                         num_active_cba_groups;
-  uint16_t                        cba_rnti[NUM_MAX_CBA_GROUP];
-#endif
-  uint8_t                         num_srb;
-  struct SRB_ToAddMod             *SRB1_config[NB_CNX_UE];
-  struct SRB_ToAddMod             *SRB2_config[NB_CNX_UE];
-  struct DRB_ToAddMod             *DRB_config[NB_CNX_UE][8];
-  rb_id_t                         *defaultDRB; // remember the ID of the default DRB
-  MeasObjectToAddMod_t            *MeasObj[NB_CNX_UE][MAX_MEAS_OBJ];
-  struct ReportConfigToAddMod     *ReportConfig[NB_CNX_UE][MAX_MEAS_CONFIG];
-  */
-  struct QuantityConfig           *QuantityConfig[NB_CNX_UE];
-  /*
-  struct MeasIdToAddMod           *MeasId[NB_CNX_UE][MAX_MEAS_ID];
-  MEAS_REPORT_LIST      *measReportList[NB_CNX_UE][MAX_MEAS_ID];
-  uint32_t           measTimer[NB_CNX_UE][MAX_MEAS_ID][6]; // 6 neighboring cells
-  RSRP_Range_t                    s_measure;
-  struct MeasConfig__speedStatePars *speedStatePars;
-  struct PhysicalConfigDedicated  *physicalConfigDedicated[NB_CNX_UE];
-  struct SPS_Config               *sps_Config[NB_CNX_UE];
-  MAC_MainConfig_t                *mac_MainConfig[NB_CNX_UE];
-  MeasGapConfig_t                 *measGapConfig[NB_CNX_UE];
-  double                          filter_coeff_rsrp; // [7] ???
-  double                          filter_coeff_rsrq; // [7] ???
-  float                           rsrp_db[7];
-  float                           rsrq_db[7];
-  float                           rsrp_db_filtered[7];
-  float                           rsrq_db_filtered[7];
-#if ENABLE_RAL
-  obj_hash_table_t               *ral_meas_thresholds;
-  ral_transaction_id_t            scan_transaction_id;
-#endif
-#if defined(ENABLE_SECURITY)
-  // KeNB as computed from parameters within USIM card //
-  uint8_t kenb[32];
-#endif
-
-  // Used integrity/ciphering algorithms //
-  CipheringAlgorithm_r12_t                          ciphering_algorithm;
-  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
-  */
-} UE_RRC_INST_NB_IoT;
-
-
-#include "proto_NB_IoT.h" //should be put here otherwise compilation error
-
-#endif
-/** @} */
+/* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file RRC/LITE/defs_NB_IoT.h
+* \brief NB-IoT RRC struct definitions and function prototypes
+* \author Navid Nikaein, Raymond Knopp and Michele Paffetti
+* \date 2010 - 2014, 2017
+* \version 1.0
+* \company Eurecom
+* \email: navid.nikaein@eurecom.fr, raymond.knopp@eurecom.fr, michele.paffetti@studio.unibo.it
+*/
+
+#ifndef __OPENAIR_RRC_DEFS_NB_IOT_H__
+#define __OPENAIR_RRC_DEFS_NB_IOT_H__
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "collection/tree.h"
+#include "rrc_types_NB_IoT.h"
+#include "COMMON/platform_constants.h"
+#include "COMMON/platform_types.h"
+#include "targets/COMMON/openairinterface5g_limits.h"
+
+#include "COMMON/mac_rrc_primitives.h"
+
+//-----NB-IoT #include files-------
+
+//#include "SystemInformationBlockType1-NB.h"
+//#include "SystemInformation-NB.h"
+#include "RRCConnectionReconfiguration-NB.h"
+#include "RRCConnectionReconfigurationComplete-NB.h"
+#include "RRCConnectionSetup-NB.h"
+#include "RRCConnectionSetupComplete-NB.h"
+#include "RRCConnectionRequest-NB.h"
+#include "RRCConnectionReestablishmentRequest-NB.h"
+#include "BCCH-DL-SCH-Message-NB.h"
+#include "BCCH-BCH-Message-NB.h"
+#include "AS-Config-NB.h"
+#include "AS-Context-NB.h"
+#include "UE-Capability-NB-r13.h" //equivalent of UE-EUTRA-Capability.h
+//-------------------
+
+#if defined(ENABLE_ITTI)
+# include "intertask_interface.h"
+#endif
+
+/* TODO: be sure this include is correct.
+ * It solves a problem of compilation of the RRH GW,
+ * issue #186.
+ */
+#if !defined(ENABLE_ITTI)
+# include "as_message.h"
+#endif
+
+#if defined(ENABLE_USE_MME)
+# include "commonDef.h"
+#endif
+
+#if ENABLE_RAL
+# include "collection/hashtable/obj_hashtable.h"
+#endif
+
+
+
+/*I will change the name of the structure for compile purposes--> hope not to undo this process*/
+
+typedef unsigned int uid_NB_IoT_t;
+#define UID_LINEAR_ALLOCATOR_BITMAP_SIZE_NB_IoT (((NUMBER_OF_UE_MAX_NB_IoT/8)/sizeof(unsigned int)) + 1)
+
+typedef struct uid_linear_allocator_NB_IoT_s {
+  unsigned int   bitmap[UID_LINEAR_ALLOCATOR_BITMAP_SIZE_NB_IoT];
+} uid_allocator_NB_IoT_t;
+
+
+#define PROTOCOL_RRC_CTXT_UE_FMT           PROTOCOL_CTXT_FMT
+#define PROTOCOL_RRC_CTXT_UE_ARGS(CTXT_Pp) PROTOCOL_CTXT_ARGS(CTXT_Pp)
+
+#define PROTOCOL_RRC_CTXT_FMT           PROTOCOL_CTXT_FMT
+#define PROTOCOL_RRC_CTXT_ARGS(CTXT_Pp) PROTOCOL_CTXT_ARGS(CTXT_Pp)
+
+
+//left as they are --> used in LAYER2/epenair2_proc.c and UE side
+typedef enum UE_STATE_NB_IoT_e {
+ RRC_INACTIVE_NB_IoT=0,
+ RRC_IDLE_NB_IoT,
+ RRC_SI_RECEIVED_NB_IoT,
+ RRC_CONNECTED_NB_IoT,
+ RRC_RECONFIGURED_NB_IoT,
+ RRC_HO_EXECUTION_NB_IoT //maybe not needed?
+} UE_STATE_NB_IoT_t;
+
+
+/** @defgroup _rrc RRC
+ * @ingroup _oai2
+ * @{
+ */
+typedef struct UE_RRC_INFO_NB_IoT_s {
+  UE_STATE_NB_IoT_t State;
+  uint8_t SIB1systemInfoValueTag;
+  uint32_t SIStatus;
+  uint32_t SIcnt;
+#if defined(Rel10) || defined(Rel14)
+  uint8_t MCCHStatus[8]; // MAX_MBSFN_AREA
+#endif
+  uint8_t SIwindowsize; //!< Corresponds to the SIB1 si-WindowLength parameter. The unit is ms. Possible values are (final): 1,2,5,10,15,20,40
+  uint8_t handoverTarget;
+  //HO_STATE_t ho_state;
+  uint16_t SIperiod; //!< Corresponds to the SIB1 si-Periodicity parameter (multiplied by 10). Possible values are (final): 80,160,320,640,1280,2560,5120
+  unsigned short UE_index;
+  uint32_t T300_active;
+  uint32_t T300_cnt;
+  uint32_t T304_active;
+  uint32_t T304_cnt;
+  uint32_t T310_active;
+  uint32_t T310_cnt;
+  uint32_t N310_cnt;
+  uint32_t N311_cnt;
+  rnti_t   rnti;
+} __attribute__ ((__packed__)) UE_RRC_INFO_NB_IoT;
+
+//#define NUM_PRECONFIGURED_LCHAN (NB_CH_CX*2)  //BCCH, CCCH
+
+#define UE_MODULE_INVALID ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!!
+#define UE_INDEX_INVALID  ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!! used to be -1
+
+
+
+// HO_STATE is not supported by NB-IoT
+
+//#define NUMBER_OF_UE_MAX MAX_MOBILES_PER_RG
+#define RRM_FREE(p)       if ( (p) != NULL) { free(p) ; p=NULL ; }
+#define RRM_MALLOC(t,n)   (t *) malloc16( sizeof(t) * n )
+#define RRM_CALLOC(t,n)   (t *) malloc16( sizeof(t) * n)
+#define RRM_CALLOC2(t,s)  (t *) malloc16( s )
+
+//Measurement Report not supported in NB-IoT
+
+#define PAYLOAD_SIZE_MAX 1024
+#define RRC_BUF_SIZE 255
+#define UNDEF_SECURITY_MODE 0xff
+#define NO_SECURITY_MODE 0x20
+
+/* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */
+#define RRC_TRANSACTION_IDENTIFIER_NUMBER  3
+
+typedef struct UE_S_TMSI_NB_IoT_s {
+  boolean_t  presence;
+  mme_code_t mme_code;
+  m_tmsi_t   m_tmsi;
+} __attribute__ ((__packed__)) UE_S_TMSI_NB_IoT;
+
+
+typedef enum e_rab_satus_NB_IoT_e {
+  E_RAB_STATUS_NEW_NB_IoT,
+  E_RAB_STATUS_DONE_NB_IoT, // from the eNB perspective
+  E_RAB_STATUS_ESTABLISHED_NB_IoT, // get the reconfigurationcomplete form UE
+  E_RAB_STATUS_FAILED_NB_IoT,
+} e_rab_status_NB_IoT_t;
+
+typedef struct e_rab_param_NB_IoT_s {
+  e_rab_t param;
+  uint8_t status;
+  uint8_t xid; // transaction_id
+} __attribute__ ((__packed__)) e_rab_param_NB_IoT_t;
+
+
+//HANDOVER_INFO not implemented in NB-IoT delete
+
+
+#define RRC_HEADER_SIZE_MAX 64
+#define RRC_BUFFER_SIZE_MAX 1024
+
+typedef struct {
+  char Payload[RRC_BUFFER_SIZE_MAX];
+  char Header[RRC_HEADER_SIZE_MAX];
+  char payload_size;
+} RRC_BUFFER_NB_IoT;
+
+#define RRC_BUFFER_SIZE_NB_IoT sizeof(RRC_BUFFER_NB_IoT)
+
+
+typedef struct RB_INFO_NB_IoT_s {
+  uint16_t Rb_id;  //=Lchan_id
+  //LCHAN_DESC Lchan_desc[2]; no more used
+  //MAC_MEAS_REQ_ENTRY *Meas_entry; //may not needed for NB-IoT
+} RB_INFO_NB_IoT;
+
+typedef struct SRB_INFO_NB_IoT_s {
+  uint16_t Srb_id;  //=Lchan_id---> useful for distinguish between SRB1 and SRB1bis?
+  RRC_BUFFER_NB_IoT Rx_buffer;
+  RRC_BUFFER_NB_IoT Tx_buffer;
+  //LCHAN_DESC Lchan_desc[2]; no more used
+  unsigned int Trans_id;
+  uint8_t Active;
+} SRB_INFO_NB_IoT;
+
+
+typedef struct RB_INFO_TABLE_ENTRY_NB_IoT_s {
+  RB_INFO_NB_IoT Rb_info;
+  uint8_t Active;
+  uint32_t Next_check_frame;
+  uint8_t Status;
+} RB_INFO_TABLE_ENTRY_NB_IoT;
+
+typedef struct SRB_INFO_TABLE_ENTRY_NB_IoT_s {
+  SRB_INFO_NB_IoT Srb_info;
+  uint8_t Active;
+  uint8_t Status;
+  uint32_t Next_check_frame;
+} SRB_INFO_TABLE_ENTRY_NB_IoT;
+
+//MEAS_REPORT_LIST_s not implemented in NB-IoT but is used at UE side
+//HANDOVER_INFO_UE not implemented in NB-IoT
+typedef struct HANDOVER_INFO_UE_NB_IoT_s {
+  PhysCellId_t targetCellId;
+  uint8_t measFlag;
+} HANDOVER_INFO_UE_NB_IoT;
+
+//NB-IoT eNB_RRC_UE_NB_IoT_s--(used as a context in eNB --> ue_context in rrc_eNB_ue_context)------
+typedef struct eNB_RRC_UE_NB_IoT_s {
+
+  EstablishmentCause_t               establishment_cause;
+  uint8_t                            primaryCC_id;
+  //in NB-IoT only SRB0, SRB1 and SRB1bis (until AS security activation) exist
+
+  /*MP: Concept behind List and List2
+   *
+   * SRB_configList --> is used for the actual list of SRBs that is managed/that should be send over the RRC message
+   * SRB_configList2--> refers to all the SRBs configured for that specific transaction identifier
+   * 					this because in a single transaction one or more SRBs could be established
+   * 					and you want to keep memory on what happen for every transaction
+   * Transaction ID (xid): is used to associate the proper RRC....Complete message received by the UE to the corresponding
+   * 					   message previously sent by the eNB (e.g. RRCConnectionSetup -- RRCConnectionSetupComplete)
+   * 					   this because it could happen that more messages are transmitted at the same time
+   */
+  SRB_ToAddModList_NB_r13_t*                SRB_configList;//for SRB1 and SRB1bis
+  SRB_ToAddModList_NB_r13_t*                SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
+  DRB_ToAddModList_NB_r13_t*                DRB_configList; //for all the DRBs
+  DRB_ToAddModList_NB_r13_t*                DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER]; //for the configured DRBs of a xid
+  uint8_t                            		DRB_active[2];//in LTE was 8 --> at most 2 for NB-IoT
+
+  struct PhysicalConfigDedicated_NB_r13*    physicalConfigDedicated_NB_IoT;
+  MAC_MainConfig_NB_r13_t*           mac_MainConfig_NB_IoT;
+
+  //No SPS(semi-persistent scheduling) in NB-IoT
+  //No Measurement report in NB-IoT
+
+  SRB_INFO_NB_IoT                           SI;
+  SRB_INFO_NB_IoT                           Srb0;
+  SRB_INFO_TABLE_ENTRY_NB_IoT               Srb1;
+  SRB_INFO_TABLE_ENTRY_NB_IoT               Srb1bis;
+
+#if defined(ENABLE_SECURITY)
+  /* KeNB as derived from KASME received from EPC */
+  uint8_t kenb[32];
+#endif
+
+  /* Used integrity/ciphering algorithms--> maintained the same for NB-IoT */
+  e_CipheringAlgorithm_r12     ciphering_algorithm; //Specs. TS 36.331 V14.1.0 pag 432 Change position of chipering enumerative w.r.t previous version
+  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
+
+  uint8_t                            Status;
+  rnti_t                             rnti;
+  uint64_t                           random_ue_identity;
+
+
+
+  /* Information from UE RRC ConnectionRequest-NB-r13_IE--> NB-IoT */
+  UE_S_TMSI_NB_IoT                          Initialue_identity_s_TMSI;
+  EstablishmentCause_NB_r13_t               establishment_cause_NB_IoT; //different set for NB-IoT
+
+  /* Information from UE RRC ConnectionReestablishmentRequest-NB--> NB-IoT */
+  ReestablishmentCause_NB_r13_t             reestablishment_cause_NB_IoT; //different set for NB_IoT
+
+  /* UE id for initial connection to S1AP */
+  uint16_t                           ue_initial_id;
+
+  /* Information from S1AP initial_context_setup_req */
+  uint32_t                           eNB_ue_s1ap_id :24;
+
+  security_capabilities_t            security_capabilities;
+
+  /* Total number of e_rab already setup in the list */ //NAS list?
+  uint8_t                           setup_e_rabs;
+  /* Number of e_rab to be setup in the list */ //NAS list?
+  uint8_t                            nb_of_e_rabs;
+  /* list of e_rab to be setup by RRC layers */
+  e_rab_param_NB_IoT_t                      e_rab[NB_RB_MAX_NB_IOT];//[S1AP_MAX_E_RAB];
+
+  // LG: For GTPV1 TUNNELS
+  uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
+  transport_layer_addr_t             enb_gtp_addrs[S1AP_MAX_E_RAB];
+  rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
+
+ //Which timers are referring to?
+  uint32_t                           ul_failure_timer;
+  uint32_t                           ue_release_timer;
+  //threshold of the release timer--> set in RRCConnectionRelease
+  uint32_t                           ue_release_timer_thres;
+} eNB_RRC_UE_NB_IoT_t;
+//--------------------------------------------------------------------------------
+
+typedef uid_NB_IoT_t ue_uid_t;
+
+
+//generally variable called: ue_context_pP
+typedef struct rrc_eNB_ue_context_NB_IoT_s {
+
+  /* Tree related data */
+  RB_ENTRY(rrc_eNB_ue_context_NB_IoT_s) entries;
+
+  /* Uniquely identifies the UE between MME and eNB within the eNB.
+   * This id is encoded on 24bits.
+   */
+  rnti_t         ue_id_rnti;
+
+  // another key for protocol layers but should not be used as a key for RB tree
+  ue_uid_t       local_uid;
+
+  /* UE id for initial connection to S1AP */
+  struct eNB_RRC_UE_NB_IoT_s   ue_context; //context of ue in the e-nB
+
+} rrc_eNB_ue_context_NB_IoT_t;
+
+
+
+//---NB-IoT (completely changed)-------------------------------
+//called "carrier"--> data from PHY layer
+typedef struct {
+
+  // buffer that contains the encoded messages
+  uint8_t							*MIB_NB_IoT;
+  uint8_t							sizeof_MIB_NB_IoT;
+
+  uint8_t                           *SIB1_NB_IoT;
+  uint8_t                           sizeof_SIB1_NB_IoT;
+  uint8_t                         	*SIB23_NB_IoT;
+  uint8_t                        	sizeof_SIB23_NB_IoT;
+
+
+  //not actually implemented in OAI
+  uint8_t                           *SIB4_NB_IoT;
+  uint8_t                           sizeof_SIB4_NB_IoT;
+  uint8_t                           *SIB5_NB_IoT;
+  uint8_t                           sizeof_SIB5_NB_IoT;
+  uint8_t                           *SIB14_NB_IoT;
+  uint8_t                           sizeof_SIB14_NB_IoT;
+  uint8_t                           *SIB16_NB_IoT;
+  uint8_t                           sizeof_SIB16_NB_IoT;
+
+  //TS 36.331 V14.2.1
+//  uint8_t                           *SIB15_NB;
+//  uint8_t                           sizeof_SIB15_NB;
+//  uint8_t                           *SIB20_NB;
+//  uint8_t                           sizeof_SIB20_NB;
+//  uint8_t                           *SIB22_NB;
+//  uint8_t                           sizeof_SIB22_NB;
+
+  //implicit parameters needed
+  int                               Ncp; //cyclic prefix for DL
+  int								Ncp_UL; //cyclic prefix for UL
+  int                               p_eNB; //number of tx antenna port
+  int								p_rx_eNB; //number of receiving antenna ports
+  uint32_t                          dl_CarrierFreq; //detected by the UE
+  uint32_t                          ul_CarrierFreq; //detected by the UE
+  uint16_t                          physCellId; //not stored in the MIB-NB but is getting through NPSS/NSSS
+
+  //are the only static one (memory has been already allocated)
+  BCCH_BCH_Message_NB_t                mib_NB_IoT;
+  BCCH_DL_SCH_Message_NB_t             siblock1_NB_IoT; //SIB1-NB
+  BCCH_DL_SCH_Message_NB_t             systemInformation_NB_IoT; //SI
+
+  SystemInformationBlockType1_NB_t     		*sib1_NB_IoT;
+  SystemInformationBlockType2_NB_r13_t   	*sib2_NB_IoT;
+  SystemInformationBlockType3_NB_r13_t   	*sib3_NB_IoT;
+  //not implemented yet
+  SystemInformationBlockType4_NB_r13_t    	*sib4_NB_IoT;
+  SystemInformationBlockType5_NB_r13_t     	*sib5_NB_IoT;
+  SystemInformationBlockType14_NB_r13_t     *sib14_NB_IoT;
+  SystemInformationBlockType16_NB_r13_t     *sib16_NB_IoT;
+
+
+  SRB_INFO_NB_IoT                          SI;
+  SRB_INFO_NB_IoT                          Srb0;
+
+  uint8_t                           **MCCH_MESSAGE; //  probably not needed , but added to remove errors
+  uint8_t                           sizeof_MCCH_MESSAGE[8];// but added to remove errors
+  SRB_INFO_NB_IoT                          MCCH_MESS[8];// MAX_MBSFN_AREA
+  /*future implementation TS 36.331 V14.2.1
+  SystemInformationBlockType15_NB_r14_t     *sib15;
+  SystemInformationBlockType20_NB_r14_t     *sib20;
+  SystemInformationBlockType22_NB_r14_t     *sib22;
+
+  uint8_t							SCPTM_flag;
+  uint8_t							sizeof_SC_MCHH_MESS[];
+  SC_MCCH_Message_NB_t				scptm;*/
+
+
+} rrc_eNB_carrier_data_NB_IoT_t;
+//---------------------------------------------------
+
+
+
+//---NB-IoT---(completely change)---------------------
+typedef struct eNB_RRC_INST_NB_IoT_s {
+
+  rrc_eNB_carrier_data_NB_IoT_t          carrier[MAX_NUM_CCs];
+
+  uid_allocator_NB_IoT_t                    uid_allocator; // for rrc_ue_head
+  RB_HEAD(rrc_ue_tree_NB_IoT_s, rrc_eNB_ue_context_NB_IoT_s)     rrc_ue_head; // ue_context tree key search by rnti
+
+  uint8_t                           Nb_ue;
+
+  hash_table_t                      *initial_id2_s1ap_ids; // key is    content is rrc_ue_s1ap_ids_t
+  hash_table_t                      *s1ap_id2_s1ap_ids   ; // key is    content is rrc_ue_s1ap_ids_t
+
+  //RRC configuration
+  RrcConfigurationReq configuration; //rrc_messages_types.h
+
+  // other PLMN parameters
+  /// Mobile country code
+  int mcc;
+  /// Mobile network code
+  int mnc;
+  /// number of mnc digits
+  int mnc_digit_length;
+
+  // other RAN parameters //FIXME: to be checked--> depends on APP layer
+  int srb1_timer_poll_retransmit;
+  int srb1_max_retx_threshold;
+  int srb1_timer_reordering;
+  int srb1_timer_status_prohibit;
+  int srs_enable[MAX_NUM_CCs];
+
+
+} eNB_RRC_INST_NB_IoT;
+
+#define RRC_HEADER_SIZE_MAX_NB_IoT 64
+#define MAX_UE_CAPABILITY_SIZE_NB_IoT 255
+
+//not needed for the moment
+typedef struct OAI_UECapability_NB_IoT_s {
+ uint8_t sdu[MAX_UE_CAPABILITY_SIZE_NB_IoT];
+ uint8_t sdu_size;
+////NB-IoT------
+  UE_Capability_NB_r13_t  UE_Capability_NB_IoT; //replace the UE_EUTRA_Capability of LTE
+} OAI_UECapability_NB_IoT_t;
+
+#define RRC_BUFFER_SIZE_MAX_NB_IoT 1024
+
+
+
+typedef struct UE_RRC_INST_NB_IoT_s {
+  Rrc_State_NB_IoT_t     RrcState;
+  Rrc_Sub_State_NB_IoT_t RrcSubState;
+# if defined(ENABLE_USE_MME)
+  plmn_t          plmnID;
+  Byte_t          rat;
+  as_nas_info_t   initialNasMsg;
+# endif
+  OAI_UECapability_NB_IoT_t *UECap;
+  uint8_t *UECapability;
+  uint8_t UECapability_size;
+
+  UE_RRC_INFO_NB_IoT Info[NB_SIG_CNX_UE];
+  
+  SRB_INFO_NB_IoT                 Srb0[NB_SIG_CNX_UE];
+  SRB_INFO_TABLE_ENTRY_NB_IoT     Srb1[NB_CNX_UE];
+  SRB_INFO_TABLE_ENTRY_NB_IoT     Srb2[NB_CNX_UE];
+  HANDOVER_INFO_UE_NB_IoT         HandoverInfoUe;
+  /*
+  uint8_t *SIB1[NB_CNX_UE];
+  uint8_t sizeof_SIB1[NB_CNX_UE];
+  uint8_t *SI[NB_CNX_UE];
+  uint8_t sizeof_SI[NB_CNX_UE];
+  uint8_t SIB1Status[NB_CNX_UE];
+  uint8_t SIStatus[NB_CNX_UE];
+  SystemInformationBlockType1_t *sib1[NB_CNX_UE];
+  SystemInformation_t *si[NB_CNX_UE]; //!< Temporary storage for an SI message. Decoding happens in decode_SI().
+  */
+  SystemInformationBlockType2_t *sib2[NB_CNX_UE];
+  /*
+  SystemInformationBlockType3_t *sib3[NB_CNX_UE];
+  SystemInformationBlockType4_t *sib4[NB_CNX_UE];
+  SystemInformationBlockType5_t *sib5[NB_CNX_UE];
+  SystemInformationBlockType6_t *sib6[NB_CNX_UE];
+  SystemInformationBlockType7_t *sib7[NB_CNX_UE];
+  SystemInformationBlockType8_t *sib8[NB_CNX_UE];
+  SystemInformationBlockType9_t *sib9[NB_CNX_UE];
+  SystemInformationBlockType10_t *sib10[NB_CNX_UE];
+  SystemInformationBlockType11_t *sib11[NB_CNX_UE];
+
+#if defined(Rel10) || defined(Rel14)
+  uint8_t                           MBMS_flag;
+  uint8_t *MCCH_MESSAGE[NB_CNX_UE];
+  uint8_t sizeof_MCCH_MESSAGE[NB_CNX_UE];
+  uint8_t MCCH_MESSAGEStatus[NB_CNX_UE];
+  MBSFNAreaConfiguration_r9_t       *mcch_message[NB_CNX_UE];
+  SystemInformationBlockType12_r9_t *sib12[NB_CNX_UE];
+  SystemInformationBlockType13_r9_t *sib13[NB_CNX_UE];
+#endif
+#ifdef CBA
+  uint8_t                         num_active_cba_groups;
+  uint16_t                        cba_rnti[NUM_MAX_CBA_GROUP];
+#endif
+  uint8_t                         num_srb;
+  struct SRB_ToAddMod             *SRB1_config[NB_CNX_UE];
+  struct SRB_ToAddMod             *SRB2_config[NB_CNX_UE];
+  struct DRB_ToAddMod             *DRB_config[NB_CNX_UE][8];
+  rb_id_t                         *defaultDRB; // remember the ID of the default DRB
+  MeasObjectToAddMod_t            *MeasObj[NB_CNX_UE][MAX_MEAS_OBJ];
+  struct ReportConfigToAddMod     *ReportConfig[NB_CNX_UE][MAX_MEAS_CONFIG];
+  */
+  struct QuantityConfig           *QuantityConfig[NB_CNX_UE];
+  /*
+  struct MeasIdToAddMod           *MeasId[NB_CNX_UE][MAX_MEAS_ID];
+  MEAS_REPORT_LIST      *measReportList[NB_CNX_UE][MAX_MEAS_ID];
+  uint32_t           measTimer[NB_CNX_UE][MAX_MEAS_ID][6]; // 6 neighboring cells
+  RSRP_Range_t                    s_measure;
+  struct MeasConfig__speedStatePars *speedStatePars;
+  struct PhysicalConfigDedicated  *physicalConfigDedicated[NB_CNX_UE];
+  struct SPS_Config               *sps_Config[NB_CNX_UE];
+  MAC_MainConfig_t                *mac_MainConfig[NB_CNX_UE];
+  MeasGapConfig_t                 *measGapConfig[NB_CNX_UE];
+  double                          filter_coeff_rsrp; // [7] ???
+  double                          filter_coeff_rsrq; // [7] ???
+  float                           rsrp_db[7];
+  float                           rsrq_db[7];
+  float                           rsrp_db_filtered[7];
+  float                           rsrq_db_filtered[7];
+#if ENABLE_RAL
+  obj_hash_table_t               *ral_meas_thresholds;
+  ral_transaction_id_t            scan_transaction_id;
+#endif
+#if defined(ENABLE_SECURITY)
+  // KeNB as computed from parameters within USIM card //
+  uint8_t kenb[32];
+#endif
+
+  // Used integrity/ciphering algorithms //
+  CipheringAlgorithm_r12_t                          ciphering_algorithm;
+  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
+  */
+} UE_RRC_INST_NB_IoT;
+
+
+#include "proto_NB_IoT.h" //should be put here otherwise compilation error
+
+#endif
+/** @} */
diff --git a/openair2/RRC/LITE/extern_NB_IoT.h b/openair2/RRC/LITE/extern_NB_IoT.h
index 39b49ecc038043d5f7da160f8e836b59ba26e339..f5e2f325756006d2841bb81f674d778ea68515f8 100644
--- a/openair2/RRC/LITE/extern_NB_IoT.h
+++ b/openair2/RRC/LITE/extern_NB_IoT.h
@@ -1,63 +1,63 @@
-/*
- * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*! \file vars.h
-* \brief rrc external vars
-* \author Navid Nikaein and Raymond Knopp, Michele Paffetti
-* \date 2011-2017
-* \version 1.0
-* \company Eurecom
-* \email: navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
-*/
-
-#ifndef __OPENAIR_RRC_EXTERN_NB_IOT_H__
-#define __OPENAIR_RRC_EXTERN_NB_IOT_H__
-#include "RRC/LITE/defs_NB_IoT.h"
-#include "PHY_INTERFACE/IF_Module_NB_IoT.h"
-#include "LAYER2/RLC/rlc.h"
-#include "LogicalChannelConfig-NB-r13.h"
-#include "LAYER2/MAC/defs_NB_IoT.h"
-
-#include "common/ran_context.h"
-
-
-//MP: NOTE:XXX some of the parameters defined in vars_nb_iot are called by the extern.h file so not replicated here
-
-extern UE_RRC_INST_NB_IoT 					*UE_rrc_inst_NB_IoT;
-
-extern eNB_RRC_INST_NB_IoT 					*eNB_rrc_inst_NB_IoT;
-extern PHY_Config_NB_IoT_t 						*config_INFO;
-
-extern rlc_info_t 							Rlc_info_am_NB_IoT,Rlc_info_am_config_NB_IoT;
-extern uint8_t 								DRB2LCHAN_NB_IoT[2];
-extern LogicalChannelConfig_NB_r13_t 		SRB1bis_logicalChannelConfig_defaultValue_NB_IoT;
-extern LogicalChannelConfig_NB_r13_t 		SRB1_logicalChannelConfig_defaultValue_NB_IoT;
-
-extern uint16_t 							T300_NB_IoT[8];
-extern uint16_t 							T301_NB_IoT[8];
-extern uint16_t 							T310_NB_IoT[8];
-extern uint16_t 							T311_NB_IoT[8];
-extern uint16_t 							N310_NB_IoT[8];
-extern uint16_t 							N311_NB_IoT[8];
-extern uint8_t *get_NB_IoT_MIB(struct eNB_RRC_INST_NB_IoT_s *nb_iot_rrc);
-#endif
-
-
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file vars.h
+* \brief rrc external vars
+* \author Navid Nikaein and Raymond Knopp, Michele Paffetti
+* \date 2011-2017
+* \version 1.0
+* \company Eurecom
+* \email: navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
+*/
+
+#ifndef __OPENAIR_RRC_EXTERN_NB_IOT_H__
+#define __OPENAIR_RRC_EXTERN_NB_IOT_H__
+#include "RRC/LITE/defs_NB_IoT.h"
+#include "PHY_INTERFACE/IF_Module_NB_IoT.h"
+#include "LAYER2/RLC/rlc.h"
+#include "LogicalChannelConfig-NB-r13.h"
+#include "LAYER2/MAC/defs_NB_IoT.h"
+
+#include "common/ran_context.h"
+
+
+//MP: NOTE:XXX some of the parameters defined in vars_nb_iot are called by the extern.h file so not replicated here
+
+extern UE_RRC_INST_NB_IoT 					*UE_rrc_inst_NB_IoT;
+
+extern eNB_RRC_INST_NB_IoT 					*eNB_rrc_inst_NB_IoT;
+extern PHY_Config_NB_IoT_t 						*config_INFO;
+
+extern rlc_info_t 							Rlc_info_am_NB_IoT,Rlc_info_am_config_NB_IoT;
+extern uint8_t 								DRB2LCHAN_NB_IoT[2];
+extern LogicalChannelConfig_NB_r13_t 		SRB1bis_logicalChannelConfig_defaultValue_NB_IoT;
+extern LogicalChannelConfig_NB_r13_t 		SRB1_logicalChannelConfig_defaultValue_NB_IoT;
+
+extern uint16_t 							T300_NB_IoT[8];
+extern uint16_t 							T301_NB_IoT[8];
+extern uint16_t 							T310_NB_IoT[8];
+extern uint16_t 							T311_NB_IoT[8];
+extern uint16_t 							N310_NB_IoT[8];
+extern uint16_t 							N311_NB_IoT[8];
+extern uint8_t *get_NB_IoT_MIB(struct eNB_RRC_INST_NB_IoT_s *nb_iot_rrc);
+#endif
+
+
diff --git a/openair2/RRC/LITE/proto_NB_IoT.h b/openair2/RRC/LITE/proto_NB_IoT.h
index e346204912d17d71eec352c2d3a4ea2309cef8b7..b2218517fc8761da2f7311554e25821f02f9f06a 100644
--- a/openair2/RRC/LITE/proto_NB_IoT.h
+++ b/openair2/RRC/LITE/proto_NB_IoT.h
@@ -1,260 +1,260 @@
-/* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*! \file proto_NB_IoT.h
- * \brief RRC functions prototypes for eNB and UE for NB-IoT
- * \author Navid Nikaein, Raymond Knopp and Michele Paffetti
- * \date 2010 - 2014
- * \email navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
- * \version 1.0
-
- */
-/** \addtogroup _rrc
- *  @{
- */
-
-#include "RRC/LITE/defs_NB_IoT.h"
-#include "pdcp.h"
-#include "rlc.h"
-#include "extern_NB_IoT.h"
-#include "LAYER2/MAC/defs_NB_IoT.h"
-/*NOTE: no static function should be declared in this header file (e.g. init_SI_NB)*/
-
-/*------------------------common_nb_iot.c----------------------------------------*/
-
-/** \brief configure  BCCH & CCCH Logical Channels and associated rrc_buffers, configure associated SRBs
- */
-void openair_rrc_on_NB_IoT(const protocol_ctxt_t* const ctxt_pP);
-
-void rrc_config_buffer_NB_IoT(SRB_INFO_NB_IoT *srb_info, uint8_t Lchan_type, uint8_t Role);
-
-int L3_xface_init_NB_IoT(void);
-
-void openair_rrc_top_init_eNB_NB_IoT(void);
-
-//void rrc_top_cleanup(void); -->seems not to be used
-
-//rrc_t310_expiration-->seems not to be used
-
-/** \brief Function to update timers every subframe.  For UE it updates T300,T304 and T310.
-@param ctxt_pP  running context
-@param enb_index
-@param CC_id
-*/
-RRC_status_t rrc_rx_tx_NB_IoT(protocol_ctxt_t* const ctxt_pP, const uint8_t  enb_index, const int CC_id);
-
-//long binary_search_int(int elements[], long numElem, int value);--> seems not to be used
-//long binary_search_float(float elements[], long numElem, float value);--> used only at UE side
-
-
-
-//---------------------------------------
-
-
-//defined in L2_interface
-//called by rx_sdu only in case of CCCH message (e.g RRCConnectionRequest-NB)
-int8_t mac_rrc_data_ind_eNB_NB_IoT(
-  const module_id_t     module_idP,
-  const int             CC_id,
-  const frame_t         frameP,
-  const sub_frame_t     sub_frameP,
-  const rnti_t          rntiP,
-  const rb_id_t         srb_idP,//could be skipped since always go through the CCCH channel
-  const uint8_t*        sduP,
-  const sdu_size_t      sdu_lenP
-);
-//-------------------------------------------
-
-//defined in L2_interface
-void dump_ue_list_NB_IoT(UE_list_NB_IoT_t *listP, int ul_flag);
-//-------------------------------------------
-
-
-//defined in L2_interface
-void mac_eNB_rrc_ul_failure_NB_IoT(
-		const module_id_t mod_idP,
-	    const int CC_idP,
-	    const frame_t frameP,
-	    const sub_frame_t subframeP,
-	    const rnti_t rntiP);
-//------------------------------------------
-
-//defined in eNB_scheduler_primitives.c
-int rrc_mac_remove_ue_NB_IoT(
-		module_id_t mod_idP,
-		rnti_t rntiP);
-//------------------------------------------
-//defined in L2_interface
-void mac_eNB_rrc_ul_in_sync_NB_IoT(
-				const module_id_t mod_idP,
-			    const int CC_idP,
-			    const frame_t frameP,
-			    const sub_frame_t subframeP,
-			    const rnti_t rntiP);
-//------------------------------------------
-//defined in L2_interface
-int mac_eNB_get_rrc_status_NB_IoT(
-  const module_id_t Mod_idP,
-  const rnti_t      rntiP
-);
-//---------------------------
-
-
-/*-----------eNB procedures (rrc_eNB_nb_iot.c)---------------*/
-
-//---Initialization--------------
-void openair_eNB_rrc_on_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP
-);
-
-void rrc_config_buffer_NB_IoT(
-  SRB_INFO_NB_IoT* Srb_info,
-  uint8_t Lchan_type,
-  uint8_t Role
-);
-
-char openair_rrc_eNB_configuration_NB_IoT(
-  const module_id_t enb_mod_idP,
-  NbIoTRrcConfigurationReq* configuration
-);
-
-//-----------------------------
-/**\brief RRC eNB task. (starting of the RRC state machine)
-   \param void *args_p Pointer on arguments to start the task. */
-void *rrc_enb_task_NB_IoT(void *args_p);
-
-/**\brief Entry routine to decode a UL-CCCH-Message-NB.  Invokes PER decoder and parses message.
-   \param ctxt_pP Running context
-   \param Srb_info Pointer to SRB0 information structure (buffer, etc.)*/
-int rrc_eNB_decode_ccch_NB_IoT(
-  protocol_ctxt_t* const ctxt_pP,
-  const SRB_INFO_NB_IoT*        const Srb_info,
-  const int              CC_id
-);
-
-/**\brief Entry routine to decode a UL-DCCH-Message-NB.  Invokes PER decoder and parses message.
-   \param ctxt_pP Context
-   \param Rx_sdu Pointer Received Message
-   \param sdu_size Size of incoming SDU*/
-int rrc_eNB_decode_dcch_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  const rb_id_t                Srb_id,
-  const uint8_t*    const      Rx_sdu,
-  const sdu_size_t             sdu_sizeP
-);
-
-/**\brief Generate RRCConnectionReestablishmentReject-NB
-   \param ctxt_pP       Running context
-   \param ue_context_pP UE context
-   \param CC_id         Component Carrier ID*/
-void rrc_eNB_generate_RRCConnectionReestablishmentReject_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP,
-  const int                    CC_id
-);
-
-void rrc_eNB_generate_RRCConnectionReject_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP,
-  const int                    CC_id
-);
-
-void rrc_eNB_generate_RRCConnectionSetup_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP,
-  const int                    CC_id
-);
-
-void rrc_eNB_process_RRCConnectionReconfigurationComplete_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*        ue_context_pP,
-  const uint8_t xid //transaction identifier
-);
-
-
-void //was under ITTI
-rrc_eNB_reconfigure_DRBs_NB_IoT(const protocol_ctxt_t* const ctxt_pP,
-			       rrc_eNB_ue_context_NB_IoT_t*  ue_context_pP);
-
-void //was under ITTI
-rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_NB_IoT(
-		const protocol_ctxt_t* const ctxt_pP,
-	    rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
-//            const uint8_t      ho_state
-	     );
-
-void rrc_eNB_process_RRCConnectionSetupComplete_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*         ue_context_pP,
-  RRCConnectionSetupComplete_NB_r13_IEs_t * rrcConnectionSetupComplete_NB
-);
-
-void rrc_eNB_generate_SecurityModeCommand_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
-);
-
-void rrc_eNB_generate_UECapabilityEnquiry_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
-);
-
-void rrc_eNB_generate_defaultRRCConnectionReconfiguration_NB_IoT(const protocol_ctxt_t* const ctxt_pP,
-						                                                     rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
-						                                                     //no HO flag
-						                                                    );
-
-
-/// Utilities------------------------------------------------
-
-void rrc_eNB_free_UE_NB_IoT(
-		const module_id_t enb_mod_idP,
-		const struct rrc_eNB_ue_context_NB_IoT_s*        const ue_context_pP
-		);
-
-void rrc_eNB_free_mem_UE_context_NB_IoT(
-  const protocol_ctxt_t*               const ctxt_pP,
-  struct rrc_eNB_ue_context_NB_IoT_s*         const ue_context_pP
-);
-
-
-
-/**\brief Function to get the next transaction identifier.
-   \param module_idP Instance ID for CH/eNB
-   \return a transaction identifier*/
-uint8_t rrc_eNB_get_next_transaction_identifier_NB_IoT(module_id_t module_idP);
-
-
-int rrc_init_global_param_NB_IoT(void);
-
-//L2_interface.c
-int8_t mac_rrc_data_req_eNB_NB_IoT(
-  const module_id_t Mod_idP,
-  const int         CC_id,
-  const frame_t     frameP,
-  const frame_t   h_frameP,
-  const sub_frame_t   subframeP, //need for the case in which both SIB1-NB_IoT and SIB23-NB_IoT will be scheduled in the same frame
-  const rb_id_t     Srb_id,
-  uint8_t* const buffer_pP,
-  uint8_t   flag
-);
-
-
-
+/* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file proto_NB_IoT.h
+ * \brief RRC functions prototypes for eNB and UE for NB-IoT
+ * \author Navid Nikaein, Raymond Knopp and Michele Paffetti
+ * \date 2010 - 2014
+ * \email navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
+ * \version 1.0
+
+ */
+/** \addtogroup _rrc
+ *  @{
+ */
+
+#include "RRC/LITE/defs_NB_IoT.h"
+#include "pdcp.h"
+#include "rlc.h"
+#include "extern_NB_IoT.h"
+#include "LAYER2/MAC/defs_NB_IoT.h"
+/*NOTE: no static function should be declared in this header file (e.g. init_SI_NB)*/
+
+/*------------------------common_nb_iot.c----------------------------------------*/
+
+/** \brief configure  BCCH & CCCH Logical Channels and associated rrc_buffers, configure associated SRBs
+ */
+void openair_rrc_on_NB_IoT(const protocol_ctxt_t* const ctxt_pP);
+
+void rrc_config_buffer_NB_IoT(SRB_INFO_NB_IoT *srb_info, uint8_t Lchan_type, uint8_t Role);
+
+int L3_xface_init_NB_IoT(void);
+
+void openair_rrc_top_init_eNB_NB_IoT(void);
+
+//void rrc_top_cleanup(void); -->seems not to be used
+
+//rrc_t310_expiration-->seems not to be used
+
+/** \brief Function to update timers every subframe.  For UE it updates T300,T304 and T310.
+@param ctxt_pP  running context
+@param enb_index
+@param CC_id
+*/
+RRC_status_t rrc_rx_tx_NB_IoT(protocol_ctxt_t* const ctxt_pP, const uint8_t  enb_index, const int CC_id);
+
+//long binary_search_int(int elements[], long numElem, int value);--> seems not to be used
+//long binary_search_float(float elements[], long numElem, float value);--> used only at UE side
+
+
+
+//---------------------------------------
+
+
+//defined in L2_interface
+//called by rx_sdu only in case of CCCH message (e.g RRCConnectionRequest-NB)
+int8_t mac_rrc_data_ind_eNB_NB_IoT(
+  const module_id_t     module_idP,
+  const int             CC_id,
+  const frame_t         frameP,
+  const sub_frame_t     sub_frameP,
+  const rnti_t          rntiP,
+  const rb_id_t         srb_idP,//could be skipped since always go through the CCCH channel
+  const uint8_t*        sduP,
+  const sdu_size_t      sdu_lenP
+);
+//-------------------------------------------
+
+//defined in L2_interface
+void dump_ue_list_NB_IoT(UE_list_NB_IoT_t *listP, int ul_flag);
+//-------------------------------------------
+
+
+//defined in L2_interface
+void mac_eNB_rrc_ul_failure_NB_IoT(
+		const module_id_t mod_idP,
+	    const int CC_idP,
+	    const frame_t frameP,
+	    const sub_frame_t subframeP,
+	    const rnti_t rntiP);
+//------------------------------------------
+
+//defined in eNB_scheduler_primitives.c
+int rrc_mac_remove_ue_NB_IoT(
+		module_id_t mod_idP,
+		rnti_t rntiP);
+//------------------------------------------
+//defined in L2_interface
+void mac_eNB_rrc_ul_in_sync_NB_IoT(
+				const module_id_t mod_idP,
+			    const int CC_idP,
+			    const frame_t frameP,
+			    const sub_frame_t subframeP,
+			    const rnti_t rntiP);
+//------------------------------------------
+//defined in L2_interface
+int mac_eNB_get_rrc_status_NB_IoT(
+  const module_id_t Mod_idP,
+  const rnti_t      rntiP
+);
+//---------------------------
+
+
+/*-----------eNB procedures (rrc_eNB_nb_iot.c)---------------*/
+
+//---Initialization--------------
+void openair_eNB_rrc_on_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP
+);
+
+void rrc_config_buffer_NB_IoT(
+  SRB_INFO_NB_IoT* Srb_info,
+  uint8_t Lchan_type,
+  uint8_t Role
+);
+
+char openair_rrc_eNB_configuration_NB_IoT(
+  const module_id_t enb_mod_idP,
+  NbIoTRrcConfigurationReq* configuration
+);
+
+//-----------------------------
+/**\brief RRC eNB task. (starting of the RRC state machine)
+   \param void *args_p Pointer on arguments to start the task. */
+void *rrc_enb_task_NB_IoT(void *args_p);
+
+/**\brief Entry routine to decode a UL-CCCH-Message-NB.  Invokes PER decoder and parses message.
+   \param ctxt_pP Running context
+   \param Srb_info Pointer to SRB0 information structure (buffer, etc.)*/
+int rrc_eNB_decode_ccch_NB_IoT(
+  protocol_ctxt_t* const ctxt_pP,
+  const SRB_INFO_NB_IoT*        const Srb_info,
+  const int              CC_id
+);
+
+/**\brief Entry routine to decode a UL-DCCH-Message-NB.  Invokes PER decoder and parses message.
+   \param ctxt_pP Context
+   \param Rx_sdu Pointer Received Message
+   \param sdu_size Size of incoming SDU*/
+int rrc_eNB_decode_dcch_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  const rb_id_t                Srb_id,
+  const uint8_t*    const      Rx_sdu,
+  const sdu_size_t             sdu_sizeP
+);
+
+/**\brief Generate RRCConnectionReestablishmentReject-NB
+   \param ctxt_pP       Running context
+   \param ue_context_pP UE context
+   \param CC_id         Component Carrier ID*/
+void rrc_eNB_generate_RRCConnectionReestablishmentReject_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP,
+  const int                    CC_id
+);
+
+void rrc_eNB_generate_RRCConnectionReject_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP,
+  const int                    CC_id
+);
+
+void rrc_eNB_generate_RRCConnectionSetup_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP,
+  const int                    CC_id
+);
+
+void rrc_eNB_process_RRCConnectionReconfigurationComplete_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*        ue_context_pP,
+  const uint8_t xid //transaction identifier
+);
+
+
+void //was under ITTI
+rrc_eNB_reconfigure_DRBs_NB_IoT(const protocol_ctxt_t* const ctxt_pP,
+			       rrc_eNB_ue_context_NB_IoT_t*  ue_context_pP);
+
+void //was under ITTI
+rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_NB_IoT(
+		const protocol_ctxt_t* const ctxt_pP,
+	    rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
+//            const uint8_t      ho_state
+	     );
+
+void rrc_eNB_process_RRCConnectionSetupComplete_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*         ue_context_pP,
+  RRCConnectionSetupComplete_NB_r13_IEs_t * rrcConnectionSetupComplete_NB
+);
+
+void rrc_eNB_generate_SecurityModeCommand_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
+);
+
+void rrc_eNB_generate_UECapabilityEnquiry_NB_IoT(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
+);
+
+void rrc_eNB_generate_defaultRRCConnectionReconfiguration_NB_IoT(const protocol_ctxt_t* const ctxt_pP,
+						                                                     rrc_eNB_ue_context_NB_IoT_t*          const ue_context_pP
+						                                                     //no HO flag
+						                                                    );
+
+
+/// Utilities------------------------------------------------
+
+void rrc_eNB_free_UE_NB_IoT(
+		const module_id_t enb_mod_idP,
+		const struct rrc_eNB_ue_context_NB_IoT_s*        const ue_context_pP
+		);
+
+void rrc_eNB_free_mem_UE_context_NB_IoT(
+  const protocol_ctxt_t*               const ctxt_pP,
+  struct rrc_eNB_ue_context_NB_IoT_s*         const ue_context_pP
+);
+
+
+
+/**\brief Function to get the next transaction identifier.
+   \param module_idP Instance ID for CH/eNB
+   \return a transaction identifier*/
+uint8_t rrc_eNB_get_next_transaction_identifier_NB_IoT(module_id_t module_idP);
+
+
+int rrc_init_global_param_NB_IoT(void);
+
+//L2_interface.c
+int8_t mac_rrc_data_req_eNB_NB_IoT(
+  const module_id_t Mod_idP,
+  const int         CC_id,
+  const frame_t     frameP,
+  const frame_t   h_frameP,
+  const sub_frame_t   subframeP, //need for the case in which both SIB1-NB_IoT and SIB23-NB_IoT will be scheduled in the same frame
+  const rb_id_t     Srb_id,
+  uint8_t* const buffer_pP,
+  uint8_t   flag
+);
+
+
+