dev_wlan_mgnt.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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-06 tyx the first version
  9. */
  10. #ifndef __DEV_WLAN_MGNT_H__
  11. #define __DEV_WLAN_MGNT_H__
  12. #include <dev_wlan.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. #ifndef AUTO_CONNECTION_PERIOD_MS
  35. #define AUTO_CONNECTION_PERIOD_MS (2000)
  36. #endif
  37. /*state fot station*/
  38. #define RT_WLAN_STATE_CONNECT (1UL << 0)
  39. #define RT_WLAN_STATE_CONNECTING (1UL << 1)
  40. #define RT_WLAN_STATE_READY (1UL << 2)
  41. #define RT_WLAN_STATE_POWERSAVE (1UL << 3)
  42. /*flags fot station*/
  43. #define RT_WLAN_STATE_AUTOEN (1UL << 0)
  44. /*state fot ap*/
  45. #define RT_WLAN_STATE_ACTIVE (1UL << 0)
  46. typedef enum
  47. {
  48. RT_WLAN_EVT_READY = 0, /* connect and prot is ok, You can send data*/
  49. RT_WLAN_EVT_SCAN_DONE, /* Scan end */
  50. RT_WLAN_EVT_SCAN_REPORT, /* Scan a info */
  51. RT_WLAN_EVT_STA_CONNECTED, /* connect success */
  52. RT_WLAN_EVT_STA_CONNECTED_FAIL, /* connection failed */
  53. RT_WLAN_EVT_STA_DISCONNECTED, /* disconnect */
  54. RT_WLAN_EVT_AP_START, /* AP start */
  55. RT_WLAN_EVT_AP_STOP, /* AP stop */
  56. RT_WLAN_EVT_AP_ASSOCIATED, /* sta associated */
  57. RT_WLAN_EVT_AP_DISASSOCIATED, /* sta disassociated */
  58. RT_WLAN_EVT_MAX
  59. } rt_wlan_event_t;
  60. typedef void (*rt_wlan_event_handler)(int event, struct rt_wlan_buff *buff, void *parameter);
  61. struct rt_wlan_scan_result
  62. {
  63. rt_int32_t num;
  64. struct rt_wlan_info *info;
  65. };
  66. /*
  67. * wifi init interface
  68. */
  69. int rt_wlan_init(void);
  70. rt_err_t rt_wlan_set_mode(const char *dev_name, rt_wlan_mode_t mode);
  71. rt_wlan_mode_t rt_wlan_get_mode(const char *dev_name);
  72. /*
  73. * wifi station mode interface
  74. */
  75. rt_err_t rt_wlan_connect(const char *ssid, const char *password);
  76. rt_err_t rt_wlan_connect_adv(struct rt_wlan_info *info, const char *password);
  77. rt_err_t rt_wlan_disconnect(void);
  78. rt_bool_t rt_wlan_is_connected(void);
  79. rt_bool_t rt_wlan_is_ready(void);
  80. rt_err_t rt_wlan_set_mac(rt_uint8_t *mac);
  81. rt_err_t rt_wlan_get_mac(rt_uint8_t *mac);
  82. rt_err_t rt_wlan_get_info(struct rt_wlan_info *info);
  83. int rt_wlan_get_rssi(void);
  84. /*
  85. * wifi ap mode interface
  86. */
  87. rt_err_t rt_wlan_start_ap(const char *ssid, const char *password);
  88. rt_err_t rt_wlan_start_ap_adv(struct rt_wlan_info *info, const char *password);
  89. rt_bool_t rt_wlan_ap_is_active(void);
  90. rt_err_t rt_wlan_ap_stop(void);
  91. rt_err_t rt_wlan_ap_get_info(struct rt_wlan_info *info);
  92. int rt_wlan_ap_get_sta_num(void);
  93. int rt_wlan_ap_get_sta_info(struct rt_wlan_info *info, int num);
  94. rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac);
  95. rt_err_t rt_wlan_ap_set_country(rt_country_code_t country_code);
  96. rt_country_code_t rt_wlan_ap_get_country(void);
  97. /*
  98. * wifi scan interface
  99. */
  100. rt_err_t rt_wlan_scan(void);
  101. struct rt_wlan_scan_result *rt_wlan_scan_sync(void);
  102. rt_err_t rt_wlan_scan_with_info(struct rt_wlan_info *info);
  103. /*
  104. * wifi auto connect interface
  105. */
  106. void rt_wlan_config_autoreconnect(rt_bool_t enable);
  107. rt_bool_t rt_wlan_get_autoreconnect_mode(void);
  108. /*
  109. * wifi power management interface
  110. */
  111. rt_err_t rt_wlan_set_powersave(int level);
  112. int rt_wlan_get_powersave(void);
  113. /*
  114. * wifi event management interface
  115. */
  116. rt_err_t rt_wlan_register_event_handler(rt_wlan_event_t event, rt_wlan_event_handler handler, void *parameter);
  117. rt_err_t rt_wlan_unregister_event_handler(rt_wlan_event_t event);
  118. /*
  119. * wifi management lock interface
  120. */
  121. void rt_wlan_mgnt_lock(void);
  122. void rt_wlan_mgnt_unlock(void);
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif