1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** NetX Component */ 17 /** */ 18 /** User Datagram Protocol (UDP) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* COMPONENT DEFINITION RELEASE */ 27 /* */ 28 /* nx_udp.h PORTABLE C */ 29 /* 6.1.9 */ 30 /* AUTHOR */ 31 /* */ 32 /* Yuxin Zhou, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file defines the NetX User Datagram Protocol (UDP) component, */ 37 /* including all data types and external references. It is assumed */ 38 /* that nx_api.h and nx_port.h have already been included. */ 39 /* */ 40 /* RELEASE HISTORY */ 41 /* */ 42 /* DATE NAME DESCRIPTION */ 43 /* */ 44 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 45 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 46 /* resulting in version 6.1 */ 47 /* 08-02-2021 Yuxin Zhou Modified comment(s), and */ 48 /* supported TCP/IP offload, */ 49 /* resulting in version 6.1.8 */ 50 /* 10-15-2021 Yuxin Zhou Modified comment(s), included */ 51 /* necessary header file, */ 52 /* resulting in version 6.1.9 */ 53 /* */ 54 /**************************************************************************/ 55 56 #ifndef NX_UDP_H 57 #define NX_UDP_H 58 59 #include "nx_api.h" 60 61 62 /* Define UDP constants. */ 63 64 #define NX_UDP_ID ((ULONG)0x55445020) 65 66 67 /* Define Basic UDP packet header data type. This will be used to 68 build new UDP packets and to examine incoming packets into NetX. */ 69 70 typedef struct NX_UDP_HEADER_STRUCT 71 { 72 73 /* Define the first 32-bit word of the UDP header. This word contains 74 the following information: 75 76 bits 31-16 UDP 16-bit source port number 77 bits 15-0 UDP 16-bit destination port number 78 */ 79 ULONG nx_udp_header_word_0; 80 81 /* Define the second and final word of the UDP header. This word contains 82 the following information: 83 84 bits 31-16 UDP 16-bit UDP length (including 8 header bytes) 85 bits 15-0 UDP 16-bit checksum (including header and pseudo IP header) 86 */ 87 ULONG nx_udp_header_word_1; 88 } NX_UDP_HEADER; 89 90 91 /* Define UDP component function prototypes. */ 92 UINT _nxd_udp_socket_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, UINT port); 93 94 VOID _nx_udp_bind_cleanup(TX_THREAD *thread_ptr NX_CLEANUP_PARAMETER); 95 UINT _nx_udp_enable(NX_IP *ip_ptr); 96 UINT _nx_udp_free_port_find(NX_IP *ip_ptr, UINT port, UINT *free_port_ptr); 97 UINT _nx_udp_info_get(NX_IP *ip_ptr, ULONG *udp_packets_sent, ULONG *udp_bytes_sent, 98 ULONG *udp_packets_received, ULONG *udp_bytes_received, 99 ULONG *udp_invalid_packets, ULONG *udp_receive_packets_dropped, 100 ULONG *udp_checksum_errors); 101 VOID _nx_udp_packet_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 102 VOID _nx_udp_receive_cleanup(TX_THREAD *thread_ptr NX_CLEANUP_PARAMETER); 103 UINT _nx_udp_socket_bind(NX_UDP_SOCKET *socket_ptr, UINT port, ULONG wait_option); 104 UINT _nx_udp_socket_bytes_available(NX_UDP_SOCKET *socket_ptr, ULONG *bytes_available); 105 UINT _nx_udp_socket_checksum_disable(NX_UDP_SOCKET *socket_ptr); 106 UINT _nx_udp_socket_checksum_enable(NX_UDP_SOCKET *socket_ptr); 107 UINT _nx_udp_socket_create(NX_IP *ip_ptr, NX_UDP_SOCKET *socket_ptr, CHAR *name, 108 ULONG type_of_service, ULONG fragment, UINT time_to_live, ULONG queue_maximum); 109 UINT _nx_udp_socket_delete(NX_UDP_SOCKET *socket_ptr); 110 UINT _nx_udp_socket_info_get(NX_UDP_SOCKET *socket_ptr, ULONG *udp_packets_sent, ULONG *udp_bytes_sent, 111 ULONG *udp_packets_received, ULONG *udp_bytes_received, ULONG *udp_packets_queued, 112 ULONG *udp_receive_packets_dropped, ULONG *udp_checksum_errors); 113 UINT _nxd_udp_socket_source_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, UINT port, UINT address_index); 114 UINT _nxde_udp_socket_source_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, UINT port, UINT address_index); 115 UINT _nx_udp_socket_port_get(NX_UDP_SOCKET *socket_ptr, UINT *port_ptr); 116 UINT _nx_udp_socket_receive(NX_UDP_SOCKET *socket_ptr, NX_PACKET **packet_ptr, 117 ULONG wait_option); 118 UINT _nx_udp_socket_receive_notify(NX_UDP_SOCKET *socket_ptr, 119 VOID (*udp_receive_notify)(NX_UDP_SOCKET *socket_ptr)); 120 121 UINT _nx_udp_socket_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, 122 ULONG ip_address, UINT port); 123 UINT _nx_udp_socket_unbind(NX_UDP_SOCKET *socket_ptr); 124 UINT _nx_udp_source_extract(NX_PACKET *packet_ptr, ULONG *ip_address, UINT *port); 125 UINT _nx_udp_packet_info_extract(NX_PACKET *packet_ptr, ULONG *ip_address, UINT *protocol, UINT *port, UINT *interface_index); 126 UINT _nxd_udp_source_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, UINT *port); 127 #ifdef NX_ENABLE_TCPIP_OFFLOAD 128 /* Define the direct UDP packet receive processing. This is used with TCP/IP offload feature. */ 129 VOID _nx_udp_socket_driver_packet_receive(NX_UDP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, 130 NXD_ADDRESS *local_ip, NXD_ADDRESS *remote_ip, UINT remote_port); 131 #endif /* NX_ENABLE_TCPIP_OFFLOAD */ 132 133 /* Define error checking shells for API services. These are only referenced by the 134 application. */ 135 136 UINT _nxe_udp_enable(NX_IP *ip_ptr); 137 UINT _nxe_udp_free_port_find(NX_IP *ip_ptr, UINT port, UINT *free_port_ptr); 138 UINT _nxe_udp_info_get(NX_IP *ip_ptr, ULONG *udp_packets_sent, ULONG *udp_bytes_sent, 139 ULONG *udp_packets_received, ULONG *udp_bytes_received, 140 ULONG *udp_invalid_packets, ULONG *udp_receive_packets_dropped, 141 ULONG *udp_checksum_errors); 142 UINT _nxe_udp_socket_bind(NX_UDP_SOCKET *socket_ptr, UINT port, ULONG wait_option); 143 UINT _nxe_udp_socket_bytes_available(NX_UDP_SOCKET *socket_ptr, ULONG *bytes_available); 144 UINT _nxe_udp_socket_checksum_disable(NX_UDP_SOCKET *socket_ptr); 145 UINT _nxe_udp_socket_checksum_enable(NX_UDP_SOCKET *socket_ptr); 146 UINT _nxe_udp_socket_create(NX_IP *ip_ptr, NX_UDP_SOCKET *socket_ptr, CHAR *name, 147 ULONG type_of_service, ULONG fragment, UINT time_to_live, ULONG queue_maximum, UINT udp_socket_size); 148 UINT _nxe_udp_socket_delete(NX_UDP_SOCKET *socket_ptr); 149 150 UINT _nxe_udp_source_extract(NX_PACKET *packet_ptr, ULONG *ip_address, UINT *port); 151 UINT _nxde_udp_source_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, UINT *port); 152 UINT _nxe_udp_socket_info_get(NX_UDP_SOCKET *socket_ptr, ULONG *udp_packets_sent, ULONG *udp_bytes_sent, 153 ULONG *udp_packets_received, ULONG *udp_bytes_received, ULONG *udp_packets_queued, 154 ULONG *udp_receive_packets_dropped, ULONG *udp_checksum_errors); 155 UINT _nxe_udp_socket_port_get(NX_UDP_SOCKET *socket_ptr, UINT *port_ptr); 156 UINT _nxe_udp_socket_receive(NX_UDP_SOCKET *socket_ptr, NX_PACKET **packet_ptr, 157 ULONG wait_option); 158 UINT _nxe_udp_socket_receive_notify(NX_UDP_SOCKET *socket_ptr, 159 VOID (*udp_receive_notify)(NX_UDP_SOCKET *socket_ptr)); 160 UINT _nx_udp_socket_source_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, 161 ULONG ip_address, UINT port, UINT address_index); 162 UINT _nxe_udp_socket_source_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET **packet_ptr, 163 ULONG ip_address, UINT port, UINT source_index); 164 UINT _nxe_udp_socket_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET **packet_ptr_ptr, 165 ULONG ip_address, UINT port); 166 UINT _nxe_udp_socket_unbind(NX_UDP_SOCKET *socket_ptr); 167 168 169 170 UINT _nxd_udp_packet_info_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, 171 UINT *protocol, UINT *port, UINT *interface_index); 172 UINT _nxde_udp_packet_info_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *ip_address, 173 UINT *protocol, UINT *port, UINT *interface_index); 174 UINT _nxe_udp_packet_info_extract(NX_PACKET *packet_ptr, ULONG *ip_address, UINT *protocol, UINT *port, UINT *interface_index); 175 UINT _nxde_udp_socket_send(NX_UDP_SOCKET *socket_ptr, NX_PACKET **packet_ptr, NXD_ADDRESS *ip_address, UINT port); 176 177 /* UDP component data declarations follow. */ 178 179 #endif 180 181