738 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			738 lines
		
	
	
		
			26 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 MAC_BCM_API_H
 | |
| #define MAC_BCM_API_H
 | |
| 
 | |
| /* os shim includes */
 | |
| #include "os_types.h"
 | |
| 
 | |
| /* common includes */
 | |
| #include "iot_utils.h"
 | |
| #include "iot_pkt_api.h"
 | |
| #include "iot_errno.h"
 | |
| 
 | |
| /* plc protocol includes */
 | |
| #include "plc_protocol.h"
 | |
| #include "plc_utils.h"
 | |
| #include "plc_fr.h"
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| /* beacon update action type */
 | |
| #define MAC_BC_ACT_ADD              (1)     /* add content */
 | |
| #define MAC_BC_ACT_DEL              (2)     /* delete content */
 | |
| 
 | |
| /* define the beacon entry section */
 | |
| #define MAC_BC_FC_INFO              (0)     /* beacon frame control info */
 | |
| #define MAC_BC_FIX_P                (1)     /* fixed beacon payload */
 | |
| #define MAC_BC_BMI_STA_CAP          (2)     /* sta capability */
 | |
| #define MAC_BC_BMI_RT_PARAM         (3)     /* route parameter */
 | |
| #define MAC_BC_BMI_FREQ_CHG         (4)     /* frequency change */
 | |
| #define MAC_BC_BMI_TIME_SLOT        (5)     /* time slot assignment */
 | |
| #define MAC_BC_BMI_VENDOR_SPEC      (6)     /* vendor specific */
 | |
| #define MAC_BC_BMI_METER            (7)     /* meter reading control info */
 | |
| #define MAC_BC_BMI_FB_DETECT        (8)     /* freq band detection */
 | |
| #define MAC_BC_BMI_RF_CHANNEL_CHG   (9)     /* rf channel change */
 | |
| #define MAC_BC_BMI_RF_ROUTE         (10)    /* rf route parameter */
 | |
| #define MAC_BC_BMI_RF_SIMPLE_PARAM  (11)    /* rf simple param */
 | |
| #define MAC_BC_BMI_RTC              (12)    /* real time clock */
 | |
| #define MAC_BC_BMI_HTBUS_FIX_P      (13)    /* HTBUS fixed beacon payload */
 | |
| #define MAC_BC_BMI_HTBUS_TIME_SLOT  (14)    /* HTBUS time slot assignment */
 | |
| #define MAC_BC_BMI_HTBUS_USER_DATA  (15)    /* HTBUS user data entry */
 | |
| #define MAC_BC_BMI_UNKNOWN          (16)    /* unknown entry */
 | |
| /* max beacon entries. always keep it defined as the last one */
 | |
| #define MAC_BC_ENTRY_MAX            (MAC_BC_BMI_UNKNOWN + 1)
 | |
| 
 | |
| /* define how many bcn entries participate in sorting */
 | |
| #define MAC_BCN_SORT_MAX_CNT        (15)
 | |
| 
 | |
| /* define the rf status of tx beacon. just send tidy beacon */
 | |
| #define MAC_RF_SEND_SIMPLE_BCN       (0)
 | |
| /* define the rf status of tx beacon. just send standard beacon */
 | |
| #define MAC_RF_SEND_STD_BCN          (1)
 | |
| 
 | |
| /* max beacon vendor app data size */
 | |
| #define MAC_BC_APP_DATA_MAX         14
 | |
| /* meter reading control entry data size */
 | |
| #define MAC_MAX_BC_METER_DATA_SIZE  (0x20)
 | |
| 
 | |
| /* min beacon csma slot, unit is 1ms */
 | |
| #define MAC_BC_CSMA_SLOT_MIN        (50)
 | |
| 
 | |
| /* beacon entry descriptor */
 | |
| typedef struct _mac_bc_ent {
 | |
|     /* beacon entry type */
 | |
|     uint8_t     type;
 | |
|     /* beacon entry data */
 | |
|     void        *data;
 | |
| } mac_bc_ent_t;
 | |
| 
 | |
| /* beacon update descriptor */
 | |
