385 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			385 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 IOT_SG_STA_NW_H
 | 
						|
#define IOT_SG_STA_NW_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"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
#if (PLC_SUPPORT_STA_ROLE && IOT_NW_APP_ENABLE)
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: iot_sg_sta_nw_sec_check - nw protocol security check.
 | 
						|
 * @param data: the pointer to header in nw 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_nw_sec_check(uint8_t *data, uint32_t len,
 | 
						|
    bool_t *is_mr_pkt);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: compare nw 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_nw_sn_cmp(uint8_t *dst_hdr, uint8_t *src_hdr);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: 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_nw_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_nw_queue_app_cache_check(iot_pkt_t *pkt,
 | 
						|
    uint8_t link_type);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: drop nw request in queue.
 | 
						|
 * @param  hdr: the pointer to header of req data.
 | 
						|
 * @param  reason: reason of drop request.
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_queue_app_drop(uint8_t *hdr, uint8_t reason);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: parse nw 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_nw_parse_mr_frame(uint8_t *hdr);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: nw meter reading counter.
 | 
						|
 * @param  hdr: the pointer to header of application protocol data.
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_mr_counter_inc(uint8_t *hdr);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: send nw 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_nw_pd_evt_bm_send(uint8_t msg_type);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: send nw 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_nw_pd_evt_addrs_send(uint8_t msg_type);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief:  send nw 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_nw_power_on_evt_send(uint8_t flag_bcast);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: send nw 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_nw_event_send(uint8_t *addr, uint8_t *data_ptr,
 | 
						|
    uint32_t len, uint8_t new_evt, uint8_t rpt_type);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: send nw event message with custom 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 seq number of this event message
 | 
						|
 * @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
 | 
						|
 * @date 2023-11-04
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_event_send_with_seq(uint8_t *addr, uint8_t *data_ptr,
 | 
						|
    uint32_t len, uint16_t seq, uint8_t rpt_type);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: handle nan wang app protocol for GW_APP_PORT_UPGRADE
 | 
						|
 *         this function always consume the pkt.
 | 
						|
 * @param pkt: the iot_pkt with nw upgrade data in it.
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_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_nw_send_start_ack(uint32_t id, uint8_t msg_type,
 | 
						|
    uint32_t result);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: send a upgrade data ack reply to CCo
 | 
						|
 * @param id: upgrading session id
 | 
						|
 * @param result: result to the upgrad data command
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_send_upgrade_data_ack(uint32_t id, uint32_t result);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: send a finishe ack reply to CCo
 | 
						|
 * @param id: upgrading session id
 | 
						|
 * @param msg_type: type for sending the message
 | 
						|
 * @param result: result to the finish upgrading command
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_send_exe_ack(uint32_t id, uint8_t msg_type,
 | 
						|
    uint32_t result);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: send a stop upgrade ack reply to CCo
 | 
						|
 * @param id: upgrading session id
 | 
						|
 * @param result: result to the stop upgrading command
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_send_stop_ack(uint32_t id, 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 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_nw_send_query_reply(uint32_t id, uint32_t start_seq,
 | 
						|
    uint16_t status, iot_pkt_t *bitmap_pkt, uint8_t msg_type);
 | 
						|
 | 
						|
/**
 | 
						|
 * @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_nw_rtc_update_rpt(uint32_t ts, uint32_t cco_ntb);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief nw 21 meter module mac get.
 | 
						|
 * @param mac: module mac.
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_21meter_mode_mac_get(uint8_t *mac);
 | 
						|
 | 
						|
#else  /* PLC_SUPPORT_STA_ROLE && IOT_NW_APP_ENABLE */
 | 
						|
 | 
						|
#define iot_sg_sta_nw_sec_check(data, total_len, is_mr_pkt) (ERR_INVAL)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_sn_cmp(dst_hdr, src_hdr)              (0)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_get_pm_addr(pkt, addr)                (ERR_FAIL)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_queue_app_cache_check(pkt, link_type) (ERR_EXIST)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_queue_app_drop(hdr, reason)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_parse_mr_frame(hdr)                   (ERR_FAIL)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_mr_counter_inc(hdr)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_pd_evt_bm_send(msg_type)              (ERR_NOT_EXIST)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_pd_evt_addrs_send(msg_type)           (ERR_NOT_EXIST)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_power_on_evt_send(flag_bcast)         (ERR_NOT_EXIST)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_event_send(addr, data_ptr, len, new_evt, \
 | 
						|
    rtp_type) (ERR_FAIL)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_handle_app_upgrade(pkt)               IOT_ASSERT(0)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_send_start_ack(id, msg_type, result)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_send_upgrade_data_ack(id, result)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_send_exe_ack(id, msg_type, result)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_send_stop_ack(id, result)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_send_query_reply(id, start_seq, status, bitmap_pkt, \
 | 
						|
    msg_type)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_rtc_update_rpt(ts, cco_ntb)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_21meter_mode_mac_get(mac)
 | 
						|
 | 
						|
