2112 lines
		
	
	
		
			68 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			2112 lines
		
	
	
		
			68 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_PROTO_H
 | 
						|
#define IOT_PROTO_H
 | 
						|
 | 
						|
#include "iot_flashinfo.h"
 | 
						|
#include "iot_cli_sg_api.h"
 | 
						|
#include "iot_oem_api.h"
 | 
						|
#include "iot_grapp.h"
 | 
						|
 | 
						|
#include "iot_edge_compute.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
/* if gree crc16 checking is needed, this micro defination should be set to 1 */
 | 
						|
#define GE_CRC_ENABLE                       1
 | 
						|
 | 
						|
/* define whether need to do trial run check */
 | 
						|
#define TRIAL_RUN_CHECK_ENABLE              0
 | 
						|
 | 
						|
/** fn code enum */
 | 
						|
typedef enum _proto_fn_code_e
 | 
						|
{
 | 
						|
    /* have to stay at the front */
 | 
						|
    PROTO_FNCODE_MIN                        = 0x00,
 | 
						|
    /* sequential control start a new round communicate */
 | 
						|
    PROTO_NEW_RD_COMM_START_CMD             = 0x24,
 | 
						|
    /* boot up password confirm */
 | 
						|
    PROTO_BTUP_PWD_CFM_CMD                  = 0x2B,
 | 
						|
    /* allot ip */
 | 
						|
    PROTO_ALLOT_IP_CMD                      = 0x47,
 | 
						|
    /* command on project numbering (bcast)  */
 | 
						|
    PROTO_NUM_PROJ_CMD                      = 0x48,
 | 
						|
    /* hint of error */
 | 
						|
    PROTO_ERROR_HINT_CMD                    = 0x54,
 | 
						|
    /* alarm of ip conflicting */
 | 
						|
    PROTO_IP_CONFLICT_ALARM_CMD             = 0x55,
 | 
						|
    /* publish device ip(s) and mac(s) of substratum  */
 | 
						|
    PROTO_PUB_SUB_IP_MAC_CMD                = 0x56,
 | 
						|
    /* publish self ip and mac */
 | 
						|
    PROTO_PUB_SELF_IP_MAC_CMD               = 0x57,
 | 
						|
    /* apply ip */
 | 
						|
    PROTO_APPLY_IP_CMD                      = 0x67,
 | 
						|
    /* ask for publishing ip(s) and mac(s) of
 | 
						|
     * slave and sub device of slave
 | 
						|
     */
 | 
						|
    PROTO_PUB_SLV_AND_SUB_IP_MAC_CMD        = 0x77,
 | 
						|
    /* WIFI master reset status confirm */
 | 
						|
    PROTO_WIFI_MASTER_RST_ST_CFM_CMD        = 0x82,
 | 
						|
    /* cancel control with priority */
 | 
						|
    PROTO_CANCEL_PRIO_CTRL_CMD              = 0xA6,
 | 
						|
    /* control with priority */
 | 
						|
    PROTO_PRIO_CTRL_CMD                     = 0xA7,
 | 
						|
    /* important status send */
 | 
						|
    PROTO_IMPTT_ST_SEND_CMD                 = 0xB7,
 | 
						|
    /* response of normal query */
 | 
						|
    PROTO_NORMAL_QUERY_RESP_CMD             = 0xD6,
 | 
						|
 | 
						|
    /* control cmd of testing online */
 | 
						|
    PROTO_ONLINE_TST_CTRL_CMD               = 0xE3,
 | 
						|
    /* normal control with valid flag-group control */
 | 
						|
    PROTO_NORMAL_GROUP_VALID_CTRL_CMD       = 0xE4,
 | 
						|
    /* normal control with valid flag-simple control */
 | 
						|
    PROTO_NORMAL_SIMP_VALID_CTRL_CMD        = 0xE5,
 | 
						|
    /* normal control-group control */
 | 
						|
    PROTO_NORMAL_GROUP_CTRL_CMD             = 0xE6,
 | 
						|
    /* normal control-simple control */
 | 
						|
    PROTO_NORMAL_SIMP_CTRL_CMD              = 0xE7,
 | 
						|
 | 
						|
    /* column query function */
 | 
						|
    PROTO_COLUMN_QUERY_CMD                  = 0xF0,
 | 
						|
    /* normal query */
 | 
						|
    PROTO_NORMAL_QUERY_CMD                  = 0xF6,
 | 
						|
    /* normal status */
 | 
						|
    PROTO_NORMAL_ST_CMD                     = 0xF7,
 | 
						|
 | 
						|
    /** gree upgrade */
 | 
						|
    PROTO_UPGRADE_DL                        = 0xFA,
 | 
						|
    /** gree upgrade ack */
 | 
						|
    PROTO_UPGRADE_UL                        = 0xFB,
 | 
						|
    /** general query cmd fn */
 | 
						|
    PROTO_GE_PLC_QUERY_CMD                  = 0xFC,
 | 
						|
    /** general response cmd fn */
 | 
						|
    PROTO_GE_PLC_RESP_CMD                   = 0xFD,
 | 
						|
    /** general set cmd fn */
 | 
						|
    PROTO_GE_PLC_SET_CMD                    = 0xFE,
 | 
						|
 | 
						|
    PROTO_FNCODE_MAX                        = 0xFF,
 | 
						|
}proto_fn_code_e;
 | 
						|
 | 
						|
/* fn = PROTO_PLC_MODULE_RESP_CMD */
 | 
						|
enum proto_query_response_subfn_e {
 | 
						|
    /* local mac response to MCU */
 | 
						|
    PROTO_LOCAL_MAC_RESP_CMD       = 1,
 | 
						|
    /* sw version response to MCU */
 | 
						|
    PROTO_FW_SWVER_RESP_CMD        = 2,
 | 
						|
    /* boot information response to MCU */
 | 
						|
    PROTO_BOOT_INFO_RESP_CMD       = 3,
 | 
						|
    /* boot up password response to MCU */
 | 
						|
    PROTO_BOOTUP_PASSD_RESP_CMD    = 4,
 | 
						|
    /* topo response to MCU or monitor */
 | 
						|
    PROTO_TOPO_RESP_CMD            = 5,
 | 
						|
    /* net states response to MCU */
 | 
						|
    PROTO_NET_STS_RESP_CMD         = 6,
 | 
						|
    /* white list response to MCU or monitor */
 | 
						|
    PROTO_WHITELIST_RESP_CMD       = 7,
 | 
						|
    /* pair table response to MCU or monitor */
 | 
						|
    PROTO_PAIR_TBLE_RESP_CMD       = 8,
 | 
						|
    /* avail network response to MCU */
 | 
						|
    PROTO_AVAIL_NW_RESP_CMD        = 9,
 | 
						|
    /* IP response to MCU */
 | 
						|
    PROTO_IP_RESP_CMD              = 10,
 | 
						|
    /* TX_PWR response to MCU */
 | 
						|
    PROTO_TX_PWR_RESP_CMD          = 11,
 | 
						|
    /* uart throughput response to MCU */
 | 
						|
    PROTO_UART_THPT_RESP_CMD       = 12,
 | 
						|
    /* network detail information response to MCU */
 | 
						|
    PROTO_NW_DETAILINFO_RESP_CMD   = 13,
 | 
						|
    /* uart param response handler */
 | 
						|
    PROTO_GE_UART_PARAM_RESP_CMD   = 14,
 | 
						|
    /* general extended whitelist response */
 | 
						|
    PROTO_GE_EXT_WL_RESP_CMD       = 15,
 | 
						|
    /* NID response to MCU */
 | 
						|
    PROTO_NID_RESP_CMD             = 16,
 | 
						|
    /* white list state response to MCU */
 | 
						|
    PROTO_WHITELIST_STATE_RESP_CMD = 17,
 | 
						|
    /* module info response to MCU */
 | 
						|
    PROTO_MODULE_INFO_RESP_CMD     = 18,
 | 
						|
    /* ntb response to MCU */
 | 
						|
    PROTO_NTB_RESP_CMD             = 19,
 | 
						|
    /* frequency band scan bitmap to MCU */
 | 
						|
    PROTO_FB_BITMAP_RESP_CMD       = 20,
 | 
						|
    /* fix rate mode response to MCU */
 | 
						|
    PROTO_FIX_RATE_MODE_RESP_CMD   = 21,
 | 
						|
    /* work band response to MCU */
 | 
						|
    PROTO_WORK_BAND_RESP_CMD       = 22,
 | 
						|
    /* node information response to MCU */
 | 
						|
    PROTO_NODE_INFO_RESP_CMD       = 23,
 | 
						|
    /* network information response to MCU */
 | 
						|
    PROTO_NW_INFO_RESP_CMD         = 24,
 | 
						|
    /* local ip4 info response to MCU */
 | 
						|
    PROTO_LOCAL_IP4_INFO_RESP_CMD  = 25,
 | 
						|
    /* aes info response to MCU */
 | 
						|
    PROTO_AES_RESP_CMD             = 26,
 | 
						|
    /* resp query gpio */
 | 
						|
    PROTO_QUERY_GPIO_RESP_CMD      = 27,
 | 
						|
};
 | 
						|
 | 
						|
/* fn = PROTO_PLC_MODULE_SET_CMD */
 | 
						|
