MAC Clean-up [Issue-ID: ODUHIGH-212]
[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 S16 buildPlmnId(Plmn plmn, OCTET_STRING_t *octe)
48 {
49    U8 mncCnt;
50    mncCnt = 2;
51    octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
52    if(mncCnt == 2)
53    {
54       octe->buf[1]  = ((0xf0) | (plmn.mcc[2]));
55       octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
56    }
57    else
58    {
59       octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
60       octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
61    }
62    RETVALUE(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  *             U8 unusedBits
77  *             U8 byteSize
78  *             U8 val
79  *
80  * @return ROK     - success
81  *         RFAILED - failure
82  *
83  * ****************************************************************/
84
85 S16 fillBitString(BIT_STRING_t *id, U8 unusedBits, U8 byteSize, U8 val)
86 {
87    U8 tmp;
88    if(id->buf == NULLP)
89    {
90       RETVALUE(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    RETVALUE(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 S16 bitStringToInt(BIT_STRING_t *bitString, U16 *val)
119 {
120    U16 idx;
121    if(bitString->buf == NULL || bitString->size <= 0)
122    {
123       DU_LOG("\nDU_APP : Bit string is empty");
124       return RFAILED;
125    }
126
127    for(idx=0; idx< bitString->size-1; idx++)
128    {
129       *val |= bitString->buf[idx];
130       *val <<= 8;
131     }
132    *val |= bitString->buf[idx];
133    *val >>= bitString->bits_unused;
134
135    return ROK;
136 }
137
138
139
140 /**********************************************************************
141   End of file
142  **********************************************************************/