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

559 lines
18 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_RT_H
#define CVG_RT_H
/* os shim includes */
#include "os_types.h"
/* public api includes */
#include "plc_utils.h"
#include "plc_protocol.h"
#include "plc_fr.h"
#include "mac_bcm_api.h"
/* cvg module internal includes */
#include "cvg_prm.h"
#include "cvg_bitmap.h"
#ifdef __cplusplus
extern "C" {
#endif
/* path serial number check result definition */
#define CVG_RT_PATH_SN_OBSOLETE 0 /* obsolete path sn */
#define CVG_RT_PATH_SN_SAME 1 /* same as current path sn */
#define CVG_RT_PATH_SN_NEW 2 /* newer than current path sn */
/* define how many times we need to check the abnormal status in one route
* period. we need to check some abnormal status multiple times in each route
* period to increase the accuracy. If this value defined to 0, it means
* we check abnormal status once in each route period. if this value defined
* to 1, it means we check abnormal status twice in each route period and so
* on.
*/
#define CVG_RT_PARTIAL_RP_NUM 7
/*
* cvg_rt_init() - global init of route module
* @glb: pointer of cvg global data
* @cfg: pointer of cvg configuration
*
* return:
* 0 -- for success case
* othersie -- error code
*/
uint32_t cvg_rt_init(cvg_global_t *glb, cvg_cfg_t *cfg);
/*
* cvg_rt_init_vdev() - vdev init of route module
* @vdev: pointer of vdev to be init
* @cfg: pointer of vdev configuration
*
* return:
* 0 -- for success case
* othersie -- error code
*/
uint32_t cvg_rt_init_vdev(cvg_vdev_t *vdev, cvg_vdev_cfg_t *cfg);
/*
* cvg_rt_deinit_vdev() - vdev deinit of route module
* @vdev: pointer of vdev to be deinit
*/
void cvg_rt_deinit_vdev(cvg_vdev_t *vdev);
/*
* cvg_rt_reset_vdev() - vdev reset of route module
* @vdev: pointer of vdev to be init
* @cfg: pointer of vdev configuration
*/
void cvg_rt_reset_vdev(cvg_vdev_t *vdev, cvg_vdev_cfg_t *cfg);
/*
* cvg_rt_vdev_start_rt_period() - start route period
* @vdev: pointer to vdev
* @tx_req: flag to mark if discovery node list mme tx required or not
*/
void cvg_rt_vdev_start_rt_period(cvg_vdev_t *vdev, uint8_t tx_req);
/*
* cvg_rt_vdev_stop_rt_period() - stop route period
* @vdev: pointer to vdev
* @clear_data: flag to mark if current route period data should be cleared
*/
void cvg_rt_vdev_stop_rt_period(cvg_vdev_t *vdev, uint8_t clear_data);
/*
* cvg_rt_route_timeout() - route period timeout function
* @vdev: pointer to vdev
*/
void cvg_rt_route_timeout(cvg_vdev_t *vdev);
/*
* cvg_rt_partial_rp_timeout() - route period timeout function
* @vdev: pointer to vdev
*/
void cvg_rt_partial_rp_timeout(cvg_vdev_t *vdev);
/*
* cvg_rt_get_next_hop() - get next hop tei of the target
* @vdev: pointer to vdev
* @dest: tei of the final destination
* @link: link type of the next hop
*
* return: tei of the next hop
*/
tei_t cvg_rt_get_next_hop(cvg_vdev_t *vdev, tei_t dest, uint8_t *link);
/*
* @brief extended verion of get next hop tei of the target
* @param vdev: pointer to vdev
* @param prev_hop: tei of previous hop of the packet. set to
* PLC_TEI_INVAL if it's not available.
* @param dest: tei of the final destination
* @param main_path_only: 1 to use main path only. 0 to allow to use back up
* path.
* @param link: link type of next hop, see PLC_LINK_TYPE_XXX.
*
* @return tei of the next hop
*/
tei_t cvg_rt_get_next_hop_ext(cvg_vdev_t *vdev, tei_t prev_hop, tei_t dest,
uint8_t main_path_only, uint8_t *link);
/*
* cvg_rt_is_dl_rt() - get route entry direction to tei
* @vdev: pointer to vdev
* @dest: tei of the final destination
*
* return:
* 0 -- the direction to destination is not downlink or no route entry
* to the destination
* 1 -- the direction to destination is downlink
*/
uint8_t cvg_rt_is_dl_rt(cvg_vdev_t *vdev, tei_t dest);
/*
* cvg_rt_is_ul_rt() - get route entry direction to tei
* @vdev: pointer to vdev
* @dest: tei of the final destination
*
* return:
* 0 -- the direction to destination is not uplink or no route entry
* to the destination
* 1 -- the direction to destination is uplink
*/
uint8_t cvg_rt_is_ul_rt(cvg_vdev_t *vdev, tei_t dest);
/*
* @brief update candidate pco list according to the tei bitmap
* @param vdev: pointer to vdev
* @param bm: pointer to tei bitmap to be checked
* @param base_level: base level while calculating proxy score
* @param base_rf_hop: base rf hop while calculating proxy score
* @param ignore_tf_sr: flag to mark if traffic success ratio should be
* calculated into proxy score
* @param ignore_hplc: flag to mark if ignore hplc link pco
* @param ignore_rf: flag to mark if ignore rf link pco
*/
void cvg_rt_check_proxy_bm(cvg_vdev_t *vdev, cvg_tei_map_t *bm,
uint8_t base_level, uint8_t base_rf_hop, uint8_t ignore_tf_sr,
uint8_t ignore_hplc, uint8_t ignore_rf);
/*
* cvg_rt_rm_cand_proxy() - remove the candidate proxy
* @vdev: pointer to vdev
* @tei_t: tei of the proxy to be removed
*/
void cvg_rt_rm_cand_proxy(cvg_vdev_t *vdev, tei_t proxy);
/*
* @brief get the candidate proxy list
* @param vdev: pointer to vdev
* @param proxy: pointer to buffer to receive the tei list of proxy. this
* buffer must large enough to save CANDIDATE_PROXY_COUNT
* of proxy. the better the proxy, the lower the array
* index.
* @param ignore_proxy: flag to mark if required to compare with current proxy
* while choose the candidate proxy.
* @param base_level: base level while calculating proxy score. this value
* will take effect while ignore_proxy is false.
* @param base_rf_hop: base rf_hop while calculating proxy score. this value
* will take effect while ignore_proxy is false.
*
* @return: number of avaible proxy in the list. should be no larger than
* CANDIDATE_PROXY_COUNT.
*/
uint8_t cvg_rt_get_cand_proxy(cvg_vdev_t *vdev, pco_link_info_t *proxy,
uint8_t ignore_proxy, uint8_t base_level, uint8_t base_rf_hop);
/*
* cvg_rt_sta_add_dest() - add route entry
* @vdev: pointer to vdev
* @proxy: tei of the proxy of the destination
* @dest: tei of the destination
* @path_sn: path serial number of this route entry. set 0 if the path sn
* is not available.
* @link: link type of dest, see PLC_LINK_TYPE_XXX
*/
void cvg_rt_sta_add_dest(cvg_vdev_t *vdev, tei_t proxy, tei_t dest,
uint32_t path_sn, uint8_t link);
/*
* cvg_rt_rm_next_hop() - clean up route entries related to the next hop
* @vdev: pointer to vdev
* @next_hop: tei of the next_hop
* @path_sn: path serial number of this route entry. set 0 if the path sn
* is not available.
*/
void cvg_rt_rm_next_hop(cvg_vdev_t *vdev, tei_t next_hop, uint32_t path_sn);
/*
* cvg_rt_rm_dest() - clean up route entry to the dest
* @vdev: pointer to vdev
* @dest: tei of the destination
* @path_sn: path serial number of this route entry. set 0 if the path sn
* is not available.
*/
void cvg_rt_rm_dest(cvg_vdev_t *vdev, tei_t dest, uint32_t path_sn);
/*
* @brief clean up back up route entry to the dest
* @param vdev: pointer to vdev
* @param dest: tei of the destination
*/
void cvg_rt_rm_backup_dest(cvg_vdev_t *vdev, tei_t dest);
/*
* @brief add back up route entry to the dest
* @param vdev: pointer to vdev
* @param next_hop: tei of the backup next hop
* @param dest: tei of the destination
*/
void cvg_rt_add_backup_dest(cvg_vdev_t *vdev, tei_t next_hop, tei_t dest);
/*
* cvg_rt_add_dl_dest() - add downlink route entry
* @vdev: pointer to vdev
* @next_hop: tei of next hop
* @dest: tei of the destination
* @path_sn: path serial number of this route entry. set 0 if the path sn
* is not available.
* @link: link type of next hop, see PLC_LINK_TYPE_XXX
*/
void cvg_rt_add_dl_dest(cvg_vdev_t *vdev, tei_t next_hop, tei_t dest,
uint32_t path_sn, uint8_t link);
/*
* cvg_rt_add_dl_dest_bm() - add multiple downlink route entries
* @vdev: pointer to vdev
* @next_hop: tei of next hop
* @bm: tei bitmap of the destination
* @path_sn: path serial number of this route entry. set 0 if the path sn
* is not available.
* @link: link type of next hop, see PLC_LINK_TYPE_XXX
*/
void cvg_rt_add_dl_dest_bm(cvg_vdev_t * vdev, tei_t next_hop,
cvg_tei_map_t *bm, uint32_t path_sn, uint8_t link);
/*
* cvg_rt_add_dl_dest() - check path serial number against a destination
* @vdev: pointer to vdev
* @dest: tei of the destination
* @new_pn: path sn to be checked
*
* return:
* check result. see CVG_RT_PATH_SN_XXX.
*/
uint32_t cvg_rt_pn_check(cvg_vdev_t *vdev, tei_t dest, uint32_t new_pn);
/*
* cvg_rt_get_rp_dur() - get current network route period duration
* @vdev: pointer to vdev
*
* return
* the duration of the route period. the unit is 1s.
*/
uint16_t cvg_rt_get_rp_dur(cvg_vdev_t *vdev);
/*
* @brief cvg_rt_inc_bc_tx() - notify routing module that a new beacon sent out.
* @param vdev: vdev which sent out the beacon.
*/
void cvg_rt_inc_bc_tx(cvg_vdev_t *vdev);
/*
* cvg_rt_set_allowed_cco_tf_sr() - set allowed to cco traffic success ratio
* @vdev: pointer to vdev
* @cco_tf_sr: value to be set
*/
void cvg_rt_set_allowed_cco_tf_sr(cvg_vdev_t *vdev, uint8_t cco_tf_sr);
/*
* cvg_rt_get_allowed_cco_tf_sr() - get allowed to cco traffic success ratio
* @vdev: pointer to vdev
*
* return
* the allowed to cco traffic success ratio of current network.
*/
uint8_t cvg_rt_get_allowed_cco_tf_sr(cvg_vdev_t *vdev);
/*
* @brief cvg_rt_get_retry_cnt() - get suggested retry count for unicast sof
* to the peer.
* @param vdev: pointer to vdev
* @param peer: pointer to the peer of next hop
*
* @return the suggested retry count. no larger than PLC_MAX_SEND_CNT.
*/
uint8_t cvg_rt_get_retry_cnt(cvg_vdev_t *vdev, cvg_peer_info_t *peer);
/**
* @brief cvg_rt_dis_node_timeout() - discover node mme send timeout
* @param vdev: pointer to vdev
*/
void cvg_rt_dis_node_timeout(cvg_vdev_t *vdev);
/*
* @brief cvg_rt_is_peer_hplc_reachable() - check if the peer hplc link
* reachable
* @param vdev: pointer to vdev
* @param peer: pointer to peer to be checked
*
* @retval 0 - peer is not reachable
* @retval 1 - peer is reachable
*/
uint8_t cvg_rt_is_peer_hplc_reachable(cvg_vdev_t *vdev, cvg_peer_info_t *peer);
/*
* @brief dump rt 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_rt_status_dump(cvg_vdev_t *vdev);
#if (PLC_SUPPORT_CCO_ROLE)
/*
* cvg_rt_cco_add_dest() - add routing entry to the specified remote peer
* @vdev: pointer of vdev to be added
* @dest: tei of the remote peer
* @path_sn: path serial number of this route entry. set 0 if the path sn
* is not available.
* @link: link type of dest, see PLC_LINK_TYPE_XXX
*/
void cvg_rt_cco_add_dest(cvg_vdev_t *vdev, tei_t dest, uint32_t path_sn,
uint8_t link);
/*
* cvg_rt_cco_rp_check() - check if route period parameters need to be updated
* @vdev: pointer of vdev to be checked
*/
void cvg_rt_cco_rp_check(cvg_vdev_t *vdev);
/*
* cvg_rt_cco_bp_end_alert() - beacon period end alert notification callback
* of rt module
* @vdev: pointer of vdev
*/
void cvg_rt_cco_bp_end_alert(cvg_vdev_t *vdev);
/*
* @brief cvg_rt_cco_fill_vendor_threshold_data() - fill threshold data info to
* vendor beacon entry
* @param vendor: pointer to vendor beacon entry
*/
void cvg_rt_cco_fill_vendor_threshold_data(mac_bc_vendor_spec_t *vendor);
#endif /* PLC_SUPPORT_CCO_ROLE */
#if PLC_SUPPORT_STA_ROLE
/*
* @brief cvg_rt_local_level_changed() - local device level changed notification
* callback. This function will update local route entry accordingly.
* @param vdev: pointer to vdev
*/
void cvg_rt_local_level_changed(cvg_vdev_t *vdev);
/**
* @brief cvg_rt_heart_beat_timeout() - heart beat report period timeout
* function
* @param vdev: pointer to vdev
*/
void cvg_rt_heart_beat_timeout(cvg_vdev_t *vdev);
/**
* @brief cvg_rt_heart_beat_fast_rpt() - fast heart beat report
* @param vdev: pointer to vdev
*/
void cvg_rt_heart_beat_fast_rpt(cvg_vdev_t *vdev);
/**
* @brief cvg_rt_tf_sr_report_timeout() - traffic success ratio report period
* timeout function
* @param vdev: pointer to vdev
* @param pco_snr_rpt: flag to mark if pco snr report should be sent
*/
void cvg_rt_tf_sr_report_timeout(cvg_vdev_t *vdev, uint8_t pco_snr_rpt);
/*
* cvg_rt_set_main_proxy() - appoint the main proxy
* @vdev: pointer to vdev
* @proxy: tei of the main proxy to be set
* @link: link type to proxy, see PLC_LINK_TYPE_XXX
* @path_sn: path serial number of this route entry. set 0 if the path sn
* is not available.
*/
void cvg_rt_set_main_proxy(cvg_vdev_t *vdev, tei_t proxy, uint8_t link,
uint32_t path_sn);
/*
* @brief - check the best phase of cco peer. cco peer support 3 phases, we
* should decide the best phase to connect with if we can see the cco
* peer.
* @param vdev: pointer to vdev
*
* @return
* NULL - no phase is available.
* otherwise - pointer to best phase cco peer.
*/
cvg_peer_info_t *cvg_rt_check_best_cco_phase(cvg_vdev_t *vdev);
/*
* @brief - check if current network cco support 3 phase traffic success ratio
* calculation separately.
* @param vdev: pointer to vdev
*
* @return
* 0 - do not support
* otherwise - support
*/
uint8_t cvg_rt_is_cco_3_phase_tf_sr(cvg_vdev_t *vdev);
/*
* @brief cvg_rt_save_threshold_date() - save the vendor threshold data info
* @param vdev: pointer to vdev
* @param vendor: pointer to bc vendor
*/
void cvg_rt_save_threshold_date(cvg_vdev_t *vdev, mac_bc_vendor_spec_t *vendor);
/*
* @brief get roam learning count
* @param vdev: pointer to vdev
*
* @return: roam learning count. unit is 1 route period.
*/
uint8_t cvg_rt_sta_get_roam_learn_cnt(cvg_vdev_t *vdev);
/*
* @brief cvg_rt_check_peer_possible_link() - evaluate possible link of peer
* @param vdev: pointer to vdev
* @param peer: pointer to peer
*
* @return: possible link type, see PLC_LINK_TYPE_RF
*/
uint8_t cvg_rt_check_peer_possible_link(cvg_vdev_t *vdev, cvg_peer_info_t *peer);
/*
* @brief cvg_rt_handle_rp() - handle route period parameters
* @vdev: pointer to vdev
* @rp: route parameters to be updated
* @tx_req: flag to mark if discovery node list mme tx required or not
* @retval: ERR_OK - for success case, otherwise -- error code
*/
uint32_t cvg_rt_handle_rp(cvg_vdev_t *vdev, mac_bc_rt_param_t *rp,
uint8_t tx_req);
#else /* PLC_SUPPORT_STA_ROLE */
#define cvg_rt_local_level_changed(vdev)
#define cvg_rt_heart_beat_timeout(vdev)
#define cvg_rt_heart_beat_fast_rpt(vdev)
#define cvg_rt_tf_sr_report_timeout(vdev, pco_snr_rpt)
#define cvg_rt_set_main_proxy(vdev, proxy, link, path_sn)
#define cvg_rt_check_best_cco_phase(vdev) (NULL)
#define cvg_rt_is_cco_3_phase_tf_sr(vdev) (0)
#define cvg_rt_save_threshold_date(vdev, vendor)
#define cvg_rt_check_peer_possible_link(vdev, peer) (PLC_LINK_TYPE_UNKNOWN)
#endif /* PLC_SUPPORT_STA_ROLE */
/* @brief calculate accumulated rx snr according the snr history
* of previous received packets.
*
* @param vdev: pointer of the peer to be calculated
* @param rx_snr: rx snr of the new received packets
*/
void cvg_rt_calc_peer_rx_snr(cvg_peer_info_t *peer, int8_t rx_snr);
/* @brief calculate accumulated tx snr according the snr history
* of previous received packets.
*
* @param vdev: pointer of the peer to be calculated
* @param rx_snr: rx snr of the new received packets
* @param nf: noise floor of the peer
*/
void cvg_rt_calc_peer_tx_snr(cvg_peer_info_t *peer, int8_t rx_snr, uint8_t nf);
/**
* @brief cvg_rt_self_peer_info_changed() - notify route module that self
* peer info changed
* @param vdev: pointer to vdev
*/
void cvg_rt_self_peer_info_changed(cvg_vdev_t *vdev);
#if CVG_RT_DEBUG
/**
* @brief cvg_rt_info_dump() - dump route info.
* @param vdev: pointer to vdev to be dumped
*/
void cvg_rt_info_dump(cvg_vdev_t *vdev);
/**
* @brief cvg_rt_debug_check() - check route debug information
* @param vdev: pointer to vdev to be checked
*
* @retval:
* 0 - restart not required
* otherwise - restart required
*/
uint32_t cvg_rt_debug_check(cvg_vdev_t *vdev);
#else /* CVG_RT_DEBUG */
#define cvg_rt_info_dump(vdev)
#define cvg_rt_debug_check(vdev) (0)
#endif
#ifdef __cplusplus
}
#endif
#endif /* CVG_RT_H */