From 4e135d76a3c222f208a8e0a3dce93dde55671a4e Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 7 Oct 2019 13:34:02 +0300 Subject: [PATCH] Bluetooth: shell: Add printing of remote version information Add printing of the remote version information whenever the new CONFIG_BT_REMOTE_VERSION option is enabled. Signed-off-by: Johan Hedberg --- subsys/bluetooth/shell/bt.c | 48 +++++++++++++++++++++++++++++++++- tests/bluetooth/shell/prj.conf | 2 ++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 9fefe33f241..4584a8c6473 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -230,6 +230,49 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, } #endif +#if defined(CONFIG_BT_REMOTE_INFO) +static const char *ver_str(u8_t ver) +{ + const char * const str[] = { + "1.0b", "1.1", "1.2", "2.0", "2.1", "3.0", "4.0", "4.1", "4.2", + "5.0", "5.1", + }; + + if (ver < ARRAY_SIZE(str)) { + return str[ver]; + } + + return "unknown"; +} + +static void remote_info_available(struct bt_conn *conn, + struct bt_conn_remote_info *remote_info) +{ + struct bt_conn_info info; + + bt_conn_get_info(conn, &info); + + if (IS_ENABLED(CONFIG_BT_REMOTE_VERSION)) { + shell_print(ctx_shell, + "Remote LMP version %s (0x%02x) subversion 0x%04x " + "manufacturer 0x%04x", ver_str(remote_info->version), + remote_info->version, remote_info->subversion, + remote_info->manufacturer); + } + + if (info.type == BT_CONN_TYPE_LE) { + u8_t features[8]; + char features_str[2 * sizeof(features) + 1]; + + sys_memcpy_swap(features, remote_info->le.features, + sizeof(features)); + bin2hex(features, sizeof(features), + features_str, sizeof(features_str)); + shell_print(ctx_shell, "LE Features: 0x%s ", features_str); + } +} +#endif /* defined(CONFIG_BT_REMOTE_INFO) */ + static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, @@ -241,6 +284,9 @@ static struct bt_conn_cb conn_callbacks = { #if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) .security_changed = security_changed, #endif +#if defined(CONFIG_BT_REMOTE_INFO) + .remote_info_available = remote_info_available, +#endif }; #endif /* CONFIG_BT_CONN */ @@ -834,8 +880,8 @@ static void print_le_addr(const char *desc, const bt_addr_le_t *addr) static int cmd_info(const struct shell *shell, size_t argc, char *argv[]) { struct bt_conn *conn = NULL; - bt_addr_le_t addr; struct bt_conn_info info; + bt_addr_le_t addr; int err; switch (argc) { diff --git a/tests/bluetooth/shell/prj.conf b/tests/bluetooth/shell/prj.conf index 3bf63a7ba63..5da865b8a6d 100644 --- a/tests/bluetooth/shell/prj.conf +++ b/tests/bluetooth/shell/prj.conf @@ -24,6 +24,8 @@ CONFIG_BT_ID_MAX=2 CONFIG_BT_GATT_DYNAMIC_DB=y CONFIG_BT_GATT_HRS=y CONFIG_BT_WHITELIST=y +CONFIG_BT_REMOTE_INFO=y +CONFIG_BT_REMOTE_VERSION=y CONFIG_BT_SETTINGS=y CONFIG_FLASH=y