2011-03-21 13:06:56

by Szymon Janc

[permalink] [raw]
Subject: [PATCH v3 0/5] Support for OOB in mgmt interface

Changes since v2:
- include Gustavo comments
- rebase and update commands codes
- move oob enabling part to separate patch

BR,
Szymon Janc
on behalf of ST-Ericsson

Szymon Janc (5):
Bluetooth: Rename cmd to param in pending_cmd
Bluetooth: Allow for NULL data in mgmt_pending_add
Bluetooth: Add read_local_oob_data management command
Bluetooth: Add add/remove_remote_oob_data management commands
Bluetooth: Enable support for out of band association model

include/net/bluetooth/hci.h | 26 ++++++
include/net/bluetooth/hci_core.h | 18 ++++
include/net/bluetooth/mgmt.h | 18 ++++
net/bluetooth/hci_core.c | 67 +++++++++++++++
net/bluetooth/hci_event.c | 56 ++++++++++++-
net/bluetooth/mgmt.c | 175 ++++++++++++++++++++++++++++++++++++--
6 files changed, 352 insertions(+), 8 deletions(-)



2011-03-21 14:42:14

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH v3 4/5] Bluetooth: Add add/remove_remote_oob_data management commands

> Hi Szymon,

Hi Vinicius,

> > static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
> > {
> > struct hci_ev_le_conn_complete *ev = (void *) skb->data;
> > @@ -2673,6 +2704,9 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
> >
> > case HCI_EV_LE_META:
> > hci_le_meta_evt(hdev, skb);
> > +
>
> Looks like you are missing a "break" here.

Thanks for spotting this, will send v4 soon.

> Cheers,

BR,
Szymon Janc

2011-03-21 14:26:40

by Vinicius Costa Gomes

[permalink] [raw]
Subject: Re: [PATCH v3 4/5] Bluetooth: Add add/remove_remote_oob_data management commands

Hi Szymon,

On 14:07 Mon 21 Mar, Szymon Janc wrote:
> This patch adds commands to add and remove remote OOB data to the managment
> interface. Remote data is stored in kernel and can be used by corresponding
> HCI commands and events when needed.
>
> Signed-off-by: Szymon Janc <[email protected]>
> ---
> include/net/bluetooth/hci.h | 19 ++++++++++
> include/net/bluetooth/hci_core.h | 16 ++++++++
> include/net/bluetooth/mgmt.h | 12 ++++++
> net/bluetooth/hci_core.c | 67 ++++++++++++++++++++++++++++++++++
> net/bluetooth/hci_event.c | 34 +++++++++++++++++
> net/bluetooth/mgmt.c | 75 ++++++++++++++++++++++++++++++++++++++
> 6 files changed, 223 insertions(+), 0 deletions(-)
>
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index 0ac0804..8c71e88 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -428,6 +428,20 @@ struct hci_rp_user_confirm_reply {
>
> #define HCI_OP_USER_CONFIRM_NEG_REPLY 0x042d
>
> +
> +#define HCI_OP_REMOTE_OOB_DATA_REPLY 0x0430
> +struct hci_cp_remote_oob_data_reply {
> + bdaddr_t bdaddr;
> + __u8 hash[16];
> + __u8 randomizer[16];
> +} __packed;
> +
> +#define HCI_OP_REMOTE_OOB_DATA_NEG_REPLY 0x0433
> +struct hci_cp_remote_oob_data_neg_reply {
> + bdaddr_t bdaddr;
> +} __packed;
> +
> +
> #define HCI_OP_IO_CAPABILITY_NEG_REPLY 0x0434
> struct hci_cp_io_capability_neg_reply {
> bdaddr_t bdaddr;
> @@ -964,6 +978,11 @@ struct hci_ev_user_confirm_req {
> __le32 passkey;
> } __packed;
>
> +#define HCI_EV_REMOTE_OOB_DATA_REQUEST 0x35
> +struct hci_ev_remote_oob_data_request {
> + bdaddr_t bdaddr;
> +} __packed;
> +
> #define HCI_EV_SIMPLE_PAIR_COMPLETE 0x36
> struct hci_ev_simple_pair_complete {
> __u8 status;
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index fd9b8a3..87bff51 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -82,6 +82,13 @@ struct link_key {
> u8 pin_len;
> };
>
> +struct oob_data {
> + struct list_head list;
> + bdaddr_t bdaddr;
> + u8 hash[16];
> + u8 randomizer[16];
> +};
> +
> #define NUM_REASSEMBLY 4
> struct hci_dev {
> struct list_head list;
> @@ -169,6 +176,8 @@ struct hci_dev {
>
> struct list_head link_keys;
>
> + struct list_head remote_oob_data;
> +
> struct hci_dev_stats stat;
>
> struct sk_buff_head driver_init;
> @@ -505,6 +514,13 @@ int hci_add_link_key(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr,
> u8 *key, u8 type, u8 pin_len);
> int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
>
> +int hci_remote_oob_data_clear(struct hci_dev *hdev);
> +struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
> + bdaddr_t *bdaddr);
> +int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
> + u8 *randomizer);
> +int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
> +
> void hci_del_off_timer(struct hci_dev *hdev);
>
> void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
> diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
> index 6ebb126..1a6283f 100644
> --- a/include/net/bluetooth/mgmt.h
> +++ b/include/net/bluetooth/mgmt.h
> @@ -183,6 +183,18 @@ struct mgmt_rp_read_local_oob_data {
> __u8 randomizer[16];
> } __packed;
>
> +#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0019
> +struct mgmt_cp_add_remote_oob_data {
> + bdaddr_t bdaddr;
> + __u8 hash[16];
> + __u8 randomizer[16];
> +} __packed;
> +
> +#define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x001A
> +struct mgmt_cp_remove_remote_oob_data {
> + bdaddr_t bdaddr;
> +} __packed;
> +
> #define MGMT_EV_CMD_COMPLETE 0x0001
> struct mgmt_ev_cmd_complete {
> __le16 opcode;
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 1f11fe3..1fa9ce5 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -1080,6 +1080,70 @@ static void hci_cmd_timer(unsigned long arg)
> tasklet_schedule(&hdev->cmd_task);
> }
>
> +struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
> + bdaddr_t *bdaddr)
> +{
> + struct oob_data *data;
> +
> + list_for_each_entry(data, &hdev->remote_oob_data, list)
> + if (bacmp(bdaddr, &data->bdaddr) == 0)
> + return data;
> +
> + return NULL;
> +}
> +
> +int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr)
> +{
> + struct oob_data *data;
> +
> + data = hci_find_remote_oob_data(hdev, bdaddr);
> + if (!data)
> + return -ENOENT;
> +
> + BT_DBG("%s removing %s", hdev->name, batostr(bdaddr));
> +
> + list_del(&data->list);
> + kfree(data);
> +
> + return 0;
> +}
> +
> +int hci_remote_oob_data_clear(struct hci_dev *hdev)
> +{
> + struct oob_data *data, *n;
> +
> + list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) {
> + list_del(&data->list);
> + kfree(data);
> + }
> +
> + return 0;
> +}
> +
> +int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
> + u8 *randomizer)
> +{
> + struct oob_data *data;
> +
> + data = hci_find_remote_oob_data(hdev, bdaddr);
> +
> + if (!data) {
> + data = kmalloc(sizeof(*data), GFP_ATOMIC);
> + if (!data)
> + return -ENOMEM;
> +
> + bacpy(&data->bdaddr, bdaddr);
> + list_add(&data->list, &hdev->remote_oob_data);
> + }
> +
> + memcpy(data->hash, hash, 16);
> + memcpy(data->randomizer, randomizer, 16);
> +
> + BT_DBG("%s for %s", hdev->name, batostr(bdaddr));
> +
> + return 0;
> +}
> +
> /* Register HCI device */
> int hci_register_dev(struct hci_dev *hdev)
> {
> @@ -1144,6 +1208,8 @@ int hci_register_dev(struct hci_dev *hdev)
>
> INIT_LIST_HEAD(&hdev->link_keys);
>
> + INIT_LIST_HEAD(&hdev->remote_oob_data);
> +
> INIT_WORK(&hdev->power_on, hci_power_on);
> INIT_WORK(&hdev->power_off, hci_power_off);
> setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
> @@ -1223,6 +1289,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
> hci_blacklist_clear(hdev);
> hci_uuids_clear(hdev);
> hci_link_keys_clear(hdev);
> + hci_remote_oob_data_clear(hdev);
> hci_dev_unlock_bh(hdev);
>
> __hci_dev_put(hdev);
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 0223b38..fba5998 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -2473,6 +2473,37 @@ static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_
> hci_dev_unlock(hdev);
> }
>
> +static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
> + struct sk_buff *skb)
> +{
> + struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
> + struct oob_data *data;
> +
> + BT_DBG("%s", hdev->name);
> +
> + hci_dev_lock(hdev);
> +
> + data = hci_find_remote_oob_data(hdev, &ev->bdaddr);
> + if (data) {
> + struct hci_cp_remote_oob_data_reply cp;
> +
> + bacpy(&cp.bdaddr, &ev->bdaddr);
> + memcpy(cp.hash, data->hash, 16);
> + memcpy(cp.randomizer, data->randomizer, 16);
> +
> + hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
> + &cp);
> + } else {
> + struct hci_cp_remote_oob_data_neg_reply cp;
> +
> + bacpy(&cp.bdaddr, &ev->bdaddr);
> + hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
> + &cp);
> + }
> +
> + hci_dev_unlock(hdev);
> +}
> +
> static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
> {
> struct hci_ev_le_conn_complete *ev = (void *) skb->data;
> @@ -2673,6 +2704,9 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
>
> case HCI_EV_LE_META:
> hci_le_meta_evt(hdev, skb);
> +

Looks like you are missing a "break" here.

> + case HCI_EV_REMOTE_OOB_DATA_REQUEST:
> + hci_remote_oob_data_request_evt(hdev, skb);
> break;
>
> default:
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index a72cbf6..46c96b3 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -1349,6 +1349,74 @@ unlock:
> return err;
> }
>
> +static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data,
> + u16 len)
> +{
> + struct hci_dev *hdev;
> + struct mgmt_cp_add_remote_oob_data *cp = (void *) data;
> + int err;
> +
> + BT_DBG("hci%u ", index);
> +
> + if (len != sizeof(*cp))
> + return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA,
> + EINVAL);
> +
> + hdev = hci_dev_get(index);
> + if (!hdev)
> + return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA,
> + ENODEV);
> +
> + hci_dev_lock_bh(hdev);
> +
> + err = hci_add_remote_oob_data(hdev, &cp->bdaddr, cp->hash,
> + cp->randomizer);
> + if (err < 0)
> + err = cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, -err);
> + else
> + err = cmd_complete(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, NULL,
> + 0);
> +
> + hci_dev_unlock_bh(hdev);
> + hci_dev_put(hdev);
> +
> + return err;
> +}
> +
> +static int remove_remote_oob_data(struct sock *sk, u16 index,
> + unsigned char *data, u16 len)
> +{
> + struct hci_dev *hdev;
> + struct mgmt_cp_remove_remote_oob_data *cp = (void *)data;
> + int err;
> +
> + BT_DBG("hci%u ", index);
> +
> + if (len != sizeof(*cp))
> + return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
> + EINVAL);
> +
> + hdev = hci_dev_get(index);
> + if (!hdev)
> + return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
> + ENODEV);
> +
> + hci_dev_lock_bh(hdev);
> +
> + err = hci_remove_remote_oob_data(hdev, &cp->bdaddr);
> + if (err < 0)
> + err = cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
> + -err);
> + else
> + err = cmd_complete(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
> + NULL, 0);
> +
> + 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;
> @@ -1450,6 +1518,13 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
> case MGMT_OP_READ_LOCAL_OOB_DATA:
> err = read_local_oob_data(sk, index);
> break;
> + case MGMT_OP_ADD_REMOTE_OOB_DATA:
> + err = add_remote_oob_data(sk, index, buf + sizeof(*hdr), len);
> + break;
> + case MGMT_OP_REMOVE_REMOTE_OOB_DATA:
> + err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr),
> + len);
> + break;
>
> default:
> BT_DBG("Unknown op %u", opcode);
> --
> 1.7.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html