| typedef struct _mac_bc_update {
 | |
|     /* flag to mark if a beacon tx need to be triggered after beacon updated */
 | |
|     uint8_t         tx_req      :1,
 | |
|     /* flag to mark if a new beacon period need to be loaded after beacon
 | |
|      * update.
 | |
|      */
 | |
|                     new_bp_req  :1,
 | |
|     /* flag to mark if phase a is allowed for tx if local device is sta role */
 | |
|                     phase_a_tx  :1,
 | |
|     /* flag to mark if phase b is allowed for tx if local device is sta role */
 | |
|                     phase_b_tx  :1,
 | |
|     /* flag to mark if phase c is allowed for tx if local device is sta role */
 | |
|                     phase_c_tx  :1,
 | |
|     /* flag to mark if use high power */
 | |
|                     high_power  :1,
 | |
|     /* flag to mark if discovery beacon send with non cco node info */
 | |
|                     bc_d_with_non :1;
 | |
|     /* entry count */
 | |
|     uint8_t         count;
 | |
|     /* for CCO role device, this value indicate the number of STA devices in
 | |
|      * the network.
 | |
|      * for STA role device, this value indicate the number of devices nearby
 | |
|      * in the same network.
 | |
|      */
 | |
|     uint16_t        peer_cnt;
 | |
|     /* valid bcn entries in entry_sort */
 | |
|     uint8_t         entry_sort_cnt;
 | |
|     /* bcn entries fill order */
 | |
|     uint8_t         entry_sort[MAC_BCN_SORT_MAX_CNT];
 | |
|     /* beacon update action */
 | |
|     uint8_t         action[MAC_BC_ENTRY_MAX];
 | |
|     /* beacon entries to be updated */
 | |
|     mac_bc_ent_t    entry[MAC_BC_ENTRY_MAX];
 | |
| } mac_bc_update_t;
 | |
| 
 | |
| /* frame control entry */
 | |
| typedef struct _mac_bc_fc {
 | |
|     /* network ID */
 | |
|     uint32_t        nid     :24,
 | |
|     /* rx band ID */
 | |
|                     band_id :8;
 | |
|     /* ntb delta. remote device network ntb - local device network ntb.
 | |
|      * this info is gotten from beacon rx meta infor from mac layer.
 | |
|      */
 | |
|     int32_t        delta_ntb;
 | |
|     /* snr of the beacon */
 | |
|     int8_t          snr;
 | |
|     /* rssi of the beacon */
 | |
|     int8_t          rssi;
 | |
|     /* network type */
 | |
|     uint8_t         net_type;
 | |
|     /* targeted phase of the beacon */
 | |
|     uint8_t         phase    :2,
 | |
|     /* flag to indicate is rf package or not */
 | |
|                     is_rf    :1,
 | |
|     /* version info */
 | |
|                     version  :5;
 | |
|     /* beacon period count */
 | |
|     uint32_t        bp_cnt;
 | |
| } mac_bc_fc_t;
 | |
| 
 | |
| /* fixed payload entry */
 | |
| typedef struct _mac_bc_fp {
 | |
|     uint8_t         type            : 2,
 | |
|                     assoc_done      : 1,
 | |
|                     allow_assoc     : 1,
 | |
|                     allow_chan_eval : 1,
 | |
|                     simple_beacon   : 1,
 | |
|                     rf_option       : 2;
 | |
|     uint8_t         network_sn;
 | |
|     uint8_t         cco_addr[IOT_MAC_ADDR_LEN];
 | |
|     uint32_t        bc_period_cnt;
 | |
|     uint32_t        rf_channel      :8,
 | |
|     /* flag to mark if enable the authorization process */
 | |
|                     auth_enable     :1,
 | |
|     /* encryption mode, see ENCRYP_MODE_XXX */
 | |
|                     encrypt_mode    :1,
 | |
|     /* communication encryption key sequence */
 | |
|                     cek_seq         :2,
 | |
|     /* encryption_algorithm, see ENCRYPT_ALGO_XXX */
 | |
|                     encrypt_algo    :1,
 | |
|     /* to solve compatibility problems */
 | |
|                     used_rsvd1      :18,
 | |
|     /* reserved for future */
 | |
|                     rsvd            :1;
 | |
|     /* to solve compatibility problems */
 | |
|     uint32_t        used_rsvd2;
 | |
| } mac_bc_fp_t;
 | |
| 
 | |
| /* sta capability entry */
 | |
