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 /**   Address Resolution Protocol (ARP)                                   */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "nx_api.h"
28 #include "nx_ip.h"
29 #include "nx_arp.h"
30 
31 /* Bring in externs for caller checking code.  */
32 
33 NX_CALLER_CHECKING_EXTERNS
34 
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _nxe_arp_static_entry_create                        PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Yuxin Zhou, Microsoft Corporation                                   */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function checks for errors in the ARP static entry create      */
49 /*    function call.                                                      */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    ip_ptr                                IP instance pointer           */
54 /*    ip_address                            IP Address to bind to         */
55 /*    physical_msw                          Physical address MSW          */
56 /*    physical_lsw                          Physical address LSW          */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _nx_arp_static_entry_create          Actual static entry create     */
65 /*                                            function                    */
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_static_entry_create(NX_IP * ip_ptr,ULONG ip_address,ULONG physical_msw,ULONG physical_lsw)80 UINT  _nxe_arp_static_entry_create(NX_IP *ip_ptr, ULONG ip_address,
81                                    ULONG physical_msw, ULONG physical_lsw)
82 {
83 
84 #ifndef NX_DISABLE_IPV4
85 UINT status;
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     if (!ip_address)
96     {
97         return(NX_IP_ADDRESS_ERROR);
98     }
99 
100     /* Determine if the IP address is multicast or directed broadcast.  */
101     if (((ip_address & NX_IP_CLASS_D_MASK) == NX_IP_CLASS_D_TYPE) ||
102         (ip_address  == NX_IP_LIMITED_BROADCAST))
103     {
104         return(NX_IP_ADDRESS_ERROR);
105     }
106 
107     /* Check for invalid physical address.  */
108     if ((physical_msw | physical_lsw) == 0)
109     {
110         return(NX_INVALID_PARAMETERS);
111     }
112 
113     /* Check to see if ARP is enabled.  */
114     if (!ip_ptr -> nx_ip_arp_allocate)
115     {
116         return(NX_NOT_ENABLED);
117     }
118 
119     /* Check for appropriate caller.  */
120     NX_INIT_AND_THREADS_CALLER_CHECKING
121 
122     /* Call actual ARP static entry create function.  */
123     status =  _nx_arp_static_entry_create(ip_ptr, ip_address, physical_msw, physical_lsw);
124 
125     /* Return completion status.  */
126     return(status);
127 #else /* NX_DISABLE_IPV4  */
128     NX_PARAMETER_NOT_USED(ip_ptr);
129     NX_PARAMETER_NOT_USED(ip_address);
130     NX_PARAMETER_NOT_USED(physical_msw);
131     NX_PARAMETER_NOT_USED(physical_lsw);
132 
133     return(NX_NOT_SUPPORTED);
134 #endif /* !NX_DISABLE_IPV4  */
135 }
136 
137