summaryrefslogtreecommitdiff
path: root/tools/hci-tester.c
diff options
context:
space:
mode:
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>2015-05-15 16:46:26 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2015-05-17 10:39:14 +0300
commitcb0182cc1780a792c9b53f796849139a415fd5b6 (patch)
treef2ba82f4b8a1931fa1f313513ffe0d3580e1c8fc /tools/hci-tester.c
parent26b9d72adf6ddcb7ee4c6726d8df9c435459b7e0 (diff)
downloadbluez-cb0182cc1780a792c9b53f796849139a415fd5b6.tar.gz
tester: Test DHKey generation in controller
Test that appropriate command status event and LE Meta events are generated.
Diffstat (limited to 'tools/hci-tester.c')
-rw-r--r--tools/hci-tester.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/hci-tester.c b/tools/hci-tester.c
index 620832d9e..460c9a9c5 100644
--- a/tools/hci-tester.c
+++ b/tools/hci-tester.c
@@ -31,6 +31,7 @@
#include "monitor/bt.h"
#include "src/shared/hci.h"
#include "src/shared/util.h"
+#include "src/shared/ecc.h"
#include "src/shared/tester.h"
struct user_data {
@@ -416,6 +417,57 @@ static void test_le_read_local_pk(const void *test_data)
test_command(BT_HCI_CMD_LE_READ_LOCAL_PK256);
}
+static void test_le_generate_dhkey_complete(const void *data, uint8_t size,
+ void *user_data)
+{
+ const uint8_t *event = data;
+
+ if (*event != BT_HCI_EVT_LE_GENERATE_DHKEY_COMPLETE) {
+ tester_warn("Failed DHKey generation command");
+ tester_test_failed();
+ return;
+ }
+
+ /* TODO: We have remote secret key and local public key, calculate
+ * DHKey and compare
+ */
+
+ tester_test_passed();
+}
+
+static void test_le_generate_dhkey_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_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];
+
+ ecc_make_key(cmd.remote_pk256, remote_sk);
+
+ bt_hci_register(user->hci_ut, BT_HCI_EVT_LE_META_EVENT,
+ test_le_generate_dhkey_complete, NULL, NULL);
+
+ if (!bt_hci_send(user->hci_ut, BT_HCI_CMD_LE_GENERATE_DHKEY, &cmd,
+ sizeof(cmd), test_le_generate_dhkey_status,
+ NULL, NULL)) {
+ tester_warn("Failed to send HCI LE Encrypt command");
+ tester_test_failed();
+ return;
+ }
+
+}
+
static void test_inquiry_complete(const void *data, uint8_t size,
void *user_data)
{
@@ -740,6 +792,8 @@ int main(int argc, char *argv[])
test_le_rand);
test_hci_local("LE Read Local PK", NULL, NULL,
test_le_read_local_pk);
+ test_hci_local("LE Generate DHKey", NULL, NULL,
+ test_le_generate_dhkey);
test_hci_local("Inquiry (LIAC)", NULL, NULL, test_inquiry_liac);