Imported Upstream version 1.42
[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 #define G_SUPPLICANT_KEYMGMT_WPA_FT_PSK (1 << 5)
60 #define G_SUPPLICANT_KEYMGMT_WPA_FT_EAP (1 << 6)
61 #define G_SUPPLICANT_KEYMGMT_WPA_EAP    (1 << 7)
62 #define G_SUPPLICANT_KEYMGMT_WPA_EAP_256        (1 << 8)
63 #define G_SUPPLICANT_KEYMGMT_WPS                (1 << 9)
64 #define G_SUPPLICANT_KEYMGMT_SAE                (1 << 10)
65
66 #define G_SUPPLICANT_PROTO_WPA          (1 << 0)
67 #define G_SUPPLICANT_PROTO_RSN          (1 << 1)
68
69 #define G_SUPPLICANT_GROUP_WEP40                (1 << 0)
70 #define G_SUPPLICANT_GROUP_WEP104               (1 << 1)
71 #define G_SUPPLICANT_GROUP_TKIP         (1 << 2)
72 #define G_SUPPLICANT_GROUP_CCMP         (1 << 3)
73
74 #define G_SUPPLICANT_PAIRWISE_NONE      (1 << 0)
75 #define G_SUPPLICANT_PAIRWISE_TKIP      (1 << 1)
76 #define G_SUPPLICANT_PAIRWISE_CCMP      (1 << 2)
77
78 #define G_SUPPLICANT_WPS_CONFIGURED     (1 << 0)
79 #define G_SUPPLICANT_WPS_PBC            (1 << 1)
80 #define G_SUPPLICANT_WPS_PIN            (1 << 2)
81 #define G_SUPPLICANT_WPS_REGISTRAR      (1 << 3)
82
83 #define G_SUPPLICANT_WPS_CONFIG_PBC     0x0080
84
85 #define G_SUPPLICANT_GROUP_ROLE_CLIENT  (1 << 0)
86 #define G_SUPPLICANT_GROUP_ROLE_GO      (1 << 1)
87
88 typedef enum {
89         G_SUPPLICANT_MODE_UNKNOWN,
90         G_SUPPLICANT_MODE_INFRA,
91         G_SUPPLICANT_MODE_IBSS,
92         G_SUPPLICANT_MODE_MASTER,
93 } GSupplicantMode;
94
95 typedef enum {
96         G_SUPPLICANT_SECURITY_UNKNOWN,
97         G_SUPPLICANT_SECURITY_NONE,
98         G_SUPPLICANT_SECURITY_WEP,
99         G_SUPPLICANT_SECURITY_PSK,
100         G_SUPPLICANT_SECURITY_IEEE8021X,
101 } GSupplicantSecurity;
102
103 typedef enum {
104         G_SUPPLICANT_STATE_UNKNOWN,
105         G_SUPPLICANT_STATE_DISABLED,
106         G_SUPPLICANT_STATE_DISCONNECTED,
107         G_SUPPLICANT_STATE_INACTIVE,
108         G_SUPPLICANT_STATE_SCANNING,
109         G_SUPPLICANT_STATE_AUTHENTICATING,
110         G_SUPPLICANT_STATE_ASSOCIATING,
111         G_SUPPLICANT_STATE_ASSOCIATED,
112         G_SUPPLICANT_STATE_4WAY_HANDSHAKE,
113         G_SUPPLICANT_STATE_GROUP_HANDSHAKE,
114         G_SUPPLICANT_STATE_COMPLETED,
115 } GSupplicantState;
116
117 typedef enum {
118         G_SUPPLICANT_WPS_STATE_UNKNOWN,
119         G_SUPPLICANT_WPS_STATE_SUCCESS,
120         G_SUPPLICANT_WPS_STATE_FAIL,
121 } GSupplicantWpsState;
122
123 typedef enum {
124         G_SUPPLICANT_PEER_SERVICES_CHANGED,
125         G_SUPPLICANT_PEER_GROUP_CHANGED,
126         G_SUPPLICANT_PEER_GROUP_STARTED,
127         G_SUPPLICANT_PEER_GROUP_FINISHED,
128         G_SUPPLICANT_PEER_GROUP_JOINED,
129         G_SUPPLICANT_PEER_GROUP_DISCONNECTED,
130         G_SUPPLICANT_PEER_GROUP_FAILED,
131 } GSupplicantPeerState;
132
133 typedef enum {
134         G_SUPPLICANT_MFP_NONE,
135         G_SUPPLICANT_MFP_OPTIONAL,
136         G_SUPPLICANT_MFP_REQUIRED,
137 } GSupplicantMfpOptions;
138
139 struct _GSupplicantSSID {
140         const void *ssid;
141         unsigned int ssid_len;
142         unsigned int scan_ssid;
143         GSupplicantMode mode;
144         GSupplicantSecurity security;
145         unsigned int protocol;
146         unsigned int pairwise_cipher;
147         unsigned int group_cipher;
148         unsigned int freq;
149         const char *eap;
150         const char *passphrase;
151         const char *identity;
152         const char *anonymous_identity;
153         const char *ca_cert_path;
154         const char *subject_match;
155         const char *altsubject_match;
156         const char *domain_suffix_match;
157         const char *domain_match;
158         const char *client_cert_path;
159         const char *private_key_path;
160         const char *private_key_passphrase;
161         const char *phase2_auth;
162         dbus_bool_t use_wps;
163         const char *pin_wps;
164         const char *bgscan;
165         unsigned int keymgmt;
166         GSupplicantMfpOptions ieee80211w;
167 };
168
169 typedef struct _GSupplicantSSID GSupplicantSSID;
170
171 struct scan_ssid {
172         unsigned char ssid[32];
173         uint8_t ssid_len;
174 };
175
176 struct _GSupplicantScanParams {
177         GSList *ssids;
178
179         uint8_t num_ssids;
180
181         uint8_t num_freqs;
182         uint16_t *freqs;
183 };
184
185 typedef struct _GSupplicantScanParams GSupplicantScanParams;
186
187 struct _GSupplicantPeerParams {
188         bool master;
189         char *wps_pin;
190         char *path;
191 };
192
193 typedef struct _GSupplicantPeerParams GSupplicantPeerParams;
194
195 struct _GSupplicantP2PServiceParams {
196         int version;
197         char *service;
198         unsigned char *query;
199         int query_length;
200         unsigned char *response;
201         int response_length;
202         unsigned char *wfd_ies;
203         int wfd_ies_length;
204 };
205
206 typedef struct _GSupplicantP2PServiceParams GSupplicantP2PServiceParams;
207
208 /* global API */
209 typedef void (*GSupplicantCountryCallback) (int result,
210                                                 const char *alpha2,
211                                                         void *user_data);
212
213 int g_supplicant_set_country(const char *alpha2,
214                                 GSupplicantCountryCallback callback,
215                                                 const void *user_data);
216
217 /* Interface API */
218 struct _GSupplicantInterface;
219 struct _GSupplicantPeer;
220
221 typedef struct _GSupplicantInterface GSupplicantInterface;
222 typedef struct _GSupplicantPeer GSupplicantPeer;
223
224 typedef void (*GSupplicantInterfaceCallback) (int result,
225                                         GSupplicantInterface *interface,
226                                                         void *user_data);
227
228 void g_supplicant_interface_cancel(GSupplicantInterface *interface);
229
230 int g_supplicant_interface_create(const char *ifname, const char *driver,
231                                         const char *bridge,
232                                         GSupplicantInterfaceCallback callback,
233                                                         void *user_data);
234 int g_supplicant_interface_remove(GSupplicantInterface *interface,
235                                         GSupplicantInterfaceCallback callback,
236                                                         void *user_data);
237 int g_supplicant_interface_scan(GSupplicantInterface *interface,
238                                         GSupplicantScanParams *scan_data,
239                                         GSupplicantInterfaceCallback callback,
240                                                         void *user_data);
241
242 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
243                                         GSupplicantInterfaceCallback callback,
244                                                         void *user_data);
245
246 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface);
247
248 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
249                                         GSupplicantPeerParams *peer_params,
250                                         GSupplicantInterfaceCallback callback,
251                                         void *user_data);
252
253 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
254                                         GSupplicantPeerParams *peer_params);
255
256 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
257                                                 int period, int interval);
258
259 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
260                                 GSupplicantInterfaceCallback callback,
261                                 GSupplicantP2PServiceParams *p2p_service_params,
262                                 void *user_data);
263
264 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
265                                 GSupplicantP2PServiceParams *p2p_service_params);
266
267 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
268                                         GSupplicantInterfaceCallback callback,
269                                         void *user_data);
270
271 int g_supplicant_interface_connect(GSupplicantInterface *interface,
272                                         GSupplicantSSID *ssid,
273                                         GSupplicantInterfaceCallback callback,
274                                                         void *user_data);
275
276 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
277                                         GSupplicantInterfaceCallback callback,
278                                                         void *user_data);
279
280 int g_supplicant_interface_set_bss_expiration_age(GSupplicantInterface *interface,
281                                         unsigned int bss_expiration_age);
282
283 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
284                                                         unsigned int ap_scan);
285
286 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
287                                                                 void *data);
288 void *g_supplicant_interface_get_data(GSupplicantInterface *interface);
289 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface);
290 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface);
291 GSupplicantState g_supplicant_interface_get_state(GSupplicantInterface *interface);
292 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface);
293 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
294                                                         unsigned int *ssid_len);
295 GSupplicantWpsState g_supplicant_interface_get_wps_state(GSupplicantInterface *interface);
296 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface);
297 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface);
298 unsigned int g_supplicant_interface_get_max_scan_ssids(
299                                         GSupplicantInterface *interface);
300
301 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
302                                                         dbus_bool_t enable);
303 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
304                                         GSupplicantCountryCallback callback,
305                                                         const char *alpha2,
306                                                         void *user_data);
307 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface);
308 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
309                                                 const char *device_name,
310                                                 const char *primary_dev_type);
311 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
312                                                 const char *identifier);
313 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface);
314
315 /* Network and Peer API */
316 struct _GSupplicantNetwork;
317 struct _GSupplicantGroup;
318
319 typedef struct _GSupplicantNetwork GSupplicantNetwork;
320 typedef struct _GSupplicantGroup GSupplicantGroup;
321
322 GSupplicantInterface *g_supplicant_network_get_interface(GSupplicantNetwork *network);
323 const char *g_supplicant_network_get_name(GSupplicantNetwork *network);
324 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network);
325 const char *g_supplicant_network_get_path(GSupplicantNetwork *network);
326 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
327                                                         unsigned int *ssid_len);
328 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network);
329 const char *g_supplicant_network_get_security(GSupplicantNetwork *network);
330 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network);
331 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network);
332 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network);
333 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network);
334 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network);
335 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network);
336
337 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer);
338 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer);
339 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer);
340 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer);
341 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer);
342 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer);
343 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
344                                                                 int *length);
345 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer);
346 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer);
347 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer);
348 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer);
349 bool g_supplicant_peer_is_client(GSupplicantPeer *peer);
350 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer);
351 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network);
352
353 struct _GSupplicantCallbacks {
354         void (*system_ready) (void);
355         void (*system_killed) (void);
356         void (*interface_added) (GSupplicantInterface *interface);
357         void (*interface_state) (GSupplicantInterface *interface);
358         void (*interface_removed) (GSupplicantInterface *interface);
359         void (*p2p_support) (GSupplicantInterface *interface);
360         void (*scan_started) (GSupplicantInterface *interface);
361         void (*scan_finished) (GSupplicantInterface *interface);
362         void (*ap_create_fail) (GSupplicantInterface *interface);
363         void (*network_added) (GSupplicantNetwork *network);
364         void (*network_removed) (GSupplicantNetwork *network);
365         void (*network_changed) (GSupplicantNetwork *network,
366                                         const char *property);
367         void (*network_associated) (GSupplicantNetwork *network);
368         void (*sta_authorized) (GSupplicantInterface *interface,
369                                         const char *addr);
370         void (*sta_deauthorized) (GSupplicantInterface *interface,
371                                         const char *addr);
372         void (*peer_found) (GSupplicantPeer *peer);
373         void (*peer_lost) (GSupplicantPeer *peer);
374         void (*peer_changed) (GSupplicantPeer *peer,
375                                         GSupplicantPeerState state);
376         void (*peer_request) (GSupplicantPeer *peer);
377         void (*debug) (const char *str);
378         void (*disconnect_reasoncode)(GSupplicantInterface *interface,
379                                 int reasoncode);
380         void (*assoc_status_code)(GSupplicantInterface *interface,
381                                 int reasoncode);
382 };
383
384 typedef struct _GSupplicantCallbacks GSupplicantCallbacks;
385
386 int g_supplicant_register(const GSupplicantCallbacks *callbacks);
387 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks);
388
389 static inline
390 void g_supplicant_free_scan_params(GSupplicantScanParams *scan_params)
391 {
392         g_slist_free_full(scan_params->ssids, g_free);
393         g_free(scan_params->freqs);
394         g_free(scan_params);
395 }
396
397 #ifdef __cplusplus
398 }
399 #endif
400
401 #endif /* __G_SUPPLICANT_H */