linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] tester: Refactor Read Local Public Key command
@ 2015-05-18  9:41 Andrei Emeltchenko
  2015-05-18  9:41 ` [PATCH 2/3] tester: Verify DHKey generation Andrei Emeltchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andrei Emeltchenko @ 2015-05-18  9:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Save Local Public Key to calculate DHKey for later tests. Also verify
that Command Status and Meta Event are generated.
---
 tools/hci-tester.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/tools/hci-tester.c b/tools/hci-tester.c
index 460c9a9..9093129 100644
--- a/tools/hci-tester.c
+++ b/tools/hci-tester.c
@@ -46,6 +46,11 @@ struct user_data {
 	uint16_t handle_ut;
 };
 
+struct le_keys {
+	uint8_t remote_sk[32];
+	uint8_t local_pk[64];
+} key_test_data;
+
 static void swap_buf(const uint8_t *src, uint8_t *dst, uint16_t len)
 {
 	int i;
@@ -412,9 +417,61 @@ static void test_le_rand(const void *test_data)
 	test_command(BT_HCI_CMD_LE_RAND);
 }
 
+static void test_le_read_local_pk_complete(const void *data, uint8_t size,
+								void *user_data)
+{
+	const uint8_t *event = data;
+	const struct bt_hci_evt_le_read_local_pk256_complete *evt;
+	struct le_keys *keys = user_data;
+
+	if (*event != BT_HCI_EVT_LE_READ_LOCAL_PK256_COMPLETE) {
+		tester_warn("Failed Read Local PK256 command");
+		tester_test_failed();
+		return;
+	}
+
+	evt = (void *)(event + 1);
+	if (evt->status) {
+		tester_warn("HCI Read Local PK complete failed (0x%02x)",
+								evt->status);
+		tester_test_failed();
+		return;
+	}
+
+	memcpy(keys->local_pk, evt->local_pk256, 64);
+
+	util_hexdump('>', evt->local_pk256, 64, test_debug, NULL);
+
+	tester_test_passed();
+}
+
+static void test_le_read_local_pk_status(const void *data, uint8_t size,
+							void *user_data)
+{
+	uint8_t status = *((uint8_t *) data);
+
+	if (status) {
+		tester_warn("Failed to send DHKey gen cmd (0x%02x)", status);
+		tester_test_failed();
+		return;
+	}
+}
+
 static void test_le_read_local_pk(const void *test_data)
 {
-	test_command(BT_HCI_CMD_LE_READ_LOCAL_PK256);
+	struct user_data *user = tester_get_data();
+
+	bt_hci_register(user->hci_ut, BT_HCI_EVT_LE_META_EVENT,
+				test_le_read_local_pk_complete,
+				(void *)test_data, NULL);
+
+	if (!bt_hci_send(user->hci_ut, BT_HCI_CMD_LE_READ_LOCAL_PK256, NULL,
+				0, test_le_read_local_pk_status,
+				NULL, NULL)) {
+		tester_warn("Failed to send HCI LE Read Local PK256 command");
+		tester_test_failed();
+		return;
+	}
 }
 
 static void test_le_generate_dhkey_complete(const void *data, uint8_t size,
@@ -790,7 +847,7 @@ int main(int argc, char *argv[])
 				test_le_encrypt);
 	test_hci_local("LE Rand", NULL, NULL,
 				test_le_rand);
-	test_hci_local("LE Read Local PK", NULL, NULL,
+	test_hci_local("LE Read Local PK", &key_test_data, NULL,
 				test_le_read_local_pk);
 	test_hci_local("LE Generate DHKey", NULL, NULL,
 				test_le_generate_dhkey);
-- 
2.1.4


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

* [PATCH 2/3] tester: Verify DHKey generation
  2015-05-18  9:41 [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
@ 2015-05-18  9:41 ` Andrei Emeltchenko
  2015-05-18  9:41 ` [PATCH 3/3] btdev: Indicate support for 4.2 encryption commands Andrei Emeltchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Andrei Emeltchenko @ 2015-05-18  9:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Verify that HCI controller correctly generate Diffie-Hellman key.
---
 tools/hci-tester.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 93 insertions(+), 7 deletions(-)

diff --git a/tools/hci-tester.c b/tools/hci-tester.c
index 9093129..75d09f0 100644
--- a/tools/hci-tester.c
+++ b/tools/hci-tester.c
@@ -474,10 +474,70 @@ static void test_le_read_local_pk(const void *test_data)
 	}
 }
 
+static void setup_le_read_local_pk_complete(const void *data, uint8_t size,
+								void *user_data)
+{
+	const uint8_t *event = data;
+	const struct bt_hci_evt_le_read_local_pk256_complete *evt;
+	struct le_keys *keys = user_data;
+
+	if (*event != BT_HCI_EVT_LE_READ_LOCAL_PK256_COMPLETE) {
+		tester_warn("Failed Read Local PK256 command");
+		tester_setup_failed();
+		return;
+	}
+
+	evt = (void *)(event + 1);
+	if (evt->status) {
+		tester_warn("HCI Read Local PK complete failed (0x%02x)",
+								evt->status);
+		tester_setup_failed();
+		return;
+	}
+
+	memcpy(keys->local_pk, evt->local_pk256, 64);
+
+	util_hexdump('>', evt->local_pk256, 64, test_debug, NULL);
+
+	tester_setup_complete();
+}
+
+static void setup_le_read_local_pk_status(const void *data, uint8_t size,
+							void *user_data)
+{
+	uint8_t status = *((uint8_t *) data);
+
+	if (status) {
+		tester_warn("Failed to send DHKey gen cmd (0x%02x)", status);
+		tester_setup_failed();
+		return;
+	}
+}
+
+static void setup_le_generate_dhkey(const void *test_data)
+{
+	struct user_data *user = tester_get_data();
+
+	bt_hci_register(user->hci_ut, BT_HCI_EVT_LE_META_EVENT,
+				setup_le_read_local_pk_complete,
+				(void *)test_data, NULL);
+
+	if (!bt_hci_send(user->hci_ut, BT_HCI_CMD_LE_READ_LOCAL_PK256, NULL,
+				0, setup_le_read_local_pk_status,
+				NULL, NULL)) {
+		tester_warn("Failed to send HCI LE Read Local PK256 command");
+		tester_setup_failed();
+		return;
+	}
+}
+
 static void test_le_generate_dhkey_complete(const void *data, uint8_t size,
 								void *user_data)
 {
 	const uint8_t *event = data;
+	const struct bt_hci_evt_le_generate_dhkey_complete *evt;
+	struct le_keys *keys = user_data;
+	uint8_t dhkey[32];
 
 	if (*event != BT_HCI_EVT_LE_GENERATE_DHKEY_COMPLETE) {
 		tester_warn("Failed DHKey generation command");
@@ -485,11 +545,32 @@ static void test_le_generate_dhkey_complete(const void *data, uint8_t size,
 		return;
 	}
 
-	/* TODO: We have remote secret key and local public key, calculate
-	 * DHKey and compare
+	evt = (void *)(event + 1);
+	if (evt->status) {
+		tester_warn("HCI Generate DHKey complete failed (0x%02x)",
+								evt->status);
+		tester_test_failed();
+		return;
+	}
+
+	util_hexdump('>', evt->dhkey, 32, test_debug, NULL);
+
+
+	util_hexdump('S', keys->remote_sk, 32, test_debug, NULL);
+	util_hexdump('P', keys->local_pk, 64, test_debug, NULL);
+
+	/* Generate DHKey ourself with local public key and remote
+	 * private key we got when generated public / private key
+	 * pair for BT_HCI_CMD_LE_GENERATE_DHKEY argument.
 	 */
+	ecdh_shared_secret(keys->local_pk, keys->remote_sk, dhkey);
 
-	tester_test_passed();
+	util_hexdump('D', dhkey, 32, test_debug, NULL);
+
+	if (!memcmp(dhkey, evt->dhkey, 32))
+		tester_test_passed();
+	else
+		tester_test_failed();
 }
 
 static void test_le_generate_dhkey_status(const void *data, uint8_t size,
@@ -508,12 +589,16 @@ static void test_le_generate_dhkey(const void *test_data)
 {
 	struct user_data *user = tester_get_data();
 	struct bt_hci_cmd_le_generate_dhkey cmd;
-	uint8_t remote_sk[32];
+	struct le_keys *keys = (void *)test_data;
+
+	ecc_make_key(cmd.remote_pk256, keys->remote_sk);
 
-	ecc_make_key(cmd.remote_pk256, remote_sk);
+	/* Unregister handler for META event */
+	bt_hci_unregister(user->hci_ut, 1);
 
 	bt_hci_register(user->hci_ut, BT_HCI_EVT_LE_META_EVENT,
-				test_le_generate_dhkey_complete, NULL, NULL);
+				test_le_generate_dhkey_complete, keys,
+				NULL);
 
 	if (!bt_hci_send(user->hci_ut, BT_HCI_CMD_LE_GENERATE_DHKEY, &cmd,
 				sizeof(cmd), test_le_generate_dhkey_status,
@@ -849,7 +934,8 @@ int main(int argc, char *argv[])
 				test_le_rand);
 	test_hci_local("LE Read Local PK", &key_test_data, NULL,
 				test_le_read_local_pk);
-	test_hci_local("LE Generate DHKey", NULL, NULL,
+	test_hci_local("LE Generate DHKey", &key_test_data,
+				setup_le_generate_dhkey,
 				test_le_generate_dhkey);
 
 	test_hci_local("Inquiry (LIAC)", NULL, NULL, test_inquiry_liac);
-- 
2.1.4


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

* [PATCH 3/3] btdev: Indicate support for 4.2 encryption commands
  2015-05-18  9:41 [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
  2015-05-18  9:41 ` [PATCH 2/3] tester: Verify DHKey generation Andrei Emeltchenko
