1 #include "common_def.h"
2 #include "OCTET_STRING.h"
3 #include "BIT_STRING.h"
4 #include "asn_codecs.h"
5 #include "odu_common_codec.h"
7 /*******************************************************************
9 * @brief Writes the encoded chunks into a buffer
13 * Function : PrepFinalEncBuf
15 * Functionality:Fills the encoded buffer
17 * @params[in] void *buffer,initial encoded data
18 * @params[in] size_t size,size of buffer
19 * @params[in] void *encodedBuf,final buffer
20 * @return ROK - success
23 * ****************************************************************/
24 int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
26 memcpy(encodedBuf + encBufSize, buffer, size);
29 } /* PrepFinalEncBuf */
31 /*******************************************************************
33 * @brief Fills the RicId
37 * Function : FillRicId
39 * Functionality: Fills the RicId
41 * @params[in] BIT_STRING_t *nbid,
46 * @return ROK - success
49 * ****************************************************************/
51 uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, uint64_t data)
58 DU_LOG("\nERROR --> DU_APP : Buffer allocation is empty");
61 memset(id->buf, 0, byteSize);
62 data = data << unusedBits;
64 /*Now, seggregate the value into 'byteSize' number of Octets in sequence:
65 * 1. Pull out a byte of value (Starting from MSB) and put in the 0th Octet
66 * 2. Fill the buffer/String Octet one by one until LSB is reached*/
67 for(byteIdx = 1; byteIdx <= byteSize; byteIdx++)
70 tmp = (tmp << (8 * (byteSize - byteIdx)));
71 tmp = (data & tmp) >> (8 * (byteSize - byteIdx));
72 id->buf[byteIdx - 1] = tmp;
74 id->bits_unused = unusedBits;
78 /*******************************************************************
80 * @brief Converts bit strings to integer
84 * Function : bitStringToInt
87 * - Converts ASN bit string format IEs to integer type
90 * @return ROK - success
93 * ****************************************************************/
94 uint8_t bitStringToInt(BIT_STRING_t *bitString, void *value)
97 uint64_t *val = NULLP;
99 if(bitString->buf == NULL || bitString->size <= 0)
101 DU_LOG("\nERROR --> DU_APP : Bit string is empty");
106 val = (uint64_t *)value;
110 for(idx=0; idx< bitString->size-1; idx++)
112 *val |= bitString->buf[idx];
115 *val |= bitString->buf[idx];
116 *val >>= bitString->bits_unused;
121 /*******************************************************************
123 * @brief Function to decode teId value from the octect String
127 * Function : teIdStringToInt
129 * Functionality: Function to decode teId value from the octect string
130 * It can used as generic function to convert
131 * octect string to uint32_t value
133 * @params[in] buf, value
136 * ****************************************************************/
137 void teIdStringToInt(uint8_t *buf, uint32_t *val)
139 uint32_t temp1 = 0, temp2 = 0, temp3 = 0;
150 *val = temp1|temp2|temp3|buf[3];
153 /*******************************************************************
155 * @brief Function to encode teId value to the octect String
159 * Function : fillTeIdString
161 * Functionality: Function to encode teId value to the octect String
162 * It can used as generic function to encode
163 * uint32_t value to octect string
165 * @params[in] bufSize, value, buf
168 * ****************************************************************/
170 void fillTeIdString(uint8_t bufSize, uint32_t val, uint8_t *buf)
174 for(bitPos = 0; bitPos < TEID_BIT_SIZE; bitPos += 8, bufSize--)
176 /*extracting bitBits from the bitPos*/
177 buf[bufSize] = (((1 << 8) - 1) & (val >> (bitPos)));
181 /**********************************************************************
183 **********************************************************************/