Linux-Bluetooth Archive on lore.kernel.org
 help / Atom feed
* [PATCH] LE Ping: Changes implement LE Ping feature
@ 2018-12-28  4:15 SpoorthiX K
  2018-12-28  4:41 ` kbuild test robot
  2018-12-29  7:33 ` Marcel Holtmann
  0 siblings, 2 replies; 3+ messages in thread
From: SpoorthiX K @ 2018-12-28  4:15 UTC (permalink / raw)
  To: linux-bluetooth

From: SpoorthiX <spoorthix.k@intel.com>

As per the Core Specification 5.0, Volume 2, Part E, Section 7.3.94
the following code changes implements HCI Write Authenticated Payload Timeout
command for LE Ping feature.

Signed-off-by: SpoorthiX <spoorthix.k@intel.com>
---
 include/net/bluetooth/hci.h  |  6 +++
 include/net/bluetooth/mgmt.h |  9 +++++
 net/bluetooth/hci_event.c    | 28 ++++++++++++++
 net/bluetooth/mgmt.c         | 92 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 135 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index c36dc1e..c2a8080 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1130,6 +1130,12 @@ struct hci_cp_write_sc_support {
 	__u8	support;
 } __packed;
 
+#define HCI_OP_WRITE_AUTH_PAYLOAD_TO    0x0c7c
+struct hci_cp_write_auth_payload_to {
+        __u16	conn_handle;
+        __u16   timeout;
+} __packed;
+
 #define HCI_OP_READ_LOCAL_OOB_EXT_DATA	0x0c7d
 struct hci_rp_read_local_oob_ext_data {
 	__u8     status;
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 9cee7dd..22c3052 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -654,6 +654,15 @@ struct mgmt_cp_set_phy_confguration {
 } __packed;
 #define MGMT_SET_PHY_CONFIGURATION_SIZE	4
 
+
+#define MGMT_OP_WRITE_AUTH_PAYLOAD_TO   0x0046
+struct mgmt_cp_write_auth_payload_to {
+       __le16  conn_handle;
+       __le16  auth_to;
+} __packed;
+#define MGMT_OP_WRITE_AUTH_PAYLOAD_TO_SIZE  4
+
+
 #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 ef9928d..eef7025 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1183,6 +1183,29 @@ static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_dev_unlock(hdev);
 }
 
+
+static void hci_cc_write_auth_payload_to (struct hci_dev *hdev, struct sk_buff *skb)
+{
+        __u8 status = *((__u8 *) skb->data);
+        struct hci_cp_write_auth_payload_to *cp;
+        struct hci_conn *conn;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, status);
+
+        if (status)
+                return;
+
+        cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO);
+        if (!cp)
+                return;
+
+        hci_dev_lock(hdev);
+
+        conn->handle = cp->conn_handle;
+
+        hci_dev_unlock(hdev);
+}
+
 static void hci_cc_le_set_ext_scan_param(struct hci_dev *hdev,
 					 struct sk_buff *skb)
 {
@@ -5913,6 +5936,7 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_remote_oob_data_request_evt(hdev, skb);
 		break;
 
+
 #if IS_ENABLED(CONFIG_BT_HS)
 	case HCI_EV_CHANNEL_SELECTED:
 		hci_chan_selected_evt(hdev, skb);
@@ -5939,6 +5963,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_num_comp_blocks_evt(hdev, skb);
 		break;
 
+        case HCI_OP_WRITE_AUTH_PAYLOAD_TO:
+                hci_cc_write_auth_payload_to(hdev, skb);
+                break;
+
 	default:
 		BT_DBG("%s event 0x%2.2x", hdev->name, event);
 		break;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index ccce954..ae6480e9 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -106,6 +106,7 @@
 	MGMT_OP_START_LIMITED_DISCOVERY,
 	MGMT_OP_READ_EXT_INFO,
 	MGMT_OP_SET_APPEARANCE,
+	MGMT_OP_WRITE_AUTH_PAYLOAD_TO,
 };
 
 static const u16 mgmt_events[] = {
@@ -3595,6 +3596,96 @@ static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status,
 	mgmt_pending_remove(cmd);
 }
 
