ble_cfg_net_api.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
  3. * Description: BLE辅助配网SDK API头文件
  4. */
  5. #ifndef BLE_CFG_NET_API_H
  6. #define BLE_CFG_NET_API_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /* WIFI信息长度宏定义 */
  11. #define WIFI_SSID_MAX_LEN 32
  12. #define WIFI_PWD_MAX_LEN 64
  13. #define WIFI_PSK_LEN 32
  14. #define WIFI_BSSID_LEN 6
  15. #define BLE_UUID_LEN 16
  16. /* 用户发送的数据类型 */
  17. typedef enum {
  18. NETCFG_DATA,
  19. CUSTOM_DATA,
  20. DATA_TYPE_BUTT
  21. } BLE_DataType;
  22. /* 属性类型定义 */
  23. typedef enum {
  24. ATTR_TYPE_SERVICE = 0,
  25. ATTR_TYPE_CHAR,
  26. ATTR_TYPE_CHAR_VALUE,
  27. ATTR_TYPE_CHAR_CLIENT_CONFIG,
  28. ATTR_TYPE_CHAR_USER_DESC,
  29. } BLE_AttrType;
  30. /* UUID长度定义 */
  31. typedef enum {
  32. UUID_TYPE_NULL = 0,
  33. UUID_TYPE_16_BIT,
  34. UUID_TYPE_32_BIT,
  35. UUID_TYPE_128_BIT,
  36. } BLE_UuidType;
  37. /* BLE辅助配网状态定义 */
  38. typedef enum {
  39. CFG_NET_PROCESS_SUCCESS = 0x00,
  40. CFG_NET_BLE_CONNECT,
  41. CFG_NET_BLE_DIS_CONNECT,
  42. CFG_NET_SPEKE_SUCCESS,
  43. CFG_NET_PROCESS_START,
  44. CFG_NET_RECEIVE_PARA,
  45. CFG_NET_WIFI_CONNECT,
  46. CFG_NET_FAIL_UNKUNOWN = 0x100,
  47. CFG_NET_FAIL_WIFI_SSID,
  48. CFG_NET_FAIL_WIFI_PWD
  49. } BLE_CfgNetStatus;
  50. /* 手机侧传过来的WIFI信息,格式复用短距配网格式 */
  51. typedef struct {
  52. unsigned char ssid[WIFI_SSID_MAX_LEN + 1];
  53. unsigned char pwd[WIFI_PWD_MAX_LEN + 1];
  54. unsigned char psk[WIFI_PSK_LEN + 1];
  55. unsigned char bssid[WIFI_BSSID_LEN + 1];
  56. unsigned char ssidLen;
  57. unsigned char pwdLen;
  58. unsigned char pskLen;
  59. unsigned char bssidLen;
  60. int authMode;
  61. int wifiInfoSrc;
  62. int channelNumber;
  63. } BLE_WifiInfo;
  64. /*
  65. * 获取设备PIN码函数类型
  66. * pincode: 存放pin码的缓冲区
  67. * size: 缓冲区的长度
  68. * len: 返回的pin码实际长度
  69. */
  70. typedef int (*BLE_GetDevPinCode)(unsigned char *pinCode, unsigned int size, unsigned int *len);
  71. /*
  72. * 获取设备信息函数类型,len即是入参也是出参,入参代表buff缓冲区长度,出参代表获取的设备信息实际长度
  73. * 格式要求:{"productId":"%s", "sn":"%s", "vendor":"%s"}
  74. */
  75. typedef int (*BLE_GetDeviceInfo)(unsigned char *devInfo, unsigned int *len);
  76. /*
  77. * 设置配网信息函数类型
  78. .* 数据格式:{"ssid":"%s","password":"%s","devId":"%s","psk":"%s","code":"%s","random":"%s","vendorData":"%s"}
  79. */
  80. typedef int (*BLE_SetCfgNetInfo)(const unsigned char *netInfo, unsigned int len);
  81. /* 接收用户数据函数类型 */
  82. typedef int (*BLE_RcvCustomData)(unsigned char *buff, unsigned int len);
  83. /* 配网过程状态处理函数类型 */
  84. typedef int (*BLE_CfgNetProcess)(BLE_CfgNetStatus status);
  85. /* BLE GATT服务读函数类型 */
  86. typedef int (*BLE_GattRead)(unsigned char *buff, unsigned int *len);
  87. /* BLE GATT服务写函数类型 */
  88. typedef int (*BLE_GattWrite)(const unsigned char *buff, unsigned int len);
  89. /* BLE GATT服务指示函数类型 */
  90. typedef int (*BLE_GattIndicate)(unsigned char *buff, unsigned int len);
  91. /* BLE GATT回调函数指针 */
  92. typedef struct {
  93. BLE_GattRead readCb;
  94. BLE_GattWrite writeCb;
  95. BLE_GattIndicate indicateCb;
  96. } BLE_GattOperateFunc;
  97. /* BLE配置参数 */
  98. typedef struct {
  99. int isBlePair;
  100. int isDeinitBleStack;
  101. int data1; /* 为后期配置参数预留,暂不使用 */
  102. int data2; /* 为后期配置参数预留,暂不使用 */
  103. int data3; /* 为后期配置参数预留,暂不使用 */
  104. } BLE_ConfPara;
  105. /* BLE GATT服务 */
  106. typedef struct {
  107. BLE_AttrType attrType;
  108. unsigned int permission;
  109. BLE_UuidType uuidType;
  110. unsigned char uuid[BLE_UUID_LEN];
  111. unsigned char *value;
  112. unsigned char valLen;
  113. unsigned char properties;
  114. BLE_GattOperateFunc func;
  115. } BLE_GattAttr;
  116. /* GATT服务(单个service及其下挂的全部characteristics和descriptions) */
  117. typedef struct {
  118. unsigned int attrNum;
  119. BLE_GattAttr *attrList;
  120. } BLE_GattService;
  121. /* GATT列表(包含多个services和返回的handle) */
  122. typedef struct {
  123. unsigned int num;
  124. BLE_GattService *service;
  125. int *handle;
  126. } BLE_GattList;
  127. /* GATT句柄列表 */
  128. typedef struct {
  129. unsigned int num;
  130. int *handle;
  131. } BLE_GattHandleList;
  132. /* BLE的广播数据和扫描应答数据 */
  133. typedef struct {
  134. unsigned char *advData;
  135. unsigned int advDataLen;
  136. unsigned char *rspData;
  137. unsigned int rspDataLen;
  138. } BLE_AdvData;
  139. /* BLE的广播参数 */
  140. typedef struct {
  141. unsigned char advType;
  142. unsigned char discMode;
  143. unsigned char connMode;
  144. unsigned int minInterval;
  145. unsigned int maxInterval;
  146. unsigned int channelMap;
  147. unsigned int timeout;
  148. int txPower;
  149. } BLE_AdvPara;
  150. /* 广播参数和数据 */
  151. typedef struct {
  152. BLE_AdvPara *advPara;
  153. BLE_AdvData *advData;
  154. } BLE_AdvInfo;
  155. /* BLE初始化参数 */
  156. typedef struct {
  157. BLE_ConfPara *confPara;
  158. BLE_AdvInfo *advInfo;
  159. BLE_GattList *gattList;
  160. } BLE_InitPara;
  161. /* BLE配网回调函数 */
  162. typedef struct {
  163. BLE_GetDevPinCode getDevPinCodeCb;
  164. BLE_GetDeviceInfo getDeviceInfoCb;
  165. BLE_SetCfgNetInfo setCfgNetInfoCb;
  166. BLE_RcvCustomData rcvCustomDataCb;
  167. BLE_CfgNetProcess cfgNetProcessCb;
  168. } BLE_CfgNetCb;
  169. /* BLE配网资源申请:BLE协议栈启动、配网回调函数挂接 */
  170. int BLE_CfgNetInit(BLE_InitPara *para, BLE_CfgNetCb *cb);
  171. /*
  172. * BLE配网资源注销:配网回调函数清理、BLE协议栈销毁
  173. * flag为0:只销毁控制和调度线程,flag为1销毁蓝牙协议栈,该函数不可重入
  174. */
  175. int BLE_CfgNetDeInit(const BLE_GattHandleList *handleList, unsigned int flag);
  176. /* BLE配网广播控制:参数代表广播时间,0:停止;0xFFFFFFFF:一直广播,其他:广播指定时间后停止,单位秒 */
  177. int BLE_CfgNetAdvCtrl(unsigned int advSecond);
  178. /*
  179. * 更新广播参数,更新完成后需调用BLE_CfgNetAdvCtrl启动广播
  180. * 传入空值时可启动hilink构造的广播
  181. */
  182. int BLE_CfgNetAdvUpdate(const BLE_AdvInfo *advInfo);
  183. /* BLE配网断开连接:防止其他任务长时间占用BLE连接 */
  184. int BLE_CfgNetDisConnect(void);
  185. /* BLE发送用户数据:用户数据发送,与接收回调函数配套使用 */
  186. int BLE_SendCustomData(BLE_DataType dataType, const unsigned char *buff, unsigned int len);
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif