ql_wifi_scan.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*================================================================
  2. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  3. Quectel Wireless Solutions Proprietary and Confidential.
  4. =================================================================*/
  5. /*=================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ------------ ------- -------------------------------------------------------------------------------
  11. =================================================================*/
  12. #ifndef QL_WIFI_SCAN_H
  13. #define QL_WIFI_SCAN_H
  14. #include "ql_api_common.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /*===========================================================================
  19. * Macro Definition
  20. ===========================================================================*/
  21. #define QL_WIFISCAN_ERRCODE_BASE (QL_COMPONENT_BSP_WIFISCAN<<16)
  22. #define QL_WIFI_SCAN_MAX_TIME (5000) //max scan time for a channel
  23. #define QL_WIFI_SCAN_MIN_TIME (120) //min scan time for a channel
  24. #define QL_WIFI_SCAN_DEFAULT_TIME (600)//default scan time for a channel
  25. #define QL_WIFI_SCAN_MAX_AP_CNT (300)//max wifi ap count to scan
  26. #define QL_WIFI_SCAN_MIN_AP_CNT (1)//min wifi ap count to scan
  27. #define QL_WIFI_SCAN_DEFAULT_AP_CNT (10)//default wifi ap count to scan
  28. #define QL_WIFI_SCAN_MAX_ROUND (10)//max round to scan
  29. #define QL_WIFI_SCAN_MIN_ROUND (1)//min round to scan
  30. #define QL_WIFI_SCAN_DEFAULT_ROUND (1)//default round to scan
  31. #define QL_WIFI_SCAN_MAX_RETRY_TIME (4000) //max retry period time
  32. #define QL_WIFI_SCAN_MIN_RETRY_TIME (100) //min retry period time
  33. #define QL_WIFI_SCAN_DEFAULT_RETRY_TIME (1000)//default retry period time
  34. /*========================================================================
  35. * Enumeration Definition
  36. *========================================================================*/
  37. /******************** error code about wifiscan **********************/
  38. typedef enum
  39. {
  40. QL_WIFISCAN_SUCCESS = 0,
  41. QL_WIFISCAN_EXECUTE_ERR = 1|QL_WIFISCAN_ERRCODE_BASE,
  42. QL_WIFISCAN_MEM_ADDR_NULL_ERR,
  43. QL_WIFISCAN_INVALID_PARAM_ERR,
  44. QL_WIFISCAN_SEMAPHORE_WAIT_ERR,
  45. QL_WIFISCAN_MUTEX_TIMEOUT_ERR,
  46. QL_WIFISCAN_OPEN_FAIL,
  47. QL_WIFISCAN_BUSY_ERR,
  48. QL_WIFISCAN_ALREADY_OPEN_ERR,
  49. QL_WIFISCAN_NOT_OPEN_ERR,
  50. QL_WIFISCAN_HW_OCCUPIED_ERR,
  51. QL_WIFISCAN_NO_SET_CB_ERR,
  52. QL_WIFISCAN_SSID_FORMAT_CONVERT_ERR, //ssid格式转换错误
  53. } ql_errcode_wifi_scan_e;
  54. typedef enum
  55. {
  56. QL_WIFISCAN_CHANNEL_ALL_BIT = 0x1FFF,
  57. QL_WIFISCAN_CHANNEL_ALL = 0,
  58. QL_WIFISCAN_CHANNEL_ONE = 0x0001,
  59. QL_WIFISCAN_CHANNEL_TWO = 0x0002,
  60. QL_WIFISCAN_CHANNEL_THREE = 0x0004,
  61. QL_WIFISCAN_CHANNEL_FOUR = 0x0008,
  62. QL_WIFISCAN_CHANNEL_FIVE = 0x0010,
  63. QL_WIFISCAN_CHANNEL_SIX = 0x0020,
  64. QL_WIFISCAN_CHANNEL_SEVEN = 0x0040,
  65. QL_WIFISCAN_CHANNEL_EIGHT = 0x0080,
  66. QL_WIFISCAN_CHANNEL_NINE = 0x0100,
  67. QL_WIFISCAN_CHANNEL_TEN = 0x0200,
  68. QL_WIFISCAN_CHANNEL_ELEVEN = 0x0400,
  69. QL_WIFISCAN_CHANNEL_TWELVE = 0x0800,
  70. QL_WIFISCAN_CHANNEL_THIRTEEN = 0x1000,
  71. QL_WIFISCAN_CHANNEL_TOTAL = 13,
  72. QL_WIFISCAN_CHANNEL_MAX,
  73. }ql_wifiscan_channel_e;
  74. typedef enum
  75. {
  76. QUEC_PAM_NO_WORK,
  77. QUEC_PAM_GNSS_WORK, //RF resources are occupied by GNSS
  78. QUEC_PAM_WIFISCAN_WORK, //RF resources are occupied by WIFISCAN
  79. QUEC_PAM_LTE_WORK, //RF resources are occupied by LTE
  80. }ql_pam_work_type_e;
  81. typedef enum
  82. {
  83. QL_DATA_PRIORITY, //lte data priority,by default
  84. QL_WIFISCAN_PRIORITY, //Wifiscan priority,Currently this parameter is not supported
  85. QL_WIFISCAN_INDEPENDENT, //Independent wifiscan,Currently this parameter is not supported
  86. }ql_wifiscan_prio_e;
  87. typedef enum
  88. {
  89. QL_WIFISCAN_SSID_FM_UTF8, //output ssid in UTF-8 format,by default
  90. QL_WIFISCAN_SSID_FM_GBK, //ssid in GBK(CP936) format
  91. QL_WIFISCAN_SSID_FM_UTF8TOHEX, //ssid in HEX(UTF-8 to hex) format,
  92. //this mode is used in ssid scenarios with "" or ,
  93. }ql_wifiscan_ssid_format_e;
  94. /*===========================================================================
  95. * Struct
  96. ===========================================================================*/
  97. typedef struct
  98. {
  99. uint32_t bssid_low; ///< mac address low
  100. uint16_t bssid_high; ///< mac address high
  101. uint8_t channel; ///< channel id
  102. int8_t rssival; ///< signal strength
  103. uint16_t reserved;
  104. uint16_t ssidlen; ///< ssid len, unit byte
  105. uint8_t ssid[32*2+1];///< 底层默认返回最大32字节的utf-8格式的ssid,如果需要转换格式,数据长度会变大。
  106. ///< beacon帧上SSID字段最长就是32字节
  107. } ql_wifi_ap_info_s;
  108. typedef struct
  109. {
  110. uint32_t ap_cnt;
  111. ql_wifi_ap_info_s *ap_infos;
  112. } ql_wifiscan_result_s;
  113. typedef struct
  114. {
  115. uint32_t msg_id;
  116. uint32_t msg_err_code;
  117. void *msg_data;
  118. } ql_wifiscan_ind_msg_s;
  119. typedef struct
  120. {
  121. uint16_t expect_ap_cnt; //the max ap cnt you want to find
  122. uint8_t round; //scan times for all channel
  123. uint16_t scan_channel; //the channel you want to scan, from bit 0 to bit 12, each bit is a channel.
  124. //if want to scan all channel, please set scan_channel to 0 or set the low 13 bits as 1 like QL_WIFISCAN_CHANNEL_ALL_BIT or 0xFFFF
  125. uint32_t channel_time; //time to scan a channel
  126. ql_wifiscan_prio_e prio; //WiFiScan priority,Currently this parameter is not supported
  127. ql_wifiscan_ssid_format_e ssid_format;//output the ssid format
  128. uint16_t retry_period; //If RF resources are occupied, retry interval,unit:ms
  129. //QL_WIFI_SCAN_DEFAULT_RETRY_TIME by default,Currently this parameter is not supported
  130. } ql_wifiscan_opt_param_s;
  131. /*===========================================================================
  132. * Functions declaration
  133. ===========================================================================*/
  134. /*
  135. * wifi scan callback function type definition.
  136. * ql_wifiscan_ind_msg_s as paramter, all the buffer will be released automatically,
  137. * so if your want, you need to save the msg data in your callback function.
  138. */
  139. typedef void (*ql_wifiscan_callback)(ql_wifiscan_ind_msg_s *msg_buf);
  140. /*
  141. * to open the wifiscan device, if it is already opened, the function will return QL_WIFISCAN_ALREADY_OPEN_ERR.
  142. */
  143. ql_errcode_wifi_scan_e ql_wifiscan_open(void);
  144. /*
  145. * to close the wifiscan device, return QL_WIFISCAN_SUCCESS always.
  146. */
  147. ql_errcode_wifi_scan_e ql_wifiscan_close(void);
  148. /*
  149. * to config the options for one time scan
  150. * expect_ap_cnt: the max ap cnt you want to find
  151. * round: scan times for all channel
  152. * scan_channel: the channel you want to scan, from bit 0 to bit 12, each bit is a channel.
  153. * if want to scan all channel, please set scan_channel to 0 or set the low 13 bits as 1 like QL_WIFISCAN_CHANNEL_ALL_BIT or 0xFFFF
  154. * channel_time: time to scan a channel
  155. */
  156. ql_errcode_wifi_scan_e ql_wifiscan_option_set(uint16_t expect_ap_cnt, uint8_t round, uint16_t scan_channel, uint32_t channel_time);
  157. /*
  158. * to config the options for one time scan
  159. * ql_wifiscan_opt_param_s as parameter
  160. */
  161. ql_errcode_wifi_scan_e ql_wifiscan_option_set_ex(ql_wifiscan_opt_param_s *param);
  162. /*
  163. * to scan the wifi AP at synchronous mode.
  164. * p_ap_cnt is to return the AP number, and the max is your expect_ap_cnt in ql_wifiscan_option_set..
  165. * p_ap_infos is to save the AP info, you need to apply the enough buffer first, like expect_ap_cnt*sizeof(ql_wifi_ap_info_s)
  166. * please don't forget to close wifiscan device by call ql_wifiscan_close
  167. */
  168. ql_errcode_wifi_scan_e ql_wifiscan_do(uint16_t *p_ap_cnt, ql_wifi_ap_info_s *p_ap_infos);
  169. /*
  170. * to register a callback funciton for wifiscan task.
  171. */
  172. ql_errcode_wifi_scan_e ql_wifiscan_register_cb(ql_wifiscan_callback wifiscan_cb);
  173. /*
  174. * start to do wifiscan at asynchronous mode, and the result will return by call your callback function.
  175. * please don't forget to close wifiscan device by call ql_wifiscan_close
  176. */
  177. ql_errcode_wifi_scan_e ql_wifiscan_async(void);
  178. #ifdef __cplusplus
  179. } /*"C" */
  180. #endif
  181. #endif /* QL_WIFI_SCAN_H */