enum proto_set_subfn_e {
 | 
						|
    /* set local mac */
 | 
						|
    PROTO_LOCAL_MAC_SET_CMD       = 1,
 | 
						|
    /* set pass word */
 | 
						|
    PROTO_PASSD_SET_CMD           = 2,
 | 
						|
    /* set join network */
 | 
						|
    PROTO_JOIN_NW_SET_CMD         = 3,
 | 
						|
    /* set leave network */
 | 
						|
    PROTO_LEAVE_NW_SET_CMD        = 4,
 | 
						|
    /* add or del while list member */
 | 
						|
    PROTO_OP_WHITELIST_SET_CMD    = 5,
 | 
						|
    /* add or del pair table member */
 | 
						|
    PROTO_OP_PAIR_TBLE_SET_CMD    = 7,
 | 
						|
    /* communicater fault report to MCU */
 | 
						|
    PROTO_COMM_FAULT_RPT_CMD      = 8,
 | 
						|
    /* connect indication report to MCU */
 | 
						|
    PROTO_CONN_IND_RPT_CMD        = 9,
 | 
						|
    /* disconnect indication report to MCU */
 | 
						|
    PROTO_DISCONN_IND_RPT_CMD     = 10,
 | 
						|
    /* CCO start group network */
 | 
						|
    PROTO_CCO_START_GROUP_NET_CMD = 13,
 | 
						|
    /* CCO end group network */
 | 
						|
    PROTO_CCO_END_GROUP_NET_CMD   = 14,
 | 
						|
    /* set NID for CCO */
 | 
						|
    PROTO_CCO_NID_SET_CMD         = 17,
 | 
						|
    /* set reboot STA cmd */
 | 
						|
    PROTO_REBOOT_STA_CMD          = 18,
 | 
						|
    /* cmd confirm cmd */
 | 
						|
    PROTO_CMD_CFM_CMD             = 20,
 | 
						|
    /* CCO state indication - ready or not ready */
 | 
						|
    PROTO_CMD_CCO_STAT_IND_CMD    = 21,
 | 
						|
    /* set tx_power */
 | 
						|
    PROTO_CMD_TX_PWR_CMD          = 22,
 | 
						|
    /* set IP for Mac */
 | 
						|
    PROTO_CMD_SET_IP_CMD          = 23,
 | 
						|
    /* boot ready indication */
 | 
						|
    PROTO_BOOT_READY_ID_CMD       = 24,
 | 
						|
    /* temporary command for clear flash */
 | 
						|
    PROTO_CLR_CUST_FLASH_CMD      = 25,
 | 
						|
    /* online monitor counter indication */
 | 
						|
    PROTO_MONITR_ONLINE_IND       = 26,
 | 
						|
    /* switch app uart mode */
 | 
						|
    PROTO_SW_UART_MODE_CMD        = 27,
 | 
						|
    /* set band id */
 | 
						|
    PROTO_SET_BAND_ID_CMD         = 28,
 | 
						|
    /* set host port */
 | 
						|
    PROTO_SET_HOST_PORT_CMD       = 29,
 | 
						|
    /* general frequency band scan bitmap set subfn */
 | 
						|
    PROTO_SET_FB_BITMAP_CMD       = 30,
 | 
						|
    /* fix rate(enable or disable) set subfn */
 | 
						|
    PROTO_SET_FIX_RATE_MODE_CMD   = 31,
 | 
						|
    /* send sta paging message subfn */
 | 
						|
    PROTO_SEND_STA_PAGING_CMD     = 32,
 | 
						|
    /* set device version info report subfn */
 | 
						|
    PROTO_SET_RPT_DEV_VERINFO_CMD = 33,
 | 
						|
    /* set sta switch boot part subbfn */
 | 
						|
    PROTO_SET_SWITCH_BOOT_PART_CMD = 34,
 | 
						|
    /* set local IP4 info */
 | 
						|
    PROTO_LOCAL_IP4_INFO_SET_CMD   = 35,
 | 
						|
    /* reject indication report to MCU */
 | 
						|
    PROTO_REJECT_IND_RPT_CMD       = 36,
 | 
						|
 | 
						|
    /* switch boot part indication subbfn */
 | 
						|
    PROTO_SWITCH_BOOT_PART_IND_CMD = 0x95,
 | 
						|
    /* Private command code start from here: */
 | 
						|
    /* Module use for annoucing whitelist. */
 | 
						|
    PROTO_WHITELIST_IND_CMD       = 0x96,//150,
 | 
						|
    /* Module use for annoucing pairtable. */
 | 
						|
    PROTO_PAIRTABLE_IND_CMD       = 0x97,//151,
 | 
						|
    /* Test loopback. */
 | 
						|
    PROTO_TEST_LOOP_BACK_CMD      = 0x98,//152,
 | 
						|
    /* app registered indication */
 | 
						|
    PROTO_APP_REG_CONF_IND        = 0x99,//153,
 | 
						|
    /* STA leaving positivly indication */
 | 
						|
    PROTO_STA_LEAVE_IND           = 0x9A,//154,
 | 
						|
    /* device version info report  indication subfn */
 | 
						|
    PROTO_RPT_DEV_VERINFO_IND_CMD = 0x9B,//155
 | 
						|
    /* pair cfm set by linectrl */
 | 
						|
    //PROTO_PAIR_CFM_SET_CMD        = 6,
 | 
						|
    /* pair start indication report to MCU */
 | 
						|
    //PROTO_PAIR_START_IND_RPT_CMD  = 11,
 | 
						|
    /* pair stop indication report to MCU */
 | 
						|
    //PROTO_PAIR_STOP_IND_RPT_CMD   = 12,
 | 
						|
    /* start pair cmd from monitor to outair */
 | 
						|
    //PROTO_START_PAIR_CMD          = 15,
 | 
						|
    /* end pair cmd from monitor to outair */
 | 
						|
    //PROTO_END_PAIR_CMD            = 16,
 | 
						|
    /* unpair devices cmd from monitor to outair */
 | 
						|
    //PROTO_UNPAIR_DEVS_CMD         = 19,
 | 
						|
    /* general data send subfn */
 | 
						|
    PROTO_GE_DATA_CMD             = 0xA0,//160,
 | 
						|
    /* uart param set handler */
 | 
						|
    PROTO_GE_UART_PARAM_SET_CMD   = 0xA1,//161,
 | 
						|
    /* general broadcast data add to beacon send subfn */
 | 
						|
    PROTO_GE_BC_DATA_CMD          = 0xA2,//162,
 | 
						|
    /* general AES subfn */
 | 
						|
    PROTO_AES_SET_CMD             = 0xA3,//163,
 | 
						|
    /* set gpio */
 | 
						|
    PROTO_GE_GPIO_CONFIG_CMD      = 0xA4,//164,
 | 
						|
    /* set gpio */
 | 
						|
    PROTO_GE_GPIO_SET_CMD         = 0xA5,//165,
 | 
						|
    /* delaytime cmd */
 | 
						|
    PROTO_GE_DELAY_TM_CMD         = 0xA6,//166,
 | 
						|
};
 | 
						|
 | 
						|
/* fn = PROTO_PLC_MODULE_QUERY_CMD */
 | 
						|
enum proto_query_subfn_e {
 | 
						|
    /* MCU query local MAC */
 | 
						|
    PROTO_LOCAL_MAC_QUERY_CMD     = 1,
 | 
						|
    /* MCU query sw version */
 | 
						|
    PROTO_FW_SWVER_QUERY_CMD      = 2,
 | 
						|
    /* MCU query system information */
 | 
						|
    PROTO_BOOTINFO_QUERY_CMD      = 3,
 | 
						|
    /* MCU query boot up password */
 | 
						|
    PROTO_BOOTUP_PASSD_QUERY_CMD  = 4,
 | 
						|
    /* MCU or monitor query topo */
 | 
						|
    PROTO_TOPO_QUERY_CMD          = 5,
 | 
						|
    /* MCU query net states */
 | 
						|
    PROTO_NET_STS_QUERY_CMD       = 6,
 | 
						|
    /* MCU or monitor query white list */
 | 
						|
    PROTO_WHITELIST_QUERY_CMD     = 7,
 | 
						|
    /* MCU or monitor pair table */
 | 
						|
    PROTO_PAIR_TBLE_QUERY_CMD     = 8,
 | 
						|
    /* MCU query avail network */
 | 
						|
    PROTO_AVAIL_NW_QUERY_CMD      = 9,
 | 
						|
    /* MCU IP */
 | 
						|
    PROTO_IP_QUERY_CMD            = 10,
 | 
						|
    /* MCU or monitor query tx power */
 | 
						|
    PROTO_TX_PWR_QUERY_CMD        = 11,
 | 
						|
    /* MCU query uart's throughput */
 | 
						|
    PROTO_UART_THRPT_QUERY_CMD    = 12,
 | 
						|
    /* MCU query network detail information */
 | 
						|
    PROTO_NW_DETAILINFO_QUERY_CMD = 13,
 | 
						|
    /* uart param query handler */
 | 
						|
    PROTO_GE_UART_PARAM_QUERY_CMD = 14,
 | 
						|
    /* general extended whitelist query */
 | 
						|
    PROTO_GE_EXT_WL_QUERY_CMD     = 15,
 | 
						|
    /* MCU query local MAC */
 | 
						|
    PROTO_NID_QUERY_CMD           = 16,
 | 
						|
    /* MCU query white list state */
 | 
						|
    PROTO_WHITELIST_STATE_QUERY_CMD = 17,
 | 
						|
    /* MCU query module info */
 | 
						|
    PROTO_MODULE_INFO_QUERY_CMD   = 18,
 | 
						|
    /* MCU query ntb */
 | 
						|
    PROTO_NTB_QUERY_CMD           = 19,
 | 
						|
    /* MCU query frequency band bitmap */
 | 
						|
    PROTO_FB_BITMAP_QUERY_CMD     = 20,
 | 
						|
    /* MCU query fixed rate mode */
 | 
						|
    PROTO_FIX_RATE_QUERY_CMD      = 21,
 | 
						|
    /* MCU query work band */
 | 
						|
    PROTO_WORK_BAND_QUERY_CMD     = 22,
 | 
						|
    /* MCU query node info */
 | 
						|
    PROTO_NODE_INFO_QUERY_CMD     = 23,
 | 
						|
    /* MCU query network info */
 | 
						|
    PROTO_NW_INFO_QUERY_CMD       = 24,
 | 
						|
    /* MCU query local IP4 info */
 | 
						|
    PROTO_LOCAL_IP4_INFO_QUERY_CMD  = 25,
 | 
						|
    /* MCU query aes info */
 | 
						|
    PROTO_AES_QUERY_CMD             = 26,
 | 
						|
    /* query gpio */
 | 
						|
    PROTO_GE_GPIO_QUERY_CMD       = 27,
 | 
						|
    /* delay time */
 | 
						|
    PROTO_GE_DELAY_TIME_CMD       = 28,
 | 
						|
};
 | 
						|
 | 
						|
/* reboot type */
 | 
						|
typedef enum _reobot_type_e {
 | 
						|
    REBOOT_NORMAL          = 0,
 | 
						|
    REBOOT_ASSERT          = 1,
 | 
						|
    REBOOT_WRITE_ZERO_ADDR = 2,
 | 
						|
    REBOOT_MAX             =0xFF,
 | 
						|
} reboot_type_e;
 | 
						|
 | 
						|
/* wl operation */
 | 
						|
#define GE_PROTO_ACTION_DEL           0
 | 
						|
#define GE_PROTO_ACTION_ADD           1
 | 
						|
#define GE_PROTO_WL_DISABLE           2
 | 
						|
#define GE_PROTO_WL_ENABLE            3
 | 
						|
#define GE_PROTO_ACTION_DEL_ALL       4
 | 
						|
 | 
						|
/* ge frame len of each field define */
 | 
						|
#define GE_FRM_PREAMBLE_FIELD_LEN     2
 | 
						|
#define GE_FRM_DATA_CNT_FIELD_LEN     1
 | 
						|
#define GE_FRM_ID_FIELD_LEN           4
 | 
						|
#define GE_FRM_TAIL_FILED_LEN         1
 | 
						|
 | 
						|
#if GE_CRC_ENABLE
 | 
						|
#define GE_FRM_MIN_LEN                10
 | 
						|
#define GE_FRM_UPGRADE_MAX_LEN        418
 | 
						|
#define GE_FRM_CHECKSUM_FIELD_LEN     2
 | 
						|
/* 255 - GE_FRM_MIN_LEN */
 | 
						|
#define GE_FRM_PLD_MAX_LEN            245
 | 
						|
#define GE_FRM_PLD_MIN_LEN           (0x0)
 | 
						|
#else
 | 
						|
#define GE_FRM_MIN_LEN                9
 | 
						|
#define GE_FRM_UPGRADE_MAX_LEN        417
 | 
						|
#define GE_FRM_CHECKSUM_FIELD_LEN     1
 | 
						|
#define GE_FRM_PLD_MAX_LEN            245
 | 
						|
#define GE_FRM_PLD_MIN_LEN           (0x80)
 | 
						|
#endif
 | 
						|
 | 
						|
#define GE_FRM_MAX_LEN               (GE_FRM_MIN_LEN + \
 | 
						|
                                      GE_FRM_PLD_MAX_LEN - \
 | 
						|
                                      GE_FRM_PLD_MIN_LEN)
 | 
						|
 | 
						|
#define GE_EXT_DATA_LEN              (GE_FRM_PLD_MAX_LEN)
 | 
						|
#define GE_EXT_DATA_FRM_MAX_LEN      (GE_FRM_MAX_LEN + GE_FRM_PLD_MAX_LEN)
 | 
						|
 | 
						|
/* temp buffer for sending to MCU */
 | 
						|
#define UL_TMP_BUF_LEN               (GE_EXT_DATA_FRM_MAX_LEN)
 | 
						|
 | 
						|
#define GE_FRM_NORMAL_SEQ_POS        7
 | 
						|
 | 
						|
#define GE_FRM_DATA_LEN_POS          2
 | 
						|
#define GE_FRM_DATA_EXT_LEN_POS      6
 | 
						|
#define GE_FRM_DATA_EXT_FLAG         0x80
 | 
						|
 | 
						|
/* the position of data length field in a intact frame
 | 
						|
 * offset start with 0
 | 
						|
*/
 | 
						|
#define GE_FRM_DATA_CNT_FIELD_POS        2
 | 
						|
 | 
						|
/* the position of check sum field in a intact frame
 | 
						|
 * offset start with data cnt
 | 
						|
*/
 | 
						|
#define GE_FRM_CHECK_SUM_FIELD_POS       7
 | 
						|
/* the position of check sum field in a intact frame
 | 
						|
 * offset start with data cnt
 | 
						|
*/
 | 
						|
#if GE_CRC_ENABLE
 | 
						|
#define GE_FRM_TAIL_CODE_FIELD_POS       9
 | 
						|
#else
 | 
						|
#define GE_FRM_TAIL_CODE_FIELD_POS       8
 | 
						|
#endif
 | 
						|
 | 
						|
#define DIR_UP_TO_MCU                    1
 | 
						|
