367 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			367 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
| 
 | |
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
| be copied by any method or incorporated into another program without
 | |
| the express written consent of Aerospace C.Power. This Information or any portion
 | |
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
| liability for its use in any way and conveys no license or title under
 | |
| any patent or copyright and makes no representation or warranty that this
 | |
| Information is free from patent or copyright infringement.
 | |
| 
 | |
| ****************************************************************************/
 | |
| 
 | |
| #ifndef CVG_APP_H
 | |
| #define CVG_APP_H
 | |
| 
 | |
| /* os shim includes */
 | |
| #include "os_types.h"
 | |
| #include "os_task.h"
 | |
| #include "os_event.h"
 | |
| 
 | |
| /* common includes */
 | |
| #include "iot_pkt_api.h"
 | |
| #include "iot_ipc.h"
 | |
| #include "iot_config.h"
 | |
| 
 | |
| /* public api includes */
 | |
| #include "plc_mac_header.h"
 | |
| #include "plc_conn_less.h"
 | |
| 
 | |
| /* cvg layer includes */
 | |
| #include "cvg.h"
 | |
| #include "cvg_prm.h"
 | |
| #include "iot_plc_msg_api.h"
 | |
| #include "iot_plc_msg_sta_api.h"
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| /* record the appid and msdu type map */
 | |
| typedef struct _cvg_app_record {
 | |
|     /* msdu type is the same as app id */
 | |
|     uint8_t msdu_type;
 | |
|     /* default priority */
 | |
|     uint8_t default_prio;
 | |
|     /* flasg mark to if app sniffer enables */
 | |
|     uint8_t app_sniffer_en  : 1,
 | |
|     /* reserved for further use */
 | |
|             rsvd            : 7;
 | |
|     /* app ipc address */
 | |
|     iot_ipc_addr_t addr;
 | |
| } cvg_app_record_t;
 | |
| 
 | |
| extern iot_ipc_h ipc_h;
 | |
| extern iot_ipc_addr_t plc_lib_bcast;
 | |
| 
 | |
| /**
 | |
|  * @brief    cvg_find_app_record()  - find the app slot by msdu type
 | |
|  * @param    msdu_type:   msdu type
 | |
|  *
 | |
|  * @retval:  NULL -- failure case
 | |
|  * @retval:  otherwise -- the corresponding slot of the msdu type
 | |
|  */
 | |
| cvg_app_record_t* cvg_find_app_record(uint8_t msdu_type);
 | |
| 
 | |
| /**
 | |
|  * @brief    cvg_find_available_app_record()  - try to find an available slot
 | |
|  * @brief                                       for new app
 | |
|  *
 | |
|  * @retval:  NULL -- failure case
 | |
|  * @retval:  otherwise -- slot for new app
 | |
|  */
 | |
| cvg_app_record_t* cvg_find_available_app_record();
 | |
| 
 | |
| /**
 | |
|  * @brief  cvg_cvg_get_default_vdev() - get default vdev to opearte on.
 | |
|  *
 | |
|  * @retval:   NULL -- error case
 | |
|  * @retval:   otherwise -- pointer to vdev
 | |
|  */
 | |
| cvg_vdev_t* cvg_get_default_vdev();
 | |
| 
 | |
| /**
 | |
|  * @brief  cvg_app_set_msdu_mac_and_sr() - set src mac, dest mac and
 | |
|                                    communication successful ratio to MSDU packet.
 | |
|  *                                  this implement support both CCO role and
 | |
|  *                                  STA role.
 | |
|  * @param msdu:       the msdu packet
 | |
|  * @param vdev:       pointer to current vdev
 | |
|  * @param src_tei:    tei of source device.
 | |
|  * @param dst_tei:    tei of original destination device.
 | |
|  */
 | |
| void cvg_app_set_msdu_mac_and_sr(iot_plc_msdu_recv_t *msdu, cvg_vdev_t *vdev,
 | |
|     tei_t src_tei, tei_t dst_tei);
 | |
