drv_wlan.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * File : drv_wlan.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-7-10 tyx the first version
  23. */
  24. #ifndef __DRV_WLAN_H__
  25. #define __DRV_WLAN_H__
  26. typedef enum
  27. {
  28. RTHW_MODE_NONE = 0,
  29. RTHW_MODE_STA,
  30. RTHW_MODE_AP,
  31. RTHW_MODE_STA_AP,
  32. RTHW_MODE_PROMISC,
  33. RTHW_MODE_P2P
  34. }rthw_mode_t;
  35. #define SHARED_ENABLED 0x00008000
  36. #define WPA_SECURITY 0x00200000
  37. #define WPA2_SECURITY 0x00400000
  38. #define WPS_ENABLED 0x10000000
  39. #define WEP_ENABLED 0x0001
  40. #define TKIP_ENABLED 0x0002
  41. #define AES_ENABLED 0x0004
  42. #define WSEC_SWFLAG 0x0008
  43. typedef enum {
  44. RTHW_SECURITY_OPEN = 0, /**< Open security */
  45. RTHW_SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
  46. RTHW_SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
  47. RTHW_SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
  48. RTHW_SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
  49. RTHW_SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
  50. RTHW_SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
  51. RTHW_SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
  52. RTHW_SECURITY_WPA_WPA2_MIXED = ( WPA_SECURITY | WPA2_SECURITY ), /**< WPA/WPA2 Security */
  53. RTHW_SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
  54. RTHW_SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
  55. RTHW_SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */
  56. RTHW_SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force rtw_security_t type to 32 bits */
  57. } rthw_security_t;
  58. typedef enum {
  59. RTHW_WIFI_EVENT_CONNECT = 0,
  60. RTHW_WIFI_EVENT_DISCONNECT = 1,
  61. RTHW_WIFI_EVENT_FOURWAY_HANDSHAKE_DONE = 2,
  62. RTHW_WIFI_EVENT_SCAN_RESULT_REPORT = 3,
  63. RTHW_WIFI_EVENT_SCAN_DONE = 4,
  64. RTHW_WIFI_EVENT_RECONNECTION_FAIL = 5,
  65. RTHW_WIFI_EVENT_SEND_ACTION_DONE = 6,
  66. RTHW_WIFI_EVENT_RX_MGNT = 7,
  67. RTHW_WIFI_EVENT_STA_ASSOC = 8,
  68. RTHW_WIFI_EVENT_STA_DISASSOC = 9,
  69. RTHW_WIFI_EVENT_STA_WPS_START = 10,
  70. RTHW_WIFI_EVENT_WPS_FINISH = 11,
  71. RTHW_WIFI_EVENT_EAPOL_START = 12,
  72. RTHW_WIFI_EVENT_EAPOL_RECVD = 13,
  73. RTHW_WIFI_EVENT_NO_NETWORK = 14,
  74. RTHW_WIFI_EVENT_BEACON_AFTER_DHCP = 15,
  75. RTHW_WIFI_EVENT_MAX,
  76. }rthw_event_indicate_t;
  77. typedef enum {
  78. RTHW_802_11_BAND_5GHZ = 0, /**< Denotes 5GHz radio band */
  79. RTHW_802_11_BAND_2_4GHZ = 1 /**< Denotes 2.4GHz radio band */
  80. } rthw_802_11_band_t;
  81. struct rthw_wlan_info
  82. {
  83. char *ssid;
  84. rt_uint8_t *bssid;
  85. rthw_802_11_band_t band;
  86. rt_uint32_t datarate;
  87. rt_uint16_t channel;
  88. rt_int16_t rssi;
  89. rthw_security_t security;
  90. };
  91. typedef void (*scan_callback_fn)(struct rthw_wlan_info *info, void *user_data);
  92. typedef void (*rthw_wlan_monitor_callback_t)(rt_uint8_t *data, int len, void *user_data);
  93. rthw_mode_t rthw_wifi_mode_get(void);
  94. int rthw_wifi_stop(void);
  95. int rthw_wifi_start(rthw_mode_t mode);
  96. int rthw_wifi_connect(char *ssid, int ssid_len, char *password, int pass_len, rthw_security_t security_type);
  97. int rthw_wifi_connect_bssid(char *bssid, char *ssid, int ssid_len, char *password, int pass_len, rthw_security_t security_type);
  98. int rthw_wifi_ap_start(char *ssid, char *password, int channel);
  99. int rthw_wifi_rssi_get(void);
  100. void rthw_wifi_channel_set(int channel);
  101. int rthw_wifi_channel_get(void);
  102. int rthw_wifi_sta_disconnect(void);
  103. int rthw_wifi_ap_disconnect(void);
  104. int rthw_wifi_scan(scan_callback_fn fun, void *data);
  105. void rthw_wifi_monitor_enable(int enable);
  106. void rthw_wifi_monitor_callback_set(rthw_wlan_monitor_callback_t callback);
  107. #endif