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 PPP-Blinky by
Diff: main.cpp
- Revision:
- 7:ab147f5e97ac
- Parent:
- 6:fba4c2e817b8
- Child:
- 8:48e40f1ff316
--- a/main.cpp Thu Dec 29 10:48:57 2016 +0000
+++ b/main.cpp Thu Dec 29 16:31:48 2016 +0000
@@ -126,6 +126,13 @@
}
+void generalFrame() {
+ xx.printf("== General Frame ==\n");
+ for(int i=0;i<ppp.pkt.len;i++) xx.printf("%02x ", ppp.pkt.buf[i]);
+ xx.printf(" C %02x %02x L=%d\n", ppp.pkt.crc&0xff, (ppp.pkt.crc>>8)&0xff, ppp.pkt.len);
+}
+
+
void sendFrame(){
crcReset(); for(int i=0;i<ppp.pkt.len-2;i++) crcDo(ppp.pkt.buf[i]);
ppp.pkt.buf[ ppp.pkt.len-2 ] = ((~crcG)>>0); // build crc lo
@@ -141,26 +148,26 @@
void LCPrequestFrame() {
- ppp.pkt.buf[4]=2; // change to an ACK packet
- sendFrame(); // acknowledge their request
- // this is the right time to send our LCP setup request to them
- ppp.pkt.buf[4]=1; // change back to a request
- ppp.pkt.buf[5] = ppp.pkt.buf[5]+1; // take the next id
- ppp.pkt.buf[16] = ppp.pkt.buf[16] ^ 0x33; // modify magic number
- ppp.pkt.buf[17] = ppp.pkt.buf[16] ^ 0x33; // modify magic number
- sendFrame(); // send our request
+ xx.printf("== LCP Request ==\n");
+ if (ppp.pkt.buf[7] != 4) {
+ ppp.pkt.buf[4]=4; // nack everything until zero len
+ sendFrame();
+ } else {
+ ppp.pkt.buf[4]=2; // ack zero conf
+ sendFrame();
+ // send our config request - also all zeros
+ ppp.pkt.buf[4]=1; // request zero conf
+ sendFrame();
+ }
+}
-}
+
+
void LCPackFrame() {
- xx.printf("== PPP is up ==\n");
+ xx.printf("== Saw Ack - PPP is up ==\n");
}
-void generalFrame() {
- xx.printf("== General Frame ==\n");
- for(int i=0;i<ppp.pkt.len;i++) xx.printf("%02x ", ppp.pkt.buf[i]);
- xx.printf(" C %02x %02x L=%d\n", ppp.pkt.crc&0xff, (ppp.pkt.crc>>8)&0xff, ppp.pkt.len);
-}
void rejectIPcompression() {
xx.printf("== IP Compression Reject Frame ==\n");
@@ -175,16 +182,22 @@
void ipRequestHandler(){
xx.printf("== IP Request Frame ==\n");
- //static char compressRequest[] = {2,6,0,45,15,1};
- //if(0==memcmp(ppp.pkt.buf+6, compressRequest, 6)) rejectIPcompression();
- generalFrame();
- ppp.pkt.buf[2]=2; // ACK
- sendFrame(); // acknowledge
-
- ppp.pkt.buf[2]=1; // request
- ppp.pkt.buf[3]++; // next sequence
- sendFrame(); // now WE do a request
-
+ if( ppp.pkt.buf[7] != 10 ) {
+ ppp.pkt.buf[4]=4; // Nack
+ sendFrame(); // we want minimum config
+ } else {
+ ppp.pkt.buf[4]=2; // ack the minimum
+ ppp.pkt.buf[10]=10; // ip addr 1
+ ppp.pkt.buf[11]=10; // ip addr 2
+ ppp.pkt.buf[12]=10; // ip addr 3
+ ppp.pkt.buf[13]=10; // ip addr 4
+ sendFrame(); // acknowledge
+ xx.printf("zeroconf ack\n");
+ // send our own request now
+ ppp.pkt.buf[4]=1; // request the minimum
+ ppp.pkt.buf[5]++; // next sequence
+ sendFrame(); // this is our request
+ }
}
void ipAckHandler(){
@@ -206,7 +219,6 @@
void LCPhandler(){
- xx.printf("== LCP Handler ==\n");
int action = ppp.pkt.buf[4];
if(0);
else if ( action == 1 ) LCPrequestFrame();
@@ -215,10 +227,10 @@
}
void IPFrame() {
- led1 = ppp.pkt.buf[3] & 1; // This is the sequence number so the led blinks on packets
- ppp.pkt.len = (((unsigned int)ppp.pkt.buf[4])<<8) + (((unsigned int)ppp.pkt.buf[5])<<0);
- ppp.pkt.id = ppp.pkt.buf[3]; // remember the sequence number
- int action = ppp.pkt.buf[2]; // packet type is here
+ led1 = ppp.pkt.buf[5] & 1; // This is the sequence number so the led blinks on packets
+ //ppp.pkt.len = (((unsigned int)ppp.pkt.buf[4])<<8) + (((unsigned int)ppp.pkt.buf[5])<<0);
+ ppp.pkt.id = ppp.pkt.buf[5]; // remember the sequence number
+ int action = ppp.pkt.buf[4]; // packet type is here
if(0);
else if ( action == 1 ) ipRequestHandler();
else if ( action == 2 ) ipAckHandler();
@@ -227,12 +239,12 @@
}
void determinePacketType() {
- static char pktLCPReqType [] = { 0xff, 3, 0xc0, 0x21 }; // LCP requeswt packet
- static char pktIPCPtype [] = { 0x80, 0x21, 1 }; // ip control packet
+ static char pktLCPReqType [] = { 0xff, 3, 0xc0, 0x21 }; // LCP packet
+ static char pktIPCPtype [] = { 0xff, 3, 0x80, 0x21, }; // IP packet
if(0);
else if (0==memcmp( ppp.pkt.buf,pktLCPReqType,4)) LCPhandler();
- else if (0==memcmp( ppp.pkt.buf,pktIPCPtype, 3)) IPFrame();
+ else if (0==memcmp( ppp.pkt.buf,pktIPCPtype, 4)) IPFrame();
else generalFrame(); // default handler
}
