/**************************************************************************** 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_H #define CVG_H /* os shim includes */ #include "os_types.h" #include "os_task.h" #include "os_event.h" /* common includes */ #include "iot_mem_pool.h" #include "iot_queue.h" #include "iot_utils.h" #include "iot_task.h" #include "iot_pkt_api.h" #include "iot_plc_msg_api.h" /* public api includes */ #include "cvg_api.h" #include "cvg_bitmap.h" #include "plc_protocol.h" #include "plc_utils.h" #include "plc_fr.h" #include "mac_data_api.h" #include "mac_uni_cfg_api.h" #ifdef __cplusplus extern "C" { #endif /* virtual device event definitions */ typedef enum { cvg_vdev_event_start = 1, cvg_vdev_event_stop, cvg_vdev_event_timeout, cvg_vdev_event_new_bp, cvg_vdev_event_bc_rx, cvg_vdev_event_sof_rx, cvg_vdev_event_cco_snr_rx, cvg_vdev_event_bp_end_alert, cvg_vdev_event_nid_rpt, cvg_vdev_event_zc_ntb_rpt, cvg_vdev_event_zc_status_rpt, cvg_vdev_event_wbl_changed, cvg_vdev_event_crypto_done, } cvg_vdev_event_t; /* cvg layer virtual device descriptor */ typedef struct _cvg_vdev { /* vdev id */ uint8_t id; /* mac vdev id */ uint8_t mac_vdev_id; /* device role */ uint8_t role; /* protocol supported */ uint8_t proto; /* flag to mark if cert test command ever detected */ uint8_t cert_test_detected; /* flag to mark if power collapsed */ uint8_t pw_collapsed :1, /* flag to mark if allow all APP data TX in power collapsed status */ ignore_pw_collapsed :1, /* reserved for future */ rsvd :6; /* record the sn of zc status report */ uint8_t zc_status_sn; /* flag to record the power frequency */ uint8_t power_freq :4, /* record the maximum zc phase collected */ zc_phase_cnt :4; /* vdev mac address */ uint8_t addr[IOT_MAC_ADDR_LEN]; /* record the count of flash log */ uint16_t flash_log_cnt; /* vdev total start count */ uint32_t total_start_cnt; /* vdev total start count */ uint8_t start_reason_cnt[CVG_VDEV_START_REASON_NUMBER]; /* app data broadcast tx total count */ uint32_t app_data_tx_bc_cnt; /* app data unicast tx total count */ uint32_t app_data_tx_uc_cnt; /* app data broadcast tx drop total count */ uint32_t app_data_tx_bc_drop_cnt; /* app data unicast tx drop total count */ uint32_t app_data_tx_uc_drop_cnt; /* app data broadcast rx total count */ uint32_t app_data_rx_bc_cnt; /* app data unicast rx total count */ uint32_t app_data_rx_uc_cnt; /* app data broadcast rx report to app total count */ uint32_t app_data_rx_bc_rpt_cnt; /* app data unicast rx report to app total count */ uint32_t app_data_rx_uc_rpt_cnt; /* app data msdu forward total count */ uint32_t app_data_fwd_cnt; /* app data broadcast rf rx total count */ uint32_t app_data_rf_rx_bc_cnt; /* app data unicast rf rx total count */ uint32_t app_data_rf_rx_uc_cnt; /* app data msdu rf forward total count */ uint32_t app_data_rf_fwd_cnt; /* app data broadcast rf rx report to app total count */ uint32_t app_data_rf_rx_bc_rpt_cnt; /* app data unicast rf rx report to app total count */ uint32_t app_data_rf_rx_uc_rpt_cnt; /* app data conn less tx total count */ uint32_t app_data_tx_conn_less_cnt; /* app data conn less tx drop total count */ uint32_t app_data_tx_conn_less_drop_cnt; /* app data conn less rx total count */ uint32_t app_data_rx_conn_less_cnt; /* app data conn less rx report to app total count */ uint32_t app_data_rx_conn_less_rpt_cnt; /* app data unicast rx capture report to app total count */ uint32_t app_data_rx_uc_cap_rpt_cnt; /* app data broadcast rx capture report to app total count */ uint32_t app_data_rx_bc_cap_rpt_cnt; /* mme data tx total count */ uint32_t app_data_tx_cnt; /* app data rx total count */ uint32_t app_data_rx_cnt; /* mme data rx total count */ uint32_t mme_data_tx_cnt; /* mme data rx total count */ uint32_t mme_data_rx_cnt; /* mme data rf tx total count */ uint32_t app_data_rf_tx_cnt; /* app data rf rx total count */ uint32_t app_data_rf_rx_cnt; /* mme data rf rx total count */ uint32_t mme_data_rf_tx_cnt; /* mme data rf rx total count */ uint32_t mme_data_rf_rx_cnt; /* route handler */ void *rt; /* peer management handler */ void *prm; /* bandwidth management handler */ void *bwm; /* network management handler */ void *nwm; /* security handler */ void *sec; } cvg_vdev_t; /* cvg layer physical device descriptor */ typedef struct _cvg_pdev { /* vdev pointer array */ cvg_vdev_t *vdev_array[CVG_MAX_VDEV_PER_PDEV]; } cvg_pdev_t; /* cvg layer global descriptor */ typedef struct _cvg_global { /* configurations from cvg module init */ cvg_cfg_t cfg; /* pdev pointer array */ cvg_pdev_t *pdev_array[CVG_MAX_PDEV]; /* cvg task configuration */ iot_task_config_t task_cfg; /* cvg task handle */ iot_task_h task_h; } cvg_global_t; /* cvg global internal structure */ extern cvg_global_t *p_cvg_glb; /* sof rx buf info */ typedef struct cvg_rx_sof_buf { /* cache plaintext sof */ iot_pkt_t *buf_plaintext; /* cache encrypted sof */ iot_pkt_t *buf_encrypted; } cvg_rx_sof_buf_t; /* * @brief cvg_init_rx_sof_buf() - initialize rx_sof_buf * @param sof_buf: initialized rx sof buffer * @param buf: rx sof * @param is_encrypt: whether the buf is encrypted */ void cvg_init_rx_sof_buf(cvg_rx_sof_buf_t *sof_buf, iot_pkt_t *buf, uint8_t is_encrypt); /* * @brief cvg_get_rx_sof_buf() - get plaintext buf from rx_sof_buf * @param sof_buf: rx sof buffer * return: plaintext buffer if valid, overwise encrypted buffer */ iot_pkt_t *cvg_get_rx_sof_buf(cvg_rx_sof_buf_t *sof_buf); /* * @brief cvg_get_and_clear_rx_sof_buf() - get plaintext buf from * rx_sof_buf and free rx sof buffer * @param sof_buf: rx sof buffer * return: plaintext buffer if valid, overwise encrypted buffer */ iot_pkt_t *cvg_get_and_clear_rx_sof_buf(cvg_rx_sof_buf_t *sof_buf); /* * @brief cvg_free_rx_sof_buf() - free rx sof buffer * @param sof_buf: rx sof buffer */ void cvg_free_rx_sof_buf(cvg_rx_sof_buf_t *sof_buf); /* * cvg_find_vdev_by_id - find vdev by vdev id * @glb: pointer of cvg global data * @id: vdev id to be searched. The upper 4 bits is pdev array index, * and the lower 4 bits is vdev array index. * * return: * NULL -- if no vdev found * otherwise -- pointer to vdev */ cvg_vdev_t *cvg_find_vdev_by_id(cvg_global_t* glb, uint8_t id); /* * cvg_get_global_cfg - get global configurations */ cvg_cfg_t *cvg_get_global_cfg(); /* * @brief cvg_save_pib_cfg() - save configuration into pib. * @param inc_sn: flag to mark if network sn should be increased while * saving the configuration to pib. * @param save_band: flag to mark if band id configuration shall be saved. * @param save_rf_channel: flag to mark if rf channel & option shall be saved. */ void cvg_save_pib_cfg(uint8_t inc_sn, uint8_t save_band, uint8_t save_rf_channel); /* * cvg_stop_vdev_internal - stop vdev * @vdev: pointer of cvg vdev to be stopped */ void cvg_stop_vdev_internal(cvg_vdev_t *vdev); /* cvg_get_wl_entry_count - get entry count in whitelist * @vdev pointer to cvg vdev * * return: * entry count of the whitelist */ uint16_t cvg_get_wl_entry_count(cvg_vdev_t *vdev); /* cvg_get_bl_entry_count - get entry count in blacklist * @vdev pointer to cvg vdev * * return: * entry count of the blacklist */ uint16_t cvg_get_bl_entry_count(cvg_vdev_t *vdev); /* cvg_convert_id_to_index - covert vdev id to pdev and vdev index * @id: vdev id to be converted * @pdev_index: pdev index. output parameter. * @vdev_index: vdev index. output parameter. */ void cvg_convert_id_to_index(uint8_t id, uint8_t *pdev_index, uint8_t *vdev_index); /* * @brief cvg_get_vdev_config() - get vdev configuration. * @param vdev: vdev to be retrieved * * @retval NULL -- for failure case * @retval otherwise -- pointer to vdev configration. */ cvg_vdev_cfg_t *cvg_get_vdev_config(cvg_vdev_t *vdev); /* * @brief cvg_gen_nid() - generate network id * @param proto: proto of the network * @param vendor: vendor id of the device * @param max_nid: allowed maximum nid * * @retval generate network id */ uint32_t cvg_gen_nid(uint8_t proto, uint16_t vendor, uint16_t max_nid); /* * @brief cvg_rf_channel_is_valid() - check if the rf channel is valid * @param rf_channel: rf channel to be checked * @param rf_option: using own option to check when rf option is invalid, * using the option passed in to check when rf option * is valid * * @retval 1 - valid, 0 - invalid */ uint8_t cvg_rf_channel_is_valid(uint8_t rf_channel, uint8_t rf_option); /* * @brief cvg_band_is_valid() - check if the hplc band id is valid * @param band_id: hplc band id to be checked * * @retval 1 - valid, 0 - invalid */ uint8_t cvg_band_is_valid(uint8_t band_id); /* * @brief cvg_gen_rf_channel() - generate rf channel id and option id * @param rf_op: generate rf option * @param rf_chn: generate rf channel * @return * ERR_OK - success, otherwise - failed */ uint8_t cvg_gen_rf_channel(uint8_t *rf_op, uint8_t *rf_chn); /* * @brief cvg_clear_rf_select_bm() - clear rf select bitmap */ void cvg_clear_rf_select_bm(); /* * @brief cvg_set_rf_select_bm() - set rf channel state to rf select bitmap * @param rf_op: rf option * @param rf_chn: rf channel * @param selected: set value of rf channel */ void cvg_set_rf_select_bm(uint8_t rf_op, uint8_t rf_chn, uint8_t selected); /* * @brief cvg_get_rf_scan_dur() - get rf scan duration * @param vdev: pointer to vdev * @retval: rf scan duration */ uint32_t cvg_get_rf_scan_dur(cvg_vdev_t *vdev); /* * @brief get rf scan duration when no network is found * @param vdev: pointer to vdev * @retval: rf scan minimum duration */ uint32_t cvg_get_rf_scan_min_dur(cvg_vdev_t *vdev); /* * @brief set hplc scan tbl * @param vdev: the vdev to be set * @param plc_scan_tbl: pointer to plc scan table * @param band_cnt: valid count in plc scan table * @param set_mac: flag to mark if plc scan table set to mac * @return * ERR_OK - success, otherwise - failed */ uint32_t cvg_set_plc_scan_tbl(cvg_vdev_t *vdev, plc_scan_band_t *plc_scan_tbl, uint8_t band_cnt, uint8_t set_mac); /** * @brief cvg query scan or support band table. * @param is_scan: 0: get support band table. * 1: get scan band table. * @param scan_band: pointer to buffer of scan band. * @param count: max band count to be queried. * @retval: band count of the queried */ uint8_t cvg_get_plc_scan_tbl(uint8_t is_scan, plc_scan_band_t *scan_band, uint8_t count); /* * @brief send cvg data to mac layer * @param vdev: the vdev on which data will be sent * @param msdu_buf: the buffer containing the msdu data to be sent. * msdu data is containted in data block of the iot_pkt. * @param tx_info: tx descriptor * * @return * ERR_OK - for successful case * otherwise - for failed case */ uint32_t cvg_send_msdu(cvg_vdev_t *vdev, iot_pkt_t* msdu_buf, mac_tx_info *tx_info); /* * @brief send app data to mac layer * @param vdev: the vdev on which data will be sent * @param msdu_buf: the buffer containing the msdu data to be sent. * msdu data is containted in data block of the iot_pkt. * @param tx_info: tx descriptor * * @return * ERR_OK - for successful case * otherwise - for failed case */ uint32_t cvg_send_app_msdu(cvg_vdev_t *vdev, iot_pkt_t* msdu_buf, mac_tx_info *tx_info); /* * @brief enable or disable fixed rate for dedicated vdev * @param vdev: the vdev to be set * @param enable: 1 - enable, 0 - disable * @param rate_level: fixed rate level, see PLC_RATE_ADAPT_RATE_XXX */ void cvg_enable_fixed_rate(cvg_vdev_t *vdev, uint8_t enable, uint8_t rate_level); /* * @brief enable or disable force phase tx * @param vdev: the vdev to be set * @param enable: 1 - enable, 0 - disable * @param phase: phase, see IOT_PLC_PHASE_XXX */ void cvg_enable_force_phase(cvg_vdev_t *vdev, uint8_t enable, uint8_t phase); /* * @brief set sta joined flag. * @param join_flag: 1 - joined, 0 - not joined */ void cvg_enable_sta_joined(cvg_vdev_t *vdev, uint8_t join_flag); /* * @brief enable or disable sw agc. * @param enable: 1 - enable, 0 - disable * * @return * ERR_OK - for successful case * otherwise - for failed case */ uint32_t cvg_enable_swagc(uint8_t enable); /* * @brief enable or disable neighbour network negotiation. * @param enable: 1 - enable, 0 - disable */ void cvg_enable_nw_nego(cvg_vdev_t *vdev, uint8_t enable); /* * @brief set 3ps sta physical phase is L/N opposite. * @param opposite_3ps: 1 - opposite, 0 - not opposite */ void cvg_enable_3ps_opposite(cvg_vdev_t *vdev, uint8_t opposite_3ps); /* * @brief get noise floor of local device * * @return * 1 ~ 63 which is mapped from noise floor range 31 ~ 93. */ uint8_t cvg_get_local_nf(); /** * @brief set network lock status * @param vdev: pointer to vdev * @param enable: if NULL - not set network lock state. * 0 - disable network lock. * 1 - enable network lock. * @param tsfm_addr: transformer mac address, if NULL, not set tsfm_addr. * @param nor_lock_time: network lock time, 0 means no lock. uint is 1min. * @param abn_lock_time: the lock time of abnormal leave network, * 0 means no lock. uint is 1min. * @param unlock_delay: network unlock delay time, unit is 1min. */ void cvg_set_nw_lock(cvg_vdev_t *vdev, uint32_t *enable, uint8_t *tsfm_addr, uint16_t *nor_lock_time, uint16_t *abn_lock_time, uint16_t *unlock_delay); /** * @brief set network monitor & ident enable status * @param vdev: pointer to vdev * @param enable: 0 - disable, 1 - enable. * @param wl_notify_enable: flag to mark if white list notification enable, * invalid for sta role case. 0 - disable, 1 - enable. * @param zc_notify_enable: flag to mark if zc ntb notification enable, * invalid for sta role case. 0 - disable, 1 - enable. */ void cvg_set_nw_monitor_enable(cvg_vdev_t *vdev, uint32_t enable, uint32_t wl_notify_enable, uint32_t zc_notify_enable); /** * @brief cvg_get_zc_status_sn() - get the sn of zc status report * @param vdev: pointer to vdev * @return: the value of sn */ uint8_t cvg_get_zc_status_sn(cvg_vdev_t *vdev); /** * @brief cvg_record_zc_status_sn() - record the sn of zc status report * @param vdev: pointer to vdev * @return: none */ void cvg_record_zc_status_sn(cvg_vdev_t *vdev); /* * @brief cvg_set_pkt_capture() - set the tei bitmap to be captured * to capture application layer frames. only supports capture * the packets matching destination tei. * @param nwm: pointer to vdev * @param bm: tei bitmap * @param enable: enable capture. 0 - disable, 1 - enable. * @return: return all captured tei bitmap. */ cvg_tei_map_t *cvg_set_pkt_capture(cvg_vdev_t *vdev, cvg_tei_map_t *bm, uint8_t enable); /** * @brief cvg_set_pw_config() - set power config * @param vdev: pointer to vdev * @param ignore_pw_collapsed: flag to mark if allow all APP data TX in power * collapsed status */ void cvg_set_pw_config(cvg_vdev_t *vdev, uint8_t ignore_pw_collapsed); /* * @brief enable or disable power save function for dedicated vdev * @param vdev: the vdev to be set * @param allow_sleep: allow sleep or not */ void cvg_set_pm_save_cfg(cvg_vdev_t *vdev, uint8_t allow_sleep); /* * @brief get tx 3phase flag. * @return: non 0 means enable tx 3phase, 0 means disable tx 3phase. */ uint8_t cvg_get_tx_3phase_flag(); /* * @brief cvg get plc ppm table * @param vdev: the vdev to be set * @param ppm_tbl: point to ppm table, length not less than * PLC_MAX_NEIGHBOR_NETWORK * @return uint8_t: vaild nid cnt */ uint8_t cvg_get_plc_ppm_tbl(cvg_vdev_t *vdev, plc_ppm_status_t *ppm_tbl); /* * @brief cvg_get_txrx_sw_gpio_phase_valid() - get txrx switch phase valid * @return: 0 - is invalid, 1 - is valid */ uint8_t cvg_get_txrx_sw_gpio_phase_valid(); /* * @brief convert addr type from meter to repeater * @param repeater_addr: save the converted result * @param meter_addr: meter address to be converted * @param rand_num: association random number, and it will be updated */ void cvg_addr_convert_meter_to_repeater(uint8_t *repeater_addr, uint8_t *meter_addr, uint32_t *rand_num); /* * @brief convert addr type from repeater to meter * @param meter_addr: save the converted result * @param repeater_addr: repeater address to be converted * @param rand_num: association random number */ void cvg_addr_convert_repeater_to_meter(uint8_t *meter_addr, uint8_t *repeater_addr, uint32_t *rand_num); #ifdef __cplusplus } #endif #endif /* CVG_H */