+static void write_auth_payload_to_complete(struct hci_dev *hdev, u8 status,
+                                     u16 opcode, struct sk_buff *skb)
+{
+        struct mgmt_cp_write_auth_payload_to *cp;
+        struct mgmt_pending_cmd *cmd;
+        BT_DBG("");
+        BT_INFO("status 0x%02x\n", status);
+
+        hci_dev_lock(hdev);
+
+        cmd = pending_find(MGMT_OP_WRITE_AUTH_PAYLOAD_TO, hdev);
+        if (!cmd)
+                goto unlock;
+        cp = cmd->param;
+
+        if (status) {
+                mgmt_cmd_status(cmd->sk, hdev->id,
+                                MGMT_OP_WRITE_AUTH_PAYLOAD_TO,
+                                mgmt_status(status));
+        } else {
+                mgmt_cmd_complete(cmd->sk, hdev->id,
+                                  MGMT_OP_WRITE_AUTH_PAYLOAD_TO, 0,
+                                  NULL, 0);
+        }
+
+        mgmt_pending_remove(cmd);
+
+unlock:
+        hci_dev_unlock(hdev);
+}
+
+
+static int write_auth_payload_to(struct sock *sk, struct hci_dev *hdev, void *data,
+                      u16 len)
+{
+	struct mgmt_cp_write_auth_payload_to *cp = data;
+	struct hci_cp_write_auth_payload_to cp_payload;
+	struct mgmt_pending_cmd *cmd;
+	struct hci_request req;
+	u16 handle;
+	u16 timeout;
+	int err;
+
+	hci_dev_lock(hdev);
+	if (!hdev_is_powered(hdev)) {
+		err = mgmt_cmd_status(sk, hdev->id,
+                                     MGMT_OP_WRITE_AUTH_PAYLOAD_TO,
+                                     MGMT_STATUS_REJECTED);
+		goto unlock;
+	}
+
+	if (pending_find(MGMT_OP_WRITE_AUTH_PAYLOAD_TO, hdev)) {
+		err = mgmt_cmd_status(sk, hdev->id,
+                                     MGMT_OP_WRITE_AUTH_PAYLOAD_TO,
+                                     MGMT_STATUS_BUSY);
+		goto unlock;
+	}
+
+	err = mgmt_cmd_complete(sk, hdev->id,
+                                       MGMT_OP_WRITE_AUTH_PAYLOAD_TO,
+                                       0, NULL, 0);
+
+	cmd = mgmt_pending_add(sk, MGMT_OP_WRITE_AUTH_PAYLOAD_TO, hdev, data,
+                              len);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto unlock;
+	}
+	hci_req_init(&req, hdev);
+
+	handle = cp->conn_handle;
+	timeout = cp->auth_to;
+
+	memset(&cp_payload, 0, sizeof(cp_payload));
+
+	cp_payload.conn_handle = handle;
+	cp_payload.timeout = timeout;
+
+	hci_req_add(&req, HCI_OP_WRITE_AUTH_PAYLOAD_TO, sizeof(cp_payload), &cp_payload);
+
+	err = hci_req_run_skb(&req, write_auth_payload_to_complete);
+	if (err < 0)
+		mgmt_pending_remove(cmd);
+
+unlock:
+	hci_dev_unlock(hdev);
+	return err;
+}
+
+
 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
 			       void *data, u16 data_len)
 {
@@ -6921,6 +7012,7 @@ static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev,
 	{ set_appearance,	   MGMT_SET_APPEARANCE_SIZE },
 	{ get_phy_configuration,   MGMT_GET_PHY_CONFIGURATION_SIZE },
 	{ set_phy_configuration,   MGMT_SET_PHY_CONFIGURATION_SIZE },
+	{ write_auth_payload_to,   MGMT_OP_WRITE_AUTH_PAYLOAD_TO_SIZE },
 };
 
 void mgmt_index_added(struct hci_dev *hdev)