| typedef struct _mac_bc_sta_cap {
 | |
|     /* tei */
 | |
|     tei_t           tei;
 | |
|     /* proxy tei */
 | |
|     tei_t           proxy;
 | |
|     /* mac address */
 | |
|     uint8_t         addr[IOT_MAC_ADDR_LEN];
 | |
|     /* minimum traffic success ratio with CCO */
 | |
|     uint8_t         min_ul_dl_sr;
 | |
|     /* role */
 | |
|     uint8_t         role;
 | |
|     /* level info */
 | |
|     uint8_t         level          : 6,
 | |
|     /* to solve compatibility problems */
 | |
|                     used_rsvd      : 2;
 | |
|     /* snr of proxy */
 | |
|     int8_t          snr;
 | |
|     /* phase info */
 | |
|     uint8_t         phase          : 3,
 | |
|     /* rf hop */
 | |
|                     rf_hop         : 4,
 | |
|     /* flag to mark if min_ul_dl_sr is invalid */
 | |
|                     min_sr_invalid : 1;
 | |
| } mac_bc_sta_cap_t;
 | |
| 
 | |
| /* simple param entry */
 | |
| typedef struct _mac_bc_simple_param {
 | |
|     /* tei */
 | |
|     uint32_t        tei             : 12,
 | |
|     /* proxy tei */
 | |
|                     pco_tei         : 12,
 | |
|     /* role, see PLC_DEV_ROLE_XXX */
 | |
|                     role            : 4,
 | |
|     /* level */
 | |
|                     level           : 4;
 | |
|     /* rf hop to cco */
 | |
|     uint8_t         rf_hop          : 4,
 | |
|     /* encryption mode, see ENCRYPTION_MODE_XXX */
 | |
|                     encrypt_mode    : 1,
 | |
|     /* encryption_algorithm, see ENCRYPTION_ALGORITHM_XXX */
 | |
|                     encrypt_algo    : 1,
 | |
|     /* to solve compatibility problems */
 | |
|                     used_rsvd       : 2;
 | |
|     /* mac addr */
 | |
|     uint8_t         addr[IOT_MAC_ADDR_LEN];
 | |
|     /* csma slot start ntb */
 | |
|     uint32_t        csma_start_ntb;
 | |
|     /* csma slot duration, unit 1ms */
 | |
|     uint16_t        csma_dur;
 | |
| } mac_bc_simple_param_t;
 | |
| 
 | |
| /* route parameter entry */
 | |
| typedef struct _mac_bc_rt_param {
 | |
|     /* route period, unit is 1s */
 | |
|     uint16_t        rt_period;
 | |
|     /* time to next route period. see CVG_RT_RP_MARK_0_DUR for more info */
 | |
|     uint16_t        rt_left_period;
 | |
|     /* proxy discovery period, unit is 1s */
 | |
|     uint16_t        p_dis_period;
 | |
|     /* sta discovery period, unit is 1s */
 | |
|     uint16_t        s_dis_period;
 | |
| } mac_bc_rt_param_t;
 | |
| 
 | |
| typedef struct _mac_bc_fp_spg {
 | |
|     uint8_t         type            : 2,
 | |
|                     assoc_done      : 1,
 | |
|                     allow_assoc     : 1,
 | |
|                     multi_select    : 1, /* diff */
 | |
|                     simple_beacon   : 1,
 | |
|                     rf_option       : 2;
 | |
|     uint8_t         rf_channel;
 | |
|     uint8_t         network_sn;
 | |
|     uint8_t         short_network_id: 4,
 | |
|                     allow_chan_eval : 1,
 | |
|     /* to solve compatibility problems */
 | |
|                     used_rsvd1      : 2,
 | |
|     /* reserved for future */
 | |
|                     rsvd            : 1;
 | |
|     uint8_t         cco_addr[IOT_MAC_ADDR_LEN];
 | |
|     /* to solve compatibility problems */
 | |
|     uint16_t        used_rsvd2;
 | |
| } mac_bc_fp_spg_t;
 | |
| 
 | |
| typedef struct _mac_bc_sta_cap_spg {
 | |
|     /* tei */
 | |
|     tei_t           tei;
 | |
|     /* proxy tei */
 | |
|     tei_t           proxy;
 | |
|     /* mac address */
 | |
|     uint8_t         addr[IOT_MAC_ADDR_LEN];
 | |
|     /* minimum traffic success ratio with CCO */
 | |
|     uint8_t         min_ul_dl_sr;
 | |
|     /* role */
 | |
|     uint8_t         role;
 | |
|     /* level info */
 | |
|     uint8_t         level;
 | |
|     /* phase info */
 | |
|     uint8_t         phase   : 3,
 | |
|     /* rf hop */
 | |
|                     rf_hop  : 4,
 | |
|     /* flag to mark if min_ul_dl_sr is invalid */
 | |
|                     min_sr_invalid : 1;
 | |
|     /* if set, use beacon for channel evaluated */
 | |
|     uint8_t         allow_chan_eval;
 | |
|     /* to solve compatibility problems */
 | |
|     uint32_t        used_rsvd;
 | |
| } mac_bc_sta_cap_spg_t;
 | |
