/** @file wlan_exp_ip_udp.h * @brief Mango wlan_exp IP/UDP Library * * @copyright Copyright 2014-2019, Mango Communications. All rights reserved. * Distributed under the Mango Reference Design license (https://mangocomm.com/802.11/license) */ /***************************** Include Files *********************************/ // Xilinx / Standard library includes #include // 802.11 Reference Design includes #include "wlan_high_types.h" #include "wlan_mac_high_sw_config.h" // Forward declarations struct arp_cache_entry_t; struct wlan_exp_ip_udp_socket_t; struct eth_rx_queue_buffer_t; struct eth_tx_queue_buffer_t; /*************************** Constant Definitions ****************************/ #ifndef WLAN_EXP_IP_UDP_H_ #define WLAN_EXP_IP_UDP_H_ // ********************************************************************** // Mango wlan_exp IP/UDP Library ARP Defines // // Mango wlan_exp IP/UDP Library ARP Table States #define ARP_TABLE_UNUSED 0 // ARP Table Entry is not in use #define ARP_TABLE_USED 1 // ARP Table Entry is in use // ********************************************************************** // Mango wlan_exp IP/UDP Library Socket Defines // // Mango wlan_exp IP/UDP Library Socket States #define SOCKET_CLOSED 0 // Socket cannot be used #define SOCKET_ALLOCATED 1 // Socket has been allocated but not bound #define SOCKET_OPEN 2 // Socket is bound and can be used // ********************************************************************** // Mango wlan_exp IP/UDP Library Ethernet Defines // #define ETH_ADDR_LEN 6 // Length of Ethernet MAC address (in bytes) #define ETH_HEADER_LEN 14 // Length of Ethernet Header (in bytes) #define ETHERTYPE_IP_V4 0x0800 // EtherType: IPv4 packet #define ETHERTYPE_ARP 0x0806 // EtherType: ARP packet // ********************************************************************** // Mango wlan_exp IP/UDP Library IP Defines // #define IP_VERSION_4 4 // IP version 4 // ********************************************************************** // Mango wlan_exp IP/UDP Library ARP Structures // - Note: The Mango wlan_exp IP/UDP Library only support IPv4 ARP // // Note: For all transmitted IP packets, IHL == 5 (ie the library always uses the minimum IP header length) #define IP_HEADER_LEN 5 // Length of IP header (in 32-bit words) // The Mango wlan_exp IP/UDP Library is best effort // See http://en.wikipedia.org/wiki/Differentiated_services // #define IP_DSCP_CS0 0 // IP Precedence: Best Effort // The Mango wlan_exp IP/UDP Library is not ECN capable // See http://en.wikipedia.org/wiki/Explicit_Congestion_Notification // #define IP_ECN_NON_ECT 0 // Non ECN-Capable Transport // Fragmentation // #define IP_NO_FRAGMENTATION 0 // No fragmentation #define IP_DF_FRAGMENT 0x4000 // "Don't Fragment" bit // Default TTL // See http://en.wikipedia.org/wiki/Time_to_live #define IP_DEFAULT_TTL 0x40 // Default TTL is 64 per recommendation // Supported IP protocols // See http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers // #define IP_PROTOCOL_ICMP 0x01 // Internet Control Message Protocol (ICMP) #define IP_PROTOCOL_UDP 0x11 // User Datagram Protocol (UDP) // ********************************************************************** // Mango wlan_exp IP/UDP Library UDP Defines // #define UDP_NO_CHECKSUM 0x0000 // Value if no checksum is generated by the transmitter // ********************************************************************** // Mango wlan_exp IP/UDP Library ARP Defines // #define arp_ipv4_packet_t_LEN 28 // Length of IPv4 ARP packet (in bytes) // ARP Hardware Types #define ARP_HTYPE_ETH 0x0001 // Hardware Type: Ethernet (big endian) // ARP Operation #define ARP_REQUEST 0x0001 // ARP Request #define ARP_REPLY 0x0002 // ARP Reply // ********************************************************************** // Mango wlan_exp IP/UDP Library ICMP Defines // #define ICMP_ECHO_REQUEST_TYPE 0x0008 // Echo Request (Ping) #define ICMP_ECHO_REPLY_TYPE 0x0000 // Echo Reply (Ping) #define ICMP_ECHO_CODE 0x0000 // Echo Request / Reply code // ********************************************************************** // Mango wlan_exp IP/UDP Library Socket Defines // // Socket Types #define SOCK_STREAM 1 // Socket stream (connection) (tcp) #define SOCK_DGRAM 2 // Socket datagram (connectionless) (udp) // Address Families #define AF_UNIX 1 // Local to host (pipes, portals) #define AF_INET 2 // Inter-network: UDP, TCP, etc. // Mango wlan_exp IP/UDP Library socket defines #define SOCKET_INVALID_SOCKET -1 // Socket is invalid /*********************** Global Structure Definitions ************************/ // ********************************************************************** // Mango wlan_exp IP/UDP Library ICMP Structures // typedef struct icmp_header_t{ u8 type; // ICMP Type u8 code; // ICMP subtype u16 checksum; // Header checksum u32 rest; // Rest of Header (4 bytes that vary based on ICMP type and code) } icmp_header_t; typedef struct icmp_echo_header_t{ u8 type; // ICMP Type u8 code; // ICMP subtype u16 checksum; // Header checksum (only ICMP part of packet) u16 identifier; // Ping identifier u16 seq_num; // Ping sequence number } icmp_echo_header_t; /*************************** Function Prototypes *****************************/ #if WLAN_SW_CONFIG_ENABLE_WLAN_EXP // Mango wlan_exp IP/UDP Library functions int ip_udp_init(u8* hw_addr, u8* ip_addr); int ip_udp_template_init(u8* pkt, u32 port, sockaddr_in_t* to); int wlan_exp_ip_udp_set_length(u8* pkt, u32 total_length); void eth_set_ip_addr(u8* ip_addr); void eth_get_ip_addr(u8* ip_addr); void eth_set_hw_addr(u8* hw_addr); void eth_get_hw_addr(u8* hw_addr); void eth_hdr_init(ethernet_header_t* eth_hdr, u8* dest_hw_addr, u8* src_hw_addr); void ip_hdr_init(ipv4_header_t* ip_hdr, u8* src_ip_addr, u8* dest_ip_addr, u8 protocol); int ipv4_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer, struct eth_tx_queue_buffer_t* eth_tx_queue_buffer); u16 ipv4_compute_checksum(u8 * data, u32 size); void udp_hdr_init(udp_header_t* udp_hdr, u16 src_port, u16 dest_port); int udp_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer); void udp_init_header(udp_header_t * header, u16 src_port); void udp_update_header(udp_header_t * header, u16 dest_port, u16 udp_length); // ICMP functions int icmp_process_packet(struct eth_rx_queue_buffer_t* eth_rx_queue_buffer, struct eth_tx_queue_buffer_t* eth_tx_queue_buffer); #endif //WLAN_SW_CONFIG_ENABLE_WLAN_EXP #endif // WLAN_EXP_IP_UDP_H_