]>
Commit | Line | Data |
---|---|---|
8fc2fb56 WS |
1 | /* |
2 | * WPA Supplicant / dbus-based control interface | |
3 | * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc. | |
7899e2f4 | 4 | * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com> |
5e3b5197 | 5 | * Copyright (c) 2009-2015, Jouni Malinen <j@w1.fi> |
8fc2fb56 | 6 | * |
c5a3cebf JM |
7 | * This software may be distributed under the terms of the BSD license. |
8 | * See README for more details. | |
8fc2fb56 WS |
9 | */ |
10 | ||
11 | #include "includes.h" | |
12 | ||
13 | #include "common.h" | |
a206a29a JM |
14 | #include "common/ieee802_11_defs.h" |
15 | #include "eap_peer/eap_methods.h" | |
16 | #include "eapol_supp/eapol_supp_sm.h" | |
7899e2f4 | 17 | #include "rsn_supp/wpa.h" |
19b3211d JM |
18 | #include "../config.h" |
19 | #include "../wpa_supplicant_i.h" | |
20 | #include "../driver_i.h" | |
19b3211d | 21 | #include "../notify.h" |
ccd286d0 | 22 | #include "../bss.h" |
9ba9fa07 | 23 | #include "../scan.h" |
7c865c68 | 24 | #include "../autoscan.h" |
a206a29a JM |
25 | #include "dbus_new_helpers.h" |
26 | #include "dbus_new.h" | |
27 | #include "dbus_new_handlers.h" | |
28 | #include "dbus_dict_helpers.h" | |
2d43d37f | 29 | #include "dbus_common_i.h" |
7a4a93b9 | 30 | #include "drivers/driver.h" |
8fc2fb56 | 31 | |
38279bdb | 32 | static const char * const debug_strings[] = { |
14dc0011 | 33 | "excessive", "msgdump", "debug", "info", "warning", "error", NULL |
a2753c28 MH |
34 | }; |
35 | ||
8fc2fb56 | 36 | |
8fc2fb56 | 37 | /** |
ff1d8104 | 38 | * wpas_dbus_error_unknown_error - Return a new UnknownError error message |
8fc2fb56 WS |
39 | * @message: Pointer to incoming dbus message this error refers to |
40 | * @arg: Optional string appended to error message | |
41 | * Returns: a dbus error message | |
42 | * | |
43 | * Convenience function to create and return an UnknownError | |
44 | */ | |
36da1358 JM |
45 | DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message, |
46 | const char *arg) | |
8fc2fb56 | 47 | { |
5228401c JM |
48 | return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR, |
49 | arg); | |
8fc2fb56 WS |
50 | } |
51 | ||
52 | ||
53 | /** | |
54 | * wpas_dbus_error_iface_unknown - Return a new invalid interface error message | |
55 | * @message: Pointer to incoming dbus message this error refers to | |
56 | * Returns: A dbus error message | |
57 | * | |
58 | * Convenience function to create and return an invalid interface error | |
59 | */ | |
60 | static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message) | |
61 | { | |
38279bdb JM |
62 | return dbus_message_new_error( |
63 | message, WPAS_DBUS_ERROR_IFACE_UNKNOWN, | |
64 | "wpa_supplicant knows nothing about this interface."); | |
8fc2fb56 WS |
65 | } |
66 | ||
67 | ||
68 | /** | |
69 | * wpas_dbus_error_network_unknown - Return a new NetworkUnknown error message | |
70 | * @message: Pointer to incoming dbus message this error refers to | |
71 | * Returns: a dbus error message | |
72 | * | |
73 | * Convenience function to create and return an invalid network error | |
74 | */ | |
75 | static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message) | |
76 | { | |
38279bdb JM |
77 | return dbus_message_new_error( |
78 | message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN, | |
79 | "There is no such a network in this interface."); | |
8fc2fb56 WS |
80 | } |
81 | ||
82 | ||
83 | /** | |
db9a76c0 | 84 | * wpas_dbus_error_invalid_args - Return a new InvalidArgs error message |
8fc2fb56 WS |
85 | * @message: Pointer to incoming dbus message this error refers to |
86 | * Returns: a dbus error message | |
87 | * | |
88 | * Convenience function to create and return an invalid options error | |
89 | */ | |
db9a76c0 | 90 | DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message, |
36da1358 | 91 | const char *arg) |
8fc2fb56 WS |
92 | { |
93 | DBusMessage *reply; | |
94 | ||
38279bdb JM |
95 | reply = dbus_message_new_error( |
96 | message, WPAS_DBUS_ERROR_INVALID_ARGS, | |
97 | "Did not receive correct message arguments."); | |
8fc2fb56 WS |
98 | if (arg != NULL) |
99 | dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg, | |
100 | DBUS_TYPE_INVALID); | |
101 | ||
102 | return reply; | |
103 | } | |
104 | ||
105 | ||
e9b32dae | 106 | /** |
107 | * wpas_dbus_error_scan_error - Return a new ScanError error message | |
108 | * @message: Pointer to incoming dbus message this error refers to | |
109 | * @error: Optional string to be used as the error message | |
110 | * Returns: a dbus error message | |
111 | * | |
112 | * Convenience function to create and return a scan error | |
113 | */ | |
3cccf0b8 JM |
114 | static DBusMessage * wpas_dbus_error_scan_error(DBusMessage *message, |
115 | const char *error) | |
e9b32dae | 116 | { |
3cccf0b8 JM |
117 | return dbus_message_new_error(message, |
118 | WPAS_DBUS_ERROR_IFACE_SCAN_ERROR, | |
119 | error); | |
e9b32dae | 120 | } |
121 | ||
122 | ||
a0caebf3 JM |
123 | DBusMessage * wpas_dbus_error_no_memory(DBusMessage *message) |
124 | { | |
125 | wpa_printf(MSG_DEBUG, "dbus: Failed to allocate memory"); | |
126 | return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL); | |
127 | } | |
128 | ||
129 | ||
38279bdb | 130 | static const char * const dont_quote[] = { |
8fc2fb56 WS |
131 | "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap", |
132 | "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path", | |
99276998 | 133 | "bssid", "scan_freq", "freq_list", NULL |
8fc2fb56 WS |
134 | }; |
135 | ||
136 | static dbus_bool_t should_quote_opt(const char *key) | |
137 | { | |
138 | int i = 0; | |
38279bdb | 139 | |
8fc2fb56 | 140 | while (dont_quote[i] != NULL) { |
5228401c | 141 | if (os_strcmp(key, dont_quote[i]) == 0) |
8fc2fb56 WS |
142 | return FALSE; |
143 | i++; | |
144 | } | |
145 | return TRUE; | |
146 | } | |
147 | ||
8fc2fb56 WS |
148 | /** |
149 | * get_iface_by_dbus_path - Get a new network interface | |
150 | * @global: Pointer to global data from wpa_supplicant_init() | |
151 | * @path: Pointer to a dbus object path representing an interface | |
152 | * Returns: Pointer to the interface or %NULL if not found | |
153 | */ | |
154 | static struct wpa_supplicant * get_iface_by_dbus_path( | |
155 | struct wpa_global *global, const char *path) | |
156 | { | |
157 | struct wpa_supplicant *wpa_s; | |
158 | ||
159 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
8a78e227 JM |
160 | if (wpa_s->dbus_new_path && |
161 | os_strcmp(wpa_s->dbus_new_path, path) == 0) | |
8fc2fb56 WS |
162 | return wpa_s; |
163 | } | |
164 | return NULL; | |
165 | } | |
166 | ||
167 | ||
168 | /** | |
169 | * set_network_properties - Set properties of a configured network | |
aa53509f | 170 | * @wpa_s: wpa_supplicant structure for a network interface |
8fc2fb56 WS |
171 | * @ssid: wpa_ssid structure for a configured network |
172 | * @iter: DBus message iterator containing dictionary of network | |
173 | * properties to set. | |
6aeeb6fa DW |
174 | * @error: On failure, an error describing the failure |
175 | * Returns: TRUE if the request succeeds, FALSE if it failed | |
8fc2fb56 WS |
176 | * |
177 | * Sets network configuration with parameters given id DBus dictionary | |
178 | */ | |
6aeeb6fa DW |
179 | dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s, |
180 | struct wpa_ssid *ssid, | |
181 | DBusMessageIter *iter, | |
182 | DBusError *error) | |
8fc2fb56 | 183 | { |
8fc2fb56 | 184 | struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING }; |
8fc2fb56 | 185 | DBusMessageIter iter_dict; |
6aeeb6fa | 186 | char *value = NULL; |
8fc2fb56 | 187 | |
6aeeb6fa DW |
188 | if (!wpa_dbus_dict_open_read(iter, &iter_dict, error)) |
189 | return FALSE; | |
8fc2fb56 WS |
190 | |
191 | while (wpa_dbus_dict_has_dict_entry(&iter_dict)) { | |
8fc2fb56 WS |
192 | size_t size = 50; |
193 | int ret; | |
6aeeb6fa DW |
194 | |
195 | if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) | |
196 | goto error; | |
197 | ||
198 | value = NULL; | |
8fc2fb56 | 199 | if (entry.type == DBUS_TYPE_ARRAY && |
5228401c | 200 | entry.array_type == DBUS_TYPE_BYTE) { |
8fc2fb56 WS |
201 | if (entry.array_len <= 0) |
202 | goto error; | |
203 | ||
204 | size = entry.array_len * 2 + 1; | |
205 | value = os_zalloc(size); | |
206 | if (value == NULL) | |
207 | goto error; | |
208 | ||
5228401c JM |
209 | ret = wpa_snprintf_hex(value, size, |
210 | (u8 *) entry.bytearray_value, | |
211 | entry.array_len); | |
8fc2fb56 WS |
212 | if (ret <= 0) |
213 | goto error; | |
fae3a72f JM |
214 | } else if (entry.type == DBUS_TYPE_STRING) { |
215 | if (should_quote_opt(entry.key)) { | |
216 | size = os_strlen(entry.str_value); | |
c1a14ef4 | 217 | if (size == 0) |
fae3a72f JM |
218 | goto error; |
219 | ||
220 | size += 3; | |
221 | value = os_zalloc(size); | |
222 | if (value == NULL) | |
223 | goto error; | |
224 | ||
225 | ret = os_snprintf(value, size, "\"%s\"", | |
226 | entry.str_value); | |
1f102d3b | 227 | if (os_snprintf_error(size, ret)) |
fae3a72f | 228 | goto error; |
5228401c | 229 | } else { |
fae3a72f JM |
230 | value = os_strdup(entry.str_value); |
231 | if (value == NULL) | |
232 | goto error; | |
8fc2fb56 | 233 | } |
fae3a72f JM |
234 | } else if (entry.type == DBUS_TYPE_UINT32) { |
235 | value = os_zalloc(size); | |
236 | if (value == NULL) | |
237 | goto error; | |
238 | ||
239 | ret = os_snprintf(value, size, "%u", | |
240 | entry.uint32_value); | |
a9aaacbb | 241 | if (os_snprintf_error(size, ret)) |
fae3a72f JM |
242 | goto error; |
243 | } else if (entry.type == DBUS_TYPE_INT32) { | |
244 | value = os_zalloc(size); | |
245 | if (value == NULL) | |
246 | goto error; | |
247 | ||
248 | ret = os_snprintf(value, size, "%d", | |
249 | entry.int32_value); | |
a9aaacbb | 250 | if (os_snprintf_error(size, ret)) |
fae3a72f JM |
251 | goto error; |
252 | } else | |
253 | goto error; | |
8fc2fb56 WS |
254 | |
255 | if (wpa_config_set(ssid, entry.key, value, 0) < 0) | |
256 | goto error; | |
257 | ||
98a4cd44 JM |
258 | if (os_strcmp(entry.key, "bssid") != 0 && |
259 | os_strcmp(entry.key, "priority") != 0) | |
260 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); | |
261 | ||
262 | if (wpa_s->current_ssid == ssid || | |
263 | wpa_s->current_ssid == NULL) { | |
264 | /* | |
265 | * Invalidate the EAP session cache if anything in the | |
266 | * current or previously used configuration changes. | |
267 | */ | |
268 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
269 | } | |
270 | ||
5228401c JM |
271 | if ((os_strcmp(entry.key, "psk") == 0 && |
272 | value[0] == '"' && ssid->ssid_len) || | |
024d018b | 273 | (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase)) |
8fc2fb56 | 274 | wpa_config_update_psk(ssid); |
aa53509f DS |
275 | else if (os_strcmp(entry.key, "priority") == 0) |
276 | wpa_config_update_prio_list(wpa_s->conf); | |
8fc2fb56 WS |
277 | |
278 | os_free(value); | |
ceb4cd89 | 279 | value = NULL; |
8fc2fb56 | 280 | wpa_dbus_dict_entry_clear(&entry); |
8fc2fb56 | 281 | } |
fae3a72f | 282 | |
6aeeb6fa DW |
283 | return TRUE; |
284 | ||
285 | error: | |
286 | os_free(value); | |
287 | wpa_dbus_dict_entry_clear(&entry); | |
288 | dbus_set_error_const(error, DBUS_ERROR_INVALID_ARGS, | |
289 | "invalid message format"); | |
290 | return FALSE; | |
8fc2fb56 WS |
291 | } |
292 | ||
293 | ||
fcea0b7d WS |
294 | /** |
295 | * wpas_dbus_simple_property_getter - Get basic type property | |
6aeeb6fa | 296 | * @iter: Message iter to use when appending arguments |
fcea0b7d WS |
297 | * @type: DBus type of property (must be basic type) |
298 | * @val: pointer to place holding property value | |
6aeeb6fa DW |
299 | * @error: On failure an error describing the failure |
300 | * Returns: TRUE if the request was successful, FALSE if it failed | |
fcea0b7d WS |
301 | * |
302 | * Generic getter for basic type properties. Type is required to be basic. | |
303 | */ | |
6aeeb6fa DW |
304 | dbus_bool_t wpas_dbus_simple_property_getter(DBusMessageIter *iter, |
305 | const int type, | |
306 | const void *val, | |
307 | DBusError *error) | |
fcea0b7d | 308 | { |
6aeeb6fa | 309 | DBusMessageIter variant_iter; |
fcea0b7d WS |
310 | |
311 | if (!dbus_type_is_basic(type)) { | |
6aeeb6fa | 312 | dbus_set_error(error, DBUS_ERROR_FAILED, |
38279bdb | 313 | "%s: given type is not basic", __func__); |
6aeeb6fa | 314 | return FALSE; |
fcea0b7d WS |
315 | } |
316 | ||
6aeeb6fa | 317 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, |
38279bdb JM |
318 | wpa_dbus_type_as_string(type), |
319 | &variant_iter) || | |
e3c4f0b5 JM |
320 | !dbus_message_iter_append_basic(&variant_iter, type, val) || |
321 | !dbus_message_iter_close_container(iter, &variant_iter)) { | |
322 | dbus_set_error(error, DBUS_ERROR_FAILED, | |
323 | "%s: error constructing reply", __func__); | |
324 | return FALSE; | |
325 | } | |
6aeeb6fa DW |
326 | |
327 | return TRUE; | |
fcea0b7d WS |
328 | } |
329 | ||
330 | ||
331 | /** | |
332 | * wpas_dbus_simple_property_setter - Set basic type property | |
333 | * @message: Pointer to incoming dbus message | |
334 | * @type: DBus type of property (must be basic type) | |
335 | * @val: pointer to place where value being set will be stored | |
6aeeb6fa | 336 | * Returns: TRUE if the request was successful, FALSE if it failed |
fcea0b7d WS |
337 | * |
338 | * Generic setter for basic type properties. Type is required to be basic. | |
339 | */ | |
6aeeb6fa DW |
340 | dbus_bool_t wpas_dbus_simple_property_setter(DBusMessageIter *iter, |
341 | DBusError *error, | |
342 | const int type, void *val) | |
fcea0b7d | 343 | { |
6aeeb6fa | 344 | DBusMessageIter variant_iter; |
fcea0b7d WS |
345 | |
346 | if (!dbus_type_is_basic(type)) { | |
6aeeb6fa DW |
347 | dbus_set_error(error, DBUS_ERROR_FAILED, |
348 | "%s: given type is not basic", __func__); | |
349 | return FALSE; | |
fcea0b7d WS |
350 | } |
351 | ||
6aeeb6fa DW |
352 | /* Look at the new value */ |
353 | dbus_message_iter_recurse(iter, &variant_iter); | |
fcea0b7d | 354 | if (dbus_message_iter_get_arg_type(&variant_iter) != type) { |
6aeeb6fa DW |
355 | dbus_set_error_const(error, DBUS_ERROR_FAILED, |
356 | "wrong property type"); | |
357 | return FALSE; | |
fcea0b7d WS |
358 | } |
359 | dbus_message_iter_get_basic(&variant_iter, val); | |
360 | ||
6aeeb6fa | 361 | return TRUE; |
fcea0b7d WS |
362 | } |
363 | ||
364 | ||
365 | /** | |
366 | * wpas_dbus_simple_array_property_getter - Get array type property | |
6aeeb6fa | 367 | * @iter: Pointer to incoming dbus message iterator |
fcea0b7d WS |
368 | * @type: DBus type of property array elements (must be basic type) |
369 | * @array: pointer to array of elements to put into response message | |
370 | * @array_len: length of above array | |
6aeeb6fa DW |
371 | * @error: a pointer to an error to fill on failure |
372 | * Returns: TRUE if the request succeeded, FALSE if it failed | |
fcea0b7d WS |
373 | * |
374 | * Generic getter for array type properties. Array elements type is | |
375 | * required to be basic. | |
376 | */ | |
6aeeb6fa DW |
377 | dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter, |
378 | const int type, | |
379 | const void *array, | |
380 | size_t array_len, | |
381 | DBusError *error) | |
fcea0b7d | 382 | { |
6aeeb6fa | 383 | DBusMessageIter variant_iter, array_iter; |
fcea0b7d WS |
384 | char type_str[] = "a?"; /* ? will be replaced with subtype letter; */ |
385 | const char *sub_type_str; | |
386 | size_t element_size, i; | |
387 | ||
388 | if (!dbus_type_is_basic(type)) { | |
6aeeb6fa | 389 | dbus_set_error(error, DBUS_ERROR_FAILED, |
38279bdb | 390 | "%s: given type is not basic", __func__); |
6aeeb6fa | 391 | return FALSE; |
fcea0b7d WS |
392 | } |
393 | ||
97d3f8c3 | 394 | sub_type_str = wpa_dbus_type_as_string(type); |
fcea0b7d WS |
395 | type_str[1] = sub_type_str[0]; |
396 | ||
6aeeb6fa | 397 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, |
e3c4f0b5 JM |
398 | type_str, &variant_iter) || |
399 | !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY, | |
fcea0b7d | 400 | sub_type_str, &array_iter)) { |
6aeeb6fa | 401 | dbus_set_error(error, DBUS_ERROR_FAILED, |
e3c4f0b5 | 402 | "%s: failed to construct message", __func__); |
6aeeb6fa | 403 | return FALSE; |
fcea0b7d WS |
404 | } |
405 | ||
38279bdb | 406 | switch (type) { |
fcea0b7d WS |
407 | case DBUS_TYPE_BYTE: |
408 | case DBUS_TYPE_BOOLEAN: | |
409 | element_size = 1; | |
410 | break; | |
411 | case DBUS_TYPE_INT16: | |
412 | case DBUS_TYPE_UINT16: | |
413 | element_size = sizeof(uint16_t); | |
414 | break; | |
415 | case DBUS_TYPE_INT32: | |
416 | case DBUS_TYPE_UINT32: | |
417 | element_size = sizeof(uint32_t); | |
418 | break; | |
419 | case DBUS_TYPE_INT64: | |
420 | case DBUS_TYPE_UINT64: | |
421 | element_size = sizeof(uint64_t); | |
422 | break; | |
423 | case DBUS_TYPE_DOUBLE: | |
424 | element_size = sizeof(double); | |
425 | break; | |
426 | case DBUS_TYPE_STRING: | |
427 | case DBUS_TYPE_OBJECT_PATH: | |
428 | element_size = sizeof(char *); | |
429 | break; | |
430 | default: | |
6aeeb6fa | 431 | dbus_set_error(error, DBUS_ERROR_FAILED, |
38279bdb | 432 | "%s: unknown element type %d", __func__, type); |
6aeeb6fa | 433 | return FALSE; |
fcea0b7d WS |
434 | } |
435 | ||
436 | for (i = 0; i < array_len; i++) { | |
25be28a3 | 437 | if (!dbus_message_iter_append_basic(&array_iter, type, |
07e36539 ST |
438 | (const char *) array + |
439 | i * element_size)) { | |
25be28a3 JM |
440 | dbus_set_error(error, DBUS_ERROR_FAILED, |
441 | "%s: failed to construct message 2.5", | |
442 | __func__); | |
443 | return FALSE; | |
444 | } | |
fcea0b7d WS |
445 | } |
446 | ||
e3c4f0b5 JM |
447 | if (!dbus_message_iter_close_container(&variant_iter, &array_iter) || |
448 | !dbus_message_iter_close_container(iter, &variant_iter)) { | |
6aeeb6fa | 449 | dbus_set_error(error, DBUS_ERROR_FAILED, |
38279bdb | 450 | "%s: failed to construct message 3", __func__); |
6aeeb6fa | 451 | return FALSE; |
fcea0b7d WS |
452 | } |
453 | ||
96c4f3a7 JS |
454 | return TRUE; |
455 | } | |
456 | ||
457 | ||
458 | /** | |
459 | * wpas_dbus_simple_array_array_property_getter - Get array array type property | |
460 | * @iter: Pointer to incoming dbus message iterator | |
461 | * @type: DBus type of property array elements (must be basic type) | |
462 | * @array: pointer to array of elements to put into response message | |
463 | * @array_len: length of above array | |
464 | * @error: a pointer to an error to fill on failure | |
465 | * Returns: TRUE if the request succeeded, FALSE if it failed | |
466 | * | |
467 | * Generic getter for array type properties. Array elements type is | |
468 | * required to be basic. | |
469 | */ | |
470 | dbus_bool_t wpas_dbus_simple_array_array_property_getter(DBusMessageIter *iter, | |
471 | const int type, | |
472 | struct wpabuf **array, | |
473 | size_t array_len, | |
474 | DBusError *error) | |
475 | { | |
476 | DBusMessageIter variant_iter, array_iter; | |
477 | char type_str[] = "aa?"; | |
478 | char inner_type_str[] = "a?"; | |
479 | const char *sub_type_str; | |
480 | size_t i; | |
481 | ||
482 | if (!dbus_type_is_basic(type)) { | |
483 | dbus_set_error(error, DBUS_ERROR_FAILED, | |
484 | "%s: given type is not basic", __func__); | |
485 | return FALSE; | |
486 | } | |
487 | ||
488 | sub_type_str = wpa_dbus_type_as_string(type); | |
489 | type_str[2] = sub_type_str[0]; | |
490 | inner_type_str[1] = sub_type_str[0]; | |
491 | ||
492 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, | |
e3c4f0b5 JM |
493 | type_str, &variant_iter) || |
494 | !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY, | |
96c4f3a7 JS |
495 | inner_type_str, &array_iter)) { |
496 | dbus_set_error(error, DBUS_ERROR_FAILED, | |
e3c4f0b5 | 497 | "%s: failed to construct message", __func__); |
96c4f3a7 JS |
498 | return FALSE; |
499 | } | |
500 | ||
010fc5f5 | 501 | for (i = 0; i < array_len && array[i]; i++) { |
96c4f3a7 JS |
502 | wpa_dbus_dict_bin_array_add_element(&array_iter, |
503 | wpabuf_head(array[i]), | |
504 | wpabuf_len(array[i])); | |
505 | ||
506 | } | |
507 | ||
e3c4f0b5 JM |
508 | if (!dbus_message_iter_close_container(&variant_iter, &array_iter) || |
509 | !dbus_message_iter_close_container(iter, &variant_iter)) { | |
96c4f3a7 | 510 | dbus_set_error(error, DBUS_ERROR_FAILED, |
e3c4f0b5 | 511 | "%s: failed to close message", __func__); |
6aeeb6fa DW |
512 | return FALSE; |
513 | } | |
514 | ||
515 | return TRUE; | |
fcea0b7d WS |
516 | } |
517 | ||
518 | ||
8fc2fb56 WS |
519 | /** |
520 | * wpas_dbus_handler_create_interface - Request registration of a network iface | |
521 | * @message: Pointer to incoming dbus message | |
522 | * @global: %wpa_supplicant global data structure | |
523 | * Returns: The object path of the new interface object, | |
524 | * or a dbus error message with more information | |
525 | * | |
2f00ad44 | 526 | * Handler function for "CreateInterface" method call. Handles requests |
8fc2fb56 WS |
527 | * by dbus clients to register a network interface that wpa_supplicant |
528 | * will manage. | |
529 | */ | |
530 | DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, | |
5228401c | 531 | struct wpa_global *global) |
8fc2fb56 | 532 | { |
8fc2fb56 WS |
533 | DBusMessageIter iter_dict; |
534 | DBusMessage *reply = NULL; | |
535 | DBusMessageIter iter; | |
536 | struct wpa_dbus_dict_entry entry; | |
2f00ad44 JM |
537 | char *driver = NULL; |
538 | char *ifname = NULL; | |
d4c1ec56 | 539 | char *confname = NULL; |
2f00ad44 | 540 | char *bridge_ifname = NULL; |
8fc2fb56 WS |
541 | |
542 | dbus_message_iter_init(message, &iter); | |
543 | ||
6aeeb6fa | 544 | if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL)) |
8fc2fb56 WS |
545 | goto error; |
546 | while (wpa_dbus_dict_has_dict_entry(&iter_dict)) { | |
547 | if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) | |
548 | goto error; | |
38279bdb JM |
549 | if (os_strcmp(entry.key, "Driver") == 0 && |
550 | entry.type == DBUS_TYPE_STRING) { | |
beb9e117 | 551 | os_free(driver); |
2f00ad44 JM |
552 | driver = os_strdup(entry.str_value); |
553 | wpa_dbus_dict_entry_clear(&entry); | |
554 | if (driver == NULL) | |
a354bcc8 | 555 | goto oom; |
38279bdb JM |
556 | } else if (os_strcmp(entry.key, "Ifname") == 0 && |
557 | entry.type == DBUS_TYPE_STRING) { | |
beb9e117 | 558 | os_free(ifname); |
2f00ad44 JM |
559 | ifname = os_strdup(entry.str_value); |
560 | wpa_dbus_dict_entry_clear(&entry); | |
561 | if (ifname == NULL) | |
a354bcc8 | 562 | goto oom; |
38279bdb JM |
563 | } else if (os_strcmp(entry.key, "ConfigFile") == 0 && |
564 | entry.type == DBUS_TYPE_STRING) { | |
beb9e117 | 565 | os_free(confname); |
d4c1ec56 SL |
566 | confname = os_strdup(entry.str_value); |
567 | wpa_dbus_dict_entry_clear(&entry); | |
568 | if (confname == NULL) | |
a354bcc8 | 569 | goto oom; |
38279bdb JM |
570 | } else if (os_strcmp(entry.key, "BridgeIfname") == 0 && |
571 | entry.type == DBUS_TYPE_STRING) { | |
beb9e117 | 572 | os_free(bridge_ifname); |
2f00ad44 JM |
573 | bridge_ifname = os_strdup(entry.str_value); |
574 | wpa_dbus_dict_entry_clear(&entry); | |
575 | if (bridge_ifname == NULL) | |
a354bcc8 | 576 | goto oom; |
5228401c | 577 | } else { |
8fc2fb56 WS |
578 | wpa_dbus_dict_entry_clear(&entry); |
579 | goto error; | |
580 | } | |
8fc2fb56 WS |
581 | } |
582 | ||
2f00ad44 JM |
583 | if (ifname == NULL) |
584 | goto error; /* Required Ifname argument missing */ | |
585 | ||
8fc2fb56 WS |
586 | /* |
587 | * Try to get the wpa_supplicant record for this iface, return | |
588 | * an error if we already control it. | |
589 | */ | |
2f00ad44 | 590 | if (wpa_supplicant_get_iface(global, ifname) != NULL) { |
38279bdb JM |
591 | reply = dbus_message_new_error( |
592 | message, WPAS_DBUS_ERROR_IFACE_EXISTS, | |
593 | "wpa_supplicant already controls this interface."); | |
8fc2fb56 WS |
594 | } else { |
595 | struct wpa_supplicant *wpa_s; | |
2f00ad44 | 596 | struct wpa_interface iface; |
38279bdb | 597 | |
2f00ad44 JM |
598 | os_memset(&iface, 0, sizeof(iface)); |
599 | iface.driver = driver; | |
600 | iface.ifname = ifname; | |
d4c1ec56 | 601 | iface.confname = confname; |
2f00ad44 | 602 | iface.bridge_ifname = bridge_ifname; |
8fc2fb56 | 603 | /* Otherwise, have wpa_supplicant attach to it. */ |
1772d348 | 604 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); |
8a78e227 | 605 | if (wpa_s && wpa_s->dbus_new_path) { |
c49cf2d6 | 606 | const char *path = wpa_s->dbus_new_path; |
38279bdb | 607 | |
8fc2fb56 WS |
608 | reply = dbus_message_new_method_return(message); |
609 | dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, | |
38279bdb | 610 | &path, DBUS_TYPE_INVALID); |
8fc2fb56 | 611 | } else { |
5228401c | 612 | reply = wpas_dbus_error_unknown_error( |
38279bdb JM |
613 | message, |
614 | "wpa_supplicant couldn't grab this interface."); | |
8fc2fb56 WS |
615 | } |
616 | } | |
2f00ad44 JM |
617 | |
618 | out: | |
619 | os_free(driver); | |
620 | os_free(ifname); | |
21270bb4 | 621 | os_free(confname); |
2f00ad44 | 622 | os_free(bridge_ifname); |
8fc2fb56 WS |
623 | return reply; |
624 | ||
625 | error: | |
db9a76c0 | 626 | reply = wpas_dbus_error_invalid_args(message, NULL); |
2f00ad44 | 627 | goto out; |
a354bcc8 JM |
628 | oom: |
629 | reply = wpas_dbus_error_no_memory(message); | |
630 | goto out; | |
8fc2fb56 WS |
631 | } |
632 | ||
633 | ||
634 | /** | |
635 | * wpas_dbus_handler_remove_interface - Request deregistration of an interface | |
636 | * @message: Pointer to incoming dbus message | |
637 | * @global: wpa_supplicant global data structure | |
638 | * Returns: a dbus message containing a UINT32 indicating success (1) or | |
639 | * failure (0), or returns a dbus error message with more information | |
640 | * | |
641 | * Handler function for "removeInterface" method call. Handles requests | |
642 | * by dbus clients to deregister a network interface that wpa_supplicant | |
643 | * currently manages. | |
644 | */ | |
645 | DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message, | |
5228401c | 646 | struct wpa_global *global) |
8fc2fb56 WS |
647 | { |
648 | struct wpa_supplicant *wpa_s; | |
649 | char *path; | |
650 | DBusMessage *reply = NULL; | |
651 | ||
652 | dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, | |
5228401c | 653 | DBUS_TYPE_INVALID); |
8fc2fb56 WS |
654 | |
655 | wpa_s = get_iface_by_dbus_path(global, path); | |
5228401c | 656 | if (wpa_s == NULL) |
8fc2fb56 | 657 | reply = wpas_dbus_error_iface_unknown(message); |
df509539 | 658 | else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) { |
5228401c | 659 | reply = wpas_dbus_error_unknown_error( |
38279bdb JM |
660 | message, |
661 | "wpa_supplicant couldn't remove this interface."); | |
8fc2fb56 WS |
662 | } |
663 | ||
664 | return reply; | |
665 | } | |
666 | ||
667 | ||
668 | /** | |
669 | * wpas_dbus_handler_get_interface - Get the object path for an interface name | |
670 | * @message: Pointer to incoming dbus message | |
671 | * @global: %wpa_supplicant global data structure | |
672 | * Returns: The object path of the interface object, | |
673 | * or a dbus error message with more information | |
674 | * | |
675 | * Handler function for "getInterface" method call. | |
676 | */ | |
677 | DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message, | |
5228401c | 678 | struct wpa_global *global) |
8fc2fb56 WS |
679 | { |
680 | DBusMessage *reply = NULL; | |
681 | const char *ifname; | |
682 | const char *path; | |
683 | struct wpa_supplicant *wpa_s; | |
684 | ||
685 | dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &ifname, | |
5228401c | 686 | DBUS_TYPE_INVALID); |
8fc2fb56 WS |
687 | |
688 | wpa_s = wpa_supplicant_get_iface(global, ifname); | |
8a78e227 | 689 | if (wpa_s == NULL || wpa_s->dbus_new_path == NULL) |
5228401c | 690 | return wpas_dbus_error_iface_unknown(message); |
8fc2fb56 | 691 | |
c49cf2d6 | 692 | path = wpa_s->dbus_new_path; |
8fc2fb56 | 693 | reply = dbus_message_new_method_return(message); |
c2b8c674 | 694 | if (reply == NULL) |
a0caebf3 | 695 | return wpas_dbus_error_no_memory(message); |
8fc2fb56 | 696 | if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, |
5228401c | 697 | DBUS_TYPE_INVALID)) { |
8fc2fb56 | 698 | dbus_message_unref(reply); |
a0caebf3 | 699 | return wpas_dbus_error_no_memory(message); |
8fc2fb56 WS |
700 | } |
701 | ||
8fc2fb56 WS |
702 | return reply; |
703 | } | |
704 | ||
705 | ||
706 | /** | |
db9133ac | 707 | * wpas_dbus_getter_debug_level - Get debug level |
6aeeb6fa DW |
708 | * @iter: Pointer to incoming dbus message iter |
709 | * @error: Location to store error on failure | |
710 | * @user_data: Function specific data | |
711 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 | 712 | * |
db9133ac | 713 | * Getter for "DebugLevel" property. |
8fc2fb56 | 714 | */ |
1aa0fb77 DW |
715 | dbus_bool_t wpas_dbus_getter_debug_level( |
716 | const struct wpa_dbus_property_desc *property_desc, | |
717 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 718 | { |
a2753c28 MH |
719 | const char *str; |
720 | int idx = wpa_debug_level; | |
6aeeb6fa | 721 | |
a2753c28 MH |
722 | if (idx < 0) |
723 | idx = 0; | |
14dc0011 PS |
724 | if (idx > 5) |
725 | idx = 5; | |
a2753c28 | 726 | str = debug_strings[idx]; |
6aeeb6fa DW |
727 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, |
728 | &str, error); | |
db9133ac | 729 | } |
8fc2fb56 | 730 | |
8fc2fb56 | 731 | |
db9133ac WS |
732 | /** |
733 | * wpas_dbus_getter_debug_timestamp - Get debug timestamp | |
6aeeb6fa DW |
734 | * @iter: Pointer to incoming dbus message iter |
735 | * @error: Location to store error on failure | |
736 | * @user_data: Function specific data | |
737 | * Returns: TRUE on success, FALSE on failure | |
db9133ac WS |
738 | * |
739 | * Getter for "DebugTimestamp" property. | |
740 | */ | |
1aa0fb77 DW |
741 | dbus_bool_t wpas_dbus_getter_debug_timestamp( |
742 | const struct wpa_dbus_property_desc *property_desc, | |
743 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
db9133ac | 744 | { |
6aeeb6fa DW |
745 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN, |
746 | &wpa_debug_timestamp, error); | |
8fc2fb56 | 747 | |
db9133ac | 748 | } |
8fc2fb56 | 749 | |
8fc2fb56 | 750 | |
db9133ac WS |
751 | /** |
752 | * wpas_dbus_getter_debug_show_keys - Get debug show keys | |
6aeeb6fa DW |
753 | * @iter: Pointer to incoming dbus message iter |
754 | * @error: Location to store error on failure | |
755 | * @user_data: Function specific data | |
756 | * Returns: TRUE on success, FALSE on failure | |
db9133ac WS |
757 | * |
758 | * Getter for "DebugShowKeys" property. | |
759 | */ | |
1aa0fb77 DW |
760 | dbus_bool_t wpas_dbus_getter_debug_show_keys( |
761 | const struct wpa_dbus_property_desc *property_desc, | |
762 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
db9133ac | 763 | { |
6aeeb6fa DW |
764 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN, |
765 | &wpa_debug_show_keys, error); | |
8fc2fb56 | 766 | |
db9133ac | 767 | } |
8fc2fb56 | 768 | |
db9133ac WS |
769 | /** |
770 | * wpas_dbus_setter_debug_level - Set debug level | |
6aeeb6fa DW |
771 | * @iter: Pointer to incoming dbus message iter |
772 | * @error: Location to store error on failure | |
773 | * @user_data: Function specific data | |
774 | * Returns: TRUE on success, FALSE on failure | |
db9133ac WS |
775 | * |
776 | * Setter for "DebugLevel" property. | |
777 | */ | |
1aa0fb77 DW |
778 | dbus_bool_t wpas_dbus_setter_debug_level( |
779 | const struct wpa_dbus_property_desc *property_desc, | |
780 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
db9133ac | 781 | { |
6aeeb6fa | 782 | struct wpa_global *global = user_data; |
a2753c28 MH |
783 | const char *str = NULL; |
784 | int i, val = -1; | |
8fc2fb56 | 785 | |
6aeeb6fa DW |
786 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING, |
787 | &str)) | |
788 | return FALSE; | |
db9133ac | 789 | |
a2753c28 MH |
790 | for (i = 0; debug_strings[i]; i++) |
791 | if (os_strcmp(debug_strings[i], str) == 0) { | |
792 | val = i; | |
793 | break; | |
794 | } | |
795 | ||
796 | if (val < 0 || | |
797 | wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp, | |
db9133ac | 798 | wpa_debug_show_keys)) { |
38279bdb JM |
799 | dbus_set_error_const(error, DBUS_ERROR_FAILED, |
800 | "wrong debug level value"); | |
6aeeb6fa | 801 | return FALSE; |
8fc2fb56 WS |
802 | } |
803 | ||
6aeeb6fa | 804 | return TRUE; |
8fc2fb56 WS |
805 | } |
806 | ||
807 | ||
808 | /** | |
db9133ac | 809 | * wpas_dbus_setter_debug_timestamp - Set debug timestamp |
6aeeb6fa DW |
810 | * @iter: Pointer to incoming dbus message iter |
811 | * @error: Location to store error on failure | |
812 | * @user_data: Function specific data | |
813 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 | 814 | * |
db9133ac | 815 | * Setter for "DebugTimestamp" property. |
8fc2fb56 | 816 | */ |
1aa0fb77 DW |
817 | dbus_bool_t wpas_dbus_setter_debug_timestamp( |
818 | const struct wpa_dbus_property_desc *property_desc, | |
819 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 820 | { |
6aeeb6fa | 821 | struct wpa_global *global = user_data; |
db9133ac | 822 | dbus_bool_t val; |
8fc2fb56 | 823 | |
6aeeb6fa DW |
824 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN, |
825 | &val)) | |
826 | return FALSE; | |
8fc2fb56 | 827 | |
db9133ac WS |
828 | wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0, |
829 | wpa_debug_show_keys); | |
6aeeb6fa | 830 | return TRUE; |
db9133ac | 831 | } |
8fc2fb56 | 832 | |
8fc2fb56 | 833 | |
db9133ac WS |
834 | /** |
835 | * wpas_dbus_setter_debug_show_keys - Set debug show keys | |
6aeeb6fa DW |
836 | * @iter: Pointer to incoming dbus message iter |
837 | * @error: Location to store error on failure | |
838 | * @user_data: Function specific data | |
839 | * Returns: TRUE on success, FALSE on failure | |
db9133ac WS |
840 | * |
841 | * Setter for "DebugShowKeys" property. | |
842 | */ | |
1aa0fb77 DW |
843 | dbus_bool_t wpas_dbus_setter_debug_show_keys( |
844 | const struct wpa_dbus_property_desc *property_desc, | |
845 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
db9133ac | 846 | { |
6aeeb6fa | 847 | struct wpa_global *global = user_data; |
db9133ac | 848 | dbus_bool_t val; |
8fc2fb56 | 849 | |
6aeeb6fa DW |
850 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN, |
851 | &val)) | |
852 | return FALSE; | |
8fc2fb56 | 853 | |
db9133ac WS |
854 | wpa_supplicant_set_debug_params(global, wpa_debug_level, |
855 | wpa_debug_timestamp, | |
856 | val ? 1 : 0); | |
6aeeb6fa | 857 | return TRUE; |
8fc2fb56 WS |
858 | } |
859 | ||
860 | ||
861 | /** | |
862 | * wpas_dbus_getter_interfaces - Request registered interfaces list | |
6aeeb6fa DW |
863 | * @iter: Pointer to incoming dbus message iter |
864 | * @error: Location to store error on failure | |
865 | * @user_data: Function specific data | |
866 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
867 | * |
868 | * Getter for "Interfaces" property. Handles requests | |
869 | * by dbus clients to return list of registered interfaces objects | |
870 | * paths | |
871 | */ | |
1aa0fb77 DW |
872 | dbus_bool_t wpas_dbus_getter_interfaces( |
873 | const struct wpa_dbus_property_desc *property_desc, | |
874 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 875 | { |
6aeeb6fa | 876 | struct wpa_global *global = user_data; |
8fc2fb56 | 877 | struct wpa_supplicant *wpa_s; |
fcea0b7d WS |
878 | const char **paths; |
879 | unsigned int i = 0, num = 0; | |
6aeeb6fa | 880 | dbus_bool_t success; |
8fc2fb56 | 881 | |
8a78e227 JM |
882 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
883 | if (wpa_s->dbus_new_path) | |
884 | num++; | |
885 | } | |
8fc2fb56 | 886 | |
f9884c09 | 887 | paths = os_calloc(num, sizeof(char *)); |
fcea0b7d | 888 | if (!paths) { |
6aeeb6fa DW |
889 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
890 | return FALSE; | |
8fc2fb56 WS |
891 | } |
892 | ||
8a78e227 JM |
893 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
894 | if (wpa_s->dbus_new_path) | |
895 | paths[i++] = wpa_s->dbus_new_path; | |
896 | } | |
8fc2fb56 | 897 | |
6aeeb6fa DW |
898 | success = wpas_dbus_simple_array_property_getter(iter, |
899 | DBUS_TYPE_OBJECT_PATH, | |
900 | paths, num, error); | |
8fc2fb56 | 901 | |
fcea0b7d | 902 | os_free(paths); |
6aeeb6fa | 903 | return success; |
8fc2fb56 WS |
904 | } |
905 | ||
906 | ||
907 | /** | |
908 | * wpas_dbus_getter_eap_methods - Request supported EAP methods list | |
6aeeb6fa DW |
909 | * @iter: Pointer to incoming dbus message iter |
910 | * @error: Location to store error on failure | |
911 | * @user_data: Function specific data | |
912 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
913 | * |
914 | * Getter for "EapMethods" property. Handles requests | |
915 | * by dbus clients to return list of strings with supported EAP methods | |
916 | */ | |
1aa0fb77 DW |
917 | dbus_bool_t wpas_dbus_getter_eap_methods( |
918 | const struct wpa_dbus_property_desc *property_desc, | |
919 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 920 | { |
8fc2fb56 | 921 | char **eap_methods; |
fcea0b7d | 922 | size_t num_items = 0; |
6aeeb6fa | 923 | dbus_bool_t success; |
8fc2fb56 WS |
924 | |
925 | eap_methods = eap_get_names_as_string_array(&num_items); | |
fcea0b7d | 926 | if (!eap_methods) { |
6aeeb6fa DW |
927 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
928 | return FALSE; | |
8fc2fb56 WS |
929 | } |
930 | ||
6aeeb6fa DW |
931 | success = wpas_dbus_simple_array_property_getter(iter, |
932 | DBUS_TYPE_STRING, | |
933 | eap_methods, | |
934 | num_items, error); | |
8fc2fb56 | 935 | |
fcea0b7d WS |
936 | while (num_items) |
937 | os_free(eap_methods[--num_items]); | |
938 | os_free(eap_methods); | |
6aeeb6fa | 939 | return success; |
8fc2fb56 WS |
940 | } |
941 | ||
942 | ||
1634ac06 DW |
943 | /** |
944 | * wpas_dbus_getter_global_capabilities - Request supported global capabilities | |
945 | * @iter: Pointer to incoming dbus message iter | |
946 | * @error: Location to store error on failure | |
947 | * @user_data: Function specific data | |
948 | * Returns: TRUE on success, FALSE on failure | |
949 | * | |
950 | * Getter for "Capabilities" property. Handles requests by dbus clients to | |
951 | * return a list of strings with supported capabilities like AP, RSN IBSS, | |
952 | * and P2P that are determined at compile time. | |
953 | */ | |
1aa0fb77 DW |
954 | dbus_bool_t wpas_dbus_getter_global_capabilities( |
955 | const struct wpa_dbus_property_desc *property_desc, | |
956 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
1634ac06 DW |
957 | { |
958 | const char *capabilities[5] = { NULL, NULL, NULL, NULL, NULL }; | |
959 | size_t num_items = 0; | |
960 | ||
961 | #ifdef CONFIG_AP | |
962 | capabilities[num_items++] = "ap"; | |
963 | #endif /* CONFIG_AP */ | |
964 | #ifdef CONFIG_IBSS_RSN | |
965 | capabilities[num_items++] = "ibss-rsn"; | |
966 | #endif /* CONFIG_IBSS_RSN */ | |
967 | #ifdef CONFIG_P2P | |
968 | capabilities[num_items++] = "p2p"; | |
969 | #endif /* CONFIG_P2P */ | |
970 | #ifdef CONFIG_INTERWORKING | |
971 | capabilities[num_items++] = "interworking"; | |
972 | #endif /* CONFIG_INTERWORKING */ | |
973 | ||
974 | return wpas_dbus_simple_array_property_getter(iter, | |
975 | DBUS_TYPE_STRING, | |
976 | capabilities, | |
977 | num_items, error); | |
978 | } | |
979 | ||
980 | ||
d401b48f JM |
981 | static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var, |
982 | char **type, DBusMessage **reply) | |
8fc2fb56 | 983 | { |
d401b48f | 984 | if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) { |
38279bdb JM |
985 | wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a string", |
986 | __func__); | |
db9a76c0 | 987 | *reply = wpas_dbus_error_invalid_args( |
d401b48f JM |
988 | message, "Wrong Type value type. String required"); |
989 | return -1; | |
990 | } | |
991 | dbus_message_iter_get_basic(var, type); | |
992 | return 0; | |
993 | } | |
8fc2fb56 | 994 | |
8fc2fb56 | 995 | |
d401b48f JM |
996 | static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var, |
997 | struct wpa_driver_scan_params *params, | |
998 | DBusMessage **reply) | |
999 | { | |
1000 | struct wpa_driver_scan_ssid *ssids = params->ssids; | |
1001 | size_t ssids_num = 0; | |
1002 | u8 *ssid; | |
1003 | DBusMessageIter array_iter, sub_array_iter; | |
1004 | char *val; | |
1005 | int len; | |
8fc2fb56 | 1006 | |
d401b48f | 1007 | if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) { |
38279bdb JM |
1008 | wpa_printf(MSG_DEBUG, |
1009 | "%s[dbus]: ssids must be an array of arrays of bytes", | |
1010 | __func__); | |
db9a76c0 | 1011 | *reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1012 | message, |
1013 | "Wrong SSIDs value type. Array of arrays of bytes required"); | |
d401b48f JM |
1014 | return -1; |
1015 | } | |
8fc2fb56 | 1016 | |
d401b48f | 1017 | dbus_message_iter_recurse(var, &array_iter); |
8fc2fb56 | 1018 | |
d401b48f | 1019 | if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY || |
38279bdb JM |
1020 | dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE) { |
1021 | wpa_printf(MSG_DEBUG, | |
1022 | "%s[dbus]: ssids must be an array of arrays of bytes", | |
1023 | __func__); | |
db9a76c0 | 1024 | *reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1025 | message, |
1026 | "Wrong SSIDs value type. Array of arrays of bytes required"); | |
d401b48f JM |
1027 | return -1; |
1028 | } | |
8fc2fb56 | 1029 | |
38279bdb | 1030 | while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) { |
d401b48f | 1031 | if (ssids_num >= WPAS_MAX_SCAN_SSIDS) { |
38279bdb JM |
1032 | wpa_printf(MSG_DEBUG, |
1033 | "%s[dbus]: Too many ssids specified on scan dbus call", | |
1034 | __func__); | |
db9a76c0 | 1035 | *reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1036 | message, |
1037 | "Too many ssids specified. Specify at most four"); | |
d401b48f JM |
1038 | return -1; |
1039 | } | |
8fc2fb56 | 1040 | |
d401b48f | 1041 | dbus_message_iter_recurse(&array_iter, &sub_array_iter); |
8fc2fb56 | 1042 | |
d401b48f | 1043 | dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len); |
8fc2fb56 | 1044 | |
eaa8eefe | 1045 | if (len > SSID_MAX_LEN) { |
f9121813 | 1046 | wpa_printf(MSG_DEBUG, |
38279bdb | 1047 | "%s[dbus]: SSID too long (len=%d max_len=%d)", |
eaa8eefe | 1048 | __func__, len, SSID_MAX_LEN); |
f9121813 SL |
1049 | *reply = wpas_dbus_error_invalid_args( |
1050 | message, "Invalid SSID: too long"); | |
1051 | return -1; | |
1052 | } | |
1053 | ||
556522ee DK |
1054 | if (len != 0) { |
1055 | ssid = os_malloc(len); | |
1056 | if (ssid == NULL) { | |
a0caebf3 | 1057 | *reply = wpas_dbus_error_no_memory(message); |
556522ee DK |
1058 | return -1; |
1059 | } | |
1060 | os_memcpy(ssid, val, len); | |
1061 | } else { | |
1062 | /* Allow zero-length SSIDs */ | |
1063 | ssid = NULL; | |
d401b48f | 1064 | } |
556522ee | 1065 | |
d401b48f JM |
1066 | ssids[ssids_num].ssid = ssid; |
1067 | ssids[ssids_num].ssid_len = len; | |
5228401c | 1068 | |
d401b48f JM |
1069 | dbus_message_iter_next(&array_iter); |
1070 | ssids_num++; | |
1071 | } | |
8fc2fb56 | 1072 | |
d401b48f JM |
1073 | params->num_ssids = ssids_num; |
1074 | return 0; | |
1075 | } | |
8fc2fb56 | 1076 | |
8fc2fb56 | 1077 | |
d401b48f JM |
1078 | static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var, |
1079 | struct wpa_driver_scan_params *params, | |
1080 | DBusMessage **reply) | |
1081 | { | |
1082 | u8 *ies = NULL, *nies; | |
1083 | int ies_len = 0; | |
1084 | DBusMessageIter array_iter, sub_array_iter; | |
1085 | char *val; | |
1086 | int len; | |
8fc2fb56 | 1087 | |
d401b48f | 1088 | if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) { |
38279bdb JM |
1089 | wpa_printf(MSG_DEBUG, |
1090 | "%s[dbus]: ies must be an array of arrays of bytes", | |
1091 | __func__); | |
db9a76c0 | 1092 | *reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1093 | message, |
1094 | "Wrong IEs value type. Array of arrays of bytes required"); | |
d401b48f JM |
1095 | return -1; |
1096 | } | |
8fc2fb56 | 1097 | |
d401b48f | 1098 | dbus_message_iter_recurse(var, &array_iter); |
8fc2fb56 | 1099 | |
d401b48f | 1100 | if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY || |
38279bdb JM |
1101 | dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE) { |
1102 | wpa_printf(MSG_DEBUG, | |
1103 | "%s[dbus]: ies must be an array of arrays of bytes", | |
1104 | __func__); | |
db9a76c0 | 1105 | *reply = wpas_dbus_error_invalid_args( |
d401b48f JM |
1106 | message, "Wrong IEs value type. Array required"); |
1107 | return -1; | |
1108 | } | |
8fc2fb56 | 1109 | |
38279bdb | 1110 | while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) { |
d401b48f | 1111 | dbus_message_iter_recurse(&array_iter, &sub_array_iter); |
8fc2fb56 | 1112 | |
d401b48f JM |
1113 | dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len); |
1114 | if (len == 0) { | |
1115 | dbus_message_iter_next(&array_iter); | |
1116 | continue; | |
1117 | } | |
8fc2fb56 | 1118 | |
d401b48f JM |
1119 | nies = os_realloc(ies, ies_len + len); |
1120 | if (nies == NULL) { | |
d401b48f | 1121 | os_free(ies); |
a0caebf3 | 1122 | *reply = wpas_dbus_error_no_memory(message); |
d401b48f JM |
1123 | return -1; |
1124 | } | |
1125 | ies = nies; | |
1126 | os_memcpy(ies + ies_len, val, len); | |
1127 | ies_len += len; | |
8fc2fb56 | 1128 | |
d401b48f JM |
1129 | dbus_message_iter_next(&array_iter); |
1130 | } | |
5228401c | 1131 | |
d401b48f JM |
1132 | params->extra_ies = ies; |
1133 | params->extra_ies_len = ies_len; | |
1134 | return 0; | |
1135 | } | |
8fc2fb56 | 1136 | |
8fc2fb56 | 1137 | |
d401b48f JM |
1138 | static int wpas_dbus_get_scan_channels(DBusMessage *message, |
1139 | DBusMessageIter *var, | |
1140 | struct wpa_driver_scan_params *params, | |
1141 | DBusMessage **reply) | |
1142 | { | |
1143 | DBusMessageIter array_iter, sub_array_iter; | |
1144 | int *freqs = NULL, *nfreqs; | |
1145 | int freqs_num = 0; | |
8fc2fb56 | 1146 | |
d401b48f | 1147 | if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) { |
38279bdb JM |
1148 | wpa_printf(MSG_DEBUG, |
1149 | "%s[dbus]: Channels must be an array of structs", | |
1150 | __func__); | |
db9a76c0 | 1151 | *reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1152 | message, |
1153 | "Wrong Channels value type. Array of structs required"); | |
d401b48f JM |
1154 | return -1; |
1155 | } | |
8fc2fb56 | 1156 | |
d401b48f | 1157 | dbus_message_iter_recurse(var, &array_iter); |
8fc2fb56 | 1158 | |
d401b48f JM |
1159 | if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) { |
1160 | wpa_printf(MSG_DEBUG, | |
38279bdb JM |
1161 | "%s[dbus]: Channels must be an array of structs", |
1162 | __func__); | |
db9a76c0 | 1163 | *reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1164 | message, |
1165 | "Wrong Channels value type. Array of structs required"); | |
d401b48f JM |
1166 | return -1; |
1167 | } | |
8fc2fb56 | 1168 | |
d401b48f JM |
1169 | while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT) |
1170 | { | |
1171 | int freq, width; | |
8fc2fb56 | 1172 | |
d401b48f | 1173 | dbus_message_iter_recurse(&array_iter, &sub_array_iter); |
8fc2fb56 | 1174 | |
d401b48f JM |
1175 | if (dbus_message_iter_get_arg_type(&sub_array_iter) != |
1176 | DBUS_TYPE_UINT32) { | |
38279bdb JM |
1177 | wpa_printf(MSG_DEBUG, |
1178 | "%s[dbus]: Channel must by specified by struct of two UINT32s %c", | |
1179 | __func__, | |
d401b48f JM |
1180 | dbus_message_iter_get_arg_type( |
1181 | &sub_array_iter)); | |
db9a76c0 | 1182 | *reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1183 | message, |
1184 | "Wrong Channel struct. Two UINT32s required"); | |
d401b48f JM |
1185 | os_free(freqs); |
1186 | return -1; | |
1187 | } | |
1188 | dbus_message_iter_get_basic(&sub_array_iter, &freq); | |
8fc2fb56 | 1189 | |
d401b48f JM |
1190 | if (!dbus_message_iter_next(&sub_array_iter) || |
1191 | dbus_message_iter_get_arg_type(&sub_array_iter) != | |
1192 | DBUS_TYPE_UINT32) { | |
38279bdb JM |
1193 | wpa_printf(MSG_DEBUG, |
1194 | "%s[dbus]: Channel must by specified by struct of two UINT32s", | |
1195 | __func__); | |
db9a76c0 | 1196 | *reply = wpas_dbus_error_invalid_args( |
d401b48f JM |
1197 | message, |
1198 | "Wrong Channel struct. Two UINT32s required"); | |
1199 | os_free(freqs); | |
1200 | return -1; | |
1201 | } | |
8fc2fb56 | 1202 | |
d401b48f | 1203 | dbus_message_iter_get_basic(&sub_array_iter, &width); |
8fc2fb56 | 1204 | |
5228401c | 1205 | #define FREQS_ALLOC_CHUNK 32 |
d401b48f | 1206 | if (freqs_num % FREQS_ALLOC_CHUNK == 0) { |
067ffa26 JM |
1207 | nfreqs = os_realloc_array( |
1208 | freqs, freqs_num + FREQS_ALLOC_CHUNK, | |
1209 | sizeof(int)); | |
d401b48f JM |
1210 | if (nfreqs == NULL) |
1211 | os_free(freqs); | |
1212 | freqs = nfreqs; | |
1213 | } | |
1214 | if (freqs == NULL) { | |
a0caebf3 | 1215 | *reply = wpas_dbus_error_no_memory(message); |
d401b48f JM |
1216 | return -1; |
1217 | } | |
8fc2fb56 | 1218 | |
d401b48f | 1219 | freqs[freqs_num] = freq; |
8fc2fb56 | 1220 | |
d401b48f JM |
1221 | freqs_num++; |
1222 | dbus_message_iter_next(&array_iter); | |
1223 | } | |
8fc2fb56 | 1224 | |
067ffa26 | 1225 | nfreqs = os_realloc_array(freqs, freqs_num + 1, sizeof(int)); |
d401b48f JM |
1226 | if (nfreqs == NULL) |
1227 | os_free(freqs); | |
1228 | freqs = nfreqs; | |
1229 | if (freqs == NULL) { | |
a0caebf3 | 1230 | *reply = wpas_dbus_error_no_memory(message); |
d401b48f JM |
1231 | return -1; |
1232 | } | |
1233 | freqs[freqs_num] = 0; | |
1234 | ||
1235 | params->freqs = freqs; | |
1236 | return 0; | |
1237 | } | |
8fc2fb56 | 1238 | |
d401b48f | 1239 | |
538922a6 DW |
1240 | static int wpas_dbus_get_scan_allow_roam(DBusMessage *message, |
1241 | DBusMessageIter *var, | |
1242 | dbus_bool_t *allow, | |
1243 | DBusMessage **reply) | |
1244 | { | |
1245 | if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN) { | |
38279bdb JM |
1246 | wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a boolean", |
1247 | __func__); | |
538922a6 DW |
1248 | *reply = wpas_dbus_error_invalid_args( |
1249 | message, "Wrong Type value type. Boolean required"); | |
1250 | return -1; | |
1251 | } | |
1252 | dbus_message_iter_get_basic(var, allow); | |
1253 | return 0; | |
1254 | } | |
1255 | ||
1256 | ||
d401b48f JM |
1257 | /** |
1258 | * wpas_dbus_handler_scan - Request a wireless scan on an interface | |
1259 | * @message: Pointer to incoming dbus message | |
1260 | * @wpa_s: wpa_supplicant structure for a network interface | |
1261 | * Returns: NULL indicating success or DBus error message on failure | |
1262 | * | |
1263 | * Handler function for "Scan" method call of a network device. Requests | |
1264 | * that wpa_supplicant perform a wireless scan as soon as possible | |
1265 | * on a particular wireless interface. | |
1266 | */ | |
1267 | DBusMessage * wpas_dbus_handler_scan(DBusMessage *message, | |
1268 | struct wpa_supplicant *wpa_s) | |
1269 | { | |
1270 | DBusMessage *reply = NULL; | |
1271 | DBusMessageIter iter, dict_iter, entry_iter, variant_iter; | |
1272 | char *key = NULL, *type = NULL; | |
1273 | struct wpa_driver_scan_params params; | |
1274 | size_t i; | |
538922a6 | 1275 | dbus_bool_t allow_roam = 1; |
d401b48f JM |
1276 | |
1277 | os_memset(¶ms, 0, sizeof(params)); | |
1278 | ||
1279 | dbus_message_iter_init(message, &iter); | |
1280 | ||
1281 | dbus_message_iter_recurse(&iter, &dict_iter); | |
1282 | ||
1283 | while (dbus_message_iter_get_arg_type(&dict_iter) == | |
38279bdb | 1284 | DBUS_TYPE_DICT_ENTRY) { |
d401b48f JM |
1285 | dbus_message_iter_recurse(&dict_iter, &entry_iter); |
1286 | dbus_message_iter_get_basic(&entry_iter, &key); | |
1287 | dbus_message_iter_next(&entry_iter); | |
1288 | dbus_message_iter_recurse(&entry_iter, &variant_iter); | |
1289 | ||
1290 | if (os_strcmp(key, "Type") == 0) { | |
1291 | if (wpas_dbus_get_scan_type(message, &variant_iter, | |
1292 | &type, &reply) < 0) | |
1293 | goto out; | |
1294 | } else if (os_strcmp(key, "SSIDs") == 0) { | |
1295 | if (wpas_dbus_get_scan_ssids(message, &variant_iter, | |
1296 | ¶ms, &reply) < 0) | |
1297 | goto out; | |
1298 | } else if (os_strcmp(key, "IEs") == 0) { | |
1299 | if (wpas_dbus_get_scan_ies(message, &variant_iter, | |
1300 | ¶ms, &reply) < 0) | |
1301 | goto out; | |
1302 | } else if (os_strcmp(key, "Channels") == 0) { | |
1303 | if (wpas_dbus_get_scan_channels(message, &variant_iter, | |
1304 | ¶ms, &reply) < 0) | |
1305 | goto out; | |
538922a6 DW |
1306 | } else if (os_strcmp(key, "AllowRoam") == 0) { |
1307 | if (wpas_dbus_get_scan_allow_roam(message, | |
1308 | &variant_iter, | |
1309 | &allow_roam, | |
1310 | &reply) < 0) | |
1311 | goto out; | |
5228401c | 1312 | } else { |
38279bdb JM |
1313 | wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown argument %s", |
1314 | __func__, key); | |
db9a76c0 | 1315 | reply = wpas_dbus_error_invalid_args(message, key); |
8fc2fb56 WS |
1316 | goto out; |
1317 | } | |
1318 | ||
1319 | dbus_message_iter_next(&dict_iter); | |
1320 | } | |
1321 | ||
1322 | if (!type) { | |
38279bdb JM |
1323 | wpa_printf(MSG_DEBUG, "%s[dbus]: Scan type not specified", |
1324 | __func__); | |
db9a76c0 | 1325 | reply = wpas_dbus_error_invalid_args(message, key); |
8fc2fb56 WS |
1326 | goto out; |
1327 | } | |
1328 | ||
38279bdb | 1329 | if (os_strcmp(type, "passive") == 0) { |
d401b48f | 1330 | if (params.num_ssids || params.extra_ies_len) { |
38279bdb JM |
1331 | wpa_printf(MSG_DEBUG, |
1332 | "%s[dbus]: SSIDs or IEs specified for passive scan.", | |
1333 | __func__); | |
db9a76c0 | 1334 | reply = wpas_dbus_error_invalid_args( |
38279bdb JM |
1335 | message, |
1336 | "You can specify only Channels in passive scan"); | |
8fc2fb56 | 1337 | goto out; |
5228401c | 1338 | } else { |
a5da6574 AS |
1339 | if (wpa_s->sched_scanning) { |
1340 | wpa_printf(MSG_DEBUG, | |
1341 | "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed", | |
1342 | __func__); | |
1343 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
1344 | } | |
1345 | ||
1346 | if (params.freqs && params.freqs[0]) { | |
1fbff0b5 | 1347 | wpa_s->last_scan_req = MANUAL_SCAN_REQ; |
a5da6574 AS |
1348 | if (wpa_supplicant_trigger_scan(wpa_s, |
1349 | ¶ms)) { | |
1350 | reply = wpas_dbus_error_scan_error( | |
1351 | message, | |
1352 | "Scan request rejected"); | |
1353 | } | |
1354 | } else { | |
1355 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
1356 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
1357 | } | |
8fc2fb56 | 1358 | } |
38279bdb | 1359 | } else if (os_strcmp(type, "active") == 0) { |
a7af023b DK |
1360 | if (!params.num_ssids) { |
1361 | /* Add wildcard ssid */ | |
1362 | params.num_ssids++; | |
1363 | } | |
7c865c68 TB |
1364 | #ifdef CONFIG_AUTOSCAN |
1365 | autoscan_deinit(wpa_s); | |
1366 | #endif /* CONFIG_AUTOSCAN */ | |
a5da6574 AS |
1367 | if (wpa_s->sched_scanning) { |
1368 | wpa_printf(MSG_DEBUG, | |
1369 | "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed", | |
1370 | __func__); | |
1371 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
1372 | } | |
1373 | ||
1fbff0b5 | 1374 | wpa_s->last_scan_req = MANUAL_SCAN_REQ; |
e9b32dae | 1375 | if (wpa_supplicant_trigger_scan(wpa_s, ¶ms)) { |
1376 | reply = wpas_dbus_error_scan_error( | |
1377 | message, "Scan request rejected"); | |
1378 | } | |
5228401c | 1379 | } else { |
38279bdb JM |
1380 | wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown scan type: %s", |
1381 | __func__, type); | |
db9a76c0 JM |
1382 | reply = wpas_dbus_error_invalid_args(message, |
1383 | "Wrong scan type"); | |
8fc2fb56 WS |
1384 | goto out; |
1385 | } | |
1386 | ||
538922a6 DW |
1387 | if (!allow_roam) |
1388 | wpa_s->scan_res_handler = scan_only_handler; | |
1389 | ||
8fc2fb56 | 1390 | out: |
d401b48f JM |
1391 | for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++) |
1392 | os_free((u8 *) params.ssids[i].ssid); | |
5228401c | 1393 | os_free((u8 *) params.extra_ies); |
8fc2fb56 WS |
1394 | os_free(params.freqs); |
1395 | return reply; | |
1396 | } | |
1397 | ||
1398 | ||
7a4a93b9 DW |
1399 | /** |
1400 | * wpas_dbus_handler_signal_poll - Request immediate signal properties | |
1401 | * @message: Pointer to incoming dbus message | |
1402 | * @wpa_s: wpa_supplicant structure for a network interface | |
1403 | * Returns: NULL indicating success or DBus error message on failure | |
1404 | * | |
1405 | * Handler function for "SignalPoll" method call of a network device. Requests | |
1406 | * that wpa_supplicant read signal properties like RSSI, noise, and link | |
1407 | * speed and return them. | |
1408 | */ | |
1409 | DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message, | |
1410 | struct wpa_supplicant *wpa_s) | |
1411 | { | |
1412 | struct wpa_signal_info si; | |
1413 | DBusMessage *reply = NULL; | |
1414 | DBusMessageIter iter, iter_dict, variant_iter; | |
1415 | int ret; | |
1416 | ||
1417 | ret = wpa_drv_signal_poll(wpa_s, &si); | |
1418 | if (ret) { | |
1419 | return dbus_message_new_error(message, DBUS_ERROR_FAILED, | |
1420 | "Failed to read signal"); | |
1421 | } | |
1422 | ||
1423 | reply = dbus_message_new_method_return(message); | |
1424 | if (reply == NULL) | |
1425 | goto nomem; | |
1426 | ||
1427 | dbus_message_iter_init_append(reply, &iter); | |
1428 | ||
1429 | if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, | |
e3c4f0b5 JM |
1430 | "a{sv}", &variant_iter) || |
1431 | !wpa_dbus_dict_open_write(&variant_iter, &iter_dict) || | |
1432 | !wpa_dbus_dict_append_int32(&iter_dict, "rssi", | |
1433 | si.current_signal) || | |
1434 | !wpa_dbus_dict_append_int32(&iter_dict, "linkspeed", | |
1435 | si.current_txrate / 1000) || | |
1436 | !wpa_dbus_dict_append_int32(&iter_dict, "noise", | |
1437 | si.current_noise) || | |
1438 | !wpa_dbus_dict_append_uint32(&iter_dict, "frequency", | |
1439 | si.frequency) || | |
1440 | (si.chanwidth != CHAN_WIDTH_UNKNOWN && | |
1441 | !wpa_dbus_dict_append_string( | |
1442 | &iter_dict, "width", | |
1443 | channel_width_to_string(si.chanwidth))) || | |
1444 | (si.center_frq1 > 0 && si.center_frq2 > 0 && | |
1445 | (!wpa_dbus_dict_append_int32(&iter_dict, "center-frq1", | |
1446 | si.center_frq1) || | |
1447 | !wpa_dbus_dict_append_int32(&iter_dict, "center-frq2", | |
1448 | si.center_frq2))) || | |
1449 | (si.avg_signal && | |
1450 | !wpa_dbus_dict_append_int32(&iter_dict, "avg-rssi", | |
1451 | si.avg_signal)) || | |
1452 | !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) || | |
1453 | !dbus_message_iter_close_container(&iter, &variant_iter)) | |
7a4a93b9 DW |
1454 | goto nomem; |
1455 | ||
1456 | return reply; | |
1457 | ||
1458 | nomem: | |
1459 | if (reply) | |
1460 | dbus_message_unref(reply); | |
a0caebf3 | 1461 | return wpas_dbus_error_no_memory(message); |
7a4a93b9 DW |
1462 | } |
1463 | ||
1464 | ||
8fc2fb56 WS |
1465 | /* |
1466 | * wpas_dbus_handler_disconnect - Terminate the current connection | |
1467 | * @message: Pointer to incoming dbus message | |
1468 | * @wpa_s: wpa_supplicant structure for a network interface | |
1469 | * Returns: NotConnected DBus error message if already not connected | |
1470 | * or NULL otherwise. | |
1471 | * | |
1472 | * Handler function for "Disconnect" method call of network interface. | |
1473 | */ | |
1474 | DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message, | |
5228401c | 1475 | struct wpa_supplicant *wpa_s) |
8fc2fb56 WS |
1476 | { |
1477 | if (wpa_s->current_ssid != NULL) { | |
1478 | wpa_s->disconnected = 1; | |
f9cd8587 JM |
1479 | wpa_supplicant_deauthenticate(wpa_s, |
1480 | WLAN_REASON_DEAUTH_LEAVING); | |
8fc2fb56 WS |
1481 | |
1482 | return NULL; | |
1483 | } | |
5228401c JM |
1484 | |
1485 | return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED, | |
1486 | "This interface is not connected"); | |
8fc2fb56 WS |
1487 | } |
1488 | ||
1489 | ||
1490 | /** | |
1491 | * wpas_dbus_new_iface_add_network - Add a new configured network | |
1492 | * @message: Pointer to incoming dbus message | |
1493 | * @wpa_s: wpa_supplicant structure for a network interface | |
1494 | * Returns: A dbus message containing the object path of the new network | |
1495 | * | |
1496 | * Handler function for "AddNetwork" method call of a network interface. | |
1497 | */ | |
1498 | DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message, | |
5228401c | 1499 | struct wpa_supplicant *wpa_s) |
8fc2fb56 WS |
1500 | { |
1501 | DBusMessage *reply = NULL; | |
1502 | DBusMessageIter iter; | |
1503 | struct wpa_ssid *ssid = NULL; | |
3e87bd54 | 1504 | char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf; |
6aeeb6fa | 1505 | DBusError error; |
8fc2fb56 WS |
1506 | |
1507 | dbus_message_iter_init(message, &iter); | |
1508 | ||
8a78e227 JM |
1509 | if (wpa_s->dbus_new_path) |
1510 | ssid = wpa_config_add_network(wpa_s->conf); | |
8fc2fb56 | 1511 | if (ssid == NULL) { |
38279bdb JM |
1512 | wpa_printf(MSG_ERROR, "%s[dbus]: can't add new interface.", |
1513 | __func__); | |
5228401c JM |
1514 | reply = wpas_dbus_error_unknown_error( |
1515 | message, | |
38279bdb | 1516 | "wpa_supplicant could not add a network on this interface."); |
8fc2fb56 WS |
1517 | goto err; |
1518 | } | |
1519 | wpas_notify_network_added(wpa_s, ssid); | |
1520 | ssid->disabled = 1; | |
1521 | wpa_config_set_network_defaults(ssid); | |
1522 | ||
6aeeb6fa DW |
1523 | dbus_error_init(&error); |
1524 | if (!set_network_properties(wpa_s, ssid, &iter, &error)) { | |
38279bdb JM |
1525 | wpa_printf(MSG_DEBUG, |
1526 | "%s[dbus]: control interface couldn't set network properties", | |
1527 | __func__); | |
6aeeb6fa DW |
1528 | reply = wpas_dbus_reply_new_from_error(message, &error, |
1529 | DBUS_ERROR_INVALID_ARGS, | |
1530 | "Failed to add network"); | |
1531 | dbus_error_free(&error); | |
8fc2fb56 WS |
1532 | goto err; |
1533 | } | |
1534 | ||
1535 | /* Construct the object path for this network. */ | |
5228401c JM |
1536 | os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX, |
1537 | "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d", | |
c49cf2d6 | 1538 | wpa_s->dbus_new_path, ssid->id); |
8fc2fb56 WS |
1539 | |
1540 | reply = dbus_message_new_method_return(message); | |
1541 | if (reply == NULL) { | |
a0caebf3 | 1542 | reply = wpas_dbus_error_no_memory(message); |
8fc2fb56 WS |
1543 | goto err; |
1544 | } | |
1545 | if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, | |
5228401c | 1546 | DBUS_TYPE_INVALID)) { |
8fc2fb56 | 1547 | dbus_message_unref(reply); |
a0caebf3 | 1548 | reply = wpas_dbus_error_no_memory(message); |
8fc2fb56 WS |
1549 | goto err; |
1550 | } | |
1551 | ||
8fc2fb56 WS |
1552 | return reply; |
1553 | ||
1554 | err: | |
1555 | if (ssid) { | |
1556 | wpas_notify_network_removed(wpa_s, ssid); | |
1557 | wpa_config_remove_network(wpa_s->conf, ssid->id); | |
1558 | } | |
8fc2fb56 WS |
1559 | return reply; |
1560 | } | |
1561 | ||
1562 | ||
6ed31175 | 1563 | /** |
481e66b1 | 1564 | * wpas_dbus_handler_reassociate - Reassociate |
6ed31175 PS |
1565 | * @message: Pointer to incoming dbus message |
1566 | * @wpa_s: wpa_supplicant structure for a network interface | |
481e66b1 | 1567 | * Returns: InterfaceDisabled DBus error message if disabled |
6ed31175 PS |
1568 | * or NULL otherwise. |
1569 | * | |
1570 | * Handler function for "Reassociate" method call of network interface. | |
1571 | */ | |
1572 | DBusMessage * wpas_dbus_handler_reassociate(DBusMessage *message, | |
1573 | struct wpa_supplicant *wpa_s) | |
1574 | { | |
481e66b1 | 1575 | if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) { |
9796a86c | 1576 | wpas_request_connection(wpa_s); |
6ed31175 PS |
1577 | return NULL; |
1578 | } | |
1579 | ||
481e66b1 FC |
1580 | return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_DISABLED, |
1581 | "This interface is disabled"); | |
6ed31175 PS |
1582 | } |
1583 | ||
1584 | ||
c143c3b7 NW |
1585 | /** |
1586 | * wpas_dbus_handler_expect_disconnect - ExpectDisconnect | |
1587 | * @message: Pointer to incoming dbus message | |
1588 | * @global: %wpa_supplicant global data structure | |
1589 | * Returns: NULL | |
1590 | * | |
1591 | * Handler function for notifying system there will be a expected disconnect. | |
1592 | * This will prevent wpa_supplicant from adding blacklists upon next disconnect.. | |
1593 | */ | |
1594 | DBusMessage * wpas_dbus_handler_expect_disconnect(DBusMessage *message, | |
1595 | struct wpa_global *global) | |
1596 | { | |
1597 | struct wpa_supplicant *wpa_s = global->ifaces; | |
1598 | ||
1599 | for (; wpa_s; wpa_s = wpa_s->next) | |
1600 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) | |
1601 | wpa_s->own_disconnect_req = 1; | |
1602 | return NULL; | |
1603 | } | |
1604 | ||
1605 | ||
0f44ec8e PQ |
1606 | /** |
1607 | * wpas_dbus_handler_reattach - Reattach to current AP | |
1608 | * @message: Pointer to incoming dbus message | |
1609 | * @wpa_s: wpa_supplicant structure for a network interface | |
1610 | * Returns: NotConnected DBus error message if not connected | |
1611 | * or NULL otherwise. | |
1612 | * | |
1613 | * Handler function for "Reattach" method call of network interface. | |
1614 | */ | |
1615 | DBusMessage * wpas_dbus_handler_reattach(DBusMessage *message, | |
1616 | struct wpa_supplicant *wpa_s) | |
1617 | { | |
1618 | if (wpa_s->current_ssid != NULL) { | |
1619 | wpa_s->reattach = 1; | |
1620 | wpas_request_connection(wpa_s); | |
1621 | return NULL; | |
1622 | } | |
1623 | ||
1624 | return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED, | |
1625 | "This interface is not connected"); | |
1626 | } | |
1627 | ||
1628 | ||
b649c0af MH |
1629 | /** |
1630 | * wpas_dbus_handler_reconnect - Reconnect if disconnected | |
1631 | * @message: Pointer to incoming dbus message | |
1632 | * @wpa_s: wpa_supplicant structure for a network interface | |
1633 | * Returns: InterfaceDisabled DBus error message if disabled | |
1634 | * or NULL otherwise. | |
1635 | * | |
1636 | * Handler function for "Reconnect" method call of network interface. | |
1637 | */ | |
1638 | DBusMessage * wpas_dbus_handler_reconnect(DBusMessage *message, | |
1639 | struct wpa_supplicant *wpa_s) | |
1640 | { | |
1641 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | |
1642 | return dbus_message_new_error(message, | |
1643 | WPAS_DBUS_ERROR_IFACE_DISABLED, | |
1644 | "This interface is disabled"); | |
1645 | } | |
1646 | ||
1647 | if (wpa_s->disconnected) | |
1648 | wpas_request_connection(wpa_s); | |
1649 | return NULL; | |
1650 | } | |
1651 | ||
1652 | ||
8fc2fb56 WS |
1653 | /** |
1654 | * wpas_dbus_handler_remove_network - Remove a configured network | |
1655 | * @message: Pointer to incoming dbus message | |
1656 | * @wpa_s: wpa_supplicant structure for a network interface | |
1657 | * Returns: NULL on success or dbus error on failure | |
1658 | * | |
1659 | * Handler function for "RemoveNetwork" method call of a network interface. | |
1660 | */ | |
1661 | DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message, | |
5228401c | 1662 | struct wpa_supplicant *wpa_s) |
8fc2fb56 WS |
1663 | { |
1664 | DBusMessage *reply = NULL; | |
1665 | const char *op; | |
054dc313 | 1666 | char *iface, *net_id; |
8fc2fb56 WS |
1667 | int id; |
1668 | struct wpa_ssid *ssid; | |
725fc39e | 1669 | int was_disabled; |
8fc2fb56 WS |
1670 | |
1671 | dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op, | |
5228401c | 1672 | DBUS_TYPE_INVALID); |
8fc2fb56 WS |
1673 | |
1674 | /* Extract the network ID and ensure the network */ | |
1675 | /* is actually a child of this interface */ | |
054dc313 JM |
1676 | iface = wpas_dbus_new_decompose_object_path(op, |
1677 | WPAS_DBUS_NEW_NETWORKS_PART, | |
1678 | &net_id); | |
8a78e227 | 1679 | if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path || |
45ac5793 | 1680 | os_strcmp(iface, wpa_s->dbus_new_path) != 0) { |
db9a76c0 | 1681 | reply = wpas_dbus_error_invalid_args(message, op); |
8fc2fb56 WS |
1682 | goto out; |
1683 | } | |
1684 | ||
45ac5793 | 1685 | errno = 0; |
8fc2fb56 | 1686 | id = strtoul(net_id, NULL, 10); |
45ac5793 | 1687 | if (errno != 0) { |
db9a76c0 | 1688 | reply = wpas_dbus_error_invalid_args(message, op); |
8fc2fb56 WS |
1689 | goto out; |
1690 | } | |
1691 | ||
1692 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1693 | if (ssid == NULL) { | |
1694 | reply = wpas_dbus_error_network_unknown(message); | |
1695 | goto out; | |
1696 | } | |
1697 | ||
725fc39e DS |
1698 | was_disabled = ssid->disabled; |
1699 | ||
8fc2fb56 WS |
1700 | wpas_notify_network_removed(wpa_s, ssid); |
1701 | ||
8fc2fb56 | 1702 | if (ssid == wpa_s->current_ssid) |
f9cd8587 JM |
1703 | wpa_supplicant_deauthenticate(wpa_s, |
1704 | WLAN_REASON_DEAUTH_LEAVING); | |
725fc39e | 1705 | else if (!was_disabled && wpa_s->sched_scanning) { |
38279bdb JM |
1706 | wpa_printf(MSG_DEBUG, |
1707 | "Stop ongoing sched_scan to remove network from filters"); | |
725fc39e DS |
1708 | wpa_supplicant_cancel_sched_scan(wpa_s); |
1709 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
1710 | } | |
1711 | ||
316f92cd HM |
1712 | if (wpa_config_remove_network(wpa_s->conf, id) < 0) { |
1713 | wpa_printf(MSG_ERROR, | |
38279bdb JM |
1714 | "%s[dbus]: error occurred when removing network %d", |
1715 | __func__, id); | |
316f92cd | 1716 | reply = wpas_dbus_error_unknown_error( |
38279bdb JM |
1717 | message, |
1718 | "error removing the specified network on is interface."); | |
316f92cd HM |
1719 | goto out; |
1720 | } | |
8fc2fb56 WS |
1721 | |
1722 | out: | |
1723 | os_free(iface); | |
8fc2fb56 WS |
1724 | return reply; |
1725 | } | |
1726 | ||
1727 | ||
7c49fdd0 SL |
1728 | static void remove_network(void *arg, struct wpa_ssid *ssid) |
1729 | { | |
1730 | struct wpa_supplicant *wpa_s = arg; | |
1731 | ||
1732 | wpas_notify_network_removed(wpa_s, ssid); | |
1733 | ||
1734 | if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) { | |
1735 | wpa_printf(MSG_ERROR, | |
38279bdb JM |
1736 | "%s[dbus]: error occurred when removing network %d", |
1737 | __func__, ssid->id); | |
7c49fdd0 SL |
1738 | return; |
1739 | } | |
1740 | ||
1741 | if (ssid == wpa_s->current_ssid) | |
07783eaa JM |
1742 | wpa_supplicant_deauthenticate(wpa_s, |
1743 | WLAN_REASON_DEAUTH_LEAVING); | |
7c49fdd0 SL |
1744 | } |
1745 | ||
1746 | ||
1747 | /** | |
1748 | * wpas_dbus_handler_remove_all_networks - Remove all configured networks | |
1749 | * @message: Pointer to incoming dbus message | |
1750 | * @wpa_s: wpa_supplicant structure for a network interface | |
1751 | * Returns: NULL on success or dbus error on failure | |
1752 | * | |
1753 | * Handler function for "RemoveAllNetworks" method call of a network interface. | |
1754 | */ | |
1755 | DBusMessage * wpas_dbus_handler_remove_all_networks( | |
1756 | DBusMessage *message, struct wpa_supplicant *wpa_s) | |
1757 | { | |
725fc39e DS |
1758 | if (wpa_s->sched_scanning) |
1759 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
1760 | ||
7c49fdd0 SL |
1761 | /* NB: could check for failure and return an error */ |
1762 | wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s); | |
1763 | return NULL; | |
1764 | } | |
1765 | ||
1766 | ||
8fc2fb56 WS |
1767 | /** |
1768 | * wpas_dbus_handler_select_network - Attempt association with a network | |
1769 | * @message: Pointer to incoming dbus message | |
1770 | * @wpa_s: wpa_supplicant structure for a network interface | |
1771 | * Returns: NULL on success or dbus error on failure | |
1772 | * | |
1773 | * Handler function for "SelectNetwork" method call of network interface. | |
1774 | */ | |
1775 | DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message, | |
5228401c | 1776 | struct wpa_supplicant *wpa_s) |
8fc2fb56 WS |
1777 | { |
1778 | DBusMessage *reply = NULL; | |
1779 | const char *op; | |
054dc313 | 1780 | char *iface, *net_id; |
8fc2fb56 WS |
1781 | int id; |
1782 | struct wpa_ssid *ssid; | |
1783 | ||
1784 | dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op, | |
5228401c | 1785 | DBUS_TYPE_INVALID); |
8fc2fb56 WS |
1786 | |
1787 | /* Extract the network ID and ensure the network */ | |
1788 | /* is actually a child of this interface */ | |
054dc313 JM |
1789 | iface = wpas_dbus_new_decompose_object_path(op, |
1790 | WPAS_DBUS_NEW_NETWORKS_PART, | |
1791 | &net_id); | |
8a78e227 | 1792 | if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path || |
45ac5793 | 1793 | os_strcmp(iface, wpa_s->dbus_new_path) != 0) { |
db9a76c0 | 1794 | reply = wpas_dbus_error_invalid_args(message, op); |
8fc2fb56 WS |
1795 | goto out; |
1796 | } | |
1797 | ||
45ac5793 | 1798 | errno = 0; |
8fc2fb56 | 1799 | id = strtoul(net_id, NULL, 10); |
45ac5793 | 1800 | if (errno != 0) { |
db9a76c0 | 1801 | reply = wpas_dbus_error_invalid_args(message, op); |
8fc2fb56 WS |
1802 | goto out; |
1803 | } | |
1804 | ||
1805 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1806 | if (ssid == NULL) { | |
1807 | reply = wpas_dbus_error_network_unknown(message); | |
1808 | goto out; | |
1809 | } | |
5228401c | 1810 | |
8fc2fb56 WS |
1811 | /* Finally, associate with the network */ |
1812 | wpa_supplicant_select_network(wpa_s, ssid); | |
1813 | ||
1814 | out: | |
1815 | os_free(iface); | |
8fc2fb56 WS |
1816 | return reply; |
1817 | } | |
1818 | ||
1819 | ||
e9c3c1af DW |
1820 | /** |
1821 | * wpas_dbus_handler_network_reply - Reply to a NetworkRequest signal | |
1822 | * @message: Pointer to incoming dbus message | |
1823 | * @wpa_s: wpa_supplicant structure for a network interface | |
1824 | * Returns: NULL on success or dbus error on failure | |
1825 | * | |
1826 | * Handler function for "NetworkReply" method call of network interface. | |
1827 | */ | |
1828 | DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message, | |
1829 | struct wpa_supplicant *wpa_s) | |
1830 | { | |
1831 | #ifdef IEEE8021X_EAPOL | |
1832 | DBusMessage *reply = NULL; | |
1833 | const char *op, *field, *value; | |
054dc313 | 1834 | char *iface, *net_id; |
e9c3c1af DW |
1835 | int id; |
1836 | struct wpa_ssid *ssid; | |
1837 | ||
1838 | if (!dbus_message_get_args(message, NULL, | |
38279bdb JM |
1839 | DBUS_TYPE_OBJECT_PATH, &op, |
1840 | DBUS_TYPE_STRING, &field, | |
1841 | DBUS_TYPE_STRING, &value, | |
1842 | DBUS_TYPE_INVALID)) | |
e9c3c1af DW |
1843 | return wpas_dbus_error_invalid_args(message, NULL); |
1844 | ||
1845 | /* Extract the network ID and ensure the network */ | |
1846 | /* is actually a child of this interface */ | |
054dc313 JM |
1847 | iface = wpas_dbus_new_decompose_object_path(op, |
1848 | WPAS_DBUS_NEW_NETWORKS_PART, | |
1849 | &net_id); | |
8a78e227 | 1850 | if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path || |
45ac5793 | 1851 | os_strcmp(iface, wpa_s->dbus_new_path) != 0) { |
e9c3c1af DW |
1852 | reply = wpas_dbus_error_invalid_args(message, op); |
1853 | goto out; | |
1854 | } | |
1855 | ||
45ac5793 | 1856 | errno = 0; |
e9c3c1af | 1857 | id = strtoul(net_id, NULL, 10); |
45ac5793 | 1858 | if (errno != 0) { |
e9c3c1af DW |
1859 | reply = wpas_dbus_error_invalid_args(message, net_id); |
1860 | goto out; | |
1861 | } | |
1862 | ||
1863 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1864 | if (ssid == NULL) { | |
1865 | reply = wpas_dbus_error_network_unknown(message); | |
1866 | goto out; | |
1867 | } | |
1868 | ||
1869 | if (wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, | |
1870 | field, value) < 0) | |
1871 | reply = wpas_dbus_error_invalid_args(message, field); | |
1872 | else { | |
1873 | /* Tell EAP to retry immediately */ | |
1874 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | |
1875 | } | |
1876 | ||
1877 | out: | |
1878 | os_free(iface); | |
e9c3c1af DW |
1879 | return reply; |
1880 | #else /* IEEE8021X_EAPOL */ | |
fb7e7dae | 1881 | wpa_printf(MSG_DEBUG, "dbus: 802.1X not included"); |
e9c3c1af DW |
1882 | return wpas_dbus_error_unknown_error(message, "802.1X not included"); |
1883 | #endif /* IEEE8021X_EAPOL */ | |
1884 | } | |
1885 | ||
1886 | ||
21f01a8e JM |
1887 | #ifndef CONFIG_NO_CONFIG_BLOBS |
1888 | ||
8fc2fb56 WS |
1889 | /** |
1890 | * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates) | |
1891 | * @message: Pointer to incoming dbus message | |
1892 | * @wpa_s: %wpa_supplicant data structure | |
1893 | * Returns: A dbus message containing an error on failure or NULL on success | |
1894 | * | |
1895 | * Asks wpa_supplicant to internally store a binary blobs. | |
1896 | */ | |
1897 | DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message, | |
5228401c | 1898 | struct wpa_supplicant *wpa_s) |
8fc2fb56 WS |
1899 | { |
1900 | DBusMessage *reply = NULL; | |
1901 | DBusMessageIter iter, array_iter; | |
1902 | ||
1903 | char *blob_name; | |
1904 | u8 *blob_data; | |
1905 | int blob_len; | |
1906 | struct wpa_config_blob *blob = NULL; | |
1907 | ||
1908 | dbus_message_iter_init(message, &iter); | |
1909 | dbus_message_iter_get_basic(&iter, &blob_name); | |
1910 | ||
1911 | if (wpa_config_get_blob(wpa_s->conf, blob_name)) { | |
5228401c JM |
1912 | return dbus_message_new_error(message, |
1913 | WPAS_DBUS_ERROR_BLOB_EXISTS, | |
1914 | NULL); | |
8fc2fb56 WS |
1915 | } |
1916 | ||
1917 | dbus_message_iter_next(&iter); | |
1918 | dbus_message_iter_recurse(&iter, &array_iter); | |
1919 | ||
1920 | dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len); | |
1921 | ||
1922 | blob = os_zalloc(sizeof(*blob)); | |
1923 | if (!blob) { | |
a0caebf3 | 1924 | reply = wpas_dbus_error_no_memory(message); |
8fc2fb56 WS |
1925 | goto err; |
1926 | } | |
1927 | ||
1928 | blob->data = os_malloc(blob_len); | |
a0caebf3 JM |
1929 | blob->name = os_strdup(blob_name); |
1930 | if (!blob->data || !blob->name) { | |
1931 | reply = wpas_dbus_error_no_memory(message); | |
8fc2fb56 WS |
1932 | goto err; |
1933 | } | |
1934 | os_memcpy(blob->data, blob_data, blob_len); | |
8fc2fb56 | 1935 | blob->len = blob_len; |
8fc2fb56 WS |
1936 | |
1937 | wpa_config_set_blob(wpa_s->conf, blob); | |
1938 | wpas_notify_blob_added(wpa_s, blob->name); | |
1939 | ||
1940 | return reply; | |
1941 | ||
1942 | err: | |
1943 | if (blob) { | |
1944 | os_free(blob->name); | |
1945 | os_free(blob->data); | |
1946 | os_free(blob); | |
1947 | } | |
1948 | return reply; | |
1949 | } | |
1950 | ||
1951 | ||
1952 | /** | |
1953 | * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates) | |
1954 | * @message: Pointer to incoming dbus message | |
1955 | * @wpa_s: %wpa_supplicant data structure | |
1956 | * Returns: A dbus message containing array of bytes (blob) | |
1957 | * | |
1958 | * Gets one wpa_supplicant's binary blobs. | |
1959 | */ | |
1960 | DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message, | |
5228401c | 1961 | struct wpa_supplicant *wpa_s) |
8fc2fb56 WS |
1962 | { |
1963 | DBusMessage *reply = NULL; | |
1964 | DBusMessageIter iter, array_iter; | |
1965 | ||
1966 | char *blob_name; | |
1967 | const struct wpa_config_blob *blob; | |
1968 | ||
1969 | dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name, | |
5228401c | 1970 | DBUS_TYPE_INVALID); |
8fc2fb56 WS |
1971 | |
1972 | blob = wpa_config_get_blob(wpa_s->conf, blob_name); | |
1973 | if (!blob) { | |
5228401c JM |
1974 | return dbus_message_new_error(message, |
1975 | WPAS_DBUS_ERROR_BLOB_UNKNOWN, | |
1976 | "Blob id not set"); | |
8fc2fb56 WS |
1977 | } |
1978 | ||
1979 | reply = dbus_message_new_method_return(message); | |
a0caebf3 JM |
1980 | if (!reply) |
1981 | return wpas_dbus_error_no_memory(message); | |
8fc2fb56 WS |
1982 | |
1983 | dbus_message_iter_init_append(reply, &iter); | |
1984 | ||
1985 | if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, | |
5228401c | 1986 | DBUS_TYPE_BYTE_AS_STRING, |
a0caebf3 JM |
1987 | &array_iter) || |
1988 | !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE, | |
1989 | &(blob->data), blob->len) || | |
1990 | !dbus_message_iter_close_container(&iter, &array_iter)) { | |
8fc2fb56 | 1991 | dbus_message_unref(reply); |
a0caebf3 | 1992 | reply = wpas_dbus_error_no_memory(message); |
8fc2fb56 WS |
1993 | } |
1994 | ||
8fc2fb56 | 1995 | return reply; |
8fc2fb56 WS |
1996 | } |
1997 | ||
1998 | ||
1999 | /** | |
2000 | * wpas_remove_handler_remove_blob - Remove named binary blob | |
2001 | * @message: Pointer to incoming dbus message | |
2002 | * @wpa_s: %wpa_supplicant data structure | |
2003 | * Returns: NULL on success or dbus error | |
2004 | * | |
2005 | * Asks wpa_supplicant to internally remove a binary blobs. | |
2006 | */ | |
2007 | DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message, | |
5228401c | 2008 | struct wpa_supplicant *wpa_s) |
8fc2fb56 WS |
2009 | { |
2010 | DBusMessage *reply = NULL; | |
8fc2fb56 WS |
2011 | char *blob_name; |
2012 | ||
2013 | dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name, | |
5228401c | 2014 | DBUS_TYPE_INVALID); |
8fc2fb56 WS |
2015 | |
2016 | if (wpa_config_remove_blob(wpa_s->conf, blob_name)) { | |
5228401c JM |
2017 | return dbus_message_new_error(message, |
2018 | WPAS_DBUS_ERROR_BLOB_UNKNOWN, | |
2019 | "Blob id not set"); | |
8fc2fb56 WS |
2020 | } |
2021 | wpas_notify_blob_removed(wpa_s, blob_name); | |
2022 | ||
2023 | return reply; | |
2024 | ||
2025 | } | |
2026 | ||
21f01a8e JM |
2027 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
2028 | ||
2029 | ||
2b65b30d SL |
2030 | /* |
2031 | * wpas_dbus_handler_flush_bss - Flush the BSS cache | |
2032 | * @message: Pointer to incoming dbus message | |
2033 | * @wpa_s: wpa_supplicant structure for a network interface | |
2034 | * Returns: NULL | |
2035 | * | |
2036 | * Handler function for "FlushBSS" method call of network interface. | |
2037 | */ | |
2038 | DBusMessage * wpas_dbus_handler_flush_bss(DBusMessage *message, | |
2039 | struct wpa_supplicant *wpa_s) | |
2040 | { | |
2041 | dbus_uint32_t age; | |
2042 | ||
2043 | dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &age, | |
2044 | DBUS_TYPE_INVALID); | |
2045 | ||
2046 | if (age == 0) | |
2047 | wpa_bss_flush(wpa_s); | |
2048 | else | |
2049 | wpa_bss_flush_by_age(wpa_s, age); | |
2050 | ||
2051 | return NULL; | |
2052 | } | |
2053 | ||
8fc2fb56 | 2054 | |
67892d5c TB |
2055 | #ifdef CONFIG_AUTOSCAN |
2056 | /** | |
2057 | * wpas_dbus_handler_autoscan - Set autoscan parameters for the interface | |
2058 | * @message: Pointer to incoming dbus message | |
2059 | * @wpa_s: wpa_supplicant structure for a network interface | |
2060 | * Returns: NULL | |
2061 | * | |
2062 | * Handler function for "AutoScan" method call of network interface. | |
2063 | */ | |
2064 | DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message, | |
2065 | struct wpa_supplicant *wpa_s) | |
2066 | { | |
2067 | DBusMessage *reply = NULL; | |
2068 | enum wpa_states state = wpa_s->wpa_state; | |
2069 | char *arg; | |
2070 | ||
2071 | dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg, | |
2072 | DBUS_TYPE_INVALID); | |
2073 | ||
2074 | if (arg != NULL && os_strlen(arg) > 0) { | |
2075 | char *tmp; | |
38279bdb | 2076 | |
67892d5c TB |
2077 | tmp = os_strdup(arg); |
2078 | if (tmp == NULL) { | |
a0caebf3 | 2079 | reply = wpas_dbus_error_no_memory(message); |
67892d5c TB |
2080 | } else { |
2081 | os_free(wpa_s->conf->autoscan); | |
2082 | wpa_s->conf->autoscan = tmp; | |
2083 | if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | |
99218999 | 2084 | autoscan_init(wpa_s, 1); |
99f00324 JM |
2085 | else if (state == WPA_SCANNING) |
2086 | wpa_supplicant_reinit_autoscan(wpa_s); | |
67892d5c TB |
2087 | } |
2088 | } else if (arg != NULL && os_strlen(arg) == 0) { | |
2089 | os_free(wpa_s->conf->autoscan); | |
2090 | wpa_s->conf->autoscan = NULL; | |
2091 | autoscan_deinit(wpa_s); | |
2092 | } else | |
2093 | reply = dbus_message_new_error(message, | |
2094 | DBUS_ERROR_INVALID_ARGS, | |
2095 | NULL); | |
2096 | ||
2097 | return reply; | |
2098 | } | |
2099 | #endif /* CONFIG_AUTOSCAN */ | |
2100 | ||
2101 | ||
754632c9 PS |
2102 | /* |
2103 | * wpas_dbus_handler_eap_logoff - IEEE 802.1X EAPOL state machine logoff | |
2104 | * @message: Pointer to incoming dbus message | |
2105 | * @wpa_s: wpa_supplicant structure for a network interface | |
2106 | * Returns: NULL | |
2107 | * | |
2108 | * Handler function for "EAPLogoff" method call of network interface. | |
2109 | */ | |
2110 | DBusMessage * wpas_dbus_handler_eap_logoff(DBusMessage *message, | |
2111 | struct wpa_supplicant *wpa_s) | |
2112 | { | |
2113 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | |
2114 | return NULL; | |
2115 | } | |
2116 | ||
2117 | ||
2118 | /* | |
2119 | * wpas_dbus_handler_eap_logon - IEEE 802.1X EAPOL state machine logon | |
2120 | * @message: Pointer to incoming dbus message | |
2121 | * @wpa_s: wpa_supplicant structure for a network interface | |
2122 | * Returns: NULL | |
2123 | * | |
2124 | * Handler function for "EAPLogin" method call of network interface. | |
2125 | */ | |
2126 | DBusMessage * wpas_dbus_handler_eap_logon(DBusMessage *message, | |
2127 | struct wpa_supplicant *wpa_s) | |
2128 | { | |
2129 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | |
2130 | return NULL; | |
2131 | } | |
2132 | ||
2133 | ||
cea97a04 PS |
2134 | #ifdef CONFIG_TDLS |
2135 | ||
508e24c2 JM |
2136 | static int get_peer_hwaddr_helper(DBusMessage *message, const char *func_name, |
2137 | u8 *peer_address, DBusMessage **error) | |
cea97a04 PS |
2138 | { |
2139 | const char *peer_string; | |
2140 | ||
508e24c2 JM |
2141 | *error = NULL; |
2142 | ||
cea97a04 PS |
2143 | if (!dbus_message_get_args(message, NULL, |
2144 | DBUS_TYPE_STRING, &peer_string, | |
508e24c2 JM |
2145 | DBUS_TYPE_INVALID)) { |
2146 | *error = wpas_dbus_error_invalid_args(message, NULL); | |
2147 | return -1; | |
2148 | } | |
cea97a04 PS |
2149 | |
2150 | if (hwaddr_aton(peer_string, peer_address)) { | |
2151 | wpa_printf(MSG_DEBUG, "%s: invalid address '%s'", | |
2152 | func_name, peer_string); | |
508e24c2 | 2153 | *error = wpas_dbus_error_invalid_args( |
cea97a04 | 2154 | message, "Invalid hardware address format"); |
508e24c2 | 2155 | return -1; |
cea97a04 PS |
2156 | } |
2157 | ||
508e24c2 | 2158 | return 0; |
cea97a04 PS |
2159 | } |
2160 | ||
2161 | ||
2162 | /* | |
2163 | * wpas_dbus_handler_tdls_discover - Discover TDLS peer | |
2164 | * @message: Pointer to incoming dbus message | |
2165 | * @wpa_s: wpa_supplicant structure for a network interface | |
2166 | * Returns: NULL indicating success or DBus error message on failure | |
2167 | * | |
2168 | * Handler function for "TDLSDiscover" method call of network interface. | |
2169 | */ | |
2170 | DBusMessage * wpas_dbus_handler_tdls_discover(DBusMessage *message, | |
2171 | struct wpa_supplicant *wpa_s) | |
2172 | { | |
2173 | u8 peer[ETH_ALEN]; | |
2174 | DBusMessage *error_reply; | |
2175 | int ret; | |
2176 | ||
508e24c2 | 2177 | if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0) |
cea97a04 PS |
2178 | return error_reply; |
2179 | ||
2180 | wpa_printf(MSG_DEBUG, "DBUS TDLS_DISCOVER " MACSTR, MAC2STR(peer)); | |
2181 | ||
2182 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
2183 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); | |
2184 | else | |
2185 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | |
2186 | ||
2187 | if (ret) { | |
2188 | return wpas_dbus_error_unknown_error( | |
2189 | message, "error performing TDLS discovery"); | |
2190 | } | |
2191 | ||
2192 | return NULL; | |
2193 | } | |
2194 | ||
2195 | ||
2196 | /* | |
2197 | * wpas_dbus_handler_tdls_setup - Setup TDLS session | |
2198 | * @message: Pointer to incoming dbus message | |
2199 | * @wpa_s: wpa_supplicant structure for a network interface | |
2200 | * Returns: NULL indicating success or DBus error message on failure | |
2201 | * | |
2202 | * Handler function for "TDLSSetup" method call of network interface. | |
2203 | */ | |
2204 | DBusMessage * wpas_dbus_handler_tdls_setup(DBusMessage *message, | |
2205 | struct wpa_supplicant *wpa_s) | |
2206 | { | |
2207 | u8 peer[ETH_ALEN]; | |
2208 | DBusMessage *error_reply; | |
2209 | int ret; | |
2210 | ||
508e24c2 | 2211 | if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0) |
cea97a04 PS |
2212 | return error_reply; |
2213 | ||
2214 | wpa_printf(MSG_DEBUG, "DBUS TDLS_SETUP " MACSTR, MAC2STR(peer)); | |
2215 | ||
2216 | wpa_tdls_remove(wpa_s->wpa, peer); | |
2217 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
2218 | ret = wpa_tdls_start(wpa_s->wpa, peer); | |
2219 | else | |
2220 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
2221 | ||
2222 | if (ret) { | |
2223 | return wpas_dbus_error_unknown_error( | |
2224 | message, "error performing TDLS setup"); | |
2225 | } | |
2226 | ||
2227 | return NULL; | |
2228 | } | |
2229 | ||
2230 | ||
2231 | /* | |
2232 | * wpas_dbus_handler_tdls_status - Return TDLS session status | |
2233 | * @message: Pointer to incoming dbus message | |
2234 | * @wpa_s: wpa_supplicant structure for a network interface | |
2235 | * Returns: A string representing the state of the link to this TDLS peer | |
2236 | * | |
2237 | * Handler function for "TDLSStatus" method call of network interface. | |
2238 | */ | |
2239 | DBusMessage * wpas_dbus_handler_tdls_status(DBusMessage *message, | |
2240 | struct wpa_supplicant *wpa_s) | |
2241 | { | |
2242 | u8 peer[ETH_ALEN]; | |
2243 | DBusMessage *reply; | |
2244 | const char *tdls_status; | |
2245 | ||
508e24c2 | 2246 | if (get_peer_hwaddr_helper(message, __func__, peer, &reply) < 0) |
cea97a04 PS |
2247 | return reply; |
2248 | ||
2249 | wpa_printf(MSG_DEBUG, "DBUS TDLS_STATUS " MACSTR, MAC2STR(peer)); | |
2250 | ||
2251 | tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer); | |
2252 | ||
2253 | reply = dbus_message_new_method_return(message); | |
2254 | dbus_message_append_args(reply, DBUS_TYPE_STRING, | |
2255 | &tdls_status, DBUS_TYPE_INVALID); | |
2256 | return reply; | |
2257 | } | |
2258 | ||
2259 | ||
2260 | /* | |
2261 | * wpas_dbus_handler_tdls_teardown - Teardown TDLS session | |
2262 | * @message: Pointer to incoming dbus message | |
2263 | * @wpa_s: wpa_supplicant structure for a network interface | |
2264 | * Returns: NULL indicating success or DBus error message on failure | |
2265 | * | |
2266 | * Handler function for "TDLSTeardown" method call of network interface. | |
2267 | */ | |
2268 | DBusMessage * wpas_dbus_handler_tdls_teardown(DBusMessage *message, | |
2269 | struct wpa_supplicant *wpa_s) | |
2270 | { | |
2271 | u8 peer[ETH_ALEN]; | |
2272 | DBusMessage *error_reply; | |
2273 | int ret; | |
2274 | ||
508e24c2 | 2275 | if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0) |
cea97a04 PS |
2276 | return error_reply; |
2277 | ||
2278 | wpa_printf(MSG_DEBUG, "DBUS TDLS_TEARDOWN " MACSTR, MAC2STR(peer)); | |
2279 | ||
2280 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
2281 | ret = wpa_tdls_teardown_link( | |
2282 | wpa_s->wpa, peer, | |
2283 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); | |
2284 | else | |
2285 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
2286 | ||
2287 | if (ret) { | |
2288 | return wpas_dbus_error_unknown_error( | |
2289 | message, "error performing TDLS teardown"); | |
2290 | } | |
2291 | ||
2292 | return NULL; | |
2293 | } | |
2294 | ||
2295 | #endif /* CONFIG_TDLS */ | |
2296 | ||
2297 | ||
2d0fe6bc PK |
2298 | #ifndef CONFIG_NO_CONFIG_WRITE |
2299 | /** | |
2300 | * wpas_dbus_handler_save_config - Save configuration to configuration file | |
2301 | * @message: Pointer to incoming dbus message | |
2302 | * @wpa_s: wpa_supplicant structure for a network interface | |
2303 | * Returns: NULL on Success, Otherwise errror message | |
2304 | * | |
2305 | * Handler function for "SaveConfig" method call of network interface. | |
2306 | */ | |
2307 | DBusMessage * wpas_dbus_handler_save_config(DBusMessage *message, | |
2308 | struct wpa_supplicant *wpa_s) | |
2309 | { | |
2310 | int ret; | |
2311 | ||
2312 | if (!wpa_s->conf->update_config) { | |
2313 | return wpas_dbus_error_unknown_error( | |
2314 | message, | |
2315 | "Not allowed to update configuration (update_config=0)"); | |
2316 | } | |
2317 | ||
2318 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | |
2319 | if (ret) | |
2320 | return wpas_dbus_error_unknown_error( | |
2321 | message, "Failed to update configuration"); | |
2322 | return NULL; | |
2323 | } | |
2324 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
2325 | ||
2326 | ||
bdec7ee5 MS |
2327 | /** |
2328 | * wpas_dbus_handler_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path | |
2329 | * @message: Pointer to incoming dbus message | |
2330 | * @wpa_s: %wpa_supplicant data structure | |
2331 | * Returns: A dbus message containing an error on failure or NULL on success | |
2332 | * | |
2333 | * Sets the PKCS #11 engine and module path. | |
2334 | */ | |
2335 | DBusMessage * wpas_dbus_handler_set_pkcs11_engine_and_module_path( | |
2336 | DBusMessage *message, struct wpa_supplicant *wpa_s) | |
2337 | { | |
2338 | DBusMessageIter iter; | |
2339 | char *value = NULL; | |
2340 | char *pkcs11_engine_path = NULL; | |
2341 | char *pkcs11_module_path = NULL; | |
2342 | ||
2343 | dbus_message_iter_init(message, &iter); | |
2344 | dbus_message_iter_get_basic(&iter, &value); | |
2345 | if (value == NULL) { | |
2346 | return dbus_message_new_error( | |
2347 | message, DBUS_ERROR_INVALID_ARGS, | |
2348 | "Invalid pkcs11_engine_path argument"); | |
2349 | } | |
2350 | /* Empty path defaults to NULL */ | |
2351 | if (os_strlen(value)) | |
2352 | pkcs11_engine_path = value; | |
2353 | ||
2354 | dbus_message_iter_next(&iter); | |
2355 | dbus_message_iter_get_basic(&iter, &value); | |
2356 | if (value == NULL) { | |
2357 | os_free(pkcs11_engine_path); | |
2358 | return dbus_message_new_error( | |
2359 | message, DBUS_ERROR_INVALID_ARGS, | |
2360 | "Invalid pkcs11_module_path argument"); | |
2361 | } | |
2362 | /* Empty path defaults to NULL */ | |
2363 | if (os_strlen(value)) | |
2364 | pkcs11_module_path = value; | |
2365 | ||
2366 | if (wpas_set_pkcs11_engine_and_module_path(wpa_s, pkcs11_engine_path, | |
2367 | pkcs11_module_path)) | |
2368 | return dbus_message_new_error( | |
2369 | message, DBUS_ERROR_FAILED, | |
38279bdb | 2370 | "Reinit of the EAPOL state machine with the new PKCS #11 engine and module path failed."); |
bdec7ee5 | 2371 | |
8a78e227 JM |
2372 | if (wpa_s->dbus_new_path) { |
2373 | wpa_dbus_mark_property_changed( | |
2374 | wpa_s->global->dbus, wpa_s->dbus_new_path, | |
2375 | WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11EnginePath"); | |
2376 | wpa_dbus_mark_property_changed( | |
2377 | wpa_s->global->dbus, wpa_s->dbus_new_path, | |
2378 | WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11ModulePath"); | |
2379 | } | |
bdec7ee5 MS |
2380 | |
2381 | return NULL; | |
2382 | } | |
2383 | ||
2384 | ||
8fc2fb56 WS |
2385 | /** |
2386 | * wpas_dbus_getter_capabilities - Return interface capabilities | |
6aeeb6fa DW |
2387 | * @iter: Pointer to incoming dbus message iter |
2388 | * @error: Location to store error on failure | |
2389 | * @user_data: Function specific data | |
2390 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
2391 | * |
2392 | * Getter for "Capabilities" property of an interface. | |
2393 | */ | |
1aa0fb77 DW |
2394 | dbus_bool_t wpas_dbus_getter_capabilities( |
2395 | const struct wpa_dbus_property_desc *property_desc, | |
2396 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 2397 | { |
6aeeb6fa | 2398 | struct wpa_supplicant *wpa_s = user_data; |
8fc2fb56 WS |
2399 | struct wpa_driver_capa capa; |
2400 | int res; | |
6aeeb6fa | 2401 | DBusMessageIter iter_dict, iter_dict_entry, iter_dict_val, iter_array, |
5228401c JM |
2402 | variant_iter; |
2403 | const char *scans[] = { "active", "passive", "ssid" }; | |
8fc2fb56 | 2404 | |
6aeeb6fa | 2405 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, |
e3c4f0b5 JM |
2406 | "a{sv}", &variant_iter) || |
2407 | !wpa_dbus_dict_open_write(&variant_iter, &iter_dict)) | |
8fc2fb56 WS |
2408 | goto nomem; |
2409 | ||
2410 | res = wpa_drv_get_capa(wpa_s, &capa); | |
2411 | ||
2412 | /***** pairwise cipher */ | |
2413 | if (res < 0) { | |
2414 | const char *args[] = {"ccmp", "tkip", "none"}; | |
38279bdb | 2415 | |
8fc2fb56 | 2416 | if (!wpa_dbus_dict_append_string_array( |
5228401c | 2417 | &iter_dict, "Pairwise", args, |
e7ecab4a | 2418 | ARRAY_SIZE(args))) |
8fc2fb56 WS |
2419 | goto nomem; |
2420 | } else { | |
2421 | if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise", | |
2422 | &iter_dict_entry, | |
2423 | &iter_dict_val, | |
e3c4f0b5 JM |
2424 | &iter_array) || |
2425 | ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP_256) && | |
2426 | !wpa_dbus_dict_string_array_add_element( | |
2427 | &iter_array, "ccmp-256")) || | |
2428 | ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP_256) && | |
2429 | !wpa_dbus_dict_string_array_add_element( | |
2430 | &iter_array, "gcmp-256")) || | |
2431 | ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) && | |
2432 | !wpa_dbus_dict_string_array_add_element( | |
2433 | &iter_array, "ccmp")) || | |
2434 | ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) && | |
2435 | !wpa_dbus_dict_string_array_add_element( | |
2436 | &iter_array, "gcmp")) || | |
2437 | ((capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) && | |
2438 | !wpa_dbus_dict_string_array_add_element( | |
2439 | &iter_array, "tkip")) || | |
2440 | ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) && | |
2441 | !wpa_dbus_dict_string_array_add_element( | |
2442 | &iter_array, "none")) || | |
2443 | !wpa_dbus_dict_end_string_array(&iter_dict, | |
8fc2fb56 WS |
2444 | &iter_dict_entry, |
2445 | &iter_dict_val, | |
2446 | &iter_array)) | |
2447 | goto nomem; | |
2448 | } | |
2449 | ||
2450 | /***** group cipher */ | |
2451 | if (res < 0) { | |
2452 | const char *args[] = { | |
2453 | "ccmp", "tkip", "wep104", "wep40" | |
2454 | }; | |
38279bdb | 2455 | |
8fc2fb56 | 2456 | if (!wpa_dbus_dict_append_string_array( |
5228401c | 2457 | &iter_dict, "Group", args, |
e7ecab4a | 2458 | ARRAY_SIZE(args))) |
8fc2fb56 WS |
2459 | goto nomem; |
2460 | } else { | |
2461 | if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group", | |
2462 | &iter_dict_entry, | |
2463 | &iter_dict_val, | |
e3c4f0b5 JM |
2464 | &iter_array) || |
2465 | ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP_256) && | |
2466 | !wpa_dbus_dict_string_array_add_element( | |
2467 | &iter_array, "ccmp-256")) || | |
2468 | ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP_256) && | |
2469 | !wpa_dbus_dict_string_array_add_element( | |
2470 | &iter_array, "gcmp-256")) || | |
2471 | ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) && | |
2472 | !wpa_dbus_dict_string_array_add_element( | |
2473 | &iter_array, "ccmp")) || | |
2474 | ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) && | |
2475 | !wpa_dbus_dict_string_array_add_element( | |
2476 | &iter_array, "gcmp")) || | |
2477 | ((capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) && | |
2478 | !wpa_dbus_dict_string_array_add_element( | |
2479 | &iter_array, "tkip")) || | |
2480 | ((capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) && | |
2481 | !wpa_dbus_dict_string_array_add_element( | |
2482 | &iter_array, "wep104")) || | |
2483 | ((capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) && | |
2484 | !wpa_dbus_dict_string_array_add_element( | |
2485 | &iter_array, "wep40")) || | |
2486 | !wpa_dbus_dict_end_string_array(&iter_dict, | |
8fc2fb56 WS |
2487 | &iter_dict_entry, |
2488 | &iter_dict_val, | |
2489 | &iter_array)) | |
2490 | goto nomem; | |
2491 | } | |
2492 | ||
2493 | /***** key management */ | |
2494 | if (res < 0) { | |
2495 | const char *args[] = { | |
2496 | "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none", | |
2497 | #ifdef CONFIG_WPS | |
2498 | "wps", | |
2499 | #endif /* CONFIG_WPS */ | |
2500 | "none" | |
2501 | }; | |
2502 | if (!wpa_dbus_dict_append_string_array( | |
5228401c | 2503 | &iter_dict, "KeyMgmt", args, |
e7ecab4a | 2504 | ARRAY_SIZE(args))) |
8fc2fb56 WS |
2505 | goto nomem; |
2506 | } else { | |
2507 | if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt", | |
2508 | &iter_dict_entry, | |
2509 | &iter_dict_val, | |
e3c4f0b5 JM |
2510 | &iter_array) || |
2511 | !wpa_dbus_dict_string_array_add_element(&iter_array, | |
2512 | "none") || | |
2513 | !wpa_dbus_dict_string_array_add_element(&iter_array, | |
8fc2fb56 WS |
2514 | "ieee8021x")) |
2515 | goto nomem; | |
2516 | ||
2517 | if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
2518 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | |
2519 | if (!wpa_dbus_dict_string_array_add_element( | |
e3c4f0b5 JM |
2520 | &iter_array, "wpa-eap") || |
2521 | ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) && | |
2522 | !wpa_dbus_dict_string_array_add_element( | |
2523 | &iter_array, "wpa-ft-eap"))) | |
8fc2fb56 | 2524 | goto nomem; |
c56ce48a | 2525 | |
c56ce48a WS |
2526 | /* TODO: Ensure that driver actually supports sha256 encryption. */ |
2527 | #ifdef CONFIG_IEEE80211W | |
2528 | if (!wpa_dbus_dict_string_array_add_element( | |
2529 | &iter_array, "wpa-eap-sha256")) | |
2530 | goto nomem; | |
2531 | #endif /* CONFIG_IEEE80211W */ | |
8fc2fb56 WS |
2532 | } |
2533 | ||
2534 | if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
2535 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
2536 | if (!wpa_dbus_dict_string_array_add_element( | |
e3c4f0b5 JM |
2537 | &iter_array, "wpa-psk") || |
2538 | ((capa.key_mgmt & | |
2539 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) && | |
2540 | !wpa_dbus_dict_string_array_add_element( | |
2541 | &iter_array, "wpa-ft-psk"))) | |
8fc2fb56 | 2542 | goto nomem; |
c56ce48a | 2543 | |
c56ce48a WS |
2544 | /* TODO: Ensure that driver actually supports sha256 encryption. */ |
2545 | #ifdef CONFIG_IEEE80211W | |
2546 | if (!wpa_dbus_dict_string_array_add_element( | |
2547 | &iter_array, "wpa-psk-sha256")) | |
2548 | goto nomem; | |
2549 | #endif /* CONFIG_IEEE80211W */ | |
8fc2fb56 WS |
2550 | } |
2551 | ||
e3c4f0b5 JM |
2552 | if ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) && |
2553 | !wpa_dbus_dict_string_array_add_element(&iter_array, | |
2554 | "wpa-none")) | |
2555 | goto nomem; | |
8fc2fb56 WS |
2556 | |
2557 | ||
2558 | #ifdef CONFIG_WPS | |
5228401c JM |
2559 | if (!wpa_dbus_dict_string_array_add_element(&iter_array, |
2560 | "wps")) | |
8fc2fb56 WS |
2561 | goto nomem; |
2562 | #endif /* CONFIG_WPS */ | |
2563 | ||
2564 | if (!wpa_dbus_dict_end_string_array(&iter_dict, | |
2565 | &iter_dict_entry, | |
2566 | &iter_dict_val, | |
2567 | &iter_array)) | |
2568 | goto nomem; | |
8fc2fb56 WS |
2569 | } |
2570 | ||
2571 | /***** WPA protocol */ | |
2572 | if (res < 0) { | |
2573 | const char *args[] = { "rsn", "wpa" }; | |
38279bdb | 2574 | |
8fc2fb56 | 2575 | if (!wpa_dbus_dict_append_string_array( |
5228401c | 2576 | &iter_dict, "Protocol", args, |
e7ecab4a | 2577 | ARRAY_SIZE(args))) |
8fc2fb56 WS |
2578 | goto nomem; |
2579 | } else { | |
2580 | if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol", | |
2581 | &iter_dict_entry, | |
2582 | &iter_dict_val, | |
e3c4f0b5 JM |
2583 | &iter_array) || |
2584 | ((capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
2585 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) && | |
2586 | !wpa_dbus_dict_string_array_add_element( | |
2587 | &iter_array, "rsn")) || | |
2588 | ((capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
2589 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) && | |
2590 | !wpa_dbus_dict_string_array_add_element( | |
2591 | &iter_array, "wpa")) || | |
2592 | !wpa_dbus_dict_end_string_array(&iter_dict, | |
8fc2fb56 WS |
2593 | &iter_dict_entry, |
2594 | &iter_dict_val, | |
2595 | &iter_array)) | |
2596 | goto nomem; | |
2597 | } | |
2598 | ||
2599 | /***** auth alg */ | |
2600 | if (res < 0) { | |
2601 | const char *args[] = { "open", "shared", "leap" }; | |
38279bdb | 2602 | |
8fc2fb56 | 2603 | if (!wpa_dbus_dict_append_string_array( |
5228401c | 2604 | &iter_dict, "AuthAlg", args, |
e7ecab4a | 2605 | ARRAY_SIZE(args))) |
8fc2fb56 WS |
2606 | goto nomem; |
2607 | } else { | |
2608 | if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg", | |
2609 | &iter_dict_entry, | |
2610 | &iter_dict_val, | |
2611 | &iter_array)) | |
2612 | goto nomem; | |
2613 | ||
e3c4f0b5 JM |
2614 | if (((capa.auth & WPA_DRIVER_AUTH_OPEN) && |
2615 | !wpa_dbus_dict_string_array_add_element( | |
2616 | &iter_array, "open")) || | |
2617 | ((capa.auth & WPA_DRIVER_AUTH_SHARED) && | |
2618 | !wpa_dbus_dict_string_array_add_element( | |
2619 | &iter_array, "shared")) || | |
2620 | ((capa.auth & WPA_DRIVER_AUTH_LEAP) && | |
2621 | !wpa_dbus_dict_string_array_add_element( | |
2622 | &iter_array, "leap")) || | |
2623 | !wpa_dbus_dict_end_string_array(&iter_dict, | |
8fc2fb56 WS |
2624 | &iter_dict_entry, |
2625 | &iter_dict_val, | |
2626 | &iter_array)) | |
2627 | goto nomem; | |
2628 | } | |
2629 | ||
2630 | /***** Scan */ | |
5228401c | 2631 | if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans, |
e7ecab4a | 2632 | ARRAY_SIZE(scans))) |
8fc2fb56 WS |
2633 | goto nomem; |
2634 | ||
2635 | /***** Modes */ | |
c988980d JS |
2636 | if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Modes", |
2637 | &iter_dict_entry, | |
2638 | &iter_dict_val, | |
e3c4f0b5 JM |
2639 | &iter_array) || |
2640 | !wpa_dbus_dict_string_array_add_element( | |
2641 | &iter_array, "infrastructure") || | |
2642 | !wpa_dbus_dict_string_array_add_element( | |
2643 | &iter_array, "ad-hoc") || | |
2644 | (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_AP) && | |
2645 | !wpa_dbus_dict_string_array_add_element( | |
2646 | &iter_array, "ap")) || | |
2647 | (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && | |
2648 | !wpa_dbus_dict_string_array_add_element( | |
2649 | &iter_array, "p2p")) || | |
2650 | !wpa_dbus_dict_end_string_array(&iter_dict, | |
c988980d JS |
2651 | &iter_dict_entry, |
2652 | &iter_dict_val, | |
2653 | &iter_array)) | |
2654 | goto nomem; | |
2655 | /***** Modes end */ | |
2656 | ||
0098ce6d MA |
2657 | if (res >= 0) { |
2658 | dbus_int32_t max_scan_ssid = capa.max_scan_ssids; | |
2659 | ||
2660 | if (!wpa_dbus_dict_append_int32(&iter_dict, "MaxScanSSID", | |
2661 | max_scan_ssid)) | |
2662 | goto nomem; | |
2663 | } | |
2664 | ||
e3c4f0b5 JM |
2665 | if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) || |
2666 | !dbus_message_iter_close_container(iter, &variant_iter)) | |
8fc2fb56 WS |
2667 | goto nomem; |
2668 | ||
6aeeb6fa | 2669 | return TRUE; |
8fc2fb56 WS |
2670 | |
2671 | nomem: | |
6aeeb6fa DW |
2672 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
2673 | return FALSE; | |
8fc2fb56 WS |
2674 | } |
2675 | ||
2676 | ||
2677 | /** | |
2678 | * wpas_dbus_getter_state - Get interface state | |
6aeeb6fa DW |
2679 | * @iter: Pointer to incoming dbus message iter |
2680 | * @error: Location to store error on failure | |
2681 | * @user_data: Function specific data | |
2682 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
2683 | * |
2684 | * Getter for "State" property. | |
2685 | */ | |
1aa0fb77 DW |
2686 | dbus_bool_t wpas_dbus_getter_state( |
2687 | const struct wpa_dbus_property_desc *property_desc, | |
2688 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 2689 | { |
6aeeb6fa | 2690 | struct wpa_supplicant *wpa_s = user_data; |
8fc2fb56 WS |
2691 | const char *str_state; |
2692 | char *state_ls, *tmp; | |
6aeeb6fa | 2693 | dbus_bool_t success = FALSE; |
8fc2fb56 | 2694 | |
fcea0b7d | 2695 | str_state = wpa_supplicant_state_txt(wpa_s->wpa_state); |
8fc2fb56 | 2696 | |
fcea0b7d WS |
2697 | /* make state string lowercase to fit new DBus API convention |
2698 | */ | |
2699 | state_ls = tmp = os_strdup(str_state); | |
2700 | if (!tmp) { | |
6aeeb6fa DW |
2701 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
2702 | return FALSE; | |
fcea0b7d WS |
2703 | } |
2704 | while (*tmp) { | |
2705 | *tmp = tolower(*tmp); | |
2706 | tmp++; | |
2707 | } | |
8fc2fb56 | 2708 | |
6aeeb6fa DW |
2709 | success = wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, |
2710 | &state_ls, error); | |
8fc2fb56 | 2711 | |
fcea0b7d | 2712 | os_free(state_ls); |
5228401c | 2713 | |
6aeeb6fa | 2714 | return success; |
8fc2fb56 WS |
2715 | } |
2716 | ||
fcea0b7d | 2717 | |
8fc2fb56 WS |
2718 | /** |
2719 | * wpas_dbus_new_iface_get_scanning - Get interface scanning state | |
6aeeb6fa DW |
2720 | * @iter: Pointer to incoming dbus message iter |
2721 | * @error: Location to store error on failure | |
2722 | * @user_data: Function specific data | |
2723 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
2724 | * |
2725 | * Getter for "scanning" property. | |
2726 | */ | |
1aa0fb77 DW |
2727 | dbus_bool_t wpas_dbus_getter_scanning( |
2728 | const struct wpa_dbus_property_desc *property_desc, | |
2729 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 2730 | { |
6aeeb6fa | 2731 | struct wpa_supplicant *wpa_s = user_data; |
8fc2fb56 | 2732 | dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE; |
6aeeb6fa DW |
2733 | |
2734 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN, | |
2735 | &scanning, error); | |
fcea0b7d | 2736 | } |
8fc2fb56 WS |
2737 | |
2738 | ||
2739 | /** | |
2740 | * wpas_dbus_getter_ap_scan - Control roaming mode | |
6aeeb6fa DW |
2741 | * @iter: Pointer to incoming dbus message iter |
2742 | * @error: Location to store error on failure | |
2743 | * @user_data: Function specific data | |
2744 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
2745 | * |
2746 | * Getter function for "ApScan" property. | |
2747 | */ | |
1aa0fb77 DW |
2748 | dbus_bool_t wpas_dbus_getter_ap_scan( |
2749 | const struct wpa_dbus_property_desc *property_desc, | |
2750 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 2751 | { |
6aeeb6fa | 2752 | struct wpa_supplicant *wpa_s = user_data; |
8fc2fb56 | 2753 | dbus_uint32_t ap_scan = wpa_s->conf->ap_scan; |
6aeeb6fa DW |
2754 | |
2755 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32, | |
2756 | &ap_scan, error); | |
8fc2fb56 WS |
2757 | } |
2758 | ||
2759 | ||
2760 | /** | |
2761 | * wpas_dbus_setter_ap_scan - Control roaming mode | |
6aeeb6fa DW |
2762 | * @iter: Pointer to incoming dbus message iter |
2763 | * @error: Location to store error on failure | |
2764 | * @user_data: Function specific data | |
2765 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
2766 | * |
2767 | * Setter function for "ApScan" property. | |
2768 | */ | |
1aa0fb77 DW |
2769 | dbus_bool_t wpas_dbus_setter_ap_scan( |
2770 | const struct wpa_dbus_property_desc *property_desc, | |
2771 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 2772 | { |
6aeeb6fa | 2773 | struct wpa_supplicant *wpa_s = user_data; |
8fc2fb56 WS |
2774 | dbus_uint32_t ap_scan; |
2775 | ||
6aeeb6fa DW |
2776 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32, |
2777 | &ap_scan)) | |
2778 | return FALSE; | |
8fc2fb56 WS |
2779 | |
2780 | if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) { | |
6aeeb6fa DW |
2781 | dbus_set_error_const(error, DBUS_ERROR_FAILED, |
2782 | "ap_scan must be 0, 1, or 2"); | |
2783 | return FALSE; | |
8fc2fb56 | 2784 | } |
6aeeb6fa | 2785 | return TRUE; |
8fc2fb56 WS |
2786 | } |
2787 | ||
2788 | ||
a4bbb606 PS |
2789 | /** |
2790 | * wpas_dbus_getter_fast_reauth - Control fast | |
2791 | * reauthentication (TLS session resumption) | |
2792 | * @iter: Pointer to incoming dbus message iter | |
2793 | * @error: Location to store error on failure | |
2794 | * @user_data: Function specific data | |
2795 | * Returns: TRUE on success, FALSE on failure | |
2796 | * | |
2797 | * Getter function for "FastReauth" property. | |
2798 | */ | |
1aa0fb77 DW |
2799 | dbus_bool_t wpas_dbus_getter_fast_reauth( |
2800 | const struct wpa_dbus_property_desc *property_desc, | |
2801 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
a4bbb606 PS |
2802 | { |
2803 | struct wpa_supplicant *wpa_s = user_data; | |
2804 | dbus_bool_t fast_reauth = wpa_s->conf->fast_reauth ? TRUE : FALSE; | |
2805 | ||
2806 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN, | |
2807 | &fast_reauth, error); | |
2808 | } | |
2809 | ||
2810 | ||
2811 | /** | |
2812 | * wpas_dbus_setter_fast_reauth - Control fast | |
2813 | * reauthentication (TLS session resumption) | |
2814 | * @iter: Pointer to incoming dbus message iter | |
2815 | * @error: Location to store error on failure | |
2816 | * @user_data: Function specific data | |
2817 | * Returns: TRUE on success, FALSE on failure | |
2818 | * | |
2819 | * Setter function for "FastReauth" property. | |
2820 | */ | |
1aa0fb77 DW |
2821 | dbus_bool_t wpas_dbus_setter_fast_reauth( |
2822 | const struct wpa_dbus_property_desc *property_desc, | |
2823 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
a4bbb606 PS |
2824 | { |
2825 | struct wpa_supplicant *wpa_s = user_data; | |
2826 | dbus_bool_t fast_reauth; | |
2827 | ||
2828 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN, | |
2829 | &fast_reauth)) | |
2830 | return FALSE; | |
2831 | ||
2832 | wpa_s->conf->fast_reauth = fast_reauth; | |
2833 | return TRUE; | |
2834 | } | |
2835 | ||
2836 | ||
0bb1e425 GM |
2837 | /** |
2838 | * wpas_dbus_getter_disconnect_reason - Get most recent reason for disconnect | |
2839 | * @iter: Pointer to incoming dbus message iter | |
2840 | * @error: Location to store error on failure | |
2841 | * @user_data: Function specific data | |
2842 | * Returns: TRUE on success, FALSE on failure | |
2843 | * | |
2844 | * Getter for "DisconnectReason" property. The reason is negative if it is | |
2845 | * locally generated. | |
2846 | */ | |
1aa0fb77 DW |
2847 | dbus_bool_t wpas_dbus_getter_disconnect_reason( |
2848 | const struct wpa_dbus_property_desc *property_desc, | |
2849 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
0bb1e425 GM |
2850 | { |
2851 | struct wpa_supplicant *wpa_s = user_data; | |
2852 | dbus_int32_t reason = wpa_s->disconnect_reason; | |
38279bdb | 2853 | |
0bb1e425 GM |
2854 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32, |
2855 | &reason, error); | |
2856 | } | |
2857 | ||
2858 | ||
78633c37 SL |
2859 | /** |
2860 | * wpas_dbus_getter_bss_expire_age - Get BSS entry expiration age | |
6aeeb6fa DW |
2861 | * @iter: Pointer to incoming dbus message iter |
2862 | * @error: Location to store error on failure | |
2863 | * @user_data: Function specific data | |
2864 | * Returns: TRUE on success, FALSE on failure | |
78633c37 SL |
2865 | * |
2866 | * Getter function for "BSSExpireAge" property. | |
2867 | */ | |
1aa0fb77 DW |
2868 | dbus_bool_t wpas_dbus_getter_bss_expire_age( |
2869 | const struct wpa_dbus_property_desc *property_desc, | |
2870 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
78633c37 | 2871 | { |
6aeeb6fa | 2872 | struct wpa_supplicant *wpa_s = user_data; |
78633c37 | 2873 | dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age; |
6aeeb6fa DW |
2874 | |
2875 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32, | |
2876 | &expire_age, error); | |
78633c37 SL |
2877 | } |
2878 | ||
2879 | ||
2880 | /** | |
2881 | * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age | |
6aeeb6fa DW |
2882 | * @iter: Pointer to incoming dbus message iter |
2883 | * @error: Location to store error on failure | |
2884 | * @user_data: Function specific data | |
2885 | * Returns: TRUE on success, FALSE on failure | |
78633c37 SL |
2886 | * |
2887 | * Setter function for "BSSExpireAge" property. | |
2888 | */ | |
1aa0fb77 DW |
2889 | dbus_bool_t wpas_dbus_setter_bss_expire_age( |
2890 | const struct wpa_dbus_property_desc *property_desc, | |
2891 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
78633c37 | 2892 | { |
6aeeb6fa | 2893 | struct wpa_supplicant *wpa_s = user_data; |
78633c37 SL |
2894 | dbus_uint32_t expire_age; |
2895 | ||
6aeeb6fa DW |
2896 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32, |
2897 | &expire_age)) | |
2898 | return FALSE; | |
78633c37 SL |
2899 | |
2900 | if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) { | |
6aeeb6fa DW |
2901 | dbus_set_error_const(error, DBUS_ERROR_FAILED, |
2902 | "BSSExpireAge must be >= 10"); | |
2903 | return FALSE; | |
78633c37 | 2904 | } |
6aeeb6fa | 2905 | return TRUE; |
78633c37 SL |
2906 | } |
2907 | ||
2908 | ||
2909 | /** | |
2910 | * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count | |
6aeeb6fa DW |
2911 | * @iter: Pointer to incoming dbus message iter |
2912 | * @error: Location to store error on failure | |
2913 | * @user_data: Function specific data | |
2914 | * Returns: TRUE on success, FALSE on failure | |
78633c37 SL |
2915 | * |
2916 | * Getter function for "BSSExpireCount" property. | |
2917 | */ | |
1aa0fb77 DW |
2918 | dbus_bool_t wpas_dbus_getter_bss_expire_count( |
2919 | const struct wpa_dbus_property_desc *property_desc, | |
2920 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
78633c37 | 2921 | { |
6aeeb6fa | 2922 | struct wpa_supplicant *wpa_s = user_data; |
c10fe8c1 | 2923 | dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_scan_count; |
6aeeb6fa DW |
2924 | |
2925 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32, | |
2926 | &expire_count, error); | |
78633c37 SL |
2927 | } |
2928 | ||
2929 | ||
2930 | /** | |
2931 | * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count | |
6aeeb6fa DW |
2932 | * @iter: Pointer to incoming dbus message iter |
2933 | * @error: Location to store error on failure | |
2934 | * @user_data: Function specific data | |
2935 | * Returns: TRUE on success, FALSE on failure | |
78633c37 SL |
2936 | * |
2937 | * Setter function for "BSSExpireCount" property. | |
2938 | */ | |
1aa0fb77 DW |
2939 | dbus_bool_t wpas_dbus_setter_bss_expire_count( |
2940 | const struct wpa_dbus_property_desc *property_desc, | |
2941 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
78633c37 | 2942 | { |
6aeeb6fa | 2943 | struct wpa_supplicant *wpa_s = user_data; |
78633c37 SL |
2944 | dbus_uint32_t expire_count; |
2945 | ||
6aeeb6fa DW |
2946 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32, |
2947 | &expire_count)) | |
2948 | return FALSE; | |
78633c37 SL |
2949 | |
2950 | if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) { | |
6aeeb6fa DW |
2951 | dbus_set_error_const(error, DBUS_ERROR_FAILED, |
2952 | "BSSExpireCount must be > 0"); | |
2953 | return FALSE; | |
78633c37 | 2954 | } |
6aeeb6fa | 2955 | return TRUE; |
78633c37 SL |
2956 | } |
2957 | ||
2958 | ||
9768da20 SL |
2959 | /** |
2960 | * wpas_dbus_getter_country - Control country code | |
6aeeb6fa DW |
2961 | * @iter: Pointer to incoming dbus message iter |
2962 | * @error: Location to store error on failure | |
2963 | * @user_data: Function specific data | |
2964 | * Returns: TRUE on success, FALSE on failure | |
9768da20 SL |
2965 | * |
2966 | * Getter function for "Country" property. | |
2967 | */ | |
1aa0fb77 DW |
2968 | dbus_bool_t wpas_dbus_getter_country( |
2969 | const struct wpa_dbus_property_desc *property_desc, | |
2970 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
9768da20 | 2971 | { |
6aeeb6fa | 2972 | struct wpa_supplicant *wpa_s = user_data; |
9768da20 SL |
2973 | char country[3]; |
2974 | char *str = country; | |
2975 | ||
2976 | country[0] = wpa_s->conf->country[0]; | |
2977 | country[1] = wpa_s->conf->country[1]; | |
2978 | country[2] = '\0'; | |
2979 | ||
6aeeb6fa DW |
2980 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, |
2981 | &str, error); | |
9768da20 SL |
2982 | } |
2983 | ||
2984 | ||
2985 | /** | |
2986 | * wpas_dbus_setter_country - Control country code | |
6aeeb6fa DW |
2987 | * @iter: Pointer to incoming dbus message iter |
2988 | * @error: Location to store error on failure | |
2989 | * @user_data: Function specific data | |
2990 | * Returns: TRUE on success, FALSE on failure | |
9768da20 SL |
2991 | * |
2992 | * Setter function for "Country" property. | |
2993 | */ | |
1aa0fb77 DW |
2994 | dbus_bool_t wpas_dbus_setter_country( |
2995 | const struct wpa_dbus_property_desc *property_desc, | |
2996 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
9768da20 | 2997 | { |
6aeeb6fa | 2998 | struct wpa_supplicant *wpa_s = user_data; |
9768da20 SL |
2999 | const char *country; |
3000 | ||
6aeeb6fa DW |
3001 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING, |
3002 | &country)) | |
3003 | return FALSE; | |
9768da20 | 3004 | |
6aeeb6fa DW |
3005 | if (!country[0] || !country[1]) { |
3006 | dbus_set_error_const(error, DBUS_ERROR_FAILED, | |
3007 | "invalid country code"); | |
3008 | return FALSE; | |
3009 | } | |
9768da20 SL |
3010 | |
3011 | if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) { | |
3012 | wpa_printf(MSG_DEBUG, "Failed to set country"); | |
6aeeb6fa DW |
3013 | dbus_set_error_const(error, DBUS_ERROR_FAILED, |
3014 | "failed to set country code"); | |
3015 | return FALSE; | |
9768da20 SL |
3016 | } |
3017 | ||
3018 | wpa_s->conf->country[0] = country[0]; | |
3019 | wpa_s->conf->country[1] = country[1]; | |
6aeeb6fa | 3020 | return TRUE; |
9768da20 SL |
3021 | } |
3022 | ||
3023 | ||
c6e86b63 MA |
3024 | /** |
3025 | * wpas_dbus_getter_scan_interval - Get scan interval | |
3026 | * @iter: Pointer to incoming dbus message iter | |
3027 | * @error: Location to store error on failure | |
3028 | * @user_data: Function specific data | |
3029 | * Returns: TRUE on success, FALSE on failure | |
3030 | * | |
3031 | * Getter function for "ScanInterval" property. | |
3032 | */ | |
1aa0fb77 DW |
3033 | dbus_bool_t wpas_dbus_getter_scan_interval( |
3034 | const struct wpa_dbus_property_desc *property_desc, | |
3035 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
c6e86b63 MA |
3036 | { |
3037 | struct wpa_supplicant *wpa_s = user_data; | |
3038 | dbus_int32_t scan_interval = wpa_s->scan_interval; | |
3039 | ||
3040 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32, | |
3041 | &scan_interval, error); | |
3042 | } | |
3043 | ||
3044 | ||
3045 | /** | |
3046 | * wpas_dbus_setter_scan_interval - Control scan interval | |
3047 | * @iter: Pointer to incoming dbus message iter | |
3048 | * @error: Location to store error on failure | |
3049 | * @user_data: Function specific data | |
3050 | * Returns: TRUE on success, FALSE on failure | |
3051 | * | |
3052 | * Setter function for "ScanInterval" property. | |
3053 | */ | |
1aa0fb77 DW |
3054 | dbus_bool_t wpas_dbus_setter_scan_interval( |
3055 | const struct wpa_dbus_property_desc *property_desc, | |
3056 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
c6e86b63 MA |
3057 | { |
3058 | struct wpa_supplicant *wpa_s = user_data; | |
3059 | dbus_int32_t scan_interval; | |
3060 | ||
3061 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_INT32, | |
3062 | &scan_interval)) | |
3063 | return FALSE; | |
3064 | ||
3065 | if (wpa_supplicant_set_scan_interval(wpa_s, scan_interval)) { | |
3066 | dbus_set_error_const(error, DBUS_ERROR_FAILED, | |
3067 | "scan_interval must be >= 0"); | |
3068 | return FALSE; | |
3069 | } | |
3070 | return TRUE; | |
3071 | } | |
3072 | ||
3073 | ||
8fc2fb56 WS |
3074 | /** |
3075 | * wpas_dbus_getter_ifname - Get interface name | |
6aeeb6fa DW |
3076 | * @iter: Pointer to incoming dbus message iter |
3077 | * @error: Location to store error on failure | |
3078 | * @user_data: Function specific data | |
3079 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3080 | * |
3081 | * Getter for "Ifname" property. | |
3082 | */ | |
1aa0fb77 DW |
3083 | dbus_bool_t wpas_dbus_getter_ifname( |
3084 | const struct wpa_dbus_property_desc *property_desc, | |
3085 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3086 | { |
6aeeb6fa | 3087 | struct wpa_supplicant *wpa_s = user_data; |
fcea0b7d | 3088 | const char *ifname = wpa_s->ifname; |
6aeeb6fa DW |
3089 | |
3090 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, | |
3091 | &ifname, error); | |
8fc2fb56 WS |
3092 | } |
3093 | ||
3094 | ||
3095 | /** | |
3096 | * wpas_dbus_getter_driver - Get interface name | |
6aeeb6fa DW |
3097 | * @iter: Pointer to incoming dbus message iter |
3098 | * @error: Location to store error on failure | |
3099 | * @user_data: Function specific data | |
3100 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3101 | * |
3102 | * Getter for "Driver" property. | |
3103 | */ | |
1aa0fb77 DW |
3104 | dbus_bool_t wpas_dbus_getter_driver( |
3105 | const struct wpa_dbus_property_desc *property_desc, | |
3106 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3107 | { |
6aeeb6fa | 3108 | struct wpa_supplicant *wpa_s = user_data; |
fcea0b7d | 3109 | const char *driver; |
8fc2fb56 WS |
3110 | |
3111 | if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) { | |
38279bdb JM |
3112 | wpa_printf(MSG_DEBUG, "%s[dbus]: wpa_s has no driver set", |
3113 | __func__); | |
6aeeb6fa DW |
3114 | dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set", |
3115 | __func__); | |
3116 | return FALSE; | |
8fc2fb56 WS |
3117 | } |
3118 | ||
3119 | driver = wpa_s->driver->name; | |
6aeeb6fa DW |
3120 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, |
3121 | &driver, error); | |
8fc2fb56 WS |
3122 | } |
3123 | ||
3124 | ||
3125 | /** | |
3126 | * wpas_dbus_getter_current_bss - Get current bss object path | |
6aeeb6fa DW |
3127 | * @iter: Pointer to incoming dbus message iter |
3128 | * @error: Location to store error on failure | |
3129 | * @user_data: Function specific data | |
3130 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3131 | * |
3132 | * Getter for "CurrentBSS" property. | |
3133 | */ | |
1aa0fb77 DW |
3134 | dbus_bool_t wpas_dbus_getter_current_bss( |
3135 | const struct wpa_dbus_property_desc *property_desc, | |
3136 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3137 | { |
6aeeb6fa | 3138 | struct wpa_supplicant *wpa_s = user_data; |
3e87bd54 | 3139 | char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf; |
8fc2fb56 | 3140 | |
8a78e227 | 3141 | if (wpa_s->current_bss && wpa_s->dbus_new_path) |
5228401c | 3142 | os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, |
ccd286d0 | 3143 | "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u", |
8f770587 | 3144 | wpa_s->dbus_new_path, wpa_s->current_bss->id); |
8fc2fb56 | 3145 | else |
5228401c | 3146 | os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/"); |
8fc2fb56 | 3147 | |
6aeeb6fa DW |
3148 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH, |
3149 | &bss_obj_path, error); | |
8fc2fb56 WS |
3150 | } |
3151 | ||
3152 | ||
3153 | /** | |
3154 | * wpas_dbus_getter_current_network - Get current network object path | |
6aeeb6fa DW |
3155 | * @iter: Pointer to incoming dbus message iter |
3156 | * @error: Location to store error on failure | |
3157 | * @user_data: Function specific data | |
3158 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3159 | * |
3160 | * Getter for "CurrentNetwork" property. | |
3161 | */ | |
1aa0fb77 DW |
3162 | dbus_bool_t wpas_dbus_getter_current_network( |
3163 | const struct wpa_dbus_property_desc *property_desc, | |
3164 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3165 | { |
6aeeb6fa | 3166 | struct wpa_supplicant *wpa_s = user_data; |
3e87bd54 | 3167 | char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf; |
8fc2fb56 | 3168 | |
8a78e227 | 3169 | if (wpa_s->current_ssid && wpa_s->dbus_new_path) |
5228401c | 3170 | os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, |
c49cf2d6 JM |
3171 | "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u", |
3172 | wpa_s->dbus_new_path, wpa_s->current_ssid->id); | |
8fc2fb56 | 3173 | else |
5228401c | 3174 | os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/"); |
8fc2fb56 | 3175 | |
6aeeb6fa DW |
3176 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH, |
3177 | &net_obj_path, error); | |
8fc2fb56 WS |
3178 | } |
3179 | ||
3180 | ||
ba6f267f PS |
3181 | /** |
3182 | * wpas_dbus_getter_current_auth_mode - Get current authentication type | |
6aeeb6fa DW |
3183 | * @iter: Pointer to incoming dbus message iter |
3184 | * @error: Location to store error on failure | |
3185 | * @user_data: Function specific data | |
3186 | * Returns: TRUE on success, FALSE on failure | |
ba6f267f PS |
3187 | * |
3188 | * Getter for "CurrentAuthMode" property. | |
3189 | */ | |
1aa0fb77 DW |
3190 | dbus_bool_t wpas_dbus_getter_current_auth_mode( |
3191 | const struct wpa_dbus_property_desc *property_desc, | |
3192 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
ba6f267f | 3193 | { |
6aeeb6fa | 3194 | struct wpa_supplicant *wpa_s = user_data; |
ba6f267f PS |
3195 | const char *eap_mode; |
3196 | const char *auth_mode; | |
3197 | char eap_mode_buf[WPAS_DBUS_AUTH_MODE_MAX]; | |
3198 | ||
3199 | if (wpa_s->wpa_state != WPA_COMPLETED) { | |
3200 | auth_mode = "INACTIVE"; | |
3201 | } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X || | |
3202 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
3203 | eap_mode = wpa_supplicant_get_eap_mode(wpa_s); | |
3204 | os_snprintf(eap_mode_buf, WPAS_DBUS_AUTH_MODE_MAX, | |
3205 | "EAP-%s", eap_mode); | |
3206 | auth_mode = eap_mode_buf; | |
3207 | ||
3208 | } else { | |
3209 | auth_mode = wpa_key_mgmt_txt(wpa_s->key_mgmt, | |
3210 | wpa_s->current_ssid->proto); | |
3211 | } | |
3212 | ||
6aeeb6fa DW |
3213 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, |
3214 | &auth_mode, error); | |
ba6f267f PS |
3215 | } |
3216 | ||
3217 | ||
8fc2fb56 WS |
3218 | /** |
3219 | * wpas_dbus_getter_bridge_ifname - Get interface name | |
6aeeb6fa DW |
3220 | * @iter: Pointer to incoming dbus message iter |
3221 | * @error: Location to store error on failure | |
3222 | * @user_data: Function specific data | |
3223 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3224 | * |
3225 | * Getter for "BridgeIfname" property. | |
3226 | */ | |
1aa0fb77 DW |
3227 | dbus_bool_t wpas_dbus_getter_bridge_ifname( |
3228 | const struct wpa_dbus_property_desc *property_desc, | |
3229 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3230 | { |
6aeeb6fa | 3231 | struct wpa_supplicant *wpa_s = user_data; |
c660b0c2 | 3232 | const char *bridge_ifname = wpa_s->bridge_ifname; |
38279bdb | 3233 | |
6aeeb6fa DW |
3234 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, |
3235 | &bridge_ifname, error); | |
8fc2fb56 WS |
3236 | } |
3237 | ||
3238 | ||
3239 | /** | |
3240 | * wpas_dbus_getter_bsss - Get array of BSSs objects | |
6aeeb6fa DW |
3241 | * @iter: Pointer to incoming dbus message iter |
3242 | * @error: Location to store error on failure | |
3243 | * @user_data: Function specific data | |
3244 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3245 | * |
3246 | * Getter for "BSSs" property. | |
3247 | */ | |
1aa0fb77 DW |
3248 | dbus_bool_t wpas_dbus_getter_bsss( |
3249 | const struct wpa_dbus_property_desc *property_desc, | |
3250 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3251 | { |
6aeeb6fa | 3252 | struct wpa_supplicant *wpa_s = user_data; |
ccd286d0 | 3253 | struct wpa_bss *bss; |
fcea0b7d WS |
3254 | char **paths; |
3255 | unsigned int i = 0; | |
6aeeb6fa | 3256 | dbus_bool_t success = FALSE; |
8fc2fb56 | 3257 | |
8a78e227 JM |
3258 | if (!wpa_s->dbus_new_path) { |
3259 | dbus_set_error(error, DBUS_ERROR_FAILED, | |
3260 | "%s: no D-Bus interface", __func__); | |
3261 | return FALSE; | |
3262 | } | |
3263 | ||
f9884c09 | 3264 | paths = os_calloc(wpa_s->num_bss, sizeof(char *)); |
fcea0b7d | 3265 | if (!paths) { |
6aeeb6fa DW |
3266 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
3267 | return FALSE; | |
8fc2fb56 WS |
3268 | } |
3269 | ||
3270 | /* Loop through scan results and append each result's object path */ | |
ccd286d0 | 3271 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
fcea0b7d WS |
3272 | paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); |
3273 | if (paths[i] == NULL) { | |
6aeeb6fa DW |
3274 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, |
3275 | "no memory"); | |
8fc2fb56 WS |
3276 | goto out; |
3277 | } | |
ccd286d0 | 3278 | /* Construct the object path for this BSS. */ |
fcea0b7d | 3279 | os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX, |
ccd286d0 | 3280 | "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u", |
c49cf2d6 | 3281 | wpa_s->dbus_new_path, bss->id); |
8fc2fb56 WS |
3282 | } |
3283 | ||
6aeeb6fa DW |
3284 | success = wpas_dbus_simple_array_property_getter(iter, |
3285 | DBUS_TYPE_OBJECT_PATH, | |
3286 | paths, wpa_s->num_bss, | |
3287 | error); | |
8fc2fb56 WS |
3288 | |
3289 | out: | |
3e87bd54 | 3290 | while (i) |
fcea0b7d WS |
3291 | os_free(paths[--i]); |
3292 | os_free(paths); | |
6aeeb6fa | 3293 | return success; |
8fc2fb56 WS |
3294 | } |
3295 | ||
3296 | ||
3297 | /** | |
3298 | * wpas_dbus_getter_networks - Get array of networks objects | |
6aeeb6fa DW |
3299 | * @iter: Pointer to incoming dbus message iter |
3300 | * @error: Location to store error on failure | |
3301 | * @user_data: Function specific data | |
3302 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3303 | * |
3304 | * Getter for "Networks" property. | |
3305 | */ | |
1aa0fb77 DW |
3306 | dbus_bool_t wpas_dbus_getter_networks( |
3307 | const struct wpa_dbus_property_desc *property_desc, | |
3308 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3309 | { |
6aeeb6fa | 3310 | struct wpa_supplicant *wpa_s = user_data; |
8fc2fb56 | 3311 | struct wpa_ssid *ssid; |
fcea0b7d WS |
3312 | char **paths; |
3313 | unsigned int i = 0, num = 0; | |
6aeeb6fa | 3314 | dbus_bool_t success = FALSE; |
8fc2fb56 | 3315 | |
8a78e227 JM |
3316 | if (!wpa_s->dbus_new_path) { |
3317 | dbus_set_error(error, DBUS_ERROR_FAILED, | |
3318 | "%s: no D-Bus interface", __func__); | |
3319 | return FALSE; | |
3320 | } | |
3321 | ||
fcea0b7d | 3322 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
c2762e41 JS |
3323 | if (!network_is_persistent_group(ssid)) |
3324 | num++; | |
8fc2fb56 | 3325 | |
f9884c09 | 3326 | paths = os_calloc(num, sizeof(char *)); |
fcea0b7d | 3327 | if (!paths) { |
6aeeb6fa DW |
3328 | dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
3329 | return FALSE; | |
8fc2fb56 WS |
3330 | } |
3331 | ||
fcea0b7d | 3332 | /* Loop through configured networks and append object path of each */ |
8fc2fb56 | 3333 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
c2762e41 JS |
3334 | if (network_is_persistent_group(ssid)) |
3335 | continue; | |
fcea0b7d WS |
3336 | paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); |
3337 | if (paths[i] == NULL) { | |
38279bdb JM |
3338 | dbus_set_error(error, DBUS_ERROR_NO_MEMORY, |
3339 | "no memory"); | |
8fc2fb56 WS |
3340 | goto out; |
3341 | } | |
3342 | ||
3343 | /* Construct the object path for this network. */ | |
fcea0b7d | 3344 | os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX, |
5228401c | 3345 | "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d", |
c49cf2d6 | 3346 | wpa_s->dbus_new_path, ssid->id); |
8fc2fb56 WS |
3347 | } |
3348 | ||
6aeeb6fa DW |
3349 | success = wpas_dbus_simple_array_property_getter(iter, |
3350 | DBUS_TYPE_OBJECT_PATH, | |
3351 | paths, num, error); | |
8fc2fb56 WS |
3352 | |
3353 | out: | |
fcea0b7d WS |
3354 | while (i) |
3355 | os_free(paths[--i]); | |
3356 | os_free(paths); | |
6aeeb6fa | 3357 | return success; |
8fc2fb56 WS |
3358 | } |
3359 | ||
3360 | ||
bdec7ee5 MS |
3361 | /** |
3362 | * wpas_dbus_getter_pkcs11_engine_path - Get PKCS #11 engine path | |
3363 | * @iter: Pointer to incoming dbus message iter | |
3364 | * @error: Location to store error on failure | |
3365 | * @user_data: Function specific data | |
3366 | * Returns: A dbus message containing the PKCS #11 engine path | |
3367 | * | |
3368 | * Getter for "PKCS11EnginePath" property. | |
3369 | */ | |
1aa0fb77 DW |
3370 | dbus_bool_t wpas_dbus_getter_pkcs11_engine_path( |
3371 | const struct wpa_dbus_property_desc *property_desc, | |
3372 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
bdec7ee5 MS |
3373 | { |
3374 | struct wpa_supplicant *wpa_s = user_data; | |
3375 | const char *pkcs11_engine_path; | |
3376 | ||
bdec7ee5 MS |
3377 | if (wpa_s->conf->pkcs11_engine_path == NULL) |
3378 | pkcs11_engine_path = ""; | |
3379 | else | |
3380 | pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path; | |
3381 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, | |
3382 | &pkcs11_engine_path, error); | |
3383 | } | |
3384 | ||
3385 | ||
3386 | /** | |
3387 | * wpas_dbus_getter_pkcs11_module_path - Get PKCS #11 module path | |
3388 | * @iter: Pointer to incoming dbus message iter | |
3389 | * @error: Location to store error on failure | |
3390 | * @user_data: Function specific data | |
3391 | * Returns: A dbus message containing the PKCS #11 module path | |
3392 | * | |
3393 | * Getter for "PKCS11ModulePath" property. | |
3394 | */ | |
1aa0fb77 DW |
3395 | dbus_bool_t wpas_dbus_getter_pkcs11_module_path( |
3396 | const struct wpa_dbus_property_desc *property_desc, | |
3397 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
bdec7ee5 MS |
3398 | { |
3399 | struct wpa_supplicant *wpa_s = user_data; | |
3400 | const char *pkcs11_module_path; | |
3401 | ||
bdec7ee5 MS |
3402 | if (wpa_s->conf->pkcs11_module_path == NULL) |
3403 | pkcs11_module_path = ""; | |
3404 | else | |
3405 | pkcs11_module_path = wpa_s->conf->pkcs11_module_path; | |
3406 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, | |
3407 | &pkcs11_module_path, error); | |
3408 | } | |
3409 | ||
3410 | ||
8fc2fb56 WS |
3411 | /** |
3412 | * wpas_dbus_getter_blobs - Get all blobs defined for this interface | |
6aeeb6fa DW |
3413 | * @iter: Pointer to incoming dbus message iter |
3414 | * @error: Location to store error on failure | |
3415 | * @user_data: Function specific data | |
3416 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
3417 | * |
3418 | * Getter for "Blobs" property. | |
3419 | */ | |
1aa0fb77 DW |
3420 | dbus_bool_t wpas_dbus_getter_blobs( |
3421 | const struct wpa_dbus_property_desc *property_desc, | |
3422 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3423 | { |
6aeeb6fa DW |
3424 | struct wpa_supplicant *wpa_s = user_data; |
3425 | DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter; | |
8fc2fb56 WS |
3426 | struct wpa_config_blob *blob; |
3427 | ||
6aeeb6fa | 3428 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, |
c2b8c674 JM |
3429 | "a{say}", &variant_iter) || |
3430 | !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY, | |
5228401c | 3431 | "{say}", &dict_iter)) { |
6aeeb6fa DW |
3432 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
3433 | return FALSE; | |
8fc2fb56 WS |
3434 | } |
3435 | ||
3436 | blob = wpa_s->conf->blobs; | |
3437 | while (blob) { | |
5228401c JM |
3438 | if (!dbus_message_iter_open_container(&dict_iter, |
3439 | DBUS_TYPE_DICT_ENTRY, | |
c2b8c674 JM |
3440 | NULL, &entry_iter) || |
3441 | !dbus_message_iter_append_basic(&entry_iter, | |
5228401c | 3442 | DBUS_TYPE_STRING, |
c2b8c674 JM |
3443 | &(blob->name)) || |
3444 | !dbus_message_iter_open_container(&entry_iter, | |
5228401c JM |
3445 | DBUS_TYPE_ARRAY, |
3446 | DBUS_TYPE_BYTE_AS_STRING, | |
c2b8c674 JM |
3447 | &array_iter) || |
3448 | !dbus_message_iter_append_fixed_array(&array_iter, | |
5228401c JM |
3449 | DBUS_TYPE_BYTE, |
3450 | &(blob->data), | |
c2b8c674 JM |
3451 | blob->len) || |
3452 | !dbus_message_iter_close_container(&entry_iter, | |
3453 | &array_iter) || | |
3454 | !dbus_message_iter_close_container(&dict_iter, | |
5228401c | 3455 | &entry_iter)) { |
6aeeb6fa DW |
3456 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, |
3457 | "no memory"); | |
3458 | return FALSE; | |
8fc2fb56 WS |
3459 | } |
3460 | ||
3461 | blob = blob->next; | |
3462 | } | |
3463 | ||
c2b8c674 | 3464 | if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) || |
6aeeb6fa DW |
3465 | !dbus_message_iter_close_container(iter, &variant_iter)) { |
3466 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); | |
3467 | return FALSE; | |
8fc2fb56 WS |
3468 | } |
3469 | ||
6aeeb6fa DW |
3470 | return TRUE; |
3471 | } | |
3472 | ||
3473 | ||
e50c50d5 DW |
3474 | dbus_bool_t wpas_dbus_getter_iface_global( |
3475 | const struct wpa_dbus_property_desc *property_desc, | |
3476 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
3477 | { | |
3478 | struct wpa_supplicant *wpa_s = user_data; | |
3479 | int ret; | |
3480 | char buf[250]; | |
3481 | char *p = buf; | |
3482 | ||
3483 | if (!property_desc->data) { | |
3484 | dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, | |
3485 | "Unhandled interface property %s", | |
3486 | property_desc->dbus_property); | |
3487 | return FALSE; | |
3488 | } | |
3489 | ||
3490 | ret = wpa_config_get_value(property_desc->data, wpa_s->conf, buf, | |
3491 | sizeof(buf)); | |
3492 | if (ret < 0) | |
3493 | *p = '\0'; | |
3494 | ||
3495 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, &p, | |
3496 | error); | |
3497 | } | |
3498 | ||
3499 | ||
3500 | dbus_bool_t wpas_dbus_setter_iface_global( | |
3501 | const struct wpa_dbus_property_desc *property_desc, | |
3502 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
3503 | { | |
3504 | struct wpa_supplicant *wpa_s = user_data; | |
3505 | const char *new_value = NULL; | |
3506 | char buf[250]; | |
3507 | size_t combined_len; | |
3508 | int ret; | |
3509 | ||
3510 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING, | |
3511 | &new_value)) | |
3512 | return FALSE; | |
3513 | ||
3514 | combined_len = os_strlen(property_desc->data) + os_strlen(new_value) + | |
3515 | 3; | |
3516 | if (combined_len >= sizeof(buf)) { | |
3517 | dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, | |
3518 | "Interface property %s value too large", | |
3519 | property_desc->dbus_property); | |
3520 | return FALSE; | |
3521 | } | |
3522 | ||
3523 | if (!new_value[0]) | |
3524 | new_value = "NULL"; | |
3525 | ||
3526 | ret = os_snprintf(buf, combined_len, "%s=%s", property_desc->data, | |
3527 | new_value); | |
3528 | if (os_snprintf_error(combined_len, ret)) { | |
3529 | dbus_set_error(error, WPAS_DBUS_ERROR_UNKNOWN_ERROR, | |
3530 | "Failed to construct new interface property %s", | |
3531 | property_desc->dbus_property); | |
3532 | return FALSE; | |
3533 | } | |
3534 | ||
3535 | if (wpa_config_process_global(wpa_s->conf, buf, -1)) { | |
3536 | dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, | |
3537 | "Failed to set interface property %s", | |
3538 | property_desc->dbus_property); | |
3539 | return FALSE; | |
3540 | } | |
3541 | ||
3542 | wpa_supplicant_update_config(wpa_s); | |
3543 | return TRUE; | |
3544 | } | |
3545 | ||
3546 | ||
6aeeb6fa DW |
3547 | static struct wpa_bss * get_bss_helper(struct bss_handler_args *args, |
3548 | DBusError *error, const char *func_name) | |
3549 | { | |
3550 | struct wpa_bss *res = wpa_bss_get_id(args->wpa_s, args->id); | |
3551 | ||
3552 | if (!res) { | |
3553 | wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found", | |
38279bdb | 3554 | func_name, args->id); |
6aeeb6fa DW |
3555 | dbus_set_error(error, DBUS_ERROR_FAILED, |
3556 | "%s: BSS %d not found", | |
3557 | func_name, args->id); | |
3558 | } | |
3559 | ||
3560 | return res; | |
8fc2fb56 WS |
3561 | } |
3562 | ||
3563 | ||
3564 | /** | |
58605c6e | 3565 | * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS |
6aeeb6fa DW |
3566 | * @iter: Pointer to incoming dbus message iter |
3567 | * @error: Location to store error on failure | |
3568 | * @user_data: Function specific data | |
3569 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 | 3570 | * |
58605c6e | 3571 | * Getter for "BSSID" property. |
8fc2fb56 | 3572 | */ |
1aa0fb77 DW |
3573 | dbus_bool_t wpas_dbus_getter_bss_bssid( |
3574 | const struct wpa_dbus_property_desc *property_desc, | |
3575 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3576 | { |
6aeeb6fa DW |
3577 | struct bss_handler_args *args = user_data; |
3578 | struct wpa_bss *res; | |
58605c6e | 3579 | |
6aeeb6fa DW |
3580 | res = get_bss_helper(args, error, __func__); |
3581 | if (!res) | |
3582 | return FALSE; | |
58605c6e | 3583 | |
6aeeb6fa DW |
3584 | return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE, |
3585 | res->bssid, ETH_ALEN, | |
3586 | error); | |
58605c6e WS |
3587 | } |
3588 | ||
3589 | ||
3590 | /** | |
3591 | * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS | |
6aeeb6fa DW |
3592 | * @iter: Pointer to incoming dbus message iter |
3593 | * @error: Location to store error on failure | |
3594 | * @user_data: Function specific data | |
3595 | * Returns: TRUE on success, FALSE on failure | |
58605c6e WS |
3596 | * |
3597 | * Getter for "SSID" property. | |
3598 | */ | |
1aa0fb77 DW |
3599 | dbus_bool_t wpas_dbus_getter_bss_ssid( |
3600 | const struct wpa_dbus_property_desc *property_desc, | |
3601 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 3602 | { |
6aeeb6fa DW |
3603 | struct bss_handler_args *args = user_data; |
3604 | struct wpa_bss *res; | |
8fc2fb56 | 3605 | |
6aeeb6fa DW |
3606 | res = get_bss_helper(args, error, __func__); |
3607 | if (!res) | |
3608 | return FALSE; | |
8fc2fb56 | 3609 | |
6aeeb6fa DW |
3610 | return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE, |
3611 | res->ssid, res->ssid_len, | |
3612 | error); | |
58605c6e | 3613 | } |
8fc2fb56 | 3614 | |
8fc2fb56 | 3615 | |
58605c6e WS |
3616 | /** |
3617 | * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS | |
6aeeb6fa DW |
3618 | * @iter: Pointer to incoming dbus message iter |
3619 | * @error: Location to store error on failure | |
3620 | * @user_data: Function specific data | |
3621 | * Returns: TRUE on success, FALSE on failure | |
58605c6e WS |
3622 | * |
3623 | * Getter for "Privacy" property. | |
3624 | */ | |
1aa0fb77 DW |
3625 | dbus_bool_t wpas_dbus_getter_bss_privacy( |
3626 | const struct wpa_dbus_property_desc *property_desc, | |
3627 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3628 | { |
6aeeb6fa DW |
3629 | struct bss_handler_args *args = user_data; |
3630 | struct wpa_bss *res; | |
58605c6e | 3631 | dbus_bool_t privacy; |
8fc2fb56 | 3632 | |
6aeeb6fa DW |
3633 | res = get_bss_helper(args, error, __func__); |
3634 | if (!res) | |
3635 | return FALSE; | |
8fc2fb56 | 3636 | |
097c5802 | 3637 | privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE; |
6aeeb6fa DW |
3638 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN, |
3639 | &privacy, error); | |
58605c6e | 3640 | } |
8fc2fb56 | 3641 | |
8fc2fb56 | 3642 | |
58605c6e WS |
3643 | /** |
3644 | * wpas_dbus_getter_bss_mode - Return the mode of a BSS | |
6aeeb6fa DW |
3645 | * @iter: Pointer to incoming dbus message iter |
3646 | * @error: Location to store error on failure | |
3647 | * @user_data: Function specific data | |
3648 | * Returns: TRUE on success, FALSE on failure | |
58605c6e WS |
3649 | * |
3650 | * Getter for "Mode" property. | |
3651 | */ | |
1aa0fb77 DW |
3652 | dbus_bool_t wpas_dbus_getter_bss_mode( |
3653 | const struct wpa_dbus_property_desc *property_desc, | |
3654 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3655 | { |
6aeeb6fa DW |
3656 | struct bss_handler_args *args = user_data; |
3657 | struct wpa_bss *res; | |
58605c6e WS |
3658 | const char *mode; |
3659 | ||
6aeeb6fa DW |
3660 | res = get_bss_helper(args, error, __func__); |
3661 | if (!res) | |
3662 | return FALSE; | |
e403ba85 BS |
3663 | if (bss_is_dmg(res)) { |
3664 | switch (res->caps & IEEE80211_CAP_DMG_MASK) { | |
3665 | case IEEE80211_CAP_DMG_PBSS: | |
3666 | case IEEE80211_CAP_DMG_IBSS: | |
3667 | mode = "ad-hoc"; | |
3668 | break; | |
3669 | case IEEE80211_CAP_DMG_AP: | |
3670 | mode = "infrastructure"; | |
3671 | break; | |
3672 | } | |
3673 | } else { | |
3674 | if (res->caps & IEEE80211_CAP_IBSS) | |
3675 | mode = "ad-hoc"; | |
3676 | else | |
3677 | mode = "infrastructure"; | |
3678 | } | |
58605c6e | 3679 | |
6aeeb6fa DW |
3680 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, |
3681 | &mode, error); | |
58605c6e WS |
3682 | } |
3683 | ||
3684 | ||
3685 | /** | |
3686 | * wpas_dbus_getter_bss_level - Return the signal strength of a BSS | |
6aeeb6fa DW |
3687 | * @iter: Pointer to incoming dbus message iter |
3688 | * @error: Location to store error on failure | |
3689 | * @user_data: Function specific data | |
3690 | * Returns: TRUE on success, FALSE on failure | |
58605c6e WS |
3691 | * |
3692 | * Getter for "Level" property. | |
3693 | */ | |
1aa0fb77 DW |
3694 | dbus_bool_t wpas_dbus_getter_bss_signal( |
3695 | const struct wpa_dbus_property_desc *property_desc, | |
3696 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3697 | { |
6aeeb6fa DW |
3698 | struct bss_handler_args *args = user_data; |
3699 | struct wpa_bss *res; | |
3d0a8438 | 3700 | s16 level; |
58605c6e | 3701 | |
6aeeb6fa DW |
3702 | res = get_bss_helper(args, error, __func__); |
3703 | if (!res) | |
3704 | return FALSE; | |
8fc2fb56 | 3705 | |
3d0a8438 | 3706 | level = (s16) res->level; |
6aeeb6fa | 3707 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16, |
3d0a8438 | 3708 | &level, error); |
58605c6e WS |
3709 | } |
3710 | ||
3711 | ||
3712 | /** | |
3713 | * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS | |
6aeeb6fa DW |
3714 | * @iter: Pointer to incoming dbus message iter |
3715 | * @error: Location to store error on failure | |
3716 | * @user_data: Function specific data | |
3717 | * Returns: TRUE on success, FALSE on failure | |
58605c6e WS |
3718 | * |
3719 | * Getter for "Frequency" property. | |
3720 | */ | |
1aa0fb77 DW |
3721 | dbus_bool_t wpas_dbus_getter_bss_frequency( |
3722 | const struct wpa_dbus_property_desc *property_desc, | |
3723 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3724 | { |
6aeeb6fa DW |
3725 | struct bss_handler_args *args = user_data; |
3726 | struct wpa_bss *res; | |
3d0a8438 | 3727 | u16 freq; |
58605c6e | 3728 | |
6aeeb6fa DW |
3729 | res = get_bss_helper(args, error, __func__); |
3730 | if (!res) | |
3731 | return FALSE; | |
8fc2fb56 | 3732 | |
3d0a8438 | 3733 | freq = (u16) res->freq; |
6aeeb6fa | 3734 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16, |
3d0a8438 | 3735 | &freq, error); |
58605c6e WS |
3736 | } |
3737 | ||
3738 | ||
75d328af WS |
3739 | static int cmp_u8s_desc(const void *a, const void *b) |
3740 | { | |
3741 | return (*(u8 *) b - *(u8 *) a); | |
3742 | } | |
3743 | ||
3744 | ||
58605c6e | 3745 | /** |
75d328af | 3746 | * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS |
6aeeb6fa DW |
3747 | * @iter: Pointer to incoming dbus message iter |
3748 | * @error: Location to store error on failure | |
3749 | * @user_data: Function specific data | |
3750 | * Returns: TRUE on success, FALSE on failure | |
58605c6e | 3751 | * |
75d328af | 3752 | * Getter for "Rates" property. |
58605c6e | 3753 | */ |
1aa0fb77 DW |
3754 | dbus_bool_t wpas_dbus_getter_bss_rates( |
3755 | const struct wpa_dbus_property_desc *property_desc, | |
3756 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3757 | { |
6aeeb6fa DW |
3758 | struct bss_handler_args *args = user_data; |
3759 | struct wpa_bss *res; | |
75d328af WS |
3760 | u8 *ie_rates = NULL; |
3761 | u32 *real_rates; | |
3762 | int rates_num, i; | |
6aeeb6fa | 3763 | dbus_bool_t success = FALSE; |
58605c6e | 3764 | |
6aeeb6fa DW |
3765 | res = get_bss_helper(args, error, __func__); |
3766 | if (!res) | |
3767 | return FALSE; | |
8fc2fb56 | 3768 | |
75d328af WS |
3769 | rates_num = wpa_bss_get_bit_rates(res, &ie_rates); |
3770 | if (rates_num < 0) | |
6aeeb6fa | 3771 | return FALSE; |
75d328af WS |
3772 | |
3773 | qsort(ie_rates, rates_num, 1, cmp_u8s_desc); | |
3774 | ||
3775 | real_rates = os_malloc(sizeof(u32) * rates_num); | |
3776 | if (!real_rates) { | |
3777 | os_free(ie_rates); | |
6aeeb6fa DW |
3778 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
3779 | return FALSE; | |
75d328af WS |
3780 | } |
3781 | ||
3782 | for (i = 0; i < rates_num; i++) | |
3783 | real_rates[i] = ie_rates[i] * 500000; | |
3784 | ||
6aeeb6fa DW |
3785 | success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32, |
3786 | real_rates, rates_num, | |
3787 | error); | |
75d328af WS |
3788 | |
3789 | os_free(ie_rates); | |
3790 | os_free(real_rates); | |
6aeeb6fa | 3791 | return success; |
58605c6e WS |
3792 | } |
3793 | ||
3794 | ||
1aa0fb77 DW |
3795 | static dbus_bool_t wpas_dbus_get_bss_security_prop( |
3796 | const struct wpa_dbus_property_desc *property_desc, | |
3797 | DBusMessageIter *iter, struct wpa_ie_data *ie_data, DBusError *error) | |
7899e2f4 | 3798 | { |
6aeeb6fa | 3799 | DBusMessageIter iter_dict, variant_iter; |
7899e2f4 | 3800 | const char *group; |
30675c34 | 3801 | const char *pairwise[5]; /* max 5 pairwise ciphers is supported */ |
5e3b5197 | 3802 | const char *key_mgmt[9]; /* max 9 key managements may be supported */ |
7899e2f4 WS |
3803 | int n; |
3804 | ||
6aeeb6fa | 3805 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, |
7899e2f4 WS |
3806 | "a{sv}", &variant_iter)) |
3807 | goto nomem; | |
3808 | ||
3809 | if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict)) | |
3810 | goto nomem; | |
3811 | ||
3812 | /* KeyMgmt */ | |
3813 | n = 0; | |
3814 | if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK) | |
3815 | key_mgmt[n++] = "wpa-psk"; | |
3816 | if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK) | |
3817 | key_mgmt[n++] = "wpa-ft-psk"; | |
3818 | if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) | |
3819 | key_mgmt[n++] = "wpa-psk-sha256"; | |
3820 | if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X) | |
3821 | key_mgmt[n++] = "wpa-eap"; | |
3822 | if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) | |
3823 | key_mgmt[n++] = "wpa-ft-eap"; | |
3824 | if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) | |
3825 | key_mgmt[n++] = "wpa-eap-sha256"; | |
5e3b5197 | 3826 | #ifdef CONFIG_SUITEB |
666497c8 JM |
3827 | if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) |
3828 | key_mgmt[n++] = "wpa-eap-suite-b"; | |
5e3b5197 JM |
3829 | #endif /* CONFIG_SUITEB */ |
3830 | #ifdef CONFIG_SUITEB192 | |
3831 | if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) | |
3832 | key_mgmt[n++] = "wpa-eap-suite-b-192"; | |
3833 | #endif /* CONFIG_SUITEB192 */ | |
7899e2f4 WS |
3834 | if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE) |
3835 | key_mgmt[n++] = "wpa-none"; | |
3836 | ||
3837 | if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt", | |
3838 | key_mgmt, n)) | |
3839 | goto nomem; | |
3840 | ||
3841 | /* Group */ | |
3842 | switch (ie_data->group_cipher) { | |
3843 | case WPA_CIPHER_WEP40: | |
3844 | group = "wep40"; | |
3845 | break; | |
3846 | case WPA_CIPHER_TKIP: | |
3847 | group = "tkip"; | |
3848 | break; | |
3849 | case WPA_CIPHER_CCMP: | |
3850 | group = "ccmp"; | |
3851 | break; | |
eb7719ff JM |
3852 | case WPA_CIPHER_GCMP: |
3853 | group = "gcmp"; | |
3854 | break; | |
7899e2f4 WS |
3855 | case WPA_CIPHER_WEP104: |
3856 | group = "wep104"; | |
3857 | break; | |
30675c34 JM |
3858 | case WPA_CIPHER_CCMP_256: |
3859 | group = "ccmp-256"; | |
3860 | break; | |
3861 | case WPA_CIPHER_GCMP_256: | |
3862 | group = "gcmp-256"; | |
3863 | break; | |
7899e2f4 WS |
3864 | default: |
3865 | group = ""; | |
3866 | break; | |
3867 | } | |
3868 | ||
3869 | if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group)) | |
3870 | goto nomem; | |
3871 | ||
3872 | /* Pairwise */ | |
3873 | n = 0; | |
3874 | if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP) | |
3875 | pairwise[n++] = "tkip"; | |
3876 | if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP) | |
3877 | pairwise[n++] = "ccmp"; | |
eb7719ff JM |
3878 | if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP) |
3879 | pairwise[n++] = "gcmp"; | |
30675c34 JM |
3880 | if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP_256) |
3881 | pairwise[n++] = "ccmp-256"; | |
3882 | if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP_256) | |
3883 | pairwise[n++] = "gcmp-256"; | |
7899e2f4 WS |
3884 | |
3885 | if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise", | |
3886 | pairwise, n)) | |
3887 | goto nomem; | |
3888 | ||
3889 | /* Management group (RSN only) */ | |
3890 | if (ie_data->proto == WPA_PROTO_RSN) { | |
3891 | switch (ie_data->mgmt_group_cipher) { | |
3892 | #ifdef CONFIG_IEEE80211W | |
3893 | case WPA_CIPHER_AES_128_CMAC: | |
3894 | group = "aes128cmac"; | |
3895 | break; | |
3896 | #endif /* CONFIG_IEEE80211W */ | |
3897 | default: | |
3898 | group = ""; | |
3899 | break; | |
3900 | } | |
3901 | ||
3902 | if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup", | |
3903 | group)) | |
3904 | goto nomem; | |
3905 | } | |
3906 | ||
e3c4f0b5 JM |
3907 | if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) || |
3908 | !dbus_message_iter_close_container(iter, &variant_iter)) | |
7899e2f4 WS |
3909 | goto nomem; |
3910 | ||
6aeeb6fa | 3911 | return TRUE; |
7899e2f4 WS |
3912 | |
3913 | nomem: | |
6aeeb6fa DW |
3914 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
3915 | return FALSE; | |
7899e2f4 WS |
3916 | } |
3917 | ||
3918 | ||
58605c6e | 3919 | /** |
7899e2f4 | 3920 | * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS |
6aeeb6fa DW |
3921 | * @iter: Pointer to incoming dbus message iter |
3922 | * @error: Location to store error on failure | |
3923 | * @user_data: Function specific data | |
3924 | * Returns: TRUE on success, FALSE on failure | |
58605c6e | 3925 | * |
7899e2f4 | 3926 | * Getter for "WPA" property. |
58605c6e | 3927 | */ |
1aa0fb77 DW |
3928 | dbus_bool_t wpas_dbus_getter_bss_wpa( |
3929 | const struct wpa_dbus_property_desc *property_desc, | |
3930 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3931 | { |
6aeeb6fa DW |
3932 | struct bss_handler_args *args = user_data; |
3933 | struct wpa_bss *res; | |
7899e2f4 | 3934 | struct wpa_ie_data wpa_data; |
58605c6e WS |
3935 | const u8 *ie; |
3936 | ||
6aeeb6fa DW |
3937 | res = get_bss_helper(args, error, __func__); |
3938 | if (!res) | |
3939 | return FALSE; | |
8fc2fb56 | 3940 | |
7899e2f4 | 3941 | os_memset(&wpa_data, 0, sizeof(wpa_data)); |
58605c6e | 3942 | ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE); |
e3c4f0b5 JM |
3943 | if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) { |
3944 | dbus_set_error_const(error, DBUS_ERROR_FAILED, | |
3945 | "failed to parse WPA IE"); | |
3946 | return FALSE; | |
af3e1b0e | 3947 | } |
7899e2f4 | 3948 | |
1aa0fb77 | 3949 | return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error); |
58605c6e | 3950 | } |
8fc2fb56 | 3951 | |
8fc2fb56 | 3952 | |
58605c6e | 3953 | /** |
7899e2f4 | 3954 | * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS |
6aeeb6fa DW |
3955 | * @iter: Pointer to incoming dbus message iter |
3956 | * @error: Location to store error on failure | |
3957 | * @user_data: Function specific data | |
3958 | * Returns: TRUE on success, FALSE on failure | |
58605c6e | 3959 | * |
7899e2f4 | 3960 | * Getter for "RSN" property. |
58605c6e | 3961 | */ |
1aa0fb77 DW |
3962 | dbus_bool_t wpas_dbus_getter_bss_rsn( |
3963 | const struct wpa_dbus_property_desc *property_desc, | |
3964 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 3965 | { |
6aeeb6fa DW |
3966 | struct bss_handler_args *args = user_data; |
3967 | struct wpa_bss *res; | |
7899e2f4 | 3968 | struct wpa_ie_data wpa_data; |
58605c6e WS |
3969 | const u8 *ie; |
3970 | ||
6aeeb6fa DW |
3971 | res = get_bss_helper(args, error, __func__); |
3972 | if (!res) | |
3973 | return FALSE; | |
58605c6e | 3974 | |
7899e2f4 | 3975 | os_memset(&wpa_data, 0, sizeof(wpa_data)); |
58605c6e | 3976 | ie = wpa_bss_get_ie(res, WLAN_EID_RSN); |
e3c4f0b5 JM |
3977 | if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) { |
3978 | dbus_set_error_const(error, DBUS_ERROR_FAILED, | |
3979 | "failed to parse RSN IE"); | |
3980 | return FALSE; | |
af3e1b0e | 3981 | } |
7899e2f4 | 3982 | |
1aa0fb77 | 3983 | return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error); |
58605c6e WS |
3984 | } |
3985 | ||
3986 | ||
caff3992 SN |
3987 | /** |
3988 | * wpas_dbus_getter_bss_wps - Return the WPS options of a BSS | |
3989 | * @iter: Pointer to incoming dbus message iter | |
3990 | * @error: Location to store error on failure | |
3991 | * @user_data: Function specific data | |
3992 | * Returns: TRUE on success, FALSE on failure | |
3993 | * | |
3994 | * Getter for "WPS" property. | |
3995 | */ | |
1aa0fb77 DW |
3996 | dbus_bool_t wpas_dbus_getter_bss_wps( |
3997 | const struct wpa_dbus_property_desc *property_desc, | |
3998 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
caff3992 SN |
3999 | { |
4000 | struct bss_handler_args *args = user_data; | |
4001 | struct wpa_bss *res; | |
4002 | #ifdef CONFIG_WPS | |
4003 | struct wpabuf *wps_ie; | |
4004 | #endif /* CONFIG_WPS */ | |
4005 | DBusMessageIter iter_dict, variant_iter; | |
8e2c5f1a | 4006 | int wps_support = 0; |
caff3992 SN |
4007 | const char *type = ""; |
4008 | ||
4009 | res = get_bss_helper(args, error, __func__); | |
4010 | if (!res) | |
4011 | return FALSE; | |
4012 | ||
4013 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, | |
e3c4f0b5 JM |
4014 | "a{sv}", &variant_iter) || |
4015 | !wpa_dbus_dict_open_write(&variant_iter, &iter_dict)) | |
caff3992 SN |
4016 | goto nomem; |
4017 | ||
4018 | #ifdef CONFIG_WPS | |
4019 | wps_ie = wpa_bss_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE); | |
4020 | if (wps_ie) { | |
8e2c5f1a | 4021 | wps_support = 1; |
caff3992 SN |
4022 | if (wps_is_selected_pbc_registrar(wps_ie)) |
4023 | type = "pbc"; | |
4024 | else if (wps_is_selected_pin_registrar(wps_ie)) | |
4025 | type = "pin"; | |
c66f2349 SM |
4026 | |
4027 | wpabuf_free(wps_ie); | |
caff3992 SN |
4028 | } |
4029 | #endif /* CONFIG_WPS */ | |
4030 | ||
8e2c5f1a | 4031 | if ((wps_support && !wpa_dbus_dict_append_string(&iter_dict, "Type", type)) || |
e3c4f0b5 JM |
4032 | !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) || |
4033 | !dbus_message_iter_close_container(iter, &variant_iter)) | |
caff3992 SN |
4034 | goto nomem; |
4035 | ||
4036 | return TRUE; | |
4037 | ||
4038 | nomem: | |
4039 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); | |
4040 | return FALSE; | |
4041 | } | |
4042 | ||
4043 | ||
58605c6e | 4044 | /** |
7899e2f4 | 4045 | * wpas_dbus_getter_bss_ies - Return all IEs of a BSS |
6aeeb6fa DW |
4046 | * @iter: Pointer to incoming dbus message iter |
4047 | * @error: Location to store error on failure | |
4048 | * @user_data: Function specific data | |
4049 | * Returns: TRUE on success, FALSE on failure | |
58605c6e | 4050 | * |
7899e2f4 | 4051 | * Getter for "IEs" property. |
58605c6e | 4052 | */ |
1aa0fb77 DW |
4053 | dbus_bool_t wpas_dbus_getter_bss_ies( |
4054 | const struct wpa_dbus_property_desc *property_desc, | |
4055 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
58605c6e | 4056 | { |
6aeeb6fa DW |
4057 | struct bss_handler_args *args = user_data; |
4058 | struct wpa_bss *res; | |
58605c6e | 4059 | |
6aeeb6fa DW |
4060 | res = get_bss_helper(args, error, __func__); |
4061 | if (!res) | |
4062 | return FALSE; | |
58605c6e | 4063 | |
6aeeb6fa DW |
4064 | return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE, |
4065 | res + 1, res->ie_len, | |
4066 | error); | |
8fc2fb56 WS |
4067 | } |
4068 | ||
4069 | ||
3bd3257a DW |
4070 | /** |
4071 | * wpas_dbus_getter_bss_age - Return time in seconds since BSS was last seen | |
4072 | * @iter: Pointer to incoming dbus message iter | |
4073 | * @error: Location to store error on failure | |
4074 | * @user_data: Function specific data | |
4075 | * Returns: TRUE on success, FALSE on failure | |
4076 | * | |
4077 | * Getter for BSS age | |
4078 | */ | |
1aa0fb77 DW |
4079 | dbus_bool_t wpas_dbus_getter_bss_age( |
4080 | const struct wpa_dbus_property_desc *property_desc, | |
4081 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
3bd3257a DW |
4082 | { |
4083 | struct bss_handler_args *args = user_data; | |
4084 | struct wpa_bss *res; | |
4085 | struct os_reltime now, diff = { 0, 0 }; | |
4086 | u32 age; | |
4087 | ||
4088 | res = get_bss_helper(args, error, __func__); | |
4089 | if (!res) | |
4090 | return FALSE; | |
4091 | ||
4092 | os_get_reltime(&now); | |
4093 | os_reltime_sub(&now, &res->last_update, &diff); | |
4094 | age = diff.sec > 0 ? diff.sec : 0; | |
4095 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32, &age, | |
4096 | error); | |
4097 | } | |
4098 | ||
4099 | ||
8fc2fb56 WS |
4100 | /** |
4101 | * wpas_dbus_getter_enabled - Check whether network is enabled or disabled | |
6aeeb6fa DW |
4102 | * @iter: Pointer to incoming dbus message iter |
4103 | * @error: Location to store error on failure | |
4104 | * @user_data: Function specific data | |
4105 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
4106 | * |
4107 | * Getter for "enabled" property of a configured network. | |
4108 | */ | |
1aa0fb77 DW |
4109 | dbus_bool_t wpas_dbus_getter_enabled( |
4110 | const struct wpa_dbus_property_desc *property_desc, | |
4111 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 4112 | { |
6aeeb6fa | 4113 | struct network_handler_args *net = user_data; |
8fc2fb56 | 4114 | dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE; |
6aeeb6fa DW |
4115 | |
4116 | return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN, | |
4117 | &enabled, error); | |
8fc2fb56 WS |
4118 | } |
4119 | ||
4120 | ||
4121 | /** | |
4122 | * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled | |
6aeeb6fa DW |
4123 | * @iter: Pointer to incoming dbus message iter |
4124 | * @error: Location to store error on failure | |
4125 | * @user_data: Function specific data | |
4126 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
4127 | * |
4128 | * Setter for "Enabled" property of a configured network. | |
4129 | */ | |
1aa0fb77 DW |
4130 | dbus_bool_t wpas_dbus_setter_enabled( |
4131 | const struct wpa_dbus_property_desc *property_desc, | |
4132 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 4133 | { |
6aeeb6fa | 4134 | struct network_handler_args *net = user_data; |
8fc2fb56 WS |
4135 | struct wpa_supplicant *wpa_s; |
4136 | struct wpa_ssid *ssid; | |
8fc2fb56 WS |
4137 | dbus_bool_t enable; |
4138 | ||
6aeeb6fa DW |
4139 | if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN, |
4140 | &enable)) | |
4141 | return FALSE; | |
8fc2fb56 WS |
4142 | |
4143 | wpa_s = net->wpa_s; | |
4144 | ssid = net->ssid; | |
4145 | ||
5228401c | 4146 | if (enable) |
8fc2fb56 | 4147 | wpa_supplicant_enable_network(wpa_s, ssid); |
5228401c | 4148 | else |
8fc2fb56 | 4149 | wpa_supplicant_disable_network(wpa_s, ssid); |
8fc2fb56 | 4150 | |
6aeeb6fa | 4151 | return TRUE; |
8fc2fb56 WS |
4152 | } |
4153 | ||
4154 | ||
4155 | /** | |
4156 | * wpas_dbus_getter_network_properties - Get options for a configured network | |
6aeeb6fa DW |
4157 | * @iter: Pointer to incoming dbus message iter |
4158 | * @error: Location to store error on failure | |
4159 | * @user_data: Function specific data | |
4160 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
4161 | * |
4162 | * Getter for "Properties" property of a configured network. | |
4163 | */ | |
1aa0fb77 DW |
4164 | dbus_bool_t wpas_dbus_getter_network_properties( |
4165 | const struct wpa_dbus_property_desc *property_desc, | |
4166 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 4167 | { |
6aeeb6fa DW |
4168 | struct network_handler_args *net = user_data; |
4169 | DBusMessageIter variant_iter, dict_iter; | |
8fc2fb56 | 4170 | char **iterator; |
d1c8ac88 | 4171 | char **props = wpa_config_get_all(net->ssid, 1); |
6aeeb6fa | 4172 | dbus_bool_t success = FALSE; |
8fc2fb56 | 4173 | |
6aeeb6fa DW |
4174 | if (!props) { |
4175 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); | |
4176 | return FALSE; | |
8fc2fb56 WS |
4177 | } |
4178 | ||
6aeeb6fa DW |
4179 | if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}", |
4180 | &variant_iter) || | |
c2b8c674 | 4181 | !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) { |
6aeeb6fa | 4182 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); |
8fc2fb56 WS |
4183 | goto out; |
4184 | } | |
4185 | ||
4186 | iterator = props; | |
4187 | while (*iterator) { | |
4188 | if (!wpa_dbus_dict_append_string(&dict_iter, *iterator, | |
5228401c | 4189 | *(iterator + 1))) { |
6aeeb6fa DW |
4190 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, |
4191 | "no memory"); | |
8fc2fb56 WS |
4192 | goto out; |
4193 | } | |
4194 | iterator += 2; | |
4195 | } | |
4196 | ||
4197 | ||
c2b8c674 | 4198 | if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) || |
6aeeb6fa DW |
4199 | !dbus_message_iter_close_container(iter, &variant_iter)) { |
4200 | dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory"); | |
8fc2fb56 WS |
4201 | goto out; |
4202 | } | |
4203 | ||
6aeeb6fa DW |
4204 | success = TRUE; |
4205 | ||
8fc2fb56 WS |
4206 | out: |
4207 | iterator = props; | |
4208 | while (*iterator) { | |
4209 | os_free(*iterator); | |
4210 | iterator++; | |
4211 | } | |
4212 | os_free(props); | |
6aeeb6fa | 4213 | return success; |
8fc2fb56 WS |
4214 | } |
4215 | ||
4216 | ||
4217 | /** | |
4218 | * wpas_dbus_setter_network_properties - Set options for a configured network | |
6aeeb6fa DW |
4219 | * @iter: Pointer to incoming dbus message iter |
4220 | * @error: Location to store error on failure | |
4221 | * @user_data: Function specific data | |
4222 | * Returns: TRUE on success, FALSE on failure | |
8fc2fb56 WS |
4223 | * |
4224 | * Setter for "Properties" property of a configured network. | |
4225 | */ | |
1aa0fb77 DW |
4226 | dbus_bool_t wpas_dbus_setter_network_properties( |
4227 | const struct wpa_dbus_property_desc *property_desc, | |
4228 | DBusMessageIter *iter, DBusError *error, void *user_data) | |
8fc2fb56 | 4229 | { |
6aeeb6fa | 4230 | struct network_handler_args *net = user_data; |
8fc2fb56 | 4231 | struct wpa_ssid *ssid = net->ssid; |
6aeeb6fa | 4232 | DBusMessageIter variant_iter; |
8fc2fb56 | 4233 | |
6aeeb6fa DW |
4234 | dbus_message_iter_recurse(iter, &variant_iter); |
4235 | return set_network_properties(net->wpa_s, ssid, &variant_iter, error); | |
8fc2fb56 | 4236 | } |
2d43d37f JB |
4237 | |
4238 | ||
4239 | #ifdef CONFIG_AP | |
4240 | ||
4241 | DBusMessage * wpas_dbus_handler_subscribe_preq( | |
4242 | DBusMessage *message, struct wpa_supplicant *wpa_s) | |
4243 | { | |
4244 | struct wpas_dbus_priv *priv = wpa_s->global->dbus; | |
4245 | char *name; | |
4246 | ||
4247 | if (wpa_s->preq_notify_peer != NULL) { | |
4248 | if (os_strcmp(dbus_message_get_sender(message), | |
4249 | wpa_s->preq_notify_peer) == 0) | |
4250 | return NULL; | |
4251 | ||
4252 | return dbus_message_new_error(message, | |
4253 | WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE, | |
4254 | "Another application is already subscribed"); | |
4255 | } | |
4256 | ||
4257 | name = os_strdup(dbus_message_get_sender(message)); | |
4258 | if (!name) | |
a0caebf3 | 4259 | return wpas_dbus_error_no_memory(message); |
2d43d37f JB |
4260 | |
4261 | wpa_s->preq_notify_peer = name; | |
4262 | ||
4263 | /* Subscribe to clean up if application closes socket */ | |
4264 | wpas_dbus_subscribe_noc(priv); | |
4265 | ||
4266 | /* | |
4267 | * Double-check it's still alive to make sure that we didn't | |
4268 | * miss the NameOwnerChanged signal, e.g. while strdup'ing. | |
4269 | */ | |
4270 | if (!dbus_bus_name_has_owner(priv->con, name, NULL)) { | |
4271 | /* | |
4272 | * Application no longer exists, clean up. | |
4273 | * The return value is irrelevant now. | |
4274 | * | |
4275 | * Need to check if the NameOwnerChanged handling | |
4276 | * already cleaned up because we have processed | |
4277 | * DBus messages while checking if the name still | |
4278 | * has an owner. | |
4279 | */ | |
4280 | if (!wpa_s->preq_notify_peer) | |
4281 | return NULL; | |
4282 | os_free(wpa_s->preq_notify_peer); | |
4283 | wpa_s->preq_notify_peer = NULL; | |
4284 | wpas_dbus_unsubscribe_noc(priv); | |
4285 | } | |
4286 | ||
4287 | return NULL; | |
4288 | } | |
4289 | ||
4290 | ||
4291 | DBusMessage * wpas_dbus_handler_unsubscribe_preq( | |
4292 | DBusMessage *message, struct wpa_supplicant *wpa_s) | |
4293 | { | |
4294 | struct wpas_dbus_priv *priv = wpa_s->global->dbus; | |
4295 | ||
4296 | if (!wpa_s->preq_notify_peer) | |
4297 | return dbus_message_new_error(message, | |
4298 | WPAS_DBUS_ERROR_NO_SUBSCRIPTION, | |
4299 | "Not subscribed"); | |
4300 | ||
4301 | if (os_strcmp(wpa_s->preq_notify_peer, | |
4302 | dbus_message_get_sender(message))) | |
4303 | return dbus_message_new_error(message, | |
4304 | WPAS_DBUS_ERROR_SUBSCRIPTION_EPERM, | |
4305 | "Can't unsubscribe others"); | |
4306 | ||
4307 | os_free(wpa_s->preq_notify_peer); | |
4308 | wpa_s->preq_notify_peer = NULL; | |
4309 | wpas_dbus_unsubscribe_noc(priv); | |
4310 | return NULL; | |
4311 | } | |
4312 | ||
4313 | ||
4314 | void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s, | |
4315 | const u8 *addr, const u8 *dst, const u8 *bssid, | |
4316 | const u8 *ie, size_t ie_len, u32 ssi_signal) | |
4317 | { | |
4318 | DBusMessage *msg; | |
4319 | DBusMessageIter iter, dict_iter; | |
4320 | struct wpas_dbus_priv *priv = wpa_s->global->dbus; | |
4321 | ||
4322 | /* Do nothing if the control interface is not turned on */ | |
8a78e227 | 4323 | if (priv == NULL || !wpa_s->dbus_new_path) |
2d43d37f JB |
4324 | return; |
4325 | ||
4326 | if (wpa_s->preq_notify_peer == NULL) | |
4327 | return; | |
4328 | ||
4329 | msg = dbus_message_new_signal(wpa_s->dbus_new_path, | |
4330 | WPAS_DBUS_NEW_IFACE_INTERFACE, | |
4331 | "ProbeRequest"); | |
4332 | if (msg == NULL) | |
4333 | return; | |
4334 | ||
4335 | dbus_message_set_destination(msg, wpa_s->preq_notify_peer); | |
4336 | ||
4337 | dbus_message_iter_init_append(msg, &iter); | |
4338 | ||
e3c4f0b5 JM |
4339 | if (!wpa_dbus_dict_open_write(&iter, &dict_iter) || |
4340 | (addr && !wpa_dbus_dict_append_byte_array(&dict_iter, "addr", | |
4341 | (const char *) addr, | |
4342 | ETH_ALEN)) || | |
4343 | (dst && !wpa_dbus_dict_append_byte_array(&dict_iter, "dst", | |
4344 | (const char *) dst, | |
4345 | ETH_ALEN)) || | |
4346 | (bssid && !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid", | |
4347 | (const char *) bssid, | |
4348 | ETH_ALEN)) || | |
4349 | (ie && ie_len && !wpa_dbus_dict_append_byte_array(&dict_iter, "ies", | |
4350 | (const char *) ie, | |
4351 | ie_len)) || | |
4352 | (ssi_signal && !wpa_dbus_dict_append_int32(&dict_iter, "signal", | |
4353 | ssi_signal)) || | |
4354 | !wpa_dbus_dict_close_write(&iter, &dict_iter)) | |
2d43d37f JB |
4355 | goto fail; |
4356 | ||
4357 | dbus_connection_send(priv->con, msg, NULL); | |
4358 | goto out; | |
4359 | fail: | |
4360 | wpa_printf(MSG_ERROR, "dbus: Failed to construct signal"); | |
4361 | out: | |
4362 | dbus_message_unref(msg); | |
4363 | } | |
4364 | ||
4365 | #endif /* CONFIG_AP */ | |
af041f99 AA |
4366 | |
4367 | ||
4368 | DBusMessage * wpas_dbus_handler_vendor_elem_add(DBusMessage *message, | |
4369 | struct wpa_supplicant *wpa_s) | |
4370 | { | |
4371 | u8 *ielems; | |
4372 | int len; | |
4373 | struct ieee802_11_elems elems; | |
4374 | dbus_int32_t frame_id; | |
4375 | DBusMessageIter iter, array; | |
4376 | ||
4377 | dbus_message_iter_init(message, &iter); | |
4378 | dbus_message_iter_get_basic(&iter, &frame_id); | |
4379 | if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) { | |
4380 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4381 | "Invalid ID"); | |
4382 | } | |
4383 | ||
4384 | dbus_message_iter_next(&iter); | |
4385 | dbus_message_iter_recurse(&iter, &array); | |
4386 | dbus_message_iter_get_fixed_array(&array, &ielems, &len); | |
4387 | if (!ielems || len == 0) { | |
4388 | return dbus_message_new_error( | |
4389 | message, DBUS_ERROR_INVALID_ARGS, "Invalid value"); | |
4390 | } | |
4391 | ||
4392 | if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) { | |
4393 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4394 | "Parse error"); | |
4395 | } | |
4396 | ||
4397 | wpa_s = wpas_vendor_elem(wpa_s, frame_id); | |
4398 | if (!wpa_s->vendor_elem[frame_id]) { | |
4399 | wpa_s->vendor_elem[frame_id] = wpabuf_alloc_copy(ielems, len); | |
4400 | wpas_vendor_elem_update(wpa_s); | |
4401 | return NULL; | |
4402 | } | |
4403 | ||
4404 | if (wpabuf_resize(&wpa_s->vendor_elem[frame_id], len) < 0) { | |
4405 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4406 | "Resize error"); | |
4407 | } | |
4408 | ||
4409 | wpabuf_put_data(wpa_s->vendor_elem[frame_id], ielems, len); | |
4410 | wpas_vendor_elem_update(wpa_s); | |
4411 | return NULL; | |
4412 | } | |
4413 | ||
4414 | ||
4415 | DBusMessage * wpas_dbus_handler_vendor_elem_get(DBusMessage *message, | |
4416 | struct wpa_supplicant *wpa_s) | |
4417 | { | |
4418 | DBusMessage *reply; | |
4419 | DBusMessageIter iter, array_iter; | |
4420 | dbus_int32_t frame_id; | |
4421 | const u8 *elem; | |
4422 | size_t elem_len; | |
4423 | ||
4424 | dbus_message_iter_init(message, &iter); | |
4425 | dbus_message_iter_get_basic(&iter, &frame_id); | |
4426 | ||
4427 | if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) { | |
4428 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4429 | "Invalid ID"); | |
4430 | } | |
4431 | ||
4432 | wpa_s = wpas_vendor_elem(wpa_s, frame_id); | |
4433 | if (!wpa_s->vendor_elem[frame_id]) { | |
4434 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4435 | "ID value does not exist"); | |
4436 | } | |
4437 | ||
4438 | reply = dbus_message_new_method_return(message); | |
4439 | if (!reply) | |
4440 | return wpas_dbus_error_no_memory(message); | |
4441 | ||
4442 | dbus_message_iter_init_append(reply, &iter); | |
4443 | ||
4444 | elem = wpabuf_head_u8(wpa_s->vendor_elem[frame_id]); | |
4445 | elem_len = wpabuf_len(wpa_s->vendor_elem[frame_id]); | |
4446 | ||
4447 | if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, | |
4448 | DBUS_TYPE_BYTE_AS_STRING, | |
4449 | &array_iter) || | |
4450 | !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE, | |
4451 | &elem, elem_len) || | |
4452 | !dbus_message_iter_close_container(&iter, &array_iter)) { | |
4453 | dbus_message_unref(reply); | |
4454 | reply = wpas_dbus_error_no_memory(message); | |
4455 | } | |
4456 | ||
4457 | return reply; | |
4458 | } | |
4459 | ||
4460 | ||
4461 | DBusMessage * wpas_dbus_handler_vendor_elem_remove(DBusMessage *message, | |
4462 | struct wpa_supplicant *wpa_s) | |
4463 | { | |
4464 | u8 *ielems; | |
4465 | int len; | |
4466 | struct ieee802_11_elems elems; | |
4467 | DBusMessageIter iter, array; | |
4468 | dbus_int32_t frame_id; | |
4469 | ||
4470 | dbus_message_iter_init(message, &iter); | |
4471 | dbus_message_iter_get_basic(&iter, &frame_id); | |
4472 | if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) { | |
4473 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4474 | "Invalid ID"); | |
4475 | } | |
4476 | ||
4477 | dbus_message_iter_next(&iter); | |
4478 | dbus_message_iter_recurse(&iter, &array); | |
4479 | dbus_message_iter_get_fixed_array(&array, &ielems, &len); | |
4480 | if (!ielems || len == 0) { | |
4481 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4482 | "Invalid value"); | |
4483 | } | |
4484 | ||
4485 | wpa_s = wpas_vendor_elem(wpa_s, frame_id); | |
4486 | ||
4487 | if (len == 1 && *ielems == '*') { | |
4488 | wpabuf_free(wpa_s->vendor_elem[frame_id]); | |
4489 | wpa_s->vendor_elem[frame_id] = NULL; | |
4490 | wpas_vendor_elem_update(wpa_s); | |
4491 | return NULL; | |
4492 | } | |
4493 | ||
4494 | if (!wpa_s->vendor_elem[frame_id]) { | |
4495 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4496 | "ID value does not exist"); | |
4497 | } | |
4498 | ||
4499 | if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) { | |
4500 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4501 | "Parse error"); | |
4502 | } | |
4503 | ||
4504 | if (wpas_vendor_elem_remove(wpa_s, frame_id, ielems, len) == 0) | |
4505 | return NULL; | |
4506 | ||
4507 | return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, | |
4508 | "Not found"); | |
4509 | } |