-- 
1.9.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] LE Ping: Changes implement LE Ping feature
  2018-12-28  4:15 [PATCH] LE Ping: Changes implement LE Ping feature SpoorthiX K
@ 2018-12-28  4:41 ` kbuild test robot
  2018-12-29  7:33 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2018-12-28  4:41 UTC (permalink / raw)
  To: SpoorthiX K; +Cc: kbuild-all, linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 1295 bytes --]

Hi SpoorthiX,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on v4.20 next-20181224]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SpoorthiX-K/LE-Ping-Changes-implement-LE-Ping-feature/20181228-121443
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: i386-randconfig-x073-201851 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   net/bluetooth/hci_event.c: In function 'hci_event_packet':
>> net/bluetooth/hci_event.c:5972:9: warning: case label value exceeds maximum value for type
            case HCI_OP_WRITE_AUTH_PAYLOAD_TO:
            ^~~~

vim +5972 net/bluetooth/hci_event.c

  5967	
  5968		case HCI_EV_NUM_COMP_BLOCKS:
  5969			hci_num_comp_blocks_evt(hdev, skb);
  5970			break;
  5971	
> 5972	        case HCI_OP_WRITE_AUTH_PAYLOAD_TO:

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 29852 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] LE Ping: Changes implement LE Ping feature
  2018-12-28  4:15 [PATCH] LE Ping: Changes implement LE Ping feature SpoorthiX K
  2018-12-28  4:41 ` kbuild test robot
@ 2018-12-29  7:33 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2018-12-29  7:33 UTC (permalink / raw)
  To: SpoorthiX K; +Cc: linux-bluetooth

Hi,

> As per the Core Specification 5.0, Volume 2, Part E, Section 7.3.94
> the following code changes implements HCI Write Authenticated Payload Timeout
> command for LE Ping feature.
> 
> Signed-off-by: SpoorthiX <spoorthix.k@intel.com>
> ---
> include/net/bluetooth/hci.h  |  6 +++
> include/net/bluetooth/mgmt.h |  9 +++++
> net/bluetooth/hci_event.c    | 28 ++++++++++++++
> net/bluetooth/mgmt.c         | 92 ++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 135 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index c36dc1e..c2a8080 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -1130,6 +1130,12 @@ struct hci_cp_write_sc_support {
> 	__u8	support;
> } __packed;
> 
> +#define HCI_OP_WRITE_AUTH_PAYLOAD_TO    0x0c7c
> +struct hci_cp_write_auth_payload_to {
> +        __u16	conn_handle;
> +        __u16   timeout;
> +} __packed;
> +
> #define HCI_OP_READ_LOCAL_OOB_EXT_DATA	0x0c7d
> struct hci_rp_read_local_oob_ext_data {
> 	__u8     status;
> diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
> index 9cee7dd..22c3052 100644
> --- a/include/net/bluetooth/mgmt.h
> +++ b/include/net/bluetooth/mgmt.h
> @@ -654,6 +654,15 @@ struct mgmt_cp_set_phy_confguration {
> } __packed;
> #define MGMT_SET_PHY_CONFIGURATION_SIZE	4
> 
> +
> +#define MGMT_OP_WRITE_AUTH_PAYLOAD_TO   0x0046
> +struct mgmt_cp_write_auth_payload_to {
> +       __le16  conn_handle;
> +       __le16  auth_to;
> +} __packed;
> +#define MGMT_OP_WRITE_AUTH_PAYLOAD_TO_SIZE  4

there is no benefit for this kind of pass-through MGMT -> HCI. If you want to provide a default auth timeout that then gets programmed to every connection, fine, but this is of no use. bluetoothd will not track a connection and then change the auth timeout. And even if we would provide an API for that, then it would be done through the L2CAP socket that has an underlying HCI connection.

Regards

Marcel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-28  4:15 [PATCH] LE Ping: Changes implement LE Ping feature SpoorthiX K
2018-12-28  4:41 ` kbuild test robot
2018-12-29  7:33 ` Marcel Holtmann

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox