X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FUdp4Dxe%2FUdp4Impl.c;h=ce952b1e2d19b148d41b88a607e682d79768b07e;hp=5cf87c7921d6e32015c009199608ea75a1528fb6;hb=d551cc64cdf1f943744294819220b78a60b10822;hpb=84b5c78e89686879f799a4cd095eeef83ff7cf34 diff --git a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c index 5cf87c7921..ce952b1e2d 100644 --- a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c +++ b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c @@ -1,7 +1,8 @@ /** @file - -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials + The implementation of the Udp4 protocol. + +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -9,15 +10,6 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Udp4Impl.c - -Abstract: - - The implementation of the Udp4 protocol. - - **/ @@ -25,7 +17,15 @@ Abstract: UINT16 mUdp4RandomPort; -STATIC +/** + This function checks and timeouts the I/O datagrams holding by the corresponding + service context. + + @param[in] Event The event this function registered to. + @param[in] Context The context data registered during the creation of + the Event. + +**/ VOID EFIAPI Udp4CheckTimeout ( @@ -33,49 +33,116 @@ Udp4CheckTimeout ( IN VOID *Context ); -STATIC +/** + This function finds the udp instance by the specified pair. + + @param[in] InstanceList Pointer to the head of the list linking the udp + instances. + @param[in] Address Pointer to the specified IPv4 address. + @param[in] Port The udp port number. + + @retval TRUE The specified pair is found. + @retval FALSE Otherwise. + +**/ BOOLEAN Udp4FindInstanceByPort ( - IN NET_LIST_ENTRY *InstanceList, + IN LIST_ENTRY *InstanceList, IN EFI_IPv4_ADDRESS *Address, IN UINT16 Port ); -STATIC +/** + This function is the packet transmitting notify function registered to the IpIo + interface. It's called to signal the udp TxToken when IpIo layer completes the + transmitting of the udp datagram. + + @param[in] Status The completion status of the output udp datagram. + @param[in] Context Pointer to the context data. + @param[in] Sender Specify a pointer of EFI_IP4_PROTOCOL for sending. + @param[in] NotifyData Pointer to the notify data. + +**/ VOID +EFIAPI Udp4DgramSent ( - IN EFI_STATUS Status, - IN VOID *Context, - IN VOID *Sender, - IN VOID *NotifyData + IN EFI_STATUS Status, + IN VOID *Context, + IN IP_IO_IP_PROTOCOL Sender, + IN VOID *NotifyData ); -STATIC +/** + This function processes the received datagram passed up by the IpIo layer. + + @param[in] Status The status of this udp datagram. + @param[in] IcmpError The IcmpError code, only available when Status is + EFI_ICMP_ERROR. + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA. + @param[in] Packet Pointer to the NET_BUF containing the received udp + datagram. + @param[in] Context Pointer to the context data. + +**/ VOID +EFIAPI Udp4DgramRcvd ( IN EFI_STATUS Status, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet, IN VOID *Context ); -STATIC +/** + This function cancels the token specified by Arg in the Map. This is a callback + used by Udp4InstanceCancelToken(). + + @param[in] Map Pointer to the NET_MAP. + @param[in] Item Pointer to the NET_MAP_ITEM. + @param[in] Arg Pointer to the token to be cancelled, if NULL, + the token specified by Item is cancelled. + + @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token + is not the same as that in the Item if Arg is not + NULL. + @retval EFI_ABORTED Arg is not NULL, and the token specified by Arg is + cancelled. + +**/ EFI_STATUS +EFIAPI Udp4CancelTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Arg OPTIONAL ); -STATIC +/** + This function matches the received udp datagram with the Instance. + + @param[in] Instance Pointer to the udp instance context data. + @param[in] Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted + from the received udp datagram. + + @retval TRUE The udp datagram matches the receiving requirments of the + udp Instance. + @retval FALSE Otherwise. + +**/ BOOLEAN Udp4MatchDgram ( IN UDP4_INSTANCE_DATA *Instance, IN EFI_UDP4_SESSION_DATA *Udp4Session ); -STATIC +/** + This function removes the Wrap specified by Context and release relevant resources. + + @param[in] Event The Event this notify function registered to. + @param[in] Context Pointer to the context data. + +**/ VOID EFIAPI Udp4RecycleRxDataWrap ( @@ -83,7 +150,18 @@ Udp4RecycleRxDataWrap ( IN VOID *Context ); -STATIC +/** + This function wraps the Packet and the RxData. + + @param[in] Instance Pointer to the instance context data. + @param[in] Packet Pointer to the buffer containing the received + datagram. + @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this + datagram. + + @return Pointer to the structure wrapping the RxData and the Packet. + +**/ UDP4_RXDATA_WRAP * Udp4WrapRxData ( IN UDP4_INSTANCE_DATA *Instance, @@ -91,7 +169,18 @@ Udp4WrapRxData ( IN EFI_UDP4_RECEIVE_DATA *RxData ); -STATIC +/** + This function enqueues the received datagram into the instances' receiving queues. + + @param[in] Udp4Service Pointer to the udp service context data. + @param[in] Packet Pointer to the buffer containing the received + datagram. + @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this + datagram. + + @return The times this datagram is enqueued. + +**/ UINTN Udp4EnqueueDgram ( IN UDP4_SERVICE_DATA *Udp4Service, @@ -99,13 +188,27 @@ Udp4EnqueueDgram ( IN EFI_UDP4_RECEIVE_DATA *RxData ); -STATIC +/** + This function delivers the datagrams enqueued in the instances. + + @param[in] Udp4Service Pointer to the udp service context data. + +**/ VOID Udp4DeliverDgram ( IN UDP4_SERVICE_DATA *Udp4Service ); -STATIC +/** + This function demultiplexes the received udp datagram to the apropriate instances. + + @param[in] Udp4Service Pointer to the udp service context data. + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from + the received datagram. + @param[in] Packet Pointer to the buffer containing the received udp + datagram. + +**/ VOID Udp4Demultiplex ( IN UDP4_SERVICE_DATA *Udp4Service, @@ -113,16 +216,35 @@ Udp4Demultiplex ( IN NET_BUF *Packet ); -STATIC +/** + This function handles the received Icmp Error message and demultiplexes it to the + instance. + + @param[in] Udp4Service Pointer to the udp service context data. + @param[in] IcmpError The icmp error code. + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted + from the received Icmp Error packet. + @param[in] Packet Pointer to the Icmp Error packet. + +**/ VOID Udp4IcmpHandler ( IN UDP4_SERVICE_DATA *Udp4Service, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet ); -STATIC +/** + This function builds and sends out a icmp port unreachable message. + + @param[in] IpIo Pointer to the IP_IO instance. + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet + causes this icmp error message. + @param[in] Udp4Header Pointer to the udp header of the datagram causes + this icmp error message. + +**/ VOID Udp4SendPortUnreach ( IN IP_IO *IpIo, @@ -134,24 +256,28 @@ Udp4SendPortUnreach ( /** Create the Udp service context data. - @param Udp4Service Pointer to the UDP4_SERVICE_DATA. - @param ImageHandle The image handle of this udp4 driver. - @param ControllerHandle The controller handle this udp4 driver binds on. + @param[in, out] Udp4Service Pointer to the UDP4_SERVICE_DATA. + @param[in] ImageHandle The image handle of this udp4 driver. + @param[in] ControllerHandle The controller handle this udp4 driver binds on. - @retval EFI_SUCCESS The udp4 service context data is created and - initialized. - @retval EFI_OUT_OF_RESOURCES Cannot allocate memory. + @retval EFI_SUCCESS The udp4 service context data is created and + initialized. + @retval EFI_OUT_OF_RESOURCES Cannot allocate memory. + @retval other Other error occurs. **/ EFI_STATUS Udp4CreateService ( - IN UDP4_SERVICE_DATA *Udp4Service, - IN EFI_HANDLE ImageHandle, - IN EFI_HANDLE ControllerHandle + IN OUT UDP4_SERVICE_DATA *Udp4Service, + IN EFI_HANDLE ImageHandle, + IN EFI_HANDLE ControllerHandle ) { - EFI_STATUS Status; - IP_IO_OPEN_DATA OpenData; + EFI_STATUS Status; + IP_IO_OPEN_DATA OpenData; + EFI_IP4_CONFIG_DATA *Ip4ConfigData; + + ZeroMem (Udp4Service, sizeof (UDP4_SERVICE_DATA)); Udp4Service->Signature = UDP4_SERVICE_DATA_SIGNATURE; Udp4Service->ServiceBinding = mUdp4ServiceBinding; @@ -159,12 +285,12 @@ Udp4CreateService ( Udp4Service->ControllerHandle = ControllerHandle; Udp4Service->ChildrenNumber = 0; - NetListInit (&Udp4Service->ChildrenList); + InitializeListHead (&Udp4Service->ChildrenList); // // Create the IpIo for this service context. // - Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle); + Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle, IP_VERSION_4); if (Udp4Service->IpIo == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -172,19 +298,20 @@ Udp4CreateService ( // // Set the OpenData used to open the IpIo. // - CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (OpenData.IpConfigData)); - OpenData.IpConfigData.AcceptBroadcast = TRUE; - OpenData.RcvdContext = (VOID *) Udp4Service; - OpenData.SndContext = NULL; - OpenData.PktRcvdNotify = Udp4DgramRcvd; - OpenData.PktSentNotify = Udp4DgramSent; + Ip4ConfigData = &OpenData.IpConfigData.Ip4CfgData; + CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA)); + Ip4ConfigData->AcceptBroadcast = TRUE; + OpenData.RcvdContext = (VOID *) Udp4Service; + OpenData.SndContext = NULL; + OpenData.PktRcvdNotify = Udp4DgramRcvd; + OpenData.PktSentNotify = Udp4DgramSent; // // Configure and start the IpIo. // Status = IpIoOpen (Udp4Service->IpIo, &OpenData); if (EFI_ERROR (Status)) { - goto RELEASE_IPIO; + goto ON_ERROR; } // @@ -192,13 +319,13 @@ Udp4CreateService ( // Status = gBS->CreateEvent ( EVT_TIMER | EVT_NOTIFY_SIGNAL, - NET_TPL_FAST_TIMER, + TPL_CALLBACK, Udp4CheckTimeout, Udp4Service, &Udp4Service->TimeoutEvent ); if (EFI_ERROR (Status)) { - goto RELEASE_IPIO; + goto ON_ERROR; } // @@ -210,18 +337,16 @@ Udp4CreateService ( UDP4_TIMEOUT_INTERVAL ); if (EFI_ERROR (Status)) { - goto RELEASE_ALL; + goto ON_ERROR; } - Udp4Service->MacString = NULL; - return EFI_SUCCESS; -RELEASE_ALL: - - gBS->CloseEvent (Udp4Service->TimeoutEvent); +ON_ERROR: -RELEASE_IPIO: + if (Udp4Service->TimeoutEvent != NULL) { + gBS->CloseEvent (Udp4Service->TimeoutEvent); + } IpIoDestroy (Udp4Service->IpIo); @@ -232,9 +357,7 @@ RELEASE_IPIO: /** Clean the Udp service context data. - @param Udp4Service Pointer to the UDP4_SERVICE_DATA. - - @return None. + @param[in] Udp4Service Pointer to the UDP4_SERVICE_DATA. **/ VOID @@ -263,14 +386,11 @@ Udp4CleanService ( This function checks and timeouts the I/O datagrams holding by the corresponding service context. - @param Event The event this function registered to. - @param Conext The context data registered during the creation of - the Event. - - @return None. + @param[in] Event The event this function registered to. + @param[in] Context The context data registered during the creation of + the Event. **/ -STATIC VOID EFIAPI Udp4CheckTimeout ( @@ -279,10 +399,10 @@ Udp4CheckTimeout ( ) { UDP4_SERVICE_DATA *Udp4Service; - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; UDP4_INSTANCE_DATA *Instance; - NET_LIST_ENTRY *WrapEntry; - NET_LIST_ENTRY *NextEntry; + LIST_ENTRY *WrapEntry; + LIST_ENTRY *NextEntry; UDP4_RXDATA_WRAP *Wrap; Udp4Service = (UDP4_SERVICE_DATA *) Context; @@ -306,15 +426,18 @@ Udp4CheckTimeout ( // // Iterate all the rxdatas belonging to this udp instance. // - Wrap = NET_LIST_USER_STRUCT (Entry, UDP4_RXDATA_WRAP, Link); + Wrap = NET_LIST_USER_STRUCT (WrapEntry, UDP4_RXDATA_WRAP, Link); - if (Wrap->TimeoutTick <= UDP4_TIMEOUT_INTERVAL / 1000) { + // + // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns. + // + if (Wrap->TimeoutTick < (UDP4_TIMEOUT_INTERVAL / 10)) { // // Remove this RxData if it timeouts. // Udp4RecycleRxDataWrap (NULL, (VOID *) Wrap); } else { - Wrap->TimeoutTick -= UDP4_TIMEOUT_INTERVAL / 1000; + Wrap->TimeoutTick -= (UDP4_TIMEOUT_INTERVAL / 10); } } } @@ -324,16 +447,14 @@ Udp4CheckTimeout ( /** This function intializes the new created udp instance. - @param Udp4Service Pointer to the UDP4_SERVICE_DATA. - @param Instance Pointer to the un-initialized UDP4_INSTANCE_DATA. - - @return None. + @param[in] Udp4Service Pointer to the UDP4_SERVICE_DATA. + @param[in, out] Instance Pointer to the un-initialized UDP4_INSTANCE_DATA. **/ VOID Udp4InitInstance ( - IN UDP4_SERVICE_DATA *Udp4Service, - IN UDP4_INSTANCE_DATA *Instance + IN UDP4_SERVICE_DATA *Udp4Service, + IN OUT UDP4_INSTANCE_DATA *Instance ) { // @@ -344,9 +465,9 @@ Udp4InitInstance ( // // Init the lists. // - NetListInit (&Instance->Link); - NetListInit (&Instance->RcvdDgramQue); - NetListInit (&Instance->DeliveredDgramQue); + InitializeListHead (&Instance->Link); + InitializeListHead (&Instance->RcvdDgramQue); + InitializeListHead (&Instance->DeliveredDgramQue); // // Init the NET_MAPs. @@ -363,16 +484,14 @@ Udp4InitInstance ( Instance->IcmpError = EFI_SUCCESS; Instance->Configured = FALSE; Instance->IsNoMapping = FALSE; - Instance->Destroyed = FALSE; + Instance->InDestroy = FALSE; } /** This function cleans the udp instance. - @param Instance Pointer to the UDP4_INSTANCE_DATA to clean. - - @return None. + @param[in] Instance Pointer to the UDP4_INSTANCE_DATA to clean. **/ VOID @@ -389,23 +508,23 @@ Udp4CleanInstance ( /** This function finds the udp instance by the specified pair. - @param InstanceList Pointer to the head of the list linking the udp - instances. - @param Address Pointer to the specified IPv4 address. - @param Port The udp port number. + @param[in] InstanceList Pointer to the head of the list linking the udp + instances. + @param[in] Address Pointer to the specified IPv4 address. + @param[in] Port The udp port number. - @return Is the specified pair found or not. + @retval TRUE The specified pair is found. + @retval FALSE Otherwise. **/ -STATIC BOOLEAN Udp4FindInstanceByPort ( - IN NET_LIST_ENTRY *InstanceList, + IN LIST_ENTRY *InstanceList, IN EFI_IPv4_ADDRESS *Address, IN UINT16 Port ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; UDP4_INSTANCE_DATA *Instance; EFI_UDP4_CONFIG_DATA *ConfigData; @@ -442,12 +561,13 @@ Udp4FindInstanceByPort ( /** This function tries to bind the udp instance according to the configured port - allocation stragety. + allocation strategy. - @param InstanceList Pointer to the head of the list linking the udp + @param[in] InstanceList Pointer to the head of the list linking the udp instances. - @param ConfigData Pointer to the ConfigData of the instance to be - bound. + @param[in, out] ConfigData Pointer to the ConfigData of the instance to be + bound. ConfigData->StationPort will be assigned + with an available port value on success. @retval EFI_SUCCESS The bound operation is completed successfully. @retval EFI_ACCESS_DENIED The specified by the ConfigData is @@ -457,8 +577,8 @@ Udp4FindInstanceByPort ( **/ EFI_STATUS Udp4Bind ( - IN NET_LIST_ENTRY *InstanceList, - IN EFI_UDP4_CONFIG_DATA *ConfigData + IN LIST_ENTRY *InstanceList, + IN OUT EFI_UDP4_CONFIG_DATA *ConfigData ) { EFI_IPv4_ADDRESS *StationAddress; @@ -525,11 +645,12 @@ Udp4Bind ( This function is used to check whether the NewConfigData has any un-reconfigurable parameters changed compared to the OldConfigData. - @param OldConfigData Pointer to the current ConfigData the udp instance + @param[in] OldConfigData Pointer to the current ConfigData the udp instance uses. - @param NewConfigData Pointer to the new ConfigData. + @param[in] NewConfigData Pointer to the new ConfigData. - @return The instance is reconfigurable or not according to the NewConfigData. + @retval TRUE The instance is reconfigurable. + @retval FALSE Otherwise. **/ BOOLEAN @@ -538,10 +659,11 @@ Udp4IsReconfigurable ( IN EFI_UDP4_CONFIG_DATA *NewConfigData ) { - if ((NewConfigData->AcceptAnyPort != OldConfigData->AcceptAnyPort) || - (NewConfigData->AcceptBroadcast != OldConfigData->AcceptBroadcast) || - (NewConfigData->AcceptPromiscuous != OldConfigData->AcceptPromiscuous) || - (NewConfigData->AllowDuplicatePort != OldConfigData->AllowDuplicatePort)) { + if ((NewConfigData->AcceptAnyPort != OldConfigData->AcceptAnyPort) || + (NewConfigData->AcceptBroadcast != OldConfigData->AcceptBroadcast) || + (NewConfigData->AcceptPromiscuous != OldConfigData->AcceptPromiscuous) || + (NewConfigData->AllowDuplicatePort != OldConfigData->AllowDuplicatePort) + ) { // // The receiving filter parameters cannot be changed. // @@ -549,7 +671,8 @@ Udp4IsReconfigurable ( } if ((!NewConfigData->AcceptAnyPort) && - (NewConfigData->StationPort != OldConfigData->StationPort)) { + (NewConfigData->StationPort != OldConfigData->StationPort) + ) { // // The port is not changeable. // @@ -566,8 +689,9 @@ Udp4IsReconfigurable ( } if (!NewConfigData->UseDefaultAddress && - (!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) || - !EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask))) { + (!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) || + !EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask)) + ) { // // If the instance doesn't use the default address, and the new address or // new subnet mask is different from the old values. @@ -583,7 +707,9 @@ Udp4IsReconfigurable ( return FALSE; } - if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) && (NewConfigData->RemotePort != OldConfigData->RemotePort)) { + if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) && + NewConfigData->RemotePort != OldConfigData->RemotePort + ) { // // The RemotePort differs if it's designated in the configdata. // @@ -600,26 +726,24 @@ Udp4IsReconfigurable ( /** This function builds the Ip4 configdata from the Udp4ConfigData. - @param Udp4ConfigData Pointer to the EFI_UDP4_CONFIG_DATA. - @param Ip4ConfigData Pointer to the EFI_IP4_CONFIG_DATA. - - @return None. + @param[in] Udp4ConfigData Pointer to the EFI_UDP4_CONFIG_DATA. + @param[in, out] Ip4ConfigData Pointer to the EFI_IP4_CONFIG_DATA. **/ VOID Udp4BuildIp4ConfigData ( - IN EFI_UDP4_CONFIG_DATA *Udp4ConfigData, - IN EFI_IP4_CONFIG_DATA *Ip4ConfigData + IN EFI_UDP4_CONFIG_DATA *Udp4ConfigData, + IN OUT EFI_IP4_CONFIG_DATA *Ip4ConfigData ) { - CopyMem (Ip4ConfigData, &mIpIoDefaultIpConfigData, sizeof (*Ip4ConfigData)); + CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (*Ip4ConfigData)); Ip4ConfigData->DefaultProtocol = EFI_IP_PROTO_UDP; Ip4ConfigData->AcceptBroadcast = Udp4ConfigData->AcceptBroadcast; Ip4ConfigData->AcceptPromiscuous = Udp4ConfigData->AcceptPromiscuous; Ip4ConfigData->UseDefaultAddress = Udp4ConfigData->UseDefaultAddress; - Ip4ConfigData->StationAddress = Udp4ConfigData->StationAddress; - Ip4ConfigData->SubnetMask = Udp4ConfigData->SubnetMask; + CopyMem (&Ip4ConfigData->StationAddress, &Udp4ConfigData->StationAddress, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Ip4ConfigData->SubnetMask, &Udp4ConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS)); // // use the -1 magic number to disable the receiving process of the ip instance. @@ -631,8 +755,8 @@ Udp4BuildIp4ConfigData ( /** This function validates the TxToken, it returns the error code according to the spec. - @param Instance Pointer to the udp instance context data. - @param TxToken Pointer to the token to be checked. + @param[in] Instance Pointer to the udp instance context data. + @param[in] TxToken Pointer to the token to be checked. @retval EFI_SUCCESS The TxToken is valid. @retval EFI_INVALID_PARAMETER One or more of the following are TRUE: This is @@ -701,9 +825,9 @@ Udp4ValidateTxToken ( } if (TxData->GatewayAddress != NULL) { - NetCopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR)); + CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR)); - if (!Ip4IsUnicast (NTOHL (GatewayAddress), 0)) { + if (!NetIp4IsUnicast (NTOHL (GatewayAddress), 0)) { // // The specified GatewayAddress is not a unicast IPv4 address while it's not 0. // @@ -716,9 +840,9 @@ Udp4ValidateTxToken ( if (UdpSessionData != NULL) { - NetCopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR)); + CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR)); - if ((SourceAddress != 0) && !Ip4IsUnicast (HTONL (SourceAddress), 0)) { + if ((SourceAddress != 0) && !NetIp4IsUnicast (HTONL (SourceAddress), 0)) { // // Check whether SourceAddress is a valid IPv4 address in case it's not zero. // The configured station address is used if SourceAddress is zero. @@ -758,10 +882,10 @@ Udp4ValidateTxToken ( /** This function checks whether the specified Token duplicates with the one in the Map. - @param Map Pointer to the NET_MAP. - @param Item Pointer to the NET_MAP_ITEM contain the pointer to + @param[in] Map Pointer to the NET_MAP. + @param[in] Item Pointer to the NET_MAP_ITEM contain the pointer to the Token. - @param Context Pointer to the Token to be checked. + @param[in] Context Pointer to the Token to be checked. @retval EFI_SUCCESS The Token specified by Context differs from the one in the Item. @@ -769,6 +893,7 @@ Udp4ValidateTxToken ( **/ EFI_STATUS +EFIAPI Udp4TokenExist ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -797,11 +922,11 @@ Udp4TokenExist ( This function calculates the checksum for the Packet, utilizing the pre-calculated pseudo HeadSum to reduce some overhead. - @param Packet Pointer to the NET_BUF contains the udp datagram. - @param HeadSum Checksum of the pseudo header execpt the length + @param[in] Packet Pointer to the NET_BUF contains the udp datagram. + @param[in] HeadSum Checksum of the pseudo header execpt the length field. - @return The 16-bit checksum of this udp datagram. + @retval The 16-bit checksum of this udp datagram. **/ UINT16 @@ -824,8 +949,8 @@ Udp4Checksum ( /** This function removes the specified Token from the TokenMap. - @param TokenMap Pointer to the NET_MAP containing the tokens. - @param Token Pointer to the Token to be removed. + @param[in, out] TokenMap Pointer to the NET_MAP containing the tokens. + @param[in] Token Pointer to the Token to be removed. @retval EFI_SUCCESS The specified Token is removed from the TokenMap. @retval EFI_NOT_FOUND The specified Token is not found in the TokenMap. @@ -833,8 +958,8 @@ Udp4Checksum ( **/ EFI_STATUS Udp4RemoveToken ( - IN NET_MAP *TokenMap, - IN EFI_UDP4_COMPLETION_TOKEN *Token + IN OUT NET_MAP *TokenMap, + IN EFI_UDP4_COMPLETION_TOKEN *Token ) { NET_MAP_ITEM *Item; @@ -862,21 +987,19 @@ Udp4RemoveToken ( interface. It's called to signal the udp TxToken when IpIo layer completes the transmitting of the udp datagram. - @param Status The completion status of the output udp datagram. - @param Context Pointer to the context data. - @param Sender Pointer to the Ip sender of the udp datagram. - @param NotifyData Pointer to the notify data. - - @return None. + @param[in] Status The completion status of the output udp datagram. + @param[in] Context Pointer to the context data. + @param[in] Sender Specify a pointer of EFI_IP4_PROTOCOL for sending. + @param[in] NotifyData Pointer to the notify data. **/ -STATIC VOID +EFIAPI Udp4DgramSent ( - IN EFI_STATUS Status, - IN VOID *Context, - IN VOID *Sender, - IN VOID *NotifyData + IN EFI_STATUS Status, + IN VOID *Context, + IN IP_IO_IP_PROTOCOL Sender, + IN VOID *NotifyData ) { UDP4_INSTANCE_DATA *Instance; @@ -891,6 +1014,7 @@ Udp4DgramSent ( // Token->Status = Status; gBS->SignalEvent (Token->Event); + DispatchDpc (); } } @@ -898,22 +1022,20 @@ Udp4DgramSent ( /** This function processes the received datagram passed up by the IpIo layer. - @param Status The status of this udp datagram. - @param IcmpError The IcmpError code, only available when Status is + @param[in] Status The status of this udp datagram. + @param[in] IcmpError The IcmpError code, only available when Status is EFI_ICMP_ERROR. - @param NetSession Pointer to the EFI_NET_SESSION_DATA. - @param Packet Pointer to the NET_BUF containing the received udp + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA. + @param[in] Packet Pointer to the NET_BUF containing the received udp datagram. - @param Context Pointer to the context data. - - @return None. + @param[in] Context Pointer to the context data. **/ -STATIC VOID +EFIAPI Udp4DgramRcvd ( IN EFI_STATUS Status, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet, IN VOID *Context @@ -935,15 +1057,21 @@ Udp4DgramRcvd ( // Udp4IcmpHandler ((UDP4_SERVICE_DATA *) Context, IcmpError, NetSession, Packet); } + + // + // Dispatch the DPC queued by the NotifyFunction of the rx token's events + // which are signaled with received data. + // + DispatchDpc (); } /** This function removes the multicast group specified by Arg from the Map. - @param Map Pointer to the NET_MAP. - @param Item Pointer to the NET_MAP_ITEM. - @param Arg Pointer to the Arg, it's the pointer to a + @param[in, out] Map Pointer to the NET_MAP. + @param[in] Item Pointer to the NET_MAP_ITEM. + @param[in] Arg Pointer to the Arg, it's the pointer to a multicast IPv4 Address. @retval EFI_SUCCESS The multicast address is removed. @@ -952,10 +1080,11 @@ Udp4DgramRcvd ( **/ EFI_STATUS +EFIAPI Udp4LeaveGroup ( - IN NET_MAP *Map, - IN NET_MAP_ITEM *Item, - IN VOID *Arg OPTIONAL + IN OUT NET_MAP *Map, + IN NET_MAP_ITEM *Item, + IN VOID *Arg OPTIONAL ) { EFI_IPv4_ADDRESS *McastIp; @@ -987,12 +1116,13 @@ Udp4LeaveGroup ( /** - This function cancle the token specified by Arg in the Map. + This function cancels the token specified by Arg in the Map. This is a callback + used by Udp4InstanceCancelToken(). - @param Map Pointer to the NET_MAP. - @param Item Pointer to the NET_MAP_ITEM. - @param Arg Pointer to the token to be cancelled, if NULL, all - the tokens in this Map will be cancelled. + @param[in] Map Pointer to the NET_MAP. + @param[in] Item Pointer to the NET_MAP_ITEM. + @param[in] Arg Pointer to the token to be cancelled, if NULL, + the token specified by Item is cancelled. @retval EFI_SUCCESS The token is cancelled if Arg is NULL or the token is not the same as that in the Item if Arg is not @@ -1001,8 +1131,8 @@ Udp4LeaveGroup ( cancelled. **/ -STATIC EFI_STATUS +EFIAPI Udp4CancelTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1033,11 +1163,10 @@ Udp4CancelTokens ( // The token is a receive token. Abort it and remove it from the Map. // TokenToCancel = (EFI_UDP4_COMPLETION_TOKEN *) Item->Key; + NetMapRemoveItem (Map, Item, NULL); TokenToCancel->Status = EFI_ABORTED; gBS->SignalEvent (TokenToCancel->Event); - - NetMapRemoveItem (Map, Item, NULL); } if (Arg != NULL) { @@ -1051,42 +1180,36 @@ Udp4CancelTokens ( /** This function removes all the Wrap datas in the RcvdDgramQue. - @param RcvdDgramQue Pointer to the list containing all the Wrap datas. - - @return None. + @param[in] Instance Pointer to the udp instance context data. **/ VOID -Udp4FlushRxData ( - IN NET_LIST_ENTRY *RcvdDgramQue +Udp4FlushRcvdDgram ( + IN UDP4_INSTANCE_DATA *Instance ) { UDP4_RXDATA_WRAP *Wrap; - EFI_TPL OldTpl; - - OldTpl = NET_RAISE_TPL (NET_TPL_RECYCLE); - while (!NetListIsEmpty (RcvdDgramQue)) { + while (!IsListEmpty (&Instance->RcvdDgramQue)) { // // Iterate all the Wraps in the RcvdDgramQue. // - Wrap = NET_LIST_HEAD (RcvdDgramQue, UDP4_RXDATA_WRAP, Link); + Wrap = NET_LIST_HEAD (&Instance->RcvdDgramQue, UDP4_RXDATA_WRAP, Link); // // The Wrap will be removed from the RcvdDgramQue by this function call. // Udp4RecycleRxDataWrap (NULL, (VOID *) Wrap); } - - NET_RESTORE_TPL (OldTpl); } /** + Cancel Udp4 tokens from the Udp4 instance. - @param Instance Pointer to the udp instance context data. - @param Token Pointer to the token to be canceled, if NULL, all + @param[in] Instance Pointer to the udp instance context data. + @param[in] Token Pointer to the token to be canceled, if NULL, all tokens in this instance will be cancelled. @retval EFI_SUCCESS The Token is cancelled. @@ -1102,7 +1225,7 @@ Udp4InstanceCancelToken ( EFI_STATUS Status; // - // Cancle this token from the TxTokens map. + // Cancel this token from the TxTokens map. // Status = NetMapIterate (&Instance->TxTokens, Udp4CancelTokens, Token); @@ -1138,14 +1261,15 @@ Udp4InstanceCancelToken ( /** This function matches the received udp datagram with the Instance. - @param Instance Pointer to the udp instance context data. - @param Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted + @param[in] Instance Pointer to the udp instance context data. + @param[in] Udp4Session Pointer to the EFI_UDP4_SESSION_DATA abstracted from the received udp datagram. - @return The udp datagram matches the receiving requirments of the Instance or not. + @retval TRUE The udp datagram matches the receiving requirments of the + udp Instance. + @retval FALSE Otherwise. **/ -STATIC BOOLEAN Udp4MatchDgram ( IN UDP4_INSTANCE_DATA *Instance, @@ -1165,7 +1289,8 @@ Udp4MatchDgram ( } if ((!ConfigData->AcceptAnyPort && (Udp4Session->DestinationPort != ConfigData->StationPort)) || - ((ConfigData->RemotePort != 0) && (Udp4Session->SourcePort != ConfigData->RemotePort))) { + ((ConfigData->RemotePort != 0) && (Udp4Session->SourcePort != ConfigData->RemotePort)) + ) { // // The local port or the remote port doesn't match. // @@ -1173,7 +1298,8 @@ Udp4MatchDgram ( } if (!EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr) && - !EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress)) { + !EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress) + ) { // // This datagram doesn't come from the instance's specified sender. // @@ -1181,15 +1307,16 @@ Udp4MatchDgram ( } if (EFI_IP4_EQUAL (&ConfigData->StationAddress, &mZeroIp4Addr) || - EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress)) { + EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress) + ) { // - // The instance is configured to receive datagrams destinated to any station IP or + // The instance is configured to receive datagrams destined to any station IP or // the destination address of this datagram matches the configured station IP. // return TRUE; } - NetCopyMem (&Destination, &Udp4Session->DestinationAddress, sizeof (IP4_ADDR)); + CopyMem (&Destination, &Udp4Session->DestinationAddress, sizeof (IP4_ADDR)); if (IP4_IS_LOCAL_BROADCAST (Destination) && ConfigData->AcceptBroadcast) { // @@ -1199,7 +1326,8 @@ Udp4MatchDgram ( } if (IP4_IS_MULTICAST (NTOHL (Destination)) && - (NULL != NetMapFindKey (&Instance->McastIps, (VOID *) (UINTN) Destination))) { + NetMapFindKey (&Instance->McastIps, (VOID *) (UINTN) Destination) != NULL + ) { // // It's a multicast packet and the multicast address is accepted by this instance. // @@ -1213,13 +1341,10 @@ Udp4MatchDgram ( /** This function removes the Wrap specified by Context and release relevant resources. - @param Event The Event this notify function registered to. - @param Context Pointer to the context data. - - @return None. + @param[in] Event The Event this notify function registered to. + @param[in] Context Pointer to the context data. **/ -STATIC VOID EFIAPI Udp4RecycleRxDataWrap ( @@ -1234,7 +1359,7 @@ Udp4RecycleRxDataWrap ( // // Remove the Wrap from the list it belongs to. // - NetListRemoveEntry (&Wrap->Link); + RemoveEntryList (&Wrap->Link); // // Free the Packet associated with this Wrap. @@ -1246,23 +1371,22 @@ Udp4RecycleRxDataWrap ( // gBS->CloseEvent (Wrap->RxData.RecycleSignal); - NetFreePool (Wrap); + FreePool (Wrap); } /** This function wraps the Packet and the RxData. - @param Instance Pointer to the instance context data. - @param Packet Pointer to the buffer containing the received - datagram. - @param RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this - datagram. + @param[in] Instance Pointer to the instance context data. + @param[in] Packet Pointer to the buffer containing the received + datagram. + @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this + datagram. @return Pointer to the structure wrapping the RxData and the Packet. **/ -STATIC UDP4_RXDATA_WRAP * Udp4WrapRxData ( IN UDP4_INSTANCE_DATA *Instance, @@ -1276,13 +1400,13 @@ Udp4WrapRxData ( // // Allocate buffer for the Wrap. // - Wrap = NetAllocatePool (sizeof (UDP4_RXDATA_WRAP) + + Wrap = AllocatePool (sizeof (UDP4_RXDATA_WRAP) + (Packet->BlockOpNum - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA)); if (Wrap == NULL) { return NULL; } - NetListInit (&Wrap->Link); + InitializeListHead (&Wrap->Link); CopyMem (&Wrap->RxData, RxData, sizeof (Wrap->RxData)); @@ -1291,13 +1415,13 @@ Udp4WrapRxData ( // Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL, - NET_TPL_RECYCLE, + TPL_NOTIFY, Udp4RecycleRxDataWrap, Wrap, &Wrap->RxData.RecycleSignal ); if (EFI_ERROR (Status)) { - NetFreePool (Wrap); + FreePool (Wrap); return NULL; } @@ -1311,16 +1435,15 @@ Udp4WrapRxData ( /** This function enqueues the received datagram into the instances' receiving queues. - @param Udp4Service Pointer to the udp service context data. - @param Packet Pointer to the buffer containing the received - datagram. - @param RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this - datagram. + @param[in] Udp4Service Pointer to the udp service context data. + @param[in] Packet Pointer to the buffer containing the received + datagram. + @param[in] RxData Pointer to the EFI_UDP4_RECEIVE_DATA of this + datagram. @return The times this datagram is enqueued. **/ -STATIC UINTN Udp4EnqueueDgram ( IN UDP4_SERVICE_DATA *Udp4Service, @@ -1328,7 +1451,7 @@ Udp4EnqueueDgram ( IN EFI_UDP4_RECEIVE_DATA *RxData ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; UDP4_INSTANCE_DATA *Instance; UDP4_RXDATA_WRAP *Wrap; UINTN Enqueued; @@ -1349,14 +1472,14 @@ Udp4EnqueueDgram ( // // Wrap the RxData and put this Wrap into the instances RcvdDgramQue. // - CopyMem (&Wrap, Udp4WrapRxData (Instance, Packet, RxData), sizeof (Wrap)); + Wrap = Udp4WrapRxData (Instance, Packet, RxData); if (Wrap == NULL) { continue; } NET_GET_REF (Packet); - NetListInsertTail (&Instance->RcvdDgramQue, &Wrap->Link); + InsertTailList (&Instance->RcvdDgramQue, &Wrap->Link); Enqueued++; } @@ -1369,9 +1492,7 @@ Udp4EnqueueDgram ( /** This function delivers the received datagrams for the specified instance. - @param Instance Pointer to the instance context data. - - @return None. + @param[in] Instance Pointer to the instance context data. **/ VOID @@ -1383,9 +1504,10 @@ Udp4InstanceDeliverDgram ( EFI_UDP4_COMPLETION_TOKEN *Token; NET_BUF *Dup; EFI_UDP4_RECEIVE_DATA *RxData; + EFI_TPL OldTpl; - if (!NetListIsEmpty (&Instance->RcvdDgramQue) && - !NetMapIsEmpty (&Instance->RxTokens)) { + if (!IsListEmpty (&Instance->RcvdDgramQue) && + !NetMapIsEmpty (&Instance->RxTokens)) { Wrap = NET_LIST_HEAD (&Instance->RcvdDgramQue, UDP4_RXDATA_WRAP, Link); @@ -1422,9 +1544,11 @@ Udp4InstanceDeliverDgram ( Token->Status = EFI_SUCCESS; Token->Packet.RxData = &Wrap->RxData; - gBS->SignalEvent (Token->Event); + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + InsertTailList (&Instance->DeliveredDgramQue, &Wrap->Link); + gBS->RestoreTPL (OldTpl); - NetListInsertTail (&Instance->DeliveredDgramQue, &Wrap->Link); + gBS->SignalEvent (Token->Event); } } @@ -1432,18 +1556,15 @@ Udp4InstanceDeliverDgram ( /** This function delivers the datagrams enqueued in the instances. - @param Udp4Service Pointer to the udp service context data. - - @return None. + @param[in] Udp4Service Pointer to the udp service context data. **/ -STATIC VOID Udp4DeliverDgram ( IN UDP4_SERVICE_DATA *Udp4Service ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; UDP4_INSTANCE_DATA *Instance; NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) { @@ -1467,16 +1588,13 @@ Udp4DeliverDgram ( /** This function demultiplexes the received udp datagram to the apropriate instances. - @param Udp4Service Pointer to the udp service context data. - @param NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from - the received datagram. - @param Packet Pointer to the buffer containing the received udp - datagram. - - @return None. + @param[in] Udp4Service Pointer to the udp service context data. + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstrated from + the received datagram. + @param[in] Packet Pointer to the buffer containing the received udp + datagram. **/ -STATIC VOID Udp4Demultiplex ( IN UDP4_SERVICE_DATA *Udp4Service, @@ -1484,7 +1602,7 @@ Udp4Demultiplex ( IN NET_BUF *Packet ) { - EFI_UDP4_HEADER *Udp4Header; + EFI_UDP_HEADER *Udp4Header; UINT16 HeadSum; EFI_UDP4_RECEIVE_DATA RxData; EFI_UDP4_SESSION_DATA *Udp4Session; @@ -1493,15 +1611,16 @@ Udp4Demultiplex ( // // Get the datagram header from the packet buffer. // - Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL); + Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Udp4Header != NULL); if (Udp4Header->Checksum != 0) { // // check the checksum. // HeadSum = NetPseudoHeadChecksum ( - NetSession->Source, - NetSession->Dest, + NetSession->Source.Addr[0], + NetSession->Dest.Addr[0], EFI_IP_PROTO_UDP, 0 ); @@ -1514,14 +1633,12 @@ Udp4Demultiplex ( } } - gRT->GetTime (&RxData.TimeStamp, NULL); - Udp4Session = &RxData.UdpSession; Udp4Session->SourcePort = NTOHS (Udp4Header->SrcPort); Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort); - NetCopyMem (&Udp4Session->SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS)); - NetCopyMem (&Udp4Session->DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Udp4Session->SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Udp4Session->DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); // // Trim the UDP header. @@ -1559,16 +1676,13 @@ Udp4Demultiplex ( /** This function builds and sends out a icmp port unreachable message. - @param IpIo Pointer to the IP_IO instance. - @param NetSession Pointer to the EFI_NET_SESSION_DATA of the packet - causes this icmp error message. - @param Udp4Header Pointer to the udp header of the datagram causes - this icmp error message. - - @return None. + @param[in] IpIo Pointer to the IP_IO instance. + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA of the packet + causes this icmp error message. + @param[in] Udp4Header Pointer to the udp header of the datagram causes + this icmp error message. **/ -STATIC VOID Udp4SendPortUnreach ( IN IP_IO *IpIo, @@ -1584,7 +1698,7 @@ Udp4SendPortUnreach ( IP_IO_OVERRIDE Override; IP_IO_IP_INFO *IpSender; - IpSender = IpIoFindSender (&IpIo, NetSession->Dest); + IpSender = IpIoFindSender (&IpIo, NetSession->IpVersion, &NetSession->Dest); if (IpSender == NULL) { // // No apropriate sender, since we cannot send out the ICMP message through @@ -1593,7 +1707,7 @@ Udp4SendPortUnreach ( return; } - IpHdr = NetSession->IpHdr; + IpHdr = NetSession->IpHdr.Ip4Hdr; // // Calculate the requried length of the icmp error message. @@ -1613,6 +1727,7 @@ Udp4SendPortUnreach ( // Allocate space for the IP4_ICMP_ERROR_HEAD. // IcmpErrHdr = (IP4_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE); + ASSERT (IcmpErrHdr != NULL); // // Set the required fields for the icmp port unreachable message. @@ -1625,13 +1740,13 @@ Udp4SendPortUnreach ( // // Copy the IP header of the datagram tragged the error. // - NetCopyMem (&IcmpErrHdr->IpHead, IpHdr, EFI_IP4_HEADER_LEN (IpHdr)); + CopyMem (&IcmpErrHdr->IpHead, IpHdr, EFI_IP4_HEADER_LEN (IpHdr)); // // Copy the UDP header. // Ptr = (UINT8 *) &IcmpErrHdr->IpHead + EFI_IP4_HEADER_LEN (IpHdr); - NetCopyMem (Ptr, Udp4Header, ICMP_ERROR_PACKET_LENGTH); + CopyMem (Ptr, Udp4Header, ICMP_ERROR_PACKET_LENGTH); // // Calculate the checksum. @@ -1641,18 +1756,18 @@ Udp4SendPortUnreach ( // // Fill the override data. // - Override.DoNotFragment = FALSE; - Override.TypeOfService = 0; - Override.TimeToLive = 255; - Override.Protocol = EFI_IP_PROTO_ICMP; + Override.Ip4OverrideData.DoNotFragment = FALSE; + Override.Ip4OverrideData.TypeOfService = 0; + Override.Ip4OverrideData.TimeToLive = 255; + Override.Ip4OverrideData.Protocol = EFI_IP_PROTO_ICMP; - NetCopyMem (&Override.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); - NetZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Override.Ip4OverrideData.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS)); // // Send out this icmp packet. // - IpIoSend (IpIo, Packet, IpSender, NULL, NULL, NetSession->Source, &Override); + IpIoSend (IpIo, Packet, IpSender, NULL, NULL, &NetSession->Source, &Override); NetbufFree (Packet); } @@ -1662,33 +1777,31 @@ Udp4SendPortUnreach ( This function handles the received Icmp Error message and demultiplexes it to the instance. - @param Udp4Service Pointer to the udp service context data. - @param IcmpError The icmp error code. - @param NetSession Pointer to the EFI_NET_SESSION_DATA abstracted + @param[in] Udp4Service Pointer to the udp service context data. + @param[in] IcmpError The icmp error code. + @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA abstracted from the received Icmp Error packet. - @param Packet Pointer to the Icmp Error packet. - - @return None. + @param[in] Packet Pointer to the Icmp Error packet. **/ -STATIC VOID Udp4IcmpHandler ( IN UDP4_SERVICE_DATA *Udp4Service, - IN ICMP_ERROR IcmpError, + IN UINT8 IcmpError, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet ) { - EFI_UDP4_HEADER *Udp4Header; + EFI_UDP_HEADER *Udp4Header; EFI_UDP4_SESSION_DATA Udp4Session; - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; UDP4_INSTANCE_DATA *Instance; - Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL); + Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Udp4Header != NULL); - NetCopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS)); - NetCopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); Udp4Session.SourcePort = NTOHS (Udp4Header->DstPort); Udp4Session.DestinationPort = NTOHS (Udp4Header->SrcPort); @@ -1699,15 +1812,7 @@ Udp4IcmpHandler ( // Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link); - if (!Instance->Configured || - Instance->ConfigData.AcceptPromiscuous || - Instance->ConfigData.AcceptAnyPort || - EFI_IP4_EQUAL (&Instance->ConfigData.StationAddress, &mZeroIp4Addr)) { - // - // Don't try to deliver the ICMP error to this instance if it is not configured, - // or it's configured to be promiscuous or accept any port or accept all the - // datagrams. - // + if (!Instance->Configured) { continue; } @@ -1715,7 +1820,7 @@ Udp4IcmpHandler ( // // Translate the Icmp Error code according to the udp spec. // - Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, NULL, NULL); + Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, IP_VERSION_4, NULL, NULL); if (IcmpError > ICMP_ERR_UNREACH_PORT) { Instance->IcmpError = EFI_ICMP_ERROR; @@ -1737,9 +1842,7 @@ Udp4IcmpHandler ( /** This function reports the received ICMP error. - @param Instance Pointer to the udp instance context data. - - @return None. + @param[in] Instance Pointer to the udp instance context data. **/ VOID @@ -1782,177 +1885,13 @@ Udp4ReportIcmpError ( This function is a dummy ext-free function for the NET_BUF created for the output udp datagram. - @param Context Pointer to the context data. - - @return None. + @param[in] Context Pointer to the context data. **/ VOID +EFIAPI Udp4NetVectorExtFree ( VOID *Context ) { -} - - -/** - Set the Udp4 variable data. - - @param Udp4Service Udp4 service data. - - @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the - variable. - @retval other Set variable failed. - -**/ -EFI_STATUS -Udp4SetVariableData ( - IN UDP4_SERVICE_DATA *Udp4Service - ) -{ - UINT32 NumConfiguredInstance; - NET_LIST_ENTRY *Entry; - UINTN VariableDataSize; - EFI_UDP4_VARIABLE_DATA *Udp4VariableData; - EFI_UDP4_SERVICE_POINT *Udp4ServicePoint; - UDP4_INSTANCE_DATA *Udp4Instance; - CHAR16 *NewMacString; - EFI_STATUS Status; - - NumConfiguredInstance = 0; - - // - // Go through the children list to count the configured children. - // - NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) { - Udp4Instance = NET_LIST_USER_STRUCT_S ( - Entry, - UDP4_INSTANCE_DATA, - Link, - UDP4_INSTANCE_DATA_SIGNATURE - ); - - if (Udp4Instance->Configured) { - NumConfiguredInstance++; - } - } - - // - // Calculate the size of the Udp4VariableData. As there may be no Udp4 child, - // we should add extra buffer for the service points only if the number of configured - // children is more than 1. - // - VariableDataSize = sizeof (EFI_UDP4_VARIABLE_DATA); - - if (NumConfiguredInstance > 1) { - VariableDataSize += sizeof (EFI_UDP4_SERVICE_POINT) * (NumConfiguredInstance - 1); - } - - Udp4VariableData = NetAllocatePool (VariableDataSize); - if (Udp4VariableData == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Udp4VariableData->DriverHandle = Udp4Service->ImageHandle; - Udp4VariableData->ServiceCount = NumConfiguredInstance; - - Udp4ServicePoint = &Udp4VariableData->Services[0]; - - // - // Go through the children list to fill the configured children's address pairs. - // - NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) { - Udp4Instance = NET_LIST_USER_STRUCT_S ( - Entry, - UDP4_INSTANCE_DATA, - Link, - UDP4_INSTANCE_DATA_SIGNATURE - ); - - if (Udp4Instance->Configured) { - Udp4ServicePoint->InstanceHandle = Udp4Instance->ChildHandle; - Udp4ServicePoint->LocalAddress = Udp4Instance->ConfigData.StationAddress; - Udp4ServicePoint->LocalPort = Udp4Instance->ConfigData.StationPort; - Udp4ServicePoint->RemoteAddress = Udp4Instance->ConfigData.RemoteAddress; - Udp4ServicePoint->RemotePort = Udp4Instance->ConfigData.RemotePort; - - Udp4ServicePoint++; - } - } - - // - // Get the mac string. - // - Status = NetLibGetMacString ( - Udp4Service->ControllerHandle, - Udp4Service->ImageHandle, - &NewMacString - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - if (Udp4Service->MacString != NULL) { - // - // The variable is set already, we're going to update it. - // - if (StrCmp (Udp4Service->MacString, NewMacString) != 0) { - // - // The mac address is changed, delete the previous variable first. - // - gRT->SetVariable ( - Udp4Service->MacString, - &gEfiUdp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - } - - NetFreePool (Udp4Service->MacString); - } - - Udp4Service->MacString = NewMacString; - - Status = gRT->SetVariable ( - Udp4Service->MacString, - &gEfiUdp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - VariableDataSize, - (VOID *) Udp4VariableData - ); - -ON_ERROR: - - NetFreePool (Udp4VariableData); - - return Status; -} - - -/** - Clear the variable and free the resource. - - @param Udp4Service Udp4 service data. - - @return None. - -**/ -VOID -Udp4ClearVariableData ( - IN UDP4_SERVICE_DATA *Udp4Service - ) -{ - ASSERT (Udp4Service->MacString != NULL); - - gRT->SetVariable ( - Udp4Service->MacString, - &gEfiUdp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - - NetFreePool (Udp4Service->MacString); - Udp4Service->MacString = NULL; -} +} \ No newline at end of file