wlan_mgnt.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-08-06 tyx the first version
  9. */
  10. #ifndef __WLAN_MGNT_H__
  11. #define __WLAN_MGNT_H__
  12. #include <wlan_dev.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #ifndef RT_WLAN_SCAN_WAIT_MS
  17. #define RT_WLAN_SCAN_WAIT_MS (10 * 1000)
  18. #endif
  19. #ifndef RT_WLAN_SCAN_CACHE_NUM
  20. #define RT_WLAN_SCAN_CACHE_NUM (50)
  21. #endif
  22. #ifndef RT_WLAN_CONNECT_WAIT_MS
  23. #define RT_WLAN_CONNECT_WAIT_MS (10 * 1000)
  24. #endif
  25. #ifndef RT_WLAN_START_AP_WAIT_MS
  26. #define RT_WLAN_START_AP_WAIT_MS (10 * 1000)
  27. #endif
  28. #ifndef RT_WLAN_EBOX_NUM
  29. #define RT_WLAN_EBOX_NUM (10)
  30. #endif
  31. #ifndef RT_WLAN_SCAN_RETRY_CNT
  32. #define RT_WLAN_SCAN_RETRY_CNT (3)
  33. #endif
  34. /*state fot station*/
  35. #define RT_WLAN_STATE_CONNECT (1UL << 0)
  36. #define RT_WLAN_STATE_CONNECTING (1UL << 1)
  37. #define RT_WLAN_STATE_READY (1UL << 2)
  38. #define RT_WLAN_STATE_POWERSAVE (1UL << 3)
  39. /*flags fot station*/
  40. #define RT_WLAN_STATE_AUTOEN (1UL << 0)
  41. /*state fot ap*/
  42. #define RT_WLAN_STATE_ACTIVE (1UL << 0)
  43. typedef enum
  44. {
  45. RT_WLAN_EVT_READY = 0, /* connect and prot is ok, You can send data*/
  46. RT_WLAN_EVT_SCAN_DONE, /* Scan a info */
  47. RT_WLAN_EVT_SCAN_REPORT, /* Scan end */
  48. RT_WLAN_EVT_STA_CONNECTED, /* connect success */
  49. RT_WLAN_EVT_STA_CONNECTED_FAIL, /* connection failed */
  50. RT_WLAN_EVT_STA_DISCONNECTED, /* disconnect */
  51. RT_WLAN_EVT_AP_START, /* AP start */
  52. RT_WLAN_EVT_AP_STOP, /* AP stop */
  53. RT_WLAN_EVT_AP_ASSOCIATED, /* sta associated */
  54. RT_WLAN_EVT_AP_DISASSOCIATED, /* sta disassociated */
  55. RT_WLAN_EVT_MAX
  56. } rt_wlan_event_t;
  57. typedef void (*rt_wlan_event_handler)(int event, struct rt_wlan_buff *buff, void *parameter);
  58. struct rt_wlan_scan_result
  59. {
  60. rt_int32_t num;
  61. struct rt_wlan_info *info;
  62. };
  63. /*
  64. * wifi init interface
  65. */
  66. int rt_wlan_init(void);
  67. rt_err_t rt_wlan_set_mode(const char *dev_name, rt_wlan_mode_t mode);
  68. rt_wlan_mode_t rt_wlan_get_mode(const char *dev_name);
  69. /*
  70. * wifi station mode interface
  71. */
  72. rt_err_t rt_wlan_connect(const char *ssid, const char *password);
  73. rt_err_t rt_wlan_connect_adv(struct rt_wlan_info *info, const char *password);
  74. rt_err_t rt_wlan_disconnect(void);
  75. rt_bool_t rt_wlan_is_connected(void);
  76. rt_bool_t rt_wlan_is_ready(void);
  77. rt_err_t rt_wlan_set_mac(rt_uint8_t *mac);
  78. rt_err_t rt_wlan_get_mac(rt_uint8_t *mac);
  79. rt_err_t rt_wlan_get_info(struct rt_wlan_info *info);
  80. int rt_wlan_get_rssi(void);
  81. /*
  82. * wifi ap mode interface
  83. */
  84. rt_err_t rt_wlan_start_ap(const char *ssid, const char *password);
  85. rt_err_t rt_wlan_start_ap_adv(struct rt_wlan_info *info, const char *password);
  86. rt_bool_t rt_wlan_ap_is_active(void);
  87. rt_err_t rt_wlan_ap_stop(void);
  88. rt_err_t rt_wlan_ap_get_info(struct rt_wlan_info *info);
  89. int rt_wlan_ap_get_sta_num(void);
  90. int rt_wlan_ap_get_sta_info(struct rt_wlan_info *info, int num);
  91. rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac);
  92. rt_err_t rt_wlan_ap_set_country(rt_country_code_t country_code);
  93. rt_country_code_t rt_wlan_ap_get_country(void);
  94. /*
  95. * wifi scan interface
  96. */
  97. rt_err_t rt_wlan_scan(void);
  98. struct rt_wlan_scan_result *rt_wlan_scan_sync(void);
  99. struct rt_wlan_scan_result *rt_wlan_scan_with_info(struct rt_wlan_info *info);
  100. int rt_wlan_scan_get_info_num(void);
  101. int rt_wlan_scan_get_info(struct rt_wlan_info *info, int num);
  102. struct rt_wlan_scan_result *rt_wlan_scan_get_result(void);
  103. void rt_wlan_scan_result_clean(void);
  104. int rt_wlan_scan_find_cache(struct rt_wlan_info *info, struct rt_wlan_info *out_info, int num);
  105. rt_bool_t rt_wlan_find_best_by_cache(const char *ssid, struct rt_wlan_info *info);
  106. /*
  107. * wifi auto connect interface
  108. */
  109. void rt_wlan_config_autoreconnect(rt_bool_t enable);
  110. rt_bool_t rt_wlan_get_autoreconnect_mode(void);
  111. /*
  112. * wifi power management interface
  113. */
  114. rt_err_t rt_wlan_set_powersave(int level);
  115. int rt_wlan_get_powersave(void);
  116. /*
  117. * wifi event management interface
  118. */
  119. rt_err_t rt_wlan_register_event_handler(rt_wlan_event_t event, rt_wlan_event_handler handler, void *parameter);
  120. rt_err_t rt_wlan_unregister_event_handler(rt_wlan_event_t event);
  121. /*
  122. * wifi management lock interface
  123. */
  124. void rt_wlan_mgnt_lock(void);
  125. void rt_wlan_mgnt_unlock(void);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif