# HG changeset patch # User Mychaela Falconia # Date 1506037505 0 # Node ID 6f078c4a5506668caf7562676bea0f75ad337bf8 # Parent d27a890682809f4992cc4df736a2a27c38e87dda rvinterf and friends converted to use libserial diff -r d27a89068280 -r 6f078c4a5506 rvinterf/lowlevel/Makefile --- a/rvinterf/lowlevel/Makefile Thu Sep 21 23:30:53 2017 +0000 +++ b/rvinterf/lowlevel/Makefile Thu Sep 21 23:45:05 2017 +0000 @@ -2,26 +2,26 @@ CFLAGS= -O2 PROGS= rvtdump rvinterf tfc139 INSTBIN=/opt/freecalypso/bin -LIBG23= ../libg23/libg23.a +LIBS= ../../libserial/libserial.a ../libg23/libg23.a -RVTDUMP_OBJS= format.o format_fc.o openport.o output.o packetrx.o rvtdump.o +RVTDUMP_OBJS= format.o format_fc.o output.o packetrx.o rvtdump.o RVINTERF_OBJS= clientcmd.o format.o format_fc.o localsock.o logsent.o \ - openport.o output.o packetrx.o packettx.o pktfwd.o rviflcd.o \ + output.o packetrx.o packettx.o pktfwd.o rviflcd.o \ rvifmain.o -TFC139_OBJS= format.o openport.o output.o packetrx.o packettx.o tfc139.o +TFC139_OBJS= format.o output.o packetrx.o packettx.o tfc139.o all: ${PROGS} -rvtdump: ${RVTDUMP_OBJS} ${LIBG23} - ${CC} ${CFLAGS} -o $@ ${RVTDUMP_OBJS} ${LIBG23} +rvtdump: ${RVTDUMP_OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${RVTDUMP_OBJS} ${LIBS} -rvinterf: ${RVINTERF_OBJS} ${LIBG23} - ${CC} ${CFLAGS} -o $@ ${RVINTERF_OBJS} ${LIBG23} +rvinterf: ${RVINTERF_OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${RVINTERF_OBJS} ${LIBS} -tfc139: ${TFC139_OBJS} ${LIBG23} - ${CC} ${CFLAGS} -o $@ ${TFC139_OBJS} ${LIBG23} +tfc139: ${TFC139_OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${TFC139_OBJS} ${LIBS} install: ${PROGS} mkdir -p ${INSTBIN} diff -r d27a89068280 -r 6f078c4a5506 rvinterf/lowlevel/openport.c --- a/rvinterf/lowlevel/openport.c Thu Sep 21 23:30:53 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* - * This module takes care of opening the serial port and setting the - * proper "raw" termios modes, including the baud rate. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int target_fd; -char *baudrate_name = "115200"; - -static struct baudrate { - char *name; - speed_t termios_code; -} baud_rate_table[] = { - {"19200", B19200}, - {"38400", B38400}, - {"57600", B57600}, - {"115200", B115200}, - /* non-standard high baud rates "remapped" by CP2102 usb2serial IC */ - {"203125", B230400}, - {"406250", B460800}, - {"812500", B921600}, - /* table search terminator */ - {NULL, B0} -}; - -static speed_t -get_baud_rate() -{ - struct baudrate *br; - - for (br = baud_rate_table; br->name; br++) - if (!strcmp(br->name, baudrate_name)) - break; - if (!br->name) { - fprintf(stderr, "baud rate \"%s\" unknown/unsupported\n", - baudrate_name); - exit(1); - } - return br->termios_code; -} - -open_target_serial(ttydev) - char *ttydev; -{ - struct termios target_termios; - speed_t br_code; - - br_code = get_baud_rate(); - target_fd = open(ttydev, O_RDWR|O_NONBLOCK); - if (target_fd < 0) { - perror(ttydev); - exit(1); - } - target_termios.c_iflag = IGNBRK; - target_termios.c_oflag = 0; - target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; - target_termios.c_lflag = 0; - target_termios.c_cc[VMIN] = 1; - target_termios.c_cc[VTIME] = 0; - cfsetispeed(&target_termios, br_code); - cfsetospeed(&target_termios, br_code); - if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { - perror("initial tcsetattr on target"); - exit(1); - } - ioctl(target_fd, TIOCEXCL); - return 0; -} - -set_serial_nonblock(state) - int state; -{ - ioctl(target_fd, FIONBIO, &state); -} diff -r d27a89068280 -r 6f078c4a5506 rvinterf/lowlevel/rvifmain.c --- a/rvinterf/lowlevel/rvifmain.c Thu Sep 21 23:30:53 2017 +0000 +++ b/rvinterf/lowlevel/rvifmain.c Thu Sep 21 23:45:05 2017 +0000 @@ -16,7 +16,6 @@ #include "client.h" extern int target_fd, listener; -extern char *baudrate_name; extern char *extlcd_program; extern u_char extlcd_invert; @@ -36,6 +35,8 @@ int wakeup_after_sec = 7; +static char *baudrate = "115200"; + static char keepalive_msg[] = "Received keepalive query, responding with keepalive answer"; static u_char keepalive_answer[2] = {RVT_KEEPALIVE_HEADER, 'A'}; @@ -58,7 +59,7 @@ no_output++; continue; case 'B': - baudrate_name = optarg; + baudrate = optarg; continue; case 'd': target_fd = atoi(optarg); @@ -90,7 +91,8 @@ if (target_fd <= 0) { if (argc - optind != 1) goto usage; - open_target_serial(argv[optind]); + open_serial_port(argv[optind]); + set_fixed_baudrate(baudrate); } max_fd = target_fd; if (extlcd_program) diff -r d27a89068280 -r 6f078c4a5506 rvinterf/lowlevel/rvtdump.c --- a/rvinterf/lowlevel/rvtdump.c Thu Sep 21 23:30:53 2017 +0000 +++ b/rvinterf/lowlevel/rvtdump.c Thu Sep 21 23:45:05 2017 +0000 @@ -12,7 +12,6 @@ #include "../include/pktmux.h" extern int target_fd; -extern char *baudrate_name; extern u_char rxpkt[]; extern size_t rxpkt_len; @@ -23,6 +22,8 @@ int background; int no_output; /* for output.c */ +static char *baudrate = "115200"; + static char keepalive_msg[] = "Received keepalive query, unable to respond, please run rvinterf"; @@ -41,7 +42,7 @@ no_output++; /* for output.c */ continue; case 'B': - baudrate_name = optarg; + baudrate = optarg; continue; case 'd': target_fd = atoi(optarg); @@ -62,7 +63,8 @@ if (target_fd <= 0) { if (argc - optind != 1) goto usage; - open_target_serial(argv[optind]); + open_serial_port(argv[optind]); + set_fixed_baudrate(baudrate); } set_serial_nonblock(0); diff -r d27a89068280 -r 6f078c4a5506 rvinterf/lowlevel/tfc139.c --- a/rvinterf/lowlevel/tfc139.c Thu Sep 21 23:30:53 2017 +0000 +++ b/rvinterf/lowlevel/tfc139.c Thu Sep 21 23:45:05 2017 +0000 @@ -22,7 +22,6 @@ #include "../include/limits.h" extern int target_fd; -extern char *baudrate_name; extern u_char rxpkt[]; extern size_t rxpkt_len; @@ -61,6 +60,7 @@ static int breakin_in_progress; static char *target_tty_port; +static char *baudrate = "57600"; static void send_compal_memwrite(addr, payload, payload_len) @@ -139,14 +139,13 @@ int c; fd_set fds; - baudrate_name = "57600"; /* what C139 firmware uses */ while ((c = getopt(argc, argv, "a:AB:l:ms:w:")) != EOF) switch (c) { case 'a': shellcode_load_addr = strtoul(optarg, 0, 16); continue; case 'B': - baudrate_name = optarg; + baudrate = optarg; continue; case 'l': logfname = optarg; @@ -177,8 +176,9 @@ fprintf(stderr, "usage error: -a option required with -s\n"); exit(1); } - open_target_serial(argv[optind]); + open_serial_port(argv[optind]); target_tty_port = argv[optind]; + set_fixed_baudrate(baudrate); set_serial_nonblock(0); setlinebuf(stdout);