Morse Micro IoT SDK  2.9.7
Morse Micro Persistent Configuration Store API

Detailed Description

This API provides functionality for managing configuration data in a key/value store with a flash backend.

Data Structures

struct  mmconfig_update_node
 Update node structure. More...
 

Macros

#define MMCONFIG_MAX_KEYLEN   32
 The maximum length of a key in bytes. More...
 

Enumerations

enum  mmconfig_result {
  MMCONFIG_OK = 0 , MMCONFIG_DATA_ERASED = 1 , MMCONFIG_ERR_INVALID_KEY = -1 , MMCONFIG_ERR_FULL = -2 ,
  MMCONFIG_ERR_NOT_FOUND = -3 , MMCONFIG_ERR_INCORRECT_TYPE = -4 , MMCONFIG_ERR_INVALID_PARTITION = -5 , MMCONFIG_ERR_INSUFFICIENT_MEMORY = -6 ,
  MMCONFIG_ERR_OUT_OF_BOUNDS = -7 , MMCONFIG_ERR_NOT_SUPPORTED = -8 , MMCONFIG_ERR_WILDCARD_KEY = -9
}
 Return & error codes. More...
 

Functions

int mmconfig_eraseall (void)
 Erases all flash blocks allocated to persistent storage and write the signature at the 2 copies in flash. More...
 
int mmconfig_write_data (const char *key, const void *data, size_t size)
 Writes the raw data to persistent store location identified by key. More...
 
static int mmconfig_delete_key (const char *key)
 Deletes the specified key(s) from persistent store. More...
 
int mmconfig_write_update_node_list (const struct mmconfig_update_node *node_list)
 Writes all updates from the update node list to persistent store. More...
 
int mmconfig_write_string (const char *key, const char *value)
 Writes the null terminated string to persistent store location identified by key. More...
 
int mmconfig_read_string (const char *key, char *buffer, int bufsize)
 Returns the persistent store string value identified by the key. More...
 
int mmconfig_alloc_and_load (const char *key, void **data)
 Allocates memory and loads the data from persistent memory into it returning a pointer. More...
 
int mmconfig_write_int (const char *key, int value)
 Converts the given integer to a string and writes to persistent store. More...
 
int mmconfig_read_int (const char *key, int *value)
 Returns the integer stored in persistent store identified by the key. More...
 
int mmconfig_write_uint32 (const char *key, uint32_t value)
 Converts the given unsigned integer to a string and writes to persistent store. More...
 
int mmconfig_read_uint32 (const char *key, uint32_t *value)
 Returns the unsigned integer stored in persistent store identified by the key. More...
 
int mmconfig_write_bool (const char *key, bool value)
 Converts the given boolean to a string and writes to persistent store. More...
 
int mmconfig_read_bool (const char *key, bool *value)
 Returns the boolean value stored in persistent store identified by the key. More...
 
int mmconfig_read_bytes (const char *key, void *buffer, uint32_t buffsize, uint32_t offset)
 Returns the persistent store data identified by the key. More...
 
int mmconfig_validate_key (const char *key)
 Validates an entire key intended for data storage. More...
 
int mmconfig_validate_key_character (char character)
 Validates a single character intended to make up a key for data storage. More...
 
int mmconfig_check_usage (const struct mmconfig_update_node *node_list, uint32_t *bytes_used, int32_t *bytes_remaining)
 Calculates the number of bytes that would be needed to write the given updates (if not NULL) and the number of bytes that would remain free in the persistent store afterwards. More...
 
void load_mmwlan_settings (void)
 Loads and applies any other mmwlan settings specified in config store. More...
 

Macro Definition Documentation

◆ MMCONFIG_MAX_KEYLEN

#define MMCONFIG_MAX_KEYLEN   32

The maximum length of a key in bytes.

Definition at line 216 of file mmconfig.h.

Enumeration Type Documentation

◆ mmconfig_result

Return & error codes.

Enumerator
MMCONFIG_OK 

Operation completed successfully.

MMCONFIG_DATA_ERASED 

Partition was erased.

MMCONFIG_ERR_INVALID_KEY 

