PSoC64 Secure Boot Utilities Middleware Library 1.0

General Description

Functions

const cy_p64_cJSONcy_p64_find_json_item (const char *path, const cy_p64_cJSON *json)
 Finds items by name in the whole JSON. More...
 
cy_p64_error_codes_t cy_p64_decode_payload_data (const char *jwt_packet, cy_p64_cJSON **json_packet)
 Decodes JWT payload data from the input jwt_packet to JSON object and returns pointer to this object: json_packet. More...
 
cy_p64_error_codes_t cy_p64_json_get_boolean (const cy_p64_cJSON *json, bool *value)
 Gets the BOOLEAN value of a JSON object. More...
 
cy_p64_error_codes_t cy_p64_json_get_uint32 (const cy_p64_cJSON *json, uint32_t *value)
 Gets the unsigned INTEGER value of a JSON object. More...
 
cy_p64_error_codes_t cy_p64_json_get_string (const cy_p64_cJSON *json, const char **value)
 Gets the unsigned STRING value of a JSON object. More...
 
cy_p64_error_codes_t cy_p64_json_get_array_uint8 (const cy_p64_cJSON *json, uint8_t *buf, uint32_t size, uint32_t *olen)
 Gets the ARRAY value, in uint8, of a JSON object. More...
 
cy_p64_error_codes_t cy_p64_policy_get_image_record (const cy_p64_cJSON *json, uint32_t image_id, const cy_p64_cJSON **json_image)
 Gets the JSON object of the image_id. More...
 
cy_p64_error_codes_t cy_p64_policy_get_image_address_and_size (const cy_p64_cJSON *json, uint32_t image_id, const char *image_type, uint32_t *address, uint32_t *size)
 Gets the image address and size from the provisioning policy. More...
 
cy_p64_error_codes_t cy_p64_policy_get_image_boot_config (const cy_p64_cJSON *json, uint32_t image_id, bool *wdt_enable, uint32_t *wdt_timeout, bool *set_img_ok)
 Gets the image wdt configuration and image_ok from provisioning policy. More...
 

Function Documentation

◆ cy_p64_find_json_item()

const cy_p64_cJSON* cy_p64_find_json_item ( const char *  path,
const cy_p64_cJSON json 
)

Finds items by name in the whole JSON.

The name can be not unique so the function returns the first item with this name. For not unique items, it is recommended to parse JSON in two steps: the first find upper unique JSON object, then parse items in this object. Alternatively, provide a full path to the path parameter with the next token(name) & index from the path, e.g.: "path:2/to/the:1/node" –> "path" & 2 For example: boot_upgrade/firmware/resources:1/address:1

Parameters
[in]pathA unique string name to lookup after, or full path.
[in]jsonJSON object to check.
Returns
Returns the pointer to the found JSON object or NULL.

◆ cy_p64_decode_payload_data()

cy_p64_error_codes_t cy_p64_decode_payload_data ( const char *  jwt_packet,
cy_p64_cJSON **  json_packet 
)

Decodes JWT payload data from the input jwt_packet to JSON object and returns pointer to this object: json_packet.

It allocates the required space in RAM for the JSON object, so after usage the caller needs to free the JSON object by calling the cy_p64_cJSON_Delete() function.

Parameters
[in]jwt_packetThe pointer to the JWT packet.
[out]json_packetOutputs the JSON object that contains the JWT payload.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_INVALID_PARAMETERThis error code is returned, if json_packet is a null pointer.
CY_P64_JWT_ERR_MALLOC_FAIL
CY_P64_JWT_ERR_B64DECODE_FAIL
CY_P64_JWT_ERR_JSN_PARSE_FAIL
CY_P64_JWT_ERR_OTHER

◆ cy_p64_json_get_boolean()

cy_p64_error_codes_t cy_p64_json_get_boolean ( const cy_p64_cJSON json,
bool *  value 
)

Gets the BOOLEAN value of a JSON object.

It's caller's responsibility to use the right function that matches the data type to retrieve data.

Parameters
[in]jsonJSON object.
[out]valueThe pointer to the BOOLEAN value.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_INVALID_PARAMETERThis error code is returned, if value is a null pointer.
CY_P64_JWT_ERR_JSN_WRONG_TYPEThis error code is returned, if JSON object type is not boolean.

◆ cy_p64_json_get_uint32()

cy_p64_error_codes_t cy_p64_json_get_uint32 ( const cy_p64_cJSON json,
uint32_t *  value 
)

Gets the unsigned INTEGER value of a JSON object.

It's caller's responsibility to use the right function that matches the data type to retrieve data.

