2 * WPA Supplicant / dbus-based control interface
3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4 * Copyright (c) 2009, 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 "../config.h"
24 #include "../wpa_supplicant_i.h"
25 #include "../driver_i.h"
26 #include "../notify.h"
27 #include "../wpas_glue.h"
29 #include "dbus_new_helpers.h"
31 #include "dbus_new_handlers.h"
32 #include "dbus_dict_helpers.h"
34 extern int wpa_debug_level;
35 extern int wpa_debug_show_keys;
36 extern int wpa_debug_timestamp;
40 * wpas_dbus_new_decompose_object_path - Decompose an interface object path into parts
41 * @path: The dbus object path
42 * @network: (out) the configured network this object path refers to, if any
43 * @bssid: (out) the scanned bssid this object path refers to, if any
44 * Returns: The object path of the network interface this path refers to
46 * For a given object path, decomposes the object path into object id, network,
47 * and BSSID parts, if those parts exist.
49 static char * wpas_dbus_new_decompose_object_path(const char *path,
53 const unsigned int dev_path_prefix_len =
54 strlen(WPAS_DBUS_NEW_PATH_INTERFACES "/");
58 /* Be a bit paranoid about path */
59 if (!path || os_strncmp(path, WPAS_DBUS_NEW_PATH_INTERFACES "/",
63 /* Ensure there's something at the end of the path */
64 if ((path + dev_path_prefix_len)[0] == '\0')
67 obj_path_only = os_strdup(path);
68 if (obj_path_only == NULL)
71 next_sep = os_strchr(obj_path_only + dev_path_prefix_len, '/');
72 if (next_sep != NULL) {
73 const char *net_part = os_strstr(
74 next_sep, WPAS_DBUS_NEW_NETWORKS_PART "/");
75 const char *bssid_part = os_strstr(
76 next_sep, WPAS_DBUS_NEW_BSSIDS_PART "/");
78 if (network && net_part) {
79 /* Deal with a request for a configured network */
80 const char *net_name = net_part +
81 os_strlen(WPAS_DBUS_NEW_NETWORKS_PART "/");
83 if (os_strlen(net_name))
84 *network = os_strdup(net_name);
85 } else if (bssid && bssid_part) {
86 /* Deal with a request for a scanned BSSID */
87 const char *bssid_name = bssid_part +
88 os_strlen(WPAS_DBUS_NEW_BSSIDS_PART "/");
89 if (strlen(bssid_name))
90 *bssid = os_strdup(bssid_name);
95 /* Cut off interface object path before "/" */
104 * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
105 * @message: Pointer to incoming dbus message this error refers to
106 * @arg: Optional string appended to error message
107 * Returns: a dbus error message
109 * Convenience function to create and return an UnknownError
111 DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
114 return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
120 * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
121 * @message: Pointer to incoming dbus message this error refers to
122 * Returns: A dbus error message
124 * Convenience function to create and return an invalid interface error
126 static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
128 return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
129 "wpa_supplicant knows nothing about "
135 * wpas_dbus_error_network_unknown - Return a new NetworkUnknown error message
136 * @message: Pointer to incoming dbus message this error refers to
137 * Returns: a dbus error message
139 * Convenience function to create and return an invalid network error
141 static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
143 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
144 "There is no such a network in this "
150 * wpas_dbus_error_invald_args - Return a new InvalidArgs error message
151 * @message: Pointer to incoming dbus message this error refers to
152 * Returns: a dbus error message
154 * Convenience function to create and return an invalid options error
156 DBusMessage * wpas_dbus_error_invald_args(DBusMessage *message,
161 reply = dbus_message_new_error(message, WPAS_DBUS_ERROR_INVALID_ARGS,
162 "Did not receive correct message "
165 dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
172 static const char *dont_quote[] = {
173 "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
174 "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
178 static dbus_bool_t should_quote_opt(const char *key)
181 while (dont_quote[i] != NULL) {
182 if (os_strcmp(key, dont_quote[i]) == 0)
190 * get_iface_by_dbus_path - Get a new network interface
191 * @global: Pointer to global data from wpa_supplicant_init()
192 * @path: Pointer to a dbus object path representing an interface
193 * Returns: Pointer to the interface or %NULL if not found
195 static struct wpa_supplicant * get_iface_by_dbus_path(
196 struct wpa_global *global, const char *path)
198 struct wpa_supplicant *wpa_s;
200 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
201 if (os_strcmp(wpa_s->dbus_new_path, path) == 0)
209 * set_network_properties - Set properties of a configured network
210 * @message: Pointer to incoming dbus message
211 * @ssid: wpa_ssid structure for a configured network
212 * @iter: DBus message iterator containing dictionary of network
214 * Returns: NULL when succeed or DBus error on failure
216 * Sets network configuration with parameters given id DBus dictionary
218 static DBusMessage * set_network_properties(DBusMessage *message,
219 struct wpa_ssid *ssid,
220 DBusMessageIter *iter)
223 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
224 DBusMessage *reply = NULL;
225 DBusMessageIter iter_dict;
227 if (!wpa_dbus_dict_open_read(iter, &iter_dict))
228 return wpas_dbus_error_invald_args(message, NULL);
230 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
234 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) {
235 reply = wpas_dbus_error_invald_args(message, NULL);
238 if (entry.type == DBUS_TYPE_ARRAY &&
239 entry.array_type == DBUS_TYPE_BYTE) {
240 if (entry.array_len <= 0)
243 size = entry.array_len * 2 + 1;
244 value = os_zalloc(size);
248 ret = wpa_snprintf_hex(value, size,
249 (u8 *) entry.bytearray_value,
253 } else if (entry.type == DBUS_TYPE_STRING) {
254 if (should_quote_opt(entry.key)) {
255 size = os_strlen(entry.str_value);
260 value = os_zalloc(size);
264 ret = os_snprintf(value, size, "\"%s\"",
266 if (ret < 0 || (size_t) ret != (size - 1))
269 value = os_strdup(entry.str_value);
273 } else if (entry.type == DBUS_TYPE_UINT32) {
274 value = os_zalloc(size);
278 ret = os_snprintf(value, size, "%u",
282 } else if (entry.type == DBUS_TYPE_INT32) {
283 value = os_zalloc(size);
287 ret = os_snprintf(value, size, "%d",
294 if (wpa_config_set(ssid, entry.key, value, 0) < 0)
297 if ((os_strcmp(entry.key, "psk") == 0 &&
298 value[0] == '"' && ssid->ssid_len) ||
299 (strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
300 wpa_config_update_psk(ssid);
303 wpa_dbus_dict_entry_clear(&entry);
308 reply = wpas_dbus_error_invald_args(message, entry.key);
309 wpa_dbus_dict_entry_clear(&entry);
317 static const char * _get_dbus_type_as_string(const int type)
321 return DBUS_TYPE_BYTE_AS_STRING;
322 case DBUS_TYPE_BOOLEAN:
323 return DBUS_TYPE_BOOLEAN_AS_STRING;
324 case DBUS_TYPE_INT16:
325 return DBUS_TYPE_INT16_AS_STRING;
326 case DBUS_TYPE_UINT16:
327 return DBUS_TYPE_UINT16_AS_STRING;
328 case DBUS_TYPE_INT32:
329 return DBUS_TYPE_INT32_AS_STRING;
330 case DBUS_TYPE_UINT32:
331 return DBUS_TYPE_UINT32_AS_STRING;
332 case DBUS_TYPE_INT64:
333 return DBUS_TYPE_INT64_AS_STRING;
334 case DBUS_TYPE_UINT64:
335 return DBUS_TYPE_UINT64_AS_STRING;
336 case DBUS_TYPE_DOUBLE:
337 return DBUS_TYPE_DOUBLE_AS_STRING;
338 case DBUS_TYPE_STRING:
339 return DBUS_TYPE_STRING_AS_STRING;
340 case DBUS_TYPE_OBJECT_PATH:
341 return DBUS_TYPE_OBJECT_PATH_AS_STRING;
349 * wpas_dbus_simple_property_getter - Get basic type property
350 * @message: Pointer to incoming dbus message
351 * @type: DBus type of property (must be basic type)
352 * @val: pointer to place holding property value
353 * Returns: The DBus message containing response for Properties.Get call
354 * or DBus error message if error occurred.
356 * Generic getter for basic type properties. Type is required to be basic.
358 DBusMessage * wpas_dbus_simple_property_getter(DBusMessage *message,
359 const int type, const void *val)
361 DBusMessage *reply = NULL;
362 DBusMessageIter iter, variant_iter;
364 if (!dbus_type_is_basic(type)) {
365 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
366 " given type is not basic");
367 return wpas_dbus_error_unknown_error(message, NULL);
371 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
373 reply = dbus_message_new_method_return(message);
376 dbus_message_iter_init_append(reply, &iter);
377 if (!dbus_message_iter_open_container(
378 &iter, DBUS_TYPE_VARIANT,
379 _get_dbus_type_as_string(type), &variant_iter) ||
380 !dbus_message_iter_append_basic(&variant_iter, type,
382 !dbus_message_iter_close_container(&iter, &variant_iter)) {
383 wpa_printf(MSG_ERROR, "dbus: "
384 "wpas_dbus_simple_property_getter: out of "
385 "memory to put property value into "
387 dbus_message_unref(reply);
388 reply = dbus_message_new_error(message,
389 DBUS_ERROR_NO_MEMORY,
393 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_getter:"
394 " out of memory to return property value");
395 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
404 * wpas_dbus_simple_property_setter - Set basic type property
405 * @message: Pointer to incoming dbus message
406 * @type: DBus type of property (must be basic type)
407 * @val: pointer to place where value being set will be stored
408 * Returns: NULL or DBus error message if error occurred.
410 * Generic setter for basic type properties. Type is required to be basic.
412 DBusMessage * wpas_dbus_simple_property_setter(DBusMessage *message,
413 const int type, void *val)
415 DBusMessageIter iter, variant_iter;
417 if (!dbus_type_is_basic(type)) {
418 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
419 " given type is not basic");
420 return wpas_dbus_error_unknown_error(message, NULL);
423 if (!dbus_message_iter_init(message, &iter)) {
424 wpa_printf(MSG_ERROR, "dbus: wpas_dbus_simple_property_setter:"
425 " out of memory to return scanning state");
426 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
430 /* omit first and second argument and get value from third */
431 dbus_message_iter_next(&iter);
432 dbus_message_iter_next(&iter);
433 dbus_message_iter_recurse(&iter, &variant_iter);
435 if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
436 return wpas_dbus_error_invald_args(message,
437 "wrong property type");
439 dbus_message_iter_get_basic(&variant_iter, val);
446 * wpas_dbus_simple_array_property_getter - Get array type property
447 * @message: Pointer to incoming dbus message
448 * @type: DBus type of property array elements (must be basic type)
449 * @array: pointer to array of elements to put into response message
450 * @array_len: length of above array
451 * Returns: The DBus message containing response for Properties.Get call
452 * or DBus error message if error occurred.
454 * Generic getter for array type properties. Array elements type is
455 * required to be basic.
457 DBusMessage * wpas_dbus_simple_array_property_getter(DBusMessage *message,
462 DBusMessage *reply = NULL;
463 DBusMessageIter iter, variant_iter, array_iter;
464 char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
465 const char *sub_type_str;
466 size_t element_size, i;
468 if (!dbus_type_is_basic(type)) {
469 wpa_printf(MSG_ERROR, "dbus: "
470 "wpas_dbus_simple_array_property_getter: given "
471 "type is not basic");
472 return wpas_dbus_error_unknown_error(message, NULL);
475 sub_type_str = _get_dbus_type_as_string(type);
476 type_str[1] = sub_type_str[0];
479 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
481 reply = dbus_message_new_method_return(message);
483 wpa_printf(MSG_ERROR, "dbus: "
484 "wpas_dbus_simple_array_property_getter: out of "
485 "memory to create return message");
486 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
490 dbus_message_iter_init_append(reply, &iter);
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 sub_type_str, &array_iter)) {
496 wpa_printf(MSG_ERROR, "dbus: "
497 "wpas_dbus_simple_array_property_getter: out of "
498 "memory to open container");
499 dbus_message_unref(reply);
500 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
506 case DBUS_TYPE_BOOLEAN:
509 case DBUS_TYPE_INT16:
510 case DBUS_TYPE_UINT16:
511 element_size = sizeof(uint16_t);
513 case DBUS_TYPE_INT32:
514 case DBUS_TYPE_UINT32:
515 element_size = sizeof(uint32_t);
517 case DBUS_TYPE_INT64:
518 case DBUS_TYPE_UINT64:
519 element_size = sizeof(uint64_t);
521 case DBUS_TYPE_DOUBLE:
522 element_size = sizeof(double);
524 case DBUS_TYPE_STRING:
525 case DBUS_TYPE_OBJECT_PATH:
526 element_size = sizeof(char *);
529 wpa_printf(MSG_ERROR, "dbus: "
530 "wpas_dbus_simple_array_property_getter: "
531 "fatal: unknown element type");
536 for (i = 0; i < array_len; i++) {
537 dbus_message_iter_append_basic(&array_iter, type,
538 array + i * element_size);
541 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
542 !dbus_message_iter_close_container(&iter, &variant_iter)) {
543 wpa_printf(MSG_ERROR, "dbus: "
544 "wpas_dbus_simple_array_property_getter: out of "
545 "memory to close container");
546 dbus_message_unref(reply);
547 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
556 * wpas_dbus_handler_create_interface - Request registration of a network iface
557 * @message: Pointer to incoming dbus message
558 * @global: %wpa_supplicant global data structure
559 * Returns: The object path of the new interface object,
560 * or a dbus error message with more information
562 * Handler function for "CreateInterface" method call. Handles requests
563 * by dbus clients to register a network interface that wpa_supplicant
566 DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
567 struct wpa_global *global)
569 DBusMessageIter iter_dict;
570 DBusMessage *reply = NULL;
571 DBusMessageIter iter;
572 struct wpa_dbus_dict_entry entry;
575 char *bridge_ifname = NULL;
577 dbus_message_iter_init(message, &iter);
579 if (!wpa_dbus_dict_open_read(&iter, &iter_dict))
581 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
582 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
584 if (!strcmp(entry.key, "Driver") &&
585 (entry.type == DBUS_TYPE_STRING)) {
586 driver = os_strdup(entry.str_value);
587 wpa_dbus_dict_entry_clear(&entry);
590 } else if (!strcmp(entry.key, "Ifname") &&
591 (entry.type == DBUS_TYPE_STRING)) {
592 ifname = os_strdup(entry.str_value);
593 wpa_dbus_dict_entry_clear(&entry);
596 } else if (!strcmp(entry.key, "BridgeIfname") &&
597 (entry.type == DBUS_TYPE_STRING)) {
598 bridge_ifname = os_strdup(entry.str_value);
599 wpa_dbus_dict_entry_clear(&entry);
600 if (bridge_ifname == NULL)
603 wpa_dbus_dict_entry_clear(&entry);
609 goto error; /* Required Ifname argument missing */
612 * Try to get the wpa_supplicant record for this iface, return
613 * an error if we already control it.
615 if (wpa_supplicant_get_iface(global, ifname) != NULL) {
616 reply = dbus_message_new_error(message,
617 WPAS_DBUS_ERROR_IFACE_EXISTS,
618 "wpa_supplicant already "
619 "controls this interface.");
621 struct wpa_supplicant *wpa_s;
622 struct wpa_interface iface;
623 os_memset(&iface, 0, sizeof(iface));
624 iface.driver = driver;
625 iface.ifname = ifname;
626 iface.bridge_ifname = bridge_ifname;
627 /* Otherwise, have wpa_supplicant attach to it. */
628 if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
629 const char *path = wpa_s->dbus_new_path;
630 reply = dbus_message_new_method_return(message);
631 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
632 &path, DBUS_TYPE_INVALID);
634 reply = wpas_dbus_error_unknown_error(
635 message, "wpa_supplicant couldn't grab this "
643 os_free(bridge_ifname);
647 reply = wpas_dbus_error_invald_args(message, NULL);
653 * wpas_dbus_handler_remove_interface - Request deregistration of an interface
654 * @message: Pointer to incoming dbus message
655 * @global: wpa_supplicant global data structure
656 * Returns: a dbus message containing a UINT32 indicating success (1) or
657 * failure (0), or returns a dbus error message with more information
659 * Handler function for "removeInterface" method call. Handles requests
660 * by dbus clients to deregister a network interface that wpa_supplicant
663 DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
664 struct wpa_global *global)
666 struct wpa_supplicant *wpa_s;
668 DBusMessage *reply = NULL;
670 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
673 wpa_s = get_iface_by_dbus_path(global, path);
675 reply = wpas_dbus_error_iface_unknown(message);
676 else if (wpa_supplicant_remove_iface(global, wpa_s)) {
677 reply = wpas_dbus_error_unknown_error(
678 message, "wpa_supplicant couldn't remove this "
687 * wpas_dbus_handler_get_interface - Get the object path for an interface name
688 * @message: Pointer to incoming dbus message
689 * @global: %wpa_supplicant global data structure
690 * Returns: The object path of the interface object,
691 * or a dbus error message with more information
693 * Handler function for "getInterface" method call.
695 DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
696 struct wpa_global *global)
698 DBusMessage *reply = NULL;
701 struct wpa_supplicant *wpa_s;
703 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &ifname,
706 wpa_s = wpa_supplicant_get_iface(global, ifname);
708 return wpas_dbus_error_iface_unknown(message);
710 path = wpa_s->dbus_new_path;
711 reply = dbus_message_new_method_return(message);
713 perror("wpas_dbus_handler_get_interface[dbus]: out of memory "
714 "when creating reply");
715 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
718 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
719 DBUS_TYPE_INVALID)) {
720 perror("wpas_dbus_handler_get_interface[dbus]: out of memory "
721 "when appending argument to reply");
722 dbus_message_unref(reply);
723 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
732 * wpas_dbus_getter_debug_level - Get debug level
733 * @message: Pointer to incoming dbus message
734 * @global: %wpa_supplicant global data structure
735 * Returns: DBus message with value of debug level
737 * Getter for "DebugLevel" property.
739 DBusMessage * wpas_dbus_getter_debug_level(DBusMessage *message,
740 struct wpa_global *global)
742 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BYTE,
749 * wpas_dbus_getter_debug_timestamp - Get debug timestamp
750 * @message: Pointer to incoming dbus message
751 * @global: %wpa_supplicant global data structure
752 * Returns: DBus message with value of debug timestamp
754 * Getter for "DebugTimestamp" property.
756 DBusMessage * wpas_dbus_getter_debug_timestamp(DBusMessage *message,
757 struct wpa_global *global)
759 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
760 &wpa_debug_timestamp);
766 * wpas_dbus_getter_debug_show_keys - Get debug show keys
767 * @message: Pointer to incoming dbus message
768 * @global: %wpa_supplicant global data structure
769 * Returns: DBus message with value of debug show_keys
771 * Getter for "DebugShowKeys" property.
773 DBusMessage * wpas_dbus_getter_debug_show_keys(DBusMessage *message,
774 struct wpa_global *global)
776 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
777 &wpa_debug_show_keys);
782 * wpas_dbus_setter_debug_level - Set debug level
783 * @message: Pointer to incoming dbus message
784 * @global: %wpa_supplicant global data structure
785 * Returns: %NULL or DBus error message
787 * Setter for "DebugLevel" property.
789 DBusMessage * wpas_dbus_setter_debug_level(DBusMessage *message,
790 struct wpa_global *global)
792 DBusMessage *reply = NULL;
795 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_INT16,
800 if (wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
801 wpa_debug_show_keys)) {
802 dbus_message_unref(reply);
803 return wpas_dbus_error_invald_args(
804 message, "Wrong debug level value");
812 * wpas_dbus_setter_debug_timestamp - Set debug timestamp
813 * @message: Pointer to incoming dbus message
814 * @global: %wpa_supplicant global data structure
815 * Returns: %NULL or DBus error message
817 * Setter for "DebugTimestamp" property.
819 DBusMessage * wpas_dbus_setter_debug_timestamp(DBusMessage *message,
820 struct wpa_global *global)
822 DBusMessage *reply = NULL;
825 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
830 wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
831 wpa_debug_show_keys);
838 * wpas_dbus_setter_debug_show_keys - Set debug show keys
839 * @message: Pointer to incoming dbus message
840 * @global: %wpa_supplicant global data structure
841 * Returns: %NULL or DBus error message
843 * Setter for "DebugShowKeys" property.
845 DBusMessage * wpas_dbus_setter_debug_show_keys(DBusMessage *message,
846 struct wpa_global *global)
848 DBusMessage *reply = NULL;
851 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
856 wpa_supplicant_set_debug_params(global, wpa_debug_level,
865 * wpas_dbus_getter_interfaces - Request registered interfaces list
866 * @message: Pointer to incoming dbus message
867 * @global: %wpa_supplicant global data structure
868 * Returns: The object paths array containing registered interfaces
869 * objects paths or DBus error on failure
871 * Getter for "Interfaces" property. Handles requests
872 * by dbus clients to return list of registered interfaces objects
875 DBusMessage * wpas_dbus_getter_interfaces(DBusMessage *message,
876 struct wpa_global *global)
878 DBusMessage *reply = NULL;
879 struct wpa_supplicant *wpa_s;
881 unsigned int i = 0, num = 0;
883 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
886 paths = os_zalloc(num * sizeof(char*));
888 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
892 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
893 paths[i] = wpa_s->dbus_new_path;
895 reply = wpas_dbus_simple_array_property_getter(message,
896 DBUS_TYPE_OBJECT_PATH,
905 * wpas_dbus_getter_eap_methods - Request supported EAP methods list
906 * @message: Pointer to incoming dbus message
907 * @nothing: not used argument. may be NULL or anything else
908 * Returns: The object paths array containing supported EAP methods
909 * represented by strings or DBus error on failure
911 * Getter for "EapMethods" property. Handles requests
912 * by dbus clients to return list of strings with supported EAP methods
914 DBusMessage * wpas_dbus_getter_eap_methods(DBusMessage *message, void *nothing)
916 DBusMessage *reply = NULL;
918 size_t num_items = 0;
920 eap_methods = eap_get_names_as_string_array(&num_items);
922 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
926 reply = wpas_dbus_simple_array_property_getter(message,
928 eap_methods, num_items);
931 os_free(eap_methods[--num_items]);
932 os_free(eap_methods);
937 static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
938 char **type, DBusMessage **reply)
940 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
941 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
942 "Type must be a string");
943 *reply = wpas_dbus_error_invald_args(
944 message, "Wrong Type value type. String required");
947 dbus_message_iter_get_basic(var, type);
952 static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
953 struct wpa_driver_scan_params *params,
956 struct wpa_driver_scan_ssid *ssids = params->ssids;
957 size_t ssids_num = 0;
959 DBusMessageIter array_iter, sub_array_iter;
963 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
964 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
965 "must be an array of arrays of bytes");
966 *reply = wpas_dbus_error_invald_args(
967 message, "Wrong SSIDs value type. Array of arrays of "
972 dbus_message_iter_recurse(var, &array_iter);
974 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
975 dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
977 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
978 "must be an array of arrays of bytes");
979 *reply = wpas_dbus_error_invald_args(
980 message, "Wrong SSIDs value type. Array of arrays of "
985 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
987 if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
988 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
989 "Too many ssids specified on scan dbus "
991 *reply = wpas_dbus_error_invald_args(
992 message, "Too many ssids specified. Specify "
997 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
999 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1001 dbus_message_iter_next(&array_iter);
1005 ssid = os_malloc(len);
1007 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1008 "out of memory. Cannot allocate memory for "
1010 *reply = dbus_message_new_error(
1011 message, DBUS_ERROR_NO_MEMORY, NULL);
1014 os_memcpy(ssid, val, len);
1015 ssids[ssids_num].ssid = ssid;
1016 ssids[ssids_num].ssid_len = len;
1018 dbus_message_iter_next(&array_iter);
1022 params->num_ssids = ssids_num;
1027 static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
1028 struct wpa_driver_scan_params *params,
1029 DBusMessage **reply)
1031 u8 *ies = NULL, *nies;
1033 DBusMessageIter array_iter, sub_array_iter;
1037 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1038 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
1039 "be an array of arrays of bytes");
1040 *reply = wpas_dbus_error_invald_args(
1041 message, "Wrong IEs value type. Array of arrays of "
1046 dbus_message_iter_recurse(var, &array_iter);
1048 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
1049 dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
1051 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
1052 "be an array of arrays of bytes");
1053 *reply = wpas_dbus_error_invald_args(
1054 message, "Wrong IEs value type. Array required");
1058 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
1060 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1062 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1064 dbus_message_iter_next(&array_iter);
1068 nies = os_realloc(ies, ies_len + len);
1070 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1071 "out of memory. Cannot allocate memory for "
1074 *reply = dbus_message_new_error(
1075 message, DBUS_ERROR_NO_MEMORY, NULL);
1079 os_memcpy(ies + ies_len, val, len);
1082 dbus_message_iter_next(&array_iter);
1085 params->extra_ies = ies;
1086 params->extra_ies_len = ies_len;
1091 static int wpas_dbus_get_scan_channels(DBusMessage *message,
1092 DBusMessageIter *var,
1093 struct wpa_driver_scan_params *params,
1094 DBusMessage **reply)
1096 DBusMessageIter array_iter, sub_array_iter;
1097 int *freqs = NULL, *nfreqs;
1100 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1101 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1102 "Channels must be an array of structs");
1103 *reply = wpas_dbus_error_invald_args(
1104 message, "Wrong Channels value type. Array of structs "
1109 dbus_message_iter_recurse(var, &array_iter);
1111 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
1112 wpa_printf(MSG_DEBUG,
1113 "wpas_dbus_handler_scan[dbus]: Channels must be an "
1114 "array of structs");
1115 *reply = wpas_dbus_error_invald_args(
1116 message, "Wrong Channels value type. Array of structs "
1121 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
1125 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1127 if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
1129 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1130 "Channel must by specified by struct of "
1132 dbus_message_iter_get_arg_type(
1134 *reply = wpas_dbus_error_invald_args(
1135 message, "Wrong Channel struct. Two UINT32s "
1140 dbus_message_iter_get_basic(&sub_array_iter, &freq);
1142 if (!dbus_message_iter_next(&sub_array_iter) ||
1143 dbus_message_iter_get_arg_type(&sub_array_iter) !=
1145 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1146 "Channel must by specified by struct of "
1148 *reply = wpas_dbus_error_invald_args(
1150 "Wrong Channel struct. Two UINT32s required");
1155 dbus_message_iter_get_basic(&sub_array_iter, &width);
1157 #define FREQS_ALLOC_CHUNK 32
1158 if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
1159 nfreqs = os_realloc(freqs, sizeof(int) *
1160 (freqs_num + FREQS_ALLOC_CHUNK));
1165 if (freqs == NULL) {
1166 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1167 "out of memory. can't allocate memory for "
1169 *reply = dbus_message_new_error(
1170 message, DBUS_ERROR_NO_MEMORY, NULL);
1174 freqs[freqs_num] = freq;
1177 dbus_message_iter_next(&array_iter);
1180 nfreqs = os_realloc(freqs,
1181 sizeof(int) * (freqs_num + 1));
1185 if (freqs == NULL) {
1186 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1187 "out of memory. Can't allocate memory for freqs");
1188 *reply = dbus_message_new_error(
1189 message, DBUS_ERROR_NO_MEMORY, NULL);
1192 freqs[freqs_num] = 0;
1194 params->freqs = freqs;
1200 * wpas_dbus_handler_scan - Request a wireless scan on an interface
1201 * @message: Pointer to incoming dbus message
1202 * @wpa_s: wpa_supplicant structure for a network interface
1203 * Returns: NULL indicating success or DBus error message on failure
1205 * Handler function for "Scan" method call of a network device. Requests
1206 * that wpa_supplicant perform a wireless scan as soon as possible
1207 * on a particular wireless interface.
1209 DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
1210 struct wpa_supplicant *wpa_s)
1212 DBusMessage *reply = NULL;
1213 DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
1214 char *key = NULL, *type = NULL;
1215 struct wpa_driver_scan_params params;
1218 os_memset(¶ms, 0, sizeof(params));
1220 dbus_message_iter_init(message, &iter);
1222 dbus_message_iter_recurse(&iter, &dict_iter);
1224 while (dbus_message_iter_get_arg_type(&dict_iter) ==
1225 DBUS_TYPE_DICT_ENTRY) {
1226 dbus_message_iter_recurse(&dict_iter, &entry_iter);
1227 dbus_message_iter_get_basic(&entry_iter, &key);
1228 dbus_message_iter_next(&entry_iter);
1229 dbus_message_iter_recurse(&entry_iter, &variant_iter);
1231 if (os_strcmp(key, "Type") == 0) {
1232 if (wpas_dbus_get_scan_type(message, &variant_iter,
1235 } else if (os_strcmp(key, "SSIDs") == 0) {
1236 if (wpas_dbus_get_scan_ssids(message, &variant_iter,
1237 ¶ms, &reply) < 0)
1239 } else if (os_strcmp(key, "IEs") == 0) {
1240 if (wpas_dbus_get_scan_ies(message, &variant_iter,
1241 ¶ms, &reply) < 0)
1243 } else if (os_strcmp(key, "Channels") == 0) {
1244 if (wpas_dbus_get_scan_channels(message, &variant_iter,
1245 ¶ms, &reply) < 0)
1248 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1249 "Unknown argument %s", key);
1250 reply = wpas_dbus_error_invald_args(message, key);
1254 dbus_message_iter_next(&dict_iter);
1258 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1259 "Scan type not specified");
1260 reply = wpas_dbus_error_invald_args(message, key);
1264 if (!os_strcmp(type, "passive")) {
1265 if (params.num_ssids || params.extra_ies_len) {
1266 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1267 "SSIDs or IEs specified for passive scan.");
1268 reply = wpas_dbus_error_invald_args(
1269 message, "You can specify only Channels in "
1272 } else if (params.freqs && params.freqs[0]) {
1275 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1277 wpa_s->scan_req = 2;
1278 wpa_supplicant_req_scan(wpa_s, 0, 0);
1280 } else if (!os_strcmp(type, "active")) {
1281 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1283 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1284 "Unknown scan type: %s", type);
1285 reply = wpas_dbus_error_invald_args(message,
1291 for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
1292 os_free((u8 *) params.ssids[i].ssid);
1293 os_free((u8 *) params.extra_ies);
1294 os_free(params.freqs);
1300 * wpas_dbus_handler_disconnect - Terminate the current connection
1301 * @message: Pointer to incoming dbus message
1302 * @wpa_s: wpa_supplicant structure for a network interface
1303 * Returns: NotConnected DBus error message if already not connected
1304 * or NULL otherwise.
1306 * Handler function for "Disconnect" method call of network interface.
1308 DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
1309 struct wpa_supplicant *wpa_s)
1311 if (wpa_s->current_ssid != NULL) {
1312 wpa_s->disconnected = 1;
1313 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1318 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
1319 "This interface is not connected");
1324 * wpas_dbus_new_iface_add_network - Add a new configured network
1325 * @message: Pointer to incoming dbus message
1326 * @wpa_s: wpa_supplicant structure for a network interface
1327 * Returns: A dbus message containing the object path of the new network
1329 * Handler function for "AddNetwork" method call of a network interface.
1331 DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
1332 struct wpa_supplicant *wpa_s)
1334 DBusMessage *reply = NULL;
1335 DBusMessageIter iter;
1336 struct wpa_ssid *ssid = NULL;
1339 path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
1341 perror("wpas_dbus_handler_add_network[dbus]: out of "
1343 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1348 dbus_message_iter_init(message, &iter);
1350 ssid = wpa_config_add_network(wpa_s->conf);
1352 wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
1353 "can't add new interface.");
1354 reply = wpas_dbus_error_unknown_error(
1356 "wpa_supplicant could not add "
1357 "a network on this interface.");
1360 wpas_notify_network_added(wpa_s, ssid);
1362 wpa_config_set_network_defaults(ssid);
1364 reply = set_network_properties(message, ssid, &iter);
1366 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
1367 "control interface couldn't set network "
1372 /* Construct the object path for this network. */
1373 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1374 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
1375 wpa_s->dbus_new_path, ssid->id);
1377 reply = dbus_message_new_method_return(message);
1378 if (reply == NULL) {
1379 perror("wpas_dbus_handler_add_network[dbus]: out of memory "
1380 "when creating reply");
1381 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1385 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
1386 DBUS_TYPE_INVALID)) {
1387 perror("wpas_dbus_handler_add_network[dbus]: out of memory "
1388 "when appending argument to reply");
1389 dbus_message_unref(reply);
1390 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1400 wpas_notify_network_removed(wpa_s, ssid);
1401 wpa_config_remove_network(wpa_s->conf, ssid->id);
1409 * wpas_dbus_handler_remove_network - Remove a configured network
1410 * @message: Pointer to incoming dbus message
1411 * @wpa_s: wpa_supplicant structure for a network interface
1412 * Returns: NULL on success or dbus error on failure
1414 * Handler function for "RemoveNetwork" method call of a network interface.
1416 DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
1417 struct wpa_supplicant *wpa_s)
1419 DBusMessage *reply = NULL;
1421 char *iface = NULL, *net_id = NULL;
1423 struct wpa_ssid *ssid;
1425 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1428 /* Extract the network ID and ensure the network */
1429 /* is actually a child of this interface */
1430 iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
1431 if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1432 reply = wpas_dbus_error_invald_args(message, op);
1436 id = strtoul(net_id, NULL, 10);
1437 if (errno == EINVAL) {
1438 reply = wpas_dbus_error_invald_args(message, op);
1442 ssid = wpa_config_get_network(wpa_s->conf, id);
1444 reply = wpas_dbus_error_network_unknown(message);
1448 wpas_notify_network_removed(wpa_s, ssid);
1450 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
1451 wpa_printf(MSG_ERROR,
1452 "wpas_dbus_handler_remove_network[dbus]: "
1453 "error occurred when removing network %d", id);
1454 reply = wpas_dbus_error_unknown_error(
1455 message, "error removing the specified network on "
1460 if (ssid == wpa_s->current_ssid)
1461 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1471 * wpas_dbus_handler_select_network - Attempt association with a network
1472 * @message: Pointer to incoming dbus message
1473 * @wpa_s: wpa_supplicant structure for a network interface
1474 * Returns: NULL on success or dbus error on failure
1476 * Handler function for "SelectNetwork" method call of network interface.
1478 DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
1479 struct wpa_supplicant *wpa_s)
1481 DBusMessage *reply = NULL;
1483 char *iface = NULL, *net_id = NULL;
1485 struct wpa_ssid *ssid;
1487 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1490 /* Extract the network ID and ensure the network */
1491 /* is actually a child of this interface */
1492 iface = wpas_dbus_new_decompose_object_path(op, &net_id, NULL);
1493 if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1494 reply = wpas_dbus_error_invald_args(message, op);
1498 id = strtoul(net_id, NULL, 10);
1499 if (errno == EINVAL) {
1500 reply = wpas_dbus_error_invald_args(message, op);
1504 ssid = wpa_config_get_network(wpa_s->conf, id);
1506 reply = wpas_dbus_error_network_unknown(message);
1510 /* Finally, associate with the network */
1511 wpa_supplicant_select_network(wpa_s, ssid);
1521 * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
1522 * @message: Pointer to incoming dbus message
1523 * @wpa_s: %wpa_supplicant data structure
1524 * Returns: A dbus message containing an error on failure or NULL on success
1526 * Asks wpa_supplicant to internally store a binary blobs.
1528 DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
1529 struct wpa_supplicant *wpa_s)
1531 DBusMessage *reply = NULL;
1532 DBusMessageIter iter, array_iter;
1537 struct wpa_config_blob *blob = NULL;
1539 dbus_message_iter_init(message, &iter);
1540 dbus_message_iter_get_basic(&iter, &blob_name);
1542 if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
1543 return dbus_message_new_error(message,
1544 WPAS_DBUS_ERROR_BLOB_EXISTS,
1548 dbus_message_iter_next(&iter);
1549 dbus_message_iter_recurse(&iter, &array_iter);
1551 dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
1553 blob = os_zalloc(sizeof(*blob));
1555 perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
1556 "trying to allocate blob struct");
1557 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1562 blob->data = os_malloc(blob_len);
1564 perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
1565 "trying to allocate blob data");
1566 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1570 os_memcpy(blob->data, blob_data, blob_len);
1572 blob->len = blob_len;
1573 blob->name = os_strdup(blob_name);
1575 perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
1576 "trying to copy blob name");
1577 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1582 wpa_config_set_blob(wpa_s->conf, blob);
1583 wpas_notify_blob_added(wpa_s, blob->name);
1589 os_free(blob->name);
1590 os_free(blob->data);
1598 * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
1599 * @message: Pointer to incoming dbus message
1600 * @wpa_s: %wpa_supplicant data structure
1601 * Returns: A dbus message containing array of bytes (blob)
1603 * Gets one wpa_supplicant's binary blobs.
1605 DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
1606 struct wpa_supplicant *wpa_s)
1608 DBusMessage *reply = NULL;
1609 DBusMessageIter iter, array_iter;
1612 const struct wpa_config_blob *blob;
1614 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
1617 blob = wpa_config_get_blob(wpa_s->conf, blob_name);
1619 return dbus_message_new_error(message,
1620 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
1624 reply = dbus_message_new_method_return(message);
1626 perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
1627 "trying to allocate return message");
1628 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1633 dbus_message_iter_init_append(reply, &iter);
1635 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
1636 DBUS_TYPE_BYTE_AS_STRING,
1638 dbus_message_unref(reply);
1639 perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
1640 "trying to open array");
1641 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1646 if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
1647 &(blob->data), blob->len)) {
1648 dbus_message_unref(reply);
1649 perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
1650 "trying to append data to array");
1651 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1656 if (!dbus_message_iter_close_container(&iter, &array_iter)) {
1657 dbus_message_unref(reply);
1658 perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
1659 "trying to close array");
1660 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
1671 * wpas_remove_handler_remove_blob - Remove named binary blob
1672 * @message: Pointer to incoming dbus message
1673 * @wpa_s: %wpa_supplicant data structure
1674 * Returns: NULL on success or dbus error
1676 * Asks wpa_supplicant to internally remove a binary blobs.
1678 DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
1679 struct wpa_supplicant *wpa_s)
1681 DBusMessage *reply = NULL;
1684 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
1687 if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
1688 return dbus_message_new_error(message,
1689 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
1692 wpas_notify_blob_removed(wpa_s, blob_name);
1700 * wpas_dbus_getter_capabilities - Return interface capabilities
1701 * @message: Pointer to incoming dbus message
1702 * @wpa_s: wpa_supplicant structure for a network interface
1703 * Returns: A dbus message containing a dict of strings
1705 * Getter for "Capabilities" property of an interface.
1707 DBusMessage * wpas_dbus_getter_capabilities(DBusMessage *message,
1708 struct wpa_supplicant *wpa_s)
1710 DBusMessage *reply = NULL;
1711 struct wpa_driver_capa capa;
1713 DBusMessageIter iter, iter_dict;
1714 DBusMessageIter iter_dict_entry, iter_dict_val, iter_array,
1716 const char *scans[] = { "active", "passive", "ssid" };
1717 const char *modes[] = { "infrastructure", "ad-hoc", "ap" };
1718 int n = sizeof(modes) / sizeof(char *);
1720 if (message == NULL)
1721 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
1723 reply = dbus_message_new_method_return(message);
1727 dbus_message_iter_init_append(reply, &iter);
1728 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
1729 "a{sv}", &variant_iter))
1732 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
1735 res = wpa_drv_get_capa(wpa_s, &capa);
1737 /***** pairwise cipher */
1739 const char *args[] = {"ccmp", "tkip", "none"};
1740 if (!wpa_dbus_dict_append_string_array(
1741 &iter_dict, "Pairwise", args,
1742 sizeof(args) / sizeof(char*)))
1745 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
1751 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1752 if (!wpa_dbus_dict_string_array_add_element(
1753 &iter_array, "ccmp"))
1757 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1758 if (!wpa_dbus_dict_string_array_add_element(
1759 &iter_array, "tkip"))
1763 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1764 if (!wpa_dbus_dict_string_array_add_element(
1765 &iter_array, "none"))
1769 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1776 /***** group cipher */
1778 const char *args[] = {
1779 "ccmp", "tkip", "wep104", "wep40"
1781 if (!wpa_dbus_dict_append_string_array(
1782 &iter_dict, "Group", args,
1783 sizeof(args) / sizeof(char*)))
1786 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
1792 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1793 if (!wpa_dbus_dict_string_array_add_element(
1794 &iter_array, "ccmp"))
1798 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1799 if (!wpa_dbus_dict_string_array_add_element(
1800 &iter_array, "tkip"))
1804 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
1805 if (!wpa_dbus_dict_string_array_add_element(
1806 &iter_array, "wep104"))
1810 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
1811 if (!wpa_dbus_dict_string_array_add_element(
1812 &iter_array, "wep40"))
1816 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1823 /***** key management */
1825 const char *args[] = {
1826 "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
1829 #endif /* CONFIG_WPS */
1832 if (!wpa_dbus_dict_append_string_array(
1833 &iter_dict, "KeyMgmt", args,
1834 sizeof(args) / sizeof(char*)))
1837 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
1843 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
1847 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
1851 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1852 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
1853 if (!wpa_dbus_dict_string_array_add_element(
1854 &iter_array, "wpa-eap"))
1858 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1859 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1860 if (!wpa_dbus_dict_string_array_add_element(
1861 &iter_array, "wpa-psk"))
1865 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1866 if (!wpa_dbus_dict_string_array_add_element(
1867 &iter_array, "wpa-none"))
1873 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
1876 #endif /* CONFIG_WPS */
1878 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1885 /***** WPA protocol */
1887 const char *args[] = { "rsn", "wpa" };
1888 if (!wpa_dbus_dict_append_string_array(
1889 &iter_dict, "Protocol", args,
1890 sizeof(args) / sizeof(char*)))
1893 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
1899 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1900 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1901 if (!wpa_dbus_dict_string_array_add_element(
1902 &iter_array, "rsn"))
1906 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1907 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
1908 if (!wpa_dbus_dict_string_array_add_element(
1909 &iter_array, "wpa"))
1913 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1922 const char *args[] = { "open", "shared", "leap" };
1923 if (!wpa_dbus_dict_append_string_array(
1924 &iter_dict, "AuthAlg", args,
1925 sizeof(args) / sizeof(char*)))
1928 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
1934 if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
1935 if (!wpa_dbus_dict_string_array_add_element(
1936 &iter_array, "open"))
1940 if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
1941 if (!wpa_dbus_dict_string_array_add_element(
1942 &iter_array, "shared"))
1946 if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
1947 if (!wpa_dbus_dict_string_array_add_element(
1948 &iter_array, "leap"))
1952 if (!wpa_dbus_dict_end_string_array(&iter_dict,
1960 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
1961 sizeof(scans) / sizeof(char *)))
1965 if (res < 0 || !(capa.flags & WPA_DRIVER_FLAGS_AP))
1966 n--; /* exclude ap mode if it is not supported by the driver */
1967 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Modes", modes, n))
1970 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
1972 if (!dbus_message_iter_close_container(&iter, &variant_iter))
1979 dbus_message_unref(reply);
1981 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
1986 * wpas_dbus_getter_state - Get interface state
1987 * @message: Pointer to incoming dbus message
1988 * @wpa_s: wpa_supplicant structure for a network interface
1989 * Returns: A dbus message containing a STRING representing the current
1992 * Getter for "State" property.
1994 DBusMessage * wpas_dbus_getter_state(DBusMessage *message,
1995 struct wpa_supplicant *wpa_s)
1997 DBusMessage *reply = NULL;
1998 const char *str_state;
1999 char *state_ls, *tmp;
2001 str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
2003 /* make state string lowercase to fit new DBus API convention
2005 state_ls = tmp = os_strdup(str_state);
2007 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2011 *tmp = tolower(*tmp);
2015 reply = wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2025 * wpas_dbus_new_iface_get_scanning - Get interface scanning state
2026 * @message: Pointer to incoming dbus message
2027 * @wpa_s: wpa_supplicant structure for a network interface
2028 * Returns: A dbus message containing whether the interface is scanning
2030 * Getter for "scanning" property.
2032 DBusMessage * wpas_dbus_getter_scanning(DBusMessage *message,
2033 struct wpa_supplicant *wpa_s)
2035 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
2036 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
2042 * wpas_dbus_getter_ap_scan - Control roaming mode
2043 * @message: Pointer to incoming dbus message
2044 * @wpa_s: wpa_supplicant structure for a network interface
2045 * Returns: A message containong value of ap_scan variable
2047 * Getter function for "ApScan" property.
2049 DBusMessage * wpas_dbus_getter_ap_scan(DBusMessage *message,
2050 struct wpa_supplicant *wpa_s)
2052 dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
2053 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT32,
2059 * wpas_dbus_setter_ap_scan - Control roaming mode
2060 * @message: Pointer to incoming dbus message
2061 * @wpa_s: wpa_supplicant structure for a network interface
2064 * Setter function for "ApScan" property.
2066 DBusMessage * wpas_dbus_setter_ap_scan(DBusMessage *message,
2067 struct wpa_supplicant *wpa_s)
2069 DBusMessage *reply = NULL;
2070 dbus_uint32_t ap_scan;
2072 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_UINT32,
2077 if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
2078 return wpas_dbus_error_invald_args(
2079 message, "ap_scan must equal 0, 1 or 2");
2086 * wpas_dbus_getter_ifname - Get interface name
2087 * @message: Pointer to incoming dbus message
2088 * @wpa_s: wpa_supplicant structure for a network interface
2089 * Returns: A dbus message containing a name of network interface
2090 * associated with with wpa_s
2092 * Getter for "Ifname" property.
2094 DBusMessage * wpas_dbus_getter_ifname(DBusMessage *message,
2095 struct wpa_supplicant *wpa_s)
2097 const char *ifname = wpa_s->ifname;
2098 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2104 * wpas_dbus_getter_driver - Get interface name
2105 * @message: Pointer to incoming dbus message
2106 * @wpa_s: wpa_supplicant structure for a network interface
2107 * Returns: A dbus message containing a name of network interface
2108 * driver associated with with wpa_s
2110 * Getter for "Driver" property.
2112 DBusMessage * wpas_dbus_getter_driver(DBusMessage *message,
2113 struct wpa_supplicant *wpa_s)
2117 if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
2118 wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
2119 "wpa_s has no driver set");
2120 return wpas_dbus_error_unknown_error(message, NULL);
2123 driver = wpa_s->driver->name;
2124 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2130 * wpas_dbus_getter_current_bss - Get current bss object path
2131 * @message: Pointer to incoming dbus message
2132 * @wpa_s: wpa_supplicant structure for a network interface
2133 * Returns: A dbus message containing a DBus object path to
2136 * Getter for "CurrentBSS" property.
2138 DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message,
2139 struct wpa_supplicant *wpa_s)
2141 DBusMessage *reply = NULL;
2142 char *bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2143 struct wpa_bss *bss = NULL;
2145 if (bss_obj_path == NULL) {
2146 perror("wpas_dbus_getter_current_bss[dbus]: out of "
2147 "memory to allocate result argument.");
2148 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2152 /* TODO: store current BSS or BSS id in wpa_s */
2153 if (!is_zero_ether_addr(wpa_s->bssid))
2154 bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2157 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2158 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2159 wpa_s->dbus_new_path, bss->id);
2161 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2163 reply = wpas_dbus_simple_property_getter(message,
2164 DBUS_TYPE_OBJECT_PATH,
2167 os_free(bss_obj_path);
2173 * wpas_dbus_getter_current_network - Get current network object path
2174 * @message: Pointer to incoming dbus message
2175 * @wpa_s: wpa_supplicant structure for a network interface
2176 * Returns: A dbus message containing a DBus object path to
2179 * Getter for "CurrentNetwork" property.
2181 DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message,
2182 struct wpa_supplicant *wpa_s)
2184 DBusMessage *reply = NULL;
2185 char *net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2187 if (net_obj_path == NULL) {
2188 perror("wpas_dbus_getter_current_network[dbus]: out of "
2189 "memory to allocate result argument.");
2190 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2194 if (wpa_s->current_ssid)
2195 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2196 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2197 wpa_s->dbus_new_path, wpa_s->current_ssid->id);
2199 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2201 reply = wpas_dbus_simple_property_getter(message,
2202 DBUS_TYPE_OBJECT_PATH,
2205 os_free(net_obj_path);
2211 * wpas_dbus_getter_bridge_ifname - Get interface name
2212 * @message: Pointer to incoming dbus message
2213 * @wpa_s: wpa_supplicant structure for a network interface
2214 * Returns: A dbus message containing a name of bridge network
2215 * interface associated with with wpa_s
2217 * Getter for "BridgeIfname" property.
2219 DBusMessage * wpas_dbus_getter_bridge_ifname(DBusMessage *message,
2220 struct wpa_supplicant *wpa_s)
2222 const char *bridge_ifname = NULL;
2224 bridge_ifname = wpa_s->bridge_ifname;
2225 if (bridge_ifname == NULL) {
2226 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bridge_ifname[dbus]: "
2227 "wpa_s has no bridge interface name set");
2228 return wpas_dbus_error_unknown_error(message, NULL);
2231 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2237 * wpas_dbus_getter_bsss - Get array of BSSs objects
2238 * @message: Pointer to incoming dbus message
2239 * @wpa_s: wpa_supplicant structure for a network interface
2240 * Returns: a dbus message containing an array of all known BSS objects
2243 * Getter for "BSSs" property.
2245 DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
2246 struct wpa_supplicant *wpa_s)
2248 DBusMessage *reply = NULL;
2249 struct wpa_bss *bss;
2253 paths = os_zalloc(wpa_s->num_bss * sizeof(char *));
2255 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2259 /* Loop through scan results and append each result's object path */
2260 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2261 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2262 if (paths[i] == NULL) {
2263 perror("wpas_dbus_getter_bsss[dbus]: out of "
2265 reply = dbus_message_new_error(message,
2266 DBUS_ERROR_NO_MEMORY,
2270 /* Construct the object path for this BSS. */
2271 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2272 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2273 wpa_s->dbus_new_path, bss->id);
2276 reply = wpas_dbus_simple_array_property_getter(message,
2277 DBUS_TYPE_OBJECT_PATH,
2278 paths, wpa_s->num_bss);
2282 os_free(paths[--i]);
2289 * wpas_dbus_getter_networks - Get array of networks objects
2290 * @message: Pointer to incoming dbus message
2291 * @wpa_s: wpa_supplicant structure for a network interface
2292 * Returns: a dbus message containing an array of all configured
2293 * networks dbus object paths.
2295 * Getter for "Networks" property.
2297 DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
2298 struct wpa_supplicant *wpa_s)
2300 DBusMessage *reply = NULL;
2301 struct wpa_ssid *ssid;
2303 unsigned int i = 0, num = 0;
2305 if (wpa_s->conf == NULL) {
2306 wpa_printf(MSG_ERROR, "wpas_dbus_getter_networks[dbus]: "
2307 "An error occurred getting networks list.");
2308 return wpas_dbus_error_unknown_error(message, NULL);
2311 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
2314 paths = os_zalloc(num * sizeof(char *));
2316 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2320 /* Loop through configured networks and append object path of each */
2321 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
2323 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2324 if (paths[i] == NULL) {
2325 perror("wpas_dbus_getter_networks[dbus]: out of "
2327 reply = dbus_message_new_error(message,
2328 DBUS_ERROR_NO_MEMORY,
2333 /* Construct the object path for this network. */
2334 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2335 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
2336 wpa_s->dbus_new_path, ssid->id);
2339 reply = wpas_dbus_simple_array_property_getter(message,
2340 DBUS_TYPE_OBJECT_PATH,
2345 os_free(paths[--i]);
2352 * wpas_dbus_getter_blobs - Get all blobs defined for this interface
2353 * @message: Pointer to incoming dbus message
2354 * @wpa_s: wpa_supplicant structure for a network interface
2355 * Returns: a dbus message containing a dictionary of pairs (blob_name, blob)
2357 * Getter for "Blobs" property.
2359 DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
2360 struct wpa_supplicant *wpa_s)
2362 DBusMessage *reply = NULL;
2363 DBusMessageIter iter, variant_iter, dict_iter, entry_iter, array_iter;
2364 struct wpa_config_blob *blob;
2366 if (message == NULL)
2367 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
2369 reply = dbus_message_new_method_return(message);
2371 perror("wpas_dbus_getter_blobs[dbus] out of memory when "
2372 "trying to initialize return message");
2373 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2378 dbus_message_iter_init_append(reply, &iter);
2380 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
2381 "a{say}", &variant_iter)) {
2382 dbus_message_unref(reply);
2383 perror("wpas_dbus_getter_blobs[dbus] out of memory when "
2384 "trying to open variant");
2385 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2390 if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
2391 "{say}", &dict_iter)) {
2392 dbus_message_unref(reply);
2393 perror("wpas_dbus_getter_blobs[dbus] out of memory when "
2394 "trying to open dictionary");
2395 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2400 blob = wpa_s->conf->blobs;
2402 if (!dbus_message_iter_open_container(&dict_iter,
2403 DBUS_TYPE_DICT_ENTRY,
2404 NULL, &entry_iter)) {
2405 dbus_message_unref(reply);
2406 perror("wpas_dbus_getter_blobs[dbus] out of memory "
2407 "when trying to open entry");
2408 reply = dbus_message_new_error(message,
2409 DBUS_ERROR_NO_MEMORY,
2414 if (!dbus_message_iter_append_basic(&entry_iter,
2417 dbus_message_unref(reply);
2418 perror("wpas_dbus_getter_blobs[dbus] out of memory "
2419 "when trying to append blob name");
2420 reply = dbus_message_new_error(message,
2421 DBUS_ERROR_NO_MEMORY,
2426 if (!dbus_message_iter_open_container(&entry_iter,
2428 DBUS_TYPE_BYTE_AS_STRING,
2430 dbus_message_unref(reply);
2431 perror("wpas_dbus_getter_blobs[dbus] out of memory "
2432 "when trying to open array");
2433 reply = dbus_message_new_error(message,
2434 DBUS_ERROR_NO_MEMORY,
2439 if (!dbus_message_iter_append_fixed_array(&array_iter,
2443 dbus_message_unref(reply);
2444 perror("wpas_dbus_getter_blobs[dbus] out of memory "
2445 "when trying to append blob data");
2446 reply = dbus_message_new_error(message,
2447 DBUS_ERROR_NO_MEMORY,
2452 if (!dbus_message_iter_close_container(&entry_iter,
2454 dbus_message_unref(reply);
2455 perror("wpas_dbus_getter_blobs[dbus] out of memory "
2456 "when trying to close array");
2457 reply = dbus_message_new_error(message,
2458 DBUS_ERROR_NO_MEMORY,
2463 if (!dbus_message_iter_close_container(&dict_iter,
2465 dbus_message_unref(reply);
2466 perror("wpas_dbus_getter_blobs[dbus] out of memory "
2467 "when trying to close entry");
2468 reply = dbus_message_new_error(message,
2469 DBUS_ERROR_NO_MEMORY,
2477 if (!dbus_message_iter_close_container(&variant_iter, &dict_iter)) {
2478 dbus_message_unref(reply);
2479 perror("wpas_dbus_getter_blobs[dbus] out of memory when "
2480 "trying to close dictionary");
2481 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2486 if (!dbus_message_iter_close_container(&iter, &variant_iter)) {
2487 dbus_message_unref(reply);
2488 perror("wpas_dbus_getter_blobs[dbus] out of memory when "
2489 "trying to close variant");
2490 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2501 * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
2502 * @message: Pointer to incoming dbus message
2503 * @bss: a pair of interface describing structure and bss's id
2504 * Returns: a dbus message containing the bssid for the requested bss
2506 * Getter for "BSSID" property.
2508 DBusMessage * wpas_dbus_getter_bss_bssid(DBusMessage *message,
2509 struct bss_handler_args *bss)
2511 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2514 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_bssid[dbus]: no "
2515 "bss with id %d found", bss->id);
2519 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2520 res->bssid, ETH_ALEN);
2525 * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
2526 * @message: Pointer to incoming dbus message
2527 * @bss: a pair of interface describing structure and bss's id
2528 * Returns: a dbus message containing the ssid for the requested bss
2530 * Getter for "SSID" property.
2532 DBusMessage * wpas_dbus_getter_bss_ssid(DBusMessage *message,
2533 struct bss_handler_args *bss)
2535 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2538 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_ssid[dbus]: no "
2539 "bss with id %d found", bss->id);
2543 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2550 * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
2551 * @message: Pointer to incoming dbus message
2552 * @bss: a pair of interface describing structure and bss's id
2553 * Returns: a dbus message containing the privacy flag value of requested bss
2555 * Getter for "Privacy" property.
2557 DBusMessage * wpas_dbus_getter_bss_privacy(DBusMessage *message,
2558 struct bss_handler_args *bss)
2560 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2561 dbus_bool_t privacy;
2564 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_privacy[dbus]: no "
2565 "bss with id %d found", bss->id);
2569 privacy = res->caps && IEEE80211_CAP_PRIVACY ? TRUE : FALSE;
2570 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
2576 * wpas_dbus_getter_bss_mode - Return the mode of a BSS
2577 * @message: Pointer to incoming dbus message
2578 * @bss: a pair of interface describing structure and bss's id
2579 * Returns: a dbus message containing the mode of requested bss
2581 * Getter for "Mode" property.
2583 DBusMessage * wpas_dbus_getter_bss_mode(DBusMessage *message,
2584 struct bss_handler_args *bss)
2586 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2590 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_mode[dbus]: no "
2591 "bss with id %d found", bss->id);
2595 if (res->caps & IEEE80211_CAP_IBSS)
2598 mode = "infrastructure";
2600 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_STRING,
2606 * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
2607 * @message: Pointer to incoming dbus message
2608 * @bss: a pair of interface describing structure and bss's id
2609 * Returns: a dbus message containing the signal strength of requested bss
2611 * Getter for "Level" property.
2613 DBusMessage * wpas_dbus_getter_bss_signal(DBusMessage *message,
2614 struct bss_handler_args *bss)
2616 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2619 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_signal[dbus]: no "
2620 "bss with id %d found", bss->id);
2624 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_INT16,
2630 * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
2631 * @message: Pointer to incoming dbus message
2632 * @bss: a pair of interface describing structure and bss's id
2633 * Returns: a dbus message containing the frequency of requested bss
2635 * Getter for "Frequency" property.
2637 DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
2638 struct bss_handler_args *bss)
2640 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2643 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_frequency[dbus]: "
2644 "no bss with id %d found", bss->id);
2648 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
2654 * wpas_dbus_getter_bss_max_rate - Return the maximal rate of a BSS
2655 * @message: Pointer to incoming dbus message
2656 * @bss: a pair of interface describing structure and bss's id
2657 * Returns: a dbus message containing the maximal data rate of requested bss
2659 * Getter for "MaxRate" property.
2661 DBusMessage * wpas_dbus_getter_bss_max_rate(DBusMessage *message,
2662 struct bss_handler_args *bss)
2664 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2668 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_max_rate[dbus]: "
2669 "no bss with id %d found", bss->id);
2673 max_rate = wpa_bss_get_max_rate(res);
2674 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
2680 * wpas_dbus_getter_bss_wpaie - Return the WPA IE of a BSS
2681 * @message: Pointer to incoming dbus message
2682 * @bss: a pair of interface describing structure and bss's id
2683 * Returns: a dbus message containing the WPA information elements
2686 * Getter for "WPAIE" property.
2688 DBusMessage * wpas_dbus_getter_bss_wpaie(DBusMessage *message,
2689 struct bss_handler_args *bss)
2691 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2695 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_wpaie[dbus]: no "
2696 "bss with id %d found", bss->id);
2700 ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
2703 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2709 * wpas_dbus_getter_bss_rsnie - Return the RSN IE of a BSS
2710 * @message: Pointer to incoming dbus message
2711 * @bss: a pair of interface describing structure and bss's id
2712 * Returns: a dbus message containing the RSN information elements
2715 * Getter for "RSNIE" property.
2717 DBusMessage * wpas_dbus_getter_bss_rsnie(DBusMessage *message,
2718 struct bss_handler_args *bss)
2720 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2724 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rsnie[dbus]: no "
2725 "bss with id %d found", bss->id);
2729 ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
2732 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2738 * wpas_dbus_getter_bss_wpsie - Return the WPS IE of a BSS
2739 * @message: Pointer to incoming dbus message
2740 * @bss: a pair of interface describing structure and bss's id
2741 * Returns: a dbus message containing the WPS information elements
2744 * Getter for "WPSIE" property.
2746 DBusMessage * wpas_dbus_getter_bss_wpsie(DBusMessage *message,
2747 struct bss_handler_args *bss)
2749 struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
2753 wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_wpsie[dbus]: no "
2754 "bss with id %d found", bss->id);
2758 ie = wpa_bss_get_vendor_ie(res, WPS_IE_VENDOR_TYPE);
2761 return wpas_dbus_simple_array_property_getter(message, DBUS_TYPE_BYTE,
2767 * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
2768 * @message: Pointer to incoming dbus message
2769 * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
2770 * and wpa_ssid structure for a configured network
2771 * Returns: DBus message with boolean indicating state of configured network
2772 * or DBus error on failure
2774 * Getter for "enabled" property of a configured network.
2776 DBusMessage * wpas_dbus_getter_enabled(DBusMessage *message,
2777 struct network_handler_args *net)
2779 dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
2780 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN,
2786 * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
2787 * @message: Pointer to incoming dbus message
2788 * @wpas_dbus_setter_enabled: wpa_supplicant structure for a network interface
2789 * and wpa_ssid structure for a configured network
2790 * Returns: NULL indicating success or DBus error on failure
2792 * Setter for "Enabled" property of a configured network.
2794 DBusMessage * wpas_dbus_setter_enabled(DBusMessage *message,
2795 struct network_handler_args *net)
2797 DBusMessage *reply = NULL;
2799 struct wpa_supplicant *wpa_s;
2800 struct wpa_ssid *ssid;
2804 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN,
2814 wpa_supplicant_enable_network(wpa_s, ssid);
2816 wpa_supplicant_disable_network(wpa_s, ssid);
2823 * wpas_dbus_getter_network_properties - Get options for a configured network
2824 * @message: Pointer to incoming dbus message
2825 * @net: wpa_supplicant structure for a network interface and
2826 * wpa_ssid structure for a configured network
2827 * Returns: DBus message with network properties or DBus error on failure
2829 * Getter for "Properties" property of a configured network.
2831 DBusMessage * wpas_dbus_getter_network_properties(
2832 DBusMessage *message, struct network_handler_args *net)
2834 DBusMessage *reply = NULL;
2835 DBusMessageIter iter, variant_iter, dict_iter;
2837 char **props = wpa_config_get_all(net->ssid, 0);
2839 perror("wpas_dbus_getter_network_properties[dbus] couldn't "
2840 "read network properties. out of memory.");
2841 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2845 if (message == NULL)
2846 reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
2848 reply = dbus_message_new_method_return(message);
2850 perror("wpas_dbus_getter_network_properties[dbus] out of "
2851 "memory when trying to initialize return message");
2852 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2857 dbus_message_iter_init_append(reply, &iter);
2859 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
2860 "a{sv}", &variant_iter)) {
2861 perror("wpas_dbus_getter_network_properties[dbus] out of "
2862 "memory when trying to open variant container");
2863 dbus_message_unref(reply);
2864 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2869 if (!wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
2870 perror("wpas_dbus_getter_network_properties[dbus] out of "
2871 "memory when trying to open dict");
2872 dbus_message_unref(reply);
2873 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2880 if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
2882 perror("wpas_dbus_getter_network_properties[dbus] out "
2883 "of memory when trying to add entry");
2884 dbus_message_unref(reply);
2885 reply = dbus_message_new_error(message,
2886 DBUS_ERROR_NO_MEMORY,
2894 if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter)) {
2895 perror("wpas_dbus_getter_network_properties[dbus] out of "
2896 "memory when trying to close dictionary");
2897 dbus_message_unref(reply);
2898 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2903 if (!dbus_message_iter_close_container(&iter, &variant_iter)) {
2904 perror("wpas_dbus_getter_network_properties[dbus] out of "
2905 "memory when trying to close variant container");
2906 dbus_message_unref(reply);
2907 reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
2924 * wpas_dbus_setter_network_properties - Set options for a configured network
2925 * @message: Pointer to incoming dbus message
2926 * @net: wpa_supplicant structure for a network interface and
2927 * wpa_ssid structure for a configured network
2928 * Returns: NULL indicating success or DBus error on failure
2930 * Setter for "Properties" property of a configured network.
2932 DBusMessage * wpas_dbus_setter_network_properties(
2933 DBusMessage *message, struct network_handler_args *net)
2935 struct wpa_ssid *ssid = net->ssid;
2937 DBusMessage *reply = NULL;
2938 DBusMessageIter iter, variant_iter;
2940 dbus_message_iter_init(message, &iter);
2942 dbus_message_iter_next(&iter);
2943 dbus_message_iter_next(&iter);
2945 dbus_message_iter_recurse(&iter, &variant_iter);
2947 reply = set_network_properties(message, ssid, &variant_iter);
2949 wpa_printf(MSG_DEBUG, "dbus control interface couldn't set "
2950 "network properties");