Skip to content

Commit 4e135d7

Browse files
Johan Hedbergjhedberg
authored andcommitted
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 <[email protected]>
1 parent 649a813 commit 4e135d7

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

subsys/bluetooth/shell/bt.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,49 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
230230
}
231231
#endif
232232

233+
#if defined(CONFIG_BT_REMOTE_INFO)
234+
static const char *ver_str(u8_t ver)
235+
{
236+
const char * const str[] = {
237+
"1.0b", "1.1", "1.2", "2.0", "2.1", "3.0", "4.0", "4.1", "4.2",
238+
"5.0", "5.1",
239+
};
240+
241+
if (ver < ARRAY_SIZE(str)) {
242+
return str[ver];
243+
}
244+
245+
return "unknown";
246+
}
247+
248+
static void remote_info_available(struct bt_conn *conn,
249+
struct bt_conn_remote_info *remote_info)
250+
{
251+
struct bt_conn_info info;
252+
253+
bt_conn_get_info(conn, &info);
254+
255+
if (IS_ENABLED(CONFIG_BT_REMOTE_VERSION)) {
256+
shell_print(ctx_shell,
257+
"Remote LMP version %s (0x%02x) subversion 0x%04x "
258+
"manufacturer 0x%04x", ver_str(remote_info->version),
259+
remote_info->version, remote_info->subversion,
260+
remote_info->manufacturer);
261+
}
262+
263+
if (info.type == BT_CONN_TYPE_LE) {
264+
u8_t features[8];
265+
char features_str[2 * sizeof(features) + 1];
266+
267+
sys_memcpy_swap(features, remote_info->le.features,
268+
sizeof(features));
269+
bin2hex(features, sizeof(features),
270+
features_str, sizeof(features_str));
271+
shell_print(ctx_shell, "LE Features: 0x%s ", features_str);
272+
}
273+
}
274+
#endif /* defined(CONFIG_BT_REMOTE_INFO) */
275+
233276
static struct bt_conn_cb conn_callbacks = {
234277
.connected = connected,
235278
.disconnected = disconnected,
@@ -241,6 +284,9 @@ static struct bt_conn_cb conn_callbacks = {
241284
#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)
242285
.security_changed = security_changed,
243286
#endif
287+
#if defined(CONFIG_BT_REMOTE_INFO)
288+
.remote_info_available = remote_info_available,
289+
#endif
244290
};
245291
#endif /* CONFIG_BT_CONN */
246292

@@ -834,8 +880,8 @@ static void print_le_addr(const char *desc, const bt_addr_le_t *addr)
834880
static int cmd_info(const struct shell *shell, size_t argc, char *argv[])
835881
{
836882
struct bt_conn *conn = NULL;
837-
bt_addr_le_t addr;
838883
struct bt_conn_info info;
884+
bt_addr_le_t addr;
839885
int err;
840886

841887
switch (argc) {

tests/bluetooth/shell/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ CONFIG_BT_ID_MAX=2
2424
CONFIG_BT_GATT_DYNAMIC_DB=y
2525
CONFIG_BT_GATT_HRS=y
2626
CONFIG_BT_WHITELIST=y
27+
CONFIG_BT_REMOTE_INFO=y
28+
CONFIG_BT_REMOTE_VERSION=y
2729

2830
CONFIG_BT_SETTINGS=y
2931
CONFIG_FLASH=y

0 commit comments

Comments
 (0)