RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Committer:
nixnax
Date:
Mon Sep 04 04:13:15 2017 +0000
Revision:
167:ff8a2d8beeb1
Parent:
165:c47826d07e0d
Child:
170:3d3b2126181c
ICMP header structure & ICMP/LCP handler rewrite.

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 167:ff8a2d8beeb1 15 unsigned int address : 8; // always 0xff
nixnax 167:ff8a2d8beeb1 16 unsigned int control : 8; // always 03
nixnax 167:ff8a2d8beeb1 17 unsigned int protocolR : 16; // byte reversed, 0x0021 for ip
nixnax 152:025c73b6c0a9 18 } pppHeaderType;
nixnax 152:025c73b6c0a9 19
nixnax 167:ff8a2d8beeb1 20 /// LCP and IPCP header
nixnax 167:ff8a2d8beeb1 21 typedef struct {
nixnax 167:ff8a2d8beeb1 22 // ppp part
nixnax 167:ff8a2d8beeb1 23 unsigned int address : 8; // always 0xff
nixnax 167:ff8a2d8beeb1 24 unsigned int control : 8; // always 03
nixnax 167:ff8a2d8beeb1 25 unsigned int protocolR : 16; // byte reversed, 0x0021 for ip
nixnax 167:ff8a2d8beeb1 26
nixnax 167:ff8a2d8beeb1 27 // ipcp and lcp part
nixnax 167:ff8a2d8beeb1 28 unsigned int code : 8; // IPCP and LCP contain a code field which identifies the requested action or response
nixnax 167:ff8a2d8beeb1 29 unsigned int identifier : 8 ;
nixnax 167:ff8a2d8beeb1 30 unsigned int lengthR : 16;
nixnax 167:ff8a2d8beeb1 31 } ipcpHeaderType;
nixnax 167:ff8a2d8beeb1 32
nixnax 159:4d1bf96a59cd 33 /// IP header
nixnax 152:025c73b6c0a9 34 typedef struct {
nixnax 154:18b2bd92f557 35 unsigned int headerLength : 4; // ip headerlength / 4
nixnax 154:18b2bd92f557 36 unsigned int version : 4; // ip version number
nixnax 154:18b2bd92f557 37 unsigned int ect : 1; // ecn capable transport
nixnax 154:18b2bd92f557 38 unsigned int ce : 1; // ecn-ce
nixnax 154:18b2bd92f557 39 unsigned int dscp : 6; // differentiated services
nixnax 160:bd701ad564cb 40 unsigned int lengthR : 16; // ip packet length (byte-reversed)
nixnax 167:ff8a2d8beeb1 41
nixnax 160:bd701ad564cb 42 unsigned int identR : 16; // ident, byte reversed
nixnax 160:bd701ad564cb 43 unsigned int fragmentOffsHi : 5;
nixnax 154:18b2bd92f557 44 unsigned int lastFragment : 1;
nixnax 160:bd701ad564cb 45 unsigned int dontFragment : 1;
nixnax 160:bd701ad564cb 46 unsigned int reservedIP : 1;
nixnax 160:bd701ad564cb 47 unsigned int fragmentOffsLo : 8;
nixnax 167:ff8a2d8beeb1 48
nixnax 160:bd701ad564cb 49 unsigned int ttl : 8;
nixnax 154:18b2bd92f557 50 unsigned int protocol : 8; // next protocol
nixnax 161:d59f778bc8ab 51 unsigned int checksumR : 16; // ip checksum, byte reversed
nixnax 167:ff8a2d8beeb1 52 union {
nixnax 167:ff8a2d8beeb1 53 unsigned int srcAdrR; // source IP address
nixnax 167:ff8a2d8beeb1 54 char srcAdrPtr [0]; // so we also have a char * to srcAdrR
nixnax 167:ff8a2d8beeb1 55 };
nixnax 167:ff8a2d8beeb1 56 union {
nixnax 167:ff8a2d8beeb1 57 unsigned int dstAdrR; // destination IP address
nixnax 167:ff8a2d8beeb1 58 char dstAdrPtr [0]; // so we also have a char * to dstAdrR
nixnax 167:ff8a2d8beeb1 59 };
nixnax 152:025c73b6c0a9 60 } ipHeaderType;
nixnax 152:025c73b6c0a9 61
nixnax 164:c3de3d212c4b 62 /// IP pseudoheader. Used in TCP/UDP checksum calculations.
nixnax 152:025c73b6c0a9 63 typedef struct {
nixnax 159:4d1bf96a59cd 64 union {
nixnax 167:ff8a2d8beeb1 65 char start [0]; // a char * to avoid type conversions
nixnax 160:bd701ad564cb 66 unsigned int srcAdrR; // source IP address
nixnax 159:4d1bf96a59cd 67 };
nixnax 159:4d1bf96a59cd 68 unsigned int dstAdrR; // destination IP address
nixnax 159:4d1bf96a59cd 69 unsigned int zero : 8;
nixnax 159:4d1bf96a59cd 70 unsigned int protocol : 8;
nixnax 159:4d1bf96a59cd 71 unsigned int lengthR : 16; // byte reversed
nixnax 159:4d1bf96a59cd 72 } pseudoIpHeaderType;
nixnax 159:4d1bf96a59cd 73
nixnax 159:4d1bf96a59cd 74 /// TCP header
nixnax 159:4d1bf96a59cd 75 typedef struct {
nixnax 159:4d1bf96a59cd 76 unsigned int srcPortR : 16; // byte reversed
nixnax 159:4d1bf96a59cd 77 unsigned int dstPortR : 16; // byte reversed
nixnax 155:9c6a1d249e26 78 unsigned int seqTcpR; // byte reversed
nixnax 155:9c6a1d249e26 79 unsigned int ackTcpR; // byte reversed
nixnax 156:163c23249731 80 unsigned int resvd1 : 4; // reserved
nixnax 156:163c23249731 81 unsigned int offset : 4; // tcp header length [5..15]
nixnax 152:025c73b6c0a9 82 union {
nixnax 156:163c23249731 83 unsigned char All; // all 8 flag bits
nixnax 156:163c23249731 84 struct { // individual flag bits
nixnax 156:163c23249731 85 unsigned char fin: 1, // fin
nixnax 156:163c23249731 86 syn : 1, // syn
nixnax 156:163c23249731 87 rst : 1, // rst
nixnax 156:163c23249731 88 psh : 1, // psh
nixnax 156:163c23249731 89 ack : 1, // ack
nixnax 156:163c23249731 90 urg : 1, // urg
nixnax 156:163c23249731 91 ece : 1, // ece
nixnax 156:163c23249731 92 cwr : 1; // cwr
nixnax 152:025c73b6c0a9 93 };
nixnax 156:163c23249731 94 } flag;
nixnax 156:163c23249731 95 unsigned int windowR : 16; // byte reversed
nixnax 154:18b2bd92f557 96 unsigned int checksumR : 16; // byte reversed
nixnax 154:18b2bd92f557 97 unsigned int urgentPointerR : 16; // byte reversed;
nixnax 154:18b2bd92f557 98 unsigned int tcpOptions[10]; // up to 10 words of options possible
nixnax 154:18b2bd92f557 99 } tcpHeaderType;
nixnax 159:4d1bf96a59cd 100
nixnax 164:c3de3d212c4b 101 /// UDP header.
nixnax 163:d1b4328e9f08 102 typedef struct {
nixnax 164:c3de3d212c4b 103 unsigned int srcPortR : 16; // byte reversed
nixnax 164:c3de3d212c4b 104 unsigned int dstPortR : 16; // byte reversed
nixnax 164:c3de3d212c4b 105 unsigned int lengthR : 16; // byte reversed
nixnax 164:c3de3d212c4b 106 unsigned int checkSumR : 16; // byte reversed
nixnax 163:d1b4328e9f08 107 char data [0]; // data area
nixnax 163:d1b4328e9f08 108 } udpHeaderType;
nixnax 165:c47826d07e0d 109
nixnax 165:c47826d07e0d 110 /// ICMP header.
nixnax 165:c47826d07e0d 111 typedef struct {
nixnax 165:c47826d07e0d 112 unsigned int type : 8;
nixnax 165:c47826d07e0d 113 unsigned int code : 8;
nixnax 165:c47826d07e0d 114 unsigned int checkSumR : 16; // byte reversed
nixnax 165:c47826d07e0d 115 unsigned int idR : 16; // byte reversed
nixnax 165:c47826d07e0d 116 unsigned int sequenceR : 16; // byte reversed
nixnax 165:c47826d07e0d 117 char data [0]; // data area
nixnax 165:c47826d07e0d 118 } icmpHeaderType;