#define DIR_DOWN_TO_PLC                  0
 | 
						|
 | 
						|
 | 
						|
/** check gree frame command */
 | 
						|
#define GE_CHECK_FRM_CMD(control)      (control >= GE_FRM_PLD_MIN_LEN && \
 | 
						|
                                        control <= GE_FRM_PLD_MAX_LEN)
 | 
						|
/* the real data length */
 | 
						|
#define ACQUIRE_DATA_LEN(data_len)     (data_len - GE_FRM_PLD_MIN_LEN)
 | 
						|
/* preamble code of gree frame */
 | 
						|
#define GE_FRM_PREAMBLE_CODE           (0xAAAA)
 | 
						|
/* tail code of gree frame */
 | 
						|
#define GE_FRM_TAIL_CODE               (0xFF)
 | 
						|
 | 
						|
/* Maximum number of gpio pin configurations supported */
 | 
						|
#define IOT_GE_VALID_GPIO_MAX               3
 | 
						|
 | 
						|
/* Maximum number of LEDC01 module gpio pin configurations supported */
 | 
						|
#define IOT_GE_LEDC01_VALID_GPIO_MAX        3
 | 
						|
 | 
						|
/** const, max buf to cache com0 input char string */
 | 
						|
#if PLC_SUPPORT_CCO_ROLE && ENABLE_GREE_UPGRADE
 | 
						|
#define MCU_DATA_RECV_MAX       (UART_RECV_SIZE_MAX + GE_FRM_UPGRADE_MAX_LEN)
 | 
						|
#else
 | 
						|
#define MCU_DATA_RECV_MAX       (UART_RECV_SIZE_MAX + GE_FRM_MAX_LEN)
 | 
						|
#endif
 | 
						|
 | 
						|
 | 
						|
/* define priorities for message to be handle */
 | 
						|
#define IOT_PROTO_TASK_QUEUE_LP           0
 | 
						|
#define IOT_PROTO_TASK_QUEUE_MAX_PRIO     1
 | 
						|
 | 
						|
#define IOT_PROTO_TASK_LIKE_ID            2
 | 
						|
 | 
						|
#if (IOT_PSRAM_ENABLE)
 | 
						|
#define IOT_PROTO_TASK_POOL_SIZE          254
 | 
						|
#else
 | 
						|
#define IOT_PROTO_TASK_POOL_SIZE          64
 | 
						|
#endif
 | 
						|
 | 
						|
/********************** message type ******************************************/
 | 
						|
/* message type - host */
 | 
						|
#define PROTO_MCU_RX_MSG                  0
 | 
						|
/* message type - plc */
 | 
						|
#define PROTO_PLC_RX_MSG                  1
 | 
						|
/* message type - timer */
 | 
						|
#define PROTO_TIMER_MSG                   2
 | 
						|
/* message type - custom app */
 | 
						|
#define PROTO_CUS_APP_MSG                 4
 | 
						|
/* message type - cli message */
 | 
						|
#define PROTO_CLI_MSG                     5
 | 
						|
/* message type - cctt message */
 | 
						|
#define PROTO_CCTT_MSG                    6
 | 
						|
 | 
						|
/********************* mcu rx message id **************************************/
 | 
						|
/* message id - unrecognized command */
 | 
						|
#define PROTO_MCU_RX_UNKNOWN_MSG          0
 | 
						|
/* message id - recv uart dl645 command */
 | 
						|
#define PROTO_MCU_RX_DL645_MSG            1
 | 
						|
/* message id - recv uart ge command */
 | 
						|
#define PROTO_MCU_RX_GE_MSG               2
 | 
						|
 | 
						|
/********************* plc rx message id **************************************/
 | 
						|
/* message id - data rx*/
 | 
						|
#define PROTO_PLC_RX_DATA_MSG             0
 | 
						|
/* message id - cmd rx*/
 | 
						|
#define PROTO_PLCTXRX_RX_CMD_MSG          1
 | 
						|
 | 
						|
/********************* plc timer message id ***********************************/
 | 
						|
/* uart monitor timer msg id */
 | 
						|
#define PROTO_TIMER_MONITOR_TIMEOUT       0
 | 
						|
/* query mac timer msg id */
 | 
						|
#define PROTO_TIMER_QUERY_MAC_TIMEOUT     1
 | 
						|
/* To announce the update of table for STA. */
 | 
						|
#define PROTO_TIMER_TABLE_ANNOUNCE        2
 | 
						|
/* For STA to query table from CCO */
 | 
						|
#define PROTO_TIMER_TABLE_QUERY           3
 | 
						|
/* wait response cmd time out msg id */
 | 
						|
#define PROTO_TIMER_WAIT_RESP_TIMEOUT     4
 | 
						|
/* timer for reboot after received a reboot cmd */
 | 
						|
#define PROTO_TIMER_REBOOT_STA_TIMEOUT    5
 | 
						|
/* timer for information statistics */
 | 
						|
#define PROTO_TIMER_STATISTIC             6
 | 
						|
/* globle timer for anounce */
 | 
						|
#define PROTO_TIMER_ANOUNCE               7
 | 
						|
/* timer for sta leaving network after received a leave cmd */
 | 
						|
#define PROTO_TIMER_STA_LEAVE_TIMEOUT     8
 | 
						|
/* timer for update upgrade state */
 | 
						|
#define PROTO_TIMER_UPDATE_STATE_TIMEOUT  9
 | 
						|
/* timer for handling broadcast pkt window */
 | 
						|
#define PROTO_TIMER_BRD_PKT_WINDOW_RPT    10
 | 
						|
/* timer for paging */
 | 
						|
#define PROTO_TIMER_PAGING_TIMEOUT        11
 | 
						|
/* timer for trial run check */
 | 
						|
#define PROTO_TIMER_TRIAL_RUN_CHECK       12
 | 
						|
/* timer for 645 meter local read mode,
 | 
						|
 * in local read mode, the 645 frame from meter uart will be cached in local,
 | 
						|
 * in this period, the meter read cmd from plc will be responsed from the cache
 | 
						|
 */
 | 
						|
#define PROTO_TIMER_645_LOCAL_MODE        13
 | 
						|
 | 
						|
/* proto open start */
 | 
						|
#define PROTO_START_EDGE_TMR_ID           14
 | 
						|
 | 
						|
/********************* custom app message id **********************************/
 | 
						|
#define PROTO_CUS_APP_SAVE_PIB_MSG       0
 | 
						|
 | 
						|
/* Message ID for cctt message ID. */
 | 
						|
#define CCTT_REBOOT_CCO                  0
 | 
						|
#define CCTT_REBOOT_STA                  1
 | 
						|
#define CCTT_QUERY_TOPO                  2
 | 
						|
#define CCTT_ADD_WHITELIST               3
 | 
						|
#define CCTT_DEL_WHITELIST               4
 | 
						|
#define CCTT_QUERY_WHITELIST             5
 | 
						|
#define CCTT_SET_WL_STATE                6
 | 
						|
#define CCTT_CLR_WHITELIST               7
 | 
						|
#define CCTT_CHECK_WL_MAC                8
 | 
						|
#define CCTT_SET_PLC_NW                  9
 | 
						|
#define CCTT_READ_PLC_NW                 10
 | 
						|
#define CCTT_REBOOT_MAC_LIST_PCO         11
 | 
						|
#define CCTT_DELAYTIME                   12
 | 
						|
#define CCTT_READ_RS485_CONFIG           13
 | 
						|
#define CCTT_SET_RS485_CONFIG            14
 | 
						|
#define CCTT_RS485_TRANS_DL645           15
 | 
						|
#define CCTT_RS485_TRANS_MODBUS          16
 | 
						|
 | 
						|
/* Message ID for global timer ID. */
 | 
						|
#define PROTO_TMR_WLIST_PERIODICALLY_REPORT      0
 | 
						|
#define PROTO_TMR_PTABLE_PERIODICALLY_REPORT     1
 | 
						|
#define PROTO_TMR_IPS_PERIODICALLY_QUERY         2
 | 
						|
 | 
						|
#define PROTO_STASTIC_UPDATE_INTVL_CNT           (40)        //unit 0.5s
 | 
						|
#define PROTO_TIMER_MONITOR_TIMEOUT_INTVL        (1000/5)    //unit ms
 | 
						|
#define PROTO_TIMER_QUERY_MAC_TIMEOUT_INTVL      (3 * 1000) //unit ms
 | 
						|
#define PROTO_TIMER_WAIT_RESPONSE_TIMEOUT_INTVL  (5 * 1000)  //unit ms
 | 
						|
#define PROTO_TIMER_REBOOT_DELAY_INTVL           (5 * 1000)  //unit ms
 | 
						|
#define PROTO_G_TMR_TIMOUT_STEP                  (60 * 1000) /* 60s seconds */
 | 
						|
#define PROTO_TIMER_LEAVE_DELAY_INTVL            (3 * 1000)  //unit ms
 | 
						|
#define PROTO_TMR_STA_JOIN_ANNOUNCE_WL           (3 * 1000)  //unit ms
 | 
						|
#define PROTO_TMR_SW_UART_MODE_DELAY_INTVL       (3 * 1000)  //unit ms
 | 
						|
#define PROTO_TMR_SET_HOST_PORT_DELAY_INTVL      (3 * 1000)  //unit ms
 | 
						|
#define PROTO_TMR_UPDATE_UPGRADE_STATE_INTVL     (4 * 1000)  //unit ms
 | 
						|
#define PROTO_TMR_PAGING_TIMEOUT_INTVL           (4 * 1000)  //unit ms
 | 
						|
#define PROTO_TMR_645_LOCAL_READ_MODE_INTVL      (10 * 1000) //unit ms
 | 
						|
 | 
						|
#define PROTO_TIMER_STATIST_INTVL                (500)       //unit ms
 | 
						|
 | 
						|
#define PROTO_TIMER_GY_FEED_WDG_INTVL_CNT        (4)         //unit 500ms
 | 
						|
 | 
						|
/* trial run check time */
 | 
						|
#define IOT_APP_FW_RECOVER_TIME                  (5*60*1000) // uint ms
 | 
						|
 | 
						|
#if HW_PLATFORM == HW_PLATFORM_SIMU
 | 
						|
 | 
						|
#define PROTO_UNICAST_RETRY_DEFAULT_INTVL        (5000)     // unit ms
 | 
						|
#define PROTO_BROADCAST_RETRY_DEFAULT_INTVL      (5000)     // unit ms
 | 
						|
#define PROTO_UNICAST_RETRY_DEFAULT_CNT          (3)
 | 
						|
#define PROTO_BROADCAST_RETRY_DEFAULT_CNT        (1)
 | 
						|
 | 
						|
#else /* HW_PLATFORM == HW_PLATFORM_SIMU */
 | 
						|
 | 
						|
#define PROTO_UNICAST_RETRY_DEFAULT_INTVL        (200)      // unit ms
 | 
						|
#define PROTO_BROADCAST_RETRY_DEFAULT_INTVL      (0)        // unit ms
 | 
						|
#define PROTO_UNICAST_RETRY_DEFAULT_CNT          (3)
 | 
						|
#define PROTO_BROADCAST_RETRY_DEFAULT_CNT        (0)
 | 
						|
#define PROTO_UNICAST_RETRY_NOACK_INTVL          (100)
 | 
						|
 | 
						|
#endif /* HW_PLATFORM == HW_PLATFORM_SIMU */
 | 
						|
 | 
						|
/* define the cache buffer for window reporting */
 | 
						|
#define PROTO_WIN_CACHE_LEN                      (256)// bytes
 | 
						|
/* define the default time window for data reporting */
 | 
						|
#define PROTO_RTP_WINDOW_DEFAULT_SPAN            (40000) //unit ms
 | 
						|
 | 
						|
/* const, max supported network info */
 | 
						|
#define PROTO_SUPPORT_MAX_NEIGHBOR_NET           16
 | 
						|
/* const, max supported monitor info */
 | 
						|
#define PROTO_SUPPORT_MAX_MONITOR                4
 | 
						|
 | 
						|
/* define the default tx power , will be set when bootup */
 | 
						|
#define DEFAULT_TX_POWER                         137
 | 
						|
 | 
						|
