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, uint8_t val)
59 memset(id->buf, 0, byteSize-1);
60 id->buf[byteSize-1] = val;
61 id->bits_unused = unusedBits;
65 /*******************************************************************
67 * @brief Converts bit strings to integer
71 * Function : bitStringToInt
74 * - Converts ASN bit string format IEs to integer type
77 * @return ROK - success
80 * ****************************************************************/
81 uint8_t bitStringToInt(BIT_STRING_t *bitString, void *value)
84 uint32_t *val = NULLP;
86 if(bitString->buf == NULL || bitString->size <= 0)
88 DU_LOG("\nDU_APP : Bit string is empty");
93 val = (uint32_t *)value;
97 for(idx=0; idx< bitString->size-1; idx++)
99 *val |= bitString->buf[idx];
102 *val |= bitString->buf[idx];
103 *val >>= bitString->bits_unused;
108 /*******************************************************************
110 * @brief Function to decode teId value from the octect String
114 * Function : teIdStringToInt
116 * Functionality: Function to decode teId value from the octect string
117 * It can used as generic function to convert
118 * octect string to uint32_t value
120 * @params[in] buf, value
123 * ****************************************************************/
124 void teIdStringToInt(uint8_t *buf, uint32_t *val)
126 uint32_t temp1 = 0, temp2 = 0, temp3 = 0;
137 *val = temp1|temp2|temp3|buf[3];
140 /*******************************************************************
142 * @brief Function to encode teId value to the octect String
146 * Function : fillTeIdString
148 * Functionality: Function to encode teId value to the octect String
149 * It can used as generic function to encode
150 * uint32_t value to octect string
152 * @params[in] bufSize, value, buf
155 * ****************************************************************/
157 void fillTeIdString(uint8_t bufSize, uint32_t val, uint8_t *buf)
161 for(bitPos = 0; bitPos < TEID_BIT_SIZE; bitPos += 8, bufSize--)
163 /*extracting bitBits from the bitPos*/
164 buf[bufSize] = (((1 << 8) - 1) & (val >> (bitPos)));
168 /**********************************************************************
170 **********************************************************************/