Files
kunlun/app/utils/iot_app_pib_api.h
2024-09-28 14:24:04 +08:00

283 lines
9.1 KiB
C
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef IOT_APP_PIB_API_H
#define IOT_APP_PIB_API_H
/* os shim includes */
#include "os_types_api.h"
#include "os_utils_api.h"
/* common includes */
#include "iot_module_api.h"
#include "iot_config_api.h"
#include "iot_plc_msg_api.h"
#include "iot_pib_api.h"
#include "iot_plc_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* max support whitelist count for cco device */
#if RUN_IN_PSRAM
#define IOT_APP_CCO_WL_PIB_ADDR_CNT 500
#else
#define IOT_APP_CCO_WL_PIB_ADDR_CNT 200
#endif
/* max support whitelist count for sta device */
#define IOT_APP_STA_WL_PIB_ADDR_CNT 16
/* max support whitelist length for cco device */
#define IOT_APP_CCO_WL_ADDR_LEN (IOT_APP_CCO_WL_PIB_ADDR_CNT * IOT_MAC_ADDR_LEN)
/* max support whitelist length for sta device */
#define IOT_APP_STA_WL_ADDR_LEN (IOT_APP_STA_WL_PIB_ADDR_CNT * IOT_MAC_ADDR_LEN)
/* whitelist phase ABC offset value */
#define IOT_APP_CCO_PHASE_OFFSET_CNT (3)
/* app pib device specific persistent storage magic */
#define APP_PIB_RW_MARK_MAGIC 0x38E20FB7
/* pack for the structures in the whole file */
#pragma pack(push) // save the pack status
#pragma pack(1) // 1 byte align
/* uart config */
typedef struct _uart_cfg {
/* if uart baud config is vaild */
uint8_t uart_conf_vaild :1,
/* reserved for future use */
reserve :7;
/* uart baud rate */
uint32_t baud_rate;
/* uart parity */
uint8_t parity;
/* Number of uart data bits */
uint8_t data_bits;
/* Number of uart stop bits */
uint8_t stop_bits;
/* UART_THR_RXTIMEOUT of threshold value */
uint32_t threshold_value;
/* reserved for future use */
uint16_t rsvd;
} uart_cfg_t;
/* app layer CCO role writable section layout in PIB */
typedef struct _iot_cco_app_pib_rw {
/* magic marker */
uint32_t mark_magic;
/* white state enable or disable */
uint8_t wl_state : 1,
/* work_band valid */
band_valid : 1,
/* reserved for future use */
rsvd : 6;
/* white list info */
uint8_t white_list[IOT_APP_CCO_WL_ADDR_LEN];
/* self mac address */
uint8_t local_mac[IOT_MAC_ADDR_LEN];
/* uart config parameter */
uart_cfg_t uart_param;
/* work band for cco */
uint8_t work_band;
/* white list ABC phase offset value */
uint16_t phase_offset[IOT_APP_CCO_PHASE_OFFSET_CNT];
/* driver specific persistent storage */
uint8_t drv[IOT_PIB_CCO_APP_WRITE_SECTION_SIZE - \
sizeof(uint32_t) - \
sizeof(uint8_t) - \
IOT_APP_CCO_WL_ADDR_LEN - \
IOT_MAC_ADDR_LEN - \
sizeof(uart_cfg_t) - \
sizeof(uint8_t) - \
sizeof(uint16_t) * IOT_APP_CCO_PHASE_OFFSET_CNT];
} iot_cco_app_pib_rw_t;
/* app layer STA role writable section layout in PIB */
typedef struct _iot_sta_app_pib_rw {
/* magic marker */
uint32_t mark_magic;
/* white state enable or disable */
uint8_t wl_state : 1,
/* scan band valid */
scan_band_valid : 1,
/* reserved for future use */
rsvd : 6;
/* white list info */
uint8_t white_list[IOT_APP_STA_WL_ADDR_LEN];
/* self mac address */
uint8_t local_mac[IOT_MAC_ADDR_LEN];
/* uart config parameter */
uart_cfg_t uart_param;
/* sta scan band for app setting */
uint8_t scan_band_bitmap[IOT_PLC_BAND_BITMAP_SIZE];
/* driver specific persistent storage */
uint8_t drv[IOT_PIB_STA_APP_WRITE_SECTION_SIZE - \
sizeof(uint32_t) - \
sizeof(uint8_t) - \
IOT_APP_STA_WL_ADDR_LEN - \
IOT_MAC_ADDR_LEN - \
sizeof(uart_cfg_t) - \
IOT_PLC_BAND_BITMAP_SIZE];
} iot_sta_app_pib_rw_t;
#if PLC_SUPPORT_CCO_ROLE
typedef iot_cco_app_pib_rw_t app_pib_rw_t;
#define IOT_APP_WL_PIB_ADDR_CNT IOT_APP_CCO_WL_PIB_ADDR_CNT
#define IOT_APP_WL_ADDR_LEN IOT_APP_CCO_WL_ADDR_LEN
#define IOT_PIB_APP_WRITE_SECTION_SIZE IOT_PIB_CCO_APP_WRITE_SECTION_SIZE
#else
typedef iot_sta_app_pib_rw_t app_pib_rw_t;
#define IOT_APP_WL_PIB_ADDR_CNT IOT_APP_STA_WL_PIB_ADDR_CNT
#define IOT_APP_WL_ADDR_LEN IOT_APP_STA_WL_ADDR_LEN
#define IOT_PIB_APP_WRITE_SECTION_SIZE IOT_PIB_STA_APP_WRITE_SECTION_SIZE
#endif /* PLC_SUPPORT_CCO_ROLE */
/* struct contain info of a white list entry */
typedef struct _iot_app_wl_entry_info {
/* meter address */
uint8_t mac_addr[IOT_MAC_ADDR_LEN];
/* protocol the node supports */
uint8_t proto_type;
} iot_app_wl_entry_info_t;
/* struct containing white list entry information */
typedef struct _iot_app_wl_entry_info_transfer {
uint16_t total_count;
uint8_t count;
iot_app_wl_entry_info_t info[0];
} iot_app_wl_entry_info_transfer_t;
#pragma pack(pop) /* restore the pack status */
/**
* @function_name: iot_app_whitelist_pib_enable_qr
* @brief : query white_state save in pib
* @param[in] app_handle: app handle.
* @param[out] value: 0 - disable 1-enable
* @return see ERR_XXX.
**/
uint32_t iot_app_whitelist_pib_enable_qr(iot_plc_app_h app_handle,
uint8_t *value);
/**
* @function_name: iot_app_whitelist_pib_enable_set
* @brief : set white_state to pib
* @param[in] app_handle: app handle.
* @param[in] value: 0 - disable 1-enable
**/
void iot_app_whitelist_pib_enable_set(iot_plc_app_h app_handle, uint8_t value);
/**
* @function_name: iot_app_whitelist_pib_add
* @brief :add whitelist to pib
* @param[in] app_handle: app handle.
* @param[in] count:add count
* @param[in] mac_addr_array:whitelist address array
* @param[in] phase:whitelist address phase
**/
void iot_app_whitelist_pib_add(iot_plc_app_h app_handle, uint16_t count,
uint8_t *mac_addr_array, uint8_t phase);
/**
* @function_name: iot_app_whitelist_pib_rm
* @brief :delete whitelist from pib
* @param[in] app_handle: app handle.
* @param[in] count:delete count
* @param[in] mac_addr_array:whitelist address array
**/
void iot_app_whitelist_pib_rm(iot_plc_app_h app_handle, uint16_t count,
uint8_t *mac_addr_array);
/**
* @function_name: iot_app_whitelist_pib_rm_all
* @brief :remove all whitelist in pib
* @param[in] app_handle: app handle.
**/
void iot_app_whitelist_pib_rm_all(iot_plc_app_h app_handle);
/**
* @function_name: iot_app_get_wl_cnt.
* @brief : get whitelist count.
* @return count of whitelist.
**/
uint16_t iot_app_get_wl_cnt();
/**
* @function_name: iot_app_whitelist_pib_sync
* @brief : sync whitelist from pib
* @param[in] app_handle: app handle.
* @return see ERR_XXX.
**/
uint32_t iot_app_whitelist_pib_sync(iot_plc_app_h app_handle);
/**
* @function_name: iot_app_get_wl_entry_info
* @brief :query whitelist info from pib
* @param[in] start_index: query start position
* @param[in] count: query count
* @param[in] ex_len: the length reserved at the head of pkt data
* @return whitelist pkt info.
**/
iot_pkt_t* iot_app_get_wl_entry_info(uint32_t start_index, uint32_t count,
uint16_t ex_len);
/**
* @function_name: iot_app_get_addrs_index_in_wl.
* @brief : get index of mac address in whitelist.
* @param[in] mac:mac address to be queried.
* @return success: index of mac address, failed: -1 .
**/
int16_t iot_app_get_addrs_index_in_wl(uint8_t *mac);
/**
* @function_name: iot_app_get_mac_in_pib.
* @brief : get local mac address saved in pib.
* @param[out] mac:mac address to be queried, big endian.
* @return success: 0, failed: others .
**/
uint8_t iot_app_get_mac_in_pib(uint8_t *mac);
/**
* @function_name: iot_app_save_mac_to_pib.
* @brief : save mac address to pib.
* @param[in] mac:mac address to be save, big endian.
* @return success: 0, failed: others .
**/
uint8_t iot_app_save_mac_to_pib(uint8_t *mac);
/**
* @function_name: iot_app_get_uart_cfg_in_pib.
* @brief : get uart config setting from pib.
* @param[out] uart_param:uart config param setting.
* @return success: 0, failed: others .
**/
uint8_t iot_app_get_uart_cfg_in_pib(uart_cfg_t *uart_param);
/**
* @function_name: iot_app_save_uart_cfg_to_pib.
* @brief : save uart config to pib.
* @param[in] uart_param:uart config param setting.
* @return success: 0, failed: others .
**/
uint8_t iot_app_save_uart_cfg_to_pib(uart_cfg_t *uart_param);
#ifdef __cplusplus
}
#endif
#endif /* IOT_APP_PIB_API_H */