* [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply
@ 2011-03-16 12:29 johan.hedberg
2011-03-16 12:29 ` [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level johan.hedberg
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: johan.hedberg @ 2011-03-16 12:29 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
The code was correctly calling _unlock at the end of the function but
there was no actual _lock call anywhere.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
net/bluetooth/mgmt.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 0054c74..4476d8e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -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;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level
2011-03-16 12:29 [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply johan.hedberg
@ 2011-03-16 12:29 ` johan.hedberg
2011-03-17 18:30 ` Gustavo F. Padovan
2011-03-16 12:29 ` [PATCH 3/4] Bluetooth: mgmt: Add local name information to read_info reply johan.hedberg
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: johan.hedberg @ 2011-03-16 12:29 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
This patch adds a clear define for the maximum device name length in HCI
messages and thereby avoids magic numbers in the code.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
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(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ec6acf2..1cd031c 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -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 0x0c13
struct hci_cp_write_local_name {
- __u8 name[248];
+ __u8 name[HCI_MAX_NAME_LENGTH];
} __packed;
#define HCI_OP_READ_LOCAL_NAME 0x0c14
struct 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
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 441dadb..9aabb14 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 3fbfa50..91ef526 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -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)
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 3c838a6..e544216 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -216,13 +216,13 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, char
static 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);
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] Bluetooth: mgmt: Add local name information to read_info reply
2011-03-16 12:29 [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply johan.hedberg
2011-03-16 12:29 ` [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level johan.hedberg
@ 2011-03-16 12:29 ` johan.hedberg
2011-03-16 12:29 ` [PATCH 4/4] Bluetooth: mgmt: Add support for setting the local name johan.hedberg
2011-03-17 18:29 ` [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply Gustavo F. Padovan
3 siblings, 0 replies; 7+ messages in thread
From: johan.hedberg @ 2011-03-16 12:29 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
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.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
include/net/bluetooth/mgmt.h | 5 +++++
net/bluetooth/mgmt.c | 4 ++++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 5fabfa8..7d0749b 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -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 0x0004
struct 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 {
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 4476d8e..67529c8 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -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);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] Bluetooth: mgmt: Add support for setting the local name
2011-03-16 12:29 [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply johan.hedberg
2011-03-16 12:29 ` [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level johan.hedberg
2011-03-16 12:29 ` [PATCH 3/4] Bluetooth: mgmt: Add local name information to read_info reply johan.hedberg
@ 2011-03-16 12:29 ` johan.hedberg
2011-03-17 18:38 ` Gustavo F. Padovan
2011-03-17 18:29 ` [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply Gustavo F. Padovan
3 siblings, 1 reply; 7+ messages in thread
From: johan.hedberg @ 2011-03-16 12:29 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
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.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
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(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 9aabb14..3912c7a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 7d0749b..89e7c82 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -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 0x0001
struct 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;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 91ef526..0def3e1 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -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);
}
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 67529c8..98988c8 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1258,6 +1258,45 @@ failed:
return err;
}
+static int set_local_name(struct sock *sk, u16 index, unsigned char *data,
+ u16 len)
+{
+ struct mgmt_cp_set_local_name *mgmt_cp = (void *) data;
+ struct hci_cp_write_local_name hci_cp;
+ struct hci_dev *hdev;
+ struct pending_cmd *cmd;
+ int err;
+
+ BT_DBG("");
+
+ if (len != sizeof(*mgmt_cp))
+ return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME, EINVAL);
+
+ hdev = hci_dev_get(index);
+ if (!hdev)
+ return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME, ENODEV);
+
+ hci_dev_lock_bh(hdev);
+
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, index, data, len);
+ if (!cmd) {
+ err = -ENOMEM;
+ goto failed;
+ }
+
+ memcpy(hci_cp.name, mgmt_cp->name, sizeof(hci_cp.name));
+ err = hci_send_cmd(hdev, HCI_OP_WRITE_LOCAL_NAME, sizeof(hci_cp),
+ &hci_cp);
+ if (err < 0)
+ mgmt_pending_remove(cmd);
+
+failed:
+ hci_dev_unlock_bh(hdev);
+ hci_dev_put(hdev);
+
+ return err;
+}
+
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
{
unsigned char *buf;
@@ -1353,6 +1392,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
case MGMT_OP_USER_CONFIRM_NEG_REPLY:
err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len, 0);
break;
+ case MGMT_OP_SET_LOCAL_NAME:
+ err = set_local_name(sk, index, buf + sizeof(*hdr), len);
+ break;
default:
BT_DBG("Unknown op %u", opcode);
err = cmd_status(sk, index, opcode, 0x01);
@@ -1649,3 +1691,36 @@ int mgmt_auth_failed(u16 index, bdaddr_t *bdaddr, u8 status)
return mgmt_event(MGMT_EV_AUTH_FAILED, index, &ev, sizeof(ev), NULL);
}
+
+int mgmt_set_local_name_complete(u16 index, u8 *name, u8 status)
+{
+ struct pending_cmd *cmd;
+ struct mgmt_cp_set_local_name ev;
+ int err;
+
+ memset(&ev, 0, sizeof(ev));
+ memcpy(ev.name, name, HCI_MAX_NAME_LENGTH);
+
+ cmd = mgmt_pending_find(MGMT_OP_SET_LOCAL_NAME, index);
+ if (!cmd)
+ goto send_event;
+
+ if (status) {
+ err = cmd_status(cmd->sk, index, MGMT_OP_SET_LOCAL_NAME, EIO);
+ goto failed;
+ }
+
+ err = cmd_complete(cmd->sk, index, MGMT_OP_SET_LOCAL_NAME, &ev,
+ sizeof(ev));
+ if (err < 0)
+ goto failed;
+
+send_event:
+ err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, index, &ev, sizeof(ev),
+ cmd ? cmd->sk : NULL);
+
+failed:
+ if (cmd)
+ mgmt_pending_remove(cmd);
+ return err;
+}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply
2011-03-16 12:29 [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply johan.hedberg
` (2 preceding siblings ...)
2011-03-16 12:29 ` [PATCH 4/4] Bluetooth: mgmt: Add support for setting the local name johan.hedberg
@ 2011-03-17 18:29 ` Gustavo F. Padovan
3 siblings, 0 replies; 7+ messages in thread
From: Gustavo F. Padovan @ 2011-03-17 18:29 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
* johan.hedberg@gmail.com <johan.hedberg@gmail.com> [2011-03-16 14:29:34 +0200]:
> From: Johan Hedberg <johan.hedberg@nokia.com>
>
> The code was correctly calling _unlock at the end of the function but
> there was no actual _lock call anywhere.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
> ---
> net/bluetooth/mgmt.c | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
Applied, thanks.
--
Gustavo F. Padovan
http://profusion.mobi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level
2011-03-16 12:29 ` [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level johan.hedberg
@ 2011-03-17 18:30 ` Gustavo F. Padovan
0 siblings, 0 replies; 7+ messages in thread
From: Gustavo F. Padovan @ 2011-03-17 18:30 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
* johan.hedberg@gmail.com <johan.hedberg@gmail.com> [2011-03-16 14:29:35 +0200]:
> From: Johan Hedberg <johan.hedberg@nokia.com>
>
> This patch adds a clear define for the maximum device name length in HCI
> messages and thereby avoids magic numbers in the code.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
> ---
> 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.
--
Gustavo F. Padovan
http://profusion.mobi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/4] Bluetooth: mgmt: Add support for setting the local name
2011-03-16 12:29 ` [PATCH 4/4] Bluetooth: mgmt: Add support for setting the local name johan.hedberg
@ 2011-03-17 18:38 ` Gustavo F. Padovan
0 siblings, 0 replies; 7+ messages in thread
From: Gustavo F. Padovan @ 2011-03-17 18:38 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
* johan.hedberg@gmail.com <johan.hedberg@gmail.com> [2011-03-16 14:29:37 +0200]:
> From: Johan Hedberg <johan.hedberg@nokia.com>
>
> 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.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
> ---
> 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.
--
Gustavo F. Padovan
http://profusion.mobi
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-03-17 18:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-16 12:29 [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply johan.hedberg
2011-03-16 12:29 ` [PATCH 2/4] Bluetooth: Add define for the maximum name length on HCI level johan.hedberg
2011-03-17 18:30 ` Gustavo F. Padovan
2011-03-16 12:29 ` [PATCH 3/4] Bluetooth: mgmt: Add local name information to read_info reply johan.hedberg
2011-03-16 12:29 ` [PATCH 4/4] Bluetooth: mgmt: Add support for setting the local name johan.hedberg
2011-03-17 18:38 ` Gustavo F. Padovan
2011-03-17 18:29 ` [PATCH 1/4] Bluetooth: Fix missing hci_dev_lock_bh in user_confirm_reply Gustavo F. Padovan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).