first commit

This commit is contained in:
2025-07-03 23:58:20 +08:00
commit ce2b3cdfd4
444 changed files with 65256 additions and 0 deletions

View File

@ -0,0 +1,145 @@
#===============================================================================
# @brief cmake file
# Copyright (c) ShangHai High-flying Electronics Technology Co.,Ltd 2022-2022. All rights reserved.
#===============================================================================
set(COMPONENT_NAME "hsf")
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/hfsys.c
)
set(PUBLIC_HEADER
${CMAKE_CURRENT_SOURCE_DIR}
)
set(PRIVATE_HEADER
)
set(PRIVATE_DEFINES
CONFIG_SUPPORT_WIFI_APSTA
)
set(PUBLIC_DEFINES
)
# use this when you want to add ccflags like -include xxx
set(COMPONENT_PUBLIC_CCFLAGS #当前组件需要对外提供的编译选项
#-Wno-error=maybe-uninitialized #变量未初始化
#-Wno-error=pointer-sign #传递参数类型不匹配
#-Wno-error=char-subscripts #使用char类作为数组下标,char有符号
#-Wno-error=unused-label #未使用的标签比如用goto
#-Wno-error=strict-prototypes #函数的声明或定义没有参数
#-Wno-unused-parameter #未使用的函数参数
#-Wno-unused-variable #未使用的变量
#-Wno-unused-function #声明但未使用函数
#-Wno-unused-but-set-variable #设置了但未使用的变量
#-Wsign-compare #有符号与无符号比较
#-Wno-error=pointer-arith
#-Wno-error=sign-compare
#-Wno-error=jump-misses-init
#-Wno-error=incompatible-pointer-types
#-Wno-error=logical-op
#-Wno-error=empty-body
)
set(COMPONENT_CCFLAGS #当前组件内部生效的编译选项
-Wno-error=maybe-uninitialized #变量未初始化
-Wno-error=pointer-sign #传递参数类型不匹配
-Wno-error=char-subscripts #使用char类作为数组下标,char有符号
-Wno-error=unused-label #未使用的标签比如用goto
-Wno-error=strict-prototypes #函数的声明或定义没有参数
-Wno-unused-parameter #未使用的函数参数
-Wno-unused-variable #未使用的变量
-Wno-unused-function #声明但未使用函数
-Wno-unused-but-set-variable #设置了但未使用的变量
-Wsign-compare #有符号与无符号比较
-Wno-error=pointer-arith
-Wno-error=sign-compare
-Wno-error=jump-misses-init
-Wno-error=incompatible-pointer-types
-Wno-error=logical-op
-Wno-error=empty-body
)
set(WHOLE_LINK
true
)
set(MAIN_COMPONENT
true
)
build_component()
set(COMPONENT_NAME "app_main")
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/app_main.c
)
set(PUBLIC_HEADER
)
set(PRIVATE_HEADER
)
set(PRIVATE_DEFINES
CONFIG_SUPPORT_WIFI_APSTA
)
set(PUBLIC_DEFINES
)
# use this when you want to add ccflags like -include xxx
set(COMPONENT_PUBLIC_CCFLAGS #当前组件需要对外提供的编译选项
#-Wno-error=maybe-uninitialized #变量未初始化
#-Wno-error=pointer-sign #传递参数类型不匹配
#-Wno-error=char-subscripts #使用char类作为数组下标,char有符号
#-Wno-error=unused-label #未使用的标签比如用goto
#-Wno-error=strict-prototypes #函数的声明或定义没有参数
#-Wno-unused-parameter #未使用的函数参数
#-Wno-unused-variable #未使用的变量
#-Wno-unused-function #声明但未使用函数
#-Wno-unused-but-set-variable #设置了但未使用的变量
#-Wsign-compare #有符号与无符号比较
#-Wno-error=pointer-arith
#-Wno-error=sign-compare
#-Wno-error=jump-misses-init
#-Wno-error=incompatible-pointer-types
#-Wno-error=logical-op
#-Wno-error=empty-body
)
set(COMPONENT_CCFLAGS #当前组件内部生效的编译选项
-Wno-error=maybe-uninitialized #变量未初始化
-Wno-error=pointer-sign #传递参数类型不匹配
-Wno-error=char-subscripts #使用char类作为数组下标,char有符号
-Wno-error=unused-label #未使用的标签比如用goto
-Wno-error=strict-prototypes #函数的声明或定义没有参数
-Wno-unused-parameter #未使用的函数参数
-Wno-unused-variable #未使用的变量
-Wno-unused-function #声明但未使用函数
-Wno-unused-but-set-variable #设置了但未使用的变量
-Wsign-compare #有符号与无符号比较
-Wno-error=pointer-arith
-Wno-error=sign-compare
-Wno-error=jump-misses-init
-Wno-error=incompatible-pointer-types
-Wno-error=logical-op
-Wno-error=empty-body
)
set(WHOLE_LINK
true
)
set(MAIN_COMPONENT
true
)
build_component()

View File

@ -0,0 +1,66 @@
/* assis_thread.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _ASSIS_THREAD_H_
#define _ASSIS_THREAD_H_
#ifdef __cplusplus
extern "C" {
#endif
#define ASSIS_PORT 48899
#define ASSIS_PBUF_SIZE 200
/**
* @brief start assis thread.
*
* @param[in] port: assis thread listen udp port
* @return[out] HF_SUCCESS-successfully, other value is failed
*/
int HSF_IAPI start_assis(uint16_t port);
/**
* @brief check whether or not in assis AT cmd mode.
*
* @param[in] None
* @return[out] 0-not in, 1-in assis AT cmd mode
* @see None.
* @note None.
*/
int HSF_IAPI assis_is_in_cmd(void);
/**
* @brief get assis AT cmd source IP address.
*
* @param[in] None
* @return[out] IP address in number format
* @see None.
* @note None.
*/
uint32_t HSF_IAPI assis_get_peer_ip(void);
/**
* @brief send response to AT commands from assis thread.
*
* @param[in] rsp: the response
* len: the length of response
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_IAPI assis_cmd_response(char *rsp, int len);
#ifdef __cplusplus
}
#endif
#endif

162
application/ws63/hsf/hfat.h Executable file
View File

@ -0,0 +1,162 @@
/* hfat.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_AT_H_
#define _HF_AT_H_
#include "hsf.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HFAT_MAX_CMD_DATA_LEN (1024)
#define HFAT_REPLY_FLAG_NOSEND_TAIL (0x00000001)
#define HFUART_TEST_WAIT_TIME 400
//#define HFAT_DELETE_PARTIAL_CMD
typedef int (*at_cmd_reply_func)(const char*,int len,int timeouts,int flags);
typedef int (*at_cmd_read_func)(char*buf,int len,int timeouts,int flags);
typedef struct _at_session
{
at_cmd_reply_func pfreply;
at_cmd_read_func pfread;
int sid;
char *rsp;
int rsp_len;
int cmd_id;
}at_session_t,*pat_session_t;
typedef pat_session_t at_session_handle;
typedef struct _at_cmd
{
const char * name;
int (*func)(pat_session_t,int, char** ,char *,int); // the main func , or init
const char * doc;
int (*callhook)(pat_session_t,int, char** ,char *,int);
} hfat_cmd_t,*phfat_cmd_t;
typedef struct _at_cmd_category
{
const char *name;
phfat_cmd_t item;
}hfat_cmd_category,*phfat_cmd_category;
enum session_id_e
{
AT_SESSION_UART0=0,
AT_SESSION_UART1=1,
AT_SESSION_ASSIST_SOCKET,
AT_SESSION_API,
};
enum ENCMDOPCODE
{
OPCODE_NONE,
OPCODE_EQUA,
OPCODE_WFLASH,
OPCODE_QUERY
};
enum ENCMDCODE
{
CMD_ERR =-1,
CMD_NONE = 0,
};
enum
{
UART0_TEST_NONE=0,
UART0_TEST_START,
UART0_TEST_SUCCESS
};
#define HFAT_TABLE_INDEX_USER 0
#define HFAT_TABLE_INDEX_UTILS 1
#define HFAT_TABLE_INDEX_SOCKA 2
#define HFAT_TABLE_INDEX_SOCKB 3
#define HFAT_TABLE_INDEX_WIFI 4
#define HFAT_TABLE_INDEX_NETWORK 5
#define HFAT_TABLE_INDEX_WIFITEST 6
extern hfat_cmd_category hf_at_cmd_tables[];
extern const hfat_cmd_t user_define_at_cmds_table[];
int setbaudrate(int baud,int uart_no);
int setparity(int parity,int uart_no);
int HSF_IAPI hfat_init(void);
int HSF_IAPI hfat_assis_send_cmd(char *cmd_line,int cmd_len);
int HSF_IAPI hfat_pars_uart_cmd(hfuart_handle_t uart, char *cmd_line, int len);
int HSF_IAPI hfat_uart_recv(char *data, uint32_t bytes, uint32_t timeouts);
int HSF_IAPI hfat_uart_send(char *data, uint32_t bytes);
void HSF_IAPI print_hex(char *rep, unsigned char h);
void HSF_IAPI cmd_reply(char *reply);
int HSF_IAPI strtowords(char *str,char *words[],int size,char *separators);
/**
* @brief enable/disable uart at command.
*
* @param[in] enable: 1-enable, 0-disable
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfat_enable_uart_session(char enable);
/**
* @brief set at command buffer size.
*
* @param[in] size: range is [1-4096], in bytes, default is 100
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfat_set_atcmd_buf_size(int size);
/**
* @brief parse at command.
*
* @param[in] cmd_line: a pointer to a buffer containing the AT command
* cmd_len: the length, in bytes, of the data pointed to by the cmd_line parameter
* rsp: a pointer to a buffer to receive AT command response data
* len: the size of the rsp parameter
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note cannot be called in ISR.
*/
int HSF_API hfat_send_cmd(char *cmd_line,int cmd_len,char *rsp,int len);
/**
* @brief parse at command response.
*
* @param[in] str: a pointer to a buffer containing the AT command response data
* words: a pointer to a pointer buffer
* size: the count of words parameter
* @return[out] the count of words
* @see None.
* @note None.
*/
int HSF_API hfat_get_words(char *str,char *words[],int size);
#ifdef __cplusplus
}
#endif
#endif

704
application/ws63/hsf/hfconfig.h Executable file
View File

