ArpMain.c 24 KB

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