/* cco send paging message can include sta mac max count */
 | 
						|
#define PROTO_STA_PAGING_MAX_CNT                 (20)
 | 
						|
 | 
						|
#define ARRAY_CNT(a)    (sizeof(a) / sizeof((a)[0]))
 | 
						|
 | 
						|
#define FIRST_WL_FRAME      1
 | 
						|
#define FIRST_PAIR_FRAME    1
 | 
						|
 | 
						|
#define FROM_PLC                                 0
 | 
						|
#define FROM_UART                                1
 | 
						|
 | 
						|
#define GE_TYPE                                  0
 | 
						|
#define MODBUS_TYPE                              1
 | 
						|
#define DL645_TYPE                               2
 | 
						|
 | 
						|
/* the ge data cmd frame length before data position */
 | 
						|
#define GE_FEA0_HEAD_LEN        sizeof(ge_frame_data_send_set_subfn160_t)
 | 
						|
 | 
						|
#define iot_ge_buf_overflow_test(ge_buf_pos, len)                       \
 | 
						|
    ((ge_buf_pos + len) < MCU_DATA_RECV_MAX)
 | 
						|
 | 
						|
typedef struct _proto_rpt_cache {
 | 
						|
    /* cached data length */
 | 
						|
    uint16_t data_len;
 | 
						|
    /* cached data */
 | 
						|
    uint8_t data[PROTO_WIN_CACHE_LEN];
 | 
						|
} proto_rpt_cache_t;
 | 
						|
 | 
						|
enum proto_check_frame_result_e {
 | 
						|
    GET_NO_FRAME,
 | 
						|
    GET_ONE_FRAME,
 | 
						|
    GET_HALF_FRAME,
 | 
						|
    GET_OVERFLOW,
 | 
						|
};
 | 
						|
 | 
						|
enum proto_cmd_handle_status_e {
 | 
						|
    PROTO_CMD_IDLE,
 | 
						|
    PROTO_CMD_WAIT_MAC_RESP,
 | 
						|
    PROTO_CMD_WAIT_IP_RESP,
 | 
						|
    PROTO_CMD_WAIT_SWVER_RESP,
 | 
						|
    PROTO_CMD_WAIT_BOOT_INFO_RESP,
 | 
						|
    PROTO_CMD_WAIT_PLCTXRX_CONFIG_RESP,
 | 
						|
    PROTO_CMD_WAIT_PASSD_RESP,
 | 
						|
    PROTO_CMD_WAIT_TOPO_RESP,
 | 
						|
    PROTO_CMD_WAIT_NET_STS_RESP,
 | 
						|
    PROTO_CMD_WAIT_PLC_STS_RESP,
 | 
						|
    PROTO_CMD_WAIT_AVAIL_NETWORK_RESP = 10,
 | 
						|
    PROTO_CMD_WAIT_RMT_WHITELIST_RESP,
 | 
						|
    PROTO_CMD_WAIT_GREE_STS_RESP,
 | 
						|
    PROTO_CMD_WAIT_RMT_PAIR_CFM,
 | 
						|
    PROTO_CMD_WAIT_CMD_CFM,
 | 
						|
    PROTO_CMD_WAIT_TX_PWR_RESP,
 | 
						|
    PROTO_CMD_WAIT_RMT_WHITELIST_CFM,
 | 
						|
    PROTO_CMD_WAIT_WHITE_LIST_SET,
 | 
						|
    PROTO_CMD_WAIT_PAIR_TABLE_SET,
 | 
						|
    PROTO_CMD_WAIT_NTB_RESP,
 | 
						|
    PROTO_CMD_WAIT_FB_BITMAP_RESP,
 | 
						|
    PROTO_CMD_WAIT_FIX_RATE_MODE_RESP,
 | 
						|
    PROTO_CMD_WAIT_WORK_BAND_RESP,
 | 
						|
    PROTO_CMD_WAIT_NODE_INFO_RESP,
 | 
						|
    PROTO_CMD_WAIT_NW_INFO_RESP,
 | 
						|
    PROTO_CMD_DL645_WAIT_TOPO_INFO_RESP,
 | 
						|
};
 | 
						|
 | 
						|
/* data or cmd tansmit direction */
 | 
						|
typedef enum _transmit_direction_e {
 | 
						|
    /* data - mcu->protocol->plctxrx->remote */
 | 
						|
    DATA_DOWN_LINK = 0,
 | 
						|
    /* data - remote->plctxrx->protocol->mcu */
 | 
						|
    DATA_UP_LINK,
 | 
						|
    /* cmd - (mcu->)protocol->plctxrx  */
 | 
						|
    CMD_LOCAL_DOWN_LINK,
 | 
						|
    /* cmd - plctxrx->protocol(->mcu)  */
 | 
						|
    CMD_LOCAL_UP_LINK,
 | 
						|
    /* cmd - plctxrx->protocol(->mcu) data path */
 | 
						|
    CMD_REMOTE_UP_LINK,
 | 
						|
    /* cmd - (mcu->)protocol->plctxrx->remote data path*/
 | 
						|
    CMD_REMOTE_DOWN_LINK,
 | 
						|
} transmit_direction_e;
 | 
						|
 | 
						|
typedef uint8_t transmit_direction_e_t;
 | 
						|
 | 
						|
enum _proto_cco_groupnet_state_e {
 | 
						|
    CCO_STATE_GROUPNET_IDLE = 0,
 | 
						|
    CCO_STATE_GROUPNETING,
 | 
						|
};
 | 
						|
 | 
						|
/* node num for saved queue */
 | 
						|
#define PROTO_SAVED_MSG_NODE_NUM   40
 | 
						|
 | 
						|
/* whitelist query request maximum STA count */
 | 
						|
#define WL_QUERY_REQ_MAX_STA_CNT  40
 | 
						|
 | 
						|
/* for fn rx statistic */
 | 
						|
#define PROTO_FN_RX_STATISTIC_IDX    3
 | 
						|
 | 
						|
#define PROTO_SET_CVG_WL_FRAG_CNT    40
 | 
						|
 | 
						|
enum proto_cmd_cnf_reason_e {
 | 
						|
    PROTO_REASON_OK,
 | 
						|
    PROTO_REASON_STA_LEAVE_ERR,
 | 
						|
    PROTO_REASON_WL_LOST_FRM,
 | 
						|
    PROTO_REASON_WL_SEQ_MISSMATCH,
 | 
						|
    PROTO_REASON_WL_CLR_NOTSUPPORT,
 | 
						|
    /* removed three pair table error reason */
 | 
						|
    PROTO_REASON_NID_DUP = 8,
 | 
						|
    PROTO_REASON_TIME_OUT,
 | 
						|
    PROTO_REASON_MAC_MISSMATCH,
 | 
						|
    PROTO_REASON_PWD_MISSMATCH, //11
 | 
						|
    PROTO_REASON_JOINED,
 | 
						|
    PROTO_REASON_NO_AUTHORITY,
 | 
						|
    PROTO_REASON_LEN_MISSMATCH,
 | 
						|
    PROTO_REASON_NID_MISSMATCH,
 | 
						|
    PROTO_REASON_CCO_GROUPNETING,
 | 
						|
    PROTO_REASON_CCO_GROUPNETING_IDLE,
 | 
						|
    PROTO_REASON_ERR_DEVTYPE,
 | 
						|
    PROTO_REASON_MAC_ADDR_ZERO,
 | 
						|
    PROTO_REASON_NO_MAC_SETTED, //20
 | 
						|
    PROTO_REASON_DUP_SETTING,
 | 
						|
    PROTO_REASON_ROLE_MISMATCH,
 | 
						|
    PROTO_REASON_CMD_DIR_ERR,
 | 
						|
    PROTO_REASON_NOT_READY,
 | 
						|
    PROTO_REASON_ALLOC_MEM_ERR,
 | 
						|
    PROTO_REASON_NO_NB_NW_FOUND,
 | 
						|
    PROTO_REASON_MONITOR_EXCESS,
 | 
						|
    PROTO_REASON_PARAME_ERR,
 | 
						|
    /* out of range */
 | 
						|
    PROTO_REASON_UART_PARAM_ERR,
 | 
						|
    PROTO_REASON_SWITCH_UART_MODE_ERR,
 | 
						|
    PROTO_REASON_SET_HOST_PORT_ERR,
 | 
						|
    PROTO_REASON_NOT_SUPPORT,
 | 
						|
 | 
						|
    PROTO_REASON_NO_IP4_SETTED,
 | 
						|
    PROTO_REASON_IP4_IS_INVALID,
 | 
						|
 | 
						|
    PROTO_REASON_MAX,
 | 
						|
};
 | 
						|
 | 
						|
/* tx power maximum value */
 | 
						|
#define PROTO_TX_POWER_VALUE_MAX 137 // unit dBuv
 | 
						|
/* tx power minimum value */
 | 
						|
#define PROTO_TX_POWER_VALUE_MIN 95  // unit dBuv
 | 
						|
 | 
						|
enum _proto_op_type {
 | 
						|
    /* It means operation object is whitelist. */
 | 
						|
    PROTO_OP_TYPE_WL   = 0,
 | 
						|
    /* It means operation object is pairtable. */
 | 
						|
    PROTO_OP_TYPE_PAIR,
 | 
						|
 | 
						|
    PROTO_OP_TYPE_MAX,
 | 
						|
};
 | 
						|
 | 
						|
/* APP data type */
 | 
						|
#define GE_HOST_DATA_TYPE          0
 | 
						|
#define GE_INTERNAL_BCN_DATA_TYPE  1
 | 
						|
 | 
						|
struct  _plctxrx_dev_info_t;
 | 
						|
struct  _plctxrx_tx_data_info_t;
 | 
						|
typedef struct _plctxrx_dev_info_t  plctxrx_dev_info_t;
 | 
						|
typedef struct _plctxrx_tx_data_info_t plctxrx_tx_data_info_t;
 | 
						|
 | 
						|
struct _protpkt_list;
 | 
						|
typedef struct _protpkt_list protpkt_list_t;
 | 
						|
struct _plctxrx_rx_data_info_t;
 | 
						|
typedef struct _plctxrx_rx_data_info_t  plctxrx_rx_data_info_t;
 | 
						|
 | 
						|
 | 
						|
/* proto message */
 | 
						|
typedef struct _iot_proto_msg_t {
 | 
						|
    /* proto task message */
 | 
						|
    iot_task_msg_t  msg;
 | 
						|
    /* message data */
 | 
						|
    void        *data1;
 | 
						|
    uint32_t     data2;
 | 
						|
} iot_proto_msg_t;
 | 
						|
 | 
						|
#pragma pack(push)  // save the pack status
 | 
						|
#pragma pack(1)     // 1 byte align
 | 
						|
/* gree protocol frame header */
 | 
						|
typedef struct _ge_frm_hdr_t {
 | 
						|
    /* preable code 0xAAAA */
 | 
						|
    uint16_t preamble;
 | 
						|
    /* data length range:[0x80,0x88] */
 | 
						|
    uint8_t  data_len;
 | 
						|
    /* function code */
 | 
						|
    uint8_t  fn;
 | 
						|
}  ge_frm_hdr_t;
 | 
						|
 | 
						|
 | 
						|
#if GE_CRC_ENABLE
 | 
						|
typedef struct _ge_frm_tail_t {
 | 
						|
    /* crc16 for gree frame */
 | 
						|
    uint16_t  check_sum;
 | 
						|
    /* tail(0xFF)code of gree frame */
 | 
						|
    uint8_t  tail;
 | 
						|
}  ge_frm_tail_t;
 | 
						|
#else
 | 
						|
typedef struct _ge_frm_tail_t {
 | 
						|
    /* check sum of gree frame */
 | 
						|
    uint8_t  check_sum;
 | 
						|
    /* tail(0xFF)code of gree frame */
 | 
						|
    uint8_t  tail;
 | 
						|
}  ge_frm_tail_t;
 | 
						|
#endif
 | 
						|
 | 
						|
#pragma pack(pop)	// restore the pack status
 | 
						|
 | 
						|
