1 | /** @file wlan_exp_ip_udp.h |
---|
2 | * @brief Mango wlan_exp IP/UDP Library |
---|
3 | * |
---|
4 | * @copyright Copyright 2014-2019, Mango Communications. All rights reserved. |
---|
5 | * Distributed under the Mango Reference Design license (https://mangocomm.com/802.11/license) |
---|
6 | */ |
---|
7 | |
---|
8 | /***************************** Include Files *********************************/ |
---|
9 | |
---|
10 | // Xilinx / Standard library includes |
---|
11 | #include <xil_types.h> |
---|
12 | |
---|
13 | // 802.11 Reference Design includes |
---|
14 | #include "wlan_high_types.h" |
---|
15 | #include "wlan_mac_high_sw_config.h" |
---|
16 | |
---|
17 | // Forward declarations |
---|
18 | struct arp_cache_entry_t; |
---|
19 | struct wlan_exp_ip_udp_socket_t; |
---|
20 | struct eth_rx_queue_buffer_t; |
---|
21 | struct eth_tx_queue_buffer_t; |
---|
22 | |
---|
23 | /*************************** Constant Definitions ****************************/ |
---|
24 | #ifndef WLAN_EXP_IP_UDP_H_ |
---|
25 | #define WLAN_EXP_IP_UDP_H_ |
---|
26 | |
---|
27 | // ********************************************************************** |
---|
28 | // Mango wlan_exp IP/UDP Library ARP Defines |
---|
29 | // |
---|
30 | |
---|
31 | // Mango wlan_exp IP/UDP Library ARP Table States |
---|
32 | #define ARP_TABLE_UNUSED 0 // ARP Table Entry is not in use |
---|
33 | #define ARP_TABLE_USED 1 // ARP Table Entry is in use |
---|
34 | |
---|
35 | |
---|
36 | // ********************************************************************** |
---|
37 | // Mango wlan_exp IP/UDP Library Socket Defines |
---|
38 | // |
---|
39 | |
---|
40 | // Mango wlan_exp IP/UDP Library Socket States |
---|
41 | #define SOCKET_CLOSED 0 // Socket cannot be used |
---|
42 | #define SOCKET_ALLOCATED 1 // Socket has been allocated but not bound |
---|
43 | #define SOCKET_OPEN 2 // Socket is bound and can be used |
---|
44 | |
---|
45 | // ********************************************************************** |
---|
46 | // Mango wlan_exp IP/UDP Library Ethernet Defines |
---|
47 | // |
---|
48 | |
---|
49 | #define ETH_ADDR_LEN 6 // Length of Ethernet MAC address (in bytes) |
---|
50 | #define ETH_HEADER_LEN 14 // Length of Ethernet Header (in bytes) |
---|
51 | #define ETHERTYPE_IP_V4 0x0800 // EtherType: IPv4 packet |
---|
52 | #define ETHERTYPE_ARP 0x0806 // EtherType: ARP packet |
---|
53 | |
---|
54 | // ********************************************************************** |
---|
55 | // Mango wlan_exp IP/UDP Library IP Defines |
---|
56 | // |
---|
57 | |
---|
58 | #define IP_VERSION_4 4 // IP version 4 |
---|
59 | |
---|
60 | // ********************************************************************** |
---|
61 | // Mango wlan_exp IP/UDP Library ARP Structures |
---|
62 | // - Note: The Mango wlan_exp IP/UDP Library only support IPv4 ARP |
---|
63 | // |
---|
64 | |
---|
65 | // Note: For all transmitted IP packets, IHL == 5 (ie the library always uses the minimum IP header length) |
---|
66 | #define IP_HEADER_LEN 5 // Length of IP header (in 32-bit words) |
---|
67 | |
---|
68 | // The Mango wlan_exp IP/UDP Library is best effort |
---|
69 | // See http://en.wikipedia.org/wiki/Differentiated_services |
---|
70 | // |
---|
71 | #define IP_DSCP_CS0 0 // IP Precedence: Best Effort |
---|
72 | |
---|
73 | // The Mango wlan_exp IP/UDP Library is not ECN capable |
---|
74 | // See http://en.wikipedia.org/wiki/Explicit_Congestion_Notification |
---|
75 | // |
---|
76 | #define IP_ECN_NON_ECT 0 // Non ECN-Capable Transport |
---|
77 | |
---|
78 | // Fragmentation |
---|
79 | // |
---|
80 | #define IP_NO_FRAGMENTATION 0 // No fragmentation |
---|
81 | #define IP_DF_FRAGMENT 0x4000 // "Don't Fragment" bit |
---|
82 | |
---|
83 | // Default TTL |
---|
84 | // See http://en.wikipedia.org/wiki/Time_to_live |
---|
85 | #define IP_DEFAULT_TTL 0x40 // Default TTL is 64 per recommendation |
---|
86 | |
---|
87 | // Supported IP protocols |
---|
88 | // See http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers |
---|
89 | // |
---|
90 | #define IP_PROTOCOL_ICMP 0x01 // Internet Control Message Protocol (ICMP) |
---|
91 | #define IP_PROTOCOL_UDP 0x11 // User Datagram Protocol (UDP) |
---|
92 | |
---|
93 | |
---|
94 | // ********************************************************************** |
---|
95 | // Mango wlan_exp IP/UDP Library UDP Defines |
---|
96 | // |
---|
97 | #define UDP_NO_CHECKSUM 0x0000 // Value if no checksum is generated by the transmitter |
---|
98 | |
---|
99 | |
---|
100 | // ********************************************************************** |
---|
101 | // Mango wlan_exp IP/UDP Library ARP Defines |
---|
102 | // |
---|
103 | |
---|
104 | #define arp_ipv4_packet_t_LEN 28 // Length of IPv4 ARP packet (in bytes) |
---|
105 | |
---|
106 | // ARP Hardware Types |
---|
107 | #define ARP_HTYPE_ETH 0x0001 // Hardware Type: Ethernet (big endian) |
---|
108 | |
---|
109 | // ARP Operation |
---|
110 | #define ARP_REQUEST 0x0001 // ARP Request |
---|
111 | #define ARP_REPLY 0x0002 // ARP Reply |
---|
112 | |
---|
113 | |
---|
114 | // ********************************************************************** |
---|
115 | // Mango wlan_exp IP/UDP Library ICMP Defines |
---|
116 | // |
---|
117 | #define ICMP_ECHO_REQUEST_TYPE 0x0008 // Echo Request (Ping) |
---|
118 | #define ICMP_ECHO_REPLY_TYPE 0x0000 // Echo Reply (Ping) |
---|
119 | #define ICMP_ECHO_CODE 0x0000 // Echo Request / Reply code |
---|
120 | |
---|
121 | |
---|
122 | // ********************************************************************** |
---|
123 | // Mango wlan_exp IP/UDP Library Socket Defines |
---|
124 | // |
---|
125 | |
---|
126 | // Socket Types |
---|
127 | #define SOCK_STREAM 1 // Socket stream (connection) (tcp) |
---|
128 | #define SOCK_DGRAM 2 // Socket datagram (connectionless) (udp) |
---|
129 | |
---|
130 | // Address Families |
---|
131 | #define AF_UNIX 1 // Local to host (pipes, portals) |
---|
132 | #define AF_INET 2 // Inter-network: UDP, TCP, etc. |
---|
133 | |
---|
134 | // Mango wlan_exp IP/UDP Library socket defines |
---|
135 | #define SOCKET_INVALID_SOCKET -1 // Socket is invalid |
---|
136 | |
---|
137 | /*********************** Global Structure Definitions ************************/ |
---|
138 | |
---|
139 | |
---|
140 | // ********************************************************************** |
---|
141 | // Mango wlan_exp IP/UDP Library ICMP Structures |
---|
142 | // |
---|
143 | |
---|
144 | typedef struct icmp_header_t{ |
---|
145 | u8 type; // ICMP Type |
---|
146 | u8 code; // ICMP subtype |
---|
147 | u16 checksum; // Header checksum |
---|
148 | u32 rest; // Rest of Header (4 bytes that vary based on ICMP type and code) |
---|
149 | } icmp_header_t; |
---|
150 | |
---|
151 | |
---|
152 | typedef struct icmp_echo_header_t{ |
---|
153 | u8 type; // ICMP Type |
---|
154 | u8 code; // ICMP subtype |
---|
155 | u16 checksum; // Header checksum (only ICMP part of packet) |
---|
156 | u16 identifier; // Ping identifier |
---|
157 | u16 seq_num; // Ping sequence number |
---|
158 | } icmp_echo_header_t; |
---|
159 | |
---|
160 | |
---|
161 | /*************************** Function Prototypes *****************************/ |
---|
162 | #if WLAN_SW_CONFIG_ENABLE_WLAN_EXP |
---|
163 | // Mango wlan_exp IP/UDP Library functions |
---|
164 | int ip_udp_init(u8* hw_addr, u8* ip_addr); |
---|
165 | int ip_udp_template_init(u8* pkt, u32 port, sockaddr_in_t* to); |
---|
166 | int wlan_exp_ip_udp_set_length(u8* pkt, u32 total_length); |
---|
167 | |
---|
168 | void eth_set_ip_addr(u8* ip_addr); |
---|
169 | void eth_get_ip_addr(u8* ip_addr); |
---|
170 | |
---|
171 | void eth_set_hw_addr(u8* hw_addr); |
---|
172 | void eth_get_hw_addr(u8* hw_addr); |
---|
173 | |
---|
174 | void eth_hdr_init(ethernet_header_t* eth_hdr, |
---|
175 | u8* dest_hw_addr, |
---|
176 | u8* src_hw_addr); |
---|
177 | |
---|
178 | void ip_hdr_init(ipv4_header_t* ip_hdr, |
---|
179 | u8* src_ip_addr, |
---|
180 | u8* dest_ip_addr, |
---|
181 | u8 protocol); |
---|
182 | |
---|
183 | int ipv4_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer, struct eth_tx_queue_buffer_t* eth_tx_queue_buffer); |
---|
184 | u16 ipv4_compute_checksum(u8 * data, u32 size); |
---|
185 | |
---|
186 | void udp_hdr_init(udp_header_t* udp_hdr, |
---|
187 | u16 src_port, |
---|
188 | u16 dest_port); |
---|
189 | |
---|
190 | int udp_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer); |
---|
191 | void udp_init_header(udp_header_t * header, u16 src_port); |
---|
192 | void udp_update_header(udp_header_t * header, u16 dest_port, u16 udp_length); |
---|
193 | |
---|
194 | // ICMP functions |
---|
195 | int icmp_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer, struct eth_tx_queue_buffer_t* eth_tx_queue_buffer); |
---|
196 | #endif //WLAN_SW_CONFIG_ENABLE_WLAN_EXP |
---|
197 | #endif // WLAN_EXP_IP_UDP_H_ |
---|