@@ -923,6 +923,7 @@ static void init_conn(struct bthost *bthost, uint16_t handle,
{
struct btconn *conn;
const uint8_t *ia, *ra;
+ uint8_t ia_type, ra_type;
conn = malloc(sizeof(*conn));
if (!conn)
@@ -939,14 +940,18 @@ static void init_conn(struct bthost *bthost, uint16_t handle,
if (bthost->conn_init) {
ia = bthost->bdaddr;
+ ia_type = addr_type;
ra = conn->bdaddr;
+ ra_type = conn->addr_type;
} else {
ia = conn->bdaddr;
+ ia_type = conn->addr_type;
ra = bthost->bdaddr;
+ ra_type = addr_type;
}
- conn->smp_data = smp_conn_add(bthost->smp_data, handle, ia, ra,
- addr_type, bthost->conn_init);
+ conn->smp_data = smp_conn_add(bthost->smp_data, handle, ia, ia_type,
+ ra, ra_type, bthost->conn_init);
if (bthost->new_conn_cb)
bthost->new_conn_cb(conn->handle, bthost->new_conn_data);
@@ -142,8 +142,9 @@ void bthost_start(struct bthost *bthost);
void *smp_start(struct bthost *bthost);
void smp_stop(void *smp_data);
-void *smp_conn_add(void *smp_data, uint16_t handle, const uint8_t *ia,
- const uint8_t *ra, uint8_t addr_type, bool conn_init);
+void *smp_conn_add(void *smp_data, uint16_t handle,
+ const uint8_t *ia, uint8_t ia_type,
+ const uint8_t *ra, uint8_t ra_type, bool conn_init);
void smp_conn_del(void *conn_data);
void smp_conn_encrypted(void *conn_data, uint8_t encrypt);
void smp_data(void *conn_data, const void *data, uint16_t len);
@@ -834,8 +834,22 @@ void smp_conn_encrypted(void *conn_data, uint8_t encrypt)
distribute_keys(conn);
}
-void *smp_conn_add(void *smp_data, uint16_t handle, const uint8_t *ia,
- const uint8_t *ra, uint8_t addr_type, bool conn_init)
+static uint8_t type2hci(uint8_t addr_type)
+{
+ switch (addr_type) {
+ case BDADDR_BREDR:
+ case BDADDR_LE_PUBLIC:
+ return LE_PUBLIC_ADDRESS;
+ case BDADDR_LE_RANDOM:
+ return LE_RANDOM_ADDRESS;
+ }
+
+ return 0x00;
+}
+
+void *smp_conn_add(void *smp_data, uint16_t handle,
+ const uint8_t *ia, uint8_t ia_type,
+ const uint8_t *ra, uint8_t ra_type, bool conn_init)
{
struct smp *smp = smp_data;
struct smp_conn *conn;
@@ -848,11 +862,11 @@ void *smp_conn_add(void *smp_data, uint16_t handle, const uint8_t *ia,
conn->smp = smp;
conn->handle = handle;
- conn->addr_type = addr_type;
conn->out = conn_init;
+ conn->addr_type = conn_init ? ia_type : ra_type;
- conn->ia_type = LE_PUBLIC_ADDRESS;
- conn->ra_type = LE_PUBLIC_ADDRESS;
+ conn->ia_type = type2hci(ia_type);
+ conn->ra_type = type2hci(ra_type);
memcpy(conn->ia, ia, 6);
memcpy(conn->ra, ra, 6);
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> This properly initialize the address type according to the connection address. --- emulator/bthost.c | 9 +++++++-- emulator/bthost.h | 5 +++-- emulator/smp.c | 24 +++++++++++++++++++----- 3 files changed, 29 insertions(+), 9 deletions(-)