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 /** Address Resolution Protocol (ARP) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define NX_SOURCE_CODE 24 25 26 /* Include necessary system files. */ 27 28 #include "nx_api.h" 29 #include "nx_arp.h" 30 #include "nx_packet.h" 31 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _nx_arp_gratuitous_send PORTABLE C */ 38 /* 6.1 */ 39 /* AUTHOR */ 40 /* */ 41 /* Yuxin Zhou, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function goes through all the physical interfaces to transmit */ 46 /* gratuitous ARP message as long as the interface IP address is */ 47 /* valid. If a response is received at a later time, the supplied */ 48 /* response handler is called. */ 49 /* */ 50 /* INPUT */ 51 /* */ 52 /* ip_ptr Pointer to IP instance */ 53 /* response_handler Pointer to function to handle */ 54 /* Gratuitous ARP response */ 55 /* */ 56 /* OUTPUT */ 57 /* */ 58 /* NX_SUCCESS Successful completion status */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* _nx_arp_announce_send Send ARP announce */ 63 /* tx_mutex_get Get protection mutex */ 64 /* tx_mutex_put Put protection mutex */ 65 /* */ 66 /* CALLED BY */ 67 /* */ 68 /* Application Code */ 69 /* */ 70 /* RELEASE HISTORY */ 71 /* */ 72 /* DATE NAME DESCRIPTION */ 73 /* */ 74 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 75 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 76 /* resulting in version 6.1 */ 77 /* */ 78 /**************************************************************************/ _nx_arp_gratuitous_send(NX_IP * ip_ptr,VOID (* response_handler)(NX_IP * ip_ptr,NX_PACKET * packet_ptr))79UINT _nx_arp_gratuitous_send(NX_IP *ip_ptr, VOID (*response_handler)(NX_IP *ip_ptr, NX_PACKET *packet_ptr)) 80 { 81 82 #ifndef NX_DISABLE_IPV4 83 ULONG i; 84 85 /* Get mutex protection. */ 86 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER); 87 88 /* Save the response handler in the IP structure. */ 89 ip_ptr -> nx_ip_arp_gratuitous_response_handler = response_handler; 90 91 /* Release mutex protection. */ 92 tx_mutex_put(&(ip_ptr -> nx_ip_protection)); 93 94 /* Loop to send ARP announce for all interfaces. */ 95 for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++) 96 { 97 98 /* Skip the entry the IP address is invalid */ 99 /*lint -e{539} suppress positive indentation. */ 100 if (ip_ptr -> nx_ip_interface[i].nx_interface_ip_address == 0) 101 { 102 continue; 103 } 104 105 /* Send ARP announce. */ 106 _nx_arp_announce_send(ip_ptr, i); 107 } 108 109 /* Return a successful completion. */ 110 return(NX_SUCCESS); 111 #else /* NX_DISABLE_IPV4 */ 112 NX_PARAMETER_NOT_USED(ip_ptr); 113 NX_PARAMETER_NOT_USED(response_handler); 114 115 return(NX_NOT_SUPPORTED); 116 #endif /* !NX_DISABLE_IPV4 */ 117 } 118 119