Merge branch 'ipsec' into tizen
[platform/upstream/connman.git] / gsupplicant / gsupplicant.h
1 /*
2  *
3  *  WPA supplicant library with GLib integration
4  *
5  *  Copyright (C) 2012-2013  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 #ifndef __G_SUPPLICANT_H
22 #define __G_SUPPLICANT_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #define G_SUPPLICANT_EAP_METHOD_MD5     (1 << 0)
29 #define G_SUPPLICANT_EAP_METHOD_TLS     (1 << 1)
30 #define G_SUPPLICANT_EAP_METHOD_MSCHAPV2        (1 << 2)
31 #define G_SUPPLICANT_EAP_METHOD_PEAP    (1 << 3)
32 #define G_SUPPLICANT_EAP_METHOD_TTLS    (1 << 4)
33 #define G_SUPPLICANT_EAP_METHOD_GTC     (1 << 5)
34 #define G_SUPPLICANT_EAP_METHOD_OTP     (1 << 6)
35 #define G_SUPPLICANT_EAP_METHOD_LEAP    (1 << 7)
36 #define G_SUPPLICANT_EAP_METHOD_WSC     (1 << 8)
37
38 #define G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN    (1 << 0)
39 #define G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED  (1 << 1)
40 #define G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP    (1 << 2)
41
42 #define G_SUPPLICANT_CAPABILITY_PROTO_WPA               (1 << 0)
43 #define G_SUPPLICANT_CAPABILITY_PROTO_RSN               (1 << 1)
44
45 #define G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE     (1 << 0)
46 #define G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE    (1 << 1)
47 #define G_SUPPLICANT_CAPABILITY_SCAN_SSID               (1 << 2)
48
49 #define G_SUPPLICANT_CAPABILITY_MODE_INFRA      (1 << 0)
50 #define G_SUPPLICANT_CAPABILITY_MODE_IBSS               (1 << 1)
51 #define G_SUPPLICANT_CAPABILITY_MODE_AP         (1 << 2)
52 #define G_SUPPLICANT_CAPABILITY_MODE_P2P        (1 << 3)
53
54 #define G_SUPPLICANT_KEYMGMT_NONE               (1 << 0)
55 #define G_SUPPLICANT_KEYMGMT_IEEE8021X  (1 << 1)
56 #define G_SUPPLICANT_KEYMGMT_WPA_NONE   (1 << 2)
57 #define G_SUPPLICANT_KEYMGMT_WPA_PSK    (1 << 3)
58 #define G_SUPPLICANT_KEYMGMT_WPA_PSK_256        (1 << 4)
59 #if defined TIZEN_EXT
60 #define G_SUPPLICANT_KEYMGMT_WPA_FT_EAP (1 << 5)
61 #define G_SUPPLICANT_KEYMGMT_WPA_FT_PSK (1 << 6)
62 #else
63 #define G_SUPPLICANT_KEYMGMT_WPA_FT_PSK (1 << 5)
64 #define G_SUPPLICANT_KEYMGMT_WPA_FT_EAP (1 << 6)
65 #endif
66 #define G_SUPPLICANT_KEYMGMT_WPA_EAP    (1 << 7)
67 #define G_SUPPLICANT_KEYMGMT_WPA_EAP_256        (1 << 8)
68 #define G_SUPPLICANT_KEYMGMT_WPS                (1 << 9)
69
70 #define G_SUPPLICANT_PROTO_WPA          (1 << 0)
71 #define G_SUPPLICANT_PROTO_RSN          (1 << 1)
72
73 #define G_SUPPLICANT_GROUP_WEP40                (1 << 0)
74 #define G_SUPPLICANT_GROUP_WEP104               (1 << 1)
75 #define G_SUPPLICANT_GROUP_TKIP         (1 << 2)
76 #define G_SUPPLICANT_GROUP_CCMP         (1 << 3)
77
78 #define G_SUPPLICANT_PAIRWISE_NONE      (1 << 0)
79 #define G_SUPPLICANT_PAIRWISE_TKIP      (1 << 1)
80 #define G_SUPPLICANT_PAIRWISE_CCMP      (1 << 2)
81
82 #define G_SUPPLICANT_WPS_CONFIGURED     (1 << 0)
83 #define G_SUPPLICANT_WPS_PBC            (1 << 1)
84 #define G_SUPPLICANT_WPS_PIN            (1 << 2)
85 #define G_SUPPLICANT_WPS_REGISTRAR      (1 << 3)
86
87 #define G_SUPPLICANT_WPS_CONFIG_PBC     0x0080
88
89 #define G_SUPPLICANT_GROUP_ROLE_CLIENT  (1 << 0)
90 #define G_SUPPLICANT_GROUP_ROLE_GO      (1 << 1)
91
92 typedef enum {
93         G_SUPPLICANT_MODE_UNKNOWN,
94         G_SUPPLICANT_MODE_INFRA,
95         G_SUPPLICANT_MODE_IBSS,
96         G_SUPPLICANT_MODE_MASTER,
97 } GSupplicantMode;
98
99 typedef enum {
100         G_SUPPLICANT_SECURITY_UNKNOWN,
101         G_SUPPLICANT_SECURITY_NONE,
102         G_SUPPLICANT_SECURITY_WEP,
103         G_SUPPLICANT_SECURITY_PSK,
104         G_SUPPLICANT_SECURITY_IEEE8021X,
105 #if defined TIZEN_EXT
106         G_SUPPLICANT_SECURITY_FT_PSK,
107         G_SUPPLICANT_SECURITY_FT_IEEE8021X,
108 #endif
109 } GSupplicantSecurity;
110
111 typedef enum {
112         G_SUPPLICANT_STATE_UNKNOWN,
113         G_SUPPLICANT_STATE_DISABLED,
114         G_SUPPLICANT_STATE_DISCONNECTED,
115         G_SUPPLICANT_STATE_INACTIVE,
116         G_SUPPLICANT_STATE_SCANNING,
117         G_SUPPLICANT_STATE_AUTHENTICATING,
118         G_SUPPLICANT_STATE_ASSOCIATING,
119         G_SUPPLICANT_STATE_ASSOCIATED,
120         G_SUPPLICANT_STATE_4WAY_HANDSHAKE,
121         G_SUPPLICANT_STATE_GROUP_HANDSHAKE,
122         G_SUPPLICANT_STATE_COMPLETED,
123 } GSupplicantState;
124
125 typedef enum {
126         G_SUPPLICANT_WPS_STATE_UNKNOWN,
127         G_SUPPLICANT_WPS_STATE_SUCCESS,
128         G_SUPPLICANT_WPS_STATE_FAIL,
129 } GSupplicantWpsState;
130
131 typedef enum {
132         G_SUPPLICANT_PEER_SERVICES_CHANGED,
133         G_SUPPLICANT_PEER_GROUP_CHANGED,
134         G_SUPPLICANT_PEER_GROUP_STARTED,
135         G_SUPPLICANT_PEER_GROUP_FINISHED,
136         G_SUPPLICANT_PEER_GROUP_JOINED,
137         G_SUPPLICANT_PEER_GROUP_DISCONNECTED,
138         G_SUPPLICANT_PEER_GROUP_FAILED,
139 } GSupplicantPeerState;
140
141 enum GSupplicantAPHiddenSSID {
142         G_SUPPLICANT_AP_NO_SSID_HIDING,
143         G_SUPPLICANT_AP_HIDDEN_SSID_ZERO_LEN,
144         G_SUPPLICANT_AP_HIDDEN_SSID_ZERO_CONTENTS,
145 };
146
147 struct _GSupplicantSSID {
148         const void *ssid;
149         unsigned int ssid_len;
150         unsigned int scan_ssid;
151         GSupplicantMode mode;
152         GSupplicantSecurity security;
153         unsigned int protocol;
154         unsigned int pairwise_cipher;
155         unsigned int group_cipher;
156         unsigned int freq;
157         const char *eap;
158         const char *passphrase;
159         const char *identity;
160         const char *ca_cert_path;
161         const char *client_cert_path;
162         const char *private_key_path;
163         const char *private_key_passphrase;
164         const char *phase2_auth;
165         dbus_bool_t use_wps;
166         const char *pin_wps;
167         const char *bgscan;
168         int ignore_broadcast_ssid;
169 #if defined TIZEN_EXT
170         unsigned char *bssid;
171 #endif
172 };
173
174 typedef struct _GSupplicantSSID GSupplicantSSID;
175
176 /*
177  * Max number of SSIDs that can be scanned.
178  * In wpa_s 0.7x the limit is 4.
179  * In wps_s 0.8 or later it is 16.
180  * The value is only used if wpa_supplicant does not return any max limit
181  * for number of scannable SSIDs.
182  */
183 #define WPAS_MAX_SCAN_SSIDS 4
184
185 struct scan_ssid {
186         unsigned char ssid[32];
187         uint8_t ssid_len;
188 };
189
190 struct _GSupplicantScanParams {
191         GSList *ssids;
192
193         uint8_t num_ssids;
194
195         uint8_t num_freqs;
196         uint16_t *freqs;
197 };
198
199 typedef struct _GSupplicantScanParams GSupplicantScanParams;
200
201 struct _GSupplicantPeerParams {
202         bool master;
203         char *wps_pin;
204         char *path;
205 };
206
207 typedef struct _GSupplicantPeerParams GSupplicantPeerParams;
208
209 struct _GSupplicantP2PServiceParams {
210         int version;
211         char *service;
212         unsigned char *query;
213         int query_length;
214         unsigned char *response;
215         int response_length;
216         unsigned char *wfd_ies;
217         int wfd_ies_length;
218 };
219
220 typedef struct _GSupplicantP2PServiceParams GSupplicantP2PServiceParams;
221
222 /* global API */
223 typedef void (*GSupplicantCountryCallback) (int result,
224                                                 const char *alpha2,
225                                                         void *user_data);
226
227 int g_supplicant_set_country(const char *alpha2,
228                                 GSupplicantCountryCallback callback,
229                                                 const void *user_data);
230
231 /* Interface API */
232 struct _GSupplicantInterface;
233 struct _GSupplicantPeer;
234
235 typedef struct _GSupplicantInterface GSupplicantInterface;
236 typedef struct _GSupplicantPeer GSupplicantPeer;
237
238 typedef void (*GSupplicantInterfaceCallback) (int result,
239                                         GSupplicantInterface *interface,
240                                                         void *user_data);
241
242 void g_supplicant_interface_cancel(GSupplicantInterface *interface);
243
244 int g_supplicant_interface_create(const char *ifname, const char *driver,
245                                         const char *bridge,
246                                         GSupplicantInterfaceCallback callback,
247                                                         void *user_data);
248 int g_supplicant_interface_remove(GSupplicantInterface *interface,
249                                         GSupplicantInterfaceCallback callback,
250                                                         void *user_data);
251 int g_supplicant_interface_scan(GSupplicantInterface *interface,
252                                         GSupplicantScanParams *scan_data,
253                                         GSupplicantInterfaceCallback callback,
254                                                         void *user_data);
255
256 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
257                                         GSupplicantInterfaceCallback callback,
258                                                         void *user_data);
259
260 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface);
261
262 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
263                                         GSupplicantPeerParams *peer_params,
264                                         GSupplicantInterfaceCallback callback,
265                                         void *user_data);
266
267 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
268                                         GSupplicantPeerParams *peer_params);
269
270 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
271                                                 int period, int interval);
272
273 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
274                                 GSupplicantInterfaceCallback callback,
275                                 GSupplicantP2PServiceParams *p2p_service_params,
276                                 void *user_data);
277
278 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
279                                 GSupplicantP2PServiceParams *p2p_service_params);
280
281 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
282                                         GSupplicantInterfaceCallback callback,
283                                         void *user_data);
284
285 int g_supplicant_interface_connect(GSupplicantInterface *interface,
286                                         GSupplicantSSID *ssid,
287                                         GSupplicantInterfaceCallback callback,
288                                                         void *user_data);
289
290 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
291                                         GSupplicantInterfaceCallback callback,
292                                                         void *user_data);
293
294 #if defined TIZEN_EXT
295 int g_supplicant_interface_remove_network(GSupplicantInterface *interface);
296 #endif
297 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
298                                                         unsigned int ap_scan);
299
300 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
301                                                                 void *data);
302 void *g_supplicant_interface_get_data(GSupplicantInterface *interface);
303 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface);
304 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface);
305 GSupplicantState g_supplicant_interface_get_state(GSupplicantInterface *interface);
306 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface);
307 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
308                                                         unsigned int *ssid_len);
309 GSupplicantWpsState g_supplicant_interface_get_wps_state(GSupplicantInterface *interface);
310 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface);
311 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface);
312 unsigned int g_supplicant_interface_get_max_scan_ssids(
313                                         GSupplicantInterface *interface);
314
315 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
316                                                         dbus_bool_t enable);
317 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
318                                         GSupplicantCountryCallback callback,
319                                                         const char *alpha2,
320                                                         void *user_data);
321 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface);
322 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
323                                                 const char *device_name,
324                                                 const char *primary_dev_type);
325 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
326                                                 const char *identifier);
327 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface);
328
329 /* Network and Peer API */
330 struct _GSupplicantNetwork;
331 struct _GSupplicantGroup;
332
333 typedef struct _GSupplicantNetwork GSupplicantNetwork;
334 typedef struct _GSupplicantGroup GSupplicantGroup;
335
336 GSupplicantInterface *g_supplicant_network_get_interface(GSupplicantNetwork *network);
337 const char *g_supplicant_network_get_name(GSupplicantNetwork *network);
338 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network);
339 const char *g_supplicant_network_get_path(GSupplicantNetwork *network);
340 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
341                                                         unsigned int *ssid_len);
342 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network);
343 const char *g_supplicant_network_get_security(GSupplicantNetwork *network);
344 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network);
345 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network);
346 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network);
347 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network);
348 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network);
349 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network);
350
351 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer);
352 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer);
353 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer);
354 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer);
355 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer);
356 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer);
357 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
358                                                                 int *length);
359 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer);
360 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer);
361 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer);
362 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer);
363 bool g_supplicant_peer_is_client(GSupplicantPeer *peer);
364 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer);
365
366 #if defined TIZEN_EXT
367 /*
368 * Description: Network client requires additional wifi specific info
369 */
370 const unsigned char *g_supplicant_network_get_bssid(
371                                                 GSupplicantNetwork *network);
372 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network);
373 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network);
374 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network);
375 unsigned int g_supplicant_network_is_hs20AP(GSupplicantNetwork *network);
376 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network);
377 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network);
378 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network);
379 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network);
380 #endif
381
382 struct _GSupplicantCallbacks {
383         void (*system_ready) (void);
384         void (*system_killed) (void);
385         void (*interface_added) (GSupplicantInterface *interface);
386         void (*interface_state) (GSupplicantInterface *interface);
387         void (*interface_removed) (GSupplicantInterface *interface);
388         void (*p2p_support) (GSupplicantInterface *interface);
389         void (*scan_started) (GSupplicantInterface *interface);
390         void (*scan_finished) (GSupplicantInterface *interface);
391         void (*network_added) (GSupplicantNetwork *network);
392         void (*network_removed) (GSupplicantNetwork *network);
393 #if defined TIZEN_EXT
394         void (*network_merged) (GSupplicantNetwork *network);
395 #endif
396         void (*network_changed) (GSupplicantNetwork *network,
397                                         const char *property);
398 #if defined TIZEN_EXT
399         void (*system_power_off) (void);
400 #endif
401         void (*add_station) (const char *mac);
402         void (*remove_station) (const char *mac);
403         void (*peer_found) (GSupplicantPeer *peer);
404         void (*peer_lost) (GSupplicantPeer *peer);
405         void (*peer_changed) (GSupplicantPeer *peer,
406                                         GSupplicantPeerState state);
407         void (*peer_request) (GSupplicantPeer *peer);
408         void (*debug) (const char *str);
409         void (*disconnect_reasoncode)(GSupplicantInterface *interface,
410                                                                 int reasoncode);
411 };
412
413 typedef struct _GSupplicantCallbacks GSupplicantCallbacks;
414
415 int g_supplicant_register(const GSupplicantCallbacks *callbacks);
416 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks);
417
418 static inline
419 void g_supplicant_free_scan_params(GSupplicantScanParams *scan_params)
420 {
421         g_slist_free_full(scan_params->ssids, g_free);
422         g_free(scan_params->freqs);
423         g_free(scan_params);
424 }
425
426 #ifdef __cplusplus
427 }
428 #endif
429
430 #endif /* __G_SUPPLICANT_H */