* [PATCH 1/5] Bluetooth: Add error handling for managment command handlers
2010-12-13 19:07 Basic Management interface command handling johan.hedberg
@ 2010-12-13 19:07 ` johan.hedberg
2010-12-16 16:52 ` Gustavo F. Padovan
2010-12-13 19:07 ` [PATCH 2/5] Bluetooth: Add read_version management command johan.hedberg
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: johan.hedberg @ 2010-12-13 19:07 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
The command handlers for bluetooth management messaging should be able
to report errors (such as memory allocation failures) to the higher
levels in the call stack.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
net/bluetooth/mgmt.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d15bf67..7ea5489 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -29,7 +29,7 @@
#include <net/bluetooth/hci_core.h>
#include <net/bluetooth/mgmt.h>
-static void cmd_status(struct sock *sk, u16 cmd, u8 status)
+static int cmd_status(struct sock *sk, u16 cmd, u8 status)
{
struct sk_buff *skb;
struct mgmt_hdr *hdr;
@@ -39,7 +39,7 @@ static void cmd_status(struct sock *sk, u16 cmd, u8 status)
skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_ATOMIC);
if (!skb)
- return;
+ return -ENOMEM;
hdr = (void *) skb_put(skb, sizeof(*hdr));
@@ -52,6 +52,8 @@ static void cmd_status(struct sock *sk, u16 cmd, u8 status)
if (sock_queue_rcv_skb(sk, skb) < 0)
kfree_skb(skb);
+
+ return 0;
}
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
@@ -87,10 +89,13 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
switch (opcode) {
default:
BT_DBG("Unknown op %u", opcode);
- cmd_status(sk, opcode, 0x01);
+ err = cmd_status(sk, opcode, 0x01);
break;
}
+ if (err < 0)
+ goto done;
+
err = msglen;
done:
--
1.7.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/5] Bluetooth: Add error handling for managment command handlers
2010-12-13 19:07 ` [PATCH 1/5] Bluetooth: Add error handling for managment command handlers johan.hedberg
@ 2010-12-16 16:52 ` Gustavo F. Padovan
2010-12-16 17:31 ` Johan Hedberg
0 siblings, 1 reply; 8+ messages in thread
From: Gustavo F. Padovan @ 2010-12-16 16:52 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
* johan.hedberg@gmail.com <johan.hedberg@gmail.com> [2010-12-13 21:07:03 +0200]:
> From: Johan Hedberg <johan.hedberg@nokia.com>
>
> The command handlers for bluetooth management messaging should be able
> to report errors (such as memory allocation failures) to the higher
> levels in the call stack.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
> ---
> net/bluetooth/mgmt.c | 11 ++++++++---
> 1 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index d15bf67..7ea5489 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -29,7 +29,7 @@
> #include <net/bluetooth/hci_core.h>
> #include <net/bluetooth/mgmt.h>
>
> -static void cmd_status(struct sock *sk, u16 cmd, u8 status)
> +static int cmd_status(struct sock *sk, u16 cmd, u8 status)
> {
> struct sk_buff *skb;
> struct mgmt_hdr *hdr;
> @@ -39,7 +39,7 @@ static void cmd_status(struct sock *sk, u16 cmd, u8 status)
>
> skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_ATOMIC);
> if (!skb)
> - return;
> + return -ENOMEM;
>
> hdr = (void *) skb_put(skb, sizeof(*hdr));
>
> @@ -52,6 +52,8 @@ static void cmd_status(struct sock *sk, u16 cmd, u8 status)
>
> if (sock_queue_rcv_skb(sk, skb) < 0)
> kfree_skb(skb);
> +
> + return 0;
> }
>
> int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
> @@ -87,10 +89,13 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
> switch (opcode) {
> default:
> BT_DBG("Unknown op %u", opcode);
> - cmd_status(sk, opcode, 0x01);
> + err = cmd_status(sk, opcode, 0x01);
> break;
> }
>
> + if (err < 0)
> + goto done;
> +
> err = msglen;
I think
if (!err)
err = msglen;
is better.
--
Gustavo F. Padovan
http://profusion.mobi
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/5] Bluetooth: Add error handling for managment command handlers
2010-12-16 16:52 ` Gustavo F. Padovan
@ 2010-12-16 17:31 ` Johan Hedberg
0 siblings, 0 replies; 8+ messages in thread
From: Johan Hedberg @ 2010-12-16 17:31 UTC (permalink / raw)
To: Gustavo F. Padovan; +Cc: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 357 bytes --]
Hi Gustavo,
On Thu, Dec 16, 2010, Gustavo F. Padovan wrote:
> > + if (err < 0)
> > + goto done;
> > +
> > err = msglen;
>
>
> I think
> if (!err)
> err = msglen;
>
>
> is better.
Agreed. Here's an updated patch. I used "err == 0" since that seems to
be more common at least in Marcel's user space projects for non-boolean
variable tests.
Johan
[-- Attachment #2: 0001-Bluetooth-Add-error-handling-for-managment-command-h.patch --]
[-- Type: text/x-diff, Size: 1740 bytes --]
>From 1b37152df73d9480382263f3e17c3856e8f403f3 Mon Sep 17 00:00:00 2001
From: Johan Hedberg <johan.hedberg@nokia.com>
Date: Fri, 10 Dec 2010 12:06:16 +0200
Subject: [PATCH] Bluetooth: Add error handling for managment command handlers
The command handlers for bluetooth management messaging should be able
to report errors (such as memory allocation failures) to the higher
levels in the call stack.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
net/bluetooth/mgmt.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d15bf67..e336fc1 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -29,7 +29,7 @@
#include <net/bluetooth/hci_core.h>
#include <net/bluetooth/mgmt.h>
-static void cmd_status(struct sock *sk, u16 cmd, u8 status)
+static int cmd_status(struct sock *sk, u16 cmd, u8 status)
{
struct sk_buff *skb;
struct mgmt_hdr *hdr;
@@ -39,7 +39,7 @@ static void cmd_status(struct sock *sk, u16 cmd, u8 status)
skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_ATOMIC);
if (!skb)
- return;
+ return -ENOMEM;
hdr = (void *) skb_put(skb, sizeof(*hdr));
@@ -52,6 +52,8 @@ static void cmd_status(struct sock *sk, u16 cmd, u8 status)
if (sock_queue_rcv_skb(sk, skb) < 0)
kfree_skb(skb);
+
+ return 0;
}
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
@@ -87,11 +89,12 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
switch (opcode) {
default:
BT_DBG("Unknown op %u", opcode);
- cmd_status(sk, opcode, 0x01);
+ err = cmd_status(sk, opcode, 0x01);
break;
}
- err = msglen;
+ if (err == 0)
+ err = msglen;
done:
kfree(buf);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] Bluetooth: Add read_version management command
2010-12-13 19:07 Basic Management interface command handling johan.hedberg
2010-12-13 19:07 ` [PATCH 1/5] Bluetooth: Add error handling for managment command handlers johan.hedberg
@ 2010-12-13 19:07 ` johan.hedberg
2010-12-13 19:07 ` [PATCH 3/5] Bluetooth: Add read_index_list " johan.hedberg
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2010-12-13 19:07 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
This patch implements the initial read_version command that userspace
will use before any other management interface operations.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
include/net/bluetooth/mgmt.h | 6 ++++++
net/bluetooth/mgmt.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 95974da..d353d64 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -27,6 +27,12 @@ struct mgmt_hdr {
} __packed;
#define MGMT_HDR_SIZE 4
+#define MGMT_OP_READ_VERSION 0x0001
+struct mgmt_rp_read_version {
+ __u8 version;
+ __le16 revision;
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 7ea5489..3e24c0b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -29,6 +29,39 @@
#include <net/bluetooth/hci_core.h>
#include <net/bluetooth/mgmt.h>
+#define MGMT_VERSION 0
+#define MGMT_REVISION 1
+
+static int read_version(struct sock *sk)
+{
+ struct sk_buff *skb;
+ struct mgmt_hdr *hdr;
+ struct mgmt_ev_cmd_complete *ev;
+ struct mgmt_rp_read_version *rp;
+
+ BT_DBG("sock %p", sk);
+
+ skb = alloc_skb(sizeof(*hdr) + sizeof(*ev) + sizeof(*rp), GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ hdr = (void *) skb_put(skb, sizeof(*hdr));
+ hdr->opcode = cpu_to_le16(MGMT_EV_CMD_COMPLETE);
+ hdr->len = cpu_to_le16(sizeof(*ev) + sizeof(*rp));
+
+ ev = (void *) skb_put(skb, sizeof(*ev));
+ put_unaligned_le16(MGMT_OP_READ_VERSION, &ev->opcode);
+
+ rp = (void *) skb_put(skb, sizeof(*rp));
+ rp->version = MGMT_VERSION;
+ put_unaligned_le16(MGMT_REVISION, &rp->revision);
+
+ if (sock_queue_rcv_skb(sk, skb) < 0)
+ kfree_skb(skb);
+
+ return 0;
+}
+
static int cmd_status(struct sock *sk, u16 cmd, u8 status)
{
struct sk_buff *skb;
@@ -87,6 +120,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
}
switch (opcode) {
+ case MGMT_OP_READ_VERSION:
+ err = read_version(sk);
+ break;
default:
BT_DBG("Unknown op %u", opcode);
err = cmd_status(sk, opcode, 0x01);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/5] Bluetooth: Add read_index_list management command
2010-12-13 19:07 Basic Management interface command handling johan.hedberg
2010-12-13 19:07 ` [PATCH 1/5] Bluetooth: Add error handling for managment command handlers johan.hedberg
2010-12-13 19:07 ` [PATCH 2/5] Bluetooth: Add read_version management command johan.hedberg
@ 2010-12-13 19:07 ` johan.hedberg
2010-12-13 19:07 ` [PATCH 4/5] Bluetooth: Add read_info " johan.hedberg
2010-12-13 19:07 ` [PATCH 5/5] Bluetooth: Add management events for controller addition & removal johan.hedberg
4 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2010-12-13 19:07 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
This patch implements the read_index_list command through which
userspace can get a list of current adapter indices.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
include/net/bluetooth/mgmt.h | 6 ++++
net/bluetooth/mgmt.c | 53 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index d353d64..c2b4c83 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -33,6 +33,12 @@ struct mgmt_rp_read_version {
__le16 revision;
} __packed;
+#define MGMT_OP_READ_INDEX_LIST 0x0003
+struct mgmt_rp_read_index_list {
+ __le16 num_controllers;
+ __le16 index[0];
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 3e24c0b..7a8e321 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -62,6 +62,56 @@ static int read_version(struct sock *sk)
return 0;
}
+static int read_index_list(struct sock *sk)
+{
+ struct sk_buff *skb;
+ struct mgmt_hdr *hdr;
+ struct mgmt_ev_cmd_complete *ev;
+ struct mgmt_rp_read_index_list *rp;
+ struct list_head *p;
+ size_t body_len;
+ u16 count;
+ int i;
+
+ BT_DBG("sock %p", sk);
+
+ read_lock(&hci_dev_list_lock);
+
+ count = 0;
+ list_for_each(p, &hci_dev_list) {
+ count++;
+ }
+
+ body_len = sizeof(*ev) + sizeof(*rp) + (2 * count);
+ skb = alloc_skb(sizeof(*hdr) + body_len, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ hdr = (void *) skb_put(skb, sizeof(*hdr));
+ hdr->opcode = cpu_to_le16(MGMT_EV_CMD_COMPLETE);
+ hdr->len = cpu_to_le16(body_len);
+
+ ev = (void *) skb_put(skb, sizeof(*ev));
+ put_unaligned_le16(MGMT_OP_READ_INDEX_LIST, &ev->opcode);
+
+ rp = (void *) skb_put(skb, sizeof(*rp) + (2 * count));
+ put_unaligned_le16(count, &rp->num_controllers);
+
+ i = 0;
+ list_for_each(p, &hci_dev_list) {
+ struct hci_dev *d = list_entry(p, struct hci_dev, list);
+ put_unaligned_le16(d->id, &rp->index[i++]);
+ BT_DBG("Added hci%u", d->id);
+ }
+
+ read_unlock(&hci_dev_list_lock);
+
+ if (sock_queue_rcv_skb(sk, skb) < 0)
+ kfree_skb(skb);
+
+ return 0;
+}
+
static int cmd_status(struct sock *sk, u16 cmd, u8 status)
{
struct sk_buff *skb;
@@ -123,6 +173,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
case MGMT_OP_READ_VERSION:
err = read_version(sk);
break;
+ case MGMT_OP_READ_INDEX_LIST:
+ err = read_index_list(sk);
+ break;
default:
BT_DBG("Unknown op %u", opcode);
err = cmd_status(sk, opcode, 0x01);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/5] Bluetooth: Add read_info management command
2010-12-13 19:07 Basic Management interface command handling johan.hedberg
` (2 preceding siblings ...)
2010-12-13 19:07 ` [PATCH 3/5] Bluetooth: Add read_index_list " johan.hedberg
@ 2010-12-13 19:07 ` johan.hedberg
2010-12-13 19:07 ` [PATCH 5/5] Bluetooth: Add management events for controller addition & removal johan.hedberg
4 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2010-12-13 19:07 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
This patch implements the read_info command which is used to fetch basic
info about an adapter.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
include/net/bluetooth/mgmt.h | 19 +++++++++
net/bluetooth/mgmt.c | 90 ++++++++++++++++++++++++++++++++++++++----
2 files changed, 101 insertions(+), 8 deletions(-)
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index c2b4c83..70985aa 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -39,6 +39,25 @@ struct mgmt_rp_read_index_list {
__le16 index[0];
} __packed;
+#define MGMT_OP_READ_INFO 0x0004
+struct mgmt_cp_read_info {
+ __le16 index;
+} __packed;
+struct mgmt_rp_read_info {
+ __le16 index;
+ __u8 type;
+ __u8 powered;
+ __u8 discoverable;
+ __u8 pairable;
+ __u8 sec_mode;
+ bdaddr_t bdaddr;
+ __u8 dev_class[3];
+ __u8 features[8];
+ __u16 manufacturer;
+ __u8 hci_ver;
+ __u16 hci_rev;
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 7a8e321..d6c5a32 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -32,6 +32,33 @@
#define MGMT_VERSION 0
#define MGMT_REVISION 1
+static int cmd_status(struct sock *sk, u16 cmd, u8 status)
+{
+ struct sk_buff *skb;
+ struct mgmt_hdr *hdr;
+ struct mgmt_ev_cmd_status *ev;
+
+ BT_DBG("sock %p", sk);
+
+ skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ hdr = (void *) skb_put(skb, sizeof(*hdr));
+
+ hdr->opcode = cpu_to_le16(MGMT_EV_CMD_STATUS);
+ hdr->len = cpu_to_le16(sizeof(*ev));
+
+ ev = (void *) skb_put(skb, sizeof(*ev));
+ ev->status = status;
+ put_unaligned_le16(cmd, &ev->opcode);
+
+ if (sock_queue_rcv_skb(sk, skb) < 0)
+ kfree_skb(skb);
+
+ return 0;
+}
+
static int read_version(struct sock *sk)
{
struct sk_buff *skb;
@@ -112,26 +139,70 @@ static int read_index_list(struct sock *sk)
return 0;
}
-static int cmd_status(struct sock *sk, u16 cmd, u8 status)
+static int read_controller_info(struct sock *sk, unsigned char *data, u16 len)
{
struct sk_buff *skb;
struct mgmt_hdr *hdr;
- struct mgmt_ev_cmd_status *ev;
+ struct mgmt_ev_cmd_complete *ev;
+ struct mgmt_rp_read_info *rp;
+ struct mgmt_cp_read_info *cp;
+ struct hci_dev *hdev;
+ u16 dev_id;
BT_DBG("sock %p", sk);
- skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_ATOMIC);
+ if (len != 2)
+ return cmd_status(sk, MGMT_OP_READ_INFO, EINVAL);
+
+ skb = alloc_skb(sizeof(*hdr) + sizeof(*ev) + sizeof(*rp), GFP_ATOMIC);
if (!skb)
return -ENOMEM;
hdr = (void *) skb_put(skb, sizeof(*hdr));
-
- hdr->opcode = cpu_to_le16(MGMT_EV_CMD_STATUS);
- hdr->len = cpu_to_le16(sizeof(*ev));
+ hdr->opcode = cpu_to_le16(MGMT_EV_CMD_COMPLETE);
+ hdr->len = cpu_to_le16(sizeof(*ev) + sizeof(*rp));
ev = (void *) skb_put(skb, sizeof(*ev));
- ev->status = status;
- put_unaligned_le16(cmd, &ev->opcode);
+ put_unaligned_le16(MGMT_OP_READ_INFO, &ev->opcode);
+
+ rp = (void *) skb_put(skb, sizeof(*rp));
+
+ cp = (void *) data;
+ dev_id = get_unaligned_le16(&cp->index);
+
+ BT_DBG("request for hci%u", dev_id);
+
+ hdev = hci_dev_get(dev_id);
+ if (!hdev) {
+ kfree_skb(skb);
+ return cmd_status(sk, MGMT_OP_READ_INFO, ENODEV);
+ }
+
+ hci_dev_lock_bh(hdev);
+
+ put_unaligned_le16(hdev->id, &rp->index);
+ rp->type = hdev->dev_type;
+
+ rp->powered = test_bit(HCI_UP, &hdev->flags);
+ rp->discoverable = test_bit(HCI_ISCAN, &hdev->flags);
+ rp->pairable = test_bit(HCI_PSCAN, &hdev->flags);
+
+ if (test_bit(HCI_AUTH, &hdev->flags))
+ rp->sec_mode = 3;
+ else if (hdev->ssp_mode > 0)
+ rp->sec_mode = 4;
+ else
+ rp->sec_mode = 2;
+
+ bacpy(&rp->bdaddr, &hdev->bdaddr);
+ memcpy(rp->features, hdev->features, 8);
+ memcpy(rp->dev_class, hdev->dev_class, 3);
+ put_unaligned_le16(hdev->manufacturer, &rp->manufacturer);
+ rp->hci_ver = hdev->hci_ver;
+ put_unaligned_le16(hdev->hci_rev, &rp->hci_rev);
+
+ hci_dev_unlock_bh(hdev);
+ hci_dev_put(hdev);
if (sock_queue_rcv_skb(sk, skb) < 0)
kfree_skb(skb);
@@ -176,6 +247,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
case MGMT_OP_READ_INDEX_LIST:
err = read_index_list(sk);
break;
+ case MGMT_OP_READ_INFO:
+ err = read_controller_info(sk, buf + sizeof(*hdr), len);
+ break;
default:
BT_DBG("Unknown op %u", opcode);
err = cmd_status(sk, opcode, 0x01);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 5/5] Bluetooth: Add management events for controller addition & removal
2010-12-13 19:07 Basic Management interface command handling johan.hedberg
` (3 preceding siblings ...)
2010-12-13 19:07 ` [PATCH 4/5] Bluetooth: Add read_info " johan.hedberg
@ 2010-12-13 19:07 ` johan.hedberg
4 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2010-12-13 19:07 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
This patch adds Bluetooth Management interface events for controller
addition and removal. The events correspond to the existing HCI_DEV_REG
and HCI_DEV_UNREG stack internal events.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
include/net/bluetooth/hci_core.h | 2 +
include/net/bluetooth/mgmt.h | 10 +++++++++
net/bluetooth/hci_core.c | 2 +
net/bluetooth/mgmt.c | 41 ++++++++++++++++++++++++++++++++++++++
4 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 1992fac..3786ee8 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -662,6 +662,8 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
/* Management interface */
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
+int mgmt_index_added(u16 index);
+int mgmt_index_removed(u16 index);
/* 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 70985aa..ca29c13 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -75,3 +75,13 @@ struct mgmt_ev_controller_error {
__le16 index;
__u8 error_code;
} __packed;
+
+#define MGMT_EV_INDEX_ADDED 0x0004
+struct mgmt_ev_index_added {
+ __le16 index;
+} __packed;
+
+#define MGMT_EV_INDEX_REMOVED 0x0005
+struct mgmt_ev_index_removed {
+ __le16 index;
+} __packed;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 51c61f7..1a4ec97 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -960,6 +960,7 @@ int hci_register_dev(struct hci_dev *hdev)
}
}
+ mgmt_index_added(hdev->id);
hci_notify(hdev, HCI_DEV_REG);
return id;
@@ -989,6 +990,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
for (i = 0; i < NUM_REASSEMBLY; i++)
kfree_skb(hdev->reassembly[i]);
+ mgmt_index_removed(hdev->id);
hci_notify(hdev, HCI_DEV_UNREG);
if (hdev->rfkill) {
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d6c5a32..f827fd9 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -265,3 +265,44 @@ done:
kfree(buf);
return err;
}
+
+static int mgmt_event(u16 event, void *data, u16 data_len)
+{
+ struct sk_buff *skb;
+ struct mgmt_hdr *hdr;
+
+ skb = alloc_skb(sizeof(*hdr) + data_len, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ bt_cb(skb)->channel = HCI_CHANNEL_CONTROL;
+
+ hdr = (void *) skb_put(skb, sizeof(*hdr));
+ hdr->opcode = cpu_to_le16(event);
+ hdr->len = cpu_to_le16(data_len);
+
+ memcpy(skb_put(skb, data_len), data, data_len);
+
+ hci_send_to_sock(NULL, skb);
+ kfree_skb(skb);
+
+ return 0;
+}
+
+int mgmt_index_added(u16 index)
+{
+ struct mgmt_ev_index_added ev;
+
+ put_unaligned_le16(index, &ev.index);
+
+ return mgmt_event(MGMT_EV_INDEX_ADDED, &ev, sizeof(ev));
+}
+
+int mgmt_index_removed(u16 index)
+{
+ struct mgmt_ev_index_added ev;
+
+ put_unaligned_le16(index, &ev.index);
+
+ return mgmt_event(MGMT_EV_INDEX_REMOVED, &ev, sizeof(ev));
+}
--
1.7.2.3
^ permalink raw reply related [flat|nested] 8+ messages in thread