Morse Micro IoT SDK  2.10.4
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{
214#endif
215
217#define MMCONFIG_MAX_KEYLEN 32
218
221{
234
241{
246 char *key;
247
250 void *data;
251
253 size_t size;
254
257};
258
266
285int mmconfig_write_data(const char *key, const void *data, size_t size);
286
300static inline int mmconfig_delete_key(const char *key)
301{
302 return mmconfig_write_data(key, NULL, 0);
303}
304
326
342int mmconfig_write_string(const char *key, const char *value);
343
365int mmconfig_read_string(const char *key, char *buffer, int bufsize);
366
384int mmconfig_alloc_and_load(const char *key, void **data);
385
400int mmconfig_write_int(const char *key, int value);
401
417int mmconfig_read_int(const char *key, int *value);
418
433int mmconfig_write_uint32(const char *key, uint32_t value);
434
450int mmconfig_read_uint32(const char *key, uint32_t *value);
451
466int mmconfig_write_bool(const char *key, bool value);
467
485int mmconfig_read_bool(const char *key, bool *value);
486
502int mmconfig_read_bytes(const char *key, void *buffer, uint32_t buffsize, uint32_t offset);
503
514int mmconfig_validate_key(const char *key);
515
529
543int mmconfig_check_usage(const struct mmconfig_update_node *node_list,
544 uint32_t *bytes_used,
545 int32_t *bytes_remaining);
546
554
555#ifdef __cplusplus
556}
557#endif
558
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:300
mmconfig_result
Return & error codes.
Definition: mmconfig.h:221
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:231
@ MMCONFIG_ERR_NOT_FOUND
Requested key was not found.
Definition: mmconfig.h:226
@ MMCONFIG_ERR_FULL
Config store is full.
Definition: mmconfig.h:225
@ MMCONFIG_DATA_ERASED
Partition was erased.
Definition: mmconfig.h:223
@ MMCONFIG_ERR_INVALID_KEY
Key provided was invalid.
Definition: mmconfig.h:224
@ MMCONFIG_ERR_OUT_OF_BOUNDS
Offset was out of bounds.
Definition: mmconfig.h:230
@ MMCONFIG_ERR_INSUFFICIENT_MEMORY
Insufficient memory.
Definition: mmconfig.h:229
@ MMCONFIG_ERR_INVALID_PARTITION
Valid partition was not found.
Definition: mmconfig.h:228
@ MMCONFIG_ERR_WILDCARD_KEY
Key contains wildcard valid only for deletion.
Definition: mmconfig.h:232
@ MMCONFIG_OK
Operation completed successfully.
Definition: mmconfig.h:222
@ MMCONFIG_ERR_INCORRECT_TYPE
Requested data type did not match found data.
Definition: mmconfig.h:227
Update node structure.
Definition: mmconfig.h:241
size_t size
Size of the data.
Definition: mmconfig.h:253
void * data
Pointer to the data.
Definition: mmconfig.h:250
char * key
The key, which should be pre-validated using mmconfig_validate_key(), unless it is to be used for mul...
Definition: mmconfig.h:246
struct mmconfig_update_node * next
Pointer to the next node in the list.
Definition: mmconfig.h:256