Cheers,
--
Vinicius

2011-03-21 13:07:01

by Szymon Janc

[permalink] [raw]
Subject: [PATCH v3 5/5] Bluetooth: Enable support for out of band association model

If remote side reports oob availability or we are pairing initiator
use oob data for pairing if available.

Signed-off-by: Szymon Janc <[email protected]>
---
net/bluetooth/hci_event.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index fba5998..393b43b 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2373,9 +2373,14 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff

bacpy(&cp.bdaddr, &ev->bdaddr);
cp.capability = conn->io_capability;
- cp.oob_data = 0;
cp.authentication = hci_get_auth_req(conn);

+ if ((conn->out == 0x01 || conn->remote_oob == 0x01) &&
+ hci_find_remote_oob_data(hdev, &conn->dst))
+ cp.oob_data = 0x01;
+ else
+ cp.oob_data = 0x00;
+
hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
sizeof(cp), &cp);
} else {
--
1.7.0.4


2011-03-21 13:07:00

by Szymon Janc

[permalink] [raw]
Subject: [PATCH v3 4/5] Bluetooth: Add add/remove_remote_oob_data management commands

This patch adds commands to add and remove remote OOB data to the managment
interface. Remote data is stored in kernel and can be used by corresponding
HCI commands and events when needed.

Signed-off-by: Szymon Janc <[email protected]>
---
include/net/bluetooth/hci.h | 19 ++++++++++
include/net/bluetooth/hci_core.h | 16 ++++++++
include/net/bluetooth/mgmt.h | 12 ++++++
net/bluetooth/hci_core.c | 67 ++++++++++++++++++++++++++++++++++
net/bluetooth/hci_event.c | 34 +++++++++++++++++
net/bluetooth/mgmt.c | 75 ++++++++++++++++++++++++++++++++++++++
6 files changed, 223 insertions(+), 0 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 0ac0804..8c71e88 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -428,6 +428,20 @@ struct hci_rp_user_confirm_reply {

#define HCI_OP_USER_CONFIRM_NEG_REPLY 0x042d

+
+#define HCI_OP_REMOTE_OOB_DATA_REPLY 0x0430
+struct hci_cp_remote_oob_data_reply {
+ bdaddr_t bdaddr;
+ __u8 hash[16];
+ __u8 randomizer[16];
+} __packed;
+
+#define HCI_OP_REMOTE_OOB_DATA_NEG_REPLY 0x0433
+struct hci_cp_remote_oob_data_neg_reply {
+ bdaddr_t bdaddr;
+} __packed;
+
+
#define HCI_OP_IO_CAPABILITY_NEG_REPLY 0x0434
struct hci_cp_io_capability_neg_reply {
bdaddr_t bdaddr;
@@ -964,6 +978,11 @@ struct hci_ev_user_confirm_req {
__le32 passkey;
} __packed;

+#define HCI_EV_REMOTE_OOB_DATA_REQUEST 0x35
+struct hci_ev_remote_oob_data_request {
+ bdaddr_t bdaddr;
+} __packed;
+
#define HCI_EV_SIMPLE_PAIR_COMPLETE 0x36
struct hci_ev_simple_pair_complete {
__u8 status;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index fd9b8a3..87bff51 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -82,6 +82,13 @@ struct link_key {
u8 pin_len;
};

+struct oob_data {
+ struct list_head list;
+ bdaddr_t bdaddr;
+ u8 hash[16];
+ u8 randomizer[16];
+};
+
#define NUM_REASSEMBLY 4
struct hci_dev {
struct list_head list;
@@ -169,6 +176,8 @@ struct hci_dev {

struct list_head link_keys;

+ struct list_head remote_oob_data;
+
struct hci_dev_stats stat;

struct sk_buff_head driver_init;
@@ -505,6 +514,13 @@ int hci_add_link_key(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr,
u8 *key, u8 type, u8 pin_len);
int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);

+int hci_remote_oob_data_clear(struct hci_dev *hdev);
+struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
+ bdaddr_t *bdaddr);
+int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
+ u8 *randomizer);
+int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
+
void hci_del_off_timer(struct hci_dev *hdev);

void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 6ebb126..1a6283f 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -183,6 +183,18 @@ struct mgmt_rp_read_local_oob_data {
__u8 randomizer[16];
} __packed;

+#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0019
+struct mgmt_cp_add_remote_oob_data {
+ bdaddr_t bdaddr;
+ __u8 hash[16];
+ __u8 randomizer[16];
+} __packed;
+
+#define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x001A
+struct mgmt_cp_remove_remote_oob_data {
+ bdaddr_t bdaddr;
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 1f11fe3..1fa9ce5 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1080,6 +1080,70 @@ static void hci_cmd_timer(unsigned long arg)
tasklet_schedule(&hdev->cmd_task);
}

+struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
+ bdaddr_t *bdaddr)
+{
+ struct oob_data *data;
+
+ list_for_each_entry(data, &hdev->remote_oob_data, list)
+ if (bacmp(bdaddr, &data->bdaddr) == 0)
+ return data;
+
+ return NULL;
+}
+
+int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr)
+{
+ struct oob_data *data;
+
+ data = hci_find_remote_oob_data(hdev, bdaddr);
+ if (!data)
+ return -ENOENT;
+
+ BT_DBG("%s removing %s", hdev->name, batostr(bdaddr));
+
+ list_del(&data->list);
+ kfree(data);
+
+ return 0;
+}
+
+int hci_remote_oob_data_clear(struct hci_dev *hdev)
+{
+ struct oob_data *data, *n;
+
+ list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) {
+ list_del(&data->list);
+ kfree(data);
+ }
+
+ return 0;
+}
+
+int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
+ u8 *randomizer)
+{
+ struct oob_data *data;
+
+ data = hci_find_remote_oob_data(hdev, bdaddr);
+
+ if (!data) {
+ data = kmalloc(sizeof(*data), GFP_ATOMIC);
+ if (!data)
+ return -ENOMEM;
+
+ bacpy(&data->bdaddr, bdaddr);
+ list_add(&data->list, &hdev->remote_oob_data);
+ }
+
+ memcpy(data->hash, hash, 16);
+ memcpy(data->randomizer, randomizer, 16);
+
+ BT_DBG("%s for %s", hdev->name, batostr(bdaddr));
+
+ return 0;
+}
+
/* Register HCI device */
int hci_register_dev(struct hci_dev *hdev)
{
@@ -1144,6 +1208,8 @@ int hci_register_dev(struct hci_dev *hdev)

INIT_LIST_HEAD(&hdev->link_keys);

+ INIT_LIST_HEAD(&hdev->remote_oob_data);
+
INIT_WORK(&hdev->power_on, hci_power_on);
INIT_WORK(&hdev->power_off, hci_power_off);
setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
@@ -1223,6 +1289,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
hci_blacklist_clear(hdev);
hci_uuids_clear(hdev);
hci_link_keys_clear(hdev);
+ hci_remote_oob_data_clear(hdev);
hci_dev_unlock_bh(hdev);

__hci_dev_put(hdev);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 0223b38..fba5998 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2473,6 +2473,37 @@ static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_
hci_dev_unlock(hdev);
}

