wlan_dev.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * RT-Thread Wi-Fi Device
  3. *
  4. * COPYRIGHT (C) 2014 - 2015, Shanghai Real-Thread Technology Co., Ltd
  5. *
  6. * This file is part of RT-Thread (http://www.rt-thread.org)
  7. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. *
  24. * Change Logs:
  25. * Date Author Notes
  26. * 2014-09-11 Bernard the first verion
  27. */
  28. #ifndef WIFI_DEVICE_H__
  29. #define WIFI_DEVICE_H__
  30. #include <stdint.h>
  31. #include <netif/ethernetif.h>
  32. typedef enum
  33. {
  34. WIFI_STATION,
  35. WIFI_AP,
  36. } rt_wlan_mode_t;
  37. typedef enum
  38. {
  39. WIFI_INIT = 0x10,
  40. WIFI_SCAN, /* trigger scanning (list cells) */
  41. WIFI_JOIN,
  42. WIFI_EASYJOIN, /* join network with less information */
  43. WIFI_SOFTAP, /* start soft-AP */
  44. WIFI_DISCONNECT,
  45. WIFI_GET_RSSI, /* get sensitivity (dBm) */
  46. WIFI_ENTER_POWERSAVE,
  47. } rt_wlan_cmd_t;
  48. typedef enum
  49. {
  50. WIFI_PWR_OFF,
  51. WIFI_PWR_SLEEP,
  52. WIFI_PWR_NORMAL
  53. } rt_wlan_powersave_t;
  54. #define SHARED_ENABLED 0x00008000
  55. #define WPA_SECURITY 0x00200000
  56. #define WPA2_SECURITY 0x00400000
  57. #define WPS_ENABLED 0x10000000
  58. #define WEP_ENABLED 0x0001
  59. #define TKIP_ENABLED 0x0002
  60. #define AES_ENABLED 0x0004
  61. #define WSEC_SWFLAG 0x0008
  62. #define KEY_ARRAY_SIZE 32
  63. /**
  64. * Enumeration of Wi-Fi security modes
  65. */
  66. typedef enum
  67. {
  68. SECURITY_OPEN = 0, /**< Open security */
  69. SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
  70. SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
  71. SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
  72. SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
  73. SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
  74. SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
  75. SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
  76. SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
  77. SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
  78. SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown.
  79. Do not pass this to the join function! */
  80. } rt_wlan_security_t;
  81. typedef enum
  82. {
  83. WIFI_EVT_LINK_DOWN,
  84. WIFI_EVT_LINK_UP,
  85. }rt_wlan_event_t;
  86. /* wifi network information */
  87. struct rt_wlan_info
  88. {
  89. rt_wlan_mode_t mode; /* wifi mode */
  90. rt_wlan_security_t security;
  91. char *ssid;
  92. uint8_t bssid[6];
  93. /* maximal data rate */
  94. uint32_t datarate;
  95. /* radio channel */
  96. uint16_t channel;
  97. /* signal strength */
  98. int16_t rssi;
  99. };
  100. struct rt_wlan_info_request
  101. {
  102. uint16_t req_number; /* the number of information item for request */
  103. uint16_t rsp_number; /* the number of information item for response */
  104. struct rt_wlan_info *infos;/* the array of information to save response */
  105. };
  106. struct rt_wlan_device;
  107. typedef void (*rt_wlan_event_handler)(struct rt_wlan_device* device, rt_wlan_event_t event, void* user_data);
  108. struct rt_wlan_device
  109. {
  110. struct eth_device parent;
  111. struct rt_wlan_info* info;
  112. char key[KEY_ARRAY_SIZE + 1];
  113. rt_wlan_event_handler handler;
  114. void* user_data;
  115. int interface;
  116. };
  117. /*
  118. * Wi-Fi Information APIs
  119. */
  120. void rt_wlan_info_init(struct rt_wlan_info* info, rt_wlan_mode_t mode, rt_wlan_security_t security,
  121. char *ssid);
  122. void rt_wlan_info_deinit(struct rt_wlan_info* info);
  123. /*
  124. * Wi-Fi Manager APIs
  125. */
  126. int rt_wlan_init(struct rt_wlan_device* device, rt_wlan_mode_t mode);
  127. int rt_wlan_connect(struct rt_wlan_device* device, struct rt_wlan_info* info,
  128. char *password);
  129. int rt_wlan_disconnect(struct rt_wlan_device* device);
  130. int rt_wlan_softap(struct rt_wlan_device* device, struct rt_wlan_info* info,
  131. char *password);
  132. /* set wifi information for AP */
  133. int rt_wlan_set_info(struct rt_wlan_device* device, struct rt_wlan_info* info);
  134. /* get wifi information for AP */
  135. struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device* device);
  136. /* get the AP result which were scaned in station */
  137. int rt_wlan_scan(struct rt_wlan_device* device, struct rt_wlan_info *infos, int item_sz);
  138. /* get rssi */
  139. int rt_wlan_get_rssi(struct rt_wlan_device* device);
  140. /* Get/Set MAC */
  141. int rt_wlan_get_mac(struct rt_wlan_device* device,rt_uint8_t hwaddr[6]);
  142. int rt_wlan_set_mac(struct rt_wlan_device* device,rt_uint8_t hwaddr[6]);
  143. /* enter power save level */
  144. int rt_wlan_enter_powersave(struct rt_wlan_device* device, int level);
  145. void rt_wlan_set_event_callback(struct rt_wlan_device* device, rt_wlan_event_handler handler,
  146. void *user_data);
  147. #endif