OSDN Git Service

tools: Add option to not set flow control for btattach
authorMarcel Holtmann <marcel@holtmann.org>
Tue, 15 Nov 2016 17:54:02 +0000 (18:54 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 15 Nov 2016 17:54:02 +0000 (18:54 +0100)
tools/btattach.c

index 9d1868a..5adbc8d 100644 (file)
@@ -49,7 +49,7 @@
 #include "src/shared/tty.h"
 #include "src/shared/hci.h"
 
-static int open_serial(const char *path, unsigned int speed)
+static int open_serial(const char *path, unsigned int speed, bool flowctl)
 {
        struct termios ti;
        int fd, saved_ldisc, ldisc = N_HCI;
@@ -78,8 +78,10 @@ static int open_serial(const char *path, unsigned int speed)
 
        ti.c_cflag |= (speed | CLOCAL | CREAD);
 
-       /* Set flow control */
-       ti.c_cflag |= CRTSCTS;
+       if (flowctl) {
+               /* Set flow control */
+               ti.c_cflag |= CRTSCTS;
+       }
 
        if (tcsetattr(fd, TCSANOW, &ti) < 0) {
                perror("Failed to set serial port settings");
@@ -107,11 +109,11 @@ static void local_version_callback(const void *data, uint8_t size,
 }
 
 static int attach_proto(const char *path, unsigned int proto,
-                               unsigned int speed, unsigned int flags)
+                       unsigned int speed, bool flowctl, unsigned int flags)
 {
        int fd, dev_id;
 
-       fd = open_serial(path, speed);
+       fd = open_serial(path, speed, flowctl);
        if (fd < 0)
                return -1;
 
@@ -191,6 +193,7 @@ static void usage(void)
                "\t-A, --amp <device>     Attach AMP controller\n"
                "\t-P, --protocol <proto> Specify protocol type\n"
                "\t-S, --speed <baudrate> Specify which baudrate to use\n"
+               "\t-N, --noflowctl        Disable flow control\n"
                "\t-h, --help             Show help options\n");
 }
 
@@ -199,6 +202,7 @@ static const struct option main_options[] = {
        { "amp",      required_argument, NULL, 'A' },
        { "protocol", required_argument, NULL, 'P' },
        { "speed",    required_argument, NULL, 'S' },
+       { "noflowctl",no_argument,       NULL, 'N' },
        { "version",  no_argument,       NULL, 'v' },
        { "help",     no_argument,       NULL, 'h' },
        { }
@@ -226,7 +230,7 @@ static const struct {
 int main(int argc, char *argv[])
 {
        const char *bredr_path = NULL, *amp_path = NULL, *proto = NULL;
-       bool raw_device = false;
+       bool flowctl = true, raw_device = false;
        sigset_t mask;
        int exit_status, count = 0, proto_id = HCI_UART_H4;
        unsigned int speed = B115200;
@@ -234,7 +238,7 @@ int main(int argc, char *argv[])
        for (;;) {
                int opt;
 
-               opt = getopt_long(argc, argv, "B:A:P:S:Rvh",
+               opt = getopt_long(argc, argv, "B:A:P:S:NRvh",
                                                main_options, NULL);
                if (opt < 0)
                        break;
@@ -256,6 +260,9 @@ int main(int argc, char *argv[])
                                return EXIT_FAILURE;
                        }
                        break;
+               case 'N':
+                       flowctl = false;
+                       break;
                case 'R':
                        raw_device = true;
                        break;
@@ -310,7 +317,7 @@ int main(int argc, char *argv[])
                if (raw_device)
                        flags = (1 << HCI_UART_RAW_DEVICE);
 
-               fd = attach_proto(bredr_path, proto_id, speed, flags);
+               fd = attach_proto(bredr_path, proto_id, speed, flowctl, flags);
                if (fd >= 0) {
                        mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
                        count++;
@@ -329,7 +336,7 @@ int main(int argc, char *argv[])
                if (raw_device)
                        flags = (1 << HCI_UART_RAW_DEVICE);
 
-               fd = attach_proto(amp_path, proto_id, speed, flags);
+               fd = attach_proto(amp_path, proto_id, speed, flowctl, flags);
                if (fd >= 0) {
                        mainloop_add_fd(fd, 0, uart_callback, NULL, NULL);
                        count++;