@ -0,0 +1,704 @@
/* hfconfig.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_CONFIG_H_
#define _HF_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "hsf.h"
#define CONFIG_HAVE_SETTIMEOFDAY 1
#define CONFIG_HAVE_GETTIMEOFDAY 1
//#define CONFIG_NO_STRUCT_TIMEZONE
#define SECRET_BUF_SIZE 3500
#define DEFAULT_NTP_SERVER "cn.ntp.org.cn"
#define UPDATEFLAG 2
#define BLE_CONKEYLEN 16
#define HILINK_SN_MAX_SIZE 36
#pragma pack(push)
#pragma pack(1)
typedef struct
{
int8_t updateflag; //update flag
int8_t validflag; //valid flag
int8_t tmode_mode;
int8_t wmode_mode;
//STA, 140 bytes
uint8_t sta_ssid[33];
uint8_t sta_key[65];
int8_t wsauth;
int8_t wsencry;
uint8_t wslko;
uint8_t pmk_av;
uint8_t sta_padding[6];
uint8_t pmk[32];
//AP, 144 bytes
int8_t wap_mode;
int8_t wap_channel;
int8_t waauth;
int8_t waencry;
uint8_t walk_led;
uint8_t max_sta_num;
uint8_t ap_enable_hide;
uint8_t ap_ssid[33];
uint8_t ap_key[65];
uint8_t ap_pmk_av;
uint8_t ap_pmk[32];
uint8_t ap_padding[6];
//UART, 20 bytes
int8_t baudrate;
int8_t data_bits;
int8_t stop_bits;
int8_t parity;
int8_t ctsrts;
int8_t uart1_baudrate;
int8_t uart1_data_bits;
int8_t uart1_stop_bits;
int8_t uart1_parity;
int8_t uart1_debug;
int8_t uartfable;
int8_t fuartte_mode;
uint16_t uarttm;
uint16_t uartbuf;
uint8_t uart_padding[4];
//NETP, 108 bytes
int8_t protocol;
int8_t app_mode;
uint8_t maxsocket;
char cipadd[101];
uint16_t pro_port;
uint16_t tcpto;
//SOCKB, 112 bytes
uint16_t sockb_port;
uint16_t sockb_tcpto;
int8_t sockb_pro;
char sockb_cipadd[101];
int8_t tcpdis;
int8_t tcpdisb;
uint16_t udp_localporta;
uint16_t udp_localportb;
//NETWORK, 108 bytes
char wann_ipaddr[16];
char wann_mask[16];
char wann_gateway[16];
char lann_ipaddr[16];
char lann_mask[16];
uint8_t wann_mode;
uint8_t network_padding[2];
uint8_t domain_name[21];
uint32_t dns_addr;
//UTILS, 124 bytes
int8_t echo;
int8_t rlden;
uint8_t debug_level;
char wel_msg[11];
uint8_t event_onoff;
uint8_t noise_filter;
uint8_t wifi_switch;
uint8_t sta_dtim;
uint8_t utils_padding[40];
uint8_t dis_power_saving;
int8_t modechange;
uint8_t ps_interval;
uint8_t mid[21];
uint8_t aswd[21];
uint8_t cmdpw[21];
//HTTPD, 36 bytes
char user_name[16];
char user_password[16];
int8_t web_switch;
uint8_t web_language;
uint8_t web_encode_format;
uint8_t httpd_padding;
//DHCPD, 4 bytes
int8_t dhcpsw;
uint8_t dhcpd_addr_start;
uint8_t dhcpd_addr_end;
uint8_t dhcpd_padding;
//UPDATE, 124 bytes
char update_url[101];
char update_file[21];
uint8_t update_padding[2];
//NTP, 8 bytes
uint8_t ntp_time;
uint8_t ntp_enable;
uint8_t ntp_padding;
int8_t time_zone;
uint32_t ntpserver;
//SMTLK, 16 bytes
uint32_t smtlk_sign;
uint8_t smtlk_mode;
uint8_t smtlk_protocol;
uint8_t smtlk_rtype;
uint8_t smtlk_ak_random;
uint8_t connect_flag;
uint8_t sta_channel;
uint8_t sta_bssid[6];
//SMARTAPLINK, 44 bytes
uint8_t smartaplink_enable;
uint8_t smartaplink_padding;
uint8_t smartaplink_prefix[21];
uint8_t smartaplink_key[21];
//NETPID, 24 bytes
uint8_t netpa_iden;
char netpa_id[11];
uint8_t netpb_iden;
char netpb_id[11];
//NETPREG, 264 bytes
uint8_t netpa_regen;
uint8_t netpa_regtype;
uint8_t netpa_reg_padding;
char netpa_regdata[129];
uint8_t netpb_regen;
uint8_t netpb_regtype;
uint8_t netpb_reg_padding;
char netpb_regdata[129];
//HEART, 124 bytes
uint16_t heart_netp_time;
uint16_t heart_sockb_time;
uint16_t heart_uart_time;
char heart_netp_data[39];
char heart_sockb_data[39];
char heart_uart_data[39];
uint8_t heart_padding;
//HTTP, 236 bytes
uint8_t http_type;
uint8_t http_version;
uint8_t http_connect_type;
uint8_t http_recv_time;
char http_url[51];
char http_header[181];
//MQTT, 224 bytes
char mqtt_username[33];
char mqtt_password[33];
char mqtt_clientid[33];
char mqtt_pub_topic[61];
char mqtt_sub_topic[61];
uint8_t mqtt_qos;
uint16_t mqtt_heart_time;
//BLE, 188 bytes
uint16_t conn_min;
uint16_t conn_max;
uint16_t conn_latency;
uint16_t supervisionTO;
uint16_t adver_min;
uint16_t adver_max;
uint8_t ble_name[27]; //BLE广播名
uint8_t ble_dms_name[27]; //BLE配网名
uint8_t ble_adver_data[27];
uint8_t ble_adver_data_len;
uint8_t ble_switch;
uint8_t ble_uuid_server;
uint8_t dms_type;
uint8_t ble_padding;
uint8_t uuid_ntf_server[17];
uint8_t uuid_ntf_read[17];
uint8_t uuid_ntf_write[17];
uint8_t uuid_ind_server[17];
uint8_t uuid_ind_read[17];
uint8_t uuid_ind_write[17];
uint8_t adver_type;
uint8_t adver_channel;
uint8_t ble_ind;
uint8_t smartconfiglink;
uint8_t ble_conenable;
uint8_t ble_conkey[BLE_CONKEYLEN];
uint8_t ble_contimeout;
uint8_t netpc_iden;
char netpc_id[11];
uint8_t netpc_idflag;
uint8_t ble_padding2[17];
uint8_t mqtt_tls;
uint8_t mqtt_padding[3];
char iot_productkey[12];
char iot_devicename[48];
char iot_devicesecret[48];
char iot_pubtopic[96];
char iot_subtopic[96];
char iot_mode;
char iot_padding[3];
uint8_t product_mode;
int8_t ctsrts_pin;
char instance_flag;
char instance_id[32];
char ntp_domain_server[33];
int8_t smk_find;
uint32_t mcu_ota_size;
uint8_t scan_ch14;
uint32_t module_reset_reason;
uint8_t radar_type; //雷达工作类型(0 is disable)
uint8_t radar_led; //雷达灯工作类型(0 is off)
uint8_t smtlk_type;
char hilink_sn[HILINK_SN_MAX_SIZE];
uint8_t prot_type;
uint8_t product;
uint8_t uart1_debug_rx_invalid;
uint8_t reserved1[51+512-HILINK_SN_MAX_SIZE-1];
uint8_t validflag_magic;
int8_t validflag_end; //valid flag
}HF_CONFIG_FILE; //sizeof Must have 16 byte alignment
typedef struct
{
uint32_t magic_code;
uint32_t crc32;
uint32_t ver;
uint32_t ota_flag;
uint32_t run_mode;
uint32_t upgrade_fw_addr;
uint8_t flash_test;
uint8_t reserved2;
uint8_t xmodem_upgrade_fw_flag;
uint8_t debug;
uint8_t rf_init;
uint8_t run_default_sw;
uint8_t run_rf_test_app;
uint8_t boot_wait_flag;
int8_t rf_table[48];
uint8_t reserved[48];
}HF_BOOT_CONFIG;
#pragma pack(pop)
extern int g_module_id;
extern HF_CONFIG_FILE g_hf_config_file;
enum ENWAUTH
{
WAUTH_OPEN = 0x00,
WAUTH_SHARED,
WAUTH_WPAPSK,
WAUTH_WPA2PSK,
WAUTH_WPAPSKWPA2PSK
};
enum ENWENCRY
{
WENCRY_NONE = 0x00,
WENCRY_WEP_A,
WENCRY_WEP_H,
WENCRY_TKIP,
WENCRY_AES,
WENCRY_TKIPAES,
WENCRY_WEP
};
enum ENNETSETAPP
{
NETSETAPP_SERVER = 0x00,
NETSETAPP_CLIENT
};
enum ENNETSETPRO
{
NETSETPRO_TCP = 0x00,
NETSETPRO_UDP,
NETSETPRO_HTTPC,
NETSETPRO_MQTT,
NETSETPRO_ALIIOT,
NETSETPRO_IGMP,
NETSETPRO_TCP_TLS,
NETSETPRO_HTTPSC
};
enum ENSOCKBPRO
{
SOCKBPRO_NONE = 0x00,
SOCKBPRO_TCP,
SOCKBPRO_UDP,
SOCKBPRO_UDPS,
SOCKBPRO_IGMP
};
typedef enum ENBAUDRATE
{
BAUDRATE_50 = 0x00,
BAUDRATE_75,
BAUDRATE_110,
BAUDRATE_134,
BAUDRATE_150,
BAUDRATE_200,
BAUDRATE_300,
BAUDRATE_600,
BAUDRATE_1200,
BAUDRATE_1800,
BAUDRATE_2400,
BAUDRATE_4800,
BAUDRATE_9600,
BAUDRATE_19200,
BAUDRATE_38400,
BAUDRATE_57600,
BAUDRATE_115200,
BAUDRATE_230400,
BAUDRATE_380400,
BAUDRATE_460800,
BAUDRATE_921600,
BAUDRATE_56000,
BAUDRATE_1000000,
BAUDRATE_1500000,
BAUDRATE_2000000,
BAUDRATE_2500000,
BAUDRATE_3000000,
BAUDRATE_3500000,
BAUDRATE_4000000
}ENBAUDRATE_E;
typedef enum ENCOMBITS
{
COMBITS_5 = 0x00,
COMBITS_6,
COMBITS_7,
COMBITS_8
}ENCOMBITS_E;
typedef enum ENCOMPARITY
{
COMPARITY_NONE = 0x00,
COMPARITY_ODD,
COMPARITY_EVEN,
COMPARITY_MARK,
COMPARITY_SPACE
}ENCOMPARITY_E;
typedef enum ENCOMSTOPBITS
{
COMSTOPBITS_1 = 0x01,
COMSTOPBITS_1P5,
COMSTOPBITS_2
}ENCOMSTOPBITS_E;
typedef enum ENCOMUARTCTL
{
COMUARTFC = 0x00,
COMUARTNFC
}ENCOMUARTCTL_E;
typedef enum ENCOMUARTCTLPIN
{
COMUARTFCPIN_DEF = 0x00,
COMUARTFCPIN_REV
}ENCOMUARTCTLPIN_E;
enum ENCOMWANNMODE
{
COMWANNDHCP = 0x00,
COMWANNSTATIC
};
enum ENUARTFABLE
{
HFUARTFDISABLE = 0x00,
HFUARTFENABLE,
HFUARTHFFORMAT,
};
enum ENUARTFMODE
{
M2M_UARTTE_FAST = 0x00,
M2M_UARTTE_NORMAL
};
enum CONFIG_WAMOD
{
CONFIG_WAMOD_11B = 0x00,
CONFIG_WAMOD_11BG,
CONFIG_WAMOD_11BGN
};
enum CONFIG_WMODE
{
CONFIG_WMODE_AP = 0x00,
CONFIG_WMODE_STA,
CONFIG_WMODE_APSTA
};
enum ENWORKTMODE
{
M2M_STATE_RUN_THROUGH = 0x00,
M2M_STATE_RUN_CMD,
M2M_STATE_RUN_GPIO,
M2M_STATE_RUN_PWM
};
enum CONFIG_PSLP
{
CONFIG_PSLP_NORMAL = 0x00,
CONFIG_PSLP_STANDBY,
CONFIG_PSLP_DEEPSLEEP
};
enum CONFIG_PRLDEN
{
CONFIG_PRLDEN_DISABLE = 0x00,
CONFIG_PRLDEN_ENABLE
};
enum CONFIG_WADHCP
{
CONFIG_WADHCP_DISABLE = 0x00,
CONFIG_WADHCP_ENABLE
};
enum CONFIG_WEBLANGUAGE
{
CONFIG_WEBLAN_EN = 0x00,
CONFIG_WEBLAN_CN
};
enum CONFIG_DISPS
{
CONFIG_EN_PS = 0x00,
CONFIG_DIS_PS
};
enum CONFIG_BLE
{
CONFIG_BLE_ON = 0x00,
CONFIG_BLE_OFF
};
enum CONFIG_BLE_IND //ble link light
{
CONFIG_BLE_IND_OFF = 0x00,
CONFIG_BLE_IND_ON
};
enum CONFIG_REG_TYPE
{
CONFIG_REG_TYPE_LINK = 0x00,
CONFIG_REG_TYPE_DATA,
CONFIG_REG_TYPE_BOTH
};
typedef enum
{
SMTLK_BLE_NARMAL =0,
SMTLK_BLE_ADD_LOCAL_CONTROL =1,
SMTLK_BLE_FAST_CONNECT =2,
SMTLK_SOFTAP =3
}config_type_t;
enum
{
SMTLK_BLE_NOMAL =1,
SMTLK_BLE_DOUBLE_CONTROL=12,
SMTLK_BLE_FAST=17
};
enum CONFIG_FACTORYTEST
{
CONFIG_FACTORYTEST_OFF = 0x00,
CONFIG_FACTORYTEST_ON = 0x01
};
void HSF_IAPI hfconfig_init(void);
int HSF_IAPI hfconfig_is_valid(void);
void HSF_IAPI hfconfig_dump(unsigned char *data, int len);
int HSF_IAPI hfconfig_protect_check(void);
int HSF_IAPI hfconfig_fseting_save_ex(HF_CONFIG_FILE *file);
int HSF_IAPI hfconfig_fseting_save(void);
void HSF_IAPI hfconfig_file_reload(void);
void HSF_IAPI hfconfig_enable_save(int enable);
void HSF_IAPI hfconfig_file_save(void);
int HSF_IAPI hfboot_config_set_ota_ready(uint32_t ota_file_addr);
int HSF_IAPI hfboot_config_set_ota_flags(uint32_t flags);
int HSF_IAPI hfboot_config_set_ota_xmodem(uint8_t flag);
int HSF_IAPI hfboot_config_set_run_default_sw(uint8_t flag);
uint8_t HSF_IAPI hfboot_config_get_run_default_sw(void);
int HSF_IAPI hfboot_config_set_flash_test(uint8_t flag);
int HSF_IAPI hfboot_config_get_flash_test(void);
void HSF_IAPI hfboot_update_run_mode(uint32_t mode);
void HSF_IAPI hfboot_set_rf_test_mode(uint8_t mode);
uint8_t HSF_IAPI hfboot_get_rf_test_mode(void);
void HSF_IAPI hfboot_set_boot_wait_flag(uint8_t flag);
uint8_t HSF_IAPI hfboot_get_boot_wait_flag(void);
int HSF_IAPI hfboot_config_set_rf_table(int8_t table[48]);
int HSF_IAPI hfboot_config_get_rf_table(int8_t table[48]);
void HSF_IAPI hfboot_update_run_mode(uint32_t mode);
void HSF_IAPI hfboot_set_debug(uint8_t on);
int HSF_IAPI hfconfig_uart_baud_en2num(int *num,int baudrate);
int HSF_IAPI hfconfig_uart_baud_num2en(int num, int *en);
uint8_t HSF_API hfproduct_is_run(void);
void HSF_API hfproduct_run_set(uint8_t mode);
int HSF_API hf_get_customer_run_mode(void);
int HSF_API hf_set_customer_run_mode(int mode);
uint8_t hf_hilink_main_is_runing(void);
void hf_set_hilink_main_runing(void);
/**
* @brief check High-flying config data is valid.
*
* @param[in] None
* @return[out] 0-invalid, 1-valid
* @see None.
* @note None.
*/
int HSF_API hfconfig_file_check_is_valid(void);
/**
* @brief read High-flying config data.
*
* @param[in] offset: the offset of config data
* data: a pointer to data
* len: the length, in bytes, of the data pointed to store data
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfconfig_file_data_read(int offset, unsigned char *data, int len);
/**
* @brief write High-flying config data.
*
* @param[in] offset: the offset of config data
* data: a pointer to data
* len: the length, in bytes, of the data pointed to write
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfconfig_file_data_write(int offset, unsigned char *data, int len);
/**
* @brief read hilink sn.
*
* @param[in] NULL
* @return[out] return hilink sn string
* @see None.
* @note None.
*/
char *hfget_hilink_sn(void);
/**
* @brief write hilink sn.
*
* @param[in] set hilink sn to flash
* @return[out] 0 set success other fail
* @see None.
* @note None.
*/
int hfset_hilink_sn(char *sn);
/**
* @brief set hilink smtlk mode.
*
* @param[in] set hilink smtlk mode to flash
* SMTLK_BLE_NARMAL ble常规配网
* SMTLK_BLE_ADD_LOCAL_CONTROL ble双联双控
* SMTLK_BLE_FAST_CONNECT ble极简配网
* SMTLK_SOFTAP softap配网
* @return[out] NULL
* @see None.
* @note None.
*/
void hfset_hilink_mode(int type);
/**
* @brief get hilink smtlk mode.
* @param[in] NULL
* @return[out] hilink mode
* SMTLK_BLE_NARMAL ble常规配网
* SMTLK_BLE_ADD_LOCAL_CONTROL ble双联双控
* SMTLK_BLE_FAST_CONNECT ble极简配网
* SMTLK_SOFTAP softap配网
* @see None.
* @note None.
*/
int hfget_hilink_mode(void);
#ifdef __cplusplus
}
#endif
#endif

