RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Committer:
nixnax
Date:
Fri Sep 01 23:04:41 2017 +0000
Revision:
155:9c6a1d249e26
Parent:
154:18b2bd92f557
Child:
156:163c23249731
Working TCP flags in tcpHeaderType.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nixnax 142:54d1543e23e5 1 /// ppp-blinky.h
nixnax 142:54d1543e23e5 2
nixnax 142:54d1543e23e5 3 #include "mbed.h"
nixnax 142:54d1543e23e5 4 #include "sha1.h"
nixnax 142:54d1543e23e5 5 #include "BufferedSerial.h"
nixnax 142:54d1543e23e5 6
nixnax 144:01d98cf7738e 7 void initializePpp();
nixnax 150:3366bf3d294e 8 int connectedPpp();
nixnax 153:7993def8663f 9 void waitForPcConnectString();
nixnax 142:54d1543e23e5 10 void waitForPppFrame();
nixnax 152:025c73b6c0a9 11 void determinePacketType();
nixnax 152:025c73b6c0a9 12
nixnax 153:7993def8663f 13 /// structure of a PPP header
nixnax 153:7993def8663f 14 typedef struct { // [ff 03 00 21]
nixnax 154:18b2bd92f557 15 unsigned int pppAddress : 8; // always 0xff
nixnax 154:18b2bd92f557 16 unsigned int pppControl : 8; // always 03
nixnax 154:18b2bd92f557 17 unsigned int pppProtocol : 16; // 2100 for IP (byte reversed, should be 0021)
nixnax 152:025c73b6c0a9 18 } pppHeaderType;
nixnax 152:025c73b6c0a9 19
nixnax 154:18b2bd92f557 20 /// structure of an IP header for little-endian devices
nixnax 152:025c73b6c0a9 21 typedef struct {
nixnax 154:18b2bd92f557 22 unsigned int headerLength : 4; // ip headerlength / 4
nixnax 154:18b2bd92f557 23 unsigned int version : 4; // ip version number
nixnax 154:18b2bd92f557 24 unsigned int ect : 1; // ecn capable transport
nixnax 154:18b2bd92f557 25 unsigned int ce : 1; // ecn-ce
nixnax 154:18b2bd92f557 26 unsigned int dscp : 6; // differentiated services
nixnax 154:18b2bd92f557 27 unsigned int lengthR : 16; // ip packet length (byte-reversed)
nixnax 154:18b2bd92f557 28 unsigned int fragmentOffset : 13;
nixnax 154:18b2bd92f557 29 unsigned int reservedIP : 1;
nixnax 154:18b2bd92f557 30 unsigned int dontFragment : 1;
nixnax 154:18b2bd92f557 31 unsigned int lastFragment : 1;
nixnax 154:18b2bd92f557 32 unsigned int identR : 16;
nixnax 154:18b2bd92f557 33 unsigned int checksum : 16;
nixnax 154:18b2bd92f557 34 unsigned int protocol : 8; // next protocol
nixnax 154:18b2bd92f557 35 unsigned int ttl : 8;
nixnax 154:18b2bd92f557 36 unsigned int srcAdrR; // source IP address
nixnax 154:18b2bd92f557 37 unsigned int dstAdrR; // destination IP address
nixnax 152:025c73b6c0a9 38 } ipHeaderType;
nixnax 152:025c73b6c0a9 39
nixnax 154:18b2bd92f557 40 /// structure of TCP header
nixnax 152:025c73b6c0a9 41 typedef struct {
nixnax 155:9c6a1d249e26 42 unsigned int srcAdrR : 16; // byte reversed
nixnax 155:9c6a1d249e26 43 unsigned int dstAdrR : 16; // byte reversed
nixnax 155:9c6a1d249e26 44 unsigned int seqTcpR; // byte reversed
nixnax 155:9c6a1d249e26 45 unsigned int ackTcpR; // byte reversed
nixnax 155:9c6a1d249e26 46 // a special union for the flag bits
nixnax 152:025c73b6c0a9 47 union {
nixnax 152:025c73b6c0a9 48 struct {
nixnax 155:9c6a1d249e26 49 unsigned int resvd1 : 4; // reserved
nixnax 155:9c6a1d249e26 50 unsigned int offset : 4; // tcp header length [5..15]
nixnax 155:9c6a1d249e26 51 unsigned int flagFin: 1, // fin
nixnax 155:9c6a1d249e26 52 flagSyn : 1, // syn
nixnax 155:9c6a1d249e26 53 flagRst : 1, // rst
nixnax 155:9c6a1d249e26 54 flagPsh : 1, // psh
nixnax 155:9c6a1d249e26 55 flagAck : 1, // ack
nixnax 155:9c6a1d249e26 56 flagUrg : 1, // urg
nixnax 155:9c6a1d249e26 57 flagEce : 1, // ece
nixnax 155:9c6a1d249e26 58 flagCwr : 1; // cwr
nixnax 155:9c6a1d249e26 59 unsigned int windowR : 16; // byte reversed
nixnax 152:025c73b6c0a9 60 };
nixnax 155:9c6a1d249e26 61 struct {
nixnax 155:9c6a1d249e26 62 unsigned int : 8; // already dealt with first 8 bits
nixnax 155:9c6a1d249e26 63 unsigned int flagsTcp : 8; // second 8 bits are the tcp flags
nixnax 155:9c6a1d249e26 64 };
nixnax 155:9c6a1d249e26 65
nixnax 152:025c73b6c0a9 66 };
nixnax 155:9c6a1d249e26 67 // end of a special union for the flag bits
nixnax 154:18b2bd92f557 68 unsigned int checksumR : 16; // byte reversed
nixnax 154:18b2bd92f557 69 unsigned int urgentPointerR : 16; // byte reversed;
nixnax 154:18b2bd92f557 70 unsigned int tcpOptions[10]; // up to 10 words of options possible
nixnax 154:18b2bd92f557 71 } tcpHeaderType;
nixnax 152:025c73b6c0a9 72