Bluetooth: Add convenience function to check for pending power off
Subsystems (2)
PATCH 1/2 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/2 Bluetooth: Disable page scan if all whitelisted devices are connected
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 remove entries from the whitelist upon connection complete and to put them back into it upon disconnection complete. A new flag is also needed so that we know which devices need to be re-entered into the whitelist.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_event.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -551,6 +551,7 @@ enum {HCI_CONN_FIPS ,HCI_CONN_STK_ENCRYPT ,HCI_CONN_AUTH_INITIATOR , + HCI_CONN_WHITELIST, };static inline bool hci_conn_ssp_enabled (struct hci_conn *conn)
net/bluetooth/hci_event.c +32 -3
@@ -2071,6 +2071,20 @@ 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); + +if (!hci_bdaddr_list_del (&hdev->whitelist, &ev->bdaddr, +BDADDR_BREDR )) { +set_bit (HCI_CONN_WHITELIST , &conn->flags); + +if (list_empty (&hdev->whitelist) && + !test_bit (HCI_CONNECTABLE , + &hdev->dev_flags)) { +u8 scan =SCAN_DISABLED ; +hci_send_cmd (hdev, +HCI_OP_WRITE_SCAN_ENABLE , +1 , &scan); + } + } }/* Set packet type for incoming connection */
@@ -2247,9 +2261,24 @@ 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); + +if (test_bit (HCI_CONN_WHITELIST , &conn->flags)) { +bool was_empty =list_empty (&hdev->whitelist); + +hci_bdaddr_list_add (&hdev->whitelist, &conn->dst, +BDADDR_BREDR ); + +if (!test_bit (HCI_CONNECTABLE , &hdev->dev_flags) && + was_empty && !mgmt_powering_down (hdev)) { +u8 scan =SCAN_PAGE ; +hci_send_cmd (hdev,HCI_OP_WRITE_SCAN_ENABLE ,1 , + &scan); + } + } + } params =hci_conn_params_lookup (hdev, &conn->dst, conn->dst_type);if (params) {
Signature · 1 line
1.9.3