2 * WPA Supplicant / dbus-based control interface
3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
10 #include <dbus/dbus.h>
13 #include "eap_peer/eap_methods.h"
14 #include "common/ieee802_11_defs.h"
15 #include "eapol_supp/eapol_supp_sm.h"
16 #include "rsn_supp/wpa.h"
17 #include "../config.h"
18 #include "../wpa_supplicant_i.h"
19 #include "../driver_i.h"
20 #include "../notify.h"
21 #include "../wpas_glue.h"
25 #include "dbus_old_handlers.h"
26 #include "dbus_dict_helpers.h"
29 * wpas_dbus_new_invalid_opts_error - Return a new invalid options error message
30 * @message: Pointer to incoming dbus message this error refers to
31 * Returns: a dbus error message
33 * Convenience function to create and return an invalid options error
35 DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
40 reply = dbus_message_new_error(message, WPAS_ERROR_INVALID_OPTS,
41 "Did not receive correct message "
44 dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
52 * wpas_dbus_new_success_reply - Return a new success reply message
53 * @message: Pointer to incoming dbus message this reply refers to
54 * Returns: a dbus message containing a single UINT32 that indicates
55 * success (ie, a value of 1)
57 * Convenience function to create and return a success reply message
59 DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message)
62 unsigned int success = 1;
64 reply = dbus_message_new_method_return(message);
65 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &success,
72 * wpas_dbus_global_add_interface - Request registration of a network interface
73 * @message: Pointer to incoming dbus message
74 * @global: %wpa_supplicant global data structure
75 * Returns: The object path of the new interface object,
76 * or a dbus error message with more information
78 * Handler function for "addInterface" method call. Handles requests
79 * by dbus clients to register a network interface that wpa_supplicant
82 DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
83 struct wpa_global *global)
87 char *driver_param = NULL;
88 char *confname = NULL;
89 char *bridge_ifname = NULL;
90 DBusMessage *reply = NULL;
93 dbus_message_iter_init(message, &iter);
95 /* First argument: interface name (DBUS_TYPE_STRING)
96 * Required; must be non-zero length
98 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
100 dbus_message_iter_get_basic(&iter, &ifname);
101 if (!os_strlen(ifname))
104 /* Second argument: dict of options */
105 if (dbus_message_iter_next(&iter)) {
106 DBusMessageIter iter_dict;
107 struct wpa_dbus_dict_entry entry;
109 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
111 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
112 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
114 if (!strcmp(entry.key, "driver") &&
115 (entry.type == DBUS_TYPE_STRING)) {
117 driver = os_strdup(entry.str_value);
118 wpa_dbus_dict_entry_clear(&entry);
121 } else if (!strcmp(entry.key, "driver-params") &&
122 (entry.type == DBUS_TYPE_STRING)) {
123 os_free(driver_param);
124 driver_param = os_strdup(entry.str_value);
125 wpa_dbus_dict_entry_clear(&entry);
126 if (driver_param == NULL)
128 } else if (!strcmp(entry.key, "config-file") &&
129 (entry.type == DBUS_TYPE_STRING)) {
131 confname = os_strdup(entry.str_value);
132 wpa_dbus_dict_entry_clear(&entry);
133 if (confname == NULL)
135 } else if (!strcmp(entry.key, "bridge-ifname") &&
136 (entry.type == DBUS_TYPE_STRING)) {
137 os_free(bridge_ifname);
138 bridge_ifname = os_strdup(entry.str_value);
139 wpa_dbus_dict_entry_clear(&entry);
140 if (bridge_ifname == NULL)
143 wpa_dbus_dict_entry_clear(&entry);
150 * Try to get the wpa_supplicant record for this iface, return
151 * an error if we already control it.
153 if (wpa_supplicant_get_iface(global, ifname) != NULL) {
154 reply = dbus_message_new_error(message,
155 WPAS_ERROR_EXISTS_ERROR,
156 "wpa_supplicant already "
157 "controls this interface.");
159 struct wpa_supplicant *wpa_s;
160 struct wpa_interface iface;
161 os_memset(&iface, 0, sizeof(iface));
162 iface.ifname = ifname;
163 iface.driver = driver;
164 iface.driver_param = driver_param;
165 iface.confname = confname;
166 iface.bridge_ifname = bridge_ifname;
167 /* Otherwise, have wpa_supplicant attach to it. */
168 if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
169 const char *path = wpa_s->dbus_path;
170 reply = dbus_message_new_method_return(message);
171 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
172 &path, DBUS_TYPE_INVALID);
174 reply = dbus_message_new_error(message,
175 WPAS_ERROR_ADD_ERROR,
177 "couldn't grab this "
184 os_free(driver_param);
186 os_free(bridge_ifname);
190 reply = wpas_dbus_new_invalid_opts_error(message, NULL);
196 * wpas_dbus_global_remove_interface - Request deregistration of an interface
197 * @message: Pointer to incoming dbus message
198 * @global: wpa_supplicant global data structure
199 * Returns: a dbus message containing a UINT32 indicating success (1) or
200 * failure (0), or returns a dbus error message with more information
202 * Handler function for "removeInterface" method call. Handles requests
203 * by dbus clients to deregister a network interface that wpa_supplicant
206 DBusMessage * wpas_dbus_global_remove_interface(DBusMessage *message,
207 struct wpa_global *global)
209 struct wpa_supplicant *wpa_s;
211 DBusMessage *reply = NULL;
213 if (!dbus_message_get_args(message, NULL,
214 DBUS_TYPE_OBJECT_PATH, &path,
215 DBUS_TYPE_INVALID)) {
216 reply = wpas_dbus_new_invalid_opts_error(message, NULL);
220 wpa_s = wpa_supplicant_get_iface_by_dbus_path(global, path);
222 reply = wpas_dbus_new_invalid_iface_error(message);
226 if (!wpa_supplicant_remove_iface(global, wpa_s, 0)) {
227 reply = wpas_dbus_new_success_reply(message);
229 reply = dbus_message_new_error(message,
230 WPAS_ERROR_REMOVE_ERROR,
231 "wpa_supplicant couldn't "
232 "remove this interface.");
241 * wpas_dbus_global_get_interface - Get the object path for an interface name
242 * @message: Pointer to incoming dbus message
243 * @global: %wpa_supplicant global data structure
244 * Returns: The object path of the interface object,
245 * or a dbus error message with more information
247 * Handler function for "getInterface" method call. Handles requests
248 * by dbus clients for the object path of an specific network interface.
250 DBusMessage * wpas_dbus_global_get_interface(DBusMessage *message,
251 struct wpa_global *global)
253 DBusMessage *reply = NULL;
256 struct wpa_supplicant *wpa_s;
258 if (!dbus_message_get_args(message, NULL,
259 DBUS_TYPE_STRING, &ifname,
260 DBUS_TYPE_INVALID)) {
261 reply = wpas_dbus_new_invalid_opts_error(message, NULL);
265 wpa_s = wpa_supplicant_get_iface(global, ifname);
267 reply = wpas_dbus_new_invalid_iface_error(message);
271 path = wpa_s->dbus_path;
272 reply = dbus_message_new_method_return(message);
273 dbus_message_append_args(reply,
274 DBUS_TYPE_OBJECT_PATH, &path,
283 * wpas_dbus_global_set_debugparams- Set the debug params
284 * @message: Pointer to incoming dbus message
285 * @global: %wpa_supplicant global data structure
286 * Returns: a dbus message containing a UINT32 indicating success (1) or
287 * failure (0), or returns a dbus error message with more information
289 * Handler function for "setDebugParams" method call. Handles requests
290 * by dbus clients for the object path of an specific network interface.
292 DBusMessage * wpas_dbus_global_set_debugparams(DBusMessage *message,
293 struct wpa_global *global)
295 DBusMessage *reply = NULL;
297 dbus_bool_t debug_timestamp;
298 dbus_bool_t debug_show_keys;
300 if (!dbus_message_get_args(message, NULL,
301 DBUS_TYPE_INT32, &debug_level,
302 DBUS_TYPE_BOOLEAN, &debug_timestamp,
303 DBUS_TYPE_BOOLEAN, &debug_show_keys,
304 DBUS_TYPE_INVALID)) {
305 return wpas_dbus_new_invalid_opts_error(message, NULL);
308 if (wpa_supplicant_set_debug_params(global, debug_level,
309 debug_timestamp ? 1 : 0,
310 debug_show_keys ? 1 : 0)) {
311 return wpas_dbus_new_invalid_opts_error(message, NULL);
314 reply = wpas_dbus_new_success_reply(message);
321 * wpas_dbus_iface_scan - Request a wireless scan on an interface
322 * @message: Pointer to incoming dbus message
323 * @wpa_s: wpa_supplicant structure for a network interface
324 * Returns: a dbus message containing a UINT32 indicating success (1) or
327 * Handler function for "scan" method call of a network device. Requests
328 * that wpa_supplicant perform a wireless scan as soon as possible
329 * on a particular wireless interface.
331 DBusMessage * wpas_dbus_iface_scan(DBusMessage *message,
332 struct wpa_supplicant *wpa_s)
334 wpa_s->scan_req = MANUAL_SCAN_REQ;
335 wpa_supplicant_req_scan(wpa_s, 0, 0);
336 return wpas_dbus_new_success_reply(message);
341 * wpas_dbus_iface_scan_results - Get the results of a recent scan request
342 * @message: Pointer to incoming dbus message
343 * @wpa_s: wpa_supplicant structure for a network interface
344 * Returns: a dbus message containing a dbus array of objects paths, or returns
345 * a dbus error message if not scan results could be found
347 * Handler function for "scanResults" method call of a network device. Returns
348 * a dbus message containing the object paths of wireless networks found.
350 DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
351 struct wpa_supplicant *wpa_s)
354 DBusMessageIter iter;
355 DBusMessageIter sub_iter;
358 /* Create and initialize the return message */
359 reply = dbus_message_new_method_return(message);
360 dbus_message_iter_init_append(reply, &iter);
361 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
362 DBUS_TYPE_OBJECT_PATH_AS_STRING,
366 /* Loop through scan results and append each result's object path */
367 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
368 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX];
369 char *path = path_buf;
371 /* Construct the object path for this network. Note that ':'
372 * is not a valid character in dbus object paths.
374 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
375 "%s/" WPAS_DBUS_BSSIDS_PART "/"
376 WPAS_DBUS_BSSID_FORMAT,
377 wpa_s->dbus_path, MAC2STR(bss->bssid));
378 if (!dbus_message_iter_append_basic(&sub_iter,
379 DBUS_TYPE_OBJECT_PATH,
384 if (!dbus_message_iter_close_container(&iter, &sub_iter))
390 dbus_message_unref(reply);
391 return dbus_message_new_error(message, WPAS_ERROR_INTERNAL_ERROR,
392 "an internal error occurred returning scan results");
397 * wpas_dbus_bssid_properties - Return the properties of a scanned network
398 * @message: Pointer to incoming dbus message
399 * @wpa_s: wpa_supplicant structure for a network interface
400 * @res: wpa_supplicant scan result for which to get properties
401 * Returns: a dbus message containing the properties for the requested network
403 * Handler function for "properties" method call of a scanned network.
404 * Returns a dbus message containing the the properties.
406 DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
407 struct wpa_supplicant *wpa_s,
411 DBusMessageIter iter, iter_dict;
414 /* Dump the properties into a dbus message */
415 reply = dbus_message_new_method_return(message);
417 dbus_message_iter_init_append(reply, &iter);
418 if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
421 if (!wpa_dbus_dict_append_byte_array(&iter_dict, "bssid",
422 (const char *) bss->bssid,
426 ie = wpa_bss_get_ie(bss, WLAN_EID_SSID);
428 if (!wpa_dbus_dict_append_byte_array(&iter_dict, "ssid",
429 (const char *) (ie + 2),
434 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
436 if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpaie",
442 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
444 if (!wpa_dbus_dict_append_byte_array(&iter_dict, "rsnie",
450 ie = wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE);
452 if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpsie",
459 if (!wpa_dbus_dict_append_int32(&iter_dict, "frequency",
463 if (!wpa_dbus_dict_append_uint16(&iter_dict, "capabilities",
466 if (!(bss->flags & WPA_BSS_QUAL_INVALID) &&
467 !wpa_dbus_dict_append_int32(&iter_dict, "quality", bss->qual))
469 if (!(bss->flags & WPA_BSS_NOISE_INVALID) &&
470 !wpa_dbus_dict_append_int32(&iter_dict, "noise", bss->noise))
472 if (!(bss->flags & WPA_BSS_LEVEL_INVALID) &&
473 !wpa_dbus_dict_append_int32(&iter_dict, "level", bss->level))
475 if (!wpa_dbus_dict_append_int32(&iter_dict, "maxrate",
476 wpa_bss_get_max_rate(bss) * 500000))
479 if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
486 dbus_message_unref(reply);
487 return dbus_message_new_error(message, WPAS_ERROR_INTERNAL_ERROR,
488 "an internal error occurred returning "
489 "BSSID properties.");
494 * wpas_dbus_iface_capabilities - Return interface capabilities
495 * @message: Pointer to incoming dbus message
496 * @wpa_s: wpa_supplicant structure for a network interface
497 * Returns: A dbus message containing a dict of strings
499 * Handler function for "capabilities" method call of an interface.
501 DBusMessage * wpas_dbus_iface_capabilities(DBusMessage *message,
502 struct wpa_supplicant *wpa_s)
504 DBusMessage *reply = NULL;
505 struct wpa_driver_capa capa;
507 DBusMessageIter iter, iter_dict;
510 dbus_bool_t strict = FALSE;
511 DBusMessageIter iter_dict_entry, iter_dict_val, iter_array;
513 if (!dbus_message_get_args(message, NULL,
514 DBUS_TYPE_BOOLEAN, &strict,
518 reply = dbus_message_new_method_return(message);
520 dbus_message_iter_init_append(reply, &iter);
521 if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
525 eap_methods = eap_get_names_as_string_array(&num_items);
527 dbus_bool_t success = FALSE;
530 success = wpa_dbus_dict_append_string_array(
531 &iter_dict, "eap", (const char **) eap_methods,
534 /* free returned method array */
535 while (eap_methods[i])
536 os_free(eap_methods[i++]);
537 os_free(eap_methods);
543 res = wpa_drv_get_capa(wpa_s, &capa);
545 /***** pairwise cipher */
548 const char *args[] = {"CCMP", "TKIP", "NONE"};
549 if (!wpa_dbus_dict_append_string_array(
550 &iter_dict, "pairwise", args,
555 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "pairwise",
561 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
562 if (!wpa_dbus_dict_string_array_add_element(
563 &iter_array, "CCMP"))
567 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
568 if (!wpa_dbus_dict_string_array_add_element(
569 &iter_array, "TKIP"))
573 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
574 if (!wpa_dbus_dict_string_array_add_element(
575 &iter_array, "NONE"))
579 if (!wpa_dbus_dict_end_string_array(&iter_dict,
586 /***** group cipher */
589 const char *args[] = {
590 "CCMP", "TKIP", "WEP104", "WEP40"
592 if (!wpa_dbus_dict_append_string_array(
593 &iter_dict, "group", args,
598 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "group",
604 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
605 if (!wpa_dbus_dict_string_array_add_element(
606 &iter_array, "CCMP"))
610 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
611 if (!wpa_dbus_dict_string_array_add_element(
612 &iter_array, "TKIP"))
616 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
617 if (!wpa_dbus_dict_string_array_add_element(
618 &iter_array, "WEP104"))
622 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
623 if (!wpa_dbus_dict_string_array_add_element(
624 &iter_array, "WEP40"))
628 if (!wpa_dbus_dict_end_string_array(&iter_dict,
635 /***** key management */
638 const char *args[] = {
639 "WPA-PSK", "WPA-EAP", "IEEE8021X", "WPA-NONE",
642 if (!wpa_dbus_dict_append_string_array(
643 &iter_dict, "key_mgmt", args,
648 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "key_mgmt",
654 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
658 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
662 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
663 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
664 if (!wpa_dbus_dict_string_array_add_element(
665 &iter_array, "WPA-EAP"))
669 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
670 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
671 if (!wpa_dbus_dict_string_array_add_element(
672 &iter_array, "WPA-PSK"))
676 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
677 if (!wpa_dbus_dict_string_array_add_element(
678 &iter_array, "WPA-NONE"))
682 if (!wpa_dbus_dict_end_string_array(&iter_dict,
689 /***** WPA protocol */
692 const char *args[] = { "RSN", "WPA" };
693 if (!wpa_dbus_dict_append_string_array(
694 &iter_dict, "proto", args,
699 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "proto",
705 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
706 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
707 if (!wpa_dbus_dict_string_array_add_element(
712 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
713 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
714 if (!wpa_dbus_dict_string_array_add_element(
719 if (!wpa_dbus_dict_end_string_array(&iter_dict,
729 const char *args[] = { "OPEN", "SHARED", "LEAP" };
730 if (!wpa_dbus_dict_append_string_array(
731 &iter_dict, "auth_alg", args,
736 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "auth_alg",
742 if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
743 if (!wpa_dbus_dict_string_array_add_element(
744 &iter_array, "OPEN"))
748 if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
749 if (!wpa_dbus_dict_string_array_add_element(
750 &iter_array, "SHARED"))
754 if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
755 if (!wpa_dbus_dict_string_array_add_element(
756 &iter_array, "LEAP"))
760 if (!wpa_dbus_dict_end_string_array(&iter_dict,
767 if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
774 dbus_message_unref(reply);
775 return dbus_message_new_error(message, WPAS_ERROR_INTERNAL_ERROR,
776 "an internal error occurred returning "
777 "interface capabilities.");
782 * wpas_dbus_iface_add_network - Add a new configured network
783 * @message: Pointer to incoming dbus message
784 * @wpa_s: wpa_supplicant structure for a network interface
785 * Returns: A dbus message containing the object path of the new network
787 * Handler function for "addNetwork" method call of a network interface.
789 DBusMessage * wpas_dbus_iface_add_network(DBusMessage *message,
790 struct wpa_supplicant *wpa_s)
792 DBusMessage *reply = NULL;
793 struct wpa_ssid *ssid;
794 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
796 ssid = wpa_config_add_network(wpa_s->conf);
798 reply = dbus_message_new_error(message,
799 WPAS_ERROR_ADD_NETWORK_ERROR,
800 "wpa_supplicant could not add "
801 "a network on this interface.");
804 wpas_notify_network_added(wpa_s, ssid);
806 wpa_config_set_network_defaults(ssid);
808 /* Construct the object path for this network. */
809 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
810 "%s/" WPAS_DBUS_NETWORKS_PART "/%d",
811 wpa_s->dbus_path, ssid->id);
813 reply = dbus_message_new_method_return(message);
814 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
815 &path, DBUS_TYPE_INVALID);
823 * wpas_dbus_iface_remove_network - Remove a configured network
824 * @message: Pointer to incoming dbus message
825 * @wpa_s: wpa_supplicant structure for a network interface
826 * Returns: A dbus message containing a UINT32 indicating success (1) or
829 * Handler function for "removeNetwork" method call of a network interface.
831 DBusMessage * wpas_dbus_iface_remove_network(DBusMessage *message,
832 struct wpa_supplicant *wpa_s)
834 DBusMessage *reply = NULL;
836 char *iface = NULL, *net_id = NULL;
838 struct wpa_ssid *ssid;
840 if (!dbus_message_get_args(message, NULL,
841 DBUS_TYPE_OBJECT_PATH, &op,
842 DBUS_TYPE_INVALID)) {
843 reply = wpas_dbus_new_invalid_opts_error(message, NULL);
847 /* Extract the network ID */
848 iface = wpas_dbus_decompose_object_path(op, &net_id, NULL);
849 if (iface == NULL || net_id == NULL) {
850 reply = wpas_dbus_new_invalid_network_error(message);
854 /* Ensure the network is actually a child of this interface */
855 if (os_strcmp(iface, wpa_s->dbus_path) != 0) {
856 reply = wpas_dbus_new_invalid_network_error(message);
860 id = strtoul(net_id, NULL, 10);
861 ssid = wpa_config_get_network(wpa_s->conf, id);
863 reply = wpas_dbus_new_invalid_network_error(message);
867 wpas_notify_network_removed(wpa_s, ssid);
869 if (ssid == wpa_s->current_ssid)
870 wpa_supplicant_deauthenticate(wpa_s,
871 WLAN_REASON_DEAUTH_LEAVING);
873 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
874 reply = dbus_message_new_error(message,
875 WPAS_ERROR_REMOVE_NETWORK_ERROR,
876 "error removing the specified "
877 "on this interface.");
881 reply = wpas_dbus_new_success_reply(message);
890 static const char *dont_quote[] = {
891 "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
892 "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
897 static dbus_bool_t should_quote_opt(const char *key)
900 while (dont_quote[i] != NULL) {
901 if (strcmp(key, dont_quote[i]) == 0)
910 * wpas_dbus_iface_set_network - Set options for a configured network
911 * @message: Pointer to incoming dbus message
912 * @wpa_s: wpa_supplicant structure for a network interface
913 * @ssid: wpa_ssid structure for a configured network
914 * Returns: a dbus message containing a UINT32 indicating success (1) or
917 * Handler function for "set" method call of a configured network.
919 DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message,
920 struct wpa_supplicant *wpa_s,
921 struct wpa_ssid *ssid)
923 DBusMessage *reply = NULL;
924 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
925 DBusMessageIter iter, iter_dict;
927 dbus_message_iter_init(message, &iter);
929 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL)) {
930 reply = wpas_dbus_new_invalid_opts_error(message, NULL);
934 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
939 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) {
940 reply = wpas_dbus_new_invalid_opts_error(message,
945 /* Type conversions, since wpa_supplicant wants strings */
946 if (entry.type == DBUS_TYPE_ARRAY &&
947 entry.array_type == DBUS_TYPE_BYTE) {
948 if (entry.array_len <= 0)
951 size = entry.array_len * 2 + 1;
952 value = os_zalloc(size);
955 ret = wpa_snprintf_hex(value, size,
956 (u8 *) entry.bytearray_value,
960 } else if (entry.type == DBUS_TYPE_STRING) {
961 if (should_quote_opt(entry.key)) {
962 size = os_strlen(entry.str_value);
963 /* Zero-length option check */
966 size += 3; /* For quotes and terminator */
967 value = os_zalloc(size);
970 ret = os_snprintf(value, size, "\"%s\"",
972 if (os_snprintf_error(size, ret))
975 value = os_strdup(entry.str_value);
979 } else if (entry.type == DBUS_TYPE_UINT32) {
980 value = os_zalloc(size);
983 ret = os_snprintf(value, size, "%u",
985 if (os_snprintf_error(size, ret))
987 } else if (entry.type == DBUS_TYPE_INT32) {
988 value = os_zalloc(size);
991 ret = os_snprintf(value, size, "%d",
993 if (os_snprintf_error(size, ret))
998 if (wpa_config_set(ssid, entry.key, value, 0) < 0)
1001 if ((os_strcmp(entry.key, "psk") == 0 &&
1002 value[0] == '"' && ssid->ssid_len) ||
1003 (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
1004 wpa_config_update_psk(ssid);
1005 else if (os_strcmp(entry.key, "priority") == 0)
1006 wpa_config_update_prio_list(wpa_s->conf);
1009 wpa_dbus_dict_entry_clear(&entry);
1014 reply = wpas_dbus_new_invalid_opts_error(message, entry.key);
1015 wpa_dbus_dict_entry_clear(&entry);
1020 reply = wpas_dbus_new_success_reply(message);
1028 * wpas_dbus_iface_enable_network - Mark a configured network as enabled
1029 * @message: Pointer to incoming dbus message
1030 * @wpa_s: wpa_supplicant structure for a network interface
1031 * @ssid: wpa_ssid structure for a configured network
1032 * Returns: A dbus message containing a UINT32 indicating success (1) or
1035 * Handler function for "enable" method call of a configured network.
1037 DBusMessage * wpas_dbus_iface_enable_network(DBusMessage *message,
1038 struct wpa_supplicant *wpa_s,
1039 struct wpa_ssid *ssid)
1041 wpa_supplicant_enable_network(wpa_s, ssid);
1042 return wpas_dbus_new_success_reply(message);
1047 * wpas_dbus_iface_disable_network - Mark a configured network as disabled
1048 * @message: Pointer to incoming dbus message
1049 * @wpa_s: wpa_supplicant structure for a network interface
1050 * @ssid: wpa_ssid structure for a configured network
1051 * Returns: A dbus message containing a UINT32 indicating success (1) or
1054 * Handler function for "disable" method call of a configured network.
1056 DBusMessage * wpas_dbus_iface_disable_network(DBusMessage *message,
1057 struct wpa_supplicant *wpa_s,
1058 struct wpa_ssid *ssid)
1060 wpa_supplicant_disable_network(wpa_s, ssid);
1061 return wpas_dbus_new_success_reply(message);
1066 * wpas_dbus_iface_select_network - Attempt association with a configured network
1067 * @message: Pointer to incoming dbus message
1068 * @wpa_s: wpa_supplicant structure for a network interface
1069 * Returns: A dbus message containing a UINT32 indicating success (1) or
1072 * Handler function for "selectNetwork" method call of network interface.
1074 DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
1075 struct wpa_supplicant *wpa_s)
1077 DBusMessage *reply = NULL;
1079 struct wpa_ssid *ssid;
1080 char *iface_obj_path = NULL;
1081 char *network = NULL;
1083 if (os_strlen(dbus_message_get_signature(message)) == 0) {
1089 if (!dbus_message_get_args(message, NULL,
1090 DBUS_TYPE_OBJECT_PATH, &op,
1091 DBUS_TYPE_INVALID)) {
1092 reply = wpas_dbus_new_invalid_opts_error(message,
1097 /* Extract the network number */
1098 iface_obj_path = wpas_dbus_decompose_object_path(op,
1101 if (iface_obj_path == NULL) {
1102 reply = wpas_dbus_new_invalid_iface_error(message);
1105 /* Ensure the object path really points to this interface */
1106 if (network == NULL ||
1107 os_strcmp(iface_obj_path, wpa_s->dbus_path) != 0) {
1108 reply = wpas_dbus_new_invalid_network_error(message);
1112 nid = strtoul(network, NULL, 10);
1113 if (errno == EINVAL) {
1114 reply = wpas_dbus_new_invalid_network_error(message);
1118 ssid = wpa_config_get_network(wpa_s->conf, nid);
1120 reply = wpas_dbus_new_invalid_network_error(message);
1125 /* Finally, associate with the network */
1126 wpa_supplicant_select_network(wpa_s, ssid);
1128 reply = wpas_dbus_new_success_reply(message);
1131 os_free(iface_obj_path);
1138 * wpas_dbus_iface_disconnect - Terminate the current connection
1139 * @message: Pointer to incoming dbus message
1140 * @wpa_s: wpa_supplicant structure for a network interface
1141 * Returns: A dbus message containing a UINT32 indicating success (1) or
1144 * Handler function for "disconnect" method call of network interface.
1146 DBusMessage * wpas_dbus_iface_disconnect(DBusMessage *message,
1147 struct wpa_supplicant *wpa_s)
1149 wpa_s->disconnected = 1;
1150 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1152 return wpas_dbus_new_success_reply(message);
1157 * wpas_dbus_iface_set_ap_scan - Control roaming mode
1158 * @message: Pointer to incoming dbus message
1159 * @wpa_s: wpa_supplicant structure for a network interface
1160 * Returns: A dbus message containing a UINT32 indicating success (1) or
1163 * Handler function for "setAPScan" method call.
1165 DBusMessage * wpas_dbus_iface_set_ap_scan(DBusMessage *message,
1166 struct wpa_supplicant *wpa_s)
1168 DBusMessage *reply = NULL;
1169 dbus_uint32_t ap_scan = 1;
1171 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &ap_scan,
1172 DBUS_TYPE_INVALID)) {
1173 reply = wpas_dbus_new_invalid_opts_error(message, NULL);
1177 if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
1178 reply = wpas_dbus_new_invalid_opts_error(message, NULL);
1182 reply = wpas_dbus_new_success_reply(message);
1190 * wpas_dbus_iface_set_smartcard_modules - Set smartcard related module paths
1191 * @message: Pointer to incoming dbus message
1192 * @wpa_s: wpa_supplicant structure for a network interface
1193 * Returns: A dbus message containing a UINT32 indicating success (1) or
1196 * Handler function for "setSmartcardModules" method call.
1198 DBusMessage * wpas_dbus_iface_set_smartcard_modules(
1199 DBusMessage *message, struct wpa_supplicant *wpa_s)
1201 DBusMessageIter iter, iter_dict;
1202 char *opensc_engine_path = NULL;
1203 char *pkcs11_engine_path = NULL;
1204 char *pkcs11_module_path = NULL;
1205 struct wpa_dbus_dict_entry entry;
1207 if (!dbus_message_iter_init(message, &iter))
1210 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
1213 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
1214 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
1216 if (!strcmp(entry.key, "opensc_engine_path") &&
1217 (entry.type == DBUS_TYPE_STRING)) {
1218 os_free(opensc_engine_path);
1219 opensc_engine_path = os_strdup(entry.str_value);
1220 if (opensc_engine_path == NULL)
1222 } else if (!strcmp(entry.key, "pkcs11_engine_path") &&
1223 (entry.type == DBUS_TYPE_STRING)) {
1224 os_free(pkcs11_engine_path);
1225 pkcs11_engine_path = os_strdup(entry.str_value);
1226 if (pkcs11_engine_path == NULL)
1228 } else if (!strcmp(entry.key, "pkcs11_module_path") &&
1229 (entry.type == DBUS_TYPE_STRING)) {
1230 os_free(pkcs11_module_path);
1231 pkcs11_module_path = os_strdup(entry.str_value);
1232 if (pkcs11_module_path == NULL)
1235 wpa_dbus_dict_entry_clear(&entry);
1238 wpa_dbus_dict_entry_clear(&entry);
1241 os_free(wpa_s->conf->opensc_engine_path);
1242 wpa_s->conf->opensc_engine_path = opensc_engine_path;
1243 os_free(wpa_s->conf->pkcs11_engine_path);
1244 wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path;
1245 os_free(wpa_s->conf->pkcs11_module_path);
1246 wpa_s->conf->pkcs11_module_path = pkcs11_module_path;
1248 wpa_sm_set_eapol(wpa_s->wpa, NULL);
1249 eapol_sm_deinit(wpa_s->eapol);
1250 wpa_s->eapol = NULL;
1251 wpa_supplicant_init_eapol(wpa_s);
1252 wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
1254 return wpas_dbus_new_success_reply(message);
1257 os_free(opensc_engine_path);
1258 os_free(pkcs11_engine_path);
1259 os_free(pkcs11_module_path);
1260 return wpas_dbus_new_invalid_opts_error(message, NULL);
1265 * wpas_dbus_iface_get_state - Get interface state
1266 * @message: Pointer to incoming dbus message
1267 * @wpa_s: wpa_supplicant structure for a network interface
1268 * Returns: A dbus message containing a STRING representing the current
1271 * Handler function for "state" method call.
1273 DBusMessage * wpas_dbus_iface_get_state(DBusMessage *message,
1274 struct wpa_supplicant *wpa_s)
1276 DBusMessage *reply = NULL;
1277 const char *str_state;
1279 reply = dbus_message_new_method_return(message);
1280 if (reply != NULL) {
1281 str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
1282 dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_state,
1291 * wpas_dbus_iface_get_scanning - Get interface scanning state
1292 * @message: Pointer to incoming dbus message
1293 * @wpa_s: wpa_supplicant structure for a network interface
1294 * Returns: A dbus message containing whether the interface is scanning
1296 * Handler function for "scanning" method call.
1298 DBusMessage * wpas_dbus_iface_get_scanning(DBusMessage *message,
1299 struct wpa_supplicant *wpa_s)
1301 DBusMessage *reply = NULL;
1302 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
1304 reply = dbus_message_new_method_return(message);
1305 if (reply != NULL) {
1306 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &scanning,
1309 wpa_printf(MSG_ERROR, "dbus: Not enough memory to return "
1317 #ifndef CONFIG_NO_CONFIG_BLOBS
1320 * wpas_dbus_iface_set_blobs - Store named binary blobs (ie, for certificates)
1321 * @message: Pointer to incoming dbus message
1322 * @wpa_s: %wpa_supplicant data structure
1323 * Returns: A dbus message containing a UINT32 indicating success (1) or
1326 * Asks wpa_supplicant to internally store a one or more binary blobs.
1328 DBusMessage * wpas_dbus_iface_set_blobs(DBusMessage *message,
1329 struct wpa_supplicant *wpa_s)
1331 DBusMessage *reply = NULL;
1332 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
1333 DBusMessageIter iter, iter_dict;
1335 dbus_message_iter_init(message, &iter);
1337 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
1338 return wpas_dbus_new_invalid_opts_error(message, NULL);
1340 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
1341 struct wpa_config_blob *blob;
1343 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) {
1344 reply = wpas_dbus_new_invalid_opts_error(message,
1349 if (entry.type != DBUS_TYPE_ARRAY ||
1350 entry.array_type != DBUS_TYPE_BYTE) {
1351 reply = wpas_dbus_new_invalid_opts_error(
1352 message, "Byte array expected.");
1356 if ((entry.array_len <= 0) || (entry.array_len > 65536) ||
1357 !strlen(entry.key)) {
1358 reply = wpas_dbus_new_invalid_opts_error(
1359 message, "Invalid array size.");
1363 blob = os_zalloc(sizeof(*blob));
1365 reply = dbus_message_new_error(
1366 message, WPAS_ERROR_ADD_ERROR,
1367 "Not enough memory to add blob.");
1370 blob->data = os_zalloc(entry.array_len);
1371 if (blob->data == NULL) {
1372 reply = dbus_message_new_error(
1373 message, WPAS_ERROR_ADD_ERROR,
1374 "Not enough memory to add blob data.");
1379 blob->name = os_strdup(entry.key);
1380 blob->len = entry.array_len;
1381 os_memcpy(blob->data, (u8 *) entry.bytearray_value,
1383 if (blob->name == NULL) {
1384 wpa_config_free_blob(blob);
1385 reply = dbus_message_new_error(
1386 message, WPAS_ERROR_ADD_ERROR,
1387 "Error adding blob.");
1392 if (!wpa_config_remove_blob(wpa_s->conf, blob->name))
1393 wpas_notify_blob_removed(wpa_s, blob->name);
1394 wpa_config_set_blob(wpa_s->conf, blob);
1395 wpas_notify_blob_added(wpa_s, blob->name);
1397 wpa_dbus_dict_entry_clear(&entry);
1399 wpa_dbus_dict_entry_clear(&entry);
1401 return reply ? reply : wpas_dbus_new_success_reply(message);
1406 * wpas_dbus_iface_remove_blob - Remove named binary blobs
1407 * @message: Pointer to incoming dbus message
1408 * @wpa_s: %wpa_supplicant data structure
1409 * Returns: A dbus message containing a UINT32 indicating success (1) or
1412 * Asks wpa_supplicant to remove one or more previously stored binary blobs.
1414 DBusMessage * wpas_dbus_iface_remove_blobs(DBusMessage *message,
1415 struct wpa_supplicant *wpa_s)
1417 DBusMessageIter iter, array;
1418 char *err_msg = NULL;
1420 dbus_message_iter_init(message, &iter);
1422 if ((dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) ||
1423 (dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_STRING))
1424 return wpas_dbus_new_invalid_opts_error(message, NULL);
1426 dbus_message_iter_recurse(&iter, &array);
1427 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
1430 dbus_message_iter_get_basic(&array, &name);
1431 if (!os_strlen(name))
1432 err_msg = "Invalid blob name.";
1433 else if (wpa_config_remove_blob(wpa_s->conf, name) != 0)
1434 err_msg = "Error removing blob.";
1436 wpas_notify_blob_removed(wpa_s, name);
1437 dbus_message_iter_next(&array);
1441 return dbus_message_new_error(message, WPAS_ERROR_REMOVE_ERROR,
1444 return wpas_dbus_new_success_reply(message);
1447 #endif /* CONFIG_NO_CONFIG_BLOBS */
1451 * wpas_dbus_iface_flush - Clear BSS of old or all inactive entries
1452 * @message: Pointer to incoming dbus message
1453 * @wpa_s: %wpa_supplicant data structure
1454 * Returns: a dbus message containing a UINT32 indicating success (1) or
1455 * failure (0), or returns a dbus error message with more information
1457 * Handler function for "flush" method call. Handles requests for an
1458 * interface with an optional "age" parameter that specifies the minimum
1459 * age of a BSS to be flushed.
1461 DBusMessage * wpas_dbus_iface_flush(DBusMessage *message,
1462 struct wpa_supplicant *wpa_s)
1466 if (os_strlen(dbus_message_get_signature(message)) != 0 &&
1467 !dbus_message_get_args(message, NULL,
1468 DBUS_TYPE_INT32, &flush_age,
1469 DBUS_TYPE_INVALID)) {
1470 return wpas_dbus_new_invalid_opts_error(message, NULL);
1474 wpa_bss_flush(wpa_s);
1476 wpa_bss_flush_by_age(wpa_s, flush_age);
1478 return wpas_dbus_new_success_reply(message);