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"
27 #include "../p2p_supplicant.h"
29 #ifdef CONFIG_AP /* until needed by something else */
32 * NameOwnerChanged handling
34 * Some services we provide allow an application to register for
35 * a signal that it needs. While it can also unregister, we must
36 * be prepared for the case where the application simply crashes
37 * and thus doesn't clean up properly. The way to handle this in
38 * DBus is to register for the NameOwnerChanged signal which will
39 * signal an owner change to NULL if the peer closes the socket
40 * for whatever reason.
42 * Handle this signal via a filter function whenever necessary.
43 * The code below also handles refcounting in case in the future
44 * there will be multiple instances of this subscription scheme.
46 static const char wpas_dbus_noc_filter_str[] =
47 "interface=org.freedesktop.DBus,member=NameOwnerChanged";
50 static DBusHandlerResult noc_filter(DBusConnection *conn,
51 DBusMessage *message, void *data)
53 struct wpas_dbus_priv *priv = data;
55 if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
56 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
58 if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
59 "NameOwnerChanged")) {
61 const char *prev_owner;
62 const char *new_owner;
64 struct wpa_supplicant *wpa_s;
66 dbus_error_init(&derr);
68 if (!dbus_message_get_args(message, &derr,
69 DBUS_TYPE_STRING, &name,
70 DBUS_TYPE_STRING, &prev_owner,
71 DBUS_TYPE_STRING, &new_owner,
73 /* Ignore this error */
74 dbus_error_free(&derr);
75 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
78 for (wpa_s = priv->global->ifaces; wpa_s; wpa_s = wpa_s->next)
80 if (wpa_s->preq_notify_peer != NULL &&
81 os_strcmp(name, wpa_s->preq_notify_peer) == 0 &&
82 (new_owner == NULL || os_strlen(new_owner) == 0)) {
83 /* probe request owner disconnected */
84 os_free(wpa_s->preq_notify_peer);
85 wpa_s->preq_notify_peer = NULL;
86 wpas_dbus_unsubscribe_noc(priv);
91 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
95 void wpas_dbus_subscribe_noc(struct wpas_dbus_priv *priv)
97 priv->dbus_noc_refcnt++;
98 if (priv->dbus_noc_refcnt > 1)
101 if (!dbus_connection_add_filter(priv->con, noc_filter, priv, NULL)) {
102 wpa_printf(MSG_ERROR, "dbus: failed to add filter");
106 dbus_bus_add_match(priv->con, wpas_dbus_noc_filter_str, NULL);
110 void wpas_dbus_unsubscribe_noc(struct wpas_dbus_priv *priv)
112 priv->dbus_noc_refcnt--;
113 if (priv->dbus_noc_refcnt > 0)
116 dbus_bus_remove_match(priv->con, wpas_dbus_noc_filter_str, NULL);
117 dbus_connection_remove_filter(priv->con, noc_filter, priv);
120 #endif /* CONFIG_AP */
124 * wpas_dbus_signal_interface - Send a interface related event signal
125 * @wpa_s: %wpa_supplicant network interface data
126 * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
127 * @properties: Whether to add second argument with object properties
129 * Notify listeners about event related with interface
131 static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
132 const char *sig_name, int properties)
134 struct wpas_dbus_priv *iface;
136 DBusMessageIter iter;
138 iface = wpa_s->global->dbus;
140 /* Do nothing if the control interface is not turned on */
144 msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
145 WPAS_DBUS_NEW_INTERFACE, sig_name);
149 dbus_message_iter_init_append(msg, &iter);
150 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
151 &wpa_s->dbus_new_path))
155 if (!wpa_dbus_get_object_properties(
156 iface, wpa_s->dbus_new_path,
157 WPAS_DBUS_NEW_IFACE_INTERFACE, &iter))
161 dbus_connection_send(iface->con, msg, NULL);
162 dbus_message_unref(msg);
166 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
167 dbus_message_unref(msg);
172 * wpas_dbus_signal_interface_added - Send a interface created signal
173 * @wpa_s: %wpa_supplicant network interface data
175 * Notify listeners about creating new interface
177 static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
179 wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
184 * wpas_dbus_signal_interface_removed - Send a interface removed signal
185 * @wpa_s: %wpa_supplicant network interface data
187 * Notify listeners about removing interface
189 static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
191 wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
197 * wpas_dbus_signal_scan_done - send scan done signal
198 * @wpa_s: %wpa_supplicant network interface data
199 * @success: indicates if scanning succeed or failed
201 * Notify listeners about finishing a scan
203 void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
205 struct wpas_dbus_priv *iface;
209 iface = wpa_s->global->dbus;
211 /* Do nothing if the control interface is not turned on */
215 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
216 WPAS_DBUS_NEW_IFACE_INTERFACE,
221 succ = success ? TRUE : FALSE;
222 if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
224 dbus_connection_send(iface->con, msg, NULL);
226 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
227 dbus_message_unref(msg);
232 * wpas_dbus_signal_blob - Send a BSS related event signal
233 * @wpa_s: %wpa_supplicant network interface data
234 * @bss_obj_path: BSS object path
235 * @sig_name: signal name - BSSAdded or BSSRemoved
236 * @properties: Whether to add second argument with object properties
238 * Notify listeners about event related with BSS
240 static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
241 const char *bss_obj_path,
242 const char *sig_name, int properties)
244 struct wpas_dbus_priv *iface;
246 DBusMessageIter iter;
248 iface = wpa_s->global->dbus;
250 /* Do nothing if the control interface is not turned on */
254 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
255 WPAS_DBUS_NEW_IFACE_INTERFACE,
260 dbus_message_iter_init_append(msg, &iter);
261 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
266 if (!wpa_dbus_get_object_properties(iface, bss_obj_path,
267 WPAS_DBUS_NEW_IFACE_BSS,
272 dbus_connection_send(iface->con, msg, NULL);
273 dbus_message_unref(msg);
277 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
278 dbus_message_unref(msg);
283 * wpas_dbus_signal_bss_added - Send a BSS added signal
284 * @wpa_s: %wpa_supplicant network interface data
285 * @bss_obj_path: new BSS object path
287 * Notify listeners about adding new BSS
289 static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
290 const char *bss_obj_path)
292 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
297 * wpas_dbus_signal_bss_removed - Send a BSS removed signal
298 * @wpa_s: %wpa_supplicant network interface data
299 * @bss_obj_path: BSS object path
301 * Notify listeners about removing BSS
303 static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
304 const char *bss_obj_path)
306 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
311 * wpas_dbus_signal_blob - Send a blob related event signal
312 * @wpa_s: %wpa_supplicant network interface data
314 * @sig_name: signal name - BlobAdded or BlobRemoved
316 * Notify listeners about event related with blob
318 static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
319 const char *name, const char *sig_name)
321 struct wpas_dbus_priv *iface;
324 iface = wpa_s->global->dbus;
326 /* Do nothing if the control interface is not turned on */
330 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
331 WPAS_DBUS_NEW_IFACE_INTERFACE,
336 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
338 dbus_connection_send(iface->con, msg, NULL);
340 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
341 dbus_message_unref(msg);
346 * wpas_dbus_signal_blob_added - Send a blob added signal
347 * @wpa_s: %wpa_supplicant network interface data
350 * Notify listeners about adding a new blob
352 void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
355 wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
360 * wpas_dbus_signal_blob_removed - Send a blob removed signal
361 * @wpa_s: %wpa_supplicant network interface data
364 * Notify listeners about removing blob
366 void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
369 wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
374 * wpas_dbus_signal_network - Send a network related event signal
375 * @wpa_s: %wpa_supplicant network interface data
376 * @id: new network id
377 * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
378 * @properties: determines if add second argument with object properties
380 * Notify listeners about event related with configured network
382 static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
383 int id, const char *sig_name,
386 struct wpas_dbus_priv *iface;
388 DBusMessageIter iter;
389 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
391 iface = wpa_s->global->dbus;
393 /* Do nothing if the control interface is not turned on */
397 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
398 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
399 wpa_s->dbus_new_path, id);
401 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
402 WPAS_DBUS_NEW_IFACE_INTERFACE,
407 dbus_message_iter_init_append(msg, &iter);
409 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
414 if (!wpa_dbus_get_object_properties(
415 iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
420 dbus_connection_send(iface->con, msg, NULL);
422 dbus_message_unref(msg);
426 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
427 dbus_message_unref(msg);
432 * wpas_dbus_signal_network_added - Send a network added signal
433 * @wpa_s: %wpa_supplicant network interface data
434 * @id: new network id
436 * Notify listeners about adding new network
438 static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
441 wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
446 * wpas_dbus_signal_network_removed - Send a network removed signal
447 * @wpa_s: %wpa_supplicant network interface data
450 * Notify listeners about removing a network
452 static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
455 wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
460 * wpas_dbus_signal_network_selected - Send a network selected signal
461 * @wpa_s: %wpa_supplicant network interface data
464 * Notify listeners about selecting a network
466 void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
468 wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
473 * wpas_dbus_signal_network_request - Indicate that additional information
474 * (EAP password, etc.) is required to complete the association to this SSID
475 * @wpa_s: %wpa_supplicant network interface data
476 * @rtype: The specific additional information required
477 * @default_text: Optional description of required information
479 * Request additional information or passwords to complete an association
482 void wpas_dbus_signal_network_request(struct wpa_supplicant *wpa_s,
483 struct wpa_ssid *ssid,
484 enum wpa_ctrl_req_type rtype,
485 const char *default_txt)
487 struct wpas_dbus_priv *iface;
489 DBusMessageIter iter;
490 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
491 const char *field, *txt = NULL, *net_ptr;
493 iface = wpa_s->global->dbus;
495 /* Do nothing if the control interface is not turned on */
499 field = wpa_supplicant_ctrl_req_to_string(rtype, default_txt, &txt);
503 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
504 WPAS_DBUS_NEW_IFACE_INTERFACE,
509 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
510 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
511 wpa_s->dbus_new_path, ssid->id);
512 net_ptr = &net_obj_path[0];
514 dbus_message_iter_init_append(msg, &iter);
515 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
518 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &field))
520 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &txt))
523 dbus_connection_send(iface->con, msg, NULL);
524 dbus_message_unref(msg);
528 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
529 dbus_message_unref(msg);
534 * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
535 * @wpa_s: %wpa_supplicant network interface data
536 * @ssid: configured network which Enabled property has changed
538 * Sends PropertyChanged signals containing new value of Enabled property
539 * for specified network
541 void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
542 struct wpa_ssid *ssid)
545 char path[WPAS_DBUS_OBJECT_PATH_MAX];
546 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
547 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
548 wpa_s->dbus_new_path, ssid->id);
550 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
551 WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
558 * wpas_dbus_signal_wps_event_success - Signals Success WPS event
559 * @wpa_s: %wpa_supplicant network interface data
561 * Sends Event dbus signal with name "success" and empty dict as arguments
563 void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
567 DBusMessageIter iter, dict_iter;
568 struct wpas_dbus_priv *iface;
569 char *key = "success";
571 iface = wpa_s->global->dbus;
573 /* Do nothing if the control interface is not turned on */
577 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
578 WPAS_DBUS_NEW_IFACE_WPS, "Event");
582 dbus_message_iter_init_append(msg, &iter);
584 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
585 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
586 !wpa_dbus_dict_close_write(&iter, &dict_iter))
587 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
589 dbus_connection_send(iface->con, msg, NULL);
591 dbus_message_unref(msg);
596 * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
597 * @wpa_s: %wpa_supplicant network interface data
599 * Sends Event dbus signal with name "fail" and dictionary containing
600 * "msg field with fail message number (int32) as arguments
602 void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
603 struct wps_event_fail *fail)
607 DBusMessageIter iter, dict_iter;
608 struct wpas_dbus_priv *iface;
611 iface = wpa_s->global->dbus;
613 /* Do nothing if the control interface is not turned on */
617 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
618 WPAS_DBUS_NEW_IFACE_WPS, "Event");
622 dbus_message_iter_init_append(msg, &iter);
624 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
625 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
626 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
627 !wpa_dbus_dict_close_write(&iter, &dict_iter))
628 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
630 dbus_connection_send(iface->con, msg, NULL);
632 dbus_message_unref(msg);
637 * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
638 * @wpa_s: %wpa_supplicant network interface data
640 * Sends Event dbus signal with name "m2d" and dictionary containing
641 * fields of wps_event_m2d structure.
643 void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
644 struct wps_event_m2d *m2d)
648 DBusMessageIter iter, dict_iter;
649 struct wpas_dbus_priv *iface;
652 iface = wpa_s->global->dbus;
654 /* Do nothing if the control interface is not turned on */
658 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
659 WPAS_DBUS_NEW_IFACE_WPS, "Event");
663 dbus_message_iter_init_append(msg, &iter);
665 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
666 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
667 !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
668 m2d->config_methods) ||
669 !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
670 (const char *) m2d->manufacturer,
671 m2d->manufacturer_len) ||
672 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
673 (const char *) m2d->model_name,
674 m2d->model_name_len) ||
675 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
676 (const char *) m2d->model_number,
677 m2d->model_number_len) ||
678 !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
681 m2d->serial_number_len) ||
682 !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
683 (const char *) m2d->dev_name,
684 m2d->dev_name_len) ||
685 !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
687 m2d->primary_dev_type, 8) ||
688 !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
689 m2d->config_error) ||
690 !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
691 m2d->dev_password_id) ||
692 !wpa_dbus_dict_close_write(&iter, &dict_iter))
693 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
695 dbus_connection_send(iface->con, msg, NULL);
697 dbus_message_unref(msg);
702 * wpas_dbus_signal_wps_cred - Signals new credentials
703 * @wpa_s: %wpa_supplicant network interface data
705 * Sends signal with credentials in directory argument
707 void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
708 const struct wps_credential *cred)
711 DBusMessageIter iter, dict_iter;
712 struct wpas_dbus_priv *iface;
713 char *auth_type[5]; /* we have five possible authentication types */
715 char *encr_type[3]; /* we have three possible encryption types */
718 iface = wpa_s->global->dbus;
720 /* Do nothing if the control interface is not turned on */
724 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
725 WPAS_DBUS_NEW_IFACE_WPS,
730 dbus_message_iter_init_append(msg, &iter);
731 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
734 if (cred->auth_type & WPS_AUTH_OPEN)
735 auth_type[at_num++] = "open";
736 if (cred->auth_type & WPS_AUTH_WPAPSK)
737 auth_type[at_num++] = "wpa-psk";
738 if (cred->auth_type & WPS_AUTH_WPA)
739 auth_type[at_num++] = "wpa-eap";
740 if (cred->auth_type & WPS_AUTH_WPA2)
741 auth_type[at_num++] = "wpa2-eap";
742 if (cred->auth_type & WPS_AUTH_WPA2PSK)
743 auth_type[at_num++] = "wpa2-psk";
745 if (cred->encr_type & WPS_ENCR_NONE)
746 encr_type[et_num++] = "none";
747 if (cred->encr_type & WPS_ENCR_TKIP)
748 encr_type[et_num++] = "tkip";
749 if (cred->encr_type & WPS_ENCR_AES)
750 encr_type[et_num++] = "aes";
752 if (wpa_s->current_ssid) {
753 if (!wpa_dbus_dict_append_byte_array(
755 (const char *) wpa_s->current_ssid->bssid,
760 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
761 (const char *) cred->ssid,
763 !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
764 (const char **) auth_type,
766 !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
767 (const char **) encr_type,
769 !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
770 (const char *) cred->key,
772 !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
774 !wpa_dbus_dict_close_write(&iter, &dict_iter))
777 dbus_connection_send(iface->con, msg, NULL);
780 dbus_message_unref(msg);
783 #endif /* CONFIG_WPS */
785 void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
786 int depth, const char *subject,
787 const char *cert_hash,
788 const struct wpabuf *cert)
790 struct wpas_dbus_priv *iface;
792 DBusMessageIter iter, dict_iter;
794 iface = wpa_s->global->dbus;
796 /* Do nothing if the control interface is not turned on */
800 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
801 WPAS_DBUS_NEW_IFACE_INTERFACE,
806 dbus_message_iter_init_append(msg, &iter);
807 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
810 if (!wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
811 !wpa_dbus_dict_append_string(&dict_iter, "subject", subject))
815 !wpa_dbus_dict_append_string(&dict_iter, "cert_hash", cert_hash))
819 !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
824 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
827 dbus_connection_send(iface->con, msg, NULL);
830 dbus_message_unref(msg);
834 void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
835 const char *status, const char *parameter)
837 struct wpas_dbus_priv *iface;
839 DBusMessageIter iter;
841 iface = wpa_s->global->dbus;
843 /* Do nothing if the control interface is not turned on */
847 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
848 WPAS_DBUS_NEW_IFACE_INTERFACE,
853 dbus_message_iter_init_append(msg, &iter);
855 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status)
857 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
861 dbus_connection_send(iface->con, msg, NULL);
864 dbus_message_unref(msg);
869 * wpas_dbus_signal_sta - Send a station related event signal
870 * @wpa_s: %wpa_supplicant network interface data
871 * @sta: station mac address
872 * @sig_name: signal name - StaAuthorized or StaDeauthorized
874 * Notify listeners about event related with station
876 static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
877 const u8 *sta, const char *sig_name)
879 struct wpas_dbus_priv *iface;
881 char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
884 os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
887 iface = wpa_s->global->dbus;
889 /* Do nothing if the control interface is not turned on */
893 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
894 WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
898 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
900 dbus_connection_send(iface->con, msg, NULL);
902 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
903 dbus_message_unref(msg);
905 wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
911 * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
912 * @wpa_s: %wpa_supplicant network interface data
913 * @sta: station mac address
915 * Notify listeners a new station has been authorized
917 void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
920 wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
925 * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
926 * @wpa_s: %wpa_supplicant network interface data
927 * @sta: station mac address
929 * Notify listeners a station has been deauthorized
931 void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
934 wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
941 * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
942 * @wpa_s: %wpa_supplicant network interface data
943 * @role: role of this device (client or GO)
944 * Sends signal with i/f name and role as string arguments
946 void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
951 DBusMessageIter iter, dict_iter;
952 struct wpas_dbus_priv *iface = wpa_s->global->dbus;
954 /* Do nothing if the control interface is not turned on */
958 if (!wpa_s->dbus_groupobj_path)
961 msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
962 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
967 dbus_message_iter_init_append(msg, &iter);
968 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
971 if (!wpa_dbus_dict_append_object_path(&dict_iter,
973 wpa_s->dbus_new_path))
976 if (!wpa_dbus_dict_append_string(&dict_iter, "role", role))
979 if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
980 wpa_s->dbus_groupobj_path) ||
981 !wpa_dbus_dict_close_write(&iter, &dict_iter))
985 dbus_connection_send(iface->con, msg, NULL);
989 wpa_printf(MSG_ERROR,
990 "dbus: Failed to construct GroupFinished");
992 dbus_message_unref(msg);
997 * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
999 * @dev_addr - who sent the request or responded to our request.
1000 * @request - Will be 1 if request, 0 for response.
1001 * @status - valid only in case of response
1002 * @config_methods - wps config methods
1003 * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
1005 * Sends following provision discovery related events:
1006 * ProvisionDiscoveryRequestDisplayPin
1007 * ProvisionDiscoveryResponseDisplayPin
1008 * ProvisionDiscoveryRequestEnterPin
1009 * ProvisionDiscoveryResponseEnterPin
1010 * ProvisionDiscoveryPBCRequest
1011 * ProvisionDiscoveryPBCResponse
1014 * ProvisionDiscoveryFailure (timeout case)
1016 void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
1017 const u8 *dev_addr, int request,
1018 enum p2p_prov_disc_status status,
1020 unsigned int generated_pin)
1023 DBusMessageIter iter;
1024 struct wpas_dbus_priv *iface;
1027 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1029 char pin[9], *p_pin = NULL;
1031 iface = wpa_s->global->dbus;
1033 /* Do nothing if the control interface is not turned on */
1037 if (request || !status) {
1038 if (config_methods & WPS_CONFIG_DISPLAY)
1040 "ProvisionDiscoveryRequestDisplayPin" :
1041 "ProvisionDiscoveryResponseEnterPin";
1042 else if (config_methods & WPS_CONFIG_KEYPAD)
1044 "ProvisionDiscoveryRequestEnterPin" :
1045 "ProvisionDiscoveryResponseDisplayPin";
1046 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1047 _signal = request ? "ProvisionDiscoveryPBCRequest" :
1048 "ProvisionDiscoveryPBCResponse";
1050 return; /* Unknown or un-supported method */
1051 } else if (!request && status)
1052 /* Explicit check for failure response */
1053 _signal = "ProvisionDiscoveryFailure";
1055 add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
1056 (!request && !status &&
1057 (config_methods & WPS_CONFIG_KEYPAD)));
1060 os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
1064 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1065 WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
1069 /* Check if this is a known peer */
1070 if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
1073 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1074 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1076 wpa_s->dbus_new_path, MAC2STR(dev_addr));
1078 path = peer_obj_path;
1080 dbus_message_iter_init_append(msg, &iter);
1082 if (!dbus_message_iter_append_basic(&iter,
1083 DBUS_TYPE_OBJECT_PATH,
1087 if (!request && status)
1088 /* Attach status to ProvisionDiscoveryFailure */
1089 error_ret = !dbus_message_iter_append_basic(&iter,
1093 error_ret = (add_pin &&
1094 !dbus_message_iter_append_basic(&iter,
1100 dbus_connection_send(iface->con, msg, NULL);
1102 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1104 dbus_message_unref(msg);
1108 void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
1109 const u8 *src, u16 dev_passwd_id)
1112 DBusMessageIter iter;
1113 struct wpas_dbus_priv *iface;
1114 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1116 iface = wpa_s->global->dbus;
1118 /* Do nothing if the control interface is not turned on */
1122 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1123 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1124 wpa_s->dbus_new_path, MAC2STR(src));
1125 path = peer_obj_path;
1127 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1128 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1129 "GONegotiationRequest");
1133 dbus_message_iter_init_append(msg, &iter);
1135 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1137 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
1139 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1141 dbus_connection_send(iface->con, msg, NULL);
1143 dbus_message_unref(msg);
1147 static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
1148 const struct wpa_ssid *ssid,
1149 char *group_obj_path)
1153 if (os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
1156 os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
1157 group_name[2] = '\0';
1159 os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1160 "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
1161 wpa_s->dbus_new_path, group_name);
1167 struct group_changed_data {
1168 struct wpa_supplicant *wpa_s;
1169 struct p2p_peer_info *info;
1173 static int match_group_where_peer_is_client(struct p2p_group *group,
1176 struct group_changed_data *data = user_data;
1177 const struct p2p_group_config *cfg;
1178 struct wpa_supplicant *wpa_s_go;
1180 if (!p2p_group_is_client_connected(group, data->info->p2p_device_addr))
1183 cfg = p2p_group_get_config(group);
1185 wpa_s_go = wpas_get_p2p_go_iface(data->wpa_s, cfg->ssid,
1187 if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
1188 wpas_dbus_signal_peer_groups_changed(
1189 data->wpa_s->parent, data->info->p2p_device_addr);
1197 static void signal_peer_groups_changed(struct p2p_peer_info *info,
1200 struct group_changed_data *data = user_data;
1201 struct wpa_supplicant *wpa_s_go;
1203 wpa_s_go = wpas_get_p2p_client_iface(data->wpa_s,
1204 info->p2p_device_addr);
1205 if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
1206 wpas_dbus_signal_peer_groups_changed(data->wpa_s->parent,
1207 info->p2p_device_addr);
1212 p2p_loop_on_all_groups(data->wpa_s->global->p2p,
1213 match_group_where_peer_is_client, data);
1218 static void peer_groups_changed(struct wpa_supplicant *wpa_s)
1220 struct group_changed_data data;
1222 os_memset(&data, 0, sizeof(data));
1225 p2p_loop_on_known_peers(wpa_s->global->p2p,
1226 signal_peer_groups_changed, &data);
1231 * wpas_dbus_signal_p2p_group_started - Signals P2P group has
1232 * started. Emitted when a group is successfully started
1233 * irrespective of the role (client/GO) of the current device
1235 * @wpa_s: %wpa_supplicant network interface data
1236 * @ssid: SSID object
1237 * @client: this device is P2P client
1238 * @network_id: network id of the group started, use instead of ssid->id
1239 * to account for persistent groups
1241 void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
1242 const struct wpa_ssid *ssid,
1243 int client, int network_id)
1246 DBusMessageIter iter, dict_iter;
1247 struct wpas_dbus_priv *iface;
1249 iface = wpa_s->parent->global->dbus;
1251 /* Do nothing if the control interface is not turned on */
1255 if (wpa_s->dbus_groupobj_path == NULL)
1258 /* New interface has been created for this group */
1259 msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
1260 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1265 dbus_message_iter_init_append(msg, &iter);
1266 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1270 * In case the device supports creating a separate interface the
1271 * DBus client will need to know the object path for the interface
1272 * object this group was created on, so include it here.
1274 if (!wpa_dbus_dict_append_object_path(&dict_iter,
1276 wpa_s->dbus_new_path))
1279 if (!wpa_dbus_dict_append_string(&dict_iter, "role",
1280 client ? "client" : "GO"))
1283 if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
1284 wpa_s->dbus_groupobj_path) ||
1285 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1288 dbus_connection_send(iface->con, msg, NULL);
1291 peer_groups_changed(wpa_s);
1294 dbus_message_unref(msg);
1300 * Method to emit GONegotiation Success or Failure signals based
1302 * @status: Status of the GO neg request. 0 for success, other for errors.
1304 void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
1305 struct p2p_go_neg_results *res)
1308 DBusMessageIter iter, dict_iter;
1309 DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
1310 struct wpas_dbus_priv *iface;
1311 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1312 dbus_int32_t freqs[P2P_MAX_CHANNELS];
1313 dbus_int32_t *f_array = freqs;
1316 iface = wpa_s->global->dbus;
1318 os_memset(freqs, 0, sizeof(freqs));
1319 /* Do nothing if the control interface is not turned on */
1323 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1324 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1325 wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
1326 path = peer_obj_path;
1328 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1329 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1330 res->status ? "GONegotiationFailure" :
1331 "GONegotiationSuccess");
1335 dbus_message_iter_init_append(msg, &iter);
1336 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1338 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1340 !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
1345 int freq_list_num = 0;
1348 if (!wpa_dbus_dict_append_byte_array(
1349 &dict_iter, "passphrase",
1350 (const char *) res->passphrase,
1351 sizeof(res->passphrase)))
1355 if (!wpa_dbus_dict_append_string(&dict_iter, "role_go",
1356 res->role_go ? "GO" :
1358 !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
1360 !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
1361 (const char *) res->ssid,
1363 !wpa_dbus_dict_append_byte_array(&dict_iter,
1366 res->peer_device_addr,
1368 !wpa_dbus_dict_append_byte_array(&dict_iter,
1369 "peer_interface_addr",
1371 res->peer_interface_addr,
1373 !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
1374 p2p_wps_method_text(
1378 for (i = 0; i < P2P_MAX_CHANNELS; i++) {
1379 if (res->freq_list[i]) {
1380 freqs[i] = res->freq_list[i];
1385 if (!wpa_dbus_dict_begin_array(&dict_iter,
1387 DBUS_TYPE_INT32_AS_STRING,
1393 if (!dbus_message_iter_append_fixed_array(&iter_dict_array,
1399 if (!wpa_dbus_dict_end_array(&dict_iter,
1405 if (!wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
1406 res->persistent_group) ||
1407 !wpa_dbus_dict_append_uint32(&dict_iter,
1408 "peer_config_timeout",
1409 res->peer_config_timeout))
1413 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1416 dbus_connection_send(iface->con, msg, NULL);
1418 dbus_message_unref(msg);
1424 * Method to emit Invitation Result signal based on status and
1426 * @status: Status of the Invite request. 0 for success, other
1428 * @bssid : Basic Service Set Identifier
1430 void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
1431 int status, const u8 *bssid)
1434 DBusMessageIter iter, dict_iter;
1435 struct wpas_dbus_priv *iface;
1437 wpa_printf(MSG_DEBUG, "%s", __func__);
1439 iface = wpa_s->global->dbus;
1440 /* Do nothing if the control interface is not turned on */
1444 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1445 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1446 "InvitationResult");
1451 dbus_message_iter_init_append(msg, &iter);
1452 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1455 if (!wpa_dbus_dict_append_int32(&dict_iter, "status", status))
1458 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
1459 (const char *) bssid,
1463 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1466 dbus_connection_send(iface->con, msg, NULL);
1469 dbus_message_unref(msg);
1475 * Method to emit a signal for a peer joining the group.
1476 * The signal will carry path to the group member object
1477 * constructed using p2p i/f addr used for connecting.
1479 * @wpa_s: %wpa_supplicant network interface data
1480 * @peer_addr: P2P Device Address of the peer joining the group
1482 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
1483 const u8 *peer_addr)
1485 struct wpas_dbus_priv *iface;
1487 DBusMessageIter iter;
1488 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1490 iface = wpa_s->global->dbus;
1492 /* Do nothing if the control interface is not turned on */
1496 if (!wpa_s->dbus_groupobj_path)
1499 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1500 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1502 wpa_s->parent->dbus_new_path, MAC2STR(peer_addr));
1504 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1505 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1510 dbus_message_iter_init_append(msg, &iter);
1511 path = peer_obj_path;
1512 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1516 dbus_connection_send(iface->con, msg, NULL);
1517 dbus_message_unref(msg);
1519 wpas_dbus_signal_peer_groups_changed(wpa_s->parent, peer_addr);
1524 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1525 dbus_message_unref(msg);
1531 * Method to emit a signal for a peer disconnecting the group.
1532 * The signal will carry path to the group member object
1533 * constructed using the P2P Device Address of the peer.
1535 * @wpa_s: %wpa_supplicant network interface data
1536 * @peer_addr: P2P Device Address of the peer joining the group
1538 void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
1539 const u8 *peer_addr)
1541 struct wpas_dbus_priv *iface;
1543 DBusMessageIter iter;
1544 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1546 iface = wpa_s->global->dbus;
1548 /* Do nothing if the control interface is not turned on */
1552 if (!wpa_s->dbus_groupobj_path)
1555 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1556 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1558 wpa_s->dbus_groupobj_path, MAC2STR(peer_addr));
1560 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1561 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1562 "PeerDisconnected");
1566 dbus_message_iter_init_append(msg, &iter);
1567 path = peer_obj_path;
1568 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1572 dbus_connection_send(iface->con, msg, NULL);
1573 dbus_message_unref(msg);
1575 wpas_dbus_signal_peer_groups_changed(wpa_s->parent, peer_addr);
1580 wpa_printf(MSG_ERROR, "dbus: Failed to construct PeerDisconnected "
1582 dbus_message_unref(msg);
1588 * Method to emit a signal for a service discovery request.
1589 * The signal will carry station address, frequency, dialog token,
1590 * update indicator and it tlvs
1592 * @wpa_s: %wpa_supplicant network interface data
1593 * @sa: station addr (p2p i/f) of the peer
1594 * @dialog_token: service discovery request dialog token
1595 * @update_indic: service discovery request update indicator
1596 * @tlvs: service discovery request genrated byte array of tlvs
1597 * @tlvs_len: service discovery request tlvs length
1599 void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
1600 int freq, const u8 *sa, u8 dialog_token,
1601 u16 update_indic, const u8 *tlvs,
1605 DBusMessageIter iter, dict_iter;
1606 struct wpas_dbus_priv *iface;
1607 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1608 iface = wpa_s->global->dbus;
1610 /* Do nothing if the control interface is not turned on */
1614 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1615 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1616 "ServiceDiscoveryRequest");
1620 /* Check if this is a known peer */
1621 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1624 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1625 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1626 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1628 path = peer_obj_path;
1630 dbus_message_iter_init_append(msg, &iter);
1631 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1635 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1637 !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
1638 !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
1640 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1642 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1643 (const char *) tlvs,
1645 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1648 dbus_connection_send(iface->con, msg, NULL);
1649 dbus_message_unref(msg);
1652 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1653 dbus_message_unref(msg);
1659 * Method to emit a signal for a service discovery response.
1660 * The signal will carry station address, update indicator and it
1663 * @wpa_s: %wpa_supplicant network interface data
1664 * @sa: station addr (p2p i/f) of the peer
1665 * @update_indic: service discovery request update indicator
1666 * @tlvs: service discovery request genrated byte array of tlvs
1667 * @tlvs_len: service discovery request tlvs length
1669 void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
1670 const u8 *sa, u16 update_indic,
1671 const u8 *tlvs, size_t tlvs_len)
1674 DBusMessageIter iter, dict_iter;
1675 struct wpas_dbus_priv *iface;
1676 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1677 iface = wpa_s->global->dbus;
1679 /* Do nothing if the control interface is not turned on */
1683 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1684 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1685 "ServiceDiscoveryResponse");
1689 /* Check if this is a known peer */
1690 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1693 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1694 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1695 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1697 path = peer_obj_path;
1699 dbus_message_iter_init_append(msg, &iter);
1700 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1703 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1705 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1707 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1708 (const char *) tlvs,
1710 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1714 dbus_connection_send(iface->con, msg, NULL);
1715 dbus_message_unref(msg);
1718 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1719 dbus_message_unref(msg);
1723 * wpas_dbus_signal_persistent_group - Send a persistent group related
1725 * @wpa_s: %wpa_supplicant network interface data
1726 * @id: new persistent group id
1727 * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
1728 * @properties: determines if add second argument with object properties
1730 * Notify listeners about an event related to persistent groups.
1732 static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
1733 int id, const char *sig_name,
1736 struct wpas_dbus_priv *iface;
1738 DBusMessageIter iter;
1739 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1741 iface = wpa_s->global->dbus;
1743 /* Do nothing if the control interface is not turned on */
1747 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1748 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
1749 wpa_s->dbus_new_path, id);
1751 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1752 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1757 dbus_message_iter_init_append(msg, &iter);
1758 path = pgrp_obj_path;
1759 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1764 if (!wpa_dbus_get_object_properties(
1765 iface, pgrp_obj_path,
1766 WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter))
1770 dbus_connection_send(iface->con, msg, NULL);
1772 dbus_message_unref(msg);
1776 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1777 dbus_message_unref(msg);
1782 * wpas_dbus_signal_persistent_group_added - Send a persistent_group
1784 * @wpa_s: %wpa_supplicant network interface data
1785 * @id: new persistent group id
1787 * Notify listeners about addition of a new persistent group.
1789 static void wpas_dbus_signal_persistent_group_added(
1790 struct wpa_supplicant *wpa_s, int id)
1792 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
1798 * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
1800 * @wpa_s: %wpa_supplicant network interface data
1801 * @id: persistent group id
1803 * Notify listeners about removal of a persistent group.
1805 static void wpas_dbus_signal_persistent_group_removed(
1806 struct wpa_supplicant *wpa_s, int id)
1808 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
1814 * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
1815 * @wpa_s: %wpa_supplicant network interface data
1817 * Sends Event dbus signal with name "fail" and dictionary containing
1818 * "msg" field with fail message number (int32) as arguments
1820 void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
1821 struct wps_event_fail *fail)
1825 DBusMessageIter iter, dict_iter;
1826 struct wpas_dbus_priv *iface;
1829 iface = wpa_s->global->dbus;
1831 /* Do nothing if the control interface is not turned on */
1835 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1836 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1841 dbus_message_iter_init_append(msg, &iter);
1843 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
1844 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1845 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
1846 !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
1847 fail->config_error) ||
1848 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1849 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1851 dbus_connection_send(iface->con, msg, NULL);
1853 dbus_message_unref(msg);
1856 #endif /*CONFIG_P2P*/
1860 * wpas_dbus_signal_prop_changed - Signals change of property
1861 * @wpa_s: %wpa_supplicant network interface data
1862 * @property: indicates which property has changed
1864 * Sends PropertyChanged signals with path, interface and arguments
1865 * depending on which property has changed.
1867 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
1868 enum wpas_dbus_prop property)
1873 if (wpa_s->dbus_new_path == NULL)
1874 return; /* Skip signal since D-Bus setup is not yet ready */
1878 case WPAS_DBUS_PROP_AP_SCAN:
1881 case WPAS_DBUS_PROP_SCANNING:
1884 case WPAS_DBUS_PROP_STATE:
1887 case WPAS_DBUS_PROP_CURRENT_BSS:
1888 prop = "CurrentBSS";
1890 case WPAS_DBUS_PROP_CURRENT_NETWORK:
1891 prop = "CurrentNetwork";
1893 case WPAS_DBUS_PROP_BSSS:
1896 case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
1897 prop = "CurrentAuthMode";
1899 case WPAS_DBUS_PROP_DISCONNECT_REASON:
1900 prop = "DisconnectReason";
1904 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1905 __func__, property);
1909 wpa_dbus_mark_property_changed(wpa_s->global->dbus,
1910 wpa_s->dbus_new_path,
1911 WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
1913 wpa_dbus_flush_object_changed_properties(
1914 wpa_s->global->dbus->con, wpa_s->dbus_new_path);
1920 * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
1921 * @wpa_s: %wpa_supplicant network interface data
1922 * @property: indicates which property has changed
1923 * @id: unique BSS identifier
1925 * Sends PropertyChanged signals with path, interface, and arguments depending
1926 * on which property has changed.
1928 void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
1929 enum wpas_dbus_bss_prop property,
1932 char path[WPAS_DBUS_OBJECT_PATH_MAX];
1936 case WPAS_DBUS_BSS_PROP_SIGNAL:
1939 case WPAS_DBUS_BSS_PROP_FREQ:
1942 case WPAS_DBUS_BSS_PROP_MODE:
1945 case WPAS_DBUS_BSS_PROP_PRIVACY:
1948 case WPAS_DBUS_BSS_PROP_RATES:
1951 case WPAS_DBUS_BSS_PROP_WPA:
1954 case WPAS_DBUS_BSS_PROP_RSN:
1957 case WPAS_DBUS_BSS_PROP_WPS:
1960 case WPAS_DBUS_BSS_PROP_IES:
1963 case WPAS_DBUS_BSS_PROP_AGE:
1967 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1968 __func__, property);
1972 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1973 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1974 wpa_s->dbus_new_path, id);
1976 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
1977 WPAS_DBUS_NEW_IFACE_BSS, prop);
1982 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
1983 * @global: wpa_global structure
1985 * Sends PropertyChanged signals informing that debug level has changed.
1987 void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
1989 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1990 WPAS_DBUS_NEW_INTERFACE,
1996 * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
1997 * @global: wpa_global structure
1999 * Sends PropertyChanged signals informing that debug timestamp has changed.
2001 void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
2003 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
2004 WPAS_DBUS_NEW_INTERFACE,
2010 * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
2011 * @global: wpa_global structure
2013 * Sends PropertyChanged signals informing that debug show_keys has changed.
2015 void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
2017 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
2018 WPAS_DBUS_NEW_INTERFACE,
2023 static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
2025 WPADBusArgumentFreeFunction priv_free,
2026 const struct wpa_dbus_method_desc *methods,
2027 const struct wpa_dbus_property_desc *properties,
2028 const struct wpa_dbus_signal_desc *signals)
2032 obj_desc->user_data = priv;
2033 obj_desc->user_data_free_func = priv_free;
2034 obj_desc->methods = methods;
2035 obj_desc->properties = properties;
2036 obj_desc->signals = signals;
2038 for (n = 0; properties && properties->dbus_property; properties++)
2041 obj_desc->prop_changed_flags = os_zalloc(n);
2042 if (!obj_desc->prop_changed_flags)
2043 wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
2048 static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
2049 { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
2050 (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
2052 { "args", "a{sv}", ARG_IN },
2053 { "path", "o", ARG_OUT },
2057 { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
2058 (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
2060 { "path", "o", ARG_IN },
2064 { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
2065 (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
2067 { "ifname", "s", ARG_IN },
2068 { "path", "o", ARG_OUT },
2072 { NULL, NULL, NULL, { END_ARGS } }
2075 static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
2076 { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
2077 wpas_dbus_getter_debug_level,
2078 wpas_dbus_setter_debug_level
2080 { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
2081 wpas_dbus_getter_debug_timestamp,
2082 wpas_dbus_setter_debug_timestamp
2084 { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
2085 wpas_dbus_getter_debug_show_keys,
2086 wpas_dbus_setter_debug_show_keys
2088 { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
2089 wpas_dbus_getter_interfaces,
2092 { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
2093 wpas_dbus_getter_eap_methods,
2096 { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
2097 wpas_dbus_getter_global_capabilities,
2100 { NULL, NULL, NULL, NULL, NULL }
2103 static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
2104 { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
2106 { "path", "o", ARG_OUT },
2107 { "properties", "a{sv}", ARG_OUT },
2111 { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
2113 { "path", "o", ARG_OUT },
2117 { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
2119 { "path", "o", ARG_OUT },
2120 { "field", "s", ARG_OUT },
2121 { "text", "s", ARG_OUT },
2125 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2126 { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
2128 { "properties", "a{sv}", ARG_OUT },
2132 { NULL, NULL, { END_ARGS } }
2137 * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
2138 * @global: Pointer to global data from wpa_supplicant_init()
2139 * Returns: 0 on success or -1 on failure
2141 * Initialize the dbus control interface for wpa_supplicantand and start
2142 * receiving commands from external programs over the bus.
2144 int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
2146 struct wpa_dbus_object_desc *obj_desc;
2149 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2151 wpa_printf(MSG_ERROR, "Not enough memory "
2152 "to create object description");
2156 wpas_dbus_register(obj_desc, priv->global, NULL,
2157 wpas_dbus_global_methods,
2158 wpas_dbus_global_properties,
2159 wpas_dbus_global_signals);
2161 wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
2162 WPAS_DBUS_NEW_PATH);
2163 ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
2164 WPAS_DBUS_NEW_SERVICE,
2167 free_dbus_object_desc(obj_desc);
2169 priv->dbus_new_initialized = 1;
2176 * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
2178 * @iface: Pointer to dbus private data from wpas_dbus_init()
2180 * Deinitialize the dbus control interface that was initialized with
2181 * wpas_dbus_ctrl_iface_init().
2183 void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
2185 if (!iface->dbus_new_initialized)
2187 wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
2188 WPAS_DBUS_NEW_PATH);
2189 dbus_connection_unregister_object_path(iface->con,
2190 WPAS_DBUS_NEW_PATH);
2194 static void wpa_dbus_free(void *ptr)
2200 static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
2201 { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
2202 wpas_dbus_getter_network_properties,
2203 wpas_dbus_setter_network_properties
2205 { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
2206 wpas_dbus_getter_enabled,
2207 wpas_dbus_setter_enabled
2209 { NULL, NULL, NULL, NULL, NULL }
2213 static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
2214 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2215 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
2217 { "properties", "a{sv}", ARG_OUT },
2221 { NULL, NULL, { END_ARGS } }
2226 * wpas_dbus_register_network - Register a configured network with dbus
2227 * @wpa_s: wpa_supplicant interface structure
2228 * @ssid: network configuration data
2229 * Returns: 0 on success, -1 on failure
2231 * Registers network representing object with dbus
2233 int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
2234 struct wpa_ssid *ssid)
2236 struct wpas_dbus_priv *ctrl_iface;
2237 struct wpa_dbus_object_desc *obj_desc;
2238 struct network_handler_args *arg;
2239 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2243 * If it is a persistent group register it as such.
2244 * This is to handle cases where an interface is being initialized
2245 * with a list of networks read from config.
2247 if (network_is_persistent_group(ssid))
2248 return wpas_dbus_register_persistent_group(wpa_s, ssid);
2249 #endif /* CONFIG_P2P */
2251 /* Do nothing if the control interface is not turned on */
2252 if (wpa_s == NULL || wpa_s->global == NULL)
2254 ctrl_iface = wpa_s->global->dbus;
2255 if (ctrl_iface == NULL)
2258 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2259 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2260 wpa_s->dbus_new_path, ssid->id);
2262 wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
2264 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2266 wpa_printf(MSG_ERROR, "Not enough memory "
2267 "to create object description");
2271 /* allocate memory for handlers arguments */
2272 arg = os_zalloc(sizeof(struct network_handler_args));
2274 wpa_printf(MSG_ERROR, "Not enough memory "
2275 "to create arguments for method");
2282 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2283 wpas_dbus_network_properties,
2284 wpas_dbus_network_signals);
2286 if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
2287 wpa_s->ifname, obj_desc))
2290 wpas_dbus_signal_network_added(wpa_s, ssid->id);
2295 free_dbus_object_desc(obj_desc);
2301 * wpas_dbus_unregister_network - Unregister a configured network from dbus
2302 * @wpa_s: wpa_supplicant interface structure
2304 * Returns: 0 on success, -1 on failure
2306 * Unregisters network representing object from dbus
2308 int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
2310 struct wpas_dbus_priv *ctrl_iface;
2311 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2314 struct wpa_ssid *ssid;
2316 ssid = wpa_config_get_network(wpa_s->conf, nid);
2318 /* If it is a persistent group unregister it as such */
2319 if (ssid && network_is_persistent_group(ssid))
2320 return wpas_dbus_unregister_persistent_group(wpa_s, nid);
2321 #endif /* CONFIG_P2P */
2323 /* Do nothing if the control interface is not turned on */
2324 if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
2326 ctrl_iface = wpa_s->global->dbus;
2327 if (ctrl_iface == NULL)
2330 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2331 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2332 wpa_s->dbus_new_path, nid);
2334 wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
2336 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
2339 wpas_dbus_signal_network_removed(wpa_s, nid);
2345 static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
2346 { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2347 wpas_dbus_getter_bss_ssid,
2350 { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2351 wpas_dbus_getter_bss_bssid,
2354 { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
2355 wpas_dbus_getter_bss_privacy,
2358 { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
2359 wpas_dbus_getter_bss_mode,
2362 { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
2363 wpas_dbus_getter_bss_signal,
2366 { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
2367 wpas_dbus_getter_bss_frequency,
2370 { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
2371 wpas_dbus_getter_bss_rates,
2374 { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2375 wpas_dbus_getter_bss_wpa,
2378 { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2379 wpas_dbus_getter_bss_rsn,
2382 { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2383 wpas_dbus_getter_bss_wps,
2386 { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2387 wpas_dbus_getter_bss_ies,
2390 { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
2391 wpas_dbus_getter_bss_age,
2394 { NULL, NULL, NULL, NULL, NULL }
2398 static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
2399 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2400 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
2402 { "properties", "a{sv}", ARG_OUT },
2406 { NULL, NULL, { END_ARGS } }
2411 * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
2412 * @wpa_s: wpa_supplicant interface structure
2413 * @bssid: scanned network bssid
2414 * @id: unique BSS identifier
2415 * Returns: 0 on success, -1 on failure
2417 * Unregisters BSS representing object from dbus
2419 int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
2420 u8 bssid[ETH_ALEN], unsigned int id)
2422 struct wpas_dbus_priv *ctrl_iface;
2423 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2425 /* Do nothing if the control interface is not turned on */
2426 if (wpa_s == NULL || wpa_s->global == NULL)
2428 ctrl_iface = wpa_s->global->dbus;
2429 if (ctrl_iface == NULL)
2432 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2433 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2434 wpa_s->dbus_new_path, id);
2436 wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
2438 if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
2439 wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
2444 wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
2445 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2452 * wpas_dbus_register_bss - Register a scanned BSS with dbus
2453 * @wpa_s: wpa_supplicant interface structure
2454 * @bssid: scanned network bssid
2455 * @id: unique BSS identifier
2456 * Returns: 0 on success, -1 on failure
2458 * Registers BSS representing object with dbus
2460 int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
2461 u8 bssid[ETH_ALEN], unsigned int id)
2463 struct wpas_dbus_priv *ctrl_iface;
2464 struct wpa_dbus_object_desc *obj_desc;
2465 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2466 struct bss_handler_args *arg;
2468 /* Do nothing if the control interface is not turned on */
2469 if (wpa_s == NULL || wpa_s->global == NULL)
2471 ctrl_iface = wpa_s->global->dbus;
2472 if (ctrl_iface == NULL)
2475 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2476 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2477 wpa_s->dbus_new_path, id);
2479 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2481 wpa_printf(MSG_ERROR, "Not enough memory "
2482 "to create object description");
2486 arg = os_zalloc(sizeof(struct bss_handler_args));
2488 wpa_printf(MSG_ERROR, "Not enough memory "
2489 "to create arguments for handler");
2495 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2496 wpas_dbus_bss_properties,
2497 wpas_dbus_bss_signals);
2499 wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
2501 if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
2502 wpa_s->ifname, obj_desc)) {
2503 wpa_printf(MSG_ERROR,
2504 "Cannot register BSSID dbus object %s.",
2509 wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
2510 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2515 free_dbus_object_desc(obj_desc);
2520 static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
2521 { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2522 (WPADBusMethodHandler) &wpas_dbus_handler_scan,
2524 { "args", "a{sv}", ARG_IN },
2528 { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
2529 (WPADBusMethodHandler) &wpas_dbus_handler_signal_poll,
2531 { "args", "a{sv}", ARG_OUT },
2535 { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2536 (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
2541 { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2542 (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
2544 { "args", "a{sv}", ARG_IN },
2545 { "path", "o", ARG_OUT },
2549 { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
2550 (WPADBusMethodHandler) &wpas_dbus_handler_reassociate,
2555 { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
2556 (WPADBusMethodHandler) &wpas_dbus_handler_reattach,
2561 { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2562 (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
2564 { "path", "o", ARG_IN },
2568 { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
2569 (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
2574 { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2575 (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
2577 { "path", "o", ARG_IN },
2581 { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
2582 (WPADBusMethodHandler) &wpas_dbus_handler_network_reply,
2584 { "path", "o", ARG_IN },
2585 { "field", "s", ARG_IN },
2586 { "value", "s", ARG_IN },
2590 #ifndef CONFIG_NO_CONFIG_BLOBS
2591 { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2592 (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
2594 { "name", "s", ARG_IN },
2595 { "data", "ay", ARG_IN },
2599 { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2600 (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
2602 { "name", "s", ARG_IN },
2603 { "data", "ay", ARG_OUT },
2607 { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2608 (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
2610 { "name", "s", ARG_IN },
2614 #endif /* CONFIG_NO_CONFIG_BLOBS */
2615 { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
2616 (WPADBusMethodHandler)
2617 &wpas_dbus_handler_set_pkcs11_engine_and_module_path,
2619 { "pkcs11_engine_path", "s", ARG_IN },
2620 { "pkcs11_module_path", "s", ARG_IN },
2625 { "Start", WPAS_DBUS_NEW_IFACE_WPS,
2626 (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
2628 { "args", "a{sv}", ARG_IN },
2629 { "output", "a{sv}", ARG_OUT },
2633 #endif /* CONFIG_WPS */
2635 { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2636 (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
2638 { "args", "a{sv}", ARG_IN },
2642 { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2643 (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
2648 { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2649 (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
2651 { "timeout", "i", ARG_IN },
2655 { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2656 (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
2658 { "args", "a{sv}", ARG_IN },
2662 { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2663 (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
2665 { "args", "a{sv}", ARG_IN },
2669 { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2670 (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
2672 { "peer", "o", ARG_IN },
2673 { "config_method", "s", ARG_IN },
2677 { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2678 (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
2680 { "args", "a{sv}", ARG_IN },
2681 { "generated_pin", "s", ARG_OUT },
2685 { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2686 (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
2688 { "args", "a{sv}", ARG_IN },
2692 { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2693 (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
2695 { "args", "a{sv}", ARG_IN },
2699 { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2700 (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
2705 { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2706 (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
2708 { "peer", "o", ARG_IN },
2712 { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2713 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
2718 { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2719 (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
2721 { "args", "a{sv}", ARG_IN },
2725 { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2726 (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
2728 { "args", "a{sv}", ARG_IN },
2732 { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2733 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
2738 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2739 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
2741 { "args", "a{sv}", ARG_IN },
2742 { "ref", "t", ARG_OUT },
2746 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2747 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
2749 { "args", "a{sv}", ARG_IN },
2753 { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2754 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
2756 { "args", "t", ARG_IN },
2760 { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2761 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
2766 { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2767 (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
2769 { "arg", "i", ARG_IN },
2773 { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2774 (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
2776 { "args", "a{sv}", ARG_IN },
2777 { "path", "o", ARG_OUT },
2781 { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2782 (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
2784 { "path", "o", ARG_IN },
2788 { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2789 (WPADBusMethodHandler)
2790 wpas_dbus_handler_remove_all_persistent_groups,
2795 #endif /* CONFIG_P2P */
2796 { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
2797 (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
2799 { "age", "u", ARG_IN },
2804 { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2805 (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
2810 { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2811 (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
2816 #endif /* CONFIG_AP */
2817 { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
2818 (WPADBusMethodHandler) &wpas_dbus_handler_eap_logoff,
2823 { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
2824 (WPADBusMethodHandler) &wpas_dbus_handler_eap_logon,
2829 #ifdef CONFIG_AUTOSCAN
2830 { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2831 (WPADBusMethodHandler) &wpas_dbus_handler_autoscan,
2833 { "arg", "s", ARG_IN },
2837 #endif /* CONFIG_AUTOSCAN */
2839 { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
2840 (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
2842 { "peer_address", "s", ARG_IN },
2846 { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
2847 (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
2849 { "peer_address", "s", ARG_IN },
2853 { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
2854 (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
2856 { "peer_address", "s", ARG_IN },
2857 { "status", "s", ARG_OUT },
2861 { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
2862 (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
2864 { "peer_address", "s", ARG_IN },
2868 #endif /* CONFIG_TDLS */
2869 { NULL, NULL, NULL, { END_ARGS } }
2872 static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
2873 { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
2874 wpas_dbus_getter_capabilities,
2877 { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2878 wpas_dbus_getter_state,
2881 { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2882 wpas_dbus_getter_scanning,
2885 { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2886 wpas_dbus_getter_ap_scan,
2887 wpas_dbus_setter_ap_scan
2889 { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2890 wpas_dbus_getter_bss_expire_age,
2891 wpas_dbus_setter_bss_expire_age
2893 { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2894 wpas_dbus_getter_bss_expire_count,
2895 wpas_dbus_setter_bss_expire_count
2897 { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2898 wpas_dbus_getter_country,
2899 wpas_dbus_setter_country
2901 { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2902 wpas_dbus_getter_ifname,
2905 { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2906 wpas_dbus_getter_driver,
2909 { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2910 wpas_dbus_getter_bridge_ifname,
2913 { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2914 wpas_dbus_getter_current_bss,
2917 { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2918 wpas_dbus_getter_current_network,
2921 { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2922 wpas_dbus_getter_current_auth_mode,
2925 { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
2926 wpas_dbus_getter_blobs,
2929 { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2930 wpas_dbus_getter_bsss,
2933 { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2934 wpas_dbus_getter_networks,
2937 { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2938 wpas_dbus_getter_fast_reauth,
2939 wpas_dbus_setter_fast_reauth
2941 { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
2942 wpas_dbus_getter_scan_interval,
2943 wpas_dbus_setter_scan_interval
2945 { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2946 wpas_dbus_getter_pkcs11_engine_path,
2949 { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2950 wpas_dbus_getter_pkcs11_module_path,
2954 { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
2955 wpas_dbus_getter_process_credentials,
2956 wpas_dbus_setter_process_credentials
2958 #endif /* CONFIG_WPS */
2960 { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
2961 wpas_dbus_getter_p2p_device_config,
2962 wpas_dbus_setter_p2p_device_config
2964 { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2965 wpas_dbus_getter_p2p_peers,
2968 { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
2969 wpas_dbus_getter_p2p_role,
2972 { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2973 wpas_dbus_getter_p2p_group,
2976 { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2977 wpas_dbus_getter_p2p_peergo,
2980 { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2981 wpas_dbus_getter_persistent_groups,
2984 #endif /* CONFIG_P2P */
2985 { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
2986 wpas_dbus_getter_disconnect_reason,
2989 { NULL, NULL, NULL, NULL, NULL }
2992 static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
2993 { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
2995 { "success", "b", ARG_OUT },
2999 { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3001 { "path", "o", ARG_OUT },
3002 { "properties", "a{sv}", ARG_OUT },
3006 { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3008 { "path", "o", ARG_OUT },
3012 { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3014 { "name", "s", ARG_OUT },
3018 { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3020 { "name", "s", ARG_OUT },
3024 { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3026 { "path", "o", ARG_OUT },
3027 { "properties", "a{sv}", ARG_OUT },
3031 { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3033 { "path", "o", ARG_OUT },
3037 { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
3039 { "path", "o", ARG_OUT },
3043 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3044 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
3046 { "properties", "a{sv}", ARG_OUT },
3051 { "Event", WPAS_DBUS_NEW_IFACE_WPS,
3053 { "name", "s", ARG_OUT },
3054 { "args", "a{sv}", ARG_OUT },
3058 { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
3060 { "credentials", "a{sv}", ARG_OUT },
3064 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3065 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
3067 { "properties", "a{sv}", ARG_OUT },
3071 #endif /* CONFIG_WPS */
3073 { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3075 { "states", "a{ss}", ARG_OUT },
3079 { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3081 { "path", "o", ARG_OUT },
3085 { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3087 { "path", "o", ARG_OUT },
3091 { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3093 { "peer_object", "o", ARG_OUT },
3094 { "pin", "s", ARG_OUT },
3098 { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3100 { "peer_object", "o", ARG_OUT },
3101 { "pin", "s", ARG_OUT },
3105 { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3107 { "peer_object", "o", ARG_OUT },
3111 { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3113 { "peer_object", "o", ARG_OUT },
3117 { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3119 { "peer_object", "o", ARG_OUT },
3123 { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3125 { "peer_object", "o", ARG_OUT },
3129 { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3131 { "peer_object", "o", ARG_OUT },
3132 { "status", "i", ARG_OUT },
3136 { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3138 { "properties", "a{sv}", ARG_OUT },
3142 { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3144 { "properties", "a{sv}", ARG_OUT },
3148 { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3150 { "properties", "a{sv}", ARG_OUT },
3154 { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3156 { "path", "o", ARG_OUT },
3157 { "dev_passwd_id", "i", ARG_OUT },
3161 { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3163 { "invite_result", "a{sv}", ARG_OUT },
3167 { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3169 { "properties", "a{sv}", ARG_OUT },
3173 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3175 { "sd_request", "a{sv}", ARG_OUT },
3179 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3181 { "sd_response", "a{sv}", ARG_OUT },
3185 { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3187 { "path", "o", ARG_OUT },
3188 { "properties", "a{sv}", ARG_OUT },
3192 { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3194 { "path", "o", ARG_OUT },
3198 { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3200 { "name", "s", ARG_OUT },
3201 { "args", "a{sv}", ARG_OUT },
3205 #endif /* CONFIG_P2P */
3207 { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
3209 { "args", "a{sv}", ARG_OUT },
3213 #endif /* CONFIG_AP */
3214 { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
3216 { "certification", "a{sv}", ARG_OUT },
3220 { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
3222 { "status", "s", ARG_OUT },
3223 { "parameter", "s", ARG_OUT },
3227 { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3229 { "name", "s", ARG_OUT },
3233 { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3235 { "name", "s", ARG_OUT },
3239 { NULL, NULL, { END_ARGS } }
3243 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
3246 struct wpa_dbus_object_desc *obj_desc = NULL;
3247 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
3250 /* Do nothing if the control interface is not turned on */
3251 if (ctrl_iface == NULL)
3254 /* Create and set the interface's object path */
3255 wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3256 if (wpa_s->dbus_new_path == NULL)
3258 next = ctrl_iface->next_objid++;
3259 os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
3260 WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
3263 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3265 wpa_printf(MSG_ERROR, "Not enough memory "
3266 "to create object description");
3270 wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
3271 wpas_dbus_interface_properties,
3272 wpas_dbus_interface_signals);
3274 wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
3275 wpa_s->dbus_new_path);
3276 if (wpa_dbus_register_object_per_iface(ctrl_iface,
3277 wpa_s->dbus_new_path,
3278 wpa_s->ifname, obj_desc))
3281 wpas_dbus_signal_interface_added(wpa_s);
3286 os_free(wpa_s->dbus_new_path);
3287 wpa_s->dbus_new_path = NULL;
3288 free_dbus_object_desc(obj_desc);
3293 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
3295 struct wpas_dbus_priv *ctrl_iface;
3297 /* Do nothing if the control interface is not turned on */
3298 if (wpa_s == NULL || wpa_s->global == NULL)
3300 ctrl_iface = wpa_s->global->dbus;
3301 if (ctrl_iface == NULL)
3304 wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
3305 wpa_s->dbus_new_path);
3308 if (wpa_s->preq_notify_peer) {
3309 wpas_dbus_unsubscribe_noc(ctrl_iface);
3310 os_free(wpa_s->preq_notify_peer);
3311 wpa_s->preq_notify_peer = NULL;
3313 #endif /* CONFIG_AP */
3315 if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
3316 wpa_s->dbus_new_path))
3319 wpas_dbus_signal_interface_removed(wpa_s);
3321 os_free(wpa_s->dbus_new_path);
3322 wpa_s->dbus_new_path = NULL;
3329 static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
3330 { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3331 wpas_dbus_getter_p2p_peer_device_name,
3334 { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3335 wpas_dbus_getter_p2p_peer_primary_device_type,
3338 { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
3339 wpas_dbus_getter_p2p_peer_config_method,
3342 { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
3343 wpas_dbus_getter_p2p_peer_level,
3346 { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3347 wpas_dbus_getter_p2p_peer_device_capability,
3350 { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3351 wpas_dbus_getter_p2p_peer_group_capability,
3354 { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3355 wpas_dbus_getter_p2p_peer_secondary_device_types,
3358 { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3359 wpas_dbus_getter_p2p_peer_vendor_extension,
3362 { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3363 wpas_dbus_getter_p2p_peer_ies,
3366 { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3367 wpas_dbus_getter_p2p_peer_device_address,
3370 { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
3371 wpas_dbus_getter_p2p_peer_groups,
3374 { NULL, NULL, NULL, NULL, NULL }
3377 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
3378 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3379 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
3381 { "properties", "a{sv}", ARG_OUT },
3385 { NULL, NULL, { END_ARGS } }
3389 * wpas_dbus_signal_peer - Send a peer related event signal
3390 * @wpa_s: %wpa_supplicant network interface data
3391 * @dev: peer device object
3392 * @interface: name of the interface emitting this signal.
3393 * In case of peer objects, it would be emitted by either
3394 * the "interface object" or by "peer objects"
3395 * @sig_name: signal name - DeviceFound
3397 * Notify listeners about event related with newly found p2p peer device
3399 static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
3400 const u8 *dev_addr, const char *interface,
3401 const char *sig_name)
3403 struct wpas_dbus_priv *iface;
3405 DBusMessageIter iter;
3406 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
3408 iface = wpa_s->global->dbus;
3410 /* Do nothing if the control interface is not turned on */
3414 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3415 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3416 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3418 msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
3423 dbus_message_iter_init_append(msg, &iter);
3424 path = peer_obj_path;
3425 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
3429 dbus_connection_send(iface->con, msg, NULL);
3431 dbus_message_unref(msg);
3435 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
3436 dbus_message_unref(msg);
3441 * wpas_dbus_signal_peer_found - Send a peer found signal
3442 * @wpa_s: %wpa_supplicant network interface data
3443 * @dev: peer device object
3445 * Notify listeners about find a p2p peer device found
3447 void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
3450 wpas_dbus_signal_peer(wpa_s, dev_addr,
3451 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3456 * wpas_dbus_signal_peer_lost - Send a peer lost signal
3457 * @wpa_s: %wpa_supplicant network interface data
3458 * @dev: peer device object
3460 * Notify listeners about lost a p2p peer device
3462 void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
3465 wpas_dbus_signal_peer(wpa_s, dev_addr,
3466 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3471 * wpas_dbus_register_peer - Register a discovered peer object with dbus
3472 * @wpa_s: wpa_supplicant interface structure
3473 * @ssid: network configuration data
3474 * Returns: 0 on success, -1 on failure
3476 * Registers network representing object with dbus
3478 int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
3480 struct wpas_dbus_priv *ctrl_iface;
3481 struct wpa_dbus_object_desc *obj_desc;
3482 struct peer_handler_args *arg;
3483 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3485 /* Do nothing if the control interface is not turned on */
3486 if (wpa_s == NULL || wpa_s->global == NULL)
3489 ctrl_iface = wpa_s->global->dbus;
3490 if (ctrl_iface == NULL)
3493 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3494 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3495 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3497 wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
3499 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3501 wpa_printf(MSG_ERROR, "Not enough memory "
3502 "to create object description");
3506 /* allocate memory for handlers arguments */
3507 arg = os_zalloc(sizeof(struct peer_handler_args));
3509 wpa_printf(MSG_ERROR, "Not enough memory "
3510 "to create arguments for method");
3515 os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
3517 wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
3519 wpas_dbus_p2p_peer_properties,
3520 wpas_dbus_p2p_peer_signals);
3522 if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
3523 wpa_s->ifname, obj_desc))
3529 free_dbus_object_desc(obj_desc);
3534 * wpas_dbus_unregister_peer - Unregister a peer object with dbus
3535 * @wpa_s: wpa_supplicant interface structure
3536 * @dev_addr: p2p device addr
3537 * Returns: 0 on success, -1 on failure
3539 * Registers network representing object with dbus
3541 int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
3544 struct wpas_dbus_priv *ctrl_iface;
3545 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3548 /* Do nothing if the control interface is not turned on */
3549 if (wpa_s == NULL || wpa_s->global == NULL ||
3550 wpa_s->dbus_new_path == NULL)
3552 ctrl_iface = wpa_s->global->dbus;
3553 if (ctrl_iface == NULL)
3556 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3557 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3558 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3560 wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
3562 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
3568 void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
3571 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3573 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3574 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3575 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3577 wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
3578 WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
3582 static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
3583 { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
3584 wpas_dbus_getter_p2p_group_members,
3587 { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
3588 wpas_dbus_getter_p2p_group,
3591 { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3592 wpas_dbus_getter_p2p_role,
3595 { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3596 wpas_dbus_getter_p2p_group_ssid,
3599 { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3600 wpas_dbus_getter_p2p_group_bssid,
3603 { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
3604 wpas_dbus_getter_p2p_group_frequency,
3607 { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3608 wpas_dbus_getter_p2p_group_passphrase,
3611 { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3612 wpas_dbus_getter_p2p_group_psk,
3615 { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
3616 wpas_dbus_getter_p2p_group_vendor_ext,
3617 wpas_dbus_setter_p2p_group_vendor_ext
3619 { NULL, NULL, NULL, NULL, NULL }
3622 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
3623 { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3625 { "peer", "o", ARG_OUT },
3629 { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3631 { "peer", "o", ARG_OUT },
3635 { NULL, NULL, { END_ARGS } }
3639 * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
3640 * @wpa_s: wpa_supplicant interface structure
3641 * @ssid: SSID struct
3642 * Returns: 0 on success, -1 on failure
3644 * Registers p2p group representing object with dbus
3646 void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
3647 struct wpa_ssid *ssid)
3649 struct wpas_dbus_priv *ctrl_iface;
3650 struct wpa_dbus_object_desc *obj_desc;
3651 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3653 /* Do nothing if the control interface is not turned on */
3654 if (wpa_s == NULL || wpa_s->global == NULL)
3657 ctrl_iface = wpa_s->global->dbus;
3658 if (ctrl_iface == NULL)
3661 if (wpa_s->dbus_groupobj_path) {
3662 wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
3663 __func__, wpa_s->dbus_groupobj_path);
3667 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
3670 wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
3671 if (wpa_s->dbus_groupobj_path == NULL)
3674 wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
3676 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3678 wpa_printf(MSG_ERROR, "Not enough memory "
3679 "to create object description");
3683 wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
3684 wpas_dbus_p2p_group_properties,
3685 wpas_dbus_p2p_group_signals);
3687 if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
3688 wpa_s->ifname, obj_desc))
3694 if (wpa_s->dbus_groupobj_path) {
3695 os_free(wpa_s->dbus_groupobj_path);
3696 wpa_s->dbus_groupobj_path = NULL;
3699 free_dbus_object_desc(obj_desc);
3703 * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
3704 * @wpa_s: wpa_supplicant interface structure
3705 * @ssid: network name of the p2p group started
3707 void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
3708 const struct wpa_ssid *ssid)
3710 struct wpas_dbus_priv *ctrl_iface;
3712 /* Do nothing if the control interface is not turned on */
3713 if (wpa_s == NULL || wpa_s->global == NULL)
3716 ctrl_iface = wpa_s->global->dbus;
3717 if (ctrl_iface == NULL)
3720 if (!wpa_s->dbus_groupobj_path) {
3721 wpa_printf(MSG_DEBUG,
3722 "%s: Group object '%s' already unregistered",
3723 __func__, wpa_s->dbus_groupobj_path);
3727 peer_groups_changed(wpa_s);
3729 wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
3730 wpa_s->dbus_groupobj_path);
3732 wpa_dbus_unregister_object_per_iface(ctrl_iface,
3733 wpa_s->dbus_groupobj_path);
3735 os_free(wpa_s->dbus_groupobj_path);
3736 wpa_s->dbus_groupobj_path = NULL;
3739 static const struct wpa_dbus_property_desc
3740 wpas_dbus_persistent_group_properties[] = {
3741 { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
3742 wpas_dbus_getter_persistent_group_properties,
3743 wpas_dbus_setter_persistent_group_properties
3745 { NULL, NULL, NULL, NULL, NULL }
3748 /* No signals intended for persistent group objects */
3751 * wpas_dbus_register_persistent_group - Register a configured(saved)
3752 * persistent group with dbus
3753 * @wpa_s: wpa_supplicant interface structure
3754 * @ssid: persistent group (still represented as a network within wpa)
3755 * configuration data
3756 * Returns: 0 on success, -1 on failure
3758 * Registers a persistent group representing object with dbus.
3760 int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
3761 struct wpa_ssid *ssid)
3763 struct wpas_dbus_priv *ctrl_iface;
3764 struct wpa_dbus_object_desc *obj_desc;
3765 struct network_handler_args *arg;
3766 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3768 /* Do nothing if the control interface is not turned on */
3769 if (wpa_s == NULL || wpa_s->global == NULL)
3772 /* Make sure ssid is a persistent group */
3773 if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
3774 return -1; /* should we return w/o complaining? */
3776 ctrl_iface = wpa_s->global->dbus;
3777 if (ctrl_iface == NULL)
3781 * Intentionally not coming up with different numbering scheme
3782 * for persistent groups.
3784 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3785 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3786 wpa_s->dbus_new_path, ssid->id);
3788 wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
3790 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3792 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3793 "object description");
3798 * Reusing the same context structure as that for networks
3799 * since these are represented using same data structure.
3801 /* allocate memory for handlers arguments */
3802 arg = os_zalloc(sizeof(struct network_handler_args));
3804 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3805 "arguments for method");
3812 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3813 wpas_dbus_persistent_group_properties,
3816 if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
3817 wpa_s->ifname, obj_desc))
3820 wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
3825 free_dbus_object_desc(obj_desc);
3831 * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
3833 * @wpa_s: wpa_supplicant interface structure
3835 * Returns: 0 on success, -1 on failure
3837 * Unregisters persistent group representing object from dbus
3839 * NOTE: There is a slight issue with the semantics here. While the
3840 * implementation simply means the persistent group is unloaded from memory,
3841 * it should not get interpreted as the group is actually being erased/removed
3842 * from persistent storage as well.
3844 int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
3847 struct wpas_dbus_priv *ctrl_iface;
3848 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3851 /* Do nothing if the control interface is not turned on */
3852 if (wpa_s == NULL || wpa_s->global == NULL ||
3853 wpa_s->dbus_new_path == NULL)
3855 ctrl_iface = wpa_s->global->dbus;
3856 if (ctrl_iface == NULL)
3859 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3860 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3861 wpa_s->dbus_new_path, nid);
3863 wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
3865 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
3868 wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
3873 #endif /* CONFIG_P2P */