Commit 37adf701 authored by Daniel Winkler's avatar Daniel Winkler Committed by Marcel Holtmann

Bluetooth: Add per-instance adv disable/remove

Add functionality to disable and remove advertising instances,
and use that functionality in MGMT add/remove advertising calls.

Currently, advertising is globally-disabled, i.e. all instances are
disabled together, even if hardware offloading is available. This
patch adds functionality to disable and remove individual adv
instances, solving two issues:

1. On new advertisement registration, a global disable was done, and
then only the new instance was enabled. This meant only the newest
instance was actually enabled.

2. On advertisement removal, the structure was removed, but the instance
was never disabled or removed, which is incorrect with hardware offload
support.
Signed-off-by: default avatarDaniel Winkler <danielwinkler@google.com>
Reviewed-by: default avatarShyh-In Hwang <josephsih@chromium.org>
Reviewed-by: default avatarAlain Michaud <alainm@chromium.org>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 629b49c8
...@@ -931,7 +931,7 @@ static void hci_req_directed_advertising(struct hci_request *req, ...@@ -931,7 +931,7 @@ static void hci_req_directed_advertising(struct hci_request *req,
* So it is required to remove adv set for handle 0x00. since we use * So it is required to remove adv set for handle 0x00. since we use
* instance 0 for directed adv. * instance 0 for directed adv.
*/ */
hci_req_add(req, HCI_OP_LE_REMOVE_ADV_SET, sizeof(cp.handle), &cp.handle); __hci_req_remove_ext_adv_instance(req, cp.handle);
hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp); hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp);
......
...@@ -1179,13 +1179,8 @@ static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev) ...@@ -1179,13 +1179,8 @@ static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev)
void __hci_req_disable_advertising(struct hci_request *req) void __hci_req_disable_advertising(struct hci_request *req)
{ {
if (ext_adv_capable(req->hdev)) { if (ext_adv_capable(req->hdev)) {
struct hci_cp_le_set_ext_adv_enable cp; __hci_req_disable_ext_adv_instance(req, 0x00);
cp.enable = 0x00;
/* Disable all sets since we only support one set at the moment */
cp.num_of_sets = 0x00;
hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_ENABLE, sizeof(cp), &cp);
} else { } else {
u8 enable = 0x00; u8 enable = 0x00;
...@@ -1950,13 +1945,59 @@ int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance) ...@@ -1950,13 +1945,59 @@ int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance)
return 0; return 0;
} }
int __hci_req_disable_ext_adv_instance(struct hci_request *req, u8 instance)
{
struct hci_dev *hdev = req->hdev;
struct hci_cp_le_set_ext_adv_enable *cp;
struct hci_cp_ext_adv_set *adv_set;
u8 data[sizeof(*cp) + sizeof(*adv_set) * 1];
u8 req_size;
/* If request specifies an instance that doesn't exist, fail */
if (instance > 0 && !hci_find_adv_instance(hdev, instance))
return -EINVAL;
memset(data, 0, sizeof(data));
cp = (void *)data;
adv_set = (void *)cp->data;
/* Instance 0x00 indicates all advertising instances will be disabled */
cp->num_of_sets = !!instance;
cp->enable = 0x00;
adv_set->handle = instance;
req_size = sizeof(*cp) + sizeof(*adv_set) * cp->num_of_sets;
hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_ENABLE, req_size, data);
return 0;
}
int __hci_req_remove_ext_adv_instance(struct hci_request *req, u8 instance)
{
struct hci_dev *hdev = req->hdev;
/* If request specifies an instance that doesn't exist, fail */
if (instance > 0 && !hci_find_adv_instance(hdev, instance))
return -EINVAL;
hci_req_add(req, HCI_OP_LE_REMOVE_ADV_SET, sizeof(instance), &instance);
return 0;
}
int __hci_req_start_ext_adv(struct hci_request *req, u8 instance) int __hci_req_start_ext_adv(struct hci_request *req, u8 instance)
{ {
struct hci_dev *hdev = req->hdev; struct hci_dev *hdev = req->hdev;
struct adv_info *adv_instance = hci_find_adv_instance(hdev, instance);
int err; int err;
if (hci_dev_test_flag(hdev, HCI_LE_ADV)) /* If instance isn't pending, the chip knows about it, and it's safe to
__hci_req_disable_advertising(req); * disable
*/
if (adv_instance && !adv_instance->pending)
__hci_req_disable_ext_adv_instance(req, instance);
err = __hci_req_setup_ext_adv_instance(req, instance); err = __hci_req_setup_ext_adv_instance(req, instance);
if (err < 0) if (err < 0)
...@@ -2104,7 +2145,7 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, ...@@ -2104,7 +2145,7 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk,
hci_dev_test_flag(hdev, HCI_ADVERTISING)) hci_dev_test_flag(hdev, HCI_ADVERTISING))
return; return;
if (next_instance) if (next_instance && !ext_adv_capable(hdev))
__hci_req_schedule_adv_instance(req, next_instance->instance, __hci_req_schedule_adv_instance(req, next_instance->instance,
false); false);
} }
......
...@@ -86,6 +86,8 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, ...@@ -86,6 +86,8 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk,
int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance); int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance);
int __hci_req_start_ext_adv(struct hci_request *req, u8 instance); int __hci_req_start_ext_adv(struct hci_request *req, u8 instance);
int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance); int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance);
int __hci_req_disable_ext_adv_instance(struct hci_request *req, u8 instance);
int __hci_req_remove_ext_adv_instance(struct hci_request *req, u8 instance);
void __hci_req_clear_ext_adv_sets(struct hci_request *req); void __hci_req_clear_ext_adv_sets(struct hci_request *req);
int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
bool use_rpa, struct adv_info *adv_instance, bool use_rpa, struct adv_info *adv_instance,
......
...@@ -7504,6 +7504,12 @@ static int remove_advertising(struct sock *sk, struct hci_dev *hdev, ...@@ -7504,6 +7504,12 @@ static int remove_advertising(struct sock *sk, struct hci_dev *hdev,
hci_req_init(&req, hdev); hci_req_init(&req, hdev);
/* If we use extended advertising, instance is disabled and removed */
if (ext_adv_capable(hdev)) {
__hci_req_disable_ext_adv_instance(&req, cp->instance);
__hci_req_remove_ext_adv_instance(&req, cp->instance);
}
hci_req_clear_adv_instance(hdev, sk, &req, cp->instance, true); hci_req_clear_adv_instance(hdev, sk, &req, cp->instance, true);
if (list_empty(&hdev->adv_instances)) if (list_empty(&hdev->adv_instances))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment