luat_wlan.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 struct luat_wlan_scan_result
  46. {
  47. char ssid[33];
  48. char bssid[6];
  49. int16_t rssi;
  50. uint8_t ch;
  51. }luat_wlan_scan_result_t;
  52. typedef struct luat_wlan_station_info
  53. {
  54. uint8_t ipv4_addr[4];
  55. uint8_t ipv4_netmask[4];
  56. uint8_t ipv4_gateway[4];
  57. uint8_t dhcp_enable;
  58. }luat_wlan_station_info_t;
  59. int luat_wlan_init(luat_wlan_config_t *conf);
  60. int luat_wlan_mode(luat_wlan_config_t *conf);
  61. int luat_wlan_ready(void);
  62. int luat_wlan_connect(luat_wlan_conninfo_t* info);
  63. int luat_wlan_disconnect(void);
  64. int luat_wlan_scan(void);
  65. int luat_wlan_scan_get_result(luat_wlan_scan_result_t *results, size_t ap_limit);
  66. int luat_wlan_set_station_ip(luat_wlan_station_info_t *info);
  67. // 配网相关
  68. // --- smartconfig 配网
  69. enum LUAT_WLAN_SC_TYPE {
  70. LUAT_SC_TYPE_STOP = 0,
  71. LUAT_SC_TYPE_ESPTOUCH,
  72. LUAT_SC_TYPE_AIRKISS,
  73. LUAT_SC_TYPE_ESPTOUCH_AIRKISS,
  74. LUAT_SC_TYPE_ESPTOUCH_V2
  75. };
  76. int luat_wlan_smartconfig_start(int tp);
  77. int luat_wlan_smartconfig_stop(void);
  78. // 数据类
  79. int luat_wlan_get_mac(int id, char* mac);
  80. int luat_wlan_set_mac(int id, const char* mac);
  81. int luat_wlan_get_ip(int type, char* data);
  82. const char* luat_wlan_get_hostname(int id);
  83. int luat_wlan_set_hostname(int id, const char* hostname);
  84. // 设置和获取省电模式
  85. int luat_wlan_set_ps(int mode);
  86. int luat_wlan_get_ps(void);
  87. int luat_wlan_get_ap_bssid(char* buff);
  88. int luat_wlan_get_ap_rssi(void);
  89. int luat_wlan_get_ap_gateway(char* buff);
  90. // AP类
  91. int luat_wlan_ap_start(luat_wlan_apinfo_t *apinfo);
  92. int luat_wlan_ap_stop(void);
  93. /**
  94. * @defgroup luat_wifiscan wifiscan扫描接口
  95. * @{
  96. */
  97. #define Luat_MAX_CHANNEL_NUM 14
  98. /// @brief wifiscan 扫描的优先级
  99. typedef enum luat_wifiscan_set_priority
  100. {
  101. LUAT_WIFISCAN_DATA_PERFERRD=0,/**< 数据优先*/
  102. LUAT_WIFISCAN_WIFI_PERFERRD
  103. }luat_wifiscan_set_priority_t;
  104. /// @brief wifiscan 控制参数结构体
  105. typedef struct luat_wifiscan_set_info
  106. {
  107. int maxTimeOut; //ms, 最大执行时间 取值范围4000~255000
  108. uint8_t round; //wifiscan total round 取值范围1~3
  109. uint8_t maxBssidNum; //wifiscan max report num 取值范围4~40
  110. uint8_t scanTimeOut; //s, max time of each round executed by RRC 取值范围1~255
  111. uint8_t wifiPriority; //CmiWifiScanPriority
  112. uint8_t channelCount; //channel count; if count is 1 and all channelId are 0, UE will scan all frequecny channel
  113. uint8_t rsvd[3];
  114. uint16_t channelRecLen; //ms, max scantime of each channel
  115. uint8_t channelId[Luat_MAX_CHANNEL_NUM]; //channel id 1-14: scan a specific channel
  116. }luat_wifiscan_set_info_t;
  117. #define LUAT_MAX_WIFI_BSSID_NUM 40 ///< bssid 的最大数量
  118. #define LUAT_MAX_SSID_HEX_LENGTH 32 ///< SSID 的最大长度
  119. /// @brief wifiscan 扫描结果
  120. typedef struct luat_wifisacn_get_info
  121. {
  122. uint8_t bssidNum; /**<wifi 个数*/
  123. uint8_t rsvd;
  124. uint8_t ssidHexLen[LUAT_MAX_WIFI_BSSID_NUM]; /**<SSID name 的长度*/
  125. uint8_t ssidHex[LUAT_MAX_WIFI_BSSID_NUM][LUAT_MAX_SSID_HEX_LENGTH]; /**<SSID name*/
  126. int8_t rssi[LUAT_MAX_WIFI_BSSID_NUM]; /**<rssi*/
  127. uint8_t channel[LUAT_MAX_WIFI_BSSID_NUM]; /**<record channel index of bssid, 2412MHz ~ 2472MHz correspoding to 1 ~ 13*/
  128. uint8_t bssid[LUAT_MAX_WIFI_BSSID_NUM][6]; /**<mac address is fixed to 6 digits*/
  129. }luat_wifisacn_get_info_t;
  130. /**
  131. * @brief 获取wifiscan 的信息
  132. * @param set_info[in] 设置控制wifiscan的参数
  133. * @param get_info[out] wifiscan 扫描结果
  134. * @return int =0成功,其他失败
  135. */
  136. int32_t luat_get_wifiscan_cell_info(luat_wifiscan_set_info_t * set_info,luat_wifisacn_get_info_t* get_info);
  137. /**
  138. * @brief 获取wifiscan 的信息
  139. * @param set_info[in] 设置控制wifiscan的参数
  140. * @return int =0成功,其他失败
  141. */
  142. int luat_wlan_scan_nonblock(luat_wifiscan_set_info_t * set_info);
  143. /**
  144. * @brief 设置wifiscan的参数
  145. * @param proi 扫描优先级,0低于数据传输 1高于数据传输
  146. * @param rounds 扫描轮数,至少1轮
  147. * @param one_round_timeout 1轮扫描的时间,单位秒,至少5秒
  148. * @param total_timeout 全局超时,单位秒
  149. * @return int =0成功,其他失败
  150. */
  151. int luat_wlan_scan_set_param(uint8_t proi, uint8_t rounds, uint8_t one_round_timeout, uint8_t total_timeout);
  152. /** @}*/
  153. #endif