812 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			812 lines
		
	
	
		
			27 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.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
#include "iot_io.h"
 | 
						|
 | 
						|
#include "iot_cli_host_interface.h"
 | 
						|
#include "iot_cli_plc_module.h"
 | 
						|
#include "iot_cli_msg.h"
 | 
						|
#include "iot_cli_plc_tx_rx.h"
 | 
						|
#include "iot_cli_sg_api.h"
 | 
						|
#include "iot_cli_sg_ctrl_api.h"
 | 
						|
#include "iot_cli_sg.h"
 | 
						|
#include "iot_cli_upgrade_status_type_def.h"
 | 
						|
#include "iot_cli_upgrade.h"
 | 
						|
 | 
						|
#if IOT_CLI_SG_INTERFACE_ENABLE
 | 
						|
 | 
						|
extern iot_plc_host_config_t *host_config;
 | 
						|
extern iot_cli_host_info_t *host_info;
 | 
						|
 | 
						|
uint8_t iot_cli_sg_get_headroom_req()
 | 
						|
{
 | 
						|
    return sizeof(iot_cli_sg_msg_header_t);
 | 
						|
}
 | 
						|
 | 
						|
uint32_t iot_cli_sg_interface_register(iot_cli_sg_interface_t *cli_interface)
 | 
						|
{
 | 
						|
    if (cli_interface == NULL) {
 | 
						|
        return IOT_CLI_SG_REGISTER_FAILURE;
 | 
						|
    }
 | 
						|
    host_config->cli_sg_interface = cli_interface;
 | 
						|
    return IOT_CLI_SG_REGISTER_SUCCESS;
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_prep_msg(iot_pkt_t *pkt, uint8_t msg_id, uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_cli_sg_msg_header_t *hd;
 | 
						|
    hd = (iot_cli_sg_msg_header_t *)iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_HEAD);
 | 
						|
    hd->msg_id = msg_id;
 | 
						|
    hd->req_id = req_id;
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_send_cmd(uint8_t req_id, uint8_t msg_id,
 | 
						|
    uint8_t *data, uint32_t data_len)
 | 
						|
{
 | 
						|
    iot_pkt_t *pkt = NULL;
 | 
						|
    uint8_t *data_ptr;
 | 
						|
 | 
						|
    if (host_config->cli_sg_interface == NULL) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    pkt = iot_pkt_alloc(data_len + iot_cli_sg_get_headroom_req(), IOT_CLI_MID);
 | 
						|
    IOT_ASSERT(pkt);
 | 
						|
 | 
						|
    data_ptr = iot_pkt_reserve(pkt, iot_cli_sg_get_headroom_req());
 | 
						|
    iot_cli_sg_prep_msg(pkt, msg_id, req_id);
 | 
						|
 | 
						|
    if (data && data_len) {
 | 
						|
        iot_pkt_set_tail(pkt,
 | 
						|
            iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_DATA) + data_len);
 | 
						|
        os_mem_cpy(data_ptr, data, data_len);
 | 
						|
    }
 | 
						|
 | 
						|
    host_config->cli_sg_interface->recv(NULL, pkt);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_send_data_to_cli_interface(iot_pkt_t *pkt, uint8_t msg_id,
 | 
						|
    uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_task_msg_t *t_msg;
 | 
						|
    if (pkt == NULL) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_prep_msg(pkt, msg_id, req_id);
 | 
						|
    t_msg = iot_cli_create_cli_msg(IOT_CLI_SG_MSG, pkt);
 | 
						|
    if (t_msg) {
 | 
						|
        iot_task_queue_msg(
 | 
						|
            host_info->host_task_h, t_msg, IOT_CLI_QUEUE_HOST);
 | 
						|
    } else if (pkt) {
 | 
						|
        iot_pkt_free(pkt);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_set_mac(uint8_t req_id, iot_cli_sg_set_mac_dl_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SET_MAC, (uint8_t *)data,
 | 
						|
        sizeof(*data));
 | 
						|
}
 | 
						|
 | 
						|
#if IOT_CLI_SUPPORT_WL_CMD
 | 
						|
 | 
						|
void iot_sg_cli_query_wl_state(uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_QUERY_WL_STATE, NULL, 0);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_query_wl(uint8_t req_id, iot_cli_sg_query_wl_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_QUERY_WL,
 | 
						|
        (uint8_t *)data, sizeof(iot_cli_sg_query_wl_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_add_wl(uint8_t req_id, iot_cli_sg_add_wl_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_ADD_WL,
 | 
						|
        (uint8_t *)data,
 | 
						|
        sizeof(iot_cli_sg_add_wl_t) + data->count * sizeof(data->node_info[0]));
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_rm_wl(uint8_t req_id, iot_cli_sg_rm_wl_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_RM_WL,
 | 
						|
        (uint8_t *)data,
 | 
						|
        sizeof(iot_cli_sg_rm_wl_t) + data->count * IOT_MAC_ADDR_LEN);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_set_wl_state(uint8_t req_id, iot_cli_sg_set_wl_state_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SET_WL_STATE,
 | 
						|
        (uint8_t *)data, sizeof(iot_cli_sg_set_wl_state_t));
 | 
						|
}
 | 
						|
 | 
						|
static uint8_t iot_cli_sg_handle_wl_msg(iot_cli_sg_msg_header_t *hdr,
 | 
						|
    uint8_t *data)
 | 
						|
{
 | 
						|
    uint8_t done = 1;
 | 
						|
    cli_app_cmd_mapping_item *cmd = NULL;
 | 
						|
    uint8_t *cli_src_mac = NULL;
 | 
						|
 | 
						|
    IOT_ASSERT(hdr);
 | 
						|
 | 
						|
    if (hdr->req_id) {
 | 
						|
        cmd = get_cmd_from_mapping_table(hdr->req_id);
 | 
						|
    }
 | 
						|
 | 
						|
    if (cmd) {
 | 
						|
        cli_src_mac = cmd->mac;
 | 
						|
        iot_printf("plc_sg_handle_mac_mapping msg=%d, index=%d\n", \
 | 
						|
            hdr->msg_id, hdr->req_id);
 | 
						|
    }
 | 
						|
 | 
						|
    switch (hdr->msg_id) {
 | 
						|
    case IOT_CLI_SG_MSG_RPT_WL_STATE:
 | 
						|
    {
 | 
						|
        iot_cli_sg_rpt_wl_state_t *rsp = (iot_cli_sg_rpt_wl_state_t *)data;
 | 
						|
        iot_printf("%s: wl state is %d\n", __FUNCTION__, rsp->state);
 | 
						|
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_GETWHITELIST_STATE_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_rpt_wl_state_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_WL:
 | 
						|
    {
 | 
						|
        iot_cli_sg_rpt_wl_t *rsp = (iot_cli_sg_rpt_wl_t *)data;
 | 
						|
        iot_printf("%s: total node: %d, transfer node: %d\n", __FUNCTION__,
 | 
						|
            rsp->total_count, rsp->rsp_count);
 | 
						|
        for (uint32_t i = 0; i < rsp->rsp_count; ++i) {
 | 
						|
            iot_printf("meter mac=[%02X:%02X:%02X:%02X:%02X:%02X],"
 | 
						|
                " proto type=%d\n",
 | 
						|
                rsp->node_info[i].mac[0], rsp->node_info[i].mac[1],
 | 
						|
                rsp->node_info[i].mac[2], rsp->node_info[i].mac[3],
 | 
						|
                rsp->node_info[i].mac[4], rsp->node_info[i].mac[5],
 | 
						|
                rsp->node_info[i].proto_type);
 | 
						|
        }
 | 
						|
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_GETWHITELIST_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_rpt_wl_t) +
 | 
						|
            (sizeof(rsp->node_info[0]) * rsp->rsp_count), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_ADD_WL:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: add wl is %lu\n", __FUNCTION__, rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_ADD_WHITELIST_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_RM_WL:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: rm wl is %lu\n", __FUNCTION__, rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_RM_WHITELIST_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_SET_WL_STATE:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: set wl state is %lu\n", __FUNCTION__, rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_SET_WHITELIST_STATE_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    default:
 | 
						|
        done = 0;
 | 
						|
        break;
 | 
						|
    }
 | 
						|
 | 
						|
    return done;
 | 
						|
}
 | 
						|
 | 
						|
#endif /* IOT_CLI_SUPPORT_WL_CMD */
 | 
						|
 | 
						|
#if PLC_SUPPORT_CCO_ROLE
 | 
						|
 | 
						|
void iot_cli_sg_get_meter_data(uint8_t req_id, uint8_t *data,
 | 
						|
    uint32_t datalen)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_GET_METER, data, datalen);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_get_meter_rt_data(uint8_t req_id, uint8_t *data,
 | 
						|
    uint32_t datalen)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_GET_RT_METER, data, datalen);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_get_report_ack(uint8_t req_id, uint8_t *data,
 | 
						|
    uint32_t datalen)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_GET_REPORT_ACK, data, datalen);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_handle_user_data(uint8_t req_id, uint8_t* src_mac,
 | 
						|
    uint8_t *data, uint32_t datalen)
 | 
						|
{
 | 
						|
    iot_pkt_t *pkt = NULL;
 | 
						|
    iot_cli_sg_user_data_dl_t *user_data;
 | 
						|
 | 
						|
    if (host_config->cli_sg_interface == NULL) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    pkt = iot_pkt_alloc(iot_cli_sg_get_headroom_req() +
 | 
						|
        datalen + sizeof(iot_cli_sg_user_data_dl_t), IOT_CLI_MID);
 | 
						|
    IOT_ASSERT(pkt);
 | 
						|
 | 
						|
    user_data = (iot_cli_sg_user_data_dl_t *)
 | 
						|
        iot_pkt_reserve(pkt, iot_cli_sg_get_headroom_req());
 | 
						|
    iot_cli_sg_prep_msg(pkt, IOT_CLI_SG_MSG_HANDLE_USER_DATA, req_id);
 | 
						|
    iot_pkt_put(pkt, datalen + sizeof(iot_cli_sg_user_data_dl_t));
 | 
						|
 | 
						|
    os_mem_cpy(user_data->src_mac, src_mac, CLI_MAC_ADDR_LEN);
 | 
						|
    user_data->data_len = (uint8_t)datalen;
 | 
						|
    os_mem_cpy(user_data->data, data, user_data->data_len);
 | 
						|
 | 
						|
    host_config->cli_sg_interface->recv(NULL, pkt);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_start_get_meter_list(uint8_t req_id, uint16_t duration)
 | 
						|
{
 | 
						|
    iot_pkt_t *pkt = NULL;
 | 
						|
    iot_cli_sg_start_sec_node_reg_dl_t *rpt;
 | 
						|
 | 
						|
    if (host_config->cli_sg_interface == NULL) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    host_config->cli_request_id = req_id;
 | 
						|
 | 
						|
    pkt = iot_pkt_alloc(CLI_SG_MSG_SHORT_BUF_SIZE, IOT_CLI_MID);
 | 
						|
    IOT_ASSERT(pkt);
 | 
						|
 | 
						|
    rpt = (iot_cli_sg_start_sec_node_reg_dl_t *)iot_pkt_reserve(pkt,
 | 
						|
        iot_cli_sg_get_headroom_req());
 | 
						|
    iot_cli_sg_prep_msg(pkt, IOT_CLI_SG_MSG_START_METER_LIST, req_id);
 | 
						|
    iot_pkt_put(pkt, sizeof(iot_cli_sg_start_sec_node_reg_dl_t));
 | 
						|
 | 
						|
    rpt->duration = duration;
 | 
						|
 | 
						|
    host_config->cli_sg_interface->recv(NULL, pkt);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_stop_get_meter_list(uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_STOP_METER_LIST, NULL, 0);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_get_meter_list(uint8_t req_id, uint16_t start_index,
 | 
						|
    uint8_t count)
 | 
						|
{
 | 
						|
    iot_pkt_t *pkt = NULL;
 | 
						|
    iot_cli_sg_get_sec_node_info_dl_t *req;
 | 
						|
 | 
						|
    if (host_config->cli_sg_interface == NULL) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    pkt = iot_pkt_alloc(CLI_SG_MSG_SHORT_BUF_SIZE, IOT_CLI_MID);
 | 
						|
    IOT_ASSERT(pkt);
 | 
						|
 | 
						|
    req = (iot_cli_sg_get_sec_node_info_dl_t *)iot_pkt_reserve(pkt,
 | 
						|
        iot_cli_sg_get_headroom_req());
 | 
						|
    iot_cli_sg_prep_msg(pkt, IOT_CLI_SG_MSG_GET_METER_LIST, req_id);
 | 
						|
    iot_pkt_put(pkt, sizeof(iot_cli_sg_get_sec_node_info_dl_t));
 | 
						|
 | 
						|
    req->sec_node_start_index = start_index;
 | 
						|
    req->sec_node_count = count;
 | 
						|
 | 
						|
    host_config->cli_sg_interface->recv(NULL, pkt);
 | 
						|
}
 | 
						|
 | 
						|
void cli_upgrade_dst_status_sg_query(uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_QUERY_UPGRADE_STATUS, NULL, 0);
 | 
						|
}
 | 
						|
 | 
						|
void cli_upgrade_dst_status_sg_list(uint16_t start_index,
 | 
						|
    uint8_t dst_num, uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_pkt_t *pkt = NULL;
 | 
						|
    iot_cli_sg_upgrade_progress_dl *query;
 | 
						|
    if (host_config->cli_sg_interface == NULL) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    pkt = iot_pkt_alloc(CLI_SG_MSG_SHORT_BUF_SIZE, IOT_CLI_MID);
 | 
						|
    IOT_ASSERT(pkt);
 | 
						|
 | 
						|
    query = (iot_cli_sg_upgrade_progress_dl *)iot_pkt_reserve(pkt,
 | 
						|
        iot_cli_sg_get_headroom_req());
 | 
						|
    iot_cli_sg_prep_msg(pkt, IOT_CLI_SG_MSG_QUERY_UPGRADE_PROGRESS, req_id);
 | 
						|
    iot_pkt_put(pkt, sizeof(iot_cli_sg_upgrade_progress_dl));
 | 
						|
 | 
						|
    query->start_index = start_index;
 | 
						|
    query->dst_num = dst_num;
 | 
						|
 | 
						|
    host_config->cli_sg_interface->recv(NULL, pkt);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_set_tsfm_detect_state(uint8_t req_id,
 | 
						|
    iot_cli_sg_set_tsfm_detect_state_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SET_TSFM_DETECT_STATE,
 | 
						|
        (uint8_t *)data, sizeof(iot_cli_sg_set_tsfm_detect_state_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_query_tsfm_detect_state(uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id,
 | 
						|
        IOT_CLI_SG_MSG_QUERY_TSFM_DETECT_STATE, NULL, 0);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_set_con_mr_param(uint8_t req_id,
 | 
						|
    iot_cli_sg_con_mr_param_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SET_CON_MR_PARAM,
 | 
						|
        (uint8_t *)data, sizeof(iot_cli_sg_con_mr_param_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_query_con_mr_param(uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_QUERY_CON_MR_PARAM, NULL, 0);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_plc_mgr_state_change(uint8_t req_id,
 | 
						|
    iot_cli_sg_plc_mgr_state_change_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_PLC_MGR_STATE_CHANGE,
 | 
						|
        (uint8_t *)data, sizeof(iot_cli_sg_plc_mgr_state_change_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_bd_start(uint8_t req_id, iot_cli_sg_bd_start_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_BD_START, (uint8_t *)data,
 | 
						|
        sizeof(iot_cli_sg_bd_start_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_bd_query_state(uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_BD_QUERY_STATE, NULL, 0);
 | 
						|
}
 | 
						|
 | 
						|
void iot_sg_cli_bd_query_ret(uint8_t req_id, iot_cli_sg_bd_query_ret_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_BD_QUERY_RESULT, (uint8_t *)data,
 | 
						|
        sizeof(iot_cli_sg_bd_query_ret_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_set_esp(uint8_t req_id, iot_cli_sg_set_esp_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SET_ESP, (uint8_t *)data,
 | 
						|
        sizeof(iot_cli_sg_set_esp_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_query_esp(uint8_t req_id)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_QUERY_ESP, NULL, 0);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_query_node_info(uint8_t req_id,
 | 
						|
    iot_cli_sg_qr_node_info_dl_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_QUERY_NODE_INFO,
 | 
						|
        (uint8_t *)data, sizeof(iot_cli_sg_qr_node_info_dl_t));
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_send_broadcast_data(uint8_t req_id,
 | 
						|
    iot_cli_sg_send_broadcast_data_dl *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SEND_BROADCAST_DATA,
 | 
						|
        (uint8_t *)data, sizeof(*data) + data->len);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_handle_msg(iot_pkt_t *pkt)
 | 
						|
{
 | 
						|
    iot_cli_sg_msg_header_t *hdr =
 | 
						|
        (iot_cli_sg_msg_header_t*)iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_HEAD);
 | 
						|
    uint8_t *data = iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_DATA);
 | 
						|
    uint32_t msg_id = CLI_MSGID_GETMETERLIST_RESP;
 | 
						|
    uint8_t *cli_src_mac = NULL;
 | 
						|
    cli_app_cmd_mapping_item *cmd = NULL;
 | 
						|
 | 
						|
    IOT_ASSERT(hdr);
 | 
						|
#if IOT_CLI_SUPPORT_WL_CMD
 | 
						|
    if (iot_cli_sg_handle_wl_msg(hdr, data)) {
 | 
						|
        iot_pkt_free(pkt);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
#endif /* IOT_CLI_SUPPORT_WL_CMD */
 | 
						|
    if ((IOT_CLI_SG_MSG_PRT_METER_DATA == hdr->msg_id) ||
 | 
						|
        (IOT_CLI_SG_MSG_PRT_RT_REQ_MR_DATA == hdr->msg_id) ||
 | 
						|
        (IOT_CLI_SG_MSG_PRT_SEARCH_METER_LIST == hdr->msg_id)) {
 | 
						|
        cmd = get_cmd_from_mapping_table(host_config->cli_request_id);
 | 
						|
    } else if (hdr->req_id) {
 | 
						|
        cmd = get_cmd_from_mapping_table(hdr->req_id);
 | 
						|
    }
 | 
						|
 | 
						|
    if (cmd) {
 | 
						|
        cli_src_mac = cmd->mac;
 | 
						|
        iot_printf("plc_sg_handle_mac_mapping msg=%d, index=%d\n", \
 | 
						|
            hdr->msg_id, hdr->req_id);
 | 
						|
    }
 | 
						|
 | 
						|
    switch (hdr->msg_id) {
 | 
						|
    case IOT_CLI_SG_MSG_RPT_CONFIG_INFO:
 | 
						|
    {
 | 
						|
        iot_cli_sg_config_t *rpt = (iot_cli_sg_config_t *)data;
 | 
						|
        host_config->proto = rpt->proto;
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_PRT_METER:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: rsp mr data ack : %d \n", __FUNCTION__,
 | 
						|
            rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_GET_METER_DATA_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_PRT_METER_DATA:
 | 
						|
    {
 | 
						|
        iot_cli_sg_rpt_mr_data_ul *rsp = (iot_cli_sg_rpt_mr_data_ul *)data;
 | 
						|
        iot_printf("%s: start report mr data ,proto %d len %lu\n", __FUNCTION__,
 | 
						|
            rsp->proto_type, rsp->datalen);
 | 
						|
        cli_ul_send_with_retry(CLI_MSGID_GET_METER_DATA_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_rpt_mr_data_ul) + rsp->datalen, cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_PRT_RT_REQ_MR_DATA:
 | 
						|
    {
 | 
						|
        iot_cli_request_rt_mr_data_ul *req =
 | 
						|
            (iot_cli_request_rt_mr_data_ul *)data;
 | 
						|
        iot_printf("%s: rt request meter reading ,opt_flag %d MAC: \
 | 
						|
            mac: %02X:%02X:%02X:%02X:%02X:%02X\n", __FUNCTION__, req->opt_flag,
 | 
						|
            req->mac_addr[0], req->mac_addr[1], req->mac_addr[2],
 | 
						|
            req->mac_addr[3], req->mac_addr[4], req->mac_addr[5]);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_GET_METER_RT_DATA_REQ, (uint8_t*)req,
 | 
						|
            sizeof(iot_cli_request_rt_mr_data_ul), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_START_METER_LIST:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: start get meter list result: %lu\n", __FUNCTION__,
 | 
						|
            rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_START_SEARCH_METER_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_STOP_METER_LIST:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: stop get meter list result: %lu\n", __FUNCTION__,
 | 
						|
            rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_STOP_SEARCH_METER_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_PRT_SEARCH_METER_LIST:
 | 
						|
    {
 | 
						|
        /* fall to next case by design. */
 | 
						|
        msg_id = CLI_MSGID_SEARCH_MERLIST_RESP;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_METER_LIST:
 | 
						|
    {
 | 
						|
        iot_cli_sg_rpt_sec_node_info_ul_t *rsp =
 | 
						|
            (iot_cli_sg_rpt_sec_node_info_ul_t *)data;
 | 
						|
 | 
						|
        iot_printf("%s: total node: %d, transfer node: %d\n", __FUNCTION__,
 | 
						|
            rsp->sec_node_count, rsp->rsp_sec_node_count);
 | 
						|
        for (uint32_t i = 0; i < rsp->rsp_sec_node_count; ++i) {
 | 
						|
            iot_printf("meter mac=[%02X:%02X:%02X:%02X:%02X:%02X], \
 | 
						|
                sta mac=[%02X:%02X:%02X:%02X:%02X:%02X]\n",
 | 
						|
                rsp->node_info[i].meter_mac[0], rsp->node_info[i].meter_mac[1],
 | 
						|
                rsp->node_info[i].meter_mac[2], rsp->node_info[i].meter_mac[3],
 | 
						|
                rsp->node_info[i].meter_mac[4], rsp->node_info[i].meter_mac[5],
 | 
						|
                rsp->node_info[i].sta_mac[0], rsp->node_info[i].sta_mac[1],
 | 
						|
                rsp->node_info[i].sta_mac[2], rsp->node_info[i].sta_mac[3],
 | 
						|
                rsp->node_info[i].sta_mac[4], rsp->node_info[i].sta_mac[5]);
 | 
						|
        }
 | 
						|
 | 
						|
        iot_cli_send_to_host(msg_id, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_rpt_sec_node_info_ul_t) +
 | 
						|
            (sizeof(rsp->node_info[0]) * rsp->rsp_sec_node_count), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_SEARCH_METER_DONE:
 | 
						|
    {
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_METERLIST_DATA_DONE_RESP, NULL, 0, cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_PRT_UPGRADE_STATUS:
 | 
						|
    {
 | 
						|
        iot_plc_upgrade_dst_status_query *req =
 | 
						|
            (iot_plc_upgrade_dst_status_query *)data;
 | 
						|
        iot_plc_upgrade_dst_status_query_ul requl;
 | 
						|
        os_mem_cpy(&(requl.query), req, sizeof(*req));
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_UPGRADE_DST_STATUS_QUERY_ACK,
 | 
						|
            (uint8_t*)&requl, sizeof(iot_plc_upgrade_dst_status_query_ul),
 | 
						|
            cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_PRT_UPGRADE_PROGRESS:
 | 
						|
    {
 | 
						|
        iot_plc_upgrade_dst_status_list *req =
 | 
						|
            (iot_plc_upgrade_dst_status_list *)data;
 | 
						|
        iot_plc_upgrade_dst_status_list_ul requl;
 | 
						|
        os_mem_cpy(&(requl.status_list), req, sizeof(*req));
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_UPGRADE_DST_STATUS_LIST_ACK,
 | 
						|
            (uint8_t*)&requl, sizeof(iot_plc_upgrade_dst_status_list_ul),
 | 
						|
            cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_EVT_DATA:
 | 
						|
    {
 | 
						|
        iot_cli_sg_rpt_evt_data_t *rsp = (iot_cli_sg_rpt_evt_data_t *)data;
 | 
						|
        iot_printf("%s: report event data.\n", __FUNCTION__);
 | 
						|
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_RPT_EVENT_DATA, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_rpt_evt_data_t) + rsp->data_len, cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_SET_TSFM_DETECT_STATE:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: set tsfm detect state is %lu.\n",
 | 
						|
            __FUNCTION__, rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_SET_TSFM_DETECT_STATE_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_TSFM_DETECT_STATE:
 | 
						|
    {
 | 
						|
        iot_cli_sg_rpt_tsfm_detect_state_t *rsp =
 | 
						|
            (iot_cli_sg_rpt_tsfm_detect_state_t *)data;
 | 
						|
        iot_printf("%s: query tsfm detect state: %lu, sta lock: %lu, "
 | 
						|
            "tsfm detect progress: %lu\n", __FUNCTION__, rsp->tsfm_detect_state,
 | 
						|
            rsp->sta_lock, rsp->tsfm_detect_progress);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_QUERY_TSFM_DETECT_STATE_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_rpt_tsfm_detect_state_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_USER_DATA:
 | 
						|
    {
 | 
						|
        iot_cli_sg_send_user_data_t *rsp = (iot_cli_sg_send_user_data_t *)data;
 | 
						|
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_USER_DATA, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_send_user_data_t) + rsp->data_len,
 | 
						|
            rsp->target_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_SET_EVENT_RPT_ENABLED:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: set event enabled result: %lu\n", __FUNCTION__,
 | 
						|
            rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_SET_EVENT_RPT_ENABLED_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_SET_CCTT_DATA_ENABLED:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: set enable cctt data result: %lu\n", __FUNCTION__,
 | 
						|
            rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_SET_CCTT_DATA_ENABLED_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_SET_CON_MR_PARAM:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: set con mr param is %lu.\n", __FUNCTION__, rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSG_SET_CON_MR_PARAM_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_QUERY_CON_MR_PARAM:
 | 
						|
    {
 | 
						|
        iot_cli_sg_con_mr_param_t *rsp = (iot_cli_sg_con_mr_param_t *)data;
 | 
						|
        iot_printf("%s: query con mr param, sec_node_monitor_timeout: %lu, "
 | 
						|
            "max_bcast_con_count: %lu\n", __FUNCTION__,
 | 
						|
            rsp->sec_node_monitor_timeout, rsp->max_bcast_con_count);
 | 
						|
        iot_cli_send_to_host(CLI_MSG_QUERY_CON_MR_PARAM_RESP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_con_mr_param_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_BD_START:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: bd start %lu.\n", __FUNCTION__, rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_BD_START_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_BD_QUERY_STATE:
 | 
						|
    {
 | 
						|
        iot_cli_sg_bd_rpt_state_t *rsp = (iot_cli_sg_bd_rpt_state_t *)data;
 | 
						|
        iot_printf("%s: bd state: %lu\n", __FUNCTION__, rsp->state);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_BD_QUERY_STATE_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_bd_rpt_state_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_BD_QUERY_RESULT:
 | 
						|
    {
 | 
						|
        iot_cli_sg_bd_ret_rpt_t *rsp = (iot_cli_sg_bd_ret_rpt_t *)data;
 | 
						|
        iot_printf("%s: bd result total_cnt: %lu, start_index: %lu, "
 | 
						|
            "rpt_cnt: %lu\n", __FUNCTION__, rsp->total_cnt, rsp->start_index,
 | 
						|
            rsp->rpt_cnt);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_BD_QUERY_RET_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_bd_ret_rpt_t) +
 | 
						|
            (rsp->rpt_cnt * sizeof(rsp->node_info[0])), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_ESP_RESULT:
 | 
						|
    {
 | 
						|
        iot_cli_sg_rpt_esp_t *rsp = (iot_cli_sg_rpt_esp_t *)data;
 | 
						|
        iot_printf("%s: rpt cco esp %lu\n", __FUNCTION__, rsp->esp);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_SET_ESP_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_rpt_esp_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_NODE_INFO:
 | 
						|
    {
 | 
						|
        iot_cli_sg_qr_node_info_ul_t *rsp =
 | 
						|
            (iot_cli_sg_qr_node_info_ul_t *)data;
 | 
						|
        iot_printf("%s: totoal_cnt %lu, start_index %lu, count %lu\n",
 | 
						|
            __FUNCTION__, rsp->total_cnt, rsp->start_index, rsp->rpt_cnt);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_NODE_INFO_RSP, (uint8_t*)rsp,
 | 
						|
            sizeof(*rsp) + (rsp->rpt_cnt * sizeof(*rsp->node_info)),
 | 
						|
            cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_SEND_BROADCAST_DATA:
 | 
						|
    {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: send broadcast data result %lu.\n", __FUNCTION__,
 | 
						|
            rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_SEND_BROADCAST_RSP, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_MSG_RPT_LOCAL_PROTO_DATA:
 | 
						|
    {
 | 
						|
        iot_cli_sg_resp_local_proto_data_ul_t *rsp =
 | 
						|
            (iot_cli_sg_resp_local_proto_data_ul_t*)data;
 | 
						|
 | 
						|
        iot_printf("%s: send response data to cli, dataLen:%d\n", __FUNCTION__,
 | 
						|
            rsp->date_len);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_TRANS_USER_LOCAL_PROTO_DATA_RESP,
 | 
						|
            (uint8_t *)rsp,
 | 
						|
            sizeof(iot_cli_sg_resp_local_proto_data_ul_t) + rsp->date_len,
 | 
						|
            cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    default:
 | 
						|
        IOT_ASSERT(0);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    iot_pkt_free(pkt);
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_set_event_rpt_enabled(uint8_t req_id,
 | 
						|
    iot_cli_sg_set_event_enabled_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SET_EVENT_RPT_ENABLED,
 | 
						|
        (uint8_t *)data, sizeof(*data));
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_set_cctt_data_enabled(uint8_t req_id,
 | 
						|
    iot_cli_sg_set_cctt_data_enabled_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_MSG_SET_CCTT_DATA_ENABLED,
 | 
						|
        (uint8_t *)data, sizeof(*data));
 | 
						|
}
 | 
						|
 | 
						|
void iot_cli_sg_trans_local_proto_data(uint8_t req_id,
 | 
						|
    iot_cli_sg_trans_local_proto_data_dl_t *data)
 | 
						|
{
 | 
						|
    iot_sg_cli_send_cmd(req_id, IOT_CLI_SG_TRANS_LOCAL_PROTO_DATA, data->data,
 | 
						|
        data->data_len);
 | 
						|
}
 | 
						|
 | 
						|
#elif ((IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA) && \
 | 
						|
    (IOT_SG_CONTROLLER_ENABLE == 1))
 | 
						|
 | 
						|
void iot_cli_sg_handle_msg(iot_pkt_t *pkt)
 | 
						|
{
 | 
						|
    iot_cli_sg_msg_header_t *hdr =
 | 
						|
        (iot_cli_sg_msg_header_t*)iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_HEAD);
 | 
						|
    uint8_t cli_src_mac[6] = { 0 };
 | 
						|
 | 
						|
    IOT_ASSERT(hdr);
 | 
						|
 | 
						|
    iot_printf("%s: msg id : %lu \n", __FUNCTION__, hdr->msg_id);
 | 
						|
    switch (hdr->msg_id) {
 | 
						|
    case IOT_CLI_SG_CTRL_MSG_RPT_IS_READY:
 | 
						|
    {
 | 
						|
        iot_cli_sg_ctrl_is_ready_t *rsp;
 | 
						|
        rsp = (iot_cli_sg_ctrl_is_ready_t *)iot_pkt_block_ptr(pkt,
 | 
						|
            IOT_PKT_BLOCK_DATA);
 | 
						|
        iot_printf("%s: ctrl is ready : %lu \n", __FUNCTION__, rsp->ready);
 | 
						|
        if (rsp->ready) {
 | 
						|
            iot_cli_host_set_ctrl_connected(1);
 | 
						|
        } else {
 | 
						|
            iot_cli_host_set_ctrl_connected(0);
 | 
						|
        }
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    case IOT_CLI_SG_CTRL_MSG_RPT_DATA_UL:
 | 
						|
    {
 | 
						|
        iot_cli_sg_ctrl_data_ul_t *rsp;
 | 
						|
        rsp = (iot_cli_sg_ctrl_data_ul_t *)iot_pkt_block_ptr(pkt,
 | 
						|
            IOT_PKT_BLOCK_DATA);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_CTRL_DATA_UL, (uint8_t *)rsp,
 | 
						|
            sizeof(*rsp) + rsp->data_len, cli_src_mac);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    default:
 | 
						|
        IOT_ASSERT(0);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_pkt_free(pkt);
 | 
						|
}
 | 
						|
 | 
						|
#elif IOT_SMART_CONFIG
 | 
						|
 | 
						|
void iot_cli_sg_handle_msg(iot_pkt_t *pkt)
 | 
						|
{
 | 
						|
    iot_cli_sg_msg_header_t *hdr =
 | 
						|
        (iot_cli_sg_msg_header_t*)iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_HEAD);
 | 
						|
    uint8_t *data = iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_DATA);
 | 
						|
    cli_app_cmd_mapping_item *cmd = NULL;
 | 
						|
    uint8_t *cli_src_mac = NULL;
 | 
						|
 | 
						|
    IOT_ASSERT(hdr);
 | 
						|
#if IOT_CLI_SUPPORT_WL_CMD
 | 
						|
    if (iot_cli_sg_handle_wl_msg(hdr, data)) {
 | 
						|
        iot_pkt_free(pkt);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
#endif /* IOT_CLI_SUPPORT_WL_CMD */
 | 
						|
 | 
						|
    if (hdr->req_id) {
 | 
						|
        cmd = get_cmd_from_mapping_table(hdr->req_id);
 | 
						|
    }
 | 
						|
    if (cmd) {
 | 
						|
        cli_src_mac = cmd->mac;
 | 
						|
        iot_printf("plc_sg_handle_mac_mapping msg=%d, index=%d\n", \
 | 
						|
            hdr->msg_id, hdr->req_id);
 | 
						|
    }
 | 
						|
    if (hdr->msg_id == IOT_CLI_SG_MSG_RPT_MAC) {
 | 
						|
        iot_cli_sg_result_t *rsp = (iot_cli_sg_result_t *)data;
 | 
						|
        iot_printf("%s: rsp set mac ack : %d \n", __FUNCTION__,
 | 
						|
            rsp->result);
 | 
						|
        iot_cli_send_to_host(CLI_MSGID_SET_MAC_ACK, (uint8_t*)rsp,
 | 
						|
            sizeof(iot_cli_sg_result_t), cli_src_mac);
 | 
						|
    }
 | 
						|
    iot_pkt_free(pkt);
 | 
						|
}
 | 
						|
 | 
						|
#endif /* PLC_SUPPORT_CCO_ROLE */
 | 
						|
 | 
						|
#endif /* IOT_CLI_SG_INTERFACE_ENABLE */
 |