@ 2015-05-18  9:41 ` Andrei Emeltchenko
  2015-05-21  7:34 ` [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
  2015-05-22 11:48 ` Johan Hedberg
  3 siblings, 0 replies; 5+ messages in thread
From: Andrei Emeltchenko @ 2015-05-18  9:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Indicate btdev support for LE Generate DHKey and LE Read Local P-256
Public Key.
---
 emulator/btdev.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index d9e38b5..7151e89 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -430,6 +430,10 @@ static void set_le_commands(struct btdev *btdev)
 	btdev->commands[28] |= 0x10;	/* LE Receiver Test */
 	btdev->commands[28] |= 0x20;	/* LE Transmitter Test */
 	btdev->commands[28] |= 0x40;	/* LE Test End */
+
+	/* Extra LE commands for >= 4.2 adapters */
+	btdev->commands[34] |= 0x02;	/* LE Read Local P-256 Public Key */
+	btdev->commands[34] |= 0x04;	/* LE Generate DHKey */
 }
 
 static void set_bredrle_commands(struct btdev *btdev)
-- 
2.1.4


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

* Re: [PATCH 1/3] tester: Refactor Read Local Public Key command
  2015-05-18  9:41 [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
  2015-05-18  9:41 ` [PATCH 2/3] tester: Verify DHKey generation Andrei Emeltchenko
  2015-05-18  9:41 ` [PATCH 3/3] btdev: Indicate support for 4.2 encryption commands Andrei Emeltchenko
@ 2015-05-21  7:34 ` Andrei Emeltchenko
  2015-05-22 11:48 ` Johan Hedberg
  3 siblings, 0 replies; 5+ messages in thread
From: Andrei Emeltchenko @ 2015-05-21  7:34 UTC (permalink / raw)
  To: linux-bluetooth

On Mon, May 18, 2015 at 12:41:35PM +0300, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Save Local Public Key to calculate DHKey for later tests. Also verify
> that Command Status and Meta Event are generated.

ping

> ---
>  tools/hci-tester.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 59 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/hci-tester.c b/tools/hci-tester.c
> index 460c9a9..9093129 100644
> --- a/tools/hci-tester.c
> +++ b/tools/hci-tester.c
> @@ -46,6 +46,11 @@ struct user_data {
>  	uint16_t handle_ut;
>  };
>  
> +struct le_keys {
> +	uint8_t remote_sk[32];
> +	uint8_t local_pk[64];
> +} key_test_data;
> +
>  static void swap_buf(const uint8_t *src, uint8_t *dst, uint16_t len)
>  {
>  	int i;
> @@ -412,9 +417,61 @@ static void test_le_rand(const void *test_data)
>  	test_command(BT_HCI_CMD_LE_RAND);
>  }
>  
> +static void test_le_read_local_pk_complete(const void *data, uint8_t size,
> +								void *user_data)
> +{
> +	const uint8_t *event = data;
> +	const struct bt_hci_evt_le_read_local_pk256_complete *evt;
> +	struct le_keys *keys = user_data;
> +
> +	if (*event != BT_HCI_EVT_LE_READ_LOCAL_PK256_COMPLETE) {
> +		tester_warn("Failed Read Local PK256 command");
> +		tester_test_failed();
> +		return;
> +	}
> +
> +	evt = (void *)(event + 1);
> +	if (evt->status) {
> +		tester_warn("HCI Read Local PK complete failed (0x%02x)",
> +								evt->status);
> +		tester_test_failed();
> +		return;
> +	}
> +
> +	memcpy(keys->local_pk, evt->local_pk256, 64);
> +
> +	util_hexdump('>', evt->local_pk256, 64, test_debug, NULL);
> +
> +	tester_test_passed();
> +}
> +
> +static void test_le_read_local_pk_status(const void *data, uint8_t size,
> +							void *user_data)
> +{
> +	uint8_t status = *((uint8_t *) data);
> +
> +	if (status) {
> +		tester_warn("Failed to send DHKey gen cmd (0x%02x)", status);
> +		tester_test_failed();
> +		return;
> +	}
> +}
> +
>  static void test_le_read_local_pk(const void *test_data)
>  {
> -	test_command(BT_HCI_CMD_LE_READ_LOCAL_PK256);
> +	struct user_data *user = tester_get_data();
> +
> +	bt_hci_register(user->hci_ut, BT_HCI_EVT_LE_META_EVENT,
> +				test_le_read_local_pk_complete,
> +				(void *)test_data, NULL);
> +
> +	if (!bt_hci_send(user->hci_ut, BT_HCI_CMD_LE_READ_LOCAL_PK256, NULL,
> +				0, test_le_read_local_pk_status,
> +				NULL, NULL)) {
> +		tester_warn("Failed to send HCI LE Read Local PK256 command");
> +		tester_test_failed();
> +		return;
> +	}
>  }
>  
>  static void test_le_generate_dhkey_complete(const void *data, uint8_t size,
> @@ -790,7 +847,7 @@ int main(int argc, char *argv[])
>  				test_le_encrypt);
>  	test_hci_local("LE Rand", NULL, NULL,
>  				test_le_rand);
> -	test_hci_local("LE Read Local PK", NULL, NULL,
> +	test_hci_local("LE Read Local PK", &key_test_data, NULL,
>  				test_le_read_local_pk);
>  	test_hci_local("LE Generate DHKey", NULL, NULL,
>  				test_le_generate_dhkey);
> -- 
> 2.1.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/3] tester: Refactor Read Local Public Key command
  2015-05-18  9:41 [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
                   ` (2 preceding siblings ...)
  2015-05-21  7:34 ` [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
@ 2015-05-22 11:48 ` Johan Hedberg
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2015-05-22 11:48 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

On Mon, May 18, 2015, Andrei Emeltchenko wrote:
> Save Local Public Key to calculate DHKey for later tests. Also verify
> that Command Status and Meta Event are generated.
> ---
>  tools/hci-tester.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 59 insertions(+), 2 deletions(-)

All three patches have been applied. Thanks.

Johan

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

end of thread, other threads:[~2015-05-22 11:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-18  9:41 [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
2015-05-18  9:41 ` [PATCH 2/3] tester: Verify DHKey generation Andrei Emeltchenko
2015-05-18  9:41 ` [PATCH 3/3] btdev: Indicate support for 4.2 encryption commands Andrei Emeltchenko
2015-05-21  7:34 ` [PATCH 1/3] tester: Refactor Read Local Public Key command Andrei Emeltchenko
2015-05-22 11:48 ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).