tty-handler: Use raw byte handling for terminal
When opening the tty for local UART mirroring, disable various special
processing of terminal input and output like flow control, line edit
(canonical) mode, character translation, special characters, etc.
This forwards all terminal input to the VUART and allow the host OS to
perform any necessary processing.
Change-Id: I8b2896e7465c8af643f0cbbcaf7ef2f9ee96e2f5
Signed-off-by: Xo Wang <xow@google.com>
diff --git a/tty-handler.c b/tty-handler.c
index e640354..b9a5afb 100644
--- a/tty-handler.c
+++ b/tty-handler.c
@@ -142,6 +142,28 @@
return 0;
}
+static int make_terminal_raw(struct tty_handler *th, const char *tty_name) {
+ struct termios term_options;
+
+ if (tcgetattr(th->fd, &term_options) < 0) {
+ warn("Can't get config for %s", tty_name);
+ return -1;
+ }
+
+ /* Disable various input and output processing including character
+ * translation, line edit (canonical) mode, flow control, and special signal
+ * generating characters. */
+ cfmakeraw(&term_options);
+
+ if (tcsetattr(th->fd, TCSAFLUSH, &term_options) < 0) {
+ warn("Couldn't commit terminal options for %s", tty_name);
+ return -1;
+ }
+ printf("Set %s for raw byte handling\n", tty_name);
+
+ return 0;
+}
+
static int tty_init(struct handler *handler, struct console *console,
struct config *config __attribute__((unused)))
{
@@ -179,6 +201,9 @@
fprintf(stderr, "Couldn't set baud rate for %s to %s\n",
tty_name, tty_baud);
+ if (make_terminal_raw(th, tty_name) != 0)
+ fprintf(stderr, "Couldn't make %s a raw terminal\n", tty_name);
+
th->poller = console_register_poller(console, handler, tty_poll,
th->fd, POLLIN, NULL);
th->console = console;