diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2013-08-25 09:59:50 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2013-08-25 09:59:50 -0400 |
commit | 7f1f0172955a41e7e616035f17bb09a765e3cdfb (patch) | |
tree | d1039a9a2ca30d6490b18d6a601bacad6eb7ab49 /redirector.c | |
parent | 502f5eb378dfa19dc35b42e6e3a408dcc2472554 (diff) | |
download | sobredirect-7f1f0172955a41e7e616035f17bb09a765e3cdfb.tar.gz sobredirect-7f1f0172955a41e7e616035f17bb09a765e3cdfb.tar.bz2 sobredirect-7f1f0172955a41e7e616035f17bb09a765e3cdfb.zip |
add in the passthrough sniffer, and start factoring out common code.
Diffstat (limited to 'redirector.c')
-rw-r--r-- | redirector.c | 230 |
1 files changed, 22 insertions, 208 deletions
diff --git a/redirector.c b/redirector.c index b45a442..d67f5c8 100644 --- a/redirector.c +++ b/redirector.c @@ -1,32 +1,24 @@ /* -*-------------------------------------------------------------------------- -* -* Copyright (C) 2006 AbsoluteValue Systems, Inc. All Rights Reserved. -* -* The contents of this file are subject to the licensing terms -* between AbsoluteValue Systems, Inc., and licensees of -* AbsoluteValue Systems linux-wlan(tm). You may not use this file -* except in compliance with the said License. When in doubt, do not -* distribute the contents of this file without permission from -* AbsoluteValue Sytems, Inc. -* -* Software distributed under the License is distributed on an "AS -* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -* implied. See the License for the specific language governing -* rights and limitations under the License. -* -* Any inquiries regarding this software may be directed to: -* -* AbsoluteValue Systems, Inc. -* info@linux-wlan.com -* http://www.linux-wlan.com -*-------------------------------------------------------------------------- -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> -#include <unistd.h> + Copyright (C) 2006 AbsoluteValue Systems, Inc. All Rights Reserved. + + Originally written and maintained by: Solomon Peachy <pizza@shaftnet.org> + Local redirection & Debugging code by: Mark Mathews <mark@linux-wlan.com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "common.h" #include <errno.h> #include <sys/types.h> @@ -43,13 +35,13 @@ #include <sys/ioctl.h> #include <fcntl.h> -#include <termios.h> #include <signal.h> #include <string.h> #include <syslog.h> + /* Basic over-the-wire serial packet */ struct s_msg { @@ -82,21 +74,9 @@ struct sob_config { #define SERIAL_ESC_CHAR2 0x00 #define SERIAL_ESC_BREAK 0x00 -#define min_t(type,x,y) \ - ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) -#define max_t(type,x,y) \ - ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) - #define MAX_PACKET_LEN 1470 #define BUF_LEN 4096 -#define SERIAL_BAUD_CASE(__b__) case __b__: cfsetispeed(cfg, B ## __b__) ; \ - cfsetospeed(cfg, B ## __b__) ; \ - break - -#define SERIAL_DATA_CASE(__b__) case __b__: cfg->c_cflag |= CS ## __b__ ; \ - break - /* ================================================================ */ static void dump_config(char *prefix, struct sob_config *cfg) @@ -157,148 +137,6 @@ static void send_config(int far_sock, struct sob_config *far_cfg, } } -int setserial(struct termios *cfg, int ser_fd, int baud, - int databits, char parity, int stopbits, - int hw_flow, int sw_flow, int modemlines) -{ - int rval = 0; - - rval = tcgetattr(ser_fd, cfg); - if (rval) goto done; - - cfmakeraw(cfg); - - cfg->c_cc[VMIN] = 1; /* 1 byte minimum */ - cfg->c_cc[VTIME] = 0; /* No timeout */ - - switch(baud) { - SERIAL_BAUD_CASE(50); - SERIAL_BAUD_CASE(75); - SERIAL_BAUD_CASE(110); - SERIAL_BAUD_CASE(134); - SERIAL_BAUD_CASE(150); - SERIAL_BAUD_CASE(200); - SERIAL_BAUD_CASE(300); - SERIAL_BAUD_CASE(600); - SERIAL_BAUD_CASE(1200); - SERIAL_BAUD_CASE(1800); - SERIAL_BAUD_CASE(2400); - SERIAL_BAUD_CASE(4800); - SERIAL_BAUD_CASE(9600); - SERIAL_BAUD_CASE(19200); - SERIAL_BAUD_CASE(38400); - SERIAL_BAUD_CASE(57600); - SERIAL_BAUD_CASE(115200); -// SERIAL_BAUD_CASE(230400); - default: - fprintf(stderr, "Invalid serial baud rate specified (%d)\n", - baud); - rval = 1; - goto done; - } - - parity &= ~0x20; /* make things case insensitive */ - switch (parity) { - case 'N': - cfg->c_cflag &= ~PARENB; - break; - case 'E': - cfg->c_cflag |= PARENB; - cfg->c_cflag &= ~PARODD; - break; - case 'O': - cfg->c_cflag |= PARENB; - cfg->c_cflag |= PARODD; - break; - default: - fprintf(stderr, "Invalid serial parity specified (%c), should be E/O/N\n", - parity); - rval = 2; - goto done; - } - - cfg->c_cflag &= ~CSIZE; - switch(databits) { - SERIAL_DATA_CASE(5); - SERIAL_DATA_CASE(6); - SERIAL_DATA_CASE(7); - SERIAL_DATA_CASE(8); - default: - fprintf(stderr, "Invalid number of data bits specified (%d), should be between 5 and 8.\n", - databits); - rval = 3; - goto done; - } - - switch (stopbits) { - case 1: - cfg->c_cflag &= ~CSTOPB; - break; - case 2: - cfg->c_cflag |= CSTOPB; - break; - default: - fprintf(stderr, "Invalid number of stop bits specified (%d), should be 1 or 2.\n", - stopbits); - rval = 4; - goto done; - } - - cfg->c_iflag &= ~CRTSCTS; - cfg->c_iflag &= ~(IXON|IXOFF|IXANY); - - if (hw_flow) { - cfg->c_iflag |= CRTSCTS; - } - if (sw_flow) { - cfg->c_iflag |= (IXON|IXOFF|IXANY); - cfg->c_cc[VSTART] = 17; - cfg->c_cc[VSTOP] = 19; - } - - if (modemlines) { - cfg->c_cflag |= HUPCL; - cfg->c_cflag &= ~CLOCAL; - } else { - cfg->c_cflag |= CLOCAL; - cfg->c_cflag &= ~HUPCL; - } - - cfg->c_cflag |= CREAD; - - cfg->c_iflag |= PARMRK; - cfg->c_iflag &= ~(IGNPAR | BRKINT | IGNBRK); - - rval = tcsetattr(ser_fd, TCSANOW, cfg); - if (rval) goto done; - -done: - if (rval) fprintf(stderr, "ERROR.. %d\n", rval); - - { - struct termios cfg2; - tcgetattr(ser_fd, &cfg2); - if (cfg->c_iflag != cfg2.c_iflag) { - fprintf(stderr, "ERROR! c_iflag %x vs %x\n", - cfg->c_iflag, cfg2.c_iflag); - } - if (cfg->c_oflag != cfg2.c_oflag) { - fprintf(stderr, "ERROR! c_oflag %x vs %x\n", - cfg->c_oflag, cfg2.c_oflag); - } - if (cfg->c_cflag != cfg2.c_cflag) { - fprintf(stderr, "ERROR! c_cflag %x vs %x\n", - cfg->c_cflag, cfg2.c_cflag); - } - if (cfg->c_lflag != cfg2.c_lflag) { - fprintf(stderr, "ERROR! c_lflag %x vs %x\n", - cfg->c_lflag, cfg2.c_lflag); - } - } - - return rval; -} - void printhelp() { fprintf(stderr, " Serial Over Broadband Redirector\n (c) AbsoluteValue Systems 2006\n\n"); fprintf(stderr, "\t-d <serialdev> -s <commsparams> -i <farhost> -p <farport>\n"); @@ -607,7 +445,7 @@ int main (int argc, char **argv) pfds[1].revents = 0; pfds[1].events = POLLIN|POLLPRI; - syslog(LOG_INFO, "sobredird WIP3 bound and active"); + syslog(LOG_INFO, "sobredird bound and active"); dump_config("Local config: ", &sob_cfg); send_config(far_sock, &sob_cfg, &far_addr); @@ -651,30 +489,6 @@ int main (int argc, char **argv) #if 0 { - fd_set rfds; - fd_set wfds; - int v = 0, j = 0; - FD_ZERO(&rfds); - FD_ZERO(&wfds); - for (j = 0; j < 2 ; j++) { - FD_SET(pfds[j].fd, &rfds); - FD_SET(pfds[j].fd, &wfds); - if (pfds[j].fd > v) - v = pfds[j].fd; - } - v = select(v+1, &rfds, &wfds, NULL, NULL); - for (j = 0; j < 2 ; j++) { - if (FD_ISSET(pfds[j].fd, &rfds)) - fprintf(stderr, "rfd %d %d set\n", j, pfds[i].fd); - if (FD_ISSET(pfds[j].fd, &wfds)) - fprintf(stderr, "wfd %d %d set\n", j, pfds[i].fd); - - } - } -#endif - -#if 0 - { // XXX this lets us get serial line twiddles: // TIOCM_CD TIOCM_RI TIOCM_DSR TIOCM_CTS // TIOCM_DTR TIOCM_RTS int val = 0, j = 0; |