+static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
+ struct sk_buff *skb)
+{
+ struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
+ struct oob_data *data;
+
+ BT_DBG("%s", hdev->name);
+
+ hci_dev_lock(hdev);
+
+ data = hci_find_remote_oob_data(hdev, &ev->bdaddr);
+ if (data) {
+ struct hci_cp_remote_oob_data_reply cp;
+
+ bacpy(&cp.bdaddr, &ev->bdaddr);
+ memcpy(cp.hash, data->hash, 16);
+ memcpy(cp.randomizer, data->randomizer, 16);
+
+ hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
+ &cp);
+ } else {
+ struct hci_cp_remote_oob_data_neg_reply cp;
+
+ bacpy(&cp.bdaddr, &ev->bdaddr);
+ hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
+ &cp);
+ }
+
+ hci_dev_unlock(hdev);
+}
+
static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
{
struct hci_ev_le_conn_complete *ev = (void *) skb->data;
@@ -2673,6 +2704,9 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)

case HCI_EV_LE_META:
hci_le_meta_evt(hdev, skb);
+
+ case HCI_EV_REMOTE_OOB_DATA_REQUEST:
+ hci_remote_oob_data_request_evt(hdev, skb);
break;

default:
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index a72cbf6..46c96b3 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1349,6 +1349,74 @@ unlock:
return err;
}

