X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fcodec_utils%2Fcommon%2Fodu_common_codec.c;h=a65aefc9e3c94f6fa35596bd1f5c600b38625e8a;hb=b5a77f556b20a2acd7d653367fdcac030461f85b;hp=b3ba6bc3e111f07db7031ce6dfa8dc15ef58036e;hpb=9c4801c94d7798cc638a6b112d514e68c695f20a;p=o-du%2Fl2.git diff --git a/src/codec_utils/common/odu_common_codec.c b/src/codec_utils/common/odu_common_codec.c index b3ba6bc3e..a65aefc9e 100644 --- a/src/codec_utils/common/odu_common_codec.c +++ b/src/codec_utils/common/odu_common_codec.c @@ -48,16 +48,29 @@ int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf) * * ****************************************************************/ -uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, uint8_t val) +uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, uint64_t data) { - uint8_t tmp; + uint64_t tmp = 0; + uint8_t byteIdx = 0; + if(id->buf == NULLP) { + DU_LOG("\nERROR --> DU_APP : Buffer allocation is empty"); return RFAILED; } - - memset(id->buf, 0, byteSize-1); - id->buf[byteSize-1] = val; + memset(id->buf, 0, byteSize); + data = data << unusedBits; + + /*Now, seggregate the value into 'byteSize' number of Octets in sequence: + * 1. Pull out a byte of value (Starting from MSB) and put in the 0th Octet + * 2. Fill the buffer/String Octet one by one until LSB is reached*/ + for(byteIdx = 1; byteIdx <= byteSize; byteIdx++) + { + tmp = (uint64_t)0xFF; + tmp = (tmp << (8 * (byteSize - byteIdx))); + tmp = (data & tmp) >> (8 * (byteSize - byteIdx)); + id->buf[byteIdx - 1] = tmp; + } id->bits_unused = unusedBits; return ROK; } @@ -81,16 +94,16 @@ uint8_t fillBitString(BIT_STRING_t *id, uint8_t unusedBits, uint8_t byteSize, ui uint8_t bitStringToInt(BIT_STRING_t *bitString, void *value) { uint16_t idx; - uint32_t *val = NULLP; + uint64_t *val = NULLP; if(bitString->buf == NULL || bitString->size <= 0) { - DU_LOG("\nDU_APP : Bit string is empty"); + DU_LOG("\nERROR --> DU_APP : Bit string is empty"); return RFAILED; } if(value) - val = (uint32_t *)value; + val = (uint64_t *)value; else return RFAILED;