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 
11 #ifndef __DEV_WLAN_MGNT_H__
12 #define __DEV_WLAN_MGNT_H__
13 
14 #include <dev_wlan.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #ifndef RT_WLAN_SCAN_WAIT_MS
21 #define RT_WLAN_SCAN_WAIT_MS       (10 * 1000)
22 #endif
23 
24 #ifndef RT_WLAN_SCAN_CACHE_NUM
25 #define RT_WLAN_SCAN_CACHE_NUM     (50)
26 #endif
27 
28 #ifndef RT_WLAN_CONNECT_WAIT_MS
29 #define RT_WLAN_CONNECT_WAIT_MS    (10 * 1000)
30 #endif
31 
32 #ifndef RT_WLAN_START_AP_WAIT_MS
33 #define RT_WLAN_START_AP_WAIT_MS    (10 * 1000)
34 #endif
35 
36 #ifndef RT_WLAN_EBOX_NUM
37 #define RT_WLAN_EBOX_NUM           (10)
38 #endif
39 
40 #ifndef RT_WLAN_SCAN_RETRY_CNT
41 #define RT_WLAN_SCAN_RETRY_CNT      (3)
42 #endif
43 
44 #ifndef AUTO_CONNECTION_PERIOD_MS
45 #define AUTO_CONNECTION_PERIOD_MS (2000)
46 #endif
47 
48 /*state fot station*/
49 #define RT_WLAN_STATE_CONNECT     (1UL << 0)
50 #define RT_WLAN_STATE_CONNECTING  (1UL << 1)
51 #define RT_WLAN_STATE_READY       (1UL << 2)
52 #define RT_WLAN_STATE_POWERSAVE   (1UL << 3)
53 
54 /*flags fot station*/
55 #define RT_WLAN_STATE_AUTOEN      (1UL << 0)
56 
57 /*state fot ap*/
58 #define RT_WLAN_STATE_ACTIVE      (1UL << 0)
59 
60 typedef enum
61 {
62     RT_WLAN_EVT_READY = 0,              /* connect and prot is ok, You can send data*/
63     RT_WLAN_EVT_SCAN_DONE,              /* Scan end */
64     RT_WLAN_EVT_SCAN_REPORT,            /* Scan a info */
65     RT_WLAN_EVT_STA_CONNECTED,          /* connect success */
66     RT_WLAN_EVT_STA_CONNECTED_FAIL,     /* connection failed */
67     RT_WLAN_EVT_STA_DISCONNECTED,       /* disconnect */
68     RT_WLAN_EVT_AP_START,               /* AP start */
69     RT_WLAN_EVT_AP_STOP,                /* AP stop */
70     RT_WLAN_EVT_AP_ASSOCIATED,          /* sta associated */
71     RT_WLAN_EVT_AP_DISASSOCIATED,       /* sta disassociated */
72     RT_WLAN_EVT_MAX
73 } rt_wlan_event_t;
74 
75 typedef void (*rt_wlan_event_handler)(int event, struct rt_wlan_buff *buff, void *parameter);
76 
77 struct rt_wlan_scan_result
78 {
79     rt_int32_t num;
80     struct rt_wlan_info *info;
81 };
82 
83 /*
84  * wifi init interface
85  */
86 int rt_wlan_init(void);
87 rt_err_t rt_wlan_set_mode(const char *dev_name, rt_wlan_mode_t mode);
88 rt_wlan_mode_t rt_wlan_get_mode(const char *dev_name);
89 
90 /*
91  * wifi station mode interface
92  */
93 rt_err_t rt_wlan_connect(const char *ssid, const char *password);
94 rt_err_t rt_wlan_connect_adv(struct rt_wlan_info *info, const char *password);
95 rt_err_t rt_wlan_disconnect(void);
96 rt_bool_t rt_wlan_is_connected(void);
97 rt_bool_t rt_wlan_is_ready(void);
98 rt_err_t rt_wlan_set_mac(rt_uint8_t *mac);
99 rt_err_t rt_wlan_get_mac(rt_uint8_t *mac);
100 rt_err_t rt_wlan_get_info(struct rt_wlan_info *info);
101 int rt_wlan_get_rssi(void);
102 
103 /*
104  * wifi ap mode interface
105  */
106 rt_err_t rt_wlan_start_ap(const char *ssid, const char *password);
107 rt_err_t rt_wlan_start_ap_adv(struct rt_wlan_info *info, const char *password);
108 rt_bool_t rt_wlan_ap_is_active(void);
109 rt_err_t rt_wlan_ap_stop(void);
110 rt_err_t rt_wlan_ap_get_info(struct rt_wlan_info *info);
111 int rt_wlan_ap_get_sta_num(void);
112 int rt_wlan_ap_get_sta_info(struct rt_wlan_info *info, int num);
113 rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac);
114 rt_err_t rt_wlan_ap_set_country(rt_country_code_t country_code);
115 rt_country_code_t rt_wlan_ap_get_country(void);
116 
117 /*
118  * wifi scan interface
119  */
120 rt_err_t rt_wlan_scan(void);
121 struct rt_wlan_scan_result *rt_wlan_scan_sync(void);
122 rt_err_t rt_wlan_scan_with_info(struct rt_wlan_info *info);
123 
124 
125 /*
126  * wifi auto connect interface
127  */
128 void rt_wlan_config_autoreconnect(rt_bool_t enable);
129 rt_bool_t rt_wlan_get_autoreconnect_mode(void);
130 
131 /*
132  * wifi power management interface
133  */
134 rt_err_t rt_wlan_set_powersave(int level);
135 int rt_wlan_get_powersave(void);
136 
137 /*
138  * wifi event management interface
139  */
140 rt_err_t rt_wlan_register_event_handler(rt_wlan_event_t event, rt_wlan_event_handler handler, void *parameter);
141 rt_err_t rt_wlan_unregister_event_handler(rt_wlan_event_t event);
142 
143 /*
144  * wifi management lock interface
145  */
146 void rt_wlan_mgnt_lock(void);
147 void rt_wlan_mgnt_unlock(void);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif
154