RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Revision:
176:011dbb3f7d03
Parent:
174:e5a3f16421a5
Parent:
175:b4e6f8a6fe00
Child:
179:ba2b2ddd0da5
--- 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;
+