2 This library provides a set of utility APIs that allow to create/read/update/delete
3 (CRUD) Redfish resources and provide basic query abilities by using [URI/RedPath]
4 (https://github.com/DMTF/libredfish).
6 The query language is based on XPath (https://www.w3.org/TR/1999/REC-xpath-19991116/).
7 This library and query language essentially treat the entire Redfish Service like it
8 was a single JSON document. In other words whenever it encounters an odata.id in JSON
9 document, it will retrieve the new JSON document (if needed). We name the path as
12 Expression Description
14 nodename Selects the JSON entity with the name "nodename".
15 If the value of nodename is an object with "@odata.id",
16 it will continue get the value from "@odata.id".
18 / Selects from the root node
20 [index] Selects the index number JSON entity from an array or
21 object. If the JSON entity is one collection (has
22 Members & Members@odata.count), means to get the index
23 member in "Members". Index number >=1, 1 means to return
26 [XXX] Operation on JSON entity.
27 If the JSON entity is one collection (has Members &
28 Members@odata.count), means to get all elements in
29 "Members". If the JSON entity is one array, means to
30 get all elements in array. Others will match the nodename
31 directly (e.g. JSON_OBJECT, JSON_STRING, JSON_TRUE,
32 JSON_FALSE, JSON_INTEGER).
34 [nodename] Selects all the elements from an JSON entity that
35 contain a property named "nodename"
37 [name=value] Selects all the elements from an JSON entity where
38 the property "name" is equal to "value"
40 [name~value] Selects all the elements from an JSON entity where
41 the string property "name" is equal to "value" using
42 case insensitive comparison.
44 [name<value] Selects all the elements from an JSON entity where
45 the property "name" is less than "value"
47 [name<=value] Selects all the elements from an JSON entity where
48 the property "name" is less than or equal to "value"
50 [name>value] Selects all the elements from an JSON entity where
51 the property "name" is greater than "value"
53 [name>=value] Selects all the elements from an JSON entity where
54 the property "name" is greater than or equal to "value"
58 /v1/Chassis[1] - Will return the first Chassis instance.
59 /v1/Chassis[SKU=1234] - Will return all Chassis instances with a SKU field equal to 1234.
60 /v1/Systems[Storage] - Will return all the System instances that have Storage field populated.
62 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
63 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
65 SPDX-License-Identifier: BSD-2-Clause-Patent
69 #ifndef REDFISH_LIB_H_
70 #define REDFISH_LIB_H_
72 #include <Library/JsonLib.h>
74 #include <Protocol/Http.h>
75 #include <Protocol/EdkIIRedfishConfigHandler.h>
77 #define ODATA_TYPE_NAME_MAX_SIZE 128
78 #define ODATA_TYPE_MAX_SIZE 128
81 /// Library class public defines
83 typedef VOID
*REDFISH_SERVICE
;
84 typedef VOID
*REDFISH_PAYLOAD
;
87 /// Library class public structures/unions
90 EFI_HTTP_STATUS_CODE
*StatusCode
;
92 EFI_HTTP_HEADER
*Headers
;
93 REDFISH_PAYLOAD Payload
;
97 /// Odata type-name mapping structure.
100 CONST CHAR8 OdataTypeName
[ODATA_TYPE_NAME_MAX_SIZE
];
101 CONST CHAR8 OdataType
[ODATA_TYPE_MAX_SIZE
];
102 } REDFISH_ODATA_TYPE_MAPPING
;
105 This function uses REST EX protocol provided in RedfishConfigServiceInfo.
106 The service enumerator will also handle the authentication flow automatically
107 if HTTP basic auth or Redfish session login is configured to use.
109 Callers are responsible for freeing the returned service by RedfishCleanupService().
111 @param[in] RedfishConfigServiceInfo Redfish service information the EFI Redfish
112 feature driver communicates with.
114 @return New created Redfish Service, or NULL if error happens.
119 RedfishCreateService (
120 IN REDFISH_CONFIG_SERVICE_INFORMATION
*RedfishConfigServiceInfo
124 Free the Service and all its related resources.
126 @param[in] RedfishService The Service to access the Redfish resources.
131 RedfishCleanupService (
132 IN REDFISH_SERVICE RedfishService
136 Create REDFISH_PAYLOAD instance in local with JSON represented resource value and
139 The returned REDFISH_PAYLOAD can be used to create or update Redfish resource in
142 Callers are responsible for freeing the returned payload by RedfishCleanupPayload().
144 @param[in] Value JSON Value of the redfish resource.
145 @param[in] RedfishService The Service to access the Redfish resources.
147 @return REDFISH_PAYLOAD instance of the resource, or NULL if error happens.
152 RedfishCreatePayload (
153 IN EDKII_JSON_VALUE Value
,
154 IN REDFISH_SERVICE RedfishService
158 Free the RedfishPayload and all its related resources.
160 @param[in] Payload Payload to be freed.
165 RedfishCleanupPayload (
166 IN REDFISH_PAYLOAD Payload
170 This function returns the decoded JSON value of a REDFISH_PAYLOAD.
172 Caller doesn't need to free the returned JSON value because it will be released
173 in corresponding RedfishCleanupPayload() function.
175 @param[in] Payload A REDFISH_PAYLOAD instance.
177 @return Decoded JSON value of the payload.
182 RedfishJsonInPayload (
183 IN REDFISH_PAYLOAD Payload
187 Fill the input RedPath string with system UUID from SMBIOS table or use the customized
188 ID if FromSmbios == FALSE.
190 This is a helper function to build a RedPath string which can be used to address
191 a Redfish resource for this computer system. The input PathString must have a Systems
192 note in format of "Systems[UUID=%g]" or "Systems[UUID~%g]" to fill the UUID value.
195 Use "/v1/Systems[UUID=%g]/Bios" to build a RedPath to address the "Bios" resource
196 for this computer system.
198 @param[in] RedPath RedPath format to be build.
199 @param[in] FromSmbios Get system UUID from SMBIOS as computer system instance ID.
200 @param[in] IdString The computer system instance ID.
202 @return Full RedPath with system UUID inside, or NULL if error happens.
207 RedfishBuildPathWithSystemUuid (
208 IN CONST CHAR8
*RedPath
,
209 IN BOOLEAN FromSmbios
,
210 IN CHAR8
*IdString OPTIONAL
214 Get a redfish response addressed by a RedPath string, including HTTP StatusCode, Headers
215 and Payload which record any HTTP response messages.
217 Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
218 redfish response data.
220 @param[in] RedfishService The Service to access the Redfish resources.
221 @param[in] RedPath RedPath string to address a resource, must start
223 @param[out] RedResponse Pointer to the Redfish response data.
225 @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not
226 NULL and the value is 2XX. The corresponding redfish resource has
227 been returned in Payload within RedResponse.
228 @retval EFI_INVALID_PARAMETER RedfishService, RedPath, or RedResponse is NULL.
229 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get
230 more error info from returned HTTP StatusCode, Headers and Payload
232 1. If the returned Payload is NULL, indicates any error happen.
233 2. If the returned StatusCode is NULL, indicates any error happen.
234 3. If the returned StatusCode is not 2XX, indicates any error happen.
238 RedfishGetByService (
239 IN REDFISH_SERVICE RedfishService
,
240 IN CONST CHAR8
*RedPath
,
241 OUT REDFISH_RESPONSE
*RedResponse
245 Get a redfish response addressed by URI, including HTTP StatusCode, Headers
246 and Payload which record any HTTP response messages.
248 Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
249 redfish response data.
251 @param[in] RedfishService The Service to access the URI resources.
252 @param[in] URI String to address a resource.
253 @param[out] RedResponse Pointer to the Redfish response data.
255 @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not
256 NULL and the value is 2XX. The corresponding redfish resource has
257 been returned in Payload within RedResponse.
258 @retval EFI_INVALID_PARAMETER RedfishService, RedPath, or RedResponse is NULL.
259 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get
260 more error info from returned HTTP StatusCode, Headers and Payload
262 1. If the returned Payload is NULL, indicates any error happen.
263 2. If the returned StatusCode is NULL, indicates any error happen.
264 3. If the returned StatusCode is not 2XX, indicates any error happen.
269 IN REDFISH_SERVICE RedfishService
,
271 OUT REDFISH_RESPONSE
*RedResponse
275 Get a redfish response addressed by the input Payload and relative RedPath string,
276 including HTTP StatusCode, Headers and Payload which record any HTTP response messages.
278 Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
279 redfish response data.
281 @param[in] Payload A existing REDFISH_PAYLOAD instance.
282 @param[in] RedPath Relative RedPath string to address a resource inside Payload.
283 @param[out] RedResponse Pointer to the Redfish response data.
285 @retval EFI_SUCCESS The opeartion is successful:
286 1. The HTTP StatusCode is NULL and the returned Payload in
287 RedResponse is not NULL, indicates the Redfish resource has
288 been parsed from the input payload directly.
289 2. The HTTP StatusCode is not NULL and the value is 2XX,
290 indicates the corresponding redfish resource has been returned
291 in Payload within RedResponse.
292 @retval EFI_INVALID_PARAMETER Payload, RedPath, or RedResponse is NULL.
293 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get
294 more error info from returned HTTP StatusCode, Headers and Payload
296 1. If the returned Payload is NULL, indicates any error happen.
297 2. If StatusCode is not NULL and the returned value of StatusCode
298 is not 2XX, indicates any error happen.
302 RedfishGetByPayload (
303 IN REDFISH_PAYLOAD Payload
,
304 IN CONST CHAR8
*RedPath
,
305 OUT REDFISH_RESPONSE
*RedResponse
309 Use HTTP PATCH to perform updates on pre-existing Redfish resource.
311 This function uses the RedfishService to patch a Redfish resource addressed by
312 Uri (only the relative path is required). Changes to one or more properties within
313 the target resource are represented in the input Content, properties not specified
314 in Content won't be changed by this request. The corresponding redfish response will
315 returned, including HTTP StatusCode, Headers and Payload which record any HTTP response
318 Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
319 redfish response data.
321 @param[in] RedfishService The Service to access the Redfish resources.
322 @param[in] Uri Relative path to address the resource.
323 @param[in] Content JSON represented properties to be update.
324 @param[out] RedResponse Pointer to the Redfish response data.
326 @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not
327 NULL and the value is 2XX. The Redfish resource will be returned
328 in Payload within RedResponse if server send it back in the HTTP
329 response message body.
330 @retval EFI_INVALID_PARAMETER RedfishService, Uri, Content, or RedResponse is NULL.
331 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get
332 more error info from returned HTTP StatusCode, Headers and Payload
334 1. If the returned StatusCode is NULL, indicates any error happen.
335 2. If the returned StatusCode is not NULL and the value is not 2XX,
336 indicates any error happen.
341 IN REDFISH_SERVICE RedfishService
,
343 IN CONST CHAR8
*Content
,
344 OUT REDFISH_RESPONSE
*RedResponse
348 Use HTTP PATCH to perform updates on target payload. Patch to odata.id in Payload directly.
350 This function uses the Payload to patch the Target. Changes to one or more properties
351 within the target resource are represented in the input Payload, properties not specified
352 in Payload won't be changed by this request. The corresponding redfish response will
353 returned, including HTTP StatusCode, Headers and Payload which record any HTTP response
356 Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
357 redfish response data.
359 @param[in] Target The target payload to be updated.
360 @param[in] Payload Palyoad with properties to be changed.
361 @param[out] RedResponse Pointer to the Redfish response data.
363 @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not
364 NULL and the value is 2XX. The Redfish resource will be returned
365 in Payload within RedResponse if server send it back in the HTTP
366 response message body.
367 @retval EFI_INVALID_PARAMETER Target, Payload, or RedResponse is NULL.
368 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get
369 more error info from returned HTTP StatusCode, Headers and Payload
371 1. If the returned StatusCode is NULL, indicates any error happen.
372 2. If the returned StatusCode is not NULL and the value is not 2XX,
373 indicates any error happen.
377 RedfishPatchToPayload (
378 IN REDFISH_PAYLOAD Target
,
379 IN REDFISH_PAYLOAD Payload
,
380 OUT REDFISH_RESPONSE
*RedResponse
384 Use HTTP POST to create a new resource in target payload.
386 The POST request should be submitted to the Resource Collection in which the new resource
387 is to belong. The Resource Collection is addressed by Target payload. The Redfish may
388 ignore any service controlled properties. The corresponding redfish response will returned,
389 including HTTP StatusCode, Headers and Payload which record any HTTP response messages.
391 Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
392 redfish response data.
394 @param[in] Target Target payload of the Resource Collection.
395 @param[in] Payload The new resource to be created.
396 @param[out] RedResponse Pointer to the Redfish response data.
398 @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not
399 NULL and the value is 2XX. The Redfish resource will be returned
400 in Payload within RedResponse if server send it back in the HTTP
401 response message body.
402 @retval EFI_INVALID_PARAMETER Target, Payload, or RedResponse is NULL.
403 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get
404 more error info from returned HTTP StatusCode, Headers and Payload
406 1. If the returned StatusCode is NULL, indicates any error happen.
407 2. If the returned StatusCode is not NULL and the value is not 2XX,
408 indicates any error happen.
412 RedfishPostToPayload (
413 IN REDFISH_PAYLOAD Target
,
414 IN REDFISH_PAYLOAD Payload
,
415 OUT REDFISH_RESPONSE
*RedResponse
419 Use HTTP DELETE to remove a resource.
421 This function uses the RedfishService to remove a Redfish resource which is addressed
422 by input Uri (only the relative path is required). The corresponding redfish response will
423 returned, including HTTP StatusCode, Headers and Payload which record any HTTP response
426 Callers are responsible for freeing the HTTP StatusCode, Headers and Payload returned in
427 redfish response data.
429 @param[in] RedfishService The Service to access the Redfish resources.
430 @param[in] Uri Relative path to address the resource.
431 @param[out] RedResponse Pointer to the Redfish response data.
433 @retval EFI_SUCCESS The opeartion is successful, indicates the HTTP StatusCode is not
434 NULL and the value is 2XX, the Redfish resource has been removed.
435 If there is any message returned from server, it will be returned
436 in Payload within RedResponse.
437 @retval EFI_INVALID_PARAMETER RedfishService, Uri, or RedResponse is NULL.
438 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. Callers can get
439 more error info from returned HTTP StatusCode, Headers and Payload
441 1. If the returned StatusCode is NULL, indicates any error happen.
442 2. If the returned StatusCode is not NULL and the value is not 2XX,
443 indicates any error happen.
448 IN REDFISH_SERVICE RedfishService
,
450 OUT REDFISH_RESPONSE
*RedResponse
454 Dump text in fractions.
456 @param[in] String ASCII string to dump.
460 RedfishDumpJsonStringFractions (
465 Extract the JSON text content from REDFISH_PAYLOAD and dump to debug console.
467 @param[in] Payload The Redfish payload to dump.
472 IN REDFISH_PAYLOAD Payload
476 Dump text in JSON value.
478 @param[in] JsonValue The Redfish JSON value to dump.
483 IN EDKII_JSON_VALUE JsonValue
487 This function will cleanup the HTTP header and Redfish payload resources.
489 @param[in] StatusCode The status code in HTTP response message.
490 @param[in] HeaderCount Number of HTTP header structures in Headers list.
491 @param[in] Headers Array containing list of HTTP headers.
492 @param[in] Payload The Redfish payload to dump.
496 RedfishFreeResponse (
497 IN EFI_HTTP_STATUS_CODE
*StatusCode
,
498 IN UINTN HeaderCount
,
499 IN EFI_HTTP_HEADER
*Headers
,
500 IN REDFISH_PAYLOAD Payload
504 Check if the "@odata.type" in Payload is valid or not.
506 @param[in] Payload The Redfish payload to be checked.
507 @param[in] OdataTypeName OdataType will be retrived from mapping list.
508 @param[in] OdataTypeMappingList The list of OdataType.
509 @param[in] OdataTypeMappingListSize The number of mapping list
511 @return TRUE if the "@odata.type" in Payload is valid, otherwise FALSE.
515 RedfishIsValidOdataType (
516 IN REDFISH_PAYLOAD Payload
,
517 IN CONST CHAR8
*OdataTypeName
,
518 IN REDFISH_ODATA_TYPE_MAPPING
*OdataTypeMappingList
,
519 IN UINTN OdataTypeMappingListSize
523 Check if the payload is collection
525 @param[in] Payload The Redfish payload to be checked.
527 @return TRUE if the payload is collection.
531 RedfishIsPayloadCollection (
532 IN REDFISH_PAYLOAD Payload
538 @param[in] Payload The Redfish collection payload
539 @param[in] CollectionSize Size of this collection
541 @return EFI_SUCCESS Coolection size is returned in CollectionSize
542 @return EFI_INVALID_PARAMETER The payload is not a collection.
545 RedfishGetCollectionSize (
546 IN REDFISH_PAYLOAD Payload
,
547 IN UINTN
*CollectionSize
551 Get Redfish payload of collection member
553 @param[in] Payload The Redfish collection payload
554 @param[in] Index Index of collection member
556 @return NULL Fail to get collection member.
557 @return Non NULL Payload is returned.
560 RedfishGetPayloadByIndex (
561 IN REDFISH_PAYLOAD Payload
,
566 Check and return Redfish resource of the given Redpath.
568 @param[in] RedfishService Pointer to REDFISH_SERVICE
569 @param[in] Redpath Redpath of the resource.
570 @param[in] Response Optional return the resource.
575 RedfishCheckIfRedpathExist (
576 IN REDFISH_SERVICE RedfishService
,
578 IN REDFISH_RESPONSE
*Response OPTIONAL
582 This function returns the string of Redfish service version.
584 @param[in] RedfishService Redfish service instance.
585 @param[out] ServiceVersionStr Redfish service string.
591 RedfishGetServiceVersion (
592 IN REDFISH_SERVICE RedfishService
,
593 OUT CHAR8
**ServiceVersionStr
597 This function returns the string of Redfish service version.
599 @param[in] ServiceVerisonStr The string of Redfish service version.
600 @param[in] Url The URL to build Redpath with ID.
601 Start with "/", for example "/Registries"
602 @param[in] Id ID string
603 @param[out] Redpath Pointer to retrive Redpath, caller has to free
604 the memory allocated for this string.
609 RedfishBuildRedpathUseId (
610 IN CHAR8
*ServiceVerisonStr
,