329 lines
11 KiB
C
329 lines
11 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 IOT_SG_STA_GW_H
|
|
#define IOT_SG_STA_GW_H
|
|
|
|
/* os shim includes */
|
|
#include "os_types_api.h"
|
|
|
|
/* common includes */
|
|
#include "iot_pkt_api.h"
|
|
#include "iot_errno_api.h"
|
|
/* smart grid internal header files */
|
|
#include "iot_sg_fr.h"
|
|
#include "proto_gw_app.h"
|
|
#include "iot_plc_msg_api.h"
|
|
#include "iot_sg_ext_sta_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#if (IOT_SMART_GRID_ENABLE && PLC_SUPPORT_STA_ROLE && IOT_GW_APP_ENABLE)
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_sec_check - gw protocol security check.
|
|
* @param data: the pointer to header in gw application protocol data.
|
|
* @param len: length of data.
|
|
* @param is_mr_pkt: the pointer to the flag of meter read request data.
|
|
* @retval: ERR_OK -- check success.
|
|
* @retval: ERR_INVAL -- check fail.
|
|
*/
|
|
uint32_t iot_sg_sta_gw_sec_check(uint8_t *data, uint32_t len,
|
|
bool_t *is_mr_pkt);
|
|
|
|
/**
|
|
* @brief: compare gw sequeue in application protocol data.
|
|
* @param dst_hdr: pointer to first nw application protocol data header
|
|
* to compare.
|
|
* @param src_hdr: pointer to second nw application protocol data header
|
|
* to compare.
|
|
* @retval: 1 -- the sequeue is the same.
|
|
* @retval: 0 -- the sequeue isn't the same.
|
|
*/
|
|
uint8_t iot_sg_sta_gw_sn_cmp(uint8_t *dst_hdr, uint8_t *src_hdr);
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_get_pm_addr - get pm address in pkt.
|
|
* @param pkt: the iot_pkt with application protocol data in it.
|
|
* @param addr: the pointer to address cache.
|
|
* @retval: ERR_OK -- get the address successfully.
|
|
* @retval: ERR_FAIL -- get address failure.
|
|
*/
|
|
uint32_t iot_sg_sta_gw_get_pm_addr(iot_pkt_t *pkt, uint8_t *addr);
|
|
|
|
/**
|
|
* @brief: check if cached data for the request exist.
|
|
* @param pkt: the iot_pkt with application protocol data in it
|
|
* @param link_type: link type, see IOT_SG_LINK_TYPE_XXX.
|
|
* @retval: ERR_OK -- cache not exist
|
|
* @retval: ERR_EXIST -- cache exist
|
|
*/
|
|
uint32_t iot_sg_sta_gw_queue_app_cache_check(iot_pkt_t *pkt,
|
|
uint8_t link_type);
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_queue_app_drop - drop gw request in queue.
|
|
* @param hdr: the pointer to header of req data.
|
|
* @param reason: reason of drop request.
|
|
*/
|
|
void iot_sg_sta_gw_queue_app_drop(uint8_t *hdr, uint8_t reason);
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_parse_mr_frame - parse gw meter reading data.
|
|
* @param hdr: the pointer to header of application protocol data.
|
|
* @retval: otherwise -- parse fail
|
|
* @retval: ERR_OK -- parse mr frame successfully.
|
|
*/
|
|
uint32_t iot_sg_sta_gw_parse_mr_frame(uint8_t *hdr);
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_mr_counter_inc - gw meter reading counter.
|
|
* @param hdr: the pointer to header of application protocol data.
|
|
*/
|
|
void iot_sg_sta_gw_mr_counter_inc(uint8_t *hdr);
|
|
|
|
/**
|
|
* @brief: send gw bitmap power off event message.
|
|
* @param msg_type: type of message, see IOT_PLC_MSG_TYPE_XXX
|
|
* @retval: ERR_OK - event sent out successfully.
|
|
* @retval: otherwise - error code. see ERR_XXX
|
|
*/
|
|
uint32_t iot_sg_sta_gw_pd_evt_bm_send(uint8_t msg_type);
|
|
|
|
/**
|
|
* @brief: send gw address power off event message.
|
|
* @param msg_type: type of message, see IOT_PLC_MSG_TYPE_XXX
|
|
* @retval: ERR_OK - event sent out successfully.
|
|
* @retval: otherwise - error code. see ERR_XXX
|
|
*/
|
|
uint32_t iot_sg_sta_gw_pd_evt_addrs_send(uint8_t msg_type);
|
|
|
|
/**
|
|
* @brief: send gw power on event message.
|
|
* @param flag_bcast: flag of bcast.
|
|
* @retval: ERR_OK - event sent out successfully.
|
|
* @retval: otherwise - error code. see ERR_XXX
|
|
*/
|
|
uint32_t iot_sg_sta_gw_power_on_evt_send(uint8_t flag_bcast);
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_sm_done_evt_send() - report the search meter results
|
|
* by event. currently, it is only used for Zhejiang II collector.
|
|
* @param pm_cnt: pm report count.
|
|
* @retval: ERR_OK - event sent out successfully.
|
|
* @retval: otherwise - error code. see ERR_XXX
|
|
*/
|
|
uint32_t iot_sg_sta_gw_sm_done_evt_send(uint8_t pm_cnt);
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_event_send - send gw event message.
|
|
* @param addr: mac address of the power meter of the event
|
|
* @param data_ptr: pointer to the event data.
|
|
* @param len: length size of event data.
|
|
* @param new_evt 0: the event isn't new, 1: the event is new.
|
|
* @param rpt_type: report event type, see IOT_SG_STA_RPT_XXX_XXX_EVT.
|
|
* @retval: ERR_OK - event sent out successfully.
|
|
* @retval: otherwise - error code. see ERR_XXX
|
|
*/
|
|
uint32_t iot_sg_sta_gw_event_send(uint8_t *addr, uint8_t *data_ptr,
|
|
uint32_t len, uint8_t new_evt, uint8_t rpt_type);
|
|
|
|
/**
|
|
* @brief: iot_sg_sta_gw_event_send_with_seq - send gw event message with seq.
|
|
* @param addr: mac address of the power meter of the event
|
|
* @param data_ptr: pointer to the event data.
|
|
* @param len: length size of event data.
|
|
* @param seq: message sequence.
|
|
* @param rpt_type: report event type, see IOT_SG_STA_RPT_XXX_XXX_EVT.
|
|
* @retval: ERR_OK - event sent out successfully.
|
|
* @retval: otherwise - error code. see ERR_XXX
|
|
*/
|
|
uint32_t iot_sg_sta_gw_event_send_with_seq(uint8_t *addr, uint8_t *data_ptr,
|
|
uint32_t len, uint16_t seq, uint8_t rpt_type);
|
|
|
|
/**
|
|
* @brief: handle guo wang app protocol for GW_APP_PORT_UPGRADE
|
|
* this function always consume the pkt.
|
|
* @param pkt: the iot_pkt with gw upgrade data in it.
|
|
*/
|
|
void iot_sg_sta_gw_handle_app_upgrade(iot_pkt_t *pkt);
|
|
|
|
/**
|
|
* @brief: send a start ack reply to CCo
|
|
* @param id: upgrading session id
|
|
* @param msg_type: type for sending the message
|
|
* @param result: result to the start upgrading command
|
|
*/
|
|
void iot_sg_sta_gw_send_start_ack(uint32_t id, uint8_t msg_type,
|
|
uint32_t result);
|
|
|
|
/**
|
|
* @brief: send query reply to STA
|
|
* @param id: upgrading session id
|
|
* @param start_seq: sn of the 1st block being queried
|
|
* @param status: STA's upgrading status
|
|
* @param cnt: number of available block in the bitmap
|
|
* @param bitmap_pkt: an iot_pkt with bitmap in its data block
|
|
* @param msg_type: msg_type used to send the reply
|
|
*/
|
|
void iot_sg_sta_gw_send_query_reply(uint32_t id, uint32_t start_seq,
|
|
uint16_t status, uint16_t cnt, iot_pkt_t *bitmap_pkt, uint8_t msg_type);
|
|
|
|
/*
|
|
* @brief: check if the block size is available for gw upgrading
|
|
* @param block_size: gw upgrading block size
|
|
* @return: 1 if block size is valid. 0 if invalid.
|
|
*/
|
|
uint32_t iot_sg_sta_gw_is_valid_block_size(uint32_t block_size);
|
|
|
|
/**
|
|
* @brief: gw tsfm query neighbor node info response.
|
|
* @param rpt: neighbor node info from cvg report.
|
|
*/
|
|
void iot_sg_sta_gw_tsfm_neighbor_snr_info_resp(iot_plc_neighbor_dev_rpt_t *rpt);
|
|
|
|
/**
|
|
* @brief: build a neutralwire and livewire abnormal event report package.
|
|
* @param cnt: neutralwire and livewire abnormal event count.
|
|
* @param data: neutralwire and livewire abnormal event info.
|
|
* @retval: NULL -- for failure.
|
|
* @retval: pkt -- the iot pkt buffer for gw event data.
|
|
*/
|
|
iot_pkt_t *iot_sg_sta_gw_nli_evt_build(uint16_t cnt, gw_app_nli_abnormal_data_t *data);
|
|
|
|
/**
|
|
* @brief: rtc update handle
|
|
* @param ts: ts for the delta between cco rtc and the
|
|
* base timer 2000.1.1 00:00:00, unit is 1s.
|
|
* @param cco_ntb: cco ntb of corresponding date, unit is 1NTB.
|
|
*/
|
|
void iot_sg_sta_gw_rtc_update_rpt(uint32_t ts, uint32_t cco_ntb);
|
|
|
|
#else /* IOT_SMART_GRID_ENABLE && PLC_SUPPORT_STA_ROLE && IOT_GW_APP_ENABLE */
|
|
|
|
#define iot_sg_sta_gw_sec_check(data, total_len, is_mr_pkt) (ERR_INVAL)
|
|
|
|
#define iot_sg_sta_gw_sn_cmp(dst_hdr, src_hdr) (0)
|
|
|
|
#define iot_sg_sta_gw_get_pm_addr(pkt, addr) (ERR_FAIL)
|
|
|
|
#define iot_sg_sta_gw_queue_app_cache_check(pkt, link_type) (ERR_EXIST)
|
|
|
|
#define iot_sg_sta_gw_queue_app_drop(hdr, reason)
|
|
|
|
#define iot_sg_sta_gw_parse_mr_frame(hdr) (ERR_FAIL)
|
|
|
|
#define iot_sg_sta_gw_mr_counter_inc(hdr)
|
|
|
|
#define iot_sg_sta_gw_pd_evt_bm_send(msg_type) (ERR_NOT_EXIST)
|
|
|
|
#define iot_sg_sta_gw_pd_evt_addrs_send(msg_type) (ERR_NOT_EXIST)
|
|
|
|
#define iot_sg_sta_gw_power_on_evt_send(flag_bcast) (ERR_NOT_EXIST)
|
|
|
|
#define iot_sg_sta_gw_sm_done_evt_send(pm_cnt) (ERR_NOT_EXIST)
|
|
|
|
#define iot_sg_sta_gw_event_send(addr, data_ptr, len, new_evt, \
|
|
rpt_type) (ERR_FAIL)
|
|
|
|
#define iot_sg_sta_gw_event_send_with_seq(addr, data_ptr, \
|
|
len, seq, rpt_type) (ERR_FAIL)
|
|
|
|
#define iot_sg_sta_gw_handle_app_upgrade(pkt) IOT_ASSERT(0)
|
|
|
|
#define iot_sg_sta_gw_send_start_ack(id, msg_type, result)
|
|
|
|
#define iot_sg_sta_gw_send_query_reply(id, start_seq, status, cnt, \
|
|
bitmap_pkt, msg_type)
|
|
|
|
#define iot_sg_sta_gw_is_valid_block_size(block_size) (0)
|
|
|
|
#define iot_sg_sta_gw_tsfm_neighbor_snr_info_resp(rpt)
|
|
|
|
#define iot_sg_sta_gw_nli_evt_build(cnt, data) (NULL)
|
|
|
|
#define iot_sg_sta_gw_rtc_update_rpt(ts, cco_ntb)
|
|
|
|
#endif /* IOT_SMART_GRID_ENABLE && PLC_SUPPORT_STA_ROLE && IOT_GW_APP_ENABLE */
|
|
|
|
/**
|
|
* @brief: ihandle gw meter read response from driver.
|
|
* @param data_type: type of response data.
|
|
* @param done_src: meter read operation done source,
|
|
* see IOT_SG_STA_MR_DONE_BY_XXX.
|
|
* @param rsp_pkt: the rsp_pkt with response data in it
|
|
*/
|
|
void iot_sg_sta_gw_mr_done_intern(uint8_t data_type, uint8_t done_src,
|
|
iot_pkt_t *rsp_pkt);
|
|
|
|
/**
|
|
* @brief: handle gw other message.
|
|
* this function always consume the pkt.
|
|
* @param pkt: the iot_pkt with application protocol data in it.
|
|
* @retval: ERR_OK - case successfully.
|
|
* @retval: otherwise - error code. see ERR_XXX
|
|
*/
|
|
uint32_t iot_sg_sta_gw_handle_app_other(iot_pkt_t *pkt);
|
|
|
|
/**
|
|
* @brief: handle gw plc message.
|
|
* this function always consume the pkt.
|
|
* @param pkt: the iot_pkt with gw message in it.
|
|
* @param data: msdu data payload in pkt.
|
|
*/
|
|
void iot_sg_sta_gw_msg_handle(iot_pkt_t *pkt,
|
|
uint8_t *data);
|
|
|
|
/**
|
|
* @brief: handle gw ctrl protocol message.
|
|
* this function always consume the pkt.
|
|
* @param pkt: the iot_pkt with gw message in it.
|
|
*/
|
|
void iot_sg_sta_gw_ctrl_proto_msg_handle(iot_pkt_t *pkt);
|
|
|
|
/**
|
|
* @brief: tsfm result send for pw.
|
|
* @param dst: final destination mac address.
|
|
* @param seq: packet sequence.
|
|
* @param node_info: same tsfm node info.
|
|
* @param node_info_len: node info len.
|
|
*/
|
|
uint32_t iot_sg_sta_gw_tsfm_result_send_pw(uint8_t *dst, uint16_t seq,
|
|
iot_sg_ext_cus_same_tsfm_node_resp_t *node_info, uint16_t node_info_len);
|
|
|
|
/**
|
|
* @brief: gw protocol correct time format check.
|
|
* @param data: data.
|
|
* @param len: data len.
|
|
* @retval: ERR_OK -- check success.
|
|
* @retval: otherwise -- check false, see ERR_XXX.
|
|
*/
|
|
uint32_t iot_sg_sta_gw_correct_time_req_check(uint8_t *data, uint32_t len);
|
|
|
|
/**
|
|
* @brief: gw plc connectionless forwarding message check.
|
|
* @param pkt: the iot_pkt with gw message in it.
|
|
* @retval: ERR_OK -- check success.
|
|
* @retval: otherwise -- check false, see ERR_XXX.
|
|
*/
|
|
uint32_t iot_sg_sta_gw_conn_fwd_msg_check(iot_pkt_t *pkt);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IOT_SG_STA_GW_H */
|