]>
Commit | Line | Data |
---|---|---|
772db4bb | 1 | /** @file\r |
0c323d07 | 2 | Implementation of EFI Address Resolution Protocol (ARP) Protocol interface functions.\r |
d1102dba LG |
3 | \r |
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
772db4bb | 6 | \r |
772db4bb | 7 | **/\r |
8 | \r | |
9 | #include "ArpImpl.h"\r | |
10 | \r | |
772db4bb | 11 | /**\r |
12 | This function is used to assign a station address to the ARP cache for this instance\r | |
0c323d07 | 13 | of the ARP driver.\r |
d1102dba LG |
14 | \r |
15 | Each ARP instance has one station address. The EFI_ARP_PROTOCOL driver will\r | |
16 | respond to ARP requests that match this registered station address. A call to\r | |
0c323d07 | 17 | this function with the ConfigData field set to NULL will reset this ARP instance.\r |
d1102dba LG |
18 | \r |
19 | Once a protocol type and station address have been assigned to this ARP instance,\r | |
20 | all the following ARP functions will use this information. Attempting to change\r | |
c6d0ee4b | 21 | the protocol type or station address to a configured ARP instance will result in errors.\r |
772db4bb | 22 | \r |
23 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
24 | @param ConfigData Pointer to the EFI_ARP_CONFIG_DATA structure.\r | |
25 | \r | |
26 | @retval EFI_SUCCESS The new station address was successfully\r | |
27 | registered.\r | |
28 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
29 | This is NULL. SwAddressLength is zero when\r | |
30 | ConfigData is not NULL. StationAddress is NULL\r | |
31 | when ConfigData is not NULL.\r | |
32 | @retval EFI_ACCESS_DENIED The SwAddressType, SwAddressLength, or\r | |
33 | StationAddress is different from the one that is\r | |
34 | already registered.\r | |
35 | @retval EFI_OUT_OF_RESOURCES Storage for the new StationAddress could not be\r | |
36 | allocated.\r | |
37 | \r | |
38 | **/\r | |
39 | EFI_STATUS\r | |
40 | EFIAPI\r | |
41 | ArpConfigure (\r | |
42 | IN EFI_ARP_PROTOCOL *This,\r | |
43 | IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL\r | |
44 | )\r | |
45 | {\r | |
46 | EFI_STATUS Status;\r | |
47 | ARP_INSTANCE_DATA *Instance;\r | |
36ee91ca | 48 | EFI_TPL OldTpl;\r |
772db4bb | 49 | \r |
50 | if (This == NULL) {\r | |
51 | return EFI_INVALID_PARAMETER;\r | |
52 | }\r | |
53 | \r | |
54 | if ((ConfigData != NULL) &&\r | |
d1050b9d MK |
55 | ((ConfigData->SwAddressLength == 0) ||\r |
56 | (ConfigData->StationAddress == NULL) ||\r | |
57 | (ConfigData->SwAddressType <= 1500)))\r | |
58 | {\r | |
772db4bb | 59 | return EFI_INVALID_PARAMETER;\r |
60 | }\r | |
61 | \r | |
62 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
63 | \r | |
e48e37fc | 64 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 65 | \r |
66 | //\r | |
67 | // Configure this instance, the ConfigData has already passed the basic checks.\r | |
68 | //\r | |
69 | Status = ArpConfigureInstance (Instance, ConfigData);\r | |
70 | \r | |
e48e37fc | 71 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 72 | \r |
73 | return Status;\r | |
74 | }\r | |
75 | \r | |
772db4bb | 76 | /**\r |
77 | This function is used to insert entries into the ARP cache.\r | |
78 | \r | |
d1102dba LG |
79 | ARP cache entries are typically inserted and updated by network protocol drivers\r |
80 | as network traffic is processed. Most ARP cache entries will time out and be\r | |
81 | deleted if the network traffic stops. ARP cache entries that were inserted\r | |
c6d0ee4b | 82 | by the Add() function may be static (will not time out) or dynamic (will time out).\r |
d1102dba LG |
83 | Default ARP cache timeout values are not covered in most network protocol\r |
84 | specifications (although RFC 1122 comes pretty close) and will only be\r | |
85 | discussed in general in this specification. The timeout values that are\r | |
86 | used in the EFI Sample Implementation should be used only as a guideline.\r | |
87 | Final product implementations of the EFI network stack should be tuned for\r | |
c6d0ee4b | 88 | their expected network environments.\r |
d1102dba | 89 | \r |
772db4bb | 90 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r |
91 | @param DenyFlag Set to TRUE if this entry is a deny entry. Set to\r | |
92 | FALSE if this entry is a normal entry.\r | |
93 | @param TargetSwAddress Pointer to a protocol address to add (or deny).\r | |
94 | May be set to NULL if DenyFlag is TRUE.\r | |
95 | @param TargetHwAddress Pointer to a hardware address to add (or deny).\r | |
96 | May be set to NULL if DenyFlag is TRUE.\r | |
97 | @param TimeoutValue Time in 100-ns units that this entry will remain\r | |
98 | in the ARP cache. A value of zero means that the\r | |
99 | entry is permanent. A nonzero value will override\r | |
100 | the one given by Configure() if the entry to be\r | |
101 | added is a dynamic entry.\r | |
102 | @param Overwrite If TRUE, the matching cache entry will be\r | |
103 | overwritten with the supplied parameters. If\r | |
104 | FALSE, EFI_ACCESS_DENIED is returned if the\r | |
105 | corresponding cache entry already exists.\r | |
106 | \r | |
107 | @retval EFI_SUCCESS The entry has been added or updated.\r | |
108 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
109 | This is NULL. DenyFlag is FALSE and\r | |
110 | TargetHwAddress is NULL. DenyFlag is FALSE and\r | |
111 | TargetSwAddress is NULL. TargetHwAddress is NULL\r | |
112 | and TargetSwAddress is NULL. Both TargetSwAddress\r | |
113 | and TargetHwAddress are not NULL when DenyFlag is\r | |
114 | TRUE.\r | |
115 | @retval EFI_OUT_OF_RESOURCES The new ARP cache entry could not be allocated.\r | |
116 | @retval EFI_ACCESS_DENIED The ARP cache entry already exists and Overwrite\r | |
117 | is not true.\r | |
118 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
119 | \r | |
120 | **/\r | |
121 | EFI_STATUS\r | |
122 | EFIAPI\r | |
123 | ArpAdd (\r | |
124 | IN EFI_ARP_PROTOCOL *This,\r | |
125 | IN BOOLEAN DenyFlag,\r | |
126 | IN VOID *TargetSwAddress OPTIONAL,\r | |
127 | IN VOID *TargetHwAddress OPTIONAL,\r | |
128 | IN UINT32 TimeoutValue,\r | |
129 | IN BOOLEAN Overwrite\r | |
130 | )\r | |
131 | {\r | |
132 | EFI_STATUS Status;\r | |
133 | ARP_INSTANCE_DATA *Instance;\r | |
134 | ARP_SERVICE_DATA *ArpService;\r | |
135 | ARP_CACHE_ENTRY *CacheEntry;\r | |
136 | EFI_SIMPLE_NETWORK_MODE *SnpMode;\r | |
137 | NET_ARP_ADDRESS MatchAddress[2];\r | |
36ee91ca | 138 | EFI_TPL OldTpl;\r |
772db4bb | 139 | \r |
140 | if (This == NULL) {\r | |
141 | return EFI_INVALID_PARAMETER;\r | |
142 | }\r | |
143 | \r | |
144 | if (((!DenyFlag) && ((TargetHwAddress == NULL) || (TargetSwAddress == NULL))) ||\r | |
d1050b9d MK |
145 | (DenyFlag && (TargetHwAddress != NULL) && (TargetSwAddress != NULL)) ||\r |
146 | ((TargetHwAddress == NULL) && (TargetSwAddress == NULL)))\r | |
147 | {\r | |
772db4bb | 148 | return EFI_INVALID_PARAMETER;\r |
149 | }\r | |
150 | \r | |
151 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
152 | \r | |
153 | if (!Instance->Configured) {\r | |
154 | return EFI_NOT_STARTED;\r | |
155 | }\r | |
156 | \r | |
157 | Status = EFI_SUCCESS;\r | |
158 | ArpService = Instance->ArpService;\r | |
159 | SnpMode = &Instance->ArpService->SnpMode;\r | |
160 | \r | |
161 | //\r | |
162 | // Fill the hardware address part in the MatchAddress.\r | |
163 | //\r | |
164 | MatchAddress[Hardware].Type = SnpMode->IfType;\r | |
d1050b9d | 165 | MatchAddress[Hardware].Length = (UINT8)SnpMode->HwAddressSize;\r |
772db4bb | 166 | MatchAddress[Hardware].AddressPtr = TargetHwAddress;\r |
167 | \r | |
168 | //\r | |
169 | // Fill the software address part in the MatchAddress.\r | |
170 | //\r | |
171 | MatchAddress[Protocol].Type = Instance->ConfigData.SwAddressType;\r | |
172 | MatchAddress[Protocol].Length = Instance->ConfigData.SwAddressLength;\r | |
173 | MatchAddress[Protocol].AddressPtr = TargetSwAddress;\r | |
174 | \r | |
e48e37fc | 175 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 176 | \r |
177 | //\r | |
8f628f78 | 178 | // See whether the entry to add exists. Check the DeniedCacheTable first.\r |
772db4bb | 179 | //\r |
180 | CacheEntry = ArpFindDeniedCacheEntry (\r | |
181 | ArpService,\r | |
182 | &MatchAddress[Protocol],\r | |
183 | &MatchAddress[Hardware]\r | |
184 | );\r | |
185 | \r | |
186 | if (CacheEntry == NULL) {\r | |
187 | //\r | |
188 | // Check the ResolvedCacheTable\r | |
189 | //\r | |
190 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
191 | &ArpService->ResolvedCacheTable,\r | |
192 | NULL,\r | |
193 | ByBoth,\r | |
194 | &MatchAddress[Protocol],\r | |
195 | &MatchAddress[Hardware]\r | |
196 | );\r | |
197 | }\r | |
198 | \r | |
199 | if ((CacheEntry != NULL) && !Overwrite) {\r | |
200 | //\r | |
8f628f78 | 201 | // The entry to add exists, if not Overwrite, deny this add request.\r |
772db4bb | 202 | //\r |
203 | Status = EFI_ACCESS_DENIED;\r | |
204 | goto UNLOCK_EXIT;\r | |
205 | }\r | |
206 | \r | |
207 | if ((CacheEntry == NULL) && (TargetSwAddress != NULL)) {\r | |
208 | //\r | |
209 | // Check whether there are pending requests matching the entry to be added.\r | |
210 | //\r | |
211 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
212 | &ArpService->PendingRequestTable,\r | |
213 | NULL,\r | |
214 | ByProtoAddress,\r | |
215 | &MatchAddress[Protocol],\r | |
216 | NULL\r | |
217 | );\r | |
218 | }\r | |
219 | \r | |
220 | if (CacheEntry != NULL) {\r | |
221 | //\r | |
222 | // Remove it from the Table.\r | |
223 | //\r | |
e48e37fc | 224 | RemoveEntryList (&CacheEntry->List);\r |
772db4bb | 225 | } else {\r |
226 | //\r | |
227 | // It's a new entry, allocate memory for the entry.\r | |
228 | //\r | |
229 | CacheEntry = ArpAllocCacheEntry (Instance);\r | |
230 | \r | |
231 | if (CacheEntry == NULL) {\r | |
c49ca4a2 | 232 | DEBUG ((DEBUG_ERROR, "ArpAdd: Failed to allocate pool for CacheEntry.\n"));\r |
772db4bb | 233 | Status = EFI_OUT_OF_RESOURCES;\r |
234 | goto UNLOCK_EXIT;\r | |
235 | }\r | |
236 | }\r | |
237 | \r | |
238 | //\r | |
239 | // Overwrite these parameters.\r | |
240 | //\r | |
241 | CacheEntry->DefaultDecayTime = TimeoutValue;\r | |
242 | CacheEntry->DecayTime = TimeoutValue;\r | |
243 | \r | |
244 | //\r | |
245 | // Fill in the addresses.\r | |
246 | //\r | |
247 | ArpFillAddressInCacheEntry (\r | |
248 | CacheEntry,\r | |
249 | &MatchAddress[Hardware],\r | |
250 | &MatchAddress[Protocol]\r | |
251 | );\r | |
252 | \r | |
253 | //\r | |
254 | // Inform the user if there is any.\r | |
255 | //\r | |
256 | ArpAddressResolved (CacheEntry, NULL, NULL);\r | |
257 | \r | |
258 | //\r | |
259 | // Add this CacheEntry to the corresponding CacheTable.\r | |
260 | //\r | |
261 | if (DenyFlag) {\r | |
e48e37fc | 262 | InsertHeadList (&ArpService->DeniedCacheTable, &CacheEntry->List);\r |
772db4bb | 263 | } else {\r |
e48e37fc | 264 | InsertHeadList (&ArpService->ResolvedCacheTable, &CacheEntry->List);\r |
772db4bb | 265 | }\r |
266 | \r | |
267 | UNLOCK_EXIT:\r | |
268 | \r | |
e48e37fc | 269 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 270 | \r |
271 | return Status;\r | |
272 | }\r | |
273 | \r | |
772db4bb | 274 | /**\r |
275 | This function searches the ARP cache for matching entries and allocates a buffer into\r | |
276 | which those entries are copied.\r | |
d1102dba LG |
277 | \r |
278 | The first part of the allocated buffer is EFI_ARP_FIND_DATA, following which\r | |
c6d0ee4b | 279 | are protocol address pairs and hardware address pairs.\r |
d1102dba LG |
280 | When finding a specific protocol address (BySwAddress is TRUE and AddressBuffer\r |
281 | is not NULL), the ARP cache timeout for the found entry is reset if Refresh is\r | |
282 | set to TRUE. If the found ARP cache entry is a permanent entry, it is not\r | |
c6d0ee4b | 283 | affected by Refresh.\r |
d1102dba | 284 | \r |
772db4bb | 285 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r |
286 | @param BySwAddress Set to TRUE to look for matching software protocol\r | |
287 | addresses. Set to FALSE to look for matching\r | |
288 | hardware protocol addresses.\r | |
289 | @param AddressBuffer Pointer to address buffer. Set to NULL to match\r | |
290 | all addresses.\r | |
291 | @param EntryLength The size of an entry in the entries buffer.\r | |
292 | @param EntryCount The number of ARP cache entries that are found by\r | |
293 | the specified criteria.\r | |
294 | @param Entries Pointer to the buffer that will receive the ARP\r | |
295 | cache entries.\r | |
296 | @param Refresh Set to TRUE to refresh the timeout value of the\r | |
297 | matching ARP cache entry.\r | |
298 | \r | |
299 | @retval EFI_SUCCESS The requested ARP cache entries were copied into\r | |
300 | the buffer.\r | |
301 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
302 | This is NULL. Both EntryCount and EntryLength are\r | |
303 | NULL, when Refresh is FALSE.\r | |
304 | @retval EFI_NOT_FOUND No matching entries were found.\r | |
305 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
306 | \r | |
307 | **/\r | |
308 | EFI_STATUS\r | |
309 | EFIAPI\r | |
310 | ArpFind (\r | |
311 | IN EFI_ARP_PROTOCOL *This,\r | |
312 | IN BOOLEAN BySwAddress,\r | |
313 | IN VOID *AddressBuffer OPTIONAL,\r | |
314 | OUT UINT32 *EntryLength OPTIONAL,\r | |
315 | OUT UINT32 *EntryCount OPTIONAL,\r | |
316 | OUT EFI_ARP_FIND_DATA **Entries OPTIONAL,\r | |
317 | IN BOOLEAN Refresh\r | |
318 | )\r | |
319 | {\r | |
320 | EFI_STATUS Status;\r | |
321 | ARP_INSTANCE_DATA *Instance;\r | |
36ee91ca | 322 | EFI_TPL OldTpl;\r |
772db4bb | 323 | \r |
324 | if ((This == NULL) ||\r | |
d1050b9d MK |
325 | (!Refresh && (EntryCount == NULL) && (EntryLength == NULL)) ||\r |
326 | ((Entries != NULL) && ((EntryLength == NULL) || (EntryCount == NULL))))\r | |
327 | {\r | |
772db4bb | 328 | return EFI_INVALID_PARAMETER;\r |
329 | }\r | |
330 | \r | |
d1050b9d | 331 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r |
772db4bb | 332 | \r |
333 | if (!Instance->Configured) {\r | |
334 | return EFI_NOT_STARTED;\r | |
335 | }\r | |
336 | \r | |
e48e37fc | 337 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 338 | \r |
339 | //\r | |
340 | // All the check passed, find the cache entries now.\r | |
341 | //\r | |
342 | Status = ArpFindCacheEntry (\r | |
343 | Instance,\r | |
344 | BySwAddress,\r | |
345 | AddressBuffer,\r | |
346 | EntryLength,\r | |
347 | EntryCount,\r | |
348 | Entries,\r | |
349 | Refresh\r | |
350 | );\r | |
351 | \r | |
e48e37fc | 352 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 353 | \r |
354 | return Status;\r | |
355 | }\r | |
356 | \r | |
772db4bb | 357 | /**\r |
358 | This function removes specified ARP cache entries.\r | |
359 | \r | |
360 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
361 | @param BySwAddress Set to TRUE to delete matching protocol addresses.\r | |
362 | Set to FALSE to delete matching hardware\r | |
363 | addresses.\r | |
364 | @param AddressBuffer Pointer to the address buffer that is used as a\r | |
365 | key to look for the cache entry. Set to NULL to\r | |
366 | delete all entries.\r | |
367 | \r | |
368 | @retval EFI_SUCCESS The entry was removed from the ARP cache.\r | |
369 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
370 | @retval EFI_NOT_FOUND The specified deletion key was not found.\r | |
371 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
372 | \r | |
373 | **/\r | |
374 | EFI_STATUS\r | |
375 | EFIAPI\r | |
376 | ArpDelete (\r | |
377 | IN EFI_ARP_PROTOCOL *This,\r | |
378 | IN BOOLEAN BySwAddress,\r | |
379 | IN VOID *AddressBuffer OPTIONAL\r | |
380 | )\r | |
381 | {\r | |
382 | ARP_INSTANCE_DATA *Instance;\r | |
772db4bb | 383 | UINTN Count;\r |
36ee91ca | 384 | EFI_TPL OldTpl;\r |
772db4bb | 385 | \r |
386 | if (This == NULL) {\r | |
387 | return EFI_INVALID_PARAMETER;\r | |
388 | }\r | |
389 | \r | |
390 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
391 | \r | |
392 | if (!Instance->Configured) {\r | |
393 | return EFI_NOT_STARTED;\r | |
394 | }\r | |
395 | \r | |
e48e37fc | 396 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 397 | \r |
398 | //\r | |
399 | // Delete the specified cache entries.\r | |
400 | //\r | |
401 | Count = ArpDeleteCacheEntry (Instance, BySwAddress, AddressBuffer, TRUE);\r | |
402 | \r | |
e48e37fc | 403 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 404 | \r |
405 | return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;\r | |
406 | }\r | |
407 | \r | |
772db4bb | 408 | /**\r |
409 | This function delete all dynamic entries from the ARP cache that match the specified\r | |
410 | software protocol type.\r | |
411 | \r | |
412 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
413 | \r | |
414 | @retval EFI_SUCCESS The cache has been flushed.\r | |
415 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
416 | @retval EFI_NOT_FOUND There are no matching dynamic cache entries.\r | |
417 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
418 | \r | |
419 | **/\r | |
420 | EFI_STATUS\r | |
421 | EFIAPI\r | |
422 | ArpFlush (\r | |
423 | IN EFI_ARP_PROTOCOL *This\r | |
424 | )\r | |
425 | {\r | |
426 | ARP_INSTANCE_DATA *Instance;\r | |
772db4bb | 427 | UINTN Count;\r |
36ee91ca | 428 | EFI_TPL OldTpl;\r |
772db4bb | 429 | \r |
430 | if (This == NULL) {\r | |
431 | return EFI_INVALID_PARAMETER;\r | |
432 | }\r | |
433 | \r | |
434 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
435 | \r | |
436 | if (!Instance->Configured) {\r | |
437 | return EFI_NOT_STARTED;\r | |
438 | }\r | |
439 | \r | |
e48e37fc | 440 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 441 | \r |
442 | //\r | |
443 | // Delete the dynamic entries from the cache table.\r | |
444 | //\r | |
445 | Count = ArpDeleteCacheEntry (Instance, FALSE, NULL, FALSE);\r | |
446 | \r | |
e48e37fc | 447 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 448 | \r |
449 | return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;\r | |
450 | }\r | |
451 | \r | |
772db4bb | 452 | /**\r |
453 | This function tries to resolve the TargetSwAddress and optionally returns a\r | |
454 | TargetHwAddress if it already exists in the ARP cache.\r | |
455 | \r | |
456 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
457 | @param TargetSwAddress Pointer to the protocol address to resolve.\r | |
458 | @param ResolvedEvent Pointer to the event that will be signaled when\r | |
459 | the address is resolved or some error occurs.\r | |
460 | @param TargetHwAddress Pointer to the buffer for the resolved hardware\r | |
461 | address in network byte order.\r | |
462 | \r | |
463 | @retval EFI_SUCCESS The data is copied from the ARP cache into the\r | |
464 | TargetHwAddress buffer.\r | |
465 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
466 | This is NULL. TargetHwAddress is NULL.\r | |
467 | @retval EFI_ACCESS_DENIED The requested address is not present in the normal\r | |
468 | ARP cache but is present in the deny address list.\r | |
469 | Outgoing traffic to that address is forbidden.\r | |
470 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
471 | @retval EFI_NOT_READY The request has been started and is not finished.\r | |
472 | \r | |
473 | **/\r | |
474 | EFI_STATUS\r | |
475 | EFIAPI\r | |
476 | ArpRequest (\r | |
477 | IN EFI_ARP_PROTOCOL *This,\r | |
478 | IN VOID *TargetSwAddress OPTIONAL,\r | |
479 | IN EFI_EVENT ResolvedEvent OPTIONAL,\r | |
480 | OUT VOID *TargetHwAddress\r | |
481 | )\r | |
482 | {\r | |
483 | EFI_STATUS Status;\r | |
484 | ARP_INSTANCE_DATA *Instance;\r | |
485 | ARP_SERVICE_DATA *ArpService;\r | |
486 | EFI_SIMPLE_NETWORK_MODE *SnpMode;\r | |
487 | ARP_CACHE_ENTRY *CacheEntry;\r | |
488 | NET_ARP_ADDRESS HardwareAddress;\r | |
489 | NET_ARP_ADDRESS ProtocolAddress;\r | |
490 | USER_REQUEST_CONTEXT *RequestContext;\r | |
36ee91ca | 491 | EFI_TPL OldTpl;\r |
772db4bb | 492 | \r |
493 | if ((This == NULL) || (TargetHwAddress == NULL)) {\r | |
494 | return EFI_INVALID_PARAMETER;\r | |
495 | }\r | |
496 | \r | |
497 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
498 | \r | |
499 | if (!Instance->Configured) {\r | |
500 | return EFI_NOT_STARTED;\r | |
501 | }\r | |
502 | \r | |
503 | Status = EFI_SUCCESS;\r | |
504 | ArpService = Instance->ArpService;\r | |
505 | SnpMode = &ArpService->SnpMode;\r | |
506 | \r | |
507 | if ((TargetSwAddress == NULL) ||\r | |
d1050b9d MK |
508 | ((Instance->ConfigData.SwAddressType == IPV4_ETHER_PROTO_TYPE) &&\r |
509 | IP4_IS_LOCAL_BROADCAST (*((UINT32 *)TargetSwAddress))))\r | |
510 | {\r | |
772db4bb | 511 | //\r |
512 | // Return the hardware broadcast address.\r | |
513 | //\r | |
e48e37fc | 514 | CopyMem (TargetHwAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize);\r |
772db4bb | 515 | \r |
516 | goto SIGNAL_USER;\r | |
517 | }\r | |
518 | \r | |
7bce0c5a | 519 | if ((Instance->ConfigData.SwAddressType == IPV4_ETHER_PROTO_TYPE) &&\r |
d1050b9d MK |
520 | IP4_IS_MULTICAST (NTOHL (*((UINT32 *)TargetSwAddress))))\r |
521 | {\r | |
772db4bb | 522 | //\r |
523 | // If the software address is an IPv4 multicast address, invoke Mnp to\r | |
524 | // resolve the address.\r | |
525 | //\r | |
526 | Status = ArpService->Mnp->McastIpToMac (\r | |
527 | ArpService->Mnp,\r | |
528 | FALSE,\r | |
529 | TargetSwAddress,\r | |
530 | TargetHwAddress\r | |
531 | );\r | |
532 | goto SIGNAL_USER;\r | |
533 | }\r | |
534 | \r | |
535 | HardwareAddress.Type = SnpMode->IfType;\r | |
536 | HardwareAddress.Length = (UINT8)SnpMode->HwAddressSize;\r | |
537 | HardwareAddress.AddressPtr = NULL;\r | |
538 | \r | |
539 | ProtocolAddress.Type = Instance->ConfigData.SwAddressType;\r | |
540 | ProtocolAddress.Length = Instance->ConfigData.SwAddressLength;\r | |
541 | ProtocolAddress.AddressPtr = TargetSwAddress;\r | |
542 | \r | |
543 | //\r | |
8f628f78 | 544 | // Initialize the TargetHwAddress to a zero address.\r |
772db4bb | 545 | //\r |
e48e37fc | 546 | ZeroMem (TargetHwAddress, SnpMode->HwAddressSize);\r |
772db4bb | 547 | \r |
e48e37fc | 548 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 549 | \r |
550 | //\r | |
551 | // Check whether the software address is in the denied table.\r | |
552 | //\r | |
553 | CacheEntry = ArpFindDeniedCacheEntry (ArpService, &ProtocolAddress, NULL);\r | |
554 | if (CacheEntry != NULL) {\r | |
555 | Status = EFI_ACCESS_DENIED;\r | |
556 | goto UNLOCK_EXIT;\r | |
557 | }\r | |
558 | \r | |
559 | //\r | |
560 | // Check whether the software address is already resolved.\r | |
561 | //\r | |
562 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
563 | &ArpService->ResolvedCacheTable,\r | |
564 | NULL,\r | |
565 | ByProtoAddress,\r | |
566 | &ProtocolAddress,\r | |
567 | NULL\r | |
568 | );\r | |
569 | if (CacheEntry != NULL) {\r | |
570 | //\r | |
571 | // Resolved, copy the address into the user buffer.\r | |
572 | //\r | |
e48e37fc | 573 | CopyMem (\r |
772db4bb | 574 | TargetHwAddress,\r |
575 | CacheEntry->Addresses[Hardware].AddressPtr,\r | |
576 | CacheEntry->Addresses[Hardware].Length\r | |
577 | );\r | |
578 | \r | |
579 | goto UNLOCK_EXIT;\r | |
580 | }\r | |
581 | \r | |
582 | if (ResolvedEvent == NULL) {\r | |
583 | Status = EFI_NOT_READY;\r | |
584 | goto UNLOCK_EXIT;\r | |
585 | }\r | |
586 | \r | |
587 | //\r | |
588 | // Create a request context for this arp request.\r | |
589 | //\r | |
d1050b9d | 590 | RequestContext = AllocatePool (sizeof (USER_REQUEST_CONTEXT));\r |
772db4bb | 591 | if (RequestContext == NULL) {\r |
c49ca4a2 | 592 | DEBUG ((DEBUG_ERROR, "ArpRequest: Allocate memory for RequestContext failed.\n"));\r |
772db4bb | 593 | \r |
594 | Status = EFI_OUT_OF_RESOURCES;\r | |
595 | goto UNLOCK_EXIT;\r | |
596 | }\r | |
597 | \r | |
598 | RequestContext->Instance = Instance;\r | |
599 | RequestContext->UserRequestEvent = ResolvedEvent;\r | |
600 | RequestContext->UserHwAddrBuffer = TargetHwAddress;\r | |
e48e37fc | 601 | InitializeListHead (&RequestContext->List);\r |
772db4bb | 602 | \r |
603 | //\r | |
604 | // Check whether there is a same request.\r | |
605 | //\r | |
606 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
607 | &ArpService->PendingRequestTable,\r | |
608 | NULL,\r | |
609 | ByProtoAddress,\r | |
610 | &ProtocolAddress,\r | |
611 | NULL\r | |
612 | );\r | |
613 | if (CacheEntry != NULL) {\r | |
772db4bb | 614 | CacheEntry->NextRetryTime = Instance->ConfigData.RetryTimeOut;\r |
615 | CacheEntry->RetryCount = Instance->ConfigData.RetryCount;\r | |
616 | } else {\r | |
617 | //\r | |
618 | // Allocate a cache entry for this request.\r | |
619 | //\r | |
620 | CacheEntry = ArpAllocCacheEntry (Instance);\r | |
621 | if (CacheEntry == NULL) {\r | |
c49ca4a2 | 622 | DEBUG ((DEBUG_ERROR, "ArpRequest: Allocate memory for CacheEntry failed.\n"));\r |
766c7483 | 623 | FreePool (RequestContext);\r |
772db4bb | 624 | \r |
625 | Status = EFI_OUT_OF_RESOURCES;\r | |
626 | goto UNLOCK_EXIT;\r | |
627 | }\r | |
628 | \r | |
629 | //\r | |
630 | // Fill the software address.\r | |
631 | //\r | |
632 | ArpFillAddressInCacheEntry (CacheEntry, &HardwareAddress, &ProtocolAddress);\r | |
633 | \r | |
634 | //\r | |
635 | // Add this entry into the PendingRequestTable.\r | |
636 | //\r | |
e48e37fc | 637 | InsertTailList (&ArpService->PendingRequestTable, &CacheEntry->List);\r |
772db4bb | 638 | }\r |
639 | \r | |
640 | //\r | |
641 | // Link this request context into the cache entry.\r | |
642 | //\r | |
e48e37fc | 643 | InsertHeadList (&CacheEntry->UserRequestList, &RequestContext->List);\r |
772db4bb | 644 | \r |
645 | //\r | |
646 | // Send out the ARP Request frame.\r | |
647 | //\r | |
648 | ArpSendFrame (Instance, CacheEntry, ARP_OPCODE_REQUEST);\r | |
649 | Status = EFI_NOT_READY;\r | |
650 | \r | |
651 | UNLOCK_EXIT:\r | |
652 | \r | |
e48e37fc | 653 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 654 | \r |
655 | SIGNAL_USER:\r | |
656 | \r | |
657 | if ((ResolvedEvent != NULL) && (Status == EFI_SUCCESS)) {\r | |
658 | gBS->SignalEvent (ResolvedEvent);\r | |
36ee91ca | 659 | \r |
660 | //\r | |
661 | // Dispatch the DPC queued by the NotifyFunction of ResolvedEvent.\r | |
662 | //\r | |
d8d26fb2 | 663 | DispatchDpc ();\r |
772db4bb | 664 | }\r |
665 | \r | |
666 | return Status;\r | |
667 | }\r | |
668 | \r | |
772db4bb | 669 | /**\r |
670 | This function aborts the previous ARP request (identified by This, TargetSwAddress\r | |
671 | and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().\r | |
d1102dba LG |
672 | \r |
673 | If the request is in the internal ARP request queue, the request is aborted\r | |
674 | immediately and its ResolvedEvent is signaled. Only an asynchronous address\r | |
8f628f78 | 675 | request needs to be canceled. If TargetSwAddress and ResolvedEvent are both\r |
d1102dba | 676 | NULL, all the pending asynchronous requests that have been issued by This\r |
c6d0ee4b | 677 | instance will be cancelled and their corresponding events will be signaled.\r |
d1102dba | 678 | \r |
772db4bb | 679 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r |
680 | @param TargetSwAddress Pointer to the protocol address in previous\r | |
681 | request session.\r | |
682 | @param ResolvedEvent Pointer to the event that is used as the\r | |
683 | notification event in previous request session.\r | |
684 | \r | |
685 | @retval EFI_SUCCESS The pending request session(s) is/are aborted and\r | |
686 | corresponding event(s) is/are signaled.\r | |
687 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
688 | This is NULL. TargetSwAddress is not NULL and\r | |
689 | ResolvedEvent is NULL. TargetSwAddress is NULL and\r | |
690 | ResolvedEvent is not NULL.\r | |
691 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
692 | @retval EFI_NOT_FOUND The request is not issued by\r | |
693 | EFI_ARP_PROTOCOL.Request().\r | |
694 | \r | |
695 | **/\r | |
696 | EFI_STATUS\r | |
697 | EFIAPI\r | |
698 | ArpCancel (\r | |
699 | IN EFI_ARP_PROTOCOL *This,\r | |
700 | IN VOID *TargetSwAddress OPTIONAL,\r | |
701 | IN EFI_EVENT ResolvedEvent OPTIONAL\r | |
702 | )\r | |
703 | {\r | |
704 | ARP_INSTANCE_DATA *Instance;\r | |
772db4bb | 705 | UINTN Count;\r |
36ee91ca | 706 | EFI_TPL OldTpl;\r |
772db4bb | 707 | \r |
708 | if ((This == NULL) ||\r | |
d1050b9d MK |
709 | ((TargetSwAddress != NULL) && (ResolvedEvent == NULL)) ||\r |
710 | ((TargetSwAddress == NULL) && (ResolvedEvent != NULL)))\r | |
711 | {\r | |
772db4bb | 712 | return EFI_INVALID_PARAMETER;\r |
713 | }\r | |
714 | \r | |
715 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
716 | \r | |
717 | if (!Instance->Configured) {\r | |
718 | return EFI_NOT_STARTED;\r | |
719 | }\r | |
720 | \r | |
e48e37fc | 721 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 722 | \r |
723 | //\r | |
724 | // Cancel the specified request.\r | |
725 | //\r | |
726 | Count = ArpCancelRequest (Instance, TargetSwAddress, ResolvedEvent);\r | |
727 | \r | |
36ee91ca | 728 | //\r |
729 | // Dispatch the DPCs queued by the NotifyFunction of the events signaled\r | |
8f628f78 | 730 | // by ArpCancelRequest.\r |
36ee91ca | 731 | //\r |
d8d26fb2 | 732 | DispatchDpc ();\r |
36ee91ca | 733 | \r |
e48e37fc | 734 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 735 | \r |
736 | return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;\r | |
737 | }\r |