All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] [v5]Add support for LE ping feature
  2019-04-24  8:17 [PATCH] [v5]Add support for LE ping feature SpoorthiX K
@ 2019-04-24  8:11 ` Marcel Holtmann
  2019-04-25 12:18 ` kbuild test robot
  2019-04-25 12:25 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2019-04-24  8:11 UTC (permalink / raw)
  To: SpoorthiX K; +Cc: linux-bluetooth

Hi Spoorthi,

> Changes made to add HCI Write Authenticated Payload timeout
> command for LE Ping feature.
> 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: Spoorthi Ravishankar Koppad <spoorthix.k@intel.com>
> ---
> include/net/bluetooth/hci.h      | 10 ++++++++++
> include/net/bluetooth/hci_core.h |  1 +
> net/bluetooth/hci_core.c         |  1 +
> net/bluetooth/hci_debugfs.c      | 29 +++++++++++++++++++++++++++
> net/bluetooth/hci_event.c        | 42 ++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 83 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index c36dc1e..366d2c7 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -1130,6 +1130,16 @@ struct hci_cp_write_sc_support {
> 	__u8	support;
> } __packed;
> 
> +#define HCI_OP_WRITE_AUTH_PAYLOAD_TO    0x0c7c
> +struct hci_cp_write_auth_payload_to {
> +	__le16  handle;
> +	__le16  timeout;
> +} __packed;
> +struct hci_rp_write_auth_payload_to {
> +	__u8    status;
> +	__le16  handle;
> +} __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/hci_core.h b/include/net/bluetooth/hci_core.h
> index e5ea633..57ec424 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -421,6 +421,7 @@ struct hci_dev {
> 	__u32			rpa_timeout;
> 	struct delayed_work	rpa_expired;
> 	bdaddr_t		rpa;
> +	__u16			auth_payload_timeout;
> 
> #if IS_ENABLED(CONFIG_BT_LEDS)
> 	struct led_trigger	*power_led;
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 7352fe8..402bbf9 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -3147,6 +3147,7 @@ struct hci_dev *hci_alloc_dev(void)
> 	hdev->le_max_tx_time = 0x0148;
> 	hdev->le_max_rx_len = 0x001b;
> 	hdev->le_max_rx_time = 0x0148;
> +	hdev->auth_payload_timeout = 0x0bb8;
> 	hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE;
> 	hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE;
> 	hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M;
> diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c
> index 51f5b1e..930f01f 100644
> --- a/net/bluetooth/hci_debugfs.c
> +++ b/net/bluetooth/hci_debugfs.c
> @@ -941,6 +941,33 @@ static int adv_max_interval_get(void *data, u64 *val)
> DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
> 			adv_max_interval_set, "%llu\n");
> 
> +static int auth_payload_timeout_set(void *data, u64 val)
> +{
> +	struct hci_dev *hdev = data;
> +
> +	if (val < 0x0001 || val > 0xffff)
> +		return -EINVAL;
> +	hci_dev_lock(hdev);
> +	hdev->auth_payload_timeout = val;
> +	hci_dev_unlock(hdev);
> +
> +	return 0;
> +}
> +
> +static int auth_payload_timeout_get(void *data, u64 *val)
> +{
> +	struct hci_dev *hdev = data;
> +
> +	hci_dev_lock(hdev);
> +	*val = hdev->auth_payload_timeout;
> +	hci_dev_unlock(hdev);
> +	return 0;
> +}
> +
> +DEFINE_SIMPLE_ATTRIBUTE(auth_payload_timeout_fops,
> +			auth_payload_timeout_get,
> +			auth_payload_timeout_set, "%llu\n");
> +
> DEFINE_QUIRK_ATTRIBUTE(quirk_strict_duplicate_filter,
> 		       HCI_QUIRK_STRICT_DUPLICATE_FILTER);
> DEFINE_QUIRK_ATTRIBUTE(quirk_simultaneous_discovery,
> @@ -995,6 +1022,8 @@ void hci_debugfs_create_le(struct hci_dev *hdev)
> 	debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
> 			   &hdev->discov_interleaved_timeout);
> 
> +	debugfs_create_file("auth_payload_timeout", 0644, hdev->debugfs, hdev,
> +			    &auth_payload_timeout_fops);
> 	debugfs_create_file("quirk_strict_duplicate_filter", 0644,
> 			    hdev->debugfs, hdev,
> 			    &quirk_strict_duplicate_filter_fops);
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index ac2826c..ecc5ea1 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -579,6 +579,25 @@ static void hci_cc_read_local_commands(struct hci_dev *hdev,
> 		memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
> }
> 
> +static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev,
> +						struct sk_buff *skb)
> +{
> +	struct hci_rp_write_auth_payload_to *rp = (void *)skb->data;
> +	struct hci_conn *conn;
> +
> +	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
> +	if (rp->status)
> +		return;
> +	hci_dev_lock(hdev);
> +
> +	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
> +	if (conn)
> +		set_bit(HCI_CONN_AUTH_PAYLOAD_TIMEOUT, &conn->flags);

you totally ignored my comment here.

> +
> +	hci_dev_unlock(hdev);
> +}
> +
> +
> static void hci_cc_read_local_features(struct hci_dev *hdev,
> 				       struct sk_buff *skb)
> {
> @@ -2975,6 +2994,25 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
> 		goto unlock;
> 	}
> 
> +	/* Set the default Authenticated Payload Timeout after
> +	 * an LE Link is established. As per Core Spec v5.0, Vol 2, Part B
> +	 * Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be
> +	 * sent when the link is active and Encryption is enabled, the conn
> +	 * type can be either LE or ACL and controller must support LMP Ping.
> +	 * Ensure for AES-CCM encryption as well.
> +	 */
> +	if ((conn->type == LE_LINK || conn->type == ACL_LINK) &&
> +	    lmp_ping_capable(hdev) && (hdev->le_features[0] & HCI_LE_PING)
> +	     test_bit(HCI_CONN_ENCRYPT, &conn->flags) &&
> +	      test_bit(HCI_CONN_AES_CCM, &conn->flags)) {
> +		struct hci_cp_write_auth_payload_to cp;


This is a) wrongly indented and b) not even compile tested.