+static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data,
+ u16 len)
+{
+ struct hci_dev *hdev;
+ struct mgmt_cp_add_remote_oob_data *cp = (void *) data;
+ int err;
+
+ BT_DBG("hci%u ", index);
+
+ if (len != sizeof(*cp))
+ return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA,
+ EINVAL);
+
+ hdev = hci_dev_get(index);
+ if (!hdev)
+ return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA,
+ ENODEV);
+
+ hci_dev_lock_bh(hdev);
+
+ err = hci_add_remote_oob_data(hdev, &cp->bdaddr, cp->hash,
+ cp->randomizer);
+ if (err < 0)
+ err = cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, -err);
+ else
+ err = cmd_complete(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, NULL,
+ 0);
+
+ hci_dev_unlock_bh(hdev);
+ hci_dev_put(hdev);
+
+ return err;
+}
+
+static int remove_remote_oob_data(struct sock *sk, u16 index,
+ unsigned char *data, u16 len)
+{
+ struct hci_dev *hdev;
+ struct mgmt_cp_remove_remote_oob_data *cp = (void *)data;
+ int err;
+
+ BT_DBG("hci%u ", index);
+
+ if (len != sizeof(*cp))
+ return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
+ EINVAL);
+
+ hdev = hci_dev_get(index);
+ if (!hdev)
+ return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
+ ENODEV);
+
+ hci_dev_lock_bh(hdev);
+
+ err = hci_remove_remote_oob_data(hdev, &cp->bdaddr);
+ if (err < 0)
+ err = cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
+ -err);
+ else
+ err = cmd_complete(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
+ NULL, 0);
+
+ 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;
@@ -1450,6 +1518,13 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
case MGMT_OP_READ_LOCAL_OOB_DATA:
err = read_local_oob_data(sk, index);
break;
+ case MGMT_OP_ADD_REMOTE_OOB_DATA:
+ err = add_remote_oob_data(sk, index, buf + sizeof(*hdr), len);
+ break;
+ case MGMT_OP_REMOVE_REMOTE_OOB_DATA:
+ err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr),
+ len);
+ break;

