[JIRA ID: ODUHIGH-242] RB configuration for Ue Context Setup for RLC
[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 Builds PLMN ID 
34  *
35  * @details
36  *
37  *    Function : plmnBuildId
38  *
39  *    Functionality: Building the PLMN ID
40  *
41  * @params[in] PLMNID plmn
42  *             OCTET_STRING_t *octe
43  * @return ROK     - success
44  *         RFAILED - failure
45  *
46  * ****************************************************************/
47 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf)
48 {
49    uint8_t mncCnt;
50    mncCnt = 2;
51    buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
52    if(mncCnt == 2)
53    {
54       buf[1]  = ((0xf0) | (plmn.mcc[2]));
55       buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
56    }
57    else
58    {
59       buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
60       buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
61    }
62    return ROK;
63 }
64
65 /*******************************************************************
66  *
67  * @brief Fills the RicId
68  *
69  * @details
70  *
71  *    Function : FillRicId
72  *
73  *    Functionality: Fills the RicId
74  *
75  * @params[in] BIT_STRING_t *nbid,
76  *             uint8_t unusedBits
77  *             uint8_t byteSize
78  *             uint8_t val
79  *
80  * @return ROK     - success
81  *         RFAILED - failure
82  *
83  * ****************************************************************/
84
85 uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, uint8_t val)
86 {
87    uint8_t tmp;
88    if(id->buf == NULLP)
89    {
90       return RFAILED;
91    }
92
93    for (tmp = 0 ; tmp < (byteSize-1); tmp++)
94    {
95       id->buf[tmp] = tmp;
96    }
97    id->buf[byteSize-1]   = val;
98    id->bits_unused = unusedBits;
99    return ROK;
100 }
101
102 /*******************************************************************
103  *
104  * @brief Converts bit strings to integer
105  *
106  * @details
107  *
108  *    Function : bitStringToInt
109  *
110  *    Functionality:
111  *      - Converts ASN bit string format IEs to integer type
112  *
113  * @params[in] void
114  * @return ROK     - success
115  *         RFAILED - failure
116  *
117  * ****************************************************************/
118 uint8_t bitStringToInt(BIT_STRING_t *bitString, void *value)
119 {
120    uint16_t idx;
121    uint32_t *val = NULLP;
122
123    if(bitString->buf == NULL || bitString->size <= 0)
124    {
125       DU_LOG("\nDU_APP : Bit string is empty");
126       return RFAILED;
127    }
128
129    if(value)
130       val = (uint32_t *)value;
131    else
132       return RFAILED;
133
134    for(idx=0; idx< bitString->size-1; idx++)
135    {
136       *val |= bitString->buf[idx];
137       *val <<= 8;
138     }
139    *val |= bitString->buf[idx];
140    *val >>= bitString->bits_unused;
141
142    return ROK;
143 }
144
145
146
147 /**********************************************************************
148   End of file
149  **********************************************************************/