From 52743028aa31788bb6e7cfffbfe8c11c91a779a3 Mon Sep 17 00:00:00 2001 From: Sharvil Nanavati Date: Wed, 5 Nov 2014 14:48:58 -0800 Subject: [PATCH] Add a "setDiscoverable" command to hci. --- tools/hci/main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/hci/main.c b/tools/hci/main.c index 5c4e148f8..844f28829 100644 --- a/tools/hci/main.c +++ b/tools/hci/main.c @@ -24,6 +24,7 @@ typedef struct { } command_t; static int help(int argc, char **argv); +static int set_discoverable(int argc, char **argv); static int set_name(int argc, char **argv); static int set_pcm_loopback(int argc, char **argv); @@ -33,6 +34,7 @@ static void usage(const char *name); static const command_t commands[] = { { "help", " - shows help text for .", help }, + { "setDiscoverable", "(true|false) - whether the controller should be discoverable.", set_discoverable }, { "setName", " - sets the device's Bluetooth name to .", set_name }, { "setPcmLoopback", "(true|false) - enables or disables PCM loopback on the controller.", set_pcm_loopback }, }; @@ -53,6 +55,24 @@ static int help(int argc, char **argv) { return 0; } +static int set_discoverable(int argc, char **argv) { + if (argc != 1) { + printf("Discoverable mode not specified.\n"); + return 1; + } + + if (strcmp(argv[0], "true") && strcmp(argv[0], "false")) { + printf("Invalid discoverable mode '%s'.\n", argv[0]); + return 2; + } + + uint8_t packet[] = { 0x1A, 0x0C, 0x01, 0x00 }; + if (argv[0][0] == 't') + packet[ARRAY_SIZE(packet) - 1] = 0x03; + + return !write_hci_command(HCI_PACKET_COMMAND, packet, ARRAY_SIZE(packet)); +} + static int set_name(int argc, char **argv) { if (argc != 1) { printf("Device name not specified.\n"); -- 2.11.0