> +
> +		cp.handle = cpu_to_le16(conn->handle);
> +		cp.timeout = cpu_to_le16(hdev->auth_payload_timeout);
> +		hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO,
> +			     sizeof(cp), &cp);
> +	}
> +
> notify:
> 	if (conn->state == BT_CONFIG) {
> 		if (!ev->status)
> @@ -3178,6 +3216,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
> 		hci_cc_read_local_commands(hdev, skb);
> 		break;
> 
> +	case HCI_OP_WRITE_AUTH_PAYLOAD_TO:
> +		hci_cc_write_auth_payload_timeout(hdev, skb);
> +		break;
> +
> 	case HCI_OP_READ_LOCAL_FEATURES:
> 		hci_cc_read_local_features(hdev, skb);
> 		break;

Regards

Marcel


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

* [PATCH] [v5]Add support for LE ping feature
@ 2019-04-24  8:17 SpoorthiX K
  2019-04-24  8:11 ` Marcel Holtmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SpoorthiX K @ 2019-04-24  8:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Spoorthi Ravishankar Koppad <spoorthix.k@intel.com>

Changes made to add HCI Write Authenticated Payload timeout
command for LE Ping feature.
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: Spoorthi Ravishankar Koppad <spoorthix.k@intel.com>
---
 include/net/bluetooth/hci.h      | 10 ++++++++++
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_core.c         |  1 +
 net/bluetooth/hci_debugfs.c      | 29 +++++++++++++++++++++++++++
 net/bluetooth/hci_event.c        | 42 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 83 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index c36dc1e..366d2c7 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1130,6 +1130,16 @@ struct hci_cp_write_sc_support {
 	__u8	support;
 } __packed;
 
+#define HCI_OP_WRITE_AUTH_PAYLOAD_TO    0x0c7c
+struct hci_cp_write_auth_payload_to {
+	__le16  handle;
+	__le16  timeout;
+} __packed;
+struct hci_rp_write_auth_payload_to {
+	__u8    status;
+	__le16  handle;
+} __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/hci_core.h b/include/net/bluetooth/hci_core.h
index e5ea633..57ec424 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -421,6 +421,7 @@ struct hci_dev {
 	__u32			rpa_timeout;
 	struct delayed_work	rpa_expired;
 	bdaddr_t		rpa;
+	__u16			auth_payload_timeout;
 
 #if IS_ENABLED(CONFIG_BT_LEDS)
 	struct led_trigger	*power_led;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 7352fe8..402bbf9 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3147,6 +3147,7 @@ struct hci_dev *hci_alloc_dev(void)
 	hdev->le_max_tx_time = 0x0148;
 	hdev->le_max_rx_len = 0x001b;
 	hdev->le_max_rx_time = 0x0148;
+	hdev->auth_payload_timeout = 0x0bb8;
 	hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE;
 	hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE;
 	hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M;
diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c
index 51f5b1e..930f01f 100644
--- a/net/bluetooth/hci_debugfs.c
+++ b/net/bluetooth/hci_debugfs.c
@@ -941,6 +941,33 @@ static int adv_max_interval_get(void *data, u64 *val)
 DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
 			adv_max_interval_set, "%llu\n");
 
+static int auth_payload_timeout_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+
+	if (val < 0x0001 || val > 0xffff)
+		return -EINVAL;
+	hci_dev_lock(hdev);
+	hdev->auth_payload_timeout = val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int auth_payload_timeout_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->auth_payload_timeout;
+	hci_dev_unlock(hdev);
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(auth_payload_timeout_fops,
+			auth_payload_timeout_get,
+			auth_payload_timeout_set, "%llu\n");
+
 DEFINE_QUIRK_ATTRIBUTE(quirk_strict_duplicate_filter,
 		       HCI_QUIRK_STRICT_DUPLICATE_FILTER);
 DEFINE_QUIRK_ATTRIBUTE(quirk_simultaneous_discovery,
@@ -995,6 +1022,8 @@ void hci_debugfs_create_le(struct hci_dev *hdev)
 	debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
 			   &hdev->discov_interleaved_timeout);
 
+	debugfs_create_file("auth_payload_timeout", 0644, hdev->debugfs, hdev,
+			    &auth_payload_timeout_fops);
 	debugfs_create_file("quirk_strict_duplicate_filter", 0644,
 			    hdev->debugfs, hdev,
 			    &quirk_strict_duplicate_filter_fops);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index ac2826c..ecc5ea1 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -579,6 +579,25 @@ static void hci_cc_read_local_commands(struct hci_dev *hdev,
 		memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
 }
 
+static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev,
+						struct sk_buff *skb)
+{
+	struct hci_rp_write_auth_payload_to *rp = (void *)skb->data;
+	struct hci_conn *conn;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
+	if (rp->status)
+		return;
+	hci_dev_lock(hdev);
+
+	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
+	if (conn)
+		set_bit(HCI_CONN_AUTH_PAYLOAD_TIMEOUT, &conn->flags);
+
+	hci_dev_unlock(hdev);
+}
+
+
 static void hci_cc_read_local_features(struct hci_dev *hdev,
 				       struct sk_buff *skb)
 {
@@ -2975,6 +2994,25 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		goto unlock;
 	}
 
+	/* Set the default Authenticated Payload Timeout after
+	 * an LE Link is established. As per Core Spec v5.0, Vol 2, Part B
+	 * Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be
+	 * sent when the link is active and Encryption is enabled, the conn
+	 * type can be either LE or ACL and controller must support LMP Ping.
+	 * Ensure for AES-CCM encryption as well.
+	 */
+	if ((conn->type == LE_LINK || conn->type == ACL_LINK) &&
+	    lmp_ping_capable(hdev) && (hdev->le_features[0] & HCI_LE_PING)
+	     test_bit(HCI_CONN_ENCRYPT, &conn->flags) &&
+	      test_bit(HCI_CONN_AES_CCM, &conn->flags)) {
+		struct hci_cp_write_auth_payload_to cp;
+
+		cp.handle = cpu_to_le16(conn->handle);
+		cp.timeout = cpu_to_le16(hdev->auth_payload_timeout);
+		hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO,
+			     sizeof(cp), &cp);
+	}
+
 notify:
 	if (conn->state == BT_CONFIG) {
 		if (!ev->status)
@@ -3178,6 +3216,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
 		hci_cc_read_local_commands(hdev, skb);
 		break;
 
+	case HCI_OP_WRITE_AUTH_PAYLOAD_TO:
+		hci_cc_write_auth_payload_timeout(hdev, skb);
+		break;
+
 	case HCI_OP_READ_LOCAL_FEATURES:
 		hci_cc_read_local_features(hdev, skb);
 		break;
-- 
1.9.1


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

* Re: [PATCH] [v5]Add support for LE ping feature
  2019-04-24  8:17 [PATCH] [v5]Add support for LE ping feature SpoorthiX K
  2019-04-24  8:11 ` Marcel Holtmann
@ 2019-04-25 12:18 ` kbuild test robot
  2019-04-25 12:25 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2019-04-25 12:18 UTC (permalink / raw)
  To: SpoorthiX K; +Cc: kbuild-all, linux-bluetooth

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

Hi SpoorthiX,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on v5.1-rc6 next-20190424]
[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/Add-support-for-LE-ping-feature/20190425-184628
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: i386-randconfig-x074-201916 (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 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   net/bluetooth/hci_event.c: In function 'hci_cc_write_auth_payload_timeout':
>> net/bluetooth/hci_event.c:595:11: error: 'HCI_CONN_AUTH_PAYLOAD_TIMEOUT' undeclared (first use in this function); did you mean 'HCI_CONN_AUTH_FAILURE'?
      set_bit(HCI_CONN_AUTH_PAYLOAD_TIMEOUT, &conn->flags);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              HCI_CONN_AUTH_FAILURE
   net/bluetooth/hci_event.c:595:11: note: each undeclared identifier is reported only once for each function it appears in
   net/bluetooth/hci_event.c: In function 'hci_encrypt_change_evt':
>> net/bluetooth/hci_event.c:3005:54: error: called object is not a function or function pointer
         lmp_ping_capable(hdev) && (hdev->le_features[0] & HCI_LE_PING)
                                   ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

vim +595 net/bluetooth/hci_event.c

   581	
   582	static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev,
   583							struct sk_buff *skb)
   584	{
   585		struct hci_rp_write_auth_payload_to *rp = (void *)skb->data;
   586		struct hci_conn *conn;
   587	
   588		BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
   589		if (rp->status)
   590			return;
   591		hci_dev_lock(hdev);
   592	
   593		conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
   594		if (conn)
 > 595			set_bit(HCI_CONN_AUTH_PAYLOAD_TIMEOUT, &conn->flags);
   596	
   597		hci_dev_unlock(hdev);
   598	}
   599	

---
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: 31348 bytes --]

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

* Re: [PATCH] [v5]Add support for LE ping feature
  2019-04-24  8:17 [PATCH] [v5]Add support for LE ping feature SpoorthiX K
  2019-04-24  8:11 ` Marcel Holtmann
  2019-04-25 12:18 ` kbuild test robot
@ 2019-04-25 12:25 ` kbuild test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2019-04-25 12:25 UTC (permalink / raw)
  To: SpoorthiX K; +Cc: kbuild-all, linux-bluetooth

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

Hi SpoorthiX,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on v5.1-rc6 next-20190424]
[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/Add-support-for-LE-ping-feature/20190425-184628
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.1.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=8.1.0 make.cross ARCH=xtensa 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   net//bluetooth/hci_event.c: In function 'hci_cc_write_auth_payload_timeout':
   net//bluetooth/hci_event.c:595:11: error: 'HCI_CONN_AUTH_PAYLOAD_TIMEOUT' undeclared (first use in this function); did you mean 'HCI_CONN_AUTH_FAILURE'?
      set_bit(HCI_CONN_AUTH_PAYLOAD_TIMEOUT, &conn->flags);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              HCI_CONN_AUTH_FAILURE
   net//bluetooth/hci_event.c:595:11: note: each undeclared identifier is reported only once for each function it appears in
   net//bluetooth/hci_event.c: In function 'hci_encrypt_change_evt':
>> net//bluetooth/hci_event.c:3005:68: error: expected ')' before 'test_bit'
         lmp_ping_capable(hdev) && (hdev->le_features[0] & HCI_LE_PING)
                                                                       ^
                                                                       )
          test_bit(HCI_CONN_ENCRYPT, &conn->flags) &&
          ~~~~~~~~                                                      
   net//bluetooth/hci_event.c:3004:5: note: to match this '('
     if ((conn->type == LE_LINK || conn->type == ACL_LINK) &&
        ^

vim +3005 net//bluetooth/hci_event.c

  2904	
  2905	static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
  2906	{
  2907		struct hci_ev_encrypt_change *ev = (void *) skb->data;
  2908		struct hci_conn *conn;
  2909	
  2910		BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
  2911	
  2912		hci_dev_lock(hdev);
  2913	
  2914		conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
  2915		if (!conn)
  2916			goto unlock;
  2917	
  2918		if (!ev->status) {
  2919			if (ev->encrypt) {
  2920				/* Encryption implies authentication */
  2921				set_bit(HCI_CONN_AUTH, &conn->flags);
  2922				set_bit(HCI_CONN_ENCRYPT, &conn->flags);
  2923				conn->sec_level = conn->pending_sec_level;
  2924	
  2925				/* P-256 authentication key implies FIPS */
  2926				if (conn->key_type == HCI_LK_AUTH_COMBINATION_P256)
  2927					set_bit(HCI_CONN_FIPS, &conn->flags);
  2928	
  2929				if ((conn->type == ACL_LINK && ev->encrypt == 0x02) ||
  2930				    conn->type == LE_LINK)
  2931					set_bit(HCI_CONN_AES_CCM, &conn->flags);
  2932			} else {
  2933				clear_bit(HCI_CONN_ENCRYPT, &conn->flags);
  2934				clear_bit(HCI_CONN_AES_CCM, &conn->flags);
  2935			}
  2936		}
  2937	
  2938		/* We should disregard the current RPA and generate a new one
  2939		 * whenever the encryption procedure fails.
  2940		 */
  2941		if (ev->status && conn->type == LE_LINK) {
  2942			hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
  2943			hci_adv_instances_set_rpa_expired(hdev, true);
  2944		}
  2945	
  2946		clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
  2947	
  2948		if (ev->status && conn->state == BT_CONNECTED) {
  2949			if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING)
  2950				set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags);
  2951	
  2952			hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
  2953			hci_conn_drop(conn);
  2954			goto unlock;
  2955		}
  2956	
  2957		/* In Secure Connections Only mode, do not allow any connections
  2958		 * that are not encrypted with AES-CCM using a P-256 authenticated
  2959		 * combination key.
  2960		 */
  2961		if (hci_dev_test_flag(hdev, HCI_SC_ONLY) &&
  2962		    (!test_bit(HCI_CONN_AES_CCM, &conn->flags) ||
  2963		     conn->key_type != HCI_LK_AUTH_COMBINATION_P256)) {
  2964			hci_connect_cfm(conn, HCI_ERROR_AUTH_FAILURE);
  2965			hci_conn_drop(conn);
  2966			goto unlock;
  2967		}
  2968	
  2969		/* Try reading the encryption key size for encrypted ACL links */
  2970		if (!ev->status && ev->encrypt && conn->type == ACL_LINK) {
  2971			struct hci_cp_read_enc_key_size cp;
  2972			struct hci_request req;
  2973	
  2974			/* Only send HCI_Read_Encryption_Key_Size if the
  2975			 * controller really supports it. If it doesn't, assume
  2976			 * the default size (16).
  2977			 */
  2978			if (!(hdev->commands[20] & 0x10)) {
  2979				conn->enc_key_size = HCI_LINK_KEY_SIZE;
  2980				goto notify;
  2981			}
  2982	
  2983			hci_req_init(&req, hdev);
  2984	
  2985			cp.handle = cpu_to_le16(conn->handle);
  2986			hci_req_add(&req, HCI_OP_READ_ENC_KEY_SIZE, sizeof(cp), &cp);
  2987	
  2988			if (hci_req_run_skb(&req, read_enc_key_size_complete)) {
  2989				bt_dev_err(hdev, "sending read key size failed");
  2990				conn->enc_key_size = HCI_LINK_KEY_SIZE;
  2991				goto notify;
  2992			}
  2993	
  2994			goto unlock;
  2995		}
  2996	
  2997		/* Set the default Authenticated Payload Timeout after
  2998		 * an LE Link is established. As per Core Spec v5.0, Vol 2, Part B
  2999		 * Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be
  3000		 * sent when the link is active and Encryption is enabled, the conn
  3001		 * type can be either LE or ACL and controller must support LMP Ping.
  3002		 * Ensure for AES-CCM encryption as well.
  3003		 */
  3004		if ((conn->type == LE_LINK || conn->type == ACL_LINK) &&
> 3005		    lmp_ping_capable(hdev) && (hdev->le_features[0] & HCI_LE_PING)
  3006		     test_bit(HCI_CONN_ENCRYPT, &conn->flags) &&
  3007		      test_bit(HCI_CONN_AES_CCM, &conn->flags)) {
  3008			struct hci_cp_write_auth_payload_to cp;
  3009	
  3010			cp.handle = cpu_to_le16(conn->handle);
  3011			cp.timeout = cpu_to_le16(hdev->auth_payload_timeout);
  3012			hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO,
  3013				     sizeof(cp), &cp);
  3014		}
  3015	
  3016	notify:
  3017		if (conn->state == BT_CONFIG) {
  3018			if (!ev->status)
  3019				conn->state = BT_CONNECTED;
  3020	
  3021			hci_connect_cfm(conn, ev->status);
  3022			hci_conn_drop(conn);
  3023		} else
  3024			hci_encrypt_cfm(conn, ev->status, ev->encrypt);
  3025	
  3026	unlock:
  3027		hci_dev_unlock(hdev);
  3028	}
  3029	

---
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: 56156 bytes --]

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

end of thread, other threads:[~2019-04-25 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-24  8:17 [PATCH] [v5]Add support for LE ping feature SpoorthiX K
2019-04-24  8:11 ` Marcel Holtmann
2019-04-25 12:18 ` kbuild test robot
2019-04-25 12:25 ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.