RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

PPP-Blinky/ppp-blinky.h

Committer:
nixnax
Date:
2017-09-02
Revision:
156:163c23249731
Parent:
155:9c6a1d249e26
Child:
159:4d1bf96a59cd

File content as of revision 156:163c23249731:

/// 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
    unsigned int pppControl : 8;  // always 03
    unsigned int pppProtocol : 16; // 2100 for IP (byte reversed, should be 0021)
} pppHeaderType;

/// structure of an IP header for little-endian devices
typedef struct {
    unsigned int headerLength   :  4;  // ip headerlength / 4
    unsigned int version        :  4;  // ip version number
    unsigned int ect            :  1;  // ecn capable transport
    unsigned int ce             :  1;  // ecn-ce
    unsigned int dscp           :  6;  // differentiated services
    unsigned int lengthR        : 16; // ip packet length (byte-reversed)
    unsigned int fragmentOffset : 13;
    unsigned int reservedIP     :  1;
    unsigned int dontFragment   :  1;
    unsigned int lastFragment   :  1;
    unsigned int identR         : 16;
    unsigned int checksum       : 16;
    unsigned int protocol       :  8;  // next protocol
    unsigned int ttl            :  8;
    unsigned int srcAdrR; // source IP address
    unsigned int dstAdrR; // destination IP address
} ipHeaderType;

/// structure of TCP header
typedef struct {
    unsigned int    srcAdrR : 16; // byte reversed
    unsigned int    dstAdrR : 16; // byte reversed
    unsigned int    seqTcpR;      // byte reversed
    unsigned int    ackTcpR;      // byte reversed
    unsigned int resvd1  : 4;  // reserved
    unsigned int offset  : 4; // tcp header length [5..15]
    union {
        unsigned char All;  // all 8 flag bits
        struct {            // individual flag bits
            unsigned char fin:  1, // fin
                     syn    :  1, // syn
                     rst    :  1, // rst
                     psh    :  1, // psh
                     ack    :  1, // ack
                     urg    :  1, // urg
                     ece    :  1, // ece
                     cwr    :  1; // cwr
        };
    } flag;
    unsigned int windowR : 16; // byte reversed
    unsigned int    checksumR : 16; // byte reversed
    unsigned int    urgentPointerR : 16; // byte reversed;
    unsigned int    tcpOptions[10]; // up to 10 words of options possible
} tcpHeaderType;