TizenRT Public API  v2.0 M2
wifi_manager.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2017 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 
31 #ifndef WIFI_MANAGER_H
32 #define WIFI_MANAGER_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* Length defines */
39 #define WIFIMGR_MACADDR_LEN 6
40 #define WIFIMGR_MACADDR_STR_LEN 17
41 #define WIFIMGR_SSID_LEN 32
42 #define WIFIMGR_PASSPHRASE_LEN 64
43 
46 typedef enum {
47  // STA mode status
48  AP_DISCONNECTED,
49  AP_CONNECTED,
50 
51  // SOFT AP mode status
52  CLIENT_CONNECTED,
53  CLIENT_DISCONNECTED,
54 
55  // Unkown
56  STATUS_UNKNOWN
58 
62 typedef enum {
63  WIFI_MANAGER_FAIL = -1,
64  WIFI_MANAGER_SUCCESS,
65  WIFI_MANAGER_INVALID_ARGS,
66  WIFI_MANAGER_INITIALIZED,
67  WIFI_MANAGER_DEINITIALIZED,
68  WIFI_MANAGER_TIMEOUT,
69  WIFI_MANAGER_BUSY,
70  WIFI_MANAGER_ALREADY_CONNECTED,
72 
76 typedef enum {
77  WIFI_MANAGER_DISCONNECT,
78  WIFI_MANAGER_RECONNECT, //AUTOCONNECT
80 
84 typedef enum {
85  WIFI_NONE = -1,
86  STA_MODE,
87  SOFTAP_MODE,
88  WIFI_MODE_CHANGING,
89  WIFI_INITIALIZING,
90  WIFI_DEINITIALIZING,
91  WIFI_FAILURE
93 
97 typedef enum {
98  WIFI_RECONN_INTERVAL,
99  WIFI_RECONN_EXPONENT,
100  WIFI_RECONN_NONE,
102 
106 typedef enum {
107  WIFI_SCAN_FAIL = -1,
108  WIFI_SCAN_SUCCESS,
110 
114 typedef enum {
122 
126 typedef enum {
135 
140  char ssid[WIFIMGR_SSID_LEN + 1]; // 802.11 spec defined unspecified or uint8
141  char bssid[WIFIMGR_MACADDR_STR_LEN + 1]; // char string e.g. xx:xx:xx:xx:xx:xx
142  int8_t rssi; // received signal strength indication
143  uint8_t channel; // channel/frequency
144  uint8_t phy_mode; // 0:legacy 1: 11N HT
145  wifi_manager_ap_auth_type_e ap_auth_type;
146  wifi_manager_ap_crypto_type_e ap_crypto_type;
147  struct wifi_manager_scan_info_s *next;
148 };
149 
151 
155 typedef struct {
156  void (*sta_connected)(wifi_manager_result_e); // in station mode, connected to ap
157  void (*sta_disconnected)(wifi_manager_disconnect_e); // in station mode, disconnected from ap
158  void (*softap_sta_joined)(void); // in softap mode, a station joined
159  void (*softap_sta_left)(void); // in softap mode, a station left
160  void (*scan_ap_done)(wifi_manager_scan_info_s **, wifi_manager_scan_result_e); // scanning ap is done
162 
166 typedef struct {
167  char ip4_address[WIFIMGR_MACADDR_STR_LEN + 1];
168  char ssid[WIFIMGR_SSID_LEN + 1];
169  char mac_address[WIFIMGR_MACADDR_LEN + 1];
170  int rssi;
171  connect_status_e status;
172  wifi_manager_mode_e mode;
174 
178 typedef struct {
179  char ssid[WIFIMGR_SSID_LEN + 1];
180  char passphrase[WIFIMGR_PASSPHRASE_LEN + 1];
181  uint16_t channel;
183 
187 typedef struct {
188  wifi_manager_reconn_type_e type;
189  // interval: if type is INTERVAL, it will try to connect AP every interval second
190  // if type is EXPONENTIAL, it is initial wait time.
191  int interval;
192  // max_interval: it is the maximum wait time if type is EXPONENTIAL
193  // : it is not used if type is INTERVAL
194  int max_interval; //
196 
200 typedef struct {
201  char ssid[WIFIMGR_SSID_LEN + 1];
202  unsigned int ssid_length;
203  char passphrase[WIFIMGR_PASSPHRASE_LEN + 1];
204  unsigned int passphrase_length;
205  wifi_manager_ap_auth_type_e ap_auth_type;
206  wifi_manager_ap_crypto_type_e ap_crypto_type;
208 
212 typedef struct {
213  uint16_t connect;
214  uint16_t connectfail;
215  uint16_t disconnect;
216  uint16_t reconnect;
217  uint16_t joined;
218  uint16_t left;
219  uint16_t scan;
220  uint16_t softap;
222 
230 wifi_manager_result_e wifi_manager_init(wifi_manager_cb_s *wmcb);
231 
239 wifi_manager_result_e wifi_manager_deinit(void);
240 
249 wifi_manager_result_e wifi_manager_set_mode(wifi_manager_mode_e mode, wifi_manager_softap_config_s *config);
250 
258 wifi_manager_result_e wifi_manager_get_info(wifi_manager_info_s *info);
259 
269 
278 wifi_manager_result_e wifi_manager_connect_ap(wifi_manager_ap_config_s *config);
279 
280 
288 wifi_manager_result_e wifi_manager_disconnect_ap(void);
289 
297 wifi_manager_result_e wifi_manager_scan_ap(void);
298 
306 wifi_manager_result_e wifi_manager_save_config(wifi_manager_ap_config_s *config);
307 
316 wifi_manager_result_e wifi_manager_get_config(wifi_manager_ap_config_s *config);
317 
324 wifi_manager_result_e wifi_manager_remove_config(void);
325 
334 wifi_manager_result_e wifi_manager_get_connected_config(wifi_manager_ap_config_s *config);
335 
343 wifi_manager_result_e wifi_manager_get_stats(wifi_manager_stats_s *stats);
344 
345 #ifdef __cplusplus
346 }
347 #endif
348 #endif
349 
wifi_manager_result_e wifi_manager_get_info(wifi_manager_info_s *info)
Retrieve current status of Wi-Fi interface including mode, connection status, ssid, received signal strengh indication, and ip address.
wifi_manager_result_e wifi_manager_deinit(void)
Deinitialize Wi-Fi Manager including stoping Wi-Fi interface.
wifi_manager_result_e wifi_manager_get_stats(wifi_manager_stats_s *stats)
Obtain WiFi Manager state stats.
wifi_manager_result_e wifi_manager_init(wifi_manager_cb_s *wmcb)
Initialize Wi-Fi Manager including starting Wi-Fi interface.
wifi_manager_ap_auth_type_e ap_auth_type
Definition: wifi_manager.h:145
wifi_manager_ap_crypto_type_e ap_crypto_type
Definition: wifi_manager.h:206
wifi_manager_mode_e
Mode of Wi-Fi interface such as station mode or ap mode.
Definition: wifi_manager.h:84
wifi_manager_result_e wifi_manager_get_connected_config(wifi_manager_ap_config_s *config)
Get the most recently connected AP configuration which was saved by Wi-Fi Manager.
wifi_manager_result_e wifi_manager_connect_ap(wifi_manager_ap_config_s *config)
Connect to an access point.
Specify the policy of reconnect when the device is disconnected.
Definition: wifi_manager.h:187
wifi_manager_result_e wifi_manager_get_config(wifi_manager_ap_config_s *config)
Get the AP configuration which was saved.
wifi_manager_result_e wifi_manager_connect_ap_config(wifi_manager_ap_config_s *config, wifi_manager_reconnect_config_s *reconn_config)
Connect to an access point.
wifi_manager_ap_auth_type_e ap_auth_type
Definition: wifi_manager.h:205
wifi_manager_result_e wifi_manager_disconnect_ap(void)
Disconnect from the connected access point.
wifi_manager_ap_crypto_type_e ap_crypto_type
Definition: wifi_manager.h:146
wifi_manager_result_e wifi_manager_scan_ap(void)
Scan nearby access points.
wifi_manager_result_e wifi_manager_remove_config(void)
Remove the AP configuration which was saved.
wifi_manager_result_e
Result types of Wi-Fi Manager APIs such as FAIL, SUCCESS, or INVALID ARGS.
Definition: wifi_manager.h:62
wifi_manager_result_e wifi_manager_save_config(wifi_manager_ap_config_s *config)
Save the AP configuration at persistent storage.
Specify information of soft access point (softAP) such as ssid and channel number.
Definition: wifi_manager.h:178
Keep information of nearby access points as scan results.
Definition: wifi_manager.h:139
Include callback functions which are asynchronously called after Wi-Fi Manager APIs are called...
Definition: wifi_manager.h:155
wifi_manager_scan_result_e
Result types of nearby access point scanning.
Definition: wifi_manager.h:106
wifi_manager_reconn_type_e
Reconnection mode of Wi-Fi interface.
Definition: wifi_manager.h:97
wifi_manager_ap_crypto_type_e
Wi-Fi encryption type such as WEP, AES, or TKIP.
Definition: wifi_manager.h:126
wifi_manager_ap_auth_type_e
Wi-Fi authentication type such as WPA, WPA2, or WPS.
Definition: wifi_manager.h:114
Specify which access point (AP) a client connects to.
Definition: wifi_manager.h:200
connect_status_e
Status of Wi-Fi interface such as connected or disconnected.
Definition: wifi_manager.h:46
wifi_manager_disconnect_e
Wi-Fi disconnect event reason.
Definition: wifi_manager.h:76
unsigned int passphrase_length
Definition: wifi_manager.h:204
wifi_manager_result_e wifi_manager_set_mode(wifi_manager_mode_e mode, wifi_manager_softap_config_s *config)
Change the Wi-Fi mode to station or AP.
Keep Wi-Fi Manager information including ip/mac address, ssid, rssi, etc.
Definition: wifi_manager.h:166
Specify Wi-Fi Manager internal stats information.
Definition: wifi_manager.h:212