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_ip.h"
30 #include "nx_arp.h"
31 
32 
33 /* Bring in externs for caller checking code.  */
34 
35 NX_CALLER_CHECKING_EXTERNS
36 
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  FUNCTION                                               RELEASE        */
41 /*                                                                        */
42 /*    _nxe_arp_gratuitous_send                            PORTABLE C      */
43 /*                                                           6.1          */
44 /*  AUTHOR                                                                */
45 /*                                                                        */
46 /*    Yuxin Zhou, Microsoft Corporation                                   */
47 /*                                                                        */
48 /*  DESCRIPTION                                                           */
49 /*                                                                        */
50 /*    This function checks for errors in the Gratuitous ARP send          */
51 /*    function call.                                                      */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    ip_ptr                                IP instance pointer           */
56 /*    response_handler                      Pointer to function to handle */
57 /*                                            Gratuitous ARP response     */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    status                                Completion status             */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    _nx_arp_gratuitous_send               Send Gratuitous ARP           */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    Application Code                                                    */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
76 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
77 /*                                            resulting in version 6.1    */
78 /*                                                                        */
79 /**************************************************************************/
_nxe_arp_gratuitous_send(NX_IP * ip_ptr,VOID (* response_handler)(NX_IP * ip_ptr,NX_PACKET * packet_ptr))80 UINT  _nxe_arp_gratuitous_send(NX_IP *ip_ptr, VOID (*response_handler)(NX_IP *ip_ptr, NX_PACKET *packet_ptr))
81 {
82 
83 #ifndef NX_DISABLE_IPV4
84 UINT status;
85 UINT i;
86 
87 
88     /* Check for invalid input pointers.  */
89     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID))
90     {
91         return(NX_PTR_ERROR);
92     }
93 
94     /* Check for invalid IP address.  */
95     for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
96     {
97         if (ip_ptr -> nx_ip_interface[i].nx_interface_ip_address)
98         {
99             break;
100         }
101     }
102 
103     if (i == NX_MAX_PHYSICAL_INTERFACES)
104     {
105         return(NX_IP_ADDRESS_ERROR);
106     }
107 
108     /* Check to see if ARP is enabled.  */
109     if (!ip_ptr -> nx_ip_arp_allocate)
110     {
111         return(NX_NOT_ENABLED);
112     }
113 
114     /* Check for appropriate caller.  */
115     NX_THREADS_ONLY_CALLER_CHECKING
116 
117     /* Call actual Gratuitous ARP send function.  */
118     status =  _nx_arp_gratuitous_send(ip_ptr, response_handler);
119 
120     /* Return completion status.  */
121     return(status);
122 #else /* NX_DISABLE_IPV4  */
123     NX_PARAMETER_NOT_USED(ip_ptr);
124     NX_PARAMETER_NOT_USED(response_handler);
125 
126     return(NX_NOT_SUPPORTED);
127 #endif /* !NX_DISABLE_IPV4  */
128 }
129 
130