435 lines
12 KiB
C
435 lines
12 KiB
C
|
/****************************************************************************
|
||
|
|
||
|
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 CVG_SEC_WL_H
|
||
|
#define CVG_SEC_WL_H
|
||
|
|
||
|
/* os shim includes */
|
||
|
#include "os_types.h"
|
||
|
#include "os_lock.h"
|
||
|
|
||
|
/* cvg module internal includes */
|
||
|
#include "cvg.h"
|
||
|
|
||
|
/* public api includes */
|
||
|
#include "plc_utils.h"
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
#if PLC_SUPPORT_CCO_ROLE
|
||
|
|
||
|
#if RUN_IN_PSRAM
|
||
|
/* max white list entry count */
|
||
|
#define CVG_SEC_WL_ENT_MAX (2048)
|
||
|
/* max black list entry count */
|
||
|
#define CVG_SEC_BL_ENT_MAX (128)
|
||
|
/* white_black list table size */
|
||
|
#define CVG_SEC_WBL_TAB_SIZE (512)
|
||
|
#else /* RUN_IN_PSRAM */
|
||
|
/* max white list entry count */
|
||
|
#define CVG_SEC_WL_ENT_MAX (PLC_NETWORK_SCALE)
|
||
|
/* max black list entry count */
|
||
|
#define CVG_SEC_BL_ENT_MAX (16)
|
||
|
/* white_black list table size */
|
||
|
#define CVG_SEC_WBL_TAB_SIZE (32)
|
||
|
#endif /* RUN_IN_PSRAM */
|
||
|
|
||
|
#else /* PLC_SUPPORT_CCO_ROLE */
|
||
|
|
||
|
/* max white list entry count */
|
||
|
#define CVG_SEC_WL_ENT_MAX (16)
|
||
|
/* max black list entry count */
|
||
|
#define CVG_SEC_BL_ENT_MAX (16)
|
||
|
|
||
|
/* white_black list table size */
|
||
|
#define CVG_SEC_WBL_TAB_SIZE (32)
|
||
|
|
||
|
#endif /* PLC_SUPPORT_CCO_ROLE */
|
||
|
|
||
|
/* white list entry */
|
||
|
#pragma pack(push)
|
||
|
#pragma pack(1)
|
||
|
typedef struct _cvg_sec_wbl_ent {
|
||
|
struct _cvg_sec_wbl_ent *next;
|
||
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
||
|
/* add element is bl or wl. bit0=1 is wl,
|
||
|
* bit0 = 0 is bl. default is bit0=0(bl)*/
|
||
|
uint8_t bw :1,
|
||
|
/* flag to mark if support freq band id 2 */
|
||
|
band2 :1,
|
||
|
/* flag to mark if support rf device */
|
||
|
support_rf :1,
|
||
|
/* the power line phase of sta device working */
|
||
|
phase :2,
|
||
|
/* reserved for future */
|
||
|
rsvd :3;
|
||
|
} cvg_sec_wbl_ent_t;
|
||
|
#pragma pack(pop)
|
||
|
|
||
|
/* white list table */
|
||
|
typedef struct _cvg_sec_wbl_tab {
|
||
|
/* white list count */
|
||
|
uint32_t wl_cnt;
|
||
|
/* next free slot */
|
||
|
uint32_t wl_next_slot;
|
||
|
/* black list count */
|
||
|
uint32_t bl_cnt;
|
||
|
/* white list support freq band id 2 count */
|
||
|
uint32_t wl_band2_cnt;
|
||
|
/* white list support rf device count */
|
||
|
uint32_t wl_support_rf_cnt;
|
||
|
/* next free slot */
|
||
|
uint32_t bl_next_slot;
|
||
|
/* entry point for each mac address hash index */
|
||
|
cvg_sec_wbl_ent_t *hash_ent[CVG_SEC_WBL_TAB_SIZE];
|
||
|
/* wl entry allocation */
|
||
|
cvg_sec_wbl_ent_t wl_entry[CVG_SEC_WL_ENT_MAX];
|
||
|
/* bl entry allocation */
|
||
|
cvg_sec_wbl_ent_t bl_entry[CVG_SEC_BL_ENT_MAX];
|
||
|
} cvg_sec_wbl_tab_t;
|
||
|
|
||
|
#if (PLC_SUPPORT_WHITE_BLACK_LIST)
|
||
|
|
||
|
/* cvg_sec_wbl_init - init while_black list table
|
||
|
* @table pointer of pointer to white_black list table
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint32_t cvg_sec_wbl_init(cvg_sec_wbl_tab_t **table);
|
||
|
|
||
|
/* cvg_sec_wbl_deinit - deinit while_black list table
|
||
|
* @table - pointer to white_black list table
|
||
|
*/
|
||
|
void cvg_sec_wbl_deinit(cvg_sec_wbl_tab_t *table);
|
||
|
|
||
|
/* cvg_sec_wl_add - add mac address into while list table
|
||
|
* @table pointer to white list table
|
||
|
* @cnt number of mac address to be added
|
||
|
* @addr mac address array
|
||
|
* @phase power line phase of sta device working
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint32_t cvg_sec_wl_add(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN], uint8_t phase);
|
||
|
|
||
|
/* cvg_sec_bl_add - add mac address into black list table
|
||
|
* @table pointer to black list table
|
||
|
* @cnt number of mac address to be added
|
||
|
* @addr mac address array
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint32_t cvg_sec_bl_add(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN]);
|
||
|
|
||
|
/* cvg_sec_wl_remove - remove mac address from while list table
|
||
|
* @table pointer to white list table
|
||
|
* @cnt number of mac address to be removed
|
||
|
* @addr mac address array
|
||
|
*/
|
||
|
void cvg_sec_wl_remove(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN]);
|
||
|
|
||
|
/* cvg_sec_wl_clear - clear mac address from while list table
|
||
|
* @table pointer to white list table
|
||
|
*/
|
||
|
void cvg_sec_wl_clear(cvg_sec_wbl_tab_t *table);
|
||
|
|
||
|
/* cvg_sec_bl_remove - remove mac address from black list table
|
||
|
* @table pointer to black list table
|
||
|
* @cnt number of mac address to be removed
|
||
|
* @addr mac address array
|
||
|
*/
|
||
|
void cvg_sec_bl_remove(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN]);
|
||
|
|
||
|
/* cvg_sec_bl_clear - clear mac address from black list table
|
||
|
* @table pointer to black list table
|
||
|
*/
|
||
|
void cvg_sec_bl_clear(cvg_sec_wbl_tab_t *table);
|
||
|
|
||
|
/* cvg_sec_wl_query - query mac address from while list table
|
||
|
* @table pointer to white list table
|
||
|
* @start start index to be queried
|
||
|
* @cnt number of mac address to be queried.
|
||
|
* this will be set to number of queried mac addres for return.
|
||
|
* @addr queried mac address array for return
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint32_t cvg_sec_wl_query(cvg_sec_wbl_tab_t *table, uint32_t start,
|
||
|
uint32_t *cnt, uint8_t addr[][IOT_MAC_ADDR_LEN]);
|
||
|
|
||
|
/* cvg_sec_wl_ext_query - query whitelist extended information
|
||
|
* @table pointer to white list table
|
||
|
* @start start index to be queried
|
||
|
* @cnt number of whitelist to be queried.
|
||
|
* this will be set to number of queried whitelist for return.
|
||
|
* @wl queried whitelist array for return
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint32_t cvg_sec_wl_ext_query(cvg_sec_wbl_tab_t *table, uint32_t start,
|
||
|
uint32_t *cnt, iot_plc_wl_ext_t wl[]);
|
||
|
|
||
|
/* cvg_sec_bl_query - query mac address from black list table
|
||
|
* @table pointer to black list table
|
||
|
* @start start index to be queried
|
||
|
* @cnt number of mac address to be queried.
|
||
|
* this will be set to number of queried mac addres for return.
|
||
|
* @addr queried mac address array for return
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint32_t cvg_sec_bl_query(cvg_sec_wbl_tab_t *table, uint32_t start,
|
||
|
uint32_t *cnt, uint8_t addr[][IOT_MAC_ADDR_LEN]);
|
||
|
|
||
|
/* cvg_sec_wbl_is_exist - check if mac address exist in
|
||
|
* the while_black list table
|
||
|
* @table pointer to white_black list table
|
||
|
* @addr mac address to be checked
|
||
|
* @wb 1: white list, 0: black list
|
||
|
* @phase pointer to whitelist phase
|
||
|
*
|
||
|
* return:
|
||
|
* true -- exist
|
||
|
* false -- not exist
|
||
|
*/
|
||
|
bool_t cvg_sec_wbl_is_exist(cvg_sec_wbl_tab_t *table, uint8_t *addr, bool_t wb,
|
||
|
uint8_t *phase);
|
||
|
|
||
|
/* cvg_sec_wl_band2_flag_set - set band2 flag into while list table
|
||
|
* @table pointer to white list table
|
||
|
* @addr mac address
|
||
|
* @band2_flag flag to mark if support freq band id 2
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint8_t cvg_sec_wl_band2_flag_set(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t band2_flag);
|
||
|
|
||
|
/* cvg_sec_wl_band2_flag_get - get band2 flag from while list table
|
||
|
* @table pointer to white list table
|
||
|
* @addr mac address
|
||
|
* @band2_flag flag to mark if support freq band id 2
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint8_t cvg_sec_wl_band2_flag_get(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t *band2_flag);
|
||
|
|
||
|
/* cvg_sec_wl_support_rf_set - set to support rf flag into while list table
|
||
|
* @table pointer to white list table
|
||
|
* @addr mac address
|
||
|
* @support_rf flag to mark if support rf device
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint8_t cvg_sec_wl_support_rf_set(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t support_rf);
|
||
|
|
||
|
/* cvg_sec_wl_support_rf_get - get support rf flag from while list table
|
||
|
* @table pointer to white list table
|
||
|
* @addr mac address
|
||
|
* @support_rf flag to mark if support rf device
|
||
|
*
|
||
|
* return:
|
||
|
* 0 -- for success case
|
||
|
* otherwise -- error code
|
||
|
*/
|
||
|
uint8_t cvg_sec_wl_support_rf_get(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t *support_rf);
|
||
|
|
||
|
/* cvg_sec_wl_phase_get - get sta phase from while list table
|
||
|
* @param vdev: pointer to cvg vdev
|
||
|
* @param addr: mac address to be checked
|
||
|
*
|
||
|
* return:
|
||
|
* phase info, see PLC_PHASE_XXX.
|
||
|
*/
|
||
|
uint8_t cvg_sec_wl_phase_get(cvg_sec_wbl_tab_t *table, uint8_t *addr);
|
||
|
|
||
|
#else /* PLC_SUPPORT_WHITE_BLACK_LIST */
|
||
|
|
||
|
#define cvg_sec_wbl_init(table) (0)
|
||
|
|
||
|
#define cvg_sec_wbl_deinit(table)
|
||
|
|
||
|
static inline uint32_t cvg_sec_wl_add(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN], uint8_t phase)
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)cnt;
|
||
|
(void)addr;
|
||
|
(void)phase;
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
static inline uint32_t cvg_sec_bl_add(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN])
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)cnt;
|
||
|
(void)addr;
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
static inline void cvg_sec_wl_remove(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN])
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)cnt;
|
||
|
(void)addr;
|
||
|
}
|
||
|
|
||
|
static inline void cvg_sec_wl_clear(cvg_sec_wbl_tab_t *table)
|
||
|
{
|
||
|
(void)table;
|
||
|
}
|
||
|
|
||
|
static inline void cvg_sec_bl_remove(cvg_sec_wbl_tab_t *table, uint32_t cnt,
|
||
|
uint8_t addr[][IOT_MAC_ADDR_LEN])
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)cnt;
|
||
|
(void)addr;
|
||
|
}
|
||
|
|
||
|
static inline void cvg_sec_bl_clear(cvg_sec_wbl_tab_t *table)
|
||
|
{
|
||
|
(void)table;
|
||
|
}
|
||
|
|
||
|
static inline uint32_t cvg_sec_wl_query(cvg_sec_wbl_tab_t *table,
|
||
|
uint32_t start, uint32_t *cnt, uint8_t addr[][IOT_MAC_ADDR_LEN])
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)start;
|
||
|
(void)addr;
|
||
|
*cnt = 0;
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
static inline uint32_t cvg_sec_wl_ext_query(cvg_sec_wbl_tab_t *table,
|
||
|
uint32_t start, uint32_t *cnt, iot_plc_wl_ext_t wl[])
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)start;
|
||
|
(void)wl;
|
||
|
*cnt = 0;
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
static inline uint32_t cvg_sec_bl_query(cvg_sec_wbl_tab_t *table,
|
||
|
uint32_t start, uint32_t *cnt, uint8_t addr[][IOT_MAC_ADDR_LEN])
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)start;
|
||
|
(void)addr;
|
||
|
*cnt = 0;
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
static inline bool_t cvg_sec_wbl_is_exist(cvg_sec_wbl_tab_t *table,
|
||
|
uint8_t *addr, bool_t wb, uint8_t *phase)
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)addr;
|
||
|
(void)phase;
|
||
|
|
||
|
if(wb)
|
||
|
return true;
|
||
|
else
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
uint8_t cvg_sec_wl_band2_flag_set(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t band2_flag)
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)addr;
|
||
|
(void)band2_flag;
|
||
|
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
uint8_t cvg_sec_wl_band2_flag_get(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t *band2_flag)
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)addr;
|
||
|
(void)band2_flag;
|
||
|
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
uint8_t cvg_sec_wl_support_rf_set(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t support_rf)
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)addr;
|
||
|
(void)support_rf;
|
||
|
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
uint8_t cvg_sec_wl_support_rf_get(cvg_sec_wbl_tab_t *table, uint8_t *addr,
|
||
|
uint8_t *support_rf)
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)addr;
|
||
|
(void)support_rf;
|
||
|
|
||
|
return ERR_NOSUPP;
|
||
|
}
|
||
|
|
||
|
uint8_t cvg_sec_wl_phase_get(cvg_sec_wbl_tab_t *table, uint8_t *addr)
|
||
|
{
|
||
|
(void)table;
|
||
|
(void)addr;
|
||
|
|
||
|
return PLC_PHASE_ALL;
|
||
|
}
|
||
|
|
||
|
#endif /* PLC_SUPPORT_WHITE_BLACK_LIST */
|
||
|
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif /* CVG_SEC_WL_H */
|