VirtualBox

Ignore:
Timestamp:
Aug 14, 2024 1:16:30 PM (6 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
164367
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
18 added
54 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Library/JsonLib.h

    r101291 r105670  
    655655  IN    CONST CHAR8        *Key,
    656656  IN    EDKII_JSON_VALUE   Json
     657  );
     658
     659/**
     660  The function is used to delete a JSON key from the given JSON bject,
     661
     662  @param[in]   JsonObj                The provided JSON object.
     663  @param[in]   Key                    The key of the JSON value to be deleted.
     664
     665  @retval      EFI_ABORTED            Some error occur and operation aborted.
     666  @retval      EFI_SUCCESS            The JSON value has been deleted from this JSON object.
     667
     668**/
     669EFI_STATUS
     670EFIAPI
     671JsonObjectDelete (
     672  IN    EDKII_JSON_OBJECT  JsonObj,
     673  IN    CONST CHAR8        *Key
    657674  );
    658675
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Library/RedfishCrtLib.h

    r99404 r105670  
    7070// Basic types mapping
    7171//
    72 typedef UINTN   size_t;
    73 typedef INTN    ssize_t;
    74 typedef INT32   time_t;
    75 typedef UINT8   __uint8_t;
    76 typedef UINT8   sa_family_t;
    77 typedef UINT32  uid_t;
    78 typedef UINT32  gid_t;
    79 typedef INT32   int32_t;
    80 typedef UINT32  uint32_t;
    81 typedef UINT16  uint16_t;
    82 typedef UINT8   uint8_t;
    83 typedef enum {
    84   false, true
    85 } bool;
     72typedef UINTN    size_t;
     73typedef INTN     ssize_t;
     74typedef INT32    time_t;
     75typedef INT32    int32_t;
     76typedef UINT32   uint32_t;
     77typedef UINT16   uint16_t;
     78typedef UINT8    uint8_t;
     79typedef BOOLEAN  bool;
     80
     81#define true   (1 == 1)
     82#define false  (1 == 0)
    8683
    8784//
     
    173170  );
    174171
    175 void           *
    176 memset     (
    177   void *,
    178   int,
     172int
     173isdigit     (
     174  int
     175  );
     176
     177int
     178isspace     (
     179  int
     180  );
     181
     182int
     183tolower     (
     184  int
     185  );
     186
     187int
     188isupper     (
     189  int
     190  );
     191
     192int
     193isxdigit    (
     194  int
     195  );
     196
     197int
     198isalnum     (
     199  int
     200  );
     201
     202int
     203strncmp     (
     204  const char *,
     205  const char *,
    179206  size_t
    180207  );
    181208
    182209int
    183 memcmp      (
    184   const void *,
    185   const void *,
    186   size_t
    187   );
    188 
    189 int
    190 isdigit     (
    191   int
    192   );
    193 
    194 int
    195 isspace     (
    196   int
    197   );
    198 
    199 int
    200 tolower     (
    201   int
    202   );
    203 
    204 int
    205 isupper     (
    206   int
    207   );
    208 
    209 int
    210 isxdigit    (
    211   int
    212   );
    213 
    214 int
    215 isalnum     (
    216   int
    217   );
    218 
    219 void           *
    220 memcpy     (
    221   void *,
    222   const void *,
    223   size_t
    224   );
    225 
    226 void           *
    227 memset     (
    228   void *,
    229   int,
    230   size_t
    231   );
    232 
    233 void           *
    234 memchr     (
    235   const void *,
    236   int,
    237   size_t
    238   );
    239 
    240 int
    241 memcmp      (
    242   const void *,
    243   const void *,
    244   size_t
    245   );
    246 
    247 void           *
    248 memmove    (
    249   void *,
    250   const void *,
    251   size_t
    252   );
    253 
    254 int
    255 strcmp      (
    256   const char *,
    257   const char *
    258   );
    259 
    260 int
    261 strncmp     (
    262   const char *,
    263   const char *,
    264   size_t
    265   );
    266 
    267 char           *
    268 strcpy     (
    269   char *,
    270   const char *
    271   );
    272 
    273 size_t
    274 strlen      (
    275   const char *
    276   );
    277 
    278 char           *
    279 strcat     (
    280   char *,
    281   const char *
    282   );
    283 
    284 char           *
    285 strchr     (
    286   const char *,
    287   int
    288   );
    289 
    290 int
    291 strcasecmp  (
    292   const char *,
    293   const char *
    294   );
    295 
    296 int
    297210strncasecmp (
    298   const char *,
    299   const char *,
    300   size_t
    301   );
    302 
    303 char           *
    304 strncpy    (
    305   char *,
    306   size_t,
    307   const char *,
    308   size_t
    309   );
    310 
    311 int
    312 strncmp     (
    313211  const char *,
    314212  const char *,
     
    327225  char **,
    328226  int
    329   );
    330 
    331 char *
    332 strstr      (
    333   const char  *s1,
    334   const char  *s2
    335227  );
    336228
     
    447339fgetc       (
    448340  FILE  *_File
    449   );
    450 
    451 uid_t
    452 getuid      (
    453   void
    454   );
    455 
    456 uid_t
    457 geteuid     (
    458   void
    459   );
    460 
    461 gid_t
    462 getgid      (
    463   void
    464   );
    465 
    466 gid_t
    467 getegid     (
    468   void
    469341  );
    470342
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Library/RedfishDebugLib.h

    r101291 r105670  
    22  This file defines the Redfish debug library interface.
    33
    4   Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     4  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    56
    67  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1213
    1314#include <Uefi.h>
     15#include <Library/DebugLib.h>
     16#include <RedfishServiceData.h>
    1417#include <Library/HiiUtilityLib.h>
    1518#include <Library/JsonLib.h>
    16 #include <Library/RedfishLib.h>
    1719
    1820#include <Protocol/EdkIIRedfishPlatformConfig.h>
    1921
    20 #define DEBUG_REDFISH_NETWORK         DEBUG_MANAGEABILITY   ///< Debug error level for Redfish networking function
    21 #define DEBUG_REDFISH_HOST_INTERFACE  DEBUG_MANAGEABILITY   ///< Debug error level for Redfish networking function
     22// Used with MdePKg DEBUG macro.
     23#define DEBUG_REDFISH_NETWORK          DEBUG_MANAGEABILITY          ///< Debug error level for Redfish networking function
     24#define DEBUG_REDFISH_HOST_INTERFACE   DEBUG_MANAGEABILITY          ///< Debug error level for Redfish Host INterface
     25#define DEBUG_REDFISH_PLATFORM_CONFIG  DEBUG_MANAGEABILITY          ///< Debug error level for Redfish Platform Configure Driver
     26
     27//
     28// Definitions of Redfish debug capability in Redfish component scope, used with DEBUG_REDFISH macro
     29// For example, Redfish Platform Config Driver
     30//   DEBUG_REDFISH(DEBUG_REDFISH_PLATFORM_CONFIG_DXE, ...)
     31//
     32#define DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE  0x00000001
     33
     34#define DEBUG_REDFISH(DebugCategory, ...) \
     35    do {                                                \
     36      if (!DebugPrintEnabled()) {                       \
     37        break;                                          \
     38      }                                                 \
     39      if (!DebugRedfishComponentEnabled (DebugCategory)) { \
     40        break;                                             \
     41      }                                                    \
     42      DEBUG ((DEBUG_MANAGEABILITY, ##__VA_ARGS__));       \
     43    } while (FALSE)
    2244
    2345/**
    24   Debug print the value of StatementValue.
     46  Determine whether the Redfish debug category is enabled in
     47  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory.
    2548
    26   @param[in]  ErrorLevel     DEBUG macro error level.
    27   @param[in]  StatementValue The statement value to print.
     49  @param[in]  DebugCategory  Redfish debug category.
    2850
    29   @retval     EFI_SUCCESS            StatementValue is printed.
    30   @retval     EFI_INVALID_PARAMETER  StatementValue is NULL.
     51  @retval     TRUE   This debug category is enabled.
     52  @retval     FALSE  This debug category is disabled..
    3153**/
    32 EFI_STATUS
    33 DumpHiiStatementValue (
    34   IN UINTN                ErrorLevel,
    35   IN HII_STATEMENT_VALUE  *StatementValue
     54BOOLEAN
     55DebugRedfishComponentEnabled (
     56  IN  UINT64  DebugCategory
    3657  );
    3758
     
    139160  );
    140161
     162/**
     163  Debug output raw data buffer.
     164
     165  @param[in]    ErrorLevel  DEBUG macro error level
     166  @param[in]    Buffer      Debug output data buffer.
     167  @param[in]    BufferSize  The size of Buffer in byte.
     168
     169  @retval EFI_SUCCESS             Debug dump finished.
     170  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
     171
     172**/
     173EFI_STATUS
     174DumpBuffer (
     175  IN  UINTN  ErrorLevel,
     176  IN  UINT8  *Buffer,
     177  IN  UINTN  BufferSize
     178  );
     179
    141180#endif
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Library/RedfishLib.h

    r99404 r105670  
    6262  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    6363  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     64  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    6465
    6566  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    7071#define REDFISH_LIB_H_
    7172
     73#include <RedfishServiceData.h>
    7274#include <Library/JsonLib.h>
    7375
     
    7779#define ODATA_TYPE_NAME_MAX_SIZE  128
    7880#define ODATA_TYPE_MAX_SIZE       128
    79 
    80 ///
    81 /// Library class public defines
    82 ///
    83 typedef  VOID  *REDFISH_SERVICE;
    84 typedef  VOID  *REDFISH_PAYLOAD;
    85 
    86 ///
    87 /// Library class public structures/unions
    88 ///
    89 typedef struct {
    90   EFI_HTTP_STATUS_CODE    *StatusCode;
    91   UINTN                   HeaderCount;
    92   EFI_HTTP_HEADER         *Headers;
    93   REDFISH_PAYLOAD         Payload;
    94 } REDFISH_RESPONSE;
    9581
    9682///
     
    185171
    186172/**
     173  This function returns the Redfish service of a REDFISH_PAYLOAD.
     174
     175  Caller doesn't need to free the returned JSON value because it will be released
     176  in corresponding RedfishCleanupService() function.
     177
     178  @param[in]    Payload     A REDFISH_PAYLOAD instance.
     179
     180  @return     Redfish service of the payload.
     181
     182**/
     183REDFISH_SERVICE
     184EFIAPI
     185RedfishServiceInPayload (
     186  IN REDFISH_PAYLOAD  Payload
     187  );
     188
     189/**
    187190  Fill the input RedPath string with system UUID from SMBIOS table or use the customized
    188191  ID if  FromSmbios == FALSE.
     
    223226  @param[out]   RedResponse           Pointer to the Redfish response data.
    224227
    225   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     228  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    226229                                  NULL and the value is 2XX. The corresponding redfish resource has
    227230                                  been returned in Payload within RedResponse.
     
    253256  @param[out]   RedResponse       Pointer to the Redfish response data.
    254257
    255   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     258  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    256259                                  NULL and the value is 2XX. The corresponding redfish resource has
    257260                                  been returned in Payload within RedResponse.
     
    283286  @param[out]   RedResponse       Pointer to the Redfish response data.
    284287
    285   @retval EFI_SUCCESS             The opeartion is successful:
     288  @retval EFI_SUCCESS             The operation is successful:
    286289                                  1. The HTTP StatusCode is NULL and the returned Payload in
    287290                                  RedResponse is not NULL, indicates the Redfish resource has
     
    324327  @param[out]   RedResponse           Pointer to the Redfish response data.
    325328
    326   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     329  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    327330                                  NULL and the value is 2XX. The Redfish resource will be returned
    328331                                  in Payload within RedResponse if server send it back in the HTTP
     
    358361
    359362  @param[in]    Target           The target payload to be updated.
    360   @param[in]    Payload          Palyoad with properties to be changed.
     363  @param[in]    Payload          Payload with properties to be changed.
    361364  @param[out]   RedResponse      Pointer to the Redfish response data.
    362365
    363   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     366  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    364367                                  NULL and the value is 2XX. The Redfish resource will be returned
    365368                                  in Payload within RedResponse if server send it back in the HTTP
     
    399402  @param[out]   RedResponse           Pointer to the Redfish response data.
    400403
    401   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     404  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    402405                                  NULL and the value is 2XX. The Redfish resource will be returned
    403406                                  in Payload within RedResponse if server send it back in the HTTP
     
    417420  IN     CONST CHAR8       *Uri,
    418421  IN     CONST CHAR8       *Content,
    419   IN     UINTN             ContentSize,
    420   IN     CONST CHAR8       *ContentType,
     422  IN     UINTN             ContentSize OPTIONAL,
     423  IN     CONST CHAR8       *ContentType OPTIONAL,
    421424  OUT    REDFISH_RESPONSE  *RedResponse
    422425  );
     
    437440  @param[out]   RedResponse     Pointer to the Redfish response data.
    438441
    439   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     442  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    440443                                  NULL and the value is 2XX. The Redfish resource will be returned
    441444                                  in Payload within RedResponse if server send it back in the HTTP
     
    472475  @param[out]   RedResponse           Pointer to the Redfish response data.
    473476
    474   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     477  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    475478                                  NULL and the value is 2XX, the Redfish resource has been removed.
    476479                                  If there is any message returned from server, it will be returned
     
    508511  @param[out]   RedResponse           Pointer to the Redfish response data.
    509512
    510   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     513  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    511514                                  NULL and the value is 2XX, the Redfish resource has been removed.
    512515                                  If there is any message returned from server, it will be returned
     
    526529  IN     CONST CHAR8       *Uri,
    527530  IN     CONST CHAR8       *Content,
     531  OUT    REDFISH_RESPONSE  *RedResponse
     532  );
     533
     534/**
     535  Use HTTP PUT to create new Redfish resource in the Resource Collection.
     536
     537  This function uses the RedfishService to put a Redfish resource addressed by
     538  Uri (only the relative path is required). Changes to one or more properties within
     539  the target resource are represented in the input Content, properties not specified
     540  in Content won't be changed by this request. The corresponding redfish response will
     541  returned, including HTTP StatusCode, Headers and Payload which record any HTTP response
     542  messages.
     543
     544  Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
     545  redfish response data.
     546
     547  @param[in]    RedfishService        The Service to access the Redfish resources.
     548  @param[in]    Uri                   Relative path to address the resource.
     549  @param[in]    Content               JSON represented properties to be update.
     550  @param[in]    ContentSize           Size of the Content to be send to Redfish service
     551  @param[in]    ContentType           Type of the Content to be send to Redfish service
     552  @param[out]   RedResponse           Pointer to the Redfish response data.
     553
     554  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
     555                                  NULL and the value is 2XX. The Redfish resource will be returned
     556                                  in Payload within RedResponse if server send it back in the HTTP
     557                                  response message body.
     558  @retval EFI_INVALID_PARAMETER   RedfishService, Uri, Content, or RedResponse is NULL.
     559  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. Callers can get
     560                                  more error info from returned HTTP StatusCode, Headers and Payload
     561                                  within RedResponse:
     562                                  1. If the returned StatusCode is NULL, indicates any error happen.
     563                                  2. If the returned StatusCode is not NULL and the value is not 2XX,
     564                                     indicates any error happen.
     565**/
     566EFI_STATUS
     567EFIAPI
     568RedfishPutToUri (
     569  IN     REDFISH_SERVICE   RedfishService,
     570  IN     CONST CHAR8       *Uri,
     571  IN     CONST CHAR8       *Content,
     572  IN     UINTN             ContentSize OPTIONAL,
     573  IN     CONST CHAR8       *ContentType OPTIONAL,
    528574  OUT    REDFISH_RESPONSE  *RedResponse
    529575  );
     
    583629
    584630  @param[in]  Payload                  The Redfish payload to be checked.
    585   @param[in]  OdataTypeName            OdataType will be retrived from mapping list.
     631  @param[in]  OdataTypeName            OdataType will be retrieved from mapping list.
    586632  @param[in]  OdataTypeMappingList     The list of OdataType.
    587633  @param[in]  OdataTypeMappingListSize The number of mapping list
     
    617663  @param[in]  CollectionSize  Size of this collection
    618664
    619   @return EFI_SUCCESS              Coolection size is returned in CollectionSize
     665  @return EFI_SUCCESS              Collection size is returned in CollectionSize
    620666  @return EFI_INVALID_PARAMETER    The payload is not a collection.
    621667**/
     
    675721  This function returns the string of Redfish service version.
    676722
    677   @param[in]   ServiceVerisonStr The string of Redfish service version.
     723  @param[in]   ServiceVersionStr The string of Redfish service version.
    678724  @param[in]   Url               The URL to build Redpath with ID.
    679725                                 Start with "/", for example "/Registries"
    680726  @param[in]   Id                ID string
    681   @param[out]  Redpath           Pointer to retrive Redpath, caller has to free
     727  @param[out]  Redpath           Pointer to retrieved Redpath, caller has to free
    682728                                 the memory allocated for this string.
    683729  @return     EFI_STATUS
     
    686732EFI_STATUS
    687733RedfishBuildRedpathUseId (
    688   IN  CHAR8  *ServiceVerisonStr,
     734  IN  CHAR8  *ServiceVersionStr,
    689735  IN  CHAR8  *Url,
    690736  IN  CHAR8  *Id,
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Library/RedfishPlatformConfigLib.h

    r101291 r105670  
    33
    44  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
    5   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    66
    77  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    8383
    8484  @param[out]  SupportedSchema     The supported schema list which is separated by ';'.
    85                                    For example: "x-uefi-redfish-Memory.v1_7_1;x-uefi-redfish-Boot.v1_0_1"
     85                                   For example: "x-UEFI-redfish-Memory.v1_7_1;x-UEFI-redfish-Boot.v1_0_1"
    8686                                   The SupportedSchema is allocated by the callee. It's caller's
    8787                                   responsibility to free this buffer using FreePool().
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Protocol/EdkIIRedfishPlatformConfig.h

    r101291 r105670  
    33
    44  (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
    5   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    66
    77  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    228228  @param[in]   This                Pointer to EDKII_REDFISH_PLATFORM_CONFIG_PROTOCOL instance.
    229229  @param[out]  SupportedSchema     The supported schema list which is separated by ';'.
    230                                    For example: "x-uefi-redfish-Memory.v1_7_1;x-uefi-redfish-Boot.v1_0_1"
     230                                   For example: "x-UEFI-redfish-Memory.v1_7_1;x-UEFI-redfish-Boot.v1_0_1"
    231231                                   The SupportedSchema is allocated by the callee. It's caller's
    232232                                   responsibility to free this buffer using FreePool().
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/HiiUtilityLib/HiiUtilityInternal.c

    r101291 r105670  
    54525452  Status            = EFI_NOT_FOUND;
    54535453  StrValue          = NULL;
     5454  ConfigAccess      = NULL;
    54545455  OriginalDefaultId = DefaultId;
    54555456  DefaultLink       = GetFirstNode (&FormSet->DefaultStoreListHead);
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.c

    r101291 r105670  
    389389      Question->Value.Buffer    = AllocateZeroPool (Question->StorageWidth);
    390390      if (Question->Value.Buffer == NULL) {
     391        FreePool (TemString);
    391392        return EFI_OUT_OF_RESOURCES;
    392393      }
     
    394395      CopyMem (Question->Value.Buffer, TemString, StrSize (TemString));
    395396      Src = Question->Value.Buffer;
     397      FreePool (TemString);
    396398    } else {
    397399      CopyMem (&Question->Value.Value, &QuestionValue->Value, sizeof (EFI_IFR_TYPE_VALUE));
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/JsonLib/JsonLib.c

    r101291 r105670  
    1919
    2020#include "jansson.h"
     21
     22extern volatile UINT32  hashtable_seed;
    2123
    2224/**
     
    803805{
    804806  if (json_object_set ((json_t *)JsonObj, Key, (json_t *)Json) != 0) {
     807    return EFI_ABORTED;
     808  } else {
     809    return EFI_SUCCESS;
     810  }
     811}
     812
     813/**
     814  The function is used to delete a JSON key from the given JSON bject
     815
     816  @param[in]   JsonObj                The provided JSON object.
     817  @param[in]   Key                    The key of the JSON value to be deleted.
     818
     819  @retval      EFI_ABORTED            Some error occur and operation aborted.
     820  @retval      EFI_SUCCESS            The JSON value has been deleted from this JSON object.
     821
     822**/
     823EFI_STATUS
     824EFIAPI
     825JsonObjectDelete (
     826  IN    EDKII_JSON_OBJECT  JsonObj,
     827  IN    CONST CHAR8        *Key
     828  )
     829{
     830  if (json_object_del ((json_t *)JsonObj, (const char *)Key) != 0) {
    805831    return EFI_ABORTED;
    806832  } else {
     
    11391165  return (EDKII_JSON_TYPE)(((json_t *)JsonValue)->type);
    11401166}
     1167
     1168/**
     1169  JSON Library constructor.
     1170
     1171  @param ImageHandle     The image handle.
     1172  @param SystemTable     The system table.
     1173
     1174  @retval  EFI_SUCCESS  Protocol listener is registered successfully.
     1175
     1176**/
     1177EFI_STATUS
     1178EFIAPI
     1179JsonLibConstructor (
     1180  IN EFI_HANDLE        ImageHandle,
     1181  IN EFI_SYSTEM_TABLE  *SystemTable
     1182  )
     1183{
     1184  //
     1185  // hashtable_seed is initalized by current time while JsonLib is loaded.
     1186  // Due to above mechanism, hashtable_seed will be different in each individual
     1187  // UEFI driver. As the result, the hash of same key in different UEFI driver
     1188  // would be different. This breaks JsonObjectGetValue() because
     1189  // JsonObjectGetValue() won't be able to find corresponding JSON value if
     1190  // this EDKII_JSON_VALUE is created by another UEFI driver.
     1191  //
     1192  // Initial the seed to a fixed magic value for JsonLib to be working in all
     1193  // UEFI drivers. This fixed number will be removed after the protocol version
     1194  // of JsonLib is implemented in the future.
     1195  //
     1196  hashtable_seed = 0xFDAE2143;
     1197
     1198  return EFI_SUCCESS;
     1199}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/JsonLib/JsonLib.inf

    r89983 r105670  
    1616  VERSION_STRING                 = 1.0
    1717  LIBRARY_CLASS                  = JsonLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER
     18  CONSTRUCTOR                    = JsonLibConstructor
    1819
    1920#
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/JsonLib/load.c

    r99404 r105670  
    66
    77 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
     8 Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    89
    910    SPDX-License-Identifier: BSD-2-Clause-Patent AND MIT
     
    718719  }
    719720
    720   lex->token      = TOKEN_REAL;
    721   lex->value.real = doubleval;
     721  lex->token         = TOKEN_INTEGER;
     722  lex->value.integer = doubleval;
    722723  return 0;
    723724
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInterfaceBmcUsbNicLib.c

    r101291 r105670  
    6666      ))
    6767  {
    68     DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    Redfish Credentail Bootstrapping is supported\n", __func__));
     68    DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    Redfish Credential Bootstrapping is supported\n"));
    6969    ReturnBool = TRUE;
    7070  } else {
    71     DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    Redfish Credentail Bootstrapping is not supported\n", __func__));
     71    DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    Redfish Credential Bootstrapping is not supported\n"));
    7272    ReturnBool = FALSE;
    7373  }
     
    121121      CopyMem (
    122122        (VOID *)&InterfaceData->DeviceDescriptor.UsbDeviceV2.MacAddress,
    123         (VOID *)&ThisInstance->MacAddress,
     123        (VOID *)ThisInstance->MacAddress,
    124124        sizeof (InterfaceData->DeviceDescriptor.UsbDeviceV2.MacAddress)
    125125        );
     
    181181      ThisProtocolRecord = (MC_HOST_INTERFACE_PROTOCOL_RECORD *)AllocateZeroPool (
    182182                                                                  sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - 1 +
    183                                                                   sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) +
     183                                                                  sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1 +
    184184                                                                  HostNameLength
    185185                                                                  );
     
    190190
    191191      ThisProtocolRecord->ProtocolType        = MCHostInterfaceProtocolTypeRedfishOverIP;
    192       ThisProtocolRecord->ProtocolTypeDataLen = sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) + HostNameLength;
     192      ThisProtocolRecord->ProtocolTypeDataLen = sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) -1 + HostNameLength;
    193193      RedfishOverIpData                       = (REDFISH_OVER_IP_PROTOCOL_DATA *)&ThisProtocolRecord->ProtocolTypeData[0];
    194194      //
     
    245245
    246246      // RedfishServiceIpPort
    247       RedfishOverIpData->RedfishServiceIpPort = 0;
     247      RedfishOverIpData->RedfishServiceIpPort = PcdGet16 (PcdRedfishServicePort);
    248248
    249249      // RedfishServiceVlanId
     
    369369      CopyMem ((VOID *)&ThisInstance->RedfishIpAddressIpv4, (VOID *)&DestIpAddress->IpAddress, sizeof (DestIpAddress->IpAddress));
    370370      //
    371       // According to UEFI spec, the IP address at BMC USB NIC host end is the IP address at BMC end minus 1.
     371      // According to the design spec:
     372      // https://github.com/tianocore/edk2/tree/master/RedfishPkg#platform-with-bmc-and-the-bmc-exposed-usb-network-device
     373      // The IP address at BMC USB NIC host end is the IP address at BMC end minus 1.
    372374      //
    373375      CopyMem ((VOID *)&ThisInstance->HostIpAddressIpv4, (VOID *)&DestIpAddress->IpAddress, sizeof (DestIpAddress->IpAddress));
     
    615617
    616618  // Initial the get MAC address request.
    617   GetLanConfigReq.SetSelector       = 0;
    618   GetLanConfigReq.BlockSelector     = 0;
    619   GetLanConfigReq.ParameterSelector = IpmiLanMacAddress;
     619  GetLanConfigReq.ChannelNumber.Uint8 = 0;
     620  GetLanConfigReq.SetSelector         = 0;
     621  GetLanConfigReq.BlockSelector       = 0;
     622  GetLanConfigReq.ParameterSelector   = IpmiLanMacAddress;
    620623
    621624  ExitStatus = EFI_NOT_FOUND;
     
    639642      DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "  No cached IPMI LAN info\n"));
    640643      DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "  Send NetFn = App, Command = 0x42 to channel %d\n", ChannelNum));
     644      GetChanelInfoRequest.ChannelNumber.Uint8          = 0;
    641645      GetChanelInfoRequest.ChannelNumber.Bits.ChannelNo = (UINT8)ChannelNum;
    642646      Status                                            = IpmiGetChannelInfo (
     
    646650                                                            );
    647651      if (EFI_ERROR (Status)) {
    648         DEBUG ((DEBUG_ERROR, "    - Fails to send command.\n", ChannelNum));
     652        DEBUG ((DEBUG_ERROR, "    - Channel %d fails to send command.\n", ChannelNum));
    649653        continue;
    650654      }
     
    730734      //
    731735      // According to design spec in Readme file under RedfishPkg.
    732       // Compare the first five MAC address and
    733       // the 6th MAC address.
     736      // https://github.com/tianocore/edk2/tree/master/RedfishPkg#platform-with-bmc-and-the-bmc-exposed-usb-network-device
     737      // Compare the first five elements of MAC address and the 6th element of MAC address.
     738      // The 6th element of MAC address must be the 6th element of
     739      // IPMI channel MAC address minus 1.
    734740      //
    735741      if ((IpmiLanMacAddressSize != UsbNicInfo->MacAddressSize) ||
     
    739745             IpmiLanMacAddressSize - 1
    740746             ) != 0) ||
    741           (IpmiLanChannelMacAddress.Addr[IpmiLanMacAddressSize - 1] !=
    742            *(UsbNicInfo->MacAddress + IpmiLanMacAddressSize - 1) - 1)
     747          ((IpmiLanChannelMacAddress.Addr[IpmiLanMacAddressSize - 1] - 1) !=
     748           *(UsbNicInfo->MacAddress + IpmiLanMacAddressSize - 1))
    743749          )
    744750      {
     
    964970
    965971/**
     972  This function identifies if the USB NIC has MAC address and internet
     973  protocol device path installed. (Only support IPv4)
     974
     975  @param[in] UsbDevicePath     USB device path.
     976
     977  @retval EFI_SUCCESS          Yes, this is IPv4 SNP handle
     978  @retval EFI_NOT_FOUND        No, this is not IPv4 SNP handle
     979
     980**/
     981EFI_STATUS
     982IdentifyNetworkMessageDevicePath (
     983  IN EFI_DEVICE_PATH_PROTOCOL  *UsbDevicePath
     984  )
     985{
     986  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
     987
     988  DevicePath = UsbDevicePath;
     989  while (TRUE) {
     990    DevicePath = NextDevicePathNode (DevicePath);
     991    if (IsDevicePathEnd (DevicePath)) {
     992      DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "MAC address device path is not found on this handle.\n"));
     993      break;
     994    }
     995
     996    if ((DevicePath->Type == MESSAGING_DEVICE_PATH) && (DevicePath->SubType == MSG_MAC_ADDR_DP)) {
     997      DevicePath = NextDevicePathNode (DevicePath); // Advance to next device path protocol.
     998      if (IsDevicePathEnd (DevicePath)) {
     999        DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "IPv4 device path is not found on this handle.\n"));
     1000        break;
     1001      }
     1002
     1003      if ((DevicePath->Type == MESSAGING_DEVICE_PATH) && (DevicePath->SubType == MSG_IPv4_DP)) {
     1004        return EFI_SUCCESS;
     1005      }
     1006
     1007      break;
     1008    }
     1009  }
     1010
     1011  return EFI_NOT_FOUND;
     1012}
     1013
     1014/**
    9661015  This function identifies if the USB NIC is exposed by BMC as
    9671016  the host-BMC channel.
     
    10141063  InitializeListHead (&BmcUsbNic->NextInstance);
    10151064  BmcUsbNic->MacAddressSize = Snp->Mode->HwAddressSize;
    1016   BmcUsbNic->MacAddress     = AllocateZeroPool (sizeof (BmcUsbNic->MacAddressSize));
     1065  BmcUsbNic->MacAddress     = AllocatePool (BmcUsbNic->MacAddressSize);
    10171066  if (BmcUsbNic->MacAddress == NULL) {
    10181067    DEBUG ((DEBUG_ERROR, "    Failed to allocate memory for HW MAC addresss.\n"));
     
    10261075    BmcUsbNic->MacAddressSize
    10271076    );
    1028   DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    MAC address (in size %d) for this SNP instance:\n      ", BmcUsbNic->MacAddressSize));
     1077  DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    MAC address (in size %d) for this SNP instance:\n", BmcUsbNic->MacAddressSize));
    10291078  for (Index = 0; Index < BmcUsbNic->MacAddressSize; Index++) {
    10301079    DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "%02x ", *(BmcUsbNic->MacAddress + Index)));
     
    10691118  EFI_STATUS                Status;
    10701119  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
    1071   BOOLEAN                   GotOneUsbNIc;
     1120  BOOLEAN                   GotBmcUsbNic;
     1121  CHAR16                    *DevicePathStr;
    10721122
    10731123  if ((HandleNumer == 0) || (HandleBuffer == NULL)) {
     
    10771127  DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry, #%d SNP handle\n", __func__, HandleNumer));
    10781128
    1079   GotOneUsbNIc = FALSE;
     1129  GotBmcUsbNic = FALSE;
    10801130  for (Index = 0; Index < HandleNumer; Index++) {
     1131    DEBUG ((DEBUG_MANAGEABILITY, "    Locate device path on handle 0x%08x\n", *(HandleBuffer + Index)));
    10811132    Status = gBS->HandleProtocol (
    10821133                    *(HandleBuffer + Index),
     
    10851136                    );
    10861137    if (EFI_ERROR (Status)) {
    1087       DEBUG ((DEBUG_ERROR, "    Failed to locate SNP on %d handle.\n", __func__, Index));
     1138      DEBUG ((DEBUG_ERROR, "    Failed to locate device path on %d handle.\n", Index));
    10881139      continue;
     1140    }
     1141
     1142    DevicePathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE);
     1143    if (DevicePathStr != NULL) {
     1144      DEBUG ((DEBUG_MANAGEABILITY, "    Device path: %s\n", DevicePathStr));
     1145      FreePool (DevicePathStr);
    10891146    }
    10901147
     
    10921149    while (TRUE) {
    10931150      if ((DevicePath->Type == MESSAGING_DEVICE_PATH) && (DevicePath->SubType == MSG_USB_DP)) {
    1094         Status = IdentifyUsbNicBmcChannel (*(HandleBuffer + Index), DevicePath);
     1151        Status = IdentifyNetworkMessageDevicePath (DevicePath);
    10951152        if (!EFI_ERROR (Status)) {
    1096           GotOneUsbNIc = TRUE;
    1097           break;
     1153          Status = IdentifyUsbNicBmcChannel (*(HandleBuffer + Index), DevicePath);
     1154          if (!EFI_ERROR (Status)) {
     1155            GotBmcUsbNic = TRUE;
     1156          }
    10981157        }
     1158
     1159        break; // Advance to next SNP handle.
    10991160      }
    11001161
     
    11061167  }
    11071168
    1108   if (GotOneUsbNIc) {
     1169  if (GotBmcUsbNic) {
    11091170    return EFI_SUCCESS;
    11101171  }
    11111172
     1173  DEBUG ((DEBUG_MANAGEABILITY, "No BMC USB NIC found on SNP handles\n"));
    11121174  return EFI_NOT_FOUND;
    11131175}
     
    11401202  DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry, the registration key - 0x%08x.\n", __func__, Registration));
    11411203
    1142   Handle     = NULL;
    1143   Status     = EFI_SUCCESS;
    1144   BufferSize = 0;
    1145 
    1146   Status = gBS->LocateHandle (
    1147                   Registration == NULL ? ByProtocol : ByRegisterNotify,
    1148                   &gEfiSimpleNetworkProtocolGuid,
    1149                   Registration,
    1150                   &BufferSize,
    1151                   NULL
    1152                   );
    1153   if (Status == EFI_BUFFER_TOO_SMALL) {
    1154     DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    %d SNP protocol instances.\n", BufferSize/sizeof (EFI_HANDLE)));
    1155     HandleBuffer = AllocateZeroPool (BufferSize);
    1156     if (HandleBuffer == NULL) {
    1157       DEBUG ((DEBUG_ERROR, "    Falied to allocate buffer for the handles.\n"));
    1158       return EFI_OUT_OF_RESOURCES;
    1159     }
    1160 
    1161     Status = gBS->LocateHandle (
    1162                     Registration == NULL ? ByProtocol : ByRegisterNotify,
    1163                     &gEfiSimpleNetworkProtocolGuid,
    1164                     Registration,
    1165                     &BufferSize,
    1166                     HandleBuffer
    1167                     );
    1168     if (EFI_ERROR (Status)) {
    1169       DEBUG ((DEBUG_ERROR, "    Falied to locate SNP protocol handles.\n"));
    1170       FreePool (HandleBuffer);
    1171       return Status;
    1172     }
    1173   } else if (EFI_ERROR (Status)) {
    1174     return Status;
    1175   }
    1176 
    1177   // Check USB NIC on handles.
    1178   Status = CheckBmcUsbNicOnHandles (BufferSize/sizeof (EFI_HANDLE), HandleBuffer);
    1179   if (!EFI_ERROR (Status)) {
    1180     // Retrieve the rest of BMC USB NIC information for Redfish over IP information
    1181     // and USB Network Interface V2.
    1182     Status = RetrievedBmcUsbNicInfo ();
    1183     if (!EFI_ERROR (Status)) {
    1184       DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    Install protocol to notify the platform Redfish Host Interface information is ready.\n"));
    1185       Status = gBS->InstallProtocolInterface (
    1186                       &Handle,
    1187                       &mPlatformHostInterfaceBmcUsbNicReadinessGuid,
    1188                       EFI_NATIVE_INTERFACE,
    1189                       NULL
     1204  Handle = NULL;
     1205  Status = EFI_SUCCESS;
     1206
     1207  do {
     1208    BufferSize = 0;
     1209    Status     = gBS->LocateHandle (
     1210                        Registration == NULL ? ByProtocol : ByRegisterNotify,
     1211                        &gEfiSimpleNetworkProtocolGuid,
     1212                        Registration,
     1213                        &BufferSize,
     1214                        NULL
     1215                        );
     1216    if (Status == EFI_BUFFER_TOO_SMALL) {
     1217      DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    %d SNP protocol instance(s).\n", BufferSize/sizeof (EFI_HANDLE)));
     1218      HandleBuffer = AllocateZeroPool (BufferSize);
     1219      if (HandleBuffer == NULL) {
     1220        DEBUG ((DEBUG_ERROR, "    Falied to allocate buffer for the handles.\n"));
     1221        return EFI_OUT_OF_RESOURCES;
     1222      }
     1223
     1224      Status = gBS->LocateHandle (
     1225                      Registration == NULL ? ByProtocol : ByRegisterNotify,
     1226                      &gEfiSimpleNetworkProtocolGuid,
     1227                      Registration,
     1228                      &BufferSize,
     1229                      HandleBuffer
    11901230                      );
    11911231      if (EFI_ERROR (Status)) {
    1192         DEBUG ((DEBUG_ERROR, "    Install protocol fail %r.\n", Status));
    1193       }
    1194     }
    1195   }
    1196 
    1197   FreePool (HandleBuffer);
     1232        DEBUG ((DEBUG_ERROR, "    Falied to locate SNP protocol handles.\n"));
     1233        FreePool (HandleBuffer);
     1234        return Status;
     1235      }
     1236    } else if (EFI_ERROR (Status)) {
     1237      if (Registration != NULL) {
     1238        DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    No more newly installed SNP protocol for this registration - %r.\n", Status));
     1239        return EFI_SUCCESS;
     1240      }
     1241
     1242      return Status;
     1243    }
     1244
     1245    // Check USB NIC on handles.
     1246    Status = CheckBmcUsbNicOnHandles (BufferSize/sizeof (EFI_HANDLE), HandleBuffer);
     1247    if (!EFI_ERROR (Status)) {
     1248      // Retrieve the rest of BMC USB NIC information for Redfish over IP information
     1249      // and USB Network Interface V2.
     1250      Status = RetrievedBmcUsbNicInfo ();
     1251      if (!EFI_ERROR (Status)) {
     1252        DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "    Install protocol to notify the platform Redfish Host Interface information is ready.\n"));
     1253        Status = gBS->InstallProtocolInterface (
     1254                        &Handle,
     1255                        &mPlatformHostInterfaceBmcUsbNicReadinessGuid,
     1256                        EFI_NATIVE_INTERFACE,
     1257                        NULL
     1258                        );
     1259        if (EFI_ERROR (Status)) {
     1260          DEBUG ((DEBUG_ERROR, "    Install protocol fail %r.\n", Status));
     1261        }
     1262      }
     1263    }
     1264
     1265    FreePool (HandleBuffer);
     1266  } while (Registration != NULL);
     1267
    11981268  return Status;
    11991269}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInterfaceBmcUsbNicLib.inf

    r101291 r105670  
    1515  MODULE_TYPE                    = DXE_DRIVER
    1616  VERSION_STRING                 = 1.0
    17   LIBRARY_CLASS                  = PlatformHostInterfaceBmcUsbNicLib
     17  LIBRARY_CLASS                  = RedfishPlatformHostInterfaceLib
    1818
    1919[Sources]
     
    4444  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishHostName     ## CONSUMED
    4545  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceUuid  ## CONSUMED
     46  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServicePort  ## CONSUMED
    4647
    4748[Depex]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c

    r101291 r105670  
    22  Redfish debug library to debug Redfish application.
    33
    4   Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     4  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    56
    67  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1415#include <Library/MemoryAllocationLib.h>
    1516#include <Library/RedfishDebugLib.h>
     17#include <Library/RedfishHttpLib.h>
    1618#include <Library/UefiLib.h>
    1719
     
    2022#endif
    2123
    22 #define REDFISH_JSON_STRING_LENGTH  200
    23 #define REDFISH_JSON_OUTPUT_FORMAT  (EDKII_JSON_COMPACT | EDKII_JSON_INDENT(2))
    24 
    25 /**
    26   Debug print the value of StatementValue.
    27 
    28   @param[in]  ErrorLevel     DEBUG macro error level.
    29   @param[in]  StatementValue The statement value to print.
    30 
    31   @retval     EFI_SUCCESS            StatementValue is printed.
    32   @retval     EFI_INVALID_PARAMETER  StatementValue is NULL.
    33 **/
    34 EFI_STATUS
    35 DumpHiiStatementValue (
    36   IN UINTN                ErrorLevel,
    37   IN HII_STATEMENT_VALUE  *StatementValue
    38   )
    39 {
    40   if (StatementValue == NULL) {
    41     return EFI_INVALID_PARAMETER;
    42   }
    43 
    44   DEBUG ((ErrorLevel, "BufferValueType: 0x%x\n", StatementValue->BufferValueType));
    45   DEBUG ((ErrorLevel, "BufferLen: 0x%x\n", StatementValue->BufferLen));
    46   DEBUG ((ErrorLevel, "Buffer:    0x%p\n", StatementValue->Buffer));
    47   DEBUG ((ErrorLevel, "Type:      0x%p\n", StatementValue->Type));
    48 
    49   switch (StatementValue->Type) {
    50     case EFI_IFR_TYPE_NUM_SIZE_8:
    51       DEBUG ((ErrorLevel, "Value:     0x%x\n", StatementValue->Value.u8));
    52       break;
    53     case EFI_IFR_TYPE_NUM_SIZE_16:
    54       DEBUG ((ErrorLevel, "Value:     0x%x\n", StatementValue->Value.u16));
    55       break;
    56     case EFI_IFR_TYPE_NUM_SIZE_32:
    57       DEBUG ((ErrorLevel, "Value:     0x%x\n", StatementValue->Value.u32));
    58       break;
    59     case EFI_IFR_TYPE_NUM_SIZE_64:
    60       DEBUG ((ErrorLevel, "Value:     0x%lx\n", StatementValue->Value.u64));
    61       break;
    62     case EFI_IFR_TYPE_BOOLEAN:
    63       DEBUG ((ErrorLevel, "Value:     %a\n", (StatementValue->Value.b ? "true" : "false")));
    64       break;
    65     case EFI_IFR_TYPE_STRING:
    66       DEBUG ((ErrorLevel, "Value:     0x%x\n", StatementValue->Value.string));
    67       break;
    68     case EFI_IFR_TYPE_TIME:
    69     case EFI_IFR_TYPE_DATE:
    70     default:
    71       break;
    72   }
    73 
    74   return EFI_SUCCESS;
     24#define REDFISH_JSON_STRING_LENGTH          200
     25#define REDFISH_JSON_OUTPUT_FORMAT          (EDKII_JSON_COMPACT | EDKII_JSON_INDENT(2))
     26#define REDFISH_PRINT_BUFFER_BYTES_PER_ROW  16
     27
     28/**
     29  Determine whether the Redfish debug category is enabled in
     30  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory.
     31
     32  @param[in]  RedfishDebugCategory  Redfish debug category.
     33
     34  @retval     TRUE   This debug category is enabled.
     35  @retval     FALSE  This debug category is disabled..
     36**/
     37BOOLEAN
     38DebugRedfishComponentEnabled (
     39  IN  UINT64  RedfishDebugCategory
     40  )
     41{
     42  UINT64  DebugCategory;
     43
     44  DebugCategory = FixedPcdGet64 (PcdRedfishDebugCategory);
     45  return ((DebugCategory & RedfishDebugCategory) != 0);
    7546}
    7647
     
    367338  return EFI_SUCCESS;
    368339}
     340
     341/**
     342  Debug output raw data buffer.
     343
     344  @param[in]    ErrorLevel  DEBUG macro error level
     345  @param[in]    Buffer      Debug output data buffer.
     346  @param[in]    BufferSize  The size of Buffer in byte.
     347
     348  @retval EFI_SUCCESS             Debug dump finished.
     349  @retval EFI_INVALID_PARAMETER   Buffer is NULL.
     350
     351**/
     352EFI_STATUS
     353DumpBuffer (
     354  IN  UINTN  ErrorLevel,
     355  IN  UINT8  *Buffer,
     356  IN  UINTN  BufferSize
     357  )
     358{
     359  UINTN  Index;
     360
     361  if (Buffer == NULL) {
     362    return EFI_INVALID_PARAMETER;
     363  }
     364
     365  DEBUG ((ErrorLevel, "Address: 0x%p size: %d\n", Buffer, BufferSize));
     366  for (Index = 0; Index < BufferSize; Index++) {
     367    if (Index % REDFISH_PRINT_BUFFER_BYTES_PER_ROW == 0) {
     368      DEBUG ((ErrorLevel, "\n%04X: ", Index));
     369    }
     370
     371    DEBUG ((ErrorLevel, "%02X ", Buffer[Index]));
     372  }
     373
     374  DEBUG ((ErrorLevel, "\n"));
     375
     376  return EFI_SUCCESS;
     377}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf

    r101291 r105670  
    22#  INF file for Redfish debug library.
    33#
    4 #  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     4#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    56#
    67#  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    3334  JsonLib
    3435  MemoryAllocationLib
    35   RedfishLib
     36  RedfishHttpLib
    3637  UefiLib
     38
     39[FixedPcd]
     40  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory
    3741
    3842[Depex]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.c

    r101291 r105670  
    33
    44  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
    5   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    66
    77  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    192192
    193193  @param[out]  SupportedSchema     The supported schema list which is separated by ';'.
    194                                    For example: "x-uefi-redfish-Memory.v1_7_1;x-uefi-redfish-Boot.v1_0_1"
     194                                   For example: "x-UEFI-redfish-Memory.v1_7_1;x-UEFI-redfish-Boot.v1_0_1"
    195195                                   The SupportedSchema is allocated by the callee. It's caller's
    196196                                   responsibility to free this buffer using FreePool().
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPlatformCredentialIpmiLib.inf

    r101291 r105670  
    1414  MODULE_TYPE                    = DXE_DRIVER
    1515  VERSION_STRING                 = 1.0
    16   LIBRARY_CLASS                  = RedfishPlatformCredentialIpmiLib
     16  LIBRARY_CLASS                  = RedfishPlatformCredentialLib
    1717
    1818[Sources]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c

    r101291 r105670  
    55  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    66  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
     7  Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    78
    89    SPDX-License-Identifier: BSD-2-Clause-Patent
     
    520521
    521522/**
    522   edk2 Jansson port does not support doubles, simply return 0.
     523  edk2 Jansson port does not support doubles, simply return integer part.
    523524
    524525  These conversion functions convert the initial portion of the string
     
    541542  would cause underflow, zero is returned and ERANGE is stored in errno.
    542543
    543   @return  Return 0.
     544  @return  Integer part of decimal number.
    544545**/
    545546double
     
    549550  )
    550551{
    551   DEBUG ((DEBUG_ERROR, "We don't supprot double type on edk2 yet!"));
    552   ASSERT (FALSE);
    553   return (double)0;
     552  UINTN  Data;
     553  UINTN  StrLen;
     554
     555  Data   = 0;
     556  StrLen = 0;
     557
     558  if (nptr == NULL) {
     559    return (double)0;
     560  }
     561
     562  AsciiStrDecimalToUintnS (nptr, NULL, &Data);
     563  DEBUG ((DEBUG_WARN, "%a: \"%a\" We don't support double type on edk2 yet. Only integer part is returned: %d\n", __func__, nptr, Data));
     564
     565  //
     566  // Force endptr to the last position of nptr because caller may
     567  // check endptr and raise assertion. We don't support floating
     568  // number in edk2 so this prevents unecessary assertion from happening.
     569  //
     570  if (endptr != NULL) {
     571    StrLen  = AsciiStrLen (nptr);
     572    *endptr = (char *__restrict)nptr + StrLen;
     573  }
     574
     575  return (double)Data;
    554576}
    555577
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf

    r101291 r105670  
    44# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    55# (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
     6# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    67#
    78#    SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2425  RedfishCrtLib.c
    2526
     27[Sources.IA32]
     28  Ia32/MathFtol.c           | MSFT
     29
    2630[LibraryClasses]
    2731  BaseLib
     
    3640  RedfishPkg/RedfishPkg.dec
    3741
    38 
     42[BuildOptions]
     43  MSFT:*_*_IA32_CC_FLAGS = /GL-
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.c

    r101291 r105670  
    55  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    66  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     7  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    78
    89  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    169170
    170171/**
     172  This function returns the Redfish service of a REDFISH_PAYLOAD.
     173
     174  Caller doesn't need to free the returned JSON value because it will be released
     175  in corresponding RedfishCleanupService() function.
     176
     177  @param[in]    Payload     A REDFISH_PAYLOAD instance.
     178
     179  @return     Redfish service of the payload.
     180
     181**/
     182REDFISH_SERVICE
     183EFIAPI
     184RedfishServiceInPayload (
     185  IN REDFISH_PAYLOAD  Payload
     186  )
     187{
     188  if (Payload == NULL) {
     189    return NULL;
     190  }
     191
     192  return ((redfishPayload *)Payload)->service;
     193}
     194
     195/**
    171196  Fill the input RedPath string with system UUID from SMBIOS table or use the customized
    172197  ID if  FromSmbios == FALSE.
     
    245270  @param[out]   RedResponse           Pointer to the Redfish response data.
    246271
    247   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     272  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    248273                                  NULL and the value is 2XX. The corresponding redfish resource has
    249274                                  been returned in Payload within RedResponse.
     
    305330  @param[out]   RedResponse       Pointer to the Redfish response data.
    306331
    307   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     332  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    308333                                  NULL and the value is 2XX. The corresponding redfish resource has
    309334                                  been returned in Payload within RedResponse.
     
    332357  ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
    333358
    334   JsonValue            = getUriFromService (RedfishService, Uri, &RedResponse->StatusCode);
     359  JsonValue            = getUriFromServiceEx (RedfishService, Uri, &RedResponse->Headers, &RedResponse->HeaderCount, &RedResponse->StatusCode);
    335360  RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
    336361
     
    368393  @param[out]   RedResponse       Pointer to the Redfish response data.
    369394
    370   @retval EFI_SUCCESS             The opeartion is successful:
     395  @retval EFI_SUCCESS             The operation is successful:
    371396                                  1. The HTTP StatusCode is NULL and the returned Payload in
    372397                                  RedResponse is not NULL, indicates the Redfish resource has
     
    441466  @param[out]   RedResponse           Pointer to the Redfish response data.
    442467
    443   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     468  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    444469                                  NULL and the value is 2XX. The Redfish resource will be returned
    445470                                  in Payload within RedResponse if server send it back in the HTTP
     
    474499  ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
    475500
    476   JsonValue = (EDKII_JSON_VALUE)patchUriFromService (
     501  JsonValue = (EDKII_JSON_VALUE)patchUriFromServiceEx (
    477502                                  RedfishService,
    478503                                  Uri,
    479504                                  Content,
     505                                  &(RedResponse->Headers),
     506                                  &(RedResponse->HeaderCount),
    480507                                  &(RedResponse->StatusCode)
    481508                                  );
     
    528555
    529556  @param[in]    Target           The target payload to be updated.
    530   @param[in]    Payload          Palyoad with properties to be changed.
     557  @param[in]    Payload          Payload with properties to be changed.
    531558  @param[out]   RedResponse      Pointer to the Redfish response data.
    532559
    533   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     560  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    534561                                  NULL and the value is 2XX. The Redfish resource will be returned
    535562                                  in Payload within RedResponse if server send it back in the HTTP
     
    602629  @param[out]   RedResponse           Pointer to the Redfish response data.
    603630
    604   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     631  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    605632                                  NULL and the value is 2XX. The Redfish resource will be returned
    606633                                  in Payload within RedResponse if server send it back in the HTTP
     
    620647  IN     CONST CHAR8       *Uri,
    621648  IN     CONST CHAR8       *Content,
    622   IN     UINTN             ContentSize,
    623   IN     CONST CHAR8       *ContentType,
     649  IN     UINTN             ContentSize OPTIONAL,
     650  IN     CONST CHAR8       *ContentType OPTIONAL,
    624651  OUT    REDFISH_RESPONSE  *RedResponse
    625652  )
     
    637664  ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
    638665
    639   JsonValue = (EDKII_JSON_VALUE)postUriFromService (
     666  JsonValue = (EDKII_JSON_VALUE)postUriFromServiceEx (
    640667                                  RedfishService,
    641668                                  Uri,
     
    643670                                  ContentSize,
    644671                                  ContentType,
     672                                  &(RedResponse->Headers),
     673                                  &(RedResponse->HeaderCount),
    645674                                  &(RedResponse->StatusCode)
    646675                                  );
     
    695724  @param[out]   RedResponse     Pointer to the Redfish response data.
    696725
    697   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     726  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    698727                                  NULL and the value is 2XX. The Redfish resource will be returned
    699728                                  in Payload within RedResponse if server send it back in the HTTP
     
    763792  @param[out]   RedResponse           Pointer to the Redfish response data.
    764793
    765   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     794  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    766795                                  NULL and the value is 2XX, the Redfish resource has been removed.
    767796                                  If there is any message returned from server, it will be returned
     
    851880  @param[out]   RedResponse           Pointer to the Redfish response data.
    852881
    853   @retval EFI_SUCCESS             The opeartion is successful, indicates the HTTP StatusCode is not
     882  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
    854883                                  NULL and the value is 2XX, the Redfish resource has been removed.
    855884                                  If there is any message returned from server, it will be returned
     
    10611090
    10621091  @param[in]  Payload                  The Redfish payload to be checked.
    1063   @param[in]  OdataTypeName            OdataType will be retrived from mapping list.
     1092  @param[in]  OdataTypeName            OdataType will be retrieved from mapping list.
    10641093  @param[in]  OdataTypeMappingList     The list of OdataType.
    10651094  @param[in]  OdataTypeMappingListSize The number of mapping list
     
    11281157  @param[in]  CollectionSize  Size of this collection
    11291158
    1130   @return EFI_SUCCESS              Coolection size is returned in CollectionSize
     1159  @return EFI_SUCCESS              Collection size is returned in CollectionSize
    11311160  @return EFI_INVALID_PARAMETER    The payload is not a collection.
    11321161**/
     
    12181247  return EFI_SUCCESS;
    12191248}
     1249
     1250/**
     1251  Use HTTP PUT to create new Redfish resource in the Resource Collection.
     1252
     1253  This function uses the RedfishService to put a Redfish resource addressed by
     1254  Uri (only the relative path is required). Changes to one or more properties within
     1255  the target resource are represented in the input Content, properties not specified
     1256  in Content won't be changed by this request. The corresponding redfish response will
     1257  returned, including HTTP StatusCode, Headers and Payload which record any HTTP response
     1258  messages.
     1259
     1260  Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
     1261  redfish response data.
     1262
     1263  @param[in]    RedfishService        The Service to access the Redfish resources.
     1264  @param[in]    Uri                   Relative path to address the resource.
     1265  @param[in]    Content               JSON represented properties to be update.
     1266  @param[in]    ContentSize           Size of the Content to be send to Redfish service
     1267  @param[in]    ContentType           Type of the Content to be send to Redfish service
     1268  @param[out]   RedResponse           Pointer to the Redfish response data.
     1269
     1270  @retval EFI_SUCCESS             The operation is successful, indicates the HTTP StatusCode is not
     1271                                  NULL and the value is 2XX. The Redfish resource will be returned
     1272                                  in Payload within RedResponse if server send it back in the HTTP
     1273                                  response message body.
     1274  @retval EFI_INVALID_PARAMETER   RedfishService, Uri, Content, or RedResponse is NULL.
     1275  @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred. Callers can get
     1276                                  more error info from returned HTTP StatusCode, Headers and Payload
     1277                                  within RedResponse:
     1278                                  1. If the returned StatusCode is NULL, indicates any error happen.
     1279                                  2. If the returned StatusCode is not NULL and the value is not 2XX,
     1280                                     indicates any error happen.
     1281**/
     1282EFI_STATUS
     1283EFIAPI
     1284RedfishPutToUri (
     1285  IN     REDFISH_SERVICE   RedfishService,
     1286  IN     CONST CHAR8       *Uri,
     1287  IN     CONST CHAR8       *Content,
     1288  IN     UINTN             ContentSize OPTIONAL,
     1289  IN     CONST CHAR8       *ContentType OPTIONAL,
     1290  OUT    REDFISH_RESPONSE  *RedResponse
     1291  )
     1292{
     1293  EFI_STATUS        Status;
     1294  EDKII_JSON_VALUE  JsonValue;
     1295
     1296  Status    = EFI_SUCCESS;
     1297  JsonValue = NULL;
     1298
     1299  if ((RedfishService == NULL) || (Uri == NULL) || (Content == NULL) || (RedResponse == NULL)) {
     1300    return EFI_INVALID_PARAMETER;
     1301  }
     1302
     1303  ZeroMem (RedResponse, sizeof (REDFISH_RESPONSE));
     1304
     1305  JsonValue = (EDKII_JSON_VALUE)putUriFromServiceEx (
     1306                                  RedfishService,
     1307                                  Uri,
     1308                                  Content,
     1309                                  ContentSize,
     1310                                  ContentType,
     1311                                  &(RedResponse->Headers),
     1312                                  &(RedResponse->HeaderCount),
     1313                                  &(RedResponse->StatusCode)
     1314                                  );
     1315
     1316  //
     1317  // 1. If the returned StatusCode is NULL, indicates any error happen.
     1318  //
     1319  if (RedResponse->StatusCode == NULL) {
     1320    Status = EFI_DEVICE_ERROR;
     1321    goto ON_EXIT;
     1322  }
     1323
     1324  //
     1325  // 2. If the returned StatusCode is not NULL and the value is not 2XX, indicates any error happen.
     1326  //    NOTE: If there is any error message returned from server, it will be returned in
     1327  //          Payload within RedResponse.
     1328  //
     1329  if ((*(RedResponse->StatusCode) < HTTP_STATUS_200_OK) || \
     1330      (*(RedResponse->StatusCode) > HTTP_STATUS_206_PARTIAL_CONTENT))
     1331  {
     1332    Status = EFI_DEVICE_ERROR;
     1333  }
     1334
     1335ON_EXIT:
     1336  if (JsonValue != NULL) {
     1337    RedResponse->Payload = createRedfishPayload (JsonValue, RedfishService);
     1338    if (RedResponse->Payload == NULL) {
     1339      //
     1340      // Ignore the error when create RedfishPayload, just free the JsonValue since it's not what
     1341      // we care about if the returned StatusCode is 2XX.
     1342      //
     1343      JsonValueFree (JsonValue);
     1344    }
     1345  }
     1346
     1347  return Status;
     1348}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/RedfishLib.inf

    r89983 r105670  
    44#  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    55#  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     6#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    67#
    78#    SPDX-License-Identifier: BSD-2-Clause-Patent
     
    4344  BaseMemoryLib
    4445  DebugLib
     46  JsonLib
    4547  HttpLib
    4648  MemoryAllocationLib
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/RedfishMisc.c

    r99404 r105670  
    44  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    55  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     6  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    169170  This function returns the string of Redfish service version.
    170171
    171   @param[in]   ServiceVerisonStr The string of Redfish service version.
     172  @param[in]   ServiceVersionStr The string of Redfish service version.
    172173  @param[in]   Url               The URL to build Redpath with ID.
    173174                                 Start with "/", for example "/Registries"
    174175  @param[in]   Id                ID string
    175   @param[out]  Redpath           Pointer to retrive Redpath, caller has to free
     176  @param[out]  Redpath           Pointer to retrieved Redpath, caller has to free
    176177                                 the memory allocated for this string.
    177178  @return     EFI_STATUS
     
    180181EFI_STATUS
    181182RedfishBuildRedpathUseId (
    182   IN  CHAR8  *ServiceVerisonStr,
     183  IN  CHAR8  *ServiceVersionStr,
    183184  IN  CHAR8  *Url,
    184185  IN  CHAR8  *Id,
     
    188189  UINTN  RedpathSize;
    189190
    190   if ((Redpath == NULL) || (ServiceVerisonStr == NULL) || (Url == NULL) || (Id == NULL)) {
     191  if ((Redpath == NULL) || (ServiceVersionStr == NULL) || (Url == NULL) || (Id == NULL)) {
    191192    return EFI_INVALID_PARAMETER;
    192193  }
    193194
    194195  RedpathSize = AsciiStrLen ("/") +
    195                 AsciiStrLen (ServiceVerisonStr) +
     196                AsciiStrLen (ServiceVersionStr) +
    196197                AsciiStrLen (Url) +
    197198                AsciiStrLen ("[Id=]") +
     
    202203  }
    203204
    204   AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVerisonStr, Url, Id);
     205  AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVersionStr, Url, Id);
    205206  return EFI_SUCCESS;
    206207}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h

    r99404 r105670  
    1111  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    1212  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     13  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    1314
    1415  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2021
    2122#include <Include/Library/RedfishCrtLib.h>
    22 
     23#include <Library/JsonLib.h>
    2324#include <jansson.h>
    2425#include <redfishService.h>
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h

    r99404 r105670  
    1111  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    1212  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     13  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    1314
    1415  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    106107
    107108json_t *
     109getUriFromServiceEx (
     110  redfishService        *service,
     111  const char            *uri,
     112  EFI_HTTP_HEADER       **Headers,
     113  UINTN                 *HeaderCount,
     114  EFI_HTTP_STATUS_CODE  **StatusCode
     115  );
     116
     117json_t *
    108118patchUriFromService (
    109119  redfishService        *service,
    110120  const char            *uri,
    111121  const char            *content,
     122  EFI_HTTP_STATUS_CODE  **StatusCode
     123  );
     124
     125json_t *
     126patchUriFromServiceEx (
     127  redfishService        *service,
     128  const char            *uri,
     129  const char            *content,
     130  EFI_HTTP_HEADER       **Headers,
     131  UINTN                 *HeaderCount,
    112132  EFI_HTTP_STATUS_CODE  **StatusCode
    113133  );
     
    120140  size_t                contentLength,
    121141  const char            *contentType,
     142  EFI_HTTP_STATUS_CODE  **StatusCode
     143  );
     144
     145json_t *
     146postUriFromServiceEx (
     147  redfishService        *service,
     148  const char            *uri,
     149  const char            *content,
     150  size_t                contentLength,
     151  const char            *contentType,
     152  EFI_HTTP_HEADER       **Headers,
     153  UINTN                 *HeaderCount,
     154  EFI_HTTP_STATUS_CODE  **StatusCode
     155  );
     156
     157json_t *
     158putUriFromServiceEx (
     159  redfishService        *service,
     160  const char            *uri,
     161  const char            *content,
     162  size_t                contentLength,
     163  const char            *contentType,
     164  EFI_HTTP_HEADER       **Headers,
     165  UINTN                 *HeaderCount,
    122166  EFI_HTTP_STATUS_CODE  **StatusCode
    123167  );
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c

    r99404 r105670  
    1111  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    1212  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     13  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    1314
    1415  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    525526
    526527  stringProp = prop->json;
    527   jsonType   = prop->json->type;
     528  jsonType   = JsonGetType (prop->json);
    528529  switch (jsonType) {
    529530    case JSON_OBJECT:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/service.c

    r101291 r105670  
    1111  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
    1212  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     13  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    1314
    1415  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    402403}
    403404
     405EFI_HTTP_HEADER *
     406cloneHttpHeaders (
     407  EFI_HTTP_MESSAGE  *message,
     408  UINTN             *HeaderCount
     409  )
     410{
     411  EFI_HTTP_HEADER  *Buffer;
     412  UINTN            Index;
     413
     414  if ((message == NULL) || (HeaderCount == NULL)) {
     415    return NULL;
     416  }
     417
     418  *HeaderCount = message->HeaderCount;
     419  Buffer       = AllocatePool (sizeof (EFI_HTTP_HEADER) *  message->HeaderCount);
     420  if (Buffer == NULL) {
     421    return NULL;
     422  }
     423
     424  for (Index = 0; Index < message->HeaderCount; Index++) {
     425    Buffer[Index].FieldName = AllocateCopyPool (AsciiStrSize (message->Headers[Index].FieldName), message->Headers[Index].FieldName);
     426    ASSERT (Buffer[Index].FieldName != NULL);
     427    Buffer[Index].FieldValue = AllocateCopyPool (AsciiStrSize (message->Headers[Index].FieldValue), message->Headers[Index].FieldValue);
     428    ASSERT (Buffer[Index].FieldValue != NULL);
     429  }
     430
     431  return Buffer;
     432}
     433
    404434json_t *
    405 getUriFromService (
     435getUriFromServiceEx (
    406436  redfishService        *service,
    407437  const char            *uri,
     438  EFI_HTTP_HEADER       **Headers OPTIONAL,
     439  UINTN                 *HeaderCount OPTIONAL,
    408440  EFI_HTTP_STATUS_CODE  **StatusCode
    409441  )
     
    423455
    424456  *StatusCode = NULL;
     457  if (HeaderCount != NULL) {
     458    *HeaderCount = 0;
     459  }
     460
     461  if (Headers != NULL) {
     462    *Headers = NULL;
     463  }
    425464
    426465  url = makeUrlForService (service, uri);
     
    429468  }
    430469
    431   DEBUG ((DEBUG_MANAGEABILITY, "libredfish: getUriFromService(): %a\n", url));
     470  DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url));
    432471
    433472  //
     
    492531  if (EFI_ERROR (Status)) {
    493532    ret = NULL;
     533
     534    //
     535    // Deliver status code to caller when error happens so caller can do error handling.
     536    //
     537    if (ResponseMsg.Data.Response != NULL) {
     538      *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
     539      if (*StatusCode == NULL) {
     540        ret = NULL;
     541        goto ON_EXIT;
     542      }
     543
     544      //
     545      // The caller shall take the responsibility to free the buffer.
     546      //
     547      **StatusCode = ResponseMsg.Data.Response->StatusCode;
     548    }
     549
    494550    goto ON_EXIT;
    495551  }
     
    509565    //
    510566    **StatusCode = ResponseMsg.Data.Response->StatusCode;
     567  }
     568
     569  if ((ResponseMsg.Headers != NULL) && (Headers != NULL) && (HeaderCount != NULL)) {
     570    *Headers = cloneHttpHeaders (&ResponseMsg, HeaderCount);
    511571  }
    512572
     
    559619
    560620json_t *
    561 patchUriFromService (
     621putUriFromServiceEx (
    562622  redfishService        *service,
    563623  const char            *uri,
    564624  const char            *content,
     625  size_t                contentLength,
     626  const char            *contentType,
     627  EFI_HTTP_HEADER       **Headers OPTIONAL,
     628  UINTN                 *HeaderCount OPTIONAL,
    565629  EFI_HTTP_STATUS_CODE  **StatusCode
    566630  )
     
    582646
    583647  *StatusCode = NULL;
     648  if (HeaderCount != NULL) {
     649    *HeaderCount = 0;
     650  }
     651
     652  if (Headers != NULL) {
     653    *Headers = NULL;
     654  }
     655
     656  url = makeUrlForService (service, uri);
     657  if (url == NULL) {
     658    return NULL;
     659  }
     660
     661  DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url));
     662
     663  if (contentLength == 0) {
     664    contentLength = strlen (content);
     665  }
     666
     667  //
     668  // Step 1: Create HTTP request message with 4 headers:
     669  //
     670  HttpIoHeader = HttpIoCreateHeader ((service->sessionToken != NULL || service->basicAuthStr != NULL) ? 9 : 8);
     671  if (HttpIoHeader == NULL) {
     672    ret = NULL;
     673    goto ON_EXIT;
     674  }
     675
     676  if (service->sessionToken) {
     677    Status = HttpIoSetHeader (HttpIoHeader, "X-Auth-Token", service->sessionToken);
     678    ASSERT_EFI_ERROR (Status);
     679  } else if (service->basicAuthStr) {
     680    Status = HttpIoSetHeader (HttpIoHeader, "Authorization", service->basicAuthStr);
     681    ASSERT_EFI_ERROR (Status);
     682  }
     683
     684  if (contentType == NULL) {
     685    Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", "application/json");
     686    ASSERT_EFI_ERROR (Status);
     687  } else {
     688    Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", (CHAR8 *)contentType);
     689    ASSERT_EFI_ERROR (Status);
     690  }
     691
     692  Status = HttpIoSetHeader (HttpIoHeader, "Host", service->HostHeaderValue);
     693  ASSERT_EFI_ERROR (Status);
     694  Status = HttpIoSetHeader (HttpIoHeader, "Content-Type", "application/json");
     695  ASSERT_EFI_ERROR (Status);
     696  Status = HttpIoSetHeader (HttpIoHeader, "Accept", "application/json");
     697  ASSERT_EFI_ERROR (Status);
     698  Status = HttpIoSetHeader (HttpIoHeader, "User-Agent", "libredfish");
     699  ASSERT_EFI_ERROR (Status);
     700  Status = HttpIoSetHeader (HttpIoHeader, "Connection", "Keep-Alive");
     701  ASSERT_EFI_ERROR (Status);
     702
     703  AsciiSPrint (
     704    ContentLengthStr,
     705    sizeof (ContentLengthStr),
     706    "%lu",
     707    (UINT64)contentLength
     708    );
     709  Status = HttpIoSetHeader (HttpIoHeader, "Content-Length", ContentLengthStr);
     710  ASSERT_EFI_ERROR (Status);
     711  Status = HttpIoSetHeader (HttpIoHeader, "OData-Version", "4.0");
     712  ASSERT_EFI_ERROR (Status);
     713
     714  //
     715  // Step 2: build the rest of HTTP request info.
     716  //
     717  RequestData = AllocateZeroPool (sizeof (EFI_HTTP_REQUEST_DATA));
     718  if (RequestData == NULL) {
     719    ret = NULL;
     720    goto ON_EXIT;
     721  }
     722
     723  RequestData->Method = HttpMethodPut;
     724  RequestData->Url    = C8ToC16 (url);
     725
     726  //
     727  // Step 3: fill in EFI_HTTP_MESSAGE
     728  //
     729  RequestMsg = AllocateZeroPool (sizeof (EFI_HTTP_MESSAGE));
     730  if (RequestMsg == NULL) {
     731    ret = NULL;
     732    goto ON_EXIT;
     733  }
     734
     735  EncodedContent    = (CHAR8 *)content;
     736  EncodedContentLen = contentLength;
     737  //
     738  // We currently only support gzip Content-Encoding.
     739  //
     740  Status = EncodeRequestContent ((CHAR8 *)HTTP_CONTENT_ENCODING_GZIP, (CHAR8 *)content, (VOID **)&EncodedContent, &EncodedContentLen);
     741  if (Status == EFI_INVALID_PARAMETER) {
     742    DEBUG ((DEBUG_ERROR, "%a: Error to encode content.\n", __func__));
     743    ret = NULL;
     744    goto ON_EXIT;
     745  } else if (Status == EFI_UNSUPPORTED) {
     746    DEBUG ((DEBUG_MANAGEABILITY, "No content coding for %a! Use raw data instead.\n", HTTP_CONTENT_ENCODING_GZIP));
     747    Status = HttpIoSetHeader (HttpIoHeader, "Content-Encoding", HTTP_CONTENT_ENCODING_IDENTITY);
     748    ASSERT_EFI_ERROR (Status);
     749  } else {
     750    Status = HttpIoSetHeader (HttpIoHeader, "Content-Encoding", HTTP_CONTENT_ENCODING_GZIP);
     751    ASSERT_EFI_ERROR (Status);
     752  }
     753
     754  RequestMsg->Data.Request = RequestData;
     755  RequestMsg->HeaderCount  = HttpIoHeader->HeaderCount;
     756  RequestMsg->Headers      = HttpIoHeader->Headers;
     757  RequestMsg->BodyLength   = EncodedContentLen;
     758  RequestMsg->Body         = (VOID *)EncodedContent;
     759
     760  ZeroMem (&ResponseMsg, sizeof (ResponseMsg));
     761
     762  //
     763  // Step 4: call RESTEx to get response from REST service.
     764  //
     765  Status = service->RestEx->SendReceive (service->RestEx, RequestMsg, &ResponseMsg);
     766  if (EFI_ERROR (Status)) {
     767    ret = NULL;
     768    goto ON_EXIT;
     769  }
     770
     771  //
     772  // Step 5: Return the HTTP StatusCode and Body message.
     773  //
     774  if (ResponseMsg.Data.Response != NULL) {
     775    *StatusCode = AllocateZeroPool (sizeof (EFI_HTTP_STATUS_CODE));
     776    if (*StatusCode == NULL) {
     777      ret = NULL;
     778      goto ON_EXIT;
     779    }
     780
     781    //
     782    // The caller shall take the responsibility to free the buffer.
     783    //
     784    **StatusCode = ResponseMsg.Data.Response->StatusCode;
     785  }
     786
     787  if ((ResponseMsg.Headers != NULL) && (Headers != NULL) && (HeaderCount != NULL)) {
     788    *Headers = cloneHttpHeaders (&ResponseMsg, HeaderCount);
     789  }
     790
     791  if (EncodedContent != content) {
     792    FreePool (EncodedContent);
     793  }
     794
     795  if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
     796    ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
     797  } else {
     798    //
     799    // There is no message body returned from server.
     800    //
     801    ret = NULL;
     802  }
     803
     804ON_EXIT:
     805  if (url != NULL) {
     806    free (url);
     807  }
     808
     809  if (HttpIoHeader != NULL) {
     810    HttpIoFreeHeader (HttpIoHeader);
     811  }
     812
     813  if (RequestData != NULL) {
     814    RestConfigFreeHttpRequestData (RequestData);
     815  }
     816
     817  if (RequestMsg != NULL) {
     818    FreePool (RequestMsg);
     819  }
     820
     821  RestConfigFreeHttpMessage (&ResponseMsg, FALSE);
     822
     823  return ret;
     824}
     825
     826json_t *
     827patchUriFromServiceEx (
     828  redfishService        *service,
     829  const char            *uri,
     830  const char            *content,
     831  EFI_HTTP_HEADER       **Headers OPTIONAL,
     832  UINTN                 *HeaderCount OPTIONAL,
     833  EFI_HTTP_STATUS_CODE  **StatusCode
     834  )
     835{
     836  char                   *url;
     837  json_t                 *ret;
     838  HTTP_IO_HEADER         *HttpIoHeader = NULL;
     839  EFI_STATUS             Status;
     840  EFI_HTTP_REQUEST_DATA  *RequestData = NULL;
     841  EFI_HTTP_MESSAGE       *RequestMsg  = NULL;
     842  EFI_HTTP_MESSAGE       ResponseMsg;
     843  CHAR8                  ContentLengthStr[80];
     844  CHAR8                  *EncodedContent;
     845  UINTN                  EncodedContentLen;
     846
     847  if ((service == NULL) || (uri == NULL) || (content == NULL) || (StatusCode == NULL)) {
     848    return NULL;
     849  }
     850
     851  *StatusCode = NULL;
     852  if (HeaderCount != NULL) {
     853    *HeaderCount = 0;
     854  }
     855
     856  if (Headers != NULL) {
     857    *Headers = NULL;
     858  }
    584859
    585860  url = makeUrlForService (service, uri);
     
    588863  }
    589864
    590   DEBUG ((DEBUG_MANAGEABILITY, "libredfish: patchUriFromService(): %a\n", url));
     865  DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url));
    591866
    592867  //
     
    702977  }
    703978
     979  if ((ResponseMsg.Headers != NULL) && (Headers != NULL) && (HeaderCount != NULL)) {
     980    *Headers = cloneHttpHeaders (&ResponseMsg, HeaderCount);
     981  }
     982
    704983  if (EncodedContent != content) {
    705984    FreePool (EncodedContent);
     
    7381017
    7391018json_t *
    740 postUriFromService (
     1019postUriFromServiceEx (
    7411020  redfishService        *service,
    7421021  const char            *uri,
     
    7441023  size_t                contentLength,
    7451024  const char            *contentType,
     1025  EFI_HTTP_HEADER       **Headers OPTIONAL,
     1026  UINTN                 *HeaderCount OPTIONAL,
    7461027  EFI_HTTP_STATUS_CODE  **StatusCode
    7471028  )
     
    7641045
    7651046  *StatusCode = NULL;
     1047  if (HeaderCount != NULL) {
     1048    *HeaderCount = 0;
     1049  }
     1050
     1051  if (Headers != NULL) {
     1052    *Headers = NULL;
     1053  }
    7661054
    7671055  url = makeUrlForService (service, uri);
     
    7701058  }
    7711059
    772   DEBUG ((DEBUG_MANAGEABILITY, "libredfish: postUriFromService(): %a\n", url));
     1060  DEBUG ((DEBUG_MANAGEABILITY, "%a: %a\n", __func__, url));
    7731061
    7741062  if (contentLength == 0) {
     
    8511139  Status = service->RestEx->SendReceive (service->RestEx, RequestMsg, &ResponseMsg);
    8521140  if (EFI_ERROR (Status)) {
    853     goto ON_EXIT;
     1141    //
     1142    // If there is no response to handle, go to error exit.
     1143    //
     1144    if (ResponseMsg.Data.Response == NULL) {
     1145      goto ON_EXIT;
     1146    }
    8541147  }
    8551148
     
    8691162  }
    8701163
     1164  if ((ResponseMsg.Headers != NULL) && (Headers != NULL) && (HeaderCount != NULL)) {
     1165    *Headers = cloneHttpHeaders (&ResponseMsg, HeaderCount);
     1166  }
     1167
    8711168  if ((ResponseMsg.BodyLength != 0) && (ResponseMsg.Body != NULL)) {
    8721169    ret = json_loadb (ResponseMsg.Body, ResponseMsg.BodyLength, 0, NULL);
     
    8741171
    8751172  //
    876   // Step 6: Parsing the HttpHeader to retrive the X-Auth-Token if the HTTP StatusCode is correct.
    877   //
    878   if ((ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_200_OK) ||
    879       (ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_204_NO_CONTENT))
     1173  // Step 6: Parsing the HttpHeader to retrieve the X-Auth-Token if the HTTP StatusCode is correct.
     1174  //
     1175  if ((ResponseMsg.Data.Response != NULL) &&
     1176      ((ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_200_OK) ||
     1177       (ResponseMsg.Data.Response->StatusCode == HTTP_STATUS_204_NO_CONTENT)))
    8801178  {
    8811179    HttpHeader = HttpFindHeader (ResponseMsg.HeaderCount, ResponseMsg.Headers, "X-Auth-Token");
     
    8871185      service->sessionToken = AllocateCopyPool (AsciiStrSize (HttpHeader->FieldValue), HttpHeader->FieldValue);
    8881186    }
    889 
    890     /*
    891     //
    892     // Below opeation seems to be unnecessary.
    893     // Besides, the FieldValue for the Location is the full HTTP URI (Http://0.0.0.0:5000/XXX), so we can't use it as the
    894     // parameter of getUriFromService () directly.
    895     //
    896     HttpHeader = HttpFindHeader (ResponseMsg.HeaderCount, ResponseMsg.Headers, "Location");
    897     if (HttpHeader != NULL) {
    898       ret = getUriFromService(service, HttpHeader->FieldValue);
    899       goto ON_EXIT;
    900     }
    901     */
    9021187  }
    9031188
     
    9221207
    9231208  return ret;
     1209}
     1210
     1211json_t *
     1212getUriFromService (
     1213  redfishService        *service,
     1214  const char            *uri,
     1215  EFI_HTTP_STATUS_CODE  **StatusCode
     1216  )
     1217{
     1218  return getUriFromServiceEx (service, uri, NULL, NULL, StatusCode);
     1219}
     1220
     1221json_t *
     1222patchUriFromService (
     1223  redfishService        *service,
     1224  const char            *uri,
     1225  const char            *content,
     1226  EFI_HTTP_STATUS_CODE  **StatusCode
     1227  )
     1228{
     1229  return patchUriFromServiceEx (service, uri, content, NULL, NULL, StatusCode);
     1230}
     1231
     1232json_t *
     1233postUriFromService (
     1234  redfishService        *service,
     1235  const char            *uri,
     1236  const char            *content,
     1237  size_t                contentLength,
     1238  const char            *contentType,
     1239  EFI_HTTP_STATUS_CODE  **StatusCode
     1240  )
     1241{
     1242  return postUriFromServiceEx (service, uri, content, contentLength, contentType, NULL, NULL, StatusCode);
    9241243}
    9251244
     
    14991818
    15001819  url = (char *)malloc (strlen (service->host)+strlen (uri)+1);
     1820  if (url == NULL) {
     1821    return NULL;
     1822  }
     1823
    15011824  strcpy (url, service->host);
    15021825  strcat (url, uri);
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Redfish.fdf.inc

    r101291 r105670  
    77#
    88# (C) Copyright 2020-2021 Hewlett Packard Enterprise Development LP<BR>
    9 # Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     9# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    1010#
    1111#    SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2121  INF RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
    2222  INF MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
     23  INF RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
    2324!endif
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishComponents.dsc.inc

    r101291 r105670  
    88#
    99# (C) Copyright 2020-2021 Hewlett Packard Enterprise Development LP<BR>
    10 # Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     10# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    1111#
    1212#    SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1717  RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
    1818  RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.inf
    19   RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
     19  RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf  {
     20    <LibraryClasses>
     21      SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
     22  }
    2023  RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.inf
    21   RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.inf
     24  RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.inf  {
     25    <LibraryClasses>
     26      SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
     27  }
    2228  RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
    2329  RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
    2430  MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
     31  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
    2532!endif
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c

    r101291 r105670  
    1818// Variables for using RFI Redfish Discover Protocol
    1919//
    20 VOID                           *gEfiRedfishDiscoverRegistration;
    21 EFI_HANDLE                     gEfiRedfishDiscoverControllerHandle = NULL;
    22 EFI_REDFISH_DISCOVER_PROTOCOL  *gEfiRedfishDiscoverProtocol        = NULL;
    23 BOOLEAN                        gRedfishDiscoverActivated           = FALSE;
    24 BOOLEAN                        gRedfishServiceDiscovered           = FALSE;
     20VOID                                    *gEfiRedfishDiscoverRegistration;
     21EFI_HANDLE                              gEfiRedfishDiscoverControllerHandle = NULL;
     22EFI_REDFISH_DISCOVER_PROTOCOL           *gEfiRedfishDiscoverProtocol        = NULL;
     23BOOLEAN                                 gRedfishDiscoverActivated           = FALSE;
     24BOOLEAN                                 gRedfishServiceDiscovered           = FALSE;
     25EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  *mNetworkInterfaces                 = NULL;
     26UINTN                                   mNumberOfNetworkInterfaces;
     27EFI_EVENT                               mEdkIIRedfishHostInterfaceReadyEvent;
     28VOID                                    *mEdkIIRedfishHostInterfaceRegistration;
    2529
    2630///
     
    341345
    342346/**
     347  Callback function executed when the gEdkIIRedfishHostInterfaceReadyProtocolGuid
     348  protocol interface is installed.
     349
     350  @param[in]   Event    Event whose notification function is being invoked.
     351  @param[in]   Context  Pointer to the Context buffer
     352
     353**/
     354VOID
     355EFIAPI
     356AcquireRedfishServiceOnNetworkInterfaceCallback (
     357  IN  EFI_EVENT  Event,
     358  IN  VOID       *Context
     359  )
     360{
     361  EFI_STATUS                              Status;
     362  EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  *ThisNetworkInterface;
     363  UINTN                                   NetworkInterfaceIndex;
     364  EFI_REDFISH_DISCOVERED_TOKEN            *ThisRedfishDiscoveredToken;
     365
     366  ThisNetworkInterface = mNetworkInterfaces;
     367  //
     368  // Loop to discover Redfish service on each network interface.
     369  //
     370  for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < mNumberOfNetworkInterfaces; NetworkInterfaceIndex++) {
     371    ThisRedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
     372    if (ThisRedfishDiscoveredToken == NULL) {
     373      DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __func__));
     374      return;
     375    }
     376
     377    ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
     378
     379    //
     380    // Initial this Redfish Discovered Token
     381    //
     382    Status = gBS->CreateEvent (
     383                    EVT_NOTIFY_SIGNAL,
     384                    TPL_CALLBACK,
     385                    RedfishServiceDiscoveredCallback,
     386                    (VOID *)ThisRedfishDiscoveredToken,
     387                    &ThisRedfishDiscoveredToken->Event
     388                    );
     389    if (EFI_ERROR (Status)) {
     390      FreePool (ThisRedfishDiscoveredToken);
     391      DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __func__));
     392      return;
     393    }
     394
     395    //
     396    // Acquire for Redfish service which is reported by
     397    // Redfish Host Interface.
     398    //
     399    Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
     400                                            gEfiRedfishDiscoverProtocol,
     401                                            gRedfishConfigData.Image,
     402                                            ThisNetworkInterface,
     403                                            EFI_REDFISH_DISCOVER_HOST_INTERFACE,
     404                                            ThisRedfishDiscoveredToken
     405                                            );
     406
     407    //
     408    // Free Redfish Discovered Token if Discover Instance was not created and
     409    // Redfish Service Discovered Callback event was not triggered.
     410    //
     411    if ((ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound == 0) ||
     412        EFI_ERROR (ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances->Status))
     413    {
     414      gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
     415      DEBUG ((DEBUG_ERROR, "%a: Free Redfish discovered token - %x.\n", __func__, ThisRedfishDiscoveredToken));
     416      FreePool (ThisRedfishDiscoveredToken);
     417    }
     418
     419    ThisNetworkInterface++;
     420  }
     421}
     422
     423/**
    343424  Callback function executed when the EFI_REDFISH_DISCOVER_PROTOCOL
    344425  protocol interface is installed.
    345426
    346427  @param[in]   Event    Event whose notification function is being invoked.
    347   @param[out]  Context  Pointer to the Context buffer
     428  @param[in]   Context  Pointer to the Context buffer
    348429
    349430**/
     
    352433RedfishDiscoverProtocolInstalled (
    353434  IN  EFI_EVENT  Event,
    354   OUT VOID       *Context
    355   )
    356 {
    357   EFI_STATUS                              Status;
    358   UINTN                                   BufferSize;
    359   EFI_HANDLE                              HandleBuffer;
    360   UINTN                                   NetworkInterfaceIndex;
    361   EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  *ThisNetworkInterface;
    362   EFI_REDFISH_DISCOVERED_TOKEN            *ThisRedfishDiscoveredToken;
    363   UINTN                                   NumberOfNetworkInterfaces;
     435  IN  VOID       *Context
     436  )
     437{
     438  EFI_STATUS  Status;
     439  UINTN       BufferSize;
     440  EFI_HANDLE  HandleBuffer;
     441  VOID        *RedfishHostInterfaceReadyProtocol;
    364442
    365443  DEBUG ((DEBUG_MANAGEABILITY, "%a: New network interface is installed on system by EFI Redfish discover driver.\n", __func__));
     
    402480                                          gEfiRedfishDiscoverProtocol,
    403481                                          gRedfishConfigData.Image,
    404                                           &NumberOfNetworkInterfaces,
    405                                           &ThisNetworkInterface
     482                                          &mNumberOfNetworkInterfaces,
     483                                          &mNetworkInterfaces
    406484                                          );
    407   if (EFI_ERROR (Status) || (NumberOfNetworkInterfaces == 0)) {
     485  if (EFI_ERROR (Status) || (mNumberOfNetworkInterfaces == 0)) {
    408486    DEBUG ((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n", __func__));
    409487    return;
     
    411489
    412490  //
    413   // Loop to discover Redfish service on each network interface.
    414   //
    415   for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < NumberOfNetworkInterfaces; NetworkInterfaceIndex++) {
    416     ThisRedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
    417     if (ThisRedfishDiscoveredToken == NULL) {
    418       DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __func__));
    419       return;
    420     }
    421 
    422     ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
    423 
    424     //
    425     // Initial this Redfish Discovered Token
    426     //
     491  // Check if Redfish Host Interface is ready or not.
     492  //
     493  Status = gBS->LocateProtocol (&gEdkIIRedfishHostInterfaceReadyProtocolGuid, NULL, &RedfishHostInterfaceReadyProtocol);
     494  if (!EFI_ERROR (Status)) {
     495    // Acquire Redfish service;
     496    AcquireRedfishServiceOnNetworkInterfaceCallback ((EFI_EVENT)NULL, (VOID *)NULL);
     497  } else {
    427498    Status = gBS->CreateEvent (
    428499                    EVT_NOTIFY_SIGNAL,
    429500                    TPL_CALLBACK,
    430                     RedfishServiceDiscoveredCallback,
    431                     (VOID *)ThisRedfishDiscoveredToken,
    432                     &ThisRedfishDiscoveredToken->Event
     501                    AcquireRedfishServiceOnNetworkInterfaceCallback,
     502                    NULL,
     503                    &mEdkIIRedfishHostInterfaceReadyEvent
    433504                    );
    434505    if (EFI_ERROR (Status)) {
    435       FreePool (ThisRedfishDiscoveredToken);
    436       DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __func__));
     506      DEBUG ((DEBUG_ERROR, "%a: Failed to create event for gEdkIIRedfishHostInterfaceReadyProtocolGuid installation.", __func__));
    437507      return;
    438508    }
    439509
    440     //
    441     // Acquire for Redfish service which is reported by
    442     // Redfish Host Interface.
    443     //
    444     Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
    445                                             gEfiRedfishDiscoverProtocol,
    446                                             gRedfishConfigData.Image,
    447                                             ThisNetworkInterface,
    448                                             EFI_REDFISH_DISCOVER_HOST_INTERFACE,
    449                                             ThisRedfishDiscoveredToken
    450                                             );
    451 
    452     //
    453     // Free Redfish Discovered Token if Discover Instance was not created and
    454     // Redfish Service Discovered Callback event was not triggered.
    455     //
    456     if ((ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound == 0) ||
    457         EFI_ERROR (ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances->Status))
    458     {
    459       gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
    460       DEBUG ((DEBUG_ERROR, "%a: Free Redfish discovered token - %x.\n", __func__, ThisRedfishDiscoveredToken));
    461       FreePool (ThisRedfishDiscoveredToken);
    462     }
    463 
    464     ThisNetworkInterface++;
     510    Status = gBS->RegisterProtocolNotify (
     511                    &gEdkIIRedfishHostInterfaceReadyProtocolGuid,
     512                    mEdkIIRedfishHostInterfaceReadyEvent,
     513                    &mEdkIIRedfishHostInterfaceRegistration
     514                    );
     515    if (EFI_ERROR (Status)) {
     516      DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of gEdkIIRedfishHostInterfaceReadyProtocolGuid.", __func__));
     517      return;
     518    }
    465519  }
    466520
     
    548602  // Install UEFI Driver Model protocol(s).
    549603  //
    550   Status = EfiLibInstallDriverBinding (
     604  Status = EfiLibInstallAllDriverProtocols2 (
    551605             ImageHandle,
    552606             SystemTable,
    553607             &gRedfishConfigDriverBinding,
    554              ImageHandle
     608             ImageHandle,
     609             &gRedfishConfigHandlerComponentName,
     610             &gRedfishConfigHandlerComponentName2,
     611             NULL,
     612             NULL,
     613             NULL,
     614             NULL
    555615             );
    556616  if (EFI_ERROR (Status)) {
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h

    r99404 r105670  
    2525// Protocol instances
    2626//
    27 extern EFI_DRIVER_BINDING_PROTOCOL  gRedfishConfigDriverBinding;
     27extern EFI_DRIVER_BINDING_PROTOCOL   gRedfishConfigDriverBinding;
     28extern EFI_COMPONENT_NAME_PROTOCOL   gRedfishConfigHandlerComponentName;
     29extern EFI_COMPONENT_NAME2_PROTOCOL  gRedfishConfigHandlerComponentName2;
    2830
    2931extern REDFISH_CONFIG_DRIVER_DATA         gRedfishConfigData;
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf

    r101291 r105670  
    3131
    3232[Sources]
     33  ComponentName.c
    3334  RedfishConfigHandlerDriver.h
    3435  RedfishConfigHandlerDriver.c
     
    4748
    4849[Protocols]
    49   gEfiRedfishDiscoverProtocolGuid         ## CONSUMES
     50  gEfiRedfishDiscoverProtocolGuid              ## CONSUMES
    5051  gEfiRestExServiceBindingProtocolGuid
    51   gEfiRestExProtocolGuid                  ## CONSUMES
    52   gEdkIIRedfishCredentialProtocolGuid     ## CONSUMES
    53   gEdkIIRedfishConfigHandlerProtocolGuid  ## CONSUMES
     52  gEfiRestExProtocolGuid                       ## CONSUMES
     53  gEdkIIRedfishCredentialProtocolGuid          ## CONSUMES
     54  gEdkIIRedfishConfigHandlerProtocolGuid       ## CONSUMES
     55  gEdkIIRedfishHostInterfaceReadyProtocolGuid  ## CONSUMES
    5456
    5557[Guids]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c

    r101291 r105670  
    77  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    88  Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>
     9  Copyright (c) 2023, Mike Maslenkin <[email protected]> <BR>
    910
    1011  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    4142  );
    4243
    43 static REDFISH_DISCOVER_REQUIRED_PROTOCOL  gRequiredProtocol[] = {
     44static REDFISH_DISCOVER_REQUIRED_PROTOCOL  mRequiredProtocol[] = {
    4445  {
    4546    ProtocolTypeTcp4,
     
    199200  Status                       = Tcp4->Configure (Tcp4, &Tcp4CfgData);
    200201  if (EFI_ERROR (Status)) {
    201     DEBUG ((DEBUG_ERROR, "%a: Can't get subnet information\n", __func__));
     202    if (Status == EFI_NO_MAPPING) {
     203      return EFI_SUCCESS;
     204    }
     205
     206    DEBUG ((DEBUG_ERROR, "%a: Can't get subnet information: %r\n", __func__, Status));
    202207    return Status;
    203208  }
     
    205210  Status = Tcp4->GetModeData (Tcp4, NULL, NULL, &IpModedata, NULL, NULL);
    206211  if (EFI_ERROR (Status)) {
    207     DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __func__));
     212    DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information: %r\n", __func__, Status));
    208213    return Status;
    209214  }
     
    268273  Status = Tcp6->GetModeData (Tcp6, NULL, NULL, &IpModedata, NULL, NULL);
    269274  if (EFI_ERROR (Status)) {
    270     DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __func__));
     275    DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information: %r\n", __func__, Status));
    271276    return Status;
    272277  }
     
    319324  EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterface;
    320325
     326  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
     327    return NULL;
     328  }
     329
    321330  ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
    322331  while (TRUE) {
    323     if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
     332    if ((MAC_COMPARE (ThisNetworkInterface, TargetNetworkInterface)) &&
     333        (VALID_TCP6 (TargetNetworkInterface, ThisNetworkInterface) ||
     334         VALID_TCP4 (TargetNetworkInterface, ThisNetworkInterface)))
     335    {
    324336      return ThisNetworkInterface;
    325337    }
     
    350362{
    351363  EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterface;
     364
     365  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
     366    return NULL;
     367  }
    352368
    353369  ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
     
    396412  ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
    397413  while (TRUE) {
    398     if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
     414    if (MAC_COMPARE (ThisNetworkInterface, TargetNetworkInterface)) {
    399415      break;
    400416    }
     
    468484  if (ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp6) {
    469485    return TRUE;
     486  }
     487
     488  return FALSE;
     489}
     490
     491/**
     492  Check if Network Protocol Type matches with SMBIOS Type 42 IP Address Type.
     493
     494  @param[in]  NetworkProtocolType  The Network Protocol Type to check with.
     495  @param[in]  IpType               The Host IP Address Type from SMBIOS Type 42.
     496**/
     497STATIC
     498BOOLEAN
     499FilterProtocol (
     500  IN UINT32  NetworkProtocolType,
     501  IN UINT8   IpType
     502  )
     503{
     504  if (NetworkProtocolType == ProtocolTypeTcp4) {
     505    return IpType != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4;
     506  }
     507
     508  if (NetworkProtocolType == ProtocolTypeTcp6) {
     509    return IpType != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6;
    470510  }
    471511
     
    508548
    509549  Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, &Data); // Search for SMBIOS type 42h
    510   if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
     550  if (EFI_ERROR (Status) || (Data == NULL) || (DeviceDescriptor == NULL)) {
     551    DEBUG ((DEBUG_ERROR, "%a: RedfishGetHostInterfaceProtocolData is failed.\n", __func__));
     552    return Status;
     553  } else {
     554    // Check IP Type and skip an unnecessary network protocol if does not match
     555    if (FilterProtocol (Instance->NetworkInterface->NetworkProtocolType, Data->HostIpAddressFormat)) {
     556      return EFI_UNSUPPORTED;
     557    }
     558
    511559    //
    512560    // Check if we can reach out Redfish service using this network interface.
     
    523571
    524572    if (MacCompareStatus != 0) {
     573      DEBUG ((DEBUG_ERROR, "%a: MAC address is not matched.\n", __func__));
     574      DEBUG ((
     575        DEBUG_ERROR,
     576        "    NetworkInterface: %02x %02x %02x %02x %02x %02x.\n",
     577        Instance->NetworkInterface->MacAddress.Addr[0],
     578        Instance->NetworkInterface->MacAddress.Addr[1],
     579        Instance->NetworkInterface->MacAddress.Addr[2],
     580        Instance->NetworkInterface->MacAddress.Addr[3],
     581        Instance->NetworkInterface->MacAddress.Addr[4],
     582        Instance->NetworkInterface->MacAddress.Addr[5]
     583        ));
     584      DEBUG ((
     585        DEBUG_ERROR,
     586        "    Redfish Host interface: %02x %02x %02x %02x %02x %02x.\n",
     587        DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress[0],
     588        DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress[1],
     589        DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress[2],
     590        DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress[3],
     591        DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress[4],
     592        DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.MacAddress[5]
     593        ));
    525594      return EFI_UNSUPPORTED;
    526595    }
     
    574643      if (Data->RedfishServiceIpPort == 443) {
    575644        IsHttps = TRUE;
     645        DEBUG ((DEBUG_MANAGEABILITY, "Redfish service port: 443\n"));
     646      } else {
     647        DEBUG ((DEBUG_MANAGEABILITY, "Redfish service port: 80\n"));
    576648      }
    577649
     
    642714
    643715/**
     716  The function releases particular strings into the structure instance.
     717
     718  @param[in]  Information           EFI_REDFISH_DISCOVERED_INFORMATION
     719
     720**/
     721STATIC
     722VOID
     723FreeInformationData (
     724  IN EFI_REDFISH_DISCOVERED_INFORMATION  *Information
     725  )
     726{
     727  if (Information->Location != NULL) {
     728    FreePool (Information->Location);
     729    Information->Location = NULL;
     730  }
     731
     732  if (Information->Uuid != NULL) {
     733    FreePool (Information->Uuid);
     734    Information->Uuid = NULL;
     735  }
     736
     737  if (Information->Os != NULL) {
     738    FreePool (Information->Os);
     739    Information->Os = NULL;
     740  }
     741
     742  if (Information->OsVersion != NULL) {
     743    FreePool (Information->OsVersion);
     744    Information->OsVersion = NULL;
     745  }
     746
     747  if (Information->Product != NULL) {
     748    FreePool (Information->Product);
     749    Information->Product = NULL;
     750  }
     751
     752  if (Information->ProductVer != NULL) {
     753    FreePool (Information->ProductVer);
     754    Information->ProductVer = NULL;
     755  }
     756}
     757
     758/**
     759  The function initializes particular strings into the structure instance.
     760
     761  @param[in]  Information           EFI_REDFISH_DISCOVERED_INFORMATION
     762  @param[in]  IsIpv6                Flag indicating IP version 6 protocol is used
     763  @param[in]  RedfishVersion        Redfish version.
     764  @param[in]  RedfishLocation       Redfish location.
     765  @param[in]  Uuid                  Service UUID string.
     766  @param[in]  Os                    OS string.
     767  @param[in]  OsVer                 OS version string.
     768  @param[in]  Product               Product string.
     769  @param[in]  ProductVer            Product version string.
     770
     771**/
     772STATIC
     773VOID
     774InitInformationData (
     775  IN EFI_REDFISH_DISCOVERED_INFORMATION  *Information,
     776  IN BOOLEAN                             IsIpv6,
     777  IN UINTN                               *RedfishVersion OPTIONAL,
     778  IN CONST CHAR8                         *RedfishLocation OPTIONAL,
     779  IN CONST CHAR8                         *Uuid OPTIONAL,
     780  IN CONST CHAR8                         *Os OPTIONAL,
     781  IN CONST CHAR8                         *OsVer OPTIONAL,
     782  IN CONST CHAR8                         *Product OPTIONAL,
     783  IN CONST CHAR8                         *ProductVer OPTIONAL
     784  )
     785{
     786  UINTN  AllocationSize;
     787
     788  if (RedfishVersion != NULL) {
     789    Information->RedfishVersion = *RedfishVersion;
     790    DEBUG ((DEBUG_MANAGEABILITY, "Redfish service version: %d.\n", Information->RedfishVersion));
     791  }
     792
     793  if (RedfishLocation != NULL) {
     794    AllocationSize = AsciiStrSize (RedfishLocation) * sizeof (CHAR16);
     795
     796    if (IsIpv6) {
     797      AllocationSize += 2 * sizeof (CHAR16); // take into account '[' and ']'
     798    }
     799
     800    Information->Location = AllocatePool (AllocationSize);
     801    if (Information->Location != NULL) {
     802      if (IsIpv6) {
     803        UnicodeSPrintAsciiFormat (Information->Location, AllocationSize, "[%a]", RedfishLocation);
     804      } else {
     805        AsciiStrToUnicodeStrS (RedfishLocation, Information->Location, AllocationSize);
     806      }
     807
     808      DEBUG ((DEBUG_MANAGEABILITY, "Redfish service location: %s.\n", Information->Location));
     809    } else {
     810      DEBUG ((
     811        DEBUG_ERROR,
     812        "%a: Can not allocate memory for Redfish service location: %a.\n",
     813        __func__,
     814        RedfishLocation
     815        ));
     816    }
     817  }
     818
     819  if (Uuid != NULL) {
     820    AllocationSize    = AsciiStrSize (Uuid) * sizeof (CHAR16);
     821    Information->Uuid = AllocatePool (AllocationSize);
     822    if (Information->Uuid != NULL) {
     823      AsciiStrToUnicodeStrS (Uuid, Information->Uuid, AllocationSize);
     824      DEBUG ((DEBUG_MANAGEABILITY, "Service UUID: %s.\n", Information->Uuid));
     825    } else {
     826      DEBUG ((
     827        DEBUG_ERROR,
     828        "%a: Can not allocate memory for Service UUID: %a.\n",
     829        __func__,
     830        Uuid
     831        ));
     832    }
     833  }
     834
     835  if (Os != NULL) {
     836    AllocationSize  = AsciiStrSize (Os) * sizeof (CHAR16);
     837    Information->Os = AllocatePool (AllocationSize);
     838    if (Information->Os != NULL) {
     839      AsciiStrToUnicodeStrS (Os, Information->Os, AllocationSize);
     840    } else {
     841      DEBUG ((
     842        DEBUG_ERROR,
     843        "%a: Can not allocate memory for Redfish service OS: %a.\n",
     844        __func__,
     845        Os
     846        ));
     847    }
     848  }
     849
     850  if (OsVer != NULL) {
     851    AllocationSize         = AsciiStrSize (OsVer) * sizeof (CHAR16);
     852    Information->OsVersion = AllocatePool (AllocationSize);
     853    if (Information->OsVersion != NULL) {
     854      AsciiStrToUnicodeStrS (OsVer, Information->OsVersion, AllocationSize);
     855      DEBUG ((
     856        DEBUG_MANAGEABILITY,
     857        "Redfish service OS: %s, Version:%s.\n",
     858        Information->Os,
     859        Information->OsVersion
     860        ));
     861    } else {
     862      DEBUG ((
     863        DEBUG_ERROR,
     864        "%a: Can not allocate memory for Redfish OS Version:%a.\n",
     865        __func__,
     866        OsVer
     867        ));
     868    }
     869  }
     870
     871  if (Product != NULL) {
     872    AllocationSize       = AsciiStrSize (Product) * sizeof (CHAR16);
     873    Information->Product = AllocatePool (AllocationSize);
     874    if (Information->Product != NULL) {
     875      AsciiStrToUnicodeStrS (Product, Information->Product, AllocationSize);
     876    } else {
     877      DEBUG ((
     878        DEBUG_ERROR,
     879        "%a: Can not allocate memory for Redfish service product: %a.\n",
     880        __func__,
     881        Product
     882        ));
     883    }
     884  }
     885
     886  if (ProductVer != NULL) {
     887    AllocationSize          = AsciiStrSize (ProductVer) * sizeof (CHAR16);
     888    Information->ProductVer = AllocatePool (AllocationSize);
     889    if (Information->ProductVer != NULL) {
     890      AsciiStrToUnicodeStrS (ProductVer, Information->ProductVer, AllocationSize);
     891      DEBUG ((
     892        DEBUG_MANAGEABILITY,
     893        "Redfish service product: %s, Version:%s.\n",
     894        Information->Product,
     895        Information->ProductVer
     896        ));
     897    } else {
     898      DEBUG ((
     899        DEBUG_ERROR,
     900        "%a: Can not allocate memory for Redfish service product Version: %a.\n",
     901        __func__,
     902        ProductVer
     903        ));
     904    }
     905  }
     906}
     907
     908/**
    644909  The function adds a new found Redfish service to internal list and
    645910  notify client.
     
    7591024  }
    7601025
     1026  if (Char16Uuid != NULL) {
     1027    FreePool (Char16Uuid);
     1028  }
     1029
    7611030  if (NewFound || InfoRefresh) {
    7621031    if (!InfoRefresh) {
     
    7721041        return EFI_OUT_OF_RESOURCES;
    7731042      }
     1043    } else {
     1044      FreeInformationData (&DiscoveredInstance->Information);
    7741045    }
    7751046
     
    7771048
    7781049    DiscoveredInstance->Information.UseHttps = UseHttps;
    779     if (RedfishVersion != NULL) {
    780       DiscoveredInstance->Information.RedfishVersion = *RedfishVersion;
    781       DEBUG ((DEBUG_MANAGEABILITY, "Redfish service version: %d.\n", DiscoveredInstance->Information.RedfishVersion));
    782     }
    783 
    784     if (RedfishLocation != NULL) {
    785       DiscoveredInstance->Information.Location = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)RedfishLocation) * sizeof (CHAR16));
    786       AsciiStrToUnicodeStrS ((const CHAR8 *)RedfishLocation, DiscoveredInstance->Information.Location, AsciiStrSize ((const CHAR8 *)RedfishLocation) * sizeof (CHAR16));
    787       DEBUG ((DEBUG_MANAGEABILITY, "Redfish service location: %s.\n", DiscoveredInstance->Information.Location));
    788     }
    789 
    790     if (Uuid != NULL) {
    791       DiscoveredInstance->Information.Uuid = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
    792       AsciiStrToUnicodeStrS ((const CHAR8 *)Uuid, DiscoveredInstance->Information.Uuid, AsciiStrSize ((const CHAR8 *)Uuid) * sizeof (CHAR16));
    793       DEBUG ((DEBUG_MANAGEABILITY, "Service UUID: %s.\n", DiscoveredInstance->Information.Uuid));
    794     }
    795 
    796     if (Os != NULL) {
    797       DiscoveredInstance->Information.Os = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Os) * sizeof (CHAR16));
    798       AsciiStrToUnicodeStrS ((const CHAR8 *)Os, DiscoveredInstance->Information.Os, AsciiStrSize ((const CHAR8 *)Os) * sizeof (CHAR16));
    799       DEBUG ((DEBUG_MANAGEABILITY, "Redfish service OS: %s, Version:%s.\n", DiscoveredInstance->Information.Os, DiscoveredInstance->Information.OsVersion));
    800     }
    801 
    802     if (OsVer != NULL) {
    803       DiscoveredInstance->Information.OsVersion = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)OsVer) * sizeof (CHAR16));
    804       AsciiStrToUnicodeStrS ((const CHAR8 *)OsVer, DiscoveredInstance->Information.OsVersion, AsciiStrSize ((const CHAR8 *)OsVer) * sizeof (CHAR16));
    805     }
    806 
    807     if ((Product != NULL) && (ProductVer != NULL)) {
    808       DiscoveredInstance->Information.Product = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)Product) * sizeof (CHAR16));
    809       AsciiStrToUnicodeStrS ((const CHAR8 *)Product, DiscoveredInstance->Information.Product, AsciiStrSize ((const CHAR8 *)Product) * sizeof (CHAR16));
    810       DiscoveredInstance->Information.ProductVer = (CHAR16 *)AllocatePool (AsciiStrSize ((const CHAR8 *)ProductVer) * sizeof (CHAR16));
    811       AsciiStrToUnicodeStrS ((const CHAR8 *)ProductVer, DiscoveredInstance->Information.ProductVer, AsciiStrSize ((const CHAR8 *)ProductVer) * sizeof (CHAR16));
    812       DEBUG ((DEBUG_MANAGEABILITY, "Redfish service product: %s, Version:%s.\n", DiscoveredInstance->Information.Product, DiscoveredInstance->Information.ProductVer));
    813     }
     1050
     1051    InitInformationData (
     1052      &DiscoveredInstance->Information,
     1053      CheckIsIpVersion6 (NetworkInterface),
     1054      RedfishVersion,
     1055      RedfishLocation,
     1056      Uuid,
     1057      Os,
     1058      OsVer,
     1059      Product,
     1060      ProductVer
     1061      );
    8141062
    8151063    if (RedfishLocation == NULL) {
     
    8351083      }
    8361084    }
    837   }
    838 
    839   if (Char16Uuid != NULL) {
    840     FreePool ((VOID *)Char16Uuid);
    8411085  }
    8421086
     
    8781122      }
    8791123
    880       RestExHttpConfigData->SendReceiveTimeout                = 5000;
     1124      RestExHttpConfigData->SendReceiveTimeout                = PcdGet32 (PcdRedfishSendReceiveTimeout);
    8811125      RestExHttpConfigData->HttpConfigData.HttpVersion        = HttpVersion11;
    8821126      RestExHttpConfigData->HttpConfigData.LocalAddressIsIPv6 = CheckIsIpVersion6 (NetworkInterface);
     
    9121156                         );
    9131157      if (EFI_ERROR (Status)) {
    914         DEBUG ((DEBUG_ERROR, "%a:REST EX configured..\n", __func__));
     1158        DEBUG ((DEBUG_ERROR, "%a: REST EX is not configured..\n", __func__));
    9151159        DeleteRestEx = TRUE;
    9161160        goto EXIT_FREE_ALL;
     1161      } else {
     1162        DEBUG ((DEBUG_MANAGEABILITY, "%a: REST EX is configured..\n", __func__));
    9171163      }
    9181164
     
    9971243
    9981244  ProtocolType = Instance->NetworkProtocolType;
    999   if ((gRequiredProtocol[ProtocolType].GetSubnetInfo != NULL) && (Instance->GotSubnetInfo == FALSE)) {
    1000     Status = gRequiredProtocol[ProtocolType].GetSubnetInfo (
     1245  if ((mRequiredProtocol[ProtocolType].GetSubnetInfo != NULL) && (Instance->GotSubnetInfo == FALSE)) {
     1246    Status = mRequiredProtocol[ProtocolType].GetSubnetInfo (
    10011247                                               ImageHandle,
    10021248                                               Instance
    10031249                                               );
    10041250    if (EFI_ERROR (Status)) {
    1005       DEBUG ((DEBUG_ERROR, "%a:Failed to get Subnet infomation.\n", __func__));
     1251      DEBUG ((DEBUG_ERROR, "%a:Failed to get Subnet information.\n", __func__));
    10061252      return Status;
    10071253    } else {
     
    10091255      if (CheckIsIpVersion6 (Instance)) {
    10101256        if (Instance->SubnetAddrInfoIPv6Number == 0) {
    1011           DEBUG ((DEBUG_ERROR, "%a: There is no Subnet infomation for IPv6 network interface.\n", __func__));
     1257          DEBUG ((DEBUG_WARN, "%a: There is no Subnet information for IPv6 network interface.\n", __func__));
    10121258          return EFI_NOT_FOUND;
    10131259        }
     
    10991345  )
    11001346{
     1347  EFI_STATUS                                       Status;
    11011348  EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterfaceIntn;
    11021349  EFI_REDFISH_DISCOVER_NETWORK_INTERFACE           *ThisNetworkInterface;
    11031350  EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL   *RestExInstance;
     1351
     1352  DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry.\n", __func__));
    11041353
    11051354  if ((This == NULL) || (NetworkIntfInstances == NULL) || (NumberOfNetworkIntfs == NULL) ||
     
    11441393
    11451394    CopyMem ((VOID *)&ThisNetworkInterface->MacAddress, &ThisNetworkInterfaceIntn->MacAddress, ThisNetworkInterfaceIntn->HwAddressSize);
    1146     NetworkInterfaceGetSubnetInfo (ThisNetworkInterfaceIntn, ImageHandle); // Get subnet info.
    1147     if (!ThisNetworkInterface->IsIpv6) {
    1148       IP4_COPY_ADDRESS (&ThisNetworkInterface->SubnetId.v4, &ThisNetworkInterfaceIntn->SubnetAddr.v4); // IPv4 subnet information.
    1149     } else {
    1150       IP6_COPY_ADDRESS (&ThisNetworkInterface->SubnetId.v6, &ThisNetworkInterfaceIntn->SubnetAddr.v6); // IPv6 subnet information in IPv6 address information.
    1151     }
    1152 
    1153     ThisNetworkInterface->SubnetPrefixLength = ThisNetworkInterfaceIntn->SubnetPrefixLength;
    1154     ThisNetworkInterface->VlanId             = ThisNetworkInterfaceIntn->VlanId;
     1395    //
     1396    // If Get Subnet Info failed then skip this interface
     1397    //
     1398    Status = NetworkInterfaceGetSubnetInfo (ThisNetworkInterfaceIntn, ImageHandle); // Get subnet info
     1399    if (!EFI_ERROR (Status)) {
     1400      if (!ThisNetworkInterface->IsIpv6) {
     1401        IP4_COPY_ADDRESS (&ThisNetworkInterface->SubnetId.v4, &ThisNetworkInterfaceIntn->SubnetAddr.v4); // IPv4 subnet information.
     1402      } else {
     1403        IP6_COPY_ADDRESS (&ThisNetworkInterface->SubnetId.v6, &ThisNetworkInterfaceIntn->SubnetAddr.v6); // IPv6 subnet information in IPv6 address information.
     1404      }
     1405
     1406      ThisNetworkInterface->SubnetPrefixLength = ThisNetworkInterfaceIntn->SubnetPrefixLength;
     1407    }
     1408
     1409    ThisNetworkInterface->VlanId = ThisNetworkInterfaceIntn->VlanId;
    11551410    RestExInstance->NumberOfNetworkInterfaces++;
    11561411    if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterfaceIntn->Entry)) {
     
    12271482  if (TargetNetworkInterface != NULL) {
    12281483    TargetNetworkInterfaceInternal = GetTargetNetworkInterfaceInternal (TargetNetworkInterface);
    1229     NumNetworkInterfaces           = 1;
     1484    if (TargetNetworkInterfaceInternal == NULL) {
     1485      DEBUG ((DEBUG_ERROR, "%a:No network interface on platform.\n", __func__));
     1486      return EFI_UNSUPPORTED;
     1487    }
     1488
     1489    NumNetworkInterfaces = 1;
    12301490  } else {
    12311491    TargetNetworkInterfaceInternal = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
     
    12571517      // RedfishServiceGetNetworkInterfaces hasn't been called yet.
    12581518      //
    1259       NetworkInterfaceGetSubnetInfo (TargetNetworkInterfaceInternal, ImageHandle);
     1519      Status1 = NetworkInterfaceGetSubnetInfo (TargetNetworkInterfaceInternal, ImageHandle);
     1520      if (EFI_ERROR (Status1)) {
     1521        //
     1522        // Get subnet information could be failed for EFI_REDFISH_DISCOVER_HOST_INTERFACE case.
     1523        // We will configure network in AddAndSignalNewRedfishService. So don't skip this
     1524        // target network interface.
     1525        //
     1526        if ((Flags & EFI_REDFISH_DISCOVER_HOST_INTERFACE) == 0) {
     1527          DEBUG ((DEBUG_ERROR, "%a: Get subnet information fail.\n", __func__));
     1528          FreePool (Instance);
     1529          continue;
     1530        }
     1531      }
     1532
    12601533      NewInstance = TRUE;
    12611534    }
     
    13231596  )
    13241597{
     1598  DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry.\n", __func__));
    13251599  // This function is used to abort Redfish service discovery through SSDP
    13261600  // on the network interface. SSDP is optionally suppoted by EFI_REDFISH_DISCOVER_PROTOCOL,
     
    13511625  EFI_REDFISH_DISCOVERED_INSTANCE       *ThisRedfishInstance;
    13521626  EFI_REDFISH_DISCOVERED_INTERNAL_LIST  *DiscoveredRedfishInstance;
     1627
     1628  DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry.\n", __func__));
    13531629
    13541630  if (IsListEmpty (&mRedfishInstanceList)) {
     
    13641640      if (DiscoveredRedfishInstance->Instance == ThisRedfishInstance) {
    13651641        RemoveEntryList (&DiscoveredRedfishInstance->NextInstance);
    1366         if (ThisRedfishInstance->Information.Location != NULL) {
    1367           FreePool (ThisRedfishInstance->Information.Location);
    1368         }
    1369 
    1370         if (ThisRedfishInstance->Information.Uuid != NULL) {
    1371           FreePool (ThisRedfishInstance->Information.Uuid);
    1372         }
    1373 
    1374         if (ThisRedfishInstance->Information.Os != NULL) {
    1375           FreePool (ThisRedfishInstance->Information.Os);
    1376         }
    1377 
    1378         if (ThisRedfishInstance->Information.OsVersion != NULL) {
    1379           FreePool (ThisRedfishInstance->Information.OsVersion);
    1380         }
    1381 
    1382         if (ThisRedfishInstance->Information.Product != NULL) {
    1383           FreePool (ThisRedfishInstance->Information.Product);
    1384         }
    1385 
    1386         if (ThisRedfishInstance->Information.ProductVer != NULL) {
    1387           FreePool (ThisRedfishInstance->Information.ProductVer);
    1388         }
    1389 
     1642        FreeInformationData (&ThisRedfishInstance->Information);
    13901643        FreePool ((VOID *)ThisRedfishInstance);
    13911644        goto ReleaseNext;
     
    15031756  Status = gBS->UninstallProtocolInterface (
    15041757                  ThisNetworkInterface->OpenDriverControllerHandle,
    1505                   gRequiredProtocol[ThisNetworkInterface->NetworkProtocolType].DiscoveredProtocolGuid,
     1758                  mRequiredProtocol[ThisNetworkInterface->NetworkProtocolType].DiscoveredProtocolGuid,
    15061759                  &ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolDiscoverId
    15071760                  );
     
    15341787  UINTN       ListCount;
    15351788
    1536   ListCount = (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL));
     1789  ListCount = (sizeof (mRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL));
    15371790  for (Index = 0; Index < ListCount; Index++) {
    15381791    Status = gBS->OpenProtocol (
    15391792                    ControllerHandle,
    1540                     gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
     1793                    mRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
    15411794                    NULL,
    15421795                    This->DriverBindingHandle,
     
    15441797                    EFI_OPEN_PROTOCOL_TEST_PROTOCOL
    15451798                    );
     1799    if (EFI_ERROR (Status)) {
     1800      return EFI_UNSUPPORTED;
     1801    }
     1802
     1803    Status = gBS->OpenProtocol (
     1804                    ControllerHandle,
     1805                    mRequiredProtocol[Index].DiscoveredProtocolGuid,
     1806                    (VOID **)&Id,
     1807                    This->DriverBindingHandle,
     1808                    ControllerHandle,
     1809                    EFI_OPEN_PROTOCOL_GET_PROTOCOL
     1810                    );
    15461811    if (!EFI_ERROR (Status)) {
    1547       Status = gBS->OpenProtocol (
    1548                       ControllerHandle,
    1549                       gRequiredProtocol[Index].DiscoveredProtocolGuid,
    1550                       (VOID **)&Id,
    1551                       This->DriverBindingHandle,
    1552                       ControllerHandle,
    1553                       EFI_OPEN_PROTOCOL_GET_PROTOCOL
    1554                       );
    1555       if (EFI_ERROR (Status)) {
    1556         if (Index == ListCount - 1) {
    1557           DEBUG ((DEBUG_ERROR, "%a: all required protocols are found on this controller handle: %p.\n", __func__, ControllerHandle));
    1558           return EFI_SUCCESS;
    1559         }
    1560       }
    1561     }
    1562   }
    1563 
    1564   return EFI_UNSUPPORTED;
     1812      // Already installed
     1813      return EFI_UNSUPPORTED;
     1814    }
     1815  }
     1816
     1817  DEBUG ((DEBUG_MANAGEABILITY, "%a: all required protocols are found on this controller handle: %p.\n", __func__, ControllerHandle));
     1818  return EFI_SUCCESS;
    15651819}
    15661820
     
    15971851  EFI_TPL                                          OldTpl;
    15981852  BOOLEAN                                          NewNetworkInterfaceInstalled;
    1599 
     1853  UINTN                                            ListCount;
     1854
     1855  ListCount                    = (sizeof (mRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL));
    16001856  NewNetworkInterfaceInstalled = FALSE;
    16011857  Index                        = 0;
    1602   do {
     1858
     1859  for (Index = 0; Index < ListCount; Index++) {
    16031860    Status = gBS->OpenProtocol (
    16041861                    // Already in list?
    16051862                    ControllerHandle,
    1606                     gRequiredProtocol[Index].DiscoveredProtocolGuid,
     1863                    mRequiredProtocol[Index].DiscoveredProtocolGuid,
    16071864                    (VOID **)&Id,
    16081865                    This->DriverBindingHandle,
     
    16111868                    );
    16121869    if (!EFI_ERROR (Status)) {
    1613       Index++;
    1614       if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
    1615         break;
    1616       }
    1617 
    16181870      continue;
    16191871    }
     
    16211873    Status = gBS->OpenProtocol (
    16221874                    ControllerHandle,
    1623                     gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
     1875                    mRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
    16241876                    &TempInterface,
    16251877                    This->DriverBindingHandle,
     
    16281880                    );
    16291881    if (EFI_ERROR (Status)) {
    1630       Index++;
    1631       if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
    1632         break;
    1633       }
    1634 
    16351882      continue;
    16361883    }
    16371884
    1638     if (gRequiredProtocol[Index].ProtocolType != ProtocolTypeRestEx) {
     1885    if (mRequiredProtocol[Index].ProtocolType != ProtocolTypeRestEx) {
    16391886      OldTpl = gBS->RaiseTPL (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL);
    1640       Status = CreateRedfishDiscoverNetworkInterface (ControllerHandle, gRequiredProtocol[Index].ProtocolType, &IsNew, &NetworkInterface);
     1887      Status = CreateRedfishDiscoverNetworkInterface (ControllerHandle, mRequiredProtocol[Index].ProtocolType, &IsNew, &NetworkInterface);
    16411888      if (EFI_ERROR (Status)) {
    16421889        gBS->RestoreTPL (OldTpl);
     
    16441891      }
    16451892
    1646       NetworkInterface->NetworkProtocolType        = gRequiredProtocol[Index].ProtocolType;
     1893      NetworkInterface->NetworkProtocolType        = mRequiredProtocol[Index].ProtocolType;
    16471894      NetworkInterface->OpenDriverAgentHandle      = This->DriverBindingHandle;
    16481895      NetworkInterface->OpenDriverControllerHandle = ControllerHandle;
    1649       CopyGuid (&NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolGuid, gRequiredProtocol[Index].RequiredProtocolGuid);
    1650       CopyGuid (&NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolServiceGuid, gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid);
     1896      CopyGuid (&NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolGuid, mRequiredProtocol[Index].RequiredProtocolGuid);
     1897      CopyGuid (&NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolServiceGuid, mRequiredProtocol[Index].RequiredServiceBindingProtocolGuid);
    16511898      ProtocolDiscoverIdPtr        = &NetworkInterface->NetworkInterfaceProtocolInfo.ProtocolDiscoverId;
    16521899      OpenDriverAgentHandle        = NetworkInterface->OpenDriverAgentHandle;
     
    16861933    Status = gBS->InstallProtocolInterface (
    16871934                    &ControllerHandle,
    1688                     gRequiredProtocol[Index].DiscoveredProtocolGuid,
     1935                    mRequiredProtocol[Index].DiscoveredProtocolGuid,
    16891936                    EFI_NATIVE_INTERFACE,
    16901937                    ProtocolDiscoverIdPtr
    16911938                    );
    16921939    if (EFI_ERROR (Status)) {
    1693       Index++;
    1694       if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
    1695         break;
    1696       }
    1697 
    16981940      continue;
    16991941    }
     
    17051947               ControllerHandle,
    17061948               This->ImageHandle,
    1707                gRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
     1949               mRequiredProtocol[Index].RequiredServiceBindingProtocolGuid,
    17081950               HandleOfProtocolInterfacePtr
    17091951               );
     
    17111953      Status = gBS->OpenProtocol (
    17121954                      *HandleOfProtocolInterfacePtr,
    1713                       gRequiredProtocol[Index].RequiredProtocolGuid,
     1955                      mRequiredProtocol[Index].RequiredProtocolGuid,
    17141956                      Interface,
    17151957                      OpenDriverAgentHandle,
     
    17181960                      );
    17191961      if (!EFI_ERROR (Status)) {
    1720         if ((gRequiredProtocol[Index].ProtocolType == ProtocolTypeRestEx)) {
     1962        if ((mRequiredProtocol[Index].ProtocolType == ProtocolTypeRestEx)) {
    17211963          // Install Redfish Discover Protocol when EFI REST EX protocol is discovered.
    17221964          // This ensures EFI REST EX is ready while the consumer of EFI_REDFISH_DISCOVER_PROTOCOL
     
    17521994        } else {
    17531995          DEBUG ((DEBUG_MANAGEABILITY, "%a: Not REST EX, continue with next\n", __func__));
    1754           Index++;
    1755           if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
    1756             break;
    1757           }
    1758 
    17591996          continue;
    17601997        }
     
    17621999
    17632000      return Status;
    1764     } else {
    1765       Index++;
    1766       if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
    1767         break;
    1768       }
    1769 
    1770       continue;
    1771     }
    1772   } while (Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)));
     2001    }
     2002  }
    17732003
    17742004  return EFI_DEVICE_ERROR;
     
    18452075  EFI_REDFISH_DISCOVER_PROTOCOL                    *RedfishDiscoverProtocol;
    18462076
    1847   for (Index = 0; Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)); Index++) {
     2077  for (Index = 0; Index < (sizeof (mRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)); Index++) {
    18482078    Status = gBS->HandleProtocol (
    18492079                    ControllerHandle,
    1850                     gRequiredProtocol[Index].RequiredProtocolGuid,
     2080                    mRequiredProtocol[Index].RequiredProtocolGuid,
    18512081                    (VOID **)&Interface
    18522082                    );
    18532083    if (!EFI_ERROR (Status)) {
    1854       if (gRequiredProtocol[Index].ProtocolType != ProtocolTypeRestEx) {
     2084      if (mRequiredProtocol[Index].ProtocolType != ProtocolTypeRestEx) {
    18552085        if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
    18562086          return EFI_NOT_FOUND;
     
    18682098                       ThisBindingProtocol,
    18692099                       ControllerHandle,
    1870                        &gRequiredProtocol[Index],
     2100                       &mRequiredProtocol[Index],
    18712101                       ThisNetworkInterface->OpenDriverAgentHandle,
    18722102                       ThisNetworkInterface->OpenDriverControllerHandle
     
    19312161                       ThisBindingProtocol,
    19322162                       ControllerHandle,
    1933                        &gRequiredProtocol[Index],
     2163                       &mRequiredProtocol[Index],
    19342164                       RestExInstance->OpenDriverAgentHandle,
    19352165                       RestExInstance->OpenDriverControllerHandle
     
    20532283  )
    20542284{
     2285  DEBUG ((DEBUG_MANAGEABILITY, "%a:Entry.\n", __func__));
    20552286  return BuildupNetworkInterface (This, ControllerHandle);
    20562287}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.inf

    r101291 r105670  
    5555[Pcd]
    5656  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDiscoverAccessModeInBand ## CONSUMES
    57 
     57  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout       ## CONSUEMS
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h

    r101291 r105670  
    3939#define REDFISH_DISCOVER_VERSION                    0x00010000
    4040#define EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL  TPL_NOTIFY
     41
     42#define MAC_COMPARE(This, Target)  (CompareMem ((VOID *)&(This)->MacAddress, &(Target)->MacAddress, (This)->HwAddressSize) == 0)
     43#define VALID_TCP6(Target, This)   ((Target)->IsIpv6 && ((This)->NetworkProtocolType == ProtocolTypeTcp6))
     44#define VALID_TCP4(Target, This)   (!(Target)->IsIpv6 && ((This)->NetworkProtocolType == ProtocolTypeTcp4))
     45#define REDFISH_HI_ITERFACE_SPECIFIC_DATA_LENGTH_OFFSET  ((UINT16)(UINTN)(&((SMBIOS_TABLE_TYPE42 *)0)->InterfaceTypeSpecificDataLength))
     46#define REDFISH_HI_PROTOCOL_HOSTNAME_LENGTH_OFFSET       ((UINT16)(UINTN)(&((REDFISH_OVER_IP_PROTOCOL_DATA *)0)->RedfishServiceHostnameLength))
    4147
    4248//
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishDiscoverDxe/RedfishSmbiosHostInterface.c

    r101291 r105670  
    5757      if (mType42Record->InterfaceType == MCHostInterfaceTypeNetworkHostInterface) {
    5858        ASSERT (Record->Length >= 9);
    59         Offset    = 5;
     59        Offset    = REDFISH_HI_ITERFACE_SPECIFIC_DATA_LENGTH_OFFSET;
    6060        RecordTmp = (UINT8 *)Record + Offset;
    6161        //
     
    7171        if ((*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) || (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2)) {
    7272          if (*RecordTmp == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
     73            // According to Redfish Host Interface specification, add additional one byte for Device Type field.
    7374            if (SpecificDataLen != sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1) {
    7475              ASSERT (SpecificDataLen == sizeof (PCI_OR_PCIE_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
     
    7677            }
    7778          } else {
     79            // According to Redfish Host Interface specification, add additional one byte for Device Type field.
    7880            if (SpecificDataLen != sizeof (USB_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1) {
    7981              ASSERT (SpecificDataLen == sizeof (USB_INTERFACE_DEVICE_DESCRIPTOR_V2) + 1);
     
    106108            // Redfish Over IP protocol is wrong.
    107109            //
    108             if ((*(RecordTmp + 90) + sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1) != ProtocolLength) {
     110            if ((*(RecordTmp + REDFISH_HI_PROTOCOL_HOSTNAME_LENGTH_OFFSET) + sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1) != ProtocolLength) {
     111              DEBUG ((
     112                DEBUG_ERROR,
     113                "%a: Length of protocol specific data is not match: %d != ProtocolLength(%d).\n",
     114                __func__,
     115                *(RecordTmp + REDFISH_HI_PROTOCOL_HOSTNAME_LENGTH_OFFSET) + sizeof (REDFISH_OVER_IP_PROTOCOL_DATA) - 1,
     116                ProtocolLength
     117                ));
    109118              return EFI_SECURITY_VIOLATION;
    110119            }
     
    115124            //
    116125            if (Offset > mType42Record->Hdr.Length) {
     126              DEBUG ((
     127                DEBUG_ERROR,
     128                "%a: Offset (%d) > mType42Record->Hdr.Length (%d).\n",
     129                __func__,
     130                Offset,
     131                mType42Record->Hdr.Length
     132                ));
    117133              return EFI_SECURITY_VIOLATION;
    118134            }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c

    r101291 r105670  
    5454  EFI_SMBIOS_PROTOCOL                *Smbios;
    5555  EFI_SMBIOS_HANDLE                  MemArrayMappedAddrSmbiosHandle;
    56 
     56  EFI_HANDLE                         Handle;
     57
     58  Handle = NULL;
    5759  //
    5860  // Get platform Redfish host interface device type descriptor data.
     
    227229  }
    228230
     231  //
     232  // Install Redfish Host Interface ready protocol.
     233  //
     234  Status = gBS->InstallProtocolInterface (
     235                  &Handle,
     236                  &gEdkIIRedfishHostInterfaceReadyProtocolGuid,
     237                  EFI_NATIVE_INTERFACE,
     238                  (VOID *)NULL
     239                  );
     240  if (EFI_ERROR (Status)) {
     241    DEBUG ((DEBUG_ERROR, "Failed to install gEdkIIRedfishHostInterfaceReadyProtocolGuid.\n"));
     242    DEBUG ((DEBUG_ERROR, "PlatformConfigHandler driver may not be triggered to acquire Redfish service.\n"));
     243  }
     244
     245  // Set Status to EFI_SUCCESS that indicates SMBIOS 42 record was installed
     246  // on the platform sucessfully.
    229247  Status = EFI_SUCCESS;
    230248
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.inf

    r89983 r105670  
    4444
    4545[Protocols]
    46   gEfiSmbiosProtocolGuid                ## TO_START
     46  gEfiSmbiosProtocolGuid                       ## TO_START
     47  gEdkIIRedfishHostInterfaceReadyProtocolGuid  ## PRODUCED
    4748
    4849[Depex]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishLibs.dsc.inc

    r101291 r105670  
    77#
    88# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
    9 # Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     9# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    1010#
    1111#    SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1515  RestExLib|RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf
    1616  Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
    17   SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
    1817  RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
    1918  JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
     
    2322  HiiUtilityLib|RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf
    2423  RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf
     24  RedfishHttpLib|RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
    2525!endif
    2626
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPkg.ci.yaml

    r99404 r105670  
    33#
    44# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
     5# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    56# SPDX-License-Identifier: BSD-2-Clause-Patent
    67##
    78{
     9    "PrEval": {
     10        "DscPath": "RedfishPkg.dsc",
     11    },
    812    "LicenseCheck": {
    913        "IgnoreFiles": []
     
    3640            "PrivateInclude/Crt/time.h",
    3741            "PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c",
     42            "PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c",
    3843            "Include/Library/RedfishCrtLib.h",
    3944            ##
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPkg.dec

    r101291 r105670  
    55# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
    66# Copyright (c) 2023, American Megatrends International LLC.
    7 # Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     7# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     8# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    89#
    910# SPDX-License-Identifier: BSD-2-Clause-Patent
     
    7071  RedfishPlatformConfigLib|Include/Library/RedfishPlatformConfigLib.h
    7172
     73  ##  @libraryclass  Provides the library functions to access Redfish HTTP
     74  #   protocol.
     75  #
     76  RedfishHttpLib|Include/Library/RedfishHttpLib.h
     77
    7278[LibraryClasses.Common.Private]
    7379  ##  @libraryclass  Provides the private C runtime library functions.
     
    9096  ## Include/Protocol/EdkIIRedfishPlatformConfig.h
    9197  gEdkIIRedfishPlatformConfigProtocolGuid = { 0X4D94A7C7, 0X4CE4, 0X4A84, { 0X88, 0XC1, 0X33, 0X0C, 0XD4, 0XA3, 0X47, 0X67 } }
     98
     99  # Redfish Host Interface ready notification protocol
     100  gEdkIIRedfishHostInterfaceReadyProtocolGuid = { 0xC3F6D062, 0x3D38, 0x4EA4, { 0x92, 0xB1, 0xE8, 0xF8, 0x02, 0x27, 0x63, 0xDF } }
     101
     102  ## Include/Protocol/EdkIIRedfishHttpProtocol.h
     103  gEdkIIRedfishHttpProtocolGuid = { 0x58a0f47e, 0xf45f, 0x4d44, { 0x89, 0x5b, 0x2a, 0xfe, 0xb0, 0x80, 0x15, 0xe2 } }
    92104
    93105[Guids]
     
    139151  #
    140152  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceUuid|L"00000000-0000-0000-0000-000000000000"|VOID*|0x00001006
     153  # Use PCD to declare the Redfish service port, default set to port 443.
     154  # Platform can overide this value in platform DSC file.
     155  #
     156  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServicePort|443|UINT16|0x00001007
    141157  #
    142158  # This PCD indicates that if BMC bootstrap credential service will be disabled by BIOS or not.
    143159  #
    144   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDisableBootstrapCredentialService|FALSE|BOOLEAN|0x00001007
     160  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDisableBootstrapCredentialService|FALSE|BOOLEAN|0x00001008
     161  #
     162  # The EFI_REST_EX_HTTP_CONFIG_DATA.SendReceiveTimeout value that RedfishDiscoverDxe driver
     163  # set to EFI_REST_EX_PROTOCOL.
     164  #
     165  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout|5000|UINT32|0x00001009
     166  #
     167  # This PCD string is introduced for platform developer to set the encoding method supported by BMC Redfish.
     168  # Currently only "None" and "gzip" are supported.
     169  #
     170  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|"None"|VOID*|0x0000100A
     171  #
     172  # Use below PCDs to control Redfhs HTTP protocol.
     173  #
     174  ## The number of retry when HTTP GET request failed. If the value is 0, there is no retry enabled.
     175  gEfiRedfishPkgTokenSpaceGuid.PcdHttpGetRetry|0|UINT16|0x0000100B
     176  ## The number of retry when HTTP PUT request failed. If the value is 0, there is no retry enabled.
     177  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPutRetry|0|UINT16|0x0000100C
     178  ## The number of retry when HTTP PATCH request failed. If the value is 0, there is no retry enabled.
     179  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPatchRetry|0|UINT16|0x0000100D
     180  ## The number of retry when HTTP POST request failed. If the value is 0, there is no retry enabled.
     181  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPostRetry|0|UINT16|0x0000100E
     182  ## The number of retry when HTTP DELETE request failed. If the value is 0, there is no retry enabled.
     183  gEfiRedfishPkgTokenSpaceGuid.PcdHttpDeleteRetry|0|UINT16|0x0000100F
     184  ## The number of second to wait before driver retry HTTP request. If the value is 0, there is no wait before next retry.
     185  gEfiRedfishPkgTokenSpaceGuid.PcdHttpRetryWaitInSecond|1|UINT16|0x00001010
     186  ## This is used to disable Redfish HTTP cache function and every request will be sent to Redfish service.
     187  gEfiRedfishPkgTokenSpaceGuid.PcdHttpCacheDisabled|FALSE|BOOLEAN|0x00001011
     188  #
     189  # Redfish debug catagories
     190  # To enable the debug message for the entire edk2 Redfish implementation, below PCDs must be set.
     191  # DEBUG_MANAGEABILITY must be set PcdDebugPrintErrorLevel.
     192  #
     193  #   0x0000000000000001  RedfishPlatformConfigDxe driver debug enabled.
     194  #
     195  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory|0|UINT64|0x00001012
     196  #
     197  # Redfish RedfishPlatformConfigDxe Debug Properties
     198  #   0x00000001  x-UEFI-redfish string database message enabled
     199  #   0x00000002  Debug Message for dumping formset
     200  #   0x00000004  Debug Message for x-UEFI-redfish searching result
     201  #   0x00000008  Debug Message for x-UEFI-redfish Regular Expression searching result
     202  #
     203  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigDebugProperty|0|UINT32|0x00001013
     204  #
     205  # RedfishPlatformConfigDxe feature enablement
     206  #   0x00000001  Enable building Redfish Attribute Registry menu path.
     207  #   0x00000002  Allow supressed HII option to be exposed on Redfish.
     208  #
     209  # Redfish RedfishPlatformConfigDxe feature Properties
     210  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigFeatureProperty|0|UINT32|0x00001014
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPkg.dsc

    r101291 r105670  
    55# (C) Copyright 2021 Hewlett-Packard Enterprise Development LP.
    66# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
    7 # Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     7# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    88#
    99#    SPDX-License-Identifier: BSD-2-Clause-Patent
     
    4646  RedfishPlatformCredentialLib|RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.inf
    4747  RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.inf
     48  ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
     49  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
    4850
    4951  # NULL instance of IPMI related library.
     
    7375  RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf
    7476  RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf
     77  RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
    7578
    7679  !include RedfishPkg/Redfish.dsc.inc
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c

    r101291 r105670  
    33
    44  (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
    5   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     6  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    205206
    206207/**
     208  Debug dump HII statement value.
     209
     210  @param[in]  ErrorLevel    DEBUG macro error level
     211  @param[in]  Value         HII statement value to dump
     212  @param[in]  Message       Debug message
     213
     214  @retval EFI_SUCCESS       Dump HII statement value successfully
     215  @retval Others            Errors occur
     216
     217**/
     218EFI_STATUS
     219DumpHiiStatementValue (
     220  IN UINTN                ErrorLevel,
     221  IN HII_STATEMENT_VALUE  *Value,
     222  IN CHAR8                *Message OPTIONAL
     223  )
     224{
     225  UINT64  Data;
     226
     227  if (Value == NULL) {
     228    return EFI_INVALID_PARAMETER;
     229  }
     230
     231  switch (Value->Type) {
     232    case EFI_IFR_TYPE_NUM_SIZE_8:
     233      Data = Value->Value.u8;
     234      break;
     235    case EFI_IFR_TYPE_NUM_SIZE_16:
     236      Data = Value->Value.u16;
     237      break;
     238    case EFI_IFR_TYPE_NUM_SIZE_32:
     239      Data = Value->Value.u32;
     240      break;
     241    case EFI_IFR_TYPE_NUM_SIZE_64:
     242      Data = Value->Value.u64;
     243      break;
     244    case EFI_IFR_TYPE_BOOLEAN:
     245      Data = (Value->Value.b ? 1 : 0);
     246      break;
     247    default:
     248      DEBUG ((ErrorLevel, "%a: unsupported type: 0x%x\n", __func__, Value->Type));
     249      return EFI_UNSUPPORTED;
     250  }
     251
     252  if (IS_EMPTY_STRING (Message)) {
     253    DEBUG ((ErrorLevel, "0x%lx\n", Data));
     254  } else {
     255    DEBUG ((ErrorLevel, "%a: 0x%lx\n", Message, Data));
     256  }
     257
     258  return EFI_SUCCESS;
     259}
     260
     261/**
     262  Debug dump HII statement prompt string.
     263
     264  @param[in]  ErrorLevel    DEBUG macro error level
     265  @param[in]  HiiHandle     HII handle instance
     266  @param[in]  HiiStatement  HII statement
     267  @param[in]  Message       Debug message
     268
     269  @retval EFI_SUCCESS       Dump HII statement string successfully
     270  @retval Others            Errors occur
     271
     272**/
     273EFI_STATUS
     274DumpHiiStatementPrompt (
     275  IN UINTN           ErrorLevel,
     276  IN EFI_HII_HANDLE  HiiHandle,
     277  IN HII_STATEMENT   *HiiStatement,
     278  IN CHAR8           *Message OPTIONAL
     279  )
     280{
     281  EFI_STRING  String;
     282
     283  if ((HiiHandle == NULL) || (HiiStatement == NULL)) {
     284    return EFI_INVALID_PARAMETER;
     285  }
     286
     287  if (HiiStatement->Prompt == 0) {
     288    return EFI_NOT_FOUND;
     289  }
     290
     291  String = HiiGetString (HiiHandle, HiiStatement->Prompt, NULL);
     292  if (String == NULL) {
     293    return EFI_NOT_FOUND;
     294  }
     295
     296  if (IS_EMPTY_STRING (Message)) {
     297    DEBUG ((ErrorLevel, "%s\n", String));
     298  } else {
     299    DEBUG ((ErrorLevel, "%a: %s\n", Message, String));
     300  }
     301
     302  FreePool (String);
     303
     304  return EFI_SUCCESS;
     305}
     306
     307/**
    207308  Build the menu path to given statement instance. It is caller's
    208309  responsibility to free returned string buffer.
     
    215316**/
    216317CHAR8 *
    217 BuildMenPath (
     318BuildMenuPath (
    218319  IN REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE  *StatementPrivate
    219320  )
     
    245346
    246347  do {
    247     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "F(%d) <-", FormPrivate->Id));
     348    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "F(%d) <-", FormPrivate->Id));
    248349    FormPrivate = FindFormLinkToThis (FormPrivate);
    249350    if (FormPrivate == NULL) {
     
    287388      AsciiStrCatS (Buffer, OldBufferSize, FormTitle);
    288389      FreePool (FormTitle);
    289       DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, " %a\n", Buffer));
     390      DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, " %a\n", Buffer));
    290391    }
    291392
     
    829930
    830931    TmpString = HiiGetRedfishString (Statement->ParentForm->ParentFormset->HiiHandle, Schema, Option->Text);
     932    if (TmpString == NULL) {
     933      TmpString = HiiGetRedfishString (Statement->ParentForm->ParentFormset->HiiHandle, ENGLISH_LANGUAGE_CODE, Option->Text);
     934    }
     935
    831936    if (TmpString != NULL) {
    832937      if (StrCmp (TmpString, HiiString) == 0) {
     
    891996    default:
    892997      RedfishValue->Type = RedfishValueTypeUnknown;
     998      DEBUG ((DEBUG_ERROR, "%a: Unsupported value type: 0x%x\n", __func__, Value->Type));
    893999      break;
    8941000  }
     
    9561062  }
    9571063
    958   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "Value.Type= 0x%x\n", OrderedListStatement->Value.Type));
    959   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "Value.BufferValueType= 0x%x\n", OrderedListStatement->Value.BufferValueType));
    960   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "Value.BufferLen= 0x%x\n", OrderedListStatement->Value.BufferLen));
    961   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "Value.Buffer= 0x%x\n", OrderedListStatement->Value.Buffer));
    962   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "Value.MaxContainers= 0x%x\n", OrderedListStatement->ExtraData.OrderListData.MaxContainers));
    963   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "StorageWidth= 0x%x\n", OrderedListStatement->StorageWidth));
     1064  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "Value.Type= 0x%x\n", OrderedListStatement->Value.Type));
     1065  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "Value.BufferValueType= 0x%x\n", OrderedListStatement->Value.BufferValueType));
     1066  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "Value.BufferLen= 0x%x\n", OrderedListStatement->Value.BufferLen));
     1067  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "Value.Buffer= 0x%x\n", OrderedListStatement->Value.Buffer));
     1068  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "Value.MaxContainers= 0x%x\n", OrderedListStatement->ExtraData.OrderListData.MaxContainers));
     1069  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "StorageWidth= 0x%x\n", OrderedListStatement->StorageWidth));
    9641070
    9651071  if (OrderedListStatement->Value.Buffer == NULL) {
     
    9781084      Count  = OrderedListStatement->StorageWidth / sizeof (UINT8);
    9791085      for (Index = 0; Index < Count; Index++) {
    980         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%d ", Value8[Index]));
     1086        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%d ", Value8[Index]));
    9811087      }
    9821088
     
    9861092      Count   = OrderedListStatement->StorageWidth / sizeof (UINT16);
    9871093      for (Index = 0; Index < Count; Index++) {
    988         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%d ", Value16[Index]));
     1094        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%d ", Value16[Index]));
    9891095      }
    9901096
     
    9941100      Count   = OrderedListStatement->StorageWidth / sizeof (UINT32);
    9951101      for (Index = 0; Index < Count; Index++) {
    996         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%d ", Value32[Index]));
     1102        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%d ", Value32[Index]));
    9971103      }
    9981104
     
    10021108      Count   = OrderedListStatement->StorageWidth / sizeof (UINT64);
    10031109      for (Index = 0; Index < Count; Index++) {
    1004         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%d ", Value64[Index]));
     1110        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%d ", Value64[Index]));
    10051111      }
    10061112
     
    10101116      Count  = OrderedListStatement->StorageWidth / sizeof (UINT8);
    10111117      for (Index = 0; Index < Count; Index++) {
    1012         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%d ", Value8[Index]));
    1013       }
    1014 
    1015       break;
    1016   }
    1017 
    1018   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "\n"));
     1118        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%d ", Value8[Index]));
     1119      }
     1120
     1121      break;
     1122  }
     1123
     1124  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "\n"));
    10191125}
    10201126
     
    11271233
    11281234    TmpString = HiiGetRedfishString (Statement->ParentForm->ParentFormset->HiiHandle, Schema, Option->Text);
     1235    if (TmpString == NULL) {
     1236      TmpString = HiiGetRedfishString (Statement->ParentForm->ParentFormset->HiiHandle, ENGLISH_LANGUAGE_CODE, Option->Text);
     1237    }
     1238
    11291239    if (TmpString != NULL) {
    11301240      if (StrCmp (TmpString, HiiString) == 0) {
     
    11881298      StringId = HiiValueToOneOfOptionStringId (HiiStatement, Value);
    11891299      if (StringId == 0) {
     1300        //
     1301        // Print prompt string of HII statement for ease of debugging
     1302        //
     1303        DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "Can not find string ID");
     1304        DumpHiiStatementValue (DEBUG_ERROR, Value, "Current value");
    11901305        ASSERT (FALSE);
    11911306        Status = EFI_DEVICE_ERROR;
     
    12551370      StringIdArray = HiiValueToOrderedListOptionStringId (HiiStatement, &Count);
    12561371      if (StringIdArray == NULL) {
     1372        //
     1373        // Print prompt string of HII statement for ease of debugging
     1374        //
     1375        DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "Can not get string ID array");
    12571376        ASSERT (FALSE);
    12581377        Status = EFI_DEVICE_ERROR;
     
    12621381      RedfishValue->Value.StringArray = AllocatePool (sizeof (CHAR8 *) * Count);
    12631382      if (RedfishValue->Value.StringArray == NULL) {
     1383        //
     1384        // Print prompt string of HII statement for ease of debugging
     1385        //
     1386        DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "Can not allocate memory");
    12641387        ASSERT (FALSE);
    12651388        Status = EFI_OUT_OF_RESOURCES;
     
    12681391
    12691392      for (Index = 0; Index < Count; Index++) {
    1270         ASSERT (StringIdArray[Index] != 0);
     1393        if (StringIdArray[Index] == 0) {
     1394          //
     1395          // Print prompt string of HII statement for ease of debugging
     1396          //
     1397          DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "String ID in array is 0");
     1398          ASSERT (FALSE);
     1399        }
     1400
    12711401        RedfishValue->Value.StringArray[Index] = HiiGetRedfishAsciiString (HiiHandle, FullSchema, StringIdArray[Index]);
    12721402        ASSERT (RedfishValue->Value.StringArray[Index] != NULL);
     
    12901420      if (RedfishValue->Value.Buffer == NULL) {
    12911421        //
    1292         // No x-uefi-redfish string defined. Try to get string in English.
     1422        // No x-UEFI-redfish string defined. Try to get string in English.
    12931423        //
    12941424        RedfishValue->Value.Buffer = HiiGetEnglishAsciiString (HiiHandle, HiiStatement->ExtraData.TextTwo);
     
    13711501  }
    13721502
    1373   StringLen = StrLen (UnicodeString) + 1;
     1503  StringLen = HiiStrLen (UnicodeString) + 1;
    13741504  Buffer    = AllocatePool (StringLen * sizeof (CHAR8));
    13751505  if (Buffer == NULL) {
     
    16611791    //
    16621792    if ((TargetStatement->HiiStatement->Operand == EFI_IFR_ONE_OF_OP) && (StatementValue->Type == EFI_IFR_TYPE_STRING)) {
    1663       TempBuffer = StrToUnicodeStr ((CHAR8 *)StatementValue->Buffer);
    1664       if (TempBuffer == NULL) {
    1665         return EFI_OUT_OF_RESOURCES;
    1666       }
    1667 
    1668       FreePool (StatementValue->Buffer);
     1793      //
     1794      // Keep input buffer to TempBuffer because StatementValue will be
     1795      // assigned in HiiStringToOneOfOptionValue().
     1796      //
     1797      TempBuffer                = (EFI_STRING)StatementValue->Buffer;
    16691798      StatementValue->Buffer    = NULL;
    16701799      StatementValue->BufferLen = 0;
     
    17451874  }
    17461875
    1747   if (StatementValue->Value.string != 0) {
    1748     HiiDeleteString (StatementValue->Value.string, TargetStatement->ParentForm->ParentFormset->HiiHandle);
     1876  if ((TargetStatement->HiiStatement->Operand == EFI_IFR_STRING_OP) && (StatementValue->Type == EFI_IFR_TYPE_STRING)) {
     1877    if (StatementValue->Value.string != 0) {
     1878      // Delete HII string which was created for HII statement operand = EFI_IFR_STRING_OP and Type = EFI_IFR_TYPE_STRING.
     1879      HiiDeleteString (StatementValue->Value.string, TargetStatement->ParentForm->ParentFormset->HiiHandle);
     1880    }
    17491881  }
    17501882
     
    18812013  REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE_REF   *StatementRef;
    18822014  LIST_ENTRY                                      *NextLink;
    1883   EFI_STRING                                      TmpString;
    18842015  EFI_STRING                                      *TmpConfigureLangList;
    18852016  UINTN                                           Index;
    18862017  CHAR8                                           *FullSchema;
     2018
     2019  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: Harvest config language of %a_%a (Regex: %s).\n", __func__, Schema, Version, RegexPattern));
    18872020
    18882021  if ((This == NULL) || IS_EMPTY_STRING (Schema) || IS_EMPTY_STRING (Version) || (Count == NULL) || (ConfigureLangList == NULL) || IS_EMPTY_STRING (RegexPattern)) {
     
    19352068      ASSERT (StatementRef->Statement->Description != 0);
    19362069      if (StatementRef->Statement->Description != 0) {
    1937         TmpString = HiiGetRedfishString (StatementRef->Statement->ParentForm->ParentFormset->HiiHandle, FullSchema, StatementRef->Statement->Description);
    1938         ASSERT (TmpString != NULL);
    1939         if (TmpString != NULL) {
    1940           TmpConfigureLangList[Index] = AllocateCopyPool (StrSize (TmpString), TmpString);
    1941           ASSERT (TmpConfigureLangList[Index] != NULL);
    1942           FreePool (TmpString);
    1943           ++Index;
    1944         }
     2070        ASSERT (StatementRef->Statement->XuefiRedfishStr != NULL);
     2071        TmpConfigureLangList[Index] = AllocateCopyPool (HiiStrSize (StatementRef->Statement->XuefiRedfishStr), (VOID *)StatementRef->Statement->XuefiRedfishStr);
     2072        ++Index;
    19452073      }
    19462074    }
     
    19502078  *ConfigureLangList = TmpConfigureLangList;
    19512079
     2080  DEBUG_REDFISH_THIS_MODULE (
     2081    REDFISH_PLATFORM_CONFIG_DEBUG_CONFIG_LANG_REGEX,
     2082    "%a: Number of configure language strings harvested: %d\n",
     2083    __func__,
     2084    StatementList.Count
     2085    );
     2086
     2087  DEBUG_REDFISH_THIS_MODULE_CODE (
     2088    REDFISH_PLATFORM_CONFIG_DEBUG_CONFIG_LANG_REGEX,
     2089    DEBUG_REDFISH (DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE, "%a: Number of configure language strings harvested: %d\n", __func__, StatementList.Count);
     2090    for (Index = 0; Index < *Count; Index++) {
     2091    DEBUG_REDFISH (DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE, "   (%d) %s\n", Index, TmpConfigureLangList[Index]);
     2092  }
     2093
     2094    );
     2095
    19522096RELEASE_RESOURCE:
    19532097
     
    19602104  }
    19612105
     2106  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: exit.\n", __func__));
    19622107  return Status;
    19632108}
     
    19682113  @param[in]   This                Pointer to EDKII_REDFISH_PLATFORM_CONFIG_PROTOCOL instance.
    19692114  @param[out]  SupportedSchema     The supported schema list which is separated by ';'.
    1970                                    For example: "x-uefi-redfish-Memory.v1_7_1;x-uefi-redfish-Boot.v1_0_1"
     2115                                   For example: "x-UEFI-redfish-Memory.v1_7_1;x-UEFI-redfish-Boot.v1_0_1"
    19712116                                   The SupportedSchema is allocated by the callee. It's caller's
    19722117                                   responsibility to free this buffer using FreePool().
     
    21742319  CHAR8                                      *Buffer;
    21752320
     2321  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: Entry\n", __func__));
    21762322  if ((This == NULL) || IS_EMPTY_STRING (Schema) || IS_EMPTY_STRING (Version) || IS_EMPTY_STRING (ConfigureLang) || (AttributeValue == NULL)) {
    21772323    return EFI_INVALID_PARAMETER;
     
    22152361  // Build up menu path
    22162362  //
    2217   AttributeValue->MenuPath = BuildMenPath (TargetStatement);
    2218   if (AttributeValue->MenuPath == NULL) {
    2219     DEBUG ((DEBUG_ERROR, "%a: failed to build menu path for \"%a\"\n", __func__, AttributeValue->AttributeName));
     2363  if (RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_BUILD_MENU_PATH)) {
     2364    AttributeValue->MenuPath = BuildMenuPath (TargetStatement);
     2365    if (AttributeValue->MenuPath == NULL) {
     2366      DEBUG ((DEBUG_ERROR, "%a: failed to build menu path for \"%a\"\n", __func__, AttributeValue->AttributeName));
     2367    }
    22202368  }
    22212369
     
    22482396  }
    22492397
     2398  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: Exit\n", __func__));
    22502399  return Status;
    22512400}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.h

    r101291 r105670  
    33
    44  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
    5   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     6  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2122#include <Library/DebugLib.h>
    2223#include <Library/MemoryAllocationLib.h>
     24#include <Library/PcdLib.h>
    2325#include <Library/PrintLib.h>
     26#include <Library/RedfishDebugLib.h>
    2427#include <Library/UefiLib.h>
    2528#include <Library/UefiBootServicesTableLib.h>
     
    3740//
    3841#include <Protocol/EdkIIRedfishPlatformConfig.h>
     42
     43//
     44// Debug message in DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE scope.
     45// To enable the debug message for this module, below PCDs must be set.
     46//
     47// 1. DEBUG_MANAGEABILITY must be set PcdDebugPrintErrorLevel.
     48//
     49// 2  RedfishPlatformConfigDxe debug enablement must be set in
     50//    PcdRedfishDebugCategory (defined in RedfishPkg.dec)
     51//
     52// 3. The subordinate debug enablement for RedfishPlatformConfigDxe
     53//    must be set in PcdRedfishPlatformConfigDebugProperty (defined
     54//    in RedfishPkg.dec).
     55//
     56#define DEBUG_REDFISH_THIS_MODULE(DebugSubordinate, ...) \
     57  while (RedfishPlatformConfigDebugProp (DebugSubordinate)) { \
     58    DEBUG_REDFISH(DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE, ##__VA_ARGS__); \
     59    break; \
     60  }
     61
     62#define DEBUG_REDFISH_THIS_MODULE_CODE_BEGIN(DebugSubordinate) \
     63  if (RedfishPlatformConfigDebugProp (DebugSubordinate)) {
     64
     65#define DEBUG_REDFISH_THIS_MODULE_CODE_END()  }
     66
     67#define DEBUG_REDFISH_THIS_MODULE_CODE(DebugSubordinate, Expression) \
     68  DEBUG_REDFISH_THIS_MODULE_CODE_BEGIN(DebugSubordinate) \
     69  Expression \
     70  DEBUG_REDFISH_THIS_MODULE_CODE_END()
     71
     72// Subordinate debug property for DEBUG_REDFISH_PLATFORM_CONFIG_DXE
     73#define REDFISH_PLATFORM_CONFIG_DEBUG_STRING_DATABASE     0x00000001
     74#define REDFISH_PLATFORM_CONFIG_DEBUG_DUMP_FORMSET        0x00000002
     75#define REDFISH_PLATFORM_CONFIG_DEBUG_CONFIG_LANG_SEARCH  0x00000004
     76#define REDFISH_PLATFORM_CONFIG_DEBUG_CONFIG_LANG_REGEX   0x00000008
    3977
    4078///
     
    74112#define REDFISH_PLATFORM_CONFIG_PRIVATE_FROM_THIS(a)  BASE_CR (a, REDFISH_PLATFORM_CONFIG_PRIVATE, Protocol)
    75113#define REGULAR_EXPRESSION_INCLUDE_ALL   L".*"
    76 #define CONFIGURE_LANGUAGE_PREFIX        "x-uefi-redfish-"
     114#define CONFIGURE_LANGUAGE_PREFIX        "x-UEFI-redfish-"
    77115#define REDFISH_PLATFORM_CONFIG_VERSION  0x00010000
    78 #define REDFISH_PLATFORM_CONFIG_DEBUG    DEBUG_MANAGEABILITY
    79 #define REDFISH_MENU_PATH_SIZE           8
     116
     117#define REDFISH_MENU_PATH_SIZE  8
     118
     119// Definitions of Redfish platform config capability
     120#define REDFISH_PLATFORM_CONFIG_BUILD_MENU_PATH   0x000000001
     121#define REDFISH_PLATFORM_CONFIG_ALLOW_SUPPRESSED  0x000000002
    80122
    81123/**
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf

    r101291 r105670  
    44#  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
    55#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     6#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    67#
    78#  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2425
    2526[Sources]
     27  RedfishPlatformConfigCapability.c
    2628  RedfishPlatformConfigDxe.h
    2729  RedfishPlatformConfigDxe.c
     
    3739  HiiUtilityLib
    3840  MemoryAllocationLib
     41  PcdLib
    3942  PrintLib
     43  RedfishDebugLib
    4044  UefiLib
    4145  UefiBootServicesTableLib
     
    5256  gEfiRegexSyntaxTypePerlGuid             ## CONSUMED
    5357
     58[FixedPcd]
     59 gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigFeatureProperty
     60 gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigDebugProperty
     61
    5462[Depex]
    5563  TRUE
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.c

    r101291 r105670  
    33
    44  (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
    5   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     6  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    3233
    3334  if ((HiiHandle == NULL) || (StringId == 0)) {
    34     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "???"));
     35    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "???"));
    3536    return EFI_INVALID_PARAMETER;
    3637  }
     
    4142  }
    4243
    43   DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%s", String));
     44  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%s", String));
    4445  FreePool (String);
    4546
     
    7980    HiiNextFormLink = GetNextNode (&FormsetPrivate->HiiFormList, HiiFormLink);
    8081
    81     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "  [%d] form: %d title: ", ++Index, HiiFormPrivate->Id));
     82    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "  [%d] form: %d title: ", ++Index, HiiFormPrivate->Id));
    8283    DumpHiiString (FormsetPrivate->HiiHandle, HiiFormPrivate->Title);
    83     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "\n"));
     84    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "\n"));
    8485
    8586    HiiStatementLink = GetFirstNode (&HiiFormPrivate->StatementList);
     
    8889      HiiNextStatementLink = GetNextNode (&HiiFormPrivate->StatementList, HiiStatementLink);
    8990
    90       DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "    QID: 0x%x Prompt: ", HiiStatementPrivate->QuestionId));
     91      DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "    QID: 0x%x Prompt: ", HiiStatementPrivate->QuestionId));
    9192      DumpHiiString (FormsetPrivate->HiiHandle, HiiStatementPrivate->Description);
    92       DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "\n"));
     93      DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "\n"));
    9394
    9495      HiiStatementLink = HiiNextStatementLink;
     
    125126
    126127  if (IsListEmpty (FormsetList)) {
    127     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: Empty formset list\n", __func__));
     128    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: Empty formset list\n", __func__));
    128129    return EFI_SUCCESS;
    129130  }
     
    135136    HiiFormsetPrivate  = REDFISH_PLATFORM_CONFIG_FORMSET_FROM_LINK (HiiFormsetLink);
    136137
    137     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "[%d] HII Handle: 0x%x formset: %g at %s\n", ++Index, HiiFormsetPrivate->HiiHandle, &HiiFormsetPrivate->Guid, HiiFormsetPrivate->DevicePathStr));
     138    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "[%d] HII Handle: 0x%x formset: %g at %s\n", ++Index, HiiFormsetPrivate->HiiHandle, &HiiFormsetPrivate->Guid, HiiFormsetPrivate->DevicePathStr));
    138139    DumpFormset (HiiFormsetPrivate);
    139140
     
    142143
    143144  return EFI_SUCCESS;
     145}
     146
     147/**
     148  Return the HII string length. We don't check word alignment
     149  of the input string as same as the checking in StrLen
     150  function, because the HII string in the database is compact
     151  at the byte alignment.
     152
     153  @param[in]  String  Input UCS format string.
     154
     155  @retval Length of the string.
     156
     157**/
     158UINTN
     159EFIAPI
     160HiiStrLen (
     161  IN  CONST CHAR16  *String
     162  )
     163{
     164  UINTN  Length;
     165
     166  ASSERT (String != NULL);
     167
     168  for (Length = 0; *String != L'\0'; String++, Length++) {
     169  }
     170
     171  return Length;
     172}
     173
     174/**
     175  Return the HII string size. We don't check word alignment
     176  of the input string as same as the checking in StrLen
     177  function, because the HII string in the database is compact
     178  at the byte alignment.
     179
     180  @param[in]  String  Input UCS format string.
     181
     182  @retval Size of the string.
     183
     184**/
     185UINTN
     186EFIAPI
     187HiiStrSize (
     188  IN      CONST CHAR16  *String
     189  )
     190{
     191  return (HiiStrLen (String) + 1) * sizeof (*String);
     192}
     193
     194/**
     195  Compare two HII strings. We don't check word alignment
     196  of the input string as same as the checking in StrLen
     197  function, because the HII string in the database is compact
     198  at the byte alignment.
     199
     200  @param[in]  FirstString   Input UCS format of string to search.
     201  @param[in]  SecondString  Input UCS format of string to look for in
     202                            FirstString;
     203
     204  @retval 0   The strings are identical.
     205          !0  The strings are not identical.
     206
     207**/
     208INTN
     209EFIAPI
     210HiiStrCmp (
     211  IN      CONST CHAR16  *FirstString,
     212  IN      CONST CHAR16  *SecondString
     213  )
     214{
     215  //
     216  // ASSERT both strings are less long than PcdMaximumUnicodeStringLength
     217  //
     218  ASSERT (HiiStrSize (FirstString) != 0);
     219  ASSERT (HiiStrSize (SecondString) != 0);
     220
     221  while ((*FirstString != L'\0') && (*FirstString == *SecondString)) {
     222    FirstString++;
     223    SecondString++;
     224  }
     225
     226  return *FirstString - *SecondString;
    144227}
    145228
     
    303386
    304387/**
    305   Get string from HII database in English language. The returned string is allocated
    306   using AllocatePool(). The caller is responsible for freeing the allocated buffer using
    307   FreePool().
    308 
    309   @param[in]  HiiHandle         A handle that was previously registered in the HII Database.
    310   @param[in]  StringId          The identifier of the string to retrieved from the string
    311                                 package associated with HiiHandle.
    312 
    313   @retval NULL   The string specified by StringId is not present in the string package.
    314   @retval Other  The string was returned.
    315 
    316 **/
    317 EFI_STRING
    318 HiiGetEnglishString (
    319   IN EFI_HII_HANDLE  HiiHandle,
    320   IN EFI_STRING_ID   StringId
    321   )
    322 {
    323   return HiiGetRedfishString (HiiHandle, ENGLISH_LANGUAGE_CODE, StringId);
    324 }
    325 
    326 /**
    327388  Get ASCII string from HII database in English language. The returned string is allocated
    328389  using AllocatePool(). The caller is responsible for freeing the allocated buffer using
     
    562623        HiiStatementPrivate  = REDFISH_PLATFORM_CONFIG_STATEMENT_FROM_LINK (HiiStatementLink);
    563624
    564         if ((HiiStatementPrivate->Description != 0) && !HiiStatementPrivate->Suppressed) {
    565           TmpString = HiiGetRedfishString (HiiFormsetPrivate->HiiHandle, Schema, HiiStatementPrivate->Description);
     625        if ((HiiStatementPrivate->Description != 0) &&
     626            (RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_ALLOW_SUPPRESSED) || !HiiStatementPrivate->Suppressed))
     627        {
     628          TmpString = HiiStatementPrivate->XuefiRedfishStr;
    566629          if (TmpString != NULL) {
    567630            Status = RegularExpressionProtocol->MatchString (
     
    593656              ++StatementList->Count;
    594657            }
    595 
    596             FreePool (TmpString);
     658          } else {
     659            if (!RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_BUILD_MENU_PATH)) {
     660              DEBUG ((DEBUG_ERROR, "%a: HiiStatementPrivate->XuefiRedfishStr is NULL, x-UEFI-string has something wrong.\n", __func__));
     661              ASSERT (FALSE);
     662            }
    597663          }
    598664        }
     
    637703  REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE  *HiiStatementPrivate;
    638704  EFI_STRING                                 TmpString;
     705  UINTN                                      Index;
    639706
    640707  if ((FormsetList == NULL) || IS_EMPTY_STRING (Schema) || IS_EMPTY_STRING (ConfigureLang)) {
     
    646713  }
    647714
     715  Index          = 0;
    648716  HiiFormsetLink = GetFirstNode (FormsetList);
    649717  while (!IsNull (FormsetList, HiiFormsetLink)) {
     
    670738        HiiStatementPrivate  = REDFISH_PLATFORM_CONFIG_STATEMENT_FROM_LINK (HiiStatementLink);
    671739
    672         DEBUG_CODE (
    673           STATIC UINTN Index = 0;
    674           DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: [%d] search %s in QID: 0x%x form: 0x%x formset: %g\n", __func__, ++Index, ConfigureLang, HiiStatementPrivate->QuestionId, HiiFormPrivate->Id, &HiiFormsetPrivate->Guid));
    675           );
    676 
    677         if (HiiStatementPrivate->Description != 0) {
    678           TmpString = HiiGetRedfishString (HiiFormsetPrivate->HiiHandle, Schema, HiiStatementPrivate->Description);
     740        if ((HiiStatementPrivate->Description != 0) &&
     741            (RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_ALLOW_SUPPRESSED) || !HiiStatementPrivate->Suppressed))
     742        {
     743          TmpString = HiiStatementPrivate->XuefiRedfishStr;
    679744          if (TmpString != NULL) {
    680             if (StrCmp (TmpString, ConfigureLang) == 0) {
    681               FreePool (TmpString);
     745            Index++;
     746            DEBUG_REDFISH_THIS_MODULE (
     747              REDFISH_PLATFORM_CONFIG_DEBUG_CONFIG_LANG_SEARCH,
     748              "%a: [%d] check %s in QID: 0x%x form: 0x%x formset: %g\n",
     749              __func__,
     750              Index,
     751              ConfigureLang,
     752              HiiStatementPrivate->QuestionId,
     753              HiiFormPrivate->Id,
     754              &HiiFormsetPrivate->Guid
     755              );
     756            if (HiiStrCmp (TmpString, ConfigureLang) == 0) {
    682757              return HiiStatementPrivate;
    683758            }
    684 
    685             FreePool (TmpString);
     759          } else {
     760            if (!RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_BUILD_MENU_PATH)) {
     761              DEBUG ((DEBUG_ERROR, "%a: HiiStatementPrivate->XuefiRedfishStr is NULL, x-UEFI-string has something wrong.\n", __func__));
     762              ASSERT (FALSE);
     763            }
    686764          }
    687765        }
     
    742820
    743821/**
     822  Release x-UEFI-string related information.
     823
     824  @param[in]      FormsetPrivate Pointer to HII form-set private instance.
     825
     826  @retval         EFI_STATUS
     827
     828**/
     829EFI_STATUS
     830ReleaseXuefiStringDatabase (
     831  IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE  *FormsetPrivate
     832  )
     833{
     834  REDFISH_X_UEFI_STRING_DATABASE  *ThisDatabase;
     835  REDFISH_X_UEFI_STRING_DATABASE  *PreDatabase;
     836  REDFISH_X_UEFI_STRINGS_ARRAY    *ThisStringArray;
     837  REDFISH_X_UEFI_STRINGS_ARRAY    *PreStringArray;
     838  BOOLEAN                         EndDatabase;
     839  BOOLEAN                         EndArray;
     840
     841  if (FormsetPrivate->HiiPackageListHeader != NULL) {
     842    FreePool (FormsetPrivate->HiiPackageListHeader);
     843  }
     844
     845  // Walk through x-UEFI-redfish string database.
     846  if (!IsListEmpty (&FormsetPrivate->XuefiRedfishStringDatabase)) {
     847    EndDatabase  = FALSE;
     848    ThisDatabase = (REDFISH_X_UEFI_STRING_DATABASE *)GetFirstNode (&FormsetPrivate->XuefiRedfishStringDatabase);
     849    while (!EndDatabase) {
     850      // Walk through string arrays.
     851      if (!IsListEmpty (&ThisDatabase->XuefiRedfishStringArrays)) {
     852        EndArray        = FALSE;
     853        ThisStringArray = (REDFISH_X_UEFI_STRINGS_ARRAY *)GetFirstNode (&ThisDatabase->XuefiRedfishStringArrays);
     854        while (!EndArray) {
     855          // Remove this array
     856          FreePool (ThisStringArray->ArrayEntryAddress);
     857          EndArray       = IsNodeAtEnd (&ThisDatabase->XuefiRedfishStringArrays, &ThisStringArray->NextArray);
     858          PreStringArray = ThisStringArray;
     859          if (!EndArray) {
     860            ThisStringArray = (REDFISH_X_UEFI_STRINGS_ARRAY *)GetNextNode (&ThisDatabase->XuefiRedfishStringArrays, &ThisStringArray->NextArray);
     861          }
     862
     863          RemoveEntryList (&PreStringArray->NextArray);
     864          FreePool (PreStringArray);
     865        }
     866      }
     867
     868      //
     869      // Remove this database
     870      //
     871      EndDatabase = IsNodeAtEnd (&FormsetPrivate->XuefiRedfishStringDatabase, &ThisDatabase->NextXuefiRedfishLanguage);
     872      PreDatabase = ThisDatabase;
     873      if (!EndDatabase) {
     874        ThisDatabase = (REDFISH_X_UEFI_STRING_DATABASE *)GetNextNode (&FormsetPrivate->XuefiRedfishStringDatabase, &ThisDatabase->NextXuefiRedfishLanguage);
     875      }
     876
     877      RemoveEntryList (&PreDatabase->NextXuefiRedfishLanguage);
     878      FreePool (PreDatabase);
     879    }
     880  }
     881
     882  return EFI_SUCCESS;
     883}
     884
     885/**
    744886  Release formset and all the forms and statements that belong to this formset.
    745887
    746   @param[in]      FormsetPrivate Pointer to HP_HII_FORM_SET_PRIVATE
     888  @param[in]      FormsetPrivate Pointer to HII form-set private instance.
    747889
    748890  @retval         EFI_STATUS
     
    779921      // HiiStatementPrivate->HiiStatement will be released in DestroyFormSet().
    780922      //
    781 
    782       if (HiiStatementPrivate->DesStringCache != NULL) {
    783         FreePool (HiiStatementPrivate->DesStringCache);
    784         HiiStatementPrivate->DesStringCache = NULL;
    785       }
    786 
    787923      RemoveEntryList (&HiiStatementPrivate->Link);
    788924      FreePool (HiiStatementPrivate);
     
    821957  }
    822958
     959  ReleaseXuefiStringDatabase (FormsetPrivate);
     960
    823961  return EFI_SUCCESS;
    824962}
     
    846984  //
    847985  InitializeListHead (&NewFormsetPrivate->HiiFormList);
     986  InitializeListHead (&NewFormsetPrivate->XuefiRedfishStringDatabase);
    848987
    849988  return NewFormsetPrivate;
     989}
     990
     991/**
     992  Create new x-UEFI-redfish string array.
     993
     994  @param[in]      XuefiRedfishStringDatabase  The x-UEFI-redfish string database.
     995
     996  @retval         EFI_OUT_OF_RESOURCES  Not enough memory for creating a new array.
     997                  EFI_SUCCESS           New array is created successfully.
     998
     999**/
     1000EFI_STATUS
     1001NewRedfishXuefiStringArray (
     1002  IN  REDFISH_X_UEFI_STRING_DATABASE  *XuefiRedfishStringDatabase
     1003  )
     1004{
     1005  REDFISH_X_UEFI_STRINGS_ARRAY  *ArrayAddress;
     1006
     1007  // Initial first REDFISH_X_UEFI_STRINGS_ARRAY memory.
     1008  ArrayAddress = (REDFISH_X_UEFI_STRINGS_ARRAY *)AllocateZeroPool (sizeof (REDFISH_X_UEFI_STRINGS_ARRAY));
     1009  if (ArrayAddress == NULL) {
     1010    DEBUG ((DEBUG_ERROR, "%a: Failed to allocate REDFISH_X_UEFI_STRINGS_ARRAY.\n", __func__));
     1011    return EFI_OUT_OF_RESOURCES;
     1012  }
     1013
     1014  InitializeListHead (&ArrayAddress->NextArray);
     1015
     1016  // Allocate memory buffer for REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT elements.
     1017  ArrayAddress->ArrayEntryAddress = \
     1018    (REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT *)AllocateZeroPool (sizeof (REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT) * X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER);
     1019  if (ArrayAddress->ArrayEntryAddress == NULL) {
     1020    FreePool (ArrayAddress);
     1021    DEBUG ((DEBUG_ERROR, "%a: Failed to allocate array for REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENTs.\n", __func__));
     1022    return EFI_OUT_OF_RESOURCES;
     1023  }
     1024
     1025  XuefiRedfishStringDatabase->StringsArrayBlocks++;
     1026  InsertTailList (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays, &ArrayAddress->NextArray);
     1027  return EFI_SUCCESS;
     1028}
     1029
     1030/**
     1031  Get the pointer of x-UEFI-redfish database or create a new database.
     1032
     1033  @param[in]      FormsetPrivate          Pointer to HII form-set private instance.
     1034  @param[in]      HiiStringPackageHeader  HII string package header.
     1035
     1036  @retval         Pointer to REDFISH_X_UEFI_STRING_DATABASE.
     1037                  If NULL, it fails to obtain x-UEFI-redfish database.
     1038
     1039**/
     1040REDFISH_X_UEFI_STRING_DATABASE *
     1041GetExistOrCreateXuefiStringDatabase (
     1042  IN  REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE  *FormsetPrivate,
     1043  IN  EFI_HII_STRING_PACKAGE_HDR                *HiiStringPackageHeader
     1044  )
     1045{
     1046  EFI_STATUS                      Status;
     1047  BOOLEAN                         CreateNewOne;
     1048  REDFISH_X_UEFI_STRING_DATABASE  *XuefiRedfishStringDatabase;
     1049
     1050  CreateNewOne               = TRUE;
     1051  XuefiRedfishStringDatabase = NULL;
     1052  if (!IsListEmpty (&FormsetPrivate->XuefiRedfishStringDatabase)) {
     1053    XuefiRedfishStringDatabase = (REDFISH_X_UEFI_STRING_DATABASE *)GetFirstNode (&FormsetPrivate->XuefiRedfishStringDatabase);
     1054
     1055    while (TRUE) {
     1056      if (AsciiStriCmp (XuefiRedfishStringDatabase->XuefiRedfishLanguage, HiiStringPackageHeader->Language) == 0) {
     1057        CreateNewOne = FALSE;
     1058        break;
     1059      }
     1060
     1061      if (IsNodeAtEnd (&FormsetPrivate->XuefiRedfishStringDatabase, &XuefiRedfishStringDatabase->NextXuefiRedfishLanguage)) {
     1062        break;
     1063      }
     1064
     1065      XuefiRedfishStringDatabase = \
     1066        (REDFISH_X_UEFI_STRING_DATABASE *)GetNextNode (&FormsetPrivate->XuefiRedfishStringDatabase, &XuefiRedfishStringDatabase->NextXuefiRedfishLanguage);
     1067    }
     1068  }
     1069
     1070  if (CreateNewOne) {
     1071    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "  Creating x-UEFI-redfish (%a) string database...\n", HiiStringPackageHeader->Language));
     1072    XuefiRedfishStringDatabase = (REDFISH_X_UEFI_STRING_DATABASE *)AllocateZeroPool (sizeof (REDFISH_X_UEFI_STRING_DATABASE));
     1073    if (XuefiRedfishStringDatabase == NULL) {
     1074      DEBUG ((DEBUG_ERROR, "  Failed to allocate REDFISH_X_UEFI_STRING_DATABASE.\n"));
     1075      return NULL;
     1076    }
     1077
     1078    InitializeListHead (&XuefiRedfishStringDatabase->NextXuefiRedfishLanguage);
     1079    InitializeListHead (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays);
     1080    XuefiRedfishStringDatabase->StringsArrayBlocks   = 0;
     1081    XuefiRedfishStringDatabase->XuefiRedfishLanguage = HiiStringPackageHeader->Language;
     1082
     1083    Status = NewRedfishXuefiStringArray (XuefiRedfishStringDatabase);
     1084    if (EFI_ERROR (Status)) {
     1085      FreePool (XuefiRedfishStringDatabase);
     1086      return NULL;
     1087    }
     1088
     1089    DEBUG ((
     1090      DEBUG_REDFISH_PLATFORM_CONFIG,
     1091      "  x-UEFI-redfish (%a):\n    String array is added to XuefiRedfishStringDatabase, total %d arrays now.\n",
     1092      XuefiRedfishStringDatabase->XuefiRedfishLanguage,
     1093      XuefiRedfishStringDatabase->StringsArrayBlocks
     1094      ));
     1095
     1096    // Link string database to FormsetPrivate.
     1097    InsertTailList (&FormsetPrivate->XuefiRedfishStringDatabase, &XuefiRedfishStringDatabase->NextXuefiRedfishLanguage);
     1098  }
     1099
     1100  return XuefiRedfishStringDatabase;
     1101}
     1102
     1103/**
     1104  Check and allocate a new x-UEFI-redfish array if it is insufficient for the
     1105  newly added x-UEFI-redfish string.
     1106
     1107  @param[in]      FormsetPrivate              Pointer to HII form-set private instance.
     1108  @param[in]      XuefiRedfishStringDatabase  Pointer to the x-UEFI-redfish database.
     1109  @param[in]      StringId                    String ID added to database.
     1110
     1111  @retval         EFI_SUCCESS                 The size of x-UEFI-string array is adjusted or
     1112                                              is not required to be adjusted.
     1113                  Otherwise, refer to the error code returned from NewRedfishXuefiStringArray().
     1114
     1115**/
     1116EFI_STATUS
     1117RedfishXuefiStringAdjustArrays (
     1118  IN  REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE  *FormsetPrivate,
     1119  IN  REDFISH_X_UEFI_STRING_DATABASE            *XuefiRedfishStringDatabase,
     1120  IN  EFI_STRING_ID                             StringId
     1121  )
     1122{
     1123  EFI_STATUS  Status;
     1124
     1125  while (((StringId + X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER) / X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER) > (UINT16)XuefiRedfishStringDatabase->StringsArrayBlocks) {
     1126    Status = NewRedfishXuefiStringArray (XuefiRedfishStringDatabase);
     1127    if (EFI_ERROR (Status)) {
     1128      DEBUG ((DEBUG_ERROR, "%a: Failed to adjust x-UEFI-string array", __func__));
     1129      return Status;
     1130    }
     1131  }
     1132
     1133  return EFI_SUCCESS;
     1134}
     1135
     1136/**
     1137  Insert a x-UEFI-redfish string to database.
     1138
     1139  @param[in]      FormsetPrivate          Pointer to HII form-set private instance.
     1140  @param[in]      HiiStringPackageHeader  Pointer to HII string package.
     1141  @param[in]      StringId                The HII string ID
     1142  @param[in]      StringTextPtr           Pointer to HII string text.
     1143
     1144  @retval         EFI_SUCCESS             The HII string is added to database.
     1145                  EFI_LOAD_ERROR          Something wrong when insert an HII string
     1146                                          to database.
     1147
     1148**/
     1149EFI_STATUS
     1150RedfishXuefiStringInsertDatabase (
     1151  IN  REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE  *FormsetPrivate,
     1152  IN  EFI_HII_STRING_PACKAGE_HDR                *HiiStringPackageHeader,
     1153  IN  EFI_STRING_ID                             StringId,
     1154  IN  CHAR16                                    *StringTextPtr
     1155  )
     1156{
     1157  EFI_STATUS                      Status;
     1158  UINTN                           StringIdOffset;
     1159  REDFISH_X_UEFI_STRING_DATABASE  *XuefiRedfishStringDatabase;
     1160  REDFISH_X_UEFI_STRINGS_ARRAY    *ThisArray;
     1161
     1162  XuefiRedfishStringDatabase = GetExistOrCreateXuefiStringDatabase (FormsetPrivate, HiiStringPackageHeader);
     1163  if (XuefiRedfishStringDatabase == NULL) {
     1164    DEBUG ((DEBUG_ERROR, "%a: Failed to get REDFISH_X_UEFI_STRING_DATABASE of x-UEFI-redfish language %a.\n", __func__, HiiStringPackageHeader->Language));
     1165    ReleaseXuefiStringDatabase (FormsetPrivate);
     1166    return EFI_LOAD_ERROR;
     1167  }
     1168
     1169  Status = RedfishXuefiStringAdjustArrays (FormsetPrivate, XuefiRedfishStringDatabase, StringId);
     1170  if (EFI_ERROR (Status)) {
     1171    DEBUG ((DEBUG_ERROR, "%a: Failed to adjust x-UEFI-redfish string array.\n", __func__));
     1172    ReleaseXuefiStringDatabase (FormsetPrivate);
     1173    return EFI_LOAD_ERROR;
     1174  }
     1175
     1176  // Insert string to x-UEFI-redfish string array.
     1177  StringIdOffset = (UINTN)StringId;
     1178  ThisArray      = (REDFISH_X_UEFI_STRINGS_ARRAY *)GetFirstNode (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays);
     1179  while (StringIdOffset >= X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER) {
     1180    ThisArray       = (REDFISH_X_UEFI_STRINGS_ARRAY *)GetNextNode (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays, &ThisArray->NextArray);
     1181    StringIdOffset -= X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER;
     1182  }
     1183
     1184  // Insert string
     1185  (ThisArray->ArrayEntryAddress + StringIdOffset)->StringId  = StringId;
     1186  (ThisArray->ArrayEntryAddress + StringIdOffset)->UcsString = StringTextPtr;
     1187
     1188  DEBUG_REDFISH_THIS_MODULE (
     1189    REDFISH_PLATFORM_CONFIG_DEBUG_STRING_DATABASE,
     1190    "  Insert string ID: (%d) to database\n    x-UEFI-string: \"%s\"\n    Language: %a.\n",
     1191    StringId,
     1192    StringTextPtr,
     1193    HiiStringPackageHeader->Language
     1194    );
     1195  return EFI_SUCCESS;
     1196}
     1197
     1198/**
     1199  Get x-UEFI-redfish string and language by string ID.
     1200
     1201  @param[in]       FormsetPrivate          Pointer to HII form-set private instance.
     1202  @param[in]       HiiStringPackageHeader  HII string package header.
     1203  @param[out]      TotalStringAdded        Return the total strings added to database.
     1204
     1205  @retval  TRUE   x-UEFI-redfish string and ID map is inserted to database.
     1206           FALSE  Something is wrong when insert x-UEFI-redfish string and ID map.
     1207
     1208**/
     1209BOOLEAN
     1210CreateXuefiLanguageStringIdMap (
     1211  IN   REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE  *FormsetPrivate,
     1212  IN   EFI_HII_STRING_PACKAGE_HDR                *HiiStringPackageHeader,
     1213  OUT  UINTN                                     *TotalStringAdded
     1214  )
     1215{
     1216  EFI_STATUS               Status;
     1217  UINT8                    *BlockHdr;
     1218  EFI_STRING_ID            CurrentStringId;
     1219  UINTN                    BlockSize;
     1220  UINTN                    Index;
     1221  UINT8                    *StringTextPtr;
     1222  UINTN                    Offset;
     1223  UINT16                   StringCount;
     1224  UINT16                   SkipCount;
     1225  UINT8                    Length8;
     1226  EFI_HII_SIBT_EXT2_BLOCK  Ext2;
     1227  UINT32                   Length32;
     1228  UINT8                    *StringBlockInfo;
     1229  UINTN                    StringsAdded;
     1230
     1231  StringsAdded = 0;
     1232
     1233  //
     1234  // Parse the string blocks to get the string text and font.
     1235  //
     1236  StringBlockInfo = (UINT8 *)((UINTN)HiiStringPackageHeader + HiiStringPackageHeader->StringInfoOffset);
     1237  BlockHdr        = StringBlockInfo;
     1238  BlockSize       = 0;
     1239  Offset          = 0;
     1240  CurrentStringId = 1;
     1241  while (*BlockHdr != EFI_HII_SIBT_END) {
     1242    switch (*BlockHdr) {
     1243      case EFI_HII_SIBT_STRING_SCSU:
     1244        Offset        = sizeof (EFI_HII_STRING_BLOCK);
     1245        StringTextPtr = BlockHdr + Offset;
     1246        BlockSize    += Offset + AsciiStrSize ((CHAR8 *)StringTextPtr);
     1247        CurrentStringId++;
     1248        break;
     1249
     1250      case EFI_HII_SIBT_STRING_SCSU_FONT:
     1251        Offset        = sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - sizeof (UINT8);
     1252        StringTextPtr = BlockHdr + Offset;
     1253        BlockSize    += Offset + AsciiStrSize ((CHAR8 *)StringTextPtr);
     1254        CurrentStringId++;
     1255        break;
     1256
     1257      case EFI_HII_SIBT_STRINGS_SCSU:
     1258        CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
     1259        StringTextPtr = (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8));
     1260        BlockSize    += StringTextPtr - BlockHdr;
     1261
     1262        for (Index = 0; Index < StringCount; Index++) {
     1263          BlockSize    += AsciiStrSize ((CHAR8 *)StringTextPtr);
     1264          StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *)StringTextPtr);
     1265          CurrentStringId++;
     1266        }
     1267
     1268        break;
     1269
     1270      case EFI_HII_SIBT_STRINGS_SCSU_FONT:
     1271        CopyMem (
     1272          &StringCount,
     1273          (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
     1274          sizeof (UINT16)
     1275          );
     1276        StringTextPtr = (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8));
     1277        BlockSize    += StringTextPtr - BlockHdr;
     1278
     1279        for (Index = 0; Index < StringCount; Index++) {
     1280          BlockSize    += AsciiStrSize ((CHAR8 *)StringTextPtr);
     1281          StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *)StringTextPtr);
     1282          CurrentStringId++;
     1283        }
     1284
     1285        break;
     1286
     1287      case EFI_HII_SIBT_STRING_UCS2:
     1288        Offset        = sizeof (EFI_HII_STRING_BLOCK);
     1289        StringTextPtr = BlockHdr + Offset;
     1290
     1291        // x-UEFI-redfish string is always encoded as UCS and started with '/'.
     1292        if (*StringTextPtr == (UINT16)'/') {
     1293          Status = RedfishXuefiStringInsertDatabase (
     1294                     FormsetPrivate,
     1295                     HiiStringPackageHeader,
     1296                     CurrentStringId,
     1297                     (CHAR16 *)StringTextPtr
     1298                     );
     1299          if (EFI_ERROR (Status)) {
     1300            DEBUG ((DEBUG_ERROR, "%a: Failed to insert x-UEFI-redfish string %s.\n", __func__, StringTextPtr));
     1301            return FALSE;
     1302          }
     1303
     1304          StringsAdded++;
     1305        }
     1306
     1307        BlockSize += (Offset + HiiStrSize ((CHAR16 *)StringTextPtr));
     1308        CurrentStringId++;
     1309        break;
     1310
     1311      case EFI_HII_SIBT_STRING_UCS2_FONT:
     1312        Offset        = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK)  - sizeof (CHAR16);
     1313        StringTextPtr = BlockHdr + Offset;
     1314        BlockSize    += (Offset + HiiStrSize ((CHAR16 *)StringTextPtr));
     1315        CurrentStringId++;
     1316        break;
     1317
     1318      case EFI_HII_SIBT_STRINGS_UCS2:
     1319        Offset        = sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeof (CHAR16);
     1320        StringTextPtr = BlockHdr + Offset;
     1321        BlockSize    += Offset;
     1322        CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
     1323        for (Index = 0; Index < StringCount; Index++) {
     1324          BlockSize    += HiiStrSize ((CHAR16 *)StringTextPtr);
     1325          StringTextPtr = StringTextPtr + HiiStrSize ((CHAR16 *)StringTextPtr);
     1326          CurrentStringId++;
     1327        }
     1328
     1329        break;
     1330
     1331      case EFI_HII_SIBT_STRINGS_UCS2_FONT:
     1332        Offset        = sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - sizeof (CHAR16);
     1333        StringTextPtr = BlockHdr + Offset;
     1334        BlockSize    += Offset;
     1335        CopyMem (
     1336          &StringCount,
     1337          (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
     1338          sizeof (UINT16)
     1339          );
     1340        for (Index = 0; Index < StringCount; Index++) {
     1341          BlockSize    += HiiStrSize ((CHAR16 *)StringTextPtr);
     1342          StringTextPtr = StringTextPtr + HiiStrSize ((CHAR16 *)StringTextPtr);
     1343          CurrentStringId++;
     1344        }
     1345
     1346        break;
     1347
     1348      case EFI_HII_SIBT_DUPLICATE:
     1349        BlockSize += sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK);
     1350        CurrentStringId++;
     1351        break;
     1352
     1353      case EFI_HII_SIBT_SKIP1:
     1354        SkipCount       = (UINT16)(*(UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK)));
     1355        CurrentStringId = (UINT16)(CurrentStringId + SkipCount);
     1356        BlockSize      +=  sizeof (EFI_HII_SIBT_SKIP1_BLOCK);
     1357        break;
     1358
     1359      case EFI_HII_SIBT_SKIP2:
     1360        CopyMem (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));
     1361        CurrentStringId = (UINT16)(CurrentStringId + SkipCount);
     1362        BlockSize      +=  sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
     1363        break;
     1364
     1365      case EFI_HII_SIBT_EXT1:
     1366        CopyMem (
     1367          &Length8,
     1368          (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
     1369          sizeof (UINT8)
     1370          );
     1371        BlockSize += Length8;
     1372        break;
     1373
     1374      case EFI_HII_SIBT_EXT2:
     1375        CopyMem (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK));
     1376        BlockSize += Ext2.Length;
     1377        break;
     1378
     1379      case EFI_HII_SIBT_EXT4:
     1380        CopyMem (
     1381          &Length32,
     1382          (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)),
     1383          sizeof (UINT32)
     1384          );
     1385
     1386        BlockSize += Length32;
     1387        break;
     1388
     1389      default:
     1390        break;
     1391    }
     1392
     1393    BlockHdr = (UINT8 *)(StringBlockInfo + BlockSize);
     1394  }
     1395
     1396  *TotalStringAdded = StringsAdded;
     1397  return TRUE;
     1398}
     1399
     1400/**
     1401  Get x-UEFI-redfish string and language by string ID.
     1402
     1403  @param[in]      FormsetPrivate       Pointer to HII form-set private instance.
     1404  @param[in]      StringId             The HII string ID.
     1405  @param[out]     String               Optionally return USC string.
     1406  @param[out]     Language             Optionally return x-UEFI-redfish language.
     1407  @param[out]     XuefiStringDatabase  Optionally return x-UEFI-redfish database.
     1408
     1409  @retval  EFI_SUCCESS            String information is returned.
     1410           EFI_INVALID_PARAMETER  One of the given parameters to this function is
     1411                                  invalid.
     1412           EFI_NOT_FOUND          String is not found.
     1413
     1414**/
     1415EFI_STATUS
     1416GetXuefiStringAndLangByStringId (
     1417  IN   REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE  *FormsetPrivate,
     1418  IN   EFI_STRING_ID                             StringId,
     1419  OUT  CHAR16                                    **String OPTIONAL,
     1420  OUT  CHAR8                                     **Language OPTIONAL,
     1421  OUT  REDFISH_X_UEFI_STRING_DATABASE            **XuefiStringDatabase OPTIONAL
     1422  )
     1423{
     1424  REDFISH_X_UEFI_STRING_DATABASE  *XuefiRedfishStringDatabase;
     1425  REDFISH_X_UEFI_STRINGS_ARRAY    *StringArray;
     1426  UINT16                          StringIndex;
     1427
     1428  if ((String == NULL) && (Language == NULL) && (XuefiStringDatabase == NULL)) {
     1429    DEBUG ((DEBUG_ERROR, "%a: Invalid parameters for this function.\n", __func__));
     1430    return EFI_INVALID_PARAMETER;
     1431  }
     1432
     1433  if (IsListEmpty (&FormsetPrivate->XuefiRedfishStringDatabase)) {
     1434    return EFI_NOT_FOUND;
     1435  }
     1436
     1437  XuefiRedfishStringDatabase = (REDFISH_X_UEFI_STRING_DATABASE *)GetFirstNode (&FormsetPrivate->XuefiRedfishStringDatabase);
     1438  while (TRUE) {
     1439    if (Language != NULL) {
     1440      *Language = XuefiRedfishStringDatabase->XuefiRedfishLanguage;
     1441    }
     1442
     1443    StringArray = (REDFISH_X_UEFI_STRINGS_ARRAY *)GetFirstNode (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays);
     1444
     1445    // Loop to the correct string array.
     1446    StringIndex = StringId;
     1447    while (StringIndex >= X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER) {
     1448      if (IsNodeAtEnd (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays, &StringArray->NextArray)) {
     1449        goto ErrorExit;
     1450      }
     1451
     1452      StringArray  = (REDFISH_X_UEFI_STRINGS_ARRAY *)GetNextNode (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays, &StringArray->NextArray);
     1453      StringIndex -= X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER;
     1454    }
     1455
     1456    //
     1457    // NOTE: The string ID in the formset is a unique number.
     1458    //       If the string in the array is NULL, then the matched string ID
     1459    //       should be in another x-UEFI-redfish database.
     1460    //
     1461    if ((StringArray->ArrayEntryAddress + StringIndex)->UcsString != NULL) {
     1462      //
     1463      // String ID is belong to this x-uef-redfish language database.
     1464      //
     1465      if (String != NULL) {
     1466        *String = (StringArray->ArrayEntryAddress + StringIndex)->UcsString;
     1467      }
     1468
     1469      if (XuefiStringDatabase != NULL) {
     1470        *XuefiStringDatabase = XuefiRedfishStringDatabase;
     1471      }
     1472
     1473      return EFI_SUCCESS;
     1474    }
     1475
     1476    if (IsNodeAtEnd (&FormsetPrivate->XuefiRedfishStringDatabase, &XuefiRedfishStringDatabase->NextXuefiRedfishLanguage)) {
     1477      return EFI_NOT_FOUND;
     1478    }
     1479
     1480    XuefiRedfishStringDatabase = (REDFISH_X_UEFI_STRING_DATABASE *)GetNextNode (
     1481                                                                     &FormsetPrivate->XuefiRedfishStringDatabase,
     1482                                                                     &XuefiRedfishStringDatabase->NextXuefiRedfishLanguage
     1483                                                                     );
     1484  }
     1485
     1486ErrorExit:;
     1487  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: String ID (%d) is not in any x-uef-redfish string databases.\n", __func__, StringId));
     1488  return EFI_NOT_FOUND;
     1489}
     1490
     1491/**
     1492  Build a x-UEFI-redfish database for the newly added x-UEFI-redfish language.
     1493
     1494  @param[in]      FormsetPrivate          Pointer to HII form-set private instance.
     1495
     1496**/
     1497VOID
     1498BuildXUefiRedfishStringDatabase (
     1499  IN  REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE  *FormsetPrivate
     1500  )
     1501{
     1502  EFI_STATUS                  Status;
     1503  UINTN                       BufferSize;
     1504  EFI_HII_PACKAGE_HEADER      *PackageHeader;
     1505  UINTN                       EndingPackageAddress;
     1506  EFI_HII_STRING_PACKAGE_HDR  *HiiStringPackageHeader;
     1507  UINTN                       SupportedSchemaLangCount;
     1508  CHAR8                       **SupportedSchemaLang;
     1509  BOOLEAN                     StringIdMapIsBuilt;
     1510  UINTN                       TotalStringsAdded;
     1511  UINTN                       NumberPackageStrings;
     1512
     1513  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: Building x-UEFI-redfish string database, HII Formset GUID - %g.\n", __func__, FormsetPrivate->Guid));
     1514
     1515  BufferSize = 0;
     1516  Status     = mRedfishPlatformConfigPrivate->HiiDatabase->ExportPackageLists (
     1517                                                             mRedfishPlatformConfigPrivate->HiiDatabase,
     1518                                                             FormsetPrivate->HiiHandle,
     1519                                                             &BufferSize,
     1520                                                             FormsetPrivate->HiiPackageListHeader
     1521                                                             );
     1522  if (Status != EFI_BUFFER_TOO_SMALL) {
     1523    DEBUG ((DEBUG_ERROR, "  Failed to export package list.\n"));
     1524    return;
     1525  }
     1526
     1527  FormsetPrivate->HiiPackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER *)AllocateZeroPool (BufferSize);
     1528  if (FormsetPrivate->HiiPackageListHeader == NULL) {
     1529    DEBUG ((DEBUG_ERROR, "  Failed to allocate memory for the exported package list.\n"));
     1530    return;
     1531  }
     1532
     1533  Status = mRedfishPlatformConfigPrivate->HiiDatabase->ExportPackageLists (
     1534                                                         mRedfishPlatformConfigPrivate->HiiDatabase,
     1535                                                         FormsetPrivate->HiiHandle,
     1536                                                         &BufferSize,
     1537                                                         FormsetPrivate->HiiPackageListHeader
     1538                                                         );
     1539  if (EFI_ERROR (Status)) {
     1540    FreePool (FormsetPrivate->HiiPackageListHeader);
     1541    FormsetPrivate->HiiPackageListHeader = NULL;
     1542    return;
     1543  }
     1544
     1545  TotalStringsAdded = 0;
     1546  //
     1547  // Finding the string package.
     1548  //
     1549  EndingPackageAddress = (UINTN)FormsetPrivate->HiiPackageListHeader + FormsetPrivate->HiiPackageListHeader->PackageLength;
     1550  PackageHeader        = (EFI_HII_PACKAGE_HEADER *)(FormsetPrivate->HiiPackageListHeader + 1);
     1551  SupportedSchemaLang  = FormsetPrivate->SupportedSchema.SchemaList;
     1552  while ((UINTN)PackageHeader < EndingPackageAddress) {
     1553    switch (PackageHeader->Type) {
     1554      case EFI_HII_PACKAGE_STRINGS:
     1555        StringIdMapIsBuilt     = FALSE;
     1556        HiiStringPackageHeader = (EFI_HII_STRING_PACKAGE_HDR *)PackageHeader;
     1557
     1558        // Check if this is the string package for x-UEFI-redfish
     1559        for (SupportedSchemaLangCount = 0;
     1560             SupportedSchemaLangCount < FormsetPrivate->SupportedSchema.Count;
     1561             SupportedSchemaLangCount++
     1562             )
     1563        {
     1564          if (AsciiStrnCmp (
     1565                *(SupportedSchemaLang + SupportedSchemaLangCount),
     1566                HiiStringPackageHeader->Language,
     1567                AsciiStrLen (HiiStringPackageHeader->Language)
     1568                ) == 0)
     1569          {
     1570            StringIdMapIsBuilt = CreateXuefiLanguageStringIdMap (FormsetPrivate, HiiStringPackageHeader, &NumberPackageStrings);
     1571            if (StringIdMapIsBuilt) {
     1572              TotalStringsAdded += NumberPackageStrings;
     1573            }
     1574
     1575            break;
     1576          }
     1577        }
     1578
     1579        if (StringIdMapIsBuilt == FALSE) {
     1580          if (AsciiStrStr (HiiStringPackageHeader->Language, X_UEFI_SCHEMA_PREFIX) == NULL) {
     1581            DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "  No need to build x-UEFI-redfish string ID map for HII language %a\n", HiiStringPackageHeader->Language));
     1582          } else {
     1583            DEBUG ((DEBUG_ERROR, "  Failed to build x-UEFI-redfish string ID map of HII language %a\n", HiiStringPackageHeader->Language));
     1584          }
     1585        }
     1586
     1587      default:
     1588        PackageHeader = (EFI_HII_PACKAGE_HEADER *)((UINTN)PackageHeader + PackageHeader->Length);
     1589    }
     1590  }
     1591
     1592  DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "  Total %d x-UEFI-redfish config language are added.\n", TotalStringsAdded));
    8501593}
    8511594
     
    8561599  @param[out] FormsetPrivate  The formset private data.
    8571600
    858   @retval EFI_STATUS
     1601  @retval EFI_STATUS          The formset is loaded successfully.
     1602  @retval EFI_UNSUPPORTED     This formset doesn't have any x-UEFI-redfish configuration.
    8591603
    8601604**/
     
    8751619  EFI_GUID                                   ZeroGuid;
    8761620  EXPRESS_RESULT                             ExpressionResult;
     1621  CHAR16                                     *String;
    8771622
    8781623  if ((HiiHandle == NULL) || (FormsetPrivate == NULL)) {
     
    8821627  HiiFormSet = AllocateZeroPool (sizeof (HII_FORMSET));
    8831628  if (HiiFormSet == NULL) {
     1629    DEBUG ((DEBUG_ERROR, "%a: No memory resource for HII_FORMSET - %g\n", __func__, FormsetPrivate->Guid));
    8841630    return EFI_OUT_OF_RESOURCES;
    8851631  }
     
    8911637  Status = CreateFormSetFromHiiHandle (HiiHandle, &ZeroGuid, HiiFormSet);
    8921638  if (EFI_ERROR (Status) || IsListEmpty (&HiiFormSet->FormListHead)) {
     1639    DEBUG ((DEBUG_ERROR, "%a: Formset not found by HII handle - %g\n", __func__, FormsetPrivate->Guid));
    8931640    Status = EFI_NOT_FOUND;
    8941641    goto ErrorExit;
     
    9091656  Status                        = GetSupportedSchema (FormsetPrivate->HiiHandle, &FormsetPrivate->SupportedSchema);
    9101657  if (EFI_ERROR (Status)) {
    911     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: No schema from HII handle: 0x%x found: %r\n", __func__, FormsetPrivate->HiiHandle, Status));
     1658    if (!RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_BUILD_MENU_PATH)) {
     1659      DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: No x-UEFI-redfish configuration found on the formset - %g\n", __func__, FormsetPrivate->Guid));
     1660      //
     1661      // If there is no x-UEFI-redfish language in this form-set, we don't add formset
     1662      // since we don't need to build menu path for attribute registry.
     1663      //
     1664      return EFI_UNSUPPORTED;
     1665    }
     1666  } else {
     1667    // Building x-UEFI-redfish string database
     1668    BuildXUefiRedfishStringDatabase (FormsetPrivate);
    9121669  }
    9131670
     
    9191676    if (HiiFormPrivate == NULL) {
    9201677      Status = EFI_OUT_OF_RESOURCES;
     1678      DEBUG ((DEBUG_ERROR, "%a: No memory resource for REDFISH_PLATFORM_CONFIG_FORM_PRIVATE.\n", __func__));
    9211679      goto ErrorExit;
    9221680    }
     
    9441702      HiiStatementPrivate = AllocateZeroPool (sizeof (REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE));
    9451703      if (HiiStatementPrivate == NULL) {
     1704        DEBUG ((DEBUG_ERROR, "%a: No memory resource for REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE.\n", __func__));
    9461705        Status = EFI_OUT_OF_RESOURCES;
    9471706        goto ErrorExit;
     
    9811740      }
    9821741
    983       //
    984       // Attach to statement list.
    985       //
    986       InsertTailList (&HiiFormPrivate->StatementList, &HiiStatementPrivate->Link);
     1742      // Get x-UEFI-redfish string using String ID.
     1743      Status = GetXuefiStringAndLangByStringId (FormsetPrivate, HiiStatementPrivate->Description, &String, NULL, NULL);
     1744      if (!EFI_ERROR (Status)) {
     1745        HiiStatementPrivate->XuefiRedfishStr = String;
     1746        //
     1747        // Attach to statement list.
     1748        //
     1749        InsertTailList (&HiiFormPrivate->StatementList, &HiiStatementPrivate->Link);
     1750      } else {
     1751        if (!RedfishPlatformConfigFeatureProp (REDFISH_PLATFORM_CONFIG_BUILD_MENU_PATH)) {
     1752          //
     1753          // If there is no x-UEFI-redfish language for this statement, we don't add this statement
     1754          // since we don't need to build menu path for attribute registry.
     1755          //
     1756          FreePool (HiiStatementPrivate);
     1757        } else {
     1758          //
     1759          // This is not x-UEFI-redfish string and we don't cache its string for searching Redfish configure language.
     1760          // When caller wants the string, we will read English string by calling HiiGetString().
     1761          //
     1762          HiiStatementPrivate->XuefiRedfishStr = NULL;
     1763          //
     1764          // Attach to statement list.
     1765          //
     1766          InsertTailList (&HiiFormPrivate->StatementList, &HiiStatementPrivate->Link);
     1767        }
     1768      }
     1769
    9871770      HiiStatementLink = GetNextNode (&HiiForm->StatementListHead, HiiStatementLink);
    9881771    }
     
    10521835  Status = LoadFormset (HiiHandle, FormsetPrivate);
    10531836  if (EFI_ERROR (Status)) {
    1054     DEBUG ((DEBUG_ERROR, "%a: failed to load formset: %r\n", __func__, Status));
     1837    DEBUG ((DEBUG_ERROR, "%a: Formset is not loaded for edk2 redfish: %r\n", __func__, Status));
    10551838    FreePool (FormsetPrivate);
    10561839    return Status;
     
    10631846
    10641847  DEBUG_CODE (
     1848    if (RedfishPlatformConfigDebugProp (REDFISH_PLATFORM_CONFIG_DEBUG_DUMP_FORMSET)) {
    10651849    DumpFormsetList (FormsetList);
     1850  }
     1851
    10661852    );
    10671853
     
    11831969    TargetPendingList->IsDeleted = FALSE;
    11841970    DEBUG_CODE (
    1185       DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: HII handle: 0x%x is updated\n", __func__, HiiHandle));
     1971      DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: HII handle: 0x%x is updated\n", __func__, HiiHandle));
    11861972      );
    11871973    return EFI_SUCCESS;
     
    11991985
    12001986  DEBUG_CODE (
    1201     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: HII handle: 0x%x is created\n", __func__, HiiHandle));
     1987    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: HII handle: 0x%x is created\n", __func__, HiiHandle));
    12021988    );
    12031989
     
    12362022    TargetPendingList->IsDeleted = TRUE;
    12372023    DEBUG_CODE (
    1238       DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: HII handle: 0x%x is updated and deleted\n", __func__, HiiHandle));
     2024      DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: HII handle: 0x%x is updated and deleted\n", __func__, HiiHandle));
    12392025      );
    12402026    return EFI_SUCCESS;
     
    12522038
    12532039  DEBUG_CODE (
    1254     DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: HII handle: 0x%x is deleted\n", __func__, HiiHandle));
     2040    DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: HII handle: 0x%x is deleted\n", __func__, HiiHandle));
    12552041    );
    12562042
     
    13012087      FormsetPrivate = GetFormsetPrivateByHiiHandle (Target->HiiHandle, FormsetList);
    13022088      if (FormsetPrivate != NULL) {
    1303         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: formset: %g is removed because driver release HII resource it already\n", __func__, FormsetPrivate->Guid));
     2089        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: formset: %g is removed because driver release HII resource it already\n", __func__, FormsetPrivate->Guid));
    13042090        RemoveEntryList (&FormsetPrivate->Link);
    13052091        ReleaseFormset (FormsetPrivate);
    13062092        FreePool (FormsetPrivate);
    13072093      } else {
    1308         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: formset on HII handle 0x%x was removed already\n", __func__, Target->HiiHandle));
     2094        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: formset on HII handle 0x%x was removed already\n", __func__, Target->HiiHandle));
    13092095      }
    13102096    } else {
     
    13172103        // HII formset already exist, release it and query again.
    13182104        //
    1319         DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: formset: %g is updated. Release current formset\n", __func__, &FormsetPrivate->Guid));
     2105        DEBUG ((DEBUG_REDFISH_PLATFORM_CONFIG, "%a: formset: %g is updated. Release current formset\n", __func__, &FormsetPrivate->Guid));
    13202106        RemoveEntryList (&FormsetPrivate->Link);
    13212107        ReleaseFormset (FormsetPrivate);
     
    13252111      Status = LoadFormsetList (Target->HiiHandle, FormsetList);
    13262112      if (EFI_ERROR (Status)) {
    1327         DEBUG ((DEBUG_ERROR, "%a: load formset from HII handle: 0x%x failed: %r\n", __func__, Target->HiiHandle, Status));
     2113        if (Status == EFI_UNSUPPORTED) {
     2114          DEBUG ((DEBUG_ERROR, "  The formset has no x-UEFI-redfish configurations.\n"));
     2115        } else {
     2116          DEBUG ((DEBUG_ERROR, "  load formset from HII handle: 0x%x failed: %r\n", Target->HiiHandle, Status));
     2117        }
    13282118      }
    13292119    }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h

    r101291 r105670  
    33
    44  (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
    5   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     5  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     6  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2930#define IS_EMPTY_STRING(a)  (a == NULL || a[0] == L'\0')
    3031#define ENGLISH_LANGUAGE_CODE  "en-US"
    31 #define X_UEFI_SCHEMA_PREFIX   "x-uefi-redfish-"
     32#define X_UEFI_SCHEMA_PREFIX   "x-UEFI-redfish-"
     33
     34#define MAX_X_UEFI_REDFISH_STRING_SIZE  (128 * 2)// 128 character in UCS.
     35
     36typedef struct _REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE;
    3237
    3338//
     
    4752} REDFISH_PLATFORM_CONFIG_SCHEMA;
    4853
     54// Defines the number of elements in array
     55#define X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER  1024
     56
     57//
     58// Definition of x-UEFI-redfish string element.
     59//
     60typedef struct {
     61  EFI_STRING_ID    StringId;
     62  CHAR16           *UcsString;
     63} REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT;
     64
     65//
     66// Discrete string array buffer, each has X_UEFI_REDFISH_STRING_ARRAY_NUMBER element.
     67//
     68typedef struct {
     69  LIST_ENTRY                              NextArray;
     70  REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT    *ArrayEntryAddress;
     71} REDFISH_X_UEFI_STRINGS_ARRAY;
     72
     73//
     74// x-UEFI-redfish string database, x-UEFI-redfish language based.
     75//
     76typedef struct {
     77  LIST_ENTRY    NextXuefiRedfishLanguage;                                     // Link to the next suppoted x-UEFI-Redfish language.
     78  CHAR8         *XuefiRedfishLanguage;                                        // x-UEFI-redfish language.
     79  UINTN         StringsArrayBlocks;                                           // Number of the array blocks that accommodate X_UEFI_REDFISH_STRING_ARRAY_NUMBER
     80                                                                              // elements in each.
     81  LIST_ENTRY    XuefiRedfishStringArrays;                                     // Link entry of x-UEFI-redfish string array.
     82} REDFISH_X_UEFI_STRING_DATABASE;
     83
    4984//
    5085// Definition of REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE
     
    5287typedef struct {
    5388  LIST_ENTRY                        Link;
    54   HII_FORMSET                       *HiiFormSet;     // Pointer to HII formset data.
    55   EFI_GUID                          Guid;            // Formset GUID.
    56   EFI_HII_HANDLE                    HiiHandle;       // Hii Handle of this formset.
    57   LIST_ENTRY                        HiiFormList;     // Form list that keep form data under this formset.
    58   CHAR16                            *DevicePathStr;  // Device path of this formset.
    59   REDFISH_PLATFORM_CONFIG_SCHEMA    SupportedSchema; // Schema that is supported in this formset.
     89  HII_FORMSET                       *HiiFormSet;                // Pointer to HII formset data.
     90  EFI_GUID                          Guid;                       // Formset GUID.
     91  EFI_HII_HANDLE                    HiiHandle;                  // Hii Handle of this formset.
     92  EFI_HII_PACKAGE_LIST_HEADER       *HiiPackageListHeader;      // Hii Package list header.
     93  LIST_ENTRY                        HiiFormList;                // Form list that keep form data under this formset.
     94  CHAR16                            *DevicePathStr;             // Device path of this formset.
     95  REDFISH_PLATFORM_CONFIG_SCHEMA    SupportedSchema;            // Schema that is supported in this formset.
     96  LIST_ENTRY                        XuefiRedfishStringDatabase; // x-UEFI-redfish string/Id data base;
    6097} REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE;
    6198
     
    91128// Definition of REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE
    92129//
    93 typedef struct {
     130struct _REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE {
    94131  LIST_ENTRY                                Link;
    95132  REDFISH_PLATFORM_CONFIG_FORM_PRIVATE      *ParentForm;
    96   HII_STATEMENT                             *HiiStatement;  // Pointer to HII statement data.
    97   EFI_QUESTION_ID                           QuestionId;     // Question ID of this statement.
    98   EFI_STRING_ID                             Description;    // String token of this question.
    99   EFI_STRING_ID                             Help;           // String token of help message.
    100   EFI_STRING                                DesStringCache; // The string cache for search function.
    101   UINT8                                     Flags;          // The statement flag.
    102   REDFISH_PLATFORM_CONFIG_STATEMENT_DATA    StatementData;  // The max/min for statement value.
    103   BOOLEAN                                   Suppressed;     // Statement is suppressed.
    104   BOOLEAN                                   GrayedOut;      // Statement is GrayedOut.
    105 } REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE;
     133  HII_STATEMENT                             *HiiStatement;     // Pointer to HII statement data.
     134  EFI_QUESTION_ID                           QuestionId;        // Question ID of this statement.
     135  EFI_STRING_ID                             Description;       // String token of this question.
     136  CHAR16                                    *XuefiRedfishStr;  // x-UEFI-redfish string of this question.
     137  EFI_STRING_ID                             Help;              // String token of help message.
     138  UINT8                                     Flags;             // The statement flag.
     139  REDFISH_PLATFORM_CONFIG_STATEMENT_DATA    StatementData;     // The max/min for statement value.
     140  BOOLEAN                                   Suppressed;        // Statement is suppressed.
     141  BOOLEAN                                   GrayedOut;         // Statement is GrayedOut.
     142};
    106143
    107144#define REDFISH_PLATFORM_CONFIG_STATEMENT_FROM_LINK(a)  BASE_CR (a, REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE, Link)
     
    348385  );
    349386
     387/**
     388  Return the HII string length. We don't check word alignment
     389  of the input string as the same as the checking in StrLen
     390  function. Because the HII string in the database is compact
     391  at the byte alignment.
     392
     393  @param[in]  String  Input UCS format string.
     394
     395  @retval Length of
     396
     397**/
     398UINTN
     399EFIAPI
     400HiiStrLen (
     401  IN  CONST CHAR16  *String
     402  );
     403
     404/**
     405  Return the HII string size. We don't check word alignment
     406  of the input string as the same as the checking in StrLen
     407  function. Because the HII string in the database is compact
     408  at the byte alignment.
     409
     410  @param[in]  String  Input UCS format string.
     411
     412  @retval Size of the string.
     413
     414**/
     415UINTN
     416EFIAPI
     417HiiStrSize (
     418  IN      CONST CHAR16  *String
     419  );
     420
     421/**
     422  Check if the debug property is enabled or not.
     423
     424  @param[in]  DebugType  Debug enablement type
     425
     426  @retval TRUE, the debug property is enabled.
     427          FALSE, the debug property is not enabled.
     428
     429**/
     430BOOLEAN
     431RedfishPlatformConfigDebugProp (
     432  IN UINT64  DebugProp
     433  );
     434
     435/**
     436  Check if the Platform Configure feature is enabled or not.
     437
     438  @param[in]  FeatureType  Redfish platform config feature enablement
     439
     440  @retval TRUE, the feature is enabled.
     441          FALSE, the feature is not enabled.
     442
     443**/
     444BOOLEAN
     445RedfishPlatformConfigFeatureProp (
     446  IN UINT64  FeatureProp
     447  );
     448
    350449#endif
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.c

    r101291 r105670  
    55  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
    66  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     7  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    78
    89  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    357358  )
    358359{
     360  EFI_STATUS  Status;
     361  UINT32      *Id;
     362
     363  Status = gBS->OpenProtocol (
     364                  ControllerHandle,
     365                  &gEfiCallerIdGuid,
     366                  (VOID **)&Id,
     367                  This->DriverBindingHandle,
     368                  ControllerHandle,
     369                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
     370                  );
     371  if (!EFI_ERROR (Status)) {
     372    return EFI_ALREADY_STARTED;
     373  }
     374
    359375  //
    360376  // Test for the HttpServiceBinding Protocol.
     
    587603
    588604/**
     605  Callback function that is invoked when HTTP event occurs.
     606
     607  @param[in]  This                Pointer to the EDKII_HTTP_CALLBACK_PROTOCOL instance.
     608  @param[in]  Event               The event that occurs in the current state.
     609  @param[in]  EventStatus         The Status of Event, EFI_SUCCESS or other errors.
     610**/
     611VOID
     612EFIAPI
     613RestExHttpCallback (
     614  IN EDKII_HTTP_CALLBACK_PROTOCOL  *This,
     615  IN EDKII_HTTP_CALLBACK_EVENT     Event,
     616  IN EFI_STATUS                    EventStatus
     617  )
     618{
     619  EFI_STATUS        Status;
     620  EFI_TLS_PROTOCOL  *TlsProtocol;
     621  RESTEX_INSTANCE   *Instance;
     622  EFI_TLS_VERIFY    TlsVerifyMethod;
     623
     624  if ((Event == HttpEventTlsConfigured) && (EventStatus == EFI_SUCCESS)) {
     625    // Reconfigure TLS configuration data.
     626    Instance = RESTEX_INSTANCE_FROM_HTTP_CALLBACK (This);
     627    Status   = gBS->HandleProtocol (
     628                      Instance->HttpIo.Handle,
     629                      &gEfiTlsProtocolGuid,
     630                      (VOID **)&TlsProtocol
     631                      );
     632    if (EFI_ERROR (Status)) {
     633      return;
     634    }
     635
     636    TlsVerifyMethod = EFI_TLS_VERIFY_NONE;
     637    Status          = TlsProtocol->SetSessionData (
     638                                     TlsProtocol,
     639                                     EfiTlsVerifyMethod,
     640                                     &TlsVerifyMethod,
     641                                     sizeof (EFI_TLS_VERIFY)
     642                                     );
     643    if (!EFI_ERROR (Status)) {
     644      DEBUG ((DEBUG_MANAGEABILITY, "%a: REST EX reconfigures TLS verify method.\n", __func__));
     645    }
     646  }
     647
     648  return;
     649}
     650
     651/**
    589652  Creates a child handle and installs a protocol.
    590653
     
    700763  }
    701764
     765  // Initial HTTP callback funciton on this REST EX instance
     766  Instance->HttpCallbakFunction.Callback = RestExHttpCallback;
     767  Status                                 = gBS->InstallProtocolInterface (
     768                                                  &Instance->HttpIo.Handle,
     769                                                  &gEdkiiHttpCallbackProtocolGuid,
     770                                                  EFI_NATIVE_INTERFACE,
     771                                                  &Instance->HttpCallbakFunction
     772                                                  );
     773  if (EFI_ERROR (Status)) {
     774    DEBUG ((DEBUG_ERROR, "%a: Fail to install HttpCallbakFunction.\n", __func__));
     775    goto ON_ERROR;
     776  }
     777
    702778  //
    703779  // Add it to the parent's child list.
     
    813889                  );
    814890
     891  //
     892  // Uninstall the HTTP callback protocol.
     893  //
     894  Status = gBS->UninstallProtocolInterface (
     895                  Instance->HttpIo.Handle,
     896                  &gEdkiiHttpCallbackProtocolGuid,
     897                  &Instance->HttpCallbakFunction
     898                  );
     899
    815900  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
    816901
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishRestExDxe/RedfishRestExDriver.h

    r101291 r105670  
    55  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
    66  Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>
     7  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    78
    89  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    3334#include <Protocol/RestEx.h>
    3435#include <Protocol/ServiceBinding.h>
     36#include <Protocol/HttpCallback.h>
     37#include <Protocol/Tls.h>
    3538
    3639///
     
    6770#define RESTEX_INSTANCE_FROM_THIS(a)  \
    6871  CR (a, RESTEX_INSTANCE, RestEx, RESTEX_INSTANCE_SIGNATURE)
     72
     73#define RESTEX_INSTANCE_FROM_HTTP_CALLBACK(a)  \
     74  CR (a, RESTEX_INSTANCE, HttpCallbakFunction, RESTEX_INSTANCE_SIGNATURE)
    6975
    7076#define RESTEX_STATE_UNCONFIGED  0
     
    95101
    96102struct _RESTEX_INSTANCE {
    97   UINT32                     Signature;
    98   LIST_ENTRY                 Link;
    99 
    100   EFI_REST_EX_PROTOCOL       RestEx;
    101 
    102   INTN                       State;
    103   BOOLEAN                    InDestroy;
    104 
    105   RESTEX_SERVICE             *Service;
    106   EFI_HANDLE                 ChildHandle;
    107 
    108   EFI_REST_EX_CONFIG_DATA    ConfigData;
     103  UINT32                          Signature;
     104  LIST_ENTRY                      Link;
     105
     106  EFI_REST_EX_PROTOCOL            RestEx;
     107
     108  INTN                            State;
     109  BOOLEAN                         InDestroy;
     110
     111  RESTEX_SERVICE                  *Service;
     112  EFI_HANDLE                      ChildHandle;
     113
     114  EFI_REST_EX_CONFIG_DATA         ConfigData;
    109115
    110116  //
    111117  // HTTP_IO to access the HTTP service
    112118  //
    113   HTTP_IO                    HttpIo;
    114 
    115   UINT32                     Flags;
     119  HTTP_IO                         HttpIo;
     120
     121  //
     122  // EDKII_HTTP_CALLBACK_PROTOCOL that listens to
     123  // HttpEventInitSession event.
     124  //
     125  EDKII_HTTP_CALLBACK_PROTOCOL    HttpCallbakFunction;
     126
     127  UINT32                          Flags;
    116128};
    117129
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf

    r101291 r105670  
    66#  Copyright (c) 2023, American Megatrends International LLC.
    77#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
     8#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    89#
    910#  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    5859  gEfiHttpProtocolGuid                            ## TO_START
    5960  gEfiDevicePathProtocolGuid                      ## TO_START
     61  gEdkiiHttpCallbackProtocolGuid                  ## CONSUMES
     62  gEfiTlsProtocolGuid                             ## CONSUMES
    6063
    6164[Pcd]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c

    r101291 r105670  
    3030  request to the REST resource identified by RequestMessage.Request.Url. The
    3131  ResponseMessage is the returned HTTP response for that request, including any HTTP
    32   status.
     32  status. It's caller's responsibility to free this ResponseMessage using FreePool().
     33  RestConfigFreeHttpMessage() in RedfishLib is an example to release ResponseMessage structure.
    3334
    3435  @param[in]  This                Pointer to EFI_REST_EX_PROTOCOL instance for a particular
     
    321322    DumpHttpStatusCode (DEBUG_REDFISH_NETWORK, ResponseData->Response.StatusCode);
    322323    Status = EFI_UNSUPPORTED;
     324
     325    //
     326    // Deliver status code back to caller so caller can handle it.
     327    //
     328    ResponseMessage->Data.Response = AllocateZeroPool (sizeof (EFI_HTTP_RESPONSE_DATA));
     329    if (ResponseMessage->Data.Response == NULL) {
     330      Status = EFI_OUT_OF_RESOURCES;
     331      goto ON_EXIT;
     332    }
     333
     334    ResponseMessage->Data.Response->StatusCode = ResponseData->Response.StatusCode;
     335
    323336    goto ON_EXIT;
    324337  }
     
    442455  if (ResponseData != NULL) {
    443456    FreePool (ResponseData);
    444   }
    445 
    446   if (EFI_ERROR (Status)) {
    447     if (ResponseMessage->Data.Response != NULL) {
    448       FreePool (ResponseMessage->Data.Response);
    449       ResponseMessage->Data.Response = NULL;
    450     }
    451 
    452     if (ResponseMessage->Body != NULL) {
    453       FreePool (ResponseMessage->Body);
    454       ResponseMessage->Body = NULL;
    455     }
    456457  }
    457458
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c

    r99404 r105670  
    55
    66  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
     7  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    78
    89  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1112
    1213#include <Uefi.h>
     14#include <Library/DebugLib.h>
    1315#include <Protocol/RestJsonStructure.h>
    1416#include "RestJsonStructureInternal.h"
     
    7375  }
    7476
     77  DEBUG ((DEBUG_MANAGEABILITY, "%a: %d REST JSON-C interpreter(s) to register for the name spaces.\n", __func__, NumberOfNS));
     78
    7579  Instance =
    7680    (REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
     
    8993  for (Index = 0; Index < NumberOfNS; Index++) {
    9094    CopyMem ((VOID *)CloneSupportedInterpId, (VOID *)&ThisSupportedInterp->RestResourceInterp, sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
     95    DEBUG ((DEBUG_MANAGEABILITY, "  Resource type : %a\n", ThisSupportedInterp->RestResourceInterp.NameSpace.ResourceTypeName));
     96    DEBUG ((DEBUG_MANAGEABILITY, "  Major version : %a\n", ThisSupportedInterp->RestResourceInterp.NameSpace.MajorVersion));
     97    DEBUG ((DEBUG_MANAGEABILITY, "  Minor version : %a\n", ThisSupportedInterp->RestResourceInterp.NameSpace.MinorVersion));
     98    DEBUG ((DEBUG_MANAGEABILITY, "  Errata version: %a\n\n", ThisSupportedInterp->RestResourceInterp.NameSpace.ErrataVersion));
    9199    ThisSupportedInterp = (EFI_REST_JSON_STRUCTURE_SUPPORTED *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink;
    92100    CloneSupportedInterpId++;
     
    125133  EFI_STATUS                              Status;
    126134  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *ThisSupportedRsrcTypeId;
     135
     136  DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry\n", __func__));
    127137
    128138  if ((This == NULL) ||
     
    147157                                    RestJSonHeader
    148158                                    );
     159    if (EFI_ERROR (Status)) {
     160      if (Status == EFI_UNSUPPORTED) {
     161        DEBUG ((
     162          DEBUG_MANAGEABILITY,
     163          "%a %a.%a.%a REST JSON to C structure interpreter has no capability to interpret the resource.\n",
     164          InterpreterInstance->SupportedRsrcIndentifier->NameSpace.ResourceTypeName,
     165          InterpreterInstance->SupportedRsrcIndentifier->NameSpace.MajorVersion,
     166          InterpreterInstance->SupportedRsrcIndentifier->NameSpace.MinorVersion,
     167          InterpreterInstance->SupportedRsrcIndentifier->NameSpace.ErrataVersion
     168          ));
     169      } else {
     170        DEBUG ((DEBUG_MANAGEABILITY, "REST JsonToStructure returns failure - %r\n", Status));
     171      }
     172    }
    149173  } else {
    150174    //
    151     // Check if the namesapce and version is supported by this interpreter.
     175    // Check if the namespace and version is supported by this interpreter.
    152176    //
    153177    ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
     
    172196                                          RestJSonHeader
    173197                                          );
     198          if (EFI_ERROR (Status)) {
     199            DEBUG ((DEBUG_MANAGEABILITY, "Don't check version of this resource type identifier JsonToStructure returns %r\n", Status));
     200            DEBUG ((DEBUG_MANAGEABILITY, "  Supported ResourceTypeName = %a\n", ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName));
     201          }
     202
    174203          break;
    175204        } else {
     
    196225                                            RestJSonHeader
    197226                                            );
     227            if (EFI_ERROR (Status)) {
     228              DEBUG ((DEBUG_MANAGEABILITY, "Check version of this resource type identifier JsonToStructure returns %r\n", Status));
     229              DEBUG ((DEBUG_MANAGEABILITY, "  Supported ResourceTypeName = %a\n", ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName));
     230              DEBUG ((DEBUG_MANAGEABILITY, "  Supported MajorVersion     = %a\n", ThisSupportedRsrcTypeId->NameSpace.MajorVersion));
     231              DEBUG ((DEBUG_MANAGEABILITY, "  Supported MinorVersion     = %a\n", ThisSupportedRsrcTypeId->NameSpace.MinorVersion));
     232              DEBUG ((DEBUG_MANAGEABILITY, "  Supported ErrataVersion    = %a\n", ThisSupportedRsrcTypeId->NameSpace.ErrataVersion));
     233            }
     234
    198235            break;
    199236          }
     
    232269  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *ThisSupportedRsrcTypeId;
    233270  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *RsrcTypeIdentifier;
     271
     272  DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry\n", __func__));
    234273
    235274  if ((This == NULL) ||
     
    285324                                        ResourceRaw
    286325                                        );
     326        if (EFI_ERROR (Status)) {
     327          DEBUG ((DEBUG_MANAGEABILITY, "StructureToJson returns %r\n", Status));
     328          DEBUG ((DEBUG_MANAGEABILITY, "  Supported ResourceTypeName = %a\n", ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName));
     329          DEBUG ((DEBUG_MANAGEABILITY, "  Supported MajorVersion     = %a\n", ThisSupportedRsrcTypeId->NameSpace.MajorVersion));
     330          DEBUG ((DEBUG_MANAGEABILITY, "  Supported MinorVersion     = %a\n", ThisSupportedRsrcTypeId->NameSpace.MinorVersion));
     331          DEBUG ((DEBUG_MANAGEABILITY, "  Supported ErrataVersion    = %a\n", ThisSupportedRsrcTypeId->NameSpace.ErrataVersion));
     332        }
     333
    287334        break;
    288335      }
     
    417464  }
    418465
     466  if (RsrcTypeIdentifier != NULL) {
     467    DEBUG ((DEBUG_MANAGEABILITY, "%a: Looking for the REST JSON to C Structure converter:\n", __func__));
     468    if (RsrcTypeIdentifier->NameSpace.ResourceTypeName != NULL) {
     469      DEBUG ((DEBUG_MANAGEABILITY, "  ResourceType: %a\n", RsrcTypeIdentifier->NameSpace.ResourceTypeName));
     470    } else {
     471      DEBUG ((DEBUG_MANAGEABILITY, "  ResourceType: NULL"));
     472    }
     473
     474    if (RsrcTypeIdentifier->NameSpace.MajorVersion != NULL) {
     475      DEBUG ((DEBUG_MANAGEABILITY, "  MajorVersion: %a\n", RsrcTypeIdentifier->NameSpace.MajorVersion));
     476    } else {
     477      DEBUG ((DEBUG_MANAGEABILITY, "  MajorVersion: NULL"));
     478    }
     479
     480    if (RsrcTypeIdentifier->NameSpace.MinorVersion != NULL) {
     481      DEBUG ((DEBUG_MANAGEABILITY, "  MinorVersion: %a\n", RsrcTypeIdentifier->NameSpace.MinorVersion));
     482    } else {
     483      DEBUG ((DEBUG_MANAGEABILITY, "  MinorVersion: NULL"));
     484    }
     485
     486    if (RsrcTypeIdentifier->NameSpace.ErrataVersion != NULL) {
     487      DEBUG ((DEBUG_MANAGEABILITY, "  ErrataVersion: %a\n", RsrcTypeIdentifier->NameSpace.ErrataVersion));
     488    } else {
     489      DEBUG ((DEBUG_MANAGEABILITY, "  ErrataVersion: NULL"));
     490    }
     491  } else {
     492    DEBUG ((DEBUG_MANAGEABILITY, "%a: RsrcTypeIdentifier is given as NULL, go through all of the REST JSON to C structure interpreters.\n", __func__));
     493  }
     494
    419495  Status   = EFI_SUCCESS;
    420496  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
     
    428504               );
    429505    if (!EFI_ERROR (Status)) {
     506      DEBUG ((DEBUG_MANAGEABILITY, "%a: REST JSON to C structure is interpreted successfully.\n", __func__));
    430507      break;
    431508    }
    432509
    433510    if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
     511      DEBUG ((DEBUG_ERROR, "%a: No REST JSON to C structure interpreter found.\n", __func__));
    434512      Status = EFI_UNSUPPORTED;
    435513      break;
     
    484562
    485563    if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
     564      DEBUG ((DEBUG_ERROR, "%a: No REST JSON to C structure interpreter found.\n", __func__));
    486565      Status = EFI_UNSUPPORTED;
    487566      break;
     
    513592  )
    514593{
    515   EFI_STATUS                    Status;
    516   REST_JSON_STRUCTURE_INSTANCE  *Instance;
     594  EFI_STATUS                              Status;
     595  REST_JSON_STRUCTURE_INSTANCE            *Instance;
     596  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER  *RsrcTypeIdentifier;
    517597
    518598  if ((This == NULL) || (RestJSonHeader == NULL) || (ResourceRaw == NULL)) {
     
    523603    return EFI_UNSUPPORTED;
    524604  }
     605
     606  RsrcTypeIdentifier = &RestJSonHeader->JsonRsrcIdentifier;
     607  DEBUG ((DEBUG_MANAGEABILITY, "Looking for the REST C Structure to JSON resource converter:\n"));
     608  DEBUG ((DEBUG_MANAGEABILITY, "  ResourceType : %a\n", RsrcTypeIdentifier->NameSpace.ResourceTypeName));
     609  DEBUG ((DEBUG_MANAGEABILITY, "  MajorVersion : %a\n", RsrcTypeIdentifier->NameSpace.MajorVersion));
     610  DEBUG ((DEBUG_MANAGEABILITY, "  MinorVersion : %a\n", RsrcTypeIdentifier->NameSpace.MinorVersion));
     611  DEBUG ((DEBUG_MANAGEABILITY, "  ErrataVersion: %a\n", RsrcTypeIdentifier->NameSpace.ErrataVersion));
    525612
    526613  Status   = EFI_SUCCESS;
     
    538625
    539626    if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
     627      DEBUG ((DEBUG_ERROR, "%a: No REST C structure to JSON interpreter found.\n", __func__));
    540628      Status = EFI_UNSUPPORTED;
    541629      break;
     
    588676
    589677/**
    590   This is the unload handle for Redfish discover module.
     678  This is the unload handle for REST JSON to C structure module.
    591679
    592680  Disconnect the driver specified by ImageHandle from all the devices in the handle database.
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf

    r89983 r105670  
    33#
    44#  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
     5#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    56#  SPDX-License-Identifier: BSD-2-Clause-Patent
    67##
     
    1819  MdePkg/MdePkg.dec
    1920  MdeModulePkg/MdeModulePkg.dec
    20   RedfishPkg/RedfishPkg.dec
    2121
    2222[Sources]
     
    2727  BaseLib
    2828  BaseMemoryLib
     29  DebugLib
    2930  MemoryAllocationLib
    3031  UefiBootServicesTableLib
  • trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h

    r99404 r105670  
    44
    55  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
     6  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2627  LIST_ENTRY                                   NextRestJsonStructureInstance; ///< Next convertor instance
    2728  UINTN                                        NumberOfNameSpaceToConvert;    ///< Number of resource type this convertor supports.
    28   EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER       *SupportedRsrcIndentifier;     ///< The resource type linklist
     29  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER       *SupportedRsrcIndentifier;     ///< The supported resource type array.
    2930  EFI_REST_JSON_STRUCTURE_TO_STRUCTURE         JsonToStructure;               ///< JSON to C structure function
    3031  EFI_REST_JSON_STRUCTURE_TO_JSON              StructureToJson;               ///< C structure to JSON function
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette