Skip to content

Commit 4f5fc3b

Browse files
Vudentzgregkh
authored andcommitted
Bluetooth: Fix Set Extended (Scan Response) Data
[ Upstream commit c9ed0a7 ] These command do have variable length and the length can go up to 251, so this changes the struct to not use a fixed size and then when creating the PDU only the actual length of the data send to the controller. Fixes: a0fb372 ("Bluetooth: Use Set ext adv/scan rsp data if controller supports") Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c5fedfc commit 4f5fc3b

3 files changed

Lines changed: 37 additions & 28 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,13 +1773,15 @@ struct hci_cp_ext_adv_set {
17731773
__u8 max_events;
17741774
} __packed;
17751775

1776+
#define HCI_MAX_EXT_AD_LENGTH 251
1777+
17761778
#define HCI_OP_LE_SET_EXT_ADV_DATA 0x2037
17771779
struct hci_cp_le_set_ext_adv_data {
17781780
__u8 handle;
17791781
__u8 operation;
17801782
__u8 frag_pref;
17811783
__u8 length;
1782-
__u8 data[HCI_MAX_AD_LENGTH];
1784+
__u8 data[];
17831785
} __packed;
17841786

17851787
#define HCI_OP_LE_SET_EXT_SCAN_RSP_DATA 0x2038
@@ -1788,7 +1790,7 @@ struct hci_cp_le_set_ext_scan_rsp_data {
17881790
__u8 operation;
17891791
__u8 frag_pref;
17901792
__u8 length;
1791-
__u8 data[HCI_MAX_AD_LENGTH];
1793+
__u8 data[];
17921794
} __packed;
17931795

17941796
#define LE_SET_ADV_DATA_OP_COMPLETE 0x03

‎include/net/bluetooth/hci_core.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ struct adv_info {
226226
__u16 remaining_time;
227227
__u16 duration;
228228
__u16 adv_data_len;
229-
__u8 adv_data[HCI_MAX_AD_LENGTH];
229+
__u8 adv_data[HCI_MAX_EXT_AD_LENGTH];
230230
__u16 scan_rsp_len;
231-
__u8 scan_rsp_data[HCI_MAX_AD_LENGTH];
231+
__u8 scan_rsp_data[HCI_MAX_EXT_AD_LENGTH];
232232
__s8 tx_power;
233233
bdaddr_t random_addr;
234234
bool rpa_expired;
@@ -523,9 +523,9 @@ struct hci_dev {
523523
DECLARE_BITMAP(dev_flags, __HCI_NUM_FLAGS);
524524

525525
__s8 adv_tx_power;
526-
__u8 adv_data[HCI_MAX_AD_LENGTH];
526+
__u8 adv_data[HCI_MAX_EXT_AD_LENGTH];
527527
__u8 adv_data_len;
528-
__u8 scan_rsp_data[HCI_MAX_AD_LENGTH];
528+
__u8 scan_rsp_data[HCI_MAX_EXT_AD_LENGTH];
529529
__u8 scan_rsp_data_len;
530530

531531
struct list_head adv_instances;

‎net/bluetooth/hci_request.c‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,30 +1596,33 @@ void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance)
15961596
return;
15971597

15981598
if (ext_adv_capable(hdev)) {
1599-
struct hci_cp_le_set_ext_scan_rsp_data cp;
1599+
struct {
1600+
struct hci_cp_le_set_ext_scan_rsp_data cp;
1601+
u8 data[HCI_MAX_EXT_AD_LENGTH];
1602+
} pdu;
16001603

1601-
memset(&cp, 0, sizeof(cp));
1604+
memset(&pdu, 0, sizeof(pdu));
16021605

16031606
if (instance)
16041607
len = create_instance_scan_rsp_data(hdev, instance,
1605-
cp.data);
1608+
pdu.data);
16061609
else
1607-
len = create_default_scan_rsp_data(hdev, cp.data);
1610+
len = create_default_scan_rsp_data(hdev, pdu.data);
16081611

16091612
if (hdev->scan_rsp_data_len == len &&
1610-
!memcmp(cp.data, hdev->scan_rsp_data, len))
1613+
!memcmp(pdu.data, hdev->scan_rsp_data, len))
16111614
return;
16121615

1613-
memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data));
1616+
memcpy(hdev->scan_rsp_data, pdu.data, len);
16141617
hdev->scan_rsp_data_len = len;
16151618

1616-
cp.handle = instance;
1617-
cp.length = len;
1618-
cp.operation = LE_SET_ADV_DATA_OP_COMPLETE;
1619-
cp.frag_pref = LE_SET_ADV_DATA_NO_FRAG;
1619+
pdu.cp.handle = instance;
1620+
pdu.cp.length = len;
1621+
pdu.cp.operation = LE_SET_ADV_DATA_OP_COMPLETE;
1622+
pdu.cp.frag_pref = LE_SET_ADV_DATA_NO_FRAG;
16201623

1621-
hci_req_add(req, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA, sizeof(cp),
1622-
&cp);
1624+
hci_req_add(req, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA,
1625+
sizeof(pdu.cp) + len, &pdu.cp);
16231626
} else {
16241627
struct hci_cp_le_set_scan_rsp_data cp;
16251628

@@ -1742,26 +1745,30 @@ void __hci_req_update_adv_data(struct hci_request *req, u8 instance)
17421745
return;
17431746

17441747
if (ext_adv_capable(hdev)) {
1745-
struct hci_cp_le_set_ext_adv_data cp;
1748+
struct {
1749+
struct hci_cp_le_set_ext_adv_data cp;
1750+
u8 data[HCI_MAX_EXT_AD_LENGTH];
1751+
} pdu;
17461752

1747-
memset(&cp, 0, sizeof(cp));
1753+
memset(&pdu, 0, sizeof(pdu));
17481754

1749-
len = create_instance_adv_data(hdev, instance, cp.data);
1755+
len = create_instance_adv_data(hdev, instance, pdu.data);
17501756

17511757
/* There's nothing to do if the data hasn't changed */
17521758
if (hdev->adv_data_len == len &&
1753-
memcmp(cp.data, hdev->adv_data, len) == 0)
1759+
memcmp(pdu.data, hdev->adv_data, len) == 0)
17541760
return;
17551761

1756-
memcpy(hdev->adv_data, cp.data, sizeof(cp.data));
1762+
memcpy(hdev->adv_data, pdu.data, len);
17571763
hdev->adv_data_len = len;
17581764

1759-
cp.length = len;
1760-
cp.handle = instance;
1761-
cp.operation = LE_SET_ADV_DATA_OP_COMPLETE;
1762-
cp.frag_pref = LE_SET_ADV_DATA_NO_FRAG;
1765+
pdu.cp.length = len;
1766+
pdu.cp.handle = instance;
1767+
pdu.cp.operation = LE_SET_ADV_DATA_OP_COMPLETE;
1768+
pdu.cp.frag_pref = LE_SET_ADV_DATA_NO_FRAG;
17631769

1764-
hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_DATA, sizeof(cp), &cp);
1770+
hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_DATA,
1771+
sizeof(pdu.cp) + len, &pdu.cp);
17651772
} else {
17661773
struct hci_cp_le_set_adv_data cp;
17671774

0 commit comments

Comments
 (0)