From nobody Tue Dec 24 13:24:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511770330657790.2770731433434; Mon, 27 Nov 2017 00:12:10 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7D0F421A1099D; Mon, 27 Nov 2017 00:07:47 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C659D21A1099A for ; Mon, 27 Nov 2017 00:07:45 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2017 00:12:07 -0800 Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.117]) by fmsmga006.fm.intel.com with ESMTP; 27 Nov 2017 00:12:05 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,463,1505804400"; d="scan'208";a="180967158" From: fanwang2 To: edk2-devel@lists.01.org Date: Mon, 27 Nov 2017 16:11:50 +0800 Message-Id: <1511770310-3984-1-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [Patch] MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media state detection X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Jiaxin Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In wireless connection, connecting state needs to be cared more about. ECR 1772 redefined the state EFI_NOT_READY to represent connecting state and can be retrieved from Aip protocol. This patch adds a new API to check media state at a specified time interval when network is connecting until the connection process finishes or timeout. Cc: Fu Siyuan Cc: Ye Ting Cc: Jiaxin Wu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan --- MdeModulePkg/Include/Library/NetLib.h | 40 +++++++ MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 160 +++++++++++++++++++++++= ++++ MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf | 2 + 3 files changed, 202 insertions(+) diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/L= ibrary/NetLib.h index b9df46c..7862df9 100644 --- a/MdeModulePkg/Include/Library/NetLib.h +++ b/MdeModulePkg/Include/Library/NetLib.h @@ -93,10 +93,16 @@ typedef UINT16 TCP_PORTNO; #define DNS_CLASS_INET 1 #define DNS_CLASS_CH 3 #define DNS_CLASS_HS 4 #define DNS_CLASS_ANY 255 =20 +// +// Number of 100ns units time Interval for network media state detect +// +#define MEDIA_STATE_DETECT_TIME_INTERVAL 1000000U + + #pragma pack(1) =20 // // Ethernet head definition // @@ -1246,10 +1252,44 @@ NetLibDetectMedia ( IN EFI_HANDLE ServiceHandle, OUT BOOLEAN *MediaPresent ); =20 /** + + Detect media state for a network device. This routine will wait for a pe= riod of time at=20 + a specified checking interval when a certain network is under connecting= until connection=20 + process finishes or timeout. If Aip protocol is supported by low layer d= rivers, three kinds + of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and EFI_NO_M= EDIA, represents + connected state, connecting state and no media state respectively. When = function detects=20 + the current state is EFI_NOT_READY, it will loop to wait for next time's= check until state=20 + turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supporte= d, function will=20 + call NetLibDetectMedia() and return state directly. + + @param[in] ServiceHandle The handle where network service binding p= rotocols are + installed on. + @param[in] Timeout The maximum number of 100ns units to wait = when network + is connecting. Zero value means detect onc= e and return + immediately. + @param[out] MediaState The pointer to the detected media state. + + @retval EFI_SUCCESS Media detection success. + @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network devic= e handle or=20 + MediaState pointer is NULL. + @retval EFI_DEVICE_ERROR A device error occurred. + @retval EFI_TIMEOUT Network is connecting but timeout. + +**/ +EFI_STATUS +EFIAPI +NetLibDetectMediaWaitTimeout ( + IN EFI_HANDLE ServiceHandle, + IN UINT64 Timeout, + OUT EFI_STATUS *MediaState + ); + + +/** Create an IPv4 device path node. =20 The header type of IPv4 device path node is MESSAGING_DEVICE_PATH. The header subtype of IPv4 device path node is MSG_IPv4_DP. The length of the IPv4 device path node in bytes is 19. diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Libr= ary/DxeNetLib/DxeNetLib.c index b8544b8..3030147 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -17,10 +17,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. #include =20 #include #include #include +#include #include #include #include #include =20 @@ -2501,10 +2502,169 @@ Exit: =20 return Status; } =20 /** + + Detect media state for a network device. This routine will wait for a pe= riod of time at=20 + a specified checking interval when a certain network is under connecting= until connection=20 + process finishes or timeout. If Aip protocol is supported by low layer d= rivers, three kinds + of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and EFI_NO_M= EDIA, represents + connected state, connecting state and no media state respectively. When = function detects=20 + the current state is EFI_NOT_READY, it will loop to wait for next time's= check until state=20 + turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supporte= d, function will=20 + call NetLibDetectMedia() and return state directly. + + @param[in] ServiceHandle The handle where network service binding p= rotocols are + installed on. + @param[in] Timeout The maximum number of 100ns units to wait = when network + is connecting. Zero value means detect onc= e and return + immediately. + @param[out] MediaState The pointer to the detected media state. + + @retval EFI_SUCCESS Media detection success. + @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network devic= e handle or=20 + MediaState pointer is NULL. + @retval EFI_DEVICE_ERROR A device error occurred. + @retval EFI_TIMEOUT Network is connecting but timeout. + +**/ + +EFI_STATUS +EFIAPI +NetLibDetectMediaWaitTimeout ( + IN EFI_HANDLE ServiceHandle, + IN UINT64 Timeout, + OUT EFI_STATUS *MediaState + ) +{ + EFI_STATUS Status; + EFI_HANDLE SnpHandle; + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + EFI_ADAPTER_INFO_MEDIA_STATE *MediaInfo; + BOOLEAN MediaPresent; + UINTN DataSize; + EFI_STATUS TimerStatus; + EFI_EVENT Timer; + UINT64 TimeRemained; + + ASSERT (MediaState !=3D NULL); + if (MediaState =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *MediaState =3D EFI_NO_MEDIA; + + // + // Get SNP handle + // + Snp =3D NULL; + SnpHandle =3D NetLibGetSnpHandle (ServiceHandle, &Snp); + if (SnpHandle =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Status =3D gBS->HandleProtocol ( + SnpHandle, + &gEfiAdapterInformationProtocolGuid, + (VOID *) &Aip + ); + if (EFI_ERROR (Status)) { + + MediaPresent =3D TRUE; + Status =3D NetLibDetectMedia (ServiceHandle, &MediaPresent); + if (!EFI_ERROR (Status)) { + if (MediaPresent =3D=3D TRUE) { + *MediaState =3D EFI_SUCCESS; + } else { + *MediaState =3D EFI_NO_MEDIA; + } + } + + // + // NetLibDetectMedia doesn't support EFI_NOT_READY status, return now! + // + return Status; + } + + Status =3D Aip->GetInformation ( + Aip, + &gEfiAdapterInfoMediaStateGuid, + (VOID **) &MediaInfo, + &DataSize + ); + if (!EFI_ERROR (Status)) { + + *MediaState =3D MediaInfo->MediaState; + if (*MediaState !=3D EFI_NOT_READY) { + + FreePool (MediaInfo); + return EFI_SUCCESS; + } + } + + if (MediaInfo !=3D NULL) { + FreePool (MediaInfo); + } + + if (Timeout < MEDIA_STATE_DETECT_TIME_INTERVAL) { + return Status; + } + + // + // Loop to check media state=20 + // + + Timer =3D NULL; + TimeRemained =3D Timeout; + Status =3D gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer= ); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + do { + Status =3D gBS->SetTimer ( + Timer, + TimerRelative, + MEDIA_STATE_DETECT_TIME_INTERVAL + ); + if (EFI_ERROR (Status)) { + gBS->CloseEvent(Timer); + return EFI_DEVICE_ERROR; + } + + do { + TimerStatus =3D gBS->CheckEvent (Timer); + if (!EFI_ERROR (TimerStatus)) { + + TimeRemained -=3D MEDIA_STATE_DETECT_TIME_INTERVAL; + Status =3D Aip->GetInformation ( + Aip, + &gEfiAdapterInfoMediaStateGuid, + (VOID **) &MediaInfo, + &DataSize + ); + if (!EFI_ERROR (Status)) { + *MediaState =3D MediaInfo->MediaState; + } + + if (MediaInfo !=3D NULL) { + FreePool (MediaInfo); + } + } + } while (TimerStatus =3D=3D EFI_NOT_READY); + } while (*MediaState =3D=3D EFI_NOT_READY && TimeRemained >=3D MEDIA_STA= TE_DETECT_TIME_INTERVAL); + + gBS->CloseEvent(Timer); + if (*MediaState =3D=3D EFI_NOT_READY && TimeRemained < MEDIA_STATE_DETEC= T_TIME_INTERVAL) { + return EFI_TIMEOUT; + } else { + return EFI_SUCCESS; + } +} + +/** Check the default address used by the IPv4 driver is static or dynamic (= acquired from DHCP). =20 If the controller handle does not have the EFI_IP4_CONFIG2_PROTOCOL inst= alled, the default address is static. If failed to get the policy from Ip4 Config2 = Protocol,=20 diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf b/MdeModulePkg/Li= brary/DxeNetLib/DxeNetLib.inf index 1ff3a4f..ad0727c 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf @@ -52,14 +52,16 @@ =20 =20 [Guids] gEfiSmbiosTableGuid ## SOMETIMES_CONSUMES ## = SystemTable gEfiSmbios3TableGuid ## SOMETIMES_CONSUMES ## = SystemTable + gEfiAdapterInfoMediaStateGuid ## SOMETIMES_CONSUMES =20 =20 [Protocols] gEfiSimpleNetworkProtocolGuid ## SOMETIMES_CONSUMES gEfiManagedNetworkProtocolGuid ## SOMETIMES_CONSUMES gEfiManagedNetworkServiceBindingProtocolGuid ## SOMETIMES_CONSUMES gEfiIp4Config2ProtocolGuid ## SOMETIMES_CONSUMES gEfiComponentNameProtocolGuid ## SOMETIMES_CONSUMES gEfiComponentName2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiAdapterInformationProtocolGuid ## SOMETIMES_CONSUMES \ No newline at end of file --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel