source: ReferenceDesigns/w3_802.11/c/wlan_mac_high_framework/wlan_exp_ip_udp/wlan_exp_ip_udp.h

Last change on this file was 6319, checked in by chunter, 5 years ago

1.8.0 release wlan-mac-se

File size: 8.2 KB
Line 
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
18struct arp_cache_entry_t;
19struct wlan_exp_ip_udp_socket_t;
20struct eth_rx_queue_buffer_t;
21struct 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
144typedef 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
152typedef 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
164int ip_udp_init(u8* hw_addr, u8* ip_addr);
165int ip_udp_template_init(u8* pkt, u32 port, sockaddr_in_t* to);
166int wlan_exp_ip_udp_set_length(u8* pkt, u32 total_length);
167
168void eth_set_ip_addr(u8* ip_addr);
169void eth_get_ip_addr(u8* ip_addr);
170
171void eth_set_hw_addr(u8* hw_addr);
172void eth_get_hw_addr(u8* hw_addr);
173
174void eth_hdr_init(ethernet_header_t* eth_hdr,
175                  u8* dest_hw_addr,
176                  u8* src_hw_addr);
177
178void ip_hdr_init(ipv4_header_t* ip_hdr,
179                 u8* src_ip_addr,
180                 u8* dest_ip_addr,
181                 u8 protocol);
182
183int ipv4_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer, struct eth_tx_queue_buffer_t* eth_tx_queue_buffer);
184u16 ipv4_compute_checksum(u8 * data, u32 size);
185
186void udp_hdr_init(udp_header_t* udp_hdr,
187                  u16 src_port,
188                  u16 dest_port);
189
190int udp_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer);
191void udp_init_header(udp_header_t * header, u16 src_port);
192void udp_update_header(udp_header_t * header, u16 dest_port, u16 udp_length);
193
194// ICMP functions
195int 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_
Note: See TracBrowser for help on using the repository browser.