230
application/ws63/hsf/hfcrypto.h Executable file
View File

@ -0,0 +1,230 @@
/* hfcrypto.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_CRYPTO_H_
#define _HF_CRYPTO_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief encrypt data with aes (ecb mode/128bit key).
*
* @param[in] key: the key of AES
* data: the data want to encrypt
* data_len: the length of data
* @return[out] the length of encrypted data
* @see None.
* @note None.
*/
int HSF_API hfcrypto_aes_ecb_encrypt(const unsigned char *key, unsigned char *data, int data_len);
/**
* @brief decrypt data with aes (ecb mode/128bit key).
*
* @param[in] key: the key of AES
* data: the data want to decrypt
* data_len: the length of data
* @return[out] the length of decrypted data
* @see None.
* @note None.
*/
int HSF_API hfcrypto_aes_ecb_decrypt(const unsigned char *key, unsigned char *data, int data_len);
/**
* @brief encrypt data with aes (cbc mode/128bit key).
*
* @param[in] key: the key of AES
* iv: the initialization vector of AES
* data: the data want to encrypt
* data_len: the length of data
* @return[out] the length of encrypted data
* @see None.
* @note None.
*/
int HSF_API hfcrypto_aes_cbc_encrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
/**
* @brief decrypt data with aes (cbc mode/128bit key).
*
* @param[in] key: the key of AES
* iv: the initialization vector of AES
* data: the data want to decrypt
* data_len: the length of data
* @return[out] the length of decrypted data
* @see None.
* @note None.
*/
int HSF_API hfcrypto_aes_cbc_decrypt(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
/**
* @brief calculate the MD5 of the data.
*
* @param[in] data: the data want to calculate MD5
* len: the length of data, in bytes
* digest: store MD5, must > 16 bytes
* @return[out] the length of MD5, in bytes
* @see None.
* @note None.
*/
int HSF_API hfcrypto_md5(const unsigned char *data, int len, unsigned char *digest);
/**
* @brief encode data as base64.
*
* @param[in] src: input byte array
* srclength: size of input byte array
* target: output byte array
* targsize: size of output byte array
* @return[out] returns the number of data bytes stored at the target, or -1 on error.
* @see None.
* @note encode data as base64, converts characters, three at a time,
* starting at src into four base64 characters in the target area
* until the entire input buffer is encoded.
*/
int HSF_API hfcrypto_base64_encode(char *src, uint32_t srclength, char *target, uint32_t targsize);
/**
* @brief decode Base64 data.
*
* @param[in] src: input byte array
* target: output byte array
* targsize: size of output byte array
* @return[out] returns the number of data bytes stored at the target, or -1 on error.
* @see None.
* @note decode Base64 data, skips all whitespace anywhere. converts
* characters, four at a time, starting at (or after) src from Base64
* numbers into three 8 bit bytes in the target area..
*/
int HSF_API hfcrypto_base64_decode(char *src, char *target, uint32_t targsize);
/**
* @brief rsa public key operation (1024bit key).
*
* @param[in] key: the key of RSA
* data: the data want to decrypt
* data_len: the length of data
* @return[out] the length of encrypted data
* @see None.
* @note None.
*/
// int HSF_API hfcrypto_rsa_public(const unsigned char *key, unsigned char *data, int data_len);
/**
* @brief HMAC-SHA1 algorithm.
*
* @param[in] key: the key of HMAC-SHA1
* key_len: the length of key
* data: the data want to calculate HMAC-SHA1
* data_len: the length of data
* mac: the hash (20 bytes)
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfcrypto_hmac_sha1(const unsigned char *key, int key_len, const unsigned char *data, int data_len, unsigned char *mac);
/**
* @brief AES CBC模式解密
*
* @param input 文本输入
* @param input_len 输入文本长度
* @param output 文本输出
* @param output_len 文本输出最大长度
* @param key 秘钥
* @param key_len 秘钥长度
* @param iv 初始化向量
* @param iv_len 初始化向量长度
* @return uint8_t 返回是否解密成功0不成功1成功
*/
uint8_t aes_cbc_decipher(uint8_t *input, uint32_t input_len,
uint8_t *output, uint32_t output_len,
uint8_t *key, uint32_t key_len,
uint8_t *iv, uint32_t iv_len);
#if 1
#define Nb 4 //加解密数据块大小固定为4
// GF(2^8) 多项式
#define BPOLY 0x1B //x^4 + x^3 + x^1 + x^0= 从右边开始算bit0、bit1、bit3、bit4、为1bit2、bit5、bit6、bit7为0即00011011=0x1B
//加密类型对应的密匙长度单位bit
typedef enum {
AES128 = 128,
AES192 = 192,
AES256 = 256,
} AESType_t;
//加解密模式
typedef enum {
AES_MODE_ECB = 0, // 电子密码本模式
AES_MODE_CBC = 1, // 密码分组链接模式
} AESMode_t;
typedef struct {
int Nk; //用户不需要填充,密钥长度,单位字节, AES128:Nk=16、AES192:Nk=24、AES256:Nr=32
int Nr; //用户不需要填充,加密的轮数 AES128:Nr=10、AES192:Nr=12、AES256:Nr=14
AESType_t type;//用户需填充关联AESType_t
AESMode_t mode;//用户需填充关联AESMode_t
const void *key;//用户需填充,密匙
const void *pIV;//用户需填充,初始化向量, 当mode=AES_MODE_CBC时需要设置指向unsigned char IV[4*Nb];
//AES拓展密匙, 空间大小 AES128:4*Nb*(10+1):4*Nb*(12+1)、AES256:4*Nb*(14+1)
unsigned char expandKey[4*Nb*(14+1)];//用户不需要填充,[4*Nb*(Nr+1)]、这里按最大的AES256进行初始化
} AESInfo_t;
/*****************************************************************************
* 函数名: AESInit
* 功能描述: 初始化
* 输入参数: aesInfoP -- 用户需要填充
* 输出参数: 无。
* 返回值: 无。
*****************************************************************************/
void AESInit(AESInfo_t *aesInfoP);
/*****************************************************************************
* 函数名: AESEncrypt
* 功能描述: 加密数据
* 输入参数: aesInfoP -- 包含key、加密方式等初始化信息
* pPlainText -- 要加密的明文数据其长度为dataLen字节。
* dataLen -- 明文数据长度,以字节为单位
* 输出参数: pCipherText -- 加密后的数据
* 返回值: 解密后的数据长度。
*****************************************************************************/
unsigned int AESEncrypt(AESInfo_t *aesInfoP, const unsigned char *pPlainText, unsigned char *pCipherText, unsigned int dataLen);
/*****************************************************************************
* 函数名: AESDecrypt
* 功能描述: 解密数据
* 输入参数: aesInfoP -- 包含key、加密方式等初始化信息
* pCipherText -- 要解密的密文
* dataLen -- 密文数据长度以字节为单位必须是整倍数AES128:16倍数、AES192:24倍数、AES256:32倍数。
* 输出参数: pPlainText -- 解密出来的明文
* 返回值: 返回解密后的数据长度。
*****************************************************************************/
unsigned int AESDecrypt(AESInfo_t *aesInfoP, unsigned char *pPlainText, const unsigned char *pCipherText, unsigned int dataLen);
#endif
#ifdef __cplusplus
}
#endif
#endif

103
application/ws63/hsf/hfflash.h Executable file
View File

