RealtimeCompLab2
Dependencies: mbed
Fork of PPP-Blinky by
PPP-Blinky/ppp-blinky.h@152:025c73b6c0a9, 2017-09-01 (annotated)
- Committer:
- nixnax
- Date:
- Fri Sep 01 15:25:04 2017 +0000
- Revision:
- 152:025c73b6c0a9
- Parent:
- 150:3366bf3d294e
- Child:
- 153:7993def8663f
PPP, IP and TCP header structures
Who changed what in which revision?
User | Revision | Line number | New 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 | 142:54d1543e23e5 | 9 | void scanForConnectString(); |
nixnax | 142:54d1543e23e5 | 10 | void waitForPppFrame(); |
nixnax | 152:025c73b6c0a9 | 11 | void determinePacketType(); |
nixnax | 152:025c73b6c0a9 | 12 | |
nixnax | 152:025c73b6c0a9 | 13 | typedef struct { // ff 03 00 21 |
nixnax | 152:025c73b6c0a9 | 14 | unsigned int pppAddress : 8, // always 0xff |
nixnax | 152:025c73b6c0a9 | 15 | pppControl : 8, // always 03 |
nixnax | 152:025c73b6c0a9 | 16 | pppProtocol : 16; // 2100 for IP (byte reversed, should be 0021) |
nixnax | 152:025c73b6c0a9 | 17 | } pppHeaderType; |
nixnax | 152:025c73b6c0a9 | 18 | |
nixnax | 152:025c73b6c0a9 | 19 | /// structure of an IP header for small-endian devices |
nixnax | 152:025c73b6c0a9 | 20 | typedef struct { |
nixnax | 152:025c73b6c0a9 | 21 | pppHeaderType pppHeader; // first four bytes is the PPP header [ff 03 00 21] |
nixnax | 152:025c73b6c0a9 | 22 | unsigned int headerLength : 4, // ip headerlength / 4 |
nixnax | 152:025c73b6c0a9 | 23 | version : 4, // ip version number |
nixnax | 152:025c73b6c0a9 | 24 | ect : 1, // ecn capable transport |
nixnax | 152:025c73b6c0a9 | 25 | ce : 1, // ecn-ce |
nixnax | 152:025c73b6c0a9 | 26 | dscp : 6, // differentiated services |
nixnax | 152:025c73b6c0a9 | 27 | length : 16; // ip packet length (byte-reversed) |
nixnax | 152:025c73b6c0a9 | 28 | |
nixnax | 152:025c73b6c0a9 | 29 | unsigned int fragmentOffset : 13, |
nixnax | 152:025c73b6c0a9 | 30 | reserved : 1, |
nixnax | 152:025c73b6c0a9 | 31 | dontFragment : 1, |
nixnax | 152:025c73b6c0a9 | 32 | lastFragment : 1, |
nixnax | 152:025c73b6c0a9 | 33 | ident : 16; |
nixnax | 152:025c73b6c0a9 | 34 | |
nixnax | 152:025c73b6c0a9 | 35 | unsigned int checksum : 16, |
nixnax | 152:025c73b6c0a9 | 36 | protocol : 8, // next protocol |
nixnax | 152:025c73b6c0a9 | 37 | ttl : 8; |
nixnax | 152:025c73b6c0a9 | 38 | |
nixnax | 152:025c73b6c0a9 | 39 | unsigned int srcAdr; // source IP address |
nixnax | 152:025c73b6c0a9 | 40 | |
nixnax | 152:025c73b6c0a9 | 41 | unsigned int dstAdr; // destination IP address |
nixnax | 152:025c73b6c0a9 | 42 | } ipHeaderType; |
nixnax | 152:025c73b6c0a9 | 43 | |
nixnax | 152:025c73b6c0a9 | 44 | typedef struct { |
nixnax | 152:025c73b6c0a9 | 45 | ipHeaderType ip; // first part of TCP header is IP header |
nixnax | 152:025c73b6c0a9 | 46 | unsigned int srcAdr : 16, // byte reversed |
nixnax | 152:025c73b6c0a9 | 47 | dstAdr : 16; // byte reversed |
nixnax | 152:025c73b6c0a9 | 48 | unsigned int seqTcp; |
nixnax | 152:025c73b6c0a9 | 49 | unsigned int ackTcp; |
nixnax | 152:025c73b6c0a9 | 50 | unsigned int res1 : 4, |
nixnax | 152:025c73b6c0a9 | 51 | offset : 4; // tcp header length [5..15] |
nixnax | 152:025c73b6c0a9 | 52 | union { |
nixnax | 152:025c73b6c0a9 | 53 | unsigned int flags : 8; |
nixnax | 152:025c73b6c0a9 | 54 | struct { |
nixnax | 152:025c73b6c0a9 | 55 | unsigned int f:1, s:1, r:1, p:1, a:1, u:1; |
nixnax | 152:025c73b6c0a9 | 56 | }; |
nixnax | 152:025c73b6c0a9 | 57 | }; |
nixnax | 152:025c73b6c0a9 | 58 | unsigned int window : 16; // byte reversed |
nixnax | 152:025c73b6c0a9 | 59 | unsigned int checksum : 16, // byte reversed |
nixnax | 152:025c73b6c0a9 | 60 | urgentPointer : 16; // byte reversed; |
nixnax | 152:025c73b6c0a9 | 61 | unsigned int tcpOptions[10]; // 10 words of options possible |
nixnax | 152:025c73b6c0a9 | 62 | } tcpHeaderType1; |
nixnax | 152:025c73b6c0a9 | 63 | |
nixnax | 152:025c73b6c0a9 | 64 | typedef struct { |
nixnax | 152:025c73b6c0a9 | 65 | ipHeaderType ip; |
nixnax | 152:025c73b6c0a9 | 66 | unsigned int options; |
nixnax | 152:025c73b6c0a9 | 67 | unsigned int srcAdr : 16, // byte reversed |
nixnax | 152:025c73b6c0a9 | 68 | dstAdr : 16; // byte reversed |
nixnax | 152:025c73b6c0a9 | 69 | unsigned int seqTcp; |
nixnax | 152:025c73b6c0a9 | 70 | unsigned int ackTcp; |
nixnax | 152:025c73b6c0a9 | 71 | unsigned int res1 : 4, |
nixnax | 152:025c73b6c0a9 | 72 | offset : 4; // tcp header length [5..15] |
nixnax | 152:025c73b6c0a9 | 73 | union { |
nixnax | 152:025c73b6c0a9 | 74 | unsigned int flags : 8; |
nixnax | 152:025c73b6c0a9 | 75 | struct { |
nixnax | 152:025c73b6c0a9 | 76 | unsigned int f:1, s:1, r:1, p:1, a:1, u:1; |
nixnax | 152:025c73b6c0a9 | 77 | }; |
nixnax | 152:025c73b6c0a9 | 78 | }; |
nixnax | 152:025c73b6c0a9 | 79 | unsigned int window : 16; // byte reversed |
nixnax | 152:025c73b6c0a9 | 80 | unsigned int checksum : 16, // byte reversed |
nixnax | 152:025c73b6c0a9 | 81 | urgentPointer : 16; // byte reversed; |
nixnax | 152:025c73b6c0a9 | 82 | unsigned int tcpOptions[10]; // 10 words of options possible |
nixnax | 152:025c73b6c0a9 | 83 | } tcpHeaderType2; |
nixnax | 152:025c73b6c0a9 | 84 |