Morse Micro IoT SDK  2.9.7
mmconfig.h
1/*
2 * Copyright 2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
205#pragma once
206
207#include <stddef.h>
208#include <stdbool.h>
209#include <stdint.h>
210
211#ifdef __cplusplus
212extern "C" {
213#endif
214
216#define MMCONFIG_MAX_KEYLEN 32
217
220{
233
240{
245 char *key;
246
249 void *data;
250
252 size_t size;
253
256};
257
265
284int mmconfig_write_data(const char *key, const void *data, size_t size);
285
299static inline int mmconfig_delete_key(const char *key)
300{
301 return mmconfig_write_data(key, NULL, 0);
302}
303
325
341int mmconfig_write_string(const char *key, const char *value);
342
364int mmconfig_read_string(const char *key, char *buffer, int bufsize);
365
383int mmconfig_alloc_and_load(const char *key, void **data);
384
399int mmconfig_write_int(const char *key, int value);
400
416int mmconfig_read_int(const char *key, int *value);
417
432int mmconfig_write_uint32(const char *key, uint32_t value);
433
449int mmconfig_read_uint32(const char *key, uint32_t *value);
450
465int mmconfig_write_bool(const char *key, bool value);
466
484int mmconfig_read_bool(const char *key, bool *value);
485
501int mmconfig_read_bytes(const char *key, void *buffer, uint32_t buffsize, uint32_t offset);
502
513int mmconfig_validate_key(const char *key);
514
528
542int mmconfig_check_usage(const struct mmconfig_update_node *node_list,
543 uint32_t *bytes_used, int32_t *bytes_remaining);
544
552
553#ifdef __cplusplus
554}
555#endif
556
int mmconfig_write_int(const char *key, int value)
Converts the given integer to a string and writes to persistent store.
static int mmconfig_delete_key(const char *key)
Deletes the specified key(s) from persistent store.
Definition: mmconfig.h:299
mmconfig_result
Return & error codes.
Definition: mmconfig.h:220
int mmconfig_read_string(const char *key, char *buffer, int bufsize)
Returns the persistent store string value identified by the key.
int mmconfig_read_int(const char *key, int *value)
Returns the integer stored in persistent store identified by the key.
int mmconfig_read_bool(const char *key, bool *value)
Returns the boolean value stored in persistent store identified by the key.
int mmconfig_write_bool(const char *key, bool value)
Converts the given boolean to a string and writes to persistent store.
int mmconfig_write_update_node_list(const struct mmconfig_update_node *node_list)
Writes all updates from the update node list to persistent store.
int mmconfig_eraseall(void)
Erases all flash blocks allocated to persistent storage and write the signature at the 2 copies in fl...
int mmconfig_write_uint32(const char *key, uint32_t value)
Converts the given unsigned integer to a string and writes to persistent store.
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 ...
void load_mmwlan_settings(void)
Loads and applies any other mmwlan settings specified in config store.
int mmconfig_write_data(const char *key, const void *data, size_t size)
Writes the raw data to persistent store location identified by key.
int mmconfig_validate_key(const char *key)
Validates an entire key intended for data storage.
int mmconfig_read_bytes(const char *key, void *buffer, uint32_t buffsize, uint32_t offset)
Returns the persistent store data identified by the key.
int mmconfig_write_string(const char *key, const char *value)
Writes the null terminated string to persistent store location identified by key.
int mmconfig_read_uint32(const char *key, uint32_t *value)
Returns the unsigned integer stored in persistent store identified by the key.
int mmconfig_alloc_and_load(const char *key, void **data)
Allocates memory and loads the data from persistent memory into it returning a pointer.
int mmconfig_validate_key_character(char character)
Validates a single character intended to make up a key for data storage.
@ MMCONFIG_ERR_NOT_SUPPORTED
Operation not supported.
Definition: mmconfig.h:230
@ MMCONFIG_ERR_NOT_FOUND
Requested key was not found.
Definition: mmconfig.h:225
@ MMCONFIG_ERR_FULL
Config store is full.
Definition: mmconfig.h:224
@ MMCONFIG_DATA_ERASED
Partition was erased.
Definition: mmconfig.h:222
@ MMCONFIG_ERR_INVALID_KEY
Key provided was invalid.
Definition: mmconfig.h:223
@ MMCONFIG_ERR_OUT_OF_BOUNDS
Offset was out of bounds.
Definition: mmconfig.h:229
@ MMCONFIG_ERR_INSUFFICIENT_MEMORY
Insufficient memory.
Definition: mmconfig.h:228
@ MMCONFIG_ERR_INVALID_PARTITION
Valid partition was not found.
Definition: mmconfig.h:227
@ MMCONFIG_ERR_WILDCARD_KEY
Key contains wildcard valid only for deletion.
Definition: mmconfig.h:231
@ MMCONFIG_OK
Operation completed successfully.
Definition: mmconfig.h:221
@ MMCONFIG_ERR_INCORRECT_TYPE
Requested data type did not match found data.
Definition: mmconfig.h:226
Update node structure.
Definition: mmconfig.h:240
size_t size
Size of the data.
Definition: mmconfig.h:252
void * data
Pointer to the data.
Definition: mmconfig.h:249
char * key
The key, which should be pre-validated using mmconfig_validate_key(), unless it is to be used for mul...
Definition: mmconfig.h:245
struct mmconfig_update_node * next
Pointer to the next node in the list.
Definition: mmconfig.h:255