Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of webserverBlinky by
Diff: main.cpp
- Revision:
- 82:051f77f7dd72
- Parent:
- 81:9ede60e9a2c8
- Child:
- 83:cdcb81d1910f
diff -r 9ede60e9a2c8 -r 051f77f7dd72 main.cpp --- a/main.cpp Sat Jul 15 20:50:13 2017 +0000 +++ b/main.cpp Sun Jul 16 13:54:08 2017 +0000 @@ -29,7 +29,7 @@ // The #define below enables/disables a SECOND (optional) serial port that prints out interesting diagnostic messages. // Change to SERIAL_PORT_MONITOR_YES to enable diagnostics messages. You need to wire a second serial port to your mbed hardware to monitor this. -#define SERIAL_PORT_MONITOR_YES /* or change to SERIAL_PORT_MONITOR_YES */ +#define SERIAL_PORT_MONITOR_NO /* or change to SERIAL_PORT_MONITOR_YES */ #ifndef SERIAL_PORT_MONITOR_NO Serial xx(PC_10, PC_11); // Not required to run, if you get compile error here, change #define SERIAL_PORT_MONITOR_YES to #define SERIAL_PORT_MONITOR_NO @@ -488,7 +488,7 @@ snprintf(srcIP,16, "%d.%d.%d.%d", srcAdr[0],srcAdr[1],srcAdr[2],srcAdr[3]); char dstIP [16]; snprintf(dstIP,16, "%d.%d.%d.%d", dstAdr[0],dstAdr[1],dstAdr[2],dstAdr[3]); - if (v0) debug("IP %s %s v%d h%d d%d e%d L%d ",srcIP,dstIP,versionIP,headerSizeIP,dscpIP,ecnIP,packetLength); + if (v0) debug("IP %s %s v%d h%d d%d e%d L%03d ",srcIP,dstIP,versionIP,headerSizeIP,dscpIP,ecnIP,packetLength); if (v0) debug("i%04x f%d t%d p%d C%04x\n",identIP,flagsIP,ttlIP,protocolIP,checksumIP); } @@ -595,6 +595,7 @@ char * acktcp = s + 8; // 4 bytes char * offset = s + 12; // 4 bits char * flagbitstcp = s + 12; // 9 bits + char * windowsizetcp = s + 14; // 2 bytes char * checksumtcp = s + 16; // 2 bytes int tcpSize = packetLength - headerSizeIP; @@ -629,6 +630,14 @@ if ( tcpDataSize != 1 ) return; ack++; case TCP_FLAG_SYN: + // ignore all TCP options by shortening packet to 40 bytes + pktLen[1] = 40; // shorten packet to 40 bytes + packetLength = 40; // shorten packet to 40 bytes + headerSizeTCP = 20; // shorten packet to 40 bytes + tcpSize = 20; // shorten packet to 40 bytes + headerSizeTCP = 20; // shorten packet to 40 bytes + offset[0] = (headerSizeTCP/4)<<4; // shorten packet to 40 bytes + flagsOut = TCP_FLAG_SYN | TCP_FLAG_ACK; // something wants to connect - ack it ppp.seq = ppp.seq + 10000; // create a new sequence number (normally random) seq = ppp.seq; // create a new sequence number (normally random) @@ -667,6 +676,9 @@ memcpy(tempHold, srctcp,2); memcpy(srctcp, dsttcp,2); memcpy(dsttcp, tempHold,2); // swap ip port source/dest + + windowsizetcp[0]=16; // ignore window size negotiation + windowsizetcp[1]=0; // ignore winodw size negotiation acktcp[0]=ack>>24; acktcp[1]=ack>>16; @@ -773,7 +785,7 @@ char dstIP [16]; snprintf(dstIP,16, "%d.%d.%d.%d", dstAdr[0],dstAdr[1],dstAdr[2],dstAdr[3]); if (v0) { - debug("IP %s %s v%d h%d d%d e%d L%d ",srcIP,dstIP,versionIP,headerSizeIP,dscpIP,ecnIP,packetLength); + debug("IP %s %s v%d h%d d%d e%d L%03d ",srcIP,dstIP,versionIP,headerSizeIP,dscpIP,ecnIP,packetLength); } if (v0) { debug("i%04x f%d t%d p%d C%04x\n",identIP,flagsIP,ttlIP,protocolIP,checksumIP); @@ -933,9 +945,8 @@ void * found2 = memchr( (char *)ppp.rx.buf, 0x7e, RXBUFLEN ); if( (found1 != NULL) | (found2 != NULL) ) { if (found1 != NULL) { - //strcpy( found1, "FOUND!FOUND!" ); // overwrite so we don't find it again + memset(ppp.rx.buf, 0x20, RXBUFLEN); // clear the receive buffer // respond with Windows Dialup networking expected "Direct Connection Between Two Computers" response string - memset(ppp.rx.buf, 0, RXBUFLEN); // clear the receive buffer pc.puts("CLIENTSERVER"); if (v0) debug("Found connect string \"CLIENTCLIENT\"\n"); } @@ -960,9 +971,7 @@ pc.attach(&rxHandler,Serial::RxIrq); // start the receive handler while(1) { - debug("scan\n"); scanForConnectString(); // respond to connect command from windows dial up networking - debug("found\n"); while(ppp.online) { wait_for_HDLC_frame(); }