Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers thread_nvm_store.h Source File

thread_nvm_store.h

00001 /*
00002  * Copyright (c) 2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: BSD-3-Clause
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holder nor the
00014  *    names of its contributors may be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 #ifndef THREAD_NVM_STORE_H_
00030 #define THREAD_NVM_STORE_H_
00031 
00032 #include <stdio.h>
00033 #include <errno.h>
00034 #include <stdint.h>
00035 
00036 /*
00037  * \file thread_nvm_store.h
00038  * \brief This API is for storing Thread related values to NVM file system.
00039  * The Posix API is used for file storing/reading (file fopen, fread, fwrite).
00040  * The get functions should only be used when the device is booted up, because read functions
00041  * are slow and can cause packet dropping.
00042  * The storing functions do some filtering (see below) in order to avoid excess writing to NVM.
00043  */
00044 
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 #define THREAD_NVM_FILE_SUCCESS            0
00051 #define THREAD_NVM_FILE_READ_ERROR        -1
00052 #define THREAD_NVM_FILE_WRITE_ERROR       -2
00053 #define THREAD_NVM_FILE_VERSION_WRONG     -3
00054 #define THREAD_NVM_FILE_CANNOT_OPEN       -4
00055 #define THREAD_NVM_FILE_ROOT_PATH_INVALID -5
00056 #define THREAD_NVM_FILE_PARAMETER_INVALID -6
00057 #define THREAD_NVM_FILE_REMOVE_ERROR      -7
00058 
00059 typedef struct {
00060     uint32_t mle_frame_counter;
00061     uint32_t mac_frame_counter;
00062     uint32_t seq_counter;
00063 } thread_nvm_fast_data_t;
00064 
00065 typedef struct {
00066     uint8_t mac[8];
00067     uint8_t mle_id[8];
00068 } thread_nvm_device_conf_t;
00069 
00070 /* reads all fast data from nvm, if the return values is THREAD_NVM_FILE_ROOT_PATH_INVALID, the cached values are returned.  */
00071 int thread_nvm_store_fast_data_read(thread_nvm_fast_data_t* fast_data);
00072 /* stores all fast data to nvm */
00073 int thread_nvm_store_fast_data_write(thread_nvm_fast_data_t* fast_data);
00074 /* stores new frame counters to nvm only if the any frame counter threshold is passed*/
00075 int thread_nvm_store_frame_counters_check_and_write(uint32_t mac_frame_counter, uint32_t mle_frame_counter);
00076 /* stores the frame counter and seq counter to nvm only if any threshold is passed*/
00077 int thread_nvm_store_fast_data_check_and_write(uint32_t mac_frame_counter, uint32_t mle_frame_counter, uint32_t network_seq_counter);
00078 /* stores the value to nvm only if it has changed */
00079 
00080 int thread_nvm_store_seq_counter_write(uint32_t network_seq_counter);
00081 /* stores the active configuration */
00082 int thread_nvm_store_active_configuration_write(void *data, uint16_t data_size);
00083 /* Reads the active configuration */
00084 int thread_nvm_store_active_configuration_read(void *data, uint16_t data_size);
00085 /* Removes the active configuration */
00086 int thread_nvm_store_active_configuration_remove(void);
00087 
00088 int thread_nvm_store_device_configuration_write(uint8_t *mac_ptr, uint8_t *mleid_ptr);
00089 int thread_nvm_store_device_configuration_read(uint8_t *mac_ptr, uint8_t *mleid_ptr);
00090 int thread_nvm_store_pending_configuration_write(void *data, uint16_t size);
00091 int thread_nvm_store_pending_configuration_read(void *data, uint16_t size);
00092 int thread_nvm_store_pending_configuration_remove(void);
00093 
00094 int thread_nvm_store_seq_counter_store(uint32_t network_seq_counter);
00095 /* read link info to cache */
00096 int thread_nvm_store_link_info_read(void);
00097 /* get link information */
00098 int thread_nvm_store_link_info_get(uint8_t *parent_mac64, uint16_t *my_short_address);
00099 /* clear link information */
00100 int thread_nvm_store_link_info_clear(void);
00101 /* write link information, will use caching and delayed writing */
00102 int thread_nvm_store_link_info_write(uint8_t *parent_mac, uint16_t short_addr);
00103 /* second timer for NVM store to delay operations */
00104 void thread_nvm_store_seconds_timer(uint32_t seconds);
00105 
00106 #ifdef __cplusplus
00107 }
00108 #endif
00109 
00110 #endif //THREAD_NVM_STORE_H_