Skip to content

Commit

Permalink
Bluetooth: Shell: fix assert when print address.
Browse files Browse the repository at this point in the history
This patch fix the assertion caused by null address pointer
that occurs when BR/EDR pairing completed.

Signed-off-by: Zihao Gao <[email protected]>
  • Loading branch information
gzh-terry authored and kartben committed Feb 20, 2025
1 parent 585d612 commit 7e18f80
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions subsys/bluetooth/host/shell/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4106,17 +4106,47 @@ static void auth_pairing_oob_data_request(struct bt_conn *conn,
static void auth_pairing_complete(struct bt_conn *conn, bool bonded)
{
char addr[BT_ADDR_LE_STR_LEN];
struct bt_conn_info info;

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (bt_conn_get_info(conn, &info) < 0) {
return;
}

switch (info.type) {
case BT_CONN_TYPE_LE:
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
break;
case BT_CONN_TYPE_BR:
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
break;
default:
bt_shell_print("Unrecognized conn type: %d", info.type);
return;
}

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

static void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err err)
{
char addr[BT_ADDR_LE_STR_LEN];
struct bt_conn_info info;

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (bt_conn_get_info(conn, &info) < 0) {
return;
}

switch (info.type) {
case BT_CONN_TYPE_LE:
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
break;
case BT_CONN_TYPE_BR:
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
break;
default:
bt_shell_print("Unrecognized conn type: %d", info.type);
return;
}

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

0 comments on commit 7e18f80

Please sign in to comment.