Bluetooth: mgmt: Implement support for passkey notification
Subsystems (2)
PATCH 1/1 Bluetooth: mgmt: Implement support for passkey notification
From: Johan Hedberg <[email protected]>
This patch adds support for Secure Simple Pairing with devices that have KeyboardOnly as their IO capability. Such devices will cause a passkey notification on our side and optionally also keypress notifications. Without this patch some keyboards cannot be paired using the mgmt interface.
--- include/net/bluetooth/hci.h | 18 +++++++++++ include/net/bluetooth/hci_core.h | 5 +++ include/net/bluetooth/mgmt.h | 7 +++++ net/bluetooth/hci_event.c | 63 ++++++++++++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 16 ++++++++++ 5 files changed, 109 insertions(+)
include/net/bluetooth/hci.h +18 -0
@@ -1249,6 +1249,24 @@ struct hci_ev_simple_pair_complete {bdaddr_t bdaddr; } __packed; +#define HCI_EV_USER_PASSKEY_NOTIFY 0x3b +struct hci_ev_user_passkey_notify { +bdaddr_t bdaddr; +__le32 passkey; +} __packed; + +#define HCI_KEYPRESS_STARTED 0 +#define HCI_KEYPRESS_ENTERED 1 +#define HCI_KEYPRESS_ERASED 2 +#define HCI_KEYPRESS_CLEARED 3 +#define HCI_KEYPRESS_COMPLETED 4 + +#define HCI_EV_KEYPRESS_NOTIFY 0x3c +struct hci_ev_keypress_notify { +bdaddr_t bdaddr; +__u8 type; +} __packed; +#define HCI_EV_REMOTE_HOST_FEATURES 0x3dstruct hci_ev_remote_host_features {bdaddr_t bdaddr;
include/net/bluetooth/hci_core.h +5 -0
@@ -303,6 +303,8 @@ struct hci_conn {__u8 pin_length;__u8 enc_key_size;__u8 io_capability; +__u32 passkey_notify; +__u8 passkey_entered;__u16 disc_timeout;unsigned long flags;
@@ -1016,6 +1018,9 @@ int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, u8 addr_type, u8 status);int mgmt_user_passkey_neg_reply_complete (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 status); +int mgmt_user_passkey_notify (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 link_type,u8 addr_type,u32 passkey, +u8 entered);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);
include/net/bluetooth/mgmt.h +7 -0
@@ -478,3 +478,10 @@ struct mgmt_ev_device_unblocked {struct mgmt_ev_device_unpaired {struct mgmt_addr_info addr; } __packed; + +#define MGMT_EV_PASSKEY_NOTIFY 0x0017 +struct mgmt_ev_passkey_notify { +struct mgmt_addr_info addr; +__le32 passkey; +__u8 entered; +} __packed;
net/bluetooth/hci_event.c +63 -0
75 lines not on this page · raw message
net/bluetooth/mgmt.c +16 -0
@@ -3276,6 +3276,22 @@ int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, MGMT_OP_USER_PASSKEY_NEG_REPLY); } +int mgmt_user_passkey_notify (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 link_type,u8 addr_type,u32 passkey, +u8 entered) +{ +struct mgmt_ev_passkey_notify ev; + +BT_DBG ("%s" , hdev->name); + +bacpy (&ev.addr.bdaddr, bdaddr); + ev.addr.type =link_to_bdaddr (link_type, addr_type); + ev.passkey =__cpu_to_le32 (passkey); + ev.entered = entered; + +return mgmt_event (MGMT_EV_PASSKEY_NOTIFY , hdev, &ev,sizeof (ev),NULL ); +} +int mgmt_auth_failed (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 status) {
Signature · 1 line
1.7.10.4
Marcel Holtmann
maintainerHi Johan,
Quoted 5 lines
This patch adds support for Secure Simple Pairing with devices that have KeyboardOnly as their IO capability. Such devices will cause a passkey notification on our side and optionally also keypress notifications. Without this patch some keyboards cannot be paired using the mgmt interface.
can we see a mgmt-api.txt documentation patch as RFC first.
Regards
Marcel
Hi Marcel,
Quoted 9 lines · Marcel Holtmann
Hi Johan,
Quoted 5 lines
This patch adds support for Secure Simple Pairing with devices that have KeyboardOnly as their IO capability. Such devices will cause a passkey notification on our side and optionally also keypress notifications. Without this patch some keyboards cannot be paired using the mgmt interface.
can we see a mgmt-api.txt documentation patch as RFC first.
Actually I already pushed that yesterday. We can still change it of course if you have improvement suggestions:
+Passkey Notify Event
+====================
+
+Event Code 0x0017 +Controller Index <controller id> +Event Parameters Address (6 Octets) + Address_Type (1 Octet) + Passkey (4 Octets) + Entered (1 Octet)
And yes, I know some description for the event (and most other events in mgmt-api.txt) would be good.
Johan
Hi Johan,
nitpicks
On Wed, Sep 05, 2012 at 11:14:10AM +0300, Johan Hedberg wrote:
...
Quoted 7 lines
net/bluetooth/hci_event.c +7
-0+ conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr); +if (!conn) +return ; + +switch (ev->type) { +case HCI_KEYPRESS_STARTED : + conn->passkey_entered =0 ;
net/bluetooth/hci_event.c static void hci_user_passkey_request_evt(struct hci_dev *hdev, · line 3310
Quoted 10 lines
net/bluetooth/hci_event.c +10
-0+return ; +case HCI_KEYPRESS_ENTERED : + conn->passkey_entered++; +break ; +case HCI_KEYPRESS_ERASED : + conn->passkey_entered--; +break ; +case HCI_KEYPRESS_CLEARED : + conn->passkey_entered =0 ; +break ;
Can we use the same style for switch like below:
...
net/bluetooth/hci_event.c void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) · line 3695
Quoted 11 lines
net/bluetooth/hci_event.c +8
-0+case HCI_EV_USER_PASSKEY_NOTIFY : +hci_user_passkey_notify_evt (hdev, skb); +break ; + +case HCI_EV_KEYPRESS_NOTIFY : +hci_keypress_notify_evt (hdev, skb); +break ; +case HCI_EV_SIMPLE_PAIR_COMPLETE :hci_simple_pair_complete_evt (hdev, skb);break ;
Best regards
Andrei Emeltchenko
PATCH v2 1/1 Bluetooth: mgmt: Implement support for passkey notification
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This patch adds support for Secure Simple Pairing with devices that have KeyboardOnly as their IO capability. Such devices will cause a passkey notification on our side and optionally also keypress notifications. Without this patch some keyboards cannot be paired using the mgmt interface.
---
v2: Make the keypress switch statement consistent with the rest of the code
include/net/bluetooth/hci.h | 18 ++++++++++ include/net/bluetooth/hci_core.h | 5 +++ include/net/bluetooth/mgmt.h | 7 ++++ net/bluetooth/hci_event.c | 67 ++++++++++++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 16 +++++++++ 5 files changed, 113 insertions(+)
include/net/bluetooth/hci.h +18 -0
@@ -1249,6 +1249,24 @@ struct hci_ev_simple_pair_complete {bdaddr_t bdaddr; } __packed; +#define HCI_EV_USER_PASSKEY_NOTIFY 0x3b +struct hci_ev_user_passkey_notify { +bdaddr_t bdaddr; +__le32 passkey; +} __packed; + +#define HCI_KEYPRESS_STARTED 0 +#define HCI_KEYPRESS_ENTERED 1 +#define HCI_KEYPRESS_ERASED 2 +#define HCI_KEYPRESS_CLEARED 3 +#define HCI_KEYPRESS_COMPLETED 4 + +#define HCI_EV_KEYPRESS_NOTIFY 0x3c +struct hci_ev_keypress_notify { +bdaddr_t bdaddr; +__u8 type; +} __packed; +#define HCI_EV_REMOTE_HOST_FEATURES 0x3dstruct hci_ev_remote_host_features {bdaddr_t bdaddr;
include/net/bluetooth/hci_core.h +5 -0
@@ -303,6 +303,8 @@ struct hci_conn {__u8 pin_length;__u8 enc_key_size;__u8 io_capability; +__u32 passkey_notify; +__u8 passkey_entered;__u16 disc_timeout;unsigned long flags;
@@ -1016,6 +1018,9 @@ int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, u8 addr_type, u8 status);int mgmt_user_passkey_neg_reply_complete (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 status); +int mgmt_user_passkey_notify (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 link_type,u8 addr_type,u32 passkey, +u8 entered);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);
include/net/bluetooth/mgmt.h +7 -0
@@ -478,3 +478,10 @@ struct mgmt_ev_device_unblocked {struct mgmt_ev_device_unpaired {struct mgmt_addr_info addr; } __packed; + +#define MGMT_EV_PASSKEY_NOTIFY 0x0017 +struct mgmt_ev_passkey_notify { +struct mgmt_addr_info addr; +__le32 passkey; +__u8 entered; +} __packed;
net/bluetooth/hci_event.c +67 -0
79 lines not on this page · raw message
net/bluetooth/mgmt.c +16 -0
@@ -3276,6 +3276,22 @@ int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, MGMT_OP_USER_PASSKEY_NEG_REPLY); } +int mgmt_user_passkey_notify (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 link_type,u8 addr_type,u32 passkey, +u8 entered) +{ +struct mgmt_ev_passkey_notify ev; + +BT_DBG ("%s" , hdev->name); + +bacpy (&ev.addr.bdaddr, bdaddr); + ev.addr.type =link_to_bdaddr (link_type, addr_type); + ev.passkey =__cpu_to_le32 (passkey); + ev.entered = entered; + +return mgmt_event (MGMT_EV_PASSKEY_NOTIFY , hdev, &ev,sizeof (ev),NULL ); +} +int mgmt_auth_failed (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 status) {
Signature · 1 line
1.7.10.4
Hi Johan,
Quoted 74 lines
This patch adds support for Secure Simple Pairing with devices that have KeyboardOnly as their IO capability. Such devices will cause a passkey notification on our side and optionally also keypress notifications. Without this patch some keyboards cannot be paired using the mgmt interface.
Signed-off-by Johan Hedberg <[email protected]>---
v2: Make the keypress switch statement consistent with the rest of the codeinclude/net/bluetooth/hci.h | 18 ++++++++++ include/net/bluetooth/hci_core.h | 5 +++ include/net/bluetooth/mgmt.h | 7 ++++ net/bluetooth/hci_event.c | 67 ++++++++++++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 16 +++++++++ 5 files changed, 113 insertions(+)include/net/bluetooth/hci.h +18
-0@@ -1249,6 +1249,24 @@ struct hci_ev_simple_pair_complete {bdaddr_t bdaddr; } __packed; +#define HCI_EV_USER_PASSKEY_NOTIFY 0x3b +struct hci_ev_user_passkey_notify { +bdaddr_t bdaddr; +__le32 passkey; +} __packed; + +#define HCI_KEYPRESS_STARTED 0 +#define HCI_KEYPRESS_ENTERED 1 +#define HCI_KEYPRESS_ERASED 2 +#define HCI_KEYPRESS_CLEARED 3 +#define HCI_KEYPRESS_COMPLETED 4 + +#define HCI_EV_KEYPRESS_NOTIFY 0x3c +struct hci_ev_keypress_notify { +bdaddr_t bdaddr; +__u8 type; +} __packed; +#define HCI_EV_REMOTE_HOST_FEATURES 0x3dstruct hci_ev_remote_host_features {bdaddr_t bdaddr;include/net/bluetooth/hci_core.h +5
-0@@ -303,6 +303,8 @@ struct hci_conn {__u8 pin_length;__u8 enc_key_size;__u8 io_capability; +__u32 passkey_notify; +__u8 passkey_entered;__u16 disc_timeout;unsigned long flags;@@ -1016,6 +1018,9 @@ int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, u8 addr_type, u8 status);int mgmt_user_passkey_neg_reply_complete (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 status); +int mgmt_user_passkey_notify (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 link_type,u8 addr_type,u32 passkey, +u8 entered);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);include/net/bluetooth/mgmt.h +0
-0
include/net/bluetooth/mgmt.h struct mgmt_ev_device_unblocked { · line 487
Quoted 10 lines
include/net/bluetooth/mgmt.h +7
-0@@ -478,3 +478,10 @@ struct mgmt_ev_device_unblocked {struct mgmt_ev_device_unpaired {struct mgmt_addr_info addr; } __packed; + +#define MGMT_EV_PASSKEY_NOTIFY 0x0017 +struct mgmt_ev_passkey_notify { +struct mgmt_addr_info addr; +__le32 passkey; +__u8 entered; +} __packed;
you need to add this to mgmt_events[] as well.
And we need an extra follow on patch that increases the API revision. However only one of the revision increases per kernel release please.
Otherwise this looks fine to me.
Regards
Marcel