@ -0,0 +1,103 @@
/* hfflash.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_FLASH_H_
#define _HF_FLASH_H_
#include "hsf.h"
#ifdef __cplusplus
extern "C" {
#endif
int HSF_IAPI hfflash_init(void);
unsigned int HSF_IAPI hfflash_size(void);
int HSF_IAPI flash_write(unsigned int addr, unsigned char *data, int len, int no_used);
int HSF_IAPI flash_erase_page(unsigned int addr, int pages);
int HSF_IAPI flash_erase_write(unsigned int addr, unsigned char *data, int len, int no_used);
int HSF_IAPI flash_read(unsigned int addr, unsigned char *data, int len, int no_used);
int HSF_IAPI flash_copy(unsigned int dstaddr, unsigned int srcaddr, int len);
int HSF_IAPI flash_valid_addr(unsigned int addr);
int HSF_IAPI flash_enable(int enable);
uint32_t HSF_IAPI hfget_flash_jedec_id(void);
void HSF_IAPI hfset_flash_jedec_id(uint32_t JedecId);
#define hfflash_write flash_write
#define hfflash_erase_page flash_erase_page
#define hfflash_erase_write flash_erase_write
#define hfflash_read flash_read
#define hfflash_copy flash_copy
#define hfflash_enable flash_enable
#define HFFLASH_PAGE_SIZE (4*1024)
/**
* @brief get the size of uflash, in bytes.
*
* @param[in] None
* @return[out] the size of uflash, in bytes
* @see None.
* @note None.
*/
int HSF_API hfuflash_size(void);
/**
* @brief erase uflash.
*
* @param[in] addr: the address of flash, start from 0
* pages: the number of pages to be erased, must <= 8, one page is 4096 bytes
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfuflash_erase_page(uint32_t addr, int pages);
/**
* @brief write data to uflash.
*
* @param[in] addr: the address of flash, start from 0
* data: a pointer to data
* len: the len of data
* @return[out] the length of write success
* @see None.
* @note None.
*/
int HSF_API hfuflash_write(uint32_t addr, char *data, int len);
/**
* @brief read data from uflash.
*
* @param[in] addr: the address of flash, start from 0
* data: a pointer to data
* len: the len of data
* @return[out] the length of read success
* @see None.
* @note None.
*/
int HSF_API hfuflash_read(uint32_t addr, char *data, int len);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,64 @@
/* hfflashlayout.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_FLASH_LAYOUT_H_
#define _HF_FLASH_LAYOUT_H_
#define CONFIG_FLASH_SIZE_4MB
#define CONFIG_FLASH_SIZE (1024*1024*4)
#define BOOT_ADDRESS 0x00002000 //BOOT
#define BOOT_SIZE (64*1024)
#define SOFTWARE_CODE_ADDRESS 0x00030000 //CODE区
#define MAX_SOFTWARE_CODE_SIZE (1720*1024)
#define SOFTWARE_HILINK_CODE_ADDRESS 0x001DE000 //HILINK CODE区
#define MAX_SOFTWARE_HILINK_CODE_SIZE (512*1024)
#define UPGRADE_ADDRESS 0x0025E000 //OTA区
#define MAX_UPGRADE_FILE_SIZE (1536*1024)
#define HILINK_FILE_SYS 0x003F3000 //HILINK文件系统区
#define HILINK_FILE_SYS_SIZE 0x00008000
#define UFLASH_ADDRESS 0x003DE000 //UFLASH区
#define HFUFLASH_SIZE (56*1024)
#define BOOT_CONFIG 0x003EC000 //HF_BOOT配置区
#define PRODUCT_PARA_ADDR 0x003ED000 //JSON配置MAC区
#define USERPAGE 0x003EE000 //AT参数存储区
#define USERPAGE_BACKUP 0x003F2000 //AT参数备份区
#define F_SETTING_ADDRESS 0x003F0000 //AT参数出厂值区
#define SECU_FLASH_ADDR 0x003F1000 //MAC存储区
#define SECU_FLASH_BACKUP_ADDR 0x003EF000 //MAC备份区
#define UFLASH1_ADDRESS 0
#define HFUFLASH1_SIZE (0)
#define HILINK_CRASH_INFO 0x003FB000 //程序崩溃信息区
#define HILINK_CRASH_INFO_SIZE 0x00001000
#define HILINK_NV_DATA 0x003FC000 //HILINK NV区
#define HILINK_NV_DATA_SIZE 0x00004000
#endif

434
application/ws63/hsf/hfgpio.h Executable file
View File

@ -0,0 +1,434 @@
/* hfgpio.h
*
* Copyright (C) 2023 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_GPIO_H_
#define _HF_GPIO_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*hfgpio_interrupt_func)(uint32_t irq, uint32_t fid);
#define HFM_PIN_NUMBER (32+1)
#define HFM_TYPE_LPT262 0
#define HFM_TYPE_LPT263 1
#define HFM_TYPE_LPT162 2
#define HFM_MAX_FUNC_CODE (HFM_PIN_NUMBER*3)
enum HF_GPIO_FUNC_E
{
//////fix/////////////////////
HFGPIO_F_JTAG_TCK=0,
HFGPIO_F_JTAG_TDO=1,
HFGPIO_F_JTAG_TDI,
HFGPIO_F_JTAG_TMS,
HFGPIO_F_USBDP,
HFGPIO_F_USBDM,
HFGPIO_F_UART0_TX,
HFGPIO_F_UART0_RTS,
HFGPIO_F_UART0_RX,
HFGPIO_F_UART0_CTS,
HFGPIO_F_SPI_MISO,
HFGPIO_F_SPI_CLK,
HFGPIO_F_SPI_CS,
HFGPIO_F_SPI_MOSI,
HFGPIO_F_UART1_TX,
HFGPIO_F_UART1_RTS,
HFGPIO_F_UART1_RX,
HFGPIO_F_UART1_CTS,
////////////////////////////////
HFGPIO_F_NLINK,
HFGPIO_F_NREADY,
HFGPIO_F_NRELOAD,
HFGPIO_F_SLEEP_RQ,
HFGPIO_F_SLEEP_ON,
HFGPIO_F_WPS,
HFGPIO_F_RESERVE1,
HFGPIO_F_RESERVE2,
HFGPIO_F_RESERVE3,
HFGPIO_F_RESERVE4,
HFGPIO_F_RESERVE5,
HFGPIO_F_USER_DEFINE
};
#define F_GPI (0x00010000)
#define F_GPO (0x00020000)
//GND
#define F_GND (0x00040000)
//vcc
#define F_VCC (0x00100000)
#define F_NC (0x00200000)
//use to system reset
#define F_RST (0x00400000)
//use to interrupt input pin
#define F_IT (0x00800000|F_GPI)
#define F_GPIO (F_GPI|F_GPO)
#define F_PWM (0x01000000)
#define F_PWM0 F_PWM
#define F_PWM1 F_PWM
#define F_PWM2 F_PWM
#define F_PWM3 F_PWM
#define F_PWM4 F_PWM
#define F_ADC (0x02000000)
#define HFM_NOPIN (0)
#define HFM_PIN1 (F_NC|1)
#define HFM_PIN2 (F_VCC|2)
#define HFM_PIN3 (F_VCC|3)
#define HFM_PIN4 (F_GPIO|F_IT|4)
#define HFM_PIN5 (F_GPIO|F_IT|5)
#define HFM_PIN6 (F_GPIO|F_IT|6)
#define HFM_PIN7 (F_GPIO|F_IT|7)
#define HFM_PIN8 (F_GPIO|F_IT|8)
#define HFM_PIN9 (F_GPIO|F_IT|9)
#define HFM_PIN10 (F_GPIO|F_IT|10)
#define HFM_PIN11 (F_GPIO|F_IT|11)
#define HFM_PIN12 (F_GPIO|F_IT|12)
#define HFM_PIN13 (F_GPIO|F_IT|13)
#define HFM_PIN14 (F_GPIO|F_IT|14)
#define HFM_PIN15 (F_GPIO|F_IT|15)
#define HFM_PIN16 (F_GPIO|F_IT|16)
#define HFM_PIN17 (F_VCC|17)
#define HFM_PIN18 (F_NC|18)
#define HFM_PIN19 (F_NC|19)
#define HFM_PIN20 (F_NC|20)
#define HFM_PIN21 (F_GND|21)
#define HFM_PIN22 (F_NC|22)
#define HFM_PIN23 (F_NC|23)
#define HFM_PIN24 (F_GPIO|F_IT|24)
#define HFM_PIN25 (F_GPIO|F_IT|25)
#define HFM_PIN26 (F_GPIO|F_IT|26)
#define HFM_PIN27 (F_GPIO|F_IT|27)
#define HFM_PIN28 (F_GPIO|F_IT|28)
#define HFM_PIN29 (F_GPIO|F_IT|29)
#define HFM_PIN30 (F_NC|30)
#define HFM_PIN31 (F_NC|31)
#define HFM_PIN32 (F_NC|32)
#define LPT26x_GPIO0 HFM_PIN4
#define LPT26x_GPIO1 HFM_PIN5
#define LPT26x_GPIO2 HFM_PIN6
#define LPT26x_GPIO3 HFM_PIN7
#define LPT26x_GPIO4 HFM_PIN8
#define LPT26x_GPIO5 HFM_PIN9
#define LPT26x_GPIO6 HFM_PIN10
#define LPT26x_GPIO7 HFM_PIN11
#define LPT26x_GPIO8 HFM_PIN12
#define LPT26x_GPIO9 HFM_PIN13
#define LPT26x_GPIO10 HFM_PIN14
#define LPT26x_GPIO11 HFM_PIN15
#define LPT26x_GPIO12 HFM_PIN16
#define LPT26x_GPIO13 HFM_PIN24
#define LPT26x_GPIO14 HFM_PIN25
#define LPT26x_GPIO15 HFM_PIN26
#define LPT26x_GPIO16 HFM_PIN27
#define LPT26x_GPIO17 HFM_PIN28
#define LPT26x_GPIO18 HFM_PIN29
#define HF_M_PINNO(_pin) ((_pin)&0xFF)
#define HFM_VALID_PINNO(_pinno) ((_pinno)>0&&(_pinno)<=HFM_PIN_NUMBER)
#define HF_M_PIN(_no) HFM_PIN##_no
/* Default pin configuration (no attribute). */
#define HFPIO_DEFAULT (0u << 0)
#define HFPIO_PULLUP (1u << 2)
#define HFPIO_PULLDOWN (1u << 3)
/* Low level interrupt is active */
#define HFPIO_IT_LOW_LEVEL (1u<<4)
/* High level interrupt is active */
#define HFPIO_IT_HIGH_LEVEL (1u<<5)
/* Falling edge interrupt is active */
#define HFPIO_IT_FALL_EDGE (1u<<6)
/* Rising edge interrupt is active */
#define HFPIO_IT_RISE_EDGE (1u<<7)
/*Interrupt Edge detection is active.*/
#define HFPIO_IT_EDGE (1u<<8)
#define HFPIO_TYPE_Pos 27
/* PIO Type Mask */
#define HFPIO_TYPE_Msk (0x7u << HFPIO_TYPE_Pos)
/* The pin is an input. */
#define HFM_IO_TYPE_INPUT (0x01 << HFPIO_TYPE_Pos)
/* The pin is an output and has a default level of 0.*/
#define HFM_IO_OUTPUT_0 (0x02 << HFPIO_TYPE_Pos)
/* The pin is an output and has a default level of 1.*/
#define HFM_IO_OUTPUT_1 (0x04 << HFPIO_TYPE_Pos)
#define HFPIO_DS (0x8u << HFPIO_TYPE_Pos)
void HSF_IAPI hfgpio_init(void);
int HSF_IAPI hfgpio_get_pid(int gpio);
int HSF_IAPI hfgpio_get_chip_pin(int fid);
int HSF_IAPI hfgpio_configure_pin(int pid,int flags);
int HSF_IAPI hfgpio_pin_is_high(int pid);
int HSF_IAPI hfgpio_fpin_add_feature(int fid,int flags);
int HSF_IAPI hfgpio_fpin_clear_feature(int fid,int flags);
void HSF_IAPI hfgpio_gpio_test_enable(int enable);
void HSF_IAPI hfgpio_set_nlink_pin(int val);
void HSF_IAPI hfgpio_set_nready_pin(int val);
int HSF_IAPI hfgpio_reload_pin_is_low(void);
#define hfgpio_set_out_high(pid) hfgpio_configure_pin(pid,HFPIO_DEFAULT|HFM_IO_OUTPUT_1)
#define hfgpio_set_out_low(pid) hfgpio_configure_pin(pid,HFPIO_DEFAULT|HFM_IO_OUTPUT_0)
/**
* @brief check the validity of hf_gpio_fid_to_pid_map_table.
*
* @param[in] type: the module type, as follows
* ==========================================
* | HFM_TYPE_LPT262 |
* |----------------------------------------|
* | HFM_TYPE_LPT263 |
* |----------------------------------------|
* | HFM_TYPE_LPT162 |
* ==========================================
* @return[out] HF_SUCCESS-successfully, other value is have multiple functions in the same pin
* @see None.
* @note None.
*/
int HSF_API hfgpio_fmap_check(int type);
/**
* @brief set the configure parameters of pin by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* flags: the flag of pin, as follows, can be used together, such as: HFPIO_DEFAULT|HFM_IO_TYPE_INPUT
* ==========================================
* | HFPIO_DEFAULT |
* |----------------------------------------|
* | HFM_IO_TYPE_INPUT |
* |----------------------------------------|
* | HFM_IO_OUTPUT_0 |
* |----------------------------------------|
* | HFM_IO_OUTPUT_1 |
* ==========================================
* @return[out] HF_SUCCESS-successfully, HF_FAIL-failed, HF_E_INVAL-illegal, HF_E_ACCES-not allowed
* @see None.
* @note None.
*/
int HSF_API hfgpio_configure_fpin(int fid, int flags);
/**
* @brief get the configure parameters of pin by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* @return[out] the configure parameters of pin
* @see None.
* @note None.
*/
int HSF_API hfgpio_fconfigure_get(int fid);
/**
* @brief set the pin to high level by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* @return[out] HF_SUCCESS-successfully, HF_FAIL-failed, HF_E_INVAL-illegal
* @see None.
* @note None.
*/
#define hfgpio_fset_out_high(fid) hfgpio_configure_fpin(fid,HFPIO_DEFAULT|HFM_IO_OUTPUT_1)
/**
* @brief set the pin to low level by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* @return[out] HF_SUCCESS-successfully, HF_FAIL-failed, HF_E_INVAL-illegal
* @see None.
* @note None.
*/
#define hfgpio_fset_out_low(fid) hfgpio_configure_fpin(fid,HFPIO_DEFAULT|HFM_IO_OUTPUT_0)
/**
* @brief configure the interrupt of pin by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* flags: the interrupt type, as follows
* ==========================================
* | HFPIO_IT_LOW_LEVEL |
* |----------------------------------------|
* | HFPIO_IT_HIGH_LEVEL |
* |----------------------------------------|
* | HFPIO_IT_FALL_EDGE |
* |----------------------------------------|
* | HFPIO_IT_RISE_EDGE |
* ==========================================
* handle: a function pointer, called back when trigger
* enable: enable or disable to trigger
* @return[out] HF_SUCCESS-successfully, HF_FAIL-failed, HF_E_INVAL-illegal, HF_E_ACCES-not allowed
* @see None.
* @note None. Timers cannot be used during interrupts
*/
int HSF_API hfgpio_configure_fpin_interrupt(int fid, uint32_t flags, hfgpio_interrupt_func handle, int enable);
/**
* @brief enable interrupt of pin by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* @return[out] HF_SUCCESS-successfully, HF_FAIL-failed, HF_E_INVAL-illegal
* @see None.
* @note None. Timers cannot be used during interrupts
*/
int HSF_API hfgpio_fenable_interrupt(int fid);
/**
* @brief disable interrupt of pin by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* @return[out] HF_SUCCESS-successfully, HF_FAIL-failed, HF_E_INVAL-illegal
* @see None.
* @note None. Timers cannot be used during interrupts
*/
int HSF_API hfgpio_fdisable_interrupt(int fid);
/**
* @brief disable interrupt of all pins by the function id.
*
* @param[in] fid:None
* @return[out] HF_SUCCESS-successfully, HF_FAIL-failed
* @see None.
* @note None. Timers cannot be used during interrupts
*/
int HSF_API hfgpio_disabel_all_interrupt(void);
/**
* @brief check the level of the pin to be high by the function id.
*
* @param[in] fid: the function id define by table 'hf_gpio_fid_to_pid_map_table'
* @return[out] >=1 high level, <=0 low level or illegal
* @see None.
* @note effective in output mode and input mode.
*/
int HSF_API hfgpio_fpin_is_high(int fid);
/**
* @brief check whether or not in GPIO test mode .
*
* @param[in] None
* @return[out] 0-not in test mode, 1-in test mode
* @see None.
* @note None.
*/
int HSF_API hfgpio_gpio_test_is_running(void);
/**
* @brief stop PWM.
*
* @param[in] fid: the function id of gpio
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfgpio_pwm_disable(int fid);
/**
* @brief start PWM.
*
* @param[in] fid: the function id of gpio
* freq: the frequency of PWM, the range is [100-800000]
* hrate: the duty cycle of PWM, the range is [0-100], 0 means low, 100 means high
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note the same PWM channel cannot be used at the same time.
*/
int HSF_API hfgpio_pwm_enable(int fid, int freq, int hrate);
/**
* @brief start PWM.
*
* @param[in] fid: the function id of gpio
* freq: the frequency of PWM, max is 20000000
* percent: high level ratio, accurate 0.0001
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note the same PWM channel cannot be used at the same time.
*/
int HSF_API hfgpio_pwm_enable_ex(int fid, int freq, float percent);
/**
* @brief start ADC.
*
* @param[in] fid: the function id of gpio
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfgpio_adc_enable(int fid);
/**
* @brief get ADC value.
*
* @param[in] fid: the function id of gpio
* @return[out]
<0-failed
>=0-the value of ADC, [0-3200] indicate [0V-3.2V]
* @see None.
* @note None.
*/
int HSF_API hfgpio_adc_get_value(int fid);
/**
* @brief init infrared function.
*
* @param[in] fid: the function id of gpio
* @see None.
* @note None.
*/
void HSF_API hf_ir_init(int fid);
/**
* @brief infrared enable.
*
* @param[in] fid: the function id of gpio
* @see None.
* @note None.
*/
void HSF_API hf_ir_enable(void);
/**
* @brief infrared disable.
*
* @param[in] fid: the function id of gpio
* @see None.
* @note None.
*/
void HSF_API hf_ir_disable(void);
#ifdef __cplusplus
}
#endif
#endif

48
application/ws63/hsf/hfmd5.h Executable file
View File

@ -0,0 +1,48 @@
#ifndef __MD5_H__
#define __MD5_H__
typedef struct
{
unsigned int count[2];
unsigned int state[4];
unsigned char buffer[64];
}IOT_MD5_CTX;
#define F(x,y,z) ((x & y) | (~x & z))
#define G(x,y,z) ((x & z) | (y & ~z))
#define H(x,y,z) (x^y^z)
#define I(x,y,z) (y ^ (x | ~z))
#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
#define FF(a,b,c,d,x,s,ac) \
{ \
a += F(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define GG(a,b,c,d,x,s,ac) \
{ \
a += G(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define HH(a,b,c,d,x,s,ac) \
{ \
a += H(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
#define II(a,b,c,d,x,s,ac) \
{ \
a += I(b,c,d) + x + ac; \
a = ROTATE_LEFT(a,s); \
a += b; \
}
void IOT_MD5Init(IOT_MD5_CTX *context);
void IOT_MD5Update(IOT_MD5_CTX *context,unsigned char *input,unsigned int inputlen);
void IOT_MD5Final(IOT_MD5_CTX *context,unsigned char digest[16]);
void IOT_MD5Transform(unsigned int state[4],unsigned char block[64]);
void IOT_MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
void IOT_MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);
void IOT_MD5_format2str(unsigned char *encrypt, unsigned char *buffer);
#endif

99
application/ws63/hsf/hfnet.h Executable file
View File

@ -0,0 +1,99 @@
#ifndef _HF_NET_H_
#define _HF_NET_H_
#include "lwip/sockets.h"
#define HFUART0 (hfuart_handle_t)(1)
#define HFUART1 (hfuart_handle_t)(2)
#define ASSIS_PORT 48899
typedef enum
{
HFNET_SOCKETA_DATA_READY=0,
HFNET_SOCKETA_CONNECTED=1,
HFNET_SOCKETA_DISCONNECTED,
HFNET_SOCKETB_DATA_READY,
HFNET_SOCKETB_CONNECTED,
HFNET_SOCKETB_DISCONNECTED,
HFNET_UART0_DATA_READY,
HFNET_UART1_DATA_READY,
HFNET_ASSIS_DATA_READY
}hfnet_event_id_t;
typedef struct _hfnet_stat
{
int hfnet_init_down;
int socketa_send_bytes;
int socketa_recv_bytes;
int socketa_connect_times;
int uart_send_bytes;
int uart_recv_bytes;
int socketb_send_bytes;
int socketb_recv_bytes;
int socketb_connect_times;
int uart_buffer_full_times;
int uart_irq_num;
int uart_thread_run;
int uart1_buffer_full_times;
int uart1_irq_num;
int uart1_thread_run;
int socketa_buffer_full_times;
int drop_arp_packet;
int drop_udp_broadcast_packet;
}hfnet_stat;
extern hfnet_stat g_hfnet_stat;
typedef int (*hfnet_callback_t)( uint32_t event,void *data,uint32_t len,uint32_t buf_len);
int hfnet_start_uart(uint32_t uxpriority, hfnet_callback_t p_callback);
int HSF_API hfnet_start_assis(uint16_t port);
int HSF_API hfnet_get_mac_address(char *mac_str);
int HSF_API hfnet_get_wan_ip(uint32_t * ip, uint32_t *mask, uint32_t *gw);
struct netif *hf_get_sta_netif(void);
int hfwifi_sta_is_connected(void);
int HSF_API hfnet_wifi_is_active(void);
int HSF_IAPI hfnet_send_assis_event(uint32_t event,void *data,uint32_t len,uint32_t buf_len);
/**
* @brief get ip address by domain name.
*
* @param[in] name: domain name
* addr: a pointer for using to store addr
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfnet_gethostbyname(const char *name, ip_addr_t *addr);
/**
* @brief check string is ip address.
*
* @param[in] ipaddr: ip string
* @return[out] 1-ip address, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfnet_is_ipaddress(const char * ipaddr);
#endif

38
application/ws63/hsf/hfntp.h Executable file
View File

@ -0,0 +1,38 @@
/* hfntp.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_NTP_H_
#define _HF_NTP_H_
#ifdef __cplusplus
extern "C"{
#endif
#define DEFAULT_NTP_SERVER "cn.ntp.org.cn"
/**
* @brief get UTC time from NTP server.
*
* @param[in] addr: NTP server address, support domain name
* port: NTP server port, such as "123"
* timeout: recv response timeout, in milliseconds
* @return[out] >0 UTC time from 1970-01-01 00:00, <0 is failed
* @see None.
* @note None.
*/
int HSF_API hfntp_get_time(const char *addr, unsigned short port, int timeout);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,34 @@
/* hfproduct.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_PRODUCT_H_
#define _HF_PRODUCT_H_
#include "hsf.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _product_cmd
{
const char * name;
void (*callhook)(int, char *);
} hfproduct_cmd_t,*phfproduct_cmd_t;
void HSF_IAPI hfproduct_init(void);
void HSF_IAPI hfproduct_read_mac(void);
#ifdef __cplusplus
}
#endif
#endif

12
application/ws63/hsf/hfsecret.h Executable file
View File

@ -0,0 +1,12 @@
#ifndef _HF_SECRET_H__
#define _HF_SECRET_H__
#include "hsf.h"
#define KEY_LEN 8
#define MAC_LEN 6
void HSF_IAPI hfwifi_init(void);
#define SECRET_MASSAGE_SIZE 256
#endif

120
application/ws63/hsf/hfsys.h Executable file
View File

@ -0,0 +1,120 @@
#ifndef _HF_SYS_H_
#define _HF_SYS_H_
#define MOD_ERROR_START(x) ((x << 16) | 0)
/* Create Module index */
#define MOD_GENERIC 0
/** HTTPD module index */
#define MOD_HTTPDE 1
/** HTTP-CLIENT module index */
#define MOD_HTTPC 2
/** WPS module index */
#define MOD_WPS 3
/** WLAN module index */
#define MOD_WLAN 4
/** USB module index */
#define MOD_USB 5
#define MOD_USER_DEFINE (0x80)
/* Globally unique success code */
#define HF_SUCCESS 0
#define HFSYS_RESET_REASON_NORMAL (0)
#define HFSYS_RESET_REASON_OTA (0x00000100)
enum hf_errno {
/* First Generic Error codes */
HF_GEN_E_BASE = MOD_ERROR_START(MOD_GENERIC),
HF_FAIL,
HF_E_PERM, /* Operation not permitted */
HF_E_NOENT, /* No such file or directory */
HF_E_SRCH, /* No such process */
HF_E_INTR, /* Interrupted system call */
HF_E_IO, /* I/O error */
HF_E_NXIO, /* No such device or address */
HF_E_2BIG, /* Argument list too long */
HF_E_NOEXEC, /* Exec format error */
HF_E_BADF, /* Bad file number */
HF_E_CHILD, /* No child processes */
HF_E_AGAIN, /* Try again */
HF_E_NOMEM, /* Out of memory */
HF_E_ACCES, /* Permission denied */
HF_E_FAULT, /* Bad address */
HF_E_NOTBLK, /* Block device required */
HF_E_BUSY, /* Device or resource busy */
HF_E_EXIST, /* File exists */
HF_E_XDEV, /* Cross-device link */
HF_E_NODEV, /* No such device */
HF_E_NOTDIR, /* Not a directory */
HF_E_ISDIR, /* Is a directory */
HF_E_INVAL, /* Invalid argument */
HF_E_NFILE, /* File table overflow */
HF_E_MFILE, /* Too many open files */
HF_E_NOTTY, /* Not a typewriter */
HF_E_TXTBSY, /* Text file busy */
HF_E_FBIG, /* File too large */
HF_E_NOSPC, /* No space left on device */
HF_E_SPIPE, /* Illegal seek */
HF_E_ROFS, /* Read-only file system */
HF_E_MLINK, /* Too many links */
HF_E_PIPE, /* Broken pipe */
HF_E_DOM, /* Math argument out of domain of func */
HF_E_RANGE, /* Math result not representable */
HF_E_DEADLK, /*Resource deadlock would occur*/
};
enum HFSYS_RUN_MODE_E
{
HFSYS_STATE_RUN_THROUGH=0,
HFSYS_STATE_RUN_CMD=1,
HFSYS_STATE_RUN_GPIO,
HFSYS_STATE_RUN_PWM,
HFSYS_STATE_MAX_VALUE
};
void HSF_API hfsys_reset(void);
uint32_t HSF_API hfsys_get_time(void);
int HSF_API hfsys_switch_run_mode(int mode);
int HSF_API hfsys_get_run_mode(void);
void HSF_API *hfmem_malloc(int size);
void HSF_API hfmem_free(void *pv);
uint32_t HSF_API hfsys_get_memory(void);
int HSF_API hfwifi_read_sta_mac_address(uint8_t *mac);
int HSF_IAPI hfwifi_write_sta_mac_address(uint8_t *mac, char *key);
uint32_t HSF_API hfsys_get_reset_reason(void);
void HSF_API hfsys_set_reset_reason(uint32_t reason);
int HSF_API hfwifi_read_sle_mac_address(uint8_t *mac);
int HSF_API hfwifi_write_sle_mac_address(uint8_t *mac);
int HSF_API hfwifi_read_ap_mac_address(uint8_t *mac);
unsigned int HSF_API hfsys_random(void);
void HSF_API hfsys_set_time(uint32_t t);
#endif

125
application/ws63/hsf/hfthread.h Executable file
View File

@ -0,0 +1,125 @@
#include "hsf.h"
#define HFTHREAD_PRIORITIES_LOW (15)
#define HFTHREAD_PRIORITIES_MID (13)
#define HFTHREAD_PRIORITIES_NORMAL (10)
#define HFTHREAD_PRIORITIES_HIGH (8)
#define HFTHREAD_MAX_PRIORITIES (1)
typedef void (*PHFTHREAD_START_ROUTINE)( void * arg);
typedef void* hfthread_sem_t;
int hfthread_create(PHFTHREAD_START_ROUTINE routine, char * name, uint16_t stack_depth, void *parameters, uint32_t uxpriority, uint32_t *created_thread, uint32_t *stack_buffer);
int hfsys_init(void);
void HSF_API hfthread_delay(uint32_t ms);
void HSF_API hfthread_destroy(uint32_t task_id);
#define msleep(ms) hfthread_delay(ms)
typedef void* hfthread_mutex_t;
#define NULL_MUTEX (hfthread_mutex_t)0
/**
* @brief create a mutex, not allow in ISR.
*
* @param[in] mutex: a pointer to mutex handle
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfthread_mutext_new(hfthread_mutex_t *pmutex);
/**
* @brief free a mutex, not allow in ISR.
*
* @param[in] pmutex: the specified mutex handle
* @return[out] None
* @see None.
* @note None.
*/
void HSF_API hfthread_mutext_free(hfthread_mutex_t mutex);
/**
* @brief releases ownership of the specified mutex object, not allow in ISR.
*
* @param[in] mutex: the specified mutex handle
* @return[out] None
* @see None.
* @note None.
*/
void HSF_API hfthread_mutext_unlock(hfthread_mutex_t mutex);
/**
* @brief waits until the specified mutex is in the signaled state, not allow in ISR.
*
* @param[in] mutex: the specified mutex handle
* timeout: timeout interval in millisecond, value >= 10, 0xFFFFFFFF mean the function will return only when the mutex is signaled
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfthread_mutext_wait(hfthread_mutex_t mutex, uint32_t timeout);
/**
* @brief try to wait a mutex, not allow in ISR.
*
* @param[in] mutex: the specified mutex handle
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfthread_mutext_trylock(hfthread_mutex_t mutex);
#define hfthread_mutext_lock(_mu) hfthread_mutext_wait(_mu,0xFFFFFFFF)
/**
* @brief create a semaphore, not allow in ISR.
*
* @param[in] sem: a pointer to semaphore handle
* cnt: the count of the semaphore, maximum is 255
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfthread_sem_new(hfthread_sem_t *sem,uint8_t cnt);
/**
* @brief free a semaphore, not allow in ISR.
*
* @param[in] sem: the specified semaphore handle
* @return[out] None
* @see None.
* @note None.
*/
void HSF_API hfthread_sem_free(hfthread_sem_t sem);
/**
* @brief increases the count of the specified semaphore object by 1.
*
* @param[in] sem: the specified semaphore handle
* @return[out] None
* @see None.
* @note None.
*/
void HSF_API hfthread_sem_signal(hfthread_sem_t sem);
/**
* @brief wait until the specified mutex is in the signaled state or the time-out interval elapses, not allow in ISR.
*
* @param[in] sem: the specified semaphore handle
* timeout: timeout interval in millisecond, value >= 10, 0xFFFFFFFF mean the function will return only when the semaphore is signaled
* @return[out] 1-the state of the specified object is signaled, 0-the time-out interval elapsed, and the object's state is nonsignaled
* @see None.
* @note None.
*/
int HSF_API hfthread_sem_wait(hfthread_sem_t sem, uint32_t timeout);

46
application/ws63/hsf/hftime.h Executable file
View File

@ -0,0 +1,46 @@
/* hftime.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_TIME_H_
#define _HF_TIME_H_
#ifdef __cplusplus
extern "C"{
#endif
#include <time.h>
#include "hsf.h"
#ifdef CONFIG_NO_STRUCT_TIMEZONE
struct timezone
{
int tz_minuteswest;
int tz_dsttime;
};
#endif
time_t time(time_t *timer);
#if !CONFIG_HAVE_SETTIMEOFDAY
int settimeofday(const struct timeval * tv, const struct timezone *tz);
#endif
#if !CONFIG_HAVE_GETTIMEOFDAY
int gettimeofday(struct timeval * tv, struct timezone * tz);
#endif
#ifdef __cplusplus
}
#endif
#endif

100
application/ws63/hsf/hfuart.h Executable file
View File

@ -0,0 +1,100 @@
#ifndef _HF_UART_H_
#define _HF_UART_H_
#include "hsf.h"
#include "ringbuf.h"
#include "hfthread.h"
#define DEBUG_LEVEL_CLOSE 0
#define DEBUG_LEVEL_NON -1
#define DEBUG_LEVEL_CLOSE 0
#define DEBUG_LEVEL_LOW 3
#define DEBUG_LEVEL_MID 4
#define DEBUG_LEVEL_HI 5
#define DEBUG_LEVEL DEBUG_LEVEL_HI
#define DEBUG_SMTLK DEBUG_LEVEL_MID
#define DEBUG_UPGRADE DEBUG_LEVEL_MID
#define DEBUG_ASSIS DEBUG_LEVEL_LOW //DEBUG_LEVEL_CLOSE
#define DEBUG_FLASH DEBUG_LEVEL_LOW
#define DEBUG_BOOTUP DEBUG_LEVEL_LOW
#define DEBUG_ATCMD DEBUG_LEVEL_LOW
#define DEBUG_CONFIG DEBUG_LEVEL_LOW
#define DEBUG_LEVEL_USER 10
#define DEBUG_WARN (DEBUG_LEVEL_USER-2)
#define DEBUG_ERROR (DEBUG_LEVEL_USER-2)
typedef void * hfuart_handle_t;
typedef struct _HFUART_THREAD
{
int uart_id;
hfuart_handle_t uart_handle;
char *uart_buf;
int uart_buf_size;
}HFUART_THREAD,*PHFUART_THREAD;
typedef struct _HFUART
{
unsigned char port; //端口 HF_UART0 0;HF_UART1 1;
char tx_enable;
char rx_enable;
char *rxbuf; //环形buff数据缓冲区
struct ringbuf uart_rx_buf; //串口环形buff句柄
volatile int b_wait_rx;
hfthread_sem_t rx_wait_event; //信号量
char fc_enable;
char fc_full;
char valid;
}HFUART,*PHFUART;
void HSF_API HF_Debug(int debug_level, const char *format , ... );
#define hfdbg_error(...) HF_Debug(DEBUG_ERROR,"[ %d error %s %d]",hfsys_get_time(),__FUNCTION__,__LINE__); \
HF_Debug(DEBUG_ERROR,__VA_ARGS__)
#define hfdbg_warn(...) HF_Debug(DEBUG_WARN,"[warnning %d %s %d]",hfsys_get_time(),__FUNCTION__,__LINE__); \
HF_Debug(DEBUG_WARN,__VA_ARGS__)
#define u_printf(...) HF_Debug(DEBUG_LEVEL_USER,__VA_ARGS__)
int hfuart_config(hfuart_handle_t huart, int baudrate, ENCOMPARITY_E parity, ENCOMBITS_E databits, ENCOMSTOPBITS_E stopbits, ENCOMUARTCTL_E fc);
hfuart_handle_t HSF_API hfuart_open(int uart_id);
int HSF_API hfuart_recv(hfuart_handle_t huart,char *recv,uint32_t bytes,uint32_t timeouts);
int HSF_API hfuart_send(hfuart_handle_t huart, char *data, uint32_t bytes, uint32_t timeouts);
int HSF_API hfuart_close(hfuart_handle_t huart);
int HSF_API hfdbg_get_level(void);
void HSF_API hfdbg_set_level(int level);
/**
* @brief set uart parameters.
*
* @param[in]
* baud: 串口波特率
* data_bits数据位 参考ENCOMBITS_E
* stop_bits停止位 参考ENCOMSTOPBITS_E
* parity :校验位 参考ENCOMPARITY_E
* len: the length, in bytes, of the data pointed to write
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note 立即生效需在hfnet_start_uart前设置默认不保存flash如需参数保存调用hfconfig_file_save();.
*/
int HSF_API hfset_uart_parameters(int baud,ENCOMBITS_E data_bits,ENCOMSTOPBITS_E stop_bits,ENCOMPARITY_E parity);
#endif

137
application/ws63/hsf/hfupdate.h Executable file
View File

@ -0,0 +1,137 @@
/* hfupdate.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_UPDATE_H_
#define _HF_UPDATE_H_
#ifdef __cplusplus
extern "C" {
#endif
#define HF_CONFIG_OTA_FLAG_REDAY (0x0A0A55A0)
#define HF_CONFIG_OTA_FLAG_OK (0x0505AA50)
#define HF_BOOT_CONFIG_MAGIC_CODE (0x48464254)
#define HF_CONFIG_OTA_FLAG_FAIL (0x5A5A5A00)
#define HF_BOOT_RUN_MODE_NORMAL (0)
#define HF_BOOT_RUN_MODE_AUTO_UPGRADE (0xA5010202)
#define HF_BOOT_RUN_MODE_DEBUG (0xA5010203)
typedef enum HFUPDATE_TYPE
{
HFUPDATE_SW=0,
HFUPDATE_CONFIG=1,
HFUPDATE_WIFIFW,
HFUPDATE_WEB,
}HFUPDATE_TYPE_E;
typedef enum http_download_type{
HTTP_DOWNLOAD_TYPE_TMP = 1, //下载到buff
HTTP_DOWNLOAD_TYPE_FLASH = 2, //下载到FLASH
HTTP_DOWNLOAD_LOCATION_UPGRADE = 4, //upgrade分区
HTTP_DOWNLOAD_LOCATION_FLASH_UPGRADE = HTTP_DOWNLOAD_TYPE_FLASH|HTTP_DOWNLOAD_LOCATION_UPGRADE, //FLASH中upgrade分区
HTTP_DOWNLOAD_LOCATION_WEB = 8, //web分区
HTTP_DOWNLOAD_LOCATION_FLASH_WEB = HTTP_DOWNLOAD_TYPE_FLASH|HTTP_DOWNLOAD_LOCATION_WEB, //FLASH中web分区
}http_download_type_t;
int HSF_IAPI hfupdate_auto_upgrade(uint32_t flags);
int HSF_IAPI http_download_enable_range(char enable);
int HSF_IAPI hfupdate_auto_upgrade_start(void);
int HSF_IAPI check_webpage_file_ok(char *addr, char *version);
/**
* @brief start OTA to update application.
*
* @param[in] type: update type, now only support 'HFUPDATE_SW' & 'HFUPDATE_WEB'
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note this function will need time to erase flash.
*/
int HSF_API hfupdate_start(HFUPDATE_TYPE_E type);
/**
* @brief write update file.
*
* @param[in] type: update type, now only support 'HFUPDATE_SW' & 'HFUPDATE_WEB'
* offset: offset address, start from 0
* data: a pointer to data
* len: the len of data
* @return[out] the length of write success
* @see None.
* @note this function will need some time to erase flash.
*/
int HSF_API hfupdate_write_file(HFUPDATE_TYPE_E type, uint32_t offset, uint8_t *data, int len);
/**
* @brief complete update.
*
* @param[in] type: update type, now only support 'HFUPDATE_SW' & 'HFUPDATE_WEB'
* file_total_len: the len of file
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note return -1 means file type error, return -2 means file crc error.
*/
int HSF_API hfupdate_complete(HFUPDATE_TYPE_E type, uint32_t file_total_len);
/**
* @brief download OTA file use http.
*
* @param[in] purl: http url
* @return[out] HF_SUCCESS-successfully, other value is failed
* @see None.
* @note None.
*/
int HSF_API hfupdate_fw_as_http(const char *purl);
/**
* @brief get bootloader version.
*
* @param[in] version: the buffer to store bootloader version
* @return[out] the crc32 of bootloader, 0 is failed
* @see None.
* @note None.
*/
unsigned int HSF_API hfupdate_read_boot_ver(char *version);
/**
* @brief check whether or not in updating
*
* @param[in] None
* @return[out] 0-not in updating, 1-in updating
* @see None.
* @note None.
*/
int HSF_API hfupdate_auto_upgrade_is_running(void);
/**
* @desc:
* @params: start_range is 0,file_len is NULL when DISABLE_HTTP_DOWNLOAD_RANGE
* @param[in] purl: http url
* @param[in] p_data: a buffer or a FLASH address to store update file
* @param[in] len: the len of p_data FLASH
* @param[in] type: the HTTP Download data to LOCATION
* @param[in] start_range: Download from Start position
* @return[out] < 0 error numb , > 0 down file length
*/
int HSF_API http_download_file(const char *purl, char *p_data, uint32_t len, http_download_type_t type, int start_range, int *file_len);
#ifdef __cplusplus
}
#endif
#endif

84
application/ws63/hsf/hfwifi.h Executable file
View File

@ -0,0 +1,84 @@
/* hfupdate.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HF_WIFI_H_
#define _HF_WIFI_H_
#define DEBUG_WIFI DEBUG_LEVEL_LOW
#define AUTH_TYPE_OPEN 0
#define AUTH_TYPE_SHARED 1
#define AUTH_TYPE_WPAPSK 2
#define AUTH_TYPE_WPA2PSK 3
#define AUTH_TYPE_WPAPSKWPA2PSK 4
#define AUTH_TYPE_WPAENT 5
#define AUTH_TYPE_WPA3SAE 6
#define AUTH_TYPE_WPA2PSKWPA3SAE 7
#define ENC_TYPE_NONE 0
#define ENC_TYPE_WEP 1
#define ENC_TYPE_TKIP 2
#define ENC_TYPE_AES 3
#define ENC_TYPE_TKIPAES 4
#define ENC_TYPE_CCMP 5
#define ENC_TYPE_INVALID 255
#define WIFI_MODE_AP 0
#define WIFI_MODE_STA 1
#define WIFI_MODE_APSTA 2
#define WIFI_MODE_NOSTART 0xFF
#define WIFI_STATE_UNINIT 0
#define WIFI_STATE_START 1
#define WIFI_STATE_STOPPING 2
#define WIFI_STATE_STOPPED 3
#define MAX_WIFI_SCAN_RESULT 50
typedef struct
{
char ssid[65];
uint8_t mac[20];
char enc[25];
char channl;
int sco;
int rssi;
}ScanResult_t;
typedef struct _WIFI_SCAN_RESULT_ITEM
{
uint8_t auth;
uint8_t encry;
uint8_t channel;
uint8_t rssi;
char ssid[32+1];
uint8_t mac[6];
int rssi_dbm;
int sco;
}WIFI_SCAN_RESULT_ITEM,*PWIFI_SCAN_RESULT_ITEM;
enum
{
HFWIFI_SCAN_EXIT=0,
HFWIFI_SCANING=1
};
typedef int (*hfwifi_scan_callback_ex_t)(PWIFI_SCAN_RESULT_ITEM,void*);
void wifi_auto_connect(void* arg);
void product_wifi_thread(void* arg);
int HSF_API hfwifi_transform_rssi(int rssi_dbm);
int HSF_API hfwifi_scan_ex(hfwifi_scan_callback_ex_t p_callback, void *ctx, unsigned char ch, unsigned char scan_time);
int HSF_API hfwifi_sta_get_current_rssi(int *dBm);
int HSF_API hf_get_wifi_state(void);
void HSF_API hf_set_wifi_state(int state);
#endif

103
application/ws63/hsf/hsf.h Executable file
View File

@ -0,0 +1,103 @@
/* hsf.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _HSF_H_
#define _HSF_H_
#define HSF_API
#define HSF_IAPI HSF_API
#define USER_FUNC
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#ifndef BYTE
// typedef unsigned char BOOL;
typedef unsigned char BYTE;
typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
typedef int INT;
typedef unsigned int UINT;
typedef long LONG;
typedef unsigned long DWORD;
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define HF_SUCCESS 0
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC extern
#include <stdbool.h>
//typedef unsigned char bool;
// #define true 1
// #define false 0
#endif
#ifndef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *) 0)
#endif
#endif
// #define _HSF_
#ifndef WEAK
#define WEAK __attribute__ ((weak))
#endif
#define FUNC_IN_RAM __attribute__((section(".tcm_code")))
// #include "hferrno.h"
#include "hfconfig.h"
#include "hfuart.h"
#include "hfat.h"
#include "hfsys.h"
#include "hfflash.h"
#include "hfthread.h"
#include "hfflashlayout.h"
#include "hfproduct.h"
#include "hfnet.h"
// #include "hf_debug.h"
#include "hfupdate.h"
#include "hfcrypto.h"
#include "hfgpio.h"
#include "hfwifi.h"
#include "hfnet.h"
#include "hfntp.h"
#include "debug_print.h"
#define DEBUG_NTP DEBUG_LEVEL_LOW
extern const char *HILINK_GetSdkVersion(void);
#define GLOBAL_VER HILINK_GetSdkVersion()
#ifdef CONFIG_FLASH_SIZE_4MB
#define GLOBAL_LVER " (2025-04-11 14:00 4M)"
#elif defined CONFIG_FLASH_SIZE_8MB
#define GLOBAL_LVER "06 (2024-09-20 17:00 8M)"
#endif
#endif

623
application/ws63/hsf/httpclient.h Executable file
View File

@ -0,0 +1,623 @@
/*! \file httpc.h
* \brief HTTP Client Module
*
* The HTTP Client module implements the functionality to perform HTTP
* operations like GET and POST on a remote web server. The HTTP client handles
* chunked encoding making it transparent to the user. It also supports
* persistent connections with the web server. Multiple HTTP requests can thus
* be channelled through the same persistent connection with the server.
*
* \section httpc_usage Usage
*
* The typical HTTP Client usage scenario is as follows:
*
* -# Initiate a connection with the remote Web Server using the
* http_open_session() call.
* -# Prepare the request with a call to http_prepare_req. The mandatory
* fields are filled depending on the members set in httpc_req_t. If some
* default fields are to be set, this is set by enabling the
* corresponding flag bits passed to http_prepare_req. If more custom
* headers are to be added please add them using the call add_header.
* -# Send one or more HTTP requests to the server using the
* http_prepare_req and http_send_request pair together. . The \ref
* httpc_req_t structure should be populated with the desired fields for
* each call if changed
* -# An optional call to http_get_response_hdr() can be made if the application
* wishes to determine certain characteristics of the HTTP response.
* -# Mutiple calls to http_read_content() are made for reading the response of
* the remote Web Server.
* -# Once all the HTTP requests have been made, the connection with the remote
* server is terminated using the http_close_session() call.
*
*/
/*
* Copyright 2008-2012, Marvell International Ltd.
* All Rights Reserved.
*/
#ifndef _HTTPC_H_
#define _HTTPC_H_
#include <time.h>
#include <stdint.h>
#include <stdbool.h>
// #define CONFIG_ENABLE_TLS
// #ifdef CONFIG_ENABLE_TLS
typedef void* tls_handle_t;
typedef void tls_init_config_t;
// #endif /* CONFIG_ENABLE_TLS */
#ifdef __cplusplus
extern "C"{
#endif
typedef int http_session_t;
/* Request methods */
typedef enum {
HTTP_OPTIONS, /* request to server for communication options */
HTTP_GET, /* retrieve information */
HTTP_HEAD, /* get meta-info */
HTTP_POST, /* request to accept new sub-ordinate of resource */
HTTP_PUT, /* modify or create new resource referred to by URI */
HTTP_DELETE, /* delete the resource */
HTTP_TRACE, /* echo */
HTTP_CONNECT, /* do we need this ? */
} http_method_t;
typedef enum {
HTTP_VER_1_0,
HTTP_VER_1_1,
} http_ver_t;
/*
* The OR of zero or more flags below is passed to the function
* \ref http_prepare_req. If the a flag is passed the corresponding HTTP
* header field is added to the HTTP header. The values added will be
* default ones.
*/
typedef enum {
HDR_ADD_DEFAULT_USER_AGENT = 0x0001,
/* Note: This flag is not necessary to set up persistent
* connections in HTTP 1.1. However, if you want the server to
* respond with persistent connection timeout values you may need
* to add this flag. These timeout values are used to find out how
* long a persistent connection will be kept alive by the
* server. */
HDR_ADD_CONN_KEEP_ALIVE = 0x0002,
HDR_ADD_CONN_CLOSE = 0x0004,
HDR_ADD_TYPE_CHUNKED = 0x0008,
} http_hdr_field_sel_t;
#define STANDARD_HDR_FLAGS \
(HDR_ADD_DEFAULT_USER_AGENT)
/*
* Note 1: A resource is a part of the string immediately after the
* hostname[:portno] part of the URL. In the URL,
* [http://]hostname[:portno][/path/to/resource],
* "/path/to/resource" part is called as a resource. It starts with the
* character '/'.
*/
/** The HTTP Client's Request structure
*
* \par
* The application should fill up this structure and pass it to the
* http_prepare_req() function while making an HTTP request. More name-value
* fields can be added to HTTP header using http_add_header().
*/
typedef struct {
/** The Type of HTTP Request */
http_method_t type;
/** The target resource for the HTTP Request. A complete URL is also
* accepted.
*/
const char *resource;
/** The HTTP Protocol Version */
http_ver_t version;
const char *content;
/** The length of the data pointed to by \a content above. This is
* don't-care if the content is set to NULL
*/
int content_len;
} httpc_req_t;
typedef struct {
const char *protocol;
http_ver_t version;
int status_code;
const char *reason_phrase; /* verbose string describing status code */
const char *server;
time_t modify_time; /* time when the resource was last modified */
const char *content_type;
const char *content_encoding;
bool keep_alive_ack;
int keep_alive_timeout; /* Server timeout */
int keep_alive_max; /* Max time for which a persistent
connection will be open, irrespective of
connection activity */
bool chunked;
uint32_t content_length; /* This will be 0 if chunked == TRUE */
} http_resp_t;
typedef struct {
char *name;
char *value;
} http_header_pair_t;
typedef struct {
const char *scheme;
const char *hostname;
unsigned portno;
const char *resource;
} parsed_url_t;
/** HTTPC Error Codes **/
enum wm_httpc_errno {
WM_E_HTTPC_ERRNO_START = MOD_ERROR_START(MOD_HTTPC),
/* TCP connection failed (maybe due to unreachable server) */
WM_E_HTTPC_TCP_CONNECT_FAIL,
/* HTTP File not found */
WM_E_HTTPC_FILE_NOT_FOUND,
/* HTTP Bad Request */
WM_E_HTTPC_BAD_REQUEST,
/* TLS not enabled */
WM_E_HTTPC_TLS_NOT_ENABLED,
};
/* Status codes */
#define HTTP_RESP_INFORMATIONAL(x) (x >=100 && < 200)
#define HTTP_RESP_SUCCESS(x) (x >= 200 && x < 300)
#define HTTP_RESP_REDIR(x) (x >= 300 && x < 400)
#define HTTP_RESP_CLIENT_ERR(x) (x >= 400 && x < 500)
#define HTTP_RESP_SERVER_ERR(x) (x >= 500 && x < 600)
/*
* These macros are not of any use to the HTTP client itself. They are used
* by the users of the HTTP client. This list may be extended if required
*/
#define HTTP_OK 200
#define HTTP_CREATED 201
#define HTTP_ACCEPTED 202
#define HTTP_FOUND 302
#define HTTP_NOT_MODIFIED 304
#define HTTP_BAD_REQUEST 400
#define HTTP_NOT_AUTH 401
#define HTTP_FORBIDDEN 403
#define HTTP_NOT_FOUND 404
/**
* If the given URL has a scheme field, and it is https then the http
* client will auto-switch to SSL mode, irrespective of the TLS_ENABLE
* flag below.
*/
typedef enum {
/** Pass this flag when you want the connection to be SSL based */
TLS_ENABLE = 0x01,
} http_open_flags_t;
/**
* Start an HTTP session.
*
* @par
* This function starts a new HTTP session. It will create a socket and
* then connect to the server.
*
* @param[in,out] handle Pointer to a handle for the session. Will be
* assigned by the callee.
* @param[in] hostname Host name or IP address. The hostname should be in
* the format [http://]hostname[:portno][/path/to/resource]. The fields
* between the square brackets above are optional. The part specifying
* the resource will be ignored. The resource detail is expected by the \a
* http_send_request API to be called later after calling current function.
* @param[in] flags This is OR of the flags mentioned in enum
* \ref http_open_flags_t. Please look at the declaration of the enum for
* more information.
* @param[in] cfg This is a pointer of the type
* \ref tls_init_config_t. This will be passed verbatim to the tls
* layer. Please look at the wm-tls.h for the structure members. \b If TLS
* (secure connection) is not needed please pass NULL.
* @param[in] retry_cnt On some systems with constrained network resources,
* only a limited sockets can be active at any given time. If the socket
* creation fails, http_open_session will wait for some time and try to create
* the socket again for retry_cnt number of times. If 0 is passed then it will
* try default number of times depending on the platform. 0 is the recommended
* option.
*
* @return WM_SUCCESS on success
* @return -WM_E_INVAL if any of the arguments were invalid
* @return -WM_FAIL if the function was unable to initiate an HTTP session with
* the server.
*/
int http_open_session(http_session_t * handle, const char *hostname,
int flags, const tls_init_config_t *cfg,
int retry_cnt);
#define hfhttp_open_session http_open_session
/**
* Prepare the HTTP header.
*
* This function will prepare an HTTP request before sending out an HTTP
* request using the function \ref http_send_request. Calling this function is
* mandatory before calling \ref http_send_request.
*
* @pre \ref http_open_session
*
* @param[in] handle Handle returned from the call to \a http_open_session
* @param[in] req Allocated and initialized \ref httpc_req_t structure.
* @param[in] field_flags Bitwise OR of flags of enum \ref
* http_hdr_field_sel_t as required by the caller.
*
* @note The field_flags parameter is a way to request the http client to
* use default field values for standard fields. If the corresponding bits
* are not set then the respective fields are not added. The user can add
* any custom fields including the standard ones using the API
* \ref http_add_header
*
* @return Standard wmsdk return codes.
*/
int http_prepare_req(http_session_t handle, const httpc_req_t *req,
http_hdr_field_sel_t field_flags);
#define hfhttp_prepare_req http_prepare_req
/**
* Add custom http headers to the partial generated header.
*
* This function allows the caller to add custom headers to the partial
* http header generated by earlier call to \ref http_prepare_req.
*
* @note This function is optional and needs to be called only if custom
* headers (or standard headers with non-default values) are to be added.
*
* @pre \ref http_prepare_req
*
* @param[in] handle Handle returned from the call to \a http_open_session
* @param[in] name The name of the field. e.g User-Agent or
* If-Modified-Since
* @param[in] value Value associated with the name given above.
*
* @return Standard wmsdk value.
*/
int http_add_header(http_session_t handle, const char *name,
const char *value);
#define hfhttp_add_header http_add_header
/**
* Perform an HTTP request.
*
* @par
* This function will peform an HTTP request.
*
* @note If this function fails and the caller decides to abandon this
* session altogether it needs to call http_close_session()
* explicitly. Failure to do this will cause undefined behaviour.
*
* @pre \a http_prepare_req mandatory. \a http_add_header optional.
*
* @param[in] handle Handle returned from the call to \a http_open_session
* @param[in] req The \httpc_req_t structure filled up with appropriate
* parameters as sent earlier to \ref http_prepare_req
*
* @return WM_SUCCESS on success
* @return -WM_E_IO if failed to send data to network
* @return -WM_E_INVAL for an invalid arguments.
*/
int http_send_request(http_session_t handle, const httpc_req_t * req);
#define hfhttp_send_request http_send_request
/**
* Get the HTTP response header
*
* @par
* This function parses the response header received from the server and
* populates the \a http_resp_t structure and returns the pointer to this
* structure. The structure \a http_resp_t is allocated by the callee.
*
* @par
* The caller is expected to analyse this information to find out the
* result of the earlier request sent through http_send_request(). If the
* earlier request was HTTP_GET then the caller will need to call
* http_read_content() to read the data sent by the server.
*
* @note Calling this function is \b optional. If the caller does not want to
* read/analyse the header and knows beforehand what to expect, s/he can
* directly call http_read_content(). The function \a http_read_content
* will internally read the HTTP response header. However, the function
* \a http_read_content will return an error if the HTTP status code
* returned is not 200. If you need to read content in cases where the
* return status code is other than 200 you need to call \ref
* http_get_response_hdr first.
*
* @note If this function fails and the caller decides to abandon this
* session altogether it needs to call http_close_session()
* explicitly. Failure to do this will cause undefined behaviour.
*
* @pre \a http_send_request is called before this call.
*
* @param[in] handle Handle returned from the call to \a http_new_session
* @param[in,out] resp Pointer to a pointer of type \a http_resp_t. The
* structure will be allocted by the callee.
*
* @return WM_SUCCESS on success
* @return -WM_FAIL on error
*/
int http_get_response_hdr(http_session_t handle, http_resp_t ** resp);
#define hfhttp_get_response_hdr http_get_response_hdr
/**
* Get a particular HTTP response header value.
*
* @par
* This function parses the response header received from the server and
* returns the value corresponding to a given name.
*
* @par
* The caller is not expected to call \ref http_get_response_hdr before
* this. However, calling \ref http_get_response_hdr is recommended so that
* the user gets to know the exact status of the HTTP operation before he
* tries to extract any field not present in structure \ref http_resp_t.
*
* @note Calling this function is \b optional. If the caller does not want to
* read/analyse the header and knows beforehand what to expect, s/he can
* directly call http_read_content(). The function \a http_read_content
* will internally read the HTTP response header. However, the function
* \a http_read_content will return an error if the HTTP status code
* returned is not 200. If you need to read content in cases where the
* return status code is other than 200 you need to call \ref
* http_get_response_hdr or the current function first.
*
* @note If this function fails and the caller decides to abandon this
* session altogether it needs to call http_close_session()
* explicitly. Failure to do this will cause undefined behaviour.
*
* @pre \a http_send_request is called before this call. Calling \ref
* http_get_response_hdr is \b not mandatory but recommended.
*
* @param[in] handle Handle returned from the call to \a http_new_session
* @param[in] header_name The name of the field whose value you wish to
* know
* @param[in,out] value A pointer which will point to the value
* corresponding to the name passed as second parameter.
*
* @return WM_SUCCESS on success
* @return -WM_FAIL on error
*/
int http_get_response_hdr_value(http_session_t handle,
const char *header_name, char **value);
#define hfhttp_get_response_hdr_value http_get_response_hdr_value
/**
* Get requested number of HTTP response header name-value pairs.
*
* @par
* This function parses the response header received from the server and
* returns requested number of HTTP response header name-value pairs.
*
* @par
* The caller is not expected to call \ref http_get_response_hdr before
* this. However, calling \ref http_get_response_hdr is recommended so that
* the user gets to know the exact status of the HTTP operation before he
* tries to extract any field not present in structure \ref http_resp_t.
*
* @note Calling this function is \b optional. If the caller does not want to
* read/analyse the header and knows beforehand what to expect, s/he can
* directly call http_read_content(). The function \a http_read_content
* will internally read the HTTP response header. However, the function
* \a http_read_content will return an error if the HTTP status code
* returned is not 200. If you need to read content in cases where the
* return status code is other than 200 you need to call \ref
* http_get_response_hdr or the current function first.
*
* @note If this function fails and the caller decides to abandon this
* session altogether it needs to call http_close_session()
* explicitly. Failure to do this will cause undefined behaviour.
*
* @pre \a http_send_request is called before this call. Calling \ref
* http_get_response_hdr is \b not mandatory but recommended.
*
* @param[in] handle Handle returned from the call to \a http_new_session
* @param[in,out] arr A pointer that points to an array of the
* structure to hold the response header name-value pairs.
* This array needs to be pre-allocated and its pointer is to be passed,
* this pointer shall point to the array of requested number of
* response header name-value pairs.
* @param[in,out] count An interger pointer that points to the number of
* response header name-value pairs that the user wants.
* This has to be passed by the user and it is later updated to the
* actual number of response header name-value pairs that were filled
* in the array mentioned above.
* @return WM_SUCCESS on success
* @return -WM_FAIL on error
*/
int http_get_response_hdr_all(http_session_t handle, http_header_pair_t *arr,
int *count);
#define hfhttp_get_response_hdr_all http_get_response_hdr_all
/**
* Read data content from the stream.
*
*@par
* This function will read the data sent by the server.
*
* @par
* The data transfer from the server to the client may be chunked. This
* fact will be reported in the response structure \ref http_resp_t returned
* in a previous call to http_get_response_hdr(). Notwithstanding this
* information, chunked data handling is transparent to the
* caller. Irrespective of the transfer type, this function should be called
* repeatedly till the return value of the function is zero.
*
* @note If this function fails and the caller decides to abandon this
* session altogether it needs to call http_close_session()
* explicitly. Failure to do this will cause undefined behaviour.
*
* @param[in] handle Handle returned from the call to http_new_session()
* @param[in, out] buf Caller allocated buffer of size max_len
* @param[in] Size of the buffer. The data read will be less than or equal
* to this size, depending on the size of the resource.
*
* @return On success, the number of bytes read is returned. Return value
* of zero is \a not an error case and should be treated as a signal that
* server is done with sending the data.
* @return -WM_FAIL if this function is called again after the previous call
* retuned 0 or for any other error.
*/
int http_read_content(http_session_t handle, void *buf, uint32_t max_len);
#define hfhttp_read_content http_read_content
/**
* Parse the given string into URL subcomponents.
*
* The hostname string syntax is:
*[scheme://]hostname[:port][/path_to_resource?query_string#fragment_id]
* The fields between the square brackets above are optional.
*
* @note <b>Buffer management</b>: To free the caller of the task of
* allocating multiple buffers of magic size to store each of the
* subcomponents we use the following strategy. This function takes a tmp
* buffer, allocted (static or dynamic) by the caller to store the
* subcomponents. The caller needs to allocate this buffer with size equal
* to (strlen(URL) + 10). When this function returns, the pointers in the
* parsed_url structure will point to appropriate address in this
* buffer. The caller may free this buffer after usage of the
* sub-components is complete. Freeing before that will cause undefined behavior.
*
* @param[in] URL Pointer to the string containing the URL. This function
* will not modify this argument.
* @param[in] tmp_buf A buffer where the strings will be stored after
* parsing. Needs to be allocated by the caller and should be of size
* atleast 10 greater than size of the URL string passed as first
* argument.
* @param[in] tmp_buf_len Size of the caller allocated, temporary buffer
* sent as second argument.
* @param[in, out] Pointer to an allocated structure. The member pointers
* will point to the appropriate address in the temporary buffer holding
* the NULL terminated string corresponding to the subcomponent.
*
*/
int http_parse_URL(const char *URL, char *tmp_buf, int tmp_buf_len,
parsed_url_t * parsed_url);
#define hfhttp_parse_URL http_parse_URL
/**
* HTTP lowlevel read
*
* This API is present to serve clients which want to handle the
* HTTP stream directly. This is useful for handling websockets for e.g.
*
* @warning This is not for general users of HTTP client API. Normal HTTP
* transactions do not need this API.
*
* @note Once this API used no other API from the HTTP API set, except \a
* http_close_session, can be used. This is because once this API is used
* the HTTP client loses track of the stream and only the caller using the
* API can know the state of the stream.
*
* @param[in] handle Handle returned from the call to http_new_session()
* @param[in, out] buf Pointer to an allocated buffer of size equal to or
* more than the value of the third parameter maxlen
* @param[in] maxlen The maximum number of bytes to be read from the
* network. Note that the actual read bytes can be less than this.
*
* @return Number of bytes read. -WM_E_INVAL is returned in case of invalid
* parameters. Standard libc error codes are returned in case when there
* other problems.
*/
int http_lowlevel_read(http_session_t handle, void *buf, unsigned maxlen);
/**
* HTTP lowlevel write
*
* This API is present to serve clients which want to handle the
* HTTP stream directly. This is useful for handling websockets for e.g.
*
* @warning This is not for general users of HTTP client API. Normal HTTP
* transactions do not need this API.
*
* @note Once this API used no other API from the HTTP API set, except \a
* http_close_session, can be used. This is because once this API is used
* the HTTP client loses track of the stream and only the caller using the
* API can know the state of the stream.
*
* @param[in] handle Handle returned from the call to http_new_session()
* @param[in, out] buf Pointer to a buffer which has the data to be written
* out.
* @param[in] maxlen The number of bytes to be written to the
* network.
*
* @return Number of bytes written. -WM_E_INVAL is returned in case of
* invalid parameters. Standard libc error codes are returned in case when
* there other problems.
*/
int http_lowlevel_write(http_session_t handle, const void *buf, unsigned len);
/**
* HTTP write chunked
*
* This API is used for chunked transfer encoding
*
* @note To end the chunked data transfer, this function should be called with
* len=0, buf may be NULL
*
* @param[in] handle Handle retrieved from the call to http_open_session
* @param[in] data Pointer to the buffer to be posted
* @param[in] len The number of bytes to be posted
* @return WM_SUCCESS is returned on success. -WM_E_INVAL is returned in case
* of invalid parameters. -WM_FAIL is returned if session is invalid.
* Standard libc error codes are returned when there are other problems.
*/
int httpc_write_chunked(http_session_t handle, const char *data, int len);
/**
* Close the session.
*
* @par
* This function will close the session represented by the given
* handle. The socket associated with this session will be closed and thus
* the TCP connection with the server will be terminated. No requests on
* this same session will succeed after this function is called.
*
* @note <b>The response structure \ref http_resp_t returned earlier from
* http_get_response_hdr() will be invalid after this call.</b>
*
* @param[in] handle Handle returned from the previous call to
* http_new_session(). The handle will be set to NULL by the callee thus
* effectively blocking futher requests on the same session handle.
*
*/
void http_close_session(http_session_t * handle);
#define hfhttp_close_session http_close_session
int http_check_data_ready(http_session_t handle,uint32_t timeous);
int hfhttp_sock_check(http_session_t handle,uint32_t timeous);
void hfhttp_set_init_state(http_session_t handle);
#define hfhttp_check_data_ready http_check_data_ready
int http_read_content_timeout(http_session_t handle, void *buf, uint32_t max_len,uint32_t timeouts);
#define hfhttp_read_content_timeout http_read_content_timeout
int http_read_content_length(http_session_t handle);
#define hfhttp_read_content_length http_read_content_length
#ifdef __cplusplus
}
#endif
#endif /* _HTTPC_H_ */

143
application/ws63/hsf/ringbuf.h Executable file
View File

@ -0,0 +1,143 @@
/** \addtogroup lib
* @{ */
/**
* \defgroup ringbuf Ring buffer library
* @{
*
* The ring buffer library implements ring (circular) buffer where
* bytes can be read and written independently. A ring buffer is
* particularly useful in device drivers where data can come in
* through interrupts.
*
*/
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Header file for the ring buffer library
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __RINGBUF_H__
#define __RINGBUF_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Structure that holds the state of a ring buffer.
*
* This structure holds the state of a ring buffer. The
* actual buffer needs to be defined separately. This
* struct is an opaque structure with no user-visible
* elements.
*
*/
struct ringbuf {
uint8_t *data;
uint16_t mask;
/* XXX these must be 8-bit quantities to avoid race conditions. */
uint16_t put_ptr, get_ptr;
};
/**
* \brief Initialize a ring buffer
* \param r A pointer to a struct ringbuf to hold the state of the ring buffer
* \param a A pointer to an array to hold the data in the buffer
* \param size_power_of_two The size of the ring buffer, which must be a power of two
*
* This function initiates a ring buffer. The data in the
* buffer is stored in an external array, to which a
* pointer must be supplied. The size of the ring buffer
* must be a power of two and cannot be larger than 128
* bytes.
*
*/
void ringbuf_init(struct ringbuf *r, uint8_t *a,
uint16_t size_power_of_two);
/**
* \brief Insert a byte into the ring buffer
* \param r A pointer to a struct ringbuf to hold the state of the ring buffer
* \param c The byte to be written to the buffer
* \return Non-zero if there data could be written, or zero if the buffer was full.
*
* This function inserts a byte into the ring buffer. It
* is safe to call this function from an interrupt
* handler.
*
*/
int ringbuf_put(struct ringbuf *r, uint8_t c);
/**
* \brief Get a byte from the ring buffer
* \param r A pointer to a struct ringbuf to hold the state of the ring buffer
* \return The data from the buffer, or -1 if the buffer was empty
*
* This function removes a byte from the ring buffer. It
* is safe to call this function from an interrupt
* handler.
*
*/
int ringbuf_get(struct ringbuf *r);
/**
* \brief Get the size of a ring buffer
* \param r A pointer to a struct ringbuf to hold the state of the ring buffer
* \return The size of the buffer.
*/
int ringbuf_size(struct ringbuf *r);
/**
* \brief Get the number of elements currently in the ring buffer
* \param r A pointer to a struct ringbuf to hold the state of the ring buffer
* \return The number of elements in the buffer.
*/
int ringbuf_elements(struct ringbuf *r);
int
ringbuf_gets(struct ringbuf *r,uint8_t *data,int size);
#ifdef __cplusplus
}
#endif
#endif /* __RINGBUF_H__ */

32
application/ws63/hsf/xmodem.h Executable file
View File

@ -0,0 +1,32 @@
/* xmodem.h
*
* Copyright (C) 2017 ShangHai High-flying Electronics Technology Co.,Ltd.
*
* This file is part of HSF.
*
*/
#ifndef _XMODEM_H_
#define _XMODEM_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*xmodem_send_callback_t)(unsigned char *data, int len);
typedef int (*xmodem_recv_callback_t)(unsigned char *data, int len, int timeout);
typedef int (*xmodem_setfile_callback_t)(unsigned char *data, int len, unsigned int offset);
int xmodem_receive_process(int wait, xmodem_send_callback_t send, xmodem_recv_callback_t recv, xmodem_setfile_callback_t write);
#ifdef __cplusplus
}
#endif
#endif/* _XMODEM_H_ */