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, Jouni Malinen <j@w1.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
20 #include "common/ieee802_11_defs.h"
21 #include "eap_peer/eap_methods.h"
22 #include "eapol_supp/eapol_supp_sm.h"
23 #include "rsn_supp/wpa.h"
24 #include "../config.h"
25 #include "../wpa_supplicant_i.h"
26 #include "../driver_i.h"
27 #include "../notify.h"
28 #include "../wpas_glue.h"
31 #include "dbus_new_helpers.h"
33 #include "dbus_new_handlers.h"
34 #include "dbus_dict_helpers.h"
36 extern int wpa_debug_level;
37 extern int wpa_debug_show_keys;
38 extern int wpa_debug_timestamp;
40 static const char *debug_strings[] = {
41 "msgdump", "debug", "info", "warning", "error", NULL
46 * wpas_dbus_new_decompose_object_path - Decompose an interface object path into parts
47 * @path: The dbus object path
48 * @network: (out) the configured network this object path refers to, if any
49 * @bssid: (out) the scanned bssid this object path refers to, if any
50 * Returns: The object path of the network interface this path refers to
52 * For a given object path, decomposes the object path into object id, network,
53 * and BSSID parts, if those parts exist.
55 static char * wpas_dbus_new_decompose_object_path(const char *path,
59 const unsigned int dev_path_prefix_len =
60 strlen(WPAS_DBUS_NEW_PATH_INTERFACES "/");
64 /* Be a bit paranoid about path */
65 if (!path || os_strncmp(path, WPAS_DBUS_NEW_PATH_INTERFACES "/",
69 /* Ensure there's something at the end of the path */
70 if ((path + dev_path_prefix_len)[0] == '\0')
73 obj_path_only = os_strdup(path);
74 if (obj_path_only == NULL)
77 next_sep = os_strchr(obj_path_only + dev_path_prefix_len, '/');
78 if (next_sep != NULL) {
79 const char *net_part = os_strstr(
80 next_sep, WPAS_DBUS_NEW_NETWORKS_PART "/");
81 const char *bssid_part = os_strstr(
82 next_sep, WPAS_DBUS_NEW_BSSIDS_PART "/");
84 if (network && net_part) {
85 /* Deal with a request for a configured network */
86 const char *net_name = net_part +
87 os_strlen(WPAS_DBUS_NEW_NETWORKS_PART "/");
89 if (os_strlen(net_name))
90 *network = os_strdup(net_name);
91 } else if (bssid && bssid_part) {
92 /* Deal with a request for a scanned BSSID */
93 const char *bssid_name = bssid_part +
94 os_strlen(WPAS_DBUS_NEW_BSSIDS_PART "/");
95 if (strlen(bssid_name))
96 *bssid = os_strdup(bssid_name);
101 /* Cut off interface object path before "/" */
105 return obj_path_only;
110 * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
111 * @message: Pointer to incoming dbus message this error refers to
112 * @arg: Optional string appended to error message
113 * Returns: a dbus error message
115 * Convenience function to create and return an UnknownError
117 DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
121 * This function can be called as a result of a failure
122 * within internal getter calls, which will call this function
123 * with a NULL message parameter. However, dbus_message_new_error
124 * looks very unkindly (i.e, abort()) on a NULL message, so
125 * in this case, we should not call it.
127 if (message == NULL) {
128 wpa_printf(MSG_INFO, "dbus: wpas_dbus_error_unknown_error "
129 "called with NULL message (arg=%s)",
134 return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
140 * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
141 * @message: Pointer to incoming dbus message this error refers to
142 * Returns: A dbus error message
144 * Convenience function to create and return an invalid interface error
146 static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
148 return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
149 "wpa_supplicant knows nothing about "
155 * wpas_dbus_error_network_unknown - Return a new NetworkUnknown error message
156 * @message: Pointer to incoming dbus message this error refers to
157 * Returns: a dbus error message
159 * Convenience function to create and return an invalid network error
161 static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
163 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
164 "There is no such a network in this "
170 * wpas_dbus_error_invalid_args - Return a new InvalidArgs error message
171 * @message: Pointer to incoming dbus message this error refers to
172 * Returns: a dbus error message
174 * Convenience function to create and return an invalid options error
176 DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
181 reply = dbus_message_new_error(message, WPAS_DBUS_ERROR_INVALID_ARGS,
182 "Did not receive correct message "
185 dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
192 static const char *dont_quote[] = {
193 "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
194 "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
198 static dbus_bool_t should_quote_opt(const char *key)
201 while (dont_quote[i] != NULL) {
202 if (os_strcmp(key, dont_quote[i]) == 0)
210 * get_iface_by_dbus_path - Get a new network interface
211 * @global: Pointer to global data from wpa_supplicant_init()
212 * @path: Pointer to a dbus object path representing an interface
213 * Returns: Pointer to the interface or %NULL if not found
215 static struct wpa_supplicant * get_iface_by_dbus_path(
216 struct wpa_global *global, const char *path)
218 struct wpa_supplicant *wpa_s;
220 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
221 if (os_strcmp(wpa_s->dbus_new_path, path) == 0)
229 * set_network_properties - Set properties of a configured network
230 * @message: Pointer to incoming dbus message
231 * @wpa_s: wpa_supplicant structure for a network interface
232 * @ssid: wpa_ssid structure for a configured network
233 * @iter: DBus message iterator containing dictionary of network
235 * Returns: NULL when succeed or DBus error on failure
237 * Sets network configuration with parameters given id DBus dictionary
239 static DBusMessage * set_network_properties(DBusMessage *message,
240 struct wpa_supplicant *wpa_s,
241 struct wpa_ssid *ssid,
242 DBusMessageIter *iter)
245 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
246 DBusMessage *reply = NULL;
247 DBusMessageIter iter_dict;
249 if (!wpa_dbus_dict_open_read(iter, &iter_dict))
250 return wpas_dbus_error_invalid_args(message, NULL);
252 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
256 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) {
257 reply = wpas_dbus_error_invalid_args(message, NULL);
260 if (entry.type == DBUS_TYPE_ARRAY &&
261 entry.array_type == DBUS_TYPE_BYTE) {
262 if (entry.array_len <= 0)
265 size = entry.array_len * 2 + 1;
266 value = os_zalloc(size);
270 ret = wpa_snprintf_hex(value, size,
271 (u8 *) entry.bytearray_value,
275 } else if (entry.type == DBUS_TYPE_STRING) {
276 if (should_quote_opt(entry.key)) {
277 size = os_strlen(entry.str_value);
282 value = os_zalloc(size);
286 ret = os_snprintf(value, size, "\"%s\"",
288 if (ret < 0 || (size_t) ret != (size - 1))
291 value = os_strdup(entry.str_value);
295 } else if (entry.type == DBUS_TYPE_UINT32) {
296 value = os_zalloc(size);
300 ret = os_snprintf(value, size, "%u",
304 } else if (entry.type == DBUS_TYPE_INT32) {
305 value = os_zalloc(size);
309 ret = os_snprintf(value, size, "%d",
316 if (wpa_config_set(ssid, entry.key, value, 0) < 0)
319 if ((os_strcmp(entry.key, "psk") == 0 &&
320 value[0] == '"' && ssid->ssid_len) ||
321 (strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
322 wpa_config_update_psk(ssid);
323 else if (os_strcmp(entry.key, "priority") == 0)
324 wpa_config_update_prio_list(wpa_s->conf);
327 wpa_dbus_dict_entry_clear(&entry);
332 reply = wpas_dbus_error_invalid_args(message, entry.key);
333 wpa_dbus_dict_entry_clear(&entry);
342 * wpas_dbus_simple_property_getter - Get basic type property
343 * @message: Pointer to incoming dbus message
344 * @type: DBus type of property (must be basic type)
345 * @val: pointer to place holding property value
346 * Returns: The DBus message containing response for Properties.Get call
347 * or DBus error message if error occurred.
349 * Generic getter for basic type properties. Type is required to be basic.
351 DBusMessage * wpas_dbus_simple_property_getter(DBusMessage *message,
352 const int type, const void *val)
354 DBusMessage *reply = NULL;
355 DBusMessageIter iter, variant_iter;
357 if (!dbus_type_is_basic(type)) {
358 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
359 " given type is not basic");
360 return wpas_dbus_error_unknown_error(message, NULL);
364 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
366 reply = dbus_message_new_method_return(message);
369 dbus_message_iter_init_append(reply, &iter);
370 if (!dbus_message_iter_open_container(
371 &iter, DBUS_TYPE_VARIANT,
372 wpa_dbus_type_as_string(type), &variant_iter) ||
373 !dbus_message_iter_append_basic(&variant_iter, type,
375 !dbus_message_iter_close_container(&iter, &variant_iter)) {
376 wpa_printf(MSG_ERROR, "dbus: "
377 "wpas_dbus_simple_property_getter: out of "
378 "memory to put property value into "
380 dbus_message_unref(reply);
381 reply = dbus_message_new_error(message,
382 DBUS_ERROR_NO_MEMORY,
386 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
387 " out of memory to return property value");
388 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
397 * wpas_dbus_simple_property_setter - Set basic type property
398 * @message: Pointer to incoming dbus message
399 * @type: DBus type of property (must be basic type)
400 * @val: pointer to place where value being set will be stored
401 * Returns: NULL or DBus error message if error occurred.
403 * Generic setter for basic type properties. Type is required to be basic.
405 DBusMessage * wpas_dbus_simple_property_setter(DBusMessage *message,
406 const int type, void *val)
408 DBusMessageIter iter, variant_iter;
410 if (!dbus_type_is_basic(type)) {
411 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
412 " given type is not basic");
413 return wpas_dbus_error_unknown_error(message, NULL);
416 if (!dbus_message_iter_init(message, &iter)) {
417 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
418 " out of memory to return scanning state");
419 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
423 /* omit first and second argument and get value from third */
424 dbus_message_iter_next(&iter);
425 dbus_message_iter_next(&iter);
426 dbus_message_iter_recurse(&iter, &variant_iter);
428 if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
429 wpa_printf(MSG_DEBUG, "dbus: wpas_dbus_simple_property_setter:"
430 " wrong property type");
431 return wpas_dbus_error_invalid_args(message,
432 "wrong property type");
434 dbus_message_iter_get_basic(&variant_iter, val);
441 * wpas_dbus_simple_array_property_getter - Get array type property
442 * @message: Pointer to incoming dbus message
443 * @type: DBus type of property array elements (must be basic type)
444 * @array: pointer to array of elements to put into response message
445 * @array_len: length of above array
446 * Returns: The DBus message containing response for Properties.Get call
447 * or DBus error message if error occurred.
449 * Generic getter for array type properties. Array elements type is
450 * required to be basic.
452 DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
457 DBusMessage *reply = NULL;
458 DBusMessageIter iter, variant_iter, array_iter;
459 char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
460 const char *sub_type_str;
461 size_t element_size, i;
463 if (!dbus_type_is_basic(type)) {
464 wpa_printf(MSG_ERROR, "dbus: "
465 "wpas_dbus_simple_array_property_getter: given "
466 "type is not basic");
467 return wpas_dbus_error_unknown_error(message, NULL);
470 sub_type_str = wpa_dbus_type_as_string(type);
471 type_str[1] = sub_type_str[0];
474 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
476 reply = dbus_message_new_method_return(message);
478 wpa_printf(MSG_ERROR, "dbus: "
479 "wpas_dbus_simple_array_property_getter: out of "
480 "memory to create return message");
481 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
485 dbus_message_iter_init_append(reply, &iter);
487 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
488 type_str, &variant_iter) ||
489 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
490 sub_type_str, &array_iter)) {
491 wpa_printf(MSG_ERROR, "dbus: "
492 "wpas_dbus_simple_array_property_getter: out of "
493 "memory to open container");
494 dbus_message_unref(reply);
495 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
501 case DBUS_TYPE_BOOLEAN:
504 case DBUS_TYPE_INT16:
505 case DBUS_TYPE_UINT16:
506 element_size = sizeof(uint16_t);
508 case DBUS_TYPE_INT32:
509 case DBUS_TYPE_UINT32:
510 element_size = sizeof(uint32_t);
512 case DBUS_TYPE_INT64:
513 case DBUS_TYPE_UINT64:
514 element_size = sizeof(uint64_t);
516 case DBUS_TYPE_DOUBLE:
517 element_size = sizeof(double);
519 case DBUS_TYPE_STRING:
520 case DBUS_TYPE_OBJECT_PATH:
521 element_size = sizeof(char *);
524 wpa_printf(MSG_ERROR, "dbus: "
525 "wpas_dbus_simple_array_property_getter: "
526 "fatal: unknown element type");
531 for (i = 0; i < array_len; i++) {
532 dbus_message_iter_append_basic(&array_iter, type,
533 array + i * element_size);
536 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
537 !dbus_message_iter_close_container(&iter, &variant_iter)) {
538 wpa_printf(MSG_ERROR, "dbus: "
539 "wpas_dbus_simple_array_property_getter: out of "
540 "memory to close container");
541 dbus_message_unref(reply);
542 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
551 * wpas_dbus_handler_create_interface - Request registration of a network iface
552 * @message: Pointer to incoming dbus message
553 * @global: %wpa_supplicant global data structure
554 * Returns: The object path of the new interface object,
555 * or a dbus error message with more information
557 * Handler function for "CreateInterface" method call. Handles requests
558 * by dbus clients to register a network interface that wpa_supplicant
561 DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
562 struct wpa_global *global)
564 DBusMessageIter iter_dict;
565 DBusMessage *reply = NULL;
566 DBusMessageIter iter;
567 struct wpa_dbus_dict_entry entry;
570 char *bridge_ifname = NULL;
572 dbus_message_iter_init(message, &iter);
574 if (!wpa_dbus_dict_open_read(&iter, &iter_dict))
576 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
577 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
579 if (!strcmp(entry.key, "Driver") &&
580 (entry.type == DBUS_TYPE_STRING)) {
581 driver = os_strdup(entry.str_value);
582 wpa_dbus_dict_entry_clear(&entry);
585 } else if (!strcmp(entry.key, "Ifname") &&
586 (entry.type == DBUS_TYPE_STRING)) {
587 ifname = os_strdup(entry.str_value);
588 wpa_dbus_dict_entry_clear(&entry);
591 } else if (!strcmp(entry.key, "BridgeIfname") &&
592 (entry.type == DBUS_TYPE_STRING)) {
593 bridge_ifname = os_strdup(entry.str_value);
594 wpa_dbus_dict_entry_clear(&entry);
595 if (bridge_ifname == NULL)
598 wpa_dbus_dict_entry_clear(&entry);
604 goto error; /* Required Ifname argument missing */
607 * Try to get the wpa_supplicant record for this iface, return
608 * an error if we already control it.
610 if (wpa_supplicant_get_iface(global, ifname) != NULL) {
611 reply = dbus_message_new_error(message,
612 WPAS_DBUS_ERROR_IFACE_EXISTS,
613 "wpa_supplicant already "
614 "controls this interface.");
616 struct wpa_supplicant *wpa_s;
617 struct wpa_interface iface;
618 os_memset(&iface, 0, sizeof(iface));
619 iface.driver = driver;
620 iface.ifname = ifname;
621 iface.bridge_ifname = bridge_ifname;
622 /* Otherwise, have wpa_supplicant attach to it. */
623 if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
624 const char *path = wpa_s->dbus_new_path;
625 reply = dbus_message_new_method_return(message);
626 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
627 &path, DBUS_TYPE_INVALID);
629 reply = wpas_dbus_error_unknown_error(
630 message, "wpa_supplicant couldn't grab this "
638 os_free(bridge_ifname);
642 reply = wpas_dbus_error_invalid_args(message, NULL);
648 * wpas_dbus_handler_remove_interface - Request deregistration of an interface
649 * @message: Pointer to incoming dbus message
650 * @global: wpa_supplicant global data structure
651 * Returns: a dbus message containing a UINT32 indicating success (1) or
652 * failure (0), or returns a dbus error message with more information
654 * Handler function for "removeInterface" method call. Handles requests
655 * by dbus clients to deregister a network interface that wpa_supplicant
658 DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
659 struct wpa_global *global)
661 struct wpa_supplicant *wpa_s;
663 DBusMessage *reply = NULL;
665 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
668 wpa_s = get_iface_by_dbus_path(global, path);
670 reply = wpas_dbus_error_iface_unknown(message);
671 else if (wpa_supplicant_remove_iface(global, wpa_s)) {
672 reply = wpas_dbus_error_unknown_error(
673 message, "wpa_supplicant couldn't remove this "
682 * wpas_dbus_handler_get_interface - Get the object path for an interface name
683 * @message: Pointer to incoming dbus message
684 * @global: %wpa_supplicant global data structure
685 * Returns: The object path of the interface object,
686 * or a dbus error message with more information
688 * Handler function for "getInterface" method call.
690 DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
691 struct wpa_global *global)
693 DBusMessage *reply = NULL;
696 struct wpa_supplicant *wpa_s;
698 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &ifname,
701 wpa_s = wpa_supplicant_get_iface(global, ifname);
703 return wpas_dbus_error_iface_unknown(message);
705 path = wpa_s->dbus_new_path;
706 reply = dbus_message_new_method_return(message);
708 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
710 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
711 DBUS_TYPE_INVALID)) {
712 dbus_message_unref(reply);
713 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
722 * wpas_dbus_getter_debug_level - Get debug level
723 * @message: Pointer to incoming dbus message
724 * @global: %wpa_supplicant global data structure
725 * Returns: DBus message with value of debug level
727 * Getter for "DebugLevel" property.
729 DBusMessage * wpas_dbus_getter_debug_level(DBusMessage *message,
730 struct wpa_global *global)
733 int idx = wpa_debug_level;
738 str = debug_strings[idx];
739 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
745 * wpas_dbus_getter_debug_timestamp - Get debug timestamp
746 * @message: Pointer to incoming dbus message
747 * @global: %wpa_supplicant global data structure
748 * Returns: DBus message with value of debug timestamp
750 * Getter for "DebugTimestamp" property.
752 DBusMessage * wpas_dbus_getter_debug_timestamp(DBusMessage *message,
753 struct wpa_global *global)
755 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
756 &wpa_debug_timestamp);
762 * wpas_dbus_getter_debug_show_keys - Get debug show keys
763 * @message: Pointer to incoming dbus message
764 * @global: %wpa_supplicant global data structure
765 * Returns: DBus message with value of debug show_keys
767 * Getter for "DebugShowKeys" property.
769 DBusMessage * wpas_dbus_getter_debug_show_keys(DBusMessage *message,
770 struct wpa_global *global)
772 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
773 &wpa_debug_show_keys);
778 * wpas_dbus_setter_debug_level - Set debug level
779 * @message: Pointer to incoming dbus message
780 * @global: %wpa_supplicant global data structure
781 * Returns: %NULL or DBus error message
783 * Setter for "DebugLevel" property.
785 DBusMessage * wpas_dbus_setter_debug_level(DBusMessage *message,
786 struct wpa_global *global)
789 const char *str = NULL;
792 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_STRING,
797 for (i = 0; debug_strings[i]; i++)
798 if (os_strcmp(debug_strings[i], str) == 0) {
804 wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
805 wpa_debug_show_keys)) {
806 dbus_message_unref(reply);
807 return wpas_dbus_error_invalid_args(
808 message, "Wrong debug level value");
816 * wpas_dbus_setter_debug_timestamp - Set debug timestamp
817 * @message: Pointer to incoming dbus message
818 * @global: %wpa_supplicant global data structure
819 * Returns: %NULL or DBus error message
821 * Setter for "DebugTimestamp" property.
823 DBusMessage * wpas_dbus_setter_debug_timestamp(DBusMessage *message,
824 struct wpa_global *global)
829 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
834 wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
835 wpa_debug_show_keys);
842 * wpas_dbus_setter_debug_show_keys - Set debug show keys
843 * @message: Pointer to incoming dbus message
844 * @global: %wpa_supplicant global data structure
845 * Returns: %NULL or DBus error message
847 * Setter for "DebugShowKeys" property.
849 DBusMessage * wpas_dbus_setter_debug_show_keys(DBusMessage *message,
850 struct wpa_global *global)
855 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
860 wpa_supplicant_set_debug_params(global, wpa_debug_level,
869 * wpas_dbus_getter_interfaces - Request registered interfaces list
870 * @message: Pointer to incoming dbus message
871 * @global: %wpa_supplicant global data structure
872 * Returns: The object paths array containing registered interfaces
873 * objects paths or DBus error on failure
875 * Getter for "Interfaces" property. Handles requests
876 * by dbus clients to return list of registered interfaces objects
879 DBusMessage * wpas_dbus_getter_interfaces(DBusMessage *message,
880 struct wpa_global *global)
882 DBusMessage *reply = NULL;
883 struct wpa_supplicant *wpa_s;
885 unsigned int i = 0, num = 0;
887 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
890 paths = os_zalloc(num * sizeof(char*));
892 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
896 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
897 paths[i] = wpa_s->dbus_new_path;
899 reply = wpas_dbus_simple_array_property_getter(message,
900 DBUS_TYPE_OBJECT_PATH,
909 * wpas_dbus_getter_eap_methods - Request supported EAP methods list
910 * @message: Pointer to incoming dbus message
911 * @nothing: not used argument. may be NULL or anything else
912 * Returns: The object paths array containing supported EAP methods
913 * represented by strings or DBus error on failure
915 * Getter for "EapMethods" property. Handles requests
916 * by dbus clients to return list of strings with supported EAP methods
918 DBusMessage * wpas_dbus_getter_eap_methods(DBusMessage *message, void *nothing)
920 DBusMessage *reply = NULL;
922 size_t num_items = 0;
924 eap_methods = eap_get_names_as_string_array(&num_items);
926 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
930 reply = wpas_dbus_simple_array_property_getter(message,
932 eap_methods, num_items);
935 os_free(eap_methods[--num_items]);
936 os_free(eap_methods);
941 static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
942 char **type, DBusMessage **reply)
944 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
945 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
946 "Type must be a string");
947 *reply = wpas_dbus_error_invalid_args(
948 message, "Wrong Type value type. String required");
951 dbus_message_iter_get_basic(var, type);
956 static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
957 struct wpa_driver_scan_params *params,
960 struct wpa_driver_scan_ssid *ssids = params->ssids;
961 size_t ssids_num = 0;
963 DBusMessageIter array_iter, sub_array_iter;
967 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
968 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
969 "must be an array of arrays of bytes");
970 *reply = wpas_dbus_error_invalid_args(
971 message, "Wrong SSIDs value type. Array of arrays of "
976 dbus_message_iter_recurse(var, &array_iter);
978 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
979 dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
981 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
982 "must be an array of arrays of bytes");
983 *reply = wpas_dbus_error_invalid_args(
984 message, "Wrong SSIDs value type. Array of arrays of "
989 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
991 if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
992 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
993 "Too many ssids specified on scan dbus "
995 *reply = wpas_dbus_error_invalid_args(
996 message, "Too many ssids specified. Specify "
1001 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1003 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1006 ssid = os_malloc(len);
1008 wpa_printf(MSG_DEBUG,
1009 "wpas_dbus_handler_scan[dbus]: "
1010 "out of memory. Cannot allocate "
1012 *reply = dbus_message_new_error(
1013 message, DBUS_ERROR_NO_MEMORY, NULL);
1016 os_memcpy(ssid, val, len);
1018 /* Allow zero-length SSIDs */
1022 ssids[ssids_num].ssid = ssid;
1023 ssids[ssids_num].ssid_len = len;
1025 dbus_message_iter_next(&array_iter);
1029 params->num_ssids = ssids_num;
1034 static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
1035 struct wpa_driver_scan_params *params,
1036 DBusMessage **reply)
1038 u8 *ies = NULL, *nies;
1040 DBusMessageIter array_iter, sub_array_iter;
1044 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1045 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
1046 "be an array of arrays of bytes");
1047 *reply = wpas_dbus_error_invalid_args(
1048 message, "Wrong IEs value type. Array of arrays of "
1053 dbus_message_iter_recurse(var, &array_iter);
1055 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
1056 dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
1058 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
1059 "be an array of arrays of bytes");
1060 *reply = wpas_dbus_error_invalid_args(
1061 message, "Wrong IEs value type. Array required");
1065 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
1067 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1069 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1071 dbus_message_iter_next(&array_iter);
1075 nies = os_realloc(ies, ies_len + len);
1077 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1078 "out of memory. Cannot allocate memory for "
1081 *reply = dbus_message_new_error(
1082 message, DBUS_ERROR_NO_MEMORY, NULL);
1086 os_memcpy(ies + ies_len, val, len);
1089 dbus_message_iter_next(&array_iter);
1092 params->extra_ies = ies;
1093 params->extra_ies_len = ies_len;
1098 static int wpas_dbus_get_scan_channels(DBusMessage *message,
1099 DBusMessageIter *var,
1100 struct wpa_driver_scan_params *params,
1101 DBusMessage **reply)
1103 DBusMessageIter array_iter, sub_array_iter;
1104 int *freqs = NULL, *nfreqs;
1107 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1108 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1109 "Channels must be an array of structs");
1110 *reply = wpas_dbus_error_invalid_args(
1111 message, "Wrong Channels value type. Array of structs "
1116 dbus_message_iter_recurse(var, &array_iter);
1118 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
1119 wpa_printf(MSG_DEBUG,
1120 "wpas_dbus_handler_scan[dbus]: Channels must be an "
1121 "array of structs");
1122 *reply = wpas_dbus_error_invalid_args(
1123 message, "Wrong Channels value type. Array of structs "
1128 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
1132 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1134 if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
1136 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1137 "Channel must by specified by struct of "
1139 dbus_message_iter_get_arg_type(
1141 *reply = wpas_dbus_error_invalid_args(
1142 message, "Wrong Channel struct. Two UINT32s "
1147 dbus_message_iter_get_basic(&sub_array_iter, &freq);
1149 if (!dbus_message_iter_next(&sub_array_iter) ||
1150 dbus_message_iter_get_arg_type(&sub_array_iter) !=
1152 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1153 "Channel must by specified by struct of "
1155 *reply = wpas_dbus_error_invalid_args(
1157 "Wrong Channel struct. Two UINT32s required");
1162 dbus_message_iter_get_basic(&sub_array_iter, &width);
1164 #define FREQS_ALLOC_CHUNK 32
1165 if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
1166 nfreqs = os_realloc(freqs, sizeof(int) *
1167 (freqs_num + FREQS_ALLOC_CHUNK));
1172 if (freqs == NULL) {
1173 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1174 "out of memory. can't allocate memory for "
1176 *reply = dbus_message_new_error(
1177 message, DBUS_ERROR_NO_MEMORY, NULL);
1181 freqs[freqs_num] = freq;
1184 dbus_message_iter_next(&array_iter);
1187 nfreqs = os_realloc(freqs,
1188 sizeof(int) * (freqs_num + 1));
1192 if (freqs == NULL) {
1193 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1194 "out of memory. Can't allocate memory for freqs");
1195 *reply = dbus_message_new_error(
1196 message, DBUS_ERROR_NO_MEMORY, NULL);
1199 freqs[freqs_num] = 0;
1201 params->freqs = freqs;
1207 * wpas_dbus_handler_scan - Request a wireless scan on an interface
1208 * @message: Pointer to incoming dbus message
1209 * @wpa_s: wpa_supplicant structure for a network interface
1210 * Returns: NULL indicating success or DBus error message on failure
1212 * Handler function for "Scan" method call of a network device. Requests
1213 * that wpa_supplicant perform a wireless scan as soon as possible
1214 * on a particular wireless interface.
1216 DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
1217 struct wpa_supplicant *wpa_s)
1219 DBusMessage *reply = NULL;
1220 DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
1221 char *key = NULL, *type = NULL;
1222 struct wpa_driver_scan_params params;
1225 os_memset(¶ms, 0, sizeof(params));
1227 dbus_message_iter_init(message, &iter);
1229 dbus_message_iter_recurse(&iter, &dict_iter);
1231 while (dbus_message_iter_get_arg_type(&dict_iter) ==
1232 DBUS_TYPE_DICT_ENTRY) {
1233 dbus_message_iter_recurse(&dict_iter, &entry_iter);
1234 dbus_message_iter_get_basic(&entry_iter, &key);
1235 dbus_message_iter_next(&entry_iter);
1236 dbus_message_iter_recurse(&entry_iter, &variant_iter);
1238 if (os_strcmp(key, "Type") == 0) {
1239 if (wpas_dbus_get_scan_type(message, &variant_iter,
1242 } else if (os_strcmp(key, "SSIDs") == 0) {
1243 if (wpas_dbus_get_scan_ssids(message, &variant_iter,
1244 ¶ms, &reply) < 0)
1246 } else if (os_strcmp(key, "IEs") == 0) {
1247 if (wpas_dbus_get_scan_ies(message, &variant_iter,
1248 ¶ms, &reply) < 0)
1250 } else if (os_strcmp(key, "Channels") == 0) {
1251 if (wpas_dbus_get_scan_channels(message, &variant_iter,
1252 ¶ms, &reply) < 0)
1255 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1256 "Unknown argument %s", key);
1257 reply = wpas_dbus_error_invalid_args(message, key);
1261 dbus_message_iter_next(&dict_iter);
1265 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1266 "Scan type not specified");
1267 reply = wpas_dbus_error_invalid_args(message, key);
1271 if (!os_strcmp(type, "passive")) {
1272 if (params.num_ssids || params.extra_ies_len) {
1273 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1274 "SSIDs or IEs specified for passive scan.");
1275 reply = wpas_dbus_error_invalid_args(
1276 message, "You can specify only Channels in "
1279 } else if (params.freqs && params.freqs[0]) {
1280 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1282 wpa_s->scan_req = 2;
1283 wpa_supplicant_req_scan(wpa_s, 0, 0);
1285 } else if (!os_strcmp(type, "active")) {
1286 if (!params.num_ssids) {
1287 /* Add wildcard ssid */
1290 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1292 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1293 "Unknown scan type: %s", type);
1294 reply = wpas_dbus_error_invalid_args(message,
1300 for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
1301 os_free((u8 *) params.ssids[i].ssid);
1302 os_free((u8 *) params.extra_ies);
1303 os_free(params.freqs);
1309 * wpas_dbus_handler_disconnect - Terminate the current connection
1310 * @message: Pointer to incoming dbus message
1311 * @wpa_s: wpa_supplicant structure for a network interface
1312 * Returns: NotConnected DBus error message if already not connected
1313 * or NULL otherwise.
1315 * Handler function for "Disconnect" method call of network interface.
1317 DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
1318 struct wpa_supplicant *wpa_s)
1320 if (wpa_s->current_ssid != NULL) {
1321 wpa_s->disconnected = 1;
1322 wpa_supplicant_deauthenticate(wpa_s,
1323 WLAN_REASON_DEAUTH_LEAVING);
1328 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
1329 "This interface is not connected");
1334 * wpas_dbus_new_iface_add_network - Add a new configured network
1335 * @message: Pointer to incoming dbus message
1336 * @wpa_s: wpa_supplicant structure for a network interface
1337 * Returns: A dbus message containing the object path of the new network
1339 * Handler function for "AddNetwork" method call of a network interface.
1341 DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
1342 struct wpa_supplicant *wpa_s)
1344 DBusMessage *reply = NULL;
1345 DBusMessageIter iter;
1346 struct wpa_ssid *ssid = NULL;
1347 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
1349 dbus_message_iter_init(message, &iter);
1351 ssid = wpa_config_add_network(wpa_s->conf);
1353 wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
1354 "can't add new interface.");
1355 reply = wpas_dbus_error_unknown_error(
1357 "wpa_supplicant could not add "
1358 "a network on this interface.");
1361 wpas_notify_network_added(wpa_s, ssid);
1363 wpa_config_set_network_defaults(ssid);
1365 reply = set_network_properties(message, wpa_s, ssid, &iter);
1367 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
1368 "control interface couldn't set network "
1373 /* Construct the object path for this network. */
1374 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1375 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
1376 wpa_s->dbus_new_path, ssid->id);
1378 reply = dbus_message_new_method_return(message);
1379 if (reply == NULL) {
1380 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1384 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
1385 DBUS_TYPE_INVALID)) {
1386 dbus_message_unref(reply);
1387 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1396 wpas_notify_network_removed(wpa_s, ssid);
1397 wpa_config_remove_network(wpa_s->conf, ssid->id);
1404 * wpas_dbus_handler_remove_network - Remove a configured network
1405 * @message: Pointer to incoming dbus message
1406 * @wpa_s: wpa_supplicant structure for a network interface
1407 * Returns: NULL on success or dbus error on failure
1409 * Handler function for "RemoveNetwork" method call of a network interface.
1411 DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
1412 struct wpa_supplicant *wpa_s)
1414 DBusMessage *reply = NULL;
1416 char *iface = NULL, *net_id = NULL;
1418 struct wpa_ssid *ssid;
1420 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1423 /* Extract the network ID and ensure the network */
1424 /* is actually a child of this interface */
1425 iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
1426 if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1427 reply = wpas_dbus_error_invalid_args(message, op);
1431 id = strtoul(net_id, NULL, 10);
1432 if (errno == EINVAL) {
1433 reply = wpas_dbus_error_invalid_args(message, op);
1437 ssid = wpa_config_get_network(wpa_s->conf, id);
1439 reply = wpas_dbus_error_network_unknown(message);
1443 wpas_notify_network_removed(wpa_s, ssid);
1445 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
1446 wpa_printf(MSG_ERROR,
1447 "wpas_dbus_handler_remove_network[dbus]: "
1448 "error occurred when removing network %d", id);
1449 reply = wpas_dbus_error_unknown_error(
1450 message, "error removing the specified network on "
1455 if (ssid == wpa_s->current_ssid)
1456 wpa_supplicant_deauthenticate(wpa_s,
1457 WLAN_REASON_DEAUTH_LEAVING);
1467 * wpas_dbus_handler_select_network - Attempt association with a network
1468 * @message: Pointer to incoming dbus message
1469 * @wpa_s: wpa_supplicant structure for a network interface
1470 * Returns: NULL on success or dbus error on failure
1472 * Handler function for "SelectNetwork" method call of network interface.
1474 DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
1475 struct wpa_supplicant *wpa_s)
1477 DBusMessage *reply = NULL;
1479 char *iface = NULL, *net_id = NULL;
1481 struct wpa_ssid *ssid;
1483 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1486 /* Extract the network ID and ensure the network */
1487 /* is actually a child of this interface */
1488 iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
1489 if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1490 reply = wpas_dbus_error_invalid_args(message, op);
1494 id = strtoul(net_id, NULL, 10);
1495 if (errno == EINVAL) {
1496 reply = wpas_dbus_error_invalid_args(message, op);
1500 ssid = wpa_config_get_network(wpa_s->conf, id);
1502 reply = wpas_dbus_error_network_unknown(message);
1506 /* Finally, associate with the network */
1507 wpa_supplicant_select_network(wpa_s, ssid);
1517 * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
1518 * @message: Pointer to incoming dbus message
1519 * @wpa_s: %wpa_supplicant data structure
1520 * Returns: A dbus message containing an error on failure or NULL on success
1522 * Asks wpa_supplicant to internally store a binary blobs.
1524 DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
1525 struct wpa_supplicant *wpa_s)
1527 DBusMessage *reply = NULL;
1528 DBusMessageIter iter, array_iter;
1533 struct wpa_config_blob *blob = NULL;
1535 dbus_message_iter_init(message, &iter);
1536 dbus_message_iter_get_basic(&iter, &blob_name);
1538 if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
1539 return dbus_message_new_error(message,
1540 WPAS_DBUS_ERROR_BLOB_EXISTS,
1544 dbus_message_iter_next(&iter);
1545 dbus_message_iter_recurse(&iter, &array_iter);
1547 dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
1549 blob = os_zalloc(sizeof(*blob));
1551 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1556 blob->data = os_malloc(blob_len);
1558 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1562 os_memcpy(blob->data, blob_data, blob_len);
1564 blob->len = blob_len;
1565 blob->name = os_strdup(blob_name);
1567 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1572 wpa_config_set_blob(wpa_s->conf, blob);
1573 wpas_notify_blob_added(wpa_s, blob->name);
1579 os_free(blob->name);
1580 os_free(blob->data);
1588 * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
1589 * @message: Pointer to incoming dbus message
1590 * @wpa_s: %wpa_supplicant data structure
1591 * Returns: A dbus message containing array of bytes (blob)
1593 * Gets one wpa_supplicant's binary blobs.
1595 DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
1596 struct wpa_supplicant *wpa_s)
1598 DBusMessage *reply = NULL;
1599 DBusMessageIter iter, array_iter;
1602 const struct wpa_config_blob *blob;
1604 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
1607 blob = wpa_config_get_blob(wpa_s->conf, blob_name);
1609 return dbus_message_new_error(message,
1610 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
1614 reply = dbus_message_new_method_return(message);
1616 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1621 dbus_message_iter_init_append(reply, &iter);
1623 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
1624 DBUS_TYPE_BYTE_AS_STRING,
1626 dbus_message_unref(reply);
1627 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1632 if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
1633 &(blob->data), blob->len)) {
1634 dbus_message_unref(reply);
1635 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1640 if (!dbus_message_iter_close_container(&iter, &array_iter)) {
1641 dbus_message_unref(reply);
1642 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1653 * wpas_remove_handler_remove_blob - Remove named binary blob
1654 * @message: Pointer to incoming dbus message
1655 * @wpa_s: %wpa_supplicant data structure
1656 * Returns: NULL on success or dbus error
1658 * Asks wpa_supplicant to internally remove a binary blobs.
1660 DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
1661 struct wpa_supplicant *wpa_s)
1663 DBusMessage *reply = NULL;
1666 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
1669 if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
1670 return dbus_message_new_error(message,
1671 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
1674 wpas_notify_blob_removed(wpa_s, blob_name);
1682 * wpas_dbus_getter_capabilities - Return interface capabilities
1683 * @message: Pointer to incoming dbus message
1684 * @wpa_s: wpa_supplicant structure for a network interface
1685 * Returns: A dbus message containing a dict of strings
1687 * Getter for "Capabilities" property of an interface.
1689 DBusMessage * wpas_dbus_getter_capabilities(DBusMessage *message,
1690 struct wpa_supplicant *wpa_s)
1692 DBusMessage *reply = NULL;
1693 struct wpa_driver_capa capa;
1695 DBusMessageIter iter, iter_dict;
1696 DBusMessageIter iter_dict_entry, iter_dict_val, iter_array,
1698 const char *scans[] = { "active", "passive", "ssid" };
1699 const char *modes[] = { "infrastructure", "ad-hoc", "ap" };
1700 int n = sizeof(modes) / sizeof(char *);
1702 if (message == NULL)
1703 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
1705 reply = dbus_message_new_method_return(message);
1709 dbus_message_iter_init_append(reply, &iter);
1710 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
1711 "a{sv}", &variant_iter))
1714 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
1717 res = wpa_drv_get_capa(wpa_s, &capa);
1719 /***** pairwise cipher */
1721 const char *args[] = {"ccmp", "tkip", "none"};
1722 if (!wpa_dbus_dict_append_string_array(
1723 &iter_dict, "Pairwise", args,
1724 sizeof(args) / sizeof(char*)))
1727 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
1733 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1734 if (!wpa_dbus_dict_string_array_add_element(
1735 &iter_array, "ccmp"))
1739 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1740 if (!wpa_dbus_dict_string_array_add_element(
1741 &iter_array, "tkip"))
1745 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1746 if (!wpa_dbus_dict_string_array_add_element(
1747 &iter_array, "none"))
1751 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1758 /***** group cipher */
1760 const char *args[] = {
1761 "ccmp", "tkip", "wep104", "wep40"
1763 if (!wpa_dbus_dict_append_string_array(
1764 &iter_dict, "Group", args,
1765 sizeof(args) / sizeof(char*)))
1768 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
1774 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1775 if (!wpa_dbus_dict_string_array_add_element(
1776 &iter_array, "ccmp"))
1780 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1781 if (!wpa_dbus_dict_string_array_add_element(
1782 &iter_array, "tkip"))
1786 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
1787 if (!wpa_dbus_dict_string_array_add_element(
1788 &iter_array, "wep104"))
1792 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
1793 if (!wpa_dbus_dict_string_array_add_element(
1794 &iter_array, "wep40"))
1798 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1805 /***** key management */
1807 const char *args[] = {
1808 "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
1811 #endif /* CONFIG_WPS */
1814 if (!wpa_dbus_dict_append_string_array(
1815 &iter_dict, "KeyMgmt", args,
1816 sizeof(args) / sizeof(char*)))
1819 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
1825 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
1829 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
1833 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1834 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
1835 if (!wpa_dbus_dict_string_array_add_element(
1836 &iter_array, "wpa-eap"))
1839 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT)
1840 if (!wpa_dbus_dict_string_array_add_element(
1841 &iter_array, "wpa-ft-eap"))
1844 /* TODO: Ensure that driver actually supports sha256 encryption. */
1845 #ifdef CONFIG_IEEE80211W
1846 if (!wpa_dbus_dict_string_array_add_element(
1847 &iter_array, "wpa-eap-sha256"))
1849 #endif /* CONFIG_IEEE80211W */
1852 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1853 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1854 if (!wpa_dbus_dict_string_array_add_element(
1855 &iter_array, "wpa-psk"))
1858 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK)
1859 if (!wpa_dbus_dict_string_array_add_element(
1860 &iter_array, "wpa-ft-psk"))
1863 /* TODO: Ensure that driver actually supports sha256 encryption. */
1864 #ifdef CONFIG_IEEE80211W
1865 if (!wpa_dbus_dict_string_array_add_element(
1866 &iter_array, "wpa-psk-sha256"))
1868 #endif /* CONFIG_IEEE80211W */
1871 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1872 if (!wpa_dbus_dict_string_array_add_element(
1873 &iter_array, "wpa-none"))
1879 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
1882 #endif /* CONFIG_WPS */
1884 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1891 /***** WPA protocol */
1893 const char *args[] = { "rsn", "wpa" };
1894 if (!wpa_dbus_dict_append_string_array(
1895 &iter_dict, "Protocol", args,
1896 sizeof(args) / sizeof(char*)))
1899 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
1905 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1906 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1907 if (!wpa_dbus_dict_string_array_add_element(
1908 &iter_array, "rsn"))
1912 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1913 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
1914 if (!wpa_dbus_dict_string_array_add_element(
1915 &iter_array, "wpa"))
1919 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1928 const char *args[] = { "open", "shared", "leap" };
1929 if (!wpa_dbus_dict_append_string_array(
1930 &iter_dict, "AuthAlg", args,
1931 sizeof(args) / sizeof(char*)))
1934 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
1940 if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
1941 if (!wpa_dbus_dict_string_array_add_element(
1942 &iter_array, "open"))
1946 if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
1947 if (!wpa_dbus_dict_string_array_add_element(
1948 &iter_array, "shared"))
1952 if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
1953 if (!wpa_dbus_dict_string_array_add_element(
1954 &iter_array, "leap"))
1958 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1966 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
1967 sizeof(scans) / sizeof(char *)))
1971 if (res < 0 || !(capa.flags & WPA_DRIVER_FLAGS_AP))
1972 n--; /* exclude ap mode if it is not supported by the driver */
1973 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Modes", modes, n))
1976 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
1978 if (!dbus_message_iter_close_container(&iter, &variant_iter))
1985 dbus_message_unref(reply);
1987 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
1992 * wpas_dbus_getter_state - Get interface state
1993 * @message: Pointer to incoming dbus message
1994 * @wpa_s: wpa_supplicant structure for a network interface
1995 * Returns: A dbus message containing a STRING representing the current
1998 * Getter for "State" property.
2000 DBusMessage * wpas_dbus_getter_state(DBusMessage *message,
2001 struct wpa_supplicant *wpa_s)
2003 DBusMessage *reply = NULL;
2004 const char *str_state;
2005 char *state_ls, *tmp;
2007 str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
2009 /* make state string lowercase to fit new DBus API convention
2011 state_ls = tmp = os_strdup(str_state);
2013 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2017 *tmp = tolower(*tmp);
2021 reply = wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2031 * wpas_dbus_new_iface_get_scanning - Get interface scanning state
2032 * @message: Pointer to incoming dbus message
2033 * @wpa_s: wpa_supplicant structure for a network interface
2034 * Returns: A dbus message containing whether the interface is scanning
2036 * Getter for "scanning" property.
2038 DBusMessage * wpas_dbus_getter_scanning(DBusMessage *message,
2039 struct wpa_supplicant *wpa_s)
2041 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
2042 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
2048 * wpas_dbus_getter_ap_scan - Control roaming mode
2049 * @message: Pointer to incoming dbus message
2050 * @wpa_s: wpa_supplicant structure for a network interface
2051 * Returns: A message containong value of ap_scan variable
2053 * Getter function for "ApScan" property.
2055 DBusMessage * wpas_dbus_getter_ap_scan(DBusMessage *message,
2056 struct wpa_supplicant *wpa_s)
2058 dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
2059 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT32,
2065 * wpas_dbus_setter_ap_scan - Control roaming mode
2066 * @message: Pointer to incoming dbus message
2067 * @wpa_s: wpa_supplicant structure for a network interface
2070 * Setter function for "ApScan" property.
2072 DBusMessage * wpas_dbus_setter_ap_scan(DBusMessage *message,
2073 struct wpa_supplicant *wpa_s)
2075 DBusMessage *reply = NULL;
2076 dbus_uint32_t ap_scan;
2078 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_UINT32,
2083 if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
2084 return wpas_dbus_error_invalid_args(
2085 message, "ap_scan must equal 0, 1 or 2");
2092 * wpas_dbus_getter_ifname - Get interface name
2093 * @message: Pointer to incoming dbus message
2094 * @wpa_s: wpa_supplicant structure for a network interface
2095 * Returns: A dbus message containing a name of network interface
2096 * associated with with wpa_s
2098 * Getter for "Ifname" property.
2100 DBusMessage * wpas_dbus_getter_ifname(DBusMessage *message,
2101 struct wpa_supplicant *wpa_s)
2103 const char *ifname = wpa_s->ifname;
2104 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2110 * wpas_dbus_getter_driver - Get interface name
2111 * @message: Pointer to incoming dbus message
2112 * @wpa_s: wpa_supplicant structure for a network interface
2113 * Returns: A dbus message containing a name of network interface
2114 * driver associated with with wpa_s
2116 * Getter for "Driver" property.
2118 DBusMessage * wpas_dbus_getter_driver(DBusMessage *message,
2119 struct wpa_supplicant *wpa_s)
2123 if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
2124 wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
2125 "wpa_s has no driver set");
2126 return wpas_dbus_error_unknown_error(message, NULL);
2129 driver = wpa_s->driver->name;
2130 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2136 * wpas_dbus_getter_current_bss - Get current bss object path
2137 * @message: Pointer to incoming dbus message
2138 * @wpa_s: wpa_supplicant structure for a network interface
2139 * Returns: A dbus message containing a DBus object path to
2142 * Getter for "CurrentBSS" property.
2144 DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message,
2145 struct wpa_supplicant *wpa_s)
2148 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
2150 if (wpa_s->current_bss)
2151 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2152 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2153 wpa_s->dbus_new_path, wpa_s->current_bss->id);
2155 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2157 reply = wpas_dbus_simple_property_getter(message,
2158 DBUS_TYPE_OBJECT_PATH,
2166 * wpas_dbus_getter_current_network - Get current network object path
2167 * @message: Pointer to incoming dbus message
2168 * @wpa_s: wpa_supplicant structure for a network interface
2169 * Returns: A dbus message containing a DBus object path to
2172 * Getter for "CurrentNetwork" property.
2174 DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message,
2175 struct wpa_supplicant *wpa_s)
2178 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
2180 if (wpa_s->current_ssid)
2181 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2182 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2183 wpa_s->dbus_new_path, wpa_s->current_ssid->id);
2185 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2187 reply = wpas_dbus_simple_property_getter(message,
2188 DBUS_TYPE_OBJECT_PATH,
2196 * wpas_dbus_getter_bridge_ifname - Get interface name
2197 * @message: Pointer to incoming dbus message
2198 * @wpa_s: wpa_supplicant structure for a network interface
2199 * Returns: A dbus message containing a name of bridge network
2200 * interface associated with with wpa_s
2202 * Getter for "BridgeIfname" property.
2204 DBusMessage * wpas_dbus_getter_bridge_ifname(DBusMessage *message,
2205 struct wpa_supplicant *wpa_s)
2207 const char *bridge_ifname = NULL;
2209 bridge_ifname = wpa_s->bridge_ifname;
2210 if (bridge_ifname == NULL) {
2211 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bridge_ifname[dbus]: "
2212 "wpa_s has no bridge interface name set");
2213 return wpas_dbus_error_unknown_error(message, NULL);
2216 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2222 * wpas_dbus_getter_bsss - Get array of BSSs objects
2223 * @message: Pointer to incoming dbus message
2224 * @wpa_s: wpa_supplicant structure for a network interface
2225 * Returns: a dbus message containing an array of all known BSS objects
2228 * Getter for "BSSs" property.
2230 DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
2231 struct wpa_supplicant *wpa_s)
2233 DBusMessage *reply = NULL;
2234 struct wpa_bss *bss;
2238 paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
2240 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2244 /* Loop through scan results and append each result's object path */
2245 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2246 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2247 if (paths[i] == NULL) {
2248 reply = dbus_message_new_error(message,
2249 DBUS_ERROR_NO_MEMORY,
2253 /* Construct the object path for this BSS. */
2254 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2255 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2256 wpa_s->dbus_new_path, bss->id);
2259 reply = wpas_dbus_simple_array_property_getter(message,
2260 DBUS_TYPE_OBJECT_PATH,
2261 paths, wpa_s->num_bss);
2265 os_free(paths[--i]);
2272 * wpas_dbus_getter_networks - Get array of networks objects
2273 * @message: Pointer to incoming dbus message
2274 * @wpa_s: wpa_supplicant structure for a network interface
2275 * Returns: a dbus message containing an array of all configured
2276 * networks dbus object paths.
2278 * Getter for "Networks" property.
2280 DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
2281 struct wpa_supplicant *wpa_s)
2283 DBusMessage *reply = NULL;
2284 struct wpa_ssid *ssid;
2286 unsigned int i = 0, num = 0;
2288 if (wpa_s->conf == NULL) {
2289 wpa_printf(MSG_ERROR, "wpas_dbus_getter_networks[dbus]: "
2290 "An error occurred getting networks list.");
2291 return wpas_dbus_error_unknown_error(message, NULL);
2294 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
2297 paths = os_zalloc(num * sizeof(char *));
2299 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2303 /* Loop through configured networks and append object path of each */
2304 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
2305 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2306 if (paths[i] == NULL) {
2307 reply = dbus_message_new_error(message,
2308 DBUS_ERROR_NO_MEMORY,
2313 /* Construct the object path for this network. */
2314 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2315 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
2316 wpa_s->dbus_new_path, ssid->id);
2319 reply = wpas_dbus_simple_array_property_getter(message,
2320 DBUS_TYPE_OBJECT_PATH,
2325 os_free(paths[--i]);
2332 * wpas_dbus_getter_blobs - Get all blobs defined for this interface
2333 * @message: Pointer to incoming dbus message
2334 * @wpa_s: wpa_supplicant structure for a network interface
2335 * Returns: a dbus message containing a dictionary of pairs (blob_name, blob)
2337 * Getter for "Blobs" property.
2339 DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
2340 struct wpa_supplicant *wpa_s)
2342 DBusMessage *reply = NULL;
2343 DBusMessageIter iter, variant_iter, dict_iter, entry_iter, array_iter;
2344 struct wpa_config_blob *blob;
2346 if (message == NULL)
2347 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
2349 reply = dbus_message_new_method_return(message);
2351 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2354 dbus_message_iter_init_append(reply, &iter);
2356 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
2357 "a{say}", &variant_iter) ||
2358 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
2359 "{say}", &dict_iter)) {
2360 dbus_message_unref(reply);
2361 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2365 blob = wpa_s->conf->blobs;
2367 if (!dbus_message_iter_open_container(&dict_iter,
2368 DBUS_TYPE_DICT_ENTRY,
2369 NULL, &entry_iter) ||
2370 !dbus_message_iter_append_basic(&entry_iter,
2373 !dbus_message_iter_open_container(&entry_iter,
2375 DBUS_TYPE_BYTE_AS_STRING,
2377 !dbus_message_iter_append_fixed_array(&array_iter,
2381 !dbus_message_iter_close_container(&entry_iter,
2383 !dbus_message_iter_close_container(&dict_iter,
2385 dbus_message_unref(reply);
2386 return dbus_message_new_error(message,
2387 DBUS_ERROR_NO_MEMORY,
2394 if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
2395 !dbus_message_iter_close_container(&iter, &variant_iter)) {
2396 dbus_message_unref(reply);
2397 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2406 * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
2407 * @message: Pointer to incoming dbus message
2408 * @bss: a pair of interface describing structure and bss's id
2409 * Returns: a dbus message containing the bssid for the requested bss
2411 * Getter for "BSSID" property.
2413 DBusMessage * wpas_dbus_getter_bss_bssid(DBusMessage *message,
2414 struct bss_handler_args *bss)
2416 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2419 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_bssid[dbus]: no "
2420 "bss with id %d found", bss->id);
2424 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2425 res->bssid, ETH_ALEN);
2430 * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
2431 * @message: Pointer to incoming dbus message
2432 * @bss: a pair of interface describing structure and bss's id
2433 * Returns: a dbus message containing the ssid for the requested bss
2435 * Getter for "SSID" property.
2437 DBusMessage * wpas_dbus_getter_bss_ssid(DBusMessage *message,
2438 struct bss_handler_args *bss)
2440 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2443 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ssid[dbus]: no "
2444 "bss with id %d found", bss->id);
2448 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2455 * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
2456 * @message: Pointer to incoming dbus message
2457 * @bss: a pair of interface describing structure and bss's id
2458 * Returns: a dbus message containing the privacy flag value of requested bss
2460 * Getter for "Privacy" property.
2462 DBusMessage * wpas_dbus_getter_bss_privacy(DBusMessage *message,
2463 struct bss_handler_args *bss)
2465 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2466 dbus_bool_t privacy;
2469 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_privacy[dbus]: no "
2470 "bss with id %d found", bss->id);
2474 privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
2475 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
2481 * wpas_dbus_getter_bss_mode - Return the mode of a BSS
2482 * @message: Pointer to incoming dbus message
2483 * @bss: a pair of interface describing structure and bss's id
2484 * Returns: a dbus message containing the mode of requested bss
2486 * Getter for "Mode" property.
2488 DBusMessage * wpas_dbus_getter_bss_mode(DBusMessage *message,
2489 struct bss_handler_args *bss)
2491 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2495 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_mode[dbus]: no "
2496 "bss with id %d found", bss->id);
2500 if (res->caps & IEEE80211_CAP_IBSS)
2503 mode = "infrastructure";
2505 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2511 * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
2512 * @message: Pointer to incoming dbus message
2513 * @bss: a pair of interface describing structure and bss's id
2514 * Returns: a dbus message containing the signal strength of requested bss
2516 * Getter for "Level" property.
2518 DBusMessage * wpas_dbus_getter_bss_signal(DBusMessage *message,
2519 struct bss_handler_args *bss)
2521 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2524 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_signal[dbus]: no "
2525 "bss with id %d found", bss->id);
2529 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_INT16,
2535 * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
2536 * @message: Pointer to incoming dbus message
2537 * @bss: a pair of interface describing structure and bss's id
2538 * Returns: a dbus message containing the frequency of requested bss
2540 * Getter for "Frequency" property.
2542 DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
2543 struct bss_handler_args *bss)
2545 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2548 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_frequency[dbus]: "
2549 "no bss with id %d found", bss->id);
2553 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
2558 static int cmp_u8s_desc(const void *a, const void *b)
2560 return (*(u8 *) b - *(u8 *) a);
2565 * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
2566 * @message: Pointer to incoming dbus message
2567 * @bss: a pair of interface describing structure and bss's id
2568 * Returns: a dbus message containing sorted array of bit rates
2570 * Getter for "Rates" property.
2572 DBusMessage * wpas_dbus_getter_bss_rates(DBusMessage *message,
2573 struct bss_handler_args *bss)
2576 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2577 u8 *ie_rates = NULL;
2582 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rates[dbus]: "
2583 "no bss with id %d found", bss->id);
2587 rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
2591 qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
2593 real_rates = os_malloc(sizeof(u32) * rates_num);
2596 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2600 for (i = 0; i < rates_num; i++)
2601 real_rates[i] = ie_rates[i] * 500000;
2603 reply = wpas_dbus_simple_array_property_getter(message,
2605 real_rates, rates_num);
2608 os_free(real_rates);
2613 static DBusMessage * wpas_dbus_get_bss_security_prop(
2614 DBusMessage *message, struct wpa_ie_data *ie_data)
2617 DBusMessageIter iter, iter_dict, variant_iter;
2619 const char *pairwise[2]; /* max 2 pairwise ciphers is supported */
2620 const char *key_mgmt[7]; /* max 7 key managements may be supported */
2623 if (message == NULL)
2624 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
2626 reply = dbus_message_new_method_return(message);
2630 dbus_message_iter_init_append(reply, &iter);
2631 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
2632 "a{sv}", &variant_iter))
2635 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
2640 if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK)
2641 key_mgmt[n++] = "wpa-psk";
2642 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK)
2643 key_mgmt[n++] = "wpa-ft-psk";
2644 if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
2645 key_mgmt[n++] = "wpa-psk-sha256";
2646 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X)
2647 key_mgmt[n++] = "wpa-eap";
2648 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
2649 key_mgmt[n++] = "wpa-ft-eap";
2650 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
2651 key_mgmt[n++] = "wpa-eap-sha256";
2652 if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
2653 key_mgmt[n++] = "wpa-none";
2655 if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt",
2660 switch (ie_data->group_cipher) {
2661 case WPA_CIPHER_WEP40:
2664 case WPA_CIPHER_TKIP:
2667 case WPA_CIPHER_CCMP:
2670 case WPA_CIPHER_WEP104:
2678 if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
2683 if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
2684 pairwise[n++] = "tkip";
2685 if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
2686 pairwise[n++] = "ccmp";
2688 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
2692 /* Management group (RSN only) */
2693 if (ie_data->proto == WPA_PROTO_RSN) {
2694 switch (ie_data->mgmt_group_cipher) {
2695 #ifdef CONFIG_IEEE80211W
2696 case WPA_CIPHER_AES_128_CMAC:
2697 group = "aes128cmac";
2699 #endif /* CONFIG_IEEE80211W */
2705 if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
2710 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
2712 if (!dbus_message_iter_close_container(&iter, &variant_iter))
2719 dbus_message_unref(reply);
2721 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
2726 * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
2727 * @message: Pointer to incoming dbus message
2728 * @bss: a pair of interface describing structure and bss's id
2729 * Returns: a dbus message containing the WPA options of requested bss
2731 * Getter for "WPA" property.
2733 DBusMessage * wpas_dbus_getter_bss_wpa(DBusMessage *message,
2734 struct bss_handler_args *bss)
2736 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2737 struct wpa_ie_data wpa_data;
2741 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_wpa[dbus]: no "
2742 "bss with id %d found", bss->id);
2746 os_memset(&wpa_data, 0, sizeof(wpa_data));
2747 ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
2749 if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0)
2750 return wpas_dbus_error_unknown_error(message,
2754 return wpas_dbus_get_bss_security_prop(message, &wpa_data);
2759 * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
2760 * @message: Pointer to incoming dbus message
2761 * @bss: a pair of interface describing structure and bss's id
2762 * Returns: a dbus message containing the RSN options of requested bss
2764 * Getter for "RSN" property.
2766 DBusMessage * wpas_dbus_getter_bss_rsn(DBusMessage *message,
2767 struct bss_handler_args *bss)
2769 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2770 struct wpa_ie_data wpa_data;
2774 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rsn[dbus]: no "
2775 "bss with id %d found", bss->id);
2779 os_memset(&wpa_data, 0, sizeof(wpa_data));
2780 ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
2782 if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0)
2783 return wpas_dbus_error_unknown_error(message,
2787 return wpas_dbus_get_bss_security_prop(message, &wpa_data);
2792 * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
2793 * @message: Pointer to incoming dbus message
2794 * @bss: a pair of interface describing structure and bss's id
2795 * Returns: a dbus message containing IEs byte array
2797 * Getter for "IEs" property.
2799 DBusMessage * wpas_dbus_getter_bss_ies(DBusMessage *message,
2800 struct bss_handler_args *bss)
2802 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2805 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ies[dbus]: no "
2806 "bss with id %d found", bss->id);
2810 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2811 res + 1, res->ie_len);
2816 * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
2817 * @message: Pointer to incoming dbus message
2818 * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
2819 * and wpa_ssid structure for a configured network
2820 * Returns: DBus message with boolean indicating state of configured network
2821 * or DBus error on failure
2823 * Getter for "enabled" property of a configured network.
2825 DBusMessage * wpas_dbus_getter_enabled(DBusMessage *message,
2826 struct network_handler_args *net)
2828 dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
2829 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
2835 * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
2836 * @message: Pointer to incoming dbus message
2837 * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
2838 * and wpa_ssid structure for a configured network
2839 * Returns: NULL indicating success or DBus error on failure
2841 * Setter for "Enabled" property of a configured network.
2843 DBusMessage * wpas_dbus_setter_enabled(DBusMessage *message,
2844 struct network_handler_args *net)
2846 DBusMessage *reply = NULL;
2848 struct wpa_supplicant *wpa_s;
2849 struct wpa_ssid *ssid;
2853 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
2863 wpa_supplicant_enable_network(wpa_s, ssid);
2865 wpa_supplicant_disable_network(wpa_s, ssid);
2872 * wpas_dbus_getter_network_properties - Get options for a configured network
2873 * @message: Pointer to incoming dbus message
2874 * @net: wpa_supplicant structure for a network interface and
2875 * wpa_ssid structure for a configured network
2876 * Returns: DBus message with network properties or DBus error on failure
2878 * Getter for "Properties" property of a configured network.
2880 DBusMessage * wpas_dbus_getter_network_properties(
2881 DBusMessage *message, struct network_handler_args *net)
2883 DBusMessage *reply = NULL;
2884 DBusMessageIter iter, variant_iter, dict_iter;
2886 char **props = wpa_config_get_all(net->ssid, 0);
2888 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2891 if (message == NULL)
2892 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
2894 reply = dbus_message_new_method_return(message);
2896 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2901 dbus_message_iter_init_append(reply, &iter);
2903 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
2904 "a{sv}", &variant_iter) ||
2905 !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
2906 dbus_message_unref(reply);
2907 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2914 if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
2916 dbus_message_unref(reply);
2917 reply = dbus_message_new_error(message,
2918 DBUS_ERROR_NO_MEMORY,
2926 if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
2927 !dbus_message_iter_close_container(&iter, &variant_iter)) {
2928 dbus_message_unref(reply);
2929 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2946 * wpas_dbus_setter_network_properties - Set options for a configured network
2947 * @message: Pointer to incoming dbus message
2948 * @net: wpa_supplicant structure for a network interface and
2949 * wpa_ssid structure for a configured network
2950 * Returns: NULL indicating success or DBus error on failure
2952 * Setter for "Properties" property of a configured network.
2954 DBusMessage * wpas_dbus_setter_network_properties(
2955 DBusMessage *message, struct network_handler_args *net)
2957 struct wpa_ssid *ssid = net->ssid;
2959 DBusMessage *reply = NULL;
2960 DBusMessageIter iter, variant_iter;
2962 dbus_message_iter_init(message, &iter);
2964 dbus_message_iter_next(&iter);
2965 dbus_message_iter_next(&iter);
2967 dbus_message_iter_recurse(&iter, &variant_iter);
2969 reply = set_network_properties(message, net->wpa_s, ssid,
2972 wpa_printf(MSG_DEBUG, "dbus control interface couldn't set "
2973 "network properties");