diff --git a/cdba-server.c b/cdba-server.c index e3267d8..cc538ca 100644 --- a/cdba-server.c +++ b/cdba-server.c @@ -26,34 +26,6 @@ static const char *username; struct device *selected_device; -int tty_open(const char *tty, struct termios *old) -{ - struct termios tios; - int ret; - int fd; - - fd = open(tty, O_RDWR | O_NOCTTY | O_EXCL); - if (fd < 0) - err(1, "unable to open \"%s\"", tty); - - ret = tcgetattr(fd, old); - if (ret < 0) - err(1, "unable to retrieve \"%s\" tios", tty); - - memset(&tios, 0, sizeof(tios)); - tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD; - tios.c_iflag = IGNPAR; - tios.c_oflag = 0; - - tcflush(fd, TCIFLUSH); - - ret = tcsetattr(fd, TCSANOW, &tios); - if (ret < 0) - err(1, "unable to update \"%s\" tios", tty); - - return fd; -} - static void fastboot_opened(struct fastboot *fb, void *data) { const uint8_t one = 1; diff --git a/cdba-server.h b/cdba-server.h index c8e00a4..4176311 100644 --- a/cdba-server.h +++ b/cdba-server.h @@ -6,8 +6,6 @@ #include "cdba.h" -int tty_open(const char *tty, struct termios *old); - void cdba_send_buf(int type, size_t len, const void *buf); #define cdba_send(type) cdba_send_buf(type, 0, NULL) diff --git a/console.c b/console.c index 434ad46..3ff0a2f 100644 --- a/console.c +++ b/console.c @@ -13,6 +13,7 @@ #include "cdba-server.h" #include "device.h" +#include "tty.h" #include "watch.h" struct console { diff --git a/drivers/alpaca.c b/drivers/alpaca.c index a493f8d..f720670 100644 --- a/drivers/alpaca.c +++ b/drivers/alpaca.c @@ -17,8 +17,8 @@ #include #include -#include "cdba-server.h" #include "device.h" +#include "tty.h" struct alpaca { int alpaca_fd; diff --git a/drivers/cdb_assist.c b/drivers/cdb_assist.c index 55b17dc..2a4759d 100644 --- a/drivers/cdb_assist.c +++ b/drivers/cdb_assist.c @@ -17,9 +17,9 @@ #include #include -#include "cdba-server.h" #include "device.h" #include "status.h" +#include "tty.h" #include "watch.h" struct cdb_assist { diff --git a/drivers/qcomlt_dbg.c b/drivers/qcomlt_dbg.c index 6e24ce1..fe55cf4 100644 --- a/drivers/qcomlt_dbg.c +++ b/drivers/qcomlt_dbg.c @@ -21,6 +21,7 @@ #include "cdba-server.h" #include "device.h" #include "status.h" +#include "tty.h" #include "watch.h" enum qcomlt_parse_state { diff --git a/meson.build b/meson.build index ef28570..763c32d 100644 --- a/meson.build +++ b/meson.build @@ -89,7 +89,8 @@ server_srcs = ['cdba-server.c', 'ppps.c', 'status.c', 'status-cmd.c', - 'watch.c'] + 'watch.c', + 'tty.c'] build_server = true foreach d: server_deps diff --git a/tty.c b/tty.c new file mode 100644 index 0000000..4c75cfe --- /dev/null +++ b/tty.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016-2018, Linaro Ltd. + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include +#include + +#include "tty.h" + +int tty_open(const char *tty, struct termios *old) +{ + struct termios tios; + int ret; + int fd; + + fd = open(tty, O_RDWR | O_NOCTTY | O_EXCL); + if (fd < 0) + err(1, "unable to open \"%s\"", tty); + + ret = tcgetattr(fd, old); + if (ret < 0) + err(1, "unable to retrieve \"%s\" tios", tty); + + memset(&tios, 0, sizeof(tios)); + tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD; + tios.c_iflag = IGNPAR; + tios.c_oflag = 0; + + tcflush(fd, TCIFLUSH); + + ret = tcsetattr(fd, TCSANOW, &tios); + if (ret < 0) + err(1, "unable to update \"%s\" tios", tty); + + return fd; +} diff --git a/tty.h b/tty.h new file mode 100644 index 0000000..6345fc0 --- /dev/null +++ b/tty.h @@ -0,0 +1,7 @@ +#ifndef __TTY_H__ +#define __TTY_H__ + +struct termios; +int tty_open(const char *tty, struct termios *old); + +#endif