577 lines
17 KiB
C
577 lines
17 KiB
C
/**
|
|
@file
|
|
quec_wifi_app.h
|
|
|
|
@brief
|
|
Quectel wifi app api header.
|
|
|
|
*/
|
|
/*============================================================================
|
|
Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
|
|
Quectel Wireless Solution Proprietary and Confidential.
|
|
=============================================================================*/
|
|
/*===========================================================================
|
|
|
|
EDIT HISTORY FOR MODULE
|
|
|
|
This section contains comments describing changes made to the module.
|
|
Notice that changes are listed in reverse chronological order.
|
|
|
|
|
|
WHEN WHO WHAT, WHERE, WHY
|
|
---------- ------------ ----------------------------------------------------
|
|
|
|
=============================================================================*/
|
|
#ifndef QUEC_WIFI_APP_H
|
|
#define QUEC_WIFI_APP_H
|
|
|
|
#include "quec_api_wifi.h"
|
|
#include "quec_wifi_spi.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
/*========================================================================
|
|
* Macro Definition
|
|
*========================================================================*/
|
|
#define QUEC_WIFI_SSID_MAX_LEN 32
|
|
#define QUEC_WIFI_BSSID_MAX_LEN 6
|
|
#define QUEC_WIFI_PASSWORD_MIN_LEN 8
|
|
#define QUEC_WIFI_PASSWORD_MAX_LEN 64
|
|
#define QUEC_WIFI_IPV4_MAX_LEN 16
|
|
#define QUEC_WIFI_VERSION_MAX 128
|
|
|
|
#define QUEC_MAC_STR_LEN_MAX 17
|
|
#define QUEC_MAC_STR_LEN_MIN 11
|
|
#define QUEC_WIFI_BLACK_MAX_NUM 8
|
|
#define QUEC_WIFI_MAC_STR_MAX 18
|
|
|
|
#define QUEC_SSL_CTX_ID_MIN 0
|
|
#define QUEC_SSL_CTX_ID_MAX 5
|
|
#define PROFILE_IDX_MIN 1
|
|
#define PROFILE_IDX_MAX 8
|
|
|
|
#define QUEC_WIFI_OTA_HEAD_LEN 12
|
|
#define QUEC_WIFI_OTA_DATA_LEN (2048)
|
|
/*========================================================================
|
|
* Enumeration Definition
|
|
*========================================================================*/
|
|
typedef enum
|
|
{
|
|
// quec_wifi_app_errcode_e extends from quec_wifi_errcode_e in file ql_api_wifi.h
|
|
QUEC_WIFI_APP_SUCCESS = 0,
|
|
QUEC_WIFI_APP_EXECUTE_ERR = 1,
|
|
QUEC_WIFI_APP_INVALID_PARAM_ERR,
|
|
QUEC_WIFI_APP_INVALID_PARAM_LEN_ERR,
|
|
QUEC_WIFI_APP_NO_MEM_ERR,
|
|
QUEC_WIFI_APP_MEM_ADDR_NULL_ERR = 5,
|
|
QUEC_WIFI_APP_INVALID_IP_ERR,
|
|
QUEC_WIFI_APP_INVALID_GW_ERR,
|
|
QUEC_WIFI_APP_INVALID_NETMASK_ERR,
|
|
QUEC_WIFI_APP_INVALID_DNS_ERR,
|
|
QUEC_WIFI_APP_INVALID_DHCP_ERR = 10,
|
|
QUEC_WIFI_APP_INVALID_MAC_ERR,
|
|
QUEC_WIFI_APP_INVALID_CID_ERR,
|
|
QUEC_WIFI_APP_STATE_ERR,
|
|
// quec_wifi_app.h add
|
|
QUEC_WIFI_APP_INIT_UART_ERR,
|
|
QUEC_WIFI_APP_INIT_SPI_ERR = 15,
|
|
QUEC_WIFI_APP_INIT_NET_ERR,
|
|
QUEC_WIFI_APP_INIT_MSG_ERR,
|
|
QUEC_WIFI_APP_INIT_TASK_ERR,
|
|
QUEC_WIFI_APP_INVALID_AP_USER_INFO_ERR,
|
|
QUEC_WIFI_APP_CB_NULL_ERR = 20,
|
|
QUEC_WIFI_APP_SCAN_WORKING_ERR,
|
|
QUEC_WIFI_APP_REPEAT_INIT_ERR,
|
|
QUEC_WIFI_APP_MUTEX_CREATE_ERR,
|
|
} quec_wifi_app_errcode_e;
|
|
|
|
typedef enum
|
|
{
|
|
QUEC_WIFI_APP_OPT_SSID = 0, // val_len: ssid len,STA/AP ssid
|
|
QUEC_WIFI_APP_OPT_PASSWORD, // val_len: password len,STA/AP password
|
|
} quec_wifi_app_opt_e;
|
|
|
|
typedef enum
|
|
{
|
|
QUEC_WIFI_AUTH_TYPE_NONE_SHARE,
|
|
QUEC_WIFI_AUTH_TYPE_NONE,
|
|
QUEC_WIFI_AUTH_TYPE_SHARE,
|
|
QUEC_WIFI_AUTH_TYPE_WPA,
|
|
QUEC_WIFI_AUTH_TYPE_WPA2,
|
|
QUEC_WIFI_AUTH_TYPE_WPA_WPA2,
|
|
QUEC_WIFI_AUTH_TYPE_MAX
|
|
} quec_wifi_auth_e;
|
|
|
|
typedef enum
|
|
{
|
|
QUEC_WIFI_ENCRYPT_TYPE_NONE,
|
|
QUEC_WIFI_ENCRYPT_TYPE_WEP,
|
|
QUEC_WIFI_ENCRYPT_TYPE_TKIP,
|
|
QUEC_WIFI_ENCRYPT_TYPE_AES,
|
|
QUEC_WIFI_AUTH_TYPE_TKIP_ASE,
|
|
QUEC_WIFI_encrypt_TYPE_MAX
|
|
} quec_wifi_encrypt_e;
|
|
|
|
typedef enum{
|
|
QUEC_WIFI_PORT_SPI_UART,
|
|
QUEC_WIFI_PORT_SPI,
|
|
QUEC_WIFI_PORT_CFG_MAX
|
|
}quec_wifi_port_cfg_e;
|
|
|
|
typedef enum{
|
|
QUEC_WIFI_OTA_WRITE_NORMAL,
|
|
QUEC_WIFI_OTA_WRITE_DONE,
|
|
QUEC_WIFI_OTA_WRITE_NOSPACE,
|
|
QUEC_WIFI_OTA_WRITE_ERROR,
|
|
QUEC_WIFI_OTA_REBOOT_DONE,
|
|
QUEC_WIFI_OTA_MAX
|
|
}quec_wifi_ota_status;/*same as ql_wifi_ota_status*/
|
|
/*========================================================================
|
|
* Type Definition
|
|
*=========================================================================*/
|
|
typedef void (*quec_wifi_app_status_cb)(void *ctx);
|
|
typedef void (*quec_wifi_app_scan_result_cb)(void *ctx);
|
|
typedef int (*quec_wifi_app_output_data_msg_cb)(void *ctx);
|
|
typedef void (*quec_ble_gatt_data_cb)(void *ctx);
|
|
typedef void (*quec_wifi_ota_data_cb)(void *ctx);
|
|
|
|
|
|
typedef struct
|
|
{
|
|
char ssid[QUEC_WIFI_SSID_MAX_LEN];
|
|
char password[QUEC_WIFI_PASSWORD_MAX_LEN];
|
|
} quec_wifi_app_user_ap_info_s;
|
|
|
|
#pragma pack(1)
|
|
typedef struct
|
|
{
|
|
char ssid[QUEC_WIFI_SSID_MAX_LEN];
|
|
char ap_power; // Signal strength, min:0, max:100
|
|
uint8_t bssid[QUEC_WIFI_BSSID_MAX_LEN]; // The BSSID of an access point
|
|
char channel; // The RF frequency, 1-13
|
|
char security[16]; // Security type, @ref wlan_sec_type_t
|
|
} quec_wifi_app_ap_info_s;
|
|
#pragma pack()
|
|
|
|
typedef struct
|
|
{
|
|
int32_t conn_state; /* 0: disconnected, 1: connected. */
|
|
int32_t wifi_strength; /* wifi signal strength of the current connected AP */
|
|
uint8_t ssid[QUEC_WIFI_SSID_MAX_LEN +1];
|
|
uint8_t bssid[QUEC_WIFI_BSSID_MAX_LEN];
|
|
uint16_t aid;
|
|
int32_t channel;
|
|
int32_t security;
|
|
} quec_wifi_link_info_s;
|
|
|
|
typedef struct
|
|
{
|
|
char dhcp;
|
|
char ip_str[16];
|
|
char netmask_str[16];
|
|
char gw_str[16];
|
|
char dhcp_str[16];
|
|
char ssid[QUEC_WIFI_SSID_MAX_LEN];
|
|
char password[QUEC_WIFI_PASSWORD_MAX_LEN];
|
|
} quec_wifi_ap_start_info;
|
|
|
|
typedef struct
|
|
{
|
|
char ApNum; // The number of access points found in scanning
|
|
quec_wifi_app_ap_info_s *ApList;
|
|
} quec_wifi_app_scan_result_s;
|
|
|
|
#pragma pack(1)
|
|
|
|
typedef struct
|
|
{
|
|
unsigned char mode;//0:close 1:mcu normal sleep, 2:rf
|
|
unsigned char enable;//0:disable 1:enable
|
|
unsigned char para;//mode 2:dtim
|
|
unsigned char reserve;
|
|
}quec_wifi_psm_info;
|
|
#pragma pack()
|
|
|
|
/*QUEC_BLE_APP_INIT_CMD 命令的参数*/
|
|
typedef struct
|
|
{ uint8_t role; //初始化BLE的角色。目前只支持参数0,表示 WIFI&BLE 模块为外围设备进行BLE初始化
|
|
}ql_ble_app_init_info;
|
|
|
|
/*
|
|
QUEC_BLE_APP_SET_SERICE_UUID_CMD & QUEC_BLE_APP_SET_CHARACT_UUID_CMD 命令的参数,
|
|
最多支持创建1个BLE 服务, 3个BLE 特征值
|
|
必须在使用QUEC_BLE_APP_INIT_CMD命令初始化BLE后使用QUEC_BLE_APP_SET_SERICE_UUID_CMD命令创建BLE服务
|
|
否则蓝牙广播、扫描及连接等功能无法正常运行
|
|
*/
|
|
typedef struct
|
|
{
|
|
uint8_t uuid_len; //蓝牙服务/特征值UUID长度为2字节或16字节
|
|
uint8_t uuid[16];
|
|
}ql_ble_app_service_info;
|
|
|
|
/*QUEC_BLE_APP_ADV_DATA_CMD & QUEC_BLE_APP_SCAN_RSP_DATA_CMD命令的参参数*/
|
|
typedef struct
|
|
{
|
|
uint8_t adv_data_len; //长度不能超过28字节
|
|
uint8_t adv_data[28];
|
|
}ql_ble_adv_data_info;
|
|
|
|
|
|
/*QUEC_BLE_APP_DATA_SEND_CMD 命令的参数*/
|
|
typedef struct
|
|
{
|
|
uint16_t uuid_len; //蓝牙特征值UUID长度为2字节或16字节
|
|
uint8_t uuid[16];
|
|
uint16_t data_len; //发送数据长度(长度不超过MTU-3,MTU默认值为23字节)
|
|
uint8_t data[20];
|
|
}ql_ble_send_data_info;
|
|
|
|
|
|
typedef struct
|
|
{
|
|
quec_wifi_mode_e mode;
|
|
uint8_t simid;
|
|
uint8_t cid;
|
|
quec_wifi_auth_e auth_type;
|
|
quec_wifi_encrypt_e encrypt_type;
|
|
char ssid[QUEC_WIFI_SSID_MAX_LEN];
|
|
char password[QUEC_WIFI_PASSWORD_MAX_LEN];
|
|
|
|
quec_wifi_port_cfg_e port_cfg;
|
|
quec_wifi_spi_cfg_t spi_config;
|
|
uint8_t uart_port;
|
|
}quec_wifi_config_t;/*must be the same as ql_wifi_config_t*/
|
|
|
|
typedef enum
|
|
{
|
|
WIFI_OTA_STATE_NONE,
|
|
WIFI_OTA_STATE_INIT,
|
|
WIFI_OTA_STATE_WRITE_WAIT,
|
|
WIFI_OTA_STATE_WRITE_READY,
|
|
WIFI_OTA_STATE_WRITE_ERROR,
|
|
WIFI_OTA_STATE_WRITE_DONE,
|
|
} quec_wifi_ota_s;
|
|
|
|
#pragma pack(4)
|
|
typedef struct{
|
|
uint32_t total_len;
|
|
uint32_t offset_len;
|
|
uint32_t data_len;
|
|
union {
|
|
uint8_t data;
|
|
uint8_t status;
|
|
}data;
|
|
}quec_wifi_ota_data_head;
|
|
#pragma pack()/*must be the same as ql_wifi_ota_data_head*/
|
|
|
|
typedef enum
|
|
{
|
|
QUEC_WIFI_IND_STATE_DISCONNECT,
|
|
QUEC_WIFI_IND_STATE_CONNECTED
|
|
} quec_wifi_ind_state_e;
|
|
|
|
typedef enum
|
|
{
|
|
QUEC_WIFI_IND_TYPE_DEVICE,
|
|
QUEC_WIFI_IND_TYPE_CLIENT
|
|
} quec_wifi_ind_e;
|
|
|
|
typedef struct
|
|
{
|
|
quec_wifi_ind_e ind_type;
|
|
quec_wifi_ind_state_e state;
|
|
char mac_str[QUEC_WIFI_MAC_STR_MAX];
|
|
} quec_wifi_ind_t;
|
|
|
|
typedef struct
|
|
{
|
|
unsigned int beacon_interval;//范围:15-1000(不含边界),单位ms,建议默认100ms
|
|
unsigned int channel;//范围: 1-13,默认11
|
|
}quec_wifi_ap_channel_config_t;
|
|
|
|
typedef void (*quec_wifi_ind_cb)(quec_wifi_ind_t *ctx);
|
|
/*========================================================================
|
|
* function Definition
|
|
*========================================================================*/
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_get_port_cfg
|
|
*
|
|
* Description: Get Wi-Fi communication interface configuration.
|
|
*
|
|
* Parameters:
|
|
*
|
|
* Return:quec_wifi_port_cfg_e
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_port_cfg_e quec_wifi_get_port_cfg(void);
|
|
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_get_user_ap_info
|
|
*
|
|
* Description: Get Wi-Fi user ap information.
|
|
*
|
|
* Parameters:
|
|
* info [out] Wi-Fi user ap information.See quec_wifi_app_user_ap_info_s.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_get_user_ap_info(quec_wifi_app_user_ap_info_s *info);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_set_user_ap_info
|
|
*
|
|
* Description: Set Wi-Fi user ap information.
|
|
* Parameters:
|
|
* info [in] Wi-Fi user ap information.See quec_wifi_app_user_ap_info_s.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_set_user_ap_info(quec_wifi_app_user_ap_info_s *info);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_scan
|
|
*
|
|
* Description: Register Wi-Fi scan callback which get the scan result and start Wi-Fi scan.
|
|
*
|
|
* Parameters:
|
|
* cb [in] Wi-Fi scan callback.Once we get the result of Wi-Fi scan,this callback will be called.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_scan(quec_wifi_app_scan_result_cb cb);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_sta_enable
|
|
*
|
|
* Description: Register Wi-Fi STA callback and enable the function of Wi-Fi STA(Station).
|
|
*
|
|
* Parameters:
|
|
* sta_status_cb [in] Wi-Fi STA callback.Once we get the status of Wi-Fi access procedure,this callback will be called.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_sta_enable(quec_wifi_ind_cb status_cb);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_sta_disable
|
|
*
|
|
* Description: Register Wi-Fi STA callback and enable the function of Wi-Fi STA(Station).
|
|
*
|
|
* Parameters:
|
|
* argv [in] No defined yet.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_sta_disable(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_reset
|
|
*
|
|
* Description: Software reset of Wi-Fi device.
|
|
*
|
|
* Parameters:
|
|
* argv [in] No defined yet.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_reset(uint8_t enable);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_init
|
|
*
|
|
* Description: Wi-Fi application initialization.All needed tasks and communication bus are initialized in this function.
|
|
*
|
|
* Parameters:
|
|
* argv [in] No defined yet.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_init(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_deinit
|
|
*
|
|
* Description: Wi-Fi application deinitialization.Release all Wi-Fi application resource.
|
|
*
|
|
* Parameters:
|
|
* argv [in] No defined yet.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_deinit(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_wifi_app_psm
|
|
*
|
|
* Description: Control Wi-Fi module to enter or exit PSM mode
|
|
*
|
|
* Parameters:
|
|
* argv [in] quec_wifi_psm_info struct pointer.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_wifi_app_psm(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_ble_init
|
|
*
|
|
* Description: Initialize BLE and create a BLE service.
|
|
*
|
|
* Parameters:
|
|
* argv [in] ql_ble_app_service_info struct pointer.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_ble_init(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_ble_set_characteristic
|
|
*
|
|
* Description: Set a BLE characteristic value
|
|
*
|
|
* Parameters:
|
|
* argv [in] ql_ble_app_service_info struct pointer.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_ble_set_characteristic(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_ble_register_gatt_data_cb
|
|
*
|
|
* Description: Register ble gatt data callback
|
|
*
|
|
* Parameters:
|
|
* cb [in] Once we get the gatt data,this callback will be called.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_ble_register_gatt_data_cb(quec_ble_gatt_data_cb cb);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_ble_set_adv_data
|
|
*
|
|
* Description: Set BLE Advertising data
|
|
*
|
|
* Parameters:
|
|
* argv [in] ql_ble_adv_data_info struct pointer.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_ble_set_adv_data(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_ble_adv_start
|
|
*
|
|
* Description: Start BLE Advertising
|
|
*
|
|
* Parameters:
|
|
* argv [in] No used yet.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_ble_adv_start(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_ble_adv_stop
|
|
*
|
|
* Description: Stop BLE Advertising
|
|
*
|
|
* Parameters:
|
|
* argv [in] No used yet.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_ble_adv_stop(void *argv);
|
|
|
|
/*****************************************************************
|
|
* Function: quec_ble_sent_gatt_data
|
|
*
|
|
* Description: Sent GATT data
|
|
*
|
|
* Parameters:
|
|
* argv [in] ql_ble_send_data_info struct pointer.
|
|
*
|
|
* Return:
|
|
* 0 success
|
|
* other error code
|
|
*
|
|
*****************************************************************/
|
|
quec_wifi_app_errcode_e quec_ble_sent_gatt_data(void *argv);
|
|
|
|
quec_wifi_app_errcode_e quec_wifi_app_ap_disable(void *argv);
|
|
|
|
quec_wifi_app_errcode_e quec_wifi_app_ap_enable(quec_wifi_ind_cb status_cb);
|
|
|
|
int quec_wifi_app_get_version(void *data_out);
|
|
|
|
int quec_wifi_app_set_black_mac(void *mac,uint8_t option);
|
|
|
|
int quec_wifi_app_config_change(void);
|
|
|
|
uint8_t quec_wifi_get_mode(void);
|
|
|
|
int quec_wifi_app_set_param(uint8_t wifi_mode, uint8_t sim_id, int profile_idx, char *ssid, char *pwd, uint8_t auth_type);
|
|
|
|
int quec_wifi_app_ota_data_cb_register(quec_wifi_ota_data_cb cb);
|
|
|
|
int quec_wifi_app_ota_data_send(quec_wifi_ota_data_head *ota_data);
|
|
|
|
quec_wifi_app_errcode_e quec_wifi_app_ap_set_channel(void *argv);
|
|
|
|
int quec_wifi_app_sta_link_info(quec_ble_gatt_data_cb cb);
|
|
|
|
#ifdef __cplusplus
|
|
} /*"C" */
|
|
#endif
|
|
|
|
#endif
|