diff --git a/devamlc.h b/devamlc.h index c872bf3..dc04513 100644 --- a/devamlc.h +++ b/devamlc.h @@ -130,13 +130,31 @@ int devamlc (int class, int func, int device) { #define CT_SERIAL 2 #define CT_DEDIP 3 - /* terminal states needed to process telnet connections */ + /* terminal states needed to process telnet connections. + Ref: http://support.microsoft.com/kb/231866 + Ref: http://www.iana.org/assignments/telnet-options */ #define TS_DATA 0 /* data state, looking for IAC */ #define TS_IAC 1 /* have seen initial IAC */ #define TS_SUBOPT 2 /* inside a suboption */ #define TS_OPTION 3 /* inside an option */ + /* telnet protocol special characters */ + +#define TN_IAC 255 +#define TN_WILL 251 +#define TN_WONT 252 +#define TN_DO 253 +#define TN_DONT 254 + + /* telnet options */ + +#define TN_BINARY 0 +#define TN_ECHO 1 +#define TN_SGA 3 /* means this is a full-duplex connection */ +#define TN_KERMIT 47 +#define TN_SUBOPT 250 + static short inited = 0; static int pollspeedup = 1; static int baudtable[16] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200}; @@ -156,7 +174,7 @@ int devamlc (int class, int func, int device) { unsigned short ctinterrupt; /* 1 bit per line */ unsigned short dss; /* 1 bit per line */ unsigned short connected; /* 1 bit per line */ - unsigned short dedicated; /* 1 bit per line */ + unsigned short isserial; /* 1 bit per line */ unsigned short dsstime; /* countdown to dss poll */ short fd[16]; /* Unix fd, 1 per line */ unsigned short tstate[16]; /* telnet state */ @@ -189,7 +207,7 @@ int devamlc (int class, int func, int device) { fd_set fds; struct timeval timeout; unsigned char ch; - int state; + int tstate, toper; int msgfd; int allbusy; unsigned short qtop, qbot, qtemp; @@ -251,7 +269,7 @@ int devamlc (int class, int func, int device) { dc[dx2].deviceid = 0; for (lx = 0; lx < 16; lx++) { dc[dx2].connected = 0; - dc[dx2].dedicated = 0; + dc[dx2].isserial = 0; for (lx = 0; lx < 16; lx++) { dc[dx2].fd[lx] = -1; dc[dx2].tstate[lx] = TS_DATA; @@ -305,7 +323,7 @@ int devamlc (int class, int func, int device) { printf("em: connected AMLC line '%o (%d) to device %s\n", i, i, devname); dc[dx2].fd[lx] = fd; dc[dx2].connected |= BITMASK16(lx+1); - dc[dx2].dedicated |= BITMASK16(lx+1); + dc[dx2].isserial |= BITMASK16(lx+1); dc[dx2].ctype[lx] = CT_SERIAL; } else { @@ -451,7 +469,7 @@ int devamlc (int class, int func, int device) { #define TIOCM_CD 0x0100 if (func == 00) { /* input Data Set Sense (carrier) */ - if (dc[dx].dedicated) { /* any serial connections? */ + if (dc[dx].isserial) { /* any serial connections? */ if (--dc[dx].dsstime == 0) { dc[dx].dsstime = DSSCOUNTDOWN; for (lx = 0; lx < 16; lx++) { /* yes, poll them */ @@ -726,7 +744,7 @@ int devamlc (int class, int func, int device) { ipaddr = ntohl(addr.sin_addr.s_addr); snprintf(ipstring, sizeof(ipstring), "%d.%d.%d.%d", (ipaddr&0xFF000000)>>24, (ipaddr&0x00FF0000)>>16, (ipaddr&0x0000FF00)>>8, (ipaddr&0x000000FF)); - printf("Connect from IP %x\n", ipaddr); + //printf("Connect from IP %s\n", ipstring); /* if there are dedicated AMLC lines (specific IP address), we have to make 2 passes: the first pass checks for IP address @@ -782,15 +800,15 @@ endconnect: methods, this stuff might be better off in a very thin connection server */ - buf[0] = 255; /* IAC */ - buf[1] = 251; /* will */ - buf[2] = 1; /* echo */ - buf[3] = 255; /* IAC */ - buf[4] = 251; /* will */ - buf[5] = 3; /* supress go ahead */ - buf[6] = 255; /* IAC */ - buf[7] = 253; /* do */ - buf[8] = 0; /* binary mode */ + buf[0] = TN_IAC; + buf[1] = TN_WILL; + buf[2] = TN_ECHO; + buf[3] = TN_IAC; + buf[4] = TN_DO; + buf[5] = TN_SGA; + buf[6] = TN_IAC; + buf[7] = TN_DO; + buf[8] = TN_BINARY; write(fd, buf, 9); /* send out the ttymsg greeting */ @@ -1008,13 +1026,13 @@ endconnect: if (n > 0) { //printf("devamlc: RECV dx=%d, lx=%d, b=%d, tried=%d, read=%d\n", dx, lx, dc[dx].bufnum, n2, n); - state = dc[dx].tstate[lx]; + tstate = dc[dx].tstate[lx]; for (i=0; i