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