typedef struct _sta_dev_t
 | 
						|
{
 | 
						|
    /* already in network */
 | 
						|
    bool_t   dev_ready;
 | 
						|
    /* network id */
 | 
						|
    uint8_t  nid;
 | 
						|
    /* role in network CCO or STA */
 | 
						|
    uint8_t  nw_role;
 | 
						|
    /* ip of sta dev */
 | 
						|
    uint8_t  ip;
 | 
						|
    /* mac of local dev */
 | 
						|
    uint8_t  mac[IOT_MAC_ADDR_LEN];
 | 
						|
    /* indication sequence */
 | 
						|
    uint8_t  ind_seq;
 | 
						|
} sta_dev_t;
 | 
						|
/*
 | 
						|
 * when handle mcu data,maybe it is a big buffer,
 | 
						|
 * we should use this struct to extract each
 | 
						|
 * intact gree frame.
 | 
						|
*/
 | 
						|
typedef struct _mcu_data_handle_t {
 | 
						|
    /* data buffer start address to hold uart input data  */
 | 
						|
    uint16_t data_pos;
 | 
						|
    /* total length of data buffer */
 | 
						|
    uint16_t total_len;
 | 
						|
    /* pointer of MCU data buffer */
 | 
						|
    uint8_t  data[MCU_DATA_RECV_MAX];
 | 
						|
} mcu_data_handle_t;
 | 
						|
 | 
						|
 | 
						|
/* state of cmd handle */
 | 
						|
typedef struct _proto_cmd_hdl_state_t {
 | 
						|
    /* current state - like wait for xxx response */
 | 
						|
    uint8_t                state;
 | 
						|
    /* save the seq for present downllink cmd */
 | 
						|
    uint8_t                seq;
 | 
						|
    /* sending direction of async response cmd
 | 
						|
     * which we are waiting for
 | 
						|
     */
 | 
						|
    transmit_direction_e_t dir;
 | 
						|
    /* save last set subfn, fill it in cnf frame */
 | 
						|
    uint8_t                cur_subfn;
 | 
						|
    /* device which we are going to send response cmd to */
 | 
						|
    plctxrx_dev_info_t     dev;
 | 
						|
} proto_cmd_hdl_state_t;
 | 
						|
 | 
						|
/* Ge Fn Code handle. Each Code should define itself function*/
 | 
						|
typedef bool_t(* PROTO_FN_HANDLE)(uint8_t *data, uint16_t len, \
 | 
						|
                                        transmit_direction_e_t dir);
 | 
						|
 | 
						|
/* parse fn from intact gree frame */
 | 
						|
typedef uint8_t(* PROTO_PARSER)(uint8_t *data);
 | 
						|
 | 
						|
/* Send Received GL Frame to MotherBoard MCU / up layer */
 | 
						|
typedef uint32_t(* PROTO_SENDTO_UPLAYER)(iot_pkt_t *data);
 | 
						|
 | 
						|
/* update cco mac callback function */
 | 
						|
typedef uint32_t(* PROTO_UPDATA_CCO_MAC)(uint8_t * cco_mac);
 | 
						|
 | 
						|
/* plc control callback */
 | 
						|
typedef uint8_t(* PLCXMIT_CMD_CB)(iot_pkt_t *data);
 | 
						|
 | 
						|
/* plc transmit unicast packet callback */
 | 
						|
typedef uint8_t(* PLCXMIT_DATA_CB)(uint8_t *data, uint16_t len,
 | 
						|
                                protpkt_tx_info_t *txinfo);
 | 
						|
 | 
						|
/* post recv data */
 | 
						|
typedef uint8_t(*POST_RECV_DATA)(uint8_t * data, uint16_t len, uint32_t param);
 | 
						|
 | 
						|
/* Ge function code table */
 | 
						|
typedef struct _proto_fnhdl_tbl_t
 | 
						|
{
 | 
						|
    /*gree function code*/
 | 
						|
    uint32_t cmdid;
 | 
						|
    /*each code handler*/
 | 
						|
    PROTO_FN_HANDLE cmd_handle_fn;
 | 
						|
 | 
						|
    /*each fn handle statistic */
 | 
						|
    uint32_t cmd_num;
 | 
						|
} proto_fnhdl_tbl_t;
 | 
						|
 | 
						|
/* list for message save */
 | 
						|
typedef struct _proto_msg_saved_list_t {
 | 
						|
    list_node_t *head;
 | 
						|
    list_node_t *tail;
 | 
						|
    uint16_t    depth;
 | 
						|
} proto_msg_saved_list_t;
 | 
						|
 | 
						|
/* message saved node */
 | 
						|
typedef struct _proto_savedmsg_node_t {
 | 
						|
    uint16_t    msg_type;
 | 
						|
    uint16_t    msg_id;
 | 
						|
    void        *data;
 | 
						|
    transmit_direction_e_t dir;
 | 
						|
    list_node_t node;
 | 
						|
} proto_savedmsg_node_t;
 | 
						|
 | 
						|
/* network wl defination */
 | 
						|
typedef struct _proto_device_list_t {
 | 
						|
    /* wl table fragment elment num  */
 | 
						|
    uint16_t wl_ccofrag_cnt;
 | 
						|
    /* tmp recv wl dev num */
 | 
						|
    uint16_t valid_dev_tmp_cnt;
 | 
						|
    /* cco wl changed num. broadcast in wl announce frm */
 | 
						|
    uint8_t  wl_cco_seq;
 | 
						|
    /* cco wl dev number */
 | 
						|
    uint16_t valid_dev_cnt;
 | 
						|
    /* online dev num */
 | 
						|
    uint16_t online_dev_cnt;
 | 
						|
    /* tmp table for add or remove */
 | 
						|
    proto_dev_t dev_tmp[STA_DEV_MAX];
 | 
						|
    /* cco wl table */
 | 
						|
    proto_dev_t dev[STA_DEV_MAX];
 | 
						|
    /* table for sta online state flag */
 | 
						|
    bool_t online_flag[STA_DEV_MAX];
 | 
						|
#if PLC_SUPPORT_CCO_ROLE
 | 
						|
    /* table for store sta pco addr */
 | 
						|
    uint8_t dev_pco[STA_DEV_MAX][IOT_MAC_ADDR_LEN];
 | 
						|
#endif
 | 
						|
} proto_dev_list_t;
 | 
						|
 | 
						|
/* network info defination */
 | 
						|
typedef struct _proto_neighbor_info_t {
 | 
						|
    /* network id  */
 | 
						|
    uint8_t  nid;
 | 
						|
    /* network rev signal */
 | 
						|
    uint8_t  best_snr;
 | 
						|
    /* flag to mark network in group or end state */
 | 
						|
    uint8_t  net_start_flag;
 | 
						|
    /* cco mac addr */
 | 
						|
    uint8_t  mac[IOT_MAC_ADDR_LEN];
 | 
						|
} proto_neighbor_info_t;
 | 
						|
 | 
						|
typedef struct  _proto_neighbor_nw_t {
 | 
						|
    /* found network num */
 | 
						|
    uint16_t count;
 | 
						|
    /* arry for each network */
 | 
						|
    proto_neighbor_info_t node[PROTO_SUPPORT_MAX_NEIGHBOR_NET];
 | 
						|
} proto_neighbor_nw_t;
 | 
						|
 | 
						|
typedef struct _proto_groupnet_state_t {
 | 
						|
    uint8_t state;
 | 
						|
} proto_groupnet_state_t;
 | 
						|
 | 
						|
#if ENABLE_GE_DATA_SEND_TO_BEACON
 | 
						|
/* cco vendor entry in beacon */
 | 
						|
typedef struct proto_vendor_info {
 | 
						|
    uint8_t data[IOT_PLC_BEACON_DATA_MAX];
 | 
						|
} proto_vendor_info_t;
 | 
						|
#endif
 | 
						|
 | 
						|
/* proto layer global context.*/
 | 
						|
typedef struct _prototask_contxt_t {
 | 
						|
    /* indicate, proto layer is one task.*/
 | 
						|
    iot_task_h               task_handle;
 | 
						|
    /* iot_task configuration */
 | 
						|
    iot_task_config_t        task_cfg;
 | 
						|
    /* validate, parser and extract Gree control code from uart stream.*/
 | 
						|
    PROTO_PARSER             proto_pase_fn;
 | 
						|
    /* api interface to report Gree packet to upper host, motherboard.*/
 | 
						|
    PROTO_SENDTO_UPLAYER     proto_sendto_mainboard_fn;
 | 
						|
    /* local device information */
 | 
						|
    sta_dev_t                local_dev;
 | 
						|
    /* CCO device information */
 | 
						|
    sta_dev_t                cco_dev;
 | 
						|
    /* rx information from remote device for command */
 | 
						|
    plctxrx_rx_data_info_t   rx_info;
 | 
						|
    /* command handled currently */
 | 
						|
    proto_cmd_hdl_state_t    sm;
 | 
						|
    /* Gree control code handle table.
 | 
						|
     * Gree team may focus on this table implementation.
 | 
						|
     */
 | 
						|
    proto_fnhdl_tbl_t        *proto_cmd_hdl_tbl;
 | 
						|
    /* plctxrx layer registered,
 | 
						|
     * Gree layer use. send Gree frame to PLC
 | 
						|
     */
 | 
						|
    PLCXMIT_DATA_CB          gree_data_send_cb;
 | 
						|
    /* group network state for CCO(outair) */
 | 
						|
    proto_groupnet_state_t   groupnet_state;
 | 
						|
    /* plctxrx layer registered, Gree layer use.
 | 
						|
     * send control message to plctxrx. eg,
 | 
						|
     * network selection, pairing.
 | 
						|
    */
 | 
						|
    PLCXMIT_CMD_CB           gree_cmd_send_cb;
 | 
						|
    /* list for saved msg */
 | 
						|
    proto_msg_saved_list_t   saved_msg_list;
 | 
						|
    /* geneal timer used to handle period
 | 
						|
     * action in proto layer
 | 
						|
     */
 | 
						|
    timer_id_t               detect_timer;
 | 
						|
    /* timer for gathering frame of up link */
 | 
						|
    timer_id_t               uart_monitor_timer;
 | 
						|
    /* timer for waiting response */
 | 
						|
    timer_id_t               wait_resp_timer;
 | 
						|
    /* timer for reboot after received reboot_cmd */
 | 
						|
    timer_id_t               reboot_tmr;
 | 
						|
    /* timer for infomation statistics */
 | 
						|
    timer_id_t               statisc_tmr;
 | 
						|
    /* timer for sta leaving network delay */
 | 
						|
    timer_id_t               leave_tmr;
 | 
						|
    /* timer for update upgrade state */
 | 
						|
    timer_id_t               upgrade_tmr;
 | 
						|
    /* window timer for reporting broadcast pkt to host port */
 | 
						|
    timer_id_t               rpt_window_tmr;
 | 
						|
    /* timer for trial run */
 | 
						|
    timer_id_t               trial_run_tmr;
 | 
						|
    /* timer for 645 meter local read mode */
 | 
						|
    timer_id_t               dl645_localmode_tmr;
 | 
						|
    /* device list for whitelist */
 | 
						|
    proto_dev_list_t         dev_lst;
 | 
						|
    /* total fn received */
 | 
						|
    uint32_t                 num_fn_received;
 | 
						|
    /* total fn send */
 | 
						|
    uint32_t                 num_fn_send;
 | 
						|
    /* topo response index */
 | 
						|
    uint16_t                 topo_resp_index;
 | 
						|
    /* to save query topo infomation type */
 | 
						|
    uint8_t                  topo_info_type;
 | 
						|
    /* neighbor net work infor */
 | 
						|
    proto_neighbor_nw_t      neighbor_nw;
 | 
						|
    /* flag marked for have mac addr
 | 
						|
       only when mcu response mac, then we can handle fn */
 | 
						|
    uint8_t                  macaddr_set;
 | 
						|
    /* flag indicate wehther cco already started group net or not */
 | 
						|
    uint8_t                  net_start_flag;
 | 
						|
    /* repsonse state to mainboard flag */
 | 
						|
    uint8_t                  resp_state_flag;
 | 
						|
    /* cache buffer for window reporting */
 | 
						|
    proto_rpt_cache_t        rpt_cache;
 | 
						|
    /* custom use, updata cco mac according to cco paging */
 | 
						|
    PROTO_UPDATA_CCO_MAC     update_cco_mac;
 | 
						|
    /* timer for sta paging */
 | 
						|
    timer_id_t               paging_timer;
 | 
						|
    /* for sta paging index in dev_list.dev */
 | 
						|
    uint32_t                 paging_index;
 | 
						|
    /* sta save the cco mac address from paging message */
 | 
						|
    uint8_t                  paging_cco_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    /* cache reboot reason, see reboot_type_e, default set REBOOT_NORMAL */
 | 
						|
    uint8_t                  reboot_reason;
 | 
						|
    /* cli interface */
 | 
						|
    iot_cli_sg_interface_t   cli_interface;
 | 
						|
    /* pib handle */
 | 
						|
    app_pib_rw_t             *pib_rw;
 | 
						|
    /* cache of load/save info into custom flash */
 | 
						|
    ge_app_pib_info_t        flashinfo;
 | 
						|
 | 
						|
#if ENABLE_GE_DATA_SEND_TO_BEACON
 | 
						|
    /* 14 Bytes beacon data */
 | 
						|
    proto_vendor_info_t      rxbc_data;
 | 
						|
#endif
 | 
						|
    /* ge_ext app and ge app sharing common_bin_dump func */
 | 
						|
    os_mutex_h               common_bin_dump_mutex;
 | 
						|
    /* cco network done */
 | 
						|
    uint8_t                  cco_net_done;
 | 
						|
    /* statistic timer cnt */
 | 
						|
    uint8_t                  statistic_cnt;
 | 
						|
    /* for hw watchdog  */
 | 
						|
    uint8_t                  hw_watchdog_en       : 1,
 | 
						|
    /* hw watchdog output control */
 | 
						|
                             hw_watchdog_out      : 1,
 | 
						|
    /* reserved */
 | 
						|
                             resv                 : 6;
 | 
						|
    /* info of edge */
 | 
						|
    edge_obj_t               edge_obj;
 | 
						|
    /* start polling in idle state */
 | 
						|
    timer_id_t               edge_monitor_start_tmr;
 | 
						|
    /* cache send uart pkt data */
 | 
						|
    iot_pkt_t                *cache_pkt;
 | 
						|
    /* detect device mac which module installed on.
 | 
						|
       device mac has high priority than module itsef mac. */
 | 
						|
    uint8_t                  detect_devmac_cnt;
 | 
						|
} prototask_contxt_t;
 | 
						|
 | 
						|
