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) {
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 */
140 if (iface == NULL || !wpa_s->dbus_new_path)
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) ||
152 !wpa_dbus_get_object_properties(
153 iface, wpa_s->dbus_new_path,
154 WPAS_DBUS_NEW_IFACE_INTERFACE, &iter)))
155 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
157 dbus_connection_send(iface->con, msg, NULL);
158 dbus_message_unref(msg);
163 * wpas_dbus_signal_interface_added - Send a interface created signal
164 * @wpa_s: %wpa_supplicant network interface data
166 * Notify listeners about creating new interface
168 static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
170 wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
175 * wpas_dbus_signal_interface_removed - Send a interface removed signal
176 * @wpa_s: %wpa_supplicant network interface data
178 * Notify listeners about removing interface
180 static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
182 wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
188 * wpas_dbus_signal_scan_done - send scan done signal
189 * @wpa_s: %wpa_supplicant network interface data
190 * @success: indicates if scanning succeed or failed
192 * Notify listeners about finishing a scan
194 void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
196 struct wpas_dbus_priv *iface;
200 iface = wpa_s->global->dbus;
202 /* Do nothing if the control interface is not turned on */
203 if (iface == NULL || !wpa_s->dbus_new_path)
206 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
207 WPAS_DBUS_NEW_IFACE_INTERFACE,
212 succ = success ? TRUE : FALSE;
213 if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
215 dbus_connection_send(iface->con, msg, NULL);
217 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
218 dbus_message_unref(msg);
223 * wpas_dbus_signal_bss - Send a BSS related event signal
224 * @wpa_s: %wpa_supplicant network interface data
225 * @bss_obj_path: BSS object path
226 * @sig_name: signal name - BSSAdded or BSSRemoved
227 * @properties: Whether to add second argument with object properties
229 * Notify listeners about event related with BSS
231 static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
232 const char *bss_obj_path,
233 const char *sig_name, int properties)
235 struct wpas_dbus_priv *iface;
237 DBusMessageIter iter;
239 iface = wpa_s->global->dbus;
241 /* Do nothing if the control interface is not turned on */
242 if (iface == NULL || !wpa_s->dbus_new_path)
245 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
246 WPAS_DBUS_NEW_IFACE_INTERFACE,
251 dbus_message_iter_init_append(msg, &iter);
252 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
255 !wpa_dbus_get_object_properties(iface, bss_obj_path,
256 WPAS_DBUS_NEW_IFACE_BSS,
258 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
260 dbus_connection_send(iface->con, msg, NULL);
261 dbus_message_unref(msg);
266 * wpas_dbus_signal_bss_added - Send a BSS added signal
267 * @wpa_s: %wpa_supplicant network interface data
268 * @bss_obj_path: new BSS object path
270 * Notify listeners about adding new BSS
272 static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
273 const char *bss_obj_path)
275 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
280 * wpas_dbus_signal_bss_removed - Send a BSS removed signal
281 * @wpa_s: %wpa_supplicant network interface data
282 * @bss_obj_path: BSS object path
284 * Notify listeners about removing BSS
286 static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
287 const char *bss_obj_path)
289 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
294 * wpas_dbus_signal_blob - Send a blob related event signal
295 * @wpa_s: %wpa_supplicant network interface data
297 * @sig_name: signal name - BlobAdded or BlobRemoved
299 * Notify listeners about event related with blob
301 static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
302 const char *name, const char *sig_name)
304 struct wpas_dbus_priv *iface;
307 iface = wpa_s->global->dbus;
309 /* Do nothing if the control interface is not turned on */
310 if (iface == NULL || !wpa_s->dbus_new_path)
313 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
314 WPAS_DBUS_NEW_IFACE_INTERFACE,
319 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
321 dbus_connection_send(iface->con, msg, NULL);
323 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
324 dbus_message_unref(msg);
329 * wpas_dbus_signal_blob_added - Send a blob added signal
330 * @wpa_s: %wpa_supplicant network interface data
333 * Notify listeners about adding a new blob
335 void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
338 wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
343 * wpas_dbus_signal_blob_removed - Send a blob removed signal
344 * @wpa_s: %wpa_supplicant network interface data
347 * Notify listeners about removing blob
349 void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
352 wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
357 * wpas_dbus_signal_network - Send a network related event signal
358 * @wpa_s: %wpa_supplicant network interface data
359 * @id: new network id
360 * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
361 * @properties: determines if add second argument with object properties
363 * Notify listeners about event related with configured network
365 static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
366 int id, const char *sig_name,
369 struct wpas_dbus_priv *iface;
371 DBusMessageIter iter;
372 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
374 iface = wpa_s->global->dbus;
376 /* Do nothing if the control interface is not turned on */
377 if (iface == NULL || !wpa_s->dbus_new_path)
380 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
381 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
382 wpa_s->dbus_new_path, id);
384 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
385 WPAS_DBUS_NEW_IFACE_INTERFACE,
390 dbus_message_iter_init_append(msg, &iter);
392 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
395 !wpa_dbus_get_object_properties(
396 iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
398 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
400 dbus_connection_send(iface->con, msg, NULL);
401 dbus_message_unref(msg);
406 * wpas_dbus_signal_network_added - Send a network added signal
407 * @wpa_s: %wpa_supplicant network interface data
408 * @id: new network id
410 * Notify listeners about adding new network
412 static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
415 wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
420 * wpas_dbus_signal_network_removed - Send a network removed signal
421 * @wpa_s: %wpa_supplicant network interface data
424 * Notify listeners about removing a network
426 static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
429 wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
434 * wpas_dbus_signal_network_selected - Send a network selected signal
435 * @wpa_s: %wpa_supplicant network interface data
438 * Notify listeners about selecting a network
440 void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
442 wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
447 * wpas_dbus_signal_network_request - Indicate that additional information
448 * (EAP password, etc.) is required to complete the association to this SSID
449 * @wpa_s: %wpa_supplicant network interface data
450 * @rtype: The specific additional information required
451 * @default_text: Optional description of required information
453 * Request additional information or passwords to complete an association
456 void wpas_dbus_signal_network_request(struct wpa_supplicant *wpa_s,
457 struct wpa_ssid *ssid,
458 enum wpa_ctrl_req_type rtype,
459 const char *default_txt)
461 struct wpas_dbus_priv *iface;
463 DBusMessageIter iter;
464 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
465 const char *field, *txt = NULL, *net_ptr;
467 iface = wpa_s->global->dbus;
469 /* Do nothing if the control interface is not turned on */
470 if (iface == NULL || !wpa_s->dbus_new_path)
473 field = wpa_supplicant_ctrl_req_to_string(rtype, default_txt, &txt);
477 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
478 WPAS_DBUS_NEW_IFACE_INTERFACE,
483 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
484 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
485 wpa_s->dbus_new_path, ssid->id);
486 net_ptr = &net_obj_path[0];
488 dbus_message_iter_init_append(msg, &iter);
489 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
491 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &field) ||
492 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &txt))
493 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
495 dbus_connection_send(iface->con, msg, NULL);
496 dbus_message_unref(msg);
501 * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
502 * @wpa_s: %wpa_supplicant network interface data
503 * @ssid: configured network which Enabled property has changed
505 * Sends PropertyChanged signals containing new value of Enabled property
506 * for specified network
508 void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
509 struct wpa_ssid *ssid)
512 char path[WPAS_DBUS_OBJECT_PATH_MAX];
514 if (!wpa_s->dbus_new_path)
516 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
517 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
518 wpa_s->dbus_new_path, ssid->id);
520 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
521 WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
528 * wpas_dbus_signal_wps_event_pbc_overlap - Signals PBC overlap WPS event
529 * @wpa_s: %wpa_supplicant network interface data
531 * Sends Event dbus signal with name "pbc-overlap" and empty dict as arguments
533 void wpas_dbus_signal_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
537 DBusMessageIter iter, dict_iter;
538 struct wpas_dbus_priv *iface;
539 char *key = "pbc-overlap";
541 iface = wpa_s->global->dbus;
543 /* Do nothing if the control interface is not turned on */
544 if (iface == NULL || !wpa_s->dbus_new_path)
547 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
548 WPAS_DBUS_NEW_IFACE_WPS, "Event");
552 dbus_message_iter_init_append(msg, &iter);
554 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
555 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
556 !wpa_dbus_dict_close_write(&iter, &dict_iter))
557 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
559 dbus_connection_send(iface->con, msg, NULL);
561 dbus_message_unref(msg);
566 * wpas_dbus_signal_wps_event_success - Signals Success WPS event
567 * @wpa_s: %wpa_supplicant network interface data
569 * Sends Event dbus signal with name "success" and empty dict as arguments
571 void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
575 DBusMessageIter iter, dict_iter;
576 struct wpas_dbus_priv *iface;
577 char *key = "success";
579 iface = wpa_s->global->dbus;
581 /* Do nothing if the control interface is not turned on */
582 if (iface == NULL || !wpa_s->dbus_new_path)
585 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
586 WPAS_DBUS_NEW_IFACE_WPS, "Event");
590 dbus_message_iter_init_append(msg, &iter);
592 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
593 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
594 !wpa_dbus_dict_close_write(&iter, &dict_iter))
595 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
597 dbus_connection_send(iface->con, msg, NULL);
599 dbus_message_unref(msg);
604 * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
605 * @wpa_s: %wpa_supplicant network interface data
607 * Sends Event dbus signal with name "fail" and dictionary containing
608 * "msg field with fail message number (int32) as arguments
610 void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
611 struct wps_event_fail *fail)
615 DBusMessageIter iter, dict_iter;
616 struct wpas_dbus_priv *iface;
619 iface = wpa_s->global->dbus;
621 /* Do nothing if the control interface is not turned on */
622 if (iface == NULL || !wpa_s->dbus_new_path)
625 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
626 WPAS_DBUS_NEW_IFACE_WPS, "Event");
630 dbus_message_iter_init_append(msg, &iter);
632 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
633 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
634 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
635 !wpa_dbus_dict_close_write(&iter, &dict_iter))
636 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
638 dbus_connection_send(iface->con, msg, NULL);
640 dbus_message_unref(msg);
645 * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
646 * @wpa_s: %wpa_supplicant network interface data
648 * Sends Event dbus signal with name "m2d" and dictionary containing
649 * fields of wps_event_m2d structure.
651 void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
652 struct wps_event_m2d *m2d)
656 DBusMessageIter iter, dict_iter;
657 struct wpas_dbus_priv *iface;
660 iface = wpa_s->global->dbus;
662 /* Do nothing if the control interface is not turned on */
663 if (iface == NULL || !wpa_s->dbus_new_path)
666 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
667 WPAS_DBUS_NEW_IFACE_WPS, "Event");
671 dbus_message_iter_init_append(msg, &iter);
673 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
674 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
675 !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
676 m2d->config_methods) ||
677 !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
678 (const char *) m2d->manufacturer,
679 m2d->manufacturer_len) ||
680 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
681 (const char *) m2d->model_name,
682 m2d->model_name_len) ||
683 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
684 (const char *) m2d->model_number,
685 m2d->model_number_len) ||
686 !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
689 m2d->serial_number_len) ||
690 !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
691 (const char *) m2d->dev_name,
692 m2d->dev_name_len) ||
693 !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
695 m2d->primary_dev_type, 8) ||
696 !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
697 m2d->config_error) ||
698 !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
699 m2d->dev_password_id) ||
700 !wpa_dbus_dict_close_write(&iter, &dict_iter))
701 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
703 dbus_connection_send(iface->con, msg, NULL);
705 dbus_message_unref(msg);
710 * wpas_dbus_signal_wps_cred - Signals new credentials
711 * @wpa_s: %wpa_supplicant network interface data
713 * Sends signal with credentials in directory argument
715 void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
716 const struct wps_credential *cred)
719 DBusMessageIter iter, dict_iter;
720 struct wpas_dbus_priv *iface;
721 char *auth_type[5]; /* we have five possible authentication types */
723 char *encr_type[3]; /* we have three possible encryption types */
726 iface = wpa_s->global->dbus;
728 /* Do nothing if the control interface is not turned on */
729 if (iface == NULL || !wpa_s->dbus_new_path)
732 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
733 WPAS_DBUS_NEW_IFACE_WPS,
738 dbus_message_iter_init_append(msg, &iter);
739 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
742 if (cred->auth_type & WPS_AUTH_OPEN)
743 auth_type[at_num++] = "open";
744 if (cred->auth_type & WPS_AUTH_WPAPSK)
745 auth_type[at_num++] = "wpa-psk";
746 if (cred->auth_type & WPS_AUTH_WPA)
747 auth_type[at_num++] = "wpa-eap";
748 if (cred->auth_type & WPS_AUTH_WPA2)
749 auth_type[at_num++] = "wpa2-eap";
750 if (cred->auth_type & WPS_AUTH_WPA2PSK)
751 auth_type[at_num++] = "wpa2-psk";
753 if (cred->encr_type & WPS_ENCR_NONE)
754 encr_type[et_num++] = "none";
755 if (cred->encr_type & WPS_ENCR_TKIP)
756 encr_type[et_num++] = "tkip";
757 if (cred->encr_type & WPS_ENCR_AES)
758 encr_type[et_num++] = "aes";
760 if ((wpa_s->current_ssid &&
761 !wpa_dbus_dict_append_byte_array(
763 (const char *) wpa_s->current_ssid->bssid, ETH_ALEN)) ||
764 !wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
765 (const char *) cred->ssid,
767 !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
768 (const char **) auth_type,
770 !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
771 (const char **) encr_type,
773 !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
774 (const char *) cred->key,
776 !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
778 !wpa_dbus_dict_close_write(&iter, &dict_iter))
781 dbus_connection_send(iface->con, msg, NULL);
784 dbus_message_unref(msg);
787 #endif /* CONFIG_WPS */
789 void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
790 int depth, const char *subject,
791 const char *altsubject[],
793 const char *cert_hash,
794 const struct wpabuf *cert)
796 struct wpas_dbus_priv *iface;
798 DBusMessageIter iter, dict_iter;
800 iface = wpa_s->global->dbus;
802 /* Do nothing if the control interface is not turned on */
803 if (iface == NULL || !wpa_s->dbus_new_path)
806 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
807 WPAS_DBUS_NEW_IFACE_INTERFACE,
812 dbus_message_iter_init_append(msg, &iter);
813 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
814 !wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
815 !wpa_dbus_dict_append_string(&dict_iter, "subject", subject) ||
816 (altsubject && num_altsubject &&
817 !wpa_dbus_dict_append_string_array(&dict_iter, "altsubject",
818 altsubject, num_altsubject)) ||
820 !wpa_dbus_dict_append_string(&dict_iter, "cert_hash",
823 !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
825 wpabuf_len(cert))) ||
826 !wpa_dbus_dict_close_write(&iter, &dict_iter))
827 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
829 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 */
844 if (iface == NULL || !wpa_s->dbus_new_path)
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) ||
856 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
858 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
860 dbus_connection_send(iface->con, msg, NULL);
861 dbus_message_unref(msg);
866 * wpas_dbus_signal_sta - Send a station related event signal
867 * @wpa_s: %wpa_supplicant network interface data
868 * @sta: station mac address
869 * @sig_name: signal name - StaAuthorized or StaDeauthorized
871 * Notify listeners about event related with station
873 static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
874 const u8 *sta, const char *sig_name)
876 struct wpas_dbus_priv *iface;
878 char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
881 os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
884 iface = wpa_s->global->dbus;
886 /* Do nothing if the control interface is not turned on */
887 if (iface == NULL || !wpa_s->dbus_new_path)
890 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
891 WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
895 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
897 dbus_connection_send(iface->con, msg, NULL);
899 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
900 dbus_message_unref(msg);
902 wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
908 * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
909 * @wpa_s: %wpa_supplicant network interface data
910 * @sta: station mac address
912 * Notify listeners a new station has been authorized
914 void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
917 wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
922 * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
923 * @wpa_s: %wpa_supplicant network interface data
924 * @sta: station mac address
926 * Notify listeners a station has been deauthorized
928 void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
931 wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
938 * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
939 * @wpa_s: %wpa_supplicant network interface data
940 * @role: role of this device (client or GO)
941 * Sends signal with i/f name and role as string arguments
943 void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
947 DBusMessageIter iter, dict_iter;
948 struct wpas_dbus_priv *iface = wpa_s->global->dbus;
949 struct wpa_supplicant *parent;
951 /* Do nothing if the control interface is not turned on */
955 parent = wpa_s->parent;
956 if (parent->p2p_mgmt)
957 parent = parent->parent;
959 if (!wpa_s->dbus_groupobj_path || !wpa_s->dbus_new_path ||
960 !parent->dbus_new_path)
963 msg = dbus_message_new_signal(parent->dbus_new_path,
964 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
969 dbus_message_iter_init_append(msg, &iter);
970 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
971 !wpa_dbus_dict_append_object_path(&dict_iter,
973 wpa_s->dbus_new_path) ||
974 !wpa_dbus_dict_append_string(&dict_iter, "role", role) ||
975 !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
976 wpa_s->dbus_groupobj_path) ||
977 !wpa_dbus_dict_close_write(&iter, &dict_iter))
978 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
980 dbus_connection_send(iface->con, msg, NULL);
981 dbus_message_unref(msg);
986 * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
988 * @dev_addr - who sent the request or responded to our request.
989 * @request - Will be 1 if request, 0 for response.
990 * @status - valid only in case of response
991 * @config_methods - wps config methods
992 * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
994 * Sends following provision discovery related events:
995 * ProvisionDiscoveryRequestDisplayPin
996 * ProvisionDiscoveryResponseDisplayPin
997 * ProvisionDiscoveryRequestEnterPin
998 * ProvisionDiscoveryResponseEnterPin
999 * ProvisionDiscoveryPBCRequest
1000 * ProvisionDiscoveryPBCResponse
1003 * ProvisionDiscoveryFailure (timeout case)
1005 void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
1006 const u8 *dev_addr, int request,
1007 enum p2p_prov_disc_status status,
1009 unsigned int generated_pin)
1012 DBusMessageIter iter;
1013 struct wpas_dbus_priv *iface;
1016 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1018 char pin[9], *p_pin = NULL;
1020 iface = wpa_s->global->dbus;
1022 /* Do nothing if the control interface is not turned on */
1026 if (wpa_s->p2p_mgmt)
1027 wpa_s = wpa_s->parent;
1028 if (!wpa_s->dbus_new_path)
1031 if (request || !status) {
1032 if (config_methods & WPS_CONFIG_DISPLAY)
1034 "ProvisionDiscoveryRequestDisplayPin" :
1035 "ProvisionDiscoveryResponseEnterPin";
1036 else if (config_methods & WPS_CONFIG_KEYPAD)
1038 "ProvisionDiscoveryRequestEnterPin" :
1039 "ProvisionDiscoveryResponseDisplayPin";
1040 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1041 _signal = request ? "ProvisionDiscoveryPBCRequest" :
1042 "ProvisionDiscoveryPBCResponse";
1044 return; /* Unknown or un-supported method */
1046 /* Explicit check for failure response */
1047 _signal = "ProvisionDiscoveryFailure";
1050 add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
1051 (!request && !status &&
1052 (config_methods & WPS_CONFIG_KEYPAD)));
1055 os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
1059 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1060 WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
1064 /* Check if this is a known peer */
1065 if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
1068 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1069 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1071 wpa_s->dbus_new_path, MAC2STR(dev_addr));
1073 path = peer_obj_path;
1075 dbus_message_iter_init_append(msg, &iter);
1077 if (!dbus_message_iter_append_basic(&iter,
1078 DBUS_TYPE_OBJECT_PATH,
1082 if (!request && status)
1083 /* Attach status to ProvisionDiscoveryFailure */
1084 error_ret = !dbus_message_iter_append_basic(&iter,
1088 error_ret = (add_pin &&
1089 !dbus_message_iter_append_basic(&iter,
1095 dbus_connection_send(iface->con, msg, NULL);
1097 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1099 dbus_message_unref(msg);
1104 * wpas_dbus_signal_p2p_go_neg_req - Signal P2P GO Negotiation Request RX
1105 * @wpa_s: %wpa_supplicant network interface data
1106 * @src: Source address of the message triggering this notification
1107 * @dev_passwd_id: WPS Device Password Id
1108 * @go_intent: Peer's GO Intent value
1110 * Sends signal to notify that a peer P2P Device is requesting group owner
1111 * negotiation with us.
1113 void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
1114 const u8 *src, u16 dev_passwd_id,
1118 DBusMessageIter iter;
1119 struct wpas_dbus_priv *iface;
1120 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1122 iface = wpa_s->global->dbus;
1124 /* Do nothing if the control interface is not turned on */
1128 if (wpa_s->p2p_mgmt)
1129 wpa_s = wpa_s->parent;
1130 if (!wpa_s->dbus_new_path)
1133 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1134 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1135 wpa_s->dbus_new_path, MAC2STR(src));
1136 path = peer_obj_path;
1138 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1139 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1140 "GONegotiationRequest");
1144 dbus_message_iter_init_append(msg, &iter);
1146 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1148 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
1150 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE,
1152 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1154 dbus_connection_send(iface->con, msg, NULL);
1156 dbus_message_unref(msg);
1160 static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
1161 const struct wpa_ssid *ssid,
1162 char *group_obj_path)
1166 if (!wpa_s->dbus_new_path ||
1167 os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
1170 os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
1171 group_name[2] = '\0';
1173 os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1174 "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
1175 wpa_s->dbus_new_path, group_name);
1181 struct group_changed_data {
1182 struct wpa_supplicant *wpa_s;
1183 struct p2p_peer_info *info;
1187 static int match_group_where_peer_is_client(struct p2p_group *group,
1190 struct group_changed_data *data = user_data;
1191 const struct p2p_group_config *cfg;
1192 struct wpa_supplicant *wpa_s_go;
1194 if (!p2p_group_is_client_connected(group, data->info->p2p_device_addr))
1197 cfg = p2p_group_get_config(group);
1199 wpa_s_go = wpas_get_p2p_go_iface(data->wpa_s, cfg->ssid,
1201 if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
1202 wpas_dbus_signal_peer_groups_changed(
1203 data->wpa_s->parent, data->info->p2p_device_addr);
1211 static void signal_peer_groups_changed(struct p2p_peer_info *info,
1214 struct group_changed_data *data = user_data;
1215 struct wpa_supplicant *wpa_s_go;
1217 wpa_s_go = wpas_get_p2p_client_iface(data->wpa_s,
1218 info->p2p_device_addr);
1219 if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
1220 wpas_dbus_signal_peer_groups_changed(data->wpa_s->parent,
1221 info->p2p_device_addr);
1226 p2p_loop_on_all_groups(data->wpa_s->global->p2p,
1227 match_group_where_peer_is_client, data);
1232 static void peer_groups_changed(struct wpa_supplicant *wpa_s)
1234 struct group_changed_data data;
1236 os_memset(&data, 0, sizeof(data));
1239 p2p_loop_on_known_peers(wpa_s->global->p2p,
1240 signal_peer_groups_changed, &data);
1245 * wpas_dbus_signal_p2p_group_started - Signals P2P group has
1246 * started. Emitted when a group is successfully started
1247 * irrespective of the role (client/GO) of the current device
1249 * @wpa_s: %wpa_supplicant network interface data
1250 * @ssid: SSID object
1251 * @client: this device is P2P client
1252 * @network_id: network id of the group started, use instead of ssid->id
1253 * to account for persistent groups
1255 void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
1256 const struct wpa_ssid *ssid,
1257 int client, int network_id)
1260 DBusMessageIter iter, dict_iter;
1261 struct wpas_dbus_priv *iface;
1262 struct wpa_supplicant *parent;
1264 parent = wpa_s->parent;
1265 if (parent->p2p_mgmt)
1266 parent = parent->parent;
1268 iface = parent->global->dbus;
1270 /* Do nothing if the control interface is not turned on */
1271 if (iface == NULL || !parent->dbus_new_path || !wpa_s->dbus_new_path)
1274 if (wpa_s->dbus_groupobj_path == NULL)
1277 /* New interface has been created for this group */
1278 msg = dbus_message_new_signal(parent->dbus_new_path,
1279 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1284 dbus_message_iter_init_append(msg, &iter);
1286 * In case the device supports creating a separate interface the
1287 * DBus client will need to know the object path for the interface
1288 * object this group was created on, so include it here.
1290 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1291 !wpa_dbus_dict_append_object_path(&dict_iter,
1293 wpa_s->dbus_new_path) ||
1294 !wpa_dbus_dict_append_string(&dict_iter, "role",
1295 client ? "client" : "GO") ||
1296 !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
1297 wpa_s->dbus_groupobj_path) ||
1298 !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
1299 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1301 dbus_connection_send(iface->con, msg, NULL);
1303 peer_groups_changed(wpa_s);
1305 dbus_message_unref(msg);
1311 * Method to emit GONegotiation Success or Failure signals based
1313 * @status: Status of the GO neg request. 0 for success, other for errors.
1315 void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
1316 struct p2p_go_neg_results *res)
1319 DBusMessageIter iter, dict_iter;
1320 DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
1321 struct wpas_dbus_priv *iface;
1322 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1323 dbus_int32_t freqs[P2P_MAX_CHANNELS];
1324 dbus_int32_t *f_array = freqs;
1327 iface = wpa_s->global->dbus;
1329 if (wpa_s->p2p_mgmt)
1330 wpa_s = wpa_s->parent;
1332 os_memset(freqs, 0, sizeof(freqs));
1333 /* Do nothing if the control interface is not turned on */
1334 if (iface == NULL || !wpa_s->dbus_new_path)
1337 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1338 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1339 wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
1340 path = peer_obj_path;
1342 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1343 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1344 res->status ? "GONegotiationFailure" :
1345 "GONegotiationSuccess");
1349 dbus_message_iter_init_append(msg, &iter);
1350 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1351 !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1353 !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
1358 int freq_list_num = 0;
1360 if ((res->role_go &&
1361 !wpa_dbus_dict_append_string(&dict_iter, "passphrase",
1362 res->passphrase)) ||
1363 !wpa_dbus_dict_append_string(&dict_iter, "role_go",
1364 res->role_go ? "GO" :
1366 !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
1368 !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
1369 (const char *) res->ssid,
1371 !wpa_dbus_dict_append_byte_array(&dict_iter,
1374 res->peer_device_addr,
1376 !wpa_dbus_dict_append_byte_array(&dict_iter,
1377 "peer_interface_addr",
1379 res->peer_interface_addr,
1381 !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
1382 p2p_wps_method_text(
1386 for (i = 0; i < P2P_MAX_CHANNELS; i++) {
1387 if (res->freq_list[i]) {
1388 freqs[i] = res->freq_list[i];
1393 if (!wpa_dbus_dict_begin_array(&dict_iter,
1395 DBUS_TYPE_INT32_AS_STRING,
1398 &iter_dict_array) ||
1399 !dbus_message_iter_append_fixed_array(&iter_dict_array,
1403 !wpa_dbus_dict_end_array(&dict_iter,
1406 &iter_dict_array) ||
1407 !wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
1408 res->persistent_group) ||
1409 !wpa_dbus_dict_append_uint32(&dict_iter,
1410 "peer_config_timeout",
1411 res->peer_config_timeout))
1415 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1418 dbus_connection_send(iface->con, msg, NULL);
1420 dbus_message_unref(msg);
1426 * Method to emit Invitation Result signal based on status and
1428 * @status: Status of the Invite request. 0 for success, other
1430 * @bssid : Basic Service Set Identifier
1432 void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
1433 int status, const u8 *bssid)
1436 DBusMessageIter iter, dict_iter;
1437 struct wpas_dbus_priv *iface;
1439 wpa_printf(MSG_DEBUG, "%s", __func__);
1441 iface = wpa_s->global->dbus;
1442 /* Do nothing if the control interface is not turned on */
1446 if (wpa_s->p2p_mgmt)
1447 wpa_s = wpa_s->parent;
1448 if (!wpa_s->dbus_new_path)
1451 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1452 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1453 "InvitationResult");
1458 dbus_message_iter_init_append(msg, &iter);
1459 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1460 !wpa_dbus_dict_append_int32(&dict_iter, "status", status) ||
1462 !wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
1463 (const char *) bssid,
1465 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1466 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1468 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;
1489 struct wpa_supplicant *parent;
1491 iface = wpa_s->global->dbus;
1493 /* Do nothing if the control interface is not turned on */
1497 if (!wpa_s->dbus_groupobj_path)
1500 parent = wpa_s->parent;
1501 if (parent->p2p_mgmt)
1502 parent = parent->parent;
1503 if (!parent->dbus_new_path)
1506 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1507 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1509 parent->dbus_new_path, MAC2STR(peer_addr));
1511 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1512 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1517 dbus_message_iter_init_append(msg, &iter);
1518 path = peer_obj_path;
1519 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1521 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1523 dbus_connection_send(iface->con, msg, NULL);
1524 wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
1526 dbus_message_unref(msg);
1532 * Method to emit a signal for a peer disconnecting the group.
1533 * The signal will carry path to the group member object
1534 * constructed using the P2P Device Address of the peer.
1536 * @wpa_s: %wpa_supplicant network interface data
1537 * @peer_addr: P2P Device Address of the peer joining the group
1539 void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
1540 const u8 *peer_addr)
1542 struct wpas_dbus_priv *iface;
1544 DBusMessageIter iter;
1545 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1546 struct wpa_supplicant *parent;
1548 iface = wpa_s->global->dbus;
1550 /* Do nothing if the control interface is not turned on */
1554 if (!wpa_s->dbus_groupobj_path)
1557 parent = wpa_s->parent;
1558 if (parent->p2p_mgmt)
1559 parent = parent->parent;
1560 if (!parent->dbus_new_path)
1563 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1564 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1566 parent->dbus_new_path, MAC2STR(peer_addr));
1568 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1569 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1570 "PeerDisconnected");
1574 dbus_message_iter_init_append(msg, &iter);
1575 path = peer_obj_path;
1576 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1578 wpa_printf(MSG_ERROR,
1579 "dbus: Failed to construct PeerDisconnected signal");
1581 dbus_connection_send(iface->con, msg, NULL);
1582 wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
1584 dbus_message_unref(msg);
1590 * Method to emit a signal for a service discovery request.
1591 * The signal will carry station address, frequency, dialog token,
1592 * update indicator and it tlvs
1594 * @wpa_s: %wpa_supplicant network interface data
1595 * @sa: station addr (p2p i/f) of the peer
1596 * @dialog_token: service discovery request dialog token
1597 * @update_indic: service discovery request update indicator
1598 * @tlvs: service discovery request genrated byte array of tlvs
1599 * @tlvs_len: service discovery request tlvs length
1601 void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
1602 int freq, const u8 *sa, u8 dialog_token,
1603 u16 update_indic, const u8 *tlvs,
1607 DBusMessageIter iter, dict_iter;
1608 struct wpas_dbus_priv *iface;
1609 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1611 iface = wpa_s->global->dbus;
1613 /* Do nothing if the control interface is not turned on */
1617 if (wpa_s->p2p_mgmt)
1618 wpa_s = wpa_s->parent;
1619 if (!wpa_s->dbus_new_path)
1622 /* Check if this is a known peer */
1623 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1626 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1627 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1628 "ServiceDiscoveryRequest");
1632 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1633 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1634 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1636 path = peer_obj_path;
1638 dbus_message_iter_init_append(msg, &iter);
1639 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1640 !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1642 !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
1643 !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
1645 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1647 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1648 (const char *) tlvs,
1650 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1651 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1653 dbus_connection_send(iface->con, msg, NULL);
1654 dbus_message_unref(msg);
1660 * Method to emit a signal for a service discovery response.
1661 * The signal will carry station address, update indicator and it
1664 * @wpa_s: %wpa_supplicant network interface data
1665 * @sa: station addr (p2p i/f) of the peer
1666 * @update_indic: service discovery request update indicator
1667 * @tlvs: service discovery request genrated byte array of tlvs
1668 * @tlvs_len: service discovery request tlvs length
1670 void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
1671 const u8 *sa, u16 update_indic,
1672 const u8 *tlvs, size_t tlvs_len)
1675 DBusMessageIter iter, dict_iter;
1676 struct wpas_dbus_priv *iface;
1677 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1679 iface = wpa_s->global->dbus;
1681 /* Do nothing if the control interface is not turned on */
1685 if (wpa_s->p2p_mgmt)
1686 wpa_s = wpa_s->parent;
1687 if (!wpa_s->dbus_new_path)
1690 /* Check if this is a known peer */
1691 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1694 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1695 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1696 "ServiceDiscoveryResponse");
1700 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1701 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1702 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1704 path = peer_obj_path;
1706 dbus_message_iter_init_append(msg, &iter);
1707 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1708 !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1710 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1712 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1713 (const char *) tlvs,
1715 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1716 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1718 dbus_connection_send(iface->con, msg, NULL);
1719 dbus_message_unref(msg);
1724 * wpas_dbus_signal_persistent_group - Send a persistent group related
1726 * @wpa_s: %wpa_supplicant network interface data
1727 * @id: new persistent group id
1728 * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
1729 * @properties: determines if add second argument with object properties
1731 * Notify listeners about an event related to persistent groups.
1733 static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
1734 int id, const char *sig_name,
1737 struct wpas_dbus_priv *iface;
1739 DBusMessageIter iter;
1740 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1742 iface = wpa_s->global->dbus;
1744 /* Do nothing if the control interface is not turned on */
1748 if (wpa_s->p2p_mgmt)
1749 wpa_s = wpa_s->parent;
1750 if (!wpa_s->dbus_new_path)
1753 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1754 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
1755 wpa_s->dbus_new_path, id);
1757 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1758 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1763 dbus_message_iter_init_append(msg, &iter);
1764 path = pgrp_obj_path;
1765 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1768 !wpa_dbus_get_object_properties(
1769 iface, pgrp_obj_path,
1770 WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter)))
1771 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1773 dbus_connection_send(iface->con, msg, NULL);
1775 dbus_message_unref(msg);
1780 * wpas_dbus_signal_persistent_group_added - Send a persistent_group
1782 * @wpa_s: %wpa_supplicant network interface data
1783 * @id: new persistent group id
1785 * Notify listeners about addition of a new persistent group.
1787 static void wpas_dbus_signal_persistent_group_added(
1788 struct wpa_supplicant *wpa_s, int id)
1790 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
1796 * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
1798 * @wpa_s: %wpa_supplicant network interface data
1799 * @id: persistent group id
1801 * Notify listeners about removal of a persistent group.
1803 static void wpas_dbus_signal_persistent_group_removed(
1804 struct wpa_supplicant *wpa_s, int id)
1806 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
1812 * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
1813 * @wpa_s: %wpa_supplicant network interface data
1815 * Sends Event dbus signal with name "fail" and dictionary containing
1816 * "msg" field with fail message number (int32) as arguments
1818 void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
1819 struct wps_event_fail *fail)
1823 DBusMessageIter iter, dict_iter;
1824 struct wpas_dbus_priv *iface;
1827 iface = wpa_s->global->dbus;
1829 /* Do nothing if the control interface is not turned on */
1833 if (wpa_s->p2p_mgmt)
1834 wpa_s = wpa_s->parent;
1836 if (!wpa_s->dbus_new_path)
1838 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1839 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1844 dbus_message_iter_init_append(msg, &iter);
1846 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
1847 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1848 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
1849 !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
1850 fail->config_error) ||
1851 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1852 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1854 dbus_connection_send(iface->con, msg, NULL);
1856 dbus_message_unref(msg);
1859 #endif /* CONFIG_P2P */
1863 * wpas_dbus_signal_prop_changed - Signals change of property
1864 * @wpa_s: %wpa_supplicant network interface data
1865 * @property: indicates which property has changed
1867 * Sends PropertyChanged signals with path, interface and arguments
1868 * depending on which property has changed.
1870 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
1871 enum wpas_dbus_prop property)
1876 if (wpa_s->dbus_new_path == NULL)
1877 return; /* Skip signal since D-Bus setup is not yet ready */
1881 case WPAS_DBUS_PROP_AP_SCAN:
1884 case WPAS_DBUS_PROP_SCANNING:
1887 case WPAS_DBUS_PROP_STATE:
1890 case WPAS_DBUS_PROP_CURRENT_BSS:
1891 prop = "CurrentBSS";
1893 case WPAS_DBUS_PROP_CURRENT_NETWORK:
1894 prop = "CurrentNetwork";
1896 case WPAS_DBUS_PROP_BSSS:
1899 case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
1900 prop = "CurrentAuthMode";
1902 case WPAS_DBUS_PROP_DISCONNECT_REASON:
1903 prop = "DisconnectReason";
1907 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1908 __func__, property);
1912 wpa_dbus_mark_property_changed(wpa_s->global->dbus,
1913 wpa_s->dbus_new_path,
1914 WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
1916 wpa_dbus_flush_object_changed_properties(
1917 wpa_s->global->dbus->con, wpa_s->dbus_new_path);
1923 * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
1924 * @wpa_s: %wpa_supplicant network interface data
1925 * @property: indicates which property has changed
1926 * @id: unique BSS identifier
1928 * Sends PropertyChanged signals with path, interface, and arguments depending
1929 * on which property has changed.
1931 void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
1932 enum wpas_dbus_bss_prop property,
1935 char path[WPAS_DBUS_OBJECT_PATH_MAX];
1938 if (!wpa_s->dbus_new_path)
1942 case WPAS_DBUS_BSS_PROP_SIGNAL:
1945 case WPAS_DBUS_BSS_PROP_FREQ:
1948 case WPAS_DBUS_BSS_PROP_MODE:
1951 case WPAS_DBUS_BSS_PROP_PRIVACY:
1954 case WPAS_DBUS_BSS_PROP_RATES:
1957 case WPAS_DBUS_BSS_PROP_WPA:
1960 case WPAS_DBUS_BSS_PROP_RSN:
1963 case WPAS_DBUS_BSS_PROP_WPS:
1966 case WPAS_DBUS_BSS_PROP_IES:
1969 case WPAS_DBUS_BSS_PROP_AGE:
1973 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1974 __func__, property);
1978 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1979 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1980 wpa_s->dbus_new_path, id);
1982 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
1983 WPAS_DBUS_NEW_IFACE_BSS, prop);
1988 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
1989 * @global: wpa_global structure
1991 * Sends PropertyChanged signals informing that debug level has changed.
1993 void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
1995 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1996 WPAS_DBUS_NEW_INTERFACE,
2002 * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
2003 * @global: wpa_global structure
2005 * Sends PropertyChanged signals informing that debug timestamp has changed.
2007 void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
2009 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
2010 WPAS_DBUS_NEW_INTERFACE,
2016 * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
2017 * @global: wpa_global structure
2019 * Sends PropertyChanged signals informing that debug show_keys has changed.
2021 void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
2023 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
2024 WPAS_DBUS_NEW_INTERFACE,
2029 static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
2031 WPADBusArgumentFreeFunction priv_free,
2032 const struct wpa_dbus_method_desc *methods,
2033 const struct wpa_dbus_property_desc *properties,
2034 const struct wpa_dbus_signal_desc *signals)
2038 obj_desc->user_data = priv;
2039 obj_desc->user_data_free_func = priv_free;
2040 obj_desc->methods = methods;
2041 obj_desc->properties = properties;
2042 obj_desc->signals = signals;
2044 for (n = 0; properties && properties->dbus_property; properties++)
2047 obj_desc->prop_changed_flags = os_zalloc(n);
2048 if (!obj_desc->prop_changed_flags)
2049 wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
2054 static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
2055 { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
2056 (WPADBusMethodHandler) wpas_dbus_handler_create_interface,
2058 { "args", "a{sv}", ARG_IN },
2059 { "path", "o", ARG_OUT },
2063 { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
2064 (WPADBusMethodHandler) wpas_dbus_handler_remove_interface,
2066 { "path", "o", ARG_IN },
2070 { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
2071 (WPADBusMethodHandler) wpas_dbus_handler_get_interface,
2073 { "ifname", "s", ARG_IN },
2074 { "path", "o", ARG_OUT },
2078 { NULL, NULL, NULL, { END_ARGS } }
2081 static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
2082 { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
2083 wpas_dbus_getter_debug_level,
2084 wpas_dbus_setter_debug_level
2086 { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
2087 wpas_dbus_getter_debug_timestamp,
2088 wpas_dbus_setter_debug_timestamp
2090 { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
2091 wpas_dbus_getter_debug_show_keys,
2092 wpas_dbus_setter_debug_show_keys
2094 { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
2095 wpas_dbus_getter_interfaces,
2098 { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
2099 wpas_dbus_getter_eap_methods,
2102 { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
2103 wpas_dbus_getter_global_capabilities,
2106 #ifdef CONFIG_WIFI_DISPLAY
2107 { "WFDIEs", WPAS_DBUS_NEW_INTERFACE, "ay",
2108 wpas_dbus_getter_global_wfd_ies,
2109 wpas_dbus_setter_global_wfd_ies
2111 #endif /* CONFIG_WIFI_DISPLAY */
2112 { NULL, NULL, NULL, NULL, NULL }
2115 static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
2116 { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
2118 { "path", "o", ARG_OUT },
2119 { "properties", "a{sv}", ARG_OUT },
2123 { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
2125 { "path", "o", ARG_OUT },
2129 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2130 { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
2132 { "properties", "a{sv}", ARG_OUT },
2136 { NULL, NULL, { END_ARGS } }
2141 * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
2142 * @global: Pointer to global data from wpa_supplicant_init()
2143 * Returns: 0 on success or -1 on failure
2145 * Initialize the dbus control interface for wpa_supplicantand and start
2146 * receiving commands from external programs over the bus.
2148 int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
2150 struct wpa_dbus_object_desc *obj_desc;
2153 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2155 wpa_printf(MSG_ERROR,
2156 "Not enough memory to create object description");
2160 wpas_dbus_register(obj_desc, priv->global, NULL,
2161 wpas_dbus_global_methods,
2162 wpas_dbus_global_properties,
2163 wpas_dbus_global_signals);
2165 wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
2166 WPAS_DBUS_NEW_PATH);
2167 ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
2168 WPAS_DBUS_NEW_SERVICE,
2171 free_dbus_object_desc(obj_desc);
2173 priv->dbus_new_initialized = 1;
2180 * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
2182 * @iface: Pointer to dbus private data from wpas_dbus_init()
2184 * Deinitialize the dbus control interface that was initialized with
2185 * wpas_dbus_ctrl_iface_init().
2187 void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
2189 if (!iface->dbus_new_initialized)
2191 wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
2192 WPAS_DBUS_NEW_PATH);
2193 dbus_connection_unregister_object_path(iface->con,
2194 WPAS_DBUS_NEW_PATH);
2198 static void wpa_dbus_free(void *ptr)
2204 static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
2205 { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
2206 wpas_dbus_getter_network_properties,
2207 wpas_dbus_setter_network_properties
2209 { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
2210 wpas_dbus_getter_enabled,
2211 wpas_dbus_setter_enabled
2213 { NULL, NULL, NULL, NULL, NULL }
2217 static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
2218 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2219 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
2221 { "properties", "a{sv}", ARG_OUT },
2225 { NULL, NULL, { END_ARGS } }
2230 * wpas_dbus_register_network - Register a configured network with dbus
2231 * @wpa_s: wpa_supplicant interface structure
2232 * @ssid: network configuration data
2233 * Returns: 0 on success, -1 on failure
2235 * Registers network representing object with dbus
2237 int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
2238 struct wpa_ssid *ssid)
2240 struct wpas_dbus_priv *ctrl_iface;
2241 struct wpa_dbus_object_desc *obj_desc;
2242 struct network_handler_args *arg;
2243 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2247 * If it is a persistent group register it as such.
2248 * This is to handle cases where an interface is being initialized
2249 * with a list of networks read from config.
2251 if (network_is_persistent_group(ssid))
2252 return wpas_dbus_register_persistent_group(wpa_s, ssid);
2253 #endif /* CONFIG_P2P */
2255 /* Do nothing if the control interface is not turned on */
2256 if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
2258 ctrl_iface = wpa_s->global->dbus;
2259 if (ctrl_iface == NULL)
2262 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2263 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2264 wpa_s->dbus_new_path, ssid->id);
2266 wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
2268 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2270 wpa_printf(MSG_ERROR,
2271 "Not enough memory to create object description");
2275 /* allocate memory for handlers arguments */
2276 arg = os_zalloc(sizeof(struct network_handler_args));
2278 wpa_printf(MSG_ERROR,
2279 "Not enough memory to create arguments for method");
2286 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2287 wpas_dbus_network_properties,
2288 wpas_dbus_network_signals);
2290 if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
2291 wpa_s->ifname, obj_desc))
2294 wpas_dbus_signal_network_added(wpa_s, ssid->id);
2299 free_dbus_object_desc(obj_desc);
2305 * wpas_dbus_unregister_network - Unregister a configured network from dbus
2306 * @wpa_s: wpa_supplicant interface structure
2308 * Returns: 0 on success, -1 on failure
2310 * Unregisters network representing object from dbus
2312 int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
2314 struct wpas_dbus_priv *ctrl_iface;
2315 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2318 struct wpa_ssid *ssid;
2320 ssid = wpa_config_get_network(wpa_s->conf, nid);
2322 /* If it is a persistent group unregister it as such */
2323 if (ssid && network_is_persistent_group(ssid))
2324 return wpas_dbus_unregister_persistent_group(wpa_s, nid);
2325 #endif /* CONFIG_P2P */
2327 /* Do nothing if the control interface is not turned on */
2328 if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
2330 ctrl_iface = wpa_s->global->dbus;
2331 if (ctrl_iface == NULL)
2334 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2335 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2336 wpa_s->dbus_new_path, nid);
2338 wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
2340 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
2343 wpas_dbus_signal_network_removed(wpa_s, nid);
2349 static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
2350 { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2351 wpas_dbus_getter_bss_ssid,
2354 { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2355 wpas_dbus_getter_bss_bssid,
2358 { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
2359 wpas_dbus_getter_bss_privacy,
2362 { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
2363 wpas_dbus_getter_bss_mode,
2366 { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
2367 wpas_dbus_getter_bss_signal,
2370 { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
2371 wpas_dbus_getter_bss_frequency,
2374 { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
2375 wpas_dbus_getter_bss_rates,
2378 { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2379 wpas_dbus_getter_bss_wpa,
2382 { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2383 wpas_dbus_getter_bss_rsn,
2386 { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2387 wpas_dbus_getter_bss_wps,
2390 { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2391 wpas_dbus_getter_bss_ies,
2394 { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
2395 wpas_dbus_getter_bss_age,
2398 { NULL, NULL, NULL, NULL, NULL }
2402 static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
2403 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2404 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
2406 { "properties", "a{sv}", ARG_OUT },
2410 { NULL, NULL, { END_ARGS } }
2415 * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
2416 * @wpa_s: wpa_supplicant interface structure
2417 * @bssid: scanned network bssid
2418 * @id: unique BSS identifier
2419 * Returns: 0 on success, -1 on failure
2421 * Unregisters BSS representing object from dbus
2423 int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
2424 u8 bssid[ETH_ALEN], unsigned int id)
2426 struct wpas_dbus_priv *ctrl_iface;
2427 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2429 /* Do nothing if the control interface is not turned on */
2430 if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
2432 ctrl_iface = wpa_s->global->dbus;
2433 if (ctrl_iface == NULL)
2436 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2437 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2438 wpa_s->dbus_new_path, id);
2440 wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
2442 if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
2443 wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
2448 wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
2449 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2456 * wpas_dbus_register_bss - Register a scanned BSS with dbus
2457 * @wpa_s: wpa_supplicant interface structure
2458 * @bssid: scanned network bssid
2459 * @id: unique BSS identifier
2460 * Returns: 0 on success, -1 on failure
2462 * Registers BSS representing object with dbus
2464 int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
2465 u8 bssid[ETH_ALEN], unsigned int id)
2467 struct wpas_dbus_priv *ctrl_iface;
2468 struct wpa_dbus_object_desc *obj_desc;
2469 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2470 struct bss_handler_args *arg;
2472 /* Do nothing if the control interface is not turned on */
2473 if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
2475 ctrl_iface = wpa_s->global->dbus;
2476 if (ctrl_iface == NULL)
2479 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2480 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2481 wpa_s->dbus_new_path, id);
2483 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2485 wpa_printf(MSG_ERROR,
2486 "Not enough memory to create object description");
2490 arg = os_zalloc(sizeof(struct bss_handler_args));
2492 wpa_printf(MSG_ERROR,
2493 "Not enough memory to create arguments for handler");
2499 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2500 wpas_dbus_bss_properties,
2501 wpas_dbus_bss_signals);
2503 wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
2505 if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
2506 wpa_s->ifname, obj_desc)) {
2507 wpa_printf(MSG_ERROR,
2508 "Cannot register BSSID dbus object %s.",
2513 wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
2514 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2519 free_dbus_object_desc(obj_desc);
2524 static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
2525 { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2526 (WPADBusMethodHandler) wpas_dbus_handler_scan,
2528 { "args", "a{sv}", ARG_IN },
2532 { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
2533 (WPADBusMethodHandler) wpas_dbus_handler_signal_poll,
2535 { "args", "a{sv}", ARG_OUT },
2539 { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2540 (WPADBusMethodHandler) wpas_dbus_handler_disconnect,
2545 { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2546 (WPADBusMethodHandler) wpas_dbus_handler_add_network,
2548 { "args", "a{sv}", ARG_IN },
2549 { "path", "o", ARG_OUT },
2553 { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
2554 (WPADBusMethodHandler) wpas_dbus_handler_reassociate,
2559 { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
2560 (WPADBusMethodHandler) wpas_dbus_handler_reattach,
2565 { "Reconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2566 (WPADBusMethodHandler) wpas_dbus_handler_reconnect,
2571 { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2572 (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
2574 { "path", "o", ARG_IN },
2578 { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
2579 (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
2584 { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2585 (WPADBusMethodHandler) wpas_dbus_handler_select_network,
2587 { "path", "o", ARG_IN },
2591 { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
2592 (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
2594 { "path", "o", ARG_IN },
2595 { "field", "s", ARG_IN },
2596 { "value", "s", ARG_IN },
2600 #ifndef CONFIG_NO_CONFIG_BLOBS
2601 { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2602 (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
2604 { "name", "s", ARG_IN },
2605 { "data", "ay", ARG_IN },
2609 { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2610 (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
2612 { "name", "s", ARG_IN },
2613 { "data", "ay", ARG_OUT },
2617 { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2618 (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
2620 { "name", "s", ARG_IN },
2624 #endif /* CONFIG_NO_CONFIG_BLOBS */
2625 { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
2626 (WPADBusMethodHandler)
2627 wpas_dbus_handler_set_pkcs11_engine_and_module_path,
2629 { "pkcs11_engine_path", "s", ARG_IN },
2630 { "pkcs11_module_path", "s", ARG_IN },
2635 { "Start", WPAS_DBUS_NEW_IFACE_WPS,
2636 (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
2638 { "args", "a{sv}", ARG_IN },
2639 { "output", "a{sv}", ARG_OUT },
2643 { "Cancel", WPAS_DBUS_NEW_IFACE_WPS,
2644 (WPADBusMethodHandler) wpas_dbus_handler_wps_cancel,
2649 #endif /* CONFIG_WPS */
2651 { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2652 (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
2654 { "args", "a{sv}", ARG_IN },
2658 { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2659 (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
2664 { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2665 (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
2667 { "timeout", "i", ARG_IN },
2671 { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2672 (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
2674 { "args", "a{sv}", ARG_IN },
2678 { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2679 (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
2681 { "args", "a{sv}", ARG_IN },
2685 { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2686 (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
2688 { "peer", "o", ARG_IN },
2689 { "config_method", "s", ARG_IN },
2693 { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2694 (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
2696 { "args", "a{sv}", ARG_IN },
2697 { "generated_pin", "s", ARG_OUT },
2701 { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2702 (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
2704 { "args", "a{sv}", ARG_IN },
2708 { "Cancel", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2709 (WPADBusMethodHandler) wpas_dbus_handler_p2p_cancel,
2714 { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2715 (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
2717 { "args", "a{sv}", ARG_IN },
2721 { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2722 (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
2727 { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2728 (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
2730 { "peer", "o", ARG_IN },
2734 { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2735 (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
2740 { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2741 (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
2743 { "args", "a{sv}", ARG_IN },
2747 { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2748 (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
2750 { "args", "a{sv}", ARG_IN },
2754 { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2755 (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
2760 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2761 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
2763 { "args", "a{sv}", ARG_IN },
2764 { "ref", "t", ARG_OUT },
2768 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2769 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
2771 { "args", "a{sv}", ARG_IN },
2775 { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2776 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
2778 { "args", "t", ARG_IN },
2782 { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2783 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
2788 { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2789 (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
2791 { "arg", "i", ARG_IN },
2795 { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2796 (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
2798 { "args", "a{sv}", ARG_IN },
2799 { "path", "o", ARG_OUT },
2803 { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2804 (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
2806 { "path", "o", ARG_IN },
2810 { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2811 (WPADBusMethodHandler)
2812 wpas_dbus_handler_remove_all_persistent_groups,
2817 #endif /* CONFIG_P2P */
2818 { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
2819 (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
2821 { "age", "u", ARG_IN },
2826 { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2827 (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
2832 { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
2833 (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
2838 #endif /* CONFIG_AP */
2839 { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
2840 (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
2845 { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
2846 (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
2851 #ifdef CONFIG_AUTOSCAN
2852 { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2853 (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
2855 { "arg", "s", ARG_IN },
2859 #endif /* CONFIG_AUTOSCAN */
2861 { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
2862 (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
2864 { "peer_address", "s", ARG_IN },
2868 { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
2869 (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
2871 { "peer_address", "s", ARG_IN },
2875 { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
2876 (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
2878 { "peer_address", "s", ARG_IN },
2879 { "status", "s", ARG_OUT },
2883 { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
2884 (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
2886 { "peer_address", "s", ARG_IN },
2890 #endif /* CONFIG_TDLS */
2891 { NULL, NULL, NULL, { END_ARGS } }
2894 static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
2895 { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
2896 wpas_dbus_getter_capabilities,
2899 { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2900 wpas_dbus_getter_state,
2903 { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2904 wpas_dbus_getter_scanning,
2907 { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2908 wpas_dbus_getter_ap_scan,
2909 wpas_dbus_setter_ap_scan
2911 { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2912 wpas_dbus_getter_bss_expire_age,
2913 wpas_dbus_setter_bss_expire_age
2915 { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2916 wpas_dbus_getter_bss_expire_count,
2917 wpas_dbus_setter_bss_expire_count
2919 { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2920 wpas_dbus_getter_country,
2921 wpas_dbus_setter_country
2923 { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2924 wpas_dbus_getter_ifname,
2927 { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2928 wpas_dbus_getter_driver,
2931 { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2932 wpas_dbus_getter_bridge_ifname,
2935 { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2936 wpas_dbus_getter_current_bss,
2939 { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2940 wpas_dbus_getter_current_network,
2943 { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2944 wpas_dbus_getter_current_auth_mode,
2947 { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
2948 wpas_dbus_getter_blobs,
2951 { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2952 wpas_dbus_getter_bsss,
2955 { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2956 wpas_dbus_getter_networks,
2959 { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2960 wpas_dbus_getter_fast_reauth,
2961 wpas_dbus_setter_fast_reauth
2963 { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
2964 wpas_dbus_getter_scan_interval,
2965 wpas_dbus_setter_scan_interval
2967 { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2968 wpas_dbus_getter_pkcs11_engine_path,
2971 { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2972 wpas_dbus_getter_pkcs11_module_path,
2976 { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
2977 wpas_dbus_getter_process_credentials,
2978 wpas_dbus_setter_process_credentials
2980 { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
2981 wpas_dbus_getter_config_methods,
2982 wpas_dbus_setter_config_methods
2984 #endif /* CONFIG_WPS */
2986 { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
2987 wpas_dbus_getter_p2p_device_config,
2988 wpas_dbus_setter_p2p_device_config
2990 { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2991 wpas_dbus_getter_p2p_peers,
2994 { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
2995 wpas_dbus_getter_p2p_role,
2998 { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2999 wpas_dbus_getter_p2p_group,
3002 { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
3003 wpas_dbus_getter_p2p_peergo,
3006 { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
3007 wpas_dbus_getter_persistent_groups,
3010 #endif /* CONFIG_P2P */
3011 { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
3012 wpas_dbus_getter_disconnect_reason,
3015 { NULL, NULL, NULL, NULL, NULL }
3018 static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
3019 { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
3021 { "success", "b", ARG_OUT },
3025 { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3027 { "path", "o", ARG_OUT },
3028 { "properties", "a{sv}", ARG_OUT },
3032 { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3034 { "path", "o", ARG_OUT },
3038 { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3040 { "name", "s", ARG_OUT },
3044 { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3046 { "name", "s", ARG_OUT },
3050 { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3052 { "path", "o", ARG_OUT },
3053 { "properties", "a{sv}", ARG_OUT },
3057 { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3059 { "path", "o", ARG_OUT },
3063 { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
3065 { "path", "o", ARG_OUT },
3069 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3070 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
3072 { "properties", "a{sv}", ARG_OUT },
3077 { "Event", WPAS_DBUS_NEW_IFACE_WPS,
3079 { "name", "s", ARG_OUT },
3080 { "args", "a{sv}", ARG_OUT },
3084 { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
3086 { "credentials", "a{sv}", ARG_OUT },
3090 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3091 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
3093 { "properties", "a{sv}", ARG_OUT },
3097 #endif /* CONFIG_WPS */
3099 { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3101 { "path", "o", ARG_OUT },
3105 { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3107 { "path", "o", ARG_OUT },
3111 { "FindStopped", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3116 { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3118 { "peer_object", "o", ARG_OUT },
3119 { "pin", "s", ARG_OUT },
3123 { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3125 { "peer_object", "o", ARG_OUT },
3126 { "pin", "s", ARG_OUT },
3130 { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3132 { "peer_object", "o", ARG_OUT },
3136 { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3138 { "peer_object", "o", ARG_OUT },
3142 { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3144 { "peer_object", "o", ARG_OUT },
3148 { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3150 { "peer_object", "o", ARG_OUT },
3154 { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3156 { "peer_object", "o", ARG_OUT },
3157 { "status", "i", ARG_OUT },
3161 { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3163 { "properties", "a{sv}", ARG_OUT },
3167 { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3169 { "properties", "a{sv}", ARG_OUT },
3173 { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3175 { "properties", "a{sv}", ARG_OUT },
3179 { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3181 { "path", "o", ARG_OUT },
3182 { "dev_passwd_id", "i", ARG_OUT },
3183 { "device_go_intent", "y", ARG_OUT },
3187 { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3189 { "invite_result", "a{sv}", ARG_OUT },
3193 { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3195 { "properties", "a{sv}", ARG_OUT },
3199 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3201 { "sd_request", "a{sv}", ARG_OUT },
3205 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3207 { "sd_response", "a{sv}", ARG_OUT },
3211 { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3213 { "path", "o", ARG_OUT },
3214 { "properties", "a{sv}", ARG_OUT },
3218 { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3220 { "path", "o", ARG_OUT },
3224 { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3226 { "name", "s", ARG_OUT },
3227 { "args", "a{sv}", ARG_OUT },
3231 #endif /* CONFIG_P2P */
3233 { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
3235 { "args", "a{sv}", ARG_OUT },
3239 #endif /* CONFIG_AP */
3240 { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
3242 { "certification", "a{sv}", ARG_OUT },
3246 { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
3248 { "status", "s", ARG_OUT },
3249 { "parameter", "s", ARG_OUT },
3253 { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3255 { "name", "s", ARG_OUT },
3259 { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3261 { "name", "s", ARG_OUT },
3265 { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
3267 { "path", "o", ARG_OUT },
3268 { "field", "s", ARG_OUT },
3269 { "text", "s", ARG_OUT },
3273 { NULL, NULL, { END_ARGS } }
3277 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
3280 struct wpa_dbus_object_desc *obj_desc = NULL;
3281 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
3284 /* Do nothing if the control interface is not turned on */
3285 if (ctrl_iface == NULL)
3288 /* Create and set the interface's object path */
3289 wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3290 if (wpa_s->dbus_new_path == NULL)
3292 next = ctrl_iface->next_objid++;
3293 os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
3294 WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
3297 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3299 wpa_printf(MSG_ERROR,
3300 "Not enough memory to create object description");
3304 wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
3305 wpas_dbus_interface_properties,
3306 wpas_dbus_interface_signals);
3308 wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
3309 wpa_s->dbus_new_path);
3310 if (wpa_dbus_register_object_per_iface(ctrl_iface,
3311 wpa_s->dbus_new_path,
3312 wpa_s->ifname, obj_desc))
3315 wpas_dbus_signal_interface_added(wpa_s);
3320 os_free(wpa_s->dbus_new_path);
3321 wpa_s->dbus_new_path = NULL;
3322 free_dbus_object_desc(obj_desc);
3327 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
3329 struct wpas_dbus_priv *ctrl_iface;
3331 /* Do nothing if the control interface is not turned on */
3332 if (wpa_s == NULL || wpa_s->global == NULL)
3334 ctrl_iface = wpa_s->global->dbus;
3335 if (ctrl_iface == NULL || wpa_s->dbus_new_path == NULL)
3338 wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
3339 wpa_s->dbus_new_path);
3342 if (wpa_s->preq_notify_peer) {
3343 wpas_dbus_unsubscribe_noc(ctrl_iface);
3344 os_free(wpa_s->preq_notify_peer);
3345 wpa_s->preq_notify_peer = NULL;
3347 #endif /* CONFIG_AP */
3349 if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
3350 wpa_s->dbus_new_path))
3353 wpas_dbus_signal_interface_removed(wpa_s);
3355 os_free(wpa_s->dbus_new_path);
3356 wpa_s->dbus_new_path = NULL;
3363 static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
3364 { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3365 wpas_dbus_getter_p2p_peer_device_name,
3368 { "Manufacturer", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3369 wpas_dbus_getter_p2p_peer_manufacturer,
3372 { "ModelName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3373 wpas_dbus_getter_p2p_peer_modelname,
3376 { "ModelNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3377 wpas_dbus_getter_p2p_peer_modelnumber,
3380 { "SerialNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3381 wpas_dbus_getter_p2p_peer_serialnumber,
3384 { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3385 wpas_dbus_getter_p2p_peer_primary_device_type,
3388 { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
3389 wpas_dbus_getter_p2p_peer_config_method,
3392 { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
3393 wpas_dbus_getter_p2p_peer_level,
3396 { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3397 wpas_dbus_getter_p2p_peer_device_capability,
3400 { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3401 wpas_dbus_getter_p2p_peer_group_capability,
3404 { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3405 wpas_dbus_getter_p2p_peer_secondary_device_types,
3408 { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3409 wpas_dbus_getter_p2p_peer_vendor_extension,
3412 { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3413 wpas_dbus_getter_p2p_peer_ies,
3416 { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3417 wpas_dbus_getter_p2p_peer_device_address,
3420 { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
3421 wpas_dbus_getter_p2p_peer_groups,
3424 { NULL, NULL, NULL, NULL, NULL }
3427 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
3428 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3429 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
3431 { "properties", "a{sv}", ARG_OUT },
3435 { NULL, NULL, { END_ARGS } }
3439 * wpas_dbus_signal_peer - Send a peer related event signal
3440 * @wpa_s: %wpa_supplicant network interface data
3441 * @dev: peer device object
3442 * @interface: name of the interface emitting this signal.
3443 * In case of peer objects, it would be emitted by either
3444 * the "interface object" or by "peer objects"
3445 * @sig_name: signal name - DeviceFound
3447 * Notify listeners about event related with newly found p2p peer device
3449 static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
3450 const u8 *dev_addr, const char *interface,
3451 const char *sig_name)
3453 struct wpas_dbus_priv *iface;
3455 DBusMessageIter iter;
3456 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
3458 if (wpa_s->p2p_mgmt)
3459 wpa_s = wpa_s->parent;
3461 iface = wpa_s->global->dbus;
3463 /* Do nothing if the control interface is not turned on */
3464 if (iface == NULL || !wpa_s->dbus_new_path)
3467 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3468 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3469 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3471 msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
3476 dbus_message_iter_init_append(msg, &iter);
3477 path = peer_obj_path;
3478 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
3480 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
3482 dbus_connection_send(iface->con, msg, NULL);
3484 dbus_message_unref(msg);
3489 * wpas_dbus_signal_peer_found - Send a peer found signal
3490 * @wpa_s: %wpa_supplicant network interface data
3491 * @dev: peer device object
3493 * Notify listeners about find a p2p peer device found
3495 void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
3498 wpas_dbus_signal_peer(wpa_s, dev_addr,
3499 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3504 * wpas_dbus_signal_peer_lost - Send a peer lost signal
3505 * @wpa_s: %wpa_supplicant network interface data
3506 * @dev: peer device object
3508 * Notify listeners about lost a p2p peer device
3510 void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
3513 wpas_dbus_signal_peer(wpa_s, dev_addr,
3514 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3519 * wpas_dbus_register_peer - Register a discovered peer object with dbus
3520 * @wpa_s: wpa_supplicant interface structure
3521 * @ssid: network configuration data
3522 * Returns: 0 on success, -1 on failure
3524 * Registers network representing object with dbus
3526 int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
3528 struct wpas_dbus_priv *ctrl_iface;
3529 struct wpa_dbus_object_desc *obj_desc;
3530 struct peer_handler_args *arg;
3531 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3533 /* Do nothing if the control interface is not turned on */
3534 if (wpa_s == NULL || wpa_s->global == NULL)
3537 ctrl_iface = wpa_s->global->dbus;
3538 if (ctrl_iface == NULL)
3541 wpa_s = wpa_s->parent->parent;
3542 if (!wpa_s->dbus_new_path)
3545 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3546 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3547 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3549 wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
3551 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3553 wpa_printf(MSG_ERROR,
3554 "Not enough memory to create object description");
3558 /* allocate memory for handlers arguments */
3559 arg = os_zalloc(sizeof(struct peer_handler_args));
3561 wpa_printf(MSG_ERROR,
3562 "Not enough memory to create arguments for method");
3567 os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
3569 wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
3571 wpas_dbus_p2p_peer_properties,
3572 wpas_dbus_p2p_peer_signals);
3574 if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
3575 wpa_s->ifname, obj_desc))
3581 free_dbus_object_desc(obj_desc);
3586 * wpas_dbus_unregister_peer - Unregister a peer object with dbus
3587 * @wpa_s: wpa_supplicant interface structure
3588 * @dev_addr: p2p device addr
3589 * Returns: 0 on success, -1 on failure
3591 * Registers network representing object with dbus
3593 int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
3596 struct wpas_dbus_priv *ctrl_iface;
3597 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3600 /* Do nothing if the control interface is not turned on */
3601 if (wpa_s == NULL || wpa_s->global == NULL)
3604 wpa_s = wpa_s->parent->parent;
3605 if (!wpa_s->dbus_new_path)
3608 ctrl_iface = wpa_s->global->dbus;
3609 if (ctrl_iface == NULL)
3612 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3613 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3614 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3616 wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
3618 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
3625 * wpas_dbus_signal_p2p_find_stopped - Send P2P Find stopped signal
3626 * @wpa_s: %wpa_supplicant network interface data
3628 * Notify listeners about P2P Find stopped
3630 void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant *wpa_s)
3632 struct wpas_dbus_priv *iface;
3635 iface = wpa_s->global->dbus;
3637 /* Do nothing if the control interface is not turned on */
3638 if (iface == NULL || !wpa_s->dbus_new_path)
3641 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
3642 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3647 dbus_connection_send(iface->con, msg, NULL);
3649 dbus_message_unref(msg);
3653 void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
3656 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3658 if (wpa_s->p2p_mgmt)
3659 wpa_s = wpa_s->parent;
3661 if (!wpa_s->dbus_new_path)
3663 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3664 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3665 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3667 wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
3668 WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
3672 static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
3673 { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
3674 wpas_dbus_getter_p2p_group_members,
3677 { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
3678 wpas_dbus_getter_p2p_group,
3681 { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3682 wpas_dbus_getter_p2p_role,
3685 { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3686 wpas_dbus_getter_p2p_group_ssid,
3689 { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3690 wpas_dbus_getter_p2p_group_bssid,
3693 { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
3694 wpas_dbus_getter_p2p_group_frequency,
3697 { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
3698 wpas_dbus_getter_p2p_group_passphrase,
3701 { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
3702 wpas_dbus_getter_p2p_group_psk,
3705 { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
3706 wpas_dbus_getter_p2p_group_vendor_ext,
3707 wpas_dbus_setter_p2p_group_vendor_ext
3709 { NULL, NULL, NULL, NULL, NULL }
3712 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
3713 { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3715 { "peer", "o", ARG_OUT },
3719 { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
3721 { "peer", "o", ARG_OUT },
3725 { NULL, NULL, { END_ARGS } }
3729 * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
3730 * @wpa_s: wpa_supplicant interface structure
3731 * @ssid: SSID struct
3732 * Returns: 0 on success, -1 on failure
3734 * Registers p2p group representing object with dbus
3736 void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
3737 struct wpa_ssid *ssid)
3739 struct wpas_dbus_priv *ctrl_iface;
3740 struct wpa_dbus_object_desc *obj_desc;
3741 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3743 /* Do nothing if the control interface is not turned on */
3744 if (wpa_s == NULL || wpa_s->global == NULL)
3747 ctrl_iface = wpa_s->global->dbus;
3748 if (ctrl_iface == NULL)
3751 if (wpa_s->dbus_groupobj_path) {
3752 wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
3753 __func__, wpa_s->dbus_groupobj_path);
3757 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
3760 wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
3761 if (wpa_s->dbus_groupobj_path == NULL)
3764 wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
3766 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3768 wpa_printf(MSG_ERROR,
3769 "Not enough memory to create object description");
3773 wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
3774 wpas_dbus_p2p_group_properties,
3775 wpas_dbus_p2p_group_signals);
3777 if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
3778 wpa_s->ifname, obj_desc))
3784 if (wpa_s->dbus_groupobj_path) {
3785 os_free(wpa_s->dbus_groupobj_path);
3786 wpa_s->dbus_groupobj_path = NULL;
3789 free_dbus_object_desc(obj_desc);
3793 * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
3794 * @wpa_s: wpa_supplicant interface structure
3795 * @ssid: network name of the p2p group started
3797 void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
3798 const struct wpa_ssid *ssid)
3800 struct wpas_dbus_priv *ctrl_iface;
3802 /* Do nothing if the control interface is not turned on */
3803 if (wpa_s == NULL || wpa_s->global == NULL)
3806 if (wpa_s->p2p_mgmt)
3807 wpa_s = wpa_s->parent;
3809 ctrl_iface = wpa_s->global->dbus;
3810 if (ctrl_iface == NULL)
3813 if (!wpa_s->dbus_groupobj_path) {
3814 wpa_printf(MSG_DEBUG,
3815 "%s: Group object '%s' already unregistered",
3816 __func__, wpa_s->dbus_groupobj_path);
3820 peer_groups_changed(wpa_s);
3822 wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
3823 wpa_s->dbus_groupobj_path);
3825 wpa_dbus_unregister_object_per_iface(ctrl_iface,
3826 wpa_s->dbus_groupobj_path);
3828 os_free(wpa_s->dbus_groupobj_path);
3829 wpa_s->dbus_groupobj_path = NULL;
3832 static const struct wpa_dbus_property_desc
3833 wpas_dbus_persistent_group_properties[] = {
3834 { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
3835 wpas_dbus_getter_persistent_group_properties,
3836 wpas_dbus_setter_persistent_group_properties
3838 { NULL, NULL, NULL, NULL, NULL }
3841 /* No signals intended for persistent group objects */
3844 * wpas_dbus_register_persistent_group - Register a configured(saved)
3845 * persistent group with dbus
3846 * @wpa_s: wpa_supplicant interface structure
3847 * @ssid: persistent group (still represented as a network within wpa)
3848 * configuration data
3849 * Returns: 0 on success, -1 on failure
3851 * Registers a persistent group representing object with dbus.
3853 int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
3854 struct wpa_ssid *ssid)
3856 struct wpas_dbus_priv *ctrl_iface;
3857 struct wpa_dbus_object_desc *obj_desc;
3858 struct network_handler_args *arg;
3859 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3861 /* Do nothing if the control interface is not turned on */
3862 if (wpa_s == NULL || wpa_s->global == NULL)
3864 wpa_s = wpa_s->parent->parent;
3865 if (!wpa_s->dbus_new_path)
3868 /* Make sure ssid is a persistent group */
3869 if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
3870 return -1; /* should we return w/o complaining? */
3872 if (wpa_s->p2p_mgmt)
3873 wpa_s = wpa_s->parent;
3875 ctrl_iface = wpa_s->global->dbus;
3876 if (ctrl_iface == NULL)
3880 * Intentionally not coming up with different numbering scheme
3881 * for persistent groups.
3883 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3884 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3885 wpa_s->dbus_new_path, ssid->id);
3887 wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
3889 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3891 wpa_printf(MSG_ERROR,
3892 "dbus: Not enough memory to create object description");
3897 * Reusing the same context structure as that for networks
3898 * since these are represented using same data structure.
3900 /* allocate memory for handlers arguments */
3901 arg = os_zalloc(sizeof(struct network_handler_args));
3903 wpa_printf(MSG_ERROR,
3904 "dbus: Not enough memory to create arguments for method");
3911 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3912 wpas_dbus_persistent_group_properties,
3915 if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
3916 wpa_s->ifname, obj_desc))
3919 wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
3924 free_dbus_object_desc(obj_desc);
3930 * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
3932 * @wpa_s: wpa_supplicant interface structure
3934 * Returns: 0 on success, -1 on failure
3936 * Unregisters persistent group representing object from dbus
3938 * NOTE: There is a slight issue with the semantics here. While the
3939 * implementation simply means the persistent group is unloaded from memory,
3940 * it should not get interpreted as the group is actually being erased/removed
3941 * from persistent storage as well.
3943 int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
3946 struct wpas_dbus_priv *ctrl_iface;
3947 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3950 /* Do nothing if the control interface is not turned on */
3951 if (wpa_s == NULL || wpa_s->global == NULL)
3954 wpa_s = wpa_s->parent->parent;
3956 ctrl_iface = wpa_s->global->dbus;
3957 if (ctrl_iface == NULL || !wpa_s->dbus_new_path)
3960 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3961 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3962 wpa_s->dbus_new_path, nid);
3964 wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
3966 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
3969 wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
3974 #endif /* CONFIG_P2P */