File tree Expand file tree Collapse file tree 9 files changed +55
-33
lines changed Expand file tree Collapse file tree 9 files changed +55
-33
lines changed Original file line number Diff line number Diff line change @@ -26,34 +26,6 @@ static const char *username;
2626
2727struct device * selected_device ;
2828
29- int tty_open (const char * tty , struct termios * old )
30- {
31- struct termios tios ;
32- int ret ;
33- int fd ;
34-
35- fd = open (tty , O_RDWR | O_NOCTTY | O_EXCL );
36- if (fd < 0 )
37- err (1 , "unable to open \"%s\"" , tty );
38-
39- ret = tcgetattr (fd , old );
40- if (ret < 0 )
41- err (1 , "unable to retrieve \"%s\" tios" , tty );
42-
43- memset (& tios , 0 , sizeof (tios ));
44- tios .c_cflag = B115200 | CS8 | CLOCAL | CREAD ;
45- tios .c_iflag = IGNPAR ;
46- tios .c_oflag = 0 ;
47-
48- tcflush (fd , TCIFLUSH );
49-
50- ret = tcsetattr (fd , TCSANOW , & tios );
51- if (ret < 0 )
52- err (1 , "unable to update \"%s\" tios" , tty );
53-
54- return fd ;
55- }
56-
5729static void fastboot_opened (struct fastboot * fb , void * data )
5830{
5931 const uint8_t one = 1 ;
Original file line number Diff line number Diff line change 66
77#include "cdba.h"
88
9- int tty_open (const char * tty , struct termios * old );
10-
119void cdba_send_buf (int type , size_t len , const void * buf );
1210#define cdba_send (type ) cdba_send_buf(type, 0, NULL)
1311
Original file line number Diff line number Diff line change 1313
1414#include "cdba-server.h"
1515#include "device.h"
16+ #include "tty.h"
1617#include "watch.h"
1718
1819struct console {
Original file line number Diff line number Diff line change 1717#include <termios.h>
1818#include <unistd.h>
1919
20- #include "cdba-server.h"
2120#include "device.h"
21+ #include "tty.h"
2222
2323struct alpaca {
2424 int alpaca_fd ;
Original file line number Diff line number Diff line change 1717#include <termios.h>
1818#include <unistd.h>
1919
20- #include "cdba-server.h"
2120#include "device.h"
2221#include "status.h"
22+ #include "tty.h"
2323#include "watch.h"
2424
2525struct cdb_assist {
Original file line number Diff line number Diff line change 2121#include "cdba-server.h"
2222#include "device.h"
2323#include "status.h"
24+ #include "tty.h"
2425#include "watch.h"
2526
2627enum qcomlt_parse_state {
Original file line number Diff line number Diff line change @@ -89,7 +89,8 @@ server_srcs = ['cdba-server.c',
8989 ' ppps.c' ,
9090 ' status.c' ,
9191 ' status-cmd.c' ,
92- ' watch.c' ]
92+ ' watch.c' ,
93+ ' tty.c' ]
9394
9495build_server = true
9596foreach d : server_deps
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2016-2018, Linaro Ltd.
3+ * All rights reserved.
4+ *
5+ * SPDX-License-Identifier: BSD-3-Clause
6+ */
7+
8+ #include <fcntl.h>
9+ #include <termios.h>
10+ #include <unistd.h>
11+ #include <err.h>
12+ #include <string.h>
13+
14+ #include "tty.h"
15+
16+ int tty_open (const char * tty , struct termios * old )
17+ {
18+ struct termios tios ;
19+ int ret ;
20+ int fd ;
21+
22+ fd = open (tty , O_RDWR | O_NOCTTY | O_EXCL );
23+ if (fd < 0 )
24+ err (1 , "unable to open \"%s\"" , tty );
25+
26+ ret = tcgetattr (fd , old );
27+ if (ret < 0 )
28+ err (1 , "unable to retrieve \"%s\" tios" , tty );
29+
30+ memset (& tios , 0 , sizeof (tios ));
31+ tios .c_cflag = B115200 | CS8 | CLOCAL | CREAD ;
32+ tios .c_iflag = IGNPAR ;
33+ tios .c_oflag = 0 ;
34+
35+ tcflush (fd , TCIFLUSH );
36+
37+ ret = tcsetattr (fd , TCSANOW , & tios );
38+ if (ret < 0 )
39+ err (1 , "unable to update \"%s\" tios" , tty );
40+
41+ return fd ;
42+ }
Original file line number Diff line number Diff line change 1+ #ifndef __TTY_H__
2+ #define __TTY_H__
3+
4+ struct termios ;
5+ int tty_open (const char * tty , struct termios * old );
6+
7+ #endif
You can’t perform that action at this time.
0 commit comments