/************************************extended fn define***********************/
 | 
						|
/* fill gree extended fn frame */
 | 
						|
#define EXT_FN_FRM_PREPARE(cmd, ext_fn, sub_fn)  do { \
 | 
						|
    cmd->hdr.hdr.preamble = GE_FRM_PREAMBLE_CODE; \
 | 
						|
    if (ext_fn == PROTO_UPGRADE_UL) {\
 | 
						|
        cmd->hdr.hdr.data_len = sizeof(*cmd) - GE_FRM_MIN_LEN + 0x90; \
 | 
						|
    } else {\
 | 
						|
        cmd->hdr.hdr.data_len = sizeof(*cmd) - \
 | 
						|
            GE_FRM_MIN_LEN + GE_FRM_PLD_MIN_LEN; \
 | 
						|
    }\
 | 
						|
    cmd->hdr.hdr.fn       = ext_fn; \
 | 
						|
    cmd->hdr.subfn        = sub_fn; \
 | 
						|
    cmd->tail.tail        = GE_FRM_TAIL_CODE; \
 | 
						|
}while(0)
 | 
						|
 | 
						|
/* fill two part gree extended fn frame */
 | 
						|
#define EXT_FN_TWO_PART_FRM_PREPARE(cmd, ptail, rsv_data_len, ext_fn, sub_fn)\
 | 
						|
    do { \
 | 
						|
    cmd->hdr.hdr.preamble = GE_FRM_PREAMBLE_CODE; \
 | 
						|
    cmd->hdr.hdr.data_len = sizeof(*cmd) - \
 | 
						|
        GE_FRM_MIN_LEN + GE_FRM_PLD_MIN_LEN + \
 | 
						|
        sizeof(ge_frm_tail_t) + rsv_data_len; \
 | 
						|
    cmd->hdr.hdr.fn        = ext_fn; \
 | 
						|
    cmd->hdr.subfn         = sub_fn; \
 | 
						|
    ptail->tail            = GE_FRM_TAIL_CODE; \
 | 
						|
}while(0)
 | 
						|
 | 
						|
/* fill header of ge frame */
 | 
						|
#define GE_FRM_HDR_PREPARE(cmd, ext_fn, sub_fn, frm_len)  do { \
 | 
						|
    cmd->hdr.hdr.preamble = GE_FRM_PREAMBLE_CODE; \
 | 
						|
    cmd->hdr.hdr.data_len = frm_len - GE_FRM_MIN_LEN; \
 | 
						|
    cmd->hdr.hdr.fn       = ext_fn; \
 | 
						|
    cmd->hdr.subfn        = sub_fn; \
 | 
						|
}while(0)
 | 
						|
 | 
						|
typedef struct _uart_thpt_t {
 | 
						|
   /* com0 recv (from mcu) char num */
 | 
						|
   uint32_t         recv_len;
 | 
						|
   /* com0 recv kbps */
 | 
						|
   uint32_t         recv_rate;
 | 
						|
   /* com0 send char num */
 | 
						|
   uint32_t         send_len;
 | 
						|
   /* com0 send kbps */
 | 
						|
   uint32_t         send_rate;
 | 
						|
} uart_thpt_t;
 | 
						|
 | 
						|
#pragma pack(push)  // save the pack status
 | 
						|
#pragma pack(1)     // 1 byte align
 | 
						|
 | 
						|
/* ge protocol frame header */
 | 
						|
typedef struct _ge_extend_fn_hdr_t {
 | 
						|
    ge_frm_hdr_t  hdr;
 | 
						|
    /* sub function code */
 | 
						|
    uint8_t  subfn;
 | 
						|
} ge_extend_fn_hdr_t;
 | 
						|
 | 
						|
/* subfn = PROTO_COMM_FAULT_RPT_CMD */
 | 
						|
typedef struct _ge_frame_comm_fault_rpt_set_subfn8_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            type;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            reason;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_comm_fault_rpt_set_subfn8_t;
 | 
						|
 | 
						|
/* subfn = PROTO_REBOOT_STA_CMD */
 | 
						|
typedef struct _ge_frame_reboot_sta_set_subfn18_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            nid;
 | 
						|
    /* reboot_type:0-normal reboot,1-assert, 2-write NULL address */
 | 
						|
    uint8_t            reboot_type;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            src_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    uint8_t            dst_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_reboot_sta_set_subfn18_t;
 | 
						|
 | 
						|
/* subfn = PROTO_CMD_CFM_CMD */
 | 
						|
typedef struct _ge_frame_cmd_cfm_set_subfn20_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            cmd;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            result;
 | 
						|
    uint8_t            reason;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_cmd_cfm_set_subfn20_t;
 | 
						|
 | 
						|
/* subfn = PROTO_CMD_CCO_STAT_IND_CMD */
 | 
						|
typedef struct _ge_frame_cco_stat_ind_set_subfn21_t{
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            resv2;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            ready;
 | 
						|
    uint8_t            nid;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_cco_stat_ind_set_subfn21_t;
 | 
						|
 | 
						|
/* subfn = PROTO_CMD_TX_PWR_CMD */
 | 
						|
typedef struct _ge_frame_tx_pwr_set_subfn22_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            txpwr;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_tx_pwr_set_subfn22_t;
 | 
						|
 | 
						|
/* subfn = PROTO_BOOT_READY_ID_CMD */
 | 
						|
typedef struct _ge_frame_boot_ready_id_set_subfn24_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            local_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    uint8_t            cco_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_boot_ready_id_set_subfn24_t;
 | 
						|
 | 
						|
/* subfn = PROTO_CLR_CUST_FLASH_CMD */
 | 
						|
typedef struct _ge_frame_clr_cust_flash_set_subfn25_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_clr_cust_flash_set_subfn25_t;
 | 
						|
 | 
						|
/* PROTO_MONITR_ONLINE_IND */
 | 
						|
typedef struct _ge_frame_monitor_online_ind_set_subfn26_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            monitor_cnt;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_monitor_online_ind_set_subfn26_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SW_UART_MODE_CMD */
 | 
						|
typedef struct _ge_frame_sw_uart_mode_set_subfn27_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_sw_uart_mode_set_subfn27_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SET_BAND_ID_CMD */
 | 
						|
typedef struct _ge_frame_band_id_set_subfn28_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            band_id;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_band_id_set_subfn28_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SET_HOST_PORT_CMD */
 | 
						|
typedef struct _ge_frame_host_port_set_subfn29_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            host_port;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_host_port_set_subfn29_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SET_FB_BITMAP_CMD */
 | 
						|
typedef struct _ge_frame_fb_scan_bitmap_set_subfn30_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /**
 | 
						|
     * scan fb_scan_bitmap defined as follow:
 | 
						|
     * bit0  == 1: support band 0
 | 
						|
     * bit1  == 1: support band 1
 | 
						|
     * ...
 | 
						|
     * bit15 == 1: support band 15
 | 
						|
     */
 | 
						|
    uint16_t           fb_scan_bitmap;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fb_scan_bitmap_set_subfn30_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SET_FIX_RATE_MODE_CMD */
 | 
						|
typedef struct _ge_frame_fix_rate_set_subfn31_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /**
 | 
						|
     * 0: disable fixed rate
 | 
						|
     * 1: enable fixed rate
 | 
						|
     */
 | 
						|
    uint8_t            enable;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fix_rate_set_subfn31_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SEND_STA_PAGING_CMD */
 | 
						|
typedef struct _ge_frame_sta_paging_subfn32_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            count;
 | 
						|
    uint8_t            cco_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    uint8_t            sta_mac[0][IOT_MAC_ADDR_LEN];
 | 
						|
} ge_frame_sta_paging_subfn32_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SET_RPT_DEV_VERINFO_CMD */
 | 
						|
typedef struct _ge_frame_set_dev_verinfo_rpt_subfn33_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            dest_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_set_dev_verinfo_rpt_subfn33_t;
 | 
						|
 | 
						|
/* subfn = PROTO_RPT_DEV_VERINFO_IND_CMD */
 | 
						|
typedef struct _ge_frame_rpt_dev_verinfo_ind_subfn155_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /* see AP_FIRMWARE_VERSION_TYPE */
 | 
						|
    uint8_t            ver_type;
 | 
						|
    /* firmware_version */
 | 
						|
    uint32_t           verinfo;
 | 
						|
    /* indicate which device responses the querry cmd */
 | 
						|
    uint8_t            dev_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    /* chip management id */
 | 
						|
    uint8_t            chip_mmid[IOT_CHIP_MMID_LEN];
 | 
						|
    /* hardware_version */
 | 
						|
    uint32_t           hw_ver;
 | 
						|
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_rpt_dev_verinfo_ind_subfn155_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SET_SWITCH_BOOT_PART_CMD */
 | 
						|
typedef struct _ge_frame_sw_bt_part_subfn34_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            src_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    uint8_t            dst_mac[IOT_MAC_ADDR_LEN];
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_sw_bt_part_subfn34_t;
 | 
						|
 | 
						|
/* subfn = PROTO_GE_BC_DATA_CMD */
 | 
						|
typedef struct _ge_frame_bc_data_send_subfn162_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            data[IOT_PLC_BEACON_DATA_MAX];
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_bc_data_send_subfn162_t;
 | 
						|
 | 
						|
/* subfn = PROTO_LOCAL_MAC_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_local_mac_query_subfn1_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            dir;
 | 
						|
    uint8_t            nw_role;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_local_mac_query_subfn1_t;
 | 
						|
 | 
						|
/* subfn = PROTO_FW_SWVER_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_fw_swver_query_subfn2_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fw_swver_query_subfn2_t;
 | 
						|
 | 
						|
/* subfn = PROTO_BOOTINFO_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_bootinfo_query_subfn3_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_bootinfo_query_subfn3_t;
 | 
						|
 | 
						|
/* subfn = PROTO_TOPO_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_topo_query_subfn5_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    /* see TOPO_INFO_TYPE_Vx */
 | 
						|
    uint8_t            type;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_topo_query_subfn5_t;
 | 
						|
 | 
						|