| 
 | |
| /* @brief   report msdu to app layer
 | |
|  * @param buf:      buf containing msdu packet
 | |
|  * @param mac:      mac header of the msdu
 | |
|  * @param app_id    application id of this msdu
 | |
|  */
 | |
| void cvg_app_report_msdu_to_app(iot_pkt_t *buf, void *mac, uint8_t app_id);
 | |
| 
 | |
| /* @brief cvg_app_report_msdu_capture_to_app - report captured msdu to app layer
 | |
|  * @param mac:      mac header of the msdu
 | |
|  * @param data:     app data of the msdu
 | |
|  * @param len:      app data len of the msdu
 | |
|  * @param app_id:   application id of the msdu
 | |
|  */
 | |
| void cvg_app_report_msdu_capture_to_app(uint8_t *mac, uint8_t *data, uint32_t len,
 | |
|     uint8_t app_id);
 | |
| 
 | |
| /* @brief cvg_app_report_conn_less_data_to_app - report a connectionless data
 | |
|  *      message to app.
 | |
|  * @param buf:    - buf containing connectionless data
 | |
|  * @param mac:    - mac header of the msdu.
 | |
|  * @param cl_hdr: - header of connectionless data
 | |
|  * @param app_id: - application id of this msdu
 | |
|  */
 | |
| void cvg_app_report_conn_less_data_to_app(iot_pkt_t *buf,
 | |
|     void *mac, plc_conn_less_hdr_t *cl_hdr, uint8_t app_id);
 | |
| 
 | |
| /* @brief cvg_app_report_ctrl_proto_msdu_to_app() - report the data defined by
 | |
|  *        the controller protocol to app.
 | |
|  * @param buf:    - buf containing msdu packet
 | |
|  * @param mac:    - mac header of the msdu.
 | |
|  * @paran data:   - pointer to the start position of the app data.
 | |
|  * @param app_id: - application id of this msdu
 | |
|  */
 | |
| void cvg_app_report_ctrl_proto_msdu_to_app(iot_pkt_t *buf, void *mac,
 | |
|     uint8_t *data, uint8_t app_id);
 | |
| 
 | |
| /* @brief cvg_app_bcast_ctrl_proto_state_rpt() - report state of connection of
 | |
|  *        controller protocol.
 | |
|  *        Note: this connection behavior is defined in the controller protocol.
 | |
|  * @param vdev:   - vdev pointer
 | |
|  * @param addr:   - remote dev addr connected to it.
 | |
|  * @param role:   - remote dev role connected to it, see IOT_PLC_DEV_ROLE_XXX.
 | |
|  * @param state:  - state, see IOT_PLC_CTRL_PROTO_STATE_XXXX.
 | |
|  * @param reason: - reasons of change state change.
 | |
|  *                  see IOT_PLC_CTRL_PROTO_DISCONN_REASON_XXX and
 | |
|  *                  IOT_PLC_CTRL_PROTO_CONN_REASON_XXX.
 | |
|  * @param sn:       remote dev sn.
 | |
|  */
 | |
| void cvg_app_bcast_ctrl_proto_state_rpt(cvg_vdev_t *vdev,
 | |
|     uint8_t *addr, uint8_t role, uint8_t state, uint8_t reason, uint8_t sn);
 | |
| 
 | |
| /* cvg_app_bcast_dev_state_change() - broadcast when device state changed
 | |
|  * cvg layer broadcast this info when state of cvg layer state changed:
 | |
|  * 1. CCo enter started state. CCo is ready to serve app.
 | |
|  * 2. CCo leave started state. CCo cannot serve app.
 | |
|  * 3. STA associated with CCo. STA is ready to serve app.
 | |
|  * 4. STA disassociated with CCo. STA cannot serve app.
 | |
|  *
 | |
|  * @vdev:   point to the vdev whose state changed
 | |
|  */
 | |
