PV1_MakeProject/3partys/boardlink/blsdk.h

213 lines
6.2 KiB
C
Raw Normal View History

2018-08-10 02:22:55 +00:00
#ifndef __SDK_H
#define __SDK_H
/*
* 0. implement all callback's of this SDK
* 1. read wifi probe frame from driver
* 2. feed wifi probe frame to sdk_pkt_process
* 3. this sdk depends on no thirdparty libraries, and there is no internet connection with net.
*/
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned int uint32;
typedef char int8;
typedef short int int16;
typedef int int32;
#define SDK_SUCCESS (0)
#define SDK_FAIL (1)
#define SDK_NULL (0)
#define OUI_LEN (3)
#define OUI_TYPE (0)
#define OUI_TYPE_LEN (1)
#define MAC_LEN (6)
#define SSID_MAX_LEN (32)
#define PASSWORD_MAX_LEN (32)
#define SDK_SHAREDKEY_LEN (32)
#define SDK_FRAME_MAX_LEN (1460)
#define FASTCON_MASTER_ID_LEN (4)
#define SDK_PACKED __attribute__((packed))
typedef void* (*sdk_memset_t) (
void* ptr,
int32 value,
uint32 num);
typedef void* (*sdk_memcpy_t) (
void* dst,
const void* src,
uint32 num);
typedef int32 (*sdk_memcmp_t) (
const void* ptr1,
const void* ptr2,
uint32 num);
typedef int32 (*sdk_printf_t) (
const char* format,
...);
typedef struct sdk_device_info_t {
uint32 vendor_id;
uint32 product_id;
uint8 mac[MAC_LEN];
uint8 * device_info;
uint16 device_info_len;
uint8 * device_id;
uint16 device_id_len;
}sdk_product_info_t;
//发现设备
typedef int32 (*sdk_found_device_t) (sdk_product_info_t *product_info);
//对应2.1 云端身份校验接口请求
typedef int32 (*sdk_challenge_post_t)(
sdk_product_info_t *product_info,
uint8 * challenge,
uint16 challenge_len);
//对应2.2 设备身份声明接口请求
typedef int32 (*sdk_signature_post_t)(
sdk_product_info_t *product_info,
uint8 * signature,
uint16 signature_len);
//sdk将设备控制token传给上层
typedef int32 (*sdk_device_token_post_t)(
sdk_product_info_t *product_info,
uint8 * token,
uint16 token_len);
//上报配置结果
//目前只支持失败结果上报。
//成功的结果是由云端推送上线通知
//result 0:成功 -1:失败
typedef int32 (*sdk_config_result_post_t) (
sdk_product_info_t *product_info,
int8 result);
//发送802.11原始报文接口
typedef int32 (*sdk_raw_pkt_send_t)(
uint8 * frame,
uint16 frame_len);
typedef struct {
sdk_memset_t memset;
sdk_memcpy_t memcpy;
sdk_memcmp_t memcmp;
sdk_printf_t printf;
sdk_found_device_t found_device;
sdk_challenge_post_t challenge_post;
sdk_signature_post_t signature_post;
sdk_device_token_post_t device_token_post;
sdk_config_result_post_t config_result_post;
sdk_raw_pkt_send_t send_raw_pkt;
} sdk_config_t;
typedef struct {
//gateway信息
//包括当前路由器信道gateway macbssid
uint8 channel; //cur channel
//若mac地址为00-11-22-33-44-55则device_mac[] = {0x00,0x11,0x22,0x33,0x44,0x55};
uint8 device_mac[MAC_LEN];
//AP的mac地址格式等同device_mac
uint8 bssid[MAC_LEN];
//由dnakit后台分配用于区分不同平台固定4个字节
uint8 fastcon_master_id[FASTCON_MASTER_ID_LEN];
//0:probe req,1:probe rsp,2:action
//报文选择根据gateway 能力自行设置
uint8 send_wlan_type;
//回调接口注册
sdk_config_t sdk_config;
} SDK_PACKED sdk_user_init_t;
typedef enum {
SDK_STATE_PROBE_DEVICE,
SDK_STATE_LOCK_CHANNEL,
SDK_STATE_CONFIG,
SDK_STATE_CONNECTING,
SDK_STATE_DONE, //Finish
SDK_STATE_FAIL,
} sdk_state_e;
/**
* @brief sdk编译时间
* @return 0
* SDK_E_INIT_FAIL sdk未初始化
*/
extern int32 sdk_version(void);
/**
* @brief sdk
* @param init
* @return 0
* SDK_E_INIT_FAIL
*/
extern int32 sdk_init(sdk_user_init_t *init);
/**
* @brief 802.11
* @param frame 802.11
* @param frame_len
* @return sdk_state_e
SDK_E_INIT_FAIL
*/
extern int32 sdk_pkt_process(uint8 *frame, int16 frame_len);
/**
* @brief token bind成功报文
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
*/
extern int32 sdk_device_token_bind_success(void);
/**
* @brief ssid和password信息发送
* @param sharedkey
* @param ssid
* @param ssid_len
* @param password
* @param password_len
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
* @example ssid为"ssid"password为"password"
*
* @code
* uint8 ssid[] = "ssid";
* uint8 password[] = "password";
* sdk_wlan_params_set(sharedkey,ssid,strlen(ssid),password,strlen(password));
* @endcode
*/
extern int32 sdk_wlan_params_set(uint8 sharedkey[SDK_SHAREDKEY_LEN],uint8 *ssid,uint16 ssid_len,uint8 *password,uint16 password_len);
/**
* @brief challenge和signature信息发送
* @param challenge
* @param challenge_len
* @param signature
* @param signature_len
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
*/
extern int32 sdk_challenge_and_signature_set(uint8 *challenge,uint16 challenge_len, uint8 *signature, uint16 signature_len);
/**
* @brief
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
*/
extern int32 sdk_user_auth_to_start_config(void);
/**
* @brief sdk状态
* @return 0
* SDK_E_INIT_FAIL
*/
extern int32 sdk_deinit(void);
#endif