Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_arp.h"
#include "nx_ip.h"
...
...
_nx_arp_static_entry_create(NX_IP *, ULONG, ULONG, ULONG)
Files
netxduo
addons
common
drivers
inc
src
crypto_libraries
nx_secure
ports
threadx
filex
usbx
HAL
CMSIS
lan8742
SourceVuSTM32 Libraries and Samplesnetxduocommon/src/nx_arp_static_entry_create.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Address Resolution Protocol (ARP) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_arp.h" #include "nx_ip.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_arp_static_entry_create PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function dynamically allocates an ARP entry for the application*/ /* to make a static IP to hardware mapping. */ /* */ /* INPUT */ /* */ /* ip_ptr IP instance pointer */ /* ip_address IP Address to bind to */ /* physical_msw Physical address MSW */ /* physical_lsw Physical address LSW */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _nx_ip_route_find Find suitable outgoing */ /* interface */ /* _nx_arp_entry_allocate Allocate an ARP entry */ /* _nx_arp_queue_send Send the queued packet */ /* tx_mutex_get Obtain protection mutex */ /* tx_mutex_put Release protection mutex */ /* */ /* CALLED BY */ /* */ /* Application Code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _nx_arp_static_entry_create(NX_IP *ip_ptr, ULONG ip_address, ULONG physical_msw, ULONG physical_lsw) { #ifndef NX_DISABLE_IPV4 TX_INTERRUPT_SAVE_AREA NX_ARP *arp_ptr; NX_ARP *search_ptr; NX_ARP *arp_list_head; UINT index; UINT status; NX_INTERFACE *nx_interface = NX_NULL; ULONG next_hop_address; /* If trace is enabled, insert this event into the trace buffer. */ NX_TRACE_IN_LINE_INSERT(NX_TRACE_ARP_STATIC_ENTRY_CREATE, ip_ptr, ip_address, physical_msw, physical_lsw, NX_TRACE_ARP_EVENTS, 0, 0); /* Make sure the destination address is directly accessible. */ if (_nx_ip_route_find(ip_ptr, ip_address, &nx_interface, &next_hop_address) != NX_SUCCESS) { return(NX_IP_ADDRESS_ERROR); }if (_nx_ip_route_find(ip_ptr, ip_address, &nx_interface, &next_hop_address) != NX_SUCCESS) { ... } /*lint -e{644} suppress variable might not be initialized, since "next_hop_address" was initialized in _nx_ip_route_find. */ if (next_hop_address != ip_address) { return(NX_IP_ADDRESS_ERROR); }if (next_hop_address != ip_address) { ... } /* Obtain protection on this IP instance for access into the ARP dynamic list. *//* ... */ tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER); /* Calculate the hash index for the specified IP address. */ index = (UINT)((ip_address + (ip_address >> 8)) & NX_ARP_TABLE_MASK); /* Pickup the head pointer of the ARP entries for this IP instance. */ arp_list_head = ip_ptr -> nx_ip_arp_table[index]; /* Search the ARP list for the same IP address. */ search_ptr = arp_list_head; arp_ptr = NX_NULL; while (search_ptr) { /* Determine if there is a duplicate IP address. */ if (search_ptr -> nx_arp_ip_address == ip_address) { /* Yes, the IP address matches, setup the ARP entry pointer. */ arp_ptr = search_ptr; /* Get out of the loop. */ break; }if (search_ptr -> nx_arp_ip_address == ip_address) { ... } /* Move to the next entry in the active list. */ search_ptr = search_ptr -> nx_arp_active_next; /* Determine if the search pointer is back at the head of the list. *//* ... */ if (search_ptr == arp_list_head) { /* End of the ARP list, end the search. */ break; }if (search_ptr == arp_list_head) { ... } }while (search_ptr) { ... } /* Determine if we find an ARP entry. */ if (arp_ptr) { /* Determine if this is a static entry. */ if (arp_ptr -> nx_arp_route_static == NX_FALSE) { /* Disable interrupts temporarily. */ TX_DISABLE /* Remove this entry from the ARP dynamic list. */ /* Determine if this is the only ARP entry on the dynamic list. */ if (arp_ptr == arp_ptr -> nx_arp_pool_next) { /* Remove the sole entry from the dynamic list head. */ ip_ptr -> nx_ip_arp_dynamic_list = NX_NULL; }if (arp_ptr == arp_ptr -> nx_arp_pool_next) { ... } else { /* Remove the entry from a list of more than one entry. */ /* Update the links of the adjacent ARP dynamic pool entries. */ (arp_ptr -> nx_arp_pool_next) -> nx_arp_pool_previous = arp_ptr -> nx_arp_pool_previous; (arp_ptr -> nx_arp_pool_previous) -> nx_arp_pool_next = arp_ptr -> nx_arp_pool_next; /* Update the list head pointer. */ if (ip_ptr -> nx_ip_arp_dynamic_list == arp_ptr) { ip_ptr -> nx_ip_arp_dynamic_list = arp_ptr -> nx_arp_pool_next; }if (ip_ptr -> nx_ip_arp_dynamic_list == arp_ptr) { ... } }else { ... } /* Decrement the number of active dynamic entries. */ ip_ptr -> nx_ip_arp_dynamic_active_count--; /* Add the entry to the ARP static list. */ /* Determine if the ARP static list is empty. */ if (ip_ptr -> nx_ip_arp_static_list == NX_NULL) { /* Just place this single ARP entry on the list. */ arp_ptr -> nx_arp_pool_next = arp_ptr; arp_ptr -> nx_arp_pool_previous = arp_ptr; ip_ptr -> nx_ip_arp_static_list = arp_ptr; }if (ip_ptr -> nx_ip_arp_static_list == NX_NULL) { ... } else { /* Add to the end of the ARP static list. */ arp_ptr -> nx_arp_pool_next = ip_ptr -> nx_ip_arp_static_list; arp_ptr -> nx_arp_pool_previous = (ip_ptr -> nx_ip_arp_static_list) -> nx_arp_pool_previous; ((ip_ptr -> nx_ip_arp_static_list) -> nx_arp_pool_previous) -> nx_arp_pool_next = arp_ptr; (ip_ptr -> nx_ip_arp_static_list) -> nx_arp_pool_previous = arp_ptr; }else { ... } /* Restore interrupts. */ TX_RESTORE #ifndef NX_DISABLE_ARP_INFO /* Increment the ARP static entry count. */ ip_ptr -> nx_ip_arp_static_entries++;/* ... */ #endif }if (arp_ptr -> nx_arp_route_static == NX_FALSE) { ... } }if (arp_ptr) { ... } /* Determine if we didn't find an ARP entry and need to allocate a new static entry. *//* ... */ else { /* No matching IP address in the ARP cache. */ /* Allocate a static ARP entry. */ status = _nx_arp_entry_allocate(ip_ptr, &(ip_ptr -> nx_ip_arp_table[index]), NX_TRUE); /* Determine if an error occurred. */ if (status != NX_SUCCESS) { /* Release the mutex. */ tx_mutex_put(&(ip_ptr -> nx_ip_protection)); /* Return the error status. */ return(status); }if (status != NX_SUCCESS) { ... } /* Otherwise, setup a pointer to the new ARP entry. The newly allocated ARP entry was allocated at the end of the ARP list so it should be referenced using the previous pointer from the list head. *//* ... */ arp_ptr = (ip_ptr -> nx_ip_arp_table[index]) -> nx_arp_active_previous; }else { ... } /* Indicate the entry does not need updating. */ arp_ptr -> nx_arp_entry_next_update = 0; /* Place the important information in the ARP structure. */ arp_ptr -> nx_arp_route_static = NX_TRUE; arp_ptr -> nx_arp_ip_address = ip_address; arp_ptr -> nx_arp_physical_address_msw = physical_msw; arp_ptr -> nx_arp_physical_address_lsw = physical_lsw; /*lint -e{644} suppress variable might not be initialized, since "nx_interface" was initialized in _nx_ip_route_find. */ arp_ptr -> nx_arp_ip_interface = nx_interface; /* Call queue send function to send the packet queued up, if the original entry is dynamic entry. */ _nx_arp_queue_send(ip_ptr, arp_ptr); /* Release the protection on the ARP list. */ tx_mutex_put(&(ip_ptr -> nx_ip_protection)); /* Return status to the caller. */ return(NX_SUCCESS);/* ... */ #else /* NX_DISABLE_IPV4 */ NX_PARAMETER_NOT_USED(ip_ptr); NX_PARAMETER_NOT_USED(ip_address); NX_PARAMETER_NOT_USED(physical_msw); NX_PARAMETER_NOT_USED(physical_lsw); return(NX_NOT_SUPPORTED);/* ... */ #endif /* !NX_DISABLE_IPV4 */ }{ ... }
Details