X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4If.c;h=44b8d9fc8faf64aeb736eb23e6adc366a908f3ce;hp=d8f88e14b12778e5be2dc4603f9b5528038c9113;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=e48e37fce2611df7a52aff271835ff72ee396d9b diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c index d8f88e14b1..44b8d9fc8f 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c @@ -1,23 +1,8 @@ /** @file - -Copyright (c) 2005 - 2007, 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 - -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: - - Ip4If.c - -Abstract: - Implement IP4 pesudo interface. +Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -27,31 +12,58 @@ Abstract: // Mac address with all zero, used to determine whethter the ARP // resolve succeeded. Failed ARP requests zero the MAC address buffer. // -STATIC EFI_MAC_ADDRESS mZeroMacAddress; +EFI_MAC_ADDRESS mZeroMacAddress; + +/** + Callback funtion when frame transmission is finished. It will + call the frame owner's callback function to tell it the result. -STATIC + @param[in] Context Context which is point to the token. + +**/ VOID EFIAPI Ip4OnFrameSentDpc ( - IN VOID *Context + IN VOID *Context ); -STATIC +/** + Request Ip4OnFrameSentDpc as a DPC at TPL_CALLBACK. + + @param[in] Event The transmit token's event. + @param[in] Context Context which is point to the token. + +**/ VOID EFIAPI Ip4OnFrameSent ( - IN EFI_EVENT Event, - IN VOID *Context + IN EFI_EVENT Event, + IN VOID *Context ); -STATIC +/** + Callback function when ARP request are finished. It will cancelled + all the queued frame if the ARP requests failed. Or transmit them + if the request succeed. + + @param[in] Context The context of the callback, a point to the ARP + queue + +**/ VOID EFIAPI Ip4OnArpResolvedDpc ( IN VOID *Context ); -STATIC +/** + Request Ip4OnArpResolvedDpc as a DPC at TPL_CALLBACK. + + @param Event The Arp request event. + @param Context The context of the callback, a point to the ARP + queue. + +**/ VOID EFIAPI Ip4OnArpResolved ( @@ -59,27 +71,53 @@ Ip4OnArpResolved ( IN VOID *Context ); -STATIC +/** + Received a frame from MNP, wrap it in net buffer then deliver + it to IP's input function. The ownship of the packet also + transferred to IP. When Ip is finished with this packet, it + will call NetbufFree to release the packet, NetbufFree will + again call the Ip4RecycleFrame to signal MNP's event and free + the token used. + + @param Context Context for the callback. + +**/ VOID EFIAPI Ip4OnFrameReceivedDpc ( - IN VOID *Context + IN VOID *Context ); -STATIC +/** + Request Ip4OnFrameReceivedDpc as a DPC at TPL_CALLBACK. + + @param Event The receive event delivered to MNP for receive. + @param Context Context for the callback. + +**/ VOID EFIAPI Ip4OnFrameReceived ( - IN EFI_EVENT Event, - IN VOID *Context + IN EFI_EVENT Event, + IN VOID *Context ); -STATIC +/** + Remove all the frames on the ARP queue that pass the FrameToCancel, + that is, either FrameToCancel is NULL or it returns true for the frame. + + @param[in] ArpQue ARP frame to remove the frames from. + @param[in] IoStatus The status returned to the cancelled frames' + callback function. + @param[in] FrameToCancel Function to select which frame to cancel. + @param[in] Context Opaque parameter to the FrameToCancel. + +**/ VOID Ip4CancelFrameArp ( IN IP4_ARP_QUE *ArpQue, IN EFI_STATUS IoStatus, - IN IP4_FRAME_TO_CANCEL FrameToCancel, OPTIONAL + IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL, IN VOID *Context ); @@ -87,25 +125,27 @@ Ip4CancelFrameArp ( /** Wrap a transmit request into a newly allocated IP4_LINK_TX_TOKEN. - @param Interface The interface to send out from - @param IpInstance The IpInstance that transmit the packet. NULL if + @param[in] Interface The interface to send out to. + @param[in] IpInstance The IpInstance that transmit the packet. NULL if the packet is sent by the IP4 driver itself. - @param Packet The packet to transmit - @param CallBack Call back function to execute if transmission + @param[in] Packet The packet to transmit + @param[in] CallBack Call back function to execute if transmission finished. - @param Context Opaque parameter to the call back. + @param[in] Context Opaque parameter to the call back. + @param[in] IpSb The pointer to the IP4 service binding instance. - @return The wrapped token if succeed or NULL + @retval Token The wrapped token if succeed + @retval NULL The wrapped token if NULL **/ -STATIC IP4_LINK_TX_TOKEN * Ip4WrapLinkTxToken ( IN IP4_INTERFACE *Interface, - IN IP4_PROTOCOL *IpInstance, OPTIONAL + IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN IP4_FRAME_CALLBACK CallBack, - IN VOID *Context + IN VOID *Context, + IN IP4_SERVICE *IpSb ) { EFI_MANAGED_NETWORK_COMPLETION_TOKEN *MnpToken; @@ -126,6 +166,7 @@ Ip4WrapLinkTxToken ( Token->Interface = Interface; Token->IpInstance = IpInstance; + Token->IpSb = IpSb; Token->CallBack = CallBack; Token->Packet = Packet; Token->Context = Context; @@ -144,7 +185,7 @@ Ip4WrapLinkTxToken ( ); if (EFI_ERROR (Status)) { - gBS->FreePool (Token); + FreePool (Token); return NULL; } @@ -170,12 +211,9 @@ Ip4WrapLinkTxToken ( Free the link layer transmit token. It will close the event then free the memory used. - @param Token Token to free - - @return NONE + @param[in] Token Token to free **/ -STATIC VOID Ip4FreeLinkTxToken ( IN IP4_LINK_TX_TOKEN *Token @@ -184,21 +222,20 @@ Ip4FreeLinkTxToken ( NET_CHECK_SIGNATURE (Token, IP4_FRAME_TX_SIGNATURE); gBS->CloseEvent (Token->MnpToken.Event); - gBS->FreePool (Token); + FreePool (Token); } /** Create an IP_ARP_QUE structure to request ARP service. - @param Interface The interface to send ARP from. - @param DestIp The destination IP (host byte order) to request MAC + @param[in] Interface The interface to send ARP from. + @param[in] DestIp The destination IP (host byte order) to request MAC for @return Point to newly created IP4_ARP_QUE if succeed, otherwise NULL. **/ -STATIC IP4_ARP_QUE * Ip4CreateArpQue ( IN IP4_INTERFACE *Interface, @@ -229,7 +266,7 @@ Ip4CreateArpQue ( ); if (EFI_ERROR (Status)) { - gBS->FreePool (ArpQue); + FreePool (ArpQue); return NULL; } @@ -243,14 +280,11 @@ Ip4CreateArpQue ( /** Remove all the transmit requests queued on the ARP queue, then free it. - @param ArpQue Arp queue to free - @param IoStatus The transmit status returned to transmit requests' + @param[in] ArpQue Arp queue to free + @param[in] IoStatus The transmit status returned to transmit requests' callback. - @return NONE - **/ -STATIC VOID Ip4FreeArpQue ( IN IP4_ARP_QUE *ArpQue, @@ -265,23 +299,22 @@ Ip4FreeArpQue ( Ip4CancelFrameArp (ArpQue, IoStatus, NULL, NULL); gBS->CloseEvent (ArpQue->OnResolved); - gBS->FreePool (ArpQue); + FreePool (ArpQue); } /** Create a link layer receive token to wrap the receive request - @param Interface The interface to receive from - @param IpInstance The instance that request the receive (NULL for IP4 + @param[in] Interface The interface to receive from + @param[in] IpInstance The instance that request the receive (NULL for IP4 driver itself) - @param CallBack Call back function to execute when finished. - @param Context Opaque parameters to the callback + @param[in] CallBack Call back function to execute when finished. + @param[in] Context Opaque parameters to the callback @return Point to created IP4_LINK_RX_TOKEN if succeed, otherwise NULL. **/ -STATIC IP4_LINK_RX_TOKEN * Ip4CreateLinkRxToken ( IN IP4_INTERFACE *Interface, @@ -317,7 +350,7 @@ Ip4CreateLinkRxToken ( ); if (EFI_ERROR (Status)) { - gBS->FreePool (Token); + FreePool (Token); return NULL; } @@ -330,12 +363,9 @@ Ip4CreateLinkRxToken ( Free the link layer request token. It will close the event then free the memory used. - @param Token Request token to free - - @return NONE + @param[in] Token Request token to free. **/ -STATIC VOID Ip4FreeFrameRxToken ( IN IP4_LINK_RX_TOKEN *Token @@ -345,7 +375,7 @@ Ip4FreeFrameRxToken ( NET_CHECK_SIGNATURE (Token, IP4_FRAME_RX_SIGNATURE); gBS->CloseEvent (Token->MnpToken.Event); - gBS->FreePool (Token); + FreePool (Token); } @@ -353,21 +383,18 @@ Ip4FreeFrameRxToken ( Remove all the frames on the ARP queue that pass the FrameToCancel, that is, either FrameToCancel is NULL or it returns true for the frame. - @param ArpQue ARP frame to remove the frames from. - @param IoStatus The status returned to the cancelled frames' + @param[in] ArpQue ARP frame to remove the frames from. + @param[in] IoStatus The status returned to the cancelled frames' callback function. - @param FrameToCancel Function to select which frame to cancel. - @param Context Opaque parameter to the FrameToCancel. - - @return NONE + @param[in] FrameToCancel Function to select which frame to cancel. + @param[in] Context Opaque parameter to the FrameToCancel. **/ -STATIC VOID Ip4CancelFrameArp ( IN IP4_ARP_QUE *ArpQue, IN EFI_STATUS IoStatus, - IN IP4_FRAME_TO_CANCEL FrameToCancel, OPTIONAL + IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL, IN VOID *Context ) { @@ -393,21 +420,19 @@ Ip4CancelFrameArp ( either queued on ARP queues or that have already been delivered to MNP and not yet recycled. - @param Interface Interface to remove the frames from - @param IoStatus The transmit status returned to the frames' - callback - @param FrameToCancel Function to select the frame to cancel, NULL to - select all - @param Context Opaque parameters passed to FrameToCancel - - @return NONE + @param[in] Interface Interface to remove the frames from. + @param[in] IoStatus The transmit status returned to the frames' + callback. + @param[in] FrameToCancel Function to select the frame to cancel, NULL to + select all. + @param[in] Context Opaque parameters passed to FrameToCancel. **/ VOID Ip4CancelFrames ( IN IP4_INTERFACE *Interface, IN EFI_STATUS IoStatus, - IN IP4_FRAME_TO_CANCEL FrameToCancel, OPTIONAL + IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL, IN VOID *Context ) { @@ -447,11 +472,11 @@ Ip4CancelFrames ( Create an IP4_INTERFACE. Delay the creation of ARP instance until the interface is configured. - @param Mnp The shared MNP child of this IP4 service binding - instance - @param Controller The controller this IP4 service binding instance + @param[in] Mnp The shared MNP child of this IP4 service binding + instance. + @param[in] Controller The controller this IP4 service binding instance is installed. Most like the UNDI handle. - @param ImageHandle This driver's image handle + @param[in] ImageHandle This driver's image handle. @return Point to the created IP4_INTERFACE, otherwise NULL. @@ -495,7 +520,7 @@ Ip4CreateInterface ( // Get the interface's Mac address and broadcast mac address from SNP // if (EFI_ERROR (Mnp->GetModeData (Mnp, NULL, &SnpMode))) { - gBS->FreePool (Interface); + FreePool (Interface); return NULL; } @@ -514,9 +539,9 @@ Ip4CreateInterface ( Set the interface's address, create and configure the ARP child if necessary. - @param Interface The interface to set the address - @param IpAddr The interface's IP address - @param SubnetMask The interface's netmask + @param Interface The interface to set the address. + @param IpAddr The interface's IP address. + @param SubnetMask The interface's netmask. @retval EFI_SUCCESS The interface is configured with Ip/netmask pair, and a ARP is created for it. @@ -525,21 +550,16 @@ Ip4CreateInterface ( **/ EFI_STATUS Ip4SetAddress ( - IN IP4_INTERFACE *Interface, - IN IP4_ADDR IpAddr, - IN IP4_ADDR SubnetMask + IN OUT IP4_INTERFACE *Interface, + IN IP4_ADDR IpAddr, + IN IP4_ADDR SubnetMask ) { EFI_ARP_CONFIG_DATA ArpConfig; EFI_STATUS Status; - INTN Type; - INTN Len; - IP4_ADDR Netmask; NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE); - ASSERT (!Interface->Configured); - // // Set the ip/netmask, then compute the subnet broadcast // and network broadcast for easy access. When computing @@ -551,19 +571,37 @@ Ip4SetAddress ( Interface->Ip = IpAddr; Interface->SubnetMask = SubnetMask; Interface->SubnetBrdcast = (IpAddr | ~SubnetMask); + Interface->NetBrdcast = (IpAddr | ~SubnetMask); + + // + // Do clean up for Arp child + // + if (Interface->ArpHandle != NULL) { + if (Interface->Arp != NULL) { + gBS->CloseProtocol ( + Interface->ArpHandle, + &gEfiArpProtocolGuid, + Interface->Image, + Interface->Controller + ); + + Interface->Arp = NULL; + } - Type = NetGetIpClass (IpAddr); - Len = NetGetMaskLength (SubnetMask); - Netmask = mIp4AllMasks[MIN (Len, Type << 3)]; - Interface->NetBrdcast = (IpAddr | ~Netmask); + NetLibDestroyServiceChild ( + Interface->Controller, + Interface->Image, + &gEfiArpServiceBindingProtocolGuid, + &Interface->ArpHandle + ); + + Interface->ArpHandle = NULL; + } // // If the address is NOT all zero, create then configure an ARP child. // Pay attention: DHCP configures its station address as 0.0.0.0/0 // - Interface->Arp = NULL; - Interface->ArpHandle = NULL; - if (IpAddr != IP4_ALLZERO_ADDRESS) { Status = NetLibCreateServiceChild ( Interface->Controller, @@ -573,7 +611,7 @@ Ip4SetAddress ( ); if (EFI_ERROR (Status)) { - return Status;; + return Status; } Status = gBS->OpenProtocol ( @@ -601,11 +639,11 @@ Ip4SetAddress ( if (EFI_ERROR (Status)) { gBS->CloseProtocol ( - Interface->ArpHandle, - &gEfiArpProtocolGuid, - Interface->Image, - Interface->Controller - ); + Interface->ArpHandle, + &gEfiArpProtocolGuid, + Interface->Image, + Interface->Controller + ); goto ON_ERROR; } @@ -627,10 +665,10 @@ ON_ERROR: /** - Fileter function to cancel all the frame related to an IP instance. + Filter function to cancel all the frame related to an IP instance. - @param Frame The transmit request to test whether to cancel - @param Context The context which is the Ip instance that issued + @param[in] Frame The transmit request to test whether to cancel + @param[in] Context The context which is the Ip instance that issued the transmit. @retval TRUE The frame belongs to this instance and is to be @@ -638,7 +676,6 @@ ON_ERROR: @retval FALSE The frame doesn't belong to this instance. **/ -STATIC BOOLEAN Ip4CancelInstanceFrame ( IN IP4_LINK_TX_TOKEN *Frame, @@ -663,9 +700,7 @@ Ip4CancelInstanceFrame ( packet and update the upper layer's transmit request status, say that from the UDP. - @param Interface The interface used by the IpInstance - - @return None + @param[in] Interface The interface used by the IpInstance **/ VOID @@ -694,9 +729,9 @@ Ip4CancelReceive ( Because the IpInstance is optional, the caller must remove IpInstance from the interface's instance list itself. - @param Interface The interface used by the IpInstance - @param IpInstance The Ip instance that free the interface. NULL if - the Ip driver is releasing the default interface. + @param[in] Interface The interface used by the IpInstance. + @param[in] IpInstance The Ip instance that free the interface. NULL if + the Ip driver is releasing the default interface. @retval EFI_SUCCESS The interface use IpInstance is freed. @@ -720,10 +755,10 @@ Ip4FreeInterface ( } // - // Destory the interface if this is the last IP instance that + // Destroy the interface if this is the last IP instance that // has the address. Remove all the system transmitted packets // from this interface, cancel the receive request if there is - // one, and destory the ARP requests. + // one, and destroy the ARP requests. // Ip4CancelFrames (Interface, EFI_ABORTED, Ip4CancelInstanceFrame, NULL); Ip4CancelReceive (Interface); @@ -749,24 +784,101 @@ Ip4FreeInterface ( } RemoveEntryList (&Interface->Link); - gBS->FreePool (Interface); + FreePool (Interface); return EFI_SUCCESS; } +/** + This function tries to send all the queued frames in ArpQue to the default gateway if + the ARP resolve for direct destination address is failed when using /32 subnet mask. + + @param[in] ArpQue The ARP queue of a failed request. + + @retval EFI_SUCCESS All the queued frames have been send to the default route. + @retval Others Failed to send the queued frames. + +**/ +EFI_STATUS +Ip4SendFrameToDefaultRoute ( + IN IP4_ARP_QUE *ArpQue + ) +{ + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + IP4_ROUTE_CACHE_ENTRY *RtCacheEntry; + IP4_LINK_TX_TOKEN *Token; + IP4_ADDR Gateway; + EFI_STATUS Status; + IP4_ROUTE_ENTRY *DefaultRoute; + + // + // ARP resolve failed when using /32 subnet mask. + // + NET_LIST_FOR_EACH_SAFE (Entry, Next, &ArpQue->Frames) { + RemoveEntryList (Entry); + Token = NET_LIST_USER_STRUCT (Entry, IP4_LINK_TX_TOKEN, Link); + ASSERT (Token->Interface->SubnetMask == IP4_ALLONE_ADDRESS); + // + // Find the default gateway IP address. The default route was saved to the RtCacheEntry->Tag in Ip4Route(). + // + RtCacheEntry = NULL; + if (Token->IpInstance != NULL) { + RtCacheEntry = Ip4FindRouteCache (Token->IpInstance->RouteTable, NTOHL (ArpQue->Ip), Token->Interface->Ip); + } + if (RtCacheEntry == NULL) { + RtCacheEntry = Ip4FindRouteCache (Token->IpSb->DefaultRouteTable, NTOHL (ArpQue->Ip), Token->Interface->Ip); + } + if (RtCacheEntry == NULL) { + Status= EFI_NO_MAPPING; + goto ON_ERROR; + } + DefaultRoute = (IP4_ROUTE_ENTRY*)RtCacheEntry->Tag; + if (DefaultRoute == NULL) { + Status= EFI_NO_MAPPING; + goto ON_ERROR; + } + // + // Try to send the frame to the default route. + // + Gateway = DefaultRoute->NextHop; + if (ArpQue->Ip == Gateway) { + // + // ARP resolve for the default route is failed, return error to caller. + // + Status= EFI_NO_MAPPING; + goto ON_ERROR; + } + RtCacheEntry->NextHop = Gateway; + Status = Ip4SendFrame (Token->Interface,Token->IpInstance,Token->Packet,Gateway,Token->CallBack,Token->Context,Token->IpSb); + if (EFI_ERROR (Status)) { + Status= EFI_NO_MAPPING; + goto ON_ERROR; + } + Ip4FreeRouteCacheEntry (RtCacheEntry); + } + + return EFI_SUCCESS; + +ON_ERROR: + if (RtCacheEntry != NULL) { + Ip4FreeRouteCacheEntry (RtCacheEntry); + } + Token->CallBack (Token->IpInstance, Token->Packet, Status, 0, Token->Context); + Ip4FreeLinkTxToken (Token); + return Status; +} + /** - Callback function when ARP request are finished. It will cancelled + Callback function when ARP request are finished. It will cancel all the queued frame if the ARP requests failed. Or transmit them if the request succeed. - @param Context The context of the callback, a point to the ARP + @param[in] Context The context of the callback, a point to the ARP queue - @return None - **/ -STATIC VOID EFIAPI Ip4OnArpResolvedDpc ( @@ -779,6 +891,7 @@ Ip4OnArpResolvedDpc ( IP4_INTERFACE *Interface; IP4_LINK_TX_TOKEN *Token; EFI_STATUS Status; + EFI_STATUS IoStatus; ArpQue = (IP4_ARP_QUE *) Context; NET_CHECK_SIGNATURE (ArpQue, IP4_FRAME_ARP_SIGNATURE); @@ -786,14 +899,23 @@ Ip4OnArpResolvedDpc ( RemoveEntryList (&ArpQue->Link); // - // ARP resolve failed for some reason. Release all the frame - // and ARP queue itself. Ip4FreeArpQue will call the frame's - // owner back. + // ARP resolve failed for some reason. // if (NET_MAC_EQUAL (&ArpQue->Mac, &mZeroMacAddress, ArpQue->Interface->HwaddrLen)) { - Ip4FreeArpQue (ArpQue, EFI_NO_MAPPING); - - return ; + if (ArpQue->Interface->SubnetMask != IP4_ALLONE_ADDRESS) { + // + // Release all the frame and ARP queue itself. Ip4FreeArpQue will call the frame's + // owner back. + // + IoStatus = EFI_NO_MAPPING; + } else { + // + // ARP resolve failed when using 32bit subnet mask, try to send the packets to the + // default route. + // + IoStatus = Ip4SendFrameToDefaultRoute (ArpQue); + } + goto ON_EXIT; } // @@ -801,6 +923,7 @@ Ip4OnArpResolvedDpc ( // queue. It isn't necessary for us to cache the ARP binding because // we always check the ARP cache first before transmit. // + IoStatus = EFI_SUCCESS; Interface = ArpQue->Interface; NET_LIST_FOR_EACH_SAFE (Entry, Next, &ArpQue->Frames) { @@ -820,7 +943,7 @@ Ip4OnArpResolvedDpc ( Status = Interface->Mnp->Transmit (Interface->Mnp, &Token->MnpToken); if (EFI_ERROR (Status)) { - RemoveEntryList (Entry); + RemoveEntryList (&Token->Link); Token->CallBack (Token->IpInstance, Token->Packet, Status, 0, Token->Context); Ip4FreeLinkTxToken (Token); @@ -828,37 +951,29 @@ Ip4OnArpResolvedDpc ( } } - Ip4FreeArpQue (ArpQue, EFI_SUCCESS); +ON_EXIT: + Ip4FreeArpQue (ArpQue, IoStatus); } -STATIC +/** + Request Ip4OnArpResolvedDpc as a DPC at TPL_CALLBACK. + + @param Event The Arp request event. + @param Context The context of the callback, a point to the ARP + queue. + +**/ VOID EFIAPI Ip4OnArpResolved ( IN EFI_EVENT Event, IN VOID *Context ) -/*++ - -Routine Description: - - Request Ip4OnArpResolvedDpc as a DPC at TPL_CALLBACK - -Arguments: - - Event - The Arp request event - Context - The context of the callback, a point to the ARP queue - -Returns: - - None - ---*/ { // // Request Ip4OnArpResolvedDpc as a DPC at TPL_CALLBACK // - NetLibQueueDpc (TPL_CALLBACK, Ip4OnArpResolvedDpc, Context); + QueueDpc (TPL_CALLBACK, Ip4OnArpResolvedDpc, Context); } @@ -867,12 +982,9 @@ Returns: Callback funtion when frame transmission is finished. It will call the frame owner's callback function to tell it the result. - @param Context Context which is point to the token. - - @return None. + @param[in] Context Context which is point to the token. **/ -STATIC VOID EFIAPI Ip4OnFrameSentDpc ( @@ -897,34 +1009,24 @@ Ip4OnFrameSentDpc ( Ip4FreeLinkTxToken (Token); } -STATIC +/** + Request Ip4OnFrameSentDpc as a DPC at TPL_CALLBACK. + + @param[in] Event The transmit token's event. + @param[in] Context Context which is point to the token. + +**/ VOID EFIAPI Ip4OnFrameSent ( IN EFI_EVENT Event, IN VOID *Context ) -/*++ - -Routine Description: - - Request Ip4OnFrameSentDpc as a DPC at TPL_CALLBACK - -Arguments: - - Event - The transmit token's event - Context - Context which is point to the token. - -Returns: - - None. - ---*/ { // // Request Ip4OnFrameSentDpc as a DPC at TPL_CALLBACK // - NetLibQueueDpc (TPL_CALLBACK, Ip4OnFrameSentDpc, Context); + QueueDpc (TPL_CALLBACK, Ip4OnFrameSentDpc, Context); } @@ -936,28 +1038,31 @@ Returns: If some error happened, the CallBack won't be called. So, the caller must test the return value, and take action when there is an error. - @param Interface The interface to send the frame from - @param IpInstance The IP child that request the transmission. NULL + @param[in] Interface The interface to send the frame from + @param[in] IpInstance The IP child that request the transmission. NULL if it is the IP4 driver itself. - @param Packet The packet to transmit. - @param NextHop The immediate destination to transmit the packet + @param[in] Packet The packet to transmit. + @param[in] NextHop The immediate destination to transmit the packet to. - @param CallBack Function to call back when transmit finished. - @param Context Opaque parameter to the call back. + @param[in] CallBack Function to call back when transmit finished. + @param[in] Context Opaque parameter to the call back. + @param[in] IpSb The pointer to the IP4 service binding instance. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to send the frame @retval EFI_NO_MAPPING Can't resolve the MAC for the nexthop @retval EFI_SUCCESS The packet is successfully transmitted. + @retval other Other error occurs. **/ EFI_STATUS Ip4SendFrame ( IN IP4_INTERFACE *Interface, - IN IP4_PROTOCOL *IpInstance, OPTIONAL + IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN IP4_ADDR NextHop, IN IP4_FRAME_CALLBACK CallBack, - IN VOID *Context + IN VOID *Context, + IN IP4_SERVICE *IpSb ) { IP4_LINK_TX_TOKEN *Token; @@ -968,7 +1073,7 @@ Ip4SendFrame ( ASSERT (Interface->Configured); - Token = Ip4WrapLinkTxToken (Interface, IpInstance, Packet, CallBack, Context); + Token = Ip4WrapLinkTxToken (Interface, IpInstance, Packet, CallBack, Context, IpSb); if (Token == NULL) { return EFI_OUT_OF_RESOURCES; @@ -1067,7 +1172,7 @@ SEND_NOW: InsertTailList (&Interface->SentFrames, &Token->Link); Status = Interface->Mnp->Transmit (Interface->Mnp, &Token->MnpToken); if (EFI_ERROR (Status)) { - RemoveEntryList (&Interface->SentFrames); + RemoveEntryList (&Token->Link); goto ON_ERROR; } @@ -1083,13 +1188,11 @@ ON_ERROR: Call back function when the received packet is freed. Check Ip4OnFrameReceived for information. - @param Context Context, which is the IP4_LINK_RX_TOKEN. - - @return None. + @param Context Context, which is the IP4_LINK_RX_TOKEN. **/ -STATIC VOID +EFIAPI Ip4RecycleFrame ( IN VOID *Context ) @@ -1114,10 +1217,7 @@ Ip4RecycleFrame ( @param Context Context for the callback. - @return None. - **/ -STATIC VOID EFIAPI Ip4OnFrameReceivedDpc ( @@ -1175,55 +1275,46 @@ Ip4OnFrameReceivedDpc ( Token->CallBack (Token->IpInstance, Packet, EFI_SUCCESS, Flag, Token->Context); } -STATIC +/** + Request Ip4OnFrameReceivedDpc as a DPC at TPL_CALLBACK. + + @param Event The receive event delivered to MNP for receive. + @param Context Context for the callback. + +**/ VOID EFIAPI Ip4OnFrameReceived ( IN EFI_EVENT Event, IN VOID *Context ) -/*++ - -Routine Description: - - Request Ip4OnFrameReceivedDpc as a DPC at TPL_CALLBACK - -Arguments: - - Event - The receive event delivered to MNP for receive. - Context - Context for the callback. - -Returns: - - None. - ---*/ { // // Request Ip4OnFrameReceivedDpc as a DPC at TPL_CALLBACK // - NetLibQueueDpc (TPL_CALLBACK, Ip4OnFrameReceivedDpc, Context); + QueueDpc (TPL_CALLBACK, Ip4OnFrameReceivedDpc, Context); } /** Request to receive the packet from the interface. - @param Interface The interface to receive the frames from - @param IpInstance The instance that requests the receive. NULL for + @param[in] Interface The interface to receive the frames from. + @param[in] IpInstance The instance that requests the receive. NULL for the driver itself. - @param CallBack Function to call when receive finished. - @param Context Opaque parameter to the callback + @param[in] CallBack Function to call when receive finished. + @param[in] Context Opaque parameter to the callback. @retval EFI_ALREADY_STARTED There is already a pending receive request. - @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to receive + @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to receive. @retval EFI_SUCCESS The recieve request has been started. + @retval other Other error occurs. **/ EFI_STATUS Ip4ReceiveFrame ( IN IP4_INTERFACE *Interface, - IN IP4_PROTOCOL *IpInstance, OPTIONAL + IN IP4_PROTOCOL *IpInstance OPTIONAL, IN IP4_FRAME_CALLBACK CallBack, IN VOID *Context )