/** @file\r
The implementation of the ARP protocol.\r
\r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
ArpCancel\r
};\r
\r
-\r
/**\r
Initialize the instance context data.\r
\r
InitializeListHead (&Instance->List);\r
}\r
\r
-\r
/**\r
Process the Arp packets received from Mnp, the procedure conforms to RFC826.\r
\r
- @param[in] Context Pointer to the context data registerd to the\r
+ @param[in] Context Pointer to the context data registered to the\r
Event.\r
\r
@return None.\r
VOID\r
EFIAPI\r
ArpOnFrameRcvdDpc (\r
- IN VOID *Context\r
+ IN VOID *Context\r
)\r
{\r
EFI_STATUS Status;\r
//\r
// Restart the receiving if packet size is not correct.\r
//\r
- goto RESTART_RECEIVE;\r
+ goto RECYCLE_RXDATA;\r
}\r
\r
//\r
// Convert the byte order of the multi-byte fields.\r
//\r
- Head = (ARP_HEAD *) RxData->PacketData;\r
+ Head = (ARP_HEAD *)RxData->PacketData;\r
Head->HwType = NTOHS (Head->HwType);\r
Head->ProtoType = NTOHS (Head->ProtoType);\r
Head->OpCode = NTOHS (Head->OpCode);\r
\r
if (RxData->DataLength < (sizeof (ARP_HEAD) + 2 * Head->HwAddrLen + 2 * Head->ProtoAddrLen)) {\r
- goto RESTART_RECEIVE;\r
+ goto RECYCLE_RXDATA;\r
}\r
\r
if ((Head->HwType != ArpService->SnpMode.IfType) ||\r
- (Head->HwAddrLen != ArpService->SnpMode.HwAddressSize) ||\r
- (RxData->ProtocolType != ARP_ETHER_PROTO_TYPE)) {\r
+ (Head->HwAddrLen != ArpService->SnpMode.HwAddressSize) ||\r
+ (RxData->ProtocolType != ARP_ETHER_PROTO_TYPE))\r
+ {\r
//\r
// The hardware type or the hardware address length doesn't match.\r
// There is a sanity check for the protocol type too.\r
ConfigData = &Instance->ConfigData;\r
\r
if ((Instance->Configured) &&\r
- (Head->ProtoType == ConfigData->SwAddressType) &&\r
- (Head->ProtoAddrLen == ConfigData->SwAddressLength)) {\r
+ (Head->ProtoType == ConfigData->SwAddressType) &&\r
+ (Head->ProtoAddrLen == ConfigData->SwAddressLength))\r
+ {\r
//\r
// The protocol type is matched for the received arp packet.\r
//\r
(VOID *)ArpAddress.TargetProtoAddr,\r
ConfigData->StationAddress,\r
ConfigData->SwAddressLength\r
- )) {\r
+ ))\r
+ {\r
//\r
// The arp driver has the target address required by the received arp packet.\r
//\r
//\r
ArpFillAddressInCacheEntry (CacheEntry, &SenderAddress[Hardware], NULL);\r
CacheEntry->DecayTime = CacheEntry->DefaultDecayTime;\r
- MergeFlag = TRUE;\r
+ MergeFlag = TRUE;\r
}\r
\r
if (!IsTarget) {\r
//\r
Status = ArpService->Mnp->Receive (ArpService->Mnp, RxToken);\r
\r
- DEBUG_CODE (\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "ArpOnFrameRcvd: ArpService->Mnp->Receive "\r
- "failed, %r\n.", Status));\r
- }\r
- );\r
+ DEBUG_CODE_BEGIN ();\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "ArpOnFrameRcvd: ArpService->Mnp->Receive "\r
+ "failed, %r\n.",\r
+ Status\r
+ ));\r
+ }\r
+\r
+ DEBUG_CODE_END ();\r
}\r
\r
/**\r
Queue ArpOnFrameRcvdDpc as a DPC at TPL_CALLBACK.\r
\r
@param[in] Event The Event this notify function registered to.\r
- @param[in] Context Pointer to the context data registerd to the\r
+ @param[in] Context Pointer to the context data registered to the\r
Event.\r
\r
@return None.\r
/**\r
Process the already sent arp packets.\r
\r
- @param[in] Context Pointer to the context data registerd to the\r
+ @param[in] Context Pointer to the context data registered to the\r
Event.\r
\r
@return None.\r
VOID\r
EFIAPI\r
ArpOnFrameSentDpc (\r
- IN VOID *Context\r
+ IN VOID *Context\r
)\r
{\r
EFI_MANAGED_NETWORK_COMPLETION_TOKEN *TxToken;\r
TxToken = (EFI_MANAGED_NETWORK_COMPLETION_TOKEN *)Context;\r
TxData = TxToken->Packet.TxData;\r
\r
- DEBUG_CODE (\r
- if (EFI_ERROR (TxToken->Status)) {\r
- DEBUG ((EFI_D_ERROR, "ArpOnFrameSent: TxToken->Status, %r.\n", TxToken->Status));\r
- }\r
- );\r
+ DEBUG_CODE_BEGIN ();\r
+ if (EFI_ERROR (TxToken->Status)) {\r
+ DEBUG ((DEBUG_ERROR, "ArpOnFrameSent: TxToken->Status, %r.\n", TxToken->Status));\r
+ }\r
+\r
+ DEBUG_CODE_END ();\r
\r
//\r
// Free the allocated memory and close the event.\r
Request ArpOnFrameSentDpc as a DPC at TPL_CALLBACK.\r
\r
@param[in] Event The Event this notify function registered to.\r
- @param[in] Context Pointer to the context data registerd to the\r
+ @param[in] Context Pointer to the context data registered to the\r
Event.\r
\r
@return None.\r
QueueDpc (TPL_CALLBACK, ArpOnFrameSentDpc, Context);\r
}\r
\r
-\r
/**\r
Process the arp cache olding and drive the retrying arp requests.\r
\r
@param[in] Event The Event this notify function registered to.\r
- @param[in] Context Pointer to the context data registerd to the\r
+ @param[in] Context Pointer to the context data registered to the\r
Event.\r
\r
@return None.\r
//\r
// resend the ARP request.\r
//\r
- ASSERT (!IsListEmpty(&CacheEntry->UserRequestList));\r
+ ASSERT (!IsListEmpty (&CacheEntry->UserRequestList));\r
\r
ContextEntry = CacheEntry->UserRequestList.ForwardLink;\r
RequestContext = NET_LIST_USER_STRUCT (ContextEntry, USER_REQUEST_CONTEXT, List);\r
}\r
}\r
\r
-\r
/**\r
Match the two NET_ARP_ADDRESSes.\r
\r
ASSERT (AddressOne != NULL && AddressTwo != NULL);\r
\r
if ((AddressOne->Type != AddressTwo->Type) ||\r
- (AddressOne->Length != AddressTwo->Length)) {\r
+ (AddressOne->Length != AddressTwo->Length))\r
+ {\r
//\r
// Either Type or Length doesn't match.\r
//\r
}\r
\r
if ((AddressOne->AddressPtr != NULL) &&\r
- (CompareMem (\r
- AddressOne->AddressPtr,\r
- AddressTwo->AddressPtr,\r
- AddressOne->Length\r
- ) != 0)) {\r
+ (CompareMem (\r
+ AddressOne->AddressPtr,\r
+ AddressTwo->AddressPtr,\r
+ AddressOne->Length\r
+ ) != 0))\r
+ {\r
//\r
// The address is not the same.\r
//\r
return TRUE;\r
}\r
\r
-\r
/**\r
Find the CacheEntry which matches the requirements in the specified CacheTable.\r
\r
**/\r
ARP_CACHE_ENTRY *\r
ArpFindNextCacheEntryInTable (\r
- IN LIST_ENTRY *CacheTable,\r
- IN LIST_ENTRY *StartEntry,\r
- IN FIND_OPTYPE FindOpType,\r
- IN NET_ARP_ADDRESS *ProtocolAddress OPTIONAL,\r
- IN NET_ARP_ADDRESS *HardwareAddress OPTIONAL\r
+ IN LIST_ENTRY *CacheTable,\r
+ IN LIST_ENTRY *StartEntry,\r
+ IN FIND_OPTYPE FindOpType,\r
+ IN NET_ARP_ADDRESS *ProtocolAddress OPTIONAL,\r
+ IN NET_ARP_ADDRESS *HardwareAddress OPTIONAL\r
)\r
{\r
LIST_ENTRY *Entry;\r
return NULL;\r
}\r
\r
-\r
/**\r
Find the CacheEntry, using ProtocolAddress or HardwareAddress or both, as the keyword,\r
in the DeniedCacheTable.\r
return CacheEntry;\r
}\r
\r
-\r
/**\r
Allocate a cache entry and initialize it.\r
\r
//\r
// Init the address pointers to point to the concrete buffer.\r
//\r
- Address = &CacheEntry->Addresses[Index];\r
+ Address = &CacheEntry->Addresses[Index];\r
Address->AddressPtr = Address->Buffer.ProtoAddress;\r
}\r
\r
return CacheEntry;\r
}\r
\r
-\r
/**\r
Turn the CacheEntry into the resolved status.\r
\r
Context = NET_LIST_USER_STRUCT (Entry, USER_REQUEST_CONTEXT, List);\r
\r
if (((Instance == NULL) || (Context->Instance == Instance)) &&\r
- ((UserEvent == NULL) || (Context->UserRequestEvent == UserEvent))) {\r
+ ((UserEvent == NULL) || (Context->UserRequestEvent == UserEvent)))\r
+ {\r
//\r
// Copy the address to the user-provided buffer and notify the user.\r
//\r
return Count;\r
}\r
\r
-\r
/**\r
Fill the addresses in the CacheEntry using the information passed in by\r
HwAddr and SwAddr.\r
}\r
}\r
\r
-\r
/**\r
Configure the instance using the ConfigData. ConfigData is already validated.\r
\r
OldConfigData = &Instance->ConfigData;\r
\r
if (ConfigData != NULL) {\r
-\r
if (Instance->Configured) {\r
//\r
// The instance is configured, check the unchangeable fields.\r
//\r
if ((OldConfigData->SwAddressType != ConfigData->SwAddressType) ||\r
- (OldConfigData->SwAddressLength != ConfigData->SwAddressLength) ||\r
- (CompareMem (\r
- OldConfigData->StationAddress,\r
- ConfigData->StationAddress,\r
- OldConfigData->SwAddressLength\r
- ) != 0)) {\r
+ (OldConfigData->SwAddressLength != ConfigData->SwAddressLength) ||\r
+ (CompareMem (\r
+ OldConfigData->StationAddress,\r
+ ConfigData->StationAddress,\r
+ OldConfigData->SwAddressLength\r
+ ) != 0))\r
+ {\r
//\r
// Deny the unallowed changes.\r
//\r
\r
OldConfigData->StationAddress = AllocatePool (OldConfigData->SwAddressLength);\r
if (OldConfigData->StationAddress == NULL) {\r
- DEBUG ((EFI_D_ERROR, "ArpConfigInstance: AllocatePool for the StationAddress "\r
- "failed.\n"));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "ArpConfigInstance: AllocatePool for the StationAddress "\r
+ "failed.\n"\r
+ ));\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
// Use the implementation specific values if the following field is zero.\r
//\r
OldConfigData->EntryTimeOut = (ConfigData->EntryTimeOut == 0) ?\r
- ARP_DEFAULT_TIMEOUT_VALUE : ConfigData->EntryTimeOut;\r
+ ARP_DEFAULT_TIMEOUT_VALUE : ConfigData->EntryTimeOut;\r
\r
- OldConfigData->RetryCount = (ConfigData->RetryCount == 0) ?\r
- ARP_DEFAULT_RETRY_COUNT : ConfigData->RetryCount;\r
+ OldConfigData->RetryCount = (ConfigData->RetryCount == 0) ?\r
+ ARP_DEFAULT_RETRY_COUNT : ConfigData->RetryCount;\r
\r
OldConfigData->RetryTimeOut = (ConfigData->RetryTimeOut == 0) ?\r
- ARP_DEFAULT_RETRY_INTERVAL : ConfigData->RetryTimeOut;\r
+ ARP_DEFAULT_RETRY_INTERVAL : ConfigData->RetryTimeOut;\r
} else {\r
//\r
// Reset the configuration.\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
- Send out an arp frame using the CachEntry and the ArpOpCode.\r
+ Send out an arp frame using the CacheEntry and the ArpOpCode.\r
\r
@param[in] Instance Pointer to the instance context data.\r
@param[in] CacheEntry Pointer to the configuration data used to\r
//\r
// Allocate memory for the TxToken.\r
//\r
- TxToken = AllocatePool (sizeof(EFI_MANAGED_NETWORK_COMPLETION_TOKEN));\r
+ TxToken = AllocatePool (sizeof (EFI_MANAGED_NETWORK_COMPLETION_TOKEN));\r
if (TxToken == NULL) {\r
- DEBUG ((EFI_D_ERROR, "ArpSendFrame: Allocate memory for TxToken failed.\n"));\r
+ DEBUG ((DEBUG_ERROR, "ArpSendFrame: Allocate memory for TxToken failed.\n"));\r
return;\r
}\r
\r
&TxToken->Event\r
);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "ArpSendFrame: CreateEvent failed for TxToken->Event.\n"));\r
+ DEBUG ((DEBUG_ERROR, "ArpSendFrame: CreateEvent failed for TxToken->Event.\n"));\r
goto CLEAN_EXIT;\r
}\r
\r
//\r
// Allocate memory for the TxData used in the TxToken.\r
//\r
- TxData = AllocatePool (sizeof(EFI_MANAGED_NETWORK_TRANSMIT_DATA));\r
+ TxData = AllocatePool (sizeof (EFI_MANAGED_NETWORK_TRANSMIT_DATA));\r
if (TxData == NULL) {\r
- DEBUG ((EFI_D_ERROR, "ArpSendFrame: Allocate memory for TxData failed.\n"));\r
+ DEBUG ((DEBUG_ERROR, "ArpSendFrame: Allocate memory for TxData failed.\n"));\r
goto CLEAN_EXIT;\r
}\r
\r
//\r
Packet = AllocatePool (TotalLength);\r
if (Packet == NULL) {\r
- DEBUG ((EFI_D_ERROR, "ArpSendFrame: Allocate memory for Packet failed.\n"));\r
+ DEBUG ((DEBUG_ERROR, "ArpSendFrame: Allocate memory for Packet failed.\n"));\r
ASSERT (Packet != NULL);\r
}\r
\r
SnpMode->HwAddressSize\r
);\r
}\r
+\r
TmpPtr += SnpMode->HwAddressSize;\r
\r
//\r
// The ethernet protocol type.\r
//\r
*(UINT16 *)TmpPtr = HTONS (ARP_ETHER_PROTO_TYPE);\r
- TmpPtr += 2;\r
+ TmpPtr += 2;\r
\r
//\r
// The ARP Head.\r
//\r
- ArpHead = (ARP_HEAD *) TmpPtr;\r
+ ArpHead = (ARP_HEAD *)TmpPtr;\r
ArpHead->HwType = HTONS ((UINT16)SnpMode->IfType);\r
ArpHead->ProtoType = HTONS (ConfigData->SwAddressType);\r
ArpHead->HwAddrLen = (UINT8)SnpMode->HwAddressSize;\r
ArpHead->ProtoAddrLen = ConfigData->SwAddressLength;\r
ArpHead->OpCode = HTONS (ArpOpCode);\r
- TmpPtr += sizeof (ARP_HEAD);\r
+ TmpPtr += sizeof (ARP_HEAD);\r
\r
//\r
// The sender hardware address.\r
TxData->SourceAddress = NULL;\r
TxData->ProtocolType = 0;\r
TxData->DataLength = TotalLength - SnpMode->MediaHeaderSize;\r
- TxData->HeaderLength = (UINT16) SnpMode->MediaHeaderSize;\r
+ TxData->HeaderLength = (UINT16)SnpMode->MediaHeaderSize;\r
TxData->FragmentCount = 1;\r
\r
TxData->FragmentTable[0].FragmentBuffer = Packet;\r
//\r
Status = ArpService->Mnp->Transmit (ArpService->Mnp, TxToken);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "Mnp->Transmit failed, %r.\n", Status));\r
+ DEBUG ((DEBUG_ERROR, "Mnp->Transmit failed, %r.\n", Status));\r
goto CLEAN_EXIT;\r
}\r
\r
FreePool (TxToken);\r
}\r
\r
-\r
/**\r
Delete the cache entries in the specified CacheTable, using the BySwAddress,\r
SwAddressType, AddressBuffer combination as the matching key, if Force is TRUE,\r
**/\r
UINTN\r
ArpDeleteCacheEntryInTable (\r
- IN LIST_ENTRY *CacheTable,\r
- IN BOOLEAN BySwAddress,\r
- IN UINT16 SwAddressType,\r
- IN UINT8 *AddressBuffer OPTIONAL,\r
- IN BOOLEAN Force\r
+ IN LIST_ENTRY *CacheTable,\r
+ IN BOOLEAN BySwAddress,\r
+ IN UINT16 SwAddressType,\r
+ IN UINT8 *AddressBuffer OPTIONAL,\r
+ IN BOOLEAN Force\r
)\r
{\r
LIST_ENTRY *Entry;\r
// Protocol address type matched. Check the address.\r
//\r
if ((AddressBuffer == NULL) ||\r
- (CompareMem (\r
- AddressBuffer,\r
- CacheEntry->Addresses[Protocol].AddressPtr,\r
- CacheEntry->Addresses[Protocol].Length\r
- ) == 0)) {\r
+ (CompareMem (\r
+ AddressBuffer,\r
+ CacheEntry->Addresses[Protocol].AddressPtr,\r
+ CacheEntry->Addresses[Protocol].Length\r
+ ) == 0))\r
+ {\r
//\r
// Address matched.\r
//\r
}\r
} else {\r
if ((AddressBuffer == NULL) ||\r
- (CompareMem (\r
- AddressBuffer,\r
- CacheEntry->Addresses[Hardware].AddressPtr,\r
- CacheEntry->Addresses[Hardware].Length\r
- ) == 0)) {\r
+ (CompareMem (\r
+ AddressBuffer,\r
+ CacheEntry->Addresses[Hardware].AddressPtr,\r
+ CacheEntry->Addresses[Hardware].Length\r
+ ) == 0))\r
+ {\r
//\r
// Address matched.\r
//\r
return Count;\r
}\r
\r
-\r
/**\r
Delete cache entries in all the cache tables.\r
\r
);\r
\r
//\r
- // Delete the cache entries inthe ResolvedCacheTable.\r
+ // Delete the cache entries in the ResolvedCacheTable.\r
//\r
Count += ArpDeleteCacheEntryInTable (\r
&ArpService->ResolvedCacheTable,\r
return Count;\r
}\r
\r
-\r
/**\r
Cancel the arp request.\r
\r
CacheEntry = NET_LIST_USER_STRUCT (Entry, ARP_CACHE_ENTRY, List);\r
\r
if ((TargetSwAddress == NULL) ||\r
- (CompareMem (\r
- TargetSwAddress,\r
- CacheEntry->Addresses[Protocol].AddressPtr,\r
- CacheEntry->Addresses[Protocol].Length\r
- ) == 0)) {\r
+ (CompareMem (\r
+ TargetSwAddress,\r
+ CacheEntry->Addresses[Protocol].AddressPtr,\r
+ CacheEntry->Addresses[Protocol].Length\r
+ ) == 0))\r
+ {\r
//\r
// This request entry matches the TargetSwAddress or all requests are to be\r
// cancelled as TargetSwAddress is NULL.\r
return Count;\r
}\r
\r
-\r
/**\r
Find the cache entry in the cache table.\r
\r
ArpService = Instance->ArpService;\r
\r
//\r
- // Init the FounEntries used to hold the found cache entries.\r
+ // Init the FoundEntries used to hold the found cache entries.\r
//\r
NetMapInit (&FoundEntries);\r
\r
\r
Status = EFI_SUCCESS;\r
\r
- FoundCount = (UINT32) NetMapGetCount (&FoundEntries);\r
+ FoundCount = (UINT32)NetMapGetCount (&FoundEntries);\r
if (FoundCount == 0) {\r
Status = EFI_NOT_FOUND;\r
goto CLEAN_EXIT;\r
// Found the entry length, make sure its 8 bytes alignment.\r
//\r
FoundEntryLength = (((sizeof (EFI_ARP_FIND_DATA) + Instance->ConfigData.SwAddressLength +\r
- ArpService->SnpMode.HwAddressSize) + 3) & ~(0x3));\r
+ ArpService->SnpMode.HwAddressSize) + 3) & ~(0x3));\r
\r
if (EntryLength != NULL) {\r
*EntryLength = FoundEntryLength;\r
//\r
FindData = AllocatePool (FoundCount * FoundEntryLength);\r
if (FindData == NULL) {\r
- DEBUG ((EFI_D_ERROR, "ArpFindCacheEntry: Failed to allocate memory.\n"));\r
+ DEBUG ((DEBUG_ERROR, "ArpFindCacheEntry: Failed to allocate memory.\n"));\r
Status = EFI_OUT_OF_RESOURCES;\r
goto CLEAN_EXIT;\r
}\r
\r
return Status;\r
}\r
-\r