| void cvg_app_bcast_dev_state_change(cvg_vdev_t *vdev);
 | |
| 
 | |
| /**
 | |
|  * @brief cvg_app_bcast_invalid_mac() -  broadcast notification to app
 | |
|  *                                       layer MAC address is invalid.
 | |
|  * @param vdev:     pointer to vdev
 | |
|  * @param nid:      network id.
 | |
|  * @param cco_addr: reject cco mac addr.
 | |
|  * @param reason:   the reasons for the invalid MAC addr,
 | |
|  *                  see IOT_PLC_INVD_MAC_XXX.
 | |
|  */
 | |
| void cvg_app_bcast_invalid_mac(cvg_vdev_t *vdev, uint32_t nid,
 | |
|     uint8_t *cco_addr, uint8_t reason);
 | |
| 
 | |
| /* @brief cvg_app_bcast_local_phase_updated() - broadcast to all apps when phase
 | |
|  *     of the local device state changed.
 | |
|  * @param vdev:     pointer to vdev
 | |
|  */
 | |
| void cvg_app_bcast_local_phase_updated(cvg_vdev_t *vdev);
 | |
| 
 | |
| /* @brief cvg_app_bcast_alloc_lid() - broadcast allocated lid to application
 | |
|  * @param vdev:      pointer to vdev
 | |
|  * @param dcsma_lid: allocated dcsma lid
 | |
|  * @param tdma_lid:  allocated tdma lid
 | |
|  */
 | |
| void cvg_app_bcast_alloc_lid(cvg_vdev_t *vdev, uint8_t dcsma_lid,
 | |
|     uint8_t tdma_lid);
 | |
| 
 | |
| /*
 | |
| * @brief - convert band scan table to bitmap.
 | |
| * @param scan_band:  band scan table to be converted
 | |
| * @param band_cnt:   band count in scan table
 | |
| * @param band_bm:    pointer to buffer of band bitmap
 | |
| * @param bm_size:    size of band bitmap
 | |
| * @return:           none
 | |
| */
 | |
| void cvg_app_convert_scan_tbl_to_bitmap(plc_scan_band_t *scan_band,
 | |
|     uint8_t band_cnt, uint8_t *band_bm, uint8_t bm_size);
 | |
| 
 | |
| #if HPLC_RF_DEV_SUPPORT
 | |
| 
 | |
| /* @brief   report single hop msdu to app layer
 | |
|  * @param buf:      buf containing msdu packet
 | |
|  * @param s_mac:    mac header of the msdu
 | |
|  * @param app_id    application id of this msdu
 | |
|  * @param stei:     source tei come from fc
 | |
|  * @param dtei:     destination tei come from fc
 | |
|  * @param is_bcast: flag to mark if this packet is broadcast packet
 | |
|  */
 | |
| void cvg_app_report_single_hop_msdu_to_app(iot_pkt_t *buf,
 | |
|     void *s_mac, uint8_t app_id, tei_t stei,
 | |
|     tei_t dtei, uint8_t is_bcast);
 | |
| 
 | |
| #endif /* HPLC_RF_DEV_SUPPORT */
 | |
| 
 | |
| #if (PLC_SUPPORT_CCO_ROLE)
 | |
| 
 | |
| /* @brief:          add info of STA leaving to iot_pkt
 | |
|  * @param pkt:      the iot_pkt to store STA info
 | |
|  * @param tei:      tei of the STA leaving
 | |
|  * @param proxy:    proxy tei of the STA leaving
 | |
|  * @param mac_addr: mac address of the STA leaving
 | |
|  *
 | |
|  * @return:
 | |
|  *   0:         pkt can stored more STA info.
 | |
|  *   otherwise: pkt cannot stored more STA info. cvg_app_bcast_sta_leave_info
 | |
|  *              shall be called for the pkt.
 | |
|  */
 | |
