aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2015-11-25 09:15:43 -0500
committerMarcel Holtmann <marcel@holtmann.org>2015-12-09 18:51:48 -0500
commitbf943cbf76ecd3b9838a80d5e08777b0f4ccc665 (patch)
tree0dff5d4878c851de4942fbbd22173515246e6750 /net
parentb1a8917c9bcbf42113dfacb6492228e094c96862 (diff)
Bluetooth: Move fast connectable code to hci_request.c
We'll soon need this both in hci_request.c and mgmt.c so move it to hci_request.c as a generic helper. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_request.c35
-rw-r--r--net/bluetooth/hci_request.h1
-rw-r--r--net/bluetooth/mgmt.c43
3 files changed, 40 insertions, 39 deletions
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 030a1bb66ef5..0abd83ddd4fb 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -349,6 +349,41 @@ void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
349 hci_req_add_ev(req, opcode, plen, param, 0); 349 hci_req_add_ev(req, opcode, plen, param, 0);
350} 350}
351 351
352void __hci_req_write_fast_connectable(struct hci_request *req, bool enable)
353{
354 struct hci_dev *hdev = req->hdev;
355 struct hci_cp_write_page_scan_activity acp;
356 u8 type;
357
358 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
359 return;
360
361 if (hdev->hci_ver < BLUETOOTH_VER_1_2)
362 return;
363
364 if (enable) {
365 type = PAGE_SCAN_TYPE_INTERLACED;
366
367 /* 160 msec page scan interval */
368 acp.interval = cpu_to_le16(0x0100);
369 } else {
370 type = PAGE_SCAN_TYPE_STANDARD; /* default */
371
372 /* default 1.28 sec page scan */
373 acp.interval = cpu_to_le16(0x0800);
374 }
375
376 acp.window = cpu_to_le16(0x0012);
377
378 if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval ||
379 __cpu_to_le16(hdev->page_scan_window) != acp.window)
380 hci_req_add(req, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY,
381 sizeof(acp), &acp);
382
383 if (hdev->page_scan_type != type)
384 hci_req_add(req, HCI_OP_WRITE_PAGE_SCAN_TYPE, 1, &type);
385}
386
352/* This function controls the background scanning based on hdev->pend_le_conns 387/* This function controls the background scanning based on hdev->pend_le_conns
353 * list. If there are pending LE connection we start the background scanning, 388 * list. If there are pending LE connection we start the background scanning,
354 * otherwise we stop it. 389 * otherwise we stop it.
diff --git a/net/bluetooth/hci_request.h b/net/bluetooth/hci_request.h
index 5af40395afa8..d3dd24deca74 100644
--- a/net/bluetooth/hci_request.h
+++ b/net/bluetooth/hci_request.h
@@ -55,6 +55,7 @@ void hci_req_sync_cancel(struct hci_dev *hdev, int err);
55struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen, 55struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen,
56 const void *param); 56 const void *param);
57 57
58void __hci_req_write_fast_connectable(struct hci_request *req, bool enable);
58void __hci_req_update_name(struct hci_request *req); 59void __hci_req_update_name(struct hci_request *req);
59void __hci_req_update_eir(struct hci_request *req); 60void __hci_req_update_eir(struct hci_request *req);
60 61
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index fa5dc67a800a..0a7e6f4de383 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1254,41 +1254,6 @@ failed:
1254 return err; 1254 return err;
1255} 1255}
1256 1256
1257static void write_fast_connectable(struct hci_request *req, bool enable)
1258{
1259 struct hci_dev *hdev = req->hdev;
1260 struct hci_cp_write_page_scan_activity acp;
1261 u8 type;
1262
1263 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
1264 return;
1265
1266 if (hdev->hci_ver < BLUETOOTH_VER_1_2)
1267 return;
1268
1269 if (enable) {
1270 type = PAGE_SCAN_TYPE_INTERLACED;
1271
1272 /* 160 msec page scan interval */
1273 acp.interval = cpu_to_le16(0x0100);
1274 } else {
1275 type = PAGE_SCAN_TYPE_STANDARD; /* default */
1276
1277 /* default 1.28 sec page scan */
1278 acp.interval = cpu_to_le16(0x0800);
1279 }
1280
1281 acp.window = cpu_to_le16(0x0012);
1282
1283 if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval ||
1284 __cpu_to_le16(hdev->page_scan_window) != acp.window)
1285 hci_req_add(req, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY,
1286 sizeof(acp), &acp);
1287
1288 if (hdev->page_scan_type != type)
1289 hci_req_add(req, HCI_OP_WRITE_PAGE_SCAN_TYPE, 1, &type);
1290}
1291
1292void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status) 1257void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status)
1293{ 1258{
1294 struct mgmt_pending_cmd *cmd; 1259 struct mgmt_pending_cmd *cmd;
@@ -4094,7 +4059,7 @@ static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev,
4094 4059
4095 hci_req_init(&req, hdev); 4060 hci_req_init(&req, hdev);
4096 4061
4097 write_fast_connectable(&req, cp->val); 4062 __hci_req_write_fast_connectable(&req, cp->val);
4098 4063
4099 err = hci_req_run(&req, fast_connectable_complete); 4064 err = hci_req_run(&req, fast_connectable_complete);
4100 if (err < 0) { 4065 if (err < 0) {
@@ -4236,7 +4201,7 @@ static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
4236 4201
4237 hci_req_init(&req, hdev); 4202 hci_req_init(&req, hdev);
4238 4203
4239 write_fast_connectable(&req, false); 4204 __hci_req_write_fast_connectable(&req, false);
4240 __hci_req_update_scan(&req); 4205 __hci_req_update_scan(&req);
4241 4206
4242 /* Since only the advertising data flags will change, there 4207 /* Since only the advertising data flags will change, there
@@ -6566,9 +6531,9 @@ static int powered_update_hci(struct hci_dev *hdev)
6566 6531
6567 if (lmp_bredr_capable(hdev)) { 6532 if (lmp_bredr_capable(hdev)) {
6568 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) 6533 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE))
6569 write_fast_connectable(&req, true); 6534 __hci_req_write_fast_connectable(&req, true);
6570 else 6535 else
6571 write_fast_connectable(&req, false); 6536 __hci_req_write_fast_connectable(&req, false);
6572 __hci_req_update_scan(&req); 6537 __hci_req_update_scan(&req);
6573 __hci_req_update_class(&req); 6538 __hci_req_update_class(&req);
6574 __hci_req_update_name(&req); 6539 __hci_req_update_name(&req);