Key provided was invalid.

MMCONFIG_ERR_FULL 

Config store is full.

MMCONFIG_ERR_NOT_FOUND 

Requested key was not found.

MMCONFIG_ERR_INCORRECT_TYPE 

Requested data type did not match found data.

MMCONFIG_ERR_INVALID_PARTITION 

Valid partition was not found.

MMCONFIG_ERR_INSUFFICIENT_MEMORY 

Insufficient memory.

MMCONFIG_ERR_OUT_OF_BOUNDS 

Offset was out of bounds.

MMCONFIG_ERR_NOT_SUPPORTED 

Operation not supported.

MMCONFIG_ERR_WILDCARD_KEY 

Key contains wildcard valid only for deletion.

Definition at line 219 of file mmconfig.h.

Function Documentation

◆ load_mmwlan_settings()

void load_mmwlan_settings ( void  )

Loads and applies any other mmwlan settings specified in config store.

Specifically looks for wlan.subbands_enabled, wlan.sgi_enabled, wlan.ampdu_enabled, wlan.fragment_threshold and wlan.rts_threshold.

◆ mmconfig_alloc_and_load()

int mmconfig_alloc_and_load ( const char *  key,
void **  data 
)

Allocates memory and loads the data from persistent memory into it returning a pointer.

It is the responsibility of the caller to free the memory when it is no longer required.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
dataReturns a pointer to allocated memory loaded with the key value. Returns NULL on any error.
Returns
Returns number of bytes read and allocated on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INSUFFICIENT_MEMORY if memory could not be allocated Other negative number for other errors.

◆ mmconfig_check_usage()

int mmconfig_check_usage ( const struct mmconfig_update_node node_list,
uint32_t *  bytes_used,
int32_t *  bytes_remaining 
)

Calculates the number of bytes that would be needed to write the given updates (if not NULL) and the number of bytes that would remain free in the persistent store afterwards.

Parameters
node_listPointer to a linked list of nodes to be sized. May be NULL if there is nothing to store
bytes_usedPointer for the size of current data plus node_list
bytes_remainingPointer for the number of bytes that would remain free if node_list was stored. May be negative if insufficient storage is available.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_NOT_SUPPORTED if there is no persistent store

◆ mmconfig_delete_key()

static int mmconfig_delete_key ( const char *  key)
inlinestatic

Deletes the specified key(s) from persistent store.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. For deletion a wildcard (*) may be specified at the end to delete multiple keys in one go. Must be a null terminated string.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors.

Definition at line 299 of file mmconfig.h.

◆ mmconfig_eraseall()

int mmconfig_eraseall ( void  )

Erases all flash blocks allocated to persistent storage and write the signature at the 2 copies in flash.

Returns
It returns 0 on success or an error code on failure.

◆ mmconfig_read_bool()

int mmconfig_read_bool ( const char *  key,
bool *  value 
)

Returns the boolean value stored in persistent store identified by the key.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
valueReturns the boolean value stored, it is converted from string but may even be a single byte raw boolean value. The string representation may be "true"/"false" or a "0"/non zero integer string. On error, the value is untouched, so can be preloaded with a default.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not an integer represented as a string

◆ mmconfig_read_bytes()

int mmconfig_read_bytes ( const char *  key,
void *  buffer,
uint32_t  buffsize,
uint32_t  offset 
)

Returns the persistent store data identified by the key.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
bufferA pointer to a pre-allocated buffer to return the data address in.
buffsizeThe length of the buffer.
offsetAn offset into the source from which to copy the data into the buffer.
Returns
Returns length of data copied on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_OUT_OF_BOUNDS if the offset is out of bounds Other negative number for other errors.

◆ mmconfig_read_int()

int mmconfig_read_int ( const char *  key,
int *  value 
)

Returns the integer stored in persistent store identified by the key.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
valueReturns the integer in this, it is converted from string. On error, the value is untouched, so can be preloaded with a default.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not an integer represented as a string

◆ mmconfig_read_string()

int mmconfig_read_string ( const char *  key,
char *  buffer,
int  bufsize 
)