| 
 | |
| /* simple param entry */
 | |
| typedef struct _mac_bc_simple_param_spg {
 | |
|     /* tei */
 | |
|     uint32_t        tei             : 12,
 | |
|     /* proxy tei */
 | |
|                     pco_tei         : 12,
 | |
|     /* role, see PLC_DEV_ROLE_XXX */
 | |
|                     role            : 4,
 | |
|     /* level */
 | |
|                     level           : 4;
 | |
|     /* rf hop to cco */
 | |
|     uint8_t         rf_hop          : 4,
 | |
|     /* hplc frequency band id */
 | |
|                     freq_band       : 2,
 | |
|     /* to solve compatibility problems */
 | |
|                     used_rsvd       : 2;
 | |
|     /* mac addr */
 | |
|     uint8_t         addr[IOT_MAC_ADDR_LEN];
 | |
|     /* csma slot start ntb */
 | |
|     uint32_t        csma_start_ntb;
 | |
|     /* csma slot duration, unit 1ms */
 | |
|     uint16_t        csma_dur;
 | |
| } mac_bc_simple_param_spg_t;
 | |
| 
 | |
| typedef struct _mac_bc_rt_param_spg {
 | |
|     /* route period, unit is 1s */
 | |
|     uint16_t        rt_period;
 | |
|     /* time to next route period, unit is 1s */
 | |
|     uint16_t        rt_left_period;
 | |
|     /* to solve compatibility problems */
 | |
|     uint16_t        used_rsvd1;
 | |
|     /* CCO MAC address */
 | |
|     uint8_t         cco_addr[IOT_MAC_ADDR_LEN];
 | |
|     /* to solve compatibility problems */
 | |
|     uint8_t         used_rsvd2[20];
 | |
| } mac_bc_rt_param_spg_t;
 | |
| 
 | |
| /* frequency change entry */
 | |
| typedef struct _mac_bc_freq_chg {
 | |
|     /* target frequency */
 | |
|     uint8_t         targer_freq;
 | |
|     /* time left */
 | |
|     uint32_t        time_left;
 | |
| } mac_bc_freq_chg_t;
 | |
| 
 | |
| /* rf channel change entry */
 | |
| typedef struct _mac_bc_rf_channel_chg {
 | |
|     /* target rf channel */
 | |
|     uint8_t  target_rf_channel;
 | |
|     /* target rf option */
 | |
|     uint8_t  target_rf_option   :2,
 | |
|     /* solve compatibility problems */
 | |
|              used_rsvd          :6;
 | |
|     /* time left, unit is 1ms */
 | |
|     uint32_t time_left;
 | |
| } mac_bc_rf_channel_chg_t;
 | |
| 
 | |
| /* rf route param entry */
 | |
| typedef struct _mac_bc_rf_route {
 | |
|     /* rf discover list period, unit is 1s */
 | |
|     uint8_t rf_dis_period;
 | |
|     /* rf traffic success ratio expired period, unit is 1 rf_dis_period */
 | |
|     uint8_t rf_age_period;
 | |
| } mac_bc_rf_route_t;
 | |
| 
 | |
| /* meter reading control entry */
 | |
| typedef struct _mac_bc_meter {
 | |
|     /* data len */
 | |
|     uint8_t len;
 | |
|     /* data */
 | |
|     uint8_t data[MAC_MAX_BC_METER_DATA_SIZE];
 | |
| } mac_bc_meter_t;
 | |
| 
 | |
| /* freq band detection entry */
 | |
| typedef struct _mac_bc_fb_detect {
 | |
|     /* target frequency band id of detection */
 | |
|     uint8_t band_id;
 | |
|     /* dedicated csma slot supported link id */
 | |
|     uint8_t d_csma_lid;
 | |
| } mac_bc_fb_detect_t;
 | |
| 
 | |
| /* rtc entry */
 | |
