Files
kunlun/plc/cvg/nwm/inc/cvg_nwm_internal.h
2024-09-28 14:24:04 +08:00

1812 lines
73 KiB
C
Executable File

/****************************************************************************
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_NWM_INTERNAL_H
#define CVG_NWM_INTERNAL_H
/* plc const includes */
#include "plc_const.h"
/* os shim includes */
#include "os_types_api.h"
#include "os_timer.h"
/* common includes */
#include "iot_errno.h"
#include "iot_pkt_api.h"
#include "iot_config.h"
#include "iot_mtd.h"
/* public api includes */
#include "plc_fr.h"
#include "plc_protocol.h"
#include "plc_mme.h"
#include "plc_rf_scan_tbl.h"
/* cvg module internal includes */
#include "cvg.h"
#include "cvg_prm.h"
#include "cvg_beacon_sg.h"
#include "cvg_beacon_spg.h"
/* mac layer includes */
#include "mac_data_api.h"
#include "mac_bcm_api.h"
#include "mac_hw_tsfm_api.h"
#ifdef __cplusplus
extern "C" {
#endif
struct _cvg_nwm_vdev;
typedef struct _cvg_nwm_vdev cvg_nwm_vdev_t;
/* define assoc request and response mme default tx retry count for each msdu */
#define CVG_NWM_ASSOC_TX_RETRY_CNT 5
/* define assoc forward mme default tx retry count for each msdu */
#define CVG_NWM_ASSOC_FWD_TX_RETRY_CNT 3
/* define proxy change request and response mme default tx retry count for each
* msdu.
*/
#define CVG_NWM_PROXY_CHG_TX_RETRY_CNT 10
/* define assoc request and response mme default tx retry count for each msdu */
#define CVG_NWM_KICK_TX_RETRY_CNT 5
/* define area notify zc ntb report mme default tx retry count for each msdu */
#define CVG_NWM_AREA_NOTIFY_TX_RETRY_CNT 2
/* define each phase collection count of zero-corss NTB area notification */
#define CVG_NWM_ZC_NOTIRY_PHASE_CLCT_CNT 85
/* define each phase collection max count of zero-corss NTB area notification */
#define CVG_NWM_ZC_NOTIFY_PHASE_CLCT_MAX 85
/* define each phase collection min count of zero-corss NTB area notification */
#define CVG_NWM_ZC_NOTIFY_PHASE_CLCT_MIN 10
/* define interval of zero-corss NTB area notification align, unit is 1 times */
#define CVG_NWM_ZC_NOTIFY_ALIGN_INTERVAL 30
/* temporary buffer size to save sub sta info */
#if PLC_SUPPORT_CCO_ROLE
#define CVG_NWM_SUB_STA_BUF_MAX \
max((8 + (((PLC_TEI_MAX_NUM >> 1) + 1) * 6)), \
max(sizeof(mac_bc_rx_desc_t), sizeof(mac_bc_rx_desc_spg_t)))
#else
#define CVG_NWM_SUB_STA_BUF_MAX \
max(((PLC_TEI_LAST + 1) * sizeof(tei_t)), \
max(sizeof(mac_bc_rx_desc_t), sizeof(mac_bc_rx_desc_spg_t)))
#endif
/* protocol conversion function returns the value according to if dual mode is
* support or not.
*/
#define CVG_NWM_RF_PROTO_CONVERT(val) (HPLC_RF_SUPPORT ? (val) : 0)
/* macro to mark if rf channel coordination is enabled */
#define CVG_NWM_CCO_RF_COD_ENABLE(nwm) \
(nwm->vdev->cert_test_detected ? 1 : nwm->desc.cco.rf_cod_enable)
/* CCO role device monitoring NID list */
#define CVG_CCO_NID_LIST_SIZE PLC_MAX_NEIGHBOR_NETWORK
/* sof frame, sent by CCO, msdu record array size for STA role device */
#define CVG_NWM_STA_CCO_REC_CNT 128
/* sof frame. sent by STA, msdu record array size for STA role device */
#define CVG_NWM_STA_STA_REC_CNT 256
#if PLC_SUPPORT_CCO_ROLE
#if RUN_IN_PSRAM
/* conn less sof frame from remote dev, msdu record array size */
#define CVG_NWM_CONN_LESS_REC_CNT 128
#else /* RUN_IN_PSRAM */
/* conn less sof frame from remote dev, msdu record array size */
#define CVG_NWM_CONN_LESS_REC_CNT 64
#endif /* RUN_IN_PSRAM */
#else /* PLC_SUPPORT_CCO_ROLE */
/* conn less sof frame from remote dev, msdu record array size */
#define CVG_NWM_CONN_LESS_REC_CNT 128
#endif /* PLC_SUPPORT_CCO_ROLE */
/* zc ntb tsfm report frame. zc collection sn record array size for STA role
* device
*/
#define CVG_NWM_STA_ZC_NTB_SN_REC_CNT 6
/* sta network peer snr level record number */
#define CVG_NWM_STA_PEER_SNR_LEVEL_REC_CNT 2
/* sta network level snr record number */
#define CVG_NWM_STA_NW_LEVEL_REC_CNT 2
/* total number of network level snr statistics. */
#define CVG_NWM_STA_NW_LEVEL_SNR_CNT (80 - SNR_LOWEST + 1)
/* snr will mapping -10 ~ 90 dB to 0 ~ 100 dB. */
#define CVG_NWM_STA_SNR_MAP_NW_LEVEL_SNR(snr) (snr - SNR_LOWEST)
/* snr will mapping 0 ~ 100 dB to -10 ~ 90 dB. */
#define CVG_NWM_STA_NW_LEVEL_SNR_MAP_SNR(snr) (snr + SNR_LOWEST)
/* network level snr convert to index */
#define CVG_NWM_STA_NW_LEVEL_SNR_TO_IDX(snr) \
(min((snr), CVG_NWM_STA_NW_LEVEL_SNR_CNT - 1))
/* index convert to network level snr */
#define CVG_NWM_STA_IDX_TO_NW_LEVEL_SNR(idx) (idx)
/* percentage of highest snr statistics collected to be used for network
* selection
*/
#define CVG_NWM_NW_LEVEL_SNR_STAT_HIGH_TH 20
/* percentage of highest cco snr statistics collected to be used for network
* selection
*/
#define CVG_NWM_NW_LEVEL_CCO_SNR_STAT_HIGH_TH 40
/* level difference threshold if two networks level has big difference */
#define CVG_NWM_NW_LEVEL_BIG_DIFF_TH 2
/* total number of rf channel statistics */
#define CVG_NWM_RF_CHANNEL_CNT 40
/* snr lowest valid threshold for tsfm, unit is 1 db */
#define CVG_NWM_LOW_SNR_VALID_TH -10
/* cco snr lowest valid threshold for tsfm, unit is 1 db. this value
* is different from CVG_NWM_LOW_SNR_VALID_TH, which is used to check if
* the CCO SNR is valid.
*/
#define CVG_NWM_CCO_LOW_SNR_VALID_TH -15
/* define the snr high threshold for disable sw agc, unit is 1 db. */
#define CVG_NWM_SW_AGC_DISABLE_HIGH_SNR_TH 16
/* define the difference threshold between the two network snr for disable
* sw agc, unit is 1 db.
*/
#define CVG_NWM_SW_AGC_DISABLE_HIGH_SNR_DIFF_TH 5
/* if the cco snr is not received in this statistical period,
* subtract a penalty value from the last statistical cco snr as the
* current statistical cco snr, unit is 1 db
*/
#define CVG_NWM_CCO_SNR_PENAL_FACTOR 1
/* define the difference threshold between the two cco snr, unit is 1 db.
* used to determine the best network for tsfm, if (CCO_SNR1 - CCO_SNR2)
* >= CVG_NWM_CCO_SNR_DIFF_TH, than CCO_SNR1 network is better.
*/
#define CVG_NWM_CCO_SNR_DIFF_TH 3
/* define the difference threshold between the two cco snr received counts,
* unit is 1 times. used to determine the best network for tsfm, if
* (CCO_SNR_CNT1 / CCO_SNR_CNT2) >= CVG_NWM_CCO_SNR_CNT_DIFF_TH,
* than CCO_SNR_CNT1 network is better.
*/
#define CVG_NWM_CCO_SNR_CNT_DIFF_TH 20
/* weight factor of received beacon snr for tsfm */
#define CVG_NWM_TSFM_SNR_BC_FACTOR 10
/* weight factor of received sof snr for tsfm */
#define CVG_NWM_TSFM_SNR_SOF_FACTOR 1
/* sta device network monitor duration for network selection & ident, unit
* is 1s
*/
#define CVG_NWM_NW_MONITOR_DUR (15 * 60)
/* sta device zc ntb tsfm duration, unit is 1s */
#define CVG_NWM_NW_ZC_MONITOR_DUR (CVG_NWM_NW_MONITOR_DUR * 2)
/* sta device tsfm startup timeout duration, unit is 1s. used to determine
* the status of tsfm enable or disable. if sta has received tsfm startup
* packet in the past, and receive timeout at this time, need to
* disable tsfm function.
*/
#define CVG_NWM_NW_TSFM_START_TIMEOUT_DUR (3 * CVG_NWM_NW_MONITOR_DUR)
/* the tsfm algorithm averaging each phase at each level. */
#define CVG_NWM_TSFM_ALGORITHM_LEVEL_PHASE_AVG 0
/* the tsfm algorithm averaging at each level, does not distinguish
* between phase.
*/
#define CVG_NWM_TSFM_ALGORITHM_LEVEL_AVG 1
/* the tsfm algorithm collect best snr peer at each level. */
#define CVG_NWM_TSFM_ALGORITHM_PEER_SNR 2
/* combination of both CVG_NWM_TSFM_ALGORITHM_LEVEL_AVG and
* CVG_NWM_TSFM_ALGORITHM_PEER_SNR algorithm. a new tranformer win
* only when both algorithm win.
*/
#define CVG_NWM_TSFM_ALGORITHM_LEVEL_PEER_SNR 3
/* the tsfm algorithm base on zc ntb delta between cco and sta. */
#define CVG_NWM_TSFM_ALGORITHM_ZC_NTB_DELTA 4
/* the tsfm algorithm base on zc correlation coefficient between cco and sta. */
#define CVG_NWM_TSFM_ALGORITHM_ZC_NTB_CORREL 5
/* define transformer switch count */
#define PLC_TSFM_SWITCH_MAX \
((iot_oem_get_user_type() == USER_TYPE_STATE_GRID_BJ) ? 8 : 7)
/* transformer history depth */
#define PLC_TSFM_HISTORY_SIZE (8)
/* define cco to send zero-cross NTB area notification interval, unit is 1s */
#define CVG_NWM_ZC_NOTIFY_INTERVAL (2 * 60)
/* define zc ntb difference array size in a statistical period */
#define CVG_NWM_ZC_NTB_ONE_PERIOD_STAT_CNT (8)
/* define zc ntb difference historical statistic array size */
#define CVG_NWM_ZC_NTB_HIS_STAT_CNT (3)
/* define the zc ntb delta mininum detection threshold between the cco and sta
* unit is 100 ntb.
*/
#define CVG_NWM_ZC_NTB_DELTA_MIN_DETECT_TH (25)
/* define the zc ntb delta variance mininum detection threshold between the
* cco and sta, unit is 1 times.
*/
#define CVG_NWM_ZC_NTB_DELTA_VAR_MIN_DETECT_TH (50)
/* define the zc ntb delta variance maxinum detection threshold between the
* cco and sta, unit is 1 times.
*/
#define CVG_NWM_ZC_NTB_DELTA_VAR_MAX_DETECT_TH (60)
/* define the zc ntb period delta variance mininum detection threshold between
* the cco and sta, unit is 1 times.
*/
#define CVG_NWM_ZC_PERIOD_VAR_MIN_DETECT_TH (2)
/* define the zc ntb period delta variance maxinum detection threshold between
* the cco and sta, unit is 1 times.
*/
#define CVG_NWM_ZC_PERIOD_VAR_MAX_DETECT_TH (4)
/* define the zc ntb period correlation coefficient high score threshold */
#define CVG_NWM_ZC_PERIOD_CORREL_H_SCORE_TH (247)
/* define the zc ntb period correlation coefficient medium score threshold */
#define CVG_NWM_ZC_PERIOD_CORREL_M_SCORE_TH (240)
/* define the zc ntb period correlation coefficient difference score threshold
*/
#define CVG_NWM_ZC_PERIOD_CORREL_DIFF_SCORE_1_TH (5)
/* define the zc ntb period correlation coefficient difference score threshold
*/
#define CVG_NWM_ZC_PERIOD_CORREL_DIFF_SCORE_2_TH (9)
/* define the zc ntb period correlation coefficient difference score threshold
*/
#define CVG_NWM_ZC_PERIOD_CORREL_DIFF_SCORE_3_TH (15)
/* count of highest zc ntb delta historical statistics to be used for tsfm */
#define CVG_NWM_NW_ZC_NTB_STAT_HIGH_TH 3
/* define the threshold for the count of sta device detect remote node mac is
* changed or tei is changed in one route period.
*/
#define CVG_NWM_STA_ADDR_CHG_TH 3
/* beacon rtc tx interval, unit is 1s */
#define CVG_NWM_BC_RTC_TX_INTERVAL (8)
/* delay time of leaving for joining check not pass, unit is 1ms */
#define CVG_NWM_JOIN_CHECK_LEAVING_DELAY_DUR (60 * 1000)
/* NID and PCO blacklist table size definition */
#define PLC_NID_BLIST_SIZE (PLC_MAX_NEIGHBOR_NETWORK)
#define PLC_PCO_BLIST_SIZE (10)
#define PLC_PCO_BLIST_COUNT (3)
/* number of zc ntb data buffer size */
#define CVG_CCO_ZC_NTB_BUFF_LEN (200)
/* the maximum number of vendor info records */
#define CVG_NWM_VENDOR_INFO_RECORD_NUM (30)
/* generate MSDU record */
#define CVG_NWM_GEN_MSDU_RECORD(_tei, _reboot_cnt, _sn) \
((((uint32_t)_tei & 0xFFF) << 16) | (((uint32_t)_reboot_cnt << 28)) \
| (uint32_t)_sn)
/* generate the long int mac address */
#define CVG_NWM_GEN_MAC_ADDR(_tei) \
((((uint64_t)0xFFFFFFFFF << 12)) | ((uint64_t)_tei & 0xFFF))
/* generate vendor code */
#define CVG_NWM_GEN_VENDOR_CODE(vendor_id, chip_id) \
(vendor_id << 16 | chip_id)
/* define test mode */
#define CVG_NWM_TEST_MODE_CERT 1
#define CVG_NWM_TEST_MODE_CONN_LESS 2
#define CVG_NWM_TEST_MODE_CTRL_PROTO 3
#define CVG_NWM_TEST_MODE_HW_TSFM 4
/* application layer data traffic load level */
#define CVG_NWM_APP_LOAD_LIGHT (0)
#define CVG_NWM_APP_LOAD_MEDIUM (1)
#define CVG_NWM_APP_LOAD_HEAVY (2)
#define CVG_NWM_APP_LOAD_MIN CVG_NWM_APP_LOAD_LIGHT
#define CVG_NWM_APP_LOAD_MAX CVG_NWM_APP_LOAD_HEAVY
#define CVG_NWM_APP_LOAD_DEFAULT CVG_NWM_APP_LOAD_LIGHT
/* cco vdev states */
typedef enum {
cco_state_invalid = 0,
cco_state_init,
cco_state_starting,
cco_state_started,
cco_state_testing,
/* always keep this as the last state */
cco_state_max,
} cvg_nwm_vdev_cco_state_t;
/* cco state machine function
* @nwm - nwm vdev pointer
* @event - event to be delivered
* @data - data pointer of the event
*
* return:
* next state of the vdev.
*/
typedef cvg_nwm_vdev_cco_state_t (*cvg_nwm_vdev_sm_cco_func_t)(
cvg_nwm_vdev_t *nwm, cvg_vdev_event_t event, void *data);
/* cco role device neighbor network information */
typedef struct _cvg_nwm_cco_nn_info {
/* nid of the neighbour network */
uint32_t nid :24,
/* flag indicate if neighbour network is single-pass to local network
* 1 means single-pass. 0 means double-pass.
*/
sp_flag :1,
/* flag to mark if address is available */
addr_flag :1,
/* reserved for future */
rsvd :6;
/* bandwidth taken by neighbour network in millisecond */
uint32_t bandwidth :16,
/* rf channel, see RF_CHANNEL_ID_XXX */
rf_channel :8,
/* rf option, see RF_OPTION_XXXX */
rf_option :2,
/* reserved for future */
rsvd1 :6;
/* time stamp of last time local device see this network */
uint64_t last_seen_ts;
/* cco mac address of the network */
uint8_t addr[IOT_MAC_ADDR_LEN];
} cvg_nwm_nn_cco_info_t;
/* vendor information */
typedef struct cvg_nwm_vendor_info {
/* vendor code */
uint32_t vendor_code;
/* zc edge type, 0 is rising edge, 1 is falling edge. */
uint8_t is_falling_edge :1,
/* reserved for future */
reserved :7;
} cvg_nwm_vendor_info_t;
#pragma pack(push)
#pragma pack(1)
/* conn less msdu record data structure, to filter duplicate frame */
typedef struct _cvg_nwm_msdu_rec {
/* pm mac addr */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* msdu sequence number */
uint16_t msdu_sn;
/* reboot count */
uint8_t reboot_cnt :4,
/* reserved for future */
rsvd :4;
} cvg_nwm_msdu_rec_t;
#pragma pack(pop)
/* cco state machine */
typedef struct _cvg_nwm_vdev_sm_cco {
/* previous state */
cvg_nwm_vdev_cco_state_t prev_state;
/* current state */
cvg_nwm_vdev_cco_state_t cur_state;
/* function pointer of each state */
cvg_nwm_vdev_sm_cco_func_t func[cco_state_max];
} cvg_nwm_vdev_sm_cco_t;
/* neighbor network rf information */
typedef struct _cvg_nwm_nn_rf_info {
/* time stamp of last time local device see this rf network. unit is 1s */
uint32_t last_seen_ts;
/* rf channel, see RF_CHANNEL_ID_XXX */
uint32_t rf_channel : 8,
/* rf option, see RF_OPTION_XXX */
rf_option : 2,
/* heard count of this rf channel */
heard_cnt : 22;
} cvg_nwm_nn_rf_info_t;
/* persistent info that won't be cleared when reset vdev */
typedef struct _cvg_nwm_cco_persist_info {
/* cco vdev state machine */
cvg_nwm_vdev_sm_cco_t sm;
/* number of supported physical phases. The range should be from 1 - 3.
* if set to 1, only phase A supported.
* if set to 2, both phase A and B are supported.
* if set to 3, Phase A, B and C are supported.
*/
uint8_t p_phase_cnt;
/* flag to mark if application data available */
uint8_t app_data_valid :1,
/* flag to mark if network monitor & ident enable */
nw_monitor_enable :1,
/* flag to mark if white list notification enable */
wl_notify_enable :1,
/* flag to mark if zc ntb notification enable */
zc_notify_enable :1,
/* flag to mark if fixed rate required for the local device */
is_fix_rate_local :1,
/* flag to mark if fixed rate required for the whole network */
is_fix_rate_network :1,
/* flag to mark if fast connect enabled */
fast_connect :1,
/* repeater_addr_start and repeater_addr_end are valid value */
repeater_addr_check :1;
/* application layer data traffic load level, see CVG_NWM_APP_LOAD_XXX */
uint8_t app_load;
/* application layer data traffic load changed timestamp. unit is 1s */
uint32_t app_load_chg_ts;
/* number of valid number in the list */
uint32_t nid_list_cnt;
/* heard network id list which can't be used as local network id */
cvg_nwm_nn_cco_info_t nid_list[CVG_CCO_NID_LIST_SIZE];
/* heard network rf list which can't be used as loacl network channel */
cvg_nwm_nn_rf_info_t rf_list[CVG_NWM_RF_CHANNEL_CNT];
/* application data cache */
uint8_t app_data[MAC_BC_APP_DATA_MAX];
/* vendor information record */
cvg_nwm_vendor_info_t vendor_info[CVG_NWM_VENDOR_INFO_RECORD_NUM];
/* conn less sof frame msdu record array */
cvg_nwm_msdu_rec_t cl_msdu_rec[CVG_NWM_CONN_LESS_REC_CNT];
/* lastest in use record index in cl_msdu_rec array */
uint16_t cl_msdu_rec_idx;
/* if the value is valid the repeater in the range are allowed to join
* network.
* if the value is invalid then all repeater are allowed to join network.
*
* 00:00:00:00:00:00 and FF:FF:FF:FF:FF:FF are invalid data.
*/
uint8_t repeater_addr_start[IOT_MAC_ADDR_LEN];
uint8_t repeater_addr_end[IOT_MAC_ADDR_LEN];
/* flasg mark to if app sniffer enables */
uint8_t app_sniffer_en : 1,
/* reference counter of app sniffer function */
app_sniffer_ref_cnt : 7;
/* fixed rate level, see PLC_RATE_ADAPT_RATE_XXX */
uint8_t fixed_rate_level;
/* flag to mark if allow to send rtc beacon entry */
uint8_t rtc_tx : 1,
/* flag to mark if all whitelist nodes have joined network in the past, in
* band 2
*/
fb_wl_joined_done : 1,
/* flag to mark if force link communication */
force_link_valid : 1,
/* force link type, 1 - force rf, 0 - force hplc */
force_rf_link : 1,
/* reserved for feture */
rsvd : 4;
} cvg_nwm_cco_persist_info_t;
/* cco vdev gather assoc request descriptor */
typedef struct _cvg_nwm_cco_gather_assoc_desc {
/* STA count in gather assoc request */
uint8_t sta_cnt;
/* STA info in gather assoc request */
sta_info_t sta_info[GATHER_ASSOC_REQ_CNT_MAX];
}cvg_nwm_cco_gather_assoc_desc_t;
/* cco zc collect states */
typedef enum {
/* initial status */
CCO_ZC_COLLECT_STATE_INIT = 0,
/* cco is checking if local zc data can be collected */
CCO_ZC_COLLECT_STATE_TEST = 1,
/* local zc data can't be collected */
CCO_ZC_COLLECT_STATE_ERROR = 2,
/* local zc data can be collected */
CCO_ZC_COLLECT_STATE_VALID = 3,
}cvg_nwm_cco_zc_state_t;
/* cco zero-cross collect status info */
typedef struct _cvg_nwm_cco_zc_info {
/* coo zc collect delay timestamp. unit is 1s */
uint32_t delay_ts;
/* save last cco collect STA tei */
tei_t prev_tei;
/* zero-corss collect task sequence number */
uint8_t task_sn;
/* cco zc collect enable flag */
uint8_t enable :1,
/* cco zc collect state. see CCO_ZC_COLLECT_STATE_XXX */
state :2,
/* cco physcial phase count */
phase_cnt :2,
/* flag to mark if cco support association request pkt carry zc ntb */
assoc_req_ntb_enable :1,
/* reserved for future */
rsvd :1,
/* flag to mark if cco hardware is 6 way zero-crossing */
zc_6_flag :1;
/* flag to mark if the 3phase device have the repeat zc */
uint8_t zc_repeat_3p :1,
/* the counter of zc sending time align */
zc_align_cnt :7;
/* record the sn of zc status report */
uint8_t zc_status_sn;
#if PLC_SUPPORT_PHY_PHASE_IDENT
/* temporary variables used to save the zero-cross data */
uint32_t temp[CVG_CCO_ZC_NTB_BUFF_LEN];
#endif
} cvg_nwm_cco_zc_info_t;
/* temporary variables used to save the zero-cross data */
typedef struct _cvg_nwm_cco_zc_temp {
/* cco zero-cross ntb data */
uint32_t cco_ntb[PLC_PHASE_CNT][CVG_CCO_ZC_NTB_BUFF_LEN];
/* cco zero-cross ntb data count */
uint32_t cco_ntb_cnt[PLC_PHASE_CNT];
/* sta zero-cross ntb data */
uint32_t sta_ntb[CVG_CCO_ZC_NTB_BUFF_LEN];
/* sta zero-cross ntb data count */
uint32_t sta_ntb_cnt;
} cvg_nwm_cco_zc_temp_t;
/* cco freq band detection tx states */
typedef enum {
/* initial status */
CVG_NWM_CCO_FB_DETECT_TX_STATE_INIT,
/* send fb detection beacon status */
CVG_NWM_CCO_FB_DETECT_TX_STATE_ENABLE,
/* do not send fb detection beacon status */
CVG_NWM_CCO_FB_DETECT_TX_STATE_DISABLE
} cvg_nwm_cco_fb_detect_tx_state_t;
/* cco vdev only descriptor */
typedef struct _cvg_nwm_vdev_cco {
/* persistent info that shall not be clear when reset vdev */
cvg_nwm_cco_persist_info_t pst_info;
/* timer for network conflict listening for starting/started case */
timer_id_t sl_timer;
/* timer for rf conflict listening for starting/started case */
timer_id_t rf_sl_timer;
/* timer for assoc request gather for level 1 sta */
timer_id_t gather_timer;
/* timer for rf assoc request gather for level 1 sta */
timer_id_t rf_gather_timer;
/* timer for zero-cross NTB area notification timer */
timer_id_t zc_notify_timer;
/* path number */
uint32_t path_number;
/* beacon frame control field for beacon update plcace holder */
mac_bc_fc_t fc_temp;
/* beacon fixed entry for beacon update plcace holder */
union {
mac_bc_fp_spg_t fp_spg;
mac_bc_fp_t fp_sg;
} fp_temp;
/* beacon station capability entry for beacon update plcace holder */
union {
mac_bc_sta_cap_spg_t cap_spg;
mac_bc_sta_cap_t cap_sg;
} cap_temp;
/* temporary buffer to save beacon parse result */
union {
/* descriptor used for SG protocol */
mac_bc_rx_desc_t *bc_temp;
/* descriptor used for SPG protocol */
mac_bc_rx_desc_spg_t *spg_bc_temp;
};
/* number of peers in the network for previous route period */
uint32_t prev_peer_cnt;
/* number of consecutive route period that number of peers in the network
* not grow up.
*/
uint8_t scale_fix_cnt;
/* allowed to cco traffic success ratio. the unit is 1%. */
uint8_t allowed_cco_tf_sr;
/* number of full route period sta need to spend on tr_sf calc. the unit
* is 1 route period.
*/
uint8_t proxy_select_dur;
/* counter for leaving peers clean up. count down for each beacon period */
uint8_t leaving_peer_cd;
/* counter for sta reported nid conflict status clean up. count down for
* each beacon period. uint is 1s.
*/
uint32_t sta_rpt_nid_conflict_cd;
/* counter for rf conflict status clean up. count down for
* each beacon period. uint is 1s.
*/
uint32_t rf_conflict_cd;
/* time stamp of the first nid conflict report from sta, uint is 1s */
uint32_t sta_rpt_nid_conflict_ts;
/* time stamp of the first rf conflict report , uint is 1s */
uint32_t rf_conflict_ts;
/* interval that sta should report calculated tsfm detection data to
* cco. unit is 1s.
*/
uint16_t rpt_tsfm_dur;
/* interval that sta should do tsfm detection check to unit is 1s. */
uint16_t check_tsfm_dur;
/* flag to mark if network hplc tx power cap is valid */
uint8_t nw_power_valid :1,
/* flag to mark if the tsfm is valid */
tsfm_valid :1,
/* flag to mark if PCO should report SNR with it's direct sub STA
* periodically.
*/
pco_snr_rpt :1,
/* algorithm to be used for transformer detection */
tsfm_algorithm :4,
/* flag to mark if network rf tx power cap is valid */
nw_rf_power_valid :1;
/* flag to mark if tsfm cco direct network detection enable */
uint8_t tsfm_cco_detect_en :1,
/* flag to mark if whole network formation done */
network_fmt_done :1,
/* flag to mark if whole network route learning done */
route_learn_done :1,
/* flag to mark if cco device test is detected */
cco_test_detected :1,
/* flag to mark if allow auto high power if detected connected hotline */
hot_high_power_en :1,
/* flag to mark if zc ntb notification enable */
zc_notify_enable :1,
/* flag to mark if all whitelist nodes have joined network */
wl_joined_done :1,
/* flag to mark if enable uplink traffic succeed ratio check */
uplink_check_en :1;
/* time stamp of the freq band detection changed, unit is 1s */
uint32_t fb_detect_chg_ts;
/* freq band detection tx state. see CVG_NWM_CCO_FB_DETECT_TX_STATE_XXX */
cvg_nwm_cco_fb_detect_tx_state_t fb_detect_tx_state;
/* flag to mark if enable freq band detection */
uint8_t fb_detect_enable :1,
/* flag to mark if allow to start freq band detection */
fb_detect_allowed :1,
/* flag to mark if allow to send freq band detection beacon */
fb_detect_tx_valid :1,
/* flag to mark if the first round of freq band detection has been completed
*/
fb_detect_first_done:1,
/* flag to mark if detected production testing */
pt_detected :1,
/* flag to mark if force phase tx is enabled */
force_phase_en :1,
/* flag to mark if beacon vendor entry is valid */
bc_vendor_valid :1,
/* flag to mark if rf channel coordination is enabled, default is enabled */
rf_cod_enable :1;
/* conn less mr only */
uint8_t rf_tx_only_conn :1,
/* reserved for future */
rsvd :7;
/* hplc network tx power cap. unit is 1 dbuv */
uint8_t nw_tx_power_cap;
/* rf network tx power cap. unit is 1 dbm */
int8_t nw_rf_tx_power_cap;
/* percentage of highest snr statistics collected to be used for tsfm */
uint8_t tsfm_snr_stat_high_th;
/* lowest valid snr threshold for tsfm, unit is 1 db */
int8_t tsfm_low_snr_th;
/* cco lowest valid snr threshold for tsfm, unit is 1 db */
int8_t tsfm_cco_low_snr_th;
/* penalty value if no cco snr was received in this statistical period,
* unit is 1 db
*/
uint8_t tsfm_cco_snr_penal;
/* snr difference threshold if two networks level is same, unit is 1 db */
uint8_t tsfm_snr_diff_th1;
/* snr difference threshold if two networks level is same, unit is 1 db */
uint8_t tsfm_snr_diff_th2;
/* level difference threshold if two networks level has big difference */
uint8_t tsfm_level_big_diff_th;
/* cco difference threshold if two networks level is same, unit is 1 db */
uint8_t tsfm_cco_diff_th1;
/* cco difference threshold if two networks level is same, unit is 1 times
*/
uint8_t tsfm_cco_diff_th2;
/* weight factor of received beacon snr for tsfm */
uint8_t tsfm_snr_bc_factor;
/* weight factor of received sof snr for tsfm */
uint8_t tsfm_snr_sof_factor;
/* zc ntb delta threshold for tsfm, unit is 100 ntb */
uint8_t tsfm_zc_diff_th1;
/* zc ntb delta variance threshold for tsfm, unit is 1 times */
uint8_t tsfm_zc_diff_th2;
/* zc period delta variance threshold for tsfm, unit is 1 times */
uint8_t tsfm_zc_diff_th3;
/* zc ntb delta threshold for tsfm, unit is 1 times or 100 ntb */
uint8_t tsfm_zc_diff_th4;
/* assoc done flag count, if no assoc ongoing for N concesutive beacon
* periods, set assoc done flag in beacon to 1.
*/
uint8_t assoc_done_cnt;
/* nid conflict detection count */
uint8_t nid_conflict_cnt;
/* rf conflict detection count */
uint8_t rf_conflict_cnt;
/* beacon period end alert count */
uint8_t bp_alert_cnt;
/* last beacon period end alert check stamp. unit is 1s */
uint32_t last_bp_check_ts;
/* last assoc time stamp. unit is 1s */
uint32_t last_assoc_ts;
/* network formation done time stamp. unit is 1s */
uint32_t fmt_done_ts;
/* number of heart beat period we spent. */
uint32_t hb_spent;
/* last rtc beacon tx timestamp, unit is 1s */
uint32_t rtc_tx_last_ts;
/* cco zero-cross collect status info */
cvg_nwm_cco_zc_info_t zc_info;
/* temporary variables used to save the zero-cross data */
cvg_nwm_cco_zc_temp_t *zc_temp;
/* temporary buffer to save gather assoc request info */
cvg_nwm_cco_gather_assoc_desc_t *gather_assoc_temp;
/* temporary buffer to save rf gather assoc request info */
cvg_nwm_cco_gather_assoc_desc_t *rf_gather_assoc_temp;
/* bitmap to mark abnormal sta device */
cvg_tei_map_t *sta_abnormal;
} cvg_nwm_vdev_cco_t;
/* sta vdev states */
typedef enum {
sta_state_invalid = 0,
sta_state_init,
sta_state_started, /* started but unassociated. network selecting */
sta_state_selecting, /* proxy selecting */
sta_state_associating, /* associating to network */
sta_state_associated, /* associated with network */
sta_state_leaving, /* leaving the network */
sta_state_testing, /* in test */
/* always keep this as the last state */
sta_state_max,
} cvg_nwm_vdev_sta_state_t;
/* sta state machine function
* @nwm - nwm vdev pointer
* @event - event to be delivered
* @data - data pointer of the event
*
* return:
* next state of the vdev.
*/
typedef cvg_nwm_vdev_sta_state_t (*cvg_nwm_vdev_sm_sta_func_t)(
cvg_nwm_vdev_t *nwm, cvg_vdev_event_t event, void *data);
/* sta state machine */
typedef struct _cvg_nwm_vdev_sm_sta {
/* previous state */
cvg_nwm_vdev_sta_state_t prev_state;
/* current state */
cvg_nwm_vdev_sta_state_t cur_state;
/* function pointer of each state */
cvg_nwm_vdev_sm_sta_func_t func[sta_state_max];
} cvg_nwm_vdev_sm_sta_t;
/* define count of peer snr list 1 for tsfm, each network level needs
* to save 3 lists.
*/
#define CVG_NWM_STA_PEER_SNR_LIST1_CNT 10
/* define count of peer snr list 2 for tsfm, each network level needs
* to save 3 lists.
*/
#define CVG_NWM_STA_PEER_SNR_LIST2_CNT 5
/* define count of peer snr list 3 for tsfm, each network level needs
* to save 3 lists.
*/
#define CVG_NWM_STA_PEER_SNR_LIST3_CNT 3
/* define max received count in peer snr list1 for tsfm */
#define CVG_NWM_STA_PEER_SNR_LIST1_SNR_CNT_MAX 10
/* define max received count in peer snr list2 for tsfm */
#define CVG_NWM_STA_PEER_SNR_LIST2_SNR_CNT_MAX 20
/* sta network peer snr info */
typedef struct _cvg_nwm_sta_peer_snr {
/* peer mac address */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* average snr, unit is (1 db >> 8) */
int16_t avg_snr;
/* received count */
uint16_t cnt;
} cvg_nwm_sta_peer_snr_t;
/* sta network peer snr statistic info */
typedef struct _cvg_nwm_sta_peer_snr_stat {
/* level */
uint8_t level;
/* received count of list1 */
cvg_nwm_sta_peer_snr_t peer_snr_list1[CVG_NWM_STA_PEER_SNR_LIST1_CNT];
/* received count of list2 */
cvg_nwm_sta_peer_snr_t peer_snr_list2[CVG_NWM_STA_PEER_SNR_LIST2_CNT];
/* received count of list3 */
cvg_nwm_sta_peer_snr_t peer_snr_list3[CVG_NWM_STA_PEER_SNR_LIST3_CNT];
} cvg_nwm_sta_peer_snr_stat_t;
/* sta network level snr statistic info */
typedef struct _cvg_nwm_sta_nw_level_snr_stat {
/* level */
uint8_t level;
/* received packet count of each phase and each snr threshold */
uint16_t snr_cnt[CVG_NWM_STA_NW_LEVEL_SNR_CNT];
} cvg_nwm_sta_nw_level_snr_stat_t;
/* candidate best snr tsfm network info */
typedef struct _cvg_nwm_sta_cand_tsfm_info {
/* nid */
uint32_t nid;
/* level */
uint8_t level;
/* snr */
int8_t snr;
} cvg_nwm_sta_cand_tsfm_info_t;
/* sta zc ntb difference statistics */
typedef struct _cvg_nwm_sta_zc_ntb_diff {
/* zc ntb delta variance of the historical statistics */
uint32_t ntb_delta_var_his[CVG_NWM_ZC_NTB_HIS_STAT_CNT];
/* zc ntb delta average of the historical statistics, unit is NTB */
int32_t ntb_delta_avg_his[CVG_NWM_ZC_NTB_HIS_STAT_CNT];
/* zc ntb delta array of current statistical period, unit is NTB */
int32_t ntb_delta[PLC_PHASE_CNT][CVG_NWM_ZC_NTB_ONE_PERIOD_STAT_CNT];
/* zc period delta variance array of current statistical period */
uint8_t period_delta_var[PLC_PHASE_CNT][
CVG_NWM_ZC_NTB_ONE_PERIOD_STAT_CNT];
/* zc period delta variance average of the historical statistics */
uint8_t period_delta_var_his[CVG_NWM_ZC_NTB_HIS_STAT_CNT];
/* count of the zc ntb delta historical statistics */
uint8_t ntb_delta_his_cnt;
/* zc ntb delta count of current statistical period */
uint8_t ntb_delta_cnt;
} cvg_nwm_sta_zc_ntb_diff_t;
/* sta role device network information */
typedef struct _cvg_nwm_sta_nw_info {
/* network id */
uint32_t nid :24,
/* flag to mark if beacon data is available */
beacon_data_valid :1,
/* flag to mark if cco mac address is available */
addr_valid :1,
/* flag to mark if network sn is available */
network_sn_valid :1,
/* lastest in use record index in the zc_tsfm_sn_rec array */
zc_tsfm_sn_rec_idx :3,
/* rf option, see RF_OPTION_XXXX */
rf_option :2;
/* timestamp that received the last packet from the network. unit is 1s */
uint32_t last_seen_ts;
/* timestamp that received the first packet from the network. unit is 1s */
uint32_t first_seen_ts;
/* flag to mark if ntb tsfm packet has been received from the network. */
uint8_t rx_ntb_tsfm_flag :1,
/* reserved for future */
rsvd :7;
/* hplc link beacon snr statistics of each phase */
int8_t snr[PLC_PHASE_CNT];
/* hplc link cco snr of last statistic period */
int8_t cco_snr;
/* rf link snr statistics */
int8_t rf_snr;
/* rf link rssi statistics */
int8_t rf_rssi;
/* beacon data info */
uint8_t beacon_data[MAC_BC_APP_DATA_MAX];
/* cco mac address */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* transformer mac address */
uint8_t tsfm_addr[IOT_MAC_ADDR_LEN];
/* network sn */
uint8_t network_sn;
/* rf channel, see RF_CHANNEL_ID_XXX */
uint8_t rf_channel;
/* hplc band id, see BEACON_FREQ_BAND_ID_XXX */
uint8_t band_id;
/* zero-corss collect tsfm task sequence number record array */
uint16_t zc_tsfm_sn_rec[CVG_NWM_STA_ZC_NTB_SN_REC_CNT];
/* iot pkt to cache the network beacon during network selection stage */
iot_pkt_t *bc_cache;
/* iot pkt to cache the network level snr statistic info */
iot_pkt_t *level_snr_buf[CVG_NWM_STA_NW_LEVEL_REC_CNT];
/* iot pkt to cache the network peer snr statistic info */
iot_pkt_t *peer_snr_buf[CVG_NWM_STA_PEER_SNR_LEVEL_REC_CNT];
/* iot pkt to cache the network zero-cross ntb difference statistic info */
iot_pkt_t *zc_ntb_diff_buf;
} cvg_nwm_sta_nw_info_t;
typedef struct _cvg_nwm_pco_blist {
uint32_t nid;
tei_t pco[PLC_PCO_BLIST_SIZE];
/* each pco add in pco blacklist timestamp. unit is 1s */
uint32_t pco_timestamp[PLC_PCO_BLIST_SIZE];
} cvg_nwm_pco_blist;
typedef struct _cvg_nwm_nid_blist {
/* network id */
uint32_t nid :24,
/* flag to mark if network sn is available */
network_sn_valid :1,
/* flag to mark if nid is enabled in blacklist */
enable :1,
/* record the number of additions */
cnt :4,
/* flag to mark if the nid blist need to be cleared quickly */
clear_quick :1,
/* reserved for future */
rsvd :1;
/* each nid add in blacklist timestamp. unit is 1s */
uint32_t timestamp;
/* each nid add in blacklist network sequence */
uint8_t network_sn;
} cvg_nwm_nid_blist;
/* best nid historical info */
typedef struct _cvg_nwm_best_nid_info {
/* network id */
uint32_t nid :24,
/* occurrence number of nid */
cnt :8;
} cvg_nwm_best_nid_info_t;
typedef struct _cvg_nwm_tsfm_history {
/* network id */
uint32_t nid :24,
/* reserved for future */
rsvd :8;
/* how many times this network win in tsfm check */
uint32_t win_cnt;
/* cco mac address */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* transformer mac address */
uint8_t tsfm_addr[IOT_MAC_ADDR_LEN];
} cvg_nwm_tsfm_history_t;
typedef struct _cvg_nwm_ntb_tsfm_history {
/* network id */
uint32_t nid :24,
/* reserved for future */
rsvd :8;
/* how many times this network absolutely win in tsfm check */
uint32_t big_win_cnt;
/* how many times this network win in tsfm check */
uint32_t win_cnt;
/* cco mac address */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* transformer mac address */
uint8_t tsfm_addr[IOT_MAC_ADDR_LEN];
} cvg_nwm_ntb_tsfm_history_t;
/* persistent info that won't be cleared when reset vdev */
typedef struct _cvg_nwm_sta_persist_info {
/* timer for clearing NID/PCO black list */
timer_id_t blacklist_timer;
/* blacklists of PCOs that STA shall not select as proxy.
* There is a blacklist for each NID.
*/
cvg_nwm_pco_blist pco_blist[PLC_PCO_BLIST_COUNT];
/* blacklist of nid that STA shall not try to assoc */
cvg_nwm_nid_blist nid_blist[PLC_NID_BLIST_SIZE];
/* identified transformer history list */
cvg_nwm_tsfm_history_t tsfm_history[PLC_TSFM_HISTORY_SIZE];
/* ntb best nid historical info */
cvg_nwm_ntb_tsfm_history_t ntb_tsfm_history[PLC_TSFM_HISTORY_SIZE];
/* sta vdev state machine */
cvg_nwm_vdev_sm_sta_t sm;
/* hplc local tx power cap. unit is 1 dbuv */
uint8_t local_tx_power_cap;
/* rf local tx power cap. unit is 1 dbm */
int8_t local_rf_tx_power_cap;
/* flag to mark if watch dog enabled */
uint8_t wdg_enable :1,
/* flag to mark if discovery enabled */
discovery_enable :1,
/* flag to mark if sw agc disabled */
sw_agc_disable :1,
/* flag to mark if the joined network is join check network */
is_cco_join_check :1,
/* number of transformer switch */
tsfm_switch_cnt :4;
/* number of ntb tsfm result check */
uint8_t zc_ntb_check_cnt;
/* phase information masks that do not need to be reported */
uint8_t phase_mask;
/* last event record */
uint8_t last_event;
/* consecutive state machine restart due to CVG_VDEV_START_ASSOC_TIMEOUT */
uint8_t assoc_timeout_cnt;
/* last leave network reason */
uint8_t last_leave_reason;
/* watch dog bite interval, unit is 1 ms, less than 30
* minutes is disallowed.
*/
uint32_t wdg_interval;
/* last event time stamp. unit is 1s */
uint32_t last_event_ts;
/* last started time stamp. unit is 1s */
uint32_t last_started_ts;
/* last selecting time stamp. unit is 1s */
uint32_t last_selecting_ts;
/* last associated time stamp. unit is 1s */
uint32_t last_associated_ts;
/* time stamp of last received tsfm startup packet. unit is 1s */
uint32_t last_tsfm_start_ts;
/* time stamp of last network role saving pib. unit is 1s */
uint32_t last_save_role_ts;
/* total roaming count */
uint32_t roam_cnt;
/* force roaming count */
uint32_t force_roam_cnt;
/* pco device leave roaming count */
uint32_t pco_leave_roam_cnt;
/* either tx or rx traffic success ratio 0 roaming count */
uint32_t tf_sr_0_roam_cnt;
/* both tx and rx traffic success ratio 0 roaming count */
uint32_t tx_rx_sr_0_roam_cnt;
/* time stamp of last ntb tsfm result check, unit is 1s */
uint32_t last_ntb_tsfm_check_ts;
/* sof frame rx count */
uint32_t sof_cnt;
/* beacon frame rx count */
uint32_t bc_cnt;
/* rf sof frame rx count */
uint32_t rf_sof_cnt;
/* rf beacon frame rx count */
uint32_t rf_bc_cnt;
/* duration of stay in current transformer area, unit is 1s */
uint32_t tsfm_stay_dur;
/* network lock time, 0 means no lock. uint is 1min. */
uint16_t nw_nor_lock_dur;
/* lock time of abnormal leave network, 0 means no lock. uint is 1min. */
uint16_t nw_abn_lock_dur;
/* flag to mark if fixed rate required for the local device */
uint32_t is_fix_rate_local :1,
/* flag to mark if fast connect enabled */
fast_connect :1,
/* flag to mark if allow transformer switch if found right transformer while
* doing transformer detection
* 0 - not allow
* 1 - allow
*/
tsfm_allow_switch_nw :1,
/* flag to mark if capture bitmap is valid */
capture_bm_valid :1,
/* flag to mark if app tsfm enable status is valid */
tsfm_app_en_valid :1,
/* flag to mark if app tsfm is enabled */
tsfm_app_enable :1,
/* flag to mark if the tsfm ntb win before */
tsfm_ntb_win :1,
/* flag to mark if scan rf option 2 full frequency */
rf_scan_glb :1,
/* 3ps device gpio tx-rx phase, see PLC_PHASE_XXX */
gpio_trx_phase :2,
/* 3ps device gpio tx-rx phase is valid */
gpio_trx_phase_valid :1,
/* record the number of 3ps device gpio tx-rx phase switching */
gpio_trx_phase_sw_cnt :3,
/* 3ps device last physical phase, bit0-2 means phaseA/B/C */
last_phy_phase :3,
/* WAR for Beijing snr tsfm cert test bed */
beijing_snr_tsfm_war :1,
/* reserved for future */
rsvd :14;
/* tei bitmap for capturing app layer frames */
cvg_tei_map_t capture_bm;
/* conn less sof frame msdu record array */
uint32_t cl_msdu_rec[CVG_NWM_CONN_LESS_REC_CNT];
/* lastest in use record index in cl_msdu_rec array */
uint16_t cl_msdu_rec_idx;
/* count of power meter connected */
uint8_t pm_cnt;
/* mac address of power meter connected, big-endian */
uint8_t pm_addr[PLC_CONN_PM_MAX_CNT][IOT_MAC_ADDR_LEN];
/* hw tsfm data len */
uint8_t hw_tsfm_data_len;
/* cache hw tsfm data */
uint8_t hw_tsfm_data[MAC_HW_TSFM_DATA_BYTE_MAX];
/* hw tsfm data send count */
uint8_t hw_tsfm_send_cnt;
/* hw tsfm send encode frequency tone num */
uint32_t hw_tsfm_freq_tone_num;
/* total count of clearing all blist */
uint8_t clear_all_blist_cnt;
/* fixed rate level, see PLC_RATE_ADAPT_RATE_XXX */
uint8_t fixed_rate_level;
} cvg_nwm_sta_persist_info_t;
/* sta vdev only descriptor */
typedef struct _cvg_nwm_vdev_sta {
/* persistent info that shall not be clear when reset vdev */
cvg_nwm_sta_persist_info_t pst_info;
/* proxy tei */
tei_t proxy_tei;
/* anchor hop as the back up hop to CCP for the initial several route
* periods after joined the network.
*/
tei_t anchor_hop;
/* mac address of cco */
uint8_t cco_addr[IOT_MAC_ADDR_LEN];
/* timer for network leaving */
timer_id_t leave_timer;
/* timer for network selection and joining */
timer_id_t join_timer;
/* in started status, this timer is used to check 3ps device gpio tx phase,
* in associated status, this timer is used to network monitoring and
* selection
*/
timer_id_t monitor_timer;
/* timer for netowrk monitor log report */
timer_id_t monitor_log_timer;
/* timer for watch dog reboot */
timer_id_t wdg_timer;
/* timer for rf scan table switch, recommended table or all option2 table */
timer_id_t rf_scan_timer;
/* cached candidate network */
union {
/* descriptor used for SG protocol */
mac_bc_rx_desc_t *cand_nw;
/* descriptor used for SPG protocol */
mac_bc_rx_desc_spg_t *spg_cand_nw;
};
/* association random number, used in sta device only */
uint32_t assoc_rand_num;
/* smart grid device type, used in sta device only */
uint8_t sg_dev_type;
/* assoc conf mme fragment total count */
uint8_t assoc_conf_total;
/* proxy change conf mme fragment total count --- non bitmap version */
uint8_t proxy_change_conf_total;
/* assigned role in beacon. see PLC_DEV_ROLE_XXX */
uint8_t bc_role;
/* rf normal scan rounds before convert to full band scanning */
uint8_t rf_scan_round: 3,
/* flag mark to if detected production testing */
pt_detected: 1,
/* flag mark to if STA has synchronized with CCO for time slots */
time_slot_sync: 1,
/* count of consecutive times to forbit association */
forbid_assoc_cnt: 3;
/* assoc conf mme fragment received */
uint16_t assoc_conf_recv;
/* proxy change conf mme fragment received --- non bitmap version */
uint16_t proxy_change_conf_recv;
/* interval that sta should report calculated tsfm detection data to
* cco. unit is 1s.
*/
uint16_t rpt_tsfm_dur;
/* interval that sta should do tsfm detection check to unit is 1s. */
uint16_t check_tsfm_dur;
/* interval that sta should do tsfm zc ntb detection check to unit is 1s. */
uint16_t check_tsfm_zc_dur;
/* the first possible power line phase */
uint32_t phase_1: 2,
/* the second possible power line phase */
phase_2: 2,
/* the third possible power line phase */
phase_3: 2,
/* flag to mark if new peer seen in previous route period */
prev_rp_new_peer: 1,
/* flag to mark if device is waiting for new beacon period to send out
* assoc or auth request.
*/
new_bp_assoc: 1,
/* flag to mark device initiates a proxy change request and waits for the
* proxy change confirmation.
*/
proxy_change_req: 1,
/* flag to mark if current network is for debug cco */
debug_cco: 1,
/* flag to mark if network monitor & ident enable */
nw_monitor_enable: 1,
/* flag to mark if phase a cco beacon received in last beacon period */
phase_a_bc_rx: 1,
/* flag to mark if phase b cco beacon received in last beacon period */
phase_b_bc_rx: 1,
/* flag to mark if phase c cco beacon received in last beacon period */
phase_c_bc_rx: 1,
/* flag to mark if local device kickout by cco due to not in white list */
kick_by_wl: 1,
/* flag to mark if the tsfm is valid */
tsfm_valid: 1,
/* algorithm to be used for transformer detection */
tsfm_algorithm: 4,
/* flag to mark if tsfm cco direct network detection enable */
tsfm_cco_detect_en: 1,
/* flag to mark if PCO should report SNR with it's direct sub STA
* periodically.
*/
pco_snr_rpt: 1,
/* flag to mark if in in_cco_wl flag is valid */
in_cco_wl_valid: 1,
/* flag to mark if local STA in in white list of CCO */
in_cco_wl: 1,
/* physical phase, bit0-2 means phaseA/B/C, set "1" to indicate
* which phase the device belongs to.
*/
phy_phase: 3,
/* flag to mark if L/N reversed in Single-phase power meter or phase
* sequence reversed in Three-phase power meter.
*/
opposite_phase: 1,
/* flag to mark if fixed rate required for the network device */
is_fix_rate_network: 1,
/* flag to mark if L/N reversed in Three-phase power meter */
opposite_3p: 1,
/* flag to mark if force link communication */
force_link_valid: 1,
/* force link type, 1 - force rf, 0 - force hplc */
force_rf_link: 1;
/* flag to mark if tsfm algorithm has been changed */
uint8_t tsfm_algo_chg: 1,
/* flag to mark if discovery beacon send with non cco node info */
bc_d_with_non: 1,
/* flag to mark if device rf link is valid */
rf_link_valid: 1,
/* reserved for future */
rsvd: 5;
/* connection position of N-wire if L/N of three-phase meter is reversed.
* see IOT_PLC_PHASE_XXX.
* Note: the position refers to the physical phase terminal.
*/
uint8_t opposite_3p_pos: 2,
/* forced roam to cco */
force_roam_cco: 1,
/* flag to mark if 3phase device zc check done. */
zc_3p_chk_done: 1,
/* flag to mark if the 3phase device have the zc repeat phase */
zc_repeat_3p: 1,
/* flag to mark if network locked */
nw_lock: 1,
/* flag to mark if the joined cco is from the same vendor as us */
same_vendor: 1,
/* flag to mark if level 1 device has been locked logical phase */
lock_phase_en: 1;
/* percentage of highest snr statistics collected to be used for tsfm */
uint8_t tsfm_snr_stat_high_th;
/* percentage of highest cco snr statistics collected to be used for tsfm */
uint8_t tsfm_cco_snr_stat_high_th;
/* lowest valid snr threshold for tsfm, unit is 1 db */
int8_t tsfm_low_snr_th;
/* cco lowest valid snr threshold for tsfm, unit is 1 db */
int8_t tsfm_cco_low_snr_th;
/* penalty value if no cco snr was received in this statistical period,
* unit is 1 db
*/
uint8_t tsfm_cco_snr_penal;
/* cco difference threshold if two networks level is same, unit is 1 db */
uint8_t tsfm_cco_diff_th1;
/* cco difference threshold if two networks level is same, unit is 1 times
*/
uint8_t tsfm_cco_diff_th2;
/* snr difference threshold if two networks level is same, unit is 1 db */
uint8_t tsfm_snr_diff_th1;
/* snr difference threshold if two networks level is same, unit is 1 db */
uint8_t tsfm_snr_diff_th2;
/* weight factor of received beacon snr for tsfm */
uint8_t tsfm_snr_bc_factor;
/* weight factor of received sof snr for tsfm */
uint8_t tsfm_snr_sof_factor;
/* level difference threshold if two networks level has big difference */
uint8_t tsfm_level_big_diff_th;
/* zc ntb difference threshold for tsfm, unit is 100 ntb */
uint8_t tsfm_zc_diff_th1;
/* zc ntb difference threshold for tsfm, unit is 0.1 times */
uint16_t tsfm_zc_diff_th2;
/* zc ntb difference threshold for tsfm, unit is 0.1 times */
uint16_t tsfm_zc_diff_th3;
/* zc ntb difference threshold for tsfm, unit is 0.1 times or 100 ntb */
uint16_t tsfm_zc_diff_th4;
/* candidate best snr tsfm network info */
cvg_nwm_sta_cand_tsfm_info_t cand_tsfm_info[2];
/* heartbeat report retry count in fast connect mode */
uint8_t fast_hb_rpt_retry_cnt;
/* hplc network tx power cap. unit is 1 dbuv */
uint8_t nw_tx_power_cap;
/* rf network tx power cap. unit is 1 dbm */
int8_t nw_rf_tx_power_cap;
/* counter to indicate local device must be switched to a new proxy.
* once the counter reaches 0 and local device can't be switched to a new
* proxy, local device will restart the whole state machine. for every
* roaming request timeout, this value will be decreased if the value is not
* zero.
*/
uint8_t force_roam_cnt;
/* number of consecutive route period that cco mac address is changed */
uint8_t cco_addr_chg_cnt;
/* number of consecutive route period that proxy is in sta role */
uint8_t proxy_role_sta_cnt;
/* number of consecutive retry assoc request or auth request */
uint8_t assoc_retry_cnt;
/* number of consecutive proxy change request tried to change the proxy
* in a route period.
*/
uint8_t roam_retry_cnt;
/* number of consecutive beacon period that indicate local device role
* out of date.
*/
uint8_t role_chg_cnt;
/* nid conflict detection count */
uint8_t nid_conflict_cnt;
/* nid changed detection count */
uint8_t nid_chg_cnt;
/* rf channel conflict detection count */
uint8_t rf_conflict_cnt;
/* rf channel conflict report count */
uint8_t rf_conflict_rpt_cnt;
/* number of remote node mac changed or tei changed */
uint8_t addr_chg_cnt;
/* last handled beacon_period count*/
uint32_t bc_period_cnt;
/* peer to peer serial number */
uint32_t p2p_sn;
/* heard network id list except id of current joined network */
cvg_nwm_sta_nw_info_t nid_list[PLC_MAX_NEIGHBOR_NETWORK];
/* neighbor network rf list, its rf channel id maybe same as current
* joined network when conflicting
*/
cvg_nwm_nn_rf_info_t rf_list[CVG_NWM_RF_CHANNEL_CNT];
/* local network info */
cvg_nwm_sta_nw_info_t nw_info;
/* best nid historical info */
cvg_nwm_best_nid_info_t best_nid_info[PLC_MAX_NEIGHBOR_NETWORK + 1];
/* total number of best nid historical info */
uint8_t nid_stat_cnt;
/* preferred cco mac address for next network selection */
uint8_t prefer_cco_addr[IOT_MAC_ADDR_LEN];
/* preferred network id */
uint32_t prefer_nid :24,
/* flag to mark if received standard beacon in last handled beacon_period
* count
*/
std_bc_rx_flag :1,
/* flag to mark if received hplc standard beacon in last handled
* beacon_period count
*/
hplc_bc_rx_flag :1,
/* mark the first candidate network link type that has been evaluated for
* network selection, bit 0 means hplc link is marked, bit 1 means rf link
* is marked.
*/
nw_sel_cand_link :2,
/* mark the more candidate network link type that has been evaluated for
* network selection, bit 0 means hplc link is marked, bit 1 means rf link
* is marked.
*/
nw_sel_extend_link :2,
/* flag to mark if network selection has been extended as tsfm switch */
nw_sel_extend_tsfm :1,
/* flag to mark if network selection has been extended as multi band */
nw_sel_extend_band :1;
/* time stamp of the end of hplc link network selection, unit is 1s */
uint32_t nw_sel_hplc_end_ts;
/* time stamp of the end of rf link network selection, unit is 1s */
uint32_t nw_sel_rf_end_ts;
/* last network conflict report time */
uint32_t nw_conflict_rpt_time;
/* last rf channel conflict report time, unit is 1s */
uint32_t rf_conflict_rpt_time;
/* number of directly connected peers in previous route period */
uint32_t prev_rp_peer_cnt;
/* number of full route period we spent.
* in proxy selection stage, this is the time we spent on traffic success
* ratio calc.
* in connected stage, this is the time we spent since associated with
* the network.
*/
uint32_t rp_spent;
/* tsfm check window win count. the larger the value, the longer the time
* we stay in the transformer. unit 1 tsfm check window.
*/
uint32_t tsfm_win_cnt;
/* time stamp of last beacon time slot assigned to local device, unit 1s */
uint32_t last_bc_ts_assign_time;
/* time stamp of last tsfm check. unit is 1s */
uint32_t last_tsfm_check_ts;
/* time stamp of last moving to associated state. unit is 1s */
uint32_t associated_ts;
/* time stamp of direct sub-node delay deletion timeout, uint is 1s */
uint32_t d_sub_del_delay_ts;
/* record peer count of starting association */
uint32_t start_assoc_peer_cnt;
/* number of valid number in the nid list */
uint8_t nid_list_cnt;
/* number of consecutive route period that no beacon received */
uint8_t no_bc_rx_cnt;
/* number of consecutive route period that the traffic success ratio
* with proxy is 0.
*/
uint8_t proxy_tf_0_cnt;
/* number of consecutive route period that the downlink traffic success
* ratio with proxy is 0.
*/
uint8_t proxy_dl_tf_0_cnt;
/* number of consecutive route period that the uplink traffic success
* ratio with proxy is 0.
*/
uint8_t proxy_ul_tf_0_cnt;
/* number of consecutive rf discovery period that the traffic success ratio
* with proxy is 0.
*/
uint8_t rf_proxy_tf_0_cnt;
/* number of consecutive rf discovery period that the downlink traffic success
* ratio with proxy is 0.
*/
uint8_t rf_proxy_dl_tf_0_cnt;
/* number of consecutive rf discovery period that the uplink traffic success
* ratio with proxy is 0.
*/
uint8_t rf_proxy_ul_tf_0_cnt;
/* number of full route period we need to spend on tr_sf calc */
uint8_t proxy_select_dur;
/* candidate proxy in last associate request */
pco_link_info_t cand_pco_list[CANDIDATE_PROXY_COUNT];
/* lastest in use record index in the CCO record array */
uint16_t cco_msdu_rec_idx;
/* lastest in use record index in the STA record array */
uint16_t sta_msdu_rec_idx;
/* CCO sof frame msdu record array */
uint32_t cco_msdu_rec[CVG_NWM_STA_CCO_REC_CNT];
/* STA sof frame msdu record array */
uint32_t sta_msdu_rec[CVG_NWM_STA_STA_REC_CNT];
} cvg_nwm_vdev_sta_t;
/* persistent info that won't be cleared when reset vdev */
typedef struct _cvg_nwm_vdev_persist_info {
/* flag to mark if certification test command listen enable */
uint8_t test_cmd_listen_en :1,
/* flag to mark if certification test band valid */
test_fb_valid :1,
/* flag to mark if enable join check, 1 - enable, 0 - disable */
join_check :1,
/* flag to mark if cert rf cfg valid */
test_rf_cfg_valid :1,
/* reserved for further use */
rsvd :4;
/* cert test tonemask */
uint8_t test_tonemask;
/* cert test rf option */
uint8_t test_rf_option;
/* cert test rf channel */
uint8_t test_rf_channel;
/* cert test band */
uint8_t test_fb;
} cvg_nwm_vdev_persist_info_t;
/* per vdev network management descriptor */
typedef struct _cvg_nwm_vdev {
/* persistent info that shall not be clear when reset vdev */
cvg_nwm_vdev_persist_info_t ps_info;
/* pointer of cvg vdev */
cvg_vdev_t *vdev;
/* self peer info */
cvg_peer_info_t *peer;
/* timer for monitoring the behavior of cert test mode */
timer_id_t test_timer;
/* timer for filtering duplicate frame of conn less mode */
timer_id_t cl_timer;
/* network formation done flag */
uint8_t assoc_done;
/* external network formation done flag */
uint8_t assoc_done_ext;
/* network allow association flag */
uint8_t allow_assoc;
/* allow to use beacon for channel estimation */
uint8_t allow_chan_eval;
/* network serial number */
uint8_t network_sn;
/* network interface id */
uint32_t nid :24,
/* flag to mark if use high power */
high_power_en :1,
/* reserved for future */
rsvd1 :7;
/* sta assoc retry interval after cco reject sta assoc request */
uint32_t assoc_retry_int;
/* tei of cco */
tei_t cco_tei;
/* tei of local device */
tei_t local_tei;
/* next available msdu sn for sof frame tx */
uint16_t tx_msdu_sn;
/* current device reboot count */
uint8_t reboot_cnt;
/* cert test mode */
uint8_t test_mode;
/* zero-crossing collection edge types, see CVG_ZC_CT_EDGE_XXX */
uint8_t zc_edge_type;
/* current startup reason */
uint8_t start_reason;
/* temporary buffer to save various temporary info.
* for sta role device:
* in started or selecting status, this buffer is used to cache the
* candidate network beacon info. see sta.cand_nw and sta.spg_cand_nw.
* in associating or associated status, this buffer is used to cache the
* sub sta info from cco as the info could be carried into multiple assoc
* conf mme.
* for cco role device:
* this buffer is used to cache the sub sta info for a peer which is
* joining the device.
*/
uint8_t *sub_sta_buf;
/* flag to mark if cco support proxy change nack feature.
* if set, CCO will send proxy change confirm with current proxy info for
* each rejected proxy change request. STA will send proxy change request
* until receive proxy change confirm from CCO.
* Note that, this is beyond spec. Only enable this feature when no other
* vendor device exist.
*/
uint8_t pco_chg_nack :1,
/* flag to mark if same vendor device found */
same_vendor_found :1,
/* reserved for further use */
rsvd :6;
/* tei bitmap to mark if received beacon is duplicated with same beacon
* period count.
*/
cvg_tei_map_t bc_rx_bm;
/* controller protocol control block */
void *ctrl_pcb;
/* per vdev type data structure.
* NOTE: union type struct must be at the end of nwm, otherwise error may
* occur when optimizing the memory size of cco and sta nwm.
*/
union {
cvg_nwm_vdev_sta_t sta;
cvg_nwm_vdev_cco_t cco;
} desc;
} cvg_nwm_vdev_t;
#if (PLC_SUPPORT_CCO_ROLE)
/*
* cvg_nwm_vdev_cco_sm() - nwm cco vdev state machine
* @nwm: nwm vdev pointer
* @event: event to be delivered
* @data: data pointer of the event
*/
void cvg_nwm_vdev_cco_sm(cvg_nwm_vdev_t *nwm, cvg_vdev_event_t event,
void *data);
/*
* @brief dump nwm cco statistics. note that this function is invoked outside
* CVG context, suppose this function should only read some statistics
* variables from CVG layer.
* @param vdev: pointer to vdev
*/
void cvg_nwm_cco_status_dump(cvg_vdev_t *vdev);
#else /* PLC_SUPPORT_CCO_ROLE */
#define cvg_nwm_vdev_cco_sm(nwm, event, data)
#define cvg_nwm_cco_status_dump(vdev)
#endif /* PLC_SUPPORT_CCO_ROLE */
#if (PLC_SUPPORT_STA_ROLE)
/*
* cvg_nwm_vdev_sta_sm() - nwm sta vdev state machine
* @nwm: nwm vdev pointer
* @event: event to be delivered
* @data: data pointer of the event
*/
void cvg_nwm_vdev_sta_sm(cvg_nwm_vdev_t *nwm, cvg_vdev_event_t event,
void *data);
/*
* @brief dump nwm sta statistics. note that this function is invoked outside
* CVG context, suppose this function should only read some statistics
* variables from CVG layer.
* @param vdev: pointer to vdev
*/
void cvg_nwm_sta_status_dump(cvg_vdev_t *vdev);
#else /* PLC_SUPPORT_STA_ROLE */
#define cvg_nwm_vdev_sta_sm(nwm, event, data)
#define cvg_nwm_sta_status_dump(vdev)
#endif /* PLC_SUPPORT_STA_ROLE */
/*
* @brief cvg_nwm_new_bp() - post a message back to self for new beacon period
* notification
* @param vdev: vdev pointer
* @param bp_cnt_delta: delta of new beacon period count and last beacon period
* count.
*/
void cvg_nwm_new_bp(cvg_vdev_t *vdev, uint32_t bp_cnt);
/*
* cvg_nwm_bc_rx() - beacon rx handling function. Same as mac_bc_rx_func_t.
* @arg: arg parameter registered alone with the callback
* @beacon: iot_pkt containing beacon raw data
* @new_bp: indicate if this beacon is the first beacon received for new bp
*/
void cvg_nwm_bc_rx(void *arg, iot_pkt_t *bc, uint8_t new_bp);
/*
* cvg_nwm_sof_rx() - sof frame rx handling func. Same as mac_recv_msdu_func_t.
* @arg: arg parameter registered alone with the callback
* @sof: iot_pkt containing sof frame raw data
*/
void cvg_nwm_sof_rx(void *arg, iot_pkt_t *sof);
/*
* @brief payload error and no payload frame rx handling func. same as
* mac_recv_cco_snr_func_t.
* @param arg: arg parameter registered alone with the callback
* @param cco_snr: iot pkt containing cco snr
*/
void cvg_nwm_cco_snr_rx(void *arg, iot_pkt_t *cco_snr);
/*
* cvg_nwm_bp_end_alert() - beacon period end alert handling function.
* Same as mac_bp_end_alert_func_t.
* @arg: arg parameter registered alone with the callback
*/
void cvg_nwm_bp_end_alert(void *arg);
/*
* @brief nid list report handling function. same as mac_nid_rpt_func_t.
* @param arg: arg parameter registered alone with the callback
* @param nid_list: iot pkt containing the nid list.
*/
void cvg_nwm_nid_rpt(void *arg, iot_pkt_t *nid_list);
/*
* @brief zero cross ntb report handling function.
* @param nwm: nwm vdev pointer
* @param zc_ntb: iot pkt containing the zc ntb.
*/
void cvg_nwm_zc_ntb_rpt(cvg_nwm_vdev_t *nwm, iot_pkt_t *zc_ntb);
/*
* @brief zero cross status report handling function.
* @param arg: arg parameter registered alone with the callback
* @param status: indicate if the phase zc info is valid.
* bit0 - Phase A, bit1 - Phase B, bit2 - Phase C
* 0 - invalid, 1 - valid.
*/
void cvg_nwm_zc_status_rpt(void *arg, uint32_t status);
/**
* @brief cvg_nwm_stop_test_timer() - stop test timer.
* @param nwm: nwm vdev pointer
*/
void cvg_nwm_stop_test_timer(cvg_nwm_vdev_t *nwm);
/**
* @brief cvg_nwm_restart_test_timer() - restart test timer.
* @param nwm: nwm vdev pointer
* @param dur: duration, uint is 1ms.
*/
void cvg_nwm_restart_test_timer(cvg_nwm_vdev_t *nwm, uint32_t dur);
/**
* @brief cvg_nwm_restart_cl_timer() - restart conn less timer.
* @param nwm: nwm vdev pointer
* @param dur: duration, uint is 1ms.
*/
void cvg_nwm_restart_cl_timer(cvg_nwm_vdev_t *nwm, uint32_t dur);
/**
* @brief cvg_nwm_test_cmd_listen_en() - certification test command listening
* enabled.
* @param nwm: nwm vdev pointer
*/
void cvg_nwm_test_cmd_listen_en(cvg_nwm_vdev_t *nwm);
/**
* @brief cvg_nwm_test_cmd_listen_dis() - certification test command listening
* disabled.
* @param nwm: nwm vdev pointer
*/
void cvg_nwm_test_cmd_listen_dis(cvg_nwm_vdev_t *nwm);
/**
* @brief cvg_nwm_config_test_mode() - configuration test mode.
* @param nwm: - nwm vdev pointer
* @param mas_mode: - master mode code, see CVG_NWM_TEST_MODE_XXXX
* @param sub_mode: - sub mode code.
* if the main mode is set to CVG_NWM_TEST_MODE_CERT, this
* submode code is valid, see CERT_TEST_CMD_ENTER_XXX.
* @param dur: - duration of mode to be set, uint is 1ms.
*/
void cvg_nwm_config_test_mode(cvg_nwm_vdev_t *nwm, uint8_t mas_mode,
uint8_t sub_mode, uint32_t dur);
/**
* @brief set hplc and rf tx power cap to mac layer.
* @param nwm: nwm vdev pointer
* @param hplc_power: pointer to hplc tx power cal to be set. unit is 1 dbuv,
* range 95 - 137.
* @param rf_power: pointer to rf tx power cal to be set. unit is 1 dbm,
* range -35 - 20.
*
* @return:
* 0 -- for success case
* otherwise -- error code
*/
uint32_t cvg_nwm_set_tx_power_cap_to_mac_ext(cvg_nwm_vdev_t *nwm,
uint8_t *hplc_power, int8_t *rf_power);
/**
* @brief set tx power cap to mac layer.
* @param nwm: nwm vdev pointer
* @param power: tx power cal to be set. unit is 1 dbm.
*
* @return:
* 0 -- for success case
* otherwise -- error code
*/
uint32_t cvg_nwm_set_tx_power_cap_to_mac(cvg_nwm_vdev_t *nwm, uint8_t power);
/**
* @brief cvg_nwm_set_period_ck_spur_to_mac() - set period check spur to mac
* @param nwm: nwm vdev pointer
* @param en: enable or disable
*/
void cvg_nwm_set_period_ck_spur_to_mac(cvg_nwm_vdev_t *nwm, uint8_t en);
#ifdef __cplusplus
}
#endif
#endif /* CVG_NWM_INTERNAL_H */