Skip to content

Commit 7e18f80

Browse files
gzh-terrykartben
authored andcommitted
Bluetooth: Shell: fix assert when print address.
This patch fix the assertion caused by null address pointer that occurs when BR/EDR pairing completed. Signed-off-by: Zihao Gao <[email protected]>
1 parent 585d612 commit 7e18f80

File tree

1 file changed

+32
-2
lines changed
  • subsys/bluetooth/host/shell

1 file changed

+32
-2
lines changed

subsys/bluetooth/host/shell/bt.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,17 +4106,47 @@ static void auth_pairing_oob_data_request(struct bt_conn *conn,
41064106
static void auth_pairing_complete(struct bt_conn *conn, bool bonded)
41074107
{
41084108
char addr[BT_ADDR_LE_STR_LEN];
4109+
struct bt_conn_info info;
41094110

4110-
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
4111+
if (bt_conn_get_info(conn, &info) < 0) {
4112+
return;
4113+
}
4114+
4115+
switch (info.type) {
4116+
case BT_CONN_TYPE_LE:
4117+
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
4118+
break;
4119+
case BT_CONN_TYPE_BR:
4120+
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
4121+
break;
4122+
default:
4123+
bt_shell_print("Unrecognized conn type: %d", info.type);
4124+
return;
4125+
}
41114126

41124127
bt_shell_print("%s with %s", bonded ? "Bonded" : "Paired", addr);
41134128
}
41144129

41154130
static void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err err)
41164131
{
41174132
char addr[BT_ADDR_LE_STR_LEN];
4133+
struct bt_conn_info info;
41184134

4119-
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
4135+
if (bt_conn_get_info(conn, &info) < 0) {
4136+
return;
4137+
}
4138+
4139+
switch (info.type) {
4140+
case BT_CONN_TYPE_LE:
4141+
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
4142+
break;
4143+
case BT_CONN_TYPE_BR:
4144+
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
4145+
break;
4146+
default:
4147+
bt_shell_print("Unrecognized conn type: %d", info.type);
4148+
return;
4149+
}
41204150

41214151
bt_shell_print("Pairing failed with %s reason: %s (%d)", addr, security_err_str(err), err);
41224152
}

0 commit comments

Comments
 (0)