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