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"
8 /*******************************************************************
10 * @brief Writes the encoded chunks into a buffer
14 * Function : PrepFinalEncBuf
16 * Functionality:Fills the encoded buffer
18 * @params[in] void *buffer,initial encoded data
19 * @params[in] size_t size,size of buffer
20 * @params[in] void *encodedBuf,final buffer
21 * @return ROK - success
24 * ****************************************************************/
25 int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
27 memcpy(encodedBuf + encBufSize, buffer, size);
30 } /* PrepFinalEncBuf */
32 /*******************************************************************
34 * @brief Fills the RicId
38 * Function : FillRicId
40 * Functionality: Fills the RicId
42 * @params[in] BIT_STRING_t *nbid,
47 * @return ROK - success
50 * ****************************************************************/
52 uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, uint64_t data)
59 DU_LOG("\nERROR --> DU_APP : Buffer allocation is empty");
62 memset(id->buf, 0, byteSize);
63 data = data << unusedBits;
65 /*Now, seggregate the value into 'byteSize' number of Octets in sequence:
66 * 1. Pull out a byte of value (Starting from MSB) and put in the 0th Octet
67 * 2. Fill the buffer/String Octet one by one until LSB is reached*/
68 for(byteIdx = 1; byteIdx <= byteSize; byteIdx++)
71 tmp = (tmp << (8 * (byteSize - byteIdx)));
72 tmp = (data & tmp) >> (8 * (byteSize - byteIdx));
73 id->buf[byteIdx - 1] = tmp;
75 id->bits_unused = unusedBits;
79 /*******************************************************************
81 * @brief Converts bit strings to integer
85 * Function : bitStringToInt
88 * - Converts ASN bit string format IEs to integer type
91 * @return ROK - success
94 * ****************************************************************/
95 uint8_t bitStringToInt(BIT_STRING_t *bitString, void *value)
98 uint64_t *val = NULLP;
100 if(bitString->buf == NULL || bitString->size <= 0)
102 DU_LOG("\nERROR --> DU_APP : Bit string is empty");
107 val = (uint64_t *)value;
111 for(idx=0; idx< bitString->size-1; idx++)
113 *val |= bitString->buf[idx];
116 *val |= bitString->buf[idx];
117 *val >>= bitString->bits_unused;
122 /*******************************************************************
124 * @brief Function to decode teId value from the octect String
128 * Function : teIdStringToInt
130 * Functionality: Function to decode teId value from the octect string
131 * It can used as generic function to convert
132 * octect string to uint32_t value
134 * @params[in] buf, value
137 * ****************************************************************/
138 void teIdStringToInt(uint8_t *buf, uint32_t *val)
140 uint32_t temp1 = 0, temp2 = 0, temp3 = 0;
151 *val = temp1|temp2|temp3|buf[3];
154 /*******************************************************************
156 * @brief Function to encode teId value to the octect String
160 * Function : fillTeIdString
162 * Functionality: Function to encode teId value to the octect String
163 * It can used as generic function to encode
164 * uint32_t value to octect string
166 * @params[in] bufSize, value, buf
169 * ****************************************************************/
171 void fillTeIdString(uint8_t bufSize, uint32_t val, uint8_t *buf)
175 for(bitPos = 0; bitPos < TEID_BIT_SIZE; bitPos += 8, bufSize--)
177 /*extracting bitBits from the bitPos*/
178 buf[bufSize] = (((1 << 8) - 1) & (val >> (bitPos)));
182 /**********************************************************************
184 **********************************************************************/