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 /** Internet Protocol (IP) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* COMPONENT DEFINITION RELEASE */ 27 /* */ 28 /* nx_ip.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 Internet Protocol 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 /* 10-15-2021 Yuxin Zhou Modified comment(s), included */ 48 /* necessary header file, */ 49 /* resulting in version 6.1.9 */ 50 /* */ 51 /**************************************************************************/ 52 53 #ifndef NX_IP_H 54 #define NX_IP_H 55 56 #include "nx_api.h" 57 58 59 /* Define IP constants. */ 60 61 #define NX_IP_ID ((ULONG)0x49502020) 62 63 64 65 /* Define the mask for the IP header length field. */ 66 67 #define NX_IP_LENGTH_MASK ((ULONG)0x0F000000) /* Mask for length bit */ 68 69 70 71 /* Define IP event flags. These events are processed by the IP thread. */ 72 73 #define NX_IP_ALL_EVENTS ((ULONG)0xFFFFFFFF) /* All event flags */ 74 #define NX_IP_PERIODIC_EVENT ((ULONG)0x00000001) /* Periodic event */ 75 #define NX_IP_UNFRAG_EVENT ((ULONG)0x00000002) /* Unfragment event */ 76 #define NX_IP_ICMP_EVENT ((ULONG)0x00000004) /* ICMP message event */ 77 #define NX_IP_RECEIVE_EVENT ((ULONG)0x00000008) /* IP receive packet event */ 78 #define NX_IP_ARP_REC_EVENT ((ULONG)0x00000010) /* ARP deferred receive event */ 79 #define NX_IP_RARP_REC_EVENT ((ULONG)0x00000020) /* RARP deferred receive event */ 80 #define NX_IP_IGMP_EVENT ((ULONG)0x00000040) /* IGMP message event */ 81 #define NX_IP_TCP_EVENT ((ULONG)0x00000080) /* TCP message event */ 82 #define NX_IP_FAST_EVENT ((ULONG)0x00000100) /* Fast TCP timer event */ 83 #ifdef NX_DRIVER_DEFERRED_PROCESSING 84 #define NX_IP_DRIVER_PACKET_EVENT ((ULONG)0x00000200) /* Driver Deferred packet event */ 85 #endif /* NX_DRIVER_DEFERRED_PROCESSING */ 86 #define NX_IP_IGMP_ENABLE_EVENT ((ULONG)0x00000400) /* IGMP enable event */ 87 #define NX_IP_DRIVER_DEFERRED_EVENT ((ULONG)0x00000800) /* Driver deferred processing */ 88 /* event */ 89 #define NX_IP_TCP_CLEANUP_DEFERRED ((ULONG)0x00001000) /* Deferred TCP cleanup event */ 90 #ifdef NX_IPSEC_ENABLE 91 #define NX_IP_HW_DONE_EVENT ((ULONG)0x00002000) /* HW done event */ 92 #endif /* NX_IPSEC_ENABLE */ 93 #define NX_IP_LINK_STATUS_EVENT ((ULONG)0x00004000) /* Link status change event */ 94 95 96 #ifndef NX_IP_FAST_TIMER_RATE 97 #define NX_IP_FAST_TIMER_RATE 10 98 #endif 99 100 /* Define the amount of time to sleep in nx_ip_(interface_)status_check */ 101 #ifndef NX_IP_STATUS_CHECK_WAIT_TIME 102 #define NX_IP_STATUS_CHECK_WAIT_TIME 1 103 #endif /* NX_IP_STATUS_CHECK_WAIT_TIME */ 104 105 #include "nx_ipv4.h" 106 107 108 109 /* Define IP function prototypes. */ 110 UINT _nx_ip_auxiliary_packet_pool_set(NX_IP *ip_ptr, NX_PACKET_POOL *auxiliary_pool); 111 USHORT _nx_ip_checksum_compute(NX_PACKET *packet_ptr, ULONG protocol, UINT data_length, 112 ULONG *_src_ip_addr, ULONG *_dest_ip_addr); 113 UINT _nx_ip_interface_address_mapping_configure(NX_IP *ip_ptr, UINT interface_index, UINT mapping_needed); 114 UINT _nx_ip_interface_capability_get(NX_IP *ip_ptr, UINT interface_index, ULONG *interface_capability_flag); 115 UINT _nx_ip_interface_capability_set(NX_IP *ip_ptr, UINT interface_index, ULONG interface_capability_flag); 116 UINT _nx_ip_interface_info_get(NX_IP *ip_ptr, UINT interface_index, CHAR **interface_name, ULONG *ip_address, 117 ULONG *network_mask, ULONG *mtu_size, ULONG *phsyical_address_msw, 118 ULONG *physical_address_lsw); 119 UINT _nx_ip_interface_mtu_set(NX_IP *ip_ptr, UINT interface_index, ULONG mtu_size); 120 UINT _nx_ip_interface_physical_address_get(NX_IP *ip_ptr, UINT interface_index, ULONG *physical_msw, ULONG *physical_lsw); 121 UINT _nx_ip_interface_physical_address_set(NX_IP *ip_ptr, UINT interface_index, ULONG physical_msw, ULONG physical_lsw, UINT update_driver); 122 UINT _nx_ip_interface_status_check(NX_IP *ip_ptr, UINT interface_index, ULONG needed_status, ULONG *actual_status, 123 ULONG wait_option); 124 UINT _nx_ip_create(NX_IP *ip_ptr, CHAR *name, ULONG ip_address, ULONG network_mask, 125 NX_PACKET_POOL *default_pool, VOID (*ip_link_driver)(NX_IP_DRIVER *), 126 VOID *memory_ptr, ULONG memory_size, UINT priority); 127 UINT _nx_ip_delete(NX_IP *ip_ptr); 128 VOID _nx_ip_delete_queue_clear(NX_PACKET *head_ptr); 129 VOID _nx_ip_deferred_link_status_process(NX_IP *ip_ptr); 130 VOID _nx_ip_driver_link_status_event(NX_IP *ip_ptr, UINT interface_index); 131 VOID _nx_ip_driver_deferred_enable(NX_IP *ip_ptr, VOID (*driver_deferred_packet_handler)(NX_IP *ip_ptr, NX_PACKET *packet_ptr)); 132 VOID _nx_ip_driver_deferred_processing(NX_IP *ip_ptr); 133 VOID _nx_ip_driver_deferred_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 134 UINT _nx_ip_driver_direct_command(NX_IP *ip_ptr, UINT command, ULONG *return_value_ptr); 135 UINT _nx_ip_driver_interface_direct_command(NX_IP *ip_ptr, UINT command, UINT interface_index, ULONG *return_value_ptr); 136 137 138 UINT _nx_ip_forwarding_disable(NX_IP *ip_ptr); 139 UINT _nx_ip_forwarding_enable(NX_IP *ip_ptr); 140 UINT _nx_ip_fragment_disable(NX_IP *ip_ptr); 141 UINT _nx_ip_fragment_enable(NX_IP *ip_ptr); 142 UINT _nx_ip_info_get(NX_IP *ip_ptr, ULONG *ip_total_packets_sent, ULONG *ip_total_bytes_sent, 143 ULONG *ip_total_packets_received, ULONG *ip_total_bytes_received, 144 ULONG *ip_invalid_packets, ULONG *ip_receive_packets_dropped, 145 ULONG *ip_receive_checksum_errors, ULONG *ip_send_packets_dropped, 146 ULONG *ip_total_fragments_sent, ULONG *ip_total_fragments_received); 147 UINT _nx_ip_interface_attach(NX_IP *ip_ptr, CHAR *interface_name, ULONG ip_address, ULONG network_mask, VOID (*ip_link_driver)(struct NX_IP_DRIVER_STRUCT *)); 148 UINT _nx_ip_interface_detach(NX_IP *ip_ptr, UINT index); 149 UINT _nx_ip_max_payload_size_find(NX_IP *ip_ptr, NXD_ADDRESS *dest_address, UINT if_index, 150 UINT src_port, UINT dest_port, ULONG protocol, ULONG *start_offset_ptr, 151 ULONG *payload_length_ptr); 152 UINT _nx_ip_raw_packet_disable(NX_IP *ip_ptr); 153 UINT _nx_ip_raw_packet_enable(NX_IP *ip_ptr); 154 UINT _nx_ip_raw_packet_filter_set(NX_IP *ip_ptr, UINT (*raw_packet_filter)(NX_IP *, ULONG, NX_PACKET *)); 155 UINT _nx_ip_raw_receive_queue_max_set(NX_IP *ip_ptr, ULONG queue_max); 156 UINT _nx_ip_raw_packet_receive(NX_IP *ip_ptr, NX_PACKET **packet_ptr, ULONG wait_option); 157 UINT _nxd_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, NXD_ADDRESS *destination_ip, UINT address_index, ULONG protocol, UINT ttl, ULONG tos); 158 VOID _nx_ip_initialize(VOID); 159 VOID _nx_ip_periodic_timer_entry(ULONG ip_address); 160 VOID _nx_ip_packet_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 161 VOID _nx_ip_packet_deferred_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 162 UINT _nx_ip_status_check(NX_IP *ip_ptr, ULONG needed_status, ULONG *actual_status, ULONG wait_option); 163 UINT _nx_ip_link_status_change_notify_set(NX_IP *ip_ptr, VOID (*link_status_change_notify)(NX_IP *ip_ptr, UINT interface_index, UINT link_up)); 164 VOID _nx_ip_thread_entry(ULONG ip_ptr_value); 165 VOID _nx_ip_raw_packet_cleanup(TX_THREAD *thread_ptr NX_CLEANUP_PARAMETER); 166 UINT _nx_ip_raw_packet_processing(NX_IP *ip_ptr, ULONG protocol, NX_PACKET *packet_ptr); 167 UINT _nxd_ip_raw_packet_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, 168 NXD_ADDRESS *destination_ip, ULONG protocol, UINT ttl, ULONG tos); 169 #ifndef NX_DISABLE_FRAGMENTATION 170 VOID _nx_ip_fragment_timeout_check(NX_IP *ip_ptr); 171 VOID _nx_ip_fragment_packet(struct NX_IP_DRIVER_STRUCT *driver_req_ptr); 172 VOID _nx_ip_fragment_assembly(NX_IP *ip_ptr); 173 #endif /* NX_DISABLE_FRAGMENTATION */ 174 #ifdef NX_ENABLE_INTERFACE_CAPABILITY 175 VOID _nx_ip_packet_checksum_compute(NX_PACKET *packet_ptr); 176 #endif /* NX_ENABLE_INTERFACE_CAPABILITY */ 177 178 179 /* Define error checking shells for API services. These are only referenced by the 180 application. */ 181 182 UINT _nxe_ip_create(NX_IP *ip_ptr, CHAR *name, ULONG ip_address, ULONG network_mask, 183 NX_PACKET_POOL *default_pool, 184 VOID (*ip_link_driver)(NX_IP_DRIVER *), 185 VOID *memory_ptr, ULONG memory_size, UINT priority, UINT ip_control_block_size); 186 UINT _nxe_ip_delete(NX_IP *ip_ptr); 187 UINT _nxe_ip_driver_direct_command(NX_IP *ip_ptr, UINT command, ULONG *return_value_ptr); 188 UINT _nxe_ip_driver_interface_direct_command(NX_IP *ip_ptr, UINT command, UINT interface_index, ULONG *return_value_ptr); 189 UINT _nxe_ip_auxiliary_packet_pool_set(NX_IP *ip_ptr, NX_PACKET_POOL *auxiliary_pool); 190 191 192 UINT _nxe_ip_forwarding_disable(NX_IP *ip_ptr); 193 UINT _nxe_ip_forwarding_enable(NX_IP *ip_ptr); 194 UINT _nxe_ip_fragment_disable(NX_IP *ip_ptr); 195 UINT _nxe_ip_fragment_enable(NX_IP *ip_ptr); 196 UINT _nxe_ip_info_get(NX_IP *ip_ptr, ULONG *ip_total_packets_sent, ULONG *ip_total_bytes_sent, 197 ULONG *ip_total_packets_received, ULONG *ip_total_bytes_received, 198 ULONG *ip_invalid_packets, ULONG *ip_receive_packets_dropped, 199 ULONG *ip_receive_checksum_errors, ULONG *ip_send_packets_dropped, 200 ULONG *ip_total_fragments_sent, ULONG *ip_total_fragments_received); 201 UINT _nxe_ip_interface_attach(NX_IP *ip_ptr, CHAR *interface_name, ULONG ip_address, ULONG network_mask, VOID (*ip_link_driver)(struct NX_IP_DRIVER_STRUCT *)); 202 UINT _nxe_ip_interface_detach(NX_IP *ip_ptr, UINT index); 203 UINT _nxe_ip_max_payload_size_find(NX_IP *ip_ptr, NXD_ADDRESS *dest_address, UINT if_index, 204 UINT src_port, UINT dest_port, ULONG protocol, ULONG *start_offset_ptr, 205 ULONG *payload_length_ptr); 206 UINT _nxe_ip_raw_packet_disable(NX_IP *ip_ptr); 207 UINT _nxe_ip_raw_packet_enable(NX_IP *ip_ptr); 208 UINT _nxe_ip_raw_packet_receive(NX_IP *ip_ptr, NX_PACKET **packet_ptr, ULONG wait_option); 209 UINT _nxde_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, NXD_ADDRESS *destination_ip, UINT address_index, ULONG protocol, UINT ttl, ULONG tos); 210 UINT _nxe_ip_status_check(NX_IP *ip_ptr, ULONG needed_status, ULONG *actual_status, 211 ULONG wait_option); 212 213 UINT _nxe_ip_link_status_change_notify_set(NX_IP *ip_ptr, VOID (*link_status_change_notify)(NX_IP *ip_ptr, UINT interface_index, UINT link_up)); 214 UINT _nxe_ip_interface_address_mapping_configure(NX_IP *ip_ptr, UINT interface_index, UINT mapping_needed); 215 UINT _nxe_ip_interface_capability_get(NX_IP *ip_ptr, UINT interface_index, ULONG *interface_capability_flag); 216 UINT _nxe_ip_interface_capability_set(NX_IP *ip_ptr, UINT interface_index, ULONG interface_capability_flag); 217 UINT _nxe_ip_interface_info_get(NX_IP *ip_ptr, UINT interface_index, CHAR **interface_name, 218 ULONG *ip_address, ULONG *network_mask, ULONG *mtu_size, 219 ULONG *physical_address_msw, ULONG *physical_address_lsw); 220 UINT _nxe_ip_interface_mtu_set(NX_IP *ip_ptr, UINT interface_index, ULONG mtu_size); 221 UINT _nxe_ip_interface_physical_address_get(NX_IP *ip_ptr, UINT interface_index, 222 ULONG *physical_msw, ULONG *physical_lsw); 223 UINT _nxe_ip_interface_physical_address_set(NX_IP *ip_ptr, UINT interface_index, 224 ULONG physical_msw, ULONG physical_lsw, UINT update_driver); 225 UINT _nxe_ip_interface_status_check(NX_IP *ip_ptr, UINT interface_index, ULONG needed_status, 226 ULONG *actual_status, ULONG wait_option); 227 UINT _nxe_ip_raw_packet_filter_set(NX_IP *ip_ptr, 228 UINT (*raw_packet_filter)(NX_IP *, ULONG, NX_PACKET *)); 229 UINT _nxe_ip_raw_receive_queue_max_set(NX_IP *ip_ptr, ULONG queue_max); 230 231 232 VOID _nx_ip_fast_periodic_timer_create(NX_IP *ip_ptr); 233 234 UINT _nx_ip_dispatch_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT protocol); 235 236 /* IP component data declarations follow. */ 237 238 /* Determine if the initialization function of this component is including 239 this file. If so, make the data definitions really happen. Otherwise, 240 make them extern so other functions in the component can access them. */ 241 242 /*lint -e767 suppress different definitions. */ 243 #ifdef NX_IP_INIT 244 #define IP_DECLARE 245 #else 246 #define IP_DECLARE extern 247 #endif 248 /*lint +e767 enable checking for different definitions. */ 249 250 251 /* Define the head pointer of the created IP list. */ 252 253 IP_DECLARE NX_IP *_nx_ip_created_ptr; 254 255 256 /* Define the number of created IP instances. */ 257 258 IP_DECLARE ULONG _nx_ip_created_count; 259 260 261 #endif 262 263