| typedef struct _mac_bc_rtc {
 | |
|     /* stand for the delta between cco rtc and the base timer 2000.1.1 00:00:00,
 | |
|      * unit is 1s
 | |
|      */
 | |
|     uint32_t cco_date;
 | |
|     /* cco ntb of corresponding date, unit is 1NTB  */
 | |
|     uint32_t cco_ntb;
 | |
| } mac_bc_rtc_t;
 | |
| 
 | |
| /* beacon tx assignment node info */
 | |
| typedef struct _mac_bc_tx_as_node {
 | |
|     /* designated TEI to send beacon */
 | |
|     uint16_t tei        : 12,
 | |
|     /* 0x0 - discovery, 0x1 - proxy */
 | |
|              type       : 1,
 | |
|     /* tx type flag, see BEACON_TX_XXX */
 | |
|              tx_flag    : 3;
 | |
| } mac_bc_tx_as_node_t;
 | |
| 
 | |
| #if PLC_SUPPORT_CCO_ROLE
 | |
| 
 | |
| #if RUN_IN_PSRAM
 | |
| /* beacon tx assignment info */
 | |
| #define MAC_MAX_BC_TX_PER_BP        (210)
 | |
| #else /* RUN_IN_PSRAM */
 | |
| #define MAC_MAX_BC_TX_PER_BP        (100)
 | |
| #endif /* RUN_IN_PSRAM */
 | |
| 
 | |
| #else /* PLC_SUPPORT_CCO_ROLE */
 | |
| 
 | |
| /* beacon tx assignment info */
 | |
| #define MAC_MAX_BC_TX_PER_BP        (210)
 | |
| 
 | |
| #endif /* PLC_SUPPORT_CCO_ROLE */
 | |
| 
 | |
| typedef struct _mac_bc_tx_as {
 | |
|     /* proxy and discover beacon count */
 | |
|     uint8_t         bc_cnt;
 | |
|     /* flag to mark if the per tei info available. according to smart grid
 | |
|      * spec, only central and discovery beacon tain per tei info. discovery
 | |
|      * beacon don't have such info.
 | |
|      */
 | |
|     uint8_t         tei_valid;
 | |
| #if PLC_SUPPORT_CCO_ROLE
 | |
|     /* phase of the tei, defination is same as PLC_PHASE_XXX macro */
 | |
|     uint8_t         phase[MAC_MAX_BC_TX_PER_BP];
 | |
| #endif
 | |
|     /* assignment node info */
 | |
|     mac_bc_tx_as_node_t sta[MAC_MAX_BC_TX_PER_BP];
 | |
| } mac_bc_tx_as_t;
 | |
| 
 | |
| /* csma slot info */
 | |
| typedef struct _mac_bc_csma_si {
 | |
|     /* csma slot supported phase count */
 | |
|     uint8_t         phase_cnt;
 | |
|     /* csma phase */
 | |
|     uint8_t         phase[PLC_PHASE_CNT];
 | |
|     /* to solve compatibility problems */
 | |
|     uint8_t         used_rsvd[PLC_PHASE_CNT];
 | |
|     /* cmsa slot duration, unit is 1ms*/
 | |
|     uint32_t        slot_dur[PLC_PHASE_CNT];
 | |
| } mac_bc_cmsa_si_t;
 | |
| 
 | |
| /* time slot assignment entry */
 | |
