2 * WPA Supplicant / dbus-based control interface
3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4 * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
5 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
14 #include "common/ieee802_11_defs.h"
16 #include "../config.h"
17 #include "../wpa_supplicant_i.h"
19 #include "../wpas_glue.h"
20 #include "dbus_new_helpers.h"
21 #include "dbus_dict_helpers.h"
23 #include "dbus_new_handlers.h"
24 #include "dbus_common_i.h"
25 #include "dbus_new_handlers_p2p.h"
28 #ifdef CONFIG_AP /* until needed by something else */
31 * NameOwnerChanged handling
33 * Some services we provide allow an application to register for
34 * a signal that it needs. While it can also unregister, we must
35 * be prepared for the case where the application simply crashes
36 * and thus doesn't clean up properly. The way to handle this in
37 * DBus is to register for the NameOwnerChanged signal which will
38 * signal an owner change to NULL if the peer closes the socket
39 * for whatever reason.
41 * Handle this signal via a filter function whenever necessary.
42 * The code below also handles refcounting in case in the future
43 * there will be multiple instances of this subscription scheme.
45 static const char wpas_dbus_noc_filter_str[] =
46 "interface=org.freedesktop.DBus,member=NameOwnerChanged";
49 static DBusHandlerResult noc_filter(DBusConnection *conn,
50 DBusMessage *message, void *data)
52 struct wpas_dbus_priv *priv = data;
54 if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
55 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
57 if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
58 "NameOwnerChanged")) {
60 const char *prev_owner;
61 const char *new_owner;
63 struct wpa_supplicant *wpa_s;
65 dbus_error_init(&derr);
67 if (!dbus_message_get_args(message, &derr,
68 DBUS_TYPE_STRING, &name,
69 DBUS_TYPE_STRING, &prev_owner,
70 DBUS_TYPE_STRING, &new_owner,
72 /* Ignore this error */
73 dbus_error_free(&derr);
74 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
77 for (wpa_s = priv->global->ifaces; wpa_s; wpa_s = wpa_s->next)
79 if (wpa_s->preq_notify_peer != NULL &&
80 os_strcmp(name, wpa_s->preq_notify_peer) == 0 &&
81 (new_owner == NULL || os_strlen(new_owner) == 0)) {
82 /* probe request owner disconnected */
83 os_free(wpa_s->preq_notify_peer);
84 wpa_s->preq_notify_peer = NULL;
85 wpas_dbus_unsubscribe_noc(priv);
90 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
94 void wpas_dbus_subscribe_noc(struct wpas_dbus_priv *priv)
96 priv->dbus_noc_refcnt++;
97 if (priv->dbus_noc_refcnt > 1)
100 if (!dbus_connection_add_filter(priv->con, noc_filter, priv, NULL)) {
101 wpa_printf(MSG_ERROR, "dbus: failed to add filter");
105 dbus_bus_add_match(priv->con, wpas_dbus_noc_filter_str, NULL);
109 void wpas_dbus_unsubscribe_noc(struct wpas_dbus_priv *priv)
111 priv->dbus_noc_refcnt--;
112 if (priv->dbus_noc_refcnt > 0)
115 dbus_bus_remove_match(priv->con, wpas_dbus_noc_filter_str, NULL);
116 dbus_connection_remove_filter(priv->con, noc_filter, priv);
119 #endif /* CONFIG_AP */
123 * wpas_dbus_signal_interface - Send a interface related event signal
124 * @wpa_s: %wpa_supplicant network interface data
125 * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
126 * @properties: Whether to add second argument with object properties
128 * Notify listeners about event related with interface
130 static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
131 const char *sig_name, int properties)
133 struct wpas_dbus_priv *iface;
135 DBusMessageIter iter;
137 iface = wpa_s->global->dbus;
139 /* Do nothing if the control interface is not turned on */
143 msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
144 WPAS_DBUS_NEW_INTERFACE, sig_name);
148 dbus_message_iter_init_append(msg, &iter);
149 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
150 &wpa_s->dbus_new_path))
154 if (!wpa_dbus_get_object_properties(
155 iface, wpa_s->dbus_new_path,
156 WPAS_DBUS_NEW_IFACE_INTERFACE, &iter))
160 dbus_connection_send(iface->con, msg, NULL);
161 dbus_message_unref(msg);
165 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
166 dbus_message_unref(msg);
171 * wpas_dbus_signal_interface_added - Send a interface created signal
172 * @wpa_s: %wpa_supplicant network interface data
174 * Notify listeners about creating new interface
176 static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
178 wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
183 * wpas_dbus_signal_interface_removed - Send a interface removed signal
184 * @wpa_s: %wpa_supplicant network interface data
186 * Notify listeners about removing interface
188 static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
190 wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
196 * wpas_dbus_signal_scan_done - send scan done signal
197 * @wpa_s: %wpa_supplicant network interface data
198 * @success: indicates if scanning succeed or failed
200 * Notify listeners about finishing a scan
202 void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
204 struct wpas_dbus_priv *iface;
208 iface = wpa_s->global->dbus;
210 /* Do nothing if the control interface is not turned on */
214 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
215 WPAS_DBUS_NEW_IFACE_INTERFACE,
220 succ = success ? TRUE : FALSE;
221 if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
223 dbus_connection_send(iface->con, msg, NULL);
225 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
226 dbus_message_unref(msg);
231 * wpas_dbus_signal_blob - Send a BSS related event signal
232 * @wpa_s: %wpa_supplicant network interface data
233 * @bss_obj_path: BSS object path
234 * @sig_name: signal name - BSSAdded or BSSRemoved
235 * @properties: Whether to add second argument with object properties
237 * Notify listeners about event related with BSS
239 static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
240 const char *bss_obj_path,
241 const char *sig_name, int properties)
243 struct wpas_dbus_priv *iface;
245 DBusMessageIter iter;
247 iface = wpa_s->global->dbus;
249 /* Do nothing if the control interface is not turned on */
253 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
254 WPAS_DBUS_NEW_IFACE_INTERFACE,
259 dbus_message_iter_init_append(msg, &iter);
260 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
265 if (!wpa_dbus_get_object_properties(iface, bss_obj_path,
266 WPAS_DBUS_NEW_IFACE_BSS,
271 dbus_connection_send(iface->con, msg, NULL);
272 dbus_message_unref(msg);
276 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
277 dbus_message_unref(msg);
282 * wpas_dbus_signal_bss_added - Send a BSS added signal
283 * @wpa_s: %wpa_supplicant network interface data
284 * @bss_obj_path: new BSS object path
286 * Notify listeners about adding new BSS
288 static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
289 const char *bss_obj_path)
291 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
296 * wpas_dbus_signal_bss_removed - Send a BSS removed signal
297 * @wpa_s: %wpa_supplicant network interface data
298 * @bss_obj_path: BSS object path
300 * Notify listeners about removing BSS
302 static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
303 const char *bss_obj_path)
305 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
310 * wpas_dbus_signal_blob - Send a blob related event signal
311 * @wpa_s: %wpa_supplicant network interface data
313 * @sig_name: signal name - BlobAdded or BlobRemoved
315 * Notify listeners about event related with blob
317 static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
318 const char *name, const char *sig_name)
320 struct wpas_dbus_priv *iface;
323 iface = wpa_s->global->dbus;
325 /* Do nothing if the control interface is not turned on */
329 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
330 WPAS_DBUS_NEW_IFACE_INTERFACE,
335 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
337 dbus_connection_send(iface->con, msg, NULL);
339 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
340 dbus_message_unref(msg);
345 * wpas_dbus_signal_blob_added - Send a blob added signal
346 * @wpa_s: %wpa_supplicant network interface data
349 * Notify listeners about adding a new blob
351 void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
354 wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
359 * wpas_dbus_signal_blob_removed - Send a blob removed signal
360 * @wpa_s: %wpa_supplicant network interface data
363 * Notify listeners about removing blob
365 void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
368 wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
373 * wpas_dbus_signal_network - Send a network related event signal
374 * @wpa_s: %wpa_supplicant network interface data
375 * @id: new network id
376 * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
377 * @properties: determines if add second argument with object properties
379 * Notify listeners about event related with configured network
381 static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
382 int id, const char *sig_name,
385 struct wpas_dbus_priv *iface;
387 DBusMessageIter iter;
388 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
390 iface = wpa_s->global->dbus;
392 /* Do nothing if the control interface is not turned on */
396 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
397 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
398 wpa_s->dbus_new_path, id);
400 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
401 WPAS_DBUS_NEW_IFACE_INTERFACE,
406 dbus_message_iter_init_append(msg, &iter);
408 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
413 if (!wpa_dbus_get_object_properties(
414 iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
419 dbus_connection_send(iface->con, msg, NULL);
421 dbus_message_unref(msg);
425 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
426 dbus_message_unref(msg);
431 * wpas_dbus_signal_network_added - Send a network added signal
432 * @wpa_s: %wpa_supplicant network interface data
433 * @id: new network id
435 * Notify listeners about adding new network
437 static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
440 wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
445 * wpas_dbus_signal_network_removed - Send a network removed signal
446 * @wpa_s: %wpa_supplicant network interface data
449 * Notify listeners about removing a network
451 static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
454 wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
459 * wpas_dbus_signal_network_selected - Send a network selected signal
460 * @wpa_s: %wpa_supplicant network interface data
463 * Notify listeners about selecting a network
465 void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
467 wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
472 * wpas_dbus_signal_network_request - Indicate that additional information
473 * (EAP password, etc.) is required to complete the association to this SSID
474 * @wpa_s: %wpa_supplicant network interface data
475 * @rtype: The specific additional information required
476 * @default_text: Optional description of required information
478 * Request additional information or passwords to complete an association
481 void wpas_dbus_signal_network_request(struct wpa_supplicant *wpa_s,
482 struct wpa_ssid *ssid,
483 enum wpa_ctrl_req_type rtype,
484 const char *default_txt)
486 struct wpas_dbus_priv *iface;
488 DBusMessageIter iter;
489 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
490 const char *field, *txt = NULL, *net_ptr;
492 iface = wpa_s->global->dbus;
494 /* Do nothing if the control interface is not turned on */
498 field = wpa_supplicant_ctrl_req_to_string(rtype, default_txt, &txt);
502 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
503 WPAS_DBUS_NEW_IFACE_INTERFACE,
508 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
509 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
510 wpa_s->dbus_new_path, ssid->id);
511 net_ptr = &net_obj_path[0];
513 dbus_message_iter_init_append(msg, &iter);
514 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
517 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &field))
519 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &txt))
522 dbus_connection_send(iface->con, msg, NULL);
523 dbus_message_unref(msg);
527 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
528 dbus_message_unref(msg);
533 * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
534 * @wpa_s: %wpa_supplicant network interface data
535 * @ssid: configured network which Enabled property has changed
537 * Sends PropertyChanged signals containing new value of Enabled property
538 * for specified network
540 void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
541 struct wpa_ssid *ssid)
544 char path[WPAS_DBUS_OBJECT_PATH_MAX];
545 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
546 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
547 wpa_s->dbus_new_path, ssid->id);
549 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
550 WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
557 * wpas_dbus_signal_wps_event_success - Signals Success WPS event
558 * @wpa_s: %wpa_supplicant network interface data
560 * Sends Event dbus signal with name "success" and empty dict as arguments
562 void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
566 DBusMessageIter iter, dict_iter;
567 struct wpas_dbus_priv *iface;
568 char *key = "success";
570 iface = wpa_s->global->dbus;
572 /* Do nothing if the control interface is not turned on */
576 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
577 WPAS_DBUS_NEW_IFACE_WPS, "Event");
581 dbus_message_iter_init_append(msg, &iter);
583 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
584 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
585 !wpa_dbus_dict_close_write(&iter, &dict_iter))
586 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
588 dbus_connection_send(iface->con, msg, NULL);
590 dbus_message_unref(msg);
595 * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
596 * @wpa_s: %wpa_supplicant network interface data
598 * Sends Event dbus signal with name "fail" and dictionary containing
599 * "msg field with fail message number (int32) as arguments
601 void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
602 struct wps_event_fail *fail)
606 DBusMessageIter iter, dict_iter;
607 struct wpas_dbus_priv *iface;
610 iface = wpa_s->global->dbus;
612 /* Do nothing if the control interface is not turned on */
616 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
617 WPAS_DBUS_NEW_IFACE_WPS, "Event");
621 dbus_message_iter_init_append(msg, &iter);
623 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
624 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
625 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
626 !wpa_dbus_dict_close_write(&iter, &dict_iter))
627 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
629 dbus_connection_send(iface->con, msg, NULL);
631 dbus_message_unref(msg);
636 * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
637 * @wpa_s: %wpa_supplicant network interface data
639 * Sends Event dbus signal with name "m2d" and dictionary containing
640 * fields of wps_event_m2d structure.
642 void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
643 struct wps_event_m2d *m2d)
647 DBusMessageIter iter, dict_iter;
648 struct wpas_dbus_priv *iface;
651 iface = wpa_s->global->dbus;
653 /* Do nothing if the control interface is not turned on */
657 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
658 WPAS_DBUS_NEW_IFACE_WPS, "Event");
662 dbus_message_iter_init_append(msg, &iter);
664 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
665 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
666 !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
667 m2d->config_methods) ||
668 !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
669 (const char *) m2d->manufacturer,
670 m2d->manufacturer_len) ||
671 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
672 (const char *) m2d->model_name,
673 m2d->model_name_len) ||
674 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
675 (const char *) m2d->model_number,
676 m2d->model_number_len) ||
677 !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
680 m2d->serial_number_len) ||
681 !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
682 (const char *) m2d->dev_name,
683 m2d->dev_name_len) ||
684 !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
686 m2d->primary_dev_type, 8) ||
687 !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
688 m2d->config_error) ||
689 !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
690 m2d->dev_password_id) ||
691 !wpa_dbus_dict_close_write(&iter, &dict_iter))
692 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
694 dbus_connection_send(iface->con, msg, NULL);
696 dbus_message_unref(msg);
701 * wpas_dbus_signal_wps_cred - Signals new credentials
702 * @wpa_s: %wpa_supplicant network interface data
704 * Sends signal with credentials in directory argument
706 void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
707 const struct wps_credential *cred)
710 DBusMessageIter iter, dict_iter;
711 struct wpas_dbus_priv *iface;
712 char *auth_type[5]; /* we have five possible authentication types */
714 char *encr_type[3]; /* we have three possible encryption types */
717 iface = wpa_s->global->dbus;
719 /* Do nothing if the control interface is not turned on */
723 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
724 WPAS_DBUS_NEW_IFACE_WPS,
729 dbus_message_iter_init_append(msg, &iter);
730 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
733 if (cred->auth_type & WPS_AUTH_OPEN)
734 auth_type[at_num++] = "open";
735 if (cred->auth_type & WPS_AUTH_WPAPSK)
736 auth_type[at_num++] = "wpa-psk";
737 if (cred->auth_type & WPS_AUTH_WPA)
738 auth_type[at_num++] = "wpa-eap";
739 if (cred->auth_type & WPS_AUTH_WPA2)
740 auth_type[at_num++] = "wpa2-eap";
741 if (cred->auth_type & WPS_AUTH_WPA2PSK)
742 auth_type[at_num++] = "wpa2-psk";
744 if (cred->encr_type & WPS_ENCR_NONE)
745 encr_type[et_num++] = "none";
746 if (cred->encr_type & WPS_ENCR_TKIP)
747 encr_type[et_num++] = "tkip";
748 if (cred->encr_type & WPS_ENCR_AES)
749 encr_type[et_num++] = "aes";
751 if (wpa_s->current_ssid) {
752 if (!wpa_dbus_dict_append_byte_array(
754 (const char *) wpa_s->current_ssid->bssid,
759 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
760 (const char *) cred->ssid,
762 !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
763 (const char **) auth_type,
765 !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
766 (const char **) encr_type,
768 !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
769 (const char *) cred->key,
771 !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
773 !wpa_dbus_dict_close_write(&iter, &dict_iter))
776 dbus_connection_send(iface->con, msg, NULL);
779 dbus_message_unref(msg);
782 #endif /* CONFIG_WPS */
784 void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
785 int depth, const char *subject,
786 const char *cert_hash,
787 const struct wpabuf *cert)
789 struct wpas_dbus_priv *iface;
791 DBusMessageIter iter, dict_iter;
793 iface = wpa_s->global->dbus;
795 /* Do nothing if the control interface is not turned on */
799 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
800 WPAS_DBUS_NEW_IFACE_INTERFACE,
805 dbus_message_iter_init_append(msg, &iter);
806 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
809 if (!wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
810 !wpa_dbus_dict_append_string(&dict_iter, "subject", subject))
814 !wpa_dbus_dict_append_string(&dict_iter, "cert_hash", cert_hash))
818 !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
823 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
826 dbus_connection_send(iface->con, msg, NULL);
829 dbus_message_unref(msg);
833 void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
834 const char *status, const char *parameter)
836 struct wpas_dbus_priv *iface;
838 DBusMessageIter iter;
840 iface = wpa_s->global->dbus;
842 /* Do nothing if the control interface is not turned on */
846 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
847 WPAS_DBUS_NEW_IFACE_INTERFACE,
852 dbus_message_iter_init_append(msg, &iter);
854 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status)
856 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
860 dbus_connection_send(iface->con, msg, NULL);
863 dbus_message_unref(msg);
868 * wpas_dbus_signal_sta - Send a station related event signal
869 * @wpa_s: %wpa_supplicant network interface data
870 * @sta: station mac address
871 * @sig_name: signal name - StaAuthorized or StaDeauthorized
873 * Notify listeners about event related with station
875 static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
876 const u8 *sta, const char *sig_name)
878 struct wpas_dbus_priv *iface;
880 char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
883 os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
886 iface = wpa_s->global->dbus;
888 /* Do nothing if the control interface is not turned on */
892 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
893 WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
897 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
899 dbus_connection_send(iface->con, msg, NULL);
901 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
902 dbus_message_unref(msg);
904 wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
910 * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
911 * @wpa_s: %wpa_supplicant network interface data
912 * @sta: station mac address
914 * Notify listeners a new station has been authorized
916 void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
919 wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
924 * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
925 * @wpa_s: %wpa_supplicant network interface data
926 * @sta: station mac address
928 * Notify listeners a station has been deauthorized
930 void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
933 wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
940 * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
941 * @wpa_s: %wpa_supplicant network interface data
942 * @role: role of this device (client or GO)
943 * Sends signal with i/f name and role as string arguments
945 void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
950 DBusMessageIter iter;
951 struct wpas_dbus_priv *iface = wpa_s->global->dbus;
952 char *ifname = wpa_s->ifname;
954 /* Do nothing if the control interface is not turned on */
958 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
959 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
964 dbus_message_iter_init_append(msg, &iter);
966 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ifname)) {
967 wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
968 "signal -not enough memory for ifname ");
972 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &role))
973 wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
974 "signal -not enough memory for role ");
976 dbus_connection_send(iface->con, msg, NULL);
979 dbus_message_unref(msg);
984 * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
986 * @dev_addr - who sent the request or responded to our request.
987 * @request - Will be 1 if request, 0 for response.
988 * @status - valid only in case of response
989 * @config_methods - wps config methods
990 * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
992 * Sends following provision discovery related events:
993 * ProvisionDiscoveryRequestDisplayPin
994 * ProvisionDiscoveryResponseDisplayPin
995 * ProvisionDiscoveryRequestEnterPin
996 * ProvisionDiscoveryResponseEnterPin
997 * ProvisionDiscoveryPBCRequest
998 * ProvisionDiscoveryPBCResponse
1001 * ProvisionDiscoveryFailure (timeout case)
1003 void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
1004 const u8 *dev_addr, int request,
1005 enum p2p_prov_disc_status status,
1007 unsigned int generated_pin)
1010 DBusMessageIter iter;
1011 struct wpas_dbus_priv *iface;
1014 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1016 char pin[9], *p_pin = NULL;
1018 iface = wpa_s->global->dbus;
1020 /* Do nothing if the control interface is not turned on */
1024 if (request || !status) {
1025 if (config_methods & WPS_CONFIG_DISPLAY)
1027 "ProvisionDiscoveryRequestDisplayPin" :
1028 "ProvisionDiscoveryResponseEnterPin";
1029 else if (config_methods & WPS_CONFIG_KEYPAD)
1031 "ProvisionDiscoveryRequestEnterPin" :
1032 "ProvisionDiscoveryResponseDisplayPin";
1033 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1034 _signal = request ? "ProvisionDiscoveryPBCRequest" :
1035 "ProvisionDiscoveryPBCResponse";
1037 return; /* Unknown or un-supported method */
1038 } else if (!request && status)
1039 /* Explicit check for failure response */
1040 _signal = "ProvisionDiscoveryFailure";
1042 add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
1043 (!request && !status &&
1044 (config_methods & WPS_CONFIG_KEYPAD)));
1047 os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
1051 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1052 WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
1056 /* Check if this is a known peer */
1057 if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
1060 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1061 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1063 wpa_s->dbus_new_path, MAC2STR(dev_addr));
1065 path = peer_obj_path;
1067 dbus_message_iter_init_append(msg, &iter);
1069 if (!dbus_message_iter_append_basic(&iter,
1070 DBUS_TYPE_OBJECT_PATH,
1074 if (!request && status)
1075 /* Attach status to ProvisionDiscoveryFailure */
1076 error_ret = !dbus_message_iter_append_basic(&iter,
1080 error_ret = (add_pin &&
1081 !dbus_message_iter_append_basic(&iter,
1087 dbus_connection_send(iface->con, msg, NULL);
1089 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1091 dbus_message_unref(msg);
1095 void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
1096 const u8 *src, u16 dev_passwd_id)
1099 DBusMessageIter iter;
1100 struct wpas_dbus_priv *iface;
1101 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1103 iface = wpa_s->global->dbus;
1105 /* Do nothing if the control interface is not turned on */
1109 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1110 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1111 wpa_s->dbus_new_path, MAC2STR(src));
1112 path = peer_obj_path;
1114 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1115 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1116 "GONegotiationRequest");
1120 dbus_message_iter_init_append(msg, &iter);
1122 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1124 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
1126 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1128 dbus_connection_send(iface->con, msg, NULL);
1130 dbus_message_unref(msg);
1134 static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
1135 const struct wpa_ssid *ssid,
1136 char *group_obj_path)
1140 if (os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
1143 os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
1144 group_name[2] = '\0';
1146 os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1147 "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
1148 wpa_s->dbus_new_path, group_name);
1155 * wpas_dbus_signal_p2p_group_started - Signals P2P group has
1156 * started. Emitted when a group is successfully started
1157 * irrespective of the role (client/GO) of the current device
1159 * @wpa_s: %wpa_supplicant network interface data
1160 * @ssid: SSID object
1161 * @client: this device is P2P client
1162 * @network_id: network id of the group started, use instead of ssid->id
1163 * to account for persistent groups
1165 void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
1166 const struct wpa_ssid *ssid,
1167 int client, int network_id)
1170 DBusMessageIter iter, dict_iter;
1171 struct wpas_dbus_priv *iface;
1173 iface = wpa_s->parent->global->dbus;
1175 /* Do nothing if the control interface is not turned on */
1179 if (wpa_s->dbus_groupobj_path == NULL)
1182 /* New interface has been created for this group */
1183 msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
1184 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1189 dbus_message_iter_init_append(msg, &iter);
1190 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1194 * In case the device supports creating a separate interface the
1195 * DBus client will need to know the object path for the interface
1196 * object this group was created on, so include it here.
1198 if (!wpa_dbus_dict_append_object_path(&dict_iter,
1200 wpa_s->dbus_new_path))
1203 if (!wpa_dbus_dict_append_string(&dict_iter, "role",
1204 client ? "client" : "GO"))
1207 if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
1208 wpa_s->dbus_groupobj_path) ||
1209 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1212 dbus_connection_send(iface->con, msg, NULL);
1215 dbus_message_unref(msg);
1221 * Method to emit GONegotiation Success or Failure signals based
1223 * @status: Status of the GO neg request. 0 for success, other for errors.
1225 void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
1226 struct p2p_go_neg_results *res)
1229 DBusMessageIter iter, dict_iter;
1230 DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
1231 struct wpas_dbus_priv *iface;
1232 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1233 dbus_int32_t freqs[P2P_MAX_CHANNELS];
1234 dbus_int32_t *f_array = freqs;
1237 iface = wpa_s->global->dbus;
1239 os_memset(freqs, 0, sizeof(freqs));
1240 /* Do nothing if the control interface is not turned on */
1244 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1245 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1246 wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
1247 path = peer_obj_path;
1249 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1250 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1251 res->status ? "GONegotiationFailure" :
1252 "GONegotiationSuccess");
1256 dbus_message_iter_init_append(msg, &iter);
1257 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1259 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1261 !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
1266 int freq_list_num = 0;
1269 if (!wpa_dbus_dict_append_byte_array(
1270 &dict_iter, "passphrase",
1271 (const char *) res->passphrase,
1272 sizeof(res->passphrase)))
1276 if (!wpa_dbus_dict_append_string(&dict_iter, "role_go",
1277 res->role_go ? "GO" :
1279 !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
1281 !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
1282 (const char *) res->ssid,
1284 !wpa_dbus_dict_append_byte_array(&dict_iter,
1287 res->peer_device_addr,
1289 !wpa_dbus_dict_append_byte_array(&dict_iter,
1290 "peer_interface_addr",
1292 res->peer_interface_addr,
1294 !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
1295 p2p_wps_method_text(
1299 for (i = 0; i < P2P_MAX_CHANNELS; i++) {
1300 if (res->freq_list[i]) {
1301 freqs[i] = res->freq_list[i];
1306 if (!wpa_dbus_dict_begin_array(&dict_iter,
1308 DBUS_TYPE_INT32_AS_STRING,
1314 if (!dbus_message_iter_append_fixed_array(&iter_dict_array,
1320 if (!wpa_dbus_dict_end_array(&dict_iter,
1326 if (!wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
1327 res->persistent_group) ||
1328 !wpa_dbus_dict_append_uint32(&dict_iter,
1329 "peer_config_timeout",
1330 res->peer_config_timeout))
1334 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1337 dbus_connection_send(iface->con, msg, NULL);
1339 dbus_message_unref(msg);
1345 * Method to emit Invitation Result signal based on status and
1347 * @status: Status of the Invite request. 0 for success, other
1349 * @bssid : Basic Service Set Identifier
1351 void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
1352 int status, const u8 *bssid)
1355 DBusMessageIter iter, dict_iter;
1356 struct wpas_dbus_priv *iface;
1358 wpa_printf(MSG_DEBUG, "%s", __func__);
1360 iface = wpa_s->global->dbus;
1361 /* Do nothing if the control interface is not turned on */
1365 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1366 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1367 "InvitationResult");
1372 dbus_message_iter_init_append(msg, &iter);
1373 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1376 if (!wpa_dbus_dict_append_int32(&dict_iter, "status", status))
1379 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
1380 (const char *) bssid,
1384 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1387 dbus_connection_send(iface->con, msg, NULL);
1390 dbus_message_unref(msg);
1396 * Method to emit a signal for a peer joining the group.
1397 * The signal will carry path to the group member object
1398 * constructed using p2p i/f addr used for connecting.
1400 * @wpa_s: %wpa_supplicant network interface data
1401 * @member_addr: addr (p2p i/f) of the peer joining the group
1403 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
1406 struct wpas_dbus_priv *iface;
1408 DBusMessageIter iter;
1409 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1411 iface = wpa_s->global->dbus;
1413 /* Do nothing if the control interface is not turned on */
1417 if (!wpa_s->dbus_groupobj_path)
1420 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1421 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
1423 wpa_s->dbus_groupobj_path, MAC2STR(member));
1425 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1426 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1431 dbus_message_iter_init_append(msg, &iter);
1432 path = groupmember_obj_path;
1433 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1437 dbus_connection_send(iface->con, msg, NULL);
1439 dbus_message_unref(msg);
1443 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1444 dbus_message_unref(msg);
1450 * Method to emit a signal for a peer disconnecting the group.
1451 * The signal will carry path to the group member object
1452 * constructed using p2p i/f addr used for connecting.
1454 * @wpa_s: %wpa_supplicant network interface data
1455 * @member_addr: addr (p2p i/f) of the peer joining the group
1457 void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
1460 struct wpas_dbus_priv *iface;
1462 DBusMessageIter iter;
1463 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1465 iface = wpa_s->global->dbus;
1467 /* Do nothing if the control interface is not turned on */
1471 if (!wpa_s->dbus_groupobj_path)
1474 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1475 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
1477 wpa_s->dbus_groupobj_path, MAC2STR(member));
1479 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1480 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1481 "PeerDisconnected");
1485 dbus_message_iter_init_append(msg, &iter);
1486 path = groupmember_obj_path;
1487 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1491 dbus_connection_send(iface->con, msg, NULL);
1493 dbus_message_unref(msg);
1497 wpa_printf(MSG_ERROR, "dbus: Failed to construct PeerDisconnected "
1499 dbus_message_unref(msg);
1505 * Method to emit a signal for a service discovery request.
1506 * The signal will carry station address, frequency, dialog token,
1507 * update indicator and it tlvs
1509 * @wpa_s: %wpa_supplicant network interface data
1510 * @sa: station addr (p2p i/f) of the peer
1511 * @dialog_token: service discovery request dialog token
1512 * @update_indic: service discovery request update indicator
1513 * @tlvs: service discovery request genrated byte array of tlvs
1514 * @tlvs_len: service discovery request tlvs length
1516 void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
1517 int freq, const u8 *sa, u8 dialog_token,
1518 u16 update_indic, const u8 *tlvs,
1522 DBusMessageIter iter, dict_iter;
1523 struct wpas_dbus_priv *iface;
1524 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1525 iface = wpa_s->global->dbus;
1527 /* Do nothing if the control interface is not turned on */
1531 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1532 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1533 "ServiceDiscoveryRequest");
1537 /* Check if this is a known peer */
1538 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1541 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1542 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1543 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1545 path = peer_obj_path;
1547 dbus_message_iter_init_append(msg, &iter);
1548 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1552 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1554 !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
1555 !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
1557 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1559 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1560 (const char *) tlvs,
1562 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1565 dbus_connection_send(iface->con, msg, NULL);
1566 dbus_message_unref(msg);
1569 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1570 dbus_message_unref(msg);
1576 * Method to emit a signal for a service discovery response.
1577 * The signal will carry station address, update indicator and it
1580 * @wpa_s: %wpa_supplicant network interface data
1581 * @sa: station addr (p2p i/f) of the peer
1582 * @update_indic: service discovery request update indicator
1583 * @tlvs: service discovery request genrated byte array of tlvs
1584 * @tlvs_len: service discovery request tlvs length
1586 void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
1587 const u8 *sa, u16 update_indic,
1588 const u8 *tlvs, size_t tlvs_len)
1591 DBusMessageIter iter, dict_iter;
1592 struct wpas_dbus_priv *iface;
1593 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1594 iface = wpa_s->global->dbus;
1596 /* Do nothing if the control interface is not turned on */
1600 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1601 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1602 "ServiceDiscoveryResponse");
1606 /* Check if this is a known peer */
1607 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1610 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1611 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1612 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1614 path = peer_obj_path;
1616 dbus_message_iter_init_append(msg, &iter);
1617 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1620 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1622 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1624 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1625 (const char *) tlvs,
1627 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1631 dbus_connection_send(iface->con, msg, NULL);
1632 dbus_message_unref(msg);
1635 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1636 dbus_message_unref(msg);
1640 * wpas_dbus_signal_persistent_group - Send a persistent group related
1642 * @wpa_s: %wpa_supplicant network interface data
1643 * @id: new persistent group id
1644 * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
1645 * @properties: determines if add second argument with object properties
1647 * Notify listeners about an event related to persistent groups.
1649 static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
1650 int id, const char *sig_name,
1653 struct wpas_dbus_priv *iface;
1655 DBusMessageIter iter;
1656 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1658 iface = wpa_s->global->dbus;
1660 /* Do nothing if the control interface is not turned on */
1664 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1665 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
1666 wpa_s->dbus_new_path, id);
1668 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1669 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1674 dbus_message_iter_init_append(msg, &iter);
1675 path = pgrp_obj_path;
1676 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1681 if (!wpa_dbus_get_object_properties(
1682 iface, pgrp_obj_path,
1683 WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter))
1687 dbus_connection_send(iface->con, msg, NULL);
1689 dbus_message_unref(msg);
1693 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1694 dbus_message_unref(msg);
1699 * wpas_dbus_signal_persistent_group_added - Send a persistent_group
1701 * @wpa_s: %wpa_supplicant network interface data
1702 * @id: new persistent group id
1704 * Notify listeners about addition of a new persistent group.
1706 static void wpas_dbus_signal_persistent_group_added(
1707 struct wpa_supplicant *wpa_s, int id)
1709 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
1715 * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
1717 * @wpa_s: %wpa_supplicant network interface data
1718 * @id: persistent group id
1720 * Notify listeners about removal of a persistent group.
1722 static void wpas_dbus_signal_persistent_group_removed(
1723 struct wpa_supplicant *wpa_s, int id)
1725 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
1731 * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
1732 * @wpa_s: %wpa_supplicant network interface data
1734 * Sends Event dbus signal with name "fail" and dictionary containing
1735 * "msg" field with fail message number (int32) as arguments
1737 void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
1738 struct wps_event_fail *fail)
1742 DBusMessageIter iter, dict_iter;
1743 struct wpas_dbus_priv *iface;
1746 iface = wpa_s->global->dbus;
1748 /* Do nothing if the control interface is not turned on */
1752 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1753 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1758 dbus_message_iter_init_append(msg, &iter);
1760 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
1761 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1762 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
1763 !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
1764 fail->config_error) ||
1765 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1766 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1768 dbus_connection_send(iface->con, msg, NULL);
1770 dbus_message_unref(msg);
1773 #endif /*CONFIG_P2P*/
1777 * wpas_dbus_signal_prop_changed - Signals change of property
1778 * @wpa_s: %wpa_supplicant network interface data
1779 * @property: indicates which property has changed
1781 * Sends PropertyChanged signals with path, interface and arguments
1782 * depending on which property has changed.
1784 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
1785 enum wpas_dbus_prop property)
1790 if (wpa_s->dbus_new_path == NULL)
1791 return; /* Skip signal since D-Bus setup is not yet ready */
1795 case WPAS_DBUS_PROP_AP_SCAN:
1798 case WPAS_DBUS_PROP_SCANNING:
1801 case WPAS_DBUS_PROP_STATE:
1804 case WPAS_DBUS_PROP_CURRENT_BSS:
1805 prop = "CurrentBSS";
1807 case WPAS_DBUS_PROP_CURRENT_NETWORK:
1808 prop = "CurrentNetwork";
1810 case WPAS_DBUS_PROP_BSSS:
1813 case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
1814 prop = "CurrentAuthMode";
1816 case WPAS_DBUS_PROP_DISCONNECT_REASON:
1817 prop = "DisconnectReason";
1821 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1822 __func__, property);
1826 wpa_dbus_mark_property_changed(wpa_s->global->dbus,
1827 wpa_s->dbus_new_path,
1828 WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
1830 wpa_dbus_flush_object_changed_properties(
1831 wpa_s->global->dbus->con, wpa_s->dbus_new_path);
1837 * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
1838 * @wpa_s: %wpa_supplicant network interface data
1839 * @property: indicates which property has changed
1840 * @id: unique BSS identifier
1842 * Sends PropertyChanged signals with path, interface, and arguments depending
1843 * on which property has changed.
1845 void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
1846 enum wpas_dbus_bss_prop property,
1849 char path[WPAS_DBUS_OBJECT_PATH_MAX];
1853 case WPAS_DBUS_BSS_PROP_SIGNAL:
1856 case WPAS_DBUS_BSS_PROP_FREQ:
1859 case WPAS_DBUS_BSS_PROP_MODE:
1862 case WPAS_DBUS_BSS_PROP_PRIVACY:
1865 case WPAS_DBUS_BSS_PROP_RATES:
1868 case WPAS_DBUS_BSS_PROP_WPA:
1871 case WPAS_DBUS_BSS_PROP_RSN:
1874 case WPAS_DBUS_BSS_PROP_WPS:
1877 case WPAS_DBUS_BSS_PROP_IES:
1881 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1882 __func__, property);
1886 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1887 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1888 wpa_s->dbus_new_path, id);
1890 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
1891 WPAS_DBUS_NEW_IFACE_BSS, prop);
1896 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
1897 * @global: wpa_global structure
1899 * Sends PropertyChanged signals informing that debug level has changed.
1901 void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
1903 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1904 WPAS_DBUS_NEW_INTERFACE,
1910 * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
1911 * @global: wpa_global structure
1913 * Sends PropertyChanged signals informing that debug timestamp has changed.
1915 void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
1917 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1918 WPAS_DBUS_NEW_INTERFACE,
1924 * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
1925 * @global: wpa_global structure
1927 * Sends PropertyChanged signals informing that debug show_keys has changed.
1929 void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
1931 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1932 WPAS_DBUS_NEW_INTERFACE,
1937 static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
1939 WPADBusArgumentFreeFunction priv_free,
1940 const struct wpa_dbus_method_desc *methods,
1941 const struct wpa_dbus_property_desc *properties,
1942 const struct wpa_dbus_signal_desc *signals)
1946 obj_desc->user_data = priv;
1947 obj_desc->user_data_free_func = priv_free;
1948 obj_desc->methods = methods;
1949 obj_desc->properties = properties;
1950 obj_desc->signals = signals;
1952 for (n = 0; properties && properties->dbus_property; properties++)
1955 obj_desc->prop_changed_flags = os_zalloc(n);
1956 if (!obj_desc->prop_changed_flags)
1957 wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
1962 static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
1963 { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
1964 (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
1966 { "args", "a{sv}", ARG_IN },
1967 { "path", "o", ARG_OUT },
1971 { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
1972 (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
1974 { "path", "o", ARG_IN },
1978 { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
1979 (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
1981 { "ifname", "s", ARG_IN },
1982 { "path", "o", ARG_OUT },
1986 { NULL, NULL, NULL, { END_ARGS } }
1989 static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
1990 { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
1991 wpas_dbus_getter_debug_level,
1992 wpas_dbus_setter_debug_level
1994 { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
1995 wpas_dbus_getter_debug_timestamp,
1996 wpas_dbus_setter_debug_timestamp
1998 { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
1999 wpas_dbus_getter_debug_show_keys,
2000 wpas_dbus_setter_debug_show_keys
2002 { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
2003 wpas_dbus_getter_interfaces,
2006 { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
2007 wpas_dbus_getter_eap_methods,
2010 { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
2011 wpas_dbus_getter_global_capabilities,
2014 { NULL, NULL, NULL, NULL, NULL }
2017 static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
2018 { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
2020 { "path", "o", ARG_OUT },
2021 { "properties", "a{sv}", ARG_OUT },
2025 { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
2027 { "path", "o", ARG_OUT },
2031 { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
2033 { "path", "o", ARG_OUT },
2034 { "field", "s", ARG_OUT },
2035 { "text", "s", ARG_OUT },
2039 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2040 { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
2042 { "properties", "a{sv}", ARG_OUT },
2046 { NULL, NULL, { END_ARGS } }
2051 * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
2052 * @global: Pointer to global data from wpa_supplicant_init()
2053 * Returns: 0 on success or -1 on failure
2055 * Initialize the dbus control interface for wpa_supplicantand and start
2056 * receiving commands from external programs over the bus.
2058 int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
2060 struct wpa_dbus_object_desc *obj_desc;
2063 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2065 wpa_printf(MSG_ERROR, "Not enough memory "
2066 "to create object description");
2070 wpas_dbus_register(obj_desc, priv->global, NULL,
2071 wpas_dbus_global_methods,
2072 wpas_dbus_global_properties,
2073 wpas_dbus_global_signals);
2075 wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
2076 WPAS_DBUS_NEW_PATH);
2077 ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
2078 WPAS_DBUS_NEW_SERVICE,
2081 free_dbus_object_desc(obj_desc);
2083 priv->dbus_new_initialized = 1;
2090 * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
2092 * @iface: Pointer to dbus private data from wpas_dbus_init()
2094 * Deinitialize the dbus control interface that was initialized with
2095 * wpas_dbus_ctrl_iface_init().
2097 void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
2099 if (!iface->dbus_new_initialized)
2101 wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
2102 WPAS_DBUS_NEW_PATH);
2103 dbus_connection_unregister_object_path(iface->con,
2104 WPAS_DBUS_NEW_PATH);
2108 static void wpa_dbus_free(void *ptr)
2114 static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
2115 { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
2116 wpas_dbus_getter_network_properties,
2117 wpas_dbus_setter_network_properties
2119 { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
2120 wpas_dbus_getter_enabled,
2121 wpas_dbus_setter_enabled
2123 { NULL, NULL, NULL, NULL, NULL }
2127 static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
2128 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2129 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
2131 { "properties", "a{sv}", ARG_OUT },
2135 { NULL, NULL, { END_ARGS } }
2140 * wpas_dbus_register_network - Register a configured network with dbus
2141 * @wpa_s: wpa_supplicant interface structure
2142 * @ssid: network configuration data
2143 * Returns: 0 on success, -1 on failure
2145 * Registers network representing object with dbus
2147 int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
2148 struct wpa_ssid *ssid)
2150 struct wpas_dbus_priv *ctrl_iface;
2151 struct wpa_dbus_object_desc *obj_desc;
2152 struct network_handler_args *arg;
2153 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2157 * If it is a persistent group register it as such.
2158 * This is to handle cases where an interface is being initialized
2159 * with a list of networks read from config.
2161 if (network_is_persistent_group(ssid))
2162 return wpas_dbus_register_persistent_group(wpa_s, ssid);
2163 #endif /* CONFIG_P2P */
2165 /* Do nothing if the control interface is not turned on */
2166 if (wpa_s == NULL || wpa_s->global == NULL)
2168 ctrl_iface = wpa_s->global->dbus;
2169 if (ctrl_iface == NULL)
2172 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2173 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2174 wpa_s->dbus_new_path, ssid->id);
2176 wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
2178 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2180 wpa_printf(MSG_ERROR, "Not enough memory "
2181 "to create object description");
2185 /* allocate memory for handlers arguments */
2186 arg = os_zalloc(sizeof(struct network_handler_args));
2188 wpa_printf(MSG_ERROR, "Not enough memory "
2189 "to create arguments for method");
2196 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2197 wpas_dbus_network_properties,
2198 wpas_dbus_network_signals);
2200 if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
2201 wpa_s->ifname, obj_desc))
2204 wpas_dbus_signal_network_added(wpa_s, ssid->id);
2209 free_dbus_object_desc(obj_desc);
2215 * wpas_dbus_unregister_network - Unregister a configured network from dbus
2216 * @wpa_s: wpa_supplicant interface structure
2218 * Returns: 0 on success, -1 on failure
2220 * Unregisters network representing object from dbus
2222 int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
2224 struct wpas_dbus_priv *ctrl_iface;
2225 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2228 struct wpa_ssid *ssid;
2230 ssid = wpa_config_get_network(wpa_s->conf, nid);
2232 /* If it is a persistent group unregister it as such */
2233 if (ssid && network_is_persistent_group(ssid))
2234 return wpas_dbus_unregister_persistent_group(wpa_s, nid);
2235 #endif /* CONFIG_P2P */
2237 /* Do nothing if the control interface is not turned on */
2238 if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
2240 ctrl_iface = wpa_s->global->dbus;
2241 if (ctrl_iface == NULL)
2244 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2245 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2246 wpa_s->dbus_new_path, nid);
2248 wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
2250 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
2253 wpas_dbus_signal_network_removed(wpa_s, nid);
2259 static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
2260 { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2261 wpas_dbus_getter_bss_ssid,
2264 { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2265 wpas_dbus_getter_bss_bssid,
2268 { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
2269 wpas_dbus_getter_bss_privacy,
2272 { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
2273 wpas_dbus_getter_bss_mode,
2276 { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
2277 wpas_dbus_getter_bss_signal,
2280 { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
2281 wpas_dbus_getter_bss_frequency,
2284 { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
2285 wpas_dbus_getter_bss_rates,
2288 { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2289 wpas_dbus_getter_bss_wpa,
2292 { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2293 wpas_dbus_getter_bss_rsn,
2296 { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2297 wpas_dbus_getter_bss_wps,
2300 { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2301 wpas_dbus_getter_bss_ies,
2304 { NULL, NULL, NULL, NULL, NULL }
2308 static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
2309 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2310 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
2312 { "properties", "a{sv}", ARG_OUT },
2316 { NULL, NULL, { END_ARGS } }
2321 * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
2322 * @wpa_s: wpa_supplicant interface structure
2323 * @bssid: scanned network bssid
2324 * @id: unique BSS identifier
2325 * Returns: 0 on success, -1 on failure
2327 * Unregisters BSS representing object from dbus
2329 int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
2330 u8 bssid[ETH_ALEN], unsigned int id)
2332 struct wpas_dbus_priv *ctrl_iface;
2333 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2335 /* Do nothing if the control interface is not turned on */
2336 if (wpa_s == NULL || wpa_s->global == NULL)
2338 ctrl_iface = wpa_s->global->dbus;
2339 if (ctrl_iface == NULL)
2342 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2343 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2344 wpa_s->dbus_new_path, id);
2346 wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
2348 if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
2349 wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
2354 wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
2355 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2362 * wpas_dbus_register_bss - Register a scanned BSS with dbus
2363 * @wpa_s: wpa_supplicant interface structure
2364 * @bssid: scanned network bssid
2365 * @id: unique BSS identifier
2366 * Returns: 0 on success, -1 on failure
2368 * Registers BSS representing object with dbus
2370 int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
2371 u8 bssid[ETH_ALEN], unsigned int id)
2373 struct wpas_dbus_priv *ctrl_iface;
2374 struct wpa_dbus_object_desc *obj_desc;
2375 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2376 struct bss_handler_args *arg;
2378 /* Do nothing if the control interface is not turned on */
2379 if (wpa_s == NULL || wpa_s->global == NULL)
2381 ctrl_iface = wpa_s->global->dbus;
2382 if (ctrl_iface == NULL)
2385 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2386 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2387 wpa_s->dbus_new_path, id);
2389 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2391 wpa_printf(MSG_ERROR, "Not enough memory "
2392 "to create object description");
2396 arg = os_zalloc(sizeof(struct bss_handler_args));
2398 wpa_printf(MSG_ERROR, "Not enough memory "
2399 "to create arguments for handler");
2405 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2406 wpas_dbus_bss_properties,
2407 wpas_dbus_bss_signals);
2409 wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
2411 if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
2412 wpa_s->ifname, obj_desc)) {
2413 wpa_printf(MSG_ERROR,
2414 "Cannot register BSSID dbus object %s.",
2419 wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
2420 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2425 free_dbus_object_desc(obj_desc);
2430 static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
2431 { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2432 (WPADBusMethodHandler) &wpas_dbus_handler_scan,
2434 { "args", "a{sv}", ARG_IN },
2438 { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2439 (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
2444 { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2445 (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
2447 { "args", "a{sv}", ARG_IN },
2448 { "path", "o", ARG_OUT },
2452 { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
2453 (WPADBusMethodHandler) &wpas_dbus_handler_reassociate,
2458 { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
2459 (WPADBusMethodHandler) &wpas_dbus_handler_reattach,
2464 { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2465 (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
2467 { "path", "o", ARG_IN },
2471 { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
2472 (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
2477 { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2478 (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
2480 { "path", "o", ARG_IN },
2484 { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
2485 (WPADBusMethodHandler) &wpas_dbus_handler_network_reply,
2487 { "path", "o", ARG_IN },
2488 { "field", "s", ARG_IN },
2489 { "value", "s", ARG_IN },
2493 #ifndef CONFIG_NO_CONFIG_BLOBS
2494 { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2495 (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
2497 { "name", "s", ARG_IN },
2498 { "data", "ay", ARG_IN },
2502 { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2503 (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
2505 { "name", "s", ARG_IN },
2506 { "data", "ay", ARG_OUT },
2510 { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2511 (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
2513 { "name", "s", ARG_IN },
2517 #endif /* CONFIG_NO_CONFIG_BLOBS */
2518 { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
2519 (WPADBusMethodHandler)
2520 &wpas_dbus_handler_set_pkcs11_engine_and_module_path,
2522 { "pkcs11_engine_path", "s", ARG_IN },
2523 { "pkcs11_module_path", "s", ARG_IN },
2528 { "Start", WPAS_DBUS_NEW_IFACE_WPS,
2529 (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
2531 { "args", "a{sv}", ARG_IN },
2532 { "output", "a{sv}", ARG_OUT },
2536 #endif /* CONFIG_WPS */
2538 { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2539 (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
2541 { "args", "a{sv}", ARG_IN },
2545 { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2546 (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
2551 { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2552 (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
2554 { "timeout", "i", ARG_IN },
2558 { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2559 (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
2561 { "args", "a{sv}", ARG_IN },
2565 { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2566 (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
2568 { "args", "a{sv}", ARG_IN },
2572 { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2573 (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
2575 { "peer", "o", ARG_IN },
2576 { "config_method", "s", ARG_IN },
2580 { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2581 (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
2583 { "args", "a{sv}", ARG_IN },
2584 { "generated_pin", "s", ARG_OUT },
2588 { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2589 (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
2591 { "args", "a{sv}", ARG_IN },
2595 { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2596 (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
2598 { "args", "a{sv}", ARG_IN },
2602 { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2603 (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
2608 { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2609 (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
2611 { "peer", "o", ARG_IN },
2615 { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2616 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
2621 { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2622 (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
2624 { "args", "a{sv}", ARG_IN },
2628 { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2629 (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
2631 { "args", "a{sv}", ARG_IN },
2635 { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2636 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
2641 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2642 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
2644 { "args", "a{sv}", ARG_IN },
2645 { "ref", "t", ARG_OUT },
2649 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2650 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
2652 { "args", "a{sv}", ARG_IN },
2656 { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2657 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
2659 { "args", "t", ARG_IN },
2663 { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2664 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
2669 { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2670 (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
2672 { "arg", "i", ARG_IN },
2676 { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2677 (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
2679 { "args", "a{sv}", ARG_IN },
2680 { "path", "o", ARG_OUT },
2684 { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2685 (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
2687 { "path", "o", ARG_IN },
2691 { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2692 (WPADBusMethodHandler)
2693 wpas_dbus_handler_remove_all_persistent_groups,
2698 #endif /* CONFIG_P2P */
2699 { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
2700 (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
2702 { "age", "u", ARG_IN },
2707 { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2708 (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
2713 { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2714 (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
2719 #endif /* CONFIG_AP */
2720 { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
2721 (WPADBusMethodHandler) &wpas_dbus_handler_eap_logoff,
2726 { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
2727 (WPADBusMethodHandler) &wpas_dbus_handler_eap_logon,
2732 #ifdef CONFIG_AUTOSCAN
2733 { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2734 (WPADBusMethodHandler) &wpas_dbus_handler_autoscan,
2736 { "arg", "s", ARG_IN },
2740 #endif /* CONFIG_AUTOSCAN */
2742 { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
2743 (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
2745 { "peer_address", "s", ARG_IN },
2749 { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
2750 (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
2752 { "peer_address", "s", ARG_IN },
2756 { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
2757 (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
2759 { "peer_address", "s", ARG_IN },
2760 { "status", "s", ARG_OUT },
2764 { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
2765 (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
2767 { "peer_address", "s", ARG_IN },
2771 #endif /* CONFIG_TDLS */
2772 { NULL, NULL, NULL, { END_ARGS } }
2775 static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
2776 { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
2777 wpas_dbus_getter_capabilities,
2780 { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2781 wpas_dbus_getter_state,
2784 { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2785 wpas_dbus_getter_scanning,
2788 { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2789 wpas_dbus_getter_ap_scan,
2790 wpas_dbus_setter_ap_scan
2792 { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2793 wpas_dbus_getter_bss_expire_age,
2794 wpas_dbus_setter_bss_expire_age
2796 { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2797 wpas_dbus_getter_bss_expire_count,
2798 wpas_dbus_setter_bss_expire_count
2800 { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2801 wpas_dbus_getter_country,
2802 wpas_dbus_setter_country
2804 { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2805 wpas_dbus_getter_ifname,
2808 { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2809 wpas_dbus_getter_driver,
2812 { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2813 wpas_dbus_getter_bridge_ifname,
2816 { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2817 wpas_dbus_getter_current_bss,
2820 { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2821 wpas_dbus_getter_current_network,
2824 { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2825 wpas_dbus_getter_current_auth_mode,
2828 { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
2829 wpas_dbus_getter_blobs,
2832 { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2833 wpas_dbus_getter_bsss,
2836 { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2837 wpas_dbus_getter_networks,
2840 { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2841 wpas_dbus_getter_fast_reauth,
2842 wpas_dbus_setter_fast_reauth
2844 { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
2845 wpas_dbus_getter_scan_interval,
2846 wpas_dbus_setter_scan_interval
2848 { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2849 wpas_dbus_getter_pkcs11_engine_path,
2852 { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2853 wpas_dbus_getter_pkcs11_module_path,
2857 { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
2858 wpas_dbus_getter_process_credentials,
2859 wpas_dbus_setter_process_credentials
2861 #endif /* CONFIG_WPS */
2863 { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
2864 wpas_dbus_getter_p2p_device_config,
2865 wpas_dbus_setter_p2p_device_config
2867 { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2868 wpas_dbus_getter_p2p_peers,
2871 { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
2872 wpas_dbus_getter_p2p_role,
2875 { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2876 wpas_dbus_getter_p2p_group,
2879 { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2880 wpas_dbus_getter_p2p_peergo,
2883 { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2884 wpas_dbus_getter_persistent_groups,
2887 #endif /* CONFIG_P2P */
2888 { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
2889 wpas_dbus_getter_disconnect_reason,
2892 { NULL, NULL, NULL, NULL, NULL }
2895 static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
2896 { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
2898 { "success", "b", ARG_OUT },
2902 { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2904 { "path", "o", ARG_OUT },
2905 { "properties", "a{sv}", ARG_OUT },
2909 { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2911 { "path", "o", ARG_OUT },
2915 { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2917 { "name", "s", ARG_OUT },
2921 { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2923 { "name", "s", ARG_OUT },
2927 { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2929 { "path", "o", ARG_OUT },
2930 { "properties", "a{sv}", ARG_OUT },
2934 { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2936 { "path", "o", ARG_OUT },
2940 { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
2942 { "path", "o", ARG_OUT },
2946 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2947 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
2949 { "properties", "a{sv}", ARG_OUT },
2954 { "Event", WPAS_DBUS_NEW_IFACE_WPS,
2956 { "name", "s", ARG_OUT },
2957 { "args", "a{sv}", ARG_OUT },
2961 { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
2963 { "credentials", "a{sv}", ARG_OUT },
2967 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2968 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
2970 { "properties", "a{sv}", ARG_OUT },
2974 #endif /* CONFIG_WPS */
2976 { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2978 { "states", "a{ss}", ARG_OUT },
2982 { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2984 { "path", "o", ARG_OUT },
2988 { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2990 { "path", "o", ARG_OUT },
2994 { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2996 { "peer_object", "o", ARG_OUT },
2997 { "pin", "s", ARG_OUT },
3001 { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3003 { "peer_object", "o", ARG_OUT },
3004 { "pin", "s", ARG_OUT },
3008 { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3010 { "peer_object", "o", ARG_OUT },
3014 { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3016 { "peer_object", "o", ARG_OUT },
3020 { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3022 { "peer_object", "o", ARG_OUT },
3026 { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3028 { "peer_object", "o", ARG_OUT },
3032 { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3034 { "peer_object", "o", ARG_OUT },
3035 { "status", "i", ARG_OUT },
3039 { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3041 { "properties", "a{sv}", ARG_OUT },
3045 { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3047 { "properties", "a{sv}", ARG_OUT },
3051 { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3053 { "properties", "a{sv}", ARG_OUT },
3057 { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3059 { "path", "o", ARG_OUT },
3060 { "dev_passwd_id", "i", ARG_OUT },
3064 { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3066 { "invite_result", "a{sv}", ARG_OUT },
3070 { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3072 { "ifname", "s", ARG_OUT },
3073 { "role", "s", ARG_OUT },
3077 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3079 { "sd_request", "a{sv}", ARG_OUT },
3083 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3085 { "sd_response", "a{sv}", ARG_OUT },
3089 { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3091 { "path", "o", ARG_OUT },
3092 { "properties", "a{sv}", ARG_OUT },
3096 { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3098 { "path", "o", ARG_OUT },
3102 { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3104 { "name", "s", ARG_OUT },
3105 { "args", "a{sv}", ARG_OUT },
3109 #endif /* CONFIG_P2P */
3111 { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
3113 { "args", "a{sv}", ARG_OUT },
3117 #endif /* CONFIG_AP */
3118 { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
3120 { "certification", "a{sv}", ARG_OUT },
3124 { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
3126 { "status", "s", ARG_OUT },
3127 { "parameter", "s", ARG_OUT },
3131 { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3133 { "name", "s", ARG_OUT },
3137 { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3139 { "name", "s", ARG_OUT },
3143 { NULL, NULL, { END_ARGS } }
3147 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
3150 struct wpa_dbus_object_desc *obj_desc = NULL;
3151 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
3154 /* Do nothing if the control interface is not turned on */
3155 if (ctrl_iface == NULL)
3158 /* Create and set the interface's object path */
3159 wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3160 if (wpa_s->dbus_new_path == NULL)
3162 next = ctrl_iface->next_objid++;
3163 os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
3164 WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
3167 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3169 wpa_printf(MSG_ERROR, "Not enough memory "
3170 "to create object description");
3174 wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
3175 wpas_dbus_interface_properties,
3176 wpas_dbus_interface_signals);
3178 wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
3179 wpa_s->dbus_new_path);
3180 if (wpa_dbus_register_object_per_iface(ctrl_iface,
3181 wpa_s->dbus_new_path,
3182 wpa_s->ifname, obj_desc))
3185 wpas_dbus_signal_interface_added(wpa_s);
3190 os_free(wpa_s->dbus_new_path);
3191 wpa_s->dbus_new_path = NULL;
3192 free_dbus_object_desc(obj_desc);
3197 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
3199 struct wpas_dbus_priv *ctrl_iface;
3201 /* Do nothing if the control interface is not turned on */
3202 if (wpa_s == NULL || wpa_s->global == NULL)
3204 ctrl_iface = wpa_s->global->dbus;
3205 if (ctrl_iface == NULL)
3208 wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
3209 wpa_s->dbus_new_path);
3212 if (wpa_s->preq_notify_peer) {
3213 wpas_dbus_unsubscribe_noc(ctrl_iface);
3214 os_free(wpa_s->preq_notify_peer);
3215 wpa_s->preq_notify_peer = NULL;
3217 #endif /* CONFIG_AP */
3219 if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
3220 wpa_s->dbus_new_path))
3223 wpas_dbus_signal_interface_removed(wpa_s);
3225 os_free(wpa_s->dbus_new_path);
3226 wpa_s->dbus_new_path = NULL;
3233 static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
3234 { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3235 wpas_dbus_getter_p2p_peer_device_name,
3238 { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3239 wpas_dbus_getter_p2p_peer_primary_device_type,
3242 { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
3243 wpas_dbus_getter_p2p_peer_config_method,
3246 { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
3247 wpas_dbus_getter_p2p_peer_level,
3250 { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3251 wpas_dbus_getter_p2p_peer_device_capability,
3254 { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3255 wpas_dbus_getter_p2p_peer_group_capability,
3258 { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3259 wpas_dbus_getter_p2p_peer_secondary_device_types,
3262 { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3263 wpas_dbus_getter_p2p_peer_vendor_extension,
3266 { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3267 wpas_dbus_getter_p2p_peer_ies,
3270 { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3271 wpas_dbus_getter_p2p_peer_device_address,
3274 { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
3275 wpas_dbus_getter_p2p_peer_groups,
3278 { NULL, NULL, NULL, NULL, NULL }
3281 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
3283 { NULL, NULL, { END_ARGS } }
3287 * wpas_dbus_signal_peer - Send a peer related event signal
3288 * @wpa_s: %wpa_supplicant network interface data
3289 * @dev: peer device object
3290 * @interface: name of the interface emitting this signal.
3291 * In case of peer objects, it would be emitted by either
3292 * the "interface object" or by "peer objects"
3293 * @sig_name: signal name - DeviceFound
3295 * Notify listeners about event related with newly found p2p peer device
3297 static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
3298 const u8 *dev_addr, const char *interface,
3299 const char *sig_name)
3301 struct wpas_dbus_priv *iface;
3303 DBusMessageIter iter;
3304 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
3306 iface = wpa_s->global->dbus;
3308 /* Do nothing if the control interface is not turned on */
3312 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3313 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3314 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3316 msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
3321 dbus_message_iter_init_append(msg, &iter);
3322 path = peer_obj_path;
3323 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
3327 dbus_connection_send(iface->con, msg, NULL);
3329 dbus_message_unref(msg);
3333 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
3334 dbus_message_unref(msg);
3339 * wpas_dbus_signal_peer_found - Send a peer found signal
3340 * @wpa_s: %wpa_supplicant network interface data
3341 * @dev: peer device object
3343 * Notify listeners about find a p2p peer device found
3345 void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
3348 wpas_dbus_signal_peer(wpa_s, dev_addr,
3349 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3354 * wpas_dbus_signal_peer_lost - Send a peer lost signal
3355 * @wpa_s: %wpa_supplicant network interface data
3356 * @dev: peer device object
3358 * Notify listeners about lost a p2p peer device
3360 void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
3363 wpas_dbus_signal_peer(wpa_s, dev_addr,
3364 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3369 * wpas_dbus_register_peer - Register a discovered peer object with dbus
3370 * @wpa_s: wpa_supplicant interface structure
3371 * @ssid: network configuration data
3372 * Returns: 0 on success, -1 on failure
3374 * Registers network representing object with dbus
3376 int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
3378 struct wpas_dbus_priv *ctrl_iface;
3379 struct wpa_dbus_object_desc *obj_desc;
3380 struct peer_handler_args *arg;
3381 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3383 /* Do nothing if the control interface is not turned on */
3384 if (wpa_s == NULL || wpa_s->global == NULL)
3387 ctrl_iface = wpa_s->global->dbus;
3388 if (ctrl_iface == NULL)
3391 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3392 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3393 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3395 wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
3397 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3399 wpa_printf(MSG_ERROR, "Not enough memory "
3400 "to create object description");
3404 /* allocate memory for handlers arguments */
3405 arg = os_zalloc(sizeof(struct peer_handler_args));
3407 wpa_printf(MSG_ERROR, "Not enough memory "
3408 "to create arguments for method");
3413 os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
3415 wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
3417 wpas_dbus_p2p_peer_properties,
3418 wpas_dbus_p2p_peer_signals);
3420 if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
3421 wpa_s->ifname, obj_desc))
3427 free_dbus_object_desc(obj_desc);
3432 * wpas_dbus_unregister_peer - Unregister a peer object with dbus
3433 * @wpa_s: wpa_supplicant interface structure
3434 * @dev_addr: p2p device addr
3435 * Returns: 0 on success, -1 on failure
3437 * Registers network representing object with dbus
3439 int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
3442 struct wpas_dbus_priv *ctrl_iface;
3443 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3446 /* Do nothing if the control interface is not turned on */
3447 if (wpa_s == NULL || wpa_s->global == NULL ||
3448 wpa_s->dbus_new_path == NULL)
3450 ctrl_iface = wpa_s->global->dbus;
3451 if (ctrl_iface == NULL)
3454 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3455 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3456 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3458 wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
3460 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
3466 static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
3467 { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
3468 wpas_dbus_getter_p2p_group_members,
3471 { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
3472 wpas_dbus_getter_p2p_group,
3475 { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3476 wpas_dbus_getter_p2p_role,
3479 { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3480 wpas_dbus_getter_p2p_group_ssid,
3483 { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3484 wpas_dbus_getter_p2p_group_bssid,
3487 { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
3488 wpas_dbus_getter_p2p_group_frequency,
3491 { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3492 wpas_dbus_getter_p2p_group_passphrase,
3495 { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3496 wpas_dbus_getter_p2p_group_psk,
3499 { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
3500 wpas_dbus_getter_p2p_group_vendor_ext,
3501 wpas_dbus_setter_p2p_group_vendor_ext
3503 { NULL, NULL, NULL, NULL, NULL }
3506 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
3507 { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3509 { "peer", "o", ARG_OUT },
3513 { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3515 { "peer", "o", ARG_OUT },
3519 { NULL, NULL, { END_ARGS } }
3523 * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
3524 * @wpa_s: wpa_supplicant interface structure
3525 * @ssid: SSID struct
3526 * Returns: 0 on success, -1 on failure
3528 * Registers p2p group representing object with dbus
3530 void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
3531 struct wpa_ssid *ssid)
3533 struct wpas_dbus_priv *ctrl_iface;
3534 struct wpa_dbus_object_desc *obj_desc;
3535 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3537 /* Do nothing if the control interface is not turned on */
3538 if (wpa_s == NULL || wpa_s->global == NULL)
3541 ctrl_iface = wpa_s->global->dbus;
3542 if (ctrl_iface == NULL)
3545 if (wpa_s->dbus_groupobj_path) {
3546 wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
3547 __func__, wpa_s->dbus_groupobj_path);
3551 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
3554 wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
3555 if (wpa_s->dbus_groupobj_path == NULL)
3558 wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
3560 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3562 wpa_printf(MSG_ERROR, "Not enough memory "
3563 "to create object description");
3567 wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
3568 wpas_dbus_p2p_group_properties,
3569 wpas_dbus_p2p_group_signals);
3571 if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
3572 wpa_s->ifname, obj_desc))
3578 if (wpa_s->dbus_groupobj_path) {
3579 os_free(wpa_s->dbus_groupobj_path);
3580 wpa_s->dbus_groupobj_path = NULL;
3583 free_dbus_object_desc(obj_desc);
3587 * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
3588 * @wpa_s: wpa_supplicant interface structure
3589 * @ssid: network name of the p2p group started
3591 void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
3592 const struct wpa_ssid *ssid)
3594 struct wpas_dbus_priv *ctrl_iface;
3596 /* Do nothing if the control interface is not turned on */
3597 if (wpa_s == NULL || wpa_s->global == NULL)
3600 ctrl_iface = wpa_s->global->dbus;
3601 if (ctrl_iface == NULL)
3604 if (!wpa_s->dbus_groupobj_path) {
3605 wpa_printf(MSG_DEBUG,
3606 "%s: Group object '%s' already unregistered",
3607 __func__, wpa_s->dbus_groupobj_path);
3611 wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
3612 wpa_s->dbus_groupobj_path);
3614 wpa_dbus_unregister_object_per_iface(ctrl_iface,
3615 wpa_s->dbus_groupobj_path);
3617 os_free(wpa_s->dbus_groupobj_path);
3618 wpa_s->dbus_groupobj_path = NULL;
3621 static const struct wpa_dbus_property_desc
3622 wpas_dbus_p2p_groupmember_properties[] = {
3623 { NULL, NULL, NULL, NULL, NULL }
3627 * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
3629 * @wpa_s: wpa_supplicant interface structure
3630 * @p2p_if_addr: i/f addr of the device joining this group
3632 * Registers p2p groupmember representing object with dbus
3634 void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
3635 const u8 *p2p_if_addr)
3637 struct wpas_dbus_priv *ctrl_iface;
3638 struct wpa_dbus_object_desc *obj_desc = NULL;
3639 struct groupmember_handler_args *arg;
3640 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3642 /* Do nothing if the control interface is not turned on */
3643 if (wpa_s == NULL || wpa_s->global == NULL)
3646 ctrl_iface = wpa_s->global->dbus;
3647 if (ctrl_iface == NULL)
3650 if (!wpa_s->dbus_groupobj_path)
3653 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3654 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
3655 wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
3657 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3659 wpa_printf(MSG_ERROR, "Not enough memory "
3660 "to create object description");
3664 /* allocate memory for handlers arguments */
3665 arg = os_zalloc(sizeof(struct groupmember_handler_args));
3667 wpa_printf(MSG_ERROR, "Not enough memory "
3668 "to create arguments for method");
3673 os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
3675 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3676 wpas_dbus_p2p_groupmember_properties, NULL);
3678 if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
3679 wpa_s->ifname, obj_desc))
3682 wpa_printf(MSG_INFO,
3683 "dbus: Registered group member object '%s' successfully",
3684 groupmember_obj_path);
3688 free_dbus_object_desc(obj_desc);
3692 * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
3694 * @wpa_s: wpa_supplicant interface structure
3695 * @p2p_if_addr: i/f addr of the device joining this group
3697 * Unregisters p2p groupmember representing object with dbus
3699 void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
3700 const u8 *p2p_if_addr)
3702 struct wpas_dbus_priv *ctrl_iface;
3703 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3705 /* Do nothing if the control interface is not turned on */
3706 if (wpa_s == NULL || wpa_s->global == NULL)
3709 ctrl_iface = wpa_s->global->dbus;
3710 if (ctrl_iface == NULL)
3713 if (!wpa_s->dbus_groupobj_path)
3716 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3717 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
3718 wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
3720 wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
3724 static const struct wpa_dbus_property_desc
3725 wpas_dbus_persistent_group_properties[] = {
3726 { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
3727 wpas_dbus_getter_persistent_group_properties,
3728 wpas_dbus_setter_persistent_group_properties
3730 { NULL, NULL, NULL, NULL, NULL }
3733 /* No signals intended for persistent group objects */
3736 * wpas_dbus_register_persistent_group - Register a configured(saved)
3737 * persistent group with dbus
3738 * @wpa_s: wpa_supplicant interface structure
3739 * @ssid: persistent group (still represented as a network within wpa)
3740 * configuration data
3741 * Returns: 0 on success, -1 on failure
3743 * Registers a persistent group representing object with dbus.
3745 int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
3746 struct wpa_ssid *ssid)
3748 struct wpas_dbus_priv *ctrl_iface;
3749 struct wpa_dbus_object_desc *obj_desc;
3750 struct network_handler_args *arg;
3751 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3753 /* Do nothing if the control interface is not turned on */
3754 if (wpa_s == NULL || wpa_s->global == NULL)
3757 /* Make sure ssid is a persistent group */
3758 if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
3759 return -1; /* should we return w/o complaining? */
3761 ctrl_iface = wpa_s->global->dbus;
3762 if (ctrl_iface == NULL)
3766 * Intentionally not coming up with different numbering scheme
3767 * for persistent groups.
3769 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3770 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3771 wpa_s->dbus_new_path, ssid->id);
3773 wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
3775 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3777 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3778 "object description");
3783 * Reusing the same context structure as that for networks
3784 * since these are represented using same data structure.
3786 /* allocate memory for handlers arguments */
3787 arg = os_zalloc(sizeof(struct network_handler_args));
3789 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3790 "arguments for method");
3797 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3798 wpas_dbus_persistent_group_properties,
3801 if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
3802 wpa_s->ifname, obj_desc))
3805 wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
3810 free_dbus_object_desc(obj_desc);
3816 * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
3818 * @wpa_s: wpa_supplicant interface structure
3820 * Returns: 0 on success, -1 on failure
3822 * Unregisters persistent group representing object from dbus
3824 * NOTE: There is a slight issue with the semantics here. While the
3825 * implementation simply means the persistent group is unloaded from memory,
3826 * it should not get interpreted as the group is actually being erased/removed
3827 * from persistent storage as well.
3829 int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
3832 struct wpas_dbus_priv *ctrl_iface;
3833 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3836 /* Do nothing if the control interface is not turned on */
3837 if (wpa_s == NULL || wpa_s->global == NULL ||
3838 wpa_s->dbus_new_path == NULL)
3840 ctrl_iface = wpa_s->global->dbus;
3841 if (ctrl_iface == NULL)
3844 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3845 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3846 wpa_s->dbus_new_path, nid);
3848 wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
3850 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
3853 wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
3858 #endif /* CONFIG_P2P */