X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4If.c;h=dd2674d22400e11f05daef17db7aebde7ff872e9;hp=5e121a5dcf5f62d6603ad070c867fb75fc3e2c24;hb=894d038a8d0e99d456042e2b6d1554c4a406ea70;hpb=2a86ff1cb089d7fb1589e1da54ea880721371000 diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c index 5e121a5dcf..dd2674d224 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c @@ -1,6 +1,7 @@ /** @file - -Copyright (c) 2005 - 2007, Intel Corporation + Implement IP4 pesudo interface. + +Copyright (c) 2005 - 2009, 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 @@ -9,16 +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: - - Ip4If.c - -Abstract: - - Implement IP4 pesudo interface. - - **/ #include "Ip4Impl.h" @@ -27,31 +18,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. + + @param[in] Context Context which is point to the token. -STATIC +**/ 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 +77,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,22 +131,22 @@ 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. - @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 @@ -170,12 +214,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 @@ -191,14 +232,13 @@ Ip4FreeLinkTxToken ( /** 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, @@ -243,14 +283,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, @@ -272,16 +309,15 @@ Ip4FreeArpQue ( /** 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, @@ -330,12 +366,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 @@ -353,21 +386,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 +423,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' + @param[in] Interface Interface to remove the frames from + @param[in] IoStatus The transmit status returned to the frames' callback - @param FrameToCancel Function to select the frame to cancel, NULL to + @param[in] FrameToCancel Function to select the frame to cancel, NULL to select all - @param Context Opaque parameters passed to FrameToCancel - - @return NONE + @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 +475,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 + @param[in] Mnp The shared MNP child of this IP4 service binding instance - @param Controller The controller 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. @@ -514,9 +542,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,9 +553,9 @@ 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; @@ -554,7 +582,7 @@ Ip4SetAddress ( Type = NetGetIpClass (IpAddr); Len = NetGetMaskLength (SubnetMask); - Netmask = gIp4AllMasks[MIN (Len, Type << 3)]; + Netmask = gIp4AllMasks[MIN ((Len - 1), Type << 3)]; Interface->NetBrdcast = (IpAddr | ~Netmask); // @@ -627,10 +655,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 +666,6 @@ ON_ERROR: @retval FALSE The frame doesn't belong to this instance. **/ -STATIC BOOLEAN Ip4CancelInstanceFrame ( IN IP4_LINK_TX_TOKEN *Frame, @@ -663,9 +690,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 +719,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. @@ -760,13 +785,10 @@ Ip4FreeInterface ( 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 ( @@ -831,29 +853,20 @@ Ip4OnArpResolvedDpc ( Ip4FreeArpQue (ArpQue, EFI_SUCCESS); } -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 @@ -867,12 +880,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,29 +907,19 @@ 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 @@ -936,24 +936,25 @@ 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. @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, @@ -1083,12 +1084,9 @@ 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 Ip4RecycleFrame ( IN VOID *Context @@ -1114,10 +1112,7 @@ Ip4RecycleFrame ( @param Context Context for the callback. - @return None. - **/ -STATIC VOID EFIAPI Ip4OnFrameReceivedDpc ( @@ -1175,29 +1170,19 @@ 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 @@ -1209,21 +1194,22 @@ Returns: /** 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_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 )