Bluetooth: Add convenience function to check for pending power off
Subsystems (2)
PATCH 1/3 Bluetooth: Add convenience function to check for pending power off
From: Johan Hedberg <[email protected]>
There are several situations where we're interested in knowing whether we're currently in the process of powering off an adapter. This patch adds a convenience function for the purpose and makes it public since we'll soon need to access it from hci_event.c as well.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/mgmt.c | 52 +++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 24 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -1351,6 +1351,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,void mgmt_remote_name (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,s8 rssi,u8 *name,u8 name_len);void mgmt_discovering (struct hci_dev *hdev,u8 discovering); +bool mgmt_powering_down (struct hci_dev *hdev);void mgmt_new_ltk (struct hci_dev *hdev,struct smp_ltk *key,bool persistent);void mgmt_new_irk (struct hci_dev *hdev,struct smp_irk *irk); void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
net/bluetooth/mgmt.c +28 -24
72 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 2/3 Bluetooth: Create unified helper function for updating page scan
From: Johan Hedberg <[email protected]>
Similar to our hci_update_background_scan() function we can simplify a lot of code by creating a unified helper function for doing page scan updates. This patch adds such a function to hci_core.c and updates all the relevant places to use it.
--- include/net/bluetooth/hci_core.h | 5 +++ net/bluetooth/hci_core.c | 31 +++++++++++++++++ net/bluetooth/mgmt.c | 72 +++++++--------------------------------- 3 files changed, 48 insertions(+), 60 deletions(-)
include/net/bluetooth/hci_core.h +5 -0
@@ -968,6 +968,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn);#define lmp_host_le_capable (dev) (!!((dev)->features[1][0] & LMP_HOST_LE))#define lmp_host_le_br_capable (dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR)) +#define hdev_is_powered (hdev) (test_bit(HCI_UP, &hdev->flags) && \ + !test_bit(HCI_AUTO_OFF, &hdev->dev_flags)) +/* ----- HCI protocols ----- */ #define HCI_PROTO_DEFER 0x01
@@ -1256,6 +1259,8 @@ bool hci_req_pending(struct hci_dev *hdev);void hci_req_add_le_scan_disable (struct hci_request *req);void hci_req_add_le_passive_scan (struct hci_request *req); +void hci_update_page_scan (struct hci_dev *hdev,struct hci_request *req); +struct sk_buff *__hci_cmd_sync (struct hci_dev *hdev,u16 opcode,u32 plen,const void *param,u32 timeout); struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
net/bluetooth/hci_core.c +31 -0
@@ -5686,3 +5686,34 @@ void hci_update_background_scan(struct hci_dev *hdev)if (err)BT_ERR ("Failed to run HCI request: err %d" , err); } + +void hci_update_page_scan (struct hci_dev *hdev,struct hci_request *req) +{ +u8 scan; + +if (!test_bit (HCI_BREDR_ENABLED , &hdev->dev_flags)) +return ; + +if (!hdev_is_powered (hdev)) +return ; + +if (mgmt_powering_down (hdev)) +return ; + +if (test_bit (HCI_CONNECTABLE , &hdev->dev_flags) || + !list_empty (&hdev->whitelist)) + scan =SCAN_PAGE ; +else + scan =SCAN_DISABLED ; + +if (test_bit (HCI_PSCAN , &hdev->flags) == !!(scan &SCAN_PAGE )) +return ; + +if (test_bit (HCI_DISCOVERABLE , &hdev->dev_flags)) + scan |=SCAN_INQUIRY ; + +if (req) +hci_req_add (req,HCI_OP_WRITE_SCAN_ENABLE ,1 , &scan); +else +hci_send_cmd (hdev,HCI_OP_WRITE_SCAN_ENABLE ,1 , &scan); +}
net/bluetooth/mgmt.c +12 -60
151 lines not on this page · raw message
Signature · 1 line
1.9.3
Marcel Holtmann
maintainerRe: [PATCH 2/3] Bluetooth: Create unified helper function for updating page scan
Hi Johan,
Quoted 11 lines
Similar to our
hci_update_background_scan()function we can simplify a lot of code by creating a unified helper function for doing page scan updates. This patch adds such a function tohci_core.cand updates all the relevant places to use it.Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci_core.h | 5 +++ net/bluetooth/hci_core.c | 31 +++++++++++++++++ net/bluetooth/mgmt.c | 72 +++++++--------------------------------- 3 files changed, 48 insertions(+), 60 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
PATCH 3/3 Bluetooth: Disable page scan if all whitelisted devices are connected
In reply to [email protected]From: Johan Hedberg <[email protected]>
When we're not connectable and all whitelisted (BR/EDR) devices are connected it doesn't make sense to keep page scan enabled. This patch adds code to check for any disconnected whitelist devices and if there are none take the appropriate action in the hci_update_page_scan() function to disable page scan.
--- net/bluetooth/hci_core.c | 20 +++++++++++++++++++- net/bluetooth/hci_event.c | 11 ++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-)
net/bluetooth/hci_core.c +19 -1
@@ -5687,6 +5687,24 @@ void hci_update_background_scan(struct hci_dev *hdev)BT_ERR ("Failed to run HCI request: err %d" , err); } +static bool disconnected_whitelist_entries (struct hci_dev *hdev) +{ +struct bdaddr_list *b; + +list_for_each_entry (b, &hdev->whitelist, list) { +struct hci_conn *conn; + + conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &b->bdaddr); +if (!conn) +return true; + +if (conn->state !=BT_CONNECTED && conn->state !=BT_CONFIG ) +return true; + } + +return false; +} +void hci_update_page_scan (struct hci_dev *hdev,struct hci_request *req) {u8 scan;
@@ -5701,7 +5719,7 @@ void hci_update_page_scan(struct hci_dev *hdev, struct hci_request *req)return ;if (test_bit (HCI_CONNECTABLE , &hdev->dev_flags) || - !list_empty (&hdev->whitelist)) +disconnected_whitelist_entries (hdev)) scan =SCAN_PAGE ;else scan =SCAN_DISABLED ;
net/bluetooth/hci_event.c +8 -3
@@ -2071,6 +2071,8 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) cp.handle = ev->handle;hci_send_cmd (hdev,HCI_OP_READ_REMOTE_FEATURES ,sizeof (cp), &cp); + +hci_update_page_scan (hdev,NULL ); }/* Set packet type for incoming connection */
@@ -2247,9 +2249,12 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)mgmt_device_disconnected (hdev, &conn->dst, conn->type, conn->dst_type, reason, mgmt_connected); -if (conn->type ==ACL_LINK && -test_bit (HCI_CONN_FLUSH_KEY , &conn->flags)) -hci_remove_link_key (hdev, &conn->dst); +if (conn->type ==ACL_LINK ) { +if (test_bit (HCI_CONN_FLUSH_KEY , &conn->flags)) +hci_remove_link_key (hdev, &conn->dst); + +hci_update_page_scan (hdev,NULL ); + } params =hci_conn_params_lookup (hdev, &conn->dst, conn->dst_type);if (params) {
Signature · 1 line
1.9.3
Marcel Holtmann
maintainerRe: [PATCH 3/3] Bluetooth: Disable page scan if all whitelisted devices are connected
Hi Johan,
Quoted 11 lines
When we're not connectable and all whitelisted (BR/EDR) devices are connected it doesn't make sense to keep page scan enabled. This patch adds code to check for any disconnected whitelist devices and if there are none take the appropriate action in the
hci_update_page_scan()function to disable page scan.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/hci_core.c| 20 +++++++++++++++++++-net/bluetooth/hci_event.c| 11 ++++++++---2 files changed, 27 insertions(+), 4 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerHi Johan,
Quoted 10 lines
There are several situations where we're interested in knowing whether we're currently in the process of powering off an adapter. This patch adds a convenience function for the purpose and makes it public since we'll soon need to access it from
hci_event.cas well.Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci_core.h| 1 +net/bluetooth/mgmt.c| 52 +++++++++++++++++++++-------------------2 files changed, 29 insertions(+), 24 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerHi Johan,
Quoted 10 lines
There are several situations where we're interested in knowing whether we're currently in the process of powering off an adapter. This patch adds a convenience function for the purpose and makes it public since we'll soon need to access it from
hci_event.cas well.Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci_core.h| 1 +net/bluetooth/mgmt.c| 52 +++++++++++++++++++++-------------------2 files changed, 29 insertions(+), 24 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel