Files
kunlun/app/iot_micro_cctt_app/cctt/iot_cctt_config.h

420 lines
12 KiB
C
Raw Normal View History

2024-09-28 14:24:04 +08:00
/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef IOT_CCTT_CONFIG_H
#define IOT_CCTT_CONFIG_H
#define CONFIG_MAGIC_NUMBER (0xAA55AA55)
#define CONFIG_INFO_LENGTH (4 * 1024)
#define CONFIG_RESERVE_LEN (CONFIG_INFO_LENGTH -\
sizeof(cctt_config_content_t) -\
sizeof(uint32_t))
/* application id definition */
typedef enum {
IOT_CCTT_APP_INVALID = 0,
IOT_CCTT_APP_DL645,
IOT_CCTT_APP_MAX = IOT_CCTT_APP_DL645,
} IOT_CCTT_APP_ID_e;
/* config version definition */
typedef enum {
IOT_CCTT_CFG_V0 = 0,
} IOT_CCTT_CFG_VERSION_e;
typedef struct {
/* application id to boot */
IOT_CCTT_APP_ID_e appid;
/* server ip port information */
uint8_t server_ip[IOT_IP4_ADDR_LEN];
uint16_t server_port;
/* debug server ip port information */
uint8_t cli_agent_svr_ip[IOT_IP4_ADDR_LEN];
uint16_t cli_agent_svr_port;
uint8_t at_mgr_svr_ip[IOT_IP4_ADDR_LEN];
uint16_t at_mgr_svr_port;
uint8_t monitor_svr_ip[IOT_IP4_ADDR_LEN];
uint16_t monitor_svr_port;
/* ethernet configuration */
uint8_t ethernet_ip[IOT_IP4_ADDR_LEN];
uint8_t ethernet_netmask[IOT_IP4_ADDR_LEN];
uint8_t ethernet_gateway[IOT_IP4_ADDR_LEN];
/* wifi configuration */
uint8_t wifi_ssid[WIFI_SSID_LEN];
uint8_t wifi_password[WIFI_PASS_LEN];
/* 4G module configuration */
uint8_t lte_apn[LTE_APN_LEN];
uint8_t lte_user[LTE_USER_LEN];
uint8_t lte_password[LTE_PASS_LEN];
/* cco mac address */
uint8_t cctt_mac[IOT_MAC_ADDR_LEN];
} cctt_config_v0_t;
typedef struct {
/* magic number, must be CONFIG_MAGIC_NUMBER */
uint32_t magic_number;
/* config version */
IOT_CCTT_CFG_VERSION_e version;
/* config sequence number, increment when updated */
uint32_t sequence;
/* version 0 configuration */
cctt_config_v0_t v0_cfg;
/* more configuration of newer version */
} cctt_config_content_t;
typedef struct {
cctt_config_content_t cctt_cfg;
uint8_t reserved[CONFIG_RESERVE_LEN]; // must be zero
/* crc-32 checksum for content and reserved */
uint32_t checksum;
} cctt_config_t;
/**
* cctt config module initialize
*
* @param none
* @return ERR_OK if success, error code otherwise
*/
uint8_t iot_cctt_config_init(void);
/**
* set cctt config to config of factory test mode
*
* @param none
* @return ERR_OK if success, error code otherwise
*/
uint8_t iot_cctt_cfg_set_to_ftm_cfg(void);
/**
* 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);
/**
* restore config to factory setting
*
* @param none
* @return ERR_OK if success, error code otherwise
*/
uint8_t iot_cctt_cfg_restore_factory_setting(void);
/**
* 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);
/*
* 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);
/**
* 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]);
/**
* 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]);
/**
* 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]);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* query boot application id from flash 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);
/**
* query server ip and port config from flash 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);
/**
* query local ethernet parameters from flash 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]);
/**
* query wifi configuraion from flash 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]);
/**
* query 4g configuraion from current used configuration
* used in factory test mode, current used config is different with flash cfg.
*
* @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]);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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]);
/**
* 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]);
/**
* 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]);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
#endif /*IOT_CCTT_CONFIG_H*/