Skip to content

Commit

Permalink
nimble/host: Set length correctly in periodic_set_adv_data
Browse files Browse the repository at this point in the history
   This change sets length field only if data is non NULL, else sets
   length to zero.
  • Loading branch information
rahult-github authored and sjanc committed Oct 3, 2023
1 parent 080e6d3 commit 05dd20c
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3711,41 +3711,55 @@ ble_gap_periodic_adv_set(uint8_t instance, struct os_mbuf **data)
static uint8_t buf[sizeof(struct ble_hci_le_set_periodic_adv_data_cp) +
MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)];
struct ble_hci_le_set_periodic_adv_data_cp *cmd = (void *) buf;
uint16_t len = OS_MBUF_PKTLEN(*data);
uint16_t len = 0;
uint16_t opcode;

if (*data) {
len = OS_MBUF_PKTLEN(*data);
}

opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_PERIODIC_ADV_DATA);

cmd->adv_handle = instance;
cmd->operation = BLE_HCI_LE_SET_DATA_OPER_COMPLETE;
cmd->adv_data_len = len;
os_mbuf_copydata(*data, 0, len, cmd->adv_data);

os_mbuf_adj(*data, len);
*data = os_mbuf_trim_front(*data);
if (len) {
os_mbuf_copydata(*data, 0, len, cmd->adv_data);

os_mbuf_adj(*data, len);
*data = os_mbuf_trim_front(*data);
}

return ble_hs_hci_cmd_tx(opcode, cmd, sizeof(*cmd) + cmd->adv_data_len,
NULL, 0);
#else
static uint8_t buf[sizeof(struct ble_hci_le_set_periodic_adv_data_cp) +
BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN];
struct ble_hci_le_set_periodic_adv_data_cp *cmd = (void *) buf;
uint16_t len = OS_MBUF_PKTLEN(*data);
uint16_t len = 0;
uint16_t opcode;
uint8_t op;
int rc;

if (*data) {
len = OS_MBUF_PKTLEN(*data);
}

opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_PERIODIC_ADV_DATA);
cmd->adv_handle = instance;

/* Complete data */
if (len <= BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN) {
cmd->operation = BLE_HCI_LE_SET_DATA_OPER_COMPLETE;
cmd->adv_data_len = len;
os_mbuf_copydata(*data, 0, len, cmd->adv_data);

os_mbuf_adj(*data, len);
*data = os_mbuf_trim_front(*data);
if (len) {
os_mbuf_copydata(*data, 0, len, cmd->adv_data);

os_mbuf_adj(*data, len);
*data = os_mbuf_trim_front(*data);
}

return ble_hs_hci_cmd_tx(opcode, cmd, sizeof(*cmd) + cmd->adv_data_len,
NULL, 0);
Expand Down

0 comments on commit 05dd20c

Please sign in to comment.