dev_wlan.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-08-03 tyx the first version
  9. * 2024-12-25 Evlers add get_info api for more new sta information
  10. * 2025-01-04 Evlers add ap_get_info api for more ap information
  11. */
  12. #ifndef __DEV_WLAN_DEVICE_H__
  13. #define __DEV_WLAN_DEVICE_H__
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #define RT_WLAN_DEV_VERSION 0x10001 /* 1.0.1 */
  18. typedef enum
  19. {
  20. RT_WLAN_NONE,
  21. RT_WLAN_STATION,
  22. RT_WLAN_AP,
  23. RT_WLAN_MODE_MAX
  24. } rt_wlan_mode_t;
  25. typedef enum
  26. {
  27. RT_WLAN_CMD_MODE = 0x10,
  28. RT_WLAN_CMD_SCAN, /* trigger scanning (list cells) */
  29. RT_WLAN_CMD_JOIN,
  30. RT_WLAN_CMD_SOFTAP, /* start soft-AP */
  31. RT_WLAN_CMD_DISCONNECT,
  32. RT_WLAN_CMD_AP_STOP, /* stop soft-AP */
  33. RT_WLAN_CMD_AP_DEAUTH,
  34. RT_WLAN_CMD_SCAN_STOP,
  35. RT_WLAN_CMD_GET_RSSI, /* get sensitivity (dBm) */
  36. RT_WLAN_CMD_GET_INFO, /* get information (rssi, channel, datarate.) */
  37. RT_WLAN_CMD_AP_GET_INFO, /* get ap information (bssid, security, channel.) */
  38. RT_WLAN_CMD_SET_POWERSAVE,
  39. RT_WLAN_CMD_GET_POWERSAVE,
  40. RT_WLAN_CMD_CFG_PROMISC, /* start/stop minitor */
  41. RT_WLAN_CMD_CFG_FILTER, /* start/stop frame filter */
  42. RT_WLAN_CMD_CFG_MGNT_FILTER, /* start/stop management frame filter */
  43. RT_WLAN_CMD_SET_CHANNEL,
  44. RT_WLAN_CMD_GET_CHANNEL,
  45. RT_WLAN_CMD_SET_COUNTRY,
  46. RT_WLAN_CMD_GET_COUNTRY,
  47. RT_WLAN_CMD_SET_MAC,
  48. RT_WLAN_CMD_GET_MAC,
  49. RT_WLAN_CMD_GET_FAST_CONNECT_INFO,
  50. RT_WLAN_CMD_FAST_CONNECT,
  51. } rt_wlan_cmd_t;
  52. typedef enum
  53. {
  54. RT_WLAN_DEV_EVT_INIT_DONE = 0,
  55. RT_WLAN_DEV_EVT_CONNECT,
  56. RT_WLAN_DEV_EVT_CONNECT_FAIL,
  57. RT_WLAN_DEV_EVT_DISCONNECT,
  58. RT_WLAN_DEV_EVT_AP_START,
  59. RT_WLAN_DEV_EVT_AP_STOP,
  60. RT_WLAN_DEV_EVT_AP_ASSOCIATED,
  61. RT_WLAN_DEV_EVT_AP_DISASSOCIATED,
  62. RT_WLAN_DEV_EVT_AP_ASSOCIATE_FAILED,
  63. RT_WLAN_DEV_EVT_SCAN_REPORT,
  64. RT_WLAN_DEV_EVT_SCAN_DONE,
  65. RT_WLAN_DEV_EVT_MAX,
  66. } rt_wlan_dev_event_t;
  67. #define SHARED_ENABLED 0x00008000
  68. #define WPA_SECURITY 0x00200000
  69. #define WPA2_SECURITY 0x00400000
  70. #define WPS_ENABLED 0x10000000
  71. #define WEP_ENABLED 0x0001
  72. #define TKIP_ENABLED 0x0002
  73. #define AES_ENABLED 0x0004
  74. #define WSEC_SWFLAG 0x0008
  75. #define RT_WLAN_FLAG_STA_ONLY (0x1 << 0)
  76. #define RT_WLAN_FLAG_AP_ONLY (0x1 << 1)
  77. #ifndef RT_WLAN_SSID_MAX_LENGTH
  78. #define RT_WLAN_SSID_MAX_LENGTH (32) /* SSID MAX LEN */
  79. #endif
  80. #ifndef RT_WLAN_BSSID_MAX_LENGTH
  81. #define RT_WLAN_BSSID_MAX_LENGTH (6) /* BSSID MAX LEN (default is 6) */
  82. #endif
  83. #ifndef RT_WLAN_PASSWORD_MAX_LENGTH
  84. #define RT_WLAN_PASSWORD_MAX_LENGTH (32) /* PASSWORD MAX LEN*/
  85. #endif
  86. #ifndef RT_WLAN_DEV_EVENT_NUM
  87. #define RT_WLAN_DEV_EVENT_NUM (2) /* EVENT GROUP MAX NUM */
  88. #endif
  89. /**
  90. * Enumeration of Wi-Fi security modes
  91. */
  92. typedef enum
  93. {
  94. SECURITY_OPEN = 0, /* Open security */
  95. SECURITY_WEP_PSK = WEP_ENABLED, /* WEP Security with open authentication */
  96. SECURITY_WEP_SHARED = (WEP_ENABLED | SHARED_ENABLED), /* WEP Security with shared authentication */
  97. SECURITY_WPA_TKIP_PSK = (WPA_SECURITY | TKIP_ENABLED), /* WPA Security with TKIP */
  98. SECURITY_WPA_AES_PSK = (WPA_SECURITY | AES_ENABLED), /* WPA Security with AES */
  99. SECURITY_WPA2_AES_PSK = (WPA2_SECURITY | AES_ENABLED), /* WPA2 Security with AES */
  100. SECURITY_WPA2_TKIP_PSK = (WPA2_SECURITY | TKIP_ENABLED), /* WPA2 Security with TKIP */
  101. SECURITY_WPA2_MIXED_PSK = (WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED), /* WPA2 Security with AES & TKIP */
  102. SECURITY_WPS_OPEN = WPS_ENABLED, /* WPS with open security */
  103. SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /* WPS with AES security */
  104. SECURITY_UNKNOWN = -1, /* May be returned by scan function if security is unknown.
  105. Do not pass this to the join function! */
  106. } rt_wlan_security_t;
  107. typedef enum
  108. {
  109. RT_802_11_BAND_5GHZ = 0, /* Denotes 5GHz radio band */
  110. RT_802_11_BAND_2_4GHZ = 1, /* Denotes 2.4GHz radio band */
  111. RT_802_11_BAND_UNKNOWN = 0x7fffffff, /* unknown */
  112. } rt_802_11_band_t;
  113. typedef enum
  114. {
  115. RT_COUNTRY_AFGHANISTAN,
  116. RT_COUNTRY_ALBANIA,
  117. RT_COUNTRY_ALGERIA,
  118. RT_COUNTRY_AMERICAN_SAMOA,
  119. RT_COUNTRY_ANGOLA,
  120. RT_COUNTRY_ANGUILLA,
  121. RT_COUNTRY_ANTIGUA_AND_BARBUDA,
  122. RT_COUNTRY_ARGENTINA,
  123. RT_COUNTRY_ARMENIA,
  124. RT_COUNTRY_ARUBA,
  125. RT_COUNTRY_AUSTRALIA,
  126. RT_COUNTRY_AUSTRIA,
  127. RT_COUNTRY_AZERBAIJAN,
  128. RT_COUNTRY_BAHAMAS,
  129. RT_COUNTRY_BAHRAIN,
  130. RT_COUNTRY_BAKER_ISLAND,
  131. RT_COUNTRY_BANGLADESH,
  132. RT_COUNTRY_BARBADOS,
  133. RT_COUNTRY_BELARUS,
  134. RT_COUNTRY_BELGIUM,
  135. RT_COUNTRY_BELIZE,
  136. RT_COUNTRY_BENIN,
  137. RT_COUNTRY_BERMUDA,
  138. RT_COUNTRY_BHUTAN,
  139. RT_COUNTRY_BOLIVIA,
  140. RT_COUNTRY_BOSNIA_AND_HERZEGOVINA,
  141. RT_COUNTRY_BOTSWANA,
  142. RT_COUNTRY_BRAZIL,
  143. RT_COUNTRY_BRITISH_INDIAN_OCEAN_TERRITORY,
  144. RT_COUNTRY_BRUNEI_DARUSSALAM,
  145. RT_COUNTRY_BULGARIA,
  146. RT_COUNTRY_BURKINA_FASO,
  147. RT_COUNTRY_BURUNDI,
  148. RT_COUNTRY_CAMBODIA,
  149. RT_COUNTRY_CAMEROON,
  150. RT_COUNTRY_CANADA,
  151. RT_COUNTRY_CAPE_VERDE,
  152. RT_COUNTRY_CAYMAN_ISLANDS,
  153. RT_COUNTRY_CENTRAL_AFRICAN_REPUBLIC,
  154. RT_COUNTRY_CHAD,
  155. RT_COUNTRY_CHILE,
  156. RT_COUNTRY_CHINA,
  157. RT_COUNTRY_CHRISTMAS_ISLAND,
  158. RT_COUNTRY_COLOMBIA,
  159. RT_COUNTRY_COMOROS,
  160. RT_COUNTRY_CONGO,
  161. RT_COUNTRY_CONGO_THE_DEMOCRATIC_REPUBLIC_OF_THE,
  162. RT_COUNTRY_COSTA_RICA,
  163. RT_COUNTRY_COTE_DIVOIRE,
  164. RT_COUNTRY_CROATIA,
  165. RT_COUNTRY_CUBA,
  166. RT_COUNTRY_CYPRUS,
  167. RT_COUNTRY_CZECH_REPUBLIC,
  168. RT_COUNTRY_DENMARK,
  169. RT_COUNTRY_DJIBOUTI,
  170. RT_COUNTRY_DOMINICA,
  171. RT_COUNTRY_DOMINICAN_REPUBLIC,
  172. RT_COUNTRY_DOWN_UNDER,
  173. RT_COUNTRY_ECUADOR,
  174. RT_COUNTRY_EGYPT,
  175. RT_COUNTRY_EL_SALVADOR,
  176. RT_COUNTRY_EQUATORIAL_GUINEA,
  177. RT_COUNTRY_ERITREA,
  178. RT_COUNTRY_ESTONIA,
  179. RT_COUNTRY_ETHIOPIA,
  180. RT_COUNTRY_FALKLAND_ISLANDS_MALVINAS,
  181. RT_COUNTRY_FAROE_ISLANDS,
  182. RT_COUNTRY_FIJI,
  183. RT_COUNTRY_FINLAND,
  184. RT_COUNTRY_FRANCE,
  185. RT_COUNTRY_FRENCH_GUINA,
  186. RT_COUNTRY_FRENCH_POLYNESIA,
  187. RT_COUNTRY_FRENCH_SOUTHERN_TERRITORIES,
  188. RT_COUNTRY_GABON,
  189. RT_COUNTRY_GAMBIA,
  190. RT_COUNTRY_GEORGIA,
  191. RT_COUNTRY_GERMANY,
  192. RT_COUNTRY_GHANA,
  193. RT_COUNTRY_GIBRALTAR,
  194. RT_COUNTRY_GREECE,
  195. RT_COUNTRY_GRENADA,
  196. RT_COUNTRY_GUADELOUPE,
  197. RT_COUNTRY_GUAM,
  198. RT_COUNTRY_GUATEMALA,
  199. RT_COUNTRY_GUERNSEY,
  200. RT_COUNTRY_GUINEA,
  201. RT_COUNTRY_GUINEA_BISSAU,
  202. RT_COUNTRY_GUYANA,
  203. RT_COUNTRY_HAITI,
  204. RT_COUNTRY_HOLY_SEE_VATICAN_CITY_STATE,
  205. RT_COUNTRY_HONDURAS,
  206. RT_COUNTRY_HONG_KONG,
  207. RT_COUNTRY_HUNGARY,
  208. RT_COUNTRY_ICELAND,
  209. RT_COUNTRY_INDIA,
  210. RT_COUNTRY_INDONESIA,
  211. RT_COUNTRY_IRAN_ISLAMIC_REPUBLIC_OF,
  212. RT_COUNTRY_IRAQ,
  213. RT_COUNTRY_IRELAND,
  214. RT_COUNTRY_ISRAEL,
  215. RT_COUNTRY_ITALY,
  216. RT_COUNTRY_JAMAICA,
  217. RT_COUNTRY_JAPAN,
  218. RT_COUNTRY_JERSEY,
  219. RT_COUNTRY_JORDAN,
  220. RT_COUNTRY_KAZAKHSTAN,
  221. RT_COUNTRY_KENYA,
  222. RT_COUNTRY_KIRIBATI,
  223. RT_COUNTRY_KOREA_REPUBLIC_OF,
  224. RT_COUNTRY_KOSOVO,
  225. RT_COUNTRY_KUWAIT,
  226. RT_COUNTRY_KYRGYZSTAN,
  227. RT_COUNTRY_LAO_PEOPLES_DEMOCRATIC_REPUBIC,
  228. RT_COUNTRY_LATVIA,
  229. RT_COUNTRY_LEBANON,
  230. RT_COUNTRY_LESOTHO,
  231. RT_COUNTRY_LIBERIA,
  232. RT_COUNTRY_LIBYAN_ARAB_JAMAHIRIYA,
  233. RT_COUNTRY_LIECHTENSTEIN,
  234. RT_COUNTRY_LITHUANIA,
  235. RT_COUNTRY_LUXEMBOURG,
  236. RT_COUNTRY_MACAO,
  237. RT_COUNTRY_MACEDONIA_FORMER_YUGOSLAV_REPUBLIC_OF,
  238. RT_COUNTRY_MADAGASCAR,
  239. RT_COUNTRY_MALAWI,
  240. RT_COUNTRY_MALAYSIA,
  241. RT_COUNTRY_MALDIVES,
  242. RT_COUNTRY_MALI,
  243. RT_COUNTRY_MALTA,
  244. RT_COUNTRY_MAN_ISLE_OF,
  245. RT_COUNTRY_MARTINIQUE,
  246. RT_COUNTRY_MAURITANIA,
  247. RT_COUNTRY_MAURITIUS,
  248. RT_COUNTRY_MAYOTTE,
  249. RT_COUNTRY_MEXICO,
  250. RT_COUNTRY_MICRONESIA_FEDERATED_STATES_OF,
  251. RT_COUNTRY_MOLDOVA_REPUBLIC_OF,
  252. RT_COUNTRY_MONACO,
  253. RT_COUNTRY_MONGOLIA,
  254. RT_COUNTRY_MONTENEGRO,
  255. RT_COUNTRY_MONTSERRAT,
  256. RT_COUNTRY_MOROCCO,
  257. RT_COUNTRY_MOZAMBIQUE,
  258. RT_COUNTRY_MYANMAR,
  259. RT_COUNTRY_NAMIBIA,
  260. RT_COUNTRY_NAURU,
  261. RT_COUNTRY_NEPAL,
  262. RT_COUNTRY_NETHERLANDS,
  263. RT_COUNTRY_NETHERLANDS_ANTILLES,
  264. RT_COUNTRY_NEW_CALEDONIA,
  265. RT_COUNTRY_NEW_ZEALAND,
  266. RT_COUNTRY_NICARAGUA,
  267. RT_COUNTRY_NIGER,
  268. RT_COUNTRY_NIGERIA,
  269. RT_COUNTRY_NORFOLK_ISLAND,
  270. RT_COUNTRY_NORTHERN_MARIANA_ISLANDS,
  271. RT_COUNTRY_NORWAY,
  272. RT_COUNTRY_OMAN,
  273. RT_COUNTRY_PAKISTAN,
  274. RT_COUNTRY_PALAU,
  275. RT_COUNTRY_PANAMA,
  276. RT_COUNTRY_PAPUA_NEW_GUINEA,
  277. RT_COUNTRY_PARAGUAY,
  278. RT_COUNTRY_PERU,
  279. RT_COUNTRY_PHILIPPINES,
  280. RT_COUNTRY_POLAND,
  281. RT_COUNTRY_PORTUGAL,
  282. RT_COUNTRY_PUETO_RICO,
  283. RT_COUNTRY_QATAR,
  284. RT_COUNTRY_REUNION,
  285. RT_COUNTRY_ROMANIA,
  286. RT_COUNTRY_RUSSIAN_FEDERATION,
  287. RT_COUNTRY_RWANDA,
  288. RT_COUNTRY_SAINT_KITTS_AND_NEVIS,
  289. RT_COUNTRY_SAINT_LUCIA,
  290. RT_COUNTRY_SAINT_PIERRE_AND_MIQUELON,
  291. RT_COUNTRY_SAINT_VINCENT_AND_THE_GRENADINES,
  292. RT_COUNTRY_SAMOA,
  293. RT_COUNTRY_SANIT_MARTIN_SINT_MARTEEN,
  294. RT_COUNTRY_SAO_TOME_AND_PRINCIPE,
  295. RT_COUNTRY_SAUDI_ARABIA,
  296. RT_COUNTRY_SENEGAL,
  297. RT_COUNTRY_SERBIA,
  298. RT_COUNTRY_SEYCHELLES,
  299. RT_COUNTRY_SIERRA_LEONE,
  300. RT_COUNTRY_SINGAPORE,
  301. RT_COUNTRY_SLOVAKIA,
  302. RT_COUNTRY_SLOVENIA,
  303. RT_COUNTRY_SOLOMON_ISLANDS,
  304. RT_COUNTRY_SOMALIA,
  305. RT_COUNTRY_SOUTH_AFRICA,
  306. RT_COUNTRY_SPAIN,
  307. RT_COUNTRY_SRI_LANKA,
  308. RT_COUNTRY_SURINAME,
  309. RT_COUNTRY_SWAZILAND,
  310. RT_COUNTRY_SWEDEN,
  311. RT_COUNTRY_SWITZERLAND,
  312. RT_COUNTRY_SYRIAN_ARAB_REPUBLIC,
  313. RT_COUNTRY_TAIWAN_PROVINCE_OF_CHINA,
  314. RT_COUNTRY_TAJIKISTAN,
  315. RT_COUNTRY_TANZANIA_UNITED_REPUBLIC_OF,
  316. RT_COUNTRY_THAILAND,
  317. RT_COUNTRY_TOGO,
  318. RT_COUNTRY_TONGA,
  319. RT_COUNTRY_TRINIDAD_AND_TOBAGO,
  320. RT_COUNTRY_TUNISIA,
  321. RT_COUNTRY_TURKEY,
  322. RT_COUNTRY_TURKMENISTAN,
  323. RT_COUNTRY_TURKS_AND_CAICOS_ISLANDS,
  324. RT_COUNTRY_TUVALU,
  325. RT_COUNTRY_UGANDA,
  326. RT_COUNTRY_UKRAINE,
  327. RT_COUNTRY_UNITED_ARAB_EMIRATES,
  328. RT_COUNTRY_UNITED_KINGDOM,
  329. RT_COUNTRY_UNITED_STATES,
  330. RT_COUNTRY_UNITED_STATES_REV4,
  331. RT_COUNTRY_UNITED_STATES_NO_DFS,
  332. RT_COUNTRY_UNITED_STATES_MINOR_OUTLYING_ISLANDS,
  333. RT_COUNTRY_URUGUAY,
  334. RT_COUNTRY_UZBEKISTAN,
  335. RT_COUNTRY_VANUATU,
  336. RT_COUNTRY_VENEZUELA,
  337. RT_COUNTRY_VIET_NAM,
  338. RT_COUNTRY_VIRGIN_ISLANDS_BRITISH,
  339. RT_COUNTRY_VIRGIN_ISLANDS_US,
  340. RT_COUNTRY_WALLIS_AND_FUTUNA,
  341. RT_COUNTRY_WEST_BANK,
  342. RT_COUNTRY_WESTERN_SAHARA,
  343. RT_COUNTRY_WORLD_WIDE_XX,
  344. RT_COUNTRY_YEMEN,
  345. RT_COUNTRY_ZAMBIA,
  346. RT_COUNTRY_ZIMBABWE,
  347. RT_COUNTRY_UNKNOWN
  348. } rt_country_code_t;
  349. struct rt_wlan_device;
  350. struct rt_wlan_buff;
  351. typedef void (*rt_wlan_dev_event_handler)(struct rt_wlan_device *device, rt_wlan_dev_event_t event, struct rt_wlan_buff *buff, void *parameter);
  352. typedef void (*rt_wlan_pormisc_callback_t)(struct rt_wlan_device *device, void *data, int len);
  353. typedef void (*rt_wlan_mgnt_filter_callback_t)(struct rt_wlan_device *device, void *data, int len);
  354. struct rt_wlan_ssid
  355. {
  356. rt_uint8_t len;
  357. rt_uint8_t val[RT_WLAN_SSID_MAX_LENGTH + 1];
  358. };
  359. typedef struct rt_wlan_ssid rt_wlan_ssid_t;
  360. struct rt_wlan_key
  361. {
  362. rt_uint8_t len;
  363. rt_uint8_t val[RT_WLAN_PASSWORD_MAX_LENGTH + 1];
  364. };
  365. typedef struct rt_wlan_key rt_wlan_key_t;
  366. #define INVALID_INFO(_info) do { \
  367. rt_memset((_info), 0, sizeof(struct rt_wlan_info)); \
  368. (_info)->band = RT_802_11_BAND_UNKNOWN; \
  369. (_info)->security = SECURITY_UNKNOWN; \
  370. (_info)->channel = -1; \
  371. } while(0)
  372. #define SSID_SET(_info, _ssid) do { \
  373. rt_strncpy((char *)(_info)->ssid.val, (_ssid), RT_WLAN_SSID_MAX_LENGTH); \
  374. (_info)->ssid.len = rt_strlen((char *)(_info)->ssid.val); \
  375. } while(0)
  376. struct rt_wlan_info
  377. {
  378. /* security type */
  379. rt_wlan_security_t security;
  380. /* 2.4G/5G */
  381. rt_802_11_band_t band;
  382. /* maximal data rate */
  383. rt_uint32_t datarate;
  384. /* radio channel */
  385. rt_int16_t channel;
  386. /* signal strength */
  387. rt_int16_t rssi;
  388. /* ssid */
  389. rt_wlan_ssid_t ssid;
  390. /* hwaddr */
  391. rt_uint8_t bssid[RT_WLAN_BSSID_MAX_LENGTH];
  392. rt_uint8_t hidden;
  393. };
  394. struct rt_wlan_buff
  395. {
  396. void *data;
  397. rt_int32_t len;
  398. };
  399. struct rt_filter_pattern
  400. {
  401. rt_uint16_t offset; /* Offset in bytes to start filtering (referenced to the start of the ethernet packet) */
  402. rt_uint16_t mask_size; /* Size of the mask in bytes */
  403. rt_uint8_t *mask; /* Pattern mask bytes to be ANDed with the pattern eg. "\xff00" (must be in network byte order) */
  404. rt_uint8_t *pattern; /* Pattern bytes used to filter eg. "\x0800" (must be in network byte order) */
  405. };
  406. typedef enum
  407. {
  408. RT_POSITIVE_MATCHING = 0, /* Receive the data matching with this pattern and discard the other data */
  409. RT_NEGATIVE_MATCHING = 1 /* Discard the data matching with this pattern and receive the other data */
  410. } rt_filter_rule_t;
  411. struct rt_wlan_filter
  412. {
  413. struct rt_filter_pattern patt;
  414. rt_filter_rule_t rule;
  415. rt_uint8_t enable;
  416. };
  417. struct rt_wlan_dev_event_desc
  418. {
  419. rt_wlan_dev_event_handler handler;
  420. void *parameter;
  421. };
  422. struct rt_wlan_device
  423. {
  424. struct rt_device device;
  425. rt_wlan_mode_t mode;
  426. struct rt_mutex lock;
  427. struct rt_wlan_dev_event_desc handler_table[RT_WLAN_DEV_EVT_MAX][RT_WLAN_DEV_EVENT_NUM];
  428. rt_wlan_pormisc_callback_t pormisc_callback;
  429. rt_wlan_mgnt_filter_callback_t mgnt_filter_callback;
  430. const struct rt_wlan_dev_ops *ops;
  431. rt_uint32_t flags;
  432. struct netdev *netdev;
  433. void *prot;
  434. void *user_data;
  435. };
  436. struct rt_sta_info
  437. {
  438. rt_wlan_ssid_t ssid;
  439. rt_wlan_key_t key;
  440. rt_uint8_t bssid[6];
  441. rt_uint16_t channel;
  442. rt_wlan_security_t security;
  443. };
  444. struct rt_ap_info
  445. {
  446. rt_wlan_ssid_t ssid;
  447. rt_wlan_key_t key;
  448. rt_bool_t hidden;
  449. rt_uint16_t channel;
  450. rt_wlan_security_t security;
  451. };
  452. struct rt_scan_info
  453. {
  454. rt_wlan_ssid_t ssid;
  455. rt_uint8_t bssid[6];
  456. rt_int16_t channel_min;
  457. rt_int16_t channel_max;
  458. rt_bool_t passive;
  459. };
  460. struct rt_wlan_dev_ops
  461. {
  462. rt_err_t (*wlan_init)(struct rt_wlan_device *wlan);
  463. rt_err_t (*wlan_mode)(struct rt_wlan_device *wlan, rt_wlan_mode_t mode);
  464. rt_err_t (*wlan_scan)(struct rt_wlan_device *wlan, struct rt_scan_info *scan_info);
  465. rt_err_t (*wlan_join)(struct rt_wlan_device *wlan, struct rt_sta_info *sta_info);
  466. rt_err_t (*wlan_softap)(struct rt_wlan_device *wlan, struct rt_ap_info *ap_info);
  467. rt_err_t (*wlan_disconnect)(struct rt_wlan_device *wlan);
  468. rt_err_t (*wlan_ap_stop)(struct rt_wlan_device *wlan);
  469. rt_err_t (*wlan_ap_deauth)(struct rt_wlan_device *wlan, rt_uint8_t mac[]);
  470. rt_err_t (*wlan_scan_stop)(struct rt_wlan_device *wlan);
  471. int (*wlan_get_rssi)(struct rt_wlan_device *wlan);
  472. int (*wlan_get_info)(struct rt_wlan_device *wlan, struct rt_wlan_info *info);
  473. int (*wlan_ap_get_info)(struct rt_wlan_device *wlan, struct rt_wlan_info *info);
  474. rt_err_t (*wlan_set_powersave)(struct rt_wlan_device *wlan, int level);
  475. int (*wlan_get_powersave)(struct rt_wlan_device *wlan);
  476. rt_err_t (*wlan_cfg_promisc)(struct rt_wlan_device *wlan, rt_bool_t start);
  477. rt_err_t (*wlan_cfg_filter)(struct rt_wlan_device *wlan, struct rt_wlan_filter *filter);
  478. rt_err_t (*wlan_cfg_mgnt_filter)(struct rt_wlan_device *wlan, rt_bool_t start);
  479. rt_err_t (*wlan_set_channel)(struct rt_wlan_device *wlan, int channel);
  480. int (*wlan_get_channel)(struct rt_wlan_device *wlan);
  481. rt_err_t (*wlan_set_country)(struct rt_wlan_device *wlan, rt_country_code_t country_code);
  482. rt_country_code_t (*wlan_get_country)(struct rt_wlan_device *wlan);
  483. rt_err_t (*wlan_set_mac)(struct rt_wlan_device *wlan, rt_uint8_t mac[]);
  484. rt_err_t (*wlan_get_mac)(struct rt_wlan_device *wlan, rt_uint8_t mac[]);
  485. int (*wlan_recv)(struct rt_wlan_device *wlan, void *buff, int len);
  486. int (*wlan_send)(struct rt_wlan_device *wlan, void *buff, int len);
  487. int (*wlan_send_raw_frame)(struct rt_wlan_device *wlan, void *buff, int len);
  488. int (*wlan_get_fast_info)(void *data);
  489. rt_err_t (*wlan_fast_connect)(void *data,rt_int32_t len);
  490. };
  491. /*
  492. * wlan device init
  493. */
  494. rt_err_t rt_wlan_dev_init(struct rt_wlan_device *device, rt_wlan_mode_t mode);
  495. /*
  496. * wlan device station interface
  497. */
  498. rt_err_t rt_wlan_dev_connect(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len);
  499. rt_err_t rt_wlan_dev_fast_connect(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len);
  500. rt_err_t rt_wlan_dev_disconnect(struct rt_wlan_device *device);
  501. int rt_wlan_dev_get_rssi(struct rt_wlan_device *device);
  502. rt_err_t rt_wlan_dev_get_info(struct rt_wlan_device *device, struct rt_wlan_info *info);
  503. /*
  504. * wlan device ap interface
  505. */
  506. rt_err_t rt_wlan_dev_ap_start(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len);
  507. rt_err_t rt_wlan_dev_ap_stop(struct rt_wlan_device *device);
  508. rt_err_t rt_wlan_dev_ap_deauth(struct rt_wlan_device *device, rt_uint8_t mac[6]);
  509. rt_err_t rt_wlan_dev_ap_get_info(struct rt_wlan_device *device, struct rt_wlan_info *info);
  510. /*
  511. * wlan device scan interface
  512. */
  513. rt_err_t rt_wlan_dev_scan(struct rt_wlan_device *device, struct rt_wlan_info *info);
  514. rt_err_t rt_wlan_dev_scan_stop(struct rt_wlan_device *device);
  515. /*
  516. * wlan device mac interface
  517. */
  518. rt_err_t rt_wlan_dev_get_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]);
  519. rt_err_t rt_wlan_dev_set_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]);
  520. /*
  521. * wlan device powersave interface
  522. */
  523. rt_err_t rt_wlan_dev_set_powersave(struct rt_wlan_device *device, int level);
  524. int rt_wlan_dev_get_powersave(struct rt_wlan_device *device);
  525. /*
  526. * wlan device event interface
  527. */
  528. rt_err_t rt_wlan_dev_register_event_handler(struct rt_wlan_device *device, rt_wlan_dev_event_t event, rt_wlan_dev_event_handler handler, void *parameter);
  529. rt_err_t rt_wlan_dev_unregister_event_handler(struct rt_wlan_device *device, rt_wlan_dev_event_t event, rt_wlan_dev_event_handler handler);
  530. void rt_wlan_dev_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_dev_event_t event, struct rt_wlan_buff *buff);
  531. /*
  532. * wlan device promisc interface
  533. */
  534. rt_err_t rt_wlan_dev_enter_promisc(struct rt_wlan_device *device);
  535. rt_err_t rt_wlan_dev_exit_promisc(struct rt_wlan_device *device);
  536. rt_err_t rt_wlan_dev_set_promisc_callback(struct rt_wlan_device *device, rt_wlan_pormisc_callback_t callback);
  537. void rt_wlan_dev_promisc_handler(struct rt_wlan_device *device, void *data, int len);
  538. /*
  539. * wlan device filter interface
  540. */
  541. rt_err_t rt_wlan_dev_cfg_filter(struct rt_wlan_device *device, struct rt_wlan_filter *filter);
  542. /*
  543. * wlan device channel interface
  544. */
  545. rt_err_t rt_wlan_dev_set_channel(struct rt_wlan_device *device, int channel);
  546. int rt_wlan_dev_get_channel(struct rt_wlan_device *device);
  547. /*
  548. * wlan device country interface
  549. */
  550. rt_err_t rt_wlan_dev_set_country(struct rt_wlan_device *device, rt_country_code_t country_code);
  551. rt_country_code_t rt_wlan_dev_get_country(struct rt_wlan_device *device);
  552. /*
  553. * wlan device datat transfer interface
  554. */
  555. rt_err_t rt_wlan_dev_report_data(struct rt_wlan_device *device, void *buff, int len);
  556. // void rt_wlan_dev_data_ready(struct rt_wlan_device *device, int len);
  557. /*
  558. * wlan device register interface
  559. */
  560. rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name,
  561. const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data);
  562. #ifdef __cplusplus
  563. }
  564. #endif
  565. #endif