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;
1172 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1174 iface = wpa_s->parent->global->dbus;
1176 /* Do nothing if the control interface is not turned on */
1180 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
1183 /* New interface has been created for this group */
1184 msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
1185 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1191 dbus_message_iter_init_append(msg, &iter);
1192 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1196 * In case the device supports creating a separate interface the
1197 * DBus client will need to know the object path for the interface
1198 * object this group was created on, so include it here.
1200 if (!wpa_dbus_dict_append_object_path(&dict_iter,
1202 wpa_s->dbus_new_path))
1205 if (!wpa_dbus_dict_append_string(&dict_iter, "role",
1206 client ? "client" : "GO"))
1209 if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
1211 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1214 dbus_connection_send(iface->con, msg, NULL);
1217 dbus_message_unref(msg);
1223 * Method to emit GONegotiation Success or Failure signals based
1225 * @status: Status of the GO neg request. 0 for success, other for errors.
1227 void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
1228 struct p2p_go_neg_results *res)
1231 DBusMessageIter iter, dict_iter;
1232 DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
1233 struct wpas_dbus_priv *iface;
1234 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1235 dbus_int32_t freqs[P2P_MAX_CHANNELS];
1236 dbus_int32_t *f_array = freqs;
1239 iface = wpa_s->global->dbus;
1241 os_memset(freqs, 0, sizeof(freqs));
1242 /* Do nothing if the control interface is not turned on */
1246 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1247 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1248 wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
1249 path = peer_obj_path;
1251 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1252 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1253 res->status ? "GONegotiationFailure" :
1254 "GONegotiationSuccess");
1258 dbus_message_iter_init_append(msg, &iter);
1259 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1261 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1263 !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
1268 int freq_list_num = 0;
1271 if (!wpa_dbus_dict_append_byte_array(
1272 &dict_iter, "passphrase",
1273 (const char *) res->passphrase,
1274 sizeof(res->passphrase)))
1278 if (!wpa_dbus_dict_append_string(&dict_iter, "role_go",
1279 res->role_go ? "GO" :
1281 !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
1283 !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
1284 (const char *) res->ssid,
1286 !wpa_dbus_dict_append_byte_array(&dict_iter,
1289 res->peer_device_addr,
1291 !wpa_dbus_dict_append_byte_array(&dict_iter,
1292 "peer_interface_addr",
1294 res->peer_interface_addr,
1296 !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
1297 p2p_wps_method_text(
1301 for (i = 0; i < P2P_MAX_CHANNELS; i++) {
1302 if (res->freq_list[i]) {
1303 freqs[i] = res->freq_list[i];
1308 if (!wpa_dbus_dict_begin_array(&dict_iter,
1310 DBUS_TYPE_INT32_AS_STRING,
1316 if (!dbus_message_iter_append_fixed_array(&iter_dict_array,
1322 if (!wpa_dbus_dict_end_array(&dict_iter,
1328 if (!wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
1329 res->persistent_group) ||
1330 !wpa_dbus_dict_append_uint32(&dict_iter,
1331 "peer_config_timeout",
1332 res->peer_config_timeout))
1336 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1339 dbus_connection_send(iface->con, msg, NULL);
1341 dbus_message_unref(msg);
1347 * Method to emit Invitation Result signal based on status and
1349 * @status: Status of the Invite request. 0 for success, other
1351 * @bssid : Basic Service Set Identifier
1353 void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
1354 int status, const u8 *bssid)
1357 DBusMessageIter iter, dict_iter;
1358 struct wpas_dbus_priv *iface;
1360 wpa_printf(MSG_DEBUG, "%s", __func__);
1362 iface = wpa_s->global->dbus;
1363 /* Do nothing if the control interface is not turned on */
1367 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1368 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1369 "InvitationResult");
1374 dbus_message_iter_init_append(msg, &iter);
1375 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1378 if (!wpa_dbus_dict_append_int32(&dict_iter, "status", status))
1381 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
1382 (const char *) bssid,
1386 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1389 dbus_connection_send(iface->con, msg, NULL);
1392 dbus_message_unref(msg);
1398 * Method to emit a signal for a peer joining the group.
1399 * The signal will carry path to the group member object
1400 * constructed using p2p i/f addr used for connecting.
1402 * @wpa_s: %wpa_supplicant network interface data
1403 * @member_addr: addr (p2p i/f) of the peer joining the group
1405 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
1408 struct wpas_dbus_priv *iface;
1410 DBusMessageIter iter;
1411 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1413 iface = wpa_s->global->dbus;
1415 /* Do nothing if the control interface is not turned on */
1419 if (!wpa_s->dbus_groupobj_path)
1422 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1423 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
1425 wpa_s->dbus_groupobj_path, MAC2STR(member));
1427 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1428 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1433 dbus_message_iter_init_append(msg, &iter);
1434 path = groupmember_obj_path;
1435 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1439 dbus_connection_send(iface->con, msg, NULL);
1441 dbus_message_unref(msg);
1445 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1446 dbus_message_unref(msg);
1452 * Method to emit a signal for a peer disconnecting the group.
1453 * The signal will carry path to the group member object
1454 * constructed using p2p i/f addr used for connecting.
1456 * @wpa_s: %wpa_supplicant network interface data
1457 * @member_addr: addr (p2p i/f) of the peer joining the group
1459 void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
1462 struct wpas_dbus_priv *iface;
1464 DBusMessageIter iter;
1465 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1467 iface = wpa_s->global->dbus;
1469 /* Do nothing if the control interface is not turned on */
1473 if (!wpa_s->dbus_groupobj_path)
1476 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1477 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
1479 wpa_s->dbus_groupobj_path, MAC2STR(member));
1481 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1482 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1483 "PeerDisconnected");
1487 dbus_message_iter_init_append(msg, &iter);
1488 path = groupmember_obj_path;
1489 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1493 dbus_connection_send(iface->con, msg, NULL);
1495 dbus_message_unref(msg);
1499 wpa_printf(MSG_ERROR, "dbus: Failed to construct PeerDisconnected "
1501 dbus_message_unref(msg);
1507 * Method to emit a signal for a service discovery request.
1508 * The signal will carry station address, frequency, dialog token,
1509 * update indicator and it tlvs
1511 * @wpa_s: %wpa_supplicant network interface data
1512 * @sa: station addr (p2p i/f) of the peer
1513 * @dialog_token: service discovery request dialog token
1514 * @update_indic: service discovery request update indicator
1515 * @tlvs: service discovery request genrated byte array of tlvs
1516 * @tlvs_len: service discovery request tlvs length
1518 void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
1519 int freq, const u8 *sa, u8 dialog_token,
1520 u16 update_indic, const u8 *tlvs,
1524 DBusMessageIter iter, dict_iter;
1525 struct wpas_dbus_priv *iface;
1526 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1527 iface = wpa_s->global->dbus;
1529 /* Do nothing if the control interface is not turned on */
1533 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1534 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1535 "ServiceDiscoveryRequest");
1539 /* Check if this is a known peer */
1540 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1543 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1544 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1545 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1547 path = peer_obj_path;
1549 dbus_message_iter_init_append(msg, &iter);
1550 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1554 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1556 !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
1557 !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
1559 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1561 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1562 (const char *) tlvs,
1564 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1567 dbus_connection_send(iface->con, msg, NULL);
1568 dbus_message_unref(msg);
1571 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1572 dbus_message_unref(msg);
1578 * Method to emit a signal for a service discovery response.
1579 * The signal will carry station address, update indicator and it
1582 * @wpa_s: %wpa_supplicant network interface data
1583 * @sa: station addr (p2p i/f) of the peer
1584 * @update_indic: service discovery request update indicator
1585 * @tlvs: service discovery request genrated byte array of tlvs
1586 * @tlvs_len: service discovery request tlvs length
1588 void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
1589 const u8 *sa, u16 update_indic,
1590 const u8 *tlvs, size_t tlvs_len)
1593 DBusMessageIter iter, dict_iter;
1594 struct wpas_dbus_priv *iface;
1595 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1596 iface = wpa_s->global->dbus;
1598 /* Do nothing if the control interface is not turned on */
1602 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1603 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1604 "ServiceDiscoveryResponse");
1608 /* Check if this is a known peer */
1609 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1612 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1613 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1614 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1616 path = peer_obj_path;
1618 dbus_message_iter_init_append(msg, &iter);
1619 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1622 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1624 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1626 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1627 (const char *) tlvs,
1629 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1633 dbus_connection_send(iface->con, msg, NULL);
1634 dbus_message_unref(msg);
1637 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1638 dbus_message_unref(msg);
1642 * wpas_dbus_signal_persistent_group - Send a persistent group related
1644 * @wpa_s: %wpa_supplicant network interface data
1645 * @id: new persistent group id
1646 * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
1647 * @properties: determines if add second argument with object properties
1649 * Notify listeners about an event related to persistent groups.
1651 static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
1652 int id, const char *sig_name,
1655 struct wpas_dbus_priv *iface;
1657 DBusMessageIter iter;
1658 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1660 iface = wpa_s->global->dbus;
1662 /* Do nothing if the control interface is not turned on */
1666 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1667 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
1668 wpa_s->dbus_new_path, id);
1670 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1671 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1676 dbus_message_iter_init_append(msg, &iter);
1677 path = pgrp_obj_path;
1678 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1683 if (!wpa_dbus_get_object_properties(
1684 iface, pgrp_obj_path,
1685 WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter))
1689 dbus_connection_send(iface->con, msg, NULL);
1691 dbus_message_unref(msg);
1695 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1696 dbus_message_unref(msg);
1701 * wpas_dbus_signal_persistent_group_added - Send a persistent_group
1703 * @wpa_s: %wpa_supplicant network interface data
1704 * @id: new persistent group id
1706 * Notify listeners about addition of a new persistent group.
1708 static void wpas_dbus_signal_persistent_group_added(
1709 struct wpa_supplicant *wpa_s, int id)
1711 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
1717 * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
1719 * @wpa_s: %wpa_supplicant network interface data
1720 * @id: persistent group id
1722 * Notify listeners about removal of a persistent group.
1724 static void wpas_dbus_signal_persistent_group_removed(
1725 struct wpa_supplicant *wpa_s, int id)
1727 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
1733 * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
1734 * @wpa_s: %wpa_supplicant network interface data
1736 * Sends Event dbus signal with name "fail" and dictionary containing
1737 * "msg" field with fail message number (int32) as arguments
1739 void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
1740 struct wps_event_fail *fail)
1744 DBusMessageIter iter, dict_iter;
1745 struct wpas_dbus_priv *iface;
1748 iface = wpa_s->global->dbus;
1750 /* Do nothing if the control interface is not turned on */
1754 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1755 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1760 dbus_message_iter_init_append(msg, &iter);
1762 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
1763 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1764 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
1765 !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
1766 fail->config_error) ||
1767 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1768 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1770 dbus_connection_send(iface->con, msg, NULL);
1772 dbus_message_unref(msg);
1775 #endif /*CONFIG_P2P*/
1779 * wpas_dbus_signal_prop_changed - Signals change of property
1780 * @wpa_s: %wpa_supplicant network interface data
1781 * @property: indicates which property has changed
1783 * Sends PropertyChanged signals with path, interface and arguments
1784 * depending on which property has changed.
1786 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
1787 enum wpas_dbus_prop property)
1792 if (wpa_s->dbus_new_path == NULL)
1793 return; /* Skip signal since D-Bus setup is not yet ready */
1797 case WPAS_DBUS_PROP_AP_SCAN:
1800 case WPAS_DBUS_PROP_SCANNING:
1803 case WPAS_DBUS_PROP_STATE:
1806 case WPAS_DBUS_PROP_CURRENT_BSS:
1807 prop = "CurrentBSS";
1809 case WPAS_DBUS_PROP_CURRENT_NETWORK:
1810 prop = "CurrentNetwork";
1812 case WPAS_DBUS_PROP_BSSS:
1815 case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
1816 prop = "CurrentAuthMode";
1818 case WPAS_DBUS_PROP_DISCONNECT_REASON:
1819 prop = "DisconnectReason";
1823 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1824 __func__, property);
1828 wpa_dbus_mark_property_changed(wpa_s->global->dbus,
1829 wpa_s->dbus_new_path,
1830 WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
1832 wpa_dbus_flush_object_changed_properties(
1833 wpa_s->global->dbus->con, wpa_s->dbus_new_path);
1839 * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
1840 * @wpa_s: %wpa_supplicant network interface data
1841 * @property: indicates which property has changed
1842 * @id: unique BSS identifier
1844 * Sends PropertyChanged signals with path, interface, and arguments depending
1845 * on which property has changed.
1847 void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
1848 enum wpas_dbus_bss_prop property,
1851 char path[WPAS_DBUS_OBJECT_PATH_MAX];
1855 case WPAS_DBUS_BSS_PROP_SIGNAL:
1858 case WPAS_DBUS_BSS_PROP_FREQ:
1861 case WPAS_DBUS_BSS_PROP_MODE:
1864 case WPAS_DBUS_BSS_PROP_PRIVACY:
1867 case WPAS_DBUS_BSS_PROP_RATES:
1870 case WPAS_DBUS_BSS_PROP_WPA:
1873 case WPAS_DBUS_BSS_PROP_RSN:
1876 case WPAS_DBUS_BSS_PROP_WPS:
1879 case WPAS_DBUS_BSS_PROP_IES:
1883 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1884 __func__, property);
1888 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1889 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1890 wpa_s->dbus_new_path, id);
1892 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
1893 WPAS_DBUS_NEW_IFACE_BSS, prop);
1898 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
1899 * @global: wpa_global structure
1901 * Sends PropertyChanged signals informing that debug level has changed.
1903 void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
1905 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1906 WPAS_DBUS_NEW_INTERFACE,
1912 * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
1913 * @global: wpa_global structure
1915 * Sends PropertyChanged signals informing that debug timestamp has changed.
1917 void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
1919 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1920 WPAS_DBUS_NEW_INTERFACE,
1926 * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
1927 * @global: wpa_global structure
1929 * Sends PropertyChanged signals informing that debug show_keys has changed.
1931 void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
1933 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1934 WPAS_DBUS_NEW_INTERFACE,
1939 static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
1941 WPADBusArgumentFreeFunction priv_free,
1942 const struct wpa_dbus_method_desc *methods,
1943 const struct wpa_dbus_property_desc *properties,
1944 const struct wpa_dbus_signal_desc *signals)
1948 obj_desc->user_data = priv;
1949 obj_desc->user_data_free_func = priv_free;
1950 obj_desc->methods = methods;
1951 obj_desc->properties = properties;
1952 obj_desc->signals = signals;
1954 for (n = 0; properties && properties->dbus_property; properties++)
1957 obj_desc->prop_changed_flags = os_zalloc(n);
1958 if (!obj_desc->prop_changed_flags)
1959 wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
1964 static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
1965 { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
1966 (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
1968 { "args", "a{sv}", ARG_IN },
1969 { "path", "o", ARG_OUT },
1973 { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
1974 (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
1976 { "path", "o", ARG_IN },
1980 { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
1981 (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
1983 { "ifname", "s", ARG_IN },
1984 { "path", "o", ARG_OUT },
1988 { NULL, NULL, NULL, { END_ARGS } }
1991 static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
1992 { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
1993 wpas_dbus_getter_debug_level,
1994 wpas_dbus_setter_debug_level
1996 { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
1997 wpas_dbus_getter_debug_timestamp,
1998 wpas_dbus_setter_debug_timestamp
2000 { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
2001 wpas_dbus_getter_debug_show_keys,
2002 wpas_dbus_setter_debug_show_keys
2004 { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
2005 wpas_dbus_getter_interfaces,
2008 { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
2009 wpas_dbus_getter_eap_methods,
2012 { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
2013 wpas_dbus_getter_global_capabilities,
2016 { NULL, NULL, NULL, NULL, NULL }
2019 static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
2020 { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
2022 { "path", "o", ARG_OUT },
2023 { "properties", "a{sv}", ARG_OUT },
2027 { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
2029 { "path", "o", ARG_OUT },
2033 { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
2035 { "path", "o", ARG_OUT },
2036 { "field", "s", ARG_OUT },
2037 { "text", "s", ARG_OUT },
2041 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2042 { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
2044 { "properties", "a{sv}", ARG_OUT },
2048 { NULL, NULL, { END_ARGS } }
2053 * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
2054 * @global: Pointer to global data from wpa_supplicant_init()
2055 * Returns: 0 on success or -1 on failure
2057 * Initialize the dbus control interface for wpa_supplicantand and start
2058 * receiving commands from external programs over the bus.
2060 int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
2062 struct wpa_dbus_object_desc *obj_desc;
2065 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2067 wpa_printf(MSG_ERROR, "Not enough memory "
2068 "to create object description");
2072 wpas_dbus_register(obj_desc, priv->global, NULL,
2073 wpas_dbus_global_methods,
2074 wpas_dbus_global_properties,
2075 wpas_dbus_global_signals);
2077 wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
2078 WPAS_DBUS_NEW_PATH);
2079 ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
2080 WPAS_DBUS_NEW_SERVICE,
2083 free_dbus_object_desc(obj_desc);
2085 priv->dbus_new_initialized = 1;
2092 * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
2094 * @iface: Pointer to dbus private data from wpas_dbus_init()
2096 * Deinitialize the dbus control interface that was initialized with
2097 * wpas_dbus_ctrl_iface_init().
2099 void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
2101 if (!iface->dbus_new_initialized)
2103 wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
2104 WPAS_DBUS_NEW_PATH);
2105 dbus_connection_unregister_object_path(iface->con,
2106 WPAS_DBUS_NEW_PATH);
2110 static void wpa_dbus_free(void *ptr)
2116 static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
2117 { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
2118 wpas_dbus_getter_network_properties,
2119 wpas_dbus_setter_network_properties
2121 { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
2122 wpas_dbus_getter_enabled,
2123 wpas_dbus_setter_enabled
2125 { NULL, NULL, NULL, NULL, NULL }
2129 static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
2130 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2131 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
2133 { "properties", "a{sv}", ARG_OUT },
2137 { NULL, NULL, { END_ARGS } }
2142 * wpas_dbus_register_network - Register a configured network with dbus
2143 * @wpa_s: wpa_supplicant interface structure
2144 * @ssid: network configuration data
2145 * Returns: 0 on success, -1 on failure
2147 * Registers network representing object with dbus
2149 int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
2150 struct wpa_ssid *ssid)
2152 struct wpas_dbus_priv *ctrl_iface;
2153 struct wpa_dbus_object_desc *obj_desc;
2154 struct network_handler_args *arg;
2155 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2159 * If it is a persistent group register it as such.
2160 * This is to handle cases where an interface is being initialized
2161 * with a list of networks read from config.
2163 if (network_is_persistent_group(ssid))
2164 return wpas_dbus_register_persistent_group(wpa_s, ssid);
2165 #endif /* CONFIG_P2P */
2167 /* Do nothing if the control interface is not turned on */
2168 if (wpa_s == NULL || wpa_s->global == NULL)
2170 ctrl_iface = wpa_s->global->dbus;
2171 if (ctrl_iface == NULL)
2174 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2175 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2176 wpa_s->dbus_new_path, ssid->id);
2178 wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
2180 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2182 wpa_printf(MSG_ERROR, "Not enough memory "
2183 "to create object description");
2187 /* allocate memory for handlers arguments */
2188 arg = os_zalloc(sizeof(struct network_handler_args));
2190 wpa_printf(MSG_ERROR, "Not enough memory "
2191 "to create arguments for method");
2198 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2199 wpas_dbus_network_properties,
2200 wpas_dbus_network_signals);
2202 if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
2203 wpa_s->ifname, obj_desc))
2206 wpas_dbus_signal_network_added(wpa_s, ssid->id);
2211 free_dbus_object_desc(obj_desc);
2217 * wpas_dbus_unregister_network - Unregister a configured network from dbus
2218 * @wpa_s: wpa_supplicant interface structure
2220 * Returns: 0 on success, -1 on failure
2222 * Unregisters network representing object from dbus
2224 int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
2226 struct wpas_dbus_priv *ctrl_iface;
2227 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2230 struct wpa_ssid *ssid;
2232 ssid = wpa_config_get_network(wpa_s->conf, nid);
2234 /* If it is a persistent group unregister it as such */
2235 if (ssid && network_is_persistent_group(ssid))
2236 return wpas_dbus_unregister_persistent_group(wpa_s, nid);
2237 #endif /* CONFIG_P2P */
2239 /* Do nothing if the control interface is not turned on */
2240 if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
2242 ctrl_iface = wpa_s->global->dbus;
2243 if (ctrl_iface == NULL)
2246 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2247 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2248 wpa_s->dbus_new_path, nid);
2250 wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
2252 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
2255 wpas_dbus_signal_network_removed(wpa_s, nid);
2261 static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
2262 { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2263 wpas_dbus_getter_bss_ssid,
2266 { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2267 wpas_dbus_getter_bss_bssid,
2270 { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
2271 wpas_dbus_getter_bss_privacy,
2274 { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
2275 wpas_dbus_getter_bss_mode,
2278 { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
2279 wpas_dbus_getter_bss_signal,
2282 { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
2283 wpas_dbus_getter_bss_frequency,
2286 { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
2287 wpas_dbus_getter_bss_rates,
2290 { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2291 wpas_dbus_getter_bss_wpa,
2294 { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2295 wpas_dbus_getter_bss_rsn,
2298 { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2299 wpas_dbus_getter_bss_wps,
2302 { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2303 wpas_dbus_getter_bss_ies,
2306 { NULL, NULL, NULL, NULL, NULL }
2310 static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
2311 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2312 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
2314 { "properties", "a{sv}", ARG_OUT },
2318 { NULL, NULL, { END_ARGS } }
2323 * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
2324 * @wpa_s: wpa_supplicant interface structure
2325 * @bssid: scanned network bssid
2326 * @id: unique BSS identifier
2327 * Returns: 0 on success, -1 on failure
2329 * Unregisters BSS representing object from dbus
2331 int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
2332 u8 bssid[ETH_ALEN], unsigned int id)
2334 struct wpas_dbus_priv *ctrl_iface;
2335 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2337 /* Do nothing if the control interface is not turned on */
2338 if (wpa_s == NULL || wpa_s->global == NULL)
2340 ctrl_iface = wpa_s->global->dbus;
2341 if (ctrl_iface == NULL)
2344 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2345 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2346 wpa_s->dbus_new_path, id);
2348 wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
2350 if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
2351 wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
2356 wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
2357 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2364 * wpas_dbus_register_bss - Register a scanned BSS with dbus
2365 * @wpa_s: wpa_supplicant interface structure
2366 * @bssid: scanned network bssid
2367 * @id: unique BSS identifier
2368 * Returns: 0 on success, -1 on failure
2370 * Registers BSS representing object with dbus
2372 int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
2373 u8 bssid[ETH_ALEN], unsigned int id)
2375 struct wpas_dbus_priv *ctrl_iface;
2376 struct wpa_dbus_object_desc *obj_desc;
2377 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2378 struct bss_handler_args *arg;
2380 /* Do nothing if the control interface is not turned on */
2381 if (wpa_s == NULL || wpa_s->global == NULL)
2383 ctrl_iface = wpa_s->global->dbus;
2384 if (ctrl_iface == NULL)
2387 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2388 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2389 wpa_s->dbus_new_path, id);
2391 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2393 wpa_printf(MSG_ERROR, "Not enough memory "
2394 "to create object description");
2398 arg = os_zalloc(sizeof(struct bss_handler_args));
2400 wpa_printf(MSG_ERROR, "Not enough memory "
2401 "to create arguments for handler");
2407 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2408 wpas_dbus_bss_properties,
2409 wpas_dbus_bss_signals);
2411 wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
2413 if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
2414 wpa_s->ifname, obj_desc)) {
2415 wpa_printf(MSG_ERROR,
2416 "Cannot register BSSID dbus object %s.",
2421 wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
2422 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2427 free_dbus_object_desc(obj_desc);
2432 static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
2433 { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2434 (WPADBusMethodHandler) &wpas_dbus_handler_scan,
2436 { "args", "a{sv}", ARG_IN },
2440 { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2441 (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
2446 { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2447 (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
2449 { "args", "a{sv}", ARG_IN },
2450 { "path", "o", ARG_OUT },
2454 { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
2455 (WPADBusMethodHandler) &wpas_dbus_handler_reassociate,
2460 { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
2461 (WPADBusMethodHandler) &wpas_dbus_handler_reattach,
2466 { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2467 (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
2469 { "path", "o", ARG_IN },
2473 { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
2474 (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
2479 { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2480 (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
2482 { "path", "o", ARG_IN },
2486 { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
2487 (WPADBusMethodHandler) &wpas_dbus_handler_network_reply,
2489 { "path", "o", ARG_IN },
2490 { "field", "s", ARG_IN },
2491 { "value", "s", ARG_IN },
2495 #ifndef CONFIG_NO_CONFIG_BLOBS
2496 { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2497 (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
2499 { "name", "s", ARG_IN },
2500 { "data", "ay", ARG_IN },
2504 { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2505 (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
2507 { "name", "s", ARG_IN },
2508 { "data", "ay", ARG_OUT },
2512 { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2513 (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
2515 { "name", "s", ARG_IN },
2519 #endif /* CONFIG_NO_CONFIG_BLOBS */
2520 { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
2521 (WPADBusMethodHandler)
2522 &wpas_dbus_handler_set_pkcs11_engine_and_module_path,
2524 { "pkcs11_engine_path", "s", ARG_IN },
2525 { "pkcs11_module_path", "s", ARG_IN },
2530 { "Start", WPAS_DBUS_NEW_IFACE_WPS,
2531 (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
2533 { "args", "a{sv}", ARG_IN },
2534 { "output", "a{sv}", ARG_OUT },
2538 #endif /* CONFIG_WPS */
2540 { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2541 (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
2543 { "args", "a{sv}", ARG_IN },
2547 { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2548 (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
2553 { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2554 (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
2556 { "timeout", "i", ARG_IN },
2560 { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2561 (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
2563 { "args", "a{sv}", ARG_IN },
2567 { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2568 (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
2570 { "args", "a{sv}", ARG_IN },
2574 { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2575 (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
2577 { "peer", "o", ARG_IN },
2578 { "config_method", "s", ARG_IN },
2582 { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2583 (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
2585 { "args", "a{sv}", ARG_IN },
2586 { "generated_pin", "s", ARG_OUT },
2590 { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2591 (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
2593 { "args", "a{sv}", ARG_IN },
2597 { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2598 (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
2600 { "args", "a{sv}", ARG_IN },
2604 { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2605 (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
2610 { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2611 (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
2613 { "peer", "o", ARG_IN },
2617 { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2618 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
2623 { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2624 (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
2626 { "args", "a{sv}", ARG_IN },
2630 { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2631 (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
2633 { "args", "a{sv}", ARG_IN },
2637 { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2638 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
2643 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2644 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
2646 { "args", "a{sv}", ARG_IN },
2647 { "ref", "t", ARG_OUT },
2651 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2652 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
2654 { "args", "a{sv}", ARG_IN },
2658 { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2659 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
2661 { "args", "t", ARG_IN },
2665 { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2666 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
2671 { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2672 (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
2674 { "arg", "i", ARG_IN },
2678 { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2679 (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
2681 { "args", "a{sv}", ARG_IN },
2682 { "path", "o", ARG_OUT },
2686 { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2687 (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
2689 { "path", "o", ARG_IN },
2693 { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2694 (WPADBusMethodHandler)
2695 wpas_dbus_handler_remove_all_persistent_groups,
2700 #endif /* CONFIG_P2P */
2701 { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
2702 (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
2704 { "age", "u", ARG_IN },
2709 { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2710 (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
2715 { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2716 (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
2721 #endif /* CONFIG_AP */
2722 { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
2723 (WPADBusMethodHandler) &wpas_dbus_handler_eap_logoff,
2728 { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
2729 (WPADBusMethodHandler) &wpas_dbus_handler_eap_logon,
2734 #ifdef CONFIG_AUTOSCAN
2735 { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2736 (WPADBusMethodHandler) &wpas_dbus_handler_autoscan,
2738 { "arg", "s", ARG_IN },
2742 #endif /* CONFIG_AUTOSCAN */
2744 { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
2745 (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
2747 { "peer_address", "s", ARG_IN },
2751 { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
2752 (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
2754 { "peer_address", "s", ARG_IN },
2758 { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
2759 (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
2761 { "peer_address", "s", ARG_IN },
2762 { "status", "s", ARG_OUT },
2766 { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
2767 (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
2769 { "peer_address", "s", ARG_IN },
2773 #endif /* CONFIG_TDLS */
2774 { NULL, NULL, NULL, { END_ARGS } }
2777 static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
2778 { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
2779 wpas_dbus_getter_capabilities,
2782 { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2783 wpas_dbus_getter_state,
2786 { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2787 wpas_dbus_getter_scanning,
2790 { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2791 wpas_dbus_getter_ap_scan,
2792 wpas_dbus_setter_ap_scan
2794 { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2795 wpas_dbus_getter_bss_expire_age,
2796 wpas_dbus_setter_bss_expire_age
2798 { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2799 wpas_dbus_getter_bss_expire_count,
2800 wpas_dbus_setter_bss_expire_count
2802 { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2803 wpas_dbus_getter_country,
2804 wpas_dbus_setter_country
2806 { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2807 wpas_dbus_getter_ifname,
2810 { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2811 wpas_dbus_getter_driver,
2814 { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2815 wpas_dbus_getter_bridge_ifname,
2818 { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2819 wpas_dbus_getter_current_bss,
2822 { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2823 wpas_dbus_getter_current_network,
2826 { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2827 wpas_dbus_getter_current_auth_mode,
2830 { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
2831 wpas_dbus_getter_blobs,
2834 { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2835 wpas_dbus_getter_bsss,
2838 { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2839 wpas_dbus_getter_networks,
2842 { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2843 wpas_dbus_getter_fast_reauth,
2844 wpas_dbus_setter_fast_reauth
2846 { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
2847 wpas_dbus_getter_scan_interval,
2848 wpas_dbus_setter_scan_interval
2850 { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2851 wpas_dbus_getter_pkcs11_engine_path,
2854 { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2855 wpas_dbus_getter_pkcs11_module_path,
2859 { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
2860 wpas_dbus_getter_process_credentials,
2861 wpas_dbus_setter_process_credentials
2863 #endif /* CONFIG_WPS */
2865 { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
2866 wpas_dbus_getter_p2p_device_config,
2867 wpas_dbus_setter_p2p_device_config
2869 { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2870 wpas_dbus_getter_p2p_peers,
2873 { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
2874 wpas_dbus_getter_p2p_role,
2877 { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2878 wpas_dbus_getter_p2p_group,
2881 { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2882 wpas_dbus_getter_p2p_peergo,
2885 { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2886 wpas_dbus_getter_persistent_groups,
2889 #endif /* CONFIG_P2P */
2890 { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
2891 wpas_dbus_getter_disconnect_reason,
2894 { NULL, NULL, NULL, NULL, NULL }
2897 static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
2898 { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
2900 { "success", "b", ARG_OUT },
2904 { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2906 { "path", "o", ARG_OUT },
2907 { "properties", "a{sv}", ARG_OUT },
2911 { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2913 { "path", "o", ARG_OUT },
2917 { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2919 { "name", "s", ARG_OUT },
2923 { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2925 { "name", "s", ARG_OUT },
2929 { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2931 { "path", "o", ARG_OUT },
2932 { "properties", "a{sv}", ARG_OUT },
2936 { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2938 { "path", "o", ARG_OUT },
2942 { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
2944 { "path", "o", ARG_OUT },
2948 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2949 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
2951 { "properties", "a{sv}", ARG_OUT },
2956 { "Event", WPAS_DBUS_NEW_IFACE_WPS,
2958 { "name", "s", ARG_OUT },
2959 { "args", "a{sv}", ARG_OUT },
2963 { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
2965 { "credentials", "a{sv}", ARG_OUT },
2969 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2970 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
2972 { "properties", "a{sv}", ARG_OUT },
2976 #endif /* CONFIG_WPS */
2978 { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2980 { "states", "a{ss}", ARG_OUT },
2984 { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2986 { "path", "o", ARG_OUT },
2990 { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2992 { "path", "o", ARG_OUT },
2996 { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2998 { "peer_object", "o", ARG_OUT },
2999 { "pin", "s", ARG_OUT },
3003 { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3005 { "peer_object", "o", ARG_OUT },
3006 { "pin", "s", ARG_OUT },
3010 { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3012 { "peer_object", "o", ARG_OUT },
3016 { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3018 { "peer_object", "o", ARG_OUT },
3022 { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3024 { "peer_object", "o", ARG_OUT },
3028 { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3030 { "peer_object", "o", ARG_OUT },
3034 { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3036 { "peer_object", "o", ARG_OUT },
3037 { "status", "i", ARG_OUT },
3041 { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3043 { "properties", "a{sv}", ARG_OUT },
3047 { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3049 { "properties", "a{sv}", ARG_OUT },
3053 { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3055 { "properties", "a{sv}", ARG_OUT },
3059 { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3061 { "path", "o", ARG_OUT },
3062 { "dev_passwd_id", "i", ARG_OUT },
3066 { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3068 { "invite_result", "a{sv}", ARG_OUT },
3072 { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3074 { "ifname", "s", ARG_OUT },
3075 { "role", "s", ARG_OUT },
3079 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3081 { "sd_request", "a{sv}", ARG_OUT },
3085 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3087 { "sd_response", "a{sv}", ARG_OUT },
3091 { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3093 { "path", "o", ARG_OUT },
3094 { "properties", "a{sv}", ARG_OUT },
3098 { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3100 { "path", "o", ARG_OUT },
3104 { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3106 { "name", "s", ARG_OUT },
3107 { "args", "a{sv}", ARG_OUT },
3111 #endif /* CONFIG_P2P */
3113 { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
3115 { "args", "a{sv}", ARG_OUT },
3119 #endif /* CONFIG_AP */
3120 { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
3122 { "certification", "a{sv}", ARG_OUT },
3126 { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
3128 { "status", "s", ARG_OUT },
3129 { "parameter", "s", ARG_OUT },
3133 { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3135 { "name", "s", ARG_OUT },
3139 { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3141 { "name", "s", ARG_OUT },
3145 { NULL, NULL, { END_ARGS } }
3149 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
3152 struct wpa_dbus_object_desc *obj_desc = NULL;
3153 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
3156 /* Do nothing if the control interface is not turned on */
3157 if (ctrl_iface == NULL)
3160 /* Create and set the interface's object path */
3161 wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3162 if (wpa_s->dbus_new_path == NULL)
3164 next = ctrl_iface->next_objid++;
3165 os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
3166 WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
3169 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3171 wpa_printf(MSG_ERROR, "Not enough memory "
3172 "to create object description");
3176 wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
3177 wpas_dbus_interface_properties,
3178 wpas_dbus_interface_signals);
3180 wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
3181 wpa_s->dbus_new_path);
3182 if (wpa_dbus_register_object_per_iface(ctrl_iface,
3183 wpa_s->dbus_new_path,
3184 wpa_s->ifname, obj_desc))
3187 wpas_dbus_signal_interface_added(wpa_s);
3192 os_free(wpa_s->dbus_new_path);
3193 wpa_s->dbus_new_path = NULL;
3194 free_dbus_object_desc(obj_desc);
3199 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
3201 struct wpas_dbus_priv *ctrl_iface;
3203 /* Do nothing if the control interface is not turned on */
3204 if (wpa_s == NULL || wpa_s->global == NULL)
3206 ctrl_iface = wpa_s->global->dbus;
3207 if (ctrl_iface == NULL)
3210 wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
3211 wpa_s->dbus_new_path);
3214 if (wpa_s->preq_notify_peer) {
3215 wpas_dbus_unsubscribe_noc(ctrl_iface);
3216 os_free(wpa_s->preq_notify_peer);
3217 wpa_s->preq_notify_peer = NULL;
3219 #endif /* CONFIG_AP */
3221 if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
3222 wpa_s->dbus_new_path))
3225 wpas_dbus_signal_interface_removed(wpa_s);
3227 os_free(wpa_s->dbus_new_path);
3228 wpa_s->dbus_new_path = NULL;
3235 static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
3236 { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3237 wpas_dbus_getter_p2p_peer_device_name,
3240 { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3241 wpas_dbus_getter_p2p_peer_primary_device_type,
3244 { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
3245 wpas_dbus_getter_p2p_peer_config_method,
3248 { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
3249 wpas_dbus_getter_p2p_peer_level,
3252 { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3253 wpas_dbus_getter_p2p_peer_device_capability,
3256 { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3257 wpas_dbus_getter_p2p_peer_group_capability,
3260 { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3261 wpas_dbus_getter_p2p_peer_secondary_device_types,
3264 { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3265 wpas_dbus_getter_p2p_peer_vendor_extension,
3268 { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3269 wpas_dbus_getter_p2p_peer_ies,
3272 { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3273 wpas_dbus_getter_p2p_peer_device_address,
3276 { NULL, NULL, NULL, NULL, NULL }
3279 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
3281 { NULL, NULL, { END_ARGS } }
3285 * wpas_dbus_signal_peer - Send a peer related event signal
3286 * @wpa_s: %wpa_supplicant network interface data
3287 * @dev: peer device object
3288 * @interface: name of the interface emitting this signal.
3289 * In case of peer objects, it would be emitted by either
3290 * the "interface object" or by "peer objects"
3291 * @sig_name: signal name - DeviceFound
3293 * Notify listeners about event related with newly found p2p peer device
3295 static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
3296 const u8 *dev_addr, const char *interface,
3297 const char *sig_name)
3299 struct wpas_dbus_priv *iface;
3301 DBusMessageIter iter;
3302 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
3304 iface = wpa_s->global->dbus;
3306 /* Do nothing if the control interface is not turned on */
3310 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3311 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3312 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3314 msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
3319 dbus_message_iter_init_append(msg, &iter);
3320 path = peer_obj_path;
3321 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
3325 dbus_connection_send(iface->con, msg, NULL);
3327 dbus_message_unref(msg);
3331 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
3332 dbus_message_unref(msg);
3337 * wpas_dbus_signal_peer_found - Send a peer found signal
3338 * @wpa_s: %wpa_supplicant network interface data
3339 * @dev: peer device object
3341 * Notify listeners about find a p2p peer device found
3343 void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
3346 wpas_dbus_signal_peer(wpa_s, dev_addr,
3347 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3352 * wpas_dbus_signal_peer_lost - Send a peer lost signal
3353 * @wpa_s: %wpa_supplicant network interface data
3354 * @dev: peer device object
3356 * Notify listeners about lost a p2p peer device
3358 void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
3361 wpas_dbus_signal_peer(wpa_s, dev_addr,
3362 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3367 * wpas_dbus_register_peer - Register a discovered peer object with dbus
3368 * @wpa_s: wpa_supplicant interface structure
3369 * @ssid: network configuration data
3370 * Returns: 0 on success, -1 on failure
3372 * Registers network representing object with dbus
3374 int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
3376 struct wpas_dbus_priv *ctrl_iface;
3377 struct wpa_dbus_object_desc *obj_desc;
3378 struct peer_handler_args *arg;
3379 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3381 /* Do nothing if the control interface is not turned on */
3382 if (wpa_s == NULL || wpa_s->global == NULL)
3385 ctrl_iface = wpa_s->global->dbus;
3386 if (ctrl_iface == NULL)
3389 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3390 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3391 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3393 wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
3395 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3397 wpa_printf(MSG_ERROR, "Not enough memory "
3398 "to create object description");
3402 /* allocate memory for handlers arguments */
3403 arg = os_zalloc(sizeof(struct peer_handler_args));
3405 wpa_printf(MSG_ERROR, "Not enough memory "
3406 "to create arguments for method");
3411 os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
3413 wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
3415 wpas_dbus_p2p_peer_properties,
3416 wpas_dbus_p2p_peer_signals);
3418 if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
3419 wpa_s->ifname, obj_desc))
3425 free_dbus_object_desc(obj_desc);
3430 * wpas_dbus_unregister_peer - Unregister a peer object with dbus
3431 * @wpa_s: wpa_supplicant interface structure
3432 * @dev_addr: p2p device addr
3433 * Returns: 0 on success, -1 on failure
3435 * Registers network representing object with dbus
3437 int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
3440 struct wpas_dbus_priv *ctrl_iface;
3441 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3444 /* Do nothing if the control interface is not turned on */
3445 if (wpa_s == NULL || wpa_s->global == NULL ||
3446 wpa_s->dbus_new_path == NULL)
3448 ctrl_iface = wpa_s->global->dbus;
3449 if (ctrl_iface == NULL)
3452 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3453 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3454 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3456 wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
3458 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
3464 static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
3465 { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
3466 wpas_dbus_getter_p2p_group_members,
3469 { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
3470 wpas_dbus_getter_p2p_group,
3473 { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3474 wpas_dbus_getter_p2p_role,
3477 { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3478 wpas_dbus_getter_p2p_group_ssid,
3481 { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3482 wpas_dbus_getter_p2p_group_bssid,
3485 { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
3486 wpas_dbus_getter_p2p_group_frequency,
3489 { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3490 wpas_dbus_getter_p2p_group_passphrase,
3493 { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3494 wpas_dbus_getter_p2p_group_psk,
3497 { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
3498 wpas_dbus_getter_p2p_group_vendor_ext,
3499 wpas_dbus_setter_p2p_group_vendor_ext
3501 { NULL, NULL, NULL, NULL, NULL }
3504 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
3505 { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3507 { "peer", "o", ARG_OUT },
3511 { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3513 { "peer", "o", ARG_OUT },
3517 { NULL, NULL, { END_ARGS } }
3521 * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
3522 * @wpa_s: wpa_supplicant interface structure
3523 * @ssid: SSID struct
3524 * Returns: 0 on success, -1 on failure
3526 * Registers p2p group representing object with dbus
3528 void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
3529 struct wpa_ssid *ssid)
3531 struct wpas_dbus_priv *ctrl_iface;
3532 struct wpa_dbus_object_desc *obj_desc;
3533 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3535 /* Do nothing if the control interface is not turned on */
3536 if (wpa_s == NULL || wpa_s->global == NULL)
3539 ctrl_iface = wpa_s->global->dbus;
3540 if (ctrl_iface == NULL)
3543 if (wpa_s->dbus_groupobj_path) {
3544 wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
3545 __func__, wpa_s->dbus_groupobj_path);
3549 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
3552 wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
3553 if (wpa_s->dbus_groupobj_path == NULL)
3556 wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
3558 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3560 wpa_printf(MSG_ERROR, "Not enough memory "
3561 "to create object description");
3565 wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
3566 wpas_dbus_p2p_group_properties,
3567 wpas_dbus_p2p_group_signals);
3569 if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
3570 wpa_s->ifname, obj_desc))
3576 if (wpa_s->dbus_groupobj_path) {
3577 os_free(wpa_s->dbus_groupobj_path);
3578 wpa_s->dbus_groupobj_path = NULL;
3581 free_dbus_object_desc(obj_desc);
3585 * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
3586 * @wpa_s: wpa_supplicant interface structure
3587 * @ssid: network name of the p2p group started
3589 void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
3590 const struct wpa_ssid *ssid)
3592 struct wpas_dbus_priv *ctrl_iface;
3594 /* Do nothing if the control interface is not turned on */
3595 if (wpa_s == NULL || wpa_s->global == NULL)
3598 ctrl_iface = wpa_s->global->dbus;
3599 if (ctrl_iface == NULL)
3602 if (!wpa_s->dbus_groupobj_path) {
3603 wpa_printf(MSG_DEBUG,
3604 "%s: Group object '%s' already unregistered",
3605 __func__, wpa_s->dbus_groupobj_path);
3609 wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
3610 wpa_s->dbus_groupobj_path);
3612 wpa_dbus_unregister_object_per_iface(ctrl_iface,
3613 wpa_s->dbus_groupobj_path);
3615 os_free(wpa_s->dbus_groupobj_path);
3616 wpa_s->dbus_groupobj_path = NULL;
3619 static const struct wpa_dbus_property_desc
3620 wpas_dbus_p2p_groupmember_properties[] = {
3621 { NULL, NULL, NULL, NULL, NULL }
3625 * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
3627 * @wpa_s: wpa_supplicant interface structure
3628 * @p2p_if_addr: i/f addr of the device joining this group
3630 * Registers p2p groupmember representing object with dbus
3632 void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
3633 const u8 *p2p_if_addr)
3635 struct wpas_dbus_priv *ctrl_iface;
3636 struct wpa_dbus_object_desc *obj_desc = NULL;
3637 struct groupmember_handler_args *arg;
3638 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3640 /* Do nothing if the control interface is not turned on */
3641 if (wpa_s == NULL || wpa_s->global == NULL)
3644 ctrl_iface = wpa_s->global->dbus;
3645 if (ctrl_iface == NULL)
3648 if (!wpa_s->dbus_groupobj_path)
3651 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3652 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
3653 wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
3655 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3657 wpa_printf(MSG_ERROR, "Not enough memory "
3658 "to create object description");
3662 /* allocate memory for handlers arguments */
3663 arg = os_zalloc(sizeof(struct groupmember_handler_args));
3665 wpa_printf(MSG_ERROR, "Not enough memory "
3666 "to create arguments for method");
3671 os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
3673 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3674 wpas_dbus_p2p_groupmember_properties, NULL);
3676 if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
3677 wpa_s->ifname, obj_desc))
3680 wpa_printf(MSG_INFO,
3681 "dbus: Registered group member object '%s' successfully",
3682 groupmember_obj_path);
3686 free_dbus_object_desc(obj_desc);
3690 * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
3692 * @wpa_s: wpa_supplicant interface structure
3693 * @p2p_if_addr: i/f addr of the device joining this group
3695 * Unregisters p2p groupmember representing object with dbus
3697 void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
3698 const u8 *p2p_if_addr)
3700 struct wpas_dbus_priv *ctrl_iface;
3701 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3703 /* Do nothing if the control interface is not turned on */
3704 if (wpa_s == NULL || wpa_s->global == NULL)
3707 ctrl_iface = wpa_s->global->dbus;
3708 if (ctrl_iface == NULL)
3711 if (!wpa_s->dbus_groupobj_path)
3714 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3715 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
3716 wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
3718 wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
3722 static const struct wpa_dbus_property_desc
3723 wpas_dbus_persistent_group_properties[] = {
3724 { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
3725 wpas_dbus_getter_persistent_group_properties,
3726 wpas_dbus_setter_persistent_group_properties
3728 { NULL, NULL, NULL, NULL, NULL }
3731 /* No signals intended for persistent group objects */
3734 * wpas_dbus_register_persistent_group - Register a configured(saved)
3735 * persistent group with dbus
3736 * @wpa_s: wpa_supplicant interface structure
3737 * @ssid: persistent group (still represented as a network within wpa)
3738 * configuration data
3739 * Returns: 0 on success, -1 on failure
3741 * Registers a persistent group representing object with dbus.
3743 int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
3744 struct wpa_ssid *ssid)
3746 struct wpas_dbus_priv *ctrl_iface;
3747 struct wpa_dbus_object_desc *obj_desc;
3748 struct network_handler_args *arg;
3749 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3751 /* Do nothing if the control interface is not turned on */
3752 if (wpa_s == NULL || wpa_s->global == NULL)
3755 /* Make sure ssid is a persistent group */
3756 if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
3757 return -1; /* should we return w/o complaining? */
3759 ctrl_iface = wpa_s->global->dbus;
3760 if (ctrl_iface == NULL)
3764 * Intentionally not coming up with different numbering scheme
3765 * for persistent groups.
3767 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3768 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3769 wpa_s->dbus_new_path, ssid->id);
3771 wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
3773 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3775 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3776 "object description");
3781 * Reusing the same context structure as that for networks
3782 * since these are represented using same data structure.
3784 /* allocate memory for handlers arguments */
3785 arg = os_zalloc(sizeof(struct network_handler_args));
3787 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3788 "arguments for method");
3795 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3796 wpas_dbus_persistent_group_properties,
3799 if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
3800 wpa_s->ifname, obj_desc))
3803 wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
3808 free_dbus_object_desc(obj_desc);
3814 * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
3816 * @wpa_s: wpa_supplicant interface structure
3818 * Returns: 0 on success, -1 on failure
3820 * Unregisters persistent group representing object from dbus
3822 * NOTE: There is a slight issue with the semantics here. While the
3823 * implementation simply means the persistent group is unloaded from memory,
3824 * it should not get interpreted as the group is actually being erased/removed
3825 * from persistent storage as well.
3827 int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
3830 struct wpas_dbus_priv *ctrl_iface;
3831 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3834 /* Do nothing if the control interface is not turned on */
3835 if (wpa_s == NULL || wpa_s->global == NULL ||
3836 wpa_s->dbus_new_path == NULL)
3838 ctrl_iface = wpa_s->global->dbus;
3839 if (ctrl_iface == NULL)
3842 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3843 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3844 wpa_s->dbus_new_path, nid);
3846 wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
3848 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
3851 wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
3856 #endif /* CONFIG_P2P */