1388 lines
		
	
	
		
			41 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			1388 lines
		
	
	
		
			41 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 <stdint.h>
 | 
						|
 | 
						|
#include "os_lock_api.h"
 | 
						|
#include "os_types_api.h"
 | 
						|
 | 
						|
#include "iot_io_api.h"
 | 
						|
#include "iot_rtc_api.h"
 | 
						|
#include "iot_crc_api.h"
 | 
						|
#include "iot_utils_api.h"
 | 
						|
#include "iot_errno_api.h"
 | 
						|
#include "iot_flash_api.h"
 | 
						|
#include "iot_cctt_comm_module.h"
 | 
						|
 | 
						|
#include "iot_cctt_config.h"
 | 
						|
 | 
						|
/* cctt config module manager data structure */
 | 
						|
typedef struct {
 | 
						|
    /* module inited or not */
 | 
						|
    bool_t                  inited;
 | 
						|
    /* factory test mode config enable */
 | 
						|
    bool_t                  ftm_en;
 | 
						|
    /* record current using config */
 | 
						|
    cctt_config_t           curr_cfg;
 | 
						|
    /*
 | 
						|
     * record non volatile config,when config changed or enter factory test mode
 | 
						|
     * curr_cfg is different with nv_cfg, otherwise both are all same
 | 
						|
     */
 | 
						|
    cctt_config_t           nv_cfg;
 | 
						|
} cctt_config_mgr_t;
 | 
						|
 | 
						|
/* custom partition for 2M flash is 376KB,
 | 
						|
 * cco maybe uses the start area of custom partition
 | 
						|
 * for example: AT cco uses the first 120KB of the custom partition
 | 
						|
 * so cctt allocates space from the end,and uses 16KB for both main and back cfg
 | 
						|
 */
 | 
						|
#define CCTT_CFG_LENGTH           (sizeof(cctt_config_t))
 | 
						|
#define CCTT_CFG_MAIN_OFFSET      (344 * 1024UL)       // 344KB
 | 
						|
#define CCTT_CFG_BACK_OFFSET      (360 * 1024UL)       // 360KB
 | 
						|
 | 
						|
 | 
						|
