summaryrefslogtreecommitdiffstats
path: root/servers/fpga_server_lin/src/fpga_conn.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-26 15:43:45 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-26 15:43:45 -0500
commit249a46324f4f46a6c8afd11f74c8c73ede152184 (patch)
tree65ef4e06e7db679f96d29039066ee1ed712fb837 /servers/fpga_server_lin/src/fpga_conn.cpp
parentfbfb9b1a49003013f646f81b344d5d3a44255c44 (diff)
downloadulab-249a46324f4f46a6c8afd11f74c8c73ede152184.tar.gz
ulab-249a46324f4f46a6c8afd11f74c8c73ede152184.zip
Add skeleton for missing functions in tde kerberos library
Diffstat (limited to 'servers/fpga_server_lin/src/fpga_conn.cpp')
-rw-r--r--servers/fpga_server_lin/src/fpga_conn.cpp127
1 files changed, 116 insertions, 11 deletions
diff --git a/servers/fpga_server_lin/src/fpga_conn.cpp b/servers/fpga_server_lin/src/fpga_conn.cpp
index 499d067..1b0927c 100644
--- a/servers/fpga_server_lin/src/fpga_conn.cpp
+++ b/servers/fpga_server_lin/src/fpga_conn.cpp
@@ -20,7 +20,21 @@
* http://www.raptorengineeringinc.com
*/
-#include <stdlib.h>
+#include <stdio.h> /* perror() */
+#include <stdlib.h> /* atoi() */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h> /* read() */
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/signal.h>
+#include <sys/types.h>
+
+#include <tqtimer.h>
#include <klocale.h>
@@ -38,12 +52,13 @@ struct exit_exception {
instance of this class.
*/
FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) :
- TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_config(static_cast<FPGAServer*>(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL) {
+ TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_config(static_cast<FPGAServer*>(parent)->m_config) {
setServiceName("remotefpga");
line = 0;
connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler()));
+ connect(this, SIGNAL(connectionClosed()), parent, SLOT(remoteConnectionClosed()));
setSocket(sock);
}
@@ -52,8 +67,11 @@ FPGASocket::~FPGASocket() {
}
void FPGASocket::close() {
- TDEKerberosServerSocket::close();
- connectionClosedHandler();
+ if (state() == TQSocket::Connected) {
+ TDEKerberosServerSocket::close();
+ connectionClosedHandler();
+ TQTimer::singleShot(0, parent(), SLOT(remoteConnectionClosed()));
+ }
}
void FPGASocket::connectionClosedHandler() {
@@ -76,8 +94,76 @@ int FPGASocket::initiateKerberosHandshake() {
}
}
-void FPGASocket::enterCommandLoop() {
- // RAJA FIXME
+int FPGASocket::setupSerial() {
+ struct termios oldtio, newtio;
+
+ m_config->setGroup("FPGA");
+ TQString serialDevice = m_config->readEntry("serialdevice", "/dev/ttyS0");
+ TQString desiredBaudRate = m_config->readEntry("baudrate", "9600");
+
+ m_fd_tty = ::open(serialDevice.ascii(), O_RDWR | O_NOCTTY | O_NONBLOCK | O_APPEND);
+ if (m_fd_tty < 0) {
+ printf("[FAIL] Unable to open serial device %s\n\r", serialDevice.ascii()); fflush(stdout);
+ return 1;
+ }
+
+ tcgetattr(m_fd_tty, &oldtio); // Save current port settings
+
+ long serialBaud;
+ if (desiredBaudRate == "9600") {
+ serialBaud = B9600;
+ }
+ else if (desiredBaudRate == "115200") {
+ serialBaud = B115200;
+ }
+ else {
+ printf("[WARNING] Invalid baudrate %s specified, selecting 9600 instead\n\r", desiredBaudRate.ascii()); fflush(stdout);
+ serialBaud = B9600;
+ }
+
+ bzero(&newtio, sizeof(newtio));
+ newtio.c_cflag = serialBaud | CS8 | CLOCAL | CREAD;
+ newtio.c_iflag = IGNPAR;
+ newtio.c_oflag = 0;
+
+ // Set input mode (non-canonical, no echo,...)
+ newtio.c_lflag = 0;
+
+ newtio.c_cc[VTIME] = 0; // Inter-character timer unused
+ newtio.c_cc[VMIN] = 0; // Blocking read unused
+
+ tcflush(m_fd_tty, TCIFLUSH);
+ tcsetattr(m_fd_tty, TCSANOW, &newtio);
+
+ return 0;
+}
+
+int FPGASocket::enterCommandLoop() {
+ m_criticalSection++;
+ try {
+ while (state() == TQSocket::Connected) {
+ // RAJA FIXME
+// cc = read(fd_tty, readbuf, 100000);
+// if (cc > 0) {
+// write_data_to_client(fd, readbuf, cc);
+// fsync(fd_tty);
+// printf("[DEBUG] Got %d bytes from the serial port\n\r", cc); fflush(stdout);
+// }
+// cc = read(fd, writebuf, 100000);
+// if (cc > 0) {
+// write(fd_tty, writebuf, cc);
+// fsync(fd);
+// printf("[DEBUG] Got %d bytes from the network interface\n\r", cc); fflush(stdout);
+// }
+ }
+
+ m_criticalSection--;
+ return 0;
+ }
+ catch (...) {
+ m_criticalSection--;
+ return -1;
+ }
}
/*
@@ -93,8 +179,6 @@ FPGAServer::FPGAServer(TQObject* parent, int port, KSimpleConfig* config) :
exit(1);
}
- socketDevice()->setAddressReusable(false);
-
printf("[INFO] Server started on port %d\n\r", port); fflush(stdout);
}
@@ -107,21 +191,42 @@ void FPGAServer::newConnection(int socket) {
s->m_remoteHost = s->peerAddress().toString();
printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii());
if (m_numberOfConnections > 0) {
- printf("[DEBUG] Connection from %s closed due to multiple access attempt\n\r", m_remoteHost.ascii());
+ printf("[DEBUG] Connection from %s closed due to multiple access attempt\n\r", s->m_remoteHost.ascii());
s->close();
delete s;
s = NULL;
+ return;
}
if (s->initiateKerberosHandshake() != 0) {
- printf("[DEBUG] Connection from %s closed due to Kerberos failure\n\r", m_remoteHost.ascii());
+ printf("[DEBUG] Connection from %s closed due to Kerberos failure\n\r", s->m_remoteHost.ascii());
+ s->close();
+ delete s;
+ s = NULL;
+ return;
+ }
+ m_config->setGroup("Security");
+ TQString masterUser = m_config->readEntry("masteruser");
+ TQString masterRealm = m_config->readEntry("masterrealm");
+ if (masterRealm == "") {
+ masterRealm = "(NULL)";
+ }
+ if ((s->m_authenticatedUserName != masterUser) || (s->m_authenticatedRealmName != masterRealm)) {
+ printf("[DEBUG] Connection from %s closed due to authentication failure (attempted connection as user %s@%s)\n\r", s->m_remoteHost.ascii(), masterUser.ascii(), masterRealm.ascii());
+ s->close();
+ delete s;
+ s = NULL;
+ return;
+ }
+ if (s->setupSerial() != 0) {
+ printf("[DEBUG] Connection from %s closed due to serial port initialization failure\n\r", s->m_remoteHost.ascii());
s->close();
delete s;
s = NULL;
+ return;
}
else {
m_numberOfConnections++;
connect(s, SIGNAL(connectionClosed()), s, SLOT(deleteLater()));
- connect(s, SIGNAL(connectionClosed()), this, SLOT(remoteConnectionClosed()));
emit newConnect(s);
s->enterCommandLoop();
}