/* subfn = PROTO_WHITELIST_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_wl_query_subfn7_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            cco_flag;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_wl_query_subfn7_t;
 | 
						|
 | 
						|
/* subfn = PROTO_PAIR_TBLE_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_pair_tbl_query_subfn8_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            cco_flag;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_pair_tbl_query_subfn8_t;
 | 
						|
 | 
						|
/* subfn = PROTO_AVAIL_NW_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_avail_nw_query_subfn9_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_avail_nw_query_subfn9_t;
 | 
						|
 | 
						|
/* subfn = PROTO_TX_PWR_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_tx_pwr_query_subfn11_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_tx_pwr_query_subfn11_t;
 | 
						|
 | 
						|
/* subfn = PROTO_UART_THRPT_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_uart0_thrpt_query_subfn12_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_uart0_thrpt_query_subfn12_t;
 | 
						|
 | 
						|
/* subfn = PROTO_WHITELIST_STATE_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_wl_state_query_subfn17_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_wl_state_query_subfn17_t;
 | 
						|
 | 
						|
/* subfn = PROTO_MODULE_INFO_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_module_info_query_subfn18_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_module_info_query_subfn18_t;
 | 
						|
 | 
						|
/* subfn = PROTO_NTB_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_ntb_query_subfn19_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_ntb_query_subfn19_t;
 | 
						|
 | 
						|
/* subfn = PROTO_FB_BITMAP_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_fb_bitmap_query_subfn20_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /**
 | 
						|
     * 0: all bands bitmap that MAC has supported.
 | 
						|
     * 1: scan bands bitmap.
 | 
						|
     */
 | 
						|
    uint8_t            is_scan_bitmap;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fb_bitmap_query_subfn20_t;
 | 
						|
 | 
						|
/* subfn = PROTO_FIX_RATE_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_fix_rate_query_subfn21_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fix_rate_query_subfn21_t;
 | 
						|
 | 
						|
/* subfn = PROTO_WORK_BAND_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_work_band_query_subfn22_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_work_band_query_subfn22_t;
 | 
						|
 | 
						|
/* subfn = PROTO_LOCAL_IP4_QUERY_CMD */
 | 
						|
typedef struct _ge_frame_local_ip4_query_subfn25_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_local_ip4_query_subfn25_t;
 | 
						|
 | 
						|
/* subfn = PROTO_FW_SWVER_RESP_CMD */
 | 
						|
typedef struct _ge_frame_fw_swver_resp_subfn2_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint32_t           swver;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fw_swver_resp_subfn2_t;
 | 
						|
 | 
						|
/* subfn = PROTO_SYSINFO_RESP_CMD */
 | 
						|
typedef struct _ge_frame_sysinfo_resp_subfn3_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint16_t           boot_cnt;
 | 
						|
    uint8_t            last_boot_reason;
 | 
						|
    uint32_t           run_time;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_sysinfo_resp_subfn3_t;
 | 
						|
 | 
						|
/* subfn = PROTO_TX_PWR_RESP_CMD */
 | 
						|
typedef struct _ge_frame_tx_pwr_resp_subfn11_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            tx_pwr;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_tx_pwr_resp_subfn11_t;
 | 
						|
 | 
						|
/* subfn = PROTO_UART_THPT_RESP_CMD */
 | 
						|
typedef struct _ge_frame_uart_thpt_resp_subfn12_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    uint8_t            recv_rate[3];
 | 
						|
    uint8_t            send_rate[3];
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_uart_thpt_resp_subfn12_t;
 | 
						|
 | 
						|
/* subfn = PROTO_WHITELIST_STATE_RESP_CMD */
 | 
						|
typedef struct _ge_frame_wl_state_resp_subfn17_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /* whitelist state, 1-enable whitelist, 0-disable whitelist */
 | 
						|
    uint8_t            state;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_wl_state_resp_subfn17_t;
 | 
						|
 | 
						|
/* subfn = PROTO_NTB_RESP_CMD */
 | 
						|
typedef struct _ge_frame_ntb_resp_subfn19_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /* ntb */
 | 
						|
    uint32_t           ntb;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_ntb_resp_subfn19_t;
 | 
						|
 | 
						|
/* subfn = PROTO_FB_BITMAP_RESP_CMD */
 | 
						|
typedef struct _ge_frame_fb_bitmap_resp_subfn20_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /**
 | 
						|
     * 0: all bands that MAC has suppprted.
 | 
						|
     * 1: scan bands.
 | 
						|
    */
 | 
						|
    uint8_t            is_scan_bitmap;
 | 
						|
    /**
 | 
						|
     * bitmap defined as follow:
 | 
						|
     * bit0  == 1: support band 0
 | 
						|
     * bit1  == 1: support band 1
 | 
						|
     * ...
 | 
						|
     * bit15 == 1: support band 15
 | 
						|
     */
 | 
						|
    uint16_t           bitmap;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fb_bitmap_resp_subfn20_t;
 | 
						|
 | 
						|
/* subfn = PROTO_FIX_RATE_MODE_RESP_CMD */
 | 
						|
typedef struct _ge_frame_fix_rate_mode_resp_subfn21_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /**
 | 
						|
     * 0:fixed rate mode disable
 | 
						|
     * 1:fixed rate mode enable
 | 
						|
    */
 | 
						|
    uint8_t            enable;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_fix_rate_mode_resp_subfn21_t;
 | 
						|
 | 
						|
/* subfn = PROTO_WORK_BAND_RESP_CMD */
 | 
						|
typedef struct _ge_frame_work_band_resp_subfn22_t {
 | 
						|
    ge_extend_fn_hdr_t hdr;
 | 
						|
    uint8_t            resv0;
 | 
						|
    uint8_t            resv1;
 | 
						|
    uint8_t            seq;
 | 
						|
    /* work band */
 | 
						|
    uint8_t            band;
 | 
						|
    ge_frm_tail_t      tail;
 | 
						|
} ge_frame_work_band_resp_subfn22_t;
 | 
						|
 | 
						|
typedef enum _iot_ge_gpio_dir_mode_e {
 | 
						|
    IOT_GE_GPIO_DIR_NONE,
 | 
						|
    IOT_GE_GPIO_DIR_OUTPUT,
 | 
						|
    IOT_GE_GPIO_DIR_INPUT,
 | 
						|
}iot_ge_gpio_dir_mode_e;
 | 
						|
 | 
						|
typedef enum _iot_ge_gpio_pull_mode_e {
 | 
						|
    IOT_GE_GPIO_PULL_NONE,
 | 
						|
    IOT_GE_GPIO_PULL_UP,
 | 
						|
    IOT_GE_GPIO_PULL_DOWN,
 | 
						|
}iot_ge_gpio_pull_mode_e;
 | 
						|
 | 
						|
typedef enum _iot_ge_gpio_state_e {
 | 
						|
    IOT_GE_GPIO_CLOSE,
 | 
						|
    IOT_GE_GPIO_OPEN,
 | 
						|
}iot_ge_gpio_state_e;
 | 
						|
 | 
						|
/* GPIO config struct */
 | 
						|
typedef struct _iot_ge_gpio_config_t {
 | 
						|
    uint8_t             gpio_num;
 | 
						|
    uint8_t             dir_mode;
 | 
						|
    uint8_t             pull_mode;
 | 
						|
    iot_ge_gpio_state_e gpio_state;
 | 
						|
}iot_ge_gpio_config_t;
 | 
						|
 | 
						|
#pragma pack(pop)
 | 
						|
 | 
						|
extern uint8_t ge_bcast_addr[IOT_MAC_ADDR_LEN];
 | 
						|
extern prototask_contxt_t prototask_contxt;
 | 
						|
extern uart_thpt_t uart_thpt;
 | 
						|
extern iot_ge_gpio_config_t iot_ge_gpio_g[IOT_GE_VALID_GPIO_MAX];
 | 
						|
/**
 | 
						|
 * @brief iot_gree_get_crc_byte - get data from the crc pos in gree frame
 | 
						|
 * @param data:          pointer of reading back data
 | 
						|
 * @retval:              crc data
 | 
						|
 */
 | 
						|
uint16_t iot_gree_get_crc_byte(uint8_t *data);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief ge_frm_checksum_calc - calculate frame check sum
 | 
						|
 * @param data:          data to check
 | 
						|
 * @param data:          data len
 | 
						|
 * @retval:              verification data for gree frame
 | 
						|
 */
 | 
						|
#if GE_CRC_ENABLE
 | 
						|
uint16_t ge_frm_checksum_calc(uint8_t *data, uint16_t len);
 | 
						|
#else
 | 
						|
uint8_t ge_frm_checksum_calc(uint8_t *data, uint16_t len);
 | 
						|
#endif
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_proto_mainboard_data_pend - pend send mainboard data to cache.
 | 
						|
 * @param p_pkt:         data to send
 | 
						|
 */
 | 
						|
void iot_proto_mainboard_data_pend(iot_pkt_t *data);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_proto_resume_pkt_2_mainboard - resume cache pkt to mainboard.
 | 
						|
 */
 | 
						|
void iot_proto_resume_pkt_2_mainboard();
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_proto_send_to_mainboard - send data to mainboard
 | 
						|
 * @param p_pkt:         data to send
 | 
						|
 */
 | 
						|
void iot_proto_send_to_mainboard(iot_pkt_t *p_pkt);
 | 
						|
 | 
						|
/* iot_proto_task_init - init protocol task
 | 
						|
 * @return:
 | 
						|
 * ERR_AGAIN - reinit proto task
 | 
						|
 * ERR_NOMEM - no  memory
 | 
						|
 * ERR_OK    - OK
 | 
						|
*/
 | 
						|
uint32_t iot_proto_task_init();
 | 
						|
 | 
						|
/* iot_proto_task_deinit - deinit protocol task
 | 
						|
*/
 | 
						|
void iot_proto_task_deinit();
 | 
						|
/* iot_proto_uplayer_data_recv_func - register in app,called when recv MCU data
 | 
						|
 * @param:
 | 
						|
 * buf: pointer of recv buffer
 | 
						|
 * len: length of recv buffer
 | 
						|
 * @return:
 | 
						|
 * ERR_NOMEM - no  memory
 | 
						|
 * ERR_OK    - OK
 | 
						|
*/
 | 
						|
uint8_t iot_proto_uplayer_data_recv_func(uint8_t *buf, uint16_t len);
 | 
						|
/* iot_proto_plc_data_recv_func - register in plctxrx,called when recv plc data
 | 
						|
 * @param:
 | 
						|
 * report_framelist: pointer of report frame list
 | 
						|
 * rxinfo: rx information of received frame
 | 
						|
 * @return:
 | 
						|
 * ERR_NOMEM - no  memory
 | 
						|
 * ERR_OK    - OK
 | 
						|
 */
 | 
						|
uint8_t iot_proto_plc_data_recv_func(protpkt_list_t  *report_framelist,
 | 
						|
                                    plctxrx_rx_data_info_t *rxinfo);
 | 
						|
 | 
						|
/* iot_proto_plctxrx_cmd_resp_recv_func - register in plctxrx,
 | 
						|
 *                                called when recv plctxrx cmd
 | 
						|
 * @param:
 | 
						|
 * data: data packet
 | 
						|
 * @return:
 | 
						|
 * ERR_NOMEM - no  memory
 | 
						|
 * ERR_OK    - OK
 | 
						|
*/
 | 
						|
uint8_t iot_proto_plctxrx_cmd_resp_recv_func(iot_pkt_t *data);
 | 
						|
 | 
						|
 | 
						|
/* iot_proto_plctxrx_register - register in protocol layer,
 | 
						|
 *                                called when recv proto data
 | 
						|
 * @param:
 | 
						|
 * cmd_cb: cmd callback function
 | 
						|
 * data_cb: data callback function
 | 
						|
 * @return:
 | 
						|
 * ERR_NOMEM - no  memory
 | 
						|
 * ERR_OK    - OK
 | 
						|
*/
 | 
						|
 | 
						|