| typedef struct _mac_bc_time_slot {
 | |
|     /* central beacon count */
 | |
|     uint8_t             cco_bc_cnt;
 | |
|     /* proxy beacon count */
 | |
|     uint8_t             proxy_bc_cnt;
 | |
|     /* beacon slot duration, unit is 1ms */
 | |
|     uint8_t             bc_slot_dur;
 | |
|     /* original csma slot fragment size for beacon send,
 | |
|      * unit is 10ms for cco
 | |
|      * unit is 1ms or 10ms for sta
 | |
|      */
 | |
|     uint8_t             org_csma_slot_frag_s;
 | |
|     /* csma slot fragment size, unit is 1ms */
 | |
|     uint16_t            csma_slot_frag_s;
 | |
|     /* dedicated csma slot supported phase count */
 | |
|     uint8_t             d_csma_lid;
 | |
|     /* tdma slot duration, unit is 1ms */
 | |
|     uint8_t             tdma_slot_dur;
 | |
|     /* tdma slot supported link id */
 | |
|     uint8_t             tdma_lid;
 | |
|     /* protected region length of future beacon period, unit is 1ms */
 | |
|     uint16_t            protected_region_dur;
 | |
|     /* beacon period */
 | |
|     uint32_t            bc_period        : 16,
 | |
|     /* rf standard beacon slot duration, unit is 1ms */
 | |
|                         rf_bc_slot_dur   : 10,
 | |
|     /* flag to mark if current time slot is allowed to be reused for following
 | |
|      * beacon periods. this flag is only valid for sta role device case.
 | |
|      */
 | |
|                         allow_reuse      : 1,
 | |
|     /* flag to mark if send rf standard beacon if local device is cco role */
 | |
|                         rf_std_tx        : 1,
 | |
|     /* reserved for future */
 | |
|                         rsvd1            : 4;
 | |
|     /* beacon period start NTB */
 | |
|     uint32_t            bp_start_ntb;
 | |
|     union {
 | |
|         struct {
 | |
|             /* solve compatibility problems for sg time slot entry */
 | |
|             uint32_t    sg_used_rsvd1    : 10,
 | |
|                         sg_used_rsvd2    : 6,
 | |
|             /* reserved for future */
 | |
|                         rsvd2            : 16;
 | |
|         };
 | |
|         struct {
 | |
|             /* solve compatibility problems for spg time slot entry */
 | |
|             uint32_t    spg_used_rsvd    : 22,
 | |
|             /* reserved for future */
 | |
|                         rsvd3            : 10;
 | |
|         };
 | |
|     };
 | |
|     /* proxy and discover beacons info */
 | |
|     mac_bc_tx_as_t      non_cco_bc_info;
 | |
|     /* csma time slot info */
 | |
|     mac_bc_cmsa_si_t    csma_info;
 | |
|     /* dedicated csma time slot info */
 | |
|     mac_bc_cmsa_si_t    d_csma_info;
 | |
| } mac_bc_time_slot_t;
 | |
| 
 | |
| /* vendor specific entry */
 | |
