RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

PPP-Blinky/ppp-blinky.h

Committer:
nixnax
Date:
2017-09-01
Revision:
153:7993def8663f
Parent:
152:025c73b6c0a9
Child:
154:18b2bd92f557

File content as of revision 153:7993def8663f:

/// ppp-blinky.h

#include "mbed.h"
#include "sha1.h"
#include "BufferedSerial.h"

void initializePpp();
int connectedPpp();
void waitForPcConnectString();
void waitForPppFrame();
void determinePacketType();

/// structure of a PPP header
typedef struct { // [ff 03 00 21]
    unsigned int pppAddress : 8,  // always 0xff
             pppControl : 8,  // always 03
             pppProtocol : 16; // 2100 for IP (byte reversed, should be 0021)
} pppHeaderType;

/// structure of an IP header for small-endian devices
typedef struct {
    pppHeaderType pppHeader; // first four bytes is the PPP header [ff 03 00 21]
    unsigned int headerLength : 4,  // ip headerlength / 4
             version : 4,  // ip version number
             ect : 1,  // ecn capable transport
             ce  : 1,  // ecn-ce
             dscp : 6,  // differentiated services
             length : 16; // ip packet length (byte-reversed)

    unsigned int fragmentOffset : 13,
             reserved : 1,
             dontFragment : 1,
             lastFragment : 1,
             ident : 16;

    unsigned int checksum : 16,
             protocol : 8,  // next protocol
             ttl : 8;

    unsigned int    srcAdr; // source IP address

    unsigned int    dstAdr; // destination IP address
} ipHeaderType;

/// structure of TCP header when ip header is 20 bytes long
typedef struct {
    ipHeaderType ip; // first part of TCP header is IP header
    unsigned int srcAdr : 16, // byte reversed
             dstAdr : 16; // byte reversed
    unsigned int seqTcp;
    unsigned int ackTcp;
    unsigned int res1 : 4,
             offset : 4; // tcp header length [5..15]
    union {
        unsigned int flags : 8;
        struct {
            unsigned int f:1, s:1, r:1, p:1, a:1, u:1;
        };
    };
    unsigned int window : 16; // byte reversed
    unsigned int checksum : 16, // byte reversed
             urgentPointer : 16; // byte reversed;
    unsigned int tcpOptions[10]; // 10 words of options possible
} tcpHeaderType1;

/// structure of TCP header when ip header is 24 bytes long
typedef struct {
    ipHeaderType ip; // first part of TCP header is IP header
    unsigned int options; // extra 4 bytes in IP header
    unsigned int srcAdr : 16, // byte reversed
             dstAdr : 16; // byte reversed
    unsigned int seqTcp;
    unsigned int ackTcp;
    unsigned int res1 : 4,
             offset : 4; // tcp header length [5..15]
    union {
        unsigned int flags : 8;
        struct {
            unsigned int f:1, s:1, r:1, p:1, a:1, u:1;
        };
    };
    unsigned int window : 16; // byte reversed
    unsigned int checksum : 16, // byte reversed
             urgentPointer : 16; // byte reversed;
    unsigned int tcpOptions[10]; // 10 words of options possible
} tcpHeaderType2;