CU testing fixes
[o-du/l2.git] / src / codec_utils / common / odu_common_codec.c
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"
6
7 /*******************************************************************
8  *
9  * @brief Writes the encoded chunks into a buffer
10  *
11  * @details
12  *
13  *    Function : PrepFinalEncBuf
14  *
15  *    Functionality:Fills the encoded buffer
16  *
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
21  *         RFAILED - failure
22  *
23  * ****************************************************************/
24 int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
25 {
26    memcpy(encodedBuf + encBufSize, buffer, size);
27    encBufSize += size;
28    return 0;
29 } /* PrepFinalEncBuf */
30
31 /*******************************************************************
32  *
33  * @brief Fills the RicId
34  *
35  * @details
36  *
37  *    Function : FillRicId
38  *
39  *    Functionality: Fills the RicId
40  *
41  * @params[in] BIT_STRING_t *nbid,
42  *             uint8_t unusedBits
43  *             uint8_t byteSize
44  *             uint8_t val
45  *
46  * @return ROK     - success
47  *         RFAILED - failure
48  *
49  * ****************************************************************/
50
51 uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, uint8_t val)
52 {
53    uint8_t tmp;
54    if(id->buf == NULLP)
55    {
56       return RFAILED;
57    }
58
59    for (tmp = 0 ; tmp < (byteSize-1); tmp++)
60    {
61       id->buf[tmp] = tmp;
62    }
63    id->buf[byteSize-1]   = val;
64    id->bits_unused = unusedBits;
65    return ROK;
66 }
67
68 /*******************************************************************
69  *
70  * @brief Converts bit strings to integer
71  *
72  * @details
73  *
74  *    Function : bitStringToInt
75  *
76  *    Functionality:
77  *      - Converts ASN bit string format IEs to integer type
78  *
79  * @params[in] void
80  * @return ROK     - success
81  *         RFAILED - failure
82  *
83  * ****************************************************************/
84 uint8_t bitStringToInt(BIT_STRING_t *bitString, void *value)
85 {
86    uint16_t idx;
87    uint32_t *val = NULLP;
88
89    if(bitString->buf == NULL || bitString->size <= 0)
90    {
91       DU_LOG("\nDU_APP : Bit string is empty");
92       return RFAILED;
93    }
94
95    if(value)
96       val = (uint32_t *)value;
97    else
98       return RFAILED;
99
100    for(idx=0; idx< bitString->size-1; idx++)
101    {
102       *val |= bitString->buf[idx];
103       *val <<= 8;
104     }
105    *val |= bitString->buf[idx];
106    *val >>= bitString->bits_unused;
107
108    return ROK;
109 }
110
111
112
113 /**********************************************************************
114   End of file
115  **********************************************************************/