default:
BT_DBG("Unknown op %u", opcode);
--
1.7.0.4


2011-03-21 13:06:59

by Szymon Janc

[permalink] [raw]
Subject: [PATCH v3 3/5] Bluetooth: Add read_local_oob_data management command

This patch adds a command to read local OOB data to the managment interface.
The command maps directly to the Read Local OOB Data HCI command.

Signed-off-by: Szymon Janc <[email protected]>
---
include/net/bluetooth/hci.h | 7 +++
include/net/bluetooth/hci_core.h | 2 +
include/net/bluetooth/mgmt.h | 6 +++
net/bluetooth/hci_event.c | 15 +++++++
net/bluetooth/mgmt.c | 85 ++++++++++++++++++++++++++++++++++++++
5 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 00fdcb7..0ac0804 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -615,6 +615,13 @@ struct hci_cp_write_ssp_mode {
__u8 mode;
} __packed;

+#define HCI_OP_READ_LOCAL_OOB_DATA 0x0c57
+struct hci_rp_read_local_oob_data {
+ __u8 status;
+ __u8 hash[16];
+ __u8 randomizer[16];
+} __packed;
+
#define HCI_OP_READ_INQ_RSP_TX_POWER 0x0c58

#define HCI_OP_READ_LOCAL_VERSION 0x1001
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 3912c7a..fd9b8a3 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -768,6 +768,8 @@ 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);
+int mgmt_read_local_oob_data_reply_complete(u16 index, u8 *hash, u8 *randomizer,
+ 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 89e7c82..6ebb126 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -177,6 +177,12 @@ struct mgmt_cp_set_local_name {
__u8 name[MGMT_MAX_NAME_LENGTH];
} __packed;

+#define MGMT_OP_READ_LOCAL_OOB_DATA 0x0018
+struct mgmt_rp_read_local_oob_data {
+ __u8 hash[16];
+ __u8 randomizer[16];
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 11f0dd8..0223b38 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -824,6 +824,17 @@ static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
rp->status);
}

