RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Committer:
nixnax
Date:
Sat Sep 02 07:48:53 2017 +0000
Revision:
159:4d1bf96a59cd
Parent:
156:163c23249731
Child:
160:bd701ad564cb
Better pseudo header.

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 159:4d1bf96a59cd 13 /// 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 159:4d1bf96a59cd 20 /// IP header
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 159:4d1bf96a59cd 40 /// IP pseudoheader
nixnax 152:025c73b6c0a9 41 typedef struct {
nixnax 159:4d1bf96a59cd 42 union {
nixnax 159:4d1bf96a59cd 43 unsigned char start [0];
nixnax 159:4d1bf96a59cd 44 unsigned int srcAdrR; // source IP address
nixnax 159:4d1bf96a59cd 45 };
nixnax 159:4d1bf96a59cd 46 unsigned int dstAdrR; // destination IP address
nixnax 159:4d1bf96a59cd 47 unsigned int zero : 8;
nixnax 159:4d1bf96a59cd 48 unsigned int protocol : 8;
nixnax 159:4d1bf96a59cd 49 unsigned int lengthR : 16; // byte reversed
nixnax 159:4d1bf96a59cd 50 } pseudoIpHeaderType;
nixnax 159:4d1bf96a59cd 51
nixnax 159:4d1bf96a59cd 52 /// TCP header
nixnax 159:4d1bf96a59cd 53 typedef struct {
nixnax 159:4d1bf96a59cd 54 unsigned int srcPortR : 16; // byte reversed
nixnax 159:4d1bf96a59cd 55 unsigned int dstPortR : 16; // byte reversed
nixnax 155:9c6a1d249e26 56 unsigned int seqTcpR; // byte reversed
nixnax 155:9c6a1d249e26 57 unsigned int ackTcpR; // byte reversed
nixnax 156:163c23249731 58 unsigned int resvd1 : 4; // reserved
nixnax 156:163c23249731 59 unsigned int offset : 4; // tcp header length [5..15]
nixnax 152:025c73b6c0a9 60 union {
nixnax 156:163c23249731 61 unsigned char All; // all 8 flag bits
nixnax 156:163c23249731 62 struct { // individual flag bits
nixnax 156:163c23249731 63 unsigned char fin: 1, // fin
nixnax 156:163c23249731 64 syn : 1, // syn
nixnax 156:163c23249731 65 rst : 1, // rst
nixnax 156:163c23249731 66 psh : 1, // psh
nixnax 156:163c23249731 67 ack : 1, // ack
nixnax 156:163c23249731 68 urg : 1, // urg
nixnax 156:163c23249731 69 ece : 1, // ece
nixnax 156:163c23249731 70 cwr : 1; // cwr
nixnax 152:025c73b6c0a9 71 };
nixnax 156:163c23249731 72 } flag;
nixnax 156:163c23249731 73 unsigned int windowR : 16; // byte reversed
nixnax 154:18b2bd92f557 74 unsigned int checksumR : 16; // byte reversed
nixnax 154:18b2bd92f557 75 unsigned int urgentPointerR : 16; // byte reversed;
nixnax 154:18b2bd92f557 76 unsigned int tcpOptions[10]; // up to 10 words of options possible
nixnax 154:18b2bd92f557 77 } tcpHeaderType;
nixnax 159:4d1bf96a59cd 78