X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FMnpDxe%2FMnpMain.c;h=d96178a1d9943a3b835c030a38be35a6d4b21094;hp=2ca3d7917f3a80c39fd09212616559022413a02a;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=24af132fc0b4a72f25b8d84c3a1e736acbf5a70c diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c b/MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c index 2ca3d7917f..d96178a1d9 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c +++ b/MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c @@ -1,29 +1,19 @@ /** @file Implementation of Managed Network Protocol public services. - -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. +Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include "MnpImpl.h" -#include -#include - +#include "MnpImpl.h" /** Returns the operational parameters for the current MNP child driver. May also - support returning the underlying SNP driver mode data. - + support returning the underlying SNP driver mode data. + The GetModeData() function is used to read the current mode data (operational - parameters) from the MNP or the underlying SNP. + parameters) from the MNP or the underlying SNP. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type @@ -32,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @param[out] SnpModeData Pointer to storage for SNP operational parameters. This feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE is defined in the EFI_SIMPLE_NETWORK_PROTOCOL. - + @retval EFI_SUCCESS The operation completed successfully. @retval EFI_INVALID_PARAMETER This is NULL. @retval EFI_UNSUPPORTED The requested feature is unsupported in this @@ -40,24 +30,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @retval EFI_NOT_STARTED This MNP child driver instance has not been configured. The default values are returned in MnpConfigData if it is not NULL. - @retval Other The mode data could not be read. + @retval Others The mode data could not be read. **/ EFI_STATUS EFIAPI MnpGetModeData ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This, - OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, - OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL + IN EFI_MANAGED_NETWORK_PROTOCOL *This, + OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, + OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL ) { MNP_INSTANCE_DATA *Instance; EFI_SIMPLE_NETWORK_PROTOCOL *Snp; EFI_TPL OldTpl; EFI_STATUS Status; + UINT32 InterruptStatus; if (This == NULL) { - return EFI_INVALID_PARAMETER; } @@ -76,7 +66,13 @@ MnpGetModeData ( // // Copy the underlayer Snp mode data. // - Snp = Instance->MnpServiceData->Snp; + Snp = Instance->MnpServiceData->MnpDeviceData->Snp; + + // + // Upon successful return of GetStatus(), the Snp->Mode->MediaPresent + // will be updated to reflect any change of media status + // + Snp->GetStatus (Snp, &InterruptStatus, NULL); CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData)); } @@ -93,9 +89,9 @@ MnpGetModeData ( /** - Sets or clears the operational parameters for the MNP child driver. - - The Configure() function is used to set, change, or reset the operational + Sets or clears the operational parameters for the MNP child driver. + + The Configure() function is used to set, change, or reset the operational parameters for the MNP child driver instance. Until the operational parameters have been set, no network traffic can be sent or received by this MNP child driver instance. Once the operational parameters have been reset, no more @@ -114,13 +110,13 @@ MnpGetModeData ( Note: Warning: Receive filter settings that overlap will consume extra processor and/or DMA resources and degrade system and network performance. - @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. - @param[in] MnpConfigData Pointer to configuration data that will be assigned - to the MNP child driver instance. If NULL, the MNP - child driver instance is reset to startup defaults - and all pending transmit and receive requests are - flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is - defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData(). + @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. + @param[in] MnpConfigData Pointer to configuration data that will be assigned + to the MNP child driver instance. If NULL, the MNP + child driver instance is reset to startup defaults + and all pending transmit and receive requests are + flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is + defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData(). @retval EFI_SUCCESS The operation completed successfully. @retval EFI_INVALID_PARAMETER One or more of the following conditions is @@ -140,15 +136,15 @@ MnpGetModeData ( @retval EFI_DEVICE_ERROR An unexpected network or system error occurred. The MNP child driver instance has been reset to startup defaults. - @retval Other The MNP child driver instance has been reset to + @retval Others The MNP child driver instance has been reset to startup defaults. **/ EFI_STATUS EFIAPI MnpConfigure ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This, - IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL + IN EFI_MANAGED_NETWORK_PROTOCOL *This, + IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL ) { MNP_INSTANCE_DATA *Instance; @@ -156,10 +152,10 @@ MnpConfigure ( EFI_STATUS Status; if ((This == NULL) || - ((MnpConfigData != NULL) && - (MnpConfigData->ProtocolTypeFilter > 0) && - (MnpConfigData->ProtocolTypeFilter <= 1500))) { - + ((MnpConfigData != NULL) && + (MnpConfigData->ProtocolTypeFilter > 0) && + (MnpConfigData->ProtocolTypeFilter <= 1500)) + ) { return EFI_INVALID_PARAMETER; } @@ -188,20 +184,20 @@ ON_EXIT: /** - Translates an IP multicast address to a hardware (MAC) multicast address. This - function may be unsupported in some MNP implementations. - + Translates an IP multicast address to a hardware (MAC) multicast address. This + function may be unsupported in some MNP implementations. + The McastIpToMac() function translates an IP multicast address to a hardware (MAC) multicast address. This function may be implemented by calling the - underlying EFI_SIMPLE_NETWORK.MCastIpToMac() function, which may also be + underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be unsupported in some MNP implementations. - @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. - @param[in] Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address. - Set to FALSE if IpAddress is an IPv4 multicast address. - @param[in] IpAddress Pointer to the multicast IP address (in network byte order) - to convert. - @param[out] MacAddress Pointer to the resulting multicast MAC address. + @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. + @param[in] Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address. + Set to FALSE if IpAddress is an IPv4 multicast address. + @param[in] IpAddress Pointer to the multicast IP address (in network byte + order) to convert. + @param[out] MacAddress Pointer to the resulting multicast MAC address. @retval EFI_SUCCESS The operation completed successfully. @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE: @@ -215,37 +211,34 @@ ON_EXIT: @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP implementation. @retval EFI_DEVICE_ERROR An unexpected network or system error occurred. - @retval Other The address could not be converted. + @retval Others The address could not be converted. **/ EFI_STATUS EFIAPI MnpMcastIpToMac ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This, - IN BOOLEAN Ipv6Flag, - IN EFI_IP_ADDRESS *IpAddress, - OUT EFI_MAC_ADDRESS *MacAddress + IN EFI_MANAGED_NETWORK_PROTOCOL *This, + IN BOOLEAN Ipv6Flag, + IN EFI_IP_ADDRESS *IpAddress, + OUT EFI_MAC_ADDRESS *MacAddress ) { EFI_STATUS Status; MNP_INSTANCE_DATA *Instance; EFI_SIMPLE_NETWORK_PROTOCOL *Snp; EFI_TPL OldTpl; + EFI_IPv6_ADDRESS *Ip6Address; if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) { - return EFI_INVALID_PARAMETER; } - if (Ipv6Flag) { - // - // Currently IPv6 isn't supported. - // - return EFI_UNSUPPORTED; - } + Ip6Address = &IpAddress->v6; - if (!IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress))) { + if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) || + (!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress))) + ) { // - // The IPv4 address passed in is not a multicast address. + // The IP address passed in is not a multicast address. // return EFI_INVALID_PARAMETER; } @@ -260,20 +253,36 @@ MnpMcastIpToMac ( goto ON_EXIT; } - Snp = Instance->MnpServiceData->Snp; + Snp = Instance->MnpServiceData->MnpDeviceData->Snp; ASSERT (Snp != NULL); + ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS)); + if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) { - // - // Translate the IPv4 address into a multicast MAC address if the NIC is an - // ethernet NIC. - // - MacAddress->Addr[0] = 0x01; - MacAddress->Addr[1] = 0x00; - MacAddress->Addr[2] = 0x5E; - MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F); - MacAddress->Addr[4] = IpAddress->v4.Addr[2]; - MacAddress->Addr[5] = IpAddress->v4.Addr[3]; + if (!Ipv6Flag) { + // + // Translate the IPv4 address into a multicast MAC address if the NIC is an + // ethernet NIC according to RFC1112.. + // + MacAddress->Addr[0] = 0x01; + MacAddress->Addr[1] = 0x00; + MacAddress->Addr[2] = 0x5E; + MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F); + MacAddress->Addr[4] = IpAddress->v4.Addr[2]; + MacAddress->Addr[5] = IpAddress->v4.Addr[3]; + } else { + // + // Translate the IPv6 address into a multicast MAC address if the NIC is an + // ethernet NIC according to RFC2464. + // + + MacAddress->Addr[0] = 0x33; + MacAddress->Addr[1] = 0x33; + MacAddress->Addr[2] = Ip6Address->Addr[12]; + MacAddress->Addr[3] = Ip6Address->Addr[13]; + MacAddress->Addr[4] = Ip6Address->Addr[14]; + MacAddress->Addr[5] = Ip6Address->Addr[15]; + } Status = EFI_SUCCESS; } else { @@ -295,14 +304,14 @@ ON_EXIT: } /** - Enables and disables receive filters for multicast address. This function may + Enables and disables receive filters for multicast address. This function may be unsupported in some MNP implementations. - - The Groups() function only adds and removes multicast MAC addresses from the + + The Groups() function only adds and removes multicast MAC addresses from the filter list. The MNP driver does not transmit or process Internet Group Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is NULL, then all joined groups are left. - + @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] JoinFlag Set to TRUE to join this multicast group. Set to FALSE to leave this multicast group. @@ -326,16 +335,16 @@ ON_EXIT: startup defaults. @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP implementation. - @retval Other The requested operation could not be completed. + @retval Others The requested operation could not be completed. The MNP multicast group settings are unchanged. **/ EFI_STATUS EFIAPI MnpGroups ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This, - IN BOOLEAN JoinFlag, - IN EFI_MAC_ADDRESS *MacAddress OPTIONAL + IN EFI_MANAGED_NETWORK_PROTOCOL *This, + IN BOOLEAN JoinFlag, + IN EFI_MAC_ADDRESS *MacAddress OPTIONAL ) { MNP_INSTANCE_DATA *Instance; @@ -355,12 +364,11 @@ MnpGroups ( } Instance = MNP_INSTANCE_DATA_FROM_THIS (This); - SnpMode = Instance->MnpServiceData->Snp->Mode; + SnpMode = Instance->MnpServiceData->MnpDeviceData->Snp->Mode; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (!Instance->Configured) { - Status = EFI_NOT_STARTED; goto ON_EXIT; } @@ -442,8 +450,8 @@ ON_EXIT: /** Places asynchronous outgoing data packets into the transmit queue. - - The Transmit() function places a completion token into the transmit packet + + The Transmit() function places a completion token into the transmit packet queue. This function is always asynchronous. The caller must fill in the Token.Event and Token.TxData fields in the completion token, and these fields cannot be NULL. When the transmit operation @@ -453,12 +461,12 @@ ON_EXIT: defragmented before it can be transmitted by the network device. Systems in which performance is critical should review the requirements and features of the underlying communications device and drivers. - - + + @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] Token Pointer to a token associated with the transmit data - descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN is - defined in "Related Definitions" below. + descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN + is defined in "Related Definitions" below. @retval EFI_SUCCESS The transmit completion token was cached. @retval EFI_NOT_STARTED This MNP child driver instance has not been @@ -487,7 +495,7 @@ ON_EXIT: @retval EFI_ACCESS_DENIED The transmit completion token is already in the transmit queue. @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a - lack of system resources (usually memory). + lack of system resources (usually memory). @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The MNP child driver instance has been reset to startup defaults. @@ -498,8 +506,8 @@ ON_EXIT: EFI_STATUS EFIAPI MnpTransmit ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This, - IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token + IN EFI_MANAGED_NETWORK_PROTOCOL *This, + IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token ) { EFI_STATUS Status; @@ -510,7 +518,6 @@ MnpTransmit ( EFI_TPL OldTpl; if ((This == NULL) || (Token == NULL)) { - return EFI_INVALID_PARAMETER; } @@ -538,7 +545,10 @@ MnpTransmit ( // // Build the tx packet // - MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen); + Status = MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } // // OK, send the packet synchronously. @@ -554,19 +564,19 @@ ON_EXIT: /** Places an asynchronous receiving request into the receiving queue. - - The Receive() function places a completion token into the receive packet + + The Receive() function places a completion token into the receive packet queue. This function is always asynchronous. The caller must fill in the Token.Event field in the completion token, and this field cannot be NULL. When the receive operation completes, the MNP updates the Token.Status and Token.RxData fields and the Token.Event is signaled. - - @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. - @param[in] Token Pointer to a token associated with the receive - data descriptor. Type - EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in - EFI_MANAGED_NETWORK_PROTOCOL.Transmit(). + + @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. + @param[in] Token Pointer to a token associated with the receive + data descriptor. Type + EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in + EFI_MANAGED_NETWORK_PROTOCOL.Transmit(). @retval EFI_SUCCESS The receive completion token was cached. @retval EFI_NOT_STARTED This MNP child driver instance has not been @@ -590,8 +600,8 @@ ON_EXIT: EFI_STATUS EFIAPI MnpReceive ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This, - IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token + IN EFI_MANAGED_NETWORK_PROTOCOL *This, + IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token ) { EFI_STATUS Status; @@ -599,7 +609,6 @@ MnpReceive ( EFI_TPL OldTpl; if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) { - return EFI_INVALID_PARAMETER; } @@ -608,7 +617,6 @@ MnpReceive ( OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (!Instance->Configured) { - Status = EFI_NOT_STARTED; goto ON_EXIT; } @@ -618,7 +626,6 @@ MnpReceive ( // Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token); if (EFI_ERROR (Status)) { - goto ON_EXIT; } @@ -626,7 +633,6 @@ MnpReceive ( // Insert the Token into the RxTokenMap. // Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL); - if (!EFI_ERROR (Status)) { // // Try to deliver any buffered packets. @@ -636,7 +642,7 @@ MnpReceive ( // // Dispatch the DPC queued by the NotifyFunction of Token->Event. // - NetLibDispatchDpc (); + DispatchDpc (); } ON_EXIT: @@ -646,8 +652,8 @@ ON_EXIT: } /** - Aborts an asynchronous transmit or receive request. - + Aborts 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 @@ -658,8 +664,8 @@ ON_EXIT: @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @param[in] Token Pointer to a token that has been issued by EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or - EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all pending - tokens are aborted. + EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all + pending tokens are aborted. @retval EFI_SUCCESS The asynchronous I/O request was aborted and Token.Event was signaled. When Token is NULL, @@ -677,8 +683,8 @@ ON_EXIT: EFI_STATUS EFIAPI MnpCancel ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This, - IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL + IN EFI_MANAGED_NETWORK_PROTOCOL *This, + IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL ) { EFI_STATUS Status; @@ -686,7 +692,6 @@ MnpCancel ( EFI_TPL OldTpl; if (This == NULL) { - return EFI_INVALID_PARAMETER; } @@ -695,7 +700,6 @@ MnpCancel ( OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (!Instance->Configured) { - Status = EFI_NOT_STARTED; goto ON_EXIT; } @@ -704,16 +708,14 @@ MnpCancel ( // Iterate the RxTokenMap to cancel the specified Token. // Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token); - if (Token != NULL) { - Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND; } // // Dispatch the DPC queued by the NotifyFunction of the cancled token's events. // - NetLibDispatchDpc (); + DispatchDpc (); ON_EXIT: gBS->RestoreTPL (OldTpl); @@ -722,9 +724,9 @@ ON_EXIT: } /** - Polls for incoming data packets and processes outgoing data packets. - - The Poll() function can be used by network drivers and applications to + Polls for incoming data packets and processes outgoing data packets. + + The Poll() function can be used by network drivers and applications to increase the rate that data packets are moved between the communications device and the transmit and receive queues. Normally, a periodic timer event internally calls the Poll() function. But, in @@ -733,7 +735,7 @@ ON_EXIT: applications that are experiencing packet loss should try calling the Poll() function more often. - @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. + @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance. @retval EFI_SUCCESS Incoming or outgoing data was processed. @retval EFI_NOT_STARTED This MNP child driver instance has not been @@ -750,7 +752,7 @@ ON_EXIT: EFI_STATUS EFIAPI MnpPoll ( - IN EFI_MANAGED_NETWORK_PROTOCOL *This + IN EFI_MANAGED_NETWORK_PROTOCOL *This ) { EFI_STATUS Status; @@ -773,13 +775,15 @@ MnpPoll ( // // Try to receive packets. // - Status = MnpReceivePacket (Instance->MnpServiceData); + Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData); - NetLibDispatchDpc (); + // + // Dispatch the DPC queued by the NotifyFunction of rx token's events. + // + DispatchDpc (); ON_EXIT: gBS->RestoreTPL (OldTpl); return Status; } -