+static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
+ struct sk_buff *skb)
+{
+ struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
+
+ BT_DBG("%s status 0x%x", hdev->name, rp->status);
+
+ mgmt_read_local_oob_data_reply_complete(hdev->id, rp->hash,
+ rp->randomizer, rp->status);
+}
+
static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
{
BT_DBG("%s status 0x%x", hdev->name, status);
@@ -1754,6 +1765,10 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
hci_cc_pin_code_neg_reply(hdev, skb);
break;

+ case HCI_OP_READ_LOCAL_OOB_DATA:
+ hci_cc_read_local_oob_data_reply(hdev, skb);
+ break;
+
case HCI_OP_LE_READ_BUFFER_SIZE:
hci_cc_le_read_buffer_size(hdev, skb);
break;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index ebf495d..a72cbf6 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1298,6 +1298,57 @@ failed:
return err;
}

+static int read_local_oob_data(struct sock *sk, u16 index)
+{
+ struct hci_dev *hdev;
+ struct pending_cmd *cmd;
+ int err;
+
+ BT_DBG("hci%u", index);
+
+ hdev = hci_dev_get(index);
+ if (!hdev)
+ return cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
+ ENODEV);
+
+ hci_dev_lock_bh(hdev);
+
+ if (!test_bit(HCI_UP, &hdev->flags)) {
+ err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
+ ENETDOWN);
+ goto unlock;
+ }
+
+ if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) {
+ err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
+ EOPNOTSUPP);
+ goto unlock;
+ }
+
+ if (mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, index)) {
+ err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, EBUSY);
+ goto unlock;
+ }
+
+ cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_DATA, index, NULL, 0);
+
+ if (!cmd) {
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ err = hci_send_cmd(hdev, HCI_OP_READ_LOCAL_OOB_DATA, 0, NULL);
+
+ if (err < 0)
+ mgmt_pending_remove(cmd);
+
+unlock:
+ 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;
@@ -1396,6 +1447,10 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
case MGMT_OP_SET_LOCAL_NAME:
err = set_local_name(sk, index, buf + sizeof(*hdr), len);
break;
+ case MGMT_OP_READ_LOCAL_OOB_DATA:
+ err = read_local_oob_data(sk, index);
+ break;
+
default:
BT_DBG("Unknown op %u", opcode);
err = cmd_status(sk, index, opcode, 0x01);
@@ -1725,3 +1780,33 @@ failed:
mgmt_pending_remove(cmd);
return err;
}
+
+int mgmt_read_local_oob_data_reply_complete(u16 index, u8 *hash, u8 *randomizer,
+ u8 status)
+{
+ struct pending_cmd *cmd;
+ int err;
+
+ BT_DBG("hci%u status %u", index, status);
+
+ cmd = mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, index);
+ if (!cmd)
+ return -ENOENT;
+
+ if (status) {
+ err = cmd_status(cmd->sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
+ EIO);
+ } else {
+ struct mgmt_rp_read_local_oob_data rp;
+
+ memcpy(rp.hash, hash, 16);
+ memcpy(rp.randomizer, randomizer, 16);
+
+ err = cmd_complete(cmd->sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
+ &rp, sizeof(rp));
+ }
+
+ mgmt_pending_remove(cmd);
+
+ return err;
+}
--
1.7.0.4