| uint8_t cvg_app_add_leave_sta_info(iot_pkt_t *pkt, uint16_t tei,
 | |
|     uint16_t proxy, uint8_t *mac_addr);
 | |
| 
 | |
| /* @brief:          add info STA that state is offline to iot_pkt
 | |
|  * @param pkt:      the iot_pkt to store STA info
 | |
|  * @param tei:      tei of the offline STA
 | |
|  * @param proxy:    proxy tei of the offline STA
 | |
|  * @param mac_addr: mac address of the offline STA
 | |
|  *
 | |
|  * @return:
 | |
|  *   0:         pkt can stored more STA info.
 | |
|  *   otherwise: pkt cannot stored more STA info. cvg_app_bcast_sta_offline_info
 | |
|  *              shall be called for the pkt.
 | |
|  */
 | |
| uint8_t cvg_app_add_offline_sta_info(iot_pkt_t *pkt, uint16_t tei,
 | |
|     uint16_t proxy, uint8_t *mac_addr);
 | |
| 
 | |
| /* @brief:          add info of STA phase update to iot_pkt
 | |
|  * @param pkt:      the iot_pkt to store STA info
 | |
|  * @param peer:     pointer to the peer of STA
 | |
|  *
 | |
|  * @return:
 | |
|  *   0:         pkt can stored more STA info.
 | |
|  *   otherwise: pkt cannot stored more STA info. cvg_app_bcast_sta_phase_info
 | |
|  *              shall be called for the pkt.
 | |
|  */
 | |
| uint8_t cvg_app_add_sta_phase_info(iot_pkt_t *pkt, cvg_peer_info_t *peer);
 | |
| 
 | |
| /* @brief:      broadcast device joining msg to apps
 | |
|  * @param vdev: vdev pointer
 | |
|  * @param peer: peer of the associated device
 | |
|  */
 | |
| void cvg_app_bcast_sta_join_info(cvg_vdev_t *vdev, cvg_peer_info_t *peer);
 | |
| 
 | |
| /* @brief:      broadcast device online msg to apps
 | |
|  * @param vdev: vdev pointer
 | |
|  * @param peer: peer of the off-line to on-line device
 | |
|  */
 | |
| void cvg_app_bcast_sta_online_info(cvg_vdev_t *vdev, cvg_peer_info_t *peer);
 | |
| 
 | |
| /*
 | |
|  * @brief:      bcast to all apps when STA's phase info updated
 | |
|  * @param vdev: vdev pointer
 | |
|  * @param peer: peer of the associated device
 | |
|  */
 | |
| void cvg_app_bcast_sta_phase_updated(cvg_vdev_t *vdev, cvg_peer_info_t *peer);
 | |
| 
 | |
| /* cvg_app_bcast_sta_leave_info() - broadcast device leaving msg to apps
 | |
|  * @pkt:    the pkt contains the device leaving messages to be broadcast to apps
 | |
|  * @reason: reason of leave this network
 | |
|  */
 | |
| void cvg_app_bcast_sta_leave_info(iot_pkt_t *pkt, uint8_t reason);
 | |
| 
 | |
| /* cvg_app_bcast_sta_offline_info() - broadcast device offline state msg to apps
 | |
|  * @pkt:    the pkt contains the device offline messages to be broadcast to apps
 | |
|  */
 | |
| void cvg_app_bcast_sta_offline_info(iot_pkt_t *pkt);
 | |
| 
 | |
| /* cvg_app_bcast_sta_phase_info() - broadcast device phase msg to apps
 | |
|  * @pkt:    the pkt contains the device phase messages to be broadcast to apps
 | |
|  */
 | |
| void cvg_app_bcast_sta_phase_info(iot_pkt_t *pkt);
 | |
| 
 | |
