From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> 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(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index 3b42c0664..16934d35a 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -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); diff --git a/emulator/bthost.h b/emulator/bthost.h index 77f17fd69..7e5286df3 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -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); diff --git a/emulator/smp.c b/emulator/smp.c index db0065d7d..ec1baea04 100644 --- a/emulator/smp.c +++ b/emulator/smp.c @@ -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); -- 2.26.2