aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c9
-rw-r--r--src/serial.c64
2 files changed, 70 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index d6493cd..dd10ce4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -134,14 +134,17 @@ int main(int argc, char* argv[])
fclose (pidfile);
}//if params.pidfile
- if(params.serial)
+ if ( params.serial )
printf("asdf");
- else if (params.telnet)
-
+ else if ( params.telnet )
+ telnet_server( params );
return 0;
}
+void dialup_server(struct prog_params params)
+{
+}
void telnet_server(struct prog_params params)
{
diff --git a/src/serial.c b/src/serial.c
new file mode 100644
index 0000000..01f27bb
--- /dev/null
+++ b/src/serial.c
@@ -0,0 +1,64 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+int
+set_interface_attribs (int fd, int speed, int parity)
+{
+ struct termios tty;
+ memset (&tty, 0, sizeof tty);
+ if (tcgetattr (fd, &tty) != 0)
+ {
+ error_message ("error %d from tcgetattr", errno);
+ return -1;
+ }
+
+ cfsetospeed (&tty, speed);
+ cfsetispeed (&tty, speed);
+
+ tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
+ // disable IGNBRK for mismatched speed tests; otherwise receive break
+ // as \000 chars
+ tty.c_iflag &= ~IGNBRK; // disable break processing
+ tty.c_lflag = 0; // no signaling chars, no echo,
+ // no canonical processing
+ tty.c_oflag = 0; // no remapping, no delays
+ tty.c_cc[VMIN] = 0; // read doesn't block
+ tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
+
+ tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
+
+ tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
+ // enable reading
+ tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
+ tty.c_cflag |= parity;
+ tty.c_cflag &= ~CSTOPB;
+ tty.c_cflag &= ~CRTSCTS;
+
+ if (tcsetattr (fd, TCSANOW, &tty) != 0)
+ {
+ error_message ("error %d from tcsetattr", errno);
+ return -1;
+ }
+ return 0;
+}
+
+void
+set_blocking (int fd, int should_block)
+{
+ struct termios tty;
+ memset (&tty, 0, sizeof tty);
+ if (tcgetattr (fd, &tty) != 0)
+ {
+ error_message ("error %d from tggetattr", errno);
+ return;
+ }
+
+ tty.c_cc[VMIN] = should_block ? 1 : 0;
+ tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
+
+ if (tcsetattr (fd, TCSANOW, &tty) != 0)
+ error_message ("error %d setting term attributes", errno);
+}