#define iot_sg_sta_nw_event_send_with_seq(addr, data_ptr, \
 | 
						|
    len, seq, rpt_type) (ERR_FAIL)
 | 
						|
 | 
						|
#endif  /* PLC_SUPPORT_STA_ROLE && IOT_NW_APP_ENABLE */
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: handle nw meter read response from driver.
 | 
						|
 * @param  data_type: type of response data.
 | 
						|
 * @param  rsp_pkt: the rsp_pkt with response data in it
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_mr_done_intern(uint8_t data_type,
 | 
						|
    iot_pkt_t *rsp_pkt);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: handle nw 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_nw_handle_app_other(iot_pkt_t *pkt);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: handle nw plc message.
 | 
						|
 *         this function always consume the pkt.
 | 
						|
 * @param  pkt: the iot_pkt with nw message in it.
 | 
						|
 * @param  data: msdu data payload in pkt.
 | 
						|
 * @retval: ERR_OK    - case successfully.
 | 
						|
 * @retval: otherwise - error code. see ERR_XXX
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_msg_handle(iot_pkt_t *pkt,
 | 
						|
   uint8_t *data);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: nw meter state score query response.
 | 
						|
 * @param: state score info.
 | 
						|
 * @retval: ERR_OK    - case successfully.
 | 
						|
 * @retval: otherwise - error code. see ERR_XXX
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_score_query_resp(iot_sg_sta_score_info_t *score_info);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: handle nw ctrl protocol message.
 | 
						|
 *         this function always consume the pkt.
 | 
						|
 * @param  pkt: the iot_pkt with gw message in it.
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_ctrl_proto_msg_handle(iot_pkt_t *pkt);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: nw query neighbor node info response.
 | 
						|
 * @param rpt: neighbor node info from cvg report.
 | 
						|
 * @param flag_broadcast: flag of broadcast request.
 | 
						|
 * @retval: ERR_OK    - case successfully.
 | 
						|
 * @retval: otherwise - error code. see ERR_XXX
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_neighbor_info_resp(iot_plc_neighbor_dev_rpt_t *rpt,
 | 
						|
    uint8_t flag_broadcast);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: nw 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_nw_correct_time_req_check(uint8_t *data, uint32_t len);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: meter state score report.
 | 
						|
 * @param  new_evt: new event flag.
 | 
						|
 * @param  meter_cnt: number of meters to be reported scoring results.
 | 
						|
 * @retval: ERR_OK    - case successfully.
 | 
						|
 * @retval: otherwise - error code. see ERR_XXX
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_meter_state_score_report(uint8_t new_evt,
 | 
						|
    uint8_t meter_cnt);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief: meter state score event handle.
 | 
						|
 * @param  fn: function of event ack from cco, see IOT_SG_STA_EVENT_RPT_XXX.
 | 
						|
 */
 | 
						|
void iot_sg_sta_nw_score_event_func_handle(uint8_t fn);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief report edge computing health event to cco.
 | 
						|
 *
 | 
						|
 * @param addr power meter address.
 | 
						|
 * @param score meter score.
 | 
						|
 * @param bitmap score desc bitmap.
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_report_ec_health_event(
 | 
						|
    uint8_t *addr, uint8_t score, iot_sg_sta_drv_score_bit_map_t *bitmap);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief report edge computing overvoltage event to cco.
 | 
						|
 *
 | 
						|
 * @param addr power meter address.
 | 
						|
 * @param is_three_phase is three phase
 | 
						|
 * @param av voltage value of phase-A, format is bin, unit is V
 | 
						|
 * @param bv voltage value of phase-B, format is bin, unit is V
 | 
						|
 * @param cv voltage value of phase-C, format is bin, unit is V
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_report_ec_overvoltage_event(uint8_t *addr,
 | 
						|
    uint8_t is_three_phase, uint16_t av, uint16_t bv, uint16_t cv);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief report edge computing undervoltage event to cco.
 | 
						|
 *
 | 
						|
 * @param addr power meter address.
 | 
						|
 * @param is_three_phase is three phase
 | 
						|
 * @param av voltage value of phase-A, format is bin, unit is V
 | 
						|
 * @param bv voltage value of phase-B, format is bin, unit is V
 | 
						|
 * @param cv voltage value of phase-C, format is bin, unit is V
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_report_ec_undervoltage_event(uint8_t *addr,
 | 
						|
    uint8_t is_three_phase, uint16_t av, uint16_t bv, uint16_t cv);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief report edge computing second pulse event to cco.
 | 
						|
 *
 | 
						|
 * @param addr power meter address.
 | 
						|
 * @param err_val clock error value compare for 1s,
 | 
						|
 *                unit is 1us.
 | 
						|
 */
 | 
						|
uint32_t iot_sg_sta_nw_report_ec_second_pulse_event(
 | 
						|
    uint8_t *addr, uint16_t err_val);
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif  /* IOT_SG_STA_NW_H */
 |