Diff between 8fbe1120206d2e81b76e125baa19e04022d41111 and d1c6a543c7444eceafdfd49d4f32beaaa5176b89

Changed Files

File Additions Deletions Status
emulator/btdev.c +1 -8 modified
emulator/bthost.c +5 -3 modified
emulator/bthost.h +1 -2 modified
emulator/le.c +3 -1 modified
emulator/smp.c +1 -2 modified
monitor/bt.h +5 -5 modified
monitor/packet.c +11 -8 modified

Full Patch

diff --git a/emulator/btdev.c b/emulator/btdev.c
index e39b0cc..4a54a23 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -2375,14 +2375,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
 		if (btdev->type == BTDEV_TYPE_BREDR)
 			goto unsupported;
 		lr.status = BT_HCI_ERR_SUCCESS;
-		lr.number[0] = rand();
-		lr.number[1] = rand();
-		lr.number[2] = rand();
-		lr.number[3] = rand();
-		lr.number[4] = rand();
-		lr.number[5] = rand();
-		lr.number[6] = rand();
-		lr.number[7] = rand();
+		lr.number = rand();
 		cmd_complete(btdev, opcode, &lr, sizeof(lr));
 		break;
 
diff --git a/emulator/bthost.c b/emulator/bthost.c
index 2f338f7..1004ac8 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -1059,7 +1059,8 @@ static void evt_le_ltk_request(struct bthost *bthost, const void *data,
 	const struct bt_hci_evt_le_long_term_key_request *ev = data;
 	struct bt_hci_cmd_le_ltk_req_reply cp;
 	struct bt_hci_cmd_le_ltk_req_neg_reply *neg_cp = (void *) &cp;
-	uint16_t handle, div;
+	uint16_t handle, ediv;
+	uint64_t rand;
 	struct btconn *conn;
 	int err;
 
@@ -1071,11 +1072,12 @@ static void evt_le_ltk_request(struct bthost *bthost, const void *data,
 	if (!conn)
 		return;
 
-	div = le16_to_cpu(ev->diversifier);
+	rand = le64_to_cpu(ev->rand);
+	ediv = le16_to_cpu(ev->ediv);
 
 	cp.handle = ev->handle;
 
-	err = smp_get_ltk(conn->smp_data, ev->number, div, cp.ltk);
+	err = smp_get_ltk(conn->smp_data, rand, ediv, cp.ltk);
 	if (err < 0)
 		send_command(bthost, BT_HCI_CMD_LE_LTK_REQ_NEG_REPLY,
 						neg_cp, sizeof(*neg_cp));
diff --git a/emulator/bthost.h b/emulator/bthost.h
index 5048094..4933b33 100644
--- a/emulator/bthost.h
+++ b/emulator/bthost.h
@@ -122,6 +122,5 @@ void *smp_conn_add(void *smp_data, uint16_t handle, const uint8_t *ia,
 					const uint8_t *ra, bool conn_init);
 void smp_conn_del(void *conn_data);
 void smp_data(void *conn_data, const void *data, uint16_t len);
-int smp_get_ltk(void *smp_data, const uint8_t *rand, uint16_t div,
-								uint8_t *ltk);
+int smp_get_ltk(void *smp_data, uint64_t rand, uint16_t ediv, uint8_t *ltk);
 void smp_pair(void *conn_data);
diff --git a/emulator/le.c b/emulator/le.c
index 1d10d76..6738857 100644
--- a/emulator/le.c
+++ b/emulator/le.c
@@ -598,14 +598,16 @@ static void cmd_le_encrypt(struct bt_le *hci, const void *data, uint8_t size)
 static void cmd_le_rand(struct bt_le *hci, const void *data, uint8_t size)
 {
 	struct bt_hci_rsp_le_rand rsp;
+	uint8_t value[8];
 
-	if (!bt_crypto_random_bytes(hci->crypto, rsp.number, 8)) {
+	if (!bt_crypto_random_bytes(hci->crypto, value, 8)) {
 		cmd_status(hci, BT_HCI_ERR_COMMAND_DISALLOWED,
 					BT_HCI_CMD_LE_RAND);
 		return;
 	}
 
 	rsp.status = BT_HCI_ERR_SUCCESS;
+	memcpy(&rsp.number, value, 8);
 
 	cmd_complete(hci, BT_HCI_CMD_LE_RAND, &rsp, sizeof(rsp));
 }
diff --git a/emulator/smp.c b/emulator/smp.c
index afb796c..32c82e5 100644
--- a/emulator/smp.c
+++ b/emulator/smp.c
@@ -201,8 +201,7 @@ void smp_data(void *conn_data, const void *data, uint16_t len)
 	}
 }
 
-int smp_get_ltk(void *smp_data, const uint8_t *rand, uint16_t div,
-								uint8_t *ltk)
+int smp_get_ltk(void *smp_data, uint64_t rand, uint16_t ediv, uint8_t *ltk)
 {
 	struct smp_conn *conn = smp_data;
 	static const uint8_t no_ltk[16] = { 0 };
diff --git a/monitor/bt.h b/monitor/bt.h
index b21f961..e35a3ae 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -1769,14 +1769,14 @@ struct bt_hci_rsp_le_encrypt {
 #define BT_HCI_CMD_LE_RAND			0x2018
 struct bt_hci_rsp_le_rand {
 	uint8_t  status;
-	uint8_t  number[8];
+	uint64_t number;
 } __attribute__ ((packed));
 
 #define BT_HCI_CMD_LE_START_ENCRYPT		0x2019
 struct bt_hci_cmd_le_start_encrypt {
 	uint16_t handle;
-	uint8_t  number[8];
-	uint16_t diversifier;
+	uint64_t rand;
+	uint16_t ediv;
 	uint8_t  ltk[16];
 } __attribute__ ((packed));
 
@@ -2353,8 +2353,8 @@ struct bt_hci_evt_le_remote_features_complete {
 #define BT_HCI_EVT_LE_LONG_TERM_KEY_REQUEST	0x05
 struct bt_hci_evt_le_long_term_key_request {
 	uint16_t handle;
-	uint8_t  number[8];
-	uint16_t diversifier;
+	uint64_t rand;
+	uint16_t ediv;
 } __attribute__ ((packed));
 
 #define BT_HCI_ERR_SUCCESS			0x00
diff --git a/monitor/packet.c b/monitor/packet.c
index f2f3e49..20ae962 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -2505,9 +2505,14 @@ void packet_print_channel_map_ll(const uint8_t *map)
 	print_le_channel_map(map);
 }
 
-static void print_random_number(const uint8_t *number)
+static void print_random_number(uint64_t rand)
 {
-	print_hex_field("Random number", number, 8);
+	print_field("Random number: 0x%16.16" PRIx64, le64_to_cpu(rand));
+}
+
+static void print_encryption_diversifier(uint16_t ediv)
+{
+	print_field("Encryption diversifier: 0x%4.4x", le16_to_cpu(ediv));
 }
 
 static const struct {
@@ -5605,9 +5610,8 @@ static void le_start_encrypt_cmd(const void *data, uint8_t size)
 	const struct bt_hci_cmd_le_start_encrypt *cmd = data;
 
 	print_handle(cmd->handle);
-	print_random_number(cmd->number);
-	print_field("Encryption diversifier: 0x%4.4x",
-					le16_to_cpu(cmd->diversifier));
+	print_random_number(cmd->rand);
+	print_encryption_diversifier(cmd->ediv);
 	print_key("Long term key", cmd->ltk);
 }
 
@@ -7211,9 +7215,8 @@ static void le_long_term_key_request_evt(const void *data, uint8_t size)
 	const struct bt_hci_evt_le_long_term_key_request *evt = data;
 
 	print_handle(evt->handle);
-	print_random_number(evt->number);
-	print_field("Encryption diversifier: 0x%4.4x",
-					le16_to_cpu(evt->diversifier));
+	print_random_number(evt->rand);
+	print_encryption_diversifier(evt->ediv);
 }
 
 struct subevent_data {