From ca9748eca7ea5dba36d761ca81ddc36179c1f6d0 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Sun, 16 Sep 2018 11:03:53 +0200
Subject: [PATCH] corrections to RNTI coding/decoding in openair3/conversions.h

---
 openair2/F1AP/f1ap_cu_rrc_message_transfer.c | 22 +++++++++-----------
 openair2/F1AP/f1ap_cu_task.c                 |  8 +++----
 openair2/F1AP/f1ap_decoder.c                 | 14 ++++++++-----
 openair2/F1AP/f1ap_handlers.c                |  1 +
 openair3/SCTP/sctp_eNB_task.c                |  1 -
 openair3/UTILS/conversions.h                 |  4 ++--
 6 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
index 52a6a63320..78090104bb 100644
--- a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
+++ b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
@@ -87,31 +87,29 @@ int CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t             instance,
   /* RNTI */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_C_RNTI, true);
-  BIT_STRING_TO_CELL_IDENTITY(&ie->value.choice.C_RNTI, rnti);
+  BUFFER_TO_INT16(ie->value.choice.C_RNTI.buf, rnti);
 
   /* RRC Container */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_RRCContainer, true);
 
-  ccch_sdu = calloc(ie->value.choice.RRCContainer.size + 1, sizeof(char));
-  memcpy(ccch_sdu, ie->value.choice.RRCContainer.buf,
-         ie->value.choice.RRCContainer.size);
-  /* Convert the mme name to a printable string */
-  ccch_sdu[ie->value.choice.RRCContainer.size] = '\0';
-  printf ("RRCContainer %s \n", ccch_sdu);
-
-  ccch_sdu_len = ie->value.choice.RRCContainer.size;
-
-  // create an ITTI message 
+  // create an ITTI message and copy SDU
   message_p = itti_alloc_new_message (TASK_CU_F1, RRC_MAC_CCCH_DATA_IND);
   memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
-  memcpy (RRC_MAC_CCCH_DATA_IND (message_p).sdu, ccch_sdu, ccch_sdu_len);
+  ccch_sdu_len = ie->value.choice.RRCContainer.size;
+  memcpy(RRC_MAC_CCCH_DATA_IND (message_p).sdu, ie->value.choice.RRCContainer.buf,
+         ccch_sdu_len);
+  printf ("RRCContainer(CCCH) :");
+  for (int i=0;i<ie->value.choice.RRCContainer.size;i++) printf("%2x ",RRC_MAC_CCCH_DATA_IND (message_p).sdu[i]);
+
+
   RRC_MAC_CCCH_DATA_IND (message_p).frame     = 0; 
   RRC_MAC_CCCH_DATA_IND (message_p).sub_frame = 0;
   RRC_MAC_CCCH_DATA_IND (message_p).sdu_size  = ccch_sdu_len;
   RRC_MAC_CCCH_DATA_IND (message_p).enb_index = instance; // CU instance 
   RRC_MAC_CCCH_DATA_IND (message_p).rnti      = rnti;
   RRC_MAC_CCCH_DATA_IND (message_p).CC_id      = CC_id; 
+  printf("Sending ITTI message to instance %d, rnti %x\n",instance,rnti);
   itti_send_msg_to_task (TASK_RRC_ENB, instance, message_p);
 
 
