Skip to content

Commit 10873f9

Browse files
Alain Michaudholtmann
authored andcommitted
Bluetooth: centralize default value initialization.
This patch centralized the initialization of default parameters. This is required to allow clients to more easily customize the default system parameters. Signed-off-by: Alain Michaud <alainm@chromium.org> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 7e90de4 commit 10873f9

4 files changed

Lines changed: 40 additions & 21 deletions

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ struct hci_dev {
295295
__u8 le_scan_type;
296296
__u16 le_scan_interval;
297297
__u16 le_scan_window;
298+
__u16 le_scan_int_suspend;
299+
__u16 le_scan_window_suspend;
300+
__u16 le_scan_int_discovery;
301+
__u16 le_scan_window_discovery;
302+
__u16 le_scan_int_adv_monitor;
303+
__u16 le_scan_window_adv_monitor;
304+
__u16 le_scan_int_connect;
305+
__u16 le_scan_window_connect;
298306
__u16 le_conn_min_interval;
299307
__u16 le_conn_max_interval;
300308
__u16 le_conn_latency;
@@ -323,6 +331,16 @@ struct hci_dev {
323331
__u16 devid_product;
324332
__u16 devid_version;
325333

334+
__u8 def_page_scan_type;
335+
__u16 def_page_scan_int;
336+
__u16 def_page_scan_window;
337+
__u8 def_inq_scan_type;
338+
__u16 def_inq_scan_int;
339+
__u16 def_inq_scan_window;
340+
__u16 def_br_lsto;
341+
__u16 def_page_timeout;
342+
__u16 def_multi_adv_rotation_duration;
343+
326344
__u16 pkt_type;
327345
__u16 esco_type;
328346
__u16 link_policy;

‎net/bluetooth/hci_conn.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,8 @@ static void set_ext_conn_params(struct hci_conn *conn,
789789

790790
memset(p, 0, sizeof(*p));
791791

792-
/* Set window to be the same value as the interval to
793-
* enable continuous scanning.
794-
*/
795-
p->scan_interval = cpu_to_le16(hdev->le_scan_interval);
796-
p->scan_window = p->scan_interval;
792+
p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect);
793+
p->scan_window = cpu_to_le16(hdev->le_scan_window_connect);
797794
p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval);
798795
p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval);
799796
p->conn_latency = cpu_to_le16(conn->le_conn_latency);
@@ -875,11 +872,8 @@ static void hci_req_add_le_create_conn(struct hci_request *req,
875872

876873
memset(&cp, 0, sizeof(cp));
877874

878-
/* Set window to be the same value as the interval to enable
879-
* continuous scanning.
880-
*/
881-
cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
882-
cp.scan_window = cp.scan_interval;
875+
cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect);
876+
cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect);
883877

884878
bacpy(&cp.peer_addr, &conn->dst);
885879
cp.peer_addr_type = conn->dst_type;

‎net/bluetooth/hci_core.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,7 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
29822982
adv_instance->remaining_time = timeout;
29832983

29842984
if (duration == 0)
2985-
adv_instance->duration = HCI_DEFAULT_ADV_DURATION;
2985+
adv_instance->duration = hdev->def_multi_adv_rotation_duration;
29862986
else
29872987
adv_instance->duration = duration;
29882988

@@ -3400,6 +3400,12 @@ struct hci_dev *hci_alloc_dev(void)
34003400
hdev->le_adv_max_interval = 0x0800;
34013401
hdev->le_scan_interval = 0x0060;
34023402
hdev->le_scan_window = 0x0030;
3403+
hdev->le_scan_int_suspend = 0x0400;
3404+
hdev->le_scan_window_suspend = 0x0012;
3405+
hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT;
3406+
hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN;
3407+
hdev->le_scan_int_connect = 0x0060;
3408+
hdev->le_scan_window_connect = 0x0060;
34033409
hdev->le_conn_min_interval = 0x0018;
34043410
hdev->le_conn_max_interval = 0x0028;
34053411
hdev->le_conn_latency = 0x0000;
@@ -3415,6 +3421,7 @@ struct hci_dev *hci_alloc_dev(void)
34153421
hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M;
34163422
hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M;
34173423
hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES;
3424+
hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION;
34183425

34193426
hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT;
34203427
hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT;
@@ -3423,6 +3430,11 @@ struct hci_dev *hci_alloc_dev(void)
34233430
hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
34243431
hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE;
34253432

3433+
/* default 1.28 sec page scan */
3434+
hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD;
3435+
hdev->def_page_scan_int = 0x0800;
3436+
hdev->def_page_scan_window = 0x0012;
3437+
34263438
mutex_init(&hdev->lock);
34273439
mutex_init(&hdev->req_lock);
34283440

‎net/bluetooth/hci_request.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#define HCI_REQ_PEND 1
3535
#define HCI_REQ_CANCELED 2
3636

37-
#define LE_SUSPEND_SCAN_WINDOW 0x0012
38-
#define LE_SUSPEND_SCAN_INTERVAL 0x0400
39-
4037
void hci_req_init(struct hci_request *req, struct hci_dev *hdev)
4138
{
4239
skb_queue_head_init(&req->cmd_q);
@@ -366,13 +363,11 @@ void __hci_req_write_fast_connectable(struct hci_request *req, bool enable)
366363
/* 160 msec page scan interval */
367364
acp.interval = cpu_to_le16(0x0100);
368365
} else {
369-
type = PAGE_SCAN_TYPE_STANDARD; /* default */
370-
371-
/* default 1.28 sec page scan */
372-
acp.interval = cpu_to_le16(0x0800);
366+
type = hdev->def_page_scan_type;
367+
acp.interval = cpu_to_le16(hdev->def_page_scan_int);
373368
}
374369

375-
acp.window = cpu_to_le16(0x0012);
370+
acp.window = cpu_to_le16(hdev->def_page_scan_window);
376371

377372
if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval ||
378373
__cpu_to_le16(hdev->page_scan_window) != acp.window)
@@ -927,8 +922,8 @@ void hci_req_add_le_passive_scan(struct hci_request *req)
927922
filter_policy |= 0x02;
928923

929924
if (hdev->suspended) {
930-
window = LE_SUSPEND_SCAN_WINDOW;
931-
interval = LE_SUSPEND_SCAN_INTERVAL;
925+
window = hdev->le_scan_window_suspend;
926+
interval = hdev->le_scan_int_suspend;
932927
} else {
933928
window = hdev->le_scan_window;
934929
interval = hdev->le_scan_interval;

0 commit comments

Comments
 (0)