| /*
 | |
|  * @brief:      bcast to all apps when STA join request rejected
 | |
|  * @param vdev:         vdev pointer
 | |
|  * @param addr:         mac address of the sta. big endian.
 | |
|  * @param addr_type:    mac address type of the sta.
 | |
|  *                      see IOT_PLC_MAC_ADDR_TYPE_XXX
 | |
|  * @param dev_type:     device type of the sta. see IOT_PLC_DEV_TYPE_XXX
 | |
|  * @param vendor_id:    vendor id of the sta
 | |
|  * @param reason:       rejected reason. see IOT_PLC_REASON_XXX.
 | |
|  */
 | |
| void cvg_app_bcast_sta_join_rejected(cvg_vdev_t *vdev, uint8_t *addr,
 | |
|     uint8_t addr_type, uint8_t dev_type, uint16_t vendor_id, uint8_t reason);
 | |
| 
 | |
| /*
 | |
|  * @brief:      bcast to all apps when STA proxy changed
 | |
|  * @param vdev: vdev pointer
 | |
|  * @param peer: peer of the proxy changed device
 | |
|  */
 | |
| void cvg_app_bcast_sta_proxy_changed(cvg_vdev_t *vdev, cvg_peer_info_t *peer);
 | |
| 
 | |
| /* @brief:      broadcast to all apps when apps load updated
 | |
|  * @param vdev: vdev pointer
 | |
|  */
 | |
| void cvg_app_bcast_app_load_updated(cvg_vdev_t *vdev);
 | |
| 
 | |
| #endif /* PLC_SUPPORT_CCO_ROLE */
 | |
| 
 | |
| #if PLC_SUPPORT_STA_ROLE
 | |
| 
 | |
| /* @brief       broadcast beacon data to application
 | |
|  * @param vdev: pointer to vdev that received the beacon
 | |
|  * @param data: pointer to the beacon data
 | |
|  * @param len:  length of the beacon data
 | |
|  */
 | |
| void cvg_app_bcast_beacon_data(cvg_vdev_t *vdev, uint8_t *data, uint8_t len);
 | |
| 
 | |
| /* @brief       broadcast discovered node to application
 | |
|  * @param vdev: pointer to vdev
 | |
|  * @param rpt:  pointer to the node info to be reported
 | |
|  */
 | |
| void cvg_app_bcast_discovered_node(cvg_vdev_t *vdev,
 | |
|     iot_plc_discovery_node_rpt_t *rpt);
 | |
| 
 | |
| /* @brief            broadcast rtc update to application
 | |
|  * @param vdev:      pointer to vdev
 | |
|  * @param cco_date:  stand for the delta between cco rtc and
 | |
|                      the base timer 2000.1.1 00:00:00
 | |
|  * @param cco_ntb:   cco ntb of corresponding date, unit is 1NTB
 | |
|  */
 | |
| void cvg_app_bcast_rtc_update(cvg_vdev_t *vdev,
 | |
|     uint32_t cco_date, uint32_t cco_ntb);
 | |
| 
 | |
| #endif /* PLC_SUPPORT_STA_ROLE */
 | |
| 
 | |
| /* cvg_app_handle_msg() - handle request from app
 | |
|  * @addr:   addr of the app sending the request
 | |
|  * @pkt:    iot_pkt containing the app request
 | |
|  */
 | |
| void cvg_app_handle_msg(iot_ipc_addr_t *addr, iot_pkt_t *pkt);
 | |
| 
 | |
| /* iot_ipc_register_cvg() - register cvg to ipc module
 | |
|  */
 | |
| void iot_ipc_register_cvg();
 | |
| 
 | |
| /* iot_ipc_deregister_cvg() - deregister cvg from ipc module
 | |
|  */
 | |
| void iot_ipc_deregister_cvg();
 | |
| 
 | |
| /* cvg_app_get_link_statistics() - get plc link statistics
 | |
|  */
 | |
| void cvg_app_get_link_statistics(iot_plc_link_statistics_t *stat);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* CVG_APP_H */
 |