<[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-421]Paging Message: CU_STUB Trigger and...
[o-du/l2.git] / src / codec_utils / common / odu_common_codec.c
index 98f0023..a65aefc 100644 (file)
@@ -1,3 +1,7 @@
+#include "common_def.h"
+#include "OCTET_STRING.h"
+#include "BIT_STRING.h"
+#include "asn_codecs.h"
 #include "odu_common_codec.h"
 
 /*******************************************************************
@@ -26,75 +30,153 @@ int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
 
 /*******************************************************************
  *
- * @brief Builds PLMN ID 
+ * @brief Fills the RicId
  *
  * @details
  *
- *    Function : plmnBuildId
+ *    Function : FillRicId
  *
- *    Functionality: Building the PLMN ID
+ *    Functionality: Fills the RicId
+ *
+ * @params[in] BIT_STRING_t *nbid,
+ *             uint8_t unusedBits
+ *             uint8_t byteSize
+ *             uint8_t val
  *
- * @params[in] PLMNID plmn
- *             OCTET_STRING_t *octe
  * @return ROK     - success
  *         RFAILED - failure
  *
  * ****************************************************************/
-S16 buildPlmnId(Plmn plmn, OCTET_STRING_t *octe)
+
+uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, uint64_t data)
 {
-   U8 mncCnt;
-   mncCnt = 2;
-   octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
-   if(mncCnt == 2)
+   uint64_t tmp = 0;
+   uint8_t byteIdx = 0;
+
+   if(id->buf == NULLP)
    {
-      octe->buf[1]  = ((0xf0) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
+      DU_LOG("\nERROR  --> DU_APP : Buffer allocation is empty");
+      return RFAILED;
    }
-   else
+   memset(id->buf, 0, byteSize);
+   data = data << unusedBits;
+   
+   /*Now, seggregate the value into 'byteSize' number of Octets in sequence:
+    * 1. Pull out a byte of value (Starting from MSB) and put in the 0th Octet
+    * 2. Fill the buffer/String Octet one by one until LSB is reached*/
+   for(byteIdx = 1; byteIdx <= byteSize; byteIdx++)
    {
-      octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
-      octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
+      tmp = (uint64_t)0xFF;
+      tmp = (tmp << (8 * (byteSize - byteIdx)));
+      tmp = (data & tmp) >> (8 * (byteSize - byteIdx));
+      id->buf[byteIdx - 1]  = tmp;
    }
-   RETVALUE(ROK);
+   id->bits_unused = unusedBits;
+   return ROK;
 }
 
 /*******************************************************************
  *
- * @brief Fills the RicId
+ * @brief Converts bit strings to integer
  *
  * @details
  *
- *    Function : FillRicId
- *
- *    Functionality: Fills the RicId
+ *    Function : bitStringToInt
  *
- * @params[in] BIT_STRING_t *nbid,
- *             U8 unusedBits
- *             U8 byteSize
- *             U8 val
+ *    Functionality:
+ *      - Converts ASN bit string format IEs to integer type
  *
+ * @params[in] void
  * @return ROK     - success
  *         RFAILED - failure
  *
  * ****************************************************************/
-
-S16 fillBitString(BIT_STRING_t *id, U8 unusedBits, U8 byteSize, U8 val)
+uint8_t bitStringToInt(BIT_STRING_t *bitString, void *value)
 {
-   U8 tmp;
-   if(id->buf == NULLP)
+   uint16_t idx;
+   uint64_t *val = NULLP;
+
+   if(bitString->buf == NULL || bitString->size <= 0)
    {
-      RETVALUE(RFAILED);
+      DU_LOG("\nERROR  --> DU_APP : Bit string is empty");
+      return RFAILED;
    }
 
-   for (tmp = 0 ; tmp < (byteSize-1); tmp++)
+   if(value)
+      val = (uint64_t *)value;
+   else
+      return RFAILED;
+
+   for(idx=0; idx< bitString->size-1; idx++)
    {
-      id->buf[tmp] = tmp;
+      *val |= bitString->buf[idx];
+      *val <<= 8;
    }
-   id->buf[byteSize-1]   = val;
-   id->bits_unused = unusedBits;
-   RETVALUE(ROK);
+   *val |= bitString->buf[idx];
+   *val >>= bitString->bits_unused;
+
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Function to decode teId value from the octect String
+ *
+ * @details
+ *
+ *    Function : teIdStringToInt
+ *
+ *    Functionality: Function to decode teId value from the octect string
+ *                   It can used as generic function to convert 
+ *                   octect string to uint32_t value 
+ *
+ * @params[in]  buf, value
+ * @return void
+ *
+ * ****************************************************************/
+void teIdStringToInt(uint8_t *buf, uint32_t *val)
+{
+   uint32_t temp1 = 0, temp2 = 0, temp3 = 0;
+
+   temp1 |= buf[0];
+   temp1 <<= 24;
+
+   temp2 |= buf[1];
+   temp2 <<= 16;
+
+   temp3 |= buf[2];
+   temp3 <<= 8;
+   
+   *val = temp1|temp2|temp3|buf[3];
 }
 
+/*******************************************************************
+ *
+ * @brief Function to encode teId value to the octect String
+ *
+ * @details
+ *
+ *    Function : fillTeIdString
+ *
+ *    Functionality: Function to encode teId value to the octect String
+ *                   It can used as generic function to encode 
+ *                   uint32_t value to octect string
+ *
+ * @params[in]  bufSize, value, buf
+ * @return void
+ *
+ * ****************************************************************/
+
+void fillTeIdString(uint8_t bufSize, uint32_t val, uint8_t *buf)
+{
+   uint8_t bitPos;
+
+   for(bitPos = 0; bitPos < TEID_BIT_SIZE; bitPos += 8, bufSize--)
+   {
+      /*extracting bitBits from the bitPos*/
+      buf[bufSize] = (((1 << 8) - 1) & (val >> (bitPos))); 
+   }
+}
 
 /**********************************************************************
   End of file