diff --git a/openair2/F1AP/f1ap_cu_task.c b/openair2/F1AP/f1ap_cu_task.c
index c7deb55e16..d6ab3adbdc 100644
--- a/openair2/F1AP/f1ap_cu_task.c
+++ b/openair2/F1AP/f1ap_cu_task.c
@@ -119,19 +119,19 @@ void *F1AP_CU_task(void *arg) {
     switch (ITTI_MSG_ID(received_msg)) {
 
       case SCTP_NEW_ASSOCIATION_IND:
-        LOG_I(CU_F1AP, "SCTP_NEW_ASSOCIATION_IND\n");
+        LOG_I(CU_F1AP, "SCTP_NEW_ASSOCIATION_IND for instance %d\n",ITTI_MESSAGE_GET_INSTANCE(received_msg));
         cu_task_handle_sctp_association_ind(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                                          &received_msg->ittiMsg.sctp_new_association_ind);
         break;
 
       case SCTP_NEW_ASSOCIATION_RESP:
-        LOG_I(CU_F1AP, "SCTP_NEW_ASSOCIATION_RESP\n");
+        LOG_I(CU_F1AP, "SCTP_NEW_ASSOCIATION_RESP for instance %d\n",ITTI_MESSAGE_GET_INSTANCE(received_msg));
         cu_task_handle_sctp_association_resp(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                                          &received_msg->ittiMsg.sctp_new_association_resp);
         break;
 
       case SCTP_DATA_IND:
-        LOG_I(CU_F1AP, "SCTP_DATA_IND\n");
+        LOG_I(CU_F1AP, "SCTP_DATA_IND for Instance %d\n",ITTI_MESSAGE_GET_INSTANCE(received_msg));
         cu_task_handle_sctp_data_ind(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                                         &received_msg->ittiMsg.sctp_data_ind);
         break;
@@ -170,4 +170,4 @@ void *F1AP_CU_task(void *arg) {
   } // while
 
   return NULL;
-}
\ No newline at end of file
+}
diff --git a/openair2/F1AP/f1ap_decoder.c b/openair2/F1AP/f1ap_decoder.c
index 6a6a761866..80279d6258 100644
--- a/openair2/F1AP/f1ap_decoder.c
+++ b/openair2/F1AP/f1ap_decoder.c
@@ -41,11 +41,15 @@ static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu)
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.initiatingMessage->procedureCode) {
-
-    case F1AP_ProcedureCode_id_F1Setup:
-      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
-      printf("f1ap_eNB_decode_initiating_message!\n");
-      break;
+    
+  case F1AP_ProcedureCode_id_F1Setup:
+    res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
+    printf("f1ap_eNB_decode_initiating_message!\n");
+    break;
+  case F1AP_ProcedureCode_id_InitialULRRCMessageTransfer:
+    res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
+    printf("f1ap_eNB_decode_initiating_message!\n");
+    break;
     // case F1AP_ProcedureCode_id_InitialContextSetup:
     //   res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
     //   message_id = F1AP_INITIAL_CONTEXT_SETUP_LOG;
diff --git a/openair2/F1AP/f1ap_handlers.c b/openair2/F1AP/f1ap_handlers.c
index c2d647e9b8..3957a7e2c9 100644
--- a/openair2/F1AP/f1ap_handlers.c
+++ b/openair2/F1AP/f1ap_handlers.c
@@ -116,6 +116,7 @@ int f1ap_handle_message(instance_t instance, uint32_t assoc_id, int32_t stream,
   }
 
   /* Calling the right handler */
+  printf("Calling handler with instance %d\n",instance);
   ret = (*f1ap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1])
         (instance, assoc_id, stream, &pdu);
   ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu);
diff --git a/openair3/SCTP/sctp_eNB_task.c b/openair3/SCTP/sctp_eNB_task.c
index d05a67edb2..168eb58b37 100644
--- a/openair3/SCTP/sctp_eNB_task.c
+++ b/openair3/SCTP/sctp_eNB_task.c
@@ -838,7 +838,6 @@ void *sctp_eNB_task(void *arg)
       break;
 
       case SCTP_DATA_REQ: {
-	printf("SCTP: Sending message via SCTP\n");
         sctp_send_data(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                        ITTI_MSG_ORIGIN_ID(received_msg),
                        &received_msg->ittiMsg.sctp_data_req);
diff --git a/openair3/UTILS/conversions.h b/openair3/UTILS/conversions.h
index d6bbbbd03d..04e9712d91 100644
--- a/openair3/UTILS/conversions.h
+++ b/openair3/UTILS/conversions.h
@@ -258,8 +258,8 @@ do {                                                                    \
 #define C_RNTI_TO_BIT_STRING(mACRO, bITsTRING)          \
 do {                                                    \
     (bITsTRING)->buf = calloc(2, sizeof(uint8_t));      \
-    (bITsTRING)->buf[0] = (mACRO) >> 4;                 \
-    (bITsTRING)->buf[1] = ((mACRO) & 0x0f) << 4;        \
+    (bITsTRING)->buf[0] = (mACRO) >> 8;                 \
+    (bITsTRING)->buf[1] = ((mACRO) & 0x0ff);            \
     (bITsTRING)->size = 2;                              \
     (bITsTRING)->bits_unused = 0;                       \
 } while(0)
-- 
GitLab