Unpack SRS report TLV not expecting padding to be present

Add a function pullx32 to pull x amount of bytes into uint32_t
Change the unpacking to pull only the needed bytes, and skip over the padding, when not Aerial
Change SRS.indication dumping function to also print the report TLV contents
Change SRS.indication unitary test to fill the last 4 byte block of the report TLV according to the length, with padding
This commit is contained in:
Rúben Soares Silva
2025-03-31 10:15:08 +01:00
parent 1d479b2aa9
commit d9e3725a21
7 changed files with 83 additions and 13 deletions
@@ -36,6 +36,18 @@ uint8_t pull8(uint8_t **in, uint8_t *out, uint8_t *end);
uint8_t pulls8(uint8_t **in, int8_t *out, uint8_t *end);
uint8_t pull16(uint8_t **in, uint16_t *out, uint8_t *end);
uint8_t pulls16(uint8_t **in, int16_t *out, uint8_t *end);
/*! \brief Pull an arbitrary amount of bytes ( 0 to 4 ) into an uint32_t
* \param length the amount of bytes to pull
* \param in the buffer from where to pull the bytes
* \param out a pointer to the destination uint32_t
* \param end a pointer to the end of the buffer in
*
* This function is used to pull `length` amount of bytes from `in` into `out`.
* Used where pulling the full 32 bits would cause the `in` pointer to go over `end`.
* It's currently used to pull the last bytes of a payload where the buffer does not contain padding at the end.
*/
uint8_t pullx32(uint8_t length, uint8_t **in, uint32_t *out, uint8_t *end);
uint8_t pull32(uint8_t **in, uint32_t *out, uint8_t *end);
uint8_t pulls32(uint8_t **in, int32_t *out, uint8_t *end);
+25
View File
@@ -259,6 +259,31 @@ uint8_t pulls16(uint8_t **in, int16_t *out, uint8_t *end)
}
}
uint8_t pullx32(uint8_t length, uint8_t **in, uint32_t *out, uint8_t *end)
{
uint8_t *pIn = *in;
if (length > 4) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s Can't pull more than 4 bytes (%d) into a uint32_t\n", __FUNCTION__, length);
on_error();
return 0;
}
if ((end - pIn) >= length) {
for (int i = 0; i < length; i++) {
#ifdef FAPI_BYTE_ORDERING_BIG_ENDIAN
*out |= ((uint32_t)pIn[i] << (8 * i));
#else
*out = ((uint32_t)pIn[i] << (8 * (length - 1 - i)));
#endif
}
(*in) += length;
return length;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
uint8_t pull32(uint8_t **in, uint32_t *out, uint8_t *end)
{
uint8_t *pIn = *in;