| typedef struct _mac_bc_vendor_spec {
 | |
|     /* allowed to cco traffic success ratio. if sta to cco's traffic success
 | |
|      * ratio is equal or higher than this value, than sta is allowed to join
 | |
|      * the network.
 | |
|      */
 | |
|     uint8_t         allowed_cco_tf_sr;
 | |
|     /* hplc tx power cap. unit is 1 dbuv */
 | |
|     uint8_t         power;
 | |
|     /* rf tx power cap, unit is 1 dbm */
 | |
|     int8_t          rf_power;
 | |
|     /* network for debug purpose */
 | |
|     uint8_t         cco_debug           :1,
 | |
|     /* flag to mark if debug target mac address is valid */
 | |
|                     addr_valid          :1,
 | |
|     /* suggested proxy selection duration, each sta should spend at least
 | |
|      * the duration for proxy slection. note that this value should not be
 | |
|      * changed in the whole network life time. the unit is 1 route period.
 | |
|      */
 | |
|                     proxy_select_dur    :3,
 | |
|     /* flag to mark if the threshold data info available */
 | |
|                     th_data_valid       :1,
 | |
|     /* flag to mark if fixed rate required for this network */
 | |
|                     fixed_rate          :1,
 | |
|     /* flag to mark if the application data is valid */
 | |
|                     app_data_valid      :1;
 | |
|     /* flag to mark if the tsfm is valid */
 | |
|     uint8_t         tsfm_valid          :1,
 | |
|     /* 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 simple pair passcode is valid */
 | |
|                     passcode_valid      :1,
 | |
|     /* algorithm to be used for transformer detection */
 | |
|                     tsfm_algorithm      :4;
 | |
|     /* lowest valid snr threshold for tsfm, unit is 1 db */
 | |
|     int8_t          tsfm_low_snr_th;
 | |
|     /* percentage of highest snr statistics collected to be used for tsfm */
 | |
|     uint8_t         tsfm_snr_stat_high_th;
 | |
|     /* vendor id of cco */
 | |
|     uint16_t        vendor_id;
 | |
|     /* app data if any */
 | |
|     uint8_t         app_data[MAC_BC_APP_DATA_MAX];
 | |
|     /* debug target mac address if any */
 | |
|     uint8_t         addr[IOT_MAC_ADDR_LEN];
 | |
|     /* define the rank from which the cco/pco role candidate start to take
 | |
|      * higher priority, this value must be equal or smaller than
 | |
|      * CANDIDATE_PROXY_COUNT.
 | |
|      */
 | |
|     uint8_t         sta_proxy_weight_rank   :4,
 | |
|     /* for (level - base_level) <= level_score_high_th, level_score_l
 | |
|      * will take effect. Otherwise, level_score_h will take effect. The
 | |
|      * purpose is to try to minimize the topo tree depth while giving enough
 | |
|      * flexibility for candidate pco selection.
 | |
|      */
 | |
|                     level_score_h_th        :4;
 | |
|     /* define sta proxy traffic success ratio threshold */
 | |
|     uint8_t         sta_proxy_good_tf_sr_th;
 | |
|     /* define proxy roaming gap. if the new proxy is better enough than current
 | |
|      * proxy, then roaming to the new proxy.
 | |
|      * new_proxy_score > (cur_proxy_score + roaming_gap)
 | |
|      * the smaller the gap, the easier to roaming to a better proxy.
 | |
|      * if traffic success ratio with proxy lower than sta_proxy_good_tf_sr_th,
 | |
|      * local device will start to use sta_roaming_gap_l while selecting
 | |
|      * candidate pco. otherwise, sta_roaming_gap_h will be used.
 | |
|      */
 | |
|     uint8_t         sta_roaming_gap_h;
 | |
|     uint8_t         sta_roaming_gap_l;
 | |
|     /* define cco phase traffic success ratio threshold */
 | |
|     uint8_t         cco_phase_check_tf_sr_th;
 | |
|     /* define level 1 device switch phase gap. if the new phase is better enough
 | |
|      * than current phase, then switch to the new phase.
 | |
|      * new_phase_score > (cur_phase_score + phase_gap)
 | |
|      * the smaller the gap, the easier to switch the phase.
 | |
|      * if traffic success ratio with cco higher than cco_phase_check_tf_sr_th,
 | |
|      * local device will start to use cco_phase_gap_other while selecting
 | |
|      * logical phase. if traffic success ratio with cco lower than
 | |
|      * sta_proxy_good_tf_sr_th, use cco_phase_gap_own_l, otherwise
 | |
|      * cco_phase_gap_own_h will be used.
 | |
|      */
 | |
|     uint8_t         cco_phase_gap_own_h;
 | |
|     uint8_t         cco_phase_gap_own_l;
 | |
|     uint8_t         cco_phase_gap_other;
 | |
|     /* define 1 level corresponding to how many score while calculating path
 | |
|      * score.
 | |
|      */
 | |
|     uint8_t         level_score_h;
 | |
|     uint8_t         level_score_l;
 | |
|     /* see CVG_RT_STA_CCO_GOOD_XXX */
 | |
|     uint8_t         cco_good_tf_sr_th;
 | |
|     uint8_t         cco_good_tx_sr_th;
 | |
|     uint8_t         cco_good_rx_sr_th;
 | |
|     /* see CVG_RT_STA_PCO_GOOD_XXX */
 | |
|     uint8_t         pco_good_tf_sr_th;
 | |
|     uint8_t         pco_good_tx_sr_th;
 | |
|     uint8_t         pco_good_rx_sr_th;
 | |
|     /* see CVG_RT_STA_CLAMBER_TF_SR_TH */
 | |
|     uint8_t         clamber_tf_sr_th;
 | |
|     /* see CVG_RT_STA_CLAMBER_TARGET_TF_SR_TH */
 | |
|     uint8_t         clamber_target_tf_sr_th;
 | |
|     /* see CVG_RT_STA_PROXY_TF_SR_RANK */
 | |
|     uint8_t         proxy_tf_sr_rank;
 | |
|     /* see CVG_RT_STA_ROAM_LEARNING_CNT */
 | |
|     uint8_t         roam_learn_cnt;
 | |
|     /* 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;
 | |
|     /* 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 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;
 | |
|     /* 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;
 | |
|     /* 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;
 | |
|     /* dual mode device tx config, 0 - invalid, 1 - async tx, 2 - sync tx */
 | |
|     uint8_t         dm_tx_cfg           :2,
 | |
|     /* flag to mark if rf tx power is valid */
 | |
|                     rf_power_valid      :1,
 | |
|     /* flag to mark if force link communication */
 | |
|                     force_link_valid    :1,
 | |
|     /* force link type, 0 - force hplc, 1 - force rf */
 | |
|                     force_rf_link       :1,
 | |
|     /* reserved for future */
 | |
|                     rsvd                :3;
 | |
|     /* simple pair passcode */
 | |
|     uint16_t        passcode;
 | |
| } mac_bc_vendor_spec_t;
 | |