Parameters
[in]jsonJSON object.
[out]valueThe pointer to the unsigned INTEGER value.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_INVALID_PARAMETERThis error code is returned, if value is a null pointer.
CY_P64_JWT_ERR_JSN_WRONG_TYPEThis error code is returned, if JSON object type is not an integer.

◆ cy_p64_json_get_string()

cy_p64_error_codes_t cy_p64_json_get_string ( const cy_p64_cJSON json,
const char **  value 
)

Gets the unsigned STRING value of a JSON object.

It's caller's responsibility to use the right function that matches the data type to retrieve data.

Parameters
[in]jsonThe JSON object.
[out]valueThe pointer to the STRING value.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_INVALID_PARAMETERThis error code is returned, if value is a null pointer.
CY_P64_JWT_ERR_JSN_WRONG_TYPEThis error ocde is returned, if JSON object type is not a string.

◆ cy_p64_json_get_array_uint8()

cy_p64_error_codes_t cy_p64_json_get_array_uint8 ( const cy_p64_cJSON json,
uint8_t *  buf,
uint32_t  size,
uint32_t *  olen 
)

Gets the ARRAY value, in uint8, of a JSON object.

It's caller's responsibility to use the right function that matches the data type to retrieve data.

Parameters
[in]jsonThe JSON object.
[out]bufThe pointer to the buffer where to store the content.
[in]sizeThe available size of the buffer in bytes.
[out]olenThe actual size used in the buffer in bytes.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_INVALID_PARAMETERThis error code is returned, if buf is a null pointer.
CY_P64_JWT_ERR_JSN_WRONG_TYPEThis error code is returned, if JSON object is not an array or it contains values other than integer or None.

◆ cy_p64_policy_get_image_record()

cy_p64_error_codes_t cy_p64_policy_get_image_record ( const cy_p64_cJSON json,
uint32_t  image_id,
const cy_p64_cJSON **  json_image 
)

Gets the JSON object of the image_id.

Parameters
[in]jsonThe JSON object with a policy to check.
[in]image_idThe image ID.
[out]json_imageOutput JSON object that contains image configuration.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_INVALID_PARAMETERThis error code is returned, if json_image is a null pointer.
CY_P64_JWT_ERR_JSN_NONOBJThis error is returned, if JSON does not contain "boot_upgrade/firmware" array
CY_P64_JWT_ERR_JSN_WRONG_TYPEThis error is returned, if "boot_upgrade/firmware" object type is not an array
CY_P64_INVALID

◆ cy_p64_policy_get_image_address_and_size()

cy_p64_error_codes_t cy_p64_policy_get_image_address_and_size ( const cy_p64_cJSON json,
uint32_t  image_id,
const char *  image_type,
uint32_t *  address,
uint32_t *  size 
)

Gets the image address and size from the provisioning policy.

It calls cy_p64_policy_get_image_record() function to get the image policy.

Parameters
[in]jsonJSON object with policy to check.
[in]image_idThe image ID.
[in]image_typeThe image type: "BOOT", "UPGRADE" or other.
[out]addressOutput image address.
[out]sizeOutput image size.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_INVALID_PARAMETERThis error code is returned, if address or size is a null pointer.
CY_P64_JWT_ERR_JSN_NONOBJThis error is returned, if JSON does not contain "resources" array
CY_P64_JWT_ERR_JSN_WRONG_TYPEThis error is returned, if "resources" object type is not an array
CY_P64_JWT_ERR_JSN_PARSE_FAIL

◆ cy_p64_policy_get_image_boot_config()

cy_p64_error_codes_t cy_p64_policy_get_image_boot_config ( const cy_p64_cJSON json,
uint32_t  image_id,
bool *  wdt_enable,
uint32_t *  wdt_timeout,
bool *  set_img_ok 
)

Gets the image wdt configuration and image_ok from provisioning policy.

It calls cy_p64_policy_get_image_record() function to get image policy. The function sets wdt_enable and set_img_ok output parameters to false if they are absent in the policy.

Parameters
[in]jsonThe JSON object with the policy to check.
[in]image_idThe image ID.
[out]wdt_enableAn optional output wdt_enable config. If the set image needs to configure WDT before launching the next image.
[out]wdt_timeoutWDT timeout value config used for WDT configuration if wdt_enable is set.
[out]set_img_okOptional Image Ok config. When it is set to "true"
  • CM0 pre-build image confirms image ok status in image trailer by calling cy_p64_confirm_image() API, otherwise the user application needs to call this function after a successful boot.
Return values
CY_P64_SUCCESS
CY_P64_JWT_ERR_JSN_PARSE_FAIL