Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5586e8cb authored by Sharvil Nanavati's avatar Sharvil Nanavati
Browse files

Add a SCO routing command to net_hci.

This allows us to change the SCO routing parameters at runtime while
debugging / doing device bringup.

Change-Id: I8bafb7c7fb7ad7470d378cd14a7ee4aad63f3b9b
parent 6cefe2c6
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -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]);