| 
 | |
| /* htbus fixed information descriptor */
 | |
| typedef struct _mac_bc_htbus_fp {
 | |
|     /* htbus becacon type, see PLC_HTBUS_BC_TYPE_XXX */
 | |
|     uint8_t   type;
 | |
|     /* reboot counter */
 | |
|     uint8_t   reboot_cnt;
 | |
|     /* reques period counter */
 | |
|     uint16_t  req_period_cnt;
 | |
| } mac_bc_htbus_fp_t;
 | |
| 
 | |
| /* habus time slot alloc entry */
 | |
| typedef struct _mac_bc_htbus_time_slot {
 | |
|     /* cco slot duration, uint is 1ms */
 | |
|     uint8_t     cco_slot;
 | |
|     /* sta slot duration, uint is 1ms */
 | |
|     uint8_t     sta_slot;
 | |
|     /* beacon period start NTB  */
 | |
|     uint32_t    start_ntb;
 | |
|     /* node tei bitmap with response slot assigned.
 | |
|      */
 | |
|     uint8_t     rsp_bm[iot_ceil(PLC_TEI_MAX_NUM, 8)];
 | |
| } mac_bc_htbus_time_slot_t;
 | |
| 
 | |
| /* htbus user data entry */
 | |
| typedef struct _mac_bc_htbus_user_data {
 | |
|     /* user data length */
 | |
|     uint16_t    len;
 | |
|     /* pointer user data */
 | |
|     uint8_t     *data_ptr;
 | |
| } mac_bc_htbus_user_data_t;
 | |
| 
 | |
| /*
 | |
|  * @brief   update beacon payload to be broadcast by mac
 | |
|  * @param vdev_id:  mac vdev id of the device to be updated
 | |
|  * @param ent:      beacon entries to be updated
 | |
|  * @param tx_cnt:   return beacon tx count of this update
 | |
|  *
 | |
|  * @return:
 | |
|  *      0         -- for success case
 | |
|  *      othersie  -- error code
 | |
|  */
 | |
| uint32_t mac_update_beacon(uint8_t pdev_id, uint8_t vdev_id,
 | |
|     mac_bc_update_t *ent, uint8_t *tx_cnt);
 | |
| 
 | |
| /*
 | |
|  * function callback to receive beacons from mac
 | |
|  * @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 of a new beacon
 | |
|  *              period
 | |
|  */
 | |
| typedef void (*mac_bc_rx_func_t)(void *arg, iot_pkt_t *beacon, uint8_t new_bp);
 | |
| 
 | |
| #if (PLC_SUPPORT_CCO_ROLE)
 | |
| 
 | |
| /*
 | |
|  * mac_start_beacon() - start sending beacon
 | |
|  * @pdev_id:    mac pdev id of the device to start sending beacon
 | |
|  * @vdev_id:    mac vdev id of the device to start sending beacon
 | |
|  *
 | |
|  * return:
 | |
|  *      0         -- for success case
 | |
|  *      othersie  -- error code
 | |
|  */
 | |
| uint32_t mac_start_beacon(uint8_t pdev_id, uint8_t vdev_id);
 | |
| 
 | |
| /*
 | |
|  * mac_stop_beacon() - stop sending beacon
 | |
|  * @pdev_id:    mac pdev id of the device to stop sending beacon
 | |
|  * @vdev_id:    mac vdev id of the device to stop sending beacon
 | |
|  *
 | |
|  * return:
 | |
|  *      0         -- for success case
 | |
|  *      othersie  -- error code
 | |
|  */
 | |
| uint32_t mac_stop_beacon(uint8_t pdev_id, uint8_t vdev_id);
 | |
| 
 | |
| #else /* PLC_SUPPORT_CCO_ROLE */
 | |
| 
 | |
| #define mac_start_beacon(pdev_id, vdev_id) IOT_ASSERT(0)
 | |
| 
 | |
| #define mac_stop_beacon(pdev_id, vdev_id) IOT_ASSERT(0)
 | |
| 
 | |
| #endif /* PLC_SUPPORT_CCO_ROLE */
 | |
| 
 | |
| 
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* MAC_BCM_API_H */
 |