Skip to content

Commit 9bf9f4b

Browse files
dwinkler2Johan Hedberg
authored andcommitted
Bluetooth: Use intervals and tx power from mgmt cmds
This patch takes the min/max intervals and tx power optionally provided in mgmt interface, stores them in the advertisement struct, and uses them when configuring the hci requests. While tx power is not used if extended advertising is unavailable, software rotation will use the min and max advertising intervals specified by the client. This change is validated manually by ensuring the min/max intervals are propagated to the controller on both hatch (extended advertising) and kukui (no extended advertising) chromebooks, and that tx power is propagated correctly on hatch. These tests are performed with multiple advertisements simultaneously. Reviewed-by: Sonny Sasaka <[email protected]> Signed-off-by: Daniel Winkler <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Johan Hedberg <[email protected]>
1 parent 1241057 commit 9bf9f4b

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ struct adv_info {
230230
__u16 scan_rsp_len;
231231
__u8 scan_rsp_data[HCI_MAX_AD_LENGTH];
232232
__s8 tx_power;
233+
__u32 min_interval;
234+
__u32 max_interval;
233235
bdaddr_t random_addr;
234236
bool rpa_expired;
235237
struct delayed_work rpa_expired_cb;
@@ -1303,7 +1305,8 @@ struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance);
13031305
int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
13041306
u16 adv_data_len, u8 *adv_data,
13051307
u16 scan_rsp_len, u8 *scan_rsp_data,
1306-
u16 timeout, u16 duration);
1308+
u16 timeout, u16 duration, s8 tx_power,
1309+
u32 min_interval, u32 max_interval);
13071310
int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
13081311
u16 adv_data_len, u8 *adv_data,
13091312
u16 scan_rsp_len, u8 *scan_rsp_data);

net/bluetooth/hci_core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,8 @@ static void adv_instance_rpa_expired(struct work_struct *work)
29512951
int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
29522952
u16 adv_data_len, u8 *adv_data,
29532953
u16 scan_rsp_len, u8 *scan_rsp_data,
2954-
u16 timeout, u16 duration)
2954+
u16 timeout, u16 duration, s8 tx_power,
2955+
u32 min_interval, u32 max_interval)
29552956
{
29562957
struct adv_info *adv_instance;
29572958

@@ -2979,6 +2980,9 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
29792980
adv_instance->flags = flags;
29802981
adv_instance->adv_data_len = adv_data_len;
29812982
adv_instance->scan_rsp_len = scan_rsp_len;
2983+
adv_instance->min_interval = min_interval;
2984+
adv_instance->max_interval = max_interval;
2985+
adv_instance->tx_power = tx_power;
29822986

29832987
if (adv_data_len)
29842988
memcpy(adv_instance->adv_data, adv_data, adv_data_len);
@@ -2995,8 +2999,6 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
29952999
else
29963000
adv_instance->duration = duration;
29973001

2998-
adv_instance->tx_power = HCI_TX_POWER_INVALID;
2999-
30003002
INIT_DELAYED_WORK(&adv_instance->rpa_expired_cb,
30013003
adv_instance_rpa_expired);
30023004

net/bluetooth/hci_request.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,13 +1488,15 @@ static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable)
14881488
void __hci_req_enable_advertising(struct hci_request *req)
14891489
{
14901490
struct hci_dev *hdev = req->hdev;
1491+
struct adv_info *adv_instance;
14911492
struct hci_cp_le_set_adv_param cp;
14921493
u8 own_addr_type, enable = 0x01;
14931494
bool connectable;
14941495
u16 adv_min_interval, adv_max_interval;
14951496
u32 flags;
14961497

14971498
flags = get_adv_instance_flags(hdev, hdev->cur_adv_instance);
1499+
adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance);
14981500

14991501
/* If the "connectable" instance flag was not set, then choose between
15001502
* ADV_IND and ADV_NONCONN_IND based on the global connectable setting.
@@ -1526,11 +1528,16 @@ void __hci_req_enable_advertising(struct hci_request *req)
15261528

15271529
memset(&cp, 0, sizeof(cp));
15281530

1529-
if (connectable) {
1530-
cp.type = LE_ADV_IND;
1531-
1531+
if (adv_instance) {
1532+
adv_min_interval = adv_instance->min_interval;
1533+
adv_max_interval = adv_instance->max_interval;
1534+
} else {
15321535
adv_min_interval = hdev->le_adv_min_interval;
15331536
adv_max_interval = hdev->le_adv_max_interval;
1537+
}
1538+
1539+
if (connectable) {
1540+
cp.type = LE_ADV_IND;
15341541
} else {
15351542
if (adv_cur_instance_is_scannable(hdev))
15361543
cp.type = LE_ADV_SCAN_IND;
@@ -1541,9 +1548,6 @@ void __hci_req_enable_advertising(struct hci_request *req)
15411548
hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) {
15421549
adv_min_interval = DISCOV_LE_FAST_ADV_INT_MIN;
15431550
adv_max_interval = DISCOV_LE_FAST_ADV_INT_MAX;
1544-
} else {
1545-
adv_min_interval = hdev->le_adv_min_interval;
1546-
adv_max_interval = hdev->le_adv_max_interval;
15471551
}
15481552
}
15491553

@@ -2119,9 +2123,15 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)
21192123

21202124
memset(&cp, 0, sizeof(cp));
21212125

2122-
/* In ext adv set param interval is 3 octets */
2123-
hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval);
2124-
hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval);
2126+
if (adv_instance) {
2127+
hci_cpu_to_le24(adv_instance->min_interval, cp.min_interval);
2128+
hci_cpu_to_le24(adv_instance->max_interval, cp.max_interval);
2129+
cp.tx_power = adv_instance->tx_power;
2130+
} else {
2131+
hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval);
2132+
hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval);
2133+
cp.tx_power = HCI_ADV_TX_POWER_NO_PREFERENCE;
2134+
}
21252135

21262136
secondary_adv = (flags & MGMT_ADV_FLAG_SEC_MASK);
21272137

@@ -2144,7 +2154,6 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)
21442154

21452155
cp.own_addr_type = own_addr_type;
21462156
cp.channel_map = hdev->le_adv_channel_map;
2147-
cp.tx_power = 127;
21482157
cp.handle = instance;
21492158

21502159
if (flags & MGMT_ADV_FLAG_SEC_2M) {

net/bluetooth/mgmt.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7533,7 +7533,10 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev,
75337533
cp->adv_data_len, cp->data,
75347534
cp->scan_rsp_len,
75357535
cp->data + cp->adv_data_len,
7536-
timeout, duration);
7536+
timeout, duration,
7537+
HCI_ADV_TX_POWER_NO_PREFERENCE,
7538+
hdev->le_adv_min_interval,
7539+
hdev->le_adv_max_interval);
75377540
if (err < 0) {
75387541
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING,
75397542
MGMT_STATUS_FAILED);
@@ -7741,7 +7744,8 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev,
77417744

77427745
/* Create advertising instance with no advertising or response data */
77437746
err = hci_add_adv_instance(hdev, cp->instance, flags,
7744-
0, NULL, 0, NULL, timeout, duration);
7747+
0, NULL, 0, NULL, timeout, duration,
7748+
tx_power, min_interval, max_interval);
77457749

77467750
if (err < 0) {
77477751
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS,

0 commit comments

Comments
 (0)