Create a function to get the padding needed to align a TLV to the next 32-bit...

Create a function to get the padding needed to align a TLV to the next 32-bit boundary, instead of re-using the formula on multiple spots;
Fix pushed length of TLVs with fixed uint16_t[5] length;
parent 8498aaea
......@@ -76,6 +76,8 @@ uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *e
uint32_t pack_vendor_extension_tlv(nfapi_tl_t* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* config);
int unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* config, nfapi_tl_t** ve_tlv);
uint8_t get_tlv_padding(uint16_t tlv_length);
typedef uint8_t (*unpack_tlv_fn)(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end);
typedef struct
{
......
......@@ -651,7 +651,7 @@ int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPa
on_error();
}
// Remove padding that ensures multiple of 4 bytes (SCF 225 Section 2.3.2.1)
int padding = ( 4 - (tl->length % 4) ) % 4;
int padding = get_tlv_padding(tl->length);
if (padding != 0) {
(*ppReadPackedMsg) += padding;
}
......@@ -678,7 +678,7 @@ int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPa
if((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + ( 4 - (generic_tl.length % 4) ) % 4;
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);
} else {
// go to the end
return 0;
......@@ -696,7 +696,7 @@ int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPa
if((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + ( 4 - (generic_tl.length % 4) ) % 4;
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);
} else {
// go to the end
return 0;
......@@ -738,7 +738,7 @@ int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **pp
on_error();
}
// Remove padding that ensures multiple of 4 bytes (SCF 225 Section 2.3.2.1)
int padding = ( 4 - (tl->length % 4) ) % 4;
int padding = get_tlv_padding(tl->length);
if (padding != 0) {
(*ppReadPackedMsg) += padding;
}
......@@ -765,7 +765,7 @@ int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **pp
if((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + ( 4 - (generic_tl.length % 4) ) % 4;
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);;
} else {
// got ot the dn
return 0;
......@@ -783,7 +783,7 @@ int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **pp
if((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + ( 4 - (generic_tl.length % 4) ) % 4;
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);
} else {
// got ot the dn
return 0;
......@@ -820,7 +820,8 @@ uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *e
// rewrite the header with the correct length
pack_tl(tl, &pStartOfTlv, end);
// Add padding that ensures multiple of 4 bytes (SCF 225 Section 2.3.2.1)
int padding = ( 4 - (tl->length % 4) ) % 4;
int padding = get_tlv_padding(tl->length);
NFAPI_TRACE(NFAPI_TRACE_DEBUG, "TLV 0x%x with padding of %d bytes\n", tl->tag, padding);
if (padding != 0) {
memset(*ppWritePackedMsg,0,padding);
(*ppWritePackedMsg) += padding;
......@@ -869,3 +870,7 @@ const char *nfapi_error_code_to_str(nfapi_error_code_e value) {
return "UNKNOWN";
}
}
uint8_t get_tlv_padding(uint16_t tlv_length){
return ( 4 - (tlv_length % 4) ) % 4;
}
\ No newline at end of file
......@@ -718,7 +718,7 @@ static uint8_t pack_nr_config_request(void *msg, uint8_t **ppWritePackedMsg, uin
numTLVs++;
push16(NFAPI_NR_CONFIG_DL_K0_TAG, ppWritePackedMsg, end);
push16(6 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(5 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.dl_k0[0].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.dl_k0[1].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.dl_k0[2].value, ppWritePackedMsg, end);
......@@ -728,7 +728,7 @@ static uint8_t pack_nr_config_request(void *msg, uint8_t **ppWritePackedMsg, uin
numTLVs++;
push16(NFAPI_NR_CONFIG_DL_GRID_SIZE_TAG, ppWritePackedMsg, end);
push16(6 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(5 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.dl_grid_size[0].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.dl_grid_size[1].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.dl_grid_size[2].value, ppWritePackedMsg, end);
......@@ -750,7 +750,7 @@ static uint8_t pack_nr_config_request(void *msg, uint8_t **ppWritePackedMsg, uin
numTLVs++;
push16(NFAPI_NR_CONFIG_UL_K0_TAG, ppWritePackedMsg, end);
push16(6 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(5 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.ul_k0[0].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.ul_k0[1].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.ul_k0[2].value, ppWritePackedMsg, end);
......@@ -760,7 +760,7 @@ static uint8_t pack_nr_config_request(void *msg, uint8_t **ppWritePackedMsg, uin
numTLVs++;
push16(NFAPI_NR_CONFIG_UL_GRID_SIZE_TAG, ppWritePackedMsg, end);
push16(6 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(5 * sizeof(uint16_t), ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.ul_grid_size[0].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.ul_grid_size[1].value, ppWritePackedMsg, end);
push16(pNfapiMsg->carrier_config.ul_grid_size[2].value, ppWritePackedMsg, end);
......@@ -2017,25 +2017,21 @@ static uint8_t unpack_nr_config_request(uint8_t **ppReadPackedMsg, uint8_t *end,
for(int i = 0; i < 5 ; i++){
result = unpack_uint16_tlv_value(&pNfapiMsg->carrier_config.dl_grid_size[i],ppReadPackedMsg,end);
}
*ppReadPackedMsg+=2;
break;
case NFAPI_NR_CONFIG_DL_K0_TAG:
for(int i = 0; i < 5 ; i++){
result = unpack_uint16_tlv_value(&pNfapiMsg->carrier_config.dl_k0[i],ppReadPackedMsg,end);
}
*ppReadPackedMsg+=2;
break;
case NFAPI_NR_CONFIG_UL_GRID_SIZE_TAG:
for(int i = 0; i < 5 ; i++){
result = unpack_uint16_tlv_value(&pNfapiMsg->carrier_config.ul_grid_size[i],ppReadPackedMsg,end);
}
*ppReadPackedMsg+=2;
break;
case NFAPI_NR_CONFIG_UL_K0_TAG:
for(int i = 0; i < 5 ; i++){
result = unpack_uint16_tlv_value(&pNfapiMsg->carrier_config.ul_k0[i],ppReadPackedMsg,end);
}
*ppReadPackedMsg+=2;
break;
case NFAPI_NR_CONFIG_BEAM_ID_TAG:
pNfapiMsg->ssb_table.ssb_beam_id_list[config_beam_idx].beam_id.tl.tag = generic_tl.tag;
......@@ -2061,11 +2057,12 @@ static uint8_t unpack_nr_config_request(uint8_t **ppReadPackedMsg, uint8_t *end,
return 0;
// check if the length was right;
if(tl->length != (*ppReadPackedMsg - pStartOfValue))
if(tl->length != ( ((*ppReadPackedMsg)) - pStartOfValue))
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning tlv tag 0x%x length %d not equal to unpack %lu\n", tl->tag, tl->length, (*ppReadPackedMsg - pStartOfValue));
// Remove padding that ensures multiple of 4 bytes (SCF 225 Section 2.3.2.1)
int padding = ( 4 - (tl->length % 4) ) % 4;
int padding = get_tlv_padding(tl->length);
NFAPI_TRACE(NFAPI_TRACE_DEBUG,"TLV 0x%x length %d with padding of %d bytes\n", tl->tag,tl->length, padding);
if (padding != 0)
(*ppReadPackedMsg) += padding;
......@@ -2091,7 +2088,7 @@ static uint8_t unpack_nr_config_request(uint8_t **ppReadPackedMsg, uint8_t *end,
if((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length ;
int padding = ( 4 - (generic_tl.length % 4) ) % 4;
int padding = get_tlv_padding(generic_tl.length);
if (padding != 0) {
(*ppReadPackedMsg) += padding;
}
......@@ -2110,7 +2107,7 @@ static uint8_t unpack_nr_config_request(uint8_t **ppReadPackedMsg, uint8_t *end,
if((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length ;
int padding = ( 4 - (generic_tl.length % 4) ) % 4;
int padding = get_tlv_padding(generic_tl.length);
if (padding != 0) {
(*ppReadPackedMsg) += padding;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment