X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4Impl.c;h=b0f597fc9754c13d550d6243adf8259089c0f69a;hp=e617d3de80a44f22fc6a5528b527c80482e4a851;hb=1f6729ffe98095107ce82e67a4a0209674601a90;hpb=687a2e5f6902fa26c7a1d7a7705e0747c4095125 diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c index e617d3de80..b0f597fc97 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c @@ -1,7 +1,7 @@ /** @file -Copyright (c) 2005 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2005 - 2015, 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,40 +9,367 @@ 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. +**/ + +#include "Ip4Impl.h" -Module Name: +EFI_IPSEC2_PROTOCOL *mIpSec = NULL; - Ip4Impl.c +/** + Gets the current operational settings for this instance of the EFI IPv4 Protocol driver. + + The GetModeData() function returns the current operational mode data for this + driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This + function is used optionally to retrieve the operational mode data of underlying + networks or drivers. -Abstract: + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure. + @param[out] MnpConfigData Pointer to the managed network configuration data structure. + @param[out] SnpModeData Pointer to the simple network mode data structure. + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated. **/ +EFI_STATUS +EFIAPI +EfiIp4GetModeData ( + IN CONST EFI_IP4_PROTOCOL *This, + OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL, + OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, + OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL + ); -#include "Ip4Impl.h" +/** + Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance. + + The Configure() function is used to set, change, or reset the operational + parameters and filter settings for this EFI IPv4 Protocol instance. Until these + parameters have been set, no network traffic can be sent or received by this + instance. Once the parameters have been reset (by calling this function with + IpConfigData set to NULL), no more traffic can be sent or received until these + parameters have been set again. Each EFI IPv4 Protocol instance can be started + and stopped independently of each other by enabling or disabling their receive + filter settings with the Configure() function. + + When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will + be appended as an alias address into the addresses list in the EFI IPv4 Protocol + driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL + to retrieve the default IPv4 address if it is not available yet. Clients could + frequently call GetModeData() to check the status to ensure that the default IPv4 + address is ready. + + If operational parameters are reset or changed, any pending transmit and receive + requests will be cancelled. Their completion token status will be set to EFI_ABORTED + and their events will be signaled. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure. + + @retval EFI_SUCCESS The driver instance was successfully opened. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE: + A configuration protocol (DHCP, BOOTP, RARP, etc.) could + not be located when clients choose to use the default IPv4 + address. This EFI IPv4 Protocol implementation does not + support this requested filter or timeout setting. + @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated. + @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the + IPv4 address or subnet mask can be changed. The interface must + also be stopped when switching to/from raw packet mode. + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4 + Protocol driver instance is not opened. +**/ +EFI_STATUS +EFIAPI +EfiIp4Configure ( + IN EFI_IP4_PROTOCOL *This, + IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL + ); /** - Get the IP child's current operational data. This can - all be used to get the underlying MNP and SNP data. + Joins and leaves multicast groups. + + The Groups() function is used to join and leave multicast group sessions. Joining + a group will enable reception of matching multicast packets. Leaving a group will + disable the multicast packet reception. + + If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave. + @param[in] GroupAddress Pointer to the IPv4 multicast address. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER One or more of the following is TRUE: + - This is NULL. + - JoinFlag is TRUE and GroupAddress is NULL. + - GroupAddress is not NULL and *GroupAddress is + not a multicast IPv4 address. + @retval EFI_NOT_STARTED This instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_OUT_OF_RESOURCES System resources could not be allocated. + @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups. + @retval EFI_ALREADY_STARTED The group address is already in the group table (when + JoinFlag is TRUE). + @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE). + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. - @param This The IP4 protocol instance - @param Ip4ModeData The IP4 operation data - @param MnpConfigData The MNP configure data - @param SnpModeData The SNP operation data +**/ +EFI_STATUS +EFIAPI +EfiIp4Groups ( + IN EFI_IP4_PROTOCOL *This, + IN BOOLEAN JoinFlag, + IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL + ); + +/** + Adds and deletes routing table entries. + + The Routes() function adds a route to or deletes a route from the routing table. + + Routes are determined by comparing the SubnetAddress with the destination IPv4 + address arithmetically AND-ed with the SubnetMask. The gateway address must be + on the same subnet as the configured station address. + + The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0. + The default route matches all destination IPv4 addresses that do not match any + other routes. + + A GatewayAddress that is zero is a nonroute. Packets are sent to the destination + IP address if it can be found in the ARP cache or on the local subnet. One automatic + nonroute entry will be inserted into the routing table for outgoing packets that + are addressed to a local subnet (gateway address of 0.0.0.0). + + Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI + IPv4 Protocol instances that use the default IPv4 address will also have copies + of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these + copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its + instances. As a result, client modification to the routing table will be lost. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to + FALSE to add this route to the routing table. SubnetAddress + and SubnetMask are used as the key to each route entry. + @param[in] SubnetAddress The address of the subnet that needs to be routed. + @param[in] SubnetMask The subnet mask of SubnetAddress. + @param[in] GatewayAddress The unicast gateway IPv4 address for this route. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_NOT_STARTED The driver instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + - This is NULL. + - SubnetAddress is NULL. + - SubnetMask is NULL. + - GatewayAddress is NULL. + - *SubnetAddress is not a valid subnet address. + - *SubnetMask is not a valid subnet mask. + - *GatewayAddress is not a valid unicast IPv4 address. + @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table. + @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE). + @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when + DeleteRoute is FALSE). - @retval EFI_INVALID_PARAMETER The parameter is invalid because This == NULL - @retval EFI_SUCCESS The operational parameter is returned. - @retval Others Failed to retrieve the IP4 route table. +**/ +EFI_STATUS +EFIAPI +EfiIp4Routes ( + IN EFI_IP4_PROTOCOL *This, + IN BOOLEAN DeleteRoute, + IN EFI_IPv4_ADDRESS *SubnetAddress, + IN EFI_IPv4_ADDRESS *SubnetMask, + IN EFI_IPv4_ADDRESS *GatewayAddress + ); + +/** + Places outgoing data packets into the transmit queue. + + The Transmit() function places a sending request in the transmit queue of this + EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some + errors occur, the event in the token will be signaled and the status is updated. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] Token Pointer to the transmit token. + + @retval EFI_SUCCESS The data has been queued for transmission. + @retval EFI_NOT_STARTED This instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER One or more pameters are invalid. + @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event + was already in the transmit queue. + @retval EFI_NOT_READY The completion token could not be queued because the transmit + queue is full. + @retval EFI_NOT_FOUND Not route is found to destination address. + @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data. + @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too + short to transmit. + @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is + greater than MTU (or greater than the maximum packet size if + Token.Packet.TxData.OverrideData. + DoNotFragment is TRUE.) + +**/ +EFI_STATUS +EFIAPI +EfiIp4Transmit ( + IN EFI_IP4_PROTOCOL *This, + IN EFI_IP4_COMPLETION_TOKEN *Token + ); + +/** + Places a receiving request into the receiving queue. + + The Receive() function places a completion token into the receive packet queue. + This function is always asynchronous. + + The Token.Event field in the completion token must be filled in by the caller + and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol + driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event + is signaled. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] Token Pointer to a token that is associated with the receive data descriptor. + + @retval EFI_SUCCESS The receive completion token was cached. + @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.) + is not finished yet. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + - This is NULL. + - Token is NULL. + - Token.Event is NULL. + @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system + resources (usually memory). + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. + The EFI IPv4 Protocol instance has been reset to startup defaults. + EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already + in the receive queue. + @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full. + @retval EFI_ICMP_ERROR An ICMP error packet was received. + +**/ +EFI_STATUS +EFIAPI +EfiIp4Receive ( + IN EFI_IP4_PROTOCOL *This, + IN EFI_IP4_COMPLETION_TOKEN *Token + ); + +/** + Abort an asynchronous transmit or receive request. + + The Cancel() function is used to abort a pending transmit or receive request. + If the token is in the transmit or receive request queues, after calling this + function, Token->Status will be set to EFI_ABORTED and then Token->Event will + be signaled. If the token is not in one of the queues, which usually means the + asynchronous operation has completed, this function will not signal the token + and EFI_NOT_FOUND is returned. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] Token Pointer to a token that has been issued by + EFI_IP4_PROTOCOL.Transmit() or + EFI_IP4_PROTOCOL.Receive(). If NULL, all pending + tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is + defined in EFI_IP4_PROTOCOL.Transmit(). + + @retval EFI_SUCCESS The asynchronous I/O request was aborted and + Token.->Event was signaled. When Token is NULL, all + pending requests were aborted and their events were signaled. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_NOT_STARTED This instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was + not found in the transmit or receive queue. It has either completed + or was not issued by Transmit() and Receive(). + +**/ +EFI_STATUS +EFIAPI +EfiIp4Cancel ( + IN EFI_IP4_PROTOCOL *This, + IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL + ); + +/** + Polls for incoming data packets and processes outgoing data packets. + + The Poll() function polls for incoming data packets and processes outgoing data + packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll() + function to increase the rate that data packets are moved between the communications + device and the transmit and receive queues. + + In some systems the periodic timer event may not poll the underlying communications + device fast enough to transmit and/or receive all data packets without missing + incoming packets or dropping outgoing packets. Drivers and applications that are + experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function + more often. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + + @retval EFI_SUCCESS Incoming or outgoing data was processed. + @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. + @retval EFI_NOT_READY No incoming or outgoing data is processed. + @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue. + Consider increasing the polling rate. + +**/ +EFI_STATUS +EFIAPI +EfiIp4Poll ( + IN EFI_IP4_PROTOCOL *This + ); + +EFI_IP4_PROTOCOL +mEfiIp4ProtocolTemplete = { + EfiIp4GetModeData, + EfiIp4Configure, + EfiIp4Groups, + EfiIp4Routes, + EfiIp4Transmit, + EfiIp4Receive, + EfiIp4Cancel, + EfiIp4Poll +}; + +/** + Gets the current operational settings for this instance of the EFI IPv4 Protocol driver. + + The GetModeData() function returns the current operational mode data for this + driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This + function is used optionally to retrieve the operational mode data of underlying + networks or drivers. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[out] Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure. + @param[out] MnpConfigData Pointer to the managed network configuration data structure. + @param[out] SnpModeData Pointer to the simple network mode data structure. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated. **/ -STATIC EFI_STATUS EFIAPI EfiIp4GetModeData ( IN CONST EFI_IP4_PROTOCOL *This, - OUT EFI_IP4_MODE_DATA *Ip4ModeData, OPTIONAL - OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL + OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL, + OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL ) { @@ -57,7 +384,7 @@ EfiIp4GetModeData ( return EFI_INVALID_PARAMETER; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This); IpSb = IpInstance->Service; @@ -79,6 +406,8 @@ EfiIp4GetModeData ( Ip4ModeData->RouteTable = NULL; Ip4ModeData->RouteCount = 0; + Ip4ModeData->MaxPacketSize = IpSb->MaxPacketSize; + // // return the current station address for this IP child. So, // the user can get the default address through this. Some @@ -89,10 +418,10 @@ EfiIp4GetModeData ( Config = &Ip4ModeData->ConfigData; Ip = HTONL (IpInstance->Interface->Ip); - NetCopyMem (&Config->StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Config->StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS)); Ip = HTONL (IpInstance->Interface->SubnetMask); - NetCopyMem (&Config->SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS)); + CopyMem (&Config->SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS)); Ip4ModeData->IsConfigured = IpInstance->Interface->Configured; @@ -102,7 +431,7 @@ EfiIp4GetModeData ( Status = Ip4BuildEfiRouteTable (IpInstance); if (EFI_ERROR (Status)) { - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } @@ -111,16 +440,13 @@ EfiIp4GetModeData ( } } - if (MnpConfigData != NULL) { - CopyMem (MnpConfigData, &IpSb->MnpConfigData, sizeof (*MnpConfigData)); - } - - if (SnpModeData != NULL) { - CopyMem (SnpModeData, &IpSb->SnpMode, sizeof (*SnpModeData)); - } + // + // Get fresh mode data from MNP, since underlying media status may change + // + Status = IpSb->Mnp->GetModeData (IpSb->Mnp, MnpConfigData, SnpModeData); - NET_RESTORE_TPL (OldTpl); - return EFI_SUCCESS; + gBS->RestoreTPL (OldTpl); + return Status; } @@ -129,14 +455,14 @@ EfiIp4GetModeData ( child to transmit/receive frames. By default, it configures MNP to receive unicast/multicast/broadcast. And it will enable/disable the promiscous receive according to whether there is IP child - enable that or not. If Force isn't false, it will iterate through + enable that or not. If Force is FALSE, it will iterate through all the IP children to check whether the promiscuous receive setting has been changed. If it hasn't been changed, it won't - reconfigure the MNP. If Force is true, the MNP is configured no + reconfigure the MNP. If Force is TRUE, the MNP is configured no matter whether that is changed or not. - @param IpSb The IP4 service instance that is to be changed. - @param Force Force the configuration or not. + @param[in] IpSb The IP4 service instance that is to be changed. + @param[in] Force Force the configuration or not. @retval EFI_SUCCESS The MNP is successfully configured/reconfigured. @retval Others Configuration failed. @@ -148,8 +474,8 @@ Ip4ServiceConfigMnp ( IN BOOLEAN Force ) { - NET_LIST_ENTRY *Entry; - NET_LIST_ENTRY *ProtoEntry; + LIST_ENTRY *Entry; + LIST_ENTRY *ProtoEntry; IP4_INTERFACE *IpIf; IP4_PROTOCOL *IpInstance; BOOLEAN Reconfig; @@ -204,302 +530,48 @@ Ip4ServiceConfigMnp ( } -/** - The event handle for IP4 auto configuration. If IP is asked - to reconfigure the default address. The original default - interface and route table are removed as the default. If there - is active IP children using the default address, the interface - will remain valid until all the children have freed their - references. If IP is signalled when auto configuration is done, - it will configure the default interface and default route table - with the configuration information retrieved by IP4_CONFIGURE. - - @param Event The event that is signalled. - @param Context The IP4 service binding instance. - - @return None - -**/ -VOID -EFIAPI -Ip4AutoConfigCallBack ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - EFI_IP4_CONFIG_PROTOCOL *Ip4Config; - EFI_IP4_IPCONFIG_DATA *Data; - EFI_IP4_ROUTE_TABLE *RouteEntry; - IP4_SERVICE *IpSb; - IP4_ROUTE_TABLE *RouteTable; - IP4_INTERFACE *IpIf; - EFI_STATUS Status; - UINTN Len; - UINT32 Index; - - IpSb = (IP4_SERVICE *) Context; - NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE); - - Ip4Config = IpSb->Ip4Config; - - // - // IP is asked to do the reconfiguration. If the default interface - // has been configured, release the default interface and route - // table, then create a new one. If there are some IP children - // using it, the interface won't be physically freed until all the - // children have released their reference to it. Also remember to - // restart the receive on the default address. IP4 driver only receive - // frames on the default address, and when the default interface is - // freed, Ip4AcceptFrame won't be informed. - // - if (Event == IpSb->ReconfigEvent) { - - if (IpSb->DefaultInterface->Configured) { - IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image); - - if (IpIf == NULL) { - return; - } - - RouteTable = Ip4CreateRouteTable (); - - if (RouteTable == NULL) { - Ip4FreeInterface (IpIf, NULL); - return; - } - - Ip4CancelReceive (IpSb->DefaultInterface); - Ip4FreeInterface (IpSb->DefaultInterface, NULL); - Ip4FreeRouteTable (IpSb->DefaultRouteTable); - - IpSb->DefaultInterface = IpIf; - NetListInsertHead (&IpSb->Interfaces, &IpIf->Link); - - IpSb->DefaultRouteTable = RouteTable; - Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb); - } - - Ip4Config->Stop (Ip4Config); - Ip4Config->Start (Ip4Config, IpSb->DoneEvent, IpSb->ReconfigEvent); - return ; - } - - // - // Get the configure data in two steps: get the length then the data. - // - Len = 0; - - if (Ip4Config->GetData (Ip4Config, &Len, NULL) != EFI_BUFFER_TOO_SMALL) { - return ; - } - - Data = NetAllocatePool (Len); - - if (Data == NULL) { - return ; - } - - Status = Ip4Config->GetData (Ip4Config, &Len, Data); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - IpIf = IpSb->DefaultInterface; - - // - // If the default address has been configured don't change it. - // This is unlikely to happen if EFI_IP4_CONFIG protocol has - // informed us to reconfigure each time it wants to change the - // configuration parameters. - // - if (IpIf->Configured) { - goto ON_EXIT; - } - - // - // Set the default interface's address, then add a directed - // route for it, that is, the route whose nexthop is zero. - // - Status = Ip4SetAddress ( - IpIf, - EFI_NTOHL (Data->StationAddress), - EFI_NTOHL (Data->SubnetMask) - ); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - Ip4AddRoute ( - IpSb->DefaultRouteTable, - EFI_NTOHL (Data->StationAddress), - EFI_NTOHL (Data->SubnetMask), - IP4_ALLZERO_ADDRESS - ); - - // - // Add routes returned by EFI_IP4_CONFIG protocol. - // - for (Index = 0; Index < Data->RouteTableSize; Index++) { - RouteEntry = &Data->RouteTable[Index]; - - Ip4AddRoute ( - IpSb->DefaultRouteTable, - EFI_NTOHL (RouteEntry->SubnetAddress), - EFI_NTOHL (RouteEntry->SubnetMask), - EFI_NTOHL (RouteEntry->GatewayAddress) - ); - } - - IpSb->State = IP4_SERVICE_CONFIGED; - - Ip4SetVariableData (IpSb); - -ON_EXIT: - NetFreePool (Data); -} - - -/** - Start the auto configuration for this IP service instance. - It will locates the EFI_IP4_CONFIG_PROTOCOL, then start the - auto configuration. - - @param IpSb The IP4 service instance to configure - - @retval EFI_SUCCESS The auto configuration is successfull started - @retval Others Failed to start auto configuration. - -**/ -EFI_STATUS -Ip4StartAutoConfig ( - IN IP4_SERVICE *IpSb - ) -{ - EFI_IP4_CONFIG_PROTOCOL *Ip4Config; - EFI_STATUS Status; - - if (IpSb->State > IP4_SERVICE_UNSTARTED) { - return EFI_SUCCESS; - } - - // - // Create the DoneEvent and ReconfigEvent to call EFI_IP4_CONFIG - // - Status = gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - NET_TPL_LOCK, - Ip4AutoConfigCallBack, - IpSb, - &IpSb->DoneEvent - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - Status = gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, - Ip4AutoConfigCallBack, - IpSb, - &IpSb->ReconfigEvent - ); - - if (EFI_ERROR (Status)) { - goto CLOSE_DONE_EVENT; - } - - // - // Open the EFI_IP4_CONFIG protocol then start auto configure - // - Status = gBS->OpenProtocol ( - IpSb->Controller, - &gEfiIp4ConfigProtocolGuid, - (VOID **) &Ip4Config, - IpSb->Image, - IpSb->Controller, - EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE - ); - - if (EFI_ERROR (Status)) { - Status = EFI_UNSUPPORTED; - goto CLOSE_RECONFIG_EVENT; - } - - Status = Ip4Config->Start (Ip4Config, IpSb->DoneEvent, IpSb->ReconfigEvent); - - if (EFI_ERROR (Status)) { - gBS->CloseProtocol ( - IpSb->Controller, - &gEfiIp4ConfigProtocolGuid, - IpSb->Image, - IpSb->Controller - ); - - goto CLOSE_RECONFIG_EVENT; - } - - IpSb->Ip4Config = Ip4Config; - IpSb->State = IP4_SERVICE_STARTED; - return Status; - -CLOSE_RECONFIG_EVENT: - gBS->CloseEvent (IpSb->ReconfigEvent); - IpSb->ReconfigEvent = NULL; - -CLOSE_DONE_EVENT: - gBS->CloseEvent (IpSb->DoneEvent); - IpSb->DoneEvent = NULL; - - return Status; -} - - /** Intiialize the IP4_PROTOCOL structure to the unconfigured states. @param IpSb The IP4 service instance. @param IpInstance The IP4 child instance. - @return None - **/ VOID Ip4InitProtocol ( - IN IP4_SERVICE *IpSb, - IN IP4_PROTOCOL *IpInstance + IN IP4_SERVICE *IpSb, + IN OUT IP4_PROTOCOL *IpInstance ) { ASSERT ((IpSb != NULL) && (IpInstance != NULL)); - NetZeroMem (IpInstance, sizeof (IP4_PROTOCOL)); + ZeroMem (IpInstance, sizeof (IP4_PROTOCOL)); IpInstance->Signature = IP4_PROTOCOL_SIGNATURE; CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto)); IpInstance->State = IP4_STATE_UNCONFIGED; IpInstance->Service = IpSb; - NetListInit (&IpInstance->Link); + InitializeListHead (&IpInstance->Link); NetMapInit (&IpInstance->RxTokens); NetMapInit (&IpInstance->TxTokens); - NetListInit (&IpInstance->Received); - NetListInit (&IpInstance->Delivered); - NetListInit (&IpInstance->AddrLink); + InitializeListHead (&IpInstance->Received); + InitializeListHead (&IpInstance->Delivered); + InitializeListHead (&IpInstance->AddrLink); - NET_RECYCLE_LOCK_INIT (&IpInstance->RecycleLock); + EfiInitializeLock (&IpInstance->RecycleLock, TPL_NOTIFY); } + /** Configure the IP4 child. If the child is already configured, change the configuration parameter. Otherwise configure it for the first time. The caller should validate the configuration before deliver them to it. It also don't do configure NULL. - @param IpInstance The IP4 child to configure. - @param Config The configure data. + @param[in, out] IpInstance The IP4 child to configure. + @param[in] Config The configure data. @retval EFI_SUCCESS The IP4 child is successfully configured. @retval EFI_DEVICE_ERROR Failed to free the pending transive or to @@ -508,12 +580,14 @@ Ip4InitProtocol ( address, but the default address hasn't been configured. The IP4 child doesn't need to be reconfigured when default address is configured. + @retval EFI_OUT_OF_RESOURCES No more memory space is available. + @retval other Other error occurs. **/ EFI_STATUS Ip4ConfigProtocol ( - IN IP4_PROTOCOL *IpInstance, - IN EFI_IP4_CONFIG_DATA *Config + IN OUT IP4_PROTOCOL *IpInstance, + IN EFI_IP4_CONFIG_DATA *Config ) { IP4_SERVICE *IpSb; @@ -521,6 +595,7 @@ Ip4ConfigProtocol ( EFI_STATUS Status; IP4_ADDR Ip; IP4_ADDR Netmask; + EFI_ARP_PROTOCOL *Arp; IpSb = IpInstance->Service; @@ -557,8 +632,8 @@ Ip4ConfigProtocol ( // // Set up the interface. // - NetCopyMem (&Ip, &Config->StationAddress, sizeof (IP4_ADDR)); - NetCopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR)); + CopyMem (&Ip, &Config->StationAddress, sizeof (IP4_ADDR)); + CopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR)); Ip = NTOHL (Ip); Netmask = NTOHL (Netmask); @@ -589,7 +664,7 @@ Ip4ConfigProtocol ( goto ON_ERROR; } - NetListInsertTail (&IpSb->Interfaces, &IpIf->Link); + InsertTailList (&IpSb->Interfaces, &IpIf->Link); } // @@ -603,11 +678,8 @@ Ip4ConfigProtocol ( // been started, start it. // if (IpSb->State == IP4_SERVICE_UNSTARTED) { - Status = Ip4StartAutoConfig (IpSb); - - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } + Status = EFI_NO_MAPPING; + goto ON_ERROR; } IpIf = IpSb->DefaultInterface; @@ -625,7 +697,21 @@ Ip4ConfigProtocol ( } IpInstance->Interface = IpIf; - NetListInsertTail (&IpIf->IpInstances, &IpInstance->AddrLink); + if (IpIf->Arp != NULL) { + Arp = NULL; + Status = gBS->OpenProtocol ( + IpIf->ArpHandle, + &gEfiArpProtocolGuid, + (VOID **) &Arp, + gIp4DriverBinding.DriverBindingHandle, + IpInstance->Handle, + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + ); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + } + InsertTailList (&IpIf->IpInstances, &IpInstance->AddrLink); CopyMem (&IpInstance->ConfigData, Config, sizeof (IpInstance->ConfigData)); IpInstance->State = IP4_STATE_CONFIGED; @@ -651,10 +737,10 @@ ON_ERROR: /** Clean up the IP4 child, release all the resources used by it. - @param IpInstance The IP4 child to clean up. + @param[in] IpInstance The IP4 child to clean up. - @retval EFI_SUCCESS The IP4 child is cleaned up - @retval EFI_DEVICE_ERROR Some resources failed to be released + @retval EFI_SUCCESS The IP4 child is cleaned up. + @retval EFI_DEVICE_ERROR Some resources failed to be released. **/ EFI_STATUS @@ -675,12 +761,20 @@ Ip4CleanProtocol ( // user forgets to recycle the packets, or because the callback // hasn't been called. Just leave it alone. // - if (!NetListIsEmpty (&IpInstance->Delivered)) { + if (!IsListEmpty (&IpInstance->Delivered)) { ; } if (IpInstance->Interface != NULL) { - NetListRemoveEntry (&IpInstance->AddrLink); + RemoveEntryList (&IpInstance->AddrLink); + if (IpInstance->Interface->Arp != NULL) { + gBS->CloseProtocol ( + IpInstance->Interface->ArpHandle, + &gEfiArpProtocolGuid, + gIp4DriverBinding.DriverBindingHandle, + IpInstance->Handle + ); + } Ip4FreeInterface (IpInstance->Interface, IpInstance); IpInstance->Interface = NULL; } @@ -695,13 +789,13 @@ Ip4CleanProtocol ( } if (IpInstance->EfiRouteTable != NULL) { - NetFreePool (IpInstance->EfiRouteTable); + FreePool (IpInstance->EfiRouteTable); IpInstance->EfiRouteTable = NULL; IpInstance->EfiRouteCount = 0; } if (IpInstance->Groups != NULL) { - NetFreePool (IpInstance->Groups); + FreePool (IpInstance->Groups); IpInstance->Groups = NULL; IpInstance->GroupCount = 0; } @@ -719,11 +813,11 @@ Ip4CleanProtocol ( address. Only continuous netmasks are supported. and check that StationAddress is a unicast address on the newtwork. - @param Ip The IP address to validate - @param Netmask The netmaks of the IP + @param[in] Ip The IP address to validate. + @param[in] Netmask The netmaks of the IP. - @retval TRUE The Ip/Netmask pair is valid - @retval FALSE The + @retval TRUE The Ip/Netmask pair is valid. + @retval FALSE The Ip/Netmask pair is invalid. **/ BOOLEAN @@ -764,7 +858,7 @@ Ip4StationAddressValid ( return FALSE; } - NetBrdcastMask = mIp4AllMasks[NET_MIN (Len, Type << 3)]; + NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)]; if (Ip == (Ip | ~NetBrdcastMask)) { return FALSE; @@ -775,21 +869,48 @@ Ip4StationAddressValid ( /** - Configure the EFI_IP4_PROTOCOL instance. If IpConfigData is NULL, - the instance is cleaned up. If the instance hasn't been configure - before, it will be initialized. Otherwise, the filter setting of - the instance is updated. - - @param This The IP4 child to configure - @param IpConfigData The configuration to apply. If NULL, clean it up. - - @retval EFI_INVALID_PARAMETER The parameter is invalid - @retval EFI_NO_MAPPING The default address hasn't been configured and the - instance wants to use it. - @retval EFI_SUCCESS The instance is configured. + Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance. + + The Configure() function is used to set, change, or reset the operational + parameters and filter settings for this EFI IPv4 Protocol instance. Until these + parameters have been set, no network traffic can be sent or received by this + instance. Once the parameters have been reset (by calling this function with + IpConfigData set to NULL), no more traffic can be sent or received until these + parameters have been set again. Each EFI IPv4 Protocol instance can be started + and stopped independently of each other by enabling or disabling their receive + filter settings with the Configure() function. + + When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will + be appended as an alias address into the addresses list in the EFI IPv4 Protocol + driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL + to retrieve the default IPv4 address if it is not available yet. Clients could + frequently call GetModeData() to check the status to ensure that the default IPv4 + address is ready. + + If operational parameters are reset or changed, any pending transmit and receive + requests will be cancelled. Their completion token status will be set to EFI_ABORTED + and their events will be signaled. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure. + + @retval EFI_SUCCESS The driver instance was successfully opened. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE: + A configuration protocol (DHCP, BOOTP, RARP, etc.) could + not be located when clients choose to use the default IPv4 + address. This EFI IPv4 Protocol implementation does not + support this requested filter or timeout setting. + @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated. + @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the + IPv4 address or subnet mask can be changed. The interface must + also be stopped when switching to/from raw packet mode. + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4 + Protocol driver instance is not opened. **/ -STATIC EFI_STATUS EFIAPI EfiIp4Configure ( @@ -813,23 +934,15 @@ EfiIp4Configure ( } IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This); - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); // // Validate the configuration first. // if (IpConfigData != NULL) { - // - // This implementation doesn't support RawData - // - if (IpConfigData->RawData) { - Status = EFI_UNSUPPORTED; - goto ON_EXIT; - } - - NetCopyMem (&IpAddress, &IpConfigData->StationAddress, sizeof (IP4_ADDR)); - NetCopyMem (&SubnetMask, &IpConfigData->SubnetMask, sizeof (IP4_ADDR)); + CopyMem (&IpAddress, &IpConfigData->StationAddress, sizeof (IP4_ADDR)); + CopyMem (&SubnetMask, &IpConfigData->SubnetMask, sizeof (IP4_ADDR)); IpAddress = NTOHL (IpAddress); SubnetMask = NTOHL (SubnetMask); @@ -860,14 +973,15 @@ EfiIp4Configure ( } if (!Current->UseDefaultAddress && - (!EFI_IP4_EQUAL (Current->StationAddress, IpConfigData->StationAddress) || - !EFI_IP4_EQUAL (Current->SubnetMask, IpConfigData->SubnetMask))) { + (!EFI_IP4_EQUAL (&Current->StationAddress, &IpConfigData->StationAddress) || + !EFI_IP4_EQUAL (&Current->SubnetMask, &IpConfigData->SubnetMask))) { Status = EFI_ALREADY_STARTED; goto ON_EXIT; } if (Current->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) { - return EFI_NO_MAPPING; + Status = EFI_NO_MAPPING; + goto ON_EXIT; } } } @@ -881,7 +995,7 @@ EfiIp4Configure ( Status = Ip4CleanProtocol (IpInstance); // - // Don't change the state if it is DESTORY, consider the following + // Don't change the state if it is DESTROY, consider the following // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped, // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED, // the unload fails miserably. @@ -897,13 +1011,8 @@ EfiIp4Configure ( // Ip4ServiceConfigMnp (IpInstance->Service, FALSE); - // - // Update the variable data. - // - Ip4SetVariableData (IpInstance->Service); - ON_EXIT: - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } @@ -913,13 +1022,13 @@ ON_EXIT: Change the IP4 child's multicast setting. The caller should make sure that the parameters is valid. - @param IpInstance The IP4 child to change the setting. - @param JoinFlag TRUE to join the group, otherwise leave it - @param GroupAddress The target group address + @param[in] IpInstance The IP4 child to change the setting. + @param[in] JoinFlag TRUE to join the group, otherwise leave it. + @param[in] GroupAddress The target group address. - @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it + @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it. @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources. - @retval EFI_DEVICE_ERROR Failed to set the group configuraton + @retval EFI_DEVICE_ERROR Failed to set the group configuraton. @retval EFI_SUCCESS Successfully updated the group setting. @retval EFI_NOT_FOUND Try to leave the group which it isn't a member. @@ -941,7 +1050,11 @@ Ip4Groups ( // host byte order // if (JoinFlag) { - NetCopyMem (&Group, GroupAddress, sizeof (IP4_ADDR)); + // + // When JoinFlag is TRUE, GroupAddress shouldn't be NULL. + // + ASSERT (GroupAddress != NULL); + CopyMem (&Group, GroupAddress, sizeof (IP4_ADDR)); for (Index = 0; Index < IpInstance->GroupCount; Index++) { if (IpInstance->Groups[Index] == Group) { @@ -956,12 +1069,12 @@ Ip4Groups ( } if (EFI_ERROR (Ip4JoinGroup (IpInstance, NTOHL (Group)))) { - NetFreePool (Members); + FreePool (Members); return EFI_DEVICE_ERROR; } if (IpInstance->Groups != NULL) { - NetFreePool (IpInstance->Groups); + FreePool (IpInstance->Groups); } IpInstance->Groups = Members; @@ -978,7 +1091,7 @@ Ip4Groups ( for (Index = IpInstance->GroupCount; Index > 0 ; Index--) { Group = IpInstance->Groups[Index - 1]; - if ((GroupAddress == NULL) || EFI_IP4_EQUAL (Group, *GroupAddress)) { + if ((GroupAddress == NULL) || EFI_IP4_EQUAL (&Group, GroupAddress)) { if (EFI_ERROR (Ip4LeaveGroup (IpInstance, NTOHL (Group)))) { return EFI_DEVICE_ERROR; } @@ -989,7 +1102,7 @@ Ip4Groups ( if (IpInstance->GroupCount == 0) { ASSERT (Index == 1); - NetFreePool (IpInstance->Groups); + FreePool (IpInstance->Groups); IpInstance->Groups = NULL; } @@ -1004,21 +1117,35 @@ Ip4Groups ( /** - Change the IP4 child's multicast setting. If JoinFlag is true, - the child wants to join the group. Otherwise it wants to leave - the group. If JoinFlag is false, and GroupAddress is NULL, - it will leave all the groups which is a member. - - @param This The IP4 child to change the setting. - @param JoinFlag TRUE to join the group, otherwise leave it. - @param GroupAddress The target group address - - @retval EFI_INVALID_PARAMETER The parameters are invalid - @retval EFI_SUCCESS The group setting has been changed. - @retval Otherwise It failed to change the setting. + Joins and leaves multicast groups. + + The Groups() function is used to join and leave multicast group sessions. Joining + a group will enable reception of matching multicast packets. Leaving a group will + disable the multicast packet reception. + + If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] JoinFlag Set to TRUE to join the multicast group session and FALSE to leave. + @param[in] GroupAddress Pointer to the IPv4 multicast address. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER One or more of the following is TRUE: + - This is NULL. + - JoinFlag is TRUE and GroupAddress is NULL. + - GroupAddress is not NULL and *GroupAddress is + not a multicast IPv4 address. + @retval EFI_NOT_STARTED This instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_OUT_OF_RESOURCES System resources could not be allocated. + @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups. + @retval EFI_ALREADY_STARTED The group address is already in the group table (when + JoinFlag is TRUE). + @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE). + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. **/ -STATIC EFI_STATUS EFIAPI EfiIp4Groups ( @@ -1037,7 +1164,7 @@ EfiIp4Groups ( } if (GroupAddress != NULL) { - NetCopyMem (&McastIp, GroupAddress, sizeof (IP4_ADDR)); + CopyMem (&McastIp, GroupAddress, sizeof (IP4_ADDR)); if (!IP4_IS_MULTICAST (NTOHL (McastIp))) { return EFI_INVALID_PARAMETER; @@ -1045,7 +1172,7 @@ EfiIp4Groups ( } IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This); - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (IpInstance->State != IP4_STATE_CONFIGED) { Status = EFI_NOT_STARTED; @@ -1060,27 +1187,61 @@ EfiIp4Groups ( Status = Ip4Groups (IpInstance, JoinFlag, GroupAddress); ON_EXIT: - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } /** - Modify the IP child's route table. Each instance has its own - route table. - - @param This The IP4 child to modify the route - @param DeleteRoute TRUE to delete the route, otherwise add it - @param SubnetAddress The destination network - @param SubnetMask The destination network's mask - @param GatewayAddress The next hop address. - - @retval EFI_INVALID_PARAMETER The parameter is invalid. - @retval EFI_SUCCESS The route table is successfully modified. - @retval Others Failed to modify the route table + Adds and deletes routing table entries. + + The Routes() function adds a route to or deletes a route from the routing table. + + Routes are determined by comparing the SubnetAddress with the destination IPv4 + address arithmetically AND-ed with the SubnetMask. The gateway address must be + on the same subnet as the configured station address. + + The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0. + The default route matches all destination IPv4 addresses that do not match any + other routes. + + A GatewayAddress that is zero is a nonroute. Packets are sent to the destination + IP address if it can be found in the ARP cache or on the local subnet. One automatic + nonroute entry will be inserted into the routing table for outgoing packets that + are addressed to a local subnet (gateway address of 0.0.0.0). + + Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI + IPv4 Protocol instances that use the default IPv4 address will also have copies + of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these + copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its + instances. As a result, client modification to the routing table will be lost. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] DeleteRoute Set to TRUE to delete this route from the routing table. Set to + FALSE to add this route to the routing table. SubnetAddress + and SubnetMask are used as the key to each route entry. + @param[in] SubnetAddress The address of the subnet that needs to be routed. + @param[in] SubnetMask The subnet mask of SubnetAddress. + @param[in] GatewayAddress The unicast gateway IPv4 address for this route. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_NOT_STARTED The driver instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + - This is NULL. + - SubnetAddress is NULL. + - SubnetMask is NULL. + - GatewayAddress is NULL. + - *SubnetAddress is not a valid subnet address. + - *SubnetMask is not a valid subnet mask. + - *GatewayAddress is not a valid unicast IPv4 address. + @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table. + @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE). + @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when + DeleteRoute is FALSE). **/ -STATIC EFI_STATUS EFIAPI EfiIp4Routes ( @@ -1108,7 +1269,7 @@ EfiIp4Routes ( } IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This); - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (IpInstance->State != IP4_STATE_CONFIGED) { Status = EFI_NOT_STARTED; @@ -1120,9 +1281,9 @@ EfiIp4Routes ( goto ON_EXIT; } - NetCopyMem (&Dest, SubnetAddress, sizeof (IP4_ADDR)); - NetCopyMem (&Netmask, SubnetMask, sizeof (IP4_ADDR)); - NetCopyMem (&Nexthop, GatewayAddress, sizeof (IP4_ADDR)); + CopyMem (&Dest, SubnetAddress, sizeof (IP4_ADDR)); + CopyMem (&Netmask, SubnetMask, sizeof (IP4_ADDR)); + CopyMem (&Nexthop, GatewayAddress, sizeof (IP4_ADDR)); Dest = NTOHL (Dest); Netmask = NTOHL (Netmask); @@ -1153,27 +1314,27 @@ EfiIp4Routes ( } ON_EXIT: - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } /** Check whether the user's token or event has already - been enqueue on IP4's list. + been enqueued on IP4's list. - @param Map The container of either user's transmit or receive - token. - @param Item Current item to check against - @param Context The Token to check againist. + @param[in] Map The container of either user's transmit or receive + token. + @param[in] Item Current item to check against. + @param[in] Context The Token to check againist. - @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP + @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP. @retval EFI_SUCCESS The current item isn't the same token/event as the context. **/ -STATIC EFI_STATUS +EFIAPI Ip4TokenExist ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1193,23 +1354,23 @@ Ip4TokenExist ( return EFI_SUCCESS; } - /** Validate the user's token against current station address. - @param Token User's token to validate - @param IpIf The IP4 child's interface. + @param[in] Token User's token to validate. + @param[in] IpIf The IP4 child's interface. + @param[in] RawData Set to TRUE to send unformatted packets. - @retval EFI_INVALID_PARAMETER Some parameters are invalid + @retval EFI_INVALID_PARAMETER Some parameters are invalid. @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long. - @retval EFI_SUCCESS The token is OK + @retval EFI_SUCCESS The token is valid. **/ -STATIC EFI_STATUS Ip4TxTokenValid ( IN EFI_IP4_COMPLETION_TOKEN *Token, - IN IP4_INTERFACE *IpIf + IN IP4_INTERFACE *IpIf, + IN BOOLEAN RawData ) { EFI_IP4_TRANSMIT_DATA *TxData; @@ -1227,20 +1388,7 @@ Ip4TxTokenValid ( TxData = Token->Packet.TxData; // - // Check the IP options: no more than 40 bytes and format is OK - // - if (TxData->OptionsLength != 0) { - if ((TxData->OptionsLength > 40) || (TxData->OptionsBuffer == NULL)) { - return EFI_INVALID_PARAMETER; - } - - if (!Ip4OptionIsValid (TxData->OptionsBuffer, TxData->OptionsLength, FALSE)) { - return EFI_INVALID_PARAMETER; - } - } - - // - // Check the fragment table: no empty fragment, and length isn't bogus + // Check the fragment table: no empty fragment, and length isn't bogus. // if ((TxData->TotalDataLength == 0) || (TxData->FragmentCount == 0)) { return EFI_INVALID_PARAMETER; @@ -1248,6 +1396,10 @@ Ip4TxTokenValid ( Offset = TxData->TotalDataLength; + if (Offset > IP4_MAX_PACKET_SIZE) { + return EFI_BAD_BUFFER_SIZE; + } + for (Index = 0; Index < TxData->FragmentCount; Index++) { if ((TxData->FragmentTable[Index].FragmentBuffer == NULL) || (TxData->FragmentTable[Index].FragmentLength == 0)) { @@ -1262,15 +1414,36 @@ Ip4TxTokenValid ( return EFI_INVALID_PARAMETER; } + // + // NOTE that OptionsLength/OptionsBuffer/OverrideData are ignored if RawData + // is TRUE. + // + if (RawData) { + return EFI_SUCCESS; + } + + // + // Check the IP options: no more than 40 bytes and format is OK + // + if (TxData->OptionsLength != 0) { + if ((TxData->OptionsLength > 40) || (TxData->OptionsBuffer == NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (!Ip4OptionIsValid (TxData->OptionsBuffer, TxData->OptionsLength, FALSE)) { + return EFI_INVALID_PARAMETER; + } + } + // // Check the source and gateway: they must be a valid unicast. // Gateway must also be on the connected network. // - if (TxData->OverrideData) { + if (TxData->OverrideData != NULL) { Override = TxData->OverrideData; - NetCopyMem (&Src, &Override->SourceAddress, sizeof (IP4_ADDR)); - NetCopyMem (&Gateway, &Override->GatewayAddress, sizeof (IP4_ADDR)); + CopyMem (&Src, &Override->SourceAddress, sizeof (IP4_ADDR)); + CopyMem (&Gateway, &Override->GatewayAddress, sizeof (IP4_ADDR)); Src = NTOHL (Src); Gateway = NTOHL (Gateway); @@ -1328,13 +1501,11 @@ Ip4TxTokenValid ( are bound together. Check the comments in Ip4Output for information about IP fragmentation. - @param Context The token's wrap - - @return None + @param[in] Context The token's wrap. **/ -STATIC VOID +EFIAPI Ip4FreeTxToken ( IN VOID *Context ) @@ -1344,6 +1515,13 @@ Ip4FreeTxToken ( Wrap = (IP4_TXTOKEN_WRAP *) Context; + // + // Signal IpSecRecycleEvent to inform IPsec free the memory + // + if (Wrap->IpSecRecycleSignal != NULL) { + gBS->SignalEvent (Wrap->IpSecRecycleSignal); + } + // // Find the token in the instance's map. EfiIp4Transmit put the // token to the map. If that failed, NetMapFindKey will return NULL. @@ -1356,9 +1534,14 @@ Ip4FreeTxToken ( if (Wrap->Sent) { gBS->SignalEvent (Wrap->Token->Event); + + // + // Dispatch the DPC queued by the NotifyFunction of Token->Event. + // + DispatchDpc (); } - NetFreePool (Wrap); + FreePool (Wrap); } @@ -1366,15 +1549,12 @@ Ip4FreeTxToken ( The callback function to Ip4Output to update the transmit status. @param Ip4Instance The Ip4Instance that request the transmit. - @param Packet The user's transmit request - @param IoStatus The result of the transmission - @param Flag Not used during transmission + @param Packet The user's transmit request. + @param IoStatus The result of the transmission. + @param Flag Not used during transmission. @param Context The token's wrap. - @return None - **/ -STATIC VOID Ip4OnPacketSent ( IP4_PROTOCOL *Ip4Instance, @@ -1407,21 +1587,34 @@ Ip4OnPacketSent ( /** - Transmit the user's data asynchronously. When transmission - completed,the Token's status is updated and its event signalled. - - @param This The IP4 child instance - @param Token The user's transmit token, which contains user's - data, the result and an event to signal when - completed. - - @retval EFI_INVALID_PARAMETER The parameter is invalid. - @retval EFI_NOT_STARTED The IP4 child hasn't been started. - @retval EFI_SUCCESS The user's data has been successfully enqueued - for transmission. + Places outgoing data packets into the transmit queue. + + The Transmit() function places a sending request in the transmit queue of this + EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some + errors occur, the event in the token will be signaled and the status is updated. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] Token Pointer to the transmit token. + + @retval EFI_SUCCESS The data has been queued for transmission. + @retval EFI_NOT_STARTED This instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER One or more pameters are invalid. + @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event + was already in the transmit queue. + @retval EFI_NOT_READY The completion token could not be queued because the transmit + queue is full. + @retval EFI_NOT_FOUND Not route is found to destination address. + @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data. + @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too + short to transmit. + @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is + greater than MTU (or greater than the maximum packet size if + Token.Packet.TxData.OverrideData. + DoNotFragment is TRUE). **/ -STATIC EFI_STATUS EFIAPI EfiIp4Transmit ( @@ -1442,6 +1635,10 @@ EfiIp4Transmit ( EFI_TPL OldTpl; BOOLEAN DontFragment; UINT32 HeadLen; + UINT8 RawHdrLen; + UINT32 OptionsLength; + UINT8 *OptionsBuffer; + VOID *FirstFragment; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -1453,7 +1650,7 @@ EfiIp4Transmit ( return EFI_NOT_STARTED; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); IpSb = IpInstance->Service; IpIf = IpInstance->Interface; @@ -1467,7 +1664,7 @@ EfiIp4Transmit ( // // make sure that token is properly formated // - Status = Ip4TxTokenValid (Token, IpIf); + Status = Ip4TxTokenValid (Token, IpIf, Config->RawData); if (EFI_ERROR (Status)) { goto ON_EXIT; @@ -1487,37 +1684,89 @@ EfiIp4Transmit ( // TxData = Token->Packet.TxData; - NetCopyMem (&Head.Dst, &TxData->DestinationAddress, sizeof (IP4_ADDR)); - Head.Dst = NTOHL (Head.Dst); + FirstFragment = NULL; - if (TxData->OverrideData) { - Override = TxData->OverrideData; - Head.Protocol = Override->Protocol; - Head.Tos = Override->TypeOfService; - Head.Ttl = Override->TimeToLive; - DontFragment = Override->DoNotFragment; + if (Config->RawData) { + // + // When RawData is TRUE, first buffer in FragmentTable points to a raw + // IPv4 fragment including IPv4 header and options. + // + FirstFragment = TxData->FragmentTable[0].FragmentBuffer; + CopyMem (&RawHdrLen, FirstFragment, sizeof (UINT8)); + + RawHdrLen = (UINT8) (RawHdrLen & 0x0f); + if (RawHdrLen < 5) { + Status = EFI_INVALID_PARAMETER; + goto ON_EXIT; + } + + RawHdrLen = (UINT8) (RawHdrLen << 2); + + CopyMem (&Head, FirstFragment, IP4_MIN_HEADLEN); - NetCopyMem (&Head.Src, &Override->SourceAddress, sizeof (IP4_ADDR)); - NetCopyMem (&GateWay, &Override->GatewayAddress, sizeof (IP4_ADDR)); + Ip4NtohHead (&Head); + HeadLen = 0; + DontFragment = IP4_DO_NOT_FRAGMENT (Head.Fragment); - Head.Src = NTOHL (Head.Src); - GateWay = NTOHL (GateWay); + if (!DontFragment) { + Status = EFI_INVALID_PARAMETER; + goto ON_EXIT; + } + + GateWay = IP4_ALLZERO_ADDRESS; + + // + // Get IPv4 options from first fragment. + // + if (RawHdrLen == IP4_MIN_HEADLEN) { + OptionsLength = 0; + OptionsBuffer = NULL; + } else { + OptionsLength = RawHdrLen - IP4_MIN_HEADLEN; + OptionsBuffer = (UINT8 *) FirstFragment + IP4_MIN_HEADLEN; + } + + // + // Trim off IPv4 header and options from first fragment. + // + TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment + RawHdrLen; + TxData->FragmentTable[0].FragmentLength = TxData->FragmentTable[0].FragmentLength - RawHdrLen; } else { - Head.Src = IpIf->Ip; - GateWay = IP4_ALLZERO_ADDRESS; - Head.Protocol = Config->DefaultProtocol; - Head.Tos = Config->TypeOfService; - Head.Ttl = Config->TimeToLive; - DontFragment = Config->DoNotFragment; - } + CopyMem (&Head.Dst, &TxData->DestinationAddress, sizeof (IP4_ADDR)); + Head.Dst = NTOHL (Head.Dst); - Head.Fragment = IP4_HEAD_FRAGMENT_FIELD (DontFragment, FALSE, 0); - HeadLen = sizeof (IP4_HEAD) + ((TxData->OptionsLength + 3) &~0x03); + if (TxData->OverrideData != NULL) { + Override = TxData->OverrideData; + Head.Protocol = Override->Protocol; + Head.Tos = Override->TypeOfService; + Head.Ttl = Override->TimeToLive; + DontFragment = Override->DoNotFragment; + + CopyMem (&Head.Src, &Override->SourceAddress, sizeof (IP4_ADDR)); + CopyMem (&GateWay, &Override->GatewayAddress, sizeof (IP4_ADDR)); + + Head.Src = NTOHL (Head.Src); + GateWay = NTOHL (GateWay); + } else { + Head.Src = IpIf->Ip; + GateWay = IP4_ALLZERO_ADDRESS; + Head.Protocol = Config->DefaultProtocol; + Head.Tos = Config->TypeOfService; + Head.Ttl = Config->TimeToLive; + DontFragment = Config->DoNotFragment; + } + + Head.Fragment = IP4_HEAD_FRAGMENT_FIELD (DontFragment, FALSE, 0); + HeadLen = (TxData->OptionsLength + 3) & (~0x03); + + OptionsLength = TxData->OptionsLength; + OptionsBuffer = (UINT8 *) (TxData->OptionsBuffer); + } // // If don't fragment and fragment needed, return error // - if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->SnpMode.MaxPacketSize)) { + if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->MaxPacketSize)) { Status = EFI_BAD_BUFFER_SIZE; goto ON_EXIT; } @@ -1527,7 +1776,7 @@ EfiIp4Transmit ( // a IP4_TXTOKEN_WRAP and the data in a netbuf // Status = EFI_OUT_OF_RESOURCES; - Wrap = NetAllocatePool (sizeof (IP4_TXTOKEN_WRAP)); + Wrap = AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP)); if (Wrap == NULL) { goto ON_EXIT; } @@ -1546,7 +1795,7 @@ EfiIp4Transmit ( ); if (Wrap->Packet == NULL) { - NetFreePool (Wrap); + FreePool (Wrap); goto ON_EXIT; } @@ -1558,56 +1807,93 @@ EfiIp4Transmit ( // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been // enqueued. // + if (Config->RawData) { + // + // Restore pointer of first fragment in RawData mode. + // + TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment; + } + NetbufFree (Wrap->Packet); goto ON_EXIT; } + // + // Mark the packet sent before output it. Mark it not sent again if the + // returned status is not EFI_SUCCESS; + // + Wrap->Sent = TRUE; + Status = Ip4Output ( IpSb, IpInstance, Wrap->Packet, &Head, - TxData->OptionsBuffer, - TxData->OptionsLength, + OptionsBuffer, + OptionsLength, GateWay, Ip4OnPacketSent, Wrap ); if (EFI_ERROR (Status)) { + Wrap->Sent = FALSE; + + if (Config->RawData) { + // + // Restore pointer of first fragment in RawData mode. + // + TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment; + } + NetbufFree (Wrap->Packet); - goto ON_EXIT; } - // - // Mark the packet sent, so when Ip4FreeTxToken is called, it - // will signal the upper layer. - // - Wrap->Sent = TRUE; + if (Config->RawData) { + // + // Restore pointer of first fragment in RawData mode. + // + TxData->FragmentTable[0].FragmentBuffer = (UINT8 *) FirstFragment; + } ON_EXIT: - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } /** - Receive a packet for the upper layer. If there are packets - pending on the child's receive queue, the receive request - will be fulfilled immediately. Otherwise, the request is - enqueued. When receive request is completed, the status in - the Token is updated and its event is signalled. - - @param This The IP4 child to receive packet. - @param Token The user's receive token - - @retval EFI_INVALID_PARAMETER The token is invalid. - @retval EFI_NOT_STARTED The IP4 child hasn't been started - @retval EFI_ACCESS_DENIED The token or event is already queued. - @retval EFI_SUCCESS The receive request has been issued. + Places a receiving request into the receiving queue. + + The Receive() function places a completion token into the receive packet queue. + This function is always asynchronous. + + The Token.Event field in the completion token must be filled in by the caller + and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol + driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event + is signaled. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] Token Pointer to a token that is associated with the receive data descriptor. + + @retval EFI_SUCCESS The receive completion token was cached. + @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.) + is not finished yet. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + - This is NULL. + - Token is NULL. + - Token.Event is NULL. + @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system + resources (usually memory). + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. + The EFI IPv4 Protocol instance has been reset to startup defaults. + EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already + in the receive queue. + @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full. + @retval EFI_ICMP_ERROR An ICMP error packet was received. **/ -STATIC EFI_STATUS EFIAPI EfiIp4Receive ( @@ -1628,25 +1914,13 @@ EfiIp4Receive ( IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This); - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (IpInstance->State != IP4_STATE_CONFIGED) { Status = EFI_NOT_STARTED; goto ON_EXIT; } - // - // Current Udp implementation creates an IP child for each Udp child. - // It initates a asynchronous receive immediately no matter whether - // there is no mapping or not. Disable this for now. - // -#if 0 - if (Config->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) { - Status = EFI_NO_MAPPING; - goto ON_EXIT; - } -#endif - // // Check whether the toke is already on the receive queue. // @@ -1668,8 +1942,14 @@ EfiIp4Receive ( Status = Ip4InstanceDeliverPacket (IpInstance); + // + // Dispatch the DPC queued by the NotifyFunction of this instane's receive + // event. + // + DispatchDpc (); + ON_EXIT: - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } @@ -1683,16 +1963,16 @@ ON_EXIT: Because Ip4CancelPacket and other functions are all called in line, so, after Ip4CancelPacket returns, the Item has been freed. - @param Map The IP4 child's transmit queue - @param Item The current transmitted packet to test. - @param Context The user's token to cancel. + @param[in] Map The IP4 child's transmit queue. + @param[in] Item The current transmitted packet to test. + @param[in] Context The user's token to cancel. @retval EFI_SUCCESS Continue to check the next Item. @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled. **/ -STATIC EFI_STATUS +EFIAPI Ip4CancelTxTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1737,9 +2017,9 @@ Ip4CancelTxTokens ( Cancel the receive request. This is quiet simple, because it is only enqueued in our local receive map. - @param Map The IP4 child's receive queue - @param Item Current receive request to cancel. - @param Context The user's token to cancel + @param[in] Map The IP4 child's receive queue. + @param[in] Item Current receive request to cancel. + @param[in] Context The user's token to cancel. @retval EFI_SUCCESS Continue to check the next receive request on the queue. @@ -1747,8 +2027,8 @@ Ip4CancelTxTokens ( cancelled. **/ -STATIC EFI_STATUS +EFIAPI Ip4CancelRxTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1782,13 +2062,13 @@ Ip4CancelRxTokens ( /** Cancel the user's receive/transmit request. - @param IpInstance The IP4 child - @param Token The token to cancel. If NULL, all token will be + @param[in] IpInstance The IP4 child. + @param[in] Token The token to cancel. If NULL, all token will be cancelled. - @retval EFI_SUCCESS The token is cancelled + @retval EFI_SUCCESS The token is cancelled. @retval EFI_NOT_FOUND The token isn't found on either the - transmit/receive queue + transmit/receive queue. @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL. **/ @@ -1820,7 +2100,11 @@ Ip4Cancel ( // for Token!=NULL and it is cancelled. // Status = NetMapIterate (&IpInstance->RxTokens, Ip4CancelRxTokens, Token); - + // + // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's + // events. + // + DispatchDpc (); if (EFI_ERROR (Status)) { if ((Token != NULL) && (Status == EFI_ABORTED)) { return EFI_SUCCESS; @@ -1852,21 +2136,34 @@ Ip4Cancel ( /** - Cancel the queued receive/transmit requests. If Token is NULL, - all the queued requests will be cancelled. It just validate - the parameter then pass them to Ip4Cancel. - - @param This The IP4 child to cancel the request - @param Token The token to cancel, if NULL, cancel all. - - @retval EFI_INVALID_PARAMETER This is NULL - @retval EFI_NOT_STARTED The IP4 child hasn't been configured. - @retval EFI_NO_MAPPING The IP4 child is configured to use the default, - but the default address hasn't been acquired. - @retval EFI_SUCCESS The Token is cancelled. + Abort an asynchronous transmit or receive request. + + The Cancel() function is used to abort a pending transmit or receive request. + If the token is in the transmit or receive request queues, after calling this + function, Token->Status will be set to EFI_ABORTED and then Token->Event will + be signaled. If the token is not in one of the queues, which usually means the + asynchronous operation has completed, this function will not signal the token + and EFI_NOT_FOUND is returned. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + @param[in] Token Pointer to a token that has been issued by + EFI_IP4_PROTOCOL.Transmit() or + EFI_IP4_PROTOCOL.Receive(). If NULL, all pending + tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is + defined in EFI_IP4_PROTOCOL.Transmit(). + + @retval EFI_SUCCESS The asynchronous I/O request was aborted and + Token.->Event was signaled. When Token is NULL, all + pending requests were aborted and their events were signaled. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_NOT_STARTED This instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was + not found in the transmit or receive queue. It has either completed + or was not issued by Transmit() and Receive(). **/ -STATIC EFI_STATUS EFIAPI EfiIp4Cancel ( @@ -1884,7 +2181,7 @@ EfiIp4Cancel ( IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This); - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (IpInstance->State != IP4_STATE_CONFIGED) { Status = EFI_NOT_STARTED; @@ -1899,22 +2196,38 @@ EfiIp4Cancel ( Status = Ip4Cancel (IpInstance, Token); ON_EXIT: - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } /** - Poll the network stack. The EFI network stack is poll based. There - is no interrupt support for the network interface card. - - @param This The IP4 child to poll through - - @retval EFI_INVALID_PARAMETER The parameter is invalid - @retval EFI_NOT_STARTED The IP4 child hasn't been configured. + Polls for incoming data packets and processes outgoing data packets. + + The Poll() function polls for incoming data packets and processes outgoing data + packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll() + function to increase the rate that data packets are moved between the communications + device and the transmit and receive queues. + + In some systems the periodic timer event may not poll the underlying communications + device fast enough to transmit and/or receive all data packets without missing + incoming packets or dropping outgoing packets. Drivers and applications that are + experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function + more often. + + @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. + + @retval EFI_SUCCESS Incoming or outgoing data was processed. + @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started. + @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, + RARP, etc.) is not finished yet. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. + @retval EFI_NOT_READY No incoming or outgoing data is processed. + @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue. + Consider increasing the polling rate. **/ -STATIC EFI_STATUS EFIAPI EfiIp4Poll ( @@ -1943,34 +2256,22 @@ EfiIp4Poll ( return Mnp->Poll (Mnp); } -EFI_IP4_PROTOCOL -mEfiIp4ProtocolTemplete = { - EfiIp4GetModeData, - EfiIp4Configure, - EfiIp4Groups, - EfiIp4Routes, - EfiIp4Transmit, - EfiIp4Receive, - EfiIp4Cancel, - EfiIp4Poll -}; - - /** Decrease the life of the transmitted packets. If it is decreased to zero, cancel the packet. This function is - called by Ip4packetTimerTicking which time out both the + called by Ip4PacketTimerTicking which time out both the received-but-not-delivered and transmitted-but-not-recycle packets. - @param Map The IP4 child's transmit map. - @param Item Current transmitted packet - @param Context Not used. + @param[in] Map The IP4 child's transmit map. + @param[in] Item Current transmitted packet. + @param[in] Context Not used. - @retval EFI_SUCCESS Always returns EFI_SUCCESS + @retval EFI_SUCCESS Always returns EFI_SUCCESS. **/ EFI_STATUS +EFIAPI Ip4SentPacketTicking ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1996,10 +2297,8 @@ Ip4SentPacketTicking ( transmitted-but-not-recycle packets, and provides time input for its IGMP protocol. - @param Event The IP4 service instance's heart beat timer. - @param Context The IP4 service instance. - - @return None + @param[in] Event The IP4 service instance's heart beat timer. + @param[in] Context The IP4 service instance. **/ VOID