RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Committer:
nixnax
Date:
Sun Sep 03 01:29:01 2017 +0000
Revision:
163:d1b4328e9f08
Parent:
161:d59f778bc8ab
Child:
164:c3de3d212c4b
UDP header structure. Rewrite udp handler.

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 160:bd701ad564cb 27 unsigned int lengthR : 16; // ip packet length (byte-reversed)
nixnax 160:bd701ad564cb 28
nixnax 160:bd701ad564cb 29 unsigned int identR : 16; // ident, byte reversed
nixnax 160:bd701ad564cb 30 unsigned int fragmentOffsHi : 5;
nixnax 154:18b2bd92f557 31 unsigned int lastFragment : 1;
nixnax 160:bd701ad564cb 32 unsigned int dontFragment : 1;
nixnax 160:bd701ad564cb 33 unsigned int reservedIP : 1;
nixnax 160:bd701ad564cb 34 unsigned int fragmentOffsLo : 8;
nixnax 160:bd701ad564cb 35
nixnax 160:bd701ad564cb 36 unsigned int ttl : 8;
nixnax 154:18b2bd92f557 37 unsigned int protocol : 8; // next protocol
nixnax 161:d59f778bc8ab 38 unsigned int checksumR : 16; // ip checksum, byte reversed
nixnax 160:bd701ad564cb 39
nixnax 154:18b2bd92f557 40 unsigned int srcAdrR; // source IP address
nixnax 154:18b2bd92f557 41 unsigned int dstAdrR; // destination IP address
nixnax 152:025c73b6c0a9 42 } ipHeaderType;
nixnax 152:025c73b6c0a9 43
nixnax 159:4d1bf96a59cd 44 /// IP pseudoheader
nixnax 152:025c73b6c0a9 45 typedef struct {
nixnax 159:4d1bf96a59cd 46 union {
nixnax 161:d59f778bc8ab 47 char start [0];
nixnax 160:bd701ad564cb 48 unsigned int srcAdrR; // source IP address
nixnax 159:4d1bf96a59cd 49 };
nixnax 159:4d1bf96a59cd 50 unsigned int dstAdrR; // destination IP address
nixnax 159:4d1bf96a59cd 51 unsigned int zero : 8;
nixnax 159:4d1bf96a59cd 52 unsigned int protocol : 8;
nixnax 159:4d1bf96a59cd 53 unsigned int lengthR : 16; // byte reversed
nixnax 159:4d1bf96a59cd 54 } pseudoIpHeaderType;
nixnax 159:4d1bf96a59cd 55
nixnax 159:4d1bf96a59cd 56 /// TCP header
nixnax 159:4d1bf96a59cd 57 typedef struct {
nixnax 159:4d1bf96a59cd 58 unsigned int srcPortR : 16; // byte reversed
nixnax 159:4d1bf96a59cd 59 unsigned int dstPortR : 16; // byte reversed
nixnax 155:9c6a1d249e26 60 unsigned int seqTcpR; // byte reversed
nixnax 155:9c6a1d249e26 61 unsigned int ackTcpR; // byte reversed
nixnax 156:163c23249731 62 unsigned int resvd1 : 4; // reserved
nixnax 156:163c23249731 63 unsigned int offset : 4; // tcp header length [5..15]
nixnax 152:025c73b6c0a9 64 union {
nixnax 156:163c23249731 65 unsigned char All; // all 8 flag bits
nixnax 156:163c23249731 66 struct { // individual flag bits
nixnax 156:163c23249731 67 unsigned char fin: 1, // fin
nixnax 156:163c23249731 68 syn : 1, // syn
nixnax 156:163c23249731 69 rst : 1, // rst
nixnax 156:163c23249731 70 psh : 1, // psh
nixnax 156:163c23249731 71 ack : 1, // ack
nixnax 156:163c23249731 72 urg : 1, // urg
nixnax 156:163c23249731 73 ece : 1, // ece
nixnax 156:163c23249731 74 cwr : 1; // cwr
nixnax 152:025c73b6c0a9 75 };
nixnax 156:163c23249731 76 } flag;
nixnax 156:163c23249731 77 unsigned int windowR : 16; // byte reversed
nixnax 154:18b2bd92f557 78 unsigned int checksumR : 16; // byte reversed
nixnax 154:18b2bd92f557 79 unsigned int urgentPointerR : 16; // byte reversed;
nixnax 154:18b2bd92f557 80 unsigned int tcpOptions[10]; // up to 10 words of options possible
nixnax 154:18b2bd92f557 81 } tcpHeaderType;
nixnax 159:4d1bf96a59cd 82
nixnax 163:d1b4328e9f08 83 typedef struct {
nixnax 163:d1b4328e9f08 84 unsigned int srcPortR : 16, // byte reversed
nixnax 163:d1b4328e9f08 85 dstPortR : 16; // byte reversed
nixnax 163:d1b4328e9f08 86 unsigned int lengthR : 16, // byte reversed
nixnax 163:d1b4328e9f08 87 checkSumR : 16; // byte reversed
nixnax 163:d1b4328e9f08 88 char data [0]; // data area
nixnax 163:d1b4328e9f08 89 } udpHeaderType;