Bluetooth: mgmt: Make Set Link Security callable while powered off
Subsystems (2)
PATCH 1/3 Bluetooth: mgmt: Make Set Link Security callable while powered off
From: Johan Hedberg <[email protected]>
This patch makes it possible to change the Link Security setting while powered off and have it automatically enabled when powering on a device. To track the desired state once powered on a new HCI_LINK_SECURITY flag is added.
--- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 6 ++++++ net/bluetooth/mgmt.c | 33 ++++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -98,6 +98,7 @@ enum {HCI_HS_ENABLED ,HCI_CONNECTABLE ,HCI_DISCOVERABLE , + HCI_LINK_SECURITY, };/* HCI ioctl defines */
net/bluetooth/hci_event.c +6 -0
@@ -594,6 +594,12 @@ static void hci_setup(struct hci_dev *hdev) sizeof(cp), &cp); } +if (test_bit (HCI_LINK_SECURITY , &hdev->dev_flags)) { +u8 enable =1 ; +hci_send_cmd (hdev,HCI_OP_WRITE_AUTH_ENABLE , +sizeof (enable), &enable); + } +if (hdev->features[4 ] &LMP_LE )hci_set_le_support (hdev); }
net/bluetooth/mgmt.c +28 -5
@@ -410,7 +410,7 @@ static u32 get_current_settings(struct hci_dev *hdev)if (hdev->host_features[0 ] &LMP_HOST_LE ) settings |=MGMT_SETTING_LE ; -if (test_bit (HCI_AUTH , &hdev->flags)) +if (test_bit (HCI_LINK_SECURITY , &hdev->dev_flags)) settings |=MGMT_SETTING_LINK_SECURITY ;if (test_bit (HCI_SSP_ENABLED , &hdev->dev_flags))
@@ -1067,8 +1067,21 @@ static int set_link_security(struct sock *sk, u16 index, void *data, u16 len)hci_dev_lock (hdev);if (!hdev_is_powered (hdev)) { - err =cmd_status (sk, index,MGMT_OP_SET_LINK_SECURITY , -MGMT_STATUS_NOT_POWERED ); +bool changed = false; + +if (!!cp->val !=test_bit (HCI_LINK_SECURITY , + &hdev->dev_flags)) { +change_bit (HCI_LINK_SECURITY , &hdev->dev_flags); + changed = true; + } + + err =send_settings_rsp (sk,MGMT_OP_SET_LINK_SECURITY , hdev); +if (err <0 ) + goto failed; + +if (changed) + err =new_settings (hdev, sk); + goto failed; }
@@ -3338,7 +3351,8 @@ int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,int mgmt_auth_enable_complete (struct hci_dev *hdev,u8 status) {struct cmd_lookup match = {NULL , hdev }; -int err; +bool changed = false; +int err =0 ;if (status) {u8 mgmt_err =mgmt_status (status);
@@ -3347,10 +3361,19 @@ int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status)return 0 ; } +if (test_bit (HCI_AUTH , &hdev->flags)) { +if (!test_and_set_bit (HCI_LINK_SECURITY , &hdev->dev_flags)) + changed = true; + }else { +if (test_and_clear_bit (HCI_LINK_SECURITY , &hdev->dev_flags)) + changed = true; + } +mgmt_pending_foreach (MGMT_OP_SET_LINK_SECURITY , hdev, settings_rsp, &match); - err =new_settings (hdev, match.sk); +if (changed) + err =new_settings (hdev, match.sk);if (match.sk)sock_put (match.sk);
Signature · 1 line
1.7.9
PATCH 2/3 Bluetooth: Remove unneeded hci_cc_read_ssp_mode function
From: Johan Hedberg <[email protected]>
The kernel has no need to track the hci_read_ssp_mode command since it has the hci_sent_cmd_data function to check what value was set when hci_write_ssp_mode completes.
--- net/bluetooth/hci_event.c | 19 ------------------- 1 files changed, 0 insertions(+), 19 deletions(-)
net/bluetooth/hci_event.c +0 -19
@@ -420,21 +420,6 @@ static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)hci_req_complete (hdev,HCI_OP_HOST_BUFFER_SIZE , status); } -static void hci_cc_read_ssp_mode (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_rp_read_ssp_mode *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%x" , hdev->name, rp->status); - -if (rp->status) -return ; - -if (rp->mode) -set_bit (HCI_SSP_ENABLED , &hdev->dev_flags); -else -clear_bit (HCI_SSP_ENABLED , &hdev->dev_flags); -} -static void hci_cc_write_ssp_mode (struct hci_dev *hdev,struct sk_buff *skb) {__u8 status = *((__u8 *) skb->data);
@@ -2201,10 +2186,6 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skhci_cc_host_buffer_size (hdev, skb);break ; -case HCI_OP_READ_SSP_MODE : -hci_cc_read_ssp_mode (hdev, skb); -break ; -case HCI_OP_WRITE_SSP_MODE :hci_cc_write_ssp_mode (hdev, skb);break ;
Signature · 1 line
1.7.9
PATCH 3/3 Bluetooth: mgmt: Make Set SSP command callable while powered off
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch makes it possible to enable SSP through mgmt even when powered off. The setting will then get automatically actiated when powering on.
--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_event.c | 20 +++++++--------- net/bluetooth/mgmt.c | 44 +++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 20 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
@@ -1006,7 +1006,7 @@ int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,int mgmt_auth_failed (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 status);int mgmt_auth_enable_complete (struct hci_dev *hdev,u8 status); -int mgmt_ssp_enable_complete (struct hci_dev *hdev,u8 status); +int mgmt_ssp_enable_complete (struct hci_dev *hdev,u8 enable,u8 status);int mgmt_set_local_name_complete (struct hci_dev *hdev,u8 *name,u8 status);int mgmt_read_local_oob_data_reply_complete (struct hci_dev *hdev,u8 *hash,u8 *randomizer,u8 status);
net/bluetooth/hci_event.c +9 -11
@@ -427,21 +427,18 @@ static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)BT_DBG ("%s status 0x%x" , hdev->name, status); -if (status) - goto done; - sent =hci_sent_cmd_data (hdev,HCI_OP_WRITE_SSP_MODE );if (!sent)return ; -if (*((u8 *) sent)) -set_bit (HCI_SSP_ENABLED , &hdev->dev_flags); -else -clear_bit (HCI_SSP_ENABLED , &hdev->dev_flags); - -done:if (test_bit (HCI_MGMT , &hdev->dev_flags)) -mgmt_ssp_enable_complete (hdev, status); +mgmt_ssp_enable_complete (hdev, *((u8 *) sent), status); +else if (!status) { +if (*((u8 *) sent)) +set_bit (HCI_SSP_ENABLED , &hdev->dev_flags); +else +clear_bit (HCI_SSP_ENABLED , &hdev->dev_flags); + } }static u8 hci_get_inquiry_mode (struct hci_dev *hdev)
@@ -560,7 +557,8 @@ static void hci_setup(struct hci_dev *hdev)if (hdev->hci_ver >BLUETOOTH_VER_1_1 )hci_send_cmd (hdev,HCI_OP_READ_LOCAL_COMMANDS ,0 ,NULL ); -if (hdev->features[6 ] &LMP_SIMPLE_PAIR ) { +if (hdev->features[6 ] &LMP_SIMPLE_PAIR && +test_bit (HCI_SSP_ENABLED , &hdev->dev_flags)) {u8 mode =0x01 ;hci_send_cmd (hdev,HCI_OP_WRITE_SSP_MODE ,sizeof (mode), &mode); }
net/bluetooth/mgmt.c +36 -8
74 lines not on this page · raw message
Signature · 1 line
1.7.9
Hi Johan,
Quoted 11 lines
This patch makes it possible to change the Link Security setting while powered off and have it automatically enabled when powering on a device. To track the desired state once powered on a new
HCI_LINK_SECURITYflag is added.Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 6 ++++++ net/bluetooth/mgmt.c | 33 ++++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-)
Regards
Marcel
Re: [PATCH 2/3] Bluetooth: Remove unneeded hci_cc_read_ssp_mode function
In reply to [email protected]Hi Johan,
Quoted 8 lines
The kernel has no need to track the
hci_read_ssp_modecommand since it has thehci_sent_cmd_datafunction to check what value was set whenhci_write_ssp_modecompletes.Signed-off-by Johan Hedberg <[email protected]>--- net/bluetooth/hci_event.c | 19 ------------------- 1 files changed, 0 insertions(+), 19 deletions(-)
Regards
Marcel
Re: [PATCH 3/3] Bluetooth: mgmt: Make Set SSP command callable while powered off
In reply to [email protected]Hi Johan,
Quoted 10 lines
This patch makes it possible to enable SSP through mgmt even when powered off. The setting will then get automatically actiated when powering on.
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_event.c | 20 +++++++--------- net/bluetooth/mgmt.c | 44 +++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 20 deletions(-)
Regards
Marcel