Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of webserverBlinky by
PPP-Blinky/ppp-blinky.h@174:e5a3f16421a5, 2017-09-06 (annotated)
- Committer:
- nixnax
- Date:
- Wed Sep 06 14:27:04 2017 +0000
- Revision:
- 174:e5a3f16421a5
- Parent:
- 173:6774a0c851c4
- Child:
- 176:011dbb3f7d03
sendUdpData()
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 | 174:e5a3f16421a5 | 12 | void sendUdpData(); |
nixnax | 152:025c73b6c0a9 | 13 | |
nixnax | 159:4d1bf96a59cd | 14 | /// PPP header |
nixnax | 153:7993def8663f | 15 | typedef struct { // [ff 03 00 21] |
nixnax | 167:ff8a2d8beeb1 | 16 | unsigned int address : 8; // always 0xff |
nixnax | 167:ff8a2d8beeb1 | 17 | unsigned int control : 8; // always 03 |
nixnax | 167:ff8a2d8beeb1 | 18 | unsigned int protocolR : 16; // byte reversed, 0x0021 for ip |
nixnax | 152:025c73b6c0a9 | 19 | } pppHeaderType; |
nixnax | 152:025c73b6c0a9 | 20 | |
nixnax | 167:ff8a2d8beeb1 | 21 | /// LCP and IPCP header |
nixnax | 167:ff8a2d8beeb1 | 22 | typedef struct { |
nixnax | 167:ff8a2d8beeb1 | 23 | // ppp part |
nixnax | 167:ff8a2d8beeb1 | 24 | unsigned int address : 8; // always 0xff |
nixnax | 167:ff8a2d8beeb1 | 25 | unsigned int control : 8; // always 03 |
nixnax | 167:ff8a2d8beeb1 | 26 | unsigned int protocolR : 16; // byte reversed, 0x0021 for ip |
nixnax | 167:ff8a2d8beeb1 | 27 | |
nixnax | 167:ff8a2d8beeb1 | 28 | // ipcp and lcp part |
nixnax | 167:ff8a2d8beeb1 | 29 | unsigned int code : 8; // IPCP and LCP contain a code field which identifies the requested action or response |
nixnax | 167:ff8a2d8beeb1 | 30 | unsigned int identifier : 8 ; |
nixnax | 167:ff8a2d8beeb1 | 31 | unsigned int lengthR : 16; |
nixnax | 173:6774a0c851c4 | 32 | char request [0]; |
nixnax | 167:ff8a2d8beeb1 | 33 | } ipcpHeaderType; |
nixnax | 167:ff8a2d8beeb1 | 34 | |
nixnax | 159:4d1bf96a59cd | 35 | /// IP header |
nixnax | 152:025c73b6c0a9 | 36 | typedef struct { |
nixnax | 154:18b2bd92f557 | 37 | unsigned int headerLength : 4; // ip headerlength / 4 |
nixnax | 154:18b2bd92f557 | 38 | unsigned int version : 4; // ip version number |
nixnax | 154:18b2bd92f557 | 39 | unsigned int ect : 1; // ecn capable transport |
nixnax | 154:18b2bd92f557 | 40 | unsigned int ce : 1; // ecn-ce |
nixnax | 154:18b2bd92f557 | 41 | unsigned int dscp : 6; // differentiated services |
nixnax | 160:bd701ad564cb | 42 | unsigned int lengthR : 16; // ip packet length (byte-reversed) |
nixnax | 167:ff8a2d8beeb1 | 43 | |
nixnax | 160:bd701ad564cb | 44 | unsigned int identR : 16; // ident, byte reversed |
nixnax | 160:bd701ad564cb | 45 | unsigned int fragmentOffsHi : 5; |
nixnax | 154:18b2bd92f557 | 46 | unsigned int lastFragment : 1; |
nixnax | 160:bd701ad564cb | 47 | unsigned int dontFragment : 1; |
nixnax | 160:bd701ad564cb | 48 | unsigned int reservedIP : 1; |
nixnax | 160:bd701ad564cb | 49 | unsigned int fragmentOffsLo : 8; |
nixnax | 167:ff8a2d8beeb1 | 50 | |
nixnax | 160:bd701ad564cb | 51 | unsigned int ttl : 8; |
nixnax | 154:18b2bd92f557 | 52 | unsigned int protocol : 8; // next protocol |
nixnax | 161:d59f778bc8ab | 53 | unsigned int checksumR : 16; // ip checksum, byte reversed |
nixnax | 167:ff8a2d8beeb1 | 54 | union { |
nixnax | 167:ff8a2d8beeb1 | 55 | unsigned int srcAdrR; // source IP address |
nixnax | 167:ff8a2d8beeb1 | 56 | char srcAdrPtr [0]; // so we also have a char * to srcAdrR |
nixnax | 167:ff8a2d8beeb1 | 57 | }; |
nixnax | 167:ff8a2d8beeb1 | 58 | union { |
nixnax | 167:ff8a2d8beeb1 | 59 | unsigned int dstAdrR; // destination IP address |
nixnax | 167:ff8a2d8beeb1 | 60 | char dstAdrPtr [0]; // so we also have a char * to dstAdrR |
nixnax | 167:ff8a2d8beeb1 | 61 | }; |
nixnax | 152:025c73b6c0a9 | 62 | } ipHeaderType; |
nixnax | 152:025c73b6c0a9 | 63 | |
nixnax | 164:c3de3d212c4b | 64 | /// IP pseudoheader. Used in TCP/UDP checksum calculations. |
nixnax | 152:025c73b6c0a9 | 65 | typedef struct { |
nixnax | 159:4d1bf96a59cd | 66 | union { |
nixnax | 167:ff8a2d8beeb1 | 67 | char start [0]; // a char * to avoid type conversions |
nixnax | 160:bd701ad564cb | 68 | unsigned int srcAdrR; // source IP address |
nixnax | 159:4d1bf96a59cd | 69 | }; |
nixnax | 159:4d1bf96a59cd | 70 | unsigned int dstAdrR; // destination IP address |
nixnax | 159:4d1bf96a59cd | 71 | unsigned int zero : 8; |
nixnax | 159:4d1bf96a59cd | 72 | unsigned int protocol : 8; |
nixnax | 159:4d1bf96a59cd | 73 | unsigned int lengthR : 16; // byte reversed |
nixnax | 159:4d1bf96a59cd | 74 | } pseudoIpHeaderType; |
nixnax | 159:4d1bf96a59cd | 75 | |
nixnax | 159:4d1bf96a59cd | 76 | /// TCP header |
nixnax | 159:4d1bf96a59cd | 77 | typedef struct { |
nixnax | 159:4d1bf96a59cd | 78 | unsigned int srcPortR : 16; // byte reversed |
nixnax | 159:4d1bf96a59cd | 79 | unsigned int dstPortR : 16; // byte reversed |
nixnax | 155:9c6a1d249e26 | 80 | unsigned int seqTcpR; // byte reversed |
nixnax | 155:9c6a1d249e26 | 81 | unsigned int ackTcpR; // byte reversed |
nixnax | 156:163c23249731 | 82 | unsigned int resvd1 : 4; // reserved |
nixnax | 156:163c23249731 | 83 | unsigned int offset : 4; // tcp header length [5..15] |
nixnax | 152:025c73b6c0a9 | 84 | union { |
nixnax | 156:163c23249731 | 85 | unsigned char All; // all 8 flag bits |
nixnax | 156:163c23249731 | 86 | struct { // individual flag bits |
nixnax | 156:163c23249731 | 87 | unsigned char fin: 1, // fin |
nixnax | 156:163c23249731 | 88 | syn : 1, // syn |
nixnax | 156:163c23249731 | 89 | rst : 1, // rst |
nixnax | 156:163c23249731 | 90 | psh : 1, // psh |
nixnax | 156:163c23249731 | 91 | ack : 1, // ack |
nixnax | 156:163c23249731 | 92 | urg : 1, // urg |
nixnax | 156:163c23249731 | 93 | ece : 1, // ece |
nixnax | 156:163c23249731 | 94 | cwr : 1; // cwr |
nixnax | 152:025c73b6c0a9 | 95 | }; |
nixnax | 156:163c23249731 | 96 | } flag; |
nixnax | 156:163c23249731 | 97 | unsigned int windowR : 16; // byte reversed |
nixnax | 154:18b2bd92f557 | 98 | unsigned int checksumR : 16; // byte reversed |
nixnax | 154:18b2bd92f557 | 99 | unsigned int urgentPointerR : 16; // byte reversed; |
nixnax | 154:18b2bd92f557 | 100 | unsigned int tcpOptions[10]; // up to 10 words of options possible |
nixnax | 154:18b2bd92f557 | 101 | } tcpHeaderType; |
nixnax | 159:4d1bf96a59cd | 102 | |
nixnax | 164:c3de3d212c4b | 103 | /// UDP header. |
nixnax | 163:d1b4328e9f08 | 104 | typedef struct { |
nixnax | 164:c3de3d212c4b | 105 | unsigned int srcPortR : 16; // byte reversed |
nixnax | 164:c3de3d212c4b | 106 | unsigned int dstPortR : 16; // byte reversed |
nixnax | 164:c3de3d212c4b | 107 | unsigned int lengthR : 16; // byte reversed |
nixnax | 170:3d3b2126181c | 108 | unsigned int checksumR : 16; // byte reversed |
nixnax | 163:d1b4328e9f08 | 109 | char data [0]; // data area |
nixnax | 163:d1b4328e9f08 | 110 | } udpHeaderType; |
nixnax | 165:c47826d07e0d | 111 | |
nixnax | 165:c47826d07e0d | 112 | /// ICMP header. |
nixnax | 165:c47826d07e0d | 113 | typedef struct { |
nixnax | 165:c47826d07e0d | 114 | unsigned int type : 8; |
nixnax | 165:c47826d07e0d | 115 | unsigned int code : 8; |
nixnax | 165:c47826d07e0d | 116 | unsigned int checkSumR : 16; // byte reversed |
nixnax | 165:c47826d07e0d | 117 | unsigned int idR : 16; // byte reversed |
nixnax | 165:c47826d07e0d | 118 | unsigned int sequenceR : 16; // byte reversed |
nixnax | 165:c47826d07e0d | 119 | char data [0]; // data area |
nixnax | 165:c47826d07e0d | 120 | } icmpHeaderType; |