From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web08.9178.1604589877871034525 for ; Thu, 05 Nov 2020 07:24:37 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=lDTDNSUG; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0578d2b66c=abner.chang@hpe.com) Received: from pps.filterd (m0150241.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A5FI773008609; Thu, 5 Nov 2020 15:24:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pps0720; bh=Rac9QlxGDFVm3j4F4BWfo+u486MswKHsiKcjdC0bb30=; b=lDTDNSUG7iYL8PSEmObT/mvwFU8L1rz1WNTxf7SwpkFK7UFOXcmsN7cQqI4d16C+6tFP HRy/l3Vs2sR725i0K6sqxdA9A+DBKH/ed7qS4R4UEJL6F7ybMDwNdO0QaoasVRWTN6Hn ShkxU0C1oGAky6aFRZRulwWKjh41Dt5upf3AQvSDeRxJRJvqre/ayNftXnXkDoDSunaa ra+Tv4yvV2+7wqxiy/TtmP3L7KCuvzxTMo4soJ27zcrwgQqbRtaxfVJZJeGS5Dn5s01C 67xugk663scDUh7fJJlZMUe7rmZZOjTfBpKniLZ232dxDu01/6ImYegOrEKoQBeYE1Ns Zg== Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0a-002e3701.pphosted.com with ESMTP id 34kr4td010-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Nov 2020 15:24:36 +0000 Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3425.houston.hpe.com (Postfix) with ESMTP id E597F92; Thu, 5 Nov 2020 15:24:35 +0000 (UTC) Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id 83B324C; Thu, 5 Nov 2020 15:24:34 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Jordan Justen , Andrew Fish , Ray Ni , Nickle Wang , Peter O'Hanley Subject: [Platform Redfish Host Interface PATCH 4/6] EmulatorPkg/Application: Publish Redfish Host Interface Record Date: Thu, 5 Nov 2020 22:38:51 +0800 Message-Id: <20201105143853.2180-5-abner.chang@hpe.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201105143853.2180-1-abner.chang@hpe.com> References: <20201105143853.2180-1-abner.chang@hpe.com> X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-05_09:2020-11-05,2020-11-05 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 malwarescore=0 suspectscore=1 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011050105 Signed-off-by: Jiaxin Wu Signed-off-by: Ting Ye Signed-off-by: Siyuan Fu Signed-off-by: Fan Wang Signed-off-by: Abner Chang Cc: Jordan Justen Cc: Andrew Fish Cc: Ray Ni Cc: Nickle Wang Cc: Peter O'Hanley --- .../RedfishPlatformConfig.c | 298 ++++++++++++++++++ .../RedfishPlatformConfig.inf | 42 +++ 2 files changed, 340 insertions(+) create mode 100644 EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.c create mode 100644 EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.inf diff --git a/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.c b/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.c new file mode 100644 index 0000000000..89d4c760a7 --- /dev/null +++ b/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.c @@ -0,0 +1,298 @@ +/** @file + The implementation for Redfish Platform Configuration application. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +UINTN Argc; +CHAR16 **Argv; + +/** + + This function parse application ARG. + + @return Status +**/ +EFI_STATUS +GetArg ( + VOID + ) +{ + EFI_STATUS Status; + EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters; + + Status = gBS->HandleProtocol ( + gImageHandle, + &gEfiShellParametersProtocolGuid, + (VOID**)&ShellParameters + ); + if (EFI_ERROR(Status)) { + return Status; + } + + Argc = ShellParameters->Argc; + Argv = ShellParameters->Argv; + return EFI_SUCCESS; +} + +/** + + This function print the help message. + +**/ +VOID +PrintHelp ( + VOID + ) +{ + Print (L"\n"); + Print (L"Format (Only Ipv4 Address is supported):\n"); + Print (L"RedfishPlatformConfig.efi -s HostIpAddress HostIpMask RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\n"); + Print (L"OR:\n"); + Print (L"RedfishPlatformConfig.efi -a RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\n"); + Print (L"\n"); +} + +/** + The user Entry Point for Application. The user code starts with this function + as the real entry point for the application. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + RETURN_STATUS ReturnStatus; + + UINT8 HostIpAssignmentType; + EFI_IPv4_ADDRESS HostIpAddress; + EFI_IPv4_ADDRESS HostIpMask; + EFI_IPv4_ADDRESS RedfishServiceIpAddress; + EFI_IPv4_ADDRESS RedfishServiceIpMask; + UINTN RedfishServiceIpPort; + + Status = GetArg(); + if (EFI_ERROR(Status)) { + return Status; + } + + // + // Format is like : + // RedfishPlatformConfig.efi -s HostIpAddress HostIpMask RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort + // RedfishPlatformConfig.efi -a RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort + // + if (Argc != 7 && Argc != 5) { + + PrintHelp(); + return EFI_UNSUPPORTED; + } + + if (StrCmp(Argv[1], L"-s") == 0) { + + HostIpAssignmentType = 1; + + Status = NetLibStrToIp4 (Argv[2], &HostIpAddress); + if (EFI_ERROR (Status)) { + PrintHelp(); + return Status; + } + Status = NetLibStrToIp4 (Argv[3], &HostIpMask); + if (EFI_ERROR (Status)) { + PrintHelp(); + return Status; + } + Status = NetLibStrToIp4 (Argv[4], &RedfishServiceIpAddress); + if (EFI_ERROR (Status)) { + PrintHelp(); + return Status; + } + Status = NetLibStrToIp4 (Argv[5], &RedfishServiceIpMask); + if (EFI_ERROR (Status)) { + PrintHelp(); + return Status; + } + ReturnStatus = StrDecimalToUintnS (Argv[6], NULL, &RedfishServiceIpPort); + if (RETURN_ERROR (ReturnStatus)) { + PrintHelp(); + return Status; + } + + Status = gRT->SetVariable ( + L"HostIpAssignmentType", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (UINT8), + &HostIpAssignmentType + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"HostIpAddress", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (EFI_IPv4_ADDRESS), + &HostIpAddress + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"HostIpMask", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (EFI_IPv4_ADDRESS), + &HostIpMask + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"RedfishServiceIpAddress", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (EFI_IPv4_ADDRESS), + &RedfishServiceIpAddress + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"RedfishServiceIpMask", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (EFI_IPv4_ADDRESS), + &RedfishServiceIpMask + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"RedfishServiceIpPort", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (UINT16), + &RedfishServiceIpPort + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Print (L"\n"); + Print (L"HostIpAssignmentType is Static!\n"); + Print (L"HostIpAddress: %s has been set Successfully!\n", Argv[2]); + Print (L"HostIpMask: %s has been set Successfully!\n", Argv[3]); + Print (L"RedfishServiceIpAddress: %s has been set Successfully!\n", Argv[4]); + Print (L"RedfishServiceIpMask: %s has been set Successfully!\n", Argv[5]); + Print (L"RedfishServiceIpPort: %s has been set Successfully!\n", Argv[6]); + Print (L"Please Restart!\n"); + + } else if (StrCmp(Argv[1], L"-a") == 0) { + + HostIpAssignmentType = 3; + + Status = NetLibStrToIp4 (Argv[2], &RedfishServiceIpAddress); + if (EFI_ERROR (Status)) { + PrintHelp(); + return Status; + } + Status = NetLibStrToIp4 (Argv[3], &RedfishServiceIpMask); + if (EFI_ERROR (Status)) { + PrintHelp(); + return Status; + } + ReturnStatus = StrDecimalToUintnS (Argv[4], NULL, &RedfishServiceIpPort); + if (RETURN_ERROR (ReturnStatus)) { + PrintHelp(); + return Status; + } + + Status = gRT->SetVariable ( + L"HostIpAssignmentType", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (UINT8), + &HostIpAssignmentType + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"RedfishServiceIpAddress", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (EFI_IPv4_ADDRESS), + &RedfishServiceIpAddress + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"RedfishServiceIpMask", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (EFI_IPv4_ADDRESS), + &RedfishServiceIpMask + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gRT->SetVariable ( + L"RedfishServiceIpPort", + &gEmuRedfishServiceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (UINT16), + &RedfishServiceIpPort + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Print (L"\n"); + Print (L"HostIpAssignmentType is Auto!\n"); + Print (L"RedfishServiceIpAddress: %s has been set Successfully!\n", Argv[2]); + Print (L"RedfishServiceIpMask: %s has been set Successfully!\n", Argv[3]); + Print (L"RedfishServiceIpPort: %s has been set Successfully!\n", Argv[4]); + Print (L"Please Restart!\n"); + } else if (StrCmp(Argv[1], L"-h") == 0 || StrCmp(Argv[1], L"-help") == 0) { + + PrintHelp(); + } else { + + PrintHelp(); + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} diff --git a/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.inf b/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.inf new file mode 100644 index 0000000000..386c9bdd8c --- /dev/null +++ b/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.inf @@ -0,0 +1,42 @@ +## @file +# Sample UEFI Application Reference EDKII Module. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x0001000b + BASE_NAME = RedfishPlatformConfig + FILE_GUID = C02B67BB-3D19-4ACC-A080-1BDB575F8F36 + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = UefiMain + +[Sources] + RedfishPlatformConfig.c + +[Packages] + EmulatorPkg/EmulatorPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + NetworkPkg/NetworkPkg.dec + RedfishPkg/RedfishPkg.dec + +[LibraryClasses] + DebugLib + NetLib + UefiApplicationEntryPoint + UefiLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib +[Protocols] + gEfiShellParametersProtocolGuid ## CONSUMES + gEfiShellProtocolGuid ## CONSUMES + +[Guids] + gEmuRedfishServiceGuid -- 2.17.1