Skip to content

Commit

Permalink
Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1
Browse files Browse the repository at this point in the history
If hdev->le_num_of_adv_sets is set to 1 it means that only handle 0x00
can be used, but since the MGMT interface instances start from 1
(instance 0 means all instances in case of MGMT_OP_REMOVE_ADVERTISING)
the code needs to map the instance to handle otherwise users will not be
able to advertise as instance 1 would attempt to use handle 0x01.

Fixes: 1d0fac2 ("Bluetooth: Use controller sets when available")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Luiz Augusto von Dentz committed May 14, 2024
1 parent 36b1c9c commit e77f43d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ struct adv_info {
bool periodic;
__u8 mesh;
__u8 instance;
__u8 handle;
__u32 flags;
__u16 timeout;
__u16 remaining_time;
Expand Down
9 changes: 9 additions & 0 deletions net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,15 @@ struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,

adv->pending = true;
adv->instance = instance;

/* If controller support only one set and the instance is set to
* 1 then there is no option other than using handle 0x00.
*/
if (hdev->le_num_of_adv_sets == 1 && instance == 1)
adv->handle = 0x00;
else
adv->handle = instance;

list_add(&adv->list, &hdev->adv_instances);
hdev->adv_instance_cnt++;
}
Expand Down
17 changes: 8 additions & 9 deletions net/bluetooth/hci_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,10 @@ static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance)
struct hci_cp_ext_adv_set *set;
u8 data[sizeof(*cp) + sizeof(*set) * 1];
u8 size;
struct adv_info *adv = NULL;

/* If request specifies an instance that doesn't exist, fail */
if (instance > 0) {
struct adv_info *adv;

adv = hci_find_adv_instance(hdev, instance);
if (!adv)
return -EINVAL;
Expand All @@ -1066,7 +1065,7 @@ static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance)
cp->num_of_sets = !!instance;
cp->enable = 0x00;

set->handle = instance;
set->handle = adv ? adv->handle : instance;

size = sizeof(*cp) + sizeof(*set) * cp->num_of_sets;

Expand Down Expand Up @@ -1249,7 +1248,7 @@ static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance)

len = eir_create_scan_rsp(hdev, instance, pdu->data);

pdu->handle = instance;
pdu->handle = adv ? adv->handle : instance;
pdu->length = len;
pdu->operation = LE_SET_ADV_DATA_OP_COMPLETE;
pdu->frag_pref = LE_SET_ADV_DATA_NO_FRAG;
Expand Down Expand Up @@ -1331,7 +1330,7 @@ int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance)

memset(set, 0, sizeof(*set));

set->handle = instance;
set->handle = adv ? adv->handle : instance;

/* Set duration per instance since controller is responsible for
* scheduling it.
Expand Down Expand Up @@ -1410,18 +1409,18 @@ static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance)
DEFINE_FLEX(struct hci_cp_le_set_per_adv_data, pdu, data, length,
HCI_MAX_PER_AD_LENGTH);
u8 len;
struct adv_info *adv = NULL;

if (instance) {
struct adv_info *adv = hci_find_adv_instance(hdev, instance);

adv = hci_find_adv_instance(hdev, instance);
if (!adv || !adv->periodic)
return 0;
}

len = eir_create_per_adv_data(hdev, instance, pdu->data);

pdu->length = len;
pdu->handle = instance;
pdu->handle = adv ? adv->handle : instance;
pdu->operation = LE_SET_ADV_DATA_OP_COMPLETE;

return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_DATA,
Expand Down Expand Up @@ -1734,7 +1733,7 @@ static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance)
len = eir_create_adv_data(hdev, instance, pdu->data);

pdu->length = len;
pdu->handle = instance;
pdu->handle = adv ? adv->handle : instance;
pdu->operation = LE_SET_ADV_DATA_OP_COMPLETE;
pdu->frag_pref = LE_SET_ADV_DATA_NO_FRAG;

Expand Down

0 comments on commit e77f43d

Please sign in to comment.