Bluetooth: Move memset closer to where it's needed
Subsystems (2)
PATCH v2 1/3 Bluetooth: Move memset closer to where it's needed
From: Johan Hedberg <[email protected]>
Minor fix to not do the memset until the variable it clears is actually used.
--- net/bluetooth/hci_conn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/hci_conn.c +2 -2
@@ -726,14 +726,14 @@ static void hci_req_add_le_create_conn(struct hci_request *req,struct hci_dev *hdev = conn->hdev;u8 own_addr_type; -memset (&cp,0 ,sizeof (cp)); -/* Update random address, but set require_privacy to false so * that we never connect with an non-resolvable address. */ if (hci_update_random_address (req, false, &own_addr_type))return ; +memset (&cp,0 ,sizeof (cp)); +/* Set window to be the same value as the interval to enable * continuous scanning. */
Signature · 1 line
2.5.0
PATCH v2 2/3 Bluetooth: Fix adding discoverable to adv instance flags
From: Johan Hedberg <[email protected]>
When lookup up the advertising instance flags for the default advertising instance (0) the discoverable flag should be filled in based on the HCI_DISCOVERABLE flag.
--- net/bluetooth/hci_request.c | 3 +++ 1 file changed, 3 insertions(+)
net/bluetooth/hci_request.c +3 -0
@@ -866,6 +866,9 @@ static u32 get_adv_instance_flags(struct hci_dev *hdev, u8 instance)if (hci_dev_test_flag (hdev,HCI_ADVERTISING_CONNECTABLE )) flags |=MGMT_ADV_FLAG_CONNECTABLE ; +if (hci_dev_test_flag (hdev,HCI_DISCOVERABLE )) + flags |=MGMT_ADV_FLAG_DISCOV ; +return flags; }
Signature · 1 line
2.5.0
PATCH v2 3/3 Bluetooth: Add support for limited privacy mode
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
Introduce a limited privacy mode indicated by value 0x02 to the mgmt Set Privacy command.
With value 0x02 the kernel will use privacy mode with a resolvable private address. In case the controller is bondable and discoverable the identity address will be used.
--- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_conn.c | 13 ++++++++++-- net/bluetooth/hci_request.c | 51 +++++++++++++++++++++++++++++++++++++++------ net/bluetooth/hci_request.h | 2 +- net/bluetooth/mgmt.c | 20 ++++++++++++++++-- 5 files changed, 76 insertions(+), 11 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -233,6 +233,7 @@ enum {HCI_SC_ENABLED ,HCI_SC_ONLY ,HCI_PRIVACY , +HCI_LIMITED_PRIVACY ,HCI_RPA_EXPIRED ,HCI_RPA_RESOLVING , HCI_HS_ENABLED,
net/bluetooth/hci_conn.c +11 -2
@@ -719,6 +719,13 @@ done:hci_dev_unlock (hdev); } +static bool conn_use_rpa (struct hci_conn *conn) +{ +struct hci_dev *hdev = conn->hdev; + +return hci_dev_test_flag (hdev,HCI_PRIVACY ); +} +static void hci_req_add_le_create_conn (struct hci_request *req,struct hci_conn *conn) {
@@ -729,7 +736,8 @@ static void hci_req_add_le_create_conn(struct hci_request *req,/* Update random address, but set require_privacy to false so * that we never connect with an non-resolvable address. */ -if (hci_update_random_address (req, false, &own_addr_type)) +if (hci_update_random_address (req, false,conn_use_rpa (conn), + &own_addr_type))return ;memset (&cp,0 ,sizeof (cp));
@@ -774,7 +782,8 @@ static void hci_req_directed_advertising(struct hci_request *req,/* Set require_privacy to false so that the remote device has a * chance of identifying us. */ -if (hci_update_random_address (req, false, &own_addr_type) <0 ) +if (hci_update_random_address (req, false,conn_use_rpa (conn), + &own_addr_type) <0 )return ;memset (&cp,0 ,sizeof (cp));
net/bluetooth/hci_request.c +45 -6
101 lines not on this page · raw message
net/bluetooth/hci_request.h +1 -1
@@ -89,7 +89,7 @@ static inline void hci_req_update_scan(struct hci_dev *hdev)void __hci_req_update_scan (struct hci_request *req);int hci_update_random_address (struct hci_request *req,bool require_privacy, -u8 *own_addr_type); +bool use_rpa,u8 *own_addr_type);int hci_abort_conn (struct hci_conn *conn,u8 reason); void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
net/bluetooth/mgmt.c +18 -2
@@ -1382,8 +1382,19 @@ static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data,if (err <0 ) goto unlock; -if (changed) +if (changed) { +/* In limited privacy mode the change of bondable mode +* may affect the local advertising address. +*/ +if (hdev_is_powered (hdev) && +hci_dev_test_flag (hdev,HCI_ADVERTISING ) && +hci_dev_test_flag (hdev,HCI_DISCOVERABLE ) && +hci_dev_test_flag (hdev,HCI_LIMITED_PRIVACY )) +queue_work (hdev->req_workqueue, + &hdev->discoverable_update); + err =new_settings (hdev, sk); + } unlock:hci_dev_unlock (hdev);
@@ -4423,7 +4434,7 @@ static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data,return mgmt_cmd_status (sk, hdev->id,MGMT_OP_SET_PRIVACY ,MGMT_STATUS_NOT_SUPPORTED ); -if (cp->privacy !=0x00 && cp->privacy !=0x01 ) +if (cp->privacy !=0x00 && cp->privacy !=0x01 && cp->privacy !=0x02 )return mgmt_cmd_status (sk, hdev->id,MGMT_OP_SET_PRIVACY ,MGMT_STATUS_INVALID_PARAMS );
@@ -4442,10 +4453,15 @@ static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, changed = !hci_dev_test_and_set_flag (hdev,HCI_PRIVACY );memcpy (hdev->irk, cp->irk,sizeof (hdev->irk));hci_dev_set_flag (hdev,HCI_RPA_EXPIRED ); +if (cp->privacy ==0x02 ) +hci_dev_set_flag (hdev,HCI_LIMITED_PRIVACY ); +else +hci_dev_clear_flag (hdev,HCI_LIMITED_PRIVACY ); }else { changed =hci_dev_test_and_clear_flag (hdev,HCI_PRIVACY );memset (hdev->irk,0 ,sizeof (hdev->irk));hci_dev_clear_flag (hdev,HCI_RPA_EXPIRED ); +hci_dev_clear_flag (hdev,HCI_LIMITED_PRIVACY ); } err =send_settings_rsp (sk,MGMT_OP_SET_PRIVACY , hdev);
Signature · 1 line
2.5.0
Marcel Holtmann
maintainerRe: [PATCH v2 3/3] Bluetooth: Add support for limited privacy mode
Hi Johan,
Quoted 7 lines
Introduce a limited privacy mode indicated by value
0x02to the mgmt Set Privacy command.With value
0x02the kernel will use privacy mode with a resolvable private address. In case the controller is bondable and discoverable the identity address will be used.
Quoted 8 lines
Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_conn.c | 13 ++++++++++-- net/bluetooth/hci_request.c | 51 +++++++++++++++++++++++++++++++++++++++------ net/bluetooth/hci_request.h | 2 +- net/bluetooth/mgmt.c | 20 ++++++++++++++++-- 5 files changed, 76 insertions(+), 11 deletions(-)
all 3 patches have been applied to bluetooth-next tree.
Regards
Marcel