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