2011-03-21 13:06:57

by Szymon Janc

[permalink] [raw]
Subject: [PATCH v3 1/5] Bluetooth: Rename cmd to param in pending_cmd

This field holds not whole command but only command specific
parameters.

Signed-off-by: Szymon Janc <[email protected]>
---
net/bluetooth/mgmt.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 98988c8..657a02d 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -36,7 +36,7 @@ struct pending_cmd {
struct list_head list;
__u16 opcode;
int index;
- void *cmd;
+ void *param;
struct sock *sk;
void *user_data;
};
@@ -217,7 +217,7 @@ static int read_controller_info(struct sock *sk, u16 index)
static void mgmt_pending_free(struct pending_cmd *cmd)
{
sock_put(cmd->sk);
- kfree(cmd->cmd);
+ kfree(cmd->param);
kfree(cmd);
}

@@ -233,13 +233,13 @@ static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
cmd->opcode = opcode;
cmd->index = index;

- cmd->cmd = kmalloc(len, GFP_ATOMIC);
- if (!cmd->cmd) {
+ cmd->param = kmalloc(len, GFP_ATOMIC);
+ if (!cmd->param) {
kfree(cmd);
return NULL;
}

- memcpy(cmd->cmd, data, len);
+ memcpy(cmd->param, data, len);

cmd->sk = sk;
sock_hold(sk);
@@ -1428,7 +1428,7 @@ struct cmd_lookup {

static void mode_rsp(struct pending_cmd *cmd, void *data)
{
- struct mgmt_mode *cp = cmd->cmd;
+ struct mgmt_mode *cp = cmd->param;
struct cmd_lookup *match = data;

if (cp->val != match->val)
@@ -1527,7 +1527,7 @@ int mgmt_connected(u16 index, bdaddr_t *bdaddr)

static void disconnect_rsp(struct pending_cmd *cmd, void *data)
{
- struct mgmt_cp_disconnect *cp = cmd->cmd;
+ struct mgmt_cp_disconnect *cp = cmd->param;
struct sock **sk = data;
struct mgmt_rp_disconnect rp;

--
1.7.0.4


2011-03-21 13:06:58

by Szymon Janc

[permalink] [raw]
Subject: [PATCH v3 2/5] Bluetooth: Allow for NULL data in mgmt_pending_add

Since index is in mgmt_hdr it is possible to have mgmt command with
no parameters that still needs to add itself to pending list.

Signed-off-by: Szymon Janc <[email protected]>
---
net/bluetooth/mgmt.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 657a02d..ebf495d 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -239,7 +239,8 @@ static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
return NULL;
}

- memcpy(cmd->param, data, len);
+ if (data)
+ memcpy(cmd->param, data, len);

cmd->sk = sk;
sock_hold(sk);
--
1.7.0.4