\r
**/\r
\r
-\r
#include "Udp4Impl.h"\r
\r
UINT16 mUdp4RandomPort;\r
VOID\r
EFIAPI\r
Udp4DgramSent (\r
- IN EFI_STATUS Status,\r
- IN VOID *Context,\r
- IN IP_IO_IP_PROTOCOL Sender,\r
- IN VOID *NotifyData\r
+ IN EFI_STATUS Status,\r
+ IN VOID *Context,\r
+ IN IP_IO_IP_PROTOCOL Sender,\r
+ IN VOID *NotifyData\r
);\r
\r
/**\r
IN VOID *Udp4Header\r
);\r
\r
-\r
/**\r
Create the Udp service context data.\r
\r
IN EFI_HANDLE ControllerHandle\r
)\r
{\r
- EFI_STATUS Status;\r
- IP_IO_OPEN_DATA OpenData;\r
- EFI_IP4_CONFIG_DATA *Ip4ConfigData;\r
+ EFI_STATUS Status;\r
+ IP_IO_OPEN_DATA OpenData;\r
+ EFI_IP4_CONFIG_DATA *Ip4ConfigData;\r
\r
ZeroMem (Udp4Service, sizeof (UDP4_SERVICE_DATA));\r
\r
Ip4ConfigData = &OpenData.IpConfigData.Ip4CfgData;\r
CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
Ip4ConfigData->AcceptBroadcast = TRUE;\r
- OpenData.RcvdContext = (VOID *) Udp4Service;\r
+ OpenData.RcvdContext = (VOID *)Udp4Service;\r
OpenData.SndContext = NULL;\r
OpenData.PktRcvdNotify = Udp4DgramRcvd;\r
OpenData.PktSentNotify = Udp4DgramSent;\r
return Status;\r
}\r
\r
-\r
/**\r
Clean the Udp service context data.\r
\r
IpIoDestroy (Udp4Service->IpIo);\r
}\r
\r
-\r
/**\r
This function checks and timeouts the I/O datagrams holding by the corresponding\r
service context.\r
LIST_ENTRY *NextEntry;\r
UDP4_RXDATA_WRAP *Wrap;\r
\r
- Udp4Service = (UDP4_SERVICE_DATA *) Context;\r
+ Udp4Service = (UDP4_SERVICE_DATA *)Context;\r
NET_CHECK_SIGNATURE (Udp4Service, UDP4_SERVICE_DATA_SIGNATURE);\r
\r
NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
//\r
// Remove this RxData if it timeouts.\r
//\r
- Udp4RecycleRxDataWrap (NULL, (VOID *) Wrap);\r
+ Udp4RecycleRxDataWrap (NULL, (VOID *)Wrap);\r
} else {\r
Wrap->TimeoutTick -= (UDP4_TIMEOUT_INTERVAL / 10);\r
}\r
}\r
}\r
\r
-\r
/**\r
This function initializes the new created udp instance.\r
\r
Instance->InDestroy = FALSE;\r
}\r
\r
-\r
/**\r
This function cleans the udp instance.\r
\r
NetMapClean (&Instance->TxTokens);\r
}\r
\r
-\r
/**\r
This function finds the udp instance by the specified <Address, Port> pair.\r
\r
}\r
\r
if (EFI_IP4_EQUAL (&ConfigData->StationAddress, Address) &&\r
- (ConfigData->StationPort == Port)) {\r
+ (ConfigData->StationPort == Port))\r
+ {\r
//\r
// if both the address and the port are the same, return TRUE.\r
//\r
return FALSE;\r
}\r
\r
-\r
/**\r
This function tries to bind the udp instance according to the configured port\r
allocation strategy.\r
StationAddress = &ConfigData->StationAddress;\r
\r
if (ConfigData->StationPort != 0) {\r
-\r
if (!ConfigData->AllowDuplicatePort &&\r
- Udp4FindInstanceByPort (InstanceList, StationAddress, ConfigData->StationPort)) {\r
+ Udp4FindInstanceByPort (InstanceList, StationAddress, ConfigData->StationPort))\r
+ {\r
//\r
// Do not allow duplicate port and the port is already used by other instance.\r
//\r
//\r
ConfigData->StationPort = mUdp4RandomPort;\r
} else {\r
-\r
StartPort = mUdp4RandomPort;\r
\r
- while (Udp4FindInstanceByPort(InstanceList, StationAddress, mUdp4RandomPort)) {\r
-\r
+ while (Udp4FindInstanceByPort (InstanceList, StationAddress, mUdp4RandomPort)) {\r
mUdp4RandomPort++;\r
if (mUdp4RandomPort == 0) {\r
mUdp4RandomPort = UDP4_PORT_KNOWN;\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
This function is used to check whether the NewConfigData has any un-reconfigurable\r
parameters changed compared to the OldConfigData.\r
(NewConfigData->AcceptBroadcast != OldConfigData->AcceptBroadcast) ||\r
(NewConfigData->AcceptPromiscuous != OldConfigData->AcceptPromiscuous) ||\r
(NewConfigData->AllowDuplicatePort != OldConfigData->AllowDuplicatePort)\r
- ) {\r
+ )\r
+ {\r
//\r
// The receiving filter parameters cannot be changed.\r
//\r
\r
if ((!NewConfigData->AcceptAnyPort) &&\r
(NewConfigData->StationPort != OldConfigData->StationPort)\r
- ) {\r
+ )\r
+ {\r
//\r
// The port is not changeable.\r
//\r
}\r
\r
if (!NewConfigData->AcceptPromiscuous) {\r
-\r
if (NewConfigData->UseDefaultAddress != OldConfigData->UseDefaultAddress) {\r
//\r
// The NewConfigData differs to the old one on the UseDefaultAddress.\r
if (!NewConfigData->UseDefaultAddress &&\r
(!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) ||\r
!EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask))\r
- ) {\r
+ )\r
+ {\r
//\r
// If the instance doesn't use the default address, and the new address or\r
// new subnet mask is different from the old values.\r
}\r
\r
if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) &&\r
- NewConfigData->RemotePort != OldConfigData->RemotePort\r
- ) {\r
+ (NewConfigData->RemotePort != OldConfigData->RemotePort)\r
+ )\r
+ {\r
//\r
// The RemotePort differs if it's designated in the configdata.\r
//\r
return TRUE;\r
}\r
\r
-\r
/**\r
This function builds the Ip4 configdata from the Udp4ConfigData.\r
\r
//\r
// use the -1 magic number to disable the receiving process of the ip instance.\r
//\r
- Ip4ConfigData->ReceiveTimeout = (UINT32) (-1);\r
+ Ip4ConfigData->ReceiveTimeout = (UINT32)(-1);\r
}\r
\r
-\r
/**\r
This function validates the TxToken, it returns the error code according to the spec.\r
\r
\r
TotalLen = 0;\r
for (Index = 0; Index < TxData->FragmentCount; Index++) {\r
-\r
if ((TxData->FragmentTable[Index].FragmentBuffer == NULL) ||\r
- (TxData->FragmentTable[Index].FragmentLength == 0)) {\r
+ (TxData->FragmentTable[Index].FragmentLength == 0))\r
+ {\r
//\r
// if the FragmentBuffer is NULL or the FragmentLeng is zero.\r
//\r
CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR));\r
\r
if (!Instance->ConfigData.UseDefaultAddress &&\r
- (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
- !NetIp4IsUnicast (NTOHL (GatewayAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\r
+ (EFI_NTOHL (Instance->ConfigData.SubnetMask) != 0) &&\r
+ !NetIp4IsUnicast (NTOHL (GatewayAddress), EFI_NTOHL (Instance->ConfigData.SubnetMask)))\r
+ {\r
//\r
// The specified GatewayAddress is not a unicast IPv4 address while it's not 0.\r
//\r
UdpSessionData = TxData->UdpSessionData;\r
\r
if (UdpSessionData != NULL) {\r
-\r
CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR));\r
\r
if ((SourceAddress != 0) &&\r
!Instance->ConfigData.UseDefaultAddress &&\r
- (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
- !NetIp4IsUnicast (HTONL (SourceAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\r
+ (EFI_NTOHL (Instance->ConfigData.SubnetMask) != 0) &&\r
+ !NetIp4IsUnicast (HTONL (SourceAddress), EFI_NTOHL (Instance->ConfigData.SubnetMask)))\r
+ {\r
//\r
// Check whether SourceAddress is a valid IPv4 address in case it's not zero.\r
// The configured station address is used if SourceAddress is zero.\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
This function checks whether the specified Token duplicates with the one in the Map.\r
\r
EFI_UDP4_COMPLETION_TOKEN *Token;\r
EFI_UDP4_COMPLETION_TOKEN *TokenInItem;\r
\r
- Token = (EFI_UDP4_COMPLETION_TOKEN*) Context;\r
- TokenInItem = (EFI_UDP4_COMPLETION_TOKEN*) Item->Key;\r
+ Token = (EFI_UDP4_COMPLETION_TOKEN *)Context;\r
+ TokenInItem = (EFI_UDP4_COMPLETION_TOKEN *)Item->Key;\r
\r
if ((Token == TokenInItem) || (Token->Event == TokenInItem->Event)) {\r
//\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
This function calculates the checksum for the Packet, utilizing the pre-calculated\r
pseudo HeadSum to reduce some overhead.\r
**/\r
UINT16\r
Udp4Checksum (\r
- IN NET_BUF *Packet,\r
- IN UINT16 HeadSum\r
+ IN NET_BUF *Packet,\r
+ IN UINT16 HeadSum\r
)\r
{\r
UINT16 Checksum;\r
\r
- Checksum = NetbufChecksum (Packet);\r
- Checksum = NetAddChecksum (Checksum, HeadSum);\r
+ Checksum = NetbufChecksum (Packet);\r
+ Checksum = NetAddChecksum (Checksum, HeadSum);\r
\r
- Checksum = NetAddChecksum (Checksum, HTONS ((UINT16) Packet->TotalSize));\r
+ Checksum = NetAddChecksum (Checksum, HTONS ((UINT16)Packet->TotalSize));\r
\r
return (UINT16) ~Checksum;\r
}\r
\r
-\r
/**\r
This function removes the specified Token from the TokenMap.\r
\r
//\r
// Find the Token first.\r
//\r
- Item = NetMapFindKey (TokenMap, (VOID *) Token);\r
+ Item = NetMapFindKey (TokenMap, (VOID *)Token);\r
\r
if (Item != NULL) {\r
//\r
return EFI_NOT_FOUND;\r
}\r
\r
-\r
/**\r
This function is the packet transmitting notify function registered to the IpIo\r
interface. It's called to signal the udp TxToken when IpIo layer completes the\r
VOID\r
EFIAPI\r
Udp4DgramSent (\r
- IN EFI_STATUS Status,\r
- IN VOID *Context,\r
- IN IP_IO_IP_PROTOCOL Sender,\r
- IN VOID *NotifyData\r
+ IN EFI_STATUS Status,\r
+ IN VOID *Context,\r
+ IN IP_IO_IP_PROTOCOL Sender,\r
+ IN VOID *NotifyData\r
)\r
{\r
UDP4_INSTANCE_DATA *Instance;\r
EFI_UDP4_COMPLETION_TOKEN *Token;\r
\r
- Instance = (UDP4_INSTANCE_DATA *) Context;\r
- Token = (EFI_UDP4_COMPLETION_TOKEN *) NotifyData;\r
+ Instance = (UDP4_INSTANCE_DATA *)Context;\r
+ Token = (EFI_UDP4_COMPLETION_TOKEN *)NotifyData;\r
\r
if (Udp4RemoveToken (&Instance->TxTokens, Token) == EFI_SUCCESS) {\r
//\r
}\r
}\r
\r
-\r
/**\r
This function processes the received datagram passed up by the IpIo layer.\r
\r
//\r
// Demultiplex the received datagram.\r
//\r
- Udp4Demultiplex ((UDP4_SERVICE_DATA *) Context, NetSession, Packet);\r
+ Udp4Demultiplex ((UDP4_SERVICE_DATA *)Context, NetSession, Packet);\r
} else {\r
//\r
// Handle the ICMP_ERROR packet.\r
//\r
- Udp4IcmpHandler ((UDP4_SERVICE_DATA *) Context, IcmpError, NetSession, Packet);\r
+ Udp4IcmpHandler ((UDP4_SERVICE_DATA *)Context, IcmpError, NetSession, Packet);\r
}\r
\r
//\r
DispatchDpc ();\r
}\r
\r
-\r
/**\r
This function removes the multicast group specified by Arg from the Map.\r
\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
This function cancels the token specified by Arg in the Map. This is a callback\r
used by Udp4InstanceCancelToken().\r
// will invoke Udp4DgramSent, the token will be signaled and this Item will\r
// be removed from the Map there.\r
//\r
- Packet = (NET_BUF *) (Item->Value);\r
- IpIo = (IP_IO *) (*((UINTN *) &Packet->ProtoData[0]));\r
+ Packet = (NET_BUF *)(Item->Value);\r
+ IpIo = (IP_IO *)(*((UINTN *)&Packet->ProtoData[0]));\r
\r
IpIoCancelTxToken (IpIo, Packet);\r
} else {\r
//\r
// The token is a receive token. Abort it and remove it from the Map.\r
//\r
- TokenToCancel = (EFI_UDP4_COMPLETION_TOKEN *) Item->Key;\r
+ TokenToCancel = (EFI_UDP4_COMPLETION_TOKEN *)Item->Key;\r
NetMapRemoveItem (Map, Item, NULL);\r
\r
TokenToCancel->Status = EFI_ABORTED;\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
This function removes all the Wrap datas in the RcvdDgramQue.\r
\r
//\r
// The Wrap will be removed from the RcvdDgramQue by this function call.\r
//\r
- Udp4RecycleRxDataWrap (NULL, (VOID *) Wrap);\r
+ Udp4RecycleRxDataWrap (NULL, (VOID *)Wrap);\r
}\r
}\r
\r
-\r
-\r
/**\r
Cancel Udp4 tokens from the Udp4 instance.\r
\r
return EFI_NOT_FOUND;\r
}\r
\r
- ASSERT ((Token != NULL) || ((0 == NetMapGetCount (&Instance->TxTokens))\r
- && (0 == NetMapGetCount (&Instance->RxTokens))));\r
+ ASSERT (\r
+ (Token != NULL) || ( (0 == NetMapGetCount (&Instance->TxTokens))\r
+ && (0 == NetMapGetCount (&Instance->RxTokens)))\r
+ );\r
\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
This function matches the received udp datagram with the Instance.\r
\r
\r
if ((!ConfigData->AcceptAnyPort && (Udp4Session->DestinationPort != ConfigData->StationPort)) ||\r
((ConfigData->RemotePort != 0) && (Udp4Session->SourcePort != ConfigData->RemotePort))\r
- ) {\r
+ )\r
+ {\r
//\r
// The local port or the remote port doesn't match.\r
//\r
\r
if (!EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr) &&\r
!EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress)\r
- ) {\r
+ )\r
+ {\r
//\r
// This datagram doesn't come from the instance's specified sender.\r
//\r
\r
if (EFI_IP4_EQUAL (&ConfigData->StationAddress, &mZeroIp4Addr) ||\r
EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress)\r
- ) {\r
+ )\r
+ {\r
//\r
// The instance is configured to receive datagrams destined to any station IP or\r
// the destination address of this datagram matches the configured station IP.\r
}\r
\r
if (IP4_IS_MULTICAST (NTOHL (Destination)) &&\r
- NetMapFindKey (&Instance->McastIps, (VOID *) (UINTN) Destination) != NULL\r
- ) {\r
+ (NetMapFindKey (&Instance->McastIps, (VOID *)(UINTN)Destination) != NULL)\r
+ )\r
+ {\r
//\r
// It's a multicast packet and the multicast address is accepted by this instance.\r
//\r
return FALSE;\r
}\r
\r
-\r
/**\r
This function removes the Wrap specified by Context and release relevant resources.\r
\r
{\r
UDP4_RXDATA_WRAP *Wrap;\r
\r
- Wrap = (UDP4_RXDATA_WRAP *) Context;\r
+ Wrap = (UDP4_RXDATA_WRAP *)Context;\r
\r
//\r
// Remove the Wrap from the list it belongs to.\r
FreePool (Wrap);\r
}\r
\r
-\r
/**\r
This function wraps the Packet and the RxData.\r
\r
IN EFI_UDP4_RECEIVE_DATA *RxData\r
)\r
{\r
- EFI_STATUS Status;\r
- UDP4_RXDATA_WRAP *Wrap;\r
+ EFI_STATUS Status;\r
+ UDP4_RXDATA_WRAP *Wrap;\r
\r
//\r
// Allocate buffer for the Wrap.\r
//\r
- Wrap = AllocatePool (sizeof (UDP4_RXDATA_WRAP) +\r
- (Packet->BlockOpNum - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r
+ Wrap = AllocatePool (\r
+ sizeof (UDP4_RXDATA_WRAP) +\r
+ (Packet->BlockOpNum - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA)\r
+ );\r
if (Wrap == NULL) {\r
return NULL;\r
}\r
return Wrap;\r
}\r
\r
-\r
/**\r
This function enqueues the received datagram into the instances' receiving queues.\r
\r
return Enqueued;\r
}\r
\r
-\r
/**\r
This function delivers the received datagrams for the specified instance.\r
\r
EFI_TPL OldTpl;\r
\r
if (!IsListEmpty (&Instance->RcvdDgramQue) &&\r
- !NetMapIsEmpty (&Instance->RxTokens)) {\r
-\r
+ !NetMapIsEmpty (&Instance->RxTokens))\r
+ {\r
Wrap = NET_LIST_HEAD (&Instance->RcvdDgramQue, UDP4_RXDATA_WRAP, Link);\r
\r
if (NET_BUF_SHARED (Wrap->Packet)) {\r
\r
NetListRemoveHead (&Instance->RcvdDgramQue);\r
\r
- Token = (EFI_UDP4_COMPLETION_TOKEN *) NetMapRemoveHead (&Instance->RxTokens, NULL);\r
+ Token = (EFI_UDP4_COMPLETION_TOKEN *)NetMapRemoveHead (&Instance->RxTokens, NULL);\r
\r
//\r
// Build the FragmentTable and set the FragmentCount in RxData.\r
\r
NetbufBuildExt (\r
Wrap->Packet,\r
- (NET_FRAGMENT *) RxData->FragmentTable,\r
+ (NET_FRAGMENT *)RxData->FragmentTable,\r
&RxData->FragmentCount\r
);\r
\r
}\r
}\r
\r
-\r
/**\r
This function delivers the datagrams enqueued in the instances.\r
\r
}\r
}\r
\r
-\r
/**\r
This function demultiplexes the received udp datagram to the appropriate instances.\r
\r
IN NET_BUF *Packet\r
)\r
{\r
- EFI_UDP_HEADER *Udp4Header;\r
+ EFI_UDP_HEADER *Udp4Header;\r
UINT16 HeadSum;\r
EFI_UDP4_RECEIVE_DATA RxData;\r
EFI_UDP4_SESSION_DATA *Udp4Session;\r
//\r
// Get the datagram header from the packet buffer.\r
//\r
- Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+ Udp4Header = (EFI_UDP_HEADER *)NetbufGetByte (Packet, 0, NULL);\r
ASSERT (Udp4Header != NULL);\r
\r
if (Udp4Header->Checksum != 0) {\r
//\r
NetbufTrim (Packet, UDP4_HEADER_SIZE, TRUE);\r
\r
- RxData.DataLength = (UINT32) Packet->TotalSize;\r
+ RxData.DataLength = (UINT32)Packet->TotalSize;\r
\r
//\r
// Try to enqueue this datagram into the instances.\r
}\r
}\r
\r
-\r
/**\r
This function builds and sends out a icmp port unreachable message.\r
\r
// Calculate the required length of the icmp error message.\r
//\r
Len = sizeof (IP4_ICMP_ERROR_HEAD) + (EFI_IP4_HEADER_LEN (IpHdr) -\r
- sizeof (IP4_HEAD)) + ICMP_ERROR_PACKET_LENGTH;\r
+ sizeof (IP4_HEAD)) + ICMP_ERROR_PACKET_LENGTH;\r
\r
//\r
// Allocate buffer for the icmp error message.\r
//\r
// Allocate space for the IP4_ICMP_ERROR_HEAD.\r
//\r
- IcmpErrHdr = (IP4_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE);\r
+ IcmpErrHdr = (IP4_ICMP_ERROR_HEAD *)NetbufAllocSpace (Packet, Len, FALSE);\r
ASSERT (IcmpErrHdr != NULL);\r
\r
//\r
//\r
// Copy the UDP header.\r
//\r
- Ptr = (UINT8 *) &IcmpErrHdr->IpHead + EFI_IP4_HEADER_LEN (IpHdr);\r
+ Ptr = (UINT8 *)&IcmpErrHdr->IpHead + EFI_IP4_HEADER_LEN (IpHdr);\r
CopyMem (Ptr, Udp4Header, ICMP_ERROR_PACKET_LENGTH);\r
\r
//\r
NetbufFree (Packet);\r
}\r
\r
-\r
/**\r
This function handles the received Icmp Error message and demultiplexes it to the\r
instance.\r
IN NET_BUF *Packet\r
)\r
{\r
- EFI_UDP_HEADER *Udp4Header;\r
+ EFI_UDP_HEADER *Udp4Header;\r
EFI_UDP4_SESSION_DATA Udp4Session;\r
LIST_ENTRY *Entry;\r
UDP4_INSTANCE_DATA *Instance;\r
return;\r
}\r
\r
- Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+ Udp4Header = (EFI_UDP_HEADER *)NetbufGetByte (Packet, 0, NULL);\r
ASSERT (Udp4Header != NULL);\r
\r
CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
NetbufFree (Packet);\r
}\r
\r
-\r
/**\r
This function reports the received ICMP error.\r
\r
//\r
// Try to get a RxToken from the RxTokens map.\r
//\r
- Token = (EFI_UDP4_COMPLETION_TOKEN *) NetMapRemoveHead (&Instance->RxTokens, NULL);\r
+ Token = (EFI_UDP4_COMPLETION_TOKEN *)NetMapRemoveHead (&Instance->RxTokens, NULL);\r
\r
if (Token != NULL) {\r
//\r
}\r
}\r
\r
-\r
/**\r
This function is a dummy ext-free function for the NET_BUF created for the output\r
udp datagram.\r
)\r
{\r
}\r
-\r