Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply
Subsystems (2)
PATCH 1/4 Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply
From: Johan Hedberg <[email protected]>
The code was correctly calling _unlock at the end of the function but there was no actual _lock call anywhere.
--- net/bluetooth/mgmt.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
net/bluetooth/mgmt.c +2 -0
@@ -1230,6 +1230,8 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data,if (!hdev)return cmd_status (sk, index, mgmt_op,ENODEV ); +hci_dev_lock_bh (hdev); +if (!test_bit (HCI_UP , &hdev->flags)) { err =cmd_status (sk, index, mgmt_op,ENETDOWN ); goto failed;
Signature · 1 line
1.7.4.1
PATCH 2/4 Bluetooth: Add define for the maximum name length on HCI level
From: Johan Hedberg <[email protected]>
This patch adds a clear define for the maximum device name length in HCI messages and thereby avoids magic numbers in the code.
--- include/net/bluetooth/hci.h | 8 +++++--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_event.c | 4 ++-- net/bluetooth/hci_sysfs.c | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-)
include/net/bluetooth/hci.h +5 -3
@@ -535,15 +535,17 @@ struct hci_cp_delete_stored_link_key {__u8 delete_all; } __packed; +#define HCI_MAX_NAME_LENGTH 248 +#define HCI_OP_WRITE_LOCAL_NAME 0x0c13struct hci_cp_write_local_name { -__u8 name[248 ]; +__u8 name[HCI_MAX_NAME_LENGTH ]; } __packed;#define HCI_OP_READ_LOCAL_NAME 0x0c14struct hci_rp_read_local_name {__u8 status; -__u8 name[248 ]; +__u8 name[HCI_MAX_NAME_LENGTH ]; } __packed;#define HCI_OP_WRITE_CA_TIMEOUT 0x0c16
@@ -745,7 +747,7 @@ struct hci_ev_auth_complete {struct hci_ev_remote_name {__u8 status;bdaddr_t bdaddr; -__u8 name[248 ]; +__u8 name[HCI_MAX_NAME_LENGTH ]; } __packed;#define HCI_EV_ENCRYPT_CHANGE 0x08
include/net/bluetooth/hci_core.h +1 -1
@@ -94,7 +94,7 @@ struct hci_dev {__u8 bus;__u8 dev_type;bdaddr_t bdaddr; -__u8 dev_name[248 ]; +__u8 dev_name[HCI_MAX_NAME_LENGTH ];__u8 dev_class[3 ];__u8 major_class;__u8 minor_class;
net/bluetooth/hci_event.c +2 -2
@@ -200,7 +200,7 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)if (!sent)return ; -memcpy (hdev->dev_name, sent,248 ); +memcpy (hdev->dev_name, sent,HCI_MAX_NAME_LENGTH ); }static void hci_cc_read_local_name (struct hci_dev *hdev,struct sk_buff *skb)
@@ -212,7 +212,7 @@ static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)if (rp->status)return ; -memcpy (hdev->dev_name, rp->name,248 ); +memcpy (hdev->dev_name, rp->name,HCI_MAX_NAME_LENGTH ); }static void hci_cc_write_auth_enable (struct hci_dev *hdev,struct sk_buff *skb)
net/bluetooth/hci_sysfs.c +3 -3
@@ -216,13 +216,13 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, charstatic ssize_t show_name (struct device *dev,struct device_attribute *attr,char *buf) {struct hci_dev *hdev =dev_get_drvdata (dev); -char name[249 ]; +char name[HCI_MAX_NAME_LENGTH +1 ];int i; -for (i =0 ; i <248 ; i++) +for (i =0 ; i <HCI_MAX_NAME_LENGTH ; i++) name[i] = hdev->dev_name[i]; - name[248 ] ='\0' ; + name[HCI_MAX_NAME_LENGTH ] ='\0' ;return sprintf (buf,"%s\n" , name); }
Signature · 1 line
1.7.4.1
Re: [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level
Hi Johan,
Quoted 5 lines · * [email protected] <[email protected]> [2011-03-16 14:29:35 +0200]:
From: Johan Hedberg <[email protected]>
This patch adds a clear define for the maximum device name length in HCI messages and thereby avoids magic numbers in the code.
Quoted 7 lines
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci.h | 8 +++++--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_event.c | 4 ++-- net/bluetooth/hci_sysfs.c | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-)
This one is also applied. Thanks.
Signature · 2 lines
Gustavo F. Padovan http://profusion.mobi
PATCH 3/4 Bluetooth: mgmt: Add local name information to read_info reply
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch adds the name of the adapter to the reply of the read_info management command.
The management messages reserve 249 bytes for the name instead of 248 (like in the HCI spec) so that there is always a guarantee that it is nul-terminated. That way it can safely be passed onto string manipulation functions.
--- include/net/bluetooth/mgmt.h | 5 +++++ net/bluetooth/mgmt.c | 4 ++++ 2 files changed, 9 insertions(+), 0 deletions(-)
include/net/bluetooth/mgmt.h +5 -0
@@ -41,6 +41,10 @@ struct mgmt_rp_read_index_list {__le16 index[0 ]; } __packed; +/* Reserve one extra byte for names in management messages so that they +* are always guaranteed to be nul-terminated */ +#define MGMT_MAX_NAME_LENGTH (HCI_MAX_NAME_LENGTH + 1) +#define MGMT_OP_READ_INFO 0x0004struct mgmt_rp_read_info {__u8 type;
@@ -55,6 +59,7 @@ struct mgmt_rp_read_info {__u16 manufacturer;__u8 hci_ver;__u16 hci_rev; +__u8 name[MGMT_MAX_NAME_LENGTH ]; } __packed;struct mgmt_mode {
net/bluetooth/mgmt.c +4 -0
@@ -183,6 +183,8 @@ static int read_controller_info(struct sock *sk, u16 index)set_bit (HCI_MGMT , &hdev->flags); +memset (&rp,0 ,sizeof (rp)); + rp.type = hdev->dev_type; rp.powered =test_bit (HCI_UP , &hdev->flags);
@@ -204,6 +206,8 @@ static int read_controller_info(struct sock *sk, u16 index) rp.hci_ver = hdev->hci_ver;put_unaligned_le16 (hdev->hci_rev, &rp.hci_rev); +memcpy (rp.name, hdev->dev_name,sizeof (hdev->dev_name)); +hci_dev_unlock_bh (hdev);hci_dev_put (hdev);
Signature · 1 line
1.7.4.1
PATCH 4/4 Bluetooth: mgmt: Add support for setting the local name
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch adds a new set_local_name management command as well as a local_name_changed management event. With these user space can both change the local name as well as monitor changes to it by others.
--- include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/mgmt.h | 10 +++++ net/bluetooth/hci_event.c | 9 +++-- net/bluetooth/mgmt.c | 75 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -767,6 +767,7 @@ int mgmt_user_confirm_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status);int mgmt_user_confirm_neg_reply_complete (u16 index,bdaddr_t *bdaddr,u8 status);int mgmt_auth_failed (u16 index,bdaddr_t *bdaddr,u8 status); +int mgmt_set_local_name_complete (u16 index,u8 *name,u8 status);/* HCI info for socket */ #define hci_pi (sk) ((struct hci_pinfo *) sk)
include/net/bluetooth/mgmt.h +10 -0
@@ -172,6 +172,11 @@ struct mgmt_rp_user_confirm_reply {#define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x0016 +#define MGMT_OP_SET_LOCAL_NAME 0x0017 +struct mgmt_cp_set_local_name { +__u8 name[MGMT_MAX_NAME_LENGTH ]; +} __packed; +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {__le16 opcode;
@@ -239,3 +244,8 @@ struct mgmt_ev_auth_failed {bdaddr_t bdaddr;__u8 status; } __packed; + +#define MGMT_EV_LOCAL_NAME_CHANGED 0x0011 +struct mgmt_ev_local_name_changed { +__u8 name[MGMT_MAX_NAME_LENGTH ]; +} __packed;
net/bluetooth/hci_event.c +6 -3
@@ -193,13 +193,16 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)BT_DBG ("%s status 0x%x" , hdev->name, status); -if (status) -return ; - sent =hci_sent_cmd_data (hdev,HCI_OP_WRITE_LOCAL_NAME );if (!sent)return ; +if (test_bit (HCI_MGMT , &hdev->flags)) +mgmt_set_local_name_complete (hdev->id, sent, status); + +if (status) +return ; +memcpy (hdev->dev_name, sent,HCI_MAX_NAME_LENGTH ); }
net/bluetooth/mgmt.c +75 -0
90 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [PATCH 4/4] Bluetooth: mgmt: Add support for setting the local name
Hi Johan,
Quoted 6 lines · * [email protected] <[email protected]> [2011-03-16 14:29:37 +0200]:
From: Johan Hedberg <[email protected]>
This patch adds a new
set_local_namemanagement command as well as alocal_name_changedmanagement event. With these user space can both change the local name as well as monitor changes to it by others.
Quoted 7 lines
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/mgmt.h | 10 +++++ net/bluetooth/hci_event.c | 9 +++-- net/bluetooth/mgmt.c | 75 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-)
Patch 3 and 4 applied. Thanks.
Signature · 2 lines
Gustavo F. Padovan http://profusion.mobi
Gustavo F. Padovan
AppliedHi Johan,
Quoted 9 lines · * [email protected] <[email protected]> [2011-03-16 14:29:34 +0200]:
From: Johan Hedberg <[email protected]>
The code was correctly calling
_unlockat the end of the function but there was no actual_lockcall anywhere.Signed-off-by Johan Hedberg <[email protected]>--- net/bluetooth/mgmt.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
Applied, thanks.
Signature · 2 lines
Gustavo F. Padovan http://profusion.mobi