OSDN Git Service

Add a SCO routing command to net_hci.
authorSharvil Nanavati <sharvil@google.com>
Thu, 16 Jul 2015 09:55:27 +0000 (02:55 -0700)
committerScott James Remnant <keybuk@google.com>
Mon, 19 Oct 2015 17:35:00 +0000 (10:35 -0700)
This allows us to change the SCO routing parameters at runtime while
debugging / doing device bringup.

Change-Id: I8bafb7c7fb7ad7470d378cd14a7ee4aad63f3b9b

tools/hci/main.c

index fc433bc..ae06400 100644 (file)
@@ -27,6 +27,7 @@ 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);
+static int set_sco_route(int argc, char **argv);
 
 static bool write_hci_command(hci_packet_t type, const void *packet, size_t length);
 static const command_t *find_command(const char *name);
@@ -37,6 +38,7 @@ static const command_t commands[] = {
   { "setDiscoverable", "(true|false) - whether the controller should be discoverable.", set_discoverable },
   { "setName", "<name> - sets the device's Bluetooth name to <name>.", set_name },
   { "setPcmLoopback", "(true|false) - enables or disables PCM loopback on the controller.", set_pcm_loopback },
+  { "setScoRoute", "(pcm|i2s|uart) - sets the SCO packet route to one of the specified buses.", set_sco_route },
 };
 
 static int help(int argc, char **argv) {
@@ -120,6 +122,31 @@ static int set_pcm_loopback(int argc, char **argv) {
   return !write_hci_command(HCI_PACKET_COMMAND, packet, ARRAY_SIZE(packet));
 }
 
+static int set_sco_route(int argc, char **argv) {
+  if (argc != 1) {
+    printf("SCO route parameter must be specified.\n");
+    return 1;
+  }
+
+  uint8_t route = 0xFF;
+  if (!strcmp(argv[0], "pcm"))
+    route = 0;
+  else if (!strcmp(argv[0], "i2s"))
+    route = 3;
+  else if (!strcmp(argv[0], "uart"))
+    route = 1;
+
+  if (route == 0xFF) {
+    printf("Invalid SCO route specified: %s\n", argv[0]);
+    return 2;
+  }
+
+  uint8_t packet[] = { 0x1C, 0xFC, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00 };
+  packet[3] = route;
+
+  return !write_hci_command(HCI_PACKET_COMMAND, packet, ARRAY_SIZE(packet));
+}
+
 int main(int argc, char **argv) {
   if (argc < 2) {
     usage(argv[0]);