360 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			360 lines
		
	
	
		
			9.9 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 "os_utils_api.h"
 | 
						|
#include "iot_io_api.h"
 | 
						|
 | 
						|
#include "iot_cli_host_interface.h"
 | 
						|
#include "iot_cli_ckb.h"
 | 
						|
#include "iot_cli_sg.h"
 | 
						|
 | 
						|
#if IOT_CLI_SUPPORT_WL_CMD
 | 
						|
 | 
						|
void cli_get_white_list_state(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)buffer;
 | 
						|
    (void)bufferlen;
 | 
						|
 | 
						|
    iot_sg_cli_query_wl_state(add_addr_to_mapping_table(src_mac));
 | 
						|
}
 | 
						|
 | 
						|
void cli_get_white_list(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_query_wl_t *cmd = (iot_cli_sg_query_wl_t *)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_sg_cli_query_wl(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_add_white_list(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    uint16_t i;
 | 
						|
    uint32_t data_len = 0;
 | 
						|
 | 
						|
    iot_cli_sg_add_wl_t *cmd = (iot_cli_sg_add_wl_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    data_len = sizeof(*cmd) +
 | 
						|
        (sizeof(cmd->node_info[0]) * cmd->count);
 | 
						|
    if (data_len > bufferlen) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_printf("cli add white list, count: %d,", cmd->count);
 | 
						|
    for (i = 0; i < cmd->count; i++) {
 | 
						|
        iot_printf(" proto_type: %d, mac:%x:%x:%x:%x:%x:%x ",
 | 
						|
            cmd->node_info[i].proto_type, cmd->node_info[i].mac[0],
 | 
						|
            cmd->node_info[i].mac[1], cmd->node_info[i].mac[2],
 | 
						|
            cmd->node_info[i].mac[3], cmd->node_info[i].mac[4],
 | 
						|
            cmd->node_info[i].mac[5]);
 | 
						|
    }
 | 
						|
    iot_printf("\n");
 | 
						|
    iot_sg_cli_add_wl(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_rm_white_list(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)src_mac;
 | 
						|
    uint16_t i;
 | 
						|
    uint32_t data_len = 0;
 | 
						|
 | 
						|
    iot_cli_sg_rm_wl_t* cmd = (iot_cli_sg_rm_wl_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    data_len = sizeof(*cmd) +
 | 
						|
        (sizeof(cmd->mac_addr[0]) * cmd->count);
 | 
						|
    if (data_len > bufferlen) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_printf("cli rm white list, count: %d, mac:", cmd->count);
 | 
						|
    for (i = 0; i < cmd->count; i++) {
 | 
						|
        iot_printf(" %x:%x:%x:%x:%x:%x ", cmd->mac_addr[i][0],
 | 
						|
            cmd->mac_addr[i][1], cmd->mac_addr[i][2],
 | 
						|
            cmd->mac_addr[i][3], cmd->mac_addr[i][4],
 | 
						|
            cmd->mac_addr[i][5]);
 | 
						|
    }
 | 
						|
    iot_printf("\n");
 | 
						|
 | 
						|
    iot_sg_cli_rm_wl(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_set_white_list_state(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_set_wl_state_t* cmd = (iot_cli_sg_set_wl_state_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_printf("cli set white list state: %d\n", cmd->state);
 | 
						|
    iot_sg_cli_set_wl_state(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
#endif /* IOT_CLI_SUPPORT_WL_CMD */
 | 
						|
 | 
						|
#if IOT_CLI_CKB_ADDR_MAPPING
 | 
						|
 | 
						|
void cli_set_mac(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)src_mac;
 | 
						|
    iot_cli_sg_set_mac_dl_t *cmd = (iot_cli_sg_set_mac_dl_t *)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
    iot_cli_sg_set_mac(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
#endif /* IOT_CLI_CKB_ADDR_MAPPING */
 | 
						|
 | 
						|
#if PLC_SUPPORT_CCO_ROLE
 | 
						|
 | 
						|
void cli_get_meter_data(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_get_meter_data(
 | 
						|
        add_addr_to_mapping_table(src_mac), buffer, bufferlen);
 | 
						|
}
 | 
						|
 | 
						|
void cli_get_meter_rt_data(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_get_meter_rt_data(
 | 
						|
        add_addr_to_mapping_table(src_mac), buffer, bufferlen);
 | 
						|
}
 | 
						|
 | 
						|
void cli_get_report_ack(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_get_report_ack(
 | 
						|
        add_addr_to_mapping_table(src_mac), buffer, bufferlen);
 | 
						|
}
 | 
						|
 | 
						|
void cli_start_search_meter(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_start_sec_node_reg_dl_t *cmd =
 | 
						|
        (iot_cli_sg_start_sec_node_reg_dl_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_start_get_meter_list(
 | 
						|
        add_addr_to_mapping_table(src_mac), cmd->duration);
 | 
						|
}
 | 
						|
 | 
						|
void cli_handle_user_data(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_handle_user_data(CLI_HOST_USE_API_BY_PLCM,
 | 
						|
        src_mac, buffer, bufferlen);
 | 
						|
}
 | 
						|
 | 
						|
void cli_stop_search_meter(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)buffer;
 | 
						|
    (void)bufferlen;
 | 
						|
    iot_sg_cli_stop_get_meter_list(add_addr_to_mapping_table(src_mac));
 | 
						|
}
 | 
						|
 | 
						|
void cli_get_meter_list(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_get_sec_node_info_dl_t *cmd = NULL;
 | 
						|
    cmd = (iot_cli_sg_get_sec_node_info_dl_t *)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_sg_cli_get_meter_list(add_addr_to_mapping_table(src_mac),
 | 
						|
        cmd->sec_node_start_index, cmd->sec_node_count);
 | 
						|
}
 | 
						|
 | 
						|
void cli_set_tsfm_detect_state(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_set_tsfm_detect_state_t *cmd =
 | 
						|
        (iot_cli_sg_set_tsfm_detect_state_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_printf("cli set tsfm detect detect state: %d, sta lock: %d\n",
 | 
						|
        cmd->tsfm_detect_state, cmd->sta_lock);
 | 
						|
    iot_sg_cli_set_tsfm_detect_state(add_addr_to_mapping_table(src_mac),
 | 
						|
        cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_get_tsfm_detect_state(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)buffer;
 | 
						|
    (void)bufferlen;
 | 
						|
 | 
						|
    iot_sg_cli_query_tsfm_detect_state(add_addr_to_mapping_table(src_mac));
 | 
						|
}
 | 
						|
 | 
						|
void cli_set_con_mr_param(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_con_mr_param_t *cmd = (iot_cli_sg_con_mr_param_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_printf("cli set con mr param, sec_node_monitor_timeout: %d, "
 | 
						|
        "max_bcast_con_count: %d\n", cmd->sec_node_monitor_timeout,
 | 
						|
        cmd->max_bcast_con_count);
 | 
						|
    iot_sg_cli_set_con_mr_param(add_addr_to_mapping_table(src_mac),
 | 
						|
        cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_get_con_mr_param(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)buffer;
 | 
						|
    (void)bufferlen;
 | 
						|
 | 
						|
    iot_sg_cli_query_con_mr_param(add_addr_to_mapping_table(src_mac));
 | 
						|
}
 | 
						|
 | 
						|
void cli_set_event_rpt_enabled(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_set_event_enabled_t *cmd =
 | 
						|
        (iot_cli_sg_set_event_enabled_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_set_event_rpt_enabled(add_addr_to_mapping_table(src_mac),
 | 
						|
        cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_set_cctt_data_enabled(
 | 
						|
    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_set_cctt_data_enabled_t *cmd =
 | 
						|
        (iot_cli_sg_set_cctt_data_enabled_t*)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_set_cctt_data_enabled(add_addr_to_mapping_table(src_mac),
 | 
						|
        cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_bd_start(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_bd_start_t *cmd = (iot_cli_sg_bd_start_t *)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_sg_cli_bd_start(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_bd_query_state(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)buffer;
 | 
						|
    (void)bufferlen;
 | 
						|
 | 
						|
    iot_sg_cli_bd_query_state(add_addr_to_mapping_table(src_mac));
 | 
						|
}
 | 
						|
 | 
						|
void cli_bd_query_result(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_bd_query_ret_t *cmd = (iot_cli_sg_bd_query_ret_t *)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_sg_cli_bd_query_ret(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_set_esp(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_set_esp_t *cmd = (iot_cli_sg_set_esp_t *)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_set_esp(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_query_esp(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | 
						|
{
 | 
						|
    (void)buffer;
 | 
						|
    (void)bufferlen;
 | 
						|
 | 
						|
    iot_cli_sg_query_esp(add_addr_to_mapping_table(src_mac));
 | 
						|
}
 | 
						|
 | 
						|
void cli_query_node_info(uint8_t *buffer, uint32_t bufferlen,
 | 
						|
    uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_qr_node_info_dl_t *cmd = (iot_cli_sg_qr_node_info_dl_t *)buffer;
 | 
						|
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd))) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_query_node_info(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_cco_send_broadcast_data(uint8_t *buffer, uint32_t bufferlen,
 | 
						|
    uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_send_broadcast_data_dl *cmd =
 | 
						|
        (iot_cli_sg_send_broadcast_data_dl *)buffer;
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd)) || (!cmd->len)) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_send_broadcast_data(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
void cli_trans_local_proto_data(uint8_t *buffer, uint32_t bufferlen,
 | 
						|
    uint8_t *src_mac)
 | 
						|
{
 | 
						|
    iot_cli_sg_trans_local_proto_data_dl_t *cmd =
 | 
						|
        (iot_cli_sg_trans_local_proto_data_dl_t *)buffer;
 | 
						|
    if ((!cmd) || (bufferlen < sizeof(*cmd)) || (!cmd->data_len)) {
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_cli_sg_trans_local_proto_data(add_addr_to_mapping_table(src_mac), cmd);
 | 
						|
}
 | 
						|
 | 
						|
#endif /* PLC_SUPPORT_CCO_ROLE */
 |