From 272b3a5c99d8ed7a5113eb79713847c74a61eaa6 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 15 Jun 2017 12:58:12 +0300 Subject: [PATCH] Bluetooth: Shell: Add gatt-show-db command gatt-show-db shows the current set of attributes available in the GATT database: bt> gatt-show-db attr 0x0011ce80 handle 0x0001 uuid 2800 perm 0x01 attr 0x0011ce94 handle 0x0002 uuid 2803 perm 0x01 attr 0x0011cea8 handle 0x0003 uuid 2a00 perm 0x01 attr 0x0011cebc handle 0x0004 uuid 2803 perm 0x01 attr 0x0011ced0 handle 0x0005 uuid 2a01 perm 0x01 attr 0x0011cde0 handle 0x0006 uuid 2800 perm 0x01 attr 0x0011cdf4 handle 0x0007 uuid 2803 perm 0x01 attr 0x0011ce08 handle 0x0008 uuid 2a05 perm 0x00 attr 0x0011ce1c handle 0x0009 uuid 2902 perm 0x03 attr 0x0011c9a0 handle 0x000a uuid 2800 perm 0x01 attr 0x0011c9b4 handle 0x000b uuid 2803 perm 0x01 Signed-off-by: Luiz Augusto von Dentz --- subsys/bluetooth/shell/bt.c | 1 + subsys/bluetooth/shell/gatt.c | 15 +++++++++++++++ subsys/bluetooth/shell/gatt.h | 1 + 3 files changed, 17 insertions(+) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 0fea5d5d028..5bf9e0de4a9 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -2014,6 +2014,7 @@ static const struct shell_cmd bt_commands[] = { " [ind]" }, { "gatt-unsubscribe", cmd_gatt_unsubscribe, HELP_NONE }, #endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ + { "gatt-show-db", cmd_gatt_show_db, HELP_NONE }, { "gatt-register-service", cmd_gatt_register_test_svc, "register pre-predefined test service" }, { "gatt-unregister-service", cmd_gatt_unregister_test_svc, diff --git a/subsys/bluetooth/shell/gatt.c b/subsys/bluetooth/shell/gatt.c index 936a71b141b..82f77ee8496 100644 --- a/subsys/bluetooth/shell/gatt.c +++ b/subsys/bluetooth/shell/gatt.c @@ -483,6 +483,21 @@ int cmd_gatt_unsubscribe(int argc, char *argv[]) } #endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ +static u8_t print_attr(const struct bt_gatt_attr *attr, void *user_data) +{ + printk("attr %p handle 0x%04x uuid %s perm 0x%02x\n", + attr, attr->handle, bt_uuid_str(attr->uuid), attr->perm); + + return BT_GATT_ITER_CONTINUE; +} + +int cmd_gatt_show_db(int argc, char *argv[]) +{ + bt_gatt_foreach_attr(0x0001, 0xffff, print_attr, NULL); + + return 0; +} + /* Custom Service Variables */ static struct bt_uuid_128 vnd_uuid = BT_UUID_INIT_128( 0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, diff --git a/subsys/bluetooth/shell/gatt.h b/subsys/bluetooth/shell/gatt.h index bbd32a91087..541ba7e13e3 100644 --- a/subsys/bluetooth/shell/gatt.h +++ b/subsys/bluetooth/shell/gatt.h @@ -13,6 +13,7 @@ #ifndef __GATT_H #define __GATT_H +int cmd_gatt_show_db(int argc, char *argv[]); int cmd_gatt_exchange_mtu(int argc, char *argv[]); int cmd_gatt_discover(int argc, char *argv[]); int cmd_gatt_read(int argc, char *argv[]);