Common Token Manager#

Routines for working with tokens using the Common Token Manager.


Introduction#

The Common Token Manager (CTM) provides a means to read and write manufacturing (static device and static secure) and dynamic tokens such as manufacturing ID, channel number, transmit power, and various pieces of information that the application needs to be persistent between device power cycles. The token system is designed to abstract implementation details and simplify interacting with differing non-volatile systems. The majority of tokens are stored in NVM3 where they can be rewritten. By default the CTM uses NVM3 component for storage.

The CTM API is designed to be used across different platforms, providing a unified interface for token management. It supports both dynamic tokens and static tokens.

  • The dynamic tokens are stored in NVM3, which can be modified at runtime, allowing for read and write operations.

  • The static tokens are typically used for manufacturing data and are not intended to be modified after the initial write. The static tokens are further divided into

    • Static device tokens, which are stored in secure memory regions, has limited storage capacity, and are mass erase protected.

    • Static secure tokens, which are stored in a dedicated flash region, with additional security measures when flash is external (uses 128-bit AES-GCM mode to secure the data). The static secure region has a reserved 8k space at the end of flash. This space is used for storing larger size tokens.

In CTM, tokens are identified by a 32-bit identifier that includes the token type, size, and a unique key. The token type can be one of the following:

  • SL_TOKEN_TYPE_NVM3: For dynamic tokens stored in NVM3.

  • SL_TOKEN_TYPE_NVM3_SECONDARY: For dynamic tokens stored in a secondary NVM3 instance.

  • SL_TOKEN_TYPE_STATIC_DEVICE: For static device tokens stored in secure memory.

  • SL_TOKEN_TYPE_STATIC_SECURE: For static secure tokens stored in a dedicated flash region. The token size is embedded in the identifier for only static tokens, allowing the CTM to manage tokens of varying sizes.

To create a 32-bit token identifier, the CTM provides helper macros such as:

The CTM API provides functions to initialize the token manager, read and write token data, increment counter tokens, and manage token sizes. It also supports partial reads of token data, allowing applications to access specific portions of token data without needing to read the entire token.

Modules#

Common Token Manager Defines

Common Token Manager lock functions

Functions#

sl_status_t

Initialize the Token Manager.

sl_status_t
sl_token_manager_get_data(uint32_t token, void *data, uint32_t length)

Read token data.

sl_status_t
sl_token_manager_set_data(uint32_t token, void *data, uint32_t length)

Write token data.

sl_status_t
sl_token_manager_get_partial_data(uint32_t token, void *data, uint32_t offset, uint32_t length)

This call supports reading both dynamic and static tokens partially.

sl_status_t

This call supports deleting a dynamic token.

sl_status_t

Increments the value of a counter object by 1.

sl_status_t
sl_token_manager_get_size(uint32_t token, uint32_t *size_out)

This call reads the token size.

Function Documentation#

sl_token_manager_init#

sl_status_t sl_token_manager_init (void )

Initialize the Token Manager.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Note

  • This function must be called before any other token manager functions are called. The sl_token_manager_init() call will be automatically added to your initialization.

Returns

  • SL_STATUS_OK if successful, an error code otherwise.


sl_token_manager_get_data#

sl_status_t sl_token_manager_get_data (uint32_t token, void * data, uint32_t length)

Read token data.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]token

A 32-bit token identifier. Refer sl_token_manager_defines.h on how to create a token.

void *[out]data

A pointer to where the token data should be placed.

uint32_t[in]length

The size of the data to be read, in bytes.

Returns

  • SL_STATUS_OK if successful, an error code otherwise.


sl_token_manager_set_data#

sl_status_t sl_token_manager_set_data (uint32_t token, void * data, uint32_t length)

Write token data.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]token

A 32-bit token identifier. Refer sl_token_manager_defines.h on how to create a token.

void *[in]data

A pointer to the data being written.

uint32_t[in]length

The size of the token data in number of bytes.

Note

  • Writing static tokens on Silicon Labs devices has different constraints depending on the series:

Silicon Labs Series 2 (EFR) devices: Only static token values that have not been written since the last erase can be written. For areas of flash that cannot be erased by user code, those static tokens are effectively write-once.

Returns

  • SL_STATUS_OK if successful, an error code otherwise.


sl_token_manager_get_partial_data#

sl_status_t sl_token_manager_get_partial_data (uint32_t token, void * data, uint32_t offset, uint32_t length)

This call supports reading both dynamic and static tokens partially.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]token

A 32-bit token identifier. Refer sl_token_manager_defines.h on how to create a token.

void *[out]data

A pointer to where the token data should be placed.

uint32_t[in]offset

Indicates the number of bytes to skip from the beginning of the token data before starting to read.

uint32_t[in]length

The size of the data (full or partial) to be read, in bytes.

Returns

  • SL_STATUS_OK if successful, an error code otherwise.


sl_token_manager_delete_dynamic_token#

sl_status_t sl_token_manager_delete_dynamic_token (uint32_t token)

This call supports deleting a dynamic token.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]token

A 32-bit token identifier. Refer sl_token_manager_defines.h on how to create a token.

Note

  • This call also supports deleting static tokens, if they have been overridden with NVM3 override tokens. Only the override tokens are deleted.

Returns

  • SL_STATUS_OK if successful, an error code otherwise.


sl_token_manager_increment_counter#

sl_status_t sl_token_manager_increment_counter (uint32_t token)

Increments the value of a counter object by 1.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]token

A 32-bit token identifier. Refer sl_token_manager_defines.h on how to create a token.

Counter tokens are stored in NVM3.

Returns

  • SL_STATUS_OK if successful, an error code otherwise.


sl_token_manager_get_size#

sl_status_t sl_token_manager_get_size (uint32_t token, uint32_t * size_out)

This call reads the token size.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]token

A 32-bit token identifier. Refer sl_token_manager_defines.h on how to create a token.

uint32_t *[out]size_out

output parameter to know the size of token.

Note

  • This call can be used to know the token size and user can allocate buffer for holding the token data at runtime.

Returns

  • SL_STATUS_OK if successful, an error code otherwise.