luat_wlan.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #ifndef LUAT_WLAN_H
  2. #define LUAT_WLAN_H
  3. #include "luat_base.h"
  4. #ifdef __LUATOS__
  5. #include "luat_msgbus.h"
  6. #include "luat_mem.h"
  7. #endif
  8. typedef struct luat_wlan_config
  9. {
  10. uint32_t mode;
  11. }luat_wlan_config_t;
  12. typedef struct luat_wlan_conninfo
  13. {
  14. char ssid[36];
  15. char password[64];
  16. char bssid[8];
  17. uint32_t authmode;
  18. uint32_t auto_reconnection;
  19. uint32_t auto_reconnection_delay_sec;
  20. }luat_wlan_conninfo_t;
  21. typedef struct luat_wlan_apinfo
  22. {
  23. char ssid[36];
  24. char password[64];
  25. uint8_t gateway[4];
  26. uint8_t netmask[4];
  27. uint8_t channel;
  28. uint8_t encrypt;
  29. uint8_t hidden;
  30. uint8_t max_conn;
  31. }luat_wlan_apinfo_t;
  32. enum LUAT_WLAN_MODE {
  33. LUAT_WLAN_MODE_NULL,
  34. LUAT_WLAN_MODE_STA,
  35. LUAT_WLAN_MODE_AP,
  36. LUAT_WLAN_MODE_APSTA,
  37. LUAT_WLAN_MODE_MAX
  38. };
  39. enum LUAT_WLAN_ENCRYPT_MODE {
  40. LUAT_WLAN_ENCRYPT_AUTO,
  41. LUAT_WLAN_ENCRYPT_NONE,
  42. LUAT_WLAN_ENCRYPT_WPA,
  43. LUAT_WLAN_ENCRYPT_WPA2
  44. };
  45. typedef enum LUAT_EVENT_MODULE {
  46. LUAT_WLAN_EVENT_MOD_WIFI_INTERNAL, /**< WiFi internal event */
  47. LUAT_WLAN_EVENT_MOD_WIFI, /**< WiFi public event */
  48. LUAT_WLAN_EVENT_MOD_NETIF, /**< Netif event */
  49. LUAT_WLAN_EVENT_MOD_COUNT, /**< Event module count */
  50. } luat_event_module_t;
  51. /**
  52. * @brief WiFi public event type
  53. */
  54. typedef enum LUAT_WIFI_EVENT {
  55. LUAT_WLAN_EVENT_WIFI_SCAN_DONE = 0, /**< WiFi scan done event */
  56. LUAT_WLAN_EVENT_WIFI_CSI_DATA_IND,
  57. LUAT_WLAN_EVENT_WIFI_CSI_ALG_IND,
  58. LUAT_WLAN_EVENT_WIFI_STA_CONNECTED, /**< The BK STA is connected */
  59. LUAT_WLAN_EVENT_WIFI_STA_DISCONNECTED, /**< The BK STA is disconnected */
  60. LUAT_WLAN_EVENT_WIFI_AP_CONNECTED, /**< A STA is connected to the BK AP */
  61. LUAT_WLAN_EVENT_WIFI_AP_DISCONNECTED, /**< A STA is disconnected from the BK AP */
  62. LUAT_WLAN_EVENT_WIFI_NETWORK_FOUND, /**< The BK STA find target AP */
  63. LUAT_WLAN_EVENT_WIFI_COUNT, /**< WiFi event count */
  64. } luat_wifi_event_t;
  65. typedef enum LUAT_WIFI_COUNTRY_POLICY {
  66. LUAT_WLAN_WIFI_COUNTRY_POLICY_AUTO, /**< Country policy is auto, use the country info of AP to which the station is connected */
  67. LUAT_WLAN_WIFI_COUNTRY_POLICY_MANUAL, /**< Country policy is manual, always use the configured country info */
  68. } luat_wifi_country_policy_t;
  69. typedef struct luat_wifi_country
  70. {
  71. char cc[3]; /**< country code string */
  72. uint8_t schan; /**< start channel */
  73. uint8_t nchan; /**< total channel number */
  74. int8_t max_tx_power; /**< maximum tx power */
  75. luat_wifi_country_policy_t policy; /**< country policy */
  76. } luat_wifi_country_t;
  77. typedef struct luat_wifi_event_scan_done
  78. {
  79. uint32_t scan_id; /**< Scan ID */
  80. uint32_t scan_use_time;/**< scan time. us */
  81. } luat_wifi_event_scan_done_t;
  82. typedef struct luat_wifi_event_network_found
  83. {
  84. char ssid[33]; /**< SSID found to be connected */
  85. uint8_t bssid[6]; /**< BSSID found to be connected */
  86. } luat_wifi_event_network_found_t;
  87. typedef struct luat_wifi_event_sta_connected
  88. {
  89. char ssid[33]; /**< SSID of connected AP */
  90. uint8_t bssid[6]; /**< BSSID of connected AP*/
  91. } luat_wifi_event_sta_connected_t;
  92. typedef struct luat_wifi_event_sta_disconnected
  93. {
  94. int disconnect_reason; /**< Disconnect reason of BK STA */
  95. uint8_t local_generated; /**< if disconnect is request by local */
  96. } luat_wifi_event_sta_disconnected_t;
  97. typedef struct luat_wifi_event_ap_connected
  98. {
  99. uint8_t mac[6]; /**< MAC of the STA connected to the BK AP */
  100. } luat_wifi_event_ap_connected_t;
  101. typedef struct luat_wifi_event_ap_disconnected
  102. {
  103. uint8_t mac[6]; /**< MAC of the STA disconnected from the BK AP */
  104. } luat_wifi_event_ap_disconnected_t;
  105. typedef struct luat_wlan_scan_result
  106. {
  107. char ssid[33];
  108. char bssid[6];
  109. int16_t rssi;
  110. uint8_t ch;
  111. }luat_wlan_scan_result_t;
  112. typedef struct luat_wlan_station_info
  113. {
  114. uint8_t ipv4_addr[4];
  115. uint8_t ipv4_netmask[4];
  116. uint8_t ipv4_gateway[4];
  117. uint8_t dhcp_enable;
  118. }luat_wlan_station_info_t;
  119. int luat_wlan_init(luat_wlan_config_t *conf);
  120. int luat_wlan_mode(luat_wlan_config_t *conf);
  121. int luat_wlan_ready(void);
  122. int luat_wlan_connect(luat_wlan_conninfo_t* info);
  123. int luat_wlan_disconnect(void);
  124. int luat_wlan_scan(void);
  125. int luat_wlan_scan_get_result(luat_wlan_scan_result_t *results, size_t ap_limit);
  126. int luat_wlan_set_station_ip(luat_wlan_station_info_t *info);
  127. // 配网相关
  128. // --- smartconfig 配网
  129. enum LUAT_WLAN_SC_TYPE {
  130. LUAT_SC_TYPE_STOP = 0,
  131. LUAT_SC_TYPE_ESPTOUCH,
  132. LUAT_SC_TYPE_AIRKISS,
  133. LUAT_SC_TYPE_ESPTOUCH_AIRKISS,
  134. LUAT_SC_TYPE_ESPTOUCH_V2
  135. };
  136. int luat_wlan_smartconfig_start(int tp);
  137. int luat_wlan_smartconfig_stop(void);
  138. // 数据类
  139. int luat_wlan_get_mac(int id, char* mac);
  140. int luat_wlan_set_mac(int id, const char* mac);
  141. int luat_wlan_get_ip(int type, char* data);
  142. const char* luat_wlan_get_hostname(int id);
  143. int luat_wlan_set_hostname(int id, const char* hostname);
  144. // 设置和获取省电模式
  145. int luat_wlan_set_ps(int mode);
  146. int luat_wlan_get_ps(void);
  147. int luat_wlan_get_ap_bssid(char* buff);
  148. int luat_wlan_get_ap_rssi(void);
  149. int luat_wlan_get_ap_gateway(char* buff);
  150. // AP类
  151. int luat_wlan_ap_start(luat_wlan_apinfo_t *apinfo);
  152. int luat_wlan_ap_stop(void);
  153. /**
  154. * @defgroup luat_wifiscan wifiscan扫描接口
  155. * @{
  156. */
  157. #define Luat_MAX_CHANNEL_NUM 14
  158. /// @brief wifiscan 扫描的优先级
  159. typedef enum luat_wifiscan_set_priority
  160. {
  161. LUAT_WIFISCAN_DATA_PERFERRD=0,/**< 数据优先*/
  162. LUAT_WIFISCAN_WIFI_PERFERRD
  163. }luat_wifiscan_set_priority_t;
  164. /// @brief wifiscan 控制参数结构体
  165. typedef struct luat_wifiscan_set_info
  166. {
  167. int maxTimeOut; //ms, 最大执行时间 取值范围4000~255000
  168. uint8_t round; //wifiscan total round 取值范围1~3
  169. uint8_t maxBssidNum; //wifiscan max report num 取值范围4~40
  170. uint8_t scanTimeOut; //s, max time of each round executed by RRC 取值范围1~255
  171. uint8_t wifiPriority; //CmiWifiScanPriority
  172. uint8_t channelCount; //channel count; if count is 1 and all channelId are 0, UE will scan all frequecny channel
  173. uint8_t rsvd[3];
  174. uint16_t channelRecLen; //ms, max scantime of each channel
  175. uint8_t channelId[Luat_MAX_CHANNEL_NUM]; //channel id 1-14: scan a specific channel
  176. }luat_wifiscan_set_info_t;
  177. #define LUAT_MAX_WIFI_BSSID_NUM 40 ///< bssid 的最大数量
  178. #define LUAT_MAX_SSID_HEX_LENGTH 32 ///< SSID 的最大长度
  179. /// @brief wifiscan 扫描结果
  180. typedef struct luat_wifisacn_get_info
  181. {
  182. uint8_t bssidNum; /**<wifi 个数*/
  183. uint8_t rsvd;
  184. uint8_t ssidHexLen[LUAT_MAX_WIFI_BSSID_NUM]; /**<SSID name 的长度*/
  185. uint8_t ssidHex[LUAT_MAX_WIFI_BSSID_NUM][LUAT_MAX_SSID_HEX_LENGTH]; /**<SSID name*/
  186. int8_t rssi[LUAT_MAX_WIFI_BSSID_NUM]; /**<rssi*/
  187. uint8_t channel[LUAT_MAX_WIFI_BSSID_NUM]; /**<record channel index of bssid, 2412MHz ~ 2472MHz correspoding to 1 ~ 13*/
  188. uint8_t bssid[LUAT_MAX_WIFI_BSSID_NUM][6]; /**<mac address is fixed to 6 digits*/
  189. }luat_wifisacn_get_info_t;
  190. /**
  191. * @brief 获取wifiscan 的信息
  192. * @param set_info[in] 设置控制wifiscan的参数
  193. * @param get_info[out] wifiscan 扫描结果
  194. * @return int =0成功,其他失败
  195. */
  196. int32_t luat_get_wifiscan_cell_info(luat_wifiscan_set_info_t * set_info,luat_wifisacn_get_info_t* get_info);
  197. /**
  198. * @brief 获取wifiscan 的信息
  199. * @param set_info[in] 设置控制wifiscan的参数
  200. * @return int =0成功,其他失败
  201. */
  202. int luat_wlan_scan_nonblock(luat_wifiscan_set_info_t * set_info);
  203. /**
  204. * @brief 设置wifiscan的参数
  205. * @param proi 扫描优先级,0低于数据传输 1高于数据传输
  206. * @param rounds 扫描轮数,至少1轮
  207. * @param one_round_timeout 1轮扫描的时间,单位秒,至少5秒
  208. * @param total_timeout 全局超时,单位秒
  209. * @return int =0成功,其他失败
  210. */
  211. int luat_wlan_scan_set_param(uint8_t proi, uint8_t rounds, uint8_t one_round_timeout, uint8_t total_timeout);
  212. /** @}*/
  213. #endif