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