From 710aa2ecc7c1afd030f68ec13c98aaa25009baeb Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 6 Jul 2015 17:09:18 +0300 Subject: [PATCH] Bluetooth: Add gatt-discover-characteristic command to btshell This adds gatt-discover-characteristic which works as follow: btshell>gatt-discover-characteristic [UUID] [start_handle] [end_handle] bt: bt_gatt_discover_characteristic (0x0010d098): start_handle 0x000b end_handle 0x0011 Discover pending btshell>bt: bt_att_recv (0x0010f294): Received ATT code 0x09 len 23 bt: att_handle_read_type_rsp (0x0010f294): bt: att_read_type_rsp (0x0010f294): err 0x00 bt: att_read_type_rsp (0x0010f294): handle 0x000b properties 0x02 value_handle 0x000c Discover found handle 11 bt: att_read_type_rsp (0x0010f294): handle 0x000d properties 0x10 value_handle 0x000e Discover found handle 13 bt: att_read_type_rsp (0x0010f294): handle 0x0010 properties 0x08 value_handle 0x0011 Discover found handle 16 Discover destroy Change-Id: I04aad56cc4f978e3a884adffc487ae4dcc1c4ee9 Signed-off-by: Luiz Augusto von Dentz --- samples/bluetooth/shell/src/main.c | 31 ++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/samples/bluetooth/shell/src/main.c b/samples/bluetooth/shell/src/main.c index 3c200760f83..c1c3ca10535 100644 --- a/samples/bluetooth/shell/src/main.c +++ b/samples/bluetooth/shell/src/main.c @@ -427,18 +427,26 @@ static void cmd_gatt_discover(int argc, char *argv[]) return; } - if (argc < 4) { - printk("UUID type required\n"); - return; - } - - uuid.u16 = xtoi(argv[3]); - discover_params.uuid = &uuid; discover_params.func = discover_func; discover_params.destroy = discover_destroy; discover_params.start_handle = 0x0001; discover_params.end_handle = 0xffff; + if (argc < 4) { + if (!strcmp(argv[0], "gatt-discover")) { + printk("UUID type required\n"); + return; + } + goto done; + } + + /* Only set the UUID if the value is valid (non zero) */ + uuid.u16 = xtoi(argv[3]); + if (uuid.u16) { + uuid.type = BT_UUID_16; + discover_params.uuid = &uuid; + } + if (argc > 4) { discover_params.start_handle = xtoi(argv[4]); if (argc > 5) { @@ -446,7 +454,13 @@ static void cmd_gatt_discover(int argc, char *argv[]) } } - err = bt_gatt_discover(conn, &discover_params); +done: + if (!strcmp(argv[0], "gatt-discover-characteristic")) { + err = bt_gatt_discover_characteristic(conn, &discover_params); + } else { + err = bt_gatt_discover(conn, &discover_params); + } + if (err) { printk("Discover failed (err %d)\n", err); } else { @@ -473,4 +487,5 @@ void main(void) shell_cmd_register("security", cmd_security); shell_cmd_register("gatt-exchange-mtu", cmd_gatt_exchange_mtu); shell_cmd_register("gatt-discover", cmd_gatt_discover); + shell_cmd_register("gatt-discover-characteristic", cmd_gatt_discover); }