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
Revision 176:011dbb3f7d03, committed 2017-09-06
- Comitter:
- nixnax
- Date:
- Wed Sep 06 21:15:44 2017 +0000
- Parent:
- 174:e5a3f16421a5
- Parent:
- 175:b4e6f8a6fe00
- Child:
- 177:dab9e685af53
- Commit message:
- Merge
Changed in this revision
| PPP-Blinky/ppp-blinky.cpp | Show annotated file Show diff for this revision Revisions of this file |
| PPP-Blinky/ppp-blinky.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/PPP-Blinky/ppp-blinky.cpp Wed Sep 06 14:27:04 2017 +0000
+++ b/PPP-Blinky/ppp-blinky.cpp Wed Sep 06 21:15:44 2017 +0000
@@ -155,57 +155,6 @@
// the standard hdlc frame start/end character. It's the tilde character "~"
#define FRAME_7E (0x7e)
-/// a structure to keep all our ppp variables in
-struct pppType {
- union {
- pppHeaderType * ppp; // pointer to ppp structure
- ipcpHeaderType * ipcp; // pointer to ipcp structure
- };
- union {
- ipHeaderType * ip; // pointer to ip header struct
- char * ipStart; // char pointer to ip header struct (need a char pointer for byte offset calculations)
- };
- union { // a union for the packet type contained in the IP packet
- tcpHeaderType * tcp; // pointer to tcp header struct
- udpHeaderType * udp; // pointer to udp header struct
- icmpHeaderType * icmp; // pointer to udp header struct
- char * tcpStart; // char pointer to tcp header struct (need a char pointer for byte offset calculations)
- char * udpStart; // char pointer to udp header struct (need a char pointer for byte offset calculations)
- char * icmpStart; // char pointer to icmp header struct (need a char pointer for byte offset calculations)
- };
- char * tcpData; // char pointer to where tcp data starts
- int online; // we hunt for a PPP connection if this is zero
- int hostIP; // ip address of host
- int fcs; // PPP "frame check sequence" - a 16-bit HDLC-like checksum used in all PPP frames
- int ledState; // state of LED1
- int responseCounter;
- int firstFrame; // cleared after first frame
- unsigned int sum; // a checksum used in headers
- struct {
-#define RXBUFLEN (1<<11)
- // the serial port receive buffer and packet buffer, size is RXBUFLEN (currently 2048 bytes)
- char buf[RXBUFLEN]; // RXBUFLEN MUST be a power of two because we use & operator for fast wrap-around in ring buffer
- int head;
- int tail;
- int rtail;
- int buflevel;
- } rx; // serial port objects
- struct {
- int len; // number of bytes in buffer
- int crc; // PPP CRC (frame check)
-#define PPP_max_size 1600
- // we are assuming 100 bytes more than MTU size of 1500
- char buf[PPP_max_size]; // send and receive buffer large enough for largest IP packet
- } pkt; // ppp buffer objects
- struct {
- int frameStartIndex; // frame start marker
- int frameEndIndex; // frame end marker
- } hdlc; // hdlc frame objects
- struct {
- unsigned int ident; // our IP ident value (outgoing frame count)
- } ipData; // ip related object
-};
-
pppType ppp; // our global - definitely not thread safe
/// Initialize the ppp structure and clear the receive buffer
@@ -223,8 +172,8 @@
ppp.hdlc.frameStartIndex=0;
ppp.responseCounter=0;
ppp.firstFrame=1;
- ppp.ppp = (pppHeaderType *)ppp.pkt.buf;
- ppp.ip = (ipHeaderType *)(ppp.pkt.buf+4); // ppp header is 4 bytes long
+ ppp.ppp = (pppHeaderType *)ppp.pkt.buf; // pointer to ppp header
+ ppp.ip = (ipHeaderType *)(ppp.pkt.buf+4); // pointer to IP header
}
/// Toggle the LED on every second PPP packet received
@@ -1155,16 +1104,16 @@
void LCPconfReq()
{
debugPrintf("LCP Config ");
- if ( ppp.ipcp->lengthR != __REV16(4) ) {
- ppp.ipcp->code=4; // allow only "no options" which means Maximum Receive Unit (MRU) is default 1500 bytes
+ if ( ppp.lcp->lengthR != __REV16(4) ) {
+ ppp.lcp->code=4; // allow only "no options" which means Maximum Receive Unit (MRU) is default 1500 bytes
debugPrintf("Reject\n");
sendPppFrame();
} else {
- ppp.ipcp->code=2; // ack zero conf
+ ppp.lcp->code=2; // ack zero conf
debugPrintf("Ack\n");
sendPppFrame();
debugPrintf("LCP Ask\n");
- ppp.ipcp->code=1; // request no options
+ ppp.lcp->code=1; // request no options
sendPppFrame();
}
}
@@ -1178,7 +1127,7 @@
/// handle LCP end (disconnect) packets by acknowledging them and by setting ppp.online to false
void LCPend()
{
- ppp.ipcp->code=6; // end
+ ppp.lcp->code=6; // end
sendPppFrame(); // acknowledge
ppp.online=0; // start hunting for connect string again
pppInitStruct(); // flush the receive buffer
@@ -1195,7 +1144,7 @@
/// process incoming LCP packets
void LCPframe()
{
- int code = ppp.ipcp->code;
+ int code = ppp.lcp->code;
switch (code) {
case 1:
LCPconfReq();
--- a/PPP-Blinky/ppp-blinky.h Wed Sep 06 14:27:04 2017 +0000
+++ b/PPP-Blinky/ppp-blinky.h Wed Sep 06 21:15:44 2017 +0000
@@ -118,3 +118,56 @@
unsigned int sequenceR : 16; // byte reversed
char data [0]; // data area
} icmpHeaderType;
+
+/// Structure to manage all ppp variables.
+typedef struct pppType {
+ union {
+ pppHeaderType * ppp; // pointer to ppp structure
+ ipcpHeaderType * ipcp; // pointer to ipcp structure
+ ipcpHeaderType * lcp; // pointer to lcp structure (same as ipcp)
+ };
+ union {
+ ipHeaderType * ip; // pointer to ip header struct
+ char * ipStart; // char pointer to ip header struct (need a char pointer for byte offset calculations)
+ };
+ union { // a union for the packet type contained in the IP packet
+ tcpHeaderType * tcp; // pointer to tcp header struct
+ udpHeaderType * udp; // pointer to udp header struct
+ icmpHeaderType * icmp; // pointer to udp header struct
+ char * tcpStart; // char pointer to tcp header struct (need a char pointer for byte offset calculations)
+ char * udpStart; // char pointer to udp header struct (need a char pointer for byte offset calculations)
+ char * icmpStart; // char pointer to icmp header struct (need a char pointer for byte offset calculations)
+ };
+ char * tcpData; // char pointer to where tcp data starts
+ int online; // we hunt for a PPP connection if this is zero
+ int hostIP; // ip address of host
+ int fcs; // PPP "frame check sequence" - a 16-bit HDLC-like checksum used in all PPP frames
+ int ledState; // state of LED1
+ int responseCounter;
+ int firstFrame; // cleared after first frame
+ unsigned int sum; // a checksum used in headers
+ struct {
+#define RXBUFLEN (1<<11)
+ // the serial port receive buffer and packet buffer, size is RXBUFLEN (currently 2048 bytes)
+ char buf[RXBUFLEN]; // RXBUFLEN MUST be a power of two because we use & operator for fast wrap-around in ring buffer
+ int head;
+ int tail;
+ int rtail;
+ int buflevel;
+ } rx; // serial port objects
+ struct {
+ int len; // number of bytes in buffer
+ int crc; // PPP CRC (frame check)
+#define PPP_max_size 1600
+ // we are assuming 100 bytes more than MTU size of 1500
+ char buf[PPP_max_size]; // send and receive buffer large enough for largest IP packet
+ } pkt; // ppp buffer objects
+ struct {
+ int frameStartIndex; // frame start marker
+ int frameEndIndex; // frame end marker
+ } hdlc; // hdlc frame objects
+ struct {
+ unsigned int ident; // our IP ident value (outgoing frame count)
+ } ipData; // ip related object
+} pppVariables;
+
