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>
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
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"
24 #include "../autoscan.h"
25 #include "dbus_new_helpers.h"
27 #include "dbus_new_handlers.h"
28 #include "dbus_dict_helpers.h"
29 #include "dbus_common_i.h"
30 #include "drivers/driver.h"
32 static const char * const debug_strings
[] = {
33 "excessive", "msgdump", "debug", "info", "warning", "error", NULL
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
43 * Convenience function to create and return an UnknownError
45 DBusMessage
* wpas_dbus_error_unknown_error(DBusMessage
*message
,
48 return dbus_message_new_error(message
, WPAS_DBUS_ERROR_UNKNOWN_ERROR
,
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
58 * Convenience function to create and return an invalid interface error
60 static DBusMessage
* wpas_dbus_error_iface_unknown(DBusMessage
*message
)
62 return dbus_message_new_error(
63 message
, WPAS_DBUS_ERROR_IFACE_UNKNOWN
,
64 "wpa_supplicant knows nothing about this interface.");
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
73 * Convenience function to create and return an invalid network error
75 static DBusMessage
* wpas_dbus_error_network_unknown(DBusMessage
*message
)
77 return dbus_message_new_error(
78 message
, WPAS_DBUS_ERROR_NETWORK_UNKNOWN
,
79 "There is no such a network in this interface.");
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
88 * Convenience function to create and return an invalid options error
90 DBusMessage
* wpas_dbus_error_invalid_args(DBusMessage
*message
,
95 reply
= dbus_message_new_error(
96 message
, WPAS_DBUS_ERROR_INVALID_ARGS
,
97 "Did not receive correct message arguments.");
99 dbus_message_append_args(reply
, DBUS_TYPE_STRING
, &arg
,
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
112 * Convenience function to create and return a scan error
114 static DBusMessage
* wpas_dbus_error_scan_error(DBusMessage
*message
,
117 return dbus_message_new_error(message
,
118 WPAS_DBUS_ERROR_IFACE_SCAN_ERROR
,
123 DBusMessage
* wpas_dbus_error_no_memory(DBusMessage
*message
)
125 wpa_printf(MSG_DEBUG
, "dbus: Failed to allocate memory");
126 return dbus_message_new_error(message
, DBUS_ERROR_NO_MEMORY
, NULL
);
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
136 static dbus_bool_t
should_quote_opt(const char *key
)
140 while (dont_quote
[i
] != NULL
) {
141 if (os_strcmp(key
, dont_quote
[i
]) == 0)
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
154 static struct wpa_supplicant
* get_iface_by_dbus_path(
155 struct wpa_global
*global
, const char *path
)
157 struct wpa_supplicant
*wpa_s
;
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)
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
174 * @error: On failure, an error describing the failure
175 * Returns: TRUE if the request succeeds, FALSE if it failed
177 * Sets network configuration with parameters given id DBus dictionary
179 dbus_bool_t
set_network_properties(struct wpa_supplicant
*wpa_s
,
180 struct wpa_ssid
*ssid
,
181 DBusMessageIter
*iter
,
184 struct wpa_dbus_dict_entry entry
= { .type
= DBUS_TYPE_STRING
};
185 DBusMessageIter iter_dict
;
188 if (!wpa_dbus_dict_open_read(iter
, &iter_dict
, error
))
191 while (wpa_dbus_dict_has_dict_entry(&iter_dict
)) {
195 if (!wpa_dbus_dict_get_entry(&iter_dict
, &entry
))
199 if (entry
.type
== DBUS_TYPE_ARRAY
&&
200 entry
.array_type
== DBUS_TYPE_BYTE
) {
201 if (entry
.array_len
<= 0)
204 size
= entry
.array_len
* 2 + 1;
205 value
= os_zalloc(size
);
209 ret
= wpa_snprintf_hex(value
, size
,
210 (u8
*) entry
.bytearray_value
,
214 } else if (entry
.type
== DBUS_TYPE_STRING
) {
215 if (should_quote_opt(entry
.key
)) {
216 size
= os_strlen(entry
.str_value
);
221 value
= os_zalloc(size
);
225 ret
= os_snprintf(value
, size
, "\"%s\"",
227 if (os_snprintf_error(size
, ret
))
230 value
= os_strdup(entry
.str_value
);
234 } else if (entry
.type
== DBUS_TYPE_UINT32
) {
235 value
= os_zalloc(size
);
239 ret
= os_snprintf(value
, size
, "%u",
241 if (os_snprintf_error(size
, ret
))
243 } else if (entry
.type
== DBUS_TYPE_INT32
) {
244 value
= os_zalloc(size
);
248 ret
= os_snprintf(value
, size
, "%d",
250 if (os_snprintf_error(size
, ret
))
255 if (wpa_config_set(ssid
, entry
.key
, value
, 0) < 0)
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
);
262 if (wpa_s
->current_ssid
== ssid
||
263 wpa_s
->current_ssid
== NULL
) {
265 * Invalidate the EAP session cache if anything in the
266 * current or previously used configuration changes.
268 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
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
);
280 wpa_dbus_dict_entry_clear(&entry
);
287 wpa_dbus_dict_entry_clear(&entry
);
288 dbus_set_error_const(error
, DBUS_ERROR_INVALID_ARGS
,
289 "invalid message format");
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
302 * Generic getter for basic type properties. Type is required to be basic.
304 dbus_bool_t
wpas_dbus_simple_property_getter(DBusMessageIter
*iter
,
309 DBusMessageIter variant_iter
;
311 if (!dbus_type_is_basic(type
)) {
312 dbus_set_error(error
, DBUS_ERROR_FAILED
,
313 "%s: given type is not basic", __func__
);
317 if (!dbus_message_iter_open_container(iter
, DBUS_TYPE_VARIANT
,
318 wpa_dbus_type_as_string(type
),
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__
);
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
338 * Generic setter for basic type properties. Type is required to be basic.
340 dbus_bool_t
wpas_dbus_simple_property_setter(DBusMessageIter
*iter
,
342 const int type
, void *val
)
344 DBusMessageIter variant_iter
;
346 if (!dbus_type_is_basic(type
)) {
347 dbus_set_error(error
, DBUS_ERROR_FAILED
,
348 "%s: given type is not basic", __func__
);
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");
359 dbus_message_iter_get_basic(&variant_iter
, val
);
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
374 * Generic getter for array type properties. Array elements type is
375 * required to be basic.
377 dbus_bool_t
wpas_dbus_simple_array_property_getter(DBusMessageIter
*iter
,
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
;
388 if (!dbus_type_is_basic(type
)) {
389 dbus_set_error(error
, DBUS_ERROR_FAILED
,
390 "%s: given type is not basic", __func__
);
394 sub_type_str
= wpa_dbus_type_as_string(type
);
395 type_str
[1] = sub_type_str
[0];
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__
);
408 case DBUS_TYPE_BOOLEAN
:
411 case DBUS_TYPE_INT16
:
412 case DBUS_TYPE_UINT16
:
413 element_size
= sizeof(uint16_t);
415 case DBUS_TYPE_INT32
:
416 case DBUS_TYPE_UINT32
:
417 element_size
= sizeof(uint32_t);
419 case DBUS_TYPE_INT64
:
420 case DBUS_TYPE_UINT64
:
421 element_size
= sizeof(uint64_t);
423 case DBUS_TYPE_DOUBLE
:
424 element_size
= sizeof(double);
426 case DBUS_TYPE_STRING
:
427 case DBUS_TYPE_OBJECT_PATH
:
428 element_size
= sizeof(char *);
431 dbus_set_error(error
, DBUS_ERROR_FAILED
,
432 "%s: unknown element type %d", __func__
, type
);
436 for (i
= 0; i
< array_len
; i
++) {
437 if (!dbus_message_iter_append_basic(&array_iter
, type
,
438 (const char *) array
+
440 dbus_set_error(error
, DBUS_ERROR_FAILED
,
441 "%s: failed to construct message 2.5",
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__
);
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
467 * Generic getter for array type properties. Array elements type is
468 * required to be basic.
470 dbus_bool_t
wpas_dbus_simple_array_array_property_getter(DBusMessageIter
*iter
,
472 struct wpabuf
**array
,
476 DBusMessageIter variant_iter
, array_iter
;
477 char type_str
[] = "aa?";
478 char inner_type_str
[] = "a?";
479 const char *sub_type_str
;
482 if (!dbus_type_is_basic(type
)) {
483 dbus_set_error(error
, DBUS_ERROR_FAILED
,
484 "%s: given type is not basic", __func__
);
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];
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__
);
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
]));
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__
);
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
526 * Handler function for "CreateInterface" method call. Handles requests
527 * by dbus clients to register a network interface that wpa_supplicant
530 DBusMessage
* wpas_dbus_handler_create_interface(DBusMessage
*message
,
531 struct wpa_global
*global
)
533 DBusMessageIter iter_dict
;
534 DBusMessage
*reply
= NULL
;
535 DBusMessageIter iter
;
536 struct wpa_dbus_dict_entry entry
;
539 char *confname
= NULL
;
540 char *bridge_ifname
= NULL
;
542 dbus_message_iter_init(message
, &iter
);
544 if (!wpa_dbus_dict_open_read(&iter
, &iter_dict
, NULL
))
546 while (wpa_dbus_dict_has_dict_entry(&iter_dict
)) {
547 if (!wpa_dbus_dict_get_entry(&iter_dict
, &entry
))
549 if (os_strcmp(entry
.key
, "Driver") == 0 &&
550 entry
.type
== DBUS_TYPE_STRING
) {
552 driver
= os_strdup(entry
.str_value
);
553 wpa_dbus_dict_entry_clear(&entry
);
556 } else if (os_strcmp(entry
.key
, "Ifname") == 0 &&
557 entry
.type
== DBUS_TYPE_STRING
) {
559 ifname
= os_strdup(entry
.str_value
);
560 wpa_dbus_dict_entry_clear(&entry
);
563 } else if (os_strcmp(entry
.key
, "ConfigFile") == 0 &&
564 entry
.type
== DBUS_TYPE_STRING
) {
566 confname
= os_strdup(entry
.str_value
);
567 wpa_dbus_dict_entry_clear(&entry
);
568 if (confname
== NULL
)
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
)
578 wpa_dbus_dict_entry_clear(&entry
);
584 goto error
; /* Required Ifname argument missing */
587 * Try to get the wpa_supplicant record for this iface, return
588 * an error if we already control it.
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.");
595 struct wpa_supplicant
*wpa_s
;
596 struct wpa_interface iface
;
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
;
608 reply
= dbus_message_new_method_return(message
);
609 dbus_message_append_args(reply
, DBUS_TYPE_OBJECT_PATH
,
610 &path
, DBUS_TYPE_INVALID
);
612 reply
= wpas_dbus_error_unknown_error(
614 "wpa_supplicant couldn't grab this interface.");
622 os_free(bridge_ifname
);
626 reply
= wpas_dbus_error_invalid_args(message
, NULL
);
629 reply
= wpas_dbus_error_no_memory(message
);
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
641 * Handler function for "removeInterface" method call. Handles requests
642 * by dbus clients to deregister a network interface that wpa_supplicant
645 DBusMessage
* wpas_dbus_handler_remove_interface(DBusMessage
*message
,
646 struct wpa_global
*global
)
648 struct wpa_supplicant
*wpa_s
;
650 DBusMessage
*reply
= NULL
;
652 dbus_message_get_args(message
, NULL
, DBUS_TYPE_OBJECT_PATH
, &path
,
655 wpa_s
= get_iface_by_dbus_path(global
, path
);
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(
661 "wpa_supplicant couldn't remove this interface.");
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
675 * Handler function for "getInterface" method call.
677 DBusMessage
* wpas_dbus_handler_get_interface(DBusMessage
*message
,
678 struct wpa_global
*global
)
680 DBusMessage
*reply
= NULL
;
683 struct wpa_supplicant
*wpa_s
;
685 dbus_message_get_args(message
, NULL
, DBUS_TYPE_STRING
, &ifname
,
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
);
692 path
= wpa_s
->dbus_new_path
;
693 reply
= dbus_message_new_method_return(message
);
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
);
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
713 * Getter for "DebugLevel" property.
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
)
720 int idx
= wpa_debug_level
;
726 str
= debug_strings
[idx
];
727 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
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
739 * Getter for "DebugTimestamp" property.
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
)
745 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_BOOLEAN
,
746 &wpa_debug_timestamp
, error
);
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
758 * Getter for "DebugShowKeys" property.
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
)
764 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_BOOLEAN
,
765 &wpa_debug_show_keys
, error
);
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
776 * Setter for "DebugLevel" property.
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
)
782 struct wpa_global
*global
= user_data
;
783 const char *str
= NULL
;
786 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_STRING
,
790 for (i
= 0; debug_strings
[i
]; i
++)
791 if (os_strcmp(debug_strings
[i
], str
) == 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");
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
815 * Setter for "DebugTimestamp" property.
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
)
821 struct wpa_global
*global
= user_data
;
824 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_BOOLEAN
,
828 wpa_supplicant_set_debug_params(global
, wpa_debug_level
, val
? 1 : 0,
829 wpa_debug_show_keys
);
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
841 * Setter for "DebugShowKeys" property.
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
)
847 struct wpa_global
*global
= user_data
;
850 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_BOOLEAN
,
854 wpa_supplicant_set_debug_params(global
, wpa_debug_level
,
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
868 * Getter for "Interfaces" property. Handles requests
869 * by dbus clients to return list of registered interfaces objects
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
)
876 struct wpa_global
*global
= user_data
;
877 struct wpa_supplicant
*wpa_s
;
879 unsigned int i
= 0, num
= 0;
882 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
883 if (wpa_s
->dbus_new_path
)
887 paths
= os_calloc(num
, sizeof(char *));
889 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
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
;
898 success
= wpas_dbus_simple_array_property_getter(iter
,
899 DBUS_TYPE_OBJECT_PATH
,
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
914 * Getter for "EapMethods" property. Handles requests
915 * by dbus clients to return list of strings with supported EAP methods
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
)
922 size_t num_items
= 0;
925 eap_methods
= eap_get_names_as_string_array(&num_items
);
927 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
931 success
= wpas_dbus_simple_array_property_getter(iter
,
937 os_free(eap_methods
[--num_items
]);
938 os_free(eap_methods
);
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
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.
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
)
958 const char *capabilities
[5] = { NULL
, NULL
, NULL
, NULL
, NULL
};
959 size_t num_items
= 0;
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 */
968 capabilities
[num_items
++] = "p2p";
969 #endif /* CONFIG_P2P */
970 #ifdef CONFIG_INTERWORKING
971 capabilities
[num_items
++] = "interworking";
972 #endif /* CONFIG_INTERWORKING */
974 return wpas_dbus_simple_array_property_getter(iter
,
981 static int wpas_dbus_get_scan_type(DBusMessage
*message
, DBusMessageIter
*var
,
982 char **type
, DBusMessage
**reply
)
984 if (dbus_message_iter_get_arg_type(var
) != DBUS_TYPE_STRING
) {
985 wpa_printf(MSG_DEBUG
, "%s[dbus]: Type must be a string",
987 *reply
= wpas_dbus_error_invalid_args(
988 message
, "Wrong Type value type. String required");
991 dbus_message_iter_get_basic(var
, type
);
996 static int wpas_dbus_get_scan_ssids(DBusMessage
*message
, DBusMessageIter
*var
,
997 struct wpa_driver_scan_params
*params
,
1000 struct wpa_driver_scan_ssid
*ssids
= params
->ssids
;
1001 size_t ssids_num
= 0;
1003 DBusMessageIter array_iter
, sub_array_iter
;
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",
1011 *reply
= wpas_dbus_error_invalid_args(
1013 "Wrong SSIDs value type. Array of arrays of bytes required");
1017 dbus_message_iter_recurse(var
, &array_iter
);
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",
1024 *reply
= wpas_dbus_error_invalid_args(
1026 "Wrong SSIDs value type. Array of arrays of bytes required");
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",
1035 *reply
= wpas_dbus_error_invalid_args(
1037 "Too many ssids specified. Specify at most four");
1041 dbus_message_iter_recurse(&array_iter
, &sub_array_iter
);
1043 dbus_message_iter_get_fixed_array(&sub_array_iter
, &val
, &len
);
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");
1055 ssid
= os_malloc(len
);
1057 *reply
= wpas_dbus_error_no_memory(message
);
1060 os_memcpy(ssid
, val
, len
);
1062 /* Allow zero-length SSIDs */
1066 ssids
[ssids_num
].ssid
= ssid
;
1067 ssids
[ssids_num
].ssid_len
= len
;
1069 dbus_message_iter_next(&array_iter
);
1073 params
->num_ssids
= ssids_num
;
1078 static int wpas_dbus_get_scan_ies(DBusMessage
*message
, DBusMessageIter
*var
,
1079 struct wpa_driver_scan_params
*params
,
1080 DBusMessage
**reply
)
1082 u8
*ies
= NULL
, *nies
;
1084 DBusMessageIter array_iter
, sub_array_iter
;
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",
1092 *reply
= wpas_dbus_error_invalid_args(
1094 "Wrong IEs value type. Array of arrays of bytes required");
1098 dbus_message_iter_recurse(var
, &array_iter
);
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",
1105 *reply
= wpas_dbus_error_invalid_args(
1106 message
, "Wrong IEs value type. Array required");
1110 while (dbus_message_iter_get_arg_type(&array_iter
) == DBUS_TYPE_ARRAY
) {
1111 dbus_message_iter_recurse(&array_iter
, &sub_array_iter
);
1113 dbus_message_iter_get_fixed_array(&sub_array_iter
, &val
, &len
);
1115 dbus_message_iter_next(&array_iter
);
1119 nies
= os_realloc(ies
, ies_len
+ len
);
1122 *reply
= wpas_dbus_error_no_memory(message
);
1126 os_memcpy(ies
+ ies_len
, val
, len
);
1129 dbus_message_iter_next(&array_iter
);
1132 params
->extra_ies
= ies
;
1133 params
->extra_ies_len
= ies_len
;
1138 static int wpas_dbus_get_scan_channels(DBusMessage
*message
,
1139 DBusMessageIter
*var
,
1140 struct wpa_driver_scan_params
*params
,
1141 DBusMessage
**reply
)
1143 DBusMessageIter array_iter
, sub_array_iter
;
1144 int *freqs
= NULL
, *nfreqs
;
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",
1151 *reply
= wpas_dbus_error_invalid_args(
1153 "Wrong Channels value type. Array of structs required");
1157 dbus_message_iter_recurse(var
, &array_iter
);
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",
1163 *reply
= wpas_dbus_error_invalid_args(
1165 "Wrong Channels value type. Array of structs required");
1169 while (dbus_message_iter_get_arg_type(&array_iter
) == DBUS_TYPE_STRUCT
)
1173 dbus_message_iter_recurse(&array_iter
, &sub_array_iter
);
1175 if (dbus_message_iter_get_arg_type(&sub_array_iter
) !=
1177 wpa_printf(MSG_DEBUG
,
1178 "%s[dbus]: Channel must by specified by struct of two UINT32s %c",
1180 dbus_message_iter_get_arg_type(
1182 *reply
= wpas_dbus_error_invalid_args(
1184 "Wrong Channel struct. Two UINT32s required");
1188 dbus_message_iter_get_basic(&sub_array_iter
, &freq
);
1190 if (!dbus_message_iter_next(&sub_array_iter
) ||
1191 dbus_message_iter_get_arg_type(&sub_array_iter
) !=
1193 wpa_printf(MSG_DEBUG
,
1194 "%s[dbus]: Channel must by specified by struct of two UINT32s",
1196 *reply
= wpas_dbus_error_invalid_args(
1198 "Wrong Channel struct. Two UINT32s required");
1203 dbus_message_iter_get_basic(&sub_array_iter
, &width
);
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
,
1214 if (freqs
== NULL
) {
1215 *reply
= wpas_dbus_error_no_memory(message
);
1219 freqs
[freqs_num
] = freq
;
1222 dbus_message_iter_next(&array_iter
);
1225 nfreqs
= os_realloc_array(freqs
, freqs_num
+ 1, sizeof(int));
1229 if (freqs
== NULL
) {
1230 *reply
= wpas_dbus_error_no_memory(message
);
1233 freqs
[freqs_num
] = 0;
1235 params
->freqs
= freqs
;
1240 static int wpas_dbus_get_scan_allow_roam(DBusMessage
*message
,
1241 DBusMessageIter
*var
,
1243 DBusMessage
**reply
)
1245 if (dbus_message_iter_get_arg_type(var
) != DBUS_TYPE_BOOLEAN
) {
1246 wpa_printf(MSG_DEBUG
, "%s[dbus]: Type must be a boolean",
1248 *reply
= wpas_dbus_error_invalid_args(
1249 message
, "Wrong Type value type. Boolean required");
1252 dbus_message_iter_get_basic(var
, allow
);
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
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.
1267 DBusMessage
* wpas_dbus_handler_scan(DBusMessage
*message
,
1268 struct wpa_supplicant
*wpa_s
)
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
;
1275 dbus_bool_t allow_roam
= 1;
1277 os_memset(¶ms
, 0, sizeof(params
));
1279 dbus_message_iter_init(message
, &iter
);
1281 dbus_message_iter_recurse(&iter
, &dict_iter
);
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
);
1290 if (os_strcmp(key
, "Type") == 0) {
1291 if (wpas_dbus_get_scan_type(message
, &variant_iter
,
1294 } else if (os_strcmp(key
, "SSIDs") == 0) {
1295 if (wpas_dbus_get_scan_ssids(message
, &variant_iter
,
1296 ¶ms
, &reply
) < 0)
1298 } else if (os_strcmp(key
, "IEs") == 0) {
1299 if (wpas_dbus_get_scan_ies(message
, &variant_iter
,
1300 ¶ms
, &reply
) < 0)
1302 } else if (os_strcmp(key
, "Channels") == 0) {
1303 if (wpas_dbus_get_scan_channels(message
, &variant_iter
,
1304 ¶ms
, &reply
) < 0)
1306 } else if (os_strcmp(key
, "AllowRoam") == 0) {
1307 if (wpas_dbus_get_scan_allow_roam(message
,
1313 wpa_printf(MSG_DEBUG
, "%s[dbus]: Unknown argument %s",
1315 reply
= wpas_dbus_error_invalid_args(message
, key
);
1319 dbus_message_iter_next(&dict_iter
);
1323 wpa_printf(MSG_DEBUG
, "%s[dbus]: Scan type not specified",
1325 reply
= wpas_dbus_error_invalid_args(message
, key
);
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.",
1334 reply
= wpas_dbus_error_invalid_args(
1336 "You can specify only Channels in passive scan");
1339 if (wpa_s
->sched_scanning
) {
1340 wpa_printf(MSG_DEBUG
,
1341 "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed",
1343 wpa_supplicant_cancel_sched_scan(wpa_s
);
1346 if (params
.freqs
&& params
.freqs
[0]) {
1347 wpa_s
->last_scan_req
= MANUAL_SCAN_REQ
;
1348 if (wpa_supplicant_trigger_scan(wpa_s
,
1350 reply
= wpas_dbus_error_scan_error(
1352 "Scan request rejected");
1355 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
1356 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1359 } else if (os_strcmp(type
, "active") == 0) {
1360 if (!params
.num_ssids
) {
1361 /* Add wildcard ssid */
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",
1371 wpa_supplicant_cancel_sched_scan(wpa_s
);
1374 wpa_s
->last_scan_req
= MANUAL_SCAN_REQ
;
1375 if (wpa_supplicant_trigger_scan(wpa_s
, ¶ms
)) {
1376 reply
= wpas_dbus_error_scan_error(
1377 message
, "Scan request rejected");
1380 wpa_printf(MSG_DEBUG
, "%s[dbus]: Unknown scan type: %s",
1382 reply
= wpas_dbus_error_invalid_args(message
,
1388 wpa_s
->scan_res_handler
= scan_only_handler
;
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
);
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
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.
1409 DBusMessage
* wpas_dbus_handler_signal_poll(DBusMessage
*message
,
1410 struct wpa_supplicant
*wpa_s
)
1412 struct wpa_signal_info si
;
1413 DBusMessage
*reply
= NULL
;
1414 DBusMessageIter iter
, iter_dict
, variant_iter
;
1417 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
1419 return dbus_message_new_error(message
, DBUS_ERROR_FAILED
,
1420 "Failed to read signal");
1423 reply
= dbus_message_new_method_return(message
);
1427 dbus_message_iter_init_append(reply
, &iter
);
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",
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",
1447 !wpa_dbus_dict_append_int32(&iter_dict
, "center-frq2",
1448 si
.center_frq2
))) ||
1450 !wpa_dbus_dict_append_int32(&iter_dict
, "avg-rssi",
1452 !wpa_dbus_dict_close_write(&variant_iter
, &iter_dict
) ||
1453 !dbus_message_iter_close_container(&iter
, &variant_iter
))
1460 dbus_message_unref(reply
);
1461 return wpas_dbus_error_no_memory(message
);
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.
1472 * Handler function for "Disconnect" method call of network interface.
1474 DBusMessage
* wpas_dbus_handler_disconnect(DBusMessage
*message
,
1475 struct wpa_supplicant
*wpa_s
)
1477 if (wpa_s
->current_ssid
!= NULL
) {
1478 wpa_s
->disconnected
= 1;
1479 wpa_supplicant_deauthenticate(wpa_s
,
1480 WLAN_REASON_DEAUTH_LEAVING
);
1485 return dbus_message_new_error(message
, WPAS_DBUS_ERROR_NOT_CONNECTED
,
1486 "This interface is not connected");
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
1496 * Handler function for "AddNetwork" method call of a network interface.
1498 DBusMessage
* wpas_dbus_handler_add_network(DBusMessage
*message
,
1499 struct wpa_supplicant
*wpa_s
)
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
;
1507 dbus_message_iter_init(message
, &iter
);
1509 if (wpa_s
->dbus_new_path
)
1510 ssid
= wpa_config_add_network(wpa_s
->conf
);
1512 wpa_printf(MSG_ERROR
, "%s[dbus]: can't add new interface.",
1514 reply
= wpas_dbus_error_unknown_error(
1516 "wpa_supplicant could not add a network on this interface.");
1519 wpas_notify_network_added(wpa_s
, ssid
);
1521 wpa_config_set_network_defaults(ssid
);
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",
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
);
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
);
1540 reply
= dbus_message_new_method_return(message
);
1541 if (reply
== NULL
) {
1542 reply
= wpas_dbus_error_no_memory(message
);
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
);
1556 wpas_notify_network_removed(wpa_s
, ssid
);
1557 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
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.
1570 * Handler function for "Reassociate" method call of network interface.
1572 DBusMessage
* wpas_dbus_handler_reassociate(DBusMessage
*message
,
1573 struct wpa_supplicant
*wpa_s
)
1575 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
) {
1576 wpas_request_connection(wpa_s
);
1580 return dbus_message_new_error(message
, WPAS_DBUS_ERROR_IFACE_DISABLED
,
1581 "This interface is disabled");
1586 * wpas_dbus_handler_expect_disconnect - ExpectDisconnect
1587 * @message: Pointer to incoming dbus message
1588 * @global: %wpa_supplicant global data structure
1591 * Handler function for notifying system there will be a expected disconnect.
1592 * This will prevent wpa_supplicant from adding blacklists upon next disconnect..
1594 DBusMessage
* wpas_dbus_handler_expect_disconnect(DBusMessage
*message
,
1595 struct wpa_global
*global
)
1597 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
1599 for (; wpa_s
; wpa_s
= wpa_s
->next
)
1600 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
)
1601 wpa_s
->own_disconnect_req
= 1;
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.
1613 * Handler function for "Reattach" method call of network interface.
1615 DBusMessage
* wpas_dbus_handler_reattach(DBusMessage
*message
,
1616 struct wpa_supplicant
*wpa_s
)
1618 if (wpa_s
->current_ssid
!= NULL
) {
1619 wpa_s
->reattach
= 1;
1620 wpas_request_connection(wpa_s
);
1624 return dbus_message_new_error(message
, WPAS_DBUS_ERROR_NOT_CONNECTED
,
1625 "This interface is not connected");
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.
1636 * Handler function for "Reconnect" method call of network interface.
1638 DBusMessage
* wpas_dbus_handler_reconnect(DBusMessage
*message
,
1639 struct wpa_supplicant
*wpa_s
)
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");
1647 if (wpa_s
->disconnected
)
1648 wpas_request_connection(wpa_s
);
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
1659 * Handler function for "RemoveNetwork" method call of a network interface.
1661 DBusMessage
* wpas_dbus_handler_remove_network(DBusMessage
*message
,
1662 struct wpa_supplicant
*wpa_s
)
1664 DBusMessage
*reply
= NULL
;
1666 char *iface
, *net_id
;
1668 struct wpa_ssid
*ssid
;
1671 dbus_message_get_args(message
, NULL
, DBUS_TYPE_OBJECT_PATH
, &op
,
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
,
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
);
1686 id
= strtoul(net_id
, NULL
, 10);
1688 reply
= wpas_dbus_error_invalid_args(message
, op
);
1692 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1694 reply
= wpas_dbus_error_network_unknown(message
);
1698 was_disabled
= ssid
->disabled
;
1700 wpas_notify_network_removed(wpa_s
, ssid
);
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);
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",
1716 reply
= wpas_dbus_error_unknown_error(
1718 "error removing the specified network on is interface.");
1728 static void remove_network(void *arg
, struct wpa_ssid
*ssid
)
1730 struct wpa_supplicant
*wpa_s
= arg
;
1732 wpas_notify_network_removed(wpa_s
, ssid
);
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
);
1741 if (ssid
== wpa_s
->current_ssid
)
1742 wpa_supplicant_deauthenticate(wpa_s
,
1743 WLAN_REASON_DEAUTH_LEAVING
);
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
1753 * Handler function for "RemoveAllNetworks" method call of a network interface.
1755 DBusMessage
* wpas_dbus_handler_remove_all_networks(
1756 DBusMessage
*message
, struct wpa_supplicant
*wpa_s
)
1758 if (wpa_s
->sched_scanning
)
1759 wpa_supplicant_cancel_sched_scan(wpa_s
);
1761 /* NB: could check for failure and return an error */
1762 wpa_config_foreach_network(wpa_s
->conf
, remove_network
, wpa_s
);
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
1773 * Handler function for "SelectNetwork" method call of network interface.
1775 DBusMessage
* wpas_dbus_handler_select_network(DBusMessage
*message
,
1776 struct wpa_supplicant
*wpa_s
)
1778 DBusMessage
*reply
= NULL
;
1780 char *iface
, *net_id
;
1782 struct wpa_ssid
*ssid
;
1784 dbus_message_get_args(message
, NULL
, DBUS_TYPE_OBJECT_PATH
, &op
,
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
,
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
);
1799 id
= strtoul(net_id
, NULL
, 10);
1801 reply
= wpas_dbus_error_invalid_args(message
, op
);
1805 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1807 reply
= wpas_dbus_error_network_unknown(message
);
1811 /* Finally, associate with the network */
1812 wpa_supplicant_select_network(wpa_s
, ssid
);
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
1826 * Handler function for "NetworkReply" method call of network interface.
1828 DBusMessage
* wpas_dbus_handler_network_reply(DBusMessage
*message
,
1829 struct wpa_supplicant
*wpa_s
)
1831 #ifdef IEEE8021X_EAPOL
1832 DBusMessage
*reply
= NULL
;
1833 const char *op
, *field
, *value
;
1834 char *iface
, *net_id
;
1836 struct wpa_ssid
*ssid
;
1838 if (!dbus_message_get_args(message
, NULL
,
1839 DBUS_TYPE_OBJECT_PATH
, &op
,
1840 DBUS_TYPE_STRING
, &field
,
1841 DBUS_TYPE_STRING
, &value
,
1843 return wpas_dbus_error_invalid_args(message
, NULL
);
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
,
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
);
1857 id
= strtoul(net_id
, NULL
, 10);
1859 reply
= wpas_dbus_error_invalid_args(message
, net_id
);
1863 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1865 reply
= wpas_dbus_error_network_unknown(message
);
1869 if (wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
,
1871 reply
= wpas_dbus_error_invalid_args(message
, field
);
1873 /* Tell EAP to retry immediately */
1874 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
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 */
1887 #ifndef CONFIG_NO_CONFIG_BLOBS
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
1895 * Asks wpa_supplicant to internally store a binary blobs.
1897 DBusMessage
* wpas_dbus_handler_add_blob(DBusMessage
*message
,
1898 struct wpa_supplicant
*wpa_s
)
1900 DBusMessage
*reply
= NULL
;
1901 DBusMessageIter iter
, array_iter
;
1906 struct wpa_config_blob
*blob
= NULL
;
1908 dbus_message_iter_init(message
, &iter
);
1909 dbus_message_iter_get_basic(&iter
, &blob_name
);
1911 if (wpa_config_get_blob(wpa_s
->conf
, blob_name
)) {
1912 return dbus_message_new_error(message
,
1913 WPAS_DBUS_ERROR_BLOB_EXISTS
,
1917 dbus_message_iter_next(&iter
);
1918 dbus_message_iter_recurse(&iter
, &array_iter
);
1920 dbus_message_iter_get_fixed_array(&array_iter
, &blob_data
, &blob_len
);
1922 blob
= os_zalloc(sizeof(*blob
));
1924 reply
= wpas_dbus_error_no_memory(message
);
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
);
1934 os_memcpy(blob
->data
, blob_data
, blob_len
);
1935 blob
->len
= blob_len
;
1937 wpa_config_set_blob(wpa_s
->conf
, blob
);
1938 wpas_notify_blob_added(wpa_s
, blob
->name
);
1944 os_free(blob
->name
);
1945 os_free(blob
->data
);
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)
1958 * Gets one wpa_supplicant's binary blobs.
1960 DBusMessage
* wpas_dbus_handler_get_blob(DBusMessage
*message
,
1961 struct wpa_supplicant
*wpa_s
)
1963 DBusMessage
*reply
= NULL
;
1964 DBusMessageIter iter
, array_iter
;
1967 const struct wpa_config_blob
*blob
;
1969 dbus_message_get_args(message
, NULL
, DBUS_TYPE_STRING
, &blob_name
,
1972 blob
= wpa_config_get_blob(wpa_s
->conf
, blob_name
);
1974 return dbus_message_new_error(message
,
1975 WPAS_DBUS_ERROR_BLOB_UNKNOWN
,
1979 reply
= dbus_message_new_method_return(message
);
1981 return wpas_dbus_error_no_memory(message
);
1983 dbus_message_iter_init_append(reply
, &iter
);
1985 if (!dbus_message_iter_open_container(&iter
, DBUS_TYPE_ARRAY
,
1986 DBUS_TYPE_BYTE_AS_STRING
,
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
);
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
2005 * Asks wpa_supplicant to internally remove a binary blobs.
2007 DBusMessage
* wpas_dbus_handler_remove_blob(DBusMessage
*message
,
2008 struct wpa_supplicant
*wpa_s
)
2010 DBusMessage
*reply
= NULL
;
2013 dbus_message_get_args(message
, NULL
, DBUS_TYPE_STRING
, &blob_name
,
2016 if (wpa_config_remove_blob(wpa_s
->conf
, blob_name
)) {
2017 return dbus_message_new_error(message
,
2018 WPAS_DBUS_ERROR_BLOB_UNKNOWN
,
2021 wpas_notify_blob_removed(wpa_s
, blob_name
);
2027 #endif /* CONFIG_NO_CONFIG_BLOBS */
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
2036 * Handler function for "FlushBSS" method call of network interface.
2038 DBusMessage
* wpas_dbus_handler_flush_bss(DBusMessage
*message
,
2039 struct wpa_supplicant
*wpa_s
)
2043 dbus_message_get_args(message
, NULL
, DBUS_TYPE_UINT32
, &age
,
2047 wpa_bss_flush(wpa_s
);
2049 wpa_bss_flush_by_age(wpa_s
, age
);
2055 #ifdef CONFIG_AUTOSCAN
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
2062 * Handler function for "AutoScan" method call of network interface.
2064 DBusMessage
* wpas_dbus_handler_autoscan(DBusMessage
*message
,
2065 struct wpa_supplicant
*wpa_s
)
2067 DBusMessage
*reply
= NULL
;
2068 enum wpa_states state
= wpa_s
->wpa_state
;
2071 dbus_message_get_args(message
, NULL
, DBUS_TYPE_STRING
, &arg
,
2074 if (arg
!= NULL
&& os_strlen(arg
) > 0) {
2077 tmp
= os_strdup(arg
);
2079 reply
= wpas_dbus_error_no_memory(message
);
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
);
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
);
2093 reply
= dbus_message_new_error(message
,
2094 DBUS_ERROR_INVALID_ARGS
,
2099 #endif /* CONFIG_AUTOSCAN */
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
2108 * Handler function for "EAPLogoff" method call of network interface.
2110 DBusMessage
* wpas_dbus_handler_eap_logoff(DBusMessage
*message
,
2111 struct wpa_supplicant
*wpa_s
)
2113 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
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
2124 * Handler function for "EAPLogin" method call of network interface.
2126 DBusMessage
* wpas_dbus_handler_eap_logon(DBusMessage
*message
,
2127 struct wpa_supplicant
*wpa_s
)
2129 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
2136 static int get_peer_hwaddr_helper(DBusMessage
*message
, const char *func_name
,
2137 u8
*peer_address
, DBusMessage
**error
)
2139 const char *peer_string
;
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
);
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");
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
2168 * Handler function for "TDLSDiscover" method call of network interface.
2170 DBusMessage
* wpas_dbus_handler_tdls_discover(DBusMessage
*message
,
2171 struct wpa_supplicant
*wpa_s
)
2174 DBusMessage
*error_reply
;
2177 if (get_peer_hwaddr_helper(message
, __func__
, peer
, &error_reply
) < 0)
2180 wpa_printf(MSG_DEBUG
, "DBUS TDLS_DISCOVER " MACSTR
, MAC2STR(peer
));
2182 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2183 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
2185 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
2188 return wpas_dbus_error_unknown_error(
2189 message
, "error performing TDLS discovery");
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
2202 * Handler function for "TDLSSetup" method call of network interface.
2204 DBusMessage
* wpas_dbus_handler_tdls_setup(DBusMessage
*message
,
2205 struct wpa_supplicant
*wpa_s
)
2208 DBusMessage
*error_reply
;
2211 if (get_peer_hwaddr_helper(message
, __func__
, peer
, &error_reply
) < 0)
2214 wpa_printf(MSG_DEBUG
, "DBUS TDLS_SETUP " MACSTR
, MAC2STR(peer
));
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
);
2220 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
2223 return wpas_dbus_error_unknown_error(
2224 message
, "error performing TDLS setup");
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
2237 * Handler function for "TDLSStatus" method call of network interface.
2239 DBusMessage
* wpas_dbus_handler_tdls_status(DBusMessage
*message
,
2240 struct wpa_supplicant
*wpa_s
)
2244 const char *tdls_status
;
2246 if (get_peer_hwaddr_helper(message
, __func__
, peer
, &reply
) < 0)
2249 wpa_printf(MSG_DEBUG
, "DBUS TDLS_STATUS " MACSTR
, MAC2STR(peer
));
2251 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
2253 reply
= dbus_message_new_method_return(message
);
2254 dbus_message_append_args(reply
, DBUS_TYPE_STRING
,
2255 &tdls_status
, DBUS_TYPE_INVALID
);
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
2266 * Handler function for "TDLSTeardown" method call of network interface.
2268 DBusMessage
* wpas_dbus_handler_tdls_teardown(DBusMessage
*message
,
2269 struct wpa_supplicant
*wpa_s
)
2272 DBusMessage
*error_reply
;
2275 if (get_peer_hwaddr_helper(message
, __func__
, peer
, &error_reply
) < 0)
2278 wpa_printf(MSG_DEBUG
, "DBUS TDLS_TEARDOWN " MACSTR
, MAC2STR(peer
));
2280 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2281 ret
= wpa_tdls_teardown_link(
2283 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
2285 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
2288 return wpas_dbus_error_unknown_error(
2289 message
, "error performing TDLS teardown");
2295 #endif /* CONFIG_TDLS */
2298 #ifndef CONFIG_NO_CONFIG_WRITE
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
2305 * Handler function for "SaveConfig" method call of network interface.
2307 DBusMessage
* wpas_dbus_handler_save_config(DBusMessage
*message
,
2308 struct wpa_supplicant
*wpa_s
)
2312 if (!wpa_s
->conf
->update_config
) {
2313 return wpas_dbus_error_unknown_error(
2315 "Not allowed to update configuration (update_config=0)");
2318 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
2320 return wpas_dbus_error_unknown_error(
2321 message
, "Failed to update configuration");
2324 #endif /* CONFIG_NO_CONFIG_WRITE */
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
2333 * Sets the PKCS #11 engine and module path.
2335 DBusMessage
* wpas_dbus_handler_set_pkcs11_engine_and_module_path(
2336 DBusMessage
*message
, struct wpa_supplicant
*wpa_s
)
2338 DBusMessageIter iter
;
2340 char *pkcs11_engine_path
= NULL
;
2341 char *pkcs11_module_path
= NULL
;
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");
2350 /* Empty path defaults to NULL */
2351 if (os_strlen(value
))
2352 pkcs11_engine_path
= value
;
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");
2362 /* Empty path defaults to NULL */
2363 if (os_strlen(value
))
2364 pkcs11_module_path
= value
;
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.");
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");
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
2392 * Getter for "Capabilities" property of an interface.
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
)
2398 struct wpa_supplicant
*wpa_s
= user_data
;
2399 struct wpa_driver_capa capa
;
2401 DBusMessageIter iter_dict
, iter_dict_entry
, iter_dict_val
, iter_array
,
2403 const char *scans
[] = { "active", "passive", "ssid" };
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
))
2410 res
= wpa_drv_get_capa(wpa_s
, &capa
);
2412 /***** pairwise cipher */
2414 const char *args
[] = {"ccmp", "tkip", "none"};
2416 if (!wpa_dbus_dict_append_string_array(
2417 &iter_dict
, "Pairwise", args
,
2421 if (!wpa_dbus_dict_begin_string_array(&iter_dict
, "Pairwise",
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
,
2450 /***** group cipher */
2452 const char *args
[] = {
2453 "ccmp", "tkip", "wep104", "wep40"
2456 if (!wpa_dbus_dict_append_string_array(
2457 &iter_dict
, "Group", args
,
2461 if (!wpa_dbus_dict_begin_string_array(&iter_dict
, "Group",
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
,
2493 /***** key management */
2495 const char *args
[] = {
2496 "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
2499 #endif /* CONFIG_WPS */
2502 if (!wpa_dbus_dict_append_string_array(
2503 &iter_dict
, "KeyMgmt", args
,
2507 if (!wpa_dbus_dict_begin_string_array(&iter_dict
, "KeyMgmt",
2511 !wpa_dbus_dict_string_array_add_element(&iter_array
,
2513 !wpa_dbus_dict_string_array_add_element(&iter_array
,
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")))
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"))
2531 #endif /* CONFIG_IEEE80211W */
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") ||
2539 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
) &&
2540 !wpa_dbus_dict_string_array_add_element(
2541 &iter_array
, "wpa-ft-psk")))
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"))
2549 #endif /* CONFIG_IEEE80211W */
2552 if ((capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) &&
2553 !wpa_dbus_dict_string_array_add_element(&iter_array
,
2559 if (!wpa_dbus_dict_string_array_add_element(&iter_array
,
2562 #endif /* CONFIG_WPS */
2564 if (!wpa_dbus_dict_end_string_array(&iter_dict
,
2571 /***** WPA protocol */
2573 const char *args
[] = { "rsn", "wpa" };
2575 if (!wpa_dbus_dict_append_string_array(
2576 &iter_dict
, "Protocol", args
,
2580 if (!wpa_dbus_dict_begin_string_array(&iter_dict
, "Protocol",
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
,
2601 const char *args
[] = { "open", "shared", "leap" };
2603 if (!wpa_dbus_dict_append_string_array(
2604 &iter_dict
, "AuthAlg", args
,
2608 if (!wpa_dbus_dict_begin_string_array(&iter_dict
, "AuthAlg",
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
,
2631 if (!wpa_dbus_dict_append_string_array(&iter_dict
, "Scan", scans
,
2636 if (!wpa_dbus_dict_begin_string_array(&iter_dict
, "Modes",
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
,
2658 dbus_int32_t max_scan_ssid
= capa
.max_scan_ssids
;
2660 if (!wpa_dbus_dict_append_int32(&iter_dict
, "MaxScanSSID",
2665 if (!wpa_dbus_dict_close_write(&variant_iter
, &iter_dict
) ||
2666 !dbus_message_iter_close_container(iter
, &variant_iter
))
2672 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
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
2684 * Getter for "State" property.
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
)
2690 struct wpa_supplicant
*wpa_s
= user_data
;
2691 const char *str_state
;
2692 char *state_ls
, *tmp
;
2693 dbus_bool_t success
= FALSE
;
2695 str_state
= wpa_supplicant_state_txt(wpa_s
->wpa_state
);
2697 /* make state string lowercase to fit new DBus API convention
2699 state_ls
= tmp
= os_strdup(str_state
);
2701 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
2705 *tmp
= tolower(*tmp
);
2709 success
= wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
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
2725 * Getter for "scanning" property.
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
)
2731 struct wpa_supplicant
*wpa_s
= user_data
;
2732 dbus_bool_t scanning
= wpa_s
->scanning
? TRUE
: FALSE
;
2734 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_BOOLEAN
,
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
2746 * Getter function for "ApScan" property.
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
)
2752 struct wpa_supplicant
*wpa_s
= user_data
;
2753 dbus_uint32_t ap_scan
= wpa_s
->conf
->ap_scan
;
2755 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_UINT32
,
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
2767 * Setter function for "ApScan" property.
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
)
2773 struct wpa_supplicant
*wpa_s
= user_data
;
2774 dbus_uint32_t ap_scan
;
2776 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_UINT32
,
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");
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
2797 * Getter function for "FastReauth" property.
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
)
2803 struct wpa_supplicant
*wpa_s
= user_data
;
2804 dbus_bool_t fast_reauth
= wpa_s
->conf
->fast_reauth
? TRUE
: FALSE
;
2806 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_BOOLEAN
,
2807 &fast_reauth
, error
);
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
2819 * Setter function for "FastReauth" property.
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
)
2825 struct wpa_supplicant
*wpa_s
= user_data
;
2826 dbus_bool_t fast_reauth
;
2828 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_BOOLEAN
,
2832 wpa_s
->conf
->fast_reauth
= fast_reauth
;
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
2844 * Getter for "DisconnectReason" property. The reason is negative if it is
2845 * locally generated.
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
)
2851 struct wpa_supplicant
*wpa_s
= user_data
;
2852 dbus_int32_t reason
= wpa_s
->disconnect_reason
;
2854 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_INT32
,
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
2866 * Getter function for "BSSExpireAge" property.
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
)
2872 struct wpa_supplicant
*wpa_s
= user_data
;
2873 dbus_uint32_t expire_age
= wpa_s
->conf
->bss_expiration_age
;
2875 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_UINT32
,
2876 &expire_age
, error
);
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
2887 * Setter function for "BSSExpireAge" property.
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
)
2893 struct wpa_supplicant
*wpa_s
= user_data
;
2894 dbus_uint32_t expire_age
;
2896 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_UINT32
,
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");
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
2916 * Getter function for "BSSExpireCount" property.
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
)
2922 struct wpa_supplicant
*wpa_s
= user_data
;
2923 dbus_uint32_t expire_count
= wpa_s
->conf
->bss_expiration_scan_count
;
2925 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_UINT32
,
2926 &expire_count
, error
);
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
2937 * Setter function for "BSSExpireCount" property.
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
)
2943 struct wpa_supplicant
*wpa_s
= user_data
;
2944 dbus_uint32_t expire_count
;
2946 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_UINT32
,
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");
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
2966 * Getter function for "Country" property.
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
)
2972 struct wpa_supplicant
*wpa_s
= user_data
;
2974 char *str
= country
;
2976 country
[0] = wpa_s
->conf
->country
[0];
2977 country
[1] = wpa_s
->conf
->country
[1];
2980 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
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
2992 * Setter function for "Country" property.
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
)
2998 struct wpa_supplicant
*wpa_s
= user_data
;
2999 const char *country
;
3001 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_STRING
,
3005 if (!country
[0] || !country
[1]) {
3006 dbus_set_error_const(error
, DBUS_ERROR_FAILED
,
3007 "invalid country code");
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");
3018 wpa_s
->conf
->country
[0] = country
[0];
3019 wpa_s
->conf
->country
[1] = country
[1];
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
3031 * Getter function for "ScanInterval" property.
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
)
3037 struct wpa_supplicant
*wpa_s
= user_data
;
3038 dbus_int32_t scan_interval
= wpa_s
->scan_interval
;
3040 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_INT32
,
3041 &scan_interval
, error
);
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
3052 * Setter function for "ScanInterval" property.
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
)
3058 struct wpa_supplicant
*wpa_s
= user_data
;
3059 dbus_int32_t scan_interval
;
3061 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_INT32
,
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");
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
3081 * Getter for "Ifname" property.
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
)
3087 struct wpa_supplicant
*wpa_s
= user_data
;
3088 const char *ifname
= wpa_s
->ifname
;
3090 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
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
3102 * Getter for "Driver" property.
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
)
3108 struct wpa_supplicant
*wpa_s
= user_data
;
3111 if (wpa_s
->driver
== NULL
|| wpa_s
->driver
->name
== NULL
) {
3112 wpa_printf(MSG_DEBUG
, "%s[dbus]: wpa_s has no driver set",
3114 dbus_set_error(error
, DBUS_ERROR_FAILED
, "%s: no driver set",
3119 driver
= wpa_s
->driver
->name
;
3120 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
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
3132 * Getter for "CurrentBSS" property.
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
)
3138 struct wpa_supplicant
*wpa_s
= user_data
;
3139 char path_buf
[WPAS_DBUS_OBJECT_PATH_MAX
], *bss_obj_path
= path_buf
;
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
);
3146 os_snprintf(bss_obj_path
, WPAS_DBUS_OBJECT_PATH_MAX
, "/");
3148 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_OBJECT_PATH
,
3149 &bss_obj_path
, error
);
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
3160 * Getter for "CurrentNetwork" property.
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
)
3166 struct wpa_supplicant
*wpa_s
= user_data
;
3167 char path_buf
[WPAS_DBUS_OBJECT_PATH_MAX
], *net_obj_path
= path_buf
;
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
);
3174 os_snprintf(net_obj_path
, WPAS_DBUS_OBJECT_PATH_MAX
, "/");
3176 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_OBJECT_PATH
,
3177 &net_obj_path
, error
);
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
3188 * Getter for "CurrentAuthMode" property.
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
)
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
];
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
;
3209 auth_mode
= wpa_key_mgmt_txt(wpa_s
->key_mgmt
,
3210 wpa_s
->current_ssid
->proto
);
3213 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
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
3225 * Getter for "BridgeIfname" property.
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
)
3231 struct wpa_supplicant
*wpa_s
= user_data
;
3232 const char *bridge_ifname
= wpa_s
->bridge_ifname
;
3234 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
3235 &bridge_ifname
, error
);
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
3246 * Getter for "BSSs" property.
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
)
3252 struct wpa_supplicant
*wpa_s
= user_data
;
3253 struct wpa_bss
*bss
;
3256 dbus_bool_t success
= FALSE
;
3258 if (!wpa_s
->dbus_new_path
) {
3259 dbus_set_error(error
, DBUS_ERROR_FAILED
,
3260 "%s: no D-Bus interface", __func__
);
3264 paths
= os_calloc(wpa_s
->num_bss
, sizeof(char *));
3266 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
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
,
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
);
3284 success
= wpas_dbus_simple_array_property_getter(iter
,
3285 DBUS_TYPE_OBJECT_PATH
,
3286 paths
, wpa_s
->num_bss
,
3291 os_free(paths
[--i
]);
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
3304 * Getter for "Networks" property.
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
)
3310 struct wpa_supplicant
*wpa_s
= user_data
;
3311 struct wpa_ssid
*ssid
;
3313 unsigned int i
= 0, num
= 0;
3314 dbus_bool_t success
= FALSE
;
3316 if (!wpa_s
->dbus_new_path
) {
3317 dbus_set_error(error
, DBUS_ERROR_FAILED
,
3318 "%s: no D-Bus interface", __func__
);
3322 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
3323 if (!network_is_persistent_group(ssid
))
3326 paths
= os_calloc(num
, sizeof(char *));
3328 dbus_set_error(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
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
))
3336 paths
[i
] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX
);
3337 if (paths
[i
] == NULL
) {
3338 dbus_set_error(error
, DBUS_ERROR_NO_MEMORY
,
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
);
3349 success
= wpas_dbus_simple_array_property_getter(iter
,
3350 DBUS_TYPE_OBJECT_PATH
,
3355 os_free(paths
[--i
]);
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
3368 * Getter for "PKCS11EnginePath" property.
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
)
3374 struct wpa_supplicant
*wpa_s
= user_data
;
3375 const char *pkcs11_engine_path
;
3377 if (wpa_s
->conf
->pkcs11_engine_path
== NULL
)
3378 pkcs11_engine_path
= "";
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
);
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
3393 * Getter for "PKCS11ModulePath" property.
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
)
3399 struct wpa_supplicant
*wpa_s
= user_data
;
3400 const char *pkcs11_module_path
;
3402 if (wpa_s
->conf
->pkcs11_module_path
== NULL
)
3403 pkcs11_module_path
= "";
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
);
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
3418 * Getter for "Blobs" property.
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
)
3424 struct wpa_supplicant
*wpa_s
= user_data
;
3425 DBusMessageIter variant_iter
, dict_iter
, entry_iter
, array_iter
;
3426 struct wpa_config_blob
*blob
;
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");
3436 blob
= wpa_s
->conf
->blobs
;
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
,
3444 !dbus_message_iter_open_container(&entry_iter
,
3446 DBUS_TYPE_BYTE_AS_STRING
,
3448 !dbus_message_iter_append_fixed_array(&array_iter
,
3452 !dbus_message_iter_close_container(&entry_iter
,
3454 !dbus_message_iter_close_container(&dict_iter
,
3456 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
,
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");
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
)
3478 struct wpa_supplicant
*wpa_s
= user_data
;
3483 if (!property_desc
->data
) {
3484 dbus_set_error(error
, DBUS_ERROR_INVALID_ARGS
,
3485 "Unhandled interface property %s",
3486 property_desc
->dbus_property
);
3490 ret
= wpa_config_get_value(property_desc
->data
, wpa_s
->conf
, buf
,
3495 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
, &p
,
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
)
3504 struct wpa_supplicant
*wpa_s
= user_data
;
3505 const char *new_value
= NULL
;
3507 size_t combined_len
;
3510 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_STRING
,
3514 combined_len
= os_strlen(property_desc
->data
) + os_strlen(new_value
) +
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
);
3526 ret
= os_snprintf(buf
, combined_len
, "%s=%s", property_desc
->data
,
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
);
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
);
3542 wpa_supplicant_update_config(wpa_s
);
3547 static struct wpa_bss
* get_bss_helper(struct bss_handler_args
*args
,
3548 DBusError
*error
, const char *func_name
)
3550 struct wpa_bss
*res
= wpa_bss_get_id(args
->wpa_s
, args
->id
);
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
);
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
3571 * Getter for "BSSID" property.
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
)
3577 struct bss_handler_args
*args
= user_data
;
3578 struct wpa_bss
*res
;
3580 res
= get_bss_helper(args
, error
, __func__
);
3584 return wpas_dbus_simple_array_property_getter(iter
, DBUS_TYPE_BYTE
,
3585 res
->bssid
, ETH_ALEN
,
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
3597 * Getter for "SSID" property.
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
)
3603 struct bss_handler_args
*args
= user_data
;
3604 struct wpa_bss
*res
;
3606 res
= get_bss_helper(args
, error
, __func__
);
3610 return wpas_dbus_simple_array_property_getter(iter
, DBUS_TYPE_BYTE
,
3611 res
->ssid
, res
->ssid_len
,
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
3623 * Getter for "Privacy" property.
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
)
3629 struct bss_handler_args
*args
= user_data
;
3630 struct wpa_bss
*res
;
3631 dbus_bool_t privacy
;
3633 res
= get_bss_helper(args
, error
, __func__
);
3637 privacy
= (res
->caps
& IEEE80211_CAP_PRIVACY
) ? TRUE
: FALSE
;
3638 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_BOOLEAN
,
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
3650 * Getter for "Mode" property.
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
)
3656 struct bss_handler_args
*args
= user_data
;
3657 struct wpa_bss
*res
;
3660 res
= get_bss_helper(args
, error
, __func__
);
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
:
3669 case IEEE80211_CAP_DMG_AP
:
3670 mode
= "infrastructure";
3674 if (res
->caps
& IEEE80211_CAP_IBSS
)
3677 mode
= "infrastructure";
3680 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_STRING
,
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
3692 * Getter for "Level" property.
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
)
3698 struct bss_handler_args
*args
= user_data
;
3699 struct wpa_bss
*res
;
3702 res
= get_bss_helper(args
, error
, __func__
);
3706 level
= (s16
) res
->level
;
3707 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_INT16
,
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
3719 * Getter for "Frequency" property.
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
)
3725 struct bss_handler_args
*args
= user_data
;
3726 struct wpa_bss
*res
;
3729 res
= get_bss_helper(args
, error
, __func__
);
3733 freq
= (u16
) res
->freq
;
3734 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_UINT16
,
3739 static int cmp_u8s_desc(const void *a
, const void *b
)
3741 return (*(u8
*) b
- *(u8
*) a
);
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
3752 * Getter for "Rates" property.
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
)
3758 struct bss_handler_args
*args
= user_data
;
3759 struct wpa_bss
*res
;
3760 u8
*ie_rates
= NULL
;
3763 dbus_bool_t success
= FALSE
;
3765 res
= get_bss_helper(args
, error
, __func__
);
3769 rates_num
= wpa_bss_get_bit_rates(res
, &ie_rates
);
3773 qsort(ie_rates
, rates_num
, 1, cmp_u8s_desc
);
3775 real_rates
= os_malloc(sizeof(u32
) * rates_num
);
3778 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
3782 for (i
= 0; i
< rates_num
; i
++)
3783 real_rates
[i
] = ie_rates
[i
] * 500000;
3785 success
= wpas_dbus_simple_array_property_getter(iter
, DBUS_TYPE_UINT32
,
3786 real_rates
, rates_num
,
3790 os_free(real_rates
);
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
)
3799 DBusMessageIter iter_dict
, variant_iter
;
3801 const char *pairwise
[5]; /* max 5 pairwise ciphers is supported */
3802 const char *key_mgmt
[9]; /* max 9 key managements may be supported */
3805 if (!dbus_message_iter_open_container(iter
, DBUS_TYPE_VARIANT
,
3806 "a{sv}", &variant_iter
))
3809 if (!wpa_dbus_dict_open_write(&variant_iter
, &iter_dict
))
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";
3837 if (!wpa_dbus_dict_append_string_array(&iter_dict
, "KeyMgmt",
3842 switch (ie_data
->group_cipher
) {
3843 case WPA_CIPHER_WEP40
:
3846 case WPA_CIPHER_TKIP
:
3849 case WPA_CIPHER_CCMP
:
3852 case WPA_CIPHER_GCMP
:
3855 case WPA_CIPHER_WEP104
:
3858 case WPA_CIPHER_CCMP_256
:
3861 case WPA_CIPHER_GCMP_256
:
3869 if (!wpa_dbus_dict_append_string(&iter_dict
, "Group", group
))
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";
3885 if (!wpa_dbus_dict_append_string_array(&iter_dict
, "Pairwise",
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";
3896 #endif /* CONFIG_IEEE80211W */
3902 if (!wpa_dbus_dict_append_string(&iter_dict
, "MgmtGroup",
3907 if (!wpa_dbus_dict_close_write(&variant_iter
, &iter_dict
) ||
3908 !dbus_message_iter_close_container(iter
, &variant_iter
))
3914 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
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
3926 * Getter for "WPA" property.
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
)
3932 struct bss_handler_args
*args
= user_data
;
3933 struct wpa_bss
*res
;
3934 struct wpa_ie_data wpa_data
;
3937 res
= get_bss_helper(args
, error
, __func__
);
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");
3949 return wpas_dbus_get_bss_security_prop(property_desc
, iter
, &wpa_data
, error
);
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
3960 * Getter for "RSN" property.
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
)
3966 struct bss_handler_args
*args
= user_data
;
3967 struct wpa_bss
*res
;
3968 struct wpa_ie_data wpa_data
;
3971 res
= get_bss_helper(args
, error
, __func__
);
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");
3983 return wpas_dbus_get_bss_security_prop(property_desc
, iter
, &wpa_data
, error
);
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
3994 * Getter for "WPS" property.
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
)
4000 struct bss_handler_args
*args
= user_data
;
4001 struct wpa_bss
*res
;
4003 struct wpabuf
*wps_ie
;
4004 #endif /* CONFIG_WPS */
4005 DBusMessageIter iter_dict
, variant_iter
;
4006 int wps_support
= 0;
4007 const char *type
= "";
4009 res
= get_bss_helper(args
, error
, __func__
);
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
))
4019 wps_ie
= wpa_bss_get_vendor_ie_multi(res
, WPS_IE_VENDOR_TYPE
);
4022 if (wps_is_selected_pbc_registrar(wps_ie
))
4024 else if (wps_is_selected_pin_registrar(wps_ie
))
4027 wpabuf_free(wps_ie
);
4029 #endif /* CONFIG_WPS */
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
))
4039 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
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
4051 * Getter for "IEs" property.
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
)
4057 struct bss_handler_args
*args
= user_data
;
4058 struct wpa_bss
*res
;
4060 res
= get_bss_helper(args
, error
, __func__
);
4064 return wpas_dbus_simple_array_property_getter(iter
, DBUS_TYPE_BYTE
,
4065 res
+ 1, res
->ie_len
,
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
4077 * Getter for BSS age
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
)
4083 struct bss_handler_args
*args
= user_data
;
4084 struct wpa_bss
*res
;
4085 struct os_reltime now
, diff
= { 0, 0 };
4088 res
= get_bss_helper(args
, error
, __func__
);
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
,
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
4107 * Getter for "enabled" property of a configured network.
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
)
4113 struct network_handler_args
*net
= user_data
;
4114 dbus_bool_t enabled
= net
->ssid
->disabled
? FALSE
: TRUE
;
4116 return wpas_dbus_simple_property_getter(iter
, DBUS_TYPE_BOOLEAN
,
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
4128 * Setter for "Enabled" property of a configured network.
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
)
4134 struct network_handler_args
*net
= user_data
;
4135 struct wpa_supplicant
*wpa_s
;
4136 struct wpa_ssid
*ssid
;
4139 if (!wpas_dbus_simple_property_setter(iter
, error
, DBUS_TYPE_BOOLEAN
,
4147 wpa_supplicant_enable_network(wpa_s
, ssid
);
4149 wpa_supplicant_disable_network(wpa_s
, ssid
);
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
4162 * Getter for "Properties" property of a configured network.
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
)
4168 struct network_handler_args
*net
= user_data
;
4169 DBusMessageIter variant_iter
, dict_iter
;
4171 char **props
= wpa_config_get_all(net
->ssid
, 1);
4172 dbus_bool_t success
= FALSE
;
4175 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
4179 if (!dbus_message_iter_open_container(iter
, DBUS_TYPE_VARIANT
, "a{sv}",
4181 !wpa_dbus_dict_open_write(&variant_iter
, &dict_iter
)) {
4182 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
, "no memory");
4188 if (!wpa_dbus_dict_append_string(&dict_iter
, *iterator
,
4190 dbus_set_error_const(error
, DBUS_ERROR_NO_MEMORY
,
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");
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
4224 * Setter for "Properties" property of a configured network.
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
)
4230 struct network_handler_args
*net
= user_data
;
4231 struct wpa_ssid
*ssid
= net
->ssid
;
4232 DBusMessageIter variant_iter
;
4234 dbus_message_iter_recurse(iter
, &variant_iter
);
4235 return set_network_properties(net
->wpa_s
, ssid
, &variant_iter
, error
);
4241 DBusMessage
* wpas_dbus_handler_subscribe_preq(
4242 DBusMessage
*message
, struct wpa_supplicant
*wpa_s
)
4244 struct wpas_dbus_priv
*priv
= wpa_s
->global
->dbus
;
4247 if (wpa_s
->preq_notify_peer
!= NULL
) {
4248 if (os_strcmp(dbus_message_get_sender(message
),
4249 wpa_s
->preq_notify_peer
) == 0)
4252 return dbus_message_new_error(message
,
4253 WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE
,
4254 "Another application is already subscribed");
4257 name
= os_strdup(dbus_message_get_sender(message
));
4259 return wpas_dbus_error_no_memory(message
);
4261 wpa_s
->preq_notify_peer
= name
;
4263 /* Subscribe to clean up if application closes socket */
4264 wpas_dbus_subscribe_noc(priv
);
4267 * Double-check it's still alive to make sure that we didn't
4268 * miss the NameOwnerChanged signal, e.g. while strdup'ing.
4270 if (!dbus_bus_name_has_owner(priv
->con
, name
, NULL
)) {
4272 * Application no longer exists, clean up.
4273 * The return value is irrelevant now.
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
4280 if (!wpa_s
->preq_notify_peer
)
4282 os_free(wpa_s
->preq_notify_peer
);
4283 wpa_s
->preq_notify_peer
= NULL
;
4284 wpas_dbus_unsubscribe_noc(priv
);
4291 DBusMessage
* wpas_dbus_handler_unsubscribe_preq(
4292 DBusMessage
*message
, struct wpa_supplicant
*wpa_s
)
4294 struct wpas_dbus_priv
*priv
= wpa_s
->global
->dbus
;
4296 if (!wpa_s
->preq_notify_peer
)
4297 return dbus_message_new_error(message
,
4298 WPAS_DBUS_ERROR_NO_SUBSCRIPTION
,
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");
4307 os_free(wpa_s
->preq_notify_peer
);
4308 wpa_s
->preq_notify_peer
= NULL
;
4309 wpas_dbus_unsubscribe_noc(priv
);
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
)
4319 DBusMessageIter iter
, dict_iter
;
4320 struct wpas_dbus_priv
*priv
= wpa_s
->global
->dbus
;
4322 /* Do nothing if the control interface is not turned on */
4323 if (priv
== NULL
|| !wpa_s
->dbus_new_path
)
4326 if (wpa_s
->preq_notify_peer
== NULL
)
4329 msg
= dbus_message_new_signal(wpa_s
->dbus_new_path
,
4330 WPAS_DBUS_NEW_IFACE_INTERFACE
,
4335 dbus_message_set_destination(msg
, wpa_s
->preq_notify_peer
);
4337 dbus_message_iter_init_append(msg
, &iter
);
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
,
4343 (dst
&& !wpa_dbus_dict_append_byte_array(&dict_iter
, "dst",
4346 (bssid
&& !wpa_dbus_dict_append_byte_array(&dict_iter
, "bssid",
4347 (const char *) bssid
,
4349 (ie
&& ie_len
&& !wpa_dbus_dict_append_byte_array(&dict_iter
, "ies",
4352 (ssi_signal
&& !wpa_dbus_dict_append_int32(&dict_iter
, "signal",
4354 !wpa_dbus_dict_close_write(&iter
, &dict_iter
))
4357 dbus_connection_send(priv
->con
, msg
, NULL
);
4360 wpa_printf(MSG_ERROR
, "dbus: Failed to construct signal");
4362 dbus_message_unref(msg
);
4365 #endif /* CONFIG_AP */
4368 DBusMessage
* wpas_dbus_handler_vendor_elem_add(DBusMessage
*message
,
4369 struct wpa_supplicant
*wpa_s
)
4373 struct ieee802_11_elems elems
;
4374 dbus_int32_t frame_id
;
4375 DBusMessageIter iter
, array
;
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
,
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");
4392 if (ieee802_11_parse_elems(ielems
, len
, &elems
, 0) == ParseFailed
) {
4393 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
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
);
4404 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame_id
], len
) < 0) {
4405 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
4409 wpabuf_put_data(wpa_s
->vendor_elem
[frame_id
], ielems
, len
);
4410 wpas_vendor_elem_update(wpa_s
);
4415 DBusMessage
* wpas_dbus_handler_vendor_elem_get(DBusMessage
*message
,
4416 struct wpa_supplicant
*wpa_s
)
4419 DBusMessageIter iter
, array_iter
;
4420 dbus_int32_t frame_id
;
4424 dbus_message_iter_init(message
, &iter
);
4425 dbus_message_iter_get_basic(&iter
, &frame_id
);
4427 if (frame_id
< 0 || frame_id
>= NUM_VENDOR_ELEM_FRAMES
) {
4428 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
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");
4438 reply
= dbus_message_new_method_return(message
);
4440 return wpas_dbus_error_no_memory(message
);
4442 dbus_message_iter_init_append(reply
, &iter
);
4444 elem
= wpabuf_head_u8(wpa_s
->vendor_elem
[frame_id
]);
4445 elem_len
= wpabuf_len(wpa_s
->vendor_elem
[frame_id
]);
4447 if (!dbus_message_iter_open_container(&iter
, DBUS_TYPE_ARRAY
,
4448 DBUS_TYPE_BYTE_AS_STRING
,
4450 !dbus_message_iter_append_fixed_array(&array_iter
, DBUS_TYPE_BYTE
,
4452 !dbus_message_iter_close_container(&iter
, &array_iter
)) {
4453 dbus_message_unref(reply
);
4454 reply
= wpas_dbus_error_no_memory(message
);
4461 DBusMessage
* wpas_dbus_handler_vendor_elem_remove(DBusMessage
*message
,
4462 struct wpa_supplicant
*wpa_s
)
4466 struct ieee802_11_elems elems
;
4467 DBusMessageIter iter
, array
;
4468 dbus_int32_t frame_id
;
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
,
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
,
4485 wpa_s
= wpas_vendor_elem(wpa_s
, frame_id
);
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
);
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");
4499 if (ieee802_11_parse_elems(ielems
, len
, &elems
, 0) == ParseFailed
) {
4500 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
4504 if (wpas_vendor_elem_remove(wpa_s
, frame_id
, ielems
, len
) == 0)
4507 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,