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 /** Reverse Address Resolution Protocol (RARP) */
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_rarp.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_rarp_enable PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Yuxin Zhou, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function enables the RARP management component for the */
44 /* specified IP instance. For a multi-homed device, RARP is enabled */
45 /* on all attahced interfaces, as long as the interface IP address */
46 /* is not configured yet. */
47 /* */
48 /* INPUT */
49 /* */
50 /* ip_ptr IP instance pointer */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* status Completion status */
55 /* */
56 /* CALLS */
57 /* */
58 /* None */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
69 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
70 /* resulting in version 6.1 */
71 /* */
72 /**************************************************************************/
_nx_rarp_enable(NX_IP * ip_ptr)73 UINT _nx_rarp_enable(NX_IP *ip_ptr)
74 {
75
76 #ifndef NX_DISABLE_IPV4
77 TX_INTERRUPT_SAVE_AREA
78
79 UINT i, rarp_enable;
80
81 /* If trace is enabled, insert this event into the trace buffer. */
82 NX_TRACE_IN_LINE_INSERT(NX_TRACE_RARP_ENABLE, ip_ptr, 0, 0, 0, NX_TRACE_RARP_EVENTS, 0, 0);
83
84 /* Disable interrupts. */
85 TX_DISABLE
86
87 /* Initialize the outcome to cancelling RARP enable. */
88 rarp_enable = NX_FALSE;
89
90 /* Loop through all the interfaces. */
91 for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
92 {
93
94 /* Skip the interfaces that are not initialized or is not Ethernet-like.*/
95 if ((ip_ptr -> nx_ip_interface[i].nx_interface_valid == 0) ||
96 (ip_ptr -> nx_ip_interface[i].nx_interface_address_mapping_needed == 0))
97 {
98 continue;
99 }
100
101
102 /* Does this interface need a valid IP address? */
103 if (ip_ptr -> nx_ip_interface[i].nx_interface_ip_address == 0)
104 {
105
106 /* Yes, reset to the flag to enable RARP. */
107 rarp_enable = NX_TRUE;
108 break;
109 }
110 }
111
112 if (rarp_enable == NX_FALSE)
113 {
114 /* Error, all host interfaces already have a valid IP address (non-zero). */
115
116 /* Restore interrupts. */
117 TX_RESTORE
118
119 /* Return to caller. */
120 return(NX_IP_ADDRESS_ERROR);
121 }
122
123 /* Check to see if RARP has been enabled already. */
124 if (ip_ptr -> nx_ip_rarp_periodic_update)
125 {
126
127 /* Error, IP instance already has RARP enabled. */
128
129 /* Restore interrupts. */
130 TX_RESTORE
131
132 /* Return to caller. */
133 return(NX_ALREADY_ENABLED);
134 }
135
136 /* Setup the RARP periodic update routine. */
137 ip_ptr -> nx_ip_rarp_periodic_update = _nx_rarp_periodic_update;
138
139 /* Restore interrupts. */
140 TX_RESTORE
141
142 /* Return successful completion. */
143 return(NX_SUCCESS);
144 #else /* NX_DISABLE_IPV4 */
145 NX_PARAMETER_NOT_USED(ip_ptr);
146
147 return(NX_NOT_SUPPORTED);
148 #endif /* !NX_DISABLE_IPV4 */
149 }
150
151