Returns the persistent store string value identified by the key.

Note
If you use mmconfig_read_string() to read data written by mmconfig_write_data() then it could fail if the data is not null terminated.
Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
bufferBuffer to read the string into. On error, the buffer is untouched, so can be preloaded with a default value.
bufsizeLength of buffer.
Returns
Returns length of string read on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not a null terminated string MMCONFIG_ERR_INSUFFICIENT_MEMORY if the buffer size is insufficient Other negative number for other errors.

◆ mmconfig_read_uint32()

int mmconfig_read_uint32 ( const char *  key,
uint32_t *  value 
)

Returns the unsigned integer stored in persistent store identified by the key.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
valueReturns the unsigned integer in this, it is converted from string. On error, the value is untouched, so can be preloaded with a default.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not an unsigned integer or hexadecimal number represented as a string

◆ mmconfig_validate_key()

int mmconfig_validate_key ( const char *  key)

Validates an entire key intended for data storage.

Parameters
keyThe key to validate
Returns
Returns MMCONFIG_OK if the key is valid, or MMCONFIG_ERR_INVALID_KEY if key is invalid
Note
If the key ends in an asterisk '*' it will fail this validation. However, it is still valid for deleting multiple keys (where any key matching up to the asterisk will be deleted).

◆ mmconfig_validate_key_character()

int mmconfig_validate_key_character ( char  character)

Validates a single character intended to make up a key for data storage.

Parameters
characterThe character to validate
Returns
Returns MMCONFIG_OK if the character is valid, or MMCONFIG_ERR_INVALID_KEY if character is invalid
Note
Additional restrictions apply to the first character of a key If the character is an asterisk '*' it will fail this validation. '*' is still valid for deleting multiple keys (where any key matching up to the asterisk will be deleted).

◆ mmconfig_write_bool()

int mmconfig_write_bool ( const char *  key,
bool  value 
)

Converts the given boolean to a string and writes to persistent store.

If there is already data with the same key then it will be replaced.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
valueThe boolean value to be written, it is converted to string and written.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid Other negative number for other errors.

◆ mmconfig_write_data()

int mmconfig_write_data ( const char *  key,
const void *  data,
size_t  size 
)

Writes the raw data to persistent store location identified by key.

If there is already data with the same key (ignoring case) then it will be replaced.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
dataThe binary data to be written, can contain nulls and need not be null terminated. Can be a pointer to a structure or any arbitrary data to be written.
sizeThe size of the binary data to be written.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors.

◆ mmconfig_write_int()

int mmconfig_write_int ( const char *  key,
int  value 
)

Converts the given integer to a string and writes to persistent store.

If there is already data with the same key then it will be replaced.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
valueThe integer to be written, it is converted to string and written.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid Other negative number for other errors.

◆ mmconfig_write_string()

int mmconfig_write_string ( const char *  key,
const char *  value 
)

Writes the null terminated string to persistent store location identified by key.

If there is already data with the same key (ignoring case) then it will be replaced.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
valueThe data to be written, must be a null terminated string.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors.

◆ mmconfig_write_uint32()

int mmconfig_write_uint32 ( const char *  key,
uint32_t  value 
)

Converts the given unsigned integer to a string and writes to persistent store.

If there is already data with the same key then it will be replaced.

Parameters
keyIdentifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string.
valueThe unsigned integer to be written, it is converted to string and written.
Returns
Returns MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid Other negative number for other errors.

◆ mmconfig_write_update_node_list()

int mmconfig_write_update_node_list ( const struct mmconfig_update_node node_list)

Writes all updates from the update node list to persistent store.

If there is already data with the same key (ignoring case) then it will be replaced. If data is NULL then it will be deleted.

Note
It is up to the caller to ensure that there is only one non-NULL data item per key, otherwise both entries will be written. The caller retains ownership of the list and is responsible for freeing the nodes after the write.
Parameters
node_listPointer to a linked list of nodes to be included in the update.
Returns
Returns MMCONFIG_OK on success. On error, no update takes place and the return code is: MMCONFIG_ERR_INVALID_KEY if a key in the list is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors.