|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <err.h> |
| 4 | + |
1 | 5 | #include "FreeRTOS.h" |
2 | 6 | #include "list.h" |
3 | 7 | #include "task.h" |
4 | 8 | #include "FreeRTOS_IP.h" |
5 | 9 | #include "FreeRTOS_IP_Private.h" |
| 10 | +#include "NetworkBufferManagement.h" |
6 | 11 |
|
7 | | -eFrameProcessingResult_t prvProcessICMPPacket( ICMPPacket_t * const pxICMPPacket ); |
| 12 | +NetworkBufferDescriptor_t *network_buffer; |
| 13 | +void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer ); |
8 | 14 |
|
9 | 15 | char data[] = |
10 | 16 | // Ethernet header |
11 | | - "\0\0\0\0\0\0\0\0\0\0\0\0\0\0" |
| 17 | + "\x00\x00\x00\x00\x00\x00" // destination |
| 18 | + "\x00\x00\x00\x00\x00\x00" // source |
| 19 | + "\x08\x00" // ether type: IPv4 |
12 | 20 | // IP header |
13 | | - "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" |
| 21 | + "\x45" // Version / IHL |
| 22 | + "\x00" // DCSP / ECN |
| 23 | + "\x00\x21" // Total Length (21) |
| 24 | + "\x00\x00" // Identification |
| 25 | + "\x00\x00" // R / DF / MF / Fragment Offset |
| 26 | + "\x00" // TTL |
| 27 | + "\x01" // protocol: icmp (1) |
| 28 | + "\x00\x00" // header checksum |
| 29 | + "\x00\x00\x00\x00" // source |
| 30 | + "\x00\x00\x00\x00" // destination |
14 | 31 | // ICMP header |
15 | | - "\x8" // Type of message -- echo request |
16 | | - // Leaving out subsequent fields results in a buffer overflow |
17 | | - // "\0" // Type of service |
18 | | - // "\0\0" // Checksum |
19 | | - // "\0\0" // Identifier |
20 | | - // "\0\0" // Sequence number |
| 32 | + "\x08" // Type of message -- echo request |
21 | 33 | ; |
22 | 34 |
|
23 | 35 | int main() |
24 | 36 | { |
25 | | - eFrameProcessingResult_t result = prvProcessICMPPacket ((ICMPPacket_t *)data); |
| 37 | + if (xNetworkBuffersInitialise() != pdPASS) { |
| 38 | + errx(1, "Error initializing network buffers"); |
| 39 | + } |
| 40 | + network_buffer = pxNetworkBufferGetFromISR(1500); |
| 41 | + network_buffer->xDataLength = sizeof(data); |
| 42 | + network_buffer->pucEthernetBuffer = data; |
| 43 | + prvProcessEthernetPacket (network_buffer); |
26 | 44 | } |
0 commit comments