RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Committer:
nixnax
Date:
Fri Sep 01 20:23:03 2017 +0000
Revision:
154:18b2bd92f557
Parent:
153:7993def8663f
Child:
155:9c6a1d249e26
Better IP and TCP header structures

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 154:18b2bd92f557 42 unsigned int srcAdrR : 16; // byte reversed
nixnax 154:18b2bd92f557 43 unsigned int dstAdrR : 16; // byte reversed
nixnax 154:18b2bd92f557 44 unsigned int seqTcpR; // byte reversed
nixnax 154:18b2bd92f557 45 unsigned int ackTcpR; // byte reversed
nixnax 154:18b2bd92f557 46 unsigned int resvd1 : 4; // reserved
nixnax 154:18b2bd92f557 47 unsigned int offset : 4; // tcp header length [5..15]
nixnax 152:025c73b6c0a9 48 union {
nixnax 154:18b2bd92f557 49 unsigned int flags : 8; // 8 tcp flag bits
nixnax 152:025c73b6c0a9 50 struct {
nixnax 154:18b2bd92f557 51 unsigned int f:1, // fin
nixnax 154:18b2bd92f557 52 s:1, // syn
nixnax 154:18b2bd92f557 53 r:1, // rst
nixnax 154:18b2bd92f557 54 p:1, // psh
nixnax 154:18b2bd92f557 55 a:1, // ack
nixnax 154:18b2bd92f557 56 u:1; // urg
nixnax 152:025c73b6c0a9 57 };
nixnax 152:025c73b6c0a9 58 };
nixnax 154:18b2bd92f557 59 unsigned int windowR : 16; // byte reversed
nixnax 154:18b2bd92f557 60 unsigned int checksumR : 16; // byte reversed
nixnax 154:18b2bd92f557 61 unsigned int urgentPointerR : 16; // byte reversed;
nixnax 154:18b2bd92f557 62 unsigned int tcpOptions[10]; // up to 10 words of options possible
nixnax 154:18b2bd92f557 63 } tcpHeaderType;
nixnax 152:025c73b6c0a9 64