From f737a816ab8ae5c52426d812b86023560a12897a Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 10 Aug 2018 10:22:55 +0800 Subject: [PATCH] Add boardlink iot sdk support --- 3partys/boardlink/blsdk.h | 212 ++++++++++++++++++++++++ 3partys/boardlink/blsdk_errno.h | 19 +++ 3partys/boardlink/libfastcon.a | Bin 0 -> 24018 bytes Example/main.c | 117 ++++++++++--- Framework/IoT/Boardlink/boardlink_iot.c | 54 +++++- Modules/Alarm/assistant.c | 5 + Modules/OTA/ota.c | 7 +- build/Makefile.def.cross | 2 +- build/Makefile.lib.cross | 4 +- include/boardlink_iot.h | 23 ++- 10 files changed, 406 insertions(+), 37 deletions(-) create mode 100644 3partys/boardlink/blsdk.h create mode 100644 3partys/boardlink/blsdk_errno.h create mode 100644 3partys/boardlink/libfastcon.a diff --git a/3partys/boardlink/blsdk.h b/3partys/boardlink/blsdk.h new file mode 100644 index 0000000..7581557 --- /dev/null +++ b/3partys/boardlink/blsdk.h @@ -0,0 +1,212 @@ +#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 mac,bssid + 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 diff --git a/3partys/boardlink/blsdk_errno.h b/3partys/boardlink/blsdk_errno.h new file mode 100644 index 0000000..369b797 --- /dev/null +++ b/3partys/boardlink/blsdk_errno.h @@ -0,0 +1,19 @@ + +#ifndef __SDK_ERRNO_H +#define __SDK_ERRNO_H + + +#define SDK_E_INIT_FAIL (-1) //SDK初始化失败 +#define SDK_E_INVPARAMS (-2) //参数异常 +#define SDK_E_STATE (-3) //sdk状态异常 + +//only use by sdk_config_result_post_t +#define SDK_E_CONNECT_AP_TIMEOUT (-101) //连接ap超时 +#define SDK_E_PKT_SEND (-102) //发送数据包失败 +#define SDK_E_OVER_RETRY_COUNT (-103) //超过最大重试次数 +#define SDK_E_VERIFY_SIGNATURE (-104) //校验网关端身份失败 +#define SDK_E_SSID_PWD (-105) //ssid和pwd解析异常 +#define SDK_E_MSG_NOT_SUPPORT (-106) //接收到不支持的消息类型 +#define SDK_E_CONFIG_TIMEOUT (-107) //配置超时,超过10分钟配置时间 + +#endif diff --git a/3partys/boardlink/libfastcon.a b/3partys/boardlink/libfastcon.a new file mode 100644 index 0000000000000000000000000000000000000000..a479fd75459a238f8006e325ff64e9c05b407483 GIT binary patch literal 24018 zcmeHve{@vGm1e!}mehzgegfH+vFv#g0(Wd#X<^w`yjo9#0F#MgHz3E@R;(71Y>~*& zNW#Gho3xMsfh7<|wn+?8J7M;)yX=hYB{^&knKZT>duA1nVq=FSBvak3l4Ot1K(hS7 zPB_DU-+T2$!`PF|o;f?S=j?;4uYTP6UH8_ldiA=brm3U3?Y{g^TUS1zEU)9v{%cwH zEMBZRqWMAyO9=1v|1xyjZ9;q;RU!P7sdas0=jK>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tb# z0~Ld4&+uLNgr>KEqaXw4aQybwzWZgthQyh~cJudrt`&1}zw7hq5atul z4erM|AJ6jmj!48YUI~m*6n3N?jyqk*&ls#tUxRR*Osf1O_s&DgkKe%w;P+9k6-TFY zXxHE!fX_o%;y!$_FF*I(-*o@c zyvMT7MO}Xd{SXk!E8}@*HAsD+{dd#P`f5M#rv`DS#r5AuKkKjKm(tHWyV}2ke%4?6 z|Ac-vO8Xz6ztr~H<-q^y*e|?a^i&oD?W2saZDrE4)UMUcv>UZ6^2WVP^7m19Pnn$E6S!_j>e?MQH^hD9Md?i@s!5X z8qa8y8YeVPYy3##IgRHvUeI_^Bd(>`_3>%+Yb*!yuGTVQ8P;OVzv2as?qK~d!cP>K zn?#>Rzs7(@Q)8h<>K5`_8p||NW*J_tF{H6dW3|Q_jbV+;G_KTGr}5wPHyvnaLf7-K z#v>Y!Y8=scOyhBlCp0ECj%s{M$KS0{GlEFk&snk>BCFkIP4d`7-nPVP7Q>fF;1T X2iXqVLhPsP{Ek>c #include #include +#include +#include #include "log.h" #include "libuv_dbus.h" @@ -1594,15 +1596,16 @@ static void __dlThreadRuntimeCb(void *pParams) static void __uvThreadTest(void *pParams) { +#ifndef PLATFORM_CPU for(int i = 0; i < 100; i++) { char buf[256]; memset(buf, 0, 256); sprintf(buf, "Send %d times\n", i); - BL_SendMessage(buf, strlen(buf)); + //BL_SendMessage(buf, strlen(buf)); sleep(1); } - +#endif #if 0 for(int i = 0; i < 100000; i++) { @@ -1797,25 +1800,97 @@ void test_netlink(void) } else { - LOG_EX(LOG_Debug, "Received message: %s\n",(char *) NLMSG_DATA(nlh)); + //LOG_EX(LOG_Debug, "Received message: %s\n",(char *) NLMSG_DATA(nlh)); + print_hex_dump_bytes("Msg", 0, NLMSG_DATA(nlh), retval); } } close(sock_fd); } +#ifndef PLATFORM_CPU static void __uvThreadNetlinkSend(void *pParams) { + char* pData = "0123456789abcdef"; + int lastSt = MSG_IN_DISCOVERY_MODE; + for(int i = 0; i < 100; i++) { - char buf[256]; - memset(buf, 0, 256); - sprintf(buf, "Send %d times", i); - //LOG_EX(LOG_Debug, "Send [%s] ret = %d\n", buf, BL_SendMessage(buf, strlen(buf))); - BL_SendMessage(buf, strlen(buf)); + BL_IOT_MSG blMsg; + + memset(&blMsg, 0, sizeof(BL_IOT_MSG)); + strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS); + memcpy(blMsg.msgData, pData, strlen(pData)); + blMsg.msglen = strlen(pData); + blMsg.msgType = MSG_BYPASS_MODE; + LOG_EX(LOG_Debug, "Send Message : %d\n", i); + BL_SendBLMsg(MSG_GET_WLAN_INFO, NULL, 0); + + if(i % 10 == 0) + { + BL_SendBLMsg(lastSt, NULL, 0); + + if(lastSt == MSG_IN_DISCOVERY_MODE) + { + lastSt = MSG_OUT_DISCOVERY_MODE; + } + else + { + lastSt = MSG_IN_DISCOVERY_MODE; + } + } + + //BL_SendMessage((unsigned char*)&blMsg, BL_IOT_MSG_LEN(blMsg.msglen)); + sleep(1); } } +#endif + +static int expectedId; + +static int nlCallback(void* msg, void* arg) +{ + struct ucred * p = (struct ucred *)msg; + LOG_EX(LOG_Debug, "receive message\n"); +} +#if 0 +void test_nl80211(void) +{ + int ret; + //allocate socket + nl_sock* sk = nl_socket_alloc(); + + //connect to generic netlink + genl_connect(sk); + + //find the nl80211 driver ID + expectedId = genl_ctrl_resolve(sk, "nl80211"); + + //attach a callback + nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, + nlCallback, NULL); + + //allocate a message + nl_msg* msg = nlmsg_alloc(); + + nl80211_commands cmd = NL80211_CMD_GET_INTERFACE; + int ifIndex = if_nametoindex("wlan0"); + int flags = 0; + + // setup the message + genlmsg_put(msg, 0, 0, expectedId, 0, flags, cmd, 0); + + //add message attributes + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifIndex); + + //send the messge (this frees it) + ret = nl_send_auto_complete(sk, msg); + + //block for message to return + nl_recvmsgs_default(sk); +} +#endif int main(int argc, char **argv) { @@ -1825,7 +1900,7 @@ int main(int argc, char **argv) uv_loop_t* pLoop = GetDBusDefaultLoop(); int modIdx = -1; char buf[256]; - BL_IOT_MSG blMsg; + #if 0 i = GetServerModeFromCC(PUBLISH_MODE, &ret); @@ -1901,28 +1976,16 @@ int main(int argc, char **argv) } //test_netlink(); - - BL_Init(); - - memset(&blMsg, 0, sizeof(BL_IOT_MSG)); - - strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS); - - if(modIdx % 2 == 0) - { - blMsg.msgType = MSG_IN_DISCOVERY_MODE; - } - else - { - blMsg.msgType = MSG_OUT_DISCOVERY_MODE; - } +#ifndef PLATFORM_CPU + BL_Init(NULL); - BL_SendMessage((unsigned char*)&blMsg, sizeof(BL_IOT_MSG)); + //L_SendMessage((unsigned char*)&blMsg, sizeof(BL_IOT_MSG)); //test_netlink(); //__uvThreadTimerV2(pLoop); - //test_task_new(__uvThreadNetlinkSend, NULL); - + test_task_new(__uvThreadNetlinkSend, NULL); +#endif + //DumpCurServerAddr("Default"); #if 0 diff --git a/Framework/IoT/Boardlink/boardlink_iot.c b/Framework/IoT/Boardlink/boardlink_iot.c index c28c4ad..820cc52 100644 --- a/Framework/IoT/Boardlink/boardlink_iot.c +++ b/Framework/IoT/Boardlink/boardlink_iot.c @@ -1,3 +1,4 @@ +#ifndef PLATFORM_CPU #include #include #include @@ -11,6 +12,8 @@ #include "log.h" #include "libuv_dbus.h" #include "boardlink_iot.h" +#include "blsdk.h" +#include "blsdk_errno.h" #else #include #include @@ -22,6 +25,7 @@ static int g_nlSock = -1; static unsigned char g_MsgSendBuf[BL_MSG_BUF_MAX]; +static BlMsgCb g_blMsgCb = NULL; static void __recvMsgThread(void *pParam) { @@ -56,7 +60,13 @@ static void __recvMsgThread(void *pParam) } else { - LOG_EX(LOG_Debug, "Recv Message: %s\n", NLMSG_DATA(pMsgHdr)); + PBL_IOT_MSG pMsg = (PBL_IOT_MSG)NLMSG_DATA(pMsgHdr); + //LOG_EX(LOG_Debug, "Recv Message: %s\n", NLMSG_DATA(pMsgHdr)); + print_hex_dump_bytes("Msg", 0, pMsg, BL_IOT_MSG_LEN(pMsg->msglen)); + if(g_blMsgCb) + { + g_blMsgCb(pMsg); + } } } } @@ -93,7 +103,7 @@ static int __nlCreateSocket(void) return 0; } -int BL_SendMessage(unsigned char* pData, unsigned int len) +static int __sendMessage(unsigned char* pData, unsigned int len) { struct iovec iov; struct sockaddr_nl dstAddr; @@ -117,7 +127,42 @@ int BL_SendMessage(unsigned char* pData, unsigned int len) return sendmsg(g_nlSock, &msgHdr, 0); } -int BL_Init(void) +int BL_SendBLMsg(BL_IOT_MSG_TYPE msgType, unsigned char* pData, unsigned int len) +{ + BL_IOT_MSG blMsg; + + memset(&blMsg, 0, sizeof(BL_IOT_MSG)); + blMsg.msgType = msgType; + blMsg.msglen = len; + strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS); + + if(pData && len > 0) + { + memcpy(blMsg.msgData, pData, len); + } + + return __sendMessage((unsigned char*)&blMsg, BL_IOT_MSG_LEN(len)); +} + +int BL_SendBLMsgTo(BL_IOT_MSG_TYPE msgType, unsigned char* pData, unsigned int len, unsigned char dstMac[ETH_ALEN]) +{ + BL_IOT_MSG blMsg; + + memset(&blMsg, 0, sizeof(BL_IOT_MSG)); + blMsg.msgType = msgType; + blMsg.msglen = len; + memcpy(blMsg.dstMac, dstMac, ETH_ALEN); + strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS); + + if(pData && len > 0) + { + memcpy(blMsg.msgData, pData, len); + } + + return __sendMessage((unsigned char*)&blMsg, BL_IOT_MSG_LEN(len)); +} + +int BL_Init(BlMsgCb cbOnMsg) { int ret = 0; uv_thread_t uvRecvThread; @@ -129,7 +174,10 @@ int BL_Init(void) return ret; } + g_blMsgCb = cbOnMsg; + uv_thread_create(&uvRecvThread, __recvMsgThread, NULL); return 0; } +#endif diff --git a/Modules/Alarm/assistant.c b/Modules/Alarm/assistant.c index e086684..c44c000 100644 --- a/Modules/Alarm/assistant.c +++ b/Modules/Alarm/assistant.c @@ -724,6 +724,7 @@ static void __dBusDeameonCb(MODULE_NAME modName, int status) static void __assistantSyncThread(void *pParam) { int ret, i = 0, isSynced = -1; + struct tm* pTmNextYear; LOG_EX(LOG_Debug, "Beging Sync holiday Database\n"); while(TRUE) @@ -826,6 +827,9 @@ static void __assistantSyncThread(void *pParam) LOG_EX(LOG_Debug, "Send CMD_REMAIND_SYNC_REQ Command: %d\n", ret); #endif + while(TRUE) + { + } pthread_detach(pthread_self()); } @@ -852,6 +856,7 @@ int main(int argc, char **argv) AlarmTimerInit(pLoop); uv_thread_create(&uvSyncThread, __assistantSyncThread, NULL); + RunUVLoop(pLoop); while(TRUE) diff --git a/Modules/OTA/ota.c b/Modules/OTA/ota.c index eeaf2ef..028389f 100644 --- a/Modules/OTA/ota.c +++ b/Modules/OTA/ota.c @@ -1041,6 +1041,7 @@ static void __otaDownloadImageCb(void *pParams) pthread_detach(pthread_self()); } +#if 0 static void __dBusDeameonCb(MODULE_NAME modName, int status) { if(status) @@ -1059,6 +1060,7 @@ static void __dBusDeameonCb(MODULE_NAME modName, int status) __otaRspStatus(OTA_CURRENT_REBOOT_TIME, g_iplInfo.setupStatus); } } +#endif static PDBUS_MSG_PACK __dBusOnMessage(uv_loop_t* pLoop, DBusConnection* pConn, PDBUS_MSG_PACK pMsg) { @@ -1112,6 +1114,9 @@ static PDBUS_MSG_PACK __dBusOnMessage(uv_loop_t* pLoop, DBusConnection* pConn, P { __otaRspStatus(OTA_SUCCESED, 1); } + __otaRspStatus(OTA_CURRENT_VERSION, g_iplInfo.curVersion); + __otaRspStatus(OTA_CURRENT_SETUP_MODE, g_iplInfo.setupMode); + __otaRspStatus(OTA_CURRENT_REBOOT_TIME, g_iplInfo.setupStatus); break; case CMD_SYSTEM_STANDBY: @@ -1276,7 +1281,7 @@ int main(int argc, char **argv) pBus = DBusWithLibuvInit(g_pMainLoop, g_pModInfoTable[MODULE_OTA].modAliase, __dBusOnMessage, - __dBusDeameonCb, + NULL, NULL, &ret); diff --git a/build/Makefile.def.cross b/build/Makefile.def.cross index f99a8ac..e7a46f4 100644 --- a/build/Makefile.def.cross +++ b/build/Makefile.def.cross @@ -1,2 +1,2 @@ -COMMON_R16_LIBS := -ldbus-1 -luv -lcrypto -lcjson -ls2json -lsqlite3 -lnghttp2 -lquickmail -lz -luuid -lconfig -lcurl -lssl -lpthread +COMMON_R16_LIBS := -ldbus-1 -luv -lcrypto -lcjson -ls2json -lsqlite3 -lnghttp2 -lquickmail -lz -luuid -lconfig -lcurl -lssl -lpthread ../3partys/boardlink/libfastcon.a COMMON_LINUX_LIBS := -ldbus-1 -luv -lcrypto -lcurl -lm -lnghttp2 -lsqlite3 -lquickmail -lz -luuid -lconfig -lssl -lpthread diff --git a/build/Makefile.lib.cross b/build/Makefile.lib.cross index d56abe5..8bb4843 100644 --- a/build/Makefile.lib.cross +++ b/build/Makefile.lib.cross @@ -58,14 +58,14 @@ PLAT_LINUX_SRCS := $(PLAT_R16_SRCS) \ # gcc CFLAGS -PLAT_R16_CFLAGS := -I../include -fPIC +PLAT_R16_CFLAGS := -I../include -fPIC -I../3partys/boardlink/ PLAT_LINUX_CFLAGS := $(PLAT_R16_CFLAGS) -I/usr/include/dbus-1.0/ -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/ -I../linux32/inc/ -I../linux32/inc/cjson/ PLAT_LINUX_CFLAGS += -I../linux32/inc/uthash/ PLAT_R16_LDFLAGS := -shared -fPIC PLAT_LINUX_LDFLAGS := $(PLAT_R16_LDFLAGS) -R16_LIBS := $(COMMON_R16_LIBS) +R16_LIBS := $(COMMON_R16_LIBS) LINUX_LIBS := $(COMMON_LINUX_LIBS) # this line must be at below of thus, because of... diff --git a/include/boardlink_iot.h b/include/boardlink_iot.h index 61aacb3..65dd47a 100644 --- a/include/boardlink_iot.h +++ b/include/boardlink_iot.h @@ -1,13 +1,15 @@ #ifndef BOARDLINK_IOT_H #define BOARDLINK_IOT_H - +#ifndef PLATFORM_CPU #define BL_IOT_MSG_TAGS ("BLNLINK") #define BL_MAX_MSG (1024) +#define ETH_ALEN (6) typedef enum { MSG_IN_DISCOVERY_MODE = 0, MSG_OUT_DISCOVERY_MODE, + MSG_GET_WLAN_INFO, MSG_BYPASS_MODE, } BL_IOT_MSG_TYPE; @@ -16,12 +18,27 @@ typedef enum typedef struct { unsigned char msgTags[8]; + unsigned char dstMac[ETH_ALEN]; unsigned char msgType; unsigned int msglen; unsigned char msgData[BL_MAX_MSG]; } BL_IOT_MSG, *PBL_IOT_MSG; + +typedef struct +{ + unsigned char channel; + unsigned char dev_mac[ETH_ALEN]; + unsigned char bssid[ETH_ALEN]; + unsigned char ssid[32]; +} WL_INFO, *PWL_INFO; #pragma pack (pop) -int BL_Init(void); -int BL_SendMessage(unsigned char* pData, unsigned int len); +#define BL_IOT_MSG_LEN(len) (sizeof(BL_IOT_MSG) - BL_MAX_MSG + len) + +typedef void (*BlMsgCb)(PBL_IOT_MSG pMsg); + +int BL_Init(BlMsgCb cbOnMsg); +int BL_SendBLMsg(BL_IOT_MSG_TYPE msgType, unsigned char* pData, unsigned int len); +int BL_SendBLMsgTo(BL_IOT_MSG_TYPE msgType, unsigned char* pData, unsigned int len, unsigned char dstMac[ETH_ALEN]); +#endif #endif