uint8_t iot_proto_plctxrx_register(PLCXMIT_CMD_CB cmd_cb,
 | 
						|
                                    PLCXMIT_DATA_CB data_cb);
 | 
						|
 | 
						|
/*
 | 
						|
  register top uart send to proto layer
 | 
						|
*/
 | 
						|
uint8_t iot_proto_register_response_to_uplayer(PROTO_SENDTO_UPLAYER fn);
 | 
						|
 | 
						|
/*
 | 
						|
  register for update cco mac before join the network
 | 
						|
*/
 | 
						|
uint8_t iot_proto_register_update_cco_mac_to_uplayer(PROTO_UPDATA_CCO_MAC fn);
 | 
						|
 | 
						|
/* app registered, proto is ready */
 | 
						|
uint8_t iot_proto_is_ready(void);
 | 
						|
 | 
						|
/*
 | 
						|
   update vendor_infor
 | 
						|
*/
 | 
						|
uint8_t iot_proto_update_vendr(iot_pkt_t *pkt);
 | 
						|
 | 
						|
void iot_proto_cfm_cmd_group(void *buf, uint8_t cmd,
 | 
						|
    uint8_t result, uint8_t reason, uint8_t seq);
 | 
						|
 | 
						|
void iot_proto_wl_save2flash(void);
 | 
						|
 | 
						|
void iot_proto_upgrade_app_pib_info(void);
 | 
						|
 | 
						|
void iot_proto_flashinfo_init(void);
 | 
						|
 | 
						|
void iot_proto_cco_groupnet_sm(uint8_t *data, uint8_t subfn,
 | 
						|
    transmit_direction_e_t dir, void *info);
 | 
						|
 | 
						|
void iot_proto_report_disconn_event2mcu(uint8_t *mac);
 | 
						|
 | 
						|
bool_t iot_proto_set_local_mac_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_join_nw_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_whitelist_set_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_conn_ind_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_start_groupnet_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_end_groupnet_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_reboot_sta_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_cmd_cfm_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_cco_state_ind_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_nid_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_sta_leave_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_comm_fault_ind_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_grapp_reg_conf_ind_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_aes_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_aes_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_resp_aes_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_resp_aes_frame(uint8_t seq);
 | 
						|
 | 
						|
bool_t iot_proto_data_handler(uint8_t *data, uint16_t len,
 | 
						|
    transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_uart_param_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_bc_data_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_local_mac_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_swver_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_boot_info_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_topo_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_net_sts_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_whitelist_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_avail_nw_handler(uint8_t *data, uint16_t len,
 | 
						|
    transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_tx_pwr_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_uart_thrpt_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_nw_detailinfo_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_uart_param_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_ext_query_wl_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_nid_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_wl_state_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_module_info_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_ntb_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_node_info_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_nw_info_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_local_ip4_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_gpio_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_delay_time_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_local_mac_resp_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_fw_swver_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_boot_info_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_topo_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_net_sts_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_whitelist_resp_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_avail_nw_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_tx_power_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_ntb_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_node_info_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_nw_info_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_gpio_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_cctt_dl645_topo_resp(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
void iot_proto_wl_pt_remote_query_timeout_from_mcu(uint32_t state);
 | 
						|
 | 
						|
void iot_proto_wait_rmt_topo_resp_timeout(proto_cmd_hdl_state_t *sm);
 | 
						|
 | 
						|
uint8_t iot_proto_plctxtx_fn_subfn_get(plctxrx_cmd_resp_t *cmd,
 | 
						|
    uint8_t *fn, uint8_t *subfn);
 | 
						|
 | 
						|
void iot_proto_query_mcu_mac();
 | 
						|
 | 
						|
proto_cmd_hdl_state_t* iot_proto_cmd_handle_state_get();
 | 
						|
 | 
						|
void iot_proto_fill_txinfo(protpkt_tx_info_t* txinfo, bool_t need_ack,
 | 
						|
    txrx_type_e send_type, uint8_t retry_cnt, uint16_t retry_intvl,
 | 
						|
    uint16_t sta_cnt, uint8_t *src_mac, uint8_t *dst_mac);
 | 
						|
 | 
						|
void iot_proto_remote_cmd_send_to_plctxrx
 | 
						|
    (uint8_t *data, uint16_t len,protpkt_tx_info_t *txinfo);
 | 
						|
 | 
						|
void iot_proto_whitelist_add_remove(uint8_t action, uint8_t *mac,
 | 
						|
    bool_t need_ack_cfm);
 | 
						|
 | 
						|
void iot_proto_whitelist_remove_all(bool_t need_ack_cfm);
 | 
						|
 | 
						|
void iot_proto_whitelist_en_disable(uint8_t action, bool_t need_ack_cfm);
 | 
						|
 | 
						|
void iot_proto_vendor_info_set(uint8_t *p_passd,
 | 
						|
    bool_t need_ack, uint8_t net_start_flag);
 | 
						|
 | 
						|
void iot_proto_cmd_send_to_plctxrx(iot_pkt_t *p_pkt);
 | 
						|
 | 
						|
void iot_proto_resp_cfm_frame(uint32_t resp, uint32_t dir,
 | 
						|
    uint32_t cmd, uint8_t seq, uint8_t *dst_mac);
 | 
						|
 | 
						|
void iot_proto_boot_ready_ind(uint8_t *local_mac);
 | 
						|
 | 
						|
void iot_proto_cmd_handle_state_init();
 | 
						|
 | 
						|
void iot_proto_set_tx_power(uint8_t tx_power, uint8_t need_ack);
 | 
						|
 | 
						|
void iot_proto_set_mac(uint8_t *mac, uint8_t dev_type, uint8_t need_ack);
 | 
						|
 | 
						|
void iot_proto_data_send_to_plctxrx(uint8_t *data, uint16_t len,
 | 
						|
                              protpkt_tx_info_t *txinfo);
 | 
						|
 | 
						|
bool_t mac_addr_is_valid_addr(uint8_t *mac);
 | 
						|
 | 
						|
bool_t mac_addr_in_flash_is_valid_addr(uint8_t *mac);
 | 
						|
 | 
						|
void iot_proto_whitelist_state_init(void);
 | 
						|
 | 
						|
bool_t iot_proto_wl_or_pt_remote_set_or_query_to_cco(uint8_t *data, uint16_t len,
 | 
						|
    transmit_direction_e_t dir, uint8_t wait_type);
 | 
						|
 | 
						|
int32_t iot_proto_check_mac_exists(uint8_t *mac, proto_dev_t *dev_tb,
 | 
						|
    uint16_t valid_cnt);
 | 
						|
 | 
						|
void iot_proto_add_wl_to_tmp(proto_dev_t *dev);
 | 
						|
 | 
						|
void iot_proto_add_wl_tmp2formal(void);
 | 
						|
 | 
						|
void iot_proto_del_wl_from_formal(void);
 | 
						|
 | 
						|
bool_t mac_addr_is_bcast_addr(uint8_t *mac);
 | 
						|
 | 
						|
void iot_proto_task_post_msg(uint16_t msg_type, uint16_t msg_id, void* data,
 | 
						|
    transmit_direction_e_t dir, uint8_t prio);
 | 
						|
 | 
						|
#define iot_proto_pairtable_state_init()
 | 
						|
/* This will store config onto customor flash area. */
 | 
						|
uint32_t iot_proto_flashsave(ge_app_pib_info_t *p_info);
 | 
						|
uint32_t iot_proto_cust_flashinfo_check(ge_app_pib_info_t *p_info);
 | 
						|
void iot_proto_cust_flashinfo_repair(ge_app_pib_info_t *p_info);
 | 
						|
/*
 | 
						|
   load flash information
 | 
						|
*/
 | 
						|
uint32_t iot_proto_flashload(ge_app_pib_info_t* info);
 | 
						|
/*
 | 
						|
   dump flash information
 | 
						|
*/
 | 
						|
void iot_proto_dumpflash(ge_app_pib_info_t* info);
 | 
						|
 | 
						|
uint8_t uart_baud_find_index(uint32_t baudrate);
 | 
						|
 | 
						|
bool_t iot_proto_uart_param_check(uint32_t baudrate, uint8_t parity,
 | 
						|
    uint8_t data_bits, uint8_t stop_bits);
 | 
						|
 | 
						|
bool_t iot_proto_clr_flashinfo_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_fb_bitmap_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_fb_bitmap_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_fb_bitmap_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
void iot_proto_set_fb_bitmap(uint16_t *p_set_bitmap, bool_t need_ack);
 | 
						|
 | 
						|
bool_t iot_proto_set_fix_rate_mode_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_fix_rate_mode_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_fix_rate_mode_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_cache_data_for_window_rpt(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_query_work_band_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_work_band_resp_subfn_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_sta_paging_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_switch_boot_part_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_config_gpio_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_local_ip4_subfn_handler(uint8_t *data,
 | 
						|
     uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
bool_t iot_proto_set_gpio_handler(uint8_t *data,
 | 
						|
    uint16_t len, transmit_direction_e_t dir);
 | 
						|
 | 
						|
void iot_proto_sta_paging_mac();
 | 
						|
 | 
						|
void iot_proto_custom_pib_info_load(void *cus_pib_info, uint8_t size);
 | 
						|
 | 
						|
void iot_proto_custom_pib_info_save(void *cus_pib_info, uint8_t size);
 | 
						|
 | 
						|
uint8_t iot_proto_data_parse_and_post(uint8_t *buf, uint16_t len,
 | 
						|
    POST_RECV_DATA post_func, uint32_t param);
 | 
						|
 | 
						|
uint16_t iot_proto_get_plc_data_len(uint8_t *src_data, uint16_t data_len);
 | 
						|
 | 
						|
/*
 | 
						|
 * ge_frame_data_len - calculate frame data len
 | 
						|
 * @data:              point to the ge frames
 | 
						|
 * @data_len:          the length of ge frames
 | 
						|
 * @frame_data_len:    point to the data length of first ge frame
 | 
						|
 * @retval: -          error code
 | 
						|
 */
 | 
						|
uint8_t ge_frame_data_len(uint8_t *data, uint16_t data_len,
 | 
						|
    uint16_t *frame_data_len);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_proto_get_cco_mac - gets the CCO address in the belonging network
 | 
						|
 * @param mac: save the cco MAC address
 | 
						|
 * @return: ERR_OK   -> succeeded
 | 
						|
 *          ERR_FAIL -> failed
 | 
						|
 */
 | 
						|
uint8_t iot_proto_get_cco_mac(uint8_t* mac);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_handle_ge_from_plc() - To pickup DL645 data
 | 
						|
 * @param p_pkt:   the pkt include input data
 | 
						|
 */
 | 
						|
void iot_handle_ge_from_plc(iot_pkt_t *p_pkt);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_edge_delay_start() - delay start edge
 | 
						|
 */
 | 
						|
void iot_edge_delay_start(void);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief is_edge_running() - check the edge status: running or not
 | 
						|
 * @retval:        true or false
 | 
						|
 */
 | 
						|
uint8_t is_edge_running(void);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_edge_post_to_proto_msg_handle() - edge post message to proto
 | 
						|
 * @param p_pkt:   point to message
 | 
						|
 * @param msg_id:  message id
 | 
						|
 */
 | 
						|
void iot_edge_post_to_proto_msg_handle(void *p_pkt, uint8_t msg_id);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_proto_post_dl645_cmd_msg() - post dl645 message to proto
 | 
						|
 * @param data:   dl645 data
 | 
						|
 * @param len:    dl645 data len
 | 
						|
 * @retval:       true or false
 | 
						|
 */
 | 
						|
uint8_t iot_proto_post_dl645_cmd_msg(uint8_t *data, uint16_t len);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_proto_cli_uart_gpio_reassign() - reassign cli uart tx rx gpio
 | 
						|
 *                ge_ext app use this function need after grapp_init.
 | 
						|
 * @param rxpin:  reassign rx_gpio
 | 
						|
 * @param txpin:  reassign tx_gpio
 | 
						|
 * @return: 0   -> error
 | 
						|
 *          1   -> success
 | 
						|
 */
 | 
						|
uint8_t iot_proto_cli_uart_gpio_reassign(uint8_t rxpin, uint8_t txpin);
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif /* IOT_PROTO_H */
 |