wifi: Set device powered from the interface create callback
[platform/upstream/connman.git] / gsupplicant / gsupplicant.h
1 /*
2  *
3  *  WPA supplicant library with GLib integration
4  *
5  *  Copyright (C) 2010  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
53 #define G_SUPPLICANT_KEYMGMT_NONE               (1 << 0)
54 #define G_SUPPLICANT_KEYMGMT_IEEE8021X  (1 << 1)
55 #define G_SUPPLICANT_KEYMGMT_WPA_NONE   (1 << 2)
56 #define G_SUPPLICANT_KEYMGMT_WPA_PSK    (1 << 3)
57 #define G_SUPPLICANT_KEYMGMT_WPA_PSK_256        (1 << 4)
58 #define G_SUPPLICANT_KEYMGMT_WPA_FT_PSK (1 << 5)
59 #define G_SUPPLICANT_KEYMGMT_WPA_FT_EAP (1 << 6)
60 #define G_SUPPLICANT_KEYMGMT_WPA_EAP    (1 << 7)
61 #define G_SUPPLICANT_KEYMGMT_WPA_EAP_256        (1 << 8)
62 #define G_SUPPLICANT_KEYMGMT_WPS                (1 << 9)
63
64 #define G_SUPPLICANT_PROTO_WPA          (1 << 0)
65 #define G_SUPPLICANT_PROTO_RSN          (1 << 1)
66
67 #define G_SUPPLICANT_GROUP_WEP40                (1 << 0)
68 #define G_SUPPLICANT_GROUP_WEP104               (1 << 1)
69 #define G_SUPPLICANT_GROUP_TKIP         (1 << 2)
70 #define G_SUPPLICANT_GROUP_CCMP         (1 << 3)
71
72 #define G_SUPPLICANT_PAIRWISE_NONE      (1 << 0)
73 #define G_SUPPLICANT_PAIRWISE_TKIP      (1 << 1)
74 #define G_SUPPLICANT_PAIRWISE_CCMP      (1 << 2)
75
76 #define G_SUPPLICANT_MAX_FAST_SCAN      4
77
78 typedef enum {
79         G_SUPPLICANT_MODE_UNKNOWN,
80         G_SUPPLICANT_MODE_INFRA,
81         G_SUPPLICANT_MODE_IBSS,
82         G_SUPPLICANT_MODE_MASTER,
83 } GSupplicantMode;
84
85 typedef enum {
86         G_SUPPLICANT_SECURITY_UNKNOWN,
87         G_SUPPLICANT_SECURITY_NONE,
88         G_SUPPLICANT_SECURITY_WEP,
89         G_SUPPLICANT_SECURITY_PSK,
90         G_SUPPLICANT_SECURITY_IEEE8021X,
91 } GSupplicantSecurity;
92
93 typedef enum {
94         G_SUPPLICANT_STATE_UNKNOWN,
95         G_SUPPLICANT_STATE_DISCONNECTED,
96         G_SUPPLICANT_STATE_INACTIVE,
97         G_SUPPLICANT_STATE_SCANNING,
98         G_SUPPLICANT_STATE_AUTHENTICATING,
99         G_SUPPLICANT_STATE_ASSOCIATING,
100         G_SUPPLICANT_STATE_ASSOCIATED,
101         G_SUPPLICANT_STATE_4WAY_HANDSHAKE,
102         G_SUPPLICANT_STATE_GROUP_HANDSHAKE,
103         G_SUPPLICANT_STATE_COMPLETED,
104 } GSupplicantState;
105
106 typedef enum {
107         G_SUPPLICANT_WPS_STATE_UNKNOWN,
108         G_SUPPLICANT_WPS_STATE_SUCCESS,
109         G_SUPPLICANT_WPS_STATE_FAIL,
110 } GSupplicantWpsState;
111
112 struct _GSupplicantSSID {
113         const void *ssid;
114         unsigned int ssid_len;
115         unsigned int scan_ssid;
116         GSupplicantMode mode;
117         GSupplicantSecurity security;
118         unsigned int protocol;
119         unsigned int pairwise_cipher;
120         unsigned int group_cipher;
121         unsigned int freq;
122         const char *eap;
123         const char *passphrase;
124         const char *identity;
125         const char *ca_cert_path;
126         const char *client_cert_path;
127         const char *private_key_path;
128         const char *private_key_passphrase;
129         const char *phase2_auth;
130         dbus_bool_t use_wps;
131         const char *pin_wps;
132 };
133
134 typedef struct _GSupplicantSSID GSupplicantSSID;
135
136 struct _GSupplicantScanParams {
137         struct scan_ssid {
138                 unsigned char ssid[32];
139                 uint8_t ssid_len;
140         } ssids[G_SUPPLICANT_MAX_FAST_SCAN];
141
142         uint8_t num_ssids;
143
144         uint16_t freqs[G_SUPPLICANT_MAX_FAST_SCAN];
145 };
146
147 typedef struct _GSupplicantScanParams GSupplicantScanParams;
148
149 /* global API */
150 typedef void (*GSupplicantCountryCallback) (void *user_data);
151
152 int g_supplicant_set_country(const char *alpha2,
153                                 GSupplicantCountryCallback callback,
154                                                 const void *user_data);
155
156 /* Interface API */
157 struct _GSupplicantInterface;
158
159 typedef struct _GSupplicantInterface GSupplicantInterface;
160
161 typedef void (*GSupplicantInterfaceCallback) (int result,
162                                         GSupplicantInterface *interface,
163                                                         void *user_data);
164
165 int g_supplicant_interface_create(const char *ifname, const char *driver,
166                                         const char *bridge,
167                                         GSupplicantInterfaceCallback callback,
168                                                         void *user_data);
169 int g_supplicant_interface_remove(GSupplicantInterface *interface,
170                                         GSupplicantInterfaceCallback callback,
171                                                         void *user_data);
172 int g_supplicant_interface_scan(GSupplicantInterface *interface,
173                                         GSupplicantScanParams *scan_data,
174                                         GSupplicantInterfaceCallback callback,
175                                                         void *user_data);
176
177 int g_supplicant_interface_connect(GSupplicantInterface *interface,
178                                         GSupplicantSSID *ssid,
179                                         GSupplicantInterfaceCallback callback,
180                                                         void *user_data);
181
182 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
183                                         GSupplicantInterfaceCallback callback,
184                                                         void *user_data);
185
186 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
187                                                         unsigned int ap_scan);
188
189 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
190                                                                 void *data);
191 void *g_supplicant_interface_get_data(GSupplicantInterface *interface);
192 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface);
193 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface);
194 GSupplicantState g_supplicant_interface_get_state(GSupplicantInterface *interface);
195 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface);
196 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
197                                                         unsigned int *ssid_len);
198 GSupplicantWpsState g_supplicant_interface_get_wps_state(GSupplicantInterface *interface);
199 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface);
200 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface);
201 unsigned int g_supplicant_interface_get_max_scan_ssids(
202                                         GSupplicantInterface *interface);
203
204 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
205                                                         dbus_bool_t enable);
206
207 /* Network API */
208 struct _GSupplicantNetwork;
209
210 typedef struct _GSupplicantNetwork GSupplicantNetwork;
211
212 GSupplicantInterface *g_supplicant_network_get_interface(GSupplicantNetwork *network);
213 const char *g_supplicant_network_get_name(GSupplicantNetwork *network);
214 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network);
215 const char *g_supplicant_network_get_path(GSupplicantNetwork *network);
216 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
217                                                         unsigned int *ssid_len);
218 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network);
219 const char *g_supplicant_network_get_security(GSupplicantNetwork *network);
220 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network);
221 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network);
222 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network);
223
224 struct _GSupplicantCallbacks {
225         void (*system_ready) (void);
226         void (*system_killed) (void);
227         void (*interface_added) (GSupplicantInterface *interface);
228         void (*interface_state) (GSupplicantInterface *interface);
229         void (*interface_removed) (GSupplicantInterface *interface);
230         void (*scan_started) (GSupplicantInterface *interface);
231         void (*scan_finished) (GSupplicantInterface *interface);
232         void (*network_added) (GSupplicantNetwork *network);
233         void (*network_removed) (GSupplicantNetwork *network);
234         void (*network_changed) (GSupplicantNetwork *network,
235                                         const char *property);
236         void (*debug) (const char *str);
237 };
238
239 typedef struct _GSupplicantCallbacks GSupplicantCallbacks;
240
241 int g_supplicant_register(const GSupplicantCallbacks *callbacks);
242 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks);
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif /* __G_SUPPLICANT_H */