Skip to content

Commit

Permalink
bluetooth: Fix bug that data length is one byte larger
Browse files Browse the repository at this point in the history
The length field of advertising data includes 1 byte that
represent data type field.
So, decrement 1 byte in notifying to application.
  • Loading branch information
SPRESENSE committed Jun 26, 2023
1 parent cf015e8 commit c493f6d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sdk/modules/bluetooth/bluetooth_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,11 +1391,15 @@ int ble_parse_advertising_data(BLE_AD_TYPE target,

while (i < adv_len)
{
len = adv[i++];
/* For calculation of data length,
* decrease 1 byte that represents length of type.
*/

len = adv[i++] - 1;
type = adv[i++];
data = &adv[i];

if (len - 1 > BT_EIR_LEN)
if (len > BT_EIR_LEN)
{
/* Invalid advertising data(invalid length information) */

Expand All @@ -1406,12 +1410,12 @@ int ble_parse_advertising_data(BLE_AD_TYPE target,
{
eir->len = len,
eir->type = type,
memcpy(eir->data, data, len - 1); /* len include type and data */
memcpy(eir->data, data, len);
ret = BT_SUCCESS;
break;
}

i += len - 1;
i += len;
}

return ret;
Expand Down

0 comments on commit c493f6d

Please sign in to comment.