#define CCTT_CFG_PRINT(fmt, args...) \
 | 
						|
    iot_cus_printf("[cctt cfg]%s:" fmt "\n", __FUNCTION__, ##args)
 | 
						|
 | 
						|
 | 
						|
static cctt_config_mgr_t g_cctt_cfg_mgr = {0};
 | 
						|
 | 
						|
/* default config definition */
 | 
						|
static const cctt_config_t g_default_cfg = {
 | 
						|
    .cctt_cfg = {
 | 
						|
        .magic_number       = CONFIG_MAGIC_NUMBER,
 | 
						|
        .version            = IOT_CCTT_CFG_V0,
 | 
						|
        .sequence           = 0,
 | 
						|
        .v0_cfg = {
 | 
						|
            /* boot DL645 application default */
 | 
						|
            .appid = IOT_CCTT_APP_DL645,
 | 
						|
            /* default server config */
 | 
						|
            .server_ip          = {192, 168, 1, 1},
 | 
						|
            .server_port        = 5001,
 | 
						|
            /* default debug server config */
 | 
						|
            .cli_agent_svr_ip   = {183, 66, 219, 86},
 | 
						|
            .cli_agent_svr_port = 9005,
 | 
						|
            .at_mgr_svr_ip      = {183, 66, 219, 86},
 | 
						|
            .at_mgr_svr_port    = 9005,
 | 
						|
            .monitor_svr_ip     = {183, 66, 219, 86},
 | 
						|
            .monitor_svr_port   = 9005,
 | 
						|
            /* default local ethernet config */
 | 
						|
            .ethernet_ip        = {192, 168, 1, 2},
 | 
						|
            .ethernet_netmask   = {255, 255, 255, 0},
 | 
						|
            .ethernet_gateway   = {192, 168, 1, 1},
 | 
						|
            /* default wifi parameters */
 | 
						|
            .wifi_ssid          = "CCTT3.0_WIFI",
 | 
						|
            .wifi_password      = "12345678",
 | 
						|
            /* default 4G configuration */
 | 
						|
            .lte_apn            = "cmnet",
 | 
						|
            .lte_user           = "card",
 | 
						|
            .lte_password       = "card",
 | 
						|
            .cctt_mac           = {0x00, 0x00, 0x12, 0x34, 0x56, 0x78},
 | 
						|
        }
 | 
						|
    },
 | 
						|
    .reserved = {0},
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
/* factory test mode config */
 | 
						|
static const cctt_config_t g_factory_test_cfg = {
 | 
						|
    .cctt_cfg = {
 | 
						|
        .magic_number       = CONFIG_MAGIC_NUMBER,
 | 
						|
        .version            = IOT_CCTT_CFG_V0,
 | 
						|
        .sequence           = 0,
 | 
						|
        .v0_cfg = {
 | 
						|
            /* boot DL645 application default */
 | 
						|
            .appid = IOT_CCTT_APP_DL645,
 | 
						|
            /* default server config */
 | 
						|
            .server_ip          = {192, 168, 1, 1},
 | 
						|
            .server_port        = 5001,
 | 
						|
            /* default debug server config */
 | 
						|
            .at_mgr_svr_ip      = {192, 168, 1, 1},
 | 
						|
            .at_mgr_svr_port    = 5002,
 | 
						|
            .cli_agent_svr_ip   = {192, 168, 1, 1},
 | 
						|
            .cli_agent_svr_port = 5003,
 | 
						|
            .monitor_svr_ip     = {192, 168, 1, 1},
 | 
						|
            .monitor_svr_port   = 5004,
 | 
						|
            /* default local ethernet config */
 | 
						|
            .ethernet_ip        = {192, 168, 1, 2},
 | 
						|
            .ethernet_netmask   = {255, 255, 255, 0},
 | 
						|
            .ethernet_gateway   = {192, 168, 1, 1},
 | 
						|
            /* default wifi parameters */
 | 
						|
            .wifi_ssid          = "CCTT3.0_WIFI",
 | 
						|
            .wifi_password      = "12345678",
 | 
						|
            /* default 4G configuration */
 | 
						|
            .lte_apn            = "cmnet",
 | 
						|
            .lte_user           = "card",
 | 
						|
            .lte_password       = "card",
 | 
						|
            .cctt_mac           = {0x00, 0x00, 0x12, 0x34, 0x56, 0x78},
 | 
						|
        }
 | 
						|
    },
 | 
						|
    .reserved = {0},
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
/***************************************************************************
 | 
						|
 *
 | 
						|
 * ---------------------------------  <- custom parition offset 344KB
 | 
						|
 * |  cctt_config_t config_main    |
 | 
						|
 * |-------------------------------|
 | 
						|
 * |        reserved               |
 | 
						|
 * |-------------------------------|  <- custom parition offset 360KB
 | 
						|
 * |  cctt_config_t config_backup  |
 | 
						|
 * |-------------------------------|
 | 
						|
 * |        reserved               |
 | 
						|
 * |-------------------------------|  <- custom parition offset 376KB
 | 
						|
 *
 | 
						|
 ****************************************************************************/
 | 
						|
 | 
						|
/**
 | 
						|
 * read cctt configuration from flash
 | 
						|
 *
 | 
						|
 * @param offset: flash offset in custom partition
 | 
						|
 * @param p_cfg : pointer to save cctt config
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
static uint8_t iot_cctt_cfg_readflash(uint32_t offset, cctt_config_t *p_cfg)
 | 
						|
{
 | 
						|
    int fd = -1;
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
 | 
						|
    if ((NULL == p_cfg)
 | 
						|
    || ((offset + CCTT_CFG_LENGTH) > custom_dev_query_rw_size()))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("invaid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == (fd = custom_dev_open()))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("cannot open custom partition");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_seek(fd, offset, DEV_SEEK_SET))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("cannot seek custom partition");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_read(fd, (void*)p_cfg, CCTT_CFG_LENGTH))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("cannot read custom partition");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
out:
 | 
						|
    if (-1 != fd) {
 | 
						|
        custom_dev_close(fd);
 | 
						|
    }
 | 
						|
    if (ERR_OK != ret) {
 | 
						|
        CCTT_CFG_PRINT("read fail.offset=%u, p_cfg=%p", offset, p_cfg);
 | 
						|
    }
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * write cctt configuration to flash
 | 
						|
 *
 | 
						|
 * @param offset: flash offset in custom partition
 | 
						|
 * @param p_cfg : pointer to cctt config to write
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
static uint8_t iot_cctt_cfg_writeflash(uint32_t offset, cctt_config_t *p_cfg)
 | 
						|
{
 | 
						|
    int fd = -1;
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
 | 
						|
    if ((NULL == p_cfg)
 | 
						|
    || ((offset + CCTT_CFG_LENGTH) > custom_dev_query_rw_size()))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("invaid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == (fd = custom_dev_open()))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("cannot open custom partition");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_seek(fd, offset, DEV_SEEK_SET))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("cannot seek custom partition");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (-1 == custom_dev_write(fd, (void*)p_cfg, CCTT_CFG_LENGTH))
 | 
						|
    {
 | 
						|
        CCTT_CFG_PRINT("cannot write custom partition");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
out:
 | 
						|
    if (-1 != fd) {
 | 
						|
        custom_dev_close(fd);
 | 
						|
    }
 | 
						|
    if (ERR_OK != ret) {
 | 
						|
        CCTT_CFG_PRINT("write fail.offset=%u, p_cfg=%p", offset, p_cfg);
 | 
						|
    }
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * check validation of cctt configuration
 | 
						|
 *
 | 
						|
 * @param p_cfg : pointer to cctt config to check
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
static uint8_t iot_cctt_cfg_check(cctt_config_t *p_cfg)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    uint32_t calc_crc32;
 | 
						|
 | 
						|
    if (NULL == p_cfg) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (CONFIG_MAGIC_NUMBER != p_cfg->cctt_cfg.magic_number) {
 | 
						|
        CCTT_CFG_PRINT("config magic number error!");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    calc_crc32 = iot_getcrc32((uint8_t *)p_cfg,
 | 
						|
        CCTT_CFG_LENGTH - sizeof(uint32_t));
 | 
						|
    if (calc_crc32 != p_cfg->checksum) {
 | 
						|
        CCTT_CFG_PRINT("config crc32 check failed!");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (IOT_CCTT_CFG_V0 != p_cfg->cctt_cfg.version) {
 | 
						|
        CCTT_CFG_PRINT("config version error!");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * read cctt configuration from flash, and check it
 | 
						|
 *
 | 
						|
 * @param offset : config offset in custom partition
 | 
						|
 * @param p_cfg  : pointer to store read config
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
static uint8_t iot_cctt_cfg_read(uint32_t offset, cctt_config_t *p_cfg)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
 | 
						|
    if (ERR_OK != iot_cctt_cfg_readflash(offset, p_cfg)) {
 | 
						|
        CCTT_CFG_PRINT("read cfg fail,offset %u", offset);
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (ERR_OK != iot_cctt_cfg_check(p_cfg)) {
 | 
						|
        CCTT_CFG_PRINT("check cfg fail,offset %u", offset);
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * refresh config sequence number, and re-calculate crc code of config
 | 
						|
 *
 | 
						|
 * @param p_cfg  : pointer to config to refresh
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
static uint8_t iot_cctt_cfg_refresh(cctt_config_t *p_cfg)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
 | 
						|
    if (NULL == p_cfg) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    p_cfg->cctt_cfg.sequence++;
 | 
						|
    p_cfg->checksum = iot_getcrc32((uint8_t *)p_cfg,
 | 
						|
        CCTT_CFG_LENGTH - sizeof(uint32_t));
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * save specified configuration to flash
 | 
						|
 *
 | 
						|
 * @param p_cfg  : pointer to config to save
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
static uint8_t iot_cctt_cfg_save(cctt_config_t *p_cfg)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
 | 
						|
    if (NULL == p_cfg) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (ERR_OK != iot_cctt_cfg_refresh(p_cfg)) {
 | 
						|
        CCTT_CFG_PRINT("refresh config failed");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (ERR_OK != iot_cctt_cfg_writeflash(CCTT_CFG_MAIN_OFFSET, p_cfg)) {
 | 
						|
        CCTT_CFG_PRINT("write main config failed!");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (ERR_OK != iot_cctt_cfg_writeflash(CCTT_CFG_BACK_OFFSET, p_cfg)) {
 | 
						|
        CCTT_CFG_PRINT("write back config failed!");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * dump configuration of specified configuration
 | 
						|
 *
 | 
						|
 * @param p_cfg  : pointer to config to dump
 | 
						|
 * @return none
 | 
						|
 */
 | 
						|
static void iot_cctt_cfg_dump(cctt_config_t *p_cfg)
 | 
						|
{
 | 
						|
    cctt_config_content_t *p_cctt_cfg;
 | 
						|
    cctt_config_v0_t *p_v0_cfg;
 | 
						|
 | 
						|
    if (NULL == p_cfg) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    p_cctt_cfg = &p_cfg->cctt_cfg;
 | 
						|
    p_v0_cfg   = &p_cctt_cfg->v0_cfg;
 | 
						|
 | 
						|
    CCTT_CFG_PRINT("cctt config dump start=================================");
 | 
						|
    CCTT_CFG_PRINT("cctt config magic        : 0x%08X", p_cctt_cfg->magic_number);
 | 
						|
    CCTT_CFG_PRINT("cctt config version      : %u", p_cctt_cfg->version);
 | 
						|
    CCTT_CFG_PRINT("cctt config sequence     : %u", p_cctt_cfg->sequence);
 | 
						|
    CCTT_CFG_PRINT("cctt config app id       : %u", p_v0_cfg->appid);
 | 
						|
    CCTT_CFG_PRINT("cctt config server       : %u.%u.%u.%u:%u",
 | 
						|
        p_v0_cfg->server_ip[0], p_v0_cfg->server_ip[1], p_v0_cfg->server_ip[2],
 | 
						|
        p_v0_cfg->server_ip[3], p_v0_cfg->server_port);
 | 
						|
    CCTT_CFG_PRINT("cctt config cli agent svr: %u.%u.%u.%u:%u",
 | 
						|
        p_v0_cfg->cli_agent_svr_ip[0], p_v0_cfg->cli_agent_svr_ip[1],
 | 
						|
        p_v0_cfg->cli_agent_svr_ip[2], p_v0_cfg->cli_agent_svr_ip[3],
 | 
						|
        p_v0_cfg->cli_agent_svr_port);
 | 
						|
    CCTT_CFG_PRINT("cctt config at mgr svr   : %u.%u.%u.%u:%u",
 | 
						|
        p_v0_cfg->at_mgr_svr_ip[0], p_v0_cfg->at_mgr_svr_ip[1],
 | 
						|
        p_v0_cfg->at_mgr_svr_ip[2], p_v0_cfg->at_mgr_svr_ip[3],
 | 
						|
        p_v0_cfg->at_mgr_svr_port);
 | 
						|
    CCTT_CFG_PRINT("cctt config monitor svr  : %u.%u.%u.%u:%u",
 | 
						|
        p_v0_cfg->monitor_svr_ip[0], p_v0_cfg->monitor_svr_ip[1],
 | 
						|
        p_v0_cfg->monitor_svr_ip[2], p_v0_cfg->monitor_svr_ip[3],
 | 
						|
        p_v0_cfg->monitor_svr_port);
 | 
						|
    CCTT_CFG_PRINT("cctt config eth ip       : %u.%u.%u.%u",
 | 
						|
        p_v0_cfg->ethernet_ip[0], p_v0_cfg->ethernet_ip[1],
 | 
						|
        p_v0_cfg->ethernet_ip[2], p_v0_cfg->ethernet_ip[3]);
 | 
						|
    CCTT_CFG_PRINT("cctt config eth netmask  : %u.%u.%u.%u",
 | 
						|
        p_v0_cfg->ethernet_netmask[0], p_v0_cfg->ethernet_netmask[1],
 | 
						|
        p_v0_cfg->ethernet_netmask[2], p_v0_cfg->ethernet_netmask[3]);
 | 
						|
    CCTT_CFG_PRINT("cctt config eth gateway  : %u.%u.%u.%u",
 | 
						|
        p_v0_cfg->ethernet_gateway[0], p_v0_cfg->ethernet_gateway[1],
 | 
						|
        p_v0_cfg->ethernet_gateway[2], p_v0_cfg->ethernet_gateway[3]);
 | 
						|
    CCTT_CFG_PRINT("cctt config wifi ssid    : %s", p_v0_cfg->wifi_ssid);
 | 
						|
    CCTT_CFG_PRINT("cctt config wifi pass    : %s", p_v0_cfg->wifi_password);
 | 
						|
    CCTT_CFG_PRINT("cctt config 4g apn       : %s", p_v0_cfg->lte_apn);
 | 
						|
    CCTT_CFG_PRINT("cctt config 4g user      : %s", p_v0_cfg->lte_user);
 | 
						|
    CCTT_CFG_PRINT("cctt config 4g password  : %s", p_v0_cfg->lte_password);
 | 
						|
    CCTT_CFG_PRINT("cctt config cco mac      : %02X:%02X:%02X:%02X:%02X:%02X",
 | 
						|
        p_v0_cfg->cctt_mac[0], p_v0_cfg->cctt_mac[1], p_v0_cfg->cctt_mac[2],
 | 
						|
        p_v0_cfg->cctt_mac[3], p_v0_cfg->cctt_mac[4], p_v0_cfg->cctt_mac[5]);
 | 
						|
    CCTT_CFG_PRINT("cctt config dump end===================================");
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * cctt config module initialize, read config from flash.
 | 
						|
 *
 | 
						|
 * @param none
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_config_init(void)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_t *p_main_cfg = &g_cctt_cfg_mgr.nv_cfg;
 | 
						|
    cctt_config_t *p_back_cfg = &g_cctt_cfg_mgr.curr_cfg;
 | 
						|
 | 
						|
    bool_t  main_cfg_valid = true;
 | 
						|
    bool_t  back_cfg_valid = true;
 | 
						|
 | 
						|
    if (true == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("cctt config module initialised!");
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (ERR_OK != iot_cctt_cfg_read(CCTT_CFG_MAIN_OFFSET, p_main_cfg)) {
 | 
						|
        main_cfg_valid = false;
 | 
						|
        CCTT_CFG_PRINT("main config is invalid!");
 | 
						|
    } else {
 | 
						|
        CCTT_CFG_PRINT("main config content:");
 | 
						|
        iot_cctt_cfg_dump(p_main_cfg);
 | 
						|
    }
 | 
						|
 | 
						|
    if (ERR_OK != iot_cctt_cfg_read(CCTT_CFG_BACK_OFFSET, p_back_cfg)) {
 | 
						|
        back_cfg_valid = false;
 | 
						|
        CCTT_CFG_PRINT("backup config is invalid!");
 | 
						|
    } else {
 | 
						|
        CCTT_CFG_PRINT("backup config content:");
 | 
						|
        iot_cctt_cfg_dump(p_back_cfg);
 | 
						|
    }
 | 
						|
 | 
						|
    if ((false == main_cfg_valid) && (false == back_cfg_valid)) {
 | 
						|
        os_mem_cpy(p_main_cfg, &g_default_cfg, CCTT_CFG_LENGTH);
 | 
						|
        os_mem_cpy(p_back_cfg,  &g_default_cfg, CCTT_CFG_LENGTH);
 | 
						|
        CCTT_CFG_PRINT("main and back config invalid, use default");
 | 
						|
    } else if ((false == main_cfg_valid) && (true == back_cfg_valid)) {
 | 
						|
        os_mem_cpy(p_main_cfg, p_back_cfg, CCTT_CFG_LENGTH);
 | 
						|
        CCTT_CFG_PRINT("only main config valid, use main config");
 | 
						|
    } else if ((true == main_cfg_valid) && (false == back_cfg_valid)) {
 | 
						|
        os_mem_cpy(p_back_cfg, p_main_cfg, CCTT_CFG_LENGTH);
 | 
						|
        CCTT_CFG_PRINT("only backup config valid, use backup config");
 | 
						|
    } else {
 | 
						|
        /* both main and backup config are valid */
 | 
						|
        if (0 == os_mem_cmp(p_main_cfg, p_back_cfg, CCTT_CFG_LENGTH)) {
 | 
						|
            /* main and backup is same, do nothing */
 | 
						|
            CCTT_CFG_PRINT("main and backup config are all same");
 | 
						|
        } else if (p_main_cfg->cctt_cfg.sequence >
 | 
						|
                   p_back_cfg->cctt_cfg.sequence){
 | 
						|
            /* sequence of main config >= sequence of backup config, use main */
 | 
						|
            os_mem_cpy(p_back_cfg, p_main_cfg, CCTT_CFG_LENGTH);
 | 
						|
            back_cfg_valid = false;
 | 
						|
            CCTT_CFG_PRINT("sequence of main config is bigger, use main");
 | 
						|
        } else {
 | 
						|
            os_mem_cpy(p_main_cfg, p_back_cfg, CCTT_CFG_LENGTH);
 | 
						|
            main_cfg_valid = false;
 | 
						|
            CCTT_CFG_PRINT("sequence of backup config is bigger, use backup");
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    if ((false == main_cfg_valid) || (false == back_cfg_valid)) {
 | 
						|
        CCTT_CFG_PRINT("need to save main config to flash");
 | 
						|
        if (ERR_OK == iot_cctt_cfg_save(p_main_cfg)) {
 | 
						|
            CCTT_CFG_PRINT("success to save main config to flash");
 | 
						|
        } else {
 | 
						|
            CCTT_CFG_PRINT("failed to save main config to flash");
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    g_cctt_cfg_mgr.inited = true;
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set cctt config mode: normal boot / factory test mode
 | 
						|
 *
 | 
						|
 * @param none
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_to_ftm_cfg(void)
 | 
						|
{
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    g_cctt_cfg_mgr.ftm_en = true;
 | 
						|
    os_mem_cpy(&g_cctt_cfg_mgr.curr_cfg, &g_factory_test_cfg, CCTT_CFG_LENGTH);
 | 
						|
    CCTT_CFG_PRINT("enter factory test mode, use default config");
 | 
						|
    iot_cctt_cfg_dump(&g_cctt_cfg_mgr.curr_cfg);
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * get cctt config mode: normal boot / factory test mode
 | 
						|
 *
 | 
						|
 * @param none
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
bool_t iot_cctt_cfg_is_ftm_cfg(void)
 | 
						|
{
 | 
						|
    return g_cctt_cfg_mgr.ftm_en;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * restore config to factory setting
 | 
						|
 *
 | 
						|
 * @param none
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_restore_factory_setting(void)
 | 
						|
{
 | 
						|
    os_mem_cpy(&g_cctt_cfg_mgr.nv_cfg, &g_default_cfg, sizeof(g_default_cfg));
 | 
						|
    return iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query boot application id from current used configuration
 | 
						|
 *
 | 
						|
 * @param none
 | 
						|
 * @return boot application id, @IOT_CCTT_APP_ID_e
 | 
						|
 */
 | 
						|
IOT_CCTT_APP_ID_e iot_cctt_cfg_get_app_id(void)
 | 
						|
{
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    return g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg.appid;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/*
 | 
						|
 * query server ip and port config from current used configuration
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_server_info(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                     uint16_t *p_port)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->server_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->server_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query local ethernet parameters from current used configuration
 | 
						|
 *
 | 
						|
 * @param p_local_ip : pointer to store local ip
 | 
						|
 * @param p_netmask  : pointer to store netmask
 | 
						|
 * @param p_gateway  : pointer to store gateway
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_eth_ip_config(uint8_t p_local_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                       uint8_t p_netmask[IOT_IP4_ADDR_LEN],
 | 
						|
                                       uint8_t p_gateway[IOT_IP4_ADDR_LEN])
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_local_ip) || (NULL == p_netmask) || (NULL == p_gateway)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_local_ip, p_v0_cfg->ethernet_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    os_mem_cpy(p_netmask,  p_v0_cfg->ethernet_netmask, IOT_IP4_ADDR_LEN);
 | 
						|
    os_mem_cpy(p_gateway,  p_v0_cfg->ethernet_gateway, IOT_IP4_ADDR_LEN);
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query wifi configuraion from current used configuration
 | 
						|
 *
 | 
						|
 * @param p_ssid : pointer to store wifi ssid
 | 
						|
 * @param p_pass : pointer to store wifi password
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_wifi_config(uint8_t p_ssid[WIFI_SSID_LEN],
 | 
						|
                                     uint8_t p_pass[WIFI_PASS_LEN])
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ssid) || (NULL == p_pass)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ssid, p_v0_cfg->wifi_ssid, WIFI_SSID_LEN);
 | 
						|
    os_mem_cpy(p_pass, p_v0_cfg->wifi_password, WIFI_PASS_LEN);
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query 4g configuraion from current used configuration
 | 
						|
 *
 | 
						|
 * @param p_apn : pointer to store 4g ssid
 | 
						|
 * @param p_user: pointer to store 4g password
 | 
						|
 * @param p_pass: pointer to store 4g password
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_4g_config(uint8_t p_apn[LTE_APN_LEN],
 | 
						|
                                   uint8_t p_user[LTE_USER_LEN],
 | 
						|
                                   uint8_t p_pass[LTE_PASS_LEN])
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_apn) || (NULL == p_user) || (NULL == p_pass)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_apn, p_v0_cfg->lte_apn, LTE_APN_LEN);
 | 
						|
    os_mem_cpy(p_user, p_v0_cfg->lte_user, LTE_USER_LEN);
 | 
						|
    os_mem_cpy(p_pass, p_v0_cfg->lte_password, LTE_PASS_LEN);
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query server ip and port config of cli agent from current used configuration
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_cli_agent_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                       uint16_t *p_port)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->cli_agent_svr_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->cli_agent_svr_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query server ip and port config of at manager from current used configuration
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_at_mgr_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                    uint16_t *p_port)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->at_mgr_svr_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->at_mgr_svr_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query server ip and port config of monitor from current used configuration
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_monitor_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                    uint16_t *p_port)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->monitor_svr_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->monitor_svr_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query cco mac address from non volatile configuration
 | 
						|
 *
 | 
						|
 * @param p_mac : pointer to store cco mac
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_cctt_mac(uint8_t *p_mac)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if (NULL == p_mac) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_mac_addr_cpy(p_mac, p_v0_cfg->cctt_mac);
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query boot application id from non volatile configuration
 | 
						|
 * used in factory test mode, current used config is different with flash cfg.
 | 
						|
 *
 | 
						|
 * @param none
 | 
						|
 * @return boot application id, @IOT_CCTT_APP_ID_e
 | 
						|
 */
 | 
						|
IOT_CCTT_APP_ID_e iot_cctt_cfg_get_nv_app_id(void)
 | 
						|
{
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    return g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg.appid;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query server ip and port config from non volatile configuration
 | 
						|
 * used in factory test mode, current used config is different with flash cfg.
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_server_info(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                        uint16_t *p_port)
 | 
						|
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->server_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->server_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query local ethernet parameters from non volatile configuration
 | 
						|
 * used in factory test mode, current used config is different with flash cfg.
 | 
						|
 *
 | 
						|
 * @param p_local_ip : pointer to store local ip
 | 
						|
 * @param p_netmask  : pointer to store netmask
 | 
						|
 * @param p_gateway  : pointer to store gateway
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_eth_ip_config(uint8_t p_local_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                          uint8_t p_netmask[IOT_IP4_ADDR_LEN],
 | 
						|
                                          uint8_t p_gateway[IOT_IP4_ADDR_LEN])
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_local_ip) || (NULL == p_netmask) || (NULL == p_gateway)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_local_ip, p_v0_cfg->ethernet_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    os_mem_cpy(p_netmask,  p_v0_cfg->ethernet_netmask, IOT_IP4_ADDR_LEN);
 | 
						|
    os_mem_cpy(p_gateway,  p_v0_cfg->ethernet_gateway, IOT_IP4_ADDR_LEN);
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query wifi configuraion from non volatile configuration
 | 
						|
 * used in factory test mode, current used config is different with flash cfg.
 | 
						|
 *
 | 
						|
 * @param p_ssid : pointer to store wifi ssid
 | 
						|
 * @param p_pass : pointer to store wifi password
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_wifi_config(uint8_t p_ssid[WIFI_SSID_LEN],
 | 
						|
                                        uint8_t p_pass[WIFI_PASS_LEN])
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ssid) || (NULL == p_pass)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ssid, p_v0_cfg->wifi_ssid, WIFI_SSID_LEN);
 | 
						|
    os_mem_cpy(p_pass, p_v0_cfg->wifi_password, WIFI_PASS_LEN);
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query 4g configuraion from non volatile configuration
 | 
						|
 *
 | 
						|
 * @param p_apn : pointer to store 4g ssid
 | 
						|
 * @param p_user: pointer to store 4g password
 | 
						|
 * @param p_pass: pointer to store 4g password
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_4g_config(uint8_t p_apn[LTE_APN_LEN],
 | 
						|
                                      uint8_t p_user[LTE_USER_LEN],
 | 
						|
                                      uint8_t p_pass[LTE_PASS_LEN])
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_apn) || (NULL == p_user) || (NULL == p_pass)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_apn, p_v0_cfg->lte_apn, LTE_APN_LEN);
 | 
						|
    os_mem_cpy(p_user, p_v0_cfg->lte_user, LTE_USER_LEN);
 | 
						|
    os_mem_cpy(p_pass, p_v0_cfg->lte_password, LTE_PASS_LEN);
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query server ip and port config of cli agent from non volatile configuration
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_cli_agent_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                          uint16_t *p_port)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->cli_agent_svr_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->cli_agent_svr_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query server ip and port config of at mgr from non volatile configuration
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_at_mgr_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                       uint16_t *p_port)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->at_mgr_svr_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->at_mgr_svr_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * query server ip and port config of monitor from non volatile configuration
 | 
						|
 *
 | 
						|
 * @param p_ip  : pointer to store ip
 | 
						|
 * @param p_port: pointer to store port
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_get_nv_monitor_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                        uint16_t *p_port)
 | 
						|
{
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        return ERR_FAIL;
 | 
						|
    }
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (NULL == p_port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_ip, p_v0_cfg->monitor_svr_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    *p_port = p_v0_cfg->monitor_svr_port;
 | 
						|
 | 
						|
    return ERR_OK;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set boot application id
 | 
						|
 *
 | 
						|
 * @param app_id: boot application id to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_boot_app_id(IOT_CCTT_APP_ID_e app_id)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
 | 
						|
    if ((IOT_CCTT_APP_INVALID == app_id) || (IOT_CCTT_APP_MAX < app_id)) {
 | 
						|
        CCTT_CFG_PRINT("invalid app_id[%u] to set", app_id);
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    CCTT_CFG_PRINT("set app id to %u", app_id);
 | 
						|
    g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg.appid = app_id;
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set ip and port of server
 | 
						|
 *
 | 
						|
 * @param p_ip: ip address to set
 | 
						|
 * @param port: port to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_server_info(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                     uint16_t port)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (0 == port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_v0_cfg->server_ip, p_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    p_v0_cfg->server_port = port;
 | 
						|
    CCTT_CFG_PRINT("set server ip:port to %u.%u.%u.%u:%u",
 | 
						|
        p_ip[0], p_ip[1], p_ip[2], p_ip[3], port);
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set local ip, netmask, gateway of ethernet.
 | 
						|
 *
 | 
						|
 * @param p_local_ip: ip address to set
 | 
						|
 * @param p_netmask : netmask to set
 | 
						|
 * @param p_gateway : gateway to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_eth_config(uint8_t p_local_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                    uint8_t p_netmask[IOT_IP4_ADDR_LEN],
 | 
						|
                                    uint8_t p_gateway[IOT_IP4_ADDR_LEN])
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if ((NULL == p_local_ip) || (NULL == p_netmask) || (NULL == p_gateway)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_v0_cfg->ethernet_ip, p_local_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    os_mem_cpy(p_v0_cfg->ethernet_netmask, p_netmask, IOT_IP4_ADDR_LEN);
 | 
						|
    os_mem_cpy(p_v0_cfg->ethernet_gateway, p_gateway, IOT_IP4_ADDR_LEN);
 | 
						|
    CCTT_CFG_PRINT("set ethernet ip      = %u.%u.%u.%u",
 | 
						|
        p_local_ip[0], p_local_ip[1], p_local_ip[2], p_local_ip[3]);
 | 
						|
    CCTT_CFG_PRINT("set ethernet netmask = %u.%u.%u.%u",
 | 
						|
        p_netmask[0], p_netmask[1], p_netmask[2], p_netmask[3]);
 | 
						|
    CCTT_CFG_PRINT("set ethernet gatewat = %u.%u.%u.%u",
 | 
						|
        p_gateway[0], p_gateway[1], p_gateway[2], p_gateway[3]);
 | 
						|
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set wifi ssid and password.
 | 
						|
 *
 | 
						|
 * @param p_ssid: wifi ssid to set
 | 
						|
 * @param p_pass: wifi password to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_wifi_config(uint8_t p_ssid[WIFI_SSID_LEN],
 | 
						|
                                     uint8_t p_pass[WIFI_PASS_LEN])
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if ((NULL == p_ssid) || (NULL == p_pass)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_v0_cfg->wifi_ssid, p_ssid, WIFI_SSID_LEN);
 | 
						|
    os_mem_cpy(p_v0_cfg->wifi_password, p_pass, WIFI_PASS_LEN);
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
    CCTT_CFG_PRINT("set wifi ssid = %s, pass = %s", p_ssid, p_pass);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set apn, user, password of 4G
 | 
						|
 *
 | 
						|
 * @param p_apn : apn to set
 | 
						|
 * @param p_user: user to set
 | 
						|
 * @param p_pass: password to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_4g_config(uint8_t p_apn[LTE_APN_LEN],
 | 
						|
                                   uint8_t p_user[LTE_USER_LEN],
 | 
						|
                                   uint8_t p_pass[LTE_PASS_LEN])
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if ((NULL == p_apn) || (NULL == p_user) || (NULL == p_pass)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_v0_cfg->lte_apn, p_apn, LTE_APN_LEN);
 | 
						|
    os_mem_cpy(p_v0_cfg->lte_user, p_user, LTE_USER_LEN);
 | 
						|
    os_mem_cpy(p_v0_cfg->lte_password, p_pass, LTE_PASS_LEN);
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
    CCTT_CFG_PRINT("set 4G apn = %s", p_apn);
 | 
						|
    CCTT_CFG_PRINT("set 4G user = %s", p_user);
 | 
						|
    CCTT_CFG_PRINT("set 4G pass = %s", p_pass);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set cctt mac address
 | 
						|
 *
 | 
						|
 * @param mac : new cctt mac to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_cctt_mac(uint8_t *p_mac)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if (NULL == p_mac) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    iot_mac_addr_cpy(p_v0_cfg->cctt_mac, p_mac);
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
    p_v0_cfg = &g_cctt_cfg_mgr.curr_cfg.cctt_cfg.v0_cfg;
 | 
						|
    iot_mac_addr_cpy(p_v0_cfg->cctt_mac, p_mac);
 | 
						|
 | 
						|
    CCTT_CFG_PRINT("set cco mac = %02X:%02X:%02X:%02X:%02X:%02X",
 | 
						|
        p_mac[0], p_mac[1], p_mac[2], p_mac[3], p_mac[4], p_mac[5]);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set ip and port of cli agent server
 | 
						|
 *
 | 
						|
 * @param p_ip: ip address to set
 | 
						|
 * @param port: port to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_cli_agent_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                       uint16_t port)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (0 == port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_v0_cfg->cli_agent_svr_ip, p_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    p_v0_cfg->cli_agent_svr_port = port;
 | 
						|
    CCTT_CFG_PRINT("set cli agent svr ip:port to %u.%u.%u.%u:%u",
 | 
						|
        p_ip[0], p_ip[1], p_ip[2], p_ip[3], port);
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set ip and port of at manager server
 | 
						|
 *
 | 
						|
 * @param p_ip: ip address to set
 | 
						|
 * @param port: port to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_at_mgr_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                    uint16_t port)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (0 == port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_v0_cfg->at_mgr_svr_ip, p_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    p_v0_cfg->at_mgr_svr_port = port;
 | 
						|
    CCTT_CFG_PRINT("set at mgr svr ip:port to %u.%u.%u.%u:%u",
 | 
						|
        p_ip[0], p_ip[1], p_ip[2], p_ip[3], port);
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * set ip and port of monitor server
 | 
						|
 *
 | 
						|
 * @param p_ip: ip address to set
 | 
						|
 * @param port: port to set
 | 
						|
 * @return ERR_OK if success, error code otherwise
 | 
						|
 */
 | 
						|
uint8_t iot_cctt_cfg_set_monitor_svr(uint8_t p_ip[IOT_IP4_ADDR_LEN],
 | 
						|
                                     uint16_t port)
 | 
						|
{
 | 
						|
    uint8_t ret = ERR_OK;
 | 
						|
    cctt_config_v0_t *p_v0_cfg = &g_cctt_cfg_mgr.nv_cfg.cctt_cfg.v0_cfg;
 | 
						|
 | 
						|
    if ((NULL == p_ip) || (0 == port)) {
 | 
						|
        CCTT_CFG_PRINT("invalid parameters");
 | 
						|
        ret = ERR_INVAL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    if (false == g_cctt_cfg_mgr.inited) {
 | 
						|
        CCTT_CFG_PRINT("please init iot cctt config module first");
 | 
						|
        ret = ERR_FAIL;
 | 
						|
        goto out;
 | 
						|
    }
 | 
						|
 | 
						|
    os_mem_cpy(p_v0_cfg->monitor_svr_ip, p_ip, IOT_IP4_ADDR_LEN);
 | 
						|
    p_v0_cfg->monitor_svr_port = port;
 | 
						|
    CCTT_CFG_PRINT("set monitor svr ip:port to %u.%u.%u.%u:%u",
 | 
						|
        p_ip[0], p_ip[1], p_ip[2], p_ip[3], port);
 | 
						|
    iot_cctt_cfg_save(&g_cctt_cfg_mgr.nv_cfg);
 | 
						|
 | 
						|
out:
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
 |