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