]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/dbus/dbus_new_handlers.c
dbus: Add support for vendor specific elements
[thirdparty/hostap.git] / wpa_supplicant / dbus / dbus_new_handlers.c
1 /*
2 * WPA Supplicant / dbus-based control interface
3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4 * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
5 * Copyright (c) 2009-2015, Jouni Malinen <j@w1.fi>
6 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
10
11 #include "includes.h"
12
13 #include "common.h"
14 #include "common/ieee802_11_defs.h"
15 #include "eap_peer/eap_methods.h"
16 #include "eapol_supp/eapol_supp_sm.h"
17 #include "rsn_supp/wpa.h"
18 #include "../config.h"
19 #include "../wpa_supplicant_i.h"
20 #include "../driver_i.h"
21 #include "../notify.h"
22 #include "../bss.h"
23 #include "../scan.h"
24 #include "../autoscan.h"
25 #include "dbus_new_helpers.h"
26 #include "dbus_new.h"
27 #include "dbus_new_handlers.h"
28 #include "dbus_dict_helpers.h"
29 #include "dbus_common_i.h"
30 #include "drivers/driver.h"
31
32 static const char * const debug_strings[] = {
33 "excessive", "msgdump", "debug", "info", "warning", "error", NULL
34 };
35
36
37 /**
38 * wpas_dbus_error_unknown_error - Return a new UnknownError error message
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 */
45 DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
46 const char *arg)
47 {
48 return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
49 arg);
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 {
62 return dbus_message_new_error(
63 message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
64 "wpa_supplicant knows nothing about this interface.");
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 {
77 return dbus_message_new_error(
78 message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
79 "There is no such a network in this interface.");
80 }
81
82
83 /**
84 * wpas_dbus_error_invalid_args - Return a new InvalidArgs error message
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 */
90 DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
91 const char *arg)
92 {
93 DBusMessage *reply;
94
95 reply = dbus_message_new_error(
96 message, WPAS_DBUS_ERROR_INVALID_ARGS,
97 "Did not receive correct message arguments.");
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
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 */
114 static DBusMessage * wpas_dbus_error_scan_error(DBusMessage *message,
115 const char *error)
116 {
117 return dbus_message_new_error(message,
118 WPAS_DBUS_ERROR_IFACE_SCAN_ERROR,
119 error);
120 }
121
122
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
130 static const char * const dont_quote[] = {
131 "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
132 "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
133 "bssid", "scan_freq", "freq_list", NULL
134 };
135
136 static dbus_bool_t should_quote_opt(const char *key)
137 {
138 int i = 0;
139
140 while (dont_quote[i] != NULL) {
141 if (os_strcmp(key, dont_quote[i]) == 0)
142 return FALSE;
143 i++;
144 }
145 return TRUE;
146 }
147
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) {
160 if (wpa_s->dbus_new_path &&
161 os_strcmp(wpa_s->dbus_new_path, path) == 0)
162 return wpa_s;
163 }
164 return NULL;
165 }
166
167
168 /**
169 * set_network_properties - Set properties of a configured network
170 * @wpa_s: wpa_supplicant structure for a network interface
171 * @ssid: wpa_ssid structure for a configured network
172 * @iter: DBus message iterator containing dictionary of network
173 * properties to set.
174 * @error: On failure, an error describing the failure
175 * Returns: TRUE if the request succeeds, FALSE if it failed
176 *
177 * Sets network configuration with parameters given id DBus dictionary
178 */
179 dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s,
180 struct wpa_ssid *ssid,
181 DBusMessageIter *iter,
182 DBusError *error)
183 {
184 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
185 DBusMessageIter iter_dict;
186 char *value = NULL;
187
188 if (!wpa_dbus_dict_open_read(iter, &iter_dict, error))
189 return FALSE;
190
191 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
192 size_t size = 50;
193 int ret;
194
195 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
196 goto error;
197
198 value = NULL;
199 if (entry.type == DBUS_TYPE_ARRAY &&
200 entry.array_type == DBUS_TYPE_BYTE) {
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
209 ret = wpa_snprintf_hex(value, size,
210 (u8 *) entry.bytearray_value,
211 entry.array_len);
212 if (ret <= 0)
213 goto error;
214 } else if (entry.type == DBUS_TYPE_STRING) {
215 if (should_quote_opt(entry.key)) {
216 size = os_strlen(entry.str_value);
217 if (size == 0)
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);
227 if (os_snprintf_error(size, ret))
228 goto error;
229 } else {
230 value = os_strdup(entry.str_value);
231 if (value == NULL)
232 goto error;
233 }
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);
241 if (os_snprintf_error(size, ret))
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);
250 if (os_snprintf_error(size, ret))
251 goto error;
252 } else
253 goto error;
254
255 if (wpa_config_set(ssid, entry.key, value, 0) < 0)
256 goto error;
257
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
271 if ((os_strcmp(entry.key, "psk") == 0 &&
272 value[0] == '"' && ssid->ssid_len) ||
273 (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
274 wpa_config_update_psk(ssid);
275 else if (os_strcmp(entry.key, "priority") == 0)
276 wpa_config_update_prio_list(wpa_s->conf);
277
278 os_free(value);
279 value = NULL;
280 wpa_dbus_dict_entry_clear(&entry);
281 }
282
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;
291 }
292
293
294 /**
295 * wpas_dbus_simple_property_getter - Get basic type property
296 * @iter: Message iter to use when appending arguments
297 * @type: DBus type of property (must be basic type)
298 * @val: pointer to place holding property value
299 * @error: On failure an error describing the failure
300 * Returns: TRUE if the request was successful, FALSE if it failed
301 *
302 * Generic getter for basic type properties. Type is required to be basic.
303 */
304 dbus_bool_t wpas_dbus_simple_property_getter(DBusMessageIter *iter,
305 const int type,
306 const void *val,
307 DBusError *error)
308 {
309 DBusMessageIter variant_iter;
310
311 if (!dbus_type_is_basic(type)) {
312 dbus_set_error(error, DBUS_ERROR_FAILED,
313 "%s: given type is not basic", __func__);
314 return FALSE;
315 }
316
317 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
318 wpa_dbus_type_as_string(type),
319 &variant_iter) ||
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 }
326
327 return TRUE;
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
336 * Returns: TRUE if the request was successful, FALSE if it failed
337 *
338 * Generic setter for basic type properties. Type is required to be basic.
339 */
340 dbus_bool_t wpas_dbus_simple_property_setter(DBusMessageIter *iter,
341 DBusError *error,
342 const int type, void *val)
343 {
344 DBusMessageIter variant_iter;
345
346 if (!dbus_type_is_basic(type)) {
347 dbus_set_error(error, DBUS_ERROR_FAILED,
348 "%s: given type is not basic", __func__);
349 return FALSE;
350 }
351
352 /* Look at the new value */
353 dbus_message_iter_recurse(iter, &variant_iter);
354 if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
355 dbus_set_error_const(error, DBUS_ERROR_FAILED,
356 "wrong property type");
357 return FALSE;
358 }
359 dbus_message_iter_get_basic(&variant_iter, val);
360
361 return TRUE;
362 }
363
364
365 /**
366 * wpas_dbus_simple_array_property_getter - Get array type property
367 * @iter: Pointer to incoming dbus message iterator
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
371 * @error: a pointer to an error to fill on failure
372 * Returns: TRUE if the request succeeded, FALSE if it failed
373 *
374 * Generic getter for array type properties. Array elements type is
375 * required to be basic.
376 */
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)
382 {
383 DBusMessageIter variant_iter, array_iter;
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)) {
389 dbus_set_error(error, DBUS_ERROR_FAILED,
390 "%s: given type is not basic", __func__);
391 return FALSE;
392 }
393
394 sub_type_str = wpa_dbus_type_as_string(type);
395 type_str[1] = sub_type_str[0];
396
397 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
398 type_str, &variant_iter) ||
399 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
400 sub_type_str, &array_iter)) {
401 dbus_set_error(error, DBUS_ERROR_FAILED,
402 "%s: failed to construct message", __func__);
403 return FALSE;
404 }
405
406 switch (type) {
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:
431 dbus_set_error(error, DBUS_ERROR_FAILED,
432 "%s: unknown element type %d", __func__, type);
433 return FALSE;
434 }
435
436 for (i = 0; i < array_len; i++) {
437 if (!dbus_message_iter_append_basic(&array_iter, type,
438 (const char *) array +
439 i * element_size)) {
440 dbus_set_error(error, DBUS_ERROR_FAILED,
441 "%s: failed to construct message 2.5",
442 __func__);
443 return FALSE;
444 }
445 }
446
447 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
448 !dbus_message_iter_close_container(iter, &variant_iter)) {
449 dbus_set_error(error, DBUS_ERROR_FAILED,
450 "%s: failed to construct message 3", __func__);
451 return FALSE;
452 }
453
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,
493 type_str, &variant_iter) ||
494 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
495 inner_type_str, &array_iter)) {
496 dbus_set_error(error, DBUS_ERROR_FAILED,
497 "%s: failed to construct message", __func__);
498 return FALSE;
499 }
500
501 for (i = 0; i < array_len && array[i]; i++) {
502 wpa_dbus_dict_bin_array_add_element(&array_iter,
503 wpabuf_head(array[i]),
504 wpabuf_len(array[i]));
505
506 }
507
508 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
509 !dbus_message_iter_close_container(iter, &variant_iter)) {
510 dbus_set_error(error, DBUS_ERROR_FAILED,
511 "%s: failed to close message", __func__);
512 return FALSE;
513 }
514
515 return TRUE;
516 }
517
518
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 *
526 * Handler function for "CreateInterface" method call. Handles requests
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,
531 struct wpa_global *global)
532 {
533 DBusMessageIter iter_dict;
534 DBusMessage *reply = NULL;
535 DBusMessageIter iter;
536 struct wpa_dbus_dict_entry entry;
537 char *driver = NULL;
538 char *ifname = NULL;
539 char *confname = NULL;
540 char *bridge_ifname = NULL;
541
542 dbus_message_iter_init(message, &iter);
543
544 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
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;
549 if (os_strcmp(entry.key, "Driver") == 0 &&
550 entry.type == DBUS_TYPE_STRING) {
551 os_free(driver);
552 driver = os_strdup(entry.str_value);
553 wpa_dbus_dict_entry_clear(&entry);
554 if (driver == NULL)
555 goto oom;
556 } else if (os_strcmp(entry.key, "Ifname") == 0 &&
557 entry.type == DBUS_TYPE_STRING) {
558 os_free(ifname);
559 ifname = os_strdup(entry.str_value);
560 wpa_dbus_dict_entry_clear(&entry);
561 if (ifname == NULL)
562 goto oom;
563 } else if (os_strcmp(entry.key, "ConfigFile") == 0 &&
564 entry.type == DBUS_TYPE_STRING) {
565 os_free(confname);
566 confname = os_strdup(entry.str_value);
567 wpa_dbus_dict_entry_clear(&entry);
568 if (confname == NULL)
569 goto oom;
570 } else if (os_strcmp(entry.key, "BridgeIfname") == 0 &&
571 entry.type == DBUS_TYPE_STRING) {
572 os_free(bridge_ifname);
573 bridge_ifname = os_strdup(entry.str_value);
574 wpa_dbus_dict_entry_clear(&entry);
575 if (bridge_ifname == NULL)
576 goto oom;
577 } else {
578 wpa_dbus_dict_entry_clear(&entry);
579 goto error;
580 }
581 }
582
583 if (ifname == NULL)
584 goto error; /* Required Ifname argument missing */
585
586 /*
587 * Try to get the wpa_supplicant record for this iface, return
588 * an error if we already control it.
589 */
590 if (wpa_supplicant_get_iface(global, ifname) != NULL) {
591 reply = dbus_message_new_error(
592 message, WPAS_DBUS_ERROR_IFACE_EXISTS,
593 "wpa_supplicant already controls this interface.");
594 } else {
595 struct wpa_supplicant *wpa_s;
596 struct wpa_interface iface;
597
598 os_memset(&iface, 0, sizeof(iface));
599 iface.driver = driver;
600 iface.ifname = ifname;
601 iface.confname = confname;
602 iface.bridge_ifname = bridge_ifname;
603 /* Otherwise, have wpa_supplicant attach to it. */
604 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
605 if (wpa_s && wpa_s->dbus_new_path) {
606 const char *path = wpa_s->dbus_new_path;
607
608 reply = dbus_message_new_method_return(message);
609 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
610 &path, DBUS_TYPE_INVALID);
611 } else {
612 reply = wpas_dbus_error_unknown_error(
613 message,
614 "wpa_supplicant couldn't grab this interface.");
615 }
616 }
617
618 out:
619 os_free(driver);
620 os_free(ifname);
621 os_free(confname);
622 os_free(bridge_ifname);
623 return reply;
624
625 error:
626 reply = wpas_dbus_error_invalid_args(message, NULL);
627 goto out;
628 oom:
629 reply = wpas_dbus_error_no_memory(message);
630 goto out;
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,
646 struct wpa_global *global)
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,
653 DBUS_TYPE_INVALID);
654
655 wpa_s = get_iface_by_dbus_path(global, path);
656 if (wpa_s == NULL)
657 reply = wpas_dbus_error_iface_unknown(message);
658 else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) {
659 reply = wpas_dbus_error_unknown_error(
660 message,
661 "wpa_supplicant couldn't remove this interface.");
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,
678 struct wpa_global *global)
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,
686 DBUS_TYPE_INVALID);
687
688 wpa_s = wpa_supplicant_get_iface(global, ifname);
689 if (wpa_s == NULL || wpa_s->dbus_new_path == NULL)
690 return wpas_dbus_error_iface_unknown(message);
691
692 path = wpa_s->dbus_new_path;
693 reply = dbus_message_new_method_return(message);
694 if (reply == NULL)
695 return wpas_dbus_error_no_memory(message);
696 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
697 DBUS_TYPE_INVALID)) {
698 dbus_message_unref(reply);
699 return wpas_dbus_error_no_memory(message);
700 }
701
702 return reply;
703 }
704
705
706 /**
707 * wpas_dbus_getter_debug_level - Get debug level
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
712 *
713 * Getter for "DebugLevel" property.
714 */
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)
718 {
719 const char *str;
720 int idx = wpa_debug_level;
721
722 if (idx < 0)
723 idx = 0;
724 if (idx > 5)
725 idx = 5;
726 str = debug_strings[idx];
727 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
728 &str, error);
729 }
730
731
732 /**
733 * wpas_dbus_getter_debug_timestamp - Get debug timestamp
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
738 *
739 * Getter for "DebugTimestamp" property.
740 */
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)
744 {
745 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
746 &wpa_debug_timestamp, error);
747
748 }
749
750
751 /**
752 * wpas_dbus_getter_debug_show_keys - Get debug show keys
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
757 *
758 * Getter for "DebugShowKeys" property.
759 */
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)
763 {
764 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
765 &wpa_debug_show_keys, error);
766
767 }
768
769 /**
770 * wpas_dbus_setter_debug_level - Set debug level
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
775 *
776 * Setter for "DebugLevel" property.
777 */
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)
781 {
782 struct wpa_global *global = user_data;
783 const char *str = NULL;
784 int i, val = -1;
785
786 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
787 &str))
788 return FALSE;
789
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,
798 wpa_debug_show_keys)) {
799 dbus_set_error_const(error, DBUS_ERROR_FAILED,
800 "wrong debug level value");
801 return FALSE;
802 }
803
804 return TRUE;
805 }
806
807
808 /**
809 * wpas_dbus_setter_debug_timestamp - Set debug timestamp
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
814 *
815 * Setter for "DebugTimestamp" property.
816 */
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)
820 {
821 struct wpa_global *global = user_data;
822 dbus_bool_t val;
823
824 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
825 &val))
826 return FALSE;
827
828 wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
829 wpa_debug_show_keys);
830 return TRUE;
831 }
832
833
834 /**
835 * wpas_dbus_setter_debug_show_keys - Set debug show keys
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
840 *
841 * Setter for "DebugShowKeys" property.
842 */
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)
846 {
847 struct wpa_global *global = user_data;
848 dbus_bool_t val;
849
850 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
851 &val))
852 return FALSE;
853
854 wpa_supplicant_set_debug_params(global, wpa_debug_level,
855 wpa_debug_timestamp,
856 val ? 1 : 0);
857 return TRUE;
858 }
859
860
861 /**
862 * wpas_dbus_getter_interfaces - Request registered interfaces list
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
867 *
868 * Getter for "Interfaces" property. Handles requests
869 * by dbus clients to return list of registered interfaces objects
870 * paths
871 */
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)
875 {
876 struct wpa_global *global = user_data;
877 struct wpa_supplicant *wpa_s;
878 const char **paths;
879 unsigned int i = 0, num = 0;
880 dbus_bool_t success;
881
882 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
883 if (wpa_s->dbus_new_path)
884 num++;
885 }
886
887 paths = os_calloc(num, sizeof(char *));
888 if (!paths) {
889 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
890 return FALSE;
891 }
892
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 }
897
898 success = wpas_dbus_simple_array_property_getter(iter,
899 DBUS_TYPE_OBJECT_PATH,
900 paths, num, error);
901
902 os_free(paths);
903 return success;
904 }
905
906
907 /**
908 * wpas_dbus_getter_eap_methods - Request supported EAP methods list
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
913 *
914 * Getter for "EapMethods" property. Handles requests
915 * by dbus clients to return list of strings with supported EAP methods
916 */
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)
920 {
921 char **eap_methods;
922 size_t num_items = 0;
923 dbus_bool_t success;
924
925 eap_methods = eap_get_names_as_string_array(&num_items);
926 if (!eap_methods) {
927 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
928 return FALSE;
929 }
930
931 success = wpas_dbus_simple_array_property_getter(iter,
932 DBUS_TYPE_STRING,
933 eap_methods,
934 num_items, error);
935
936 while (num_items)
937 os_free(eap_methods[--num_items]);
938 os_free(eap_methods);
939 return success;
940 }
941
942
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 */
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)
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
981 static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
982 char **type, DBusMessage **reply)
983 {
984 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
985 wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a string",
986 __func__);
987 *reply = wpas_dbus_error_invalid_args(
988 message, "Wrong Type value type. String required");
989 return -1;
990 }
991 dbus_message_iter_get_basic(var, type);
992 return 0;
993 }
994
995
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;
1006
1007 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1008 wpa_printf(MSG_DEBUG,
1009 "%s[dbus]: ssids must be an array of arrays of bytes",
1010 __func__);
1011 *reply = wpas_dbus_error_invalid_args(
1012 message,
1013 "Wrong SSIDs value type. Array of arrays of bytes required");
1014 return -1;
1015 }
1016
1017 dbus_message_iter_recurse(var, &array_iter);
1018
1019 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
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__);
1024 *reply = wpas_dbus_error_invalid_args(
1025 message,
1026 "Wrong SSIDs value type. Array of arrays of bytes required");
1027 return -1;
1028 }
1029
1030 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) {
1031 if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
1032 wpa_printf(MSG_DEBUG,
1033 "%s[dbus]: Too many ssids specified on scan dbus call",
1034 __func__);
1035 *reply = wpas_dbus_error_invalid_args(
1036 message,
1037 "Too many ssids specified. Specify at most four");
1038 return -1;
1039 }
1040
1041 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1042
1043 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1044
1045 if (len > SSID_MAX_LEN) {
1046 wpa_printf(MSG_DEBUG,
1047 "%s[dbus]: SSID too long (len=%d max_len=%d)",
1048 __func__, len, SSID_MAX_LEN);
1049 *reply = wpas_dbus_error_invalid_args(
1050 message, "Invalid SSID: too long");
1051 return -1;
1052 }
1053
1054 if (len != 0) {
1055 ssid = os_malloc(len);
1056 if (ssid == NULL) {
1057 *reply = wpas_dbus_error_no_memory(message);
1058 return -1;
1059 }
1060 os_memcpy(ssid, val, len);
1061 } else {
1062 /* Allow zero-length SSIDs */
1063 ssid = NULL;
1064 }
1065
1066 ssids[ssids_num].ssid = ssid;
1067 ssids[ssids_num].ssid_len = len;
1068
1069 dbus_message_iter_next(&array_iter);
1070 ssids_num++;
1071 }
1072
1073 params->num_ssids = ssids_num;
1074 return 0;
1075 }
1076
1077
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;
1087
1088 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1089 wpa_printf(MSG_DEBUG,
1090 "%s[dbus]: ies must be an array of arrays of bytes",
1091 __func__);
1092 *reply = wpas_dbus_error_invalid_args(
1093 message,
1094 "Wrong IEs value type. Array of arrays of bytes required");
1095 return -1;
1096 }
1097
1098 dbus_message_iter_recurse(var, &array_iter);
1099
1100 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
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__);
1105 *reply = wpas_dbus_error_invalid_args(
1106 message, "Wrong IEs value type. Array required");
1107 return -1;
1108 }
1109
1110 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) {
1111 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1112
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 }
1118
1119 nies = os_realloc(ies, ies_len + len);
1120 if (nies == NULL) {
1121 os_free(ies);
1122 *reply = wpas_dbus_error_no_memory(message);
1123 return -1;
1124 }
1125 ies = nies;
1126 os_memcpy(ies + ies_len, val, len);
1127 ies_len += len;
1128
1129 dbus_message_iter_next(&array_iter);
1130 }
1131
1132 params->extra_ies = ies;
1133 params->extra_ies_len = ies_len;
1134 return 0;
1135 }
1136
1137
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;
1146
1147 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1148 wpa_printf(MSG_DEBUG,
1149 "%s[dbus]: Channels must be an array of structs",
1150 __func__);
1151 *reply = wpas_dbus_error_invalid_args(
1152 message,
1153 "Wrong Channels value type. Array of structs required");
1154 return -1;
1155 }
1156
1157 dbus_message_iter_recurse(var, &array_iter);
1158
1159 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
1160 wpa_printf(MSG_DEBUG,
1161 "%s[dbus]: Channels must be an array of structs",
1162 __func__);
1163 *reply = wpas_dbus_error_invalid_args(
1164 message,
1165 "Wrong Channels value type. Array of structs required");
1166 return -1;
1167 }
1168
1169 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
1170 {
1171 int freq, width;
1172
1173 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1174
1175 if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
1176 DBUS_TYPE_UINT32) {
1177 wpa_printf(MSG_DEBUG,
1178 "%s[dbus]: Channel must by specified by struct of two UINT32s %c",
1179 __func__,
1180 dbus_message_iter_get_arg_type(
1181 &sub_array_iter));
1182 *reply = wpas_dbus_error_invalid_args(
1183 message,
1184 "Wrong Channel struct. Two UINT32s required");
1185 os_free(freqs);
1186 return -1;
1187 }
1188 dbus_message_iter_get_basic(&sub_array_iter, &freq);
1189
1190 if (!dbus_message_iter_next(&sub_array_iter) ||
1191 dbus_message_iter_get_arg_type(&sub_array_iter) !=
1192 DBUS_TYPE_UINT32) {
1193 wpa_printf(MSG_DEBUG,
1194 "%s[dbus]: Channel must by specified by struct of two UINT32s",
1195 __func__);
1196 *reply = wpas_dbus_error_invalid_args(
1197 message,
1198 "Wrong Channel struct. Two UINT32s required");
1199 os_free(freqs);
1200 return -1;
1201 }
1202
1203 dbus_message_iter_get_basic(&sub_array_iter, &width);
1204
1205 #define FREQS_ALLOC_CHUNK 32
1206 if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
1207 nfreqs = os_realloc_array(
1208 freqs, freqs_num + FREQS_ALLOC_CHUNK,
1209 sizeof(int));
1210 if (nfreqs == NULL)
1211 os_free(freqs);
1212 freqs = nfreqs;
1213 }
1214 if (freqs == NULL) {
1215 *reply = wpas_dbus_error_no_memory(message);
1216 return -1;
1217 }
1218
1219 freqs[freqs_num] = freq;
1220
1221 freqs_num++;
1222 dbus_message_iter_next(&array_iter);
1223 }
1224
1225 nfreqs = os_realloc_array(freqs, freqs_num + 1, sizeof(int));
1226 if (nfreqs == NULL)
1227 os_free(freqs);
1228 freqs = nfreqs;
1229 if (freqs == NULL) {
1230 *reply = wpas_dbus_error_no_memory(message);
1231 return -1;
1232 }
1233 freqs[freqs_num] = 0;
1234
1235 params->freqs = freqs;
1236 return 0;
1237 }
1238
1239
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) {
1246 wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a boolean",
1247 __func__);
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
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;
1275 dbus_bool_t allow_roam = 1;
1276
1277 os_memset(&params, 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) ==
1284 DBUS_TYPE_DICT_ENTRY) {
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 &params, &reply) < 0)
1297 goto out;
1298 } else if (os_strcmp(key, "IEs") == 0) {
1299 if (wpas_dbus_get_scan_ies(message, &variant_iter,
1300 &params, &reply) < 0)
1301 goto out;
1302 } else if (os_strcmp(key, "Channels") == 0) {
1303 if (wpas_dbus_get_scan_channels(message, &variant_iter,
1304 &params, &reply) < 0)
1305 goto out;
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;
1312 } else {
1313 wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown argument %s",
1314 __func__, key);
1315 reply = wpas_dbus_error_invalid_args(message, key);
1316 goto out;
1317 }
1318
1319 dbus_message_iter_next(&dict_iter);
1320 }
1321
1322 if (!type) {
1323 wpa_printf(MSG_DEBUG, "%s[dbus]: Scan type not specified",
1324 __func__);
1325 reply = wpas_dbus_error_invalid_args(message, key);
1326 goto out;
1327 }
1328
1329 if (os_strcmp(type, "passive") == 0) {
1330 if (params.num_ssids || params.extra_ies_len) {
1331 wpa_printf(MSG_DEBUG,
1332 "%s[dbus]: SSIDs or IEs specified for passive scan.",
1333 __func__);
1334 reply = wpas_dbus_error_invalid_args(
1335 message,
1336 "You can specify only Channels in passive scan");
1337 goto out;
1338 } else {
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]) {
1347 wpa_s->last_scan_req = MANUAL_SCAN_REQ;
1348 if (wpa_supplicant_trigger_scan(wpa_s,
1349 &params)) {
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 }
1358 }
1359 } else if (os_strcmp(type, "active") == 0) {
1360 if (!params.num_ssids) {
1361 /* Add wildcard ssid */
1362 params.num_ssids++;
1363 }
1364 #ifdef CONFIG_AUTOSCAN
1365 autoscan_deinit(wpa_s);
1366 #endif /* CONFIG_AUTOSCAN */
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
1374 wpa_s->last_scan_req = MANUAL_SCAN_REQ;
1375 if (wpa_supplicant_trigger_scan(wpa_s, &params)) {
1376 reply = wpas_dbus_error_scan_error(
1377 message, "Scan request rejected");
1378 }
1379 } else {
1380 wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown scan type: %s",
1381 __func__, type);
1382 reply = wpas_dbus_error_invalid_args(message,
1383 "Wrong scan type");
1384 goto out;
1385 }
1386
1387 if (!allow_roam)
1388 wpa_s->scan_res_handler = scan_only_handler;
1389
1390 out:
1391 for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
1392 os_free((u8 *) params.ssids[i].ssid);
1393 os_free((u8 *) params.extra_ies);
1394 os_free(params.freqs);
1395 return reply;
1396 }
1397
1398
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,
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))
1454 goto nomem;
1455
1456 return reply;
1457
1458 nomem:
1459 if (reply)
1460 dbus_message_unref(reply);
1461 return wpas_dbus_error_no_memory(message);
1462 }
1463
1464
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,
1475 struct wpa_supplicant *wpa_s)
1476 {
1477 if (wpa_s->current_ssid != NULL) {
1478 wpa_s->disconnected = 1;
1479 wpa_supplicant_deauthenticate(wpa_s,
1480 WLAN_REASON_DEAUTH_LEAVING);
1481
1482 return NULL;
1483 }
1484
1485 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
1486 "This interface is not connected");
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,
1499 struct wpa_supplicant *wpa_s)
1500 {
1501 DBusMessage *reply = NULL;
1502 DBusMessageIter iter;
1503 struct wpa_ssid *ssid = NULL;
1504 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
1505 DBusError error;
1506
1507 dbus_message_iter_init(message, &iter);
1508
1509 if (wpa_s->dbus_new_path)
1510 ssid = wpa_config_add_network(wpa_s->conf);
1511 if (ssid == NULL) {
1512 wpa_printf(MSG_ERROR, "%s[dbus]: can't add new interface.",
1513 __func__);
1514 reply = wpas_dbus_error_unknown_error(
1515 message,
1516 "wpa_supplicant could not add a network on this interface.");
1517 goto err;
1518 }
1519 wpas_notify_network_added(wpa_s, ssid);
1520 ssid->disabled = 1;
1521 wpa_config_set_network_defaults(ssid);
1522
1523 dbus_error_init(&error);
1524 if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
1525 wpa_printf(MSG_DEBUG,
1526 "%s[dbus]: control interface couldn't set network properties",
1527 __func__);
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);
1532 goto err;
1533 }
1534
1535 /* Construct the object path for this network. */
1536 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1537 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
1538 wpa_s->dbus_new_path, ssid->id);
1539
1540 reply = dbus_message_new_method_return(message);
1541 if (reply == NULL) {
1542 reply = wpas_dbus_error_no_memory(message);
1543 goto err;
1544 }
1545 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
1546 DBUS_TYPE_INVALID)) {
1547 dbus_message_unref(reply);
1548 reply = wpas_dbus_error_no_memory(message);
1549 goto err;
1550 }
1551
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 }
1559 return reply;
1560 }
1561
1562
1563 /**
1564 * wpas_dbus_handler_reassociate - Reassociate
1565 * @message: Pointer to incoming dbus message
1566 * @wpa_s: wpa_supplicant structure for a network interface
1567 * Returns: InterfaceDisabled DBus error message if disabled
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 {
1575 if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) {
1576 wpas_request_connection(wpa_s);
1577 return NULL;
1578 }
1579
1580 return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_DISABLED,
1581 "This interface is disabled");
1582 }
1583
1584
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
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
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
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,
1662 struct wpa_supplicant *wpa_s)
1663 {
1664 DBusMessage *reply = NULL;
1665 const char *op;
1666 char *iface, *net_id;
1667 int id;
1668 struct wpa_ssid *ssid;
1669 int was_disabled;
1670
1671 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1672 DBUS_TYPE_INVALID);
1673
1674 /* Extract the network ID and ensure the network */
1675 /* is actually a child of this interface */
1676 iface = wpas_dbus_new_decompose_object_path(op,
1677 WPAS_DBUS_NEW_NETWORKS_PART,
1678 &net_id);
1679 if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
1680 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1681 reply = wpas_dbus_error_invalid_args(message, op);
1682 goto out;
1683 }
1684
1685 errno = 0;
1686 id = strtoul(net_id, NULL, 10);
1687 if (errno != 0) {
1688 reply = wpas_dbus_error_invalid_args(message, op);
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
1698 was_disabled = ssid->disabled;
1699
1700 wpas_notify_network_removed(wpa_s, ssid);
1701
1702 if (ssid == wpa_s->current_ssid)
1703 wpa_supplicant_deauthenticate(wpa_s,
1704 WLAN_REASON_DEAUTH_LEAVING);
1705 else if (!was_disabled && wpa_s->sched_scanning) {
1706 wpa_printf(MSG_DEBUG,
1707 "Stop ongoing sched_scan to remove network from filters");
1708 wpa_supplicant_cancel_sched_scan(wpa_s);
1709 wpa_supplicant_req_scan(wpa_s, 0, 0);
1710 }
1711
1712 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
1713 wpa_printf(MSG_ERROR,
1714 "%s[dbus]: error occurred when removing network %d",
1715 __func__, id);
1716 reply = wpas_dbus_error_unknown_error(
1717 message,
1718 "error removing the specified network on is interface.");
1719 goto out;
1720 }
1721
1722 out:
1723 os_free(iface);
1724 return reply;
1725 }
1726
1727
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,
1736 "%s[dbus]: error occurred when removing network %d",
1737 __func__, ssid->id);
1738 return;
1739 }
1740
1741 if (ssid == wpa_s->current_ssid)
1742 wpa_supplicant_deauthenticate(wpa_s,
1743 WLAN_REASON_DEAUTH_LEAVING);
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 {
1758 if (wpa_s->sched_scanning)
1759 wpa_supplicant_cancel_sched_scan(wpa_s);
1760
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
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,
1776 struct wpa_supplicant *wpa_s)
1777 {
1778 DBusMessage *reply = NULL;
1779 const char *op;
1780 char *iface, *net_id;
1781 int id;
1782 struct wpa_ssid *ssid;
1783
1784 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1785 DBUS_TYPE_INVALID);
1786
1787 /* Extract the network ID and ensure the network */
1788 /* is actually a child of this interface */
1789 iface = wpas_dbus_new_decompose_object_path(op,
1790 WPAS_DBUS_NEW_NETWORKS_PART,
1791 &net_id);
1792 if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
1793 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1794 reply = wpas_dbus_error_invalid_args(message, op);
1795 goto out;
1796 }
1797
1798 errno = 0;
1799 id = strtoul(net_id, NULL, 10);
1800 if (errno != 0) {
1801 reply = wpas_dbus_error_invalid_args(message, op);
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 }
1810
1811 /* Finally, associate with the network */
1812 wpa_supplicant_select_network(wpa_s, ssid);
1813
1814 out:
1815 os_free(iface);
1816 return reply;
1817 }
1818
1819
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;
1834 char *iface, *net_id;
1835 int id;
1836 struct wpa_ssid *ssid;
1837
1838 if (!dbus_message_get_args(message, NULL,
1839 DBUS_TYPE_OBJECT_PATH, &op,
1840 DBUS_TYPE_STRING, &field,
1841 DBUS_TYPE_STRING, &value,
1842 DBUS_TYPE_INVALID))
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 */
1847 iface = wpas_dbus_new_decompose_object_path(op,
1848 WPAS_DBUS_NEW_NETWORKS_PART,
1849 &net_id);
1850 if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
1851 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1852 reply = wpas_dbus_error_invalid_args(message, op);
1853 goto out;
1854 }
1855
1856 errno = 0;
1857 id = strtoul(net_id, NULL, 10);
1858 if (errno != 0) {
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);
1879 return reply;
1880 #else /* IEEE8021X_EAPOL */
1881 wpa_printf(MSG_DEBUG, "dbus: 802.1X not included");
1882 return wpas_dbus_error_unknown_error(message, "802.1X not included");
1883 #endif /* IEEE8021X_EAPOL */
1884 }
1885
1886
1887 #ifndef CONFIG_NO_CONFIG_BLOBS
1888
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,
1898 struct wpa_supplicant *wpa_s)
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)) {
1912 return dbus_message_new_error(message,
1913 WPAS_DBUS_ERROR_BLOB_EXISTS,
1914 NULL);
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) {
1924 reply = wpas_dbus_error_no_memory(message);
1925 goto err;
1926 }
1927
1928 blob->data = os_malloc(blob_len);
1929 blob->name = os_strdup(blob_name);
1930 if (!blob->data || !blob->name) {
1931 reply = wpas_dbus_error_no_memory(message);
1932 goto err;
1933 }
1934 os_memcpy(blob->data, blob_data, blob_len);
1935 blob->len = blob_len;
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,
1961 struct wpa_supplicant *wpa_s)
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,
1970 DBUS_TYPE_INVALID);
1971
1972 blob = wpa_config_get_blob(wpa_s->conf, blob_name);
1973 if (!blob) {
1974 return dbus_message_new_error(message,
1975 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
1976 "Blob id not set");
1977 }
1978
1979 reply = dbus_message_new_method_return(message);
1980 if (!reply)
1981 return wpas_dbus_error_no_memory(message);
1982
1983 dbus_message_iter_init_append(reply, &iter);
1984
1985 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
1986 DBUS_TYPE_BYTE_AS_STRING,
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)) {
1991 dbus_message_unref(reply);
1992 reply = wpas_dbus_error_no_memory(message);
1993 }
1994
1995 return reply;
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,
2008 struct wpa_supplicant *wpa_s)
2009 {
2010 DBusMessage *reply = NULL;
2011 char *blob_name;
2012
2013 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
2014 DBUS_TYPE_INVALID);
2015
2016 if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
2017 return dbus_message_new_error(message,
2018 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
2019 "Blob id not set");
2020 }
2021 wpas_notify_blob_removed(wpa_s, blob_name);
2022
2023 return reply;
2024
2025 }
2026
2027 #endif /* CONFIG_NO_CONFIG_BLOBS */
2028
2029
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
2054
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;
2076
2077 tmp = os_strdup(arg);
2078 if (tmp == NULL) {
2079 reply = wpas_dbus_error_no_memory(message);
2080 } else {
2081 os_free(wpa_s->conf->autoscan);
2082 wpa_s->conf->autoscan = tmp;
2083 if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
2084 autoscan_init(wpa_s, 1);
2085 else if (state == WPA_SCANNING)
2086 wpa_supplicant_reinit_autoscan(wpa_s);
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
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
2134 #ifdef CONFIG_TDLS
2135
2136 static int get_peer_hwaddr_helper(DBusMessage *message, const char *func_name,
2137 u8 *peer_address, DBusMessage **error)
2138 {
2139 const char *peer_string;
2140
2141 *error = NULL;
2142
2143 if (!dbus_message_get_args(message, NULL,
2144 DBUS_TYPE_STRING, &peer_string,
2145 DBUS_TYPE_INVALID)) {
2146 *error = wpas_dbus_error_invalid_args(message, NULL);
2147 return -1;
2148 }
2149
2150 if (hwaddr_aton(peer_string, peer_address)) {
2151 wpa_printf(MSG_DEBUG, "%s: invalid address '%s'",
2152 func_name, peer_string);
2153 *error = wpas_dbus_error_invalid_args(
2154 message, "Invalid hardware address format");
2155 return -1;
2156 }
2157
2158 return 0;
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
2177 if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
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
2211 if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
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
2246 if (get_peer_hwaddr_helper(message, __func__, peer, &reply) < 0)
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
2275 if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
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
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
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,
2370 "Reinit of the EAPOL state machine with the new PKCS #11 engine and module path failed.");
2371
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 }
2380
2381 return NULL;
2382 }
2383
2384
2385 /**
2386 * wpas_dbus_getter_capabilities - Return interface capabilities
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
2391 *
2392 * Getter for "Capabilities" property of an interface.
2393 */
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)
2397 {
2398 struct wpa_supplicant *wpa_s = user_data;
2399 struct wpa_driver_capa capa;
2400 int res;
2401 DBusMessageIter iter_dict, iter_dict_entry, iter_dict_val, iter_array,
2402 variant_iter;
2403 const char *scans[] = { "active", "passive", "ssid" };
2404
2405 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
2406 "a{sv}", &variant_iter) ||
2407 !wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
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"};
2415
2416 if (!wpa_dbus_dict_append_string_array(
2417 &iter_dict, "Pairwise", args,
2418 ARRAY_SIZE(args)))
2419 goto nomem;
2420 } else {
2421 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
2422 &iter_dict_entry,
2423 &iter_dict_val,
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,
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 };
2455
2456 if (!wpa_dbus_dict_append_string_array(
2457 &iter_dict, "Group", args,
2458 ARRAY_SIZE(args)))
2459 goto nomem;
2460 } else {
2461 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
2462 &iter_dict_entry,
2463 &iter_dict_val,
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,
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(
2503 &iter_dict, "KeyMgmt", args,
2504 ARRAY_SIZE(args)))
2505 goto nomem;
2506 } else {
2507 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
2508 &iter_dict_entry,
2509 &iter_dict_val,
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,
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(
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")))
2524 goto nomem;
2525
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 */
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(
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")))
2542 goto nomem;
2543
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 */
2550 }
2551
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;
2556
2557
2558 #ifdef CONFIG_WPS
2559 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
2560 "wps"))
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;
2569 }
2570
2571 /***** WPA protocol */
2572 if (res < 0) {
2573 const char *args[] = { "rsn", "wpa" };
2574
2575 if (!wpa_dbus_dict_append_string_array(
2576 &iter_dict, "Protocol", args,
2577 ARRAY_SIZE(args)))
2578 goto nomem;
2579 } else {
2580 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
2581 &iter_dict_entry,
2582 &iter_dict_val,
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,
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" };
2602
2603 if (!wpa_dbus_dict_append_string_array(
2604 &iter_dict, "AuthAlg", args,
2605 ARRAY_SIZE(args)))
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
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,
2624 &iter_dict_entry,
2625 &iter_dict_val,
2626 &iter_array))
2627 goto nomem;
2628 }
2629
2630 /***** Scan */
2631 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
2632 ARRAY_SIZE(scans)))
2633 goto nomem;
2634
2635 /***** Modes */
2636 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Modes",
2637 &iter_dict_entry,
2638 &iter_dict_val,
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,
2651 &iter_dict_entry,
2652 &iter_dict_val,
2653 &iter_array))
2654 goto nomem;
2655 /***** Modes end */
2656
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
2665 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
2666 !dbus_message_iter_close_container(iter, &variant_iter))
2667 goto nomem;
2668
2669 return TRUE;
2670
2671 nomem:
2672 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2673 return FALSE;
2674 }
2675
2676
2677 /**
2678 * wpas_dbus_getter_state - Get interface state
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
2683 *
2684 * Getter for "State" property.
2685 */
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)
2689 {
2690 struct wpa_supplicant *wpa_s = user_data;
2691 const char *str_state;
2692 char *state_ls, *tmp;
2693 dbus_bool_t success = FALSE;
2694
2695 str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
2696
2697 /* make state string lowercase to fit new DBus API convention
2698 */
2699 state_ls = tmp = os_strdup(str_state);
2700 if (!tmp) {
2701 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2702 return FALSE;
2703 }
2704 while (*tmp) {
2705 *tmp = tolower(*tmp);
2706 tmp++;
2707 }
2708
2709 success = wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2710 &state_ls, error);
2711
2712 os_free(state_ls);
2713
2714 return success;
2715 }
2716
2717
2718 /**
2719 * wpas_dbus_new_iface_get_scanning - Get interface scanning state
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
2724 *
2725 * Getter for "scanning" property.
2726 */
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)
2730 {
2731 struct wpa_supplicant *wpa_s = user_data;
2732 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
2733
2734 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
2735 &scanning, error);
2736 }
2737
2738
2739 /**
2740 * wpas_dbus_getter_ap_scan - Control roaming mode
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
2745 *
2746 * Getter function for "ApScan" property.
2747 */
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)
2751 {
2752 struct wpa_supplicant *wpa_s = user_data;
2753 dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
2754
2755 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2756 &ap_scan, error);
2757 }
2758
2759
2760 /**
2761 * wpas_dbus_setter_ap_scan - Control roaming mode
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
2766 *
2767 * Setter function for "ApScan" property.
2768 */
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)
2772 {
2773 struct wpa_supplicant *wpa_s = user_data;
2774 dbus_uint32_t ap_scan;
2775
2776 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2777 &ap_scan))
2778 return FALSE;
2779
2780 if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
2781 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2782 "ap_scan must be 0, 1, or 2");
2783 return FALSE;
2784 }
2785 return TRUE;
2786 }
2787
2788
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 */
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)
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 */
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)
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
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 */
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)
2850 {
2851 struct wpa_supplicant *wpa_s = user_data;
2852 dbus_int32_t reason = wpa_s->disconnect_reason;
2853
2854 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
2855 &reason, error);
2856 }
2857
2858
2859 /**
2860 * wpas_dbus_getter_bss_expire_age - Get BSS entry expiration age
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
2865 *
2866 * Getter function for "BSSExpireAge" property.
2867 */
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)
2871 {
2872 struct wpa_supplicant *wpa_s = user_data;
2873 dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age;
2874
2875 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2876 &expire_age, error);
2877 }
2878
2879
2880 /**
2881 * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age
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
2886 *
2887 * Setter function for "BSSExpireAge" property.
2888 */
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)
2892 {
2893 struct wpa_supplicant *wpa_s = user_data;
2894 dbus_uint32_t expire_age;
2895
2896 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2897 &expire_age))
2898 return FALSE;
2899
2900 if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) {
2901 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2902 "BSSExpireAge must be >= 10");
2903 return FALSE;
2904 }
2905 return TRUE;
2906 }
2907
2908
2909 /**
2910 * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count
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
2915 *
2916 * Getter function for "BSSExpireCount" property.
2917 */
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)
2921 {
2922 struct wpa_supplicant *wpa_s = user_data;
2923 dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_scan_count;
2924
2925 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2926 &expire_count, error);
2927 }
2928
2929
2930 /**
2931 * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count
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
2936 *
2937 * Setter function for "BSSExpireCount" property.
2938 */
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)
2942 {
2943 struct wpa_supplicant *wpa_s = user_data;
2944 dbus_uint32_t expire_count;
2945
2946 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2947 &expire_count))
2948 return FALSE;
2949
2950 if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) {
2951 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2952 "BSSExpireCount must be > 0");
2953 return FALSE;
2954 }
2955 return TRUE;
2956 }
2957
2958
2959 /**
2960 * wpas_dbus_getter_country - Control country code
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
2965 *
2966 * Getter function for "Country" property.
2967 */
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)
2971 {
2972 struct wpa_supplicant *wpa_s = user_data;
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
2980 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2981 &str, error);
2982 }
2983
2984
2985 /**
2986 * wpas_dbus_setter_country - Control country code
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
2991 *
2992 * Setter function for "Country" property.
2993 */
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)
2997 {
2998 struct wpa_supplicant *wpa_s = user_data;
2999 const char *country;
3000
3001 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
3002 &country))
3003 return FALSE;
3004
3005 if (!country[0] || !country[1]) {
3006 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3007 "invalid country code");
3008 return FALSE;
3009 }
3010
3011 if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) {
3012 wpa_printf(MSG_DEBUG, "Failed to set country");
3013 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3014 "failed to set country code");
3015 return FALSE;
3016 }
3017
3018 wpa_s->conf->country[0] = country[0];
3019 wpa_s->conf->country[1] = country[1];
3020 return TRUE;
3021 }
3022
3023
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 */
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)
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 */
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)
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
3074 /**
3075 * wpas_dbus_getter_ifname - Get interface name
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
3080 *
3081 * Getter for "Ifname" property.
3082 */
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)
3086 {
3087 struct wpa_supplicant *wpa_s = user_data;
3088 const char *ifname = wpa_s->ifname;
3089
3090 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3091 &ifname, error);
3092 }
3093
3094
3095 /**
3096 * wpas_dbus_getter_driver - Get interface name
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
3101 *
3102 * Getter for "Driver" property.
3103 */
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)
3107 {
3108 struct wpa_supplicant *wpa_s = user_data;
3109 const char *driver;
3110
3111 if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
3112 wpa_printf(MSG_DEBUG, "%s[dbus]: wpa_s has no driver set",
3113 __func__);
3114 dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
3115 __func__);
3116 return FALSE;
3117 }
3118
3119 driver = wpa_s->driver->name;
3120 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3121 &driver, error);
3122 }
3123
3124
3125 /**
3126 * wpas_dbus_getter_current_bss - Get current bss object path
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
3131 *
3132 * Getter for "CurrentBSS" property.
3133 */
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)
3137 {
3138 struct wpa_supplicant *wpa_s = user_data;
3139 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
3140
3141 if (wpa_s->current_bss && wpa_s->dbus_new_path)
3142 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3143 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
3144 wpa_s->dbus_new_path, wpa_s->current_bss->id);
3145 else
3146 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
3147
3148 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
3149 &bss_obj_path, error);
3150 }
3151
3152
3153 /**
3154 * wpas_dbus_getter_current_network - Get current network object path
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
3159 *
3160 * Getter for "CurrentNetwork" property.
3161 */
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)
3165 {
3166 struct wpa_supplicant *wpa_s = user_data;
3167 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
3168
3169 if (wpa_s->current_ssid && wpa_s->dbus_new_path)
3170 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3171 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
3172 wpa_s->dbus_new_path, wpa_s->current_ssid->id);
3173 else
3174 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
3175
3176 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
3177 &net_obj_path, error);
3178 }
3179
3180
3181 /**
3182 * wpas_dbus_getter_current_auth_mode - Get current authentication type
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
3187 *
3188 * Getter for "CurrentAuthMode" property.
3189 */
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)
3193 {
3194 struct wpa_supplicant *wpa_s = user_data;
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
3213 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3214 &auth_mode, error);
3215 }
3216
3217
3218 /**
3219 * wpas_dbus_getter_bridge_ifname - Get interface name
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
3224 *
3225 * Getter for "BridgeIfname" property.
3226 */
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)
3230 {
3231 struct wpa_supplicant *wpa_s = user_data;
3232 const char *bridge_ifname = wpa_s->bridge_ifname;
3233
3234 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3235 &bridge_ifname, error);
3236 }
3237
3238
3239 /**
3240 * wpas_dbus_getter_bsss - Get array of BSSs objects
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
3245 *
3246 * Getter for "BSSs" property.
3247 */
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)
3251 {
3252 struct wpa_supplicant *wpa_s = user_data;
3253 struct wpa_bss *bss;
3254 char **paths;
3255 unsigned int i = 0;
3256 dbus_bool_t success = FALSE;
3257
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
3264 paths = os_calloc(wpa_s->num_bss, sizeof(char *));
3265 if (!paths) {
3266 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3267 return FALSE;
3268 }
3269
3270 /* Loop through scan results and append each result's object path */
3271 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3272 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3273 if (paths[i] == NULL) {
3274 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3275 "no memory");
3276 goto out;
3277 }
3278 /* Construct the object path for this BSS. */
3279 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3280 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
3281 wpa_s->dbus_new_path, bss->id);
3282 }
3283
3284 success = wpas_dbus_simple_array_property_getter(iter,
3285 DBUS_TYPE_OBJECT_PATH,
3286 paths, wpa_s->num_bss,
3287 error);
3288
3289 out:
3290 while (i)
3291 os_free(paths[--i]);
3292 os_free(paths);
3293 return success;
3294 }
3295
3296
3297 /**
3298 * wpas_dbus_getter_networks - Get array of networks objects
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
3303 *
3304 * Getter for "Networks" property.
3305 */
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)
3309 {
3310 struct wpa_supplicant *wpa_s = user_data;
3311 struct wpa_ssid *ssid;
3312 char **paths;
3313 unsigned int i = 0, num = 0;
3314 dbus_bool_t success = FALSE;
3315
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
3322 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
3323 if (!network_is_persistent_group(ssid))
3324 num++;
3325
3326 paths = os_calloc(num, sizeof(char *));
3327 if (!paths) {
3328 dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
3329 return FALSE;
3330 }
3331
3332 /* Loop through configured networks and append object path of each */
3333 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
3334 if (network_is_persistent_group(ssid))
3335 continue;
3336 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3337 if (paths[i] == NULL) {
3338 dbus_set_error(error, DBUS_ERROR_NO_MEMORY,
3339 "no memory");
3340 goto out;
3341 }
3342
3343 /* Construct the object path for this network. */
3344 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3345 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
3346 wpa_s->dbus_new_path, ssid->id);
3347 }
3348
3349 success = wpas_dbus_simple_array_property_getter(iter,
3350 DBUS_TYPE_OBJECT_PATH,
3351 paths, num, error);
3352
3353 out:
3354 while (i)
3355 os_free(paths[--i]);
3356 os_free(paths);
3357 return success;
3358 }
3359
3360
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 */
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)
3373 {
3374 struct wpa_supplicant *wpa_s = user_data;
3375 const char *pkcs11_engine_path;
3376
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 */
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)
3398 {
3399 struct wpa_supplicant *wpa_s = user_data;
3400 const char *pkcs11_module_path;
3401
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
3411 /**
3412 * wpas_dbus_getter_blobs - Get all blobs defined for this interface
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
3417 *
3418 * Getter for "Blobs" property.
3419 */
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)
3423 {
3424 struct wpa_supplicant *wpa_s = user_data;
3425 DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter;
3426 struct wpa_config_blob *blob;
3427
3428 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
3429 "a{say}", &variant_iter) ||
3430 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
3431 "{say}", &dict_iter)) {
3432 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3433 return FALSE;
3434 }
3435
3436 blob = wpa_s->conf->blobs;
3437 while (blob) {
3438 if (!dbus_message_iter_open_container(&dict_iter,
3439 DBUS_TYPE_DICT_ENTRY,
3440 NULL, &entry_iter) ||
3441 !dbus_message_iter_append_basic(&entry_iter,
3442 DBUS_TYPE_STRING,
3443 &(blob->name)) ||
3444 !dbus_message_iter_open_container(&entry_iter,
3445 DBUS_TYPE_ARRAY,
3446 DBUS_TYPE_BYTE_AS_STRING,
3447 &array_iter) ||
3448 !dbus_message_iter_append_fixed_array(&array_iter,
3449 DBUS_TYPE_BYTE,
3450 &(blob->data),
3451 blob->len) ||
3452 !dbus_message_iter_close_container(&entry_iter,
3453 &array_iter) ||
3454 !dbus_message_iter_close_container(&dict_iter,
3455 &entry_iter)) {
3456 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3457 "no memory");
3458 return FALSE;
3459 }
3460
3461 blob = blob->next;
3462 }
3463
3464 if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
3465 !dbus_message_iter_close_container(iter, &variant_iter)) {
3466 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3467 return FALSE;
3468 }
3469
3470 return TRUE;
3471 }
3472
3473
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
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",
3554 func_name, args->id);
3555 dbus_set_error(error, DBUS_ERROR_FAILED,
3556 "%s: BSS %d not found",
3557 func_name, args->id);
3558 }
3559
3560 return res;
3561 }
3562
3563
3564 /**
3565 * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
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
3570 *
3571 * Getter for "BSSID" property.
3572 */
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)
3576 {
3577 struct bss_handler_args *args = user_data;
3578 struct wpa_bss *res;
3579
3580 res = get_bss_helper(args, error, __func__);
3581 if (!res)
3582 return FALSE;
3583
3584 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3585 res->bssid, ETH_ALEN,
3586 error);
3587 }
3588
3589
3590 /**
3591 * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
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
3596 *
3597 * Getter for "SSID" property.
3598 */
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)
3602 {
3603 struct bss_handler_args *args = user_data;
3604 struct wpa_bss *res;
3605
3606 res = get_bss_helper(args, error, __func__);
3607 if (!res)
3608 return FALSE;
3609
3610 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3611 res->ssid, res->ssid_len,
3612 error);
3613 }
3614
3615
3616 /**
3617 * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
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
3622 *
3623 * Getter for "Privacy" property.
3624 */
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)
3628 {
3629 struct bss_handler_args *args = user_data;
3630 struct wpa_bss *res;
3631 dbus_bool_t privacy;
3632
3633 res = get_bss_helper(args, error, __func__);
3634 if (!res)
3635 return FALSE;
3636
3637 privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
3638 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
3639 &privacy, error);
3640 }
3641
3642
3643 /**
3644 * wpas_dbus_getter_bss_mode - Return the mode of a BSS
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
3649 *
3650 * Getter for "Mode" property.
3651 */
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)
3655 {
3656 struct bss_handler_args *args = user_data;
3657 struct wpa_bss *res;
3658 const char *mode;
3659
3660 res = get_bss_helper(args, error, __func__);
3661 if (!res)
3662 return FALSE;
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 }
3679
3680 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3681 &mode, error);
3682 }
3683
3684
3685 /**
3686 * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
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
3691 *
3692 * Getter for "Level" property.
3693 */
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)
3697 {
3698 struct bss_handler_args *args = user_data;
3699 struct wpa_bss *res;
3700 s16 level;
3701
3702 res = get_bss_helper(args, error, __func__);
3703 if (!res)
3704 return FALSE;
3705
3706 level = (s16) res->level;
3707 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16,
3708 &level, error);
3709 }
3710
3711
3712 /**
3713 * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
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
3718 *
3719 * Getter for "Frequency" property.
3720 */
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)
3724 {
3725 struct bss_handler_args *args = user_data;
3726 struct wpa_bss *res;
3727 u16 freq;
3728
3729 res = get_bss_helper(args, error, __func__);
3730 if (!res)
3731 return FALSE;
3732
3733 freq = (u16) res->freq;
3734 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
3735 &freq, error);
3736 }
3737
3738
3739 static int cmp_u8s_desc(const void *a, const void *b)
3740 {
3741 return (*(u8 *) b - *(u8 *) a);
3742 }
3743
3744
3745 /**
3746 * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
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
3751 *
3752 * Getter for "Rates" property.
3753 */
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)
3757 {
3758 struct bss_handler_args *args = user_data;
3759 struct wpa_bss *res;
3760 u8 *ie_rates = NULL;
3761 u32 *real_rates;
3762 int rates_num, i;
3763 dbus_bool_t success = FALSE;
3764
3765 res = get_bss_helper(args, error, __func__);
3766 if (!res)
3767 return FALSE;
3768
3769 rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
3770 if (rates_num < 0)
3771 return FALSE;
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);
3778 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3779 return FALSE;
3780 }
3781
3782 for (i = 0; i < rates_num; i++)
3783 real_rates[i] = ie_rates[i] * 500000;
3784
3785 success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32,
3786 real_rates, rates_num,
3787 error);
3788
3789 os_free(ie_rates);
3790 os_free(real_rates);
3791 return success;
3792 }
3793
3794
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)
3798 {
3799 DBusMessageIter iter_dict, variant_iter;
3800 const char *group;
3801 const char *pairwise[5]; /* max 5 pairwise ciphers is supported */
3802 const char *key_mgmt[9]; /* max 9 key managements may be supported */
3803 int n;
3804
3805 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
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";
3826 #ifdef CONFIG_SUITEB
3827 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B)
3828 key_mgmt[n++] = "wpa-eap-suite-b";
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 */
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;
3852 case WPA_CIPHER_GCMP:
3853 group = "gcmp";
3854 break;
3855 case WPA_CIPHER_WEP104:
3856 group = "wep104";
3857 break;
3858 case WPA_CIPHER_CCMP_256:
3859 group = "ccmp-256";
3860 break;
3861 case WPA_CIPHER_GCMP_256:
3862 group = "gcmp-256";
3863 break;
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";
3878 if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP)
3879 pairwise[n++] = "gcmp";
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";
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
3907 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
3908 !dbus_message_iter_close_container(iter, &variant_iter))
3909 goto nomem;
3910
3911 return TRUE;
3912
3913 nomem:
3914 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3915 return FALSE;
3916 }
3917
3918
3919 /**
3920 * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
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
3925 *
3926 * Getter for "WPA" property.
3927 */
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)
3931 {
3932 struct bss_handler_args *args = user_data;
3933 struct wpa_bss *res;
3934 struct wpa_ie_data wpa_data;
3935 const u8 *ie;
3936
3937 res = get_bss_helper(args, error, __func__);
3938 if (!res)
3939 return FALSE;
3940
3941 os_memset(&wpa_data, 0, sizeof(wpa_data));
3942 ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
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;
3947 }
3948
3949 return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
3950 }
3951
3952
3953 /**
3954 * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
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
3959 *
3960 * Getter for "RSN" property.
3961 */
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)
3965 {
3966 struct bss_handler_args *args = user_data;
3967 struct wpa_bss *res;
3968 struct wpa_ie_data wpa_data;
3969 const u8 *ie;
3970
3971 res = get_bss_helper(args, error, __func__);
3972 if (!res)
3973 return FALSE;
3974
3975 os_memset(&wpa_data, 0, sizeof(wpa_data));
3976 ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
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;
3981 }
3982
3983 return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
3984 }
3985
3986
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 */
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)
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;
4006 int wps_support = 0;
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,
4014 "a{sv}", &variant_iter) ||
4015 !wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
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) {
4021 wps_support = 1;
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";
4026
4027 wpabuf_free(wps_ie);
4028 }
4029 #endif /* CONFIG_WPS */
4030
4031 if ((wps_support && !wpa_dbus_dict_append_string(&iter_dict, "Type", type)) ||
4032 !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
4033 !dbus_message_iter_close_container(iter, &variant_iter))
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
4044 /**
4045 * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
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
4050 *
4051 * Getter for "IEs" property.
4052 */
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)
4056 {
4057 struct bss_handler_args *args = user_data;
4058 struct wpa_bss *res;
4059
4060 res = get_bss_helper(args, error, __func__);
4061 if (!res)
4062 return FALSE;
4063
4064 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
4065 res + 1, res->ie_len,
4066 error);
4067 }
4068
4069
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 */
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)
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
4100 /**
4101 * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
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
4106 *
4107 * Getter for "enabled" property of a configured network.
4108 */
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)
4112 {
4113 struct network_handler_args *net = user_data;
4114 dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
4115
4116 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
4117 &enabled, error);
4118 }
4119
4120
4121 /**
4122 * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
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
4127 *
4128 * Setter for "Enabled" property of a configured network.
4129 */
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)
4133 {
4134 struct network_handler_args *net = user_data;
4135 struct wpa_supplicant *wpa_s;
4136 struct wpa_ssid *ssid;
4137 dbus_bool_t enable;
4138
4139 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
4140 &enable))
4141 return FALSE;
4142
4143 wpa_s = net->wpa_s;
4144 ssid = net->ssid;
4145
4146 if (enable)
4147 wpa_supplicant_enable_network(wpa_s, ssid);
4148 else
4149 wpa_supplicant_disable_network(wpa_s, ssid);
4150
4151 return TRUE;
4152 }
4153
4154
4155 /**
4156 * wpas_dbus_getter_network_properties - Get options for a configured network
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
4161 *
4162 * Getter for "Properties" property of a configured network.
4163 */
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)
4167 {
4168 struct network_handler_args *net = user_data;
4169 DBusMessageIter variant_iter, dict_iter;
4170 char **iterator;
4171 char **props = wpa_config_get_all(net->ssid, 1);
4172 dbus_bool_t success = FALSE;
4173
4174 if (!props) {
4175 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4176 return FALSE;
4177 }
4178
4179 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
4180 &variant_iter) ||
4181 !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
4182 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4183 goto out;
4184 }
4185
4186 iterator = props;
4187 while (*iterator) {
4188 if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
4189 *(iterator + 1))) {
4190 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
4191 "no memory");
4192 goto out;
4193 }
4194 iterator += 2;
4195 }
4196
4197
4198 if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
4199 !dbus_message_iter_close_container(iter, &variant_iter)) {
4200 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4201 goto out;
4202 }
4203
4204 success = TRUE;
4205
4206 out:
4207 iterator = props;
4208 while (*iterator) {
4209 os_free(*iterator);
4210 iterator++;
4211 }
4212 os_free(props);
4213 return success;
4214 }
4215
4216
4217 /**
4218 * wpas_dbus_setter_network_properties - Set options for a configured network
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
4223 *
4224 * Setter for "Properties" property of a configured network.
4225 */
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)
4229 {
4230 struct network_handler_args *net = user_data;
4231 struct wpa_ssid *ssid = net->ssid;
4232 DBusMessageIter variant_iter;
4233
4234 dbus_message_iter_recurse(iter, &variant_iter);
4235 return set_network_properties(net->wpa_s, ssid, &variant_iter, error);
4236 }
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)
4259 return wpas_dbus_error_no_memory(message);
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 */
4323 if (priv == NULL || !wpa_s->dbus_new_path)
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
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))
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 */
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 }