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
606 * @fail: WPS failure information
608 * Sends Event dbus signal with name "fail" and dictionary containing
609 * "msg field with fail message number (int32) as arguments
611 void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
612 struct wps_event_fail *fail)
616 DBusMessageIter iter, dict_iter;
617 struct wpas_dbus_priv *iface;
620 iface = wpa_s->global->dbus;
622 /* Do nothing if the control interface is not turned on */
623 if (iface == NULL || !wpa_s->dbus_new_path)
626 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
627 WPAS_DBUS_NEW_IFACE_WPS, "Event");
631 dbus_message_iter_init_append(msg, &iter);
633 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
634 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
635 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
636 !wpa_dbus_dict_append_int32(&dict_iter, "config_error",
637 fail->config_error) ||
638 !wpa_dbus_dict_append_int32(&dict_iter, "error_indication",
639 fail->error_indication) ||
640 !wpa_dbus_dict_close_write(&iter, &dict_iter))
641 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
643 dbus_connection_send(iface->con, msg, NULL);
645 dbus_message_unref(msg);
650 * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
651 * @wpa_s: %wpa_supplicant network interface data
652 * @m2d: M2D event data information
654 * Sends Event dbus signal with name "m2d" and dictionary containing
655 * fields of wps_event_m2d structure.
657 void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
658 struct wps_event_m2d *m2d)
662 DBusMessageIter iter, dict_iter;
663 struct wpas_dbus_priv *iface;
666 iface = wpa_s->global->dbus;
668 /* Do nothing if the control interface is not turned on */
669 if (iface == NULL || !wpa_s->dbus_new_path)
672 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
673 WPAS_DBUS_NEW_IFACE_WPS, "Event");
677 dbus_message_iter_init_append(msg, &iter);
679 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
680 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
681 !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
682 m2d->config_methods) ||
683 !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
684 (const char *) m2d->manufacturer,
685 m2d->manufacturer_len) ||
686 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
687 (const char *) m2d->model_name,
688 m2d->model_name_len) ||
689 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
690 (const char *) m2d->model_number,
691 m2d->model_number_len) ||
692 !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
695 m2d->serial_number_len) ||
696 !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
697 (const char *) m2d->dev_name,
698 m2d->dev_name_len) ||
699 !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
701 m2d->primary_dev_type, 8) ||
702 !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
703 m2d->config_error) ||
704 !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
705 m2d->dev_password_id) ||
706 !wpa_dbus_dict_close_write(&iter, &dict_iter))
707 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
709 dbus_connection_send(iface->con, msg, NULL);
711 dbus_message_unref(msg);
716 * wpas_dbus_signal_wps_cred - Signals new credentials
717 * @wpa_s: %wpa_supplicant network interface data
718 * @cred: WPS Credential information
720 * Sends signal with credentials in directory argument
722 void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
723 const struct wps_credential *cred)
726 DBusMessageIter iter, dict_iter;
727 struct wpas_dbus_priv *iface;
728 char *auth_type[5]; /* we have five possible authentication types */
730 char *encr_type[3]; /* we have three possible encryption types */
733 iface = wpa_s->global->dbus;
735 /* Do nothing if the control interface is not turned on */
736 if (iface == NULL || !wpa_s->dbus_new_path)
739 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
740 WPAS_DBUS_NEW_IFACE_WPS,
745 dbus_message_iter_init_append(msg, &iter);
746 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
749 if (cred->auth_type & WPS_AUTH_OPEN)
750 auth_type[at_num++] = "open";
751 if (cred->auth_type & WPS_AUTH_WPAPSK)
752 auth_type[at_num++] = "wpa-psk";
753 if (cred->auth_type & WPS_AUTH_WPA)
754 auth_type[at_num++] = "wpa-eap";
755 if (cred->auth_type & WPS_AUTH_WPA2)
756 auth_type[at_num++] = "wpa2-eap";
757 if (cred->auth_type & WPS_AUTH_WPA2PSK)
758 auth_type[at_num++] = "wpa2-psk";
760 if (cred->encr_type & WPS_ENCR_NONE)
761 encr_type[et_num++] = "none";
762 if (cred->encr_type & WPS_ENCR_TKIP)
763 encr_type[et_num++] = "tkip";
764 if (cred->encr_type & WPS_ENCR_AES)
765 encr_type[et_num++] = "aes";
767 if ((wpa_s->current_ssid &&
768 !wpa_dbus_dict_append_byte_array(
770 (const char *) wpa_s->current_ssid->bssid, ETH_ALEN)) ||
771 !wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
772 (const char *) cred->ssid,
774 !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
775 (const char **) auth_type,
777 !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
778 (const char **) encr_type,
780 !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
781 (const char *) cred->key,
783 !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
785 !wpa_dbus_dict_close_write(&iter, &dict_iter))
788 dbus_connection_send(iface->con, msg, NULL);
791 dbus_message_unref(msg);
794 #endif /* CONFIG_WPS */
796 void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
797 int depth, const char *subject,
798 const char *altsubject[],
800 const char *cert_hash,
801 const struct wpabuf *cert)
803 struct wpas_dbus_priv *iface;
805 DBusMessageIter iter, dict_iter;
807 iface = wpa_s->global->dbus;
809 /* Do nothing if the control interface is not turned on */
810 if (iface == NULL || !wpa_s->dbus_new_path)
813 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
814 WPAS_DBUS_NEW_IFACE_INTERFACE,
819 dbus_message_iter_init_append(msg, &iter);
820 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
821 !wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
822 !wpa_dbus_dict_append_string(&dict_iter, "subject", subject) ||
823 (altsubject && num_altsubject &&
824 !wpa_dbus_dict_append_string_array(&dict_iter, "altsubject",
825 altsubject, num_altsubject)) ||
827 !wpa_dbus_dict_append_string(&dict_iter, "cert_hash",
830 !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
832 wpabuf_len(cert))) ||
833 !wpa_dbus_dict_close_write(&iter, &dict_iter))
834 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
836 dbus_connection_send(iface->con, msg, NULL);
837 dbus_message_unref(msg);
841 void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
842 const char *status, const char *parameter)
844 struct wpas_dbus_priv *iface;
846 DBusMessageIter iter;
848 iface = wpa_s->global->dbus;
850 /* Do nothing if the control interface is not turned on */
851 if (iface == NULL || !wpa_s->dbus_new_path)
854 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
855 WPAS_DBUS_NEW_IFACE_INTERFACE,
860 dbus_message_iter_init_append(msg, &iter);
862 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status) ||
863 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
865 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
867 dbus_connection_send(iface->con, msg, NULL);
868 dbus_message_unref(msg);
873 * wpas_dbus_signal_sta - Send a station related event signal
874 * @wpa_s: %wpa_supplicant network interface data
875 * @sta: station mac address
876 * @sig_name: signal name - StaAuthorized or StaDeauthorized
878 * Notify listeners about event related with station
880 static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
881 const u8 *sta, const char *sig_name)
883 struct wpas_dbus_priv *iface;
885 char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
888 os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
891 iface = wpa_s->global->dbus;
893 /* Do nothing if the control interface is not turned on */
894 if (iface == NULL || !wpa_s->dbus_new_path)
897 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
898 WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
902 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
904 dbus_connection_send(iface->con, msg, NULL);
906 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
907 dbus_message_unref(msg);
909 wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
915 * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
916 * @wpa_s: %wpa_supplicant network interface data
917 * @sta: station mac address
919 * Notify listeners a new station has been authorized
921 void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
924 wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
929 * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
930 * @wpa_s: %wpa_supplicant network interface data
931 * @sta: station mac address
933 * Notify listeners a station has been deauthorized
935 void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
938 wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
945 * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
946 * @wpa_s: %wpa_supplicant network interface data
947 * @role: role of this device (client or GO)
948 * Sends signal with i/f name and role as string arguments
950 void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
954 DBusMessageIter iter, dict_iter;
955 struct wpas_dbus_priv *iface = wpa_s->global->dbus;
956 struct wpa_supplicant *parent;
958 /* Do nothing if the control interface is not turned on */
962 parent = wpa_s->parent;
963 if (parent->p2p_mgmt)
964 parent = parent->parent;
966 if (!wpa_s->dbus_groupobj_path || !wpa_s->dbus_new_path ||
967 !parent->dbus_new_path)
970 msg = dbus_message_new_signal(parent->dbus_new_path,
971 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
976 dbus_message_iter_init_append(msg, &iter);
977 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
978 !wpa_dbus_dict_append_object_path(&dict_iter,
980 wpa_s->dbus_new_path) ||
981 !wpa_dbus_dict_append_string(&dict_iter, "role", role) ||
982 !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
983 wpa_s->dbus_groupobj_path) ||
984 !wpa_dbus_dict_close_write(&iter, &dict_iter))
985 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
987 dbus_connection_send(iface->con, msg, NULL);
988 dbus_message_unref(msg);
993 * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
995 * @dev_addr - who sent the request or responded to our request.
996 * @request - Will be 1 if request, 0 for response.
997 * @status - valid only in case of response
998 * @config_methods - wps config methods
999 * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
1001 * Sends following provision discovery related events:
1002 * ProvisionDiscoveryRequestDisplayPin
1003 * ProvisionDiscoveryResponseDisplayPin
1004 * ProvisionDiscoveryRequestEnterPin
1005 * ProvisionDiscoveryResponseEnterPin
1006 * ProvisionDiscoveryPBCRequest
1007 * ProvisionDiscoveryPBCResponse
1010 * ProvisionDiscoveryFailure (timeout case)
1012 void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
1013 const u8 *dev_addr, int request,
1014 enum p2p_prov_disc_status status,
1016 unsigned int generated_pin)
1019 DBusMessageIter iter;
1020 struct wpas_dbus_priv *iface;
1023 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1025 char pin[9], *p_pin = NULL;
1027 iface = wpa_s->global->dbus;
1029 /* Do nothing if the control interface is not turned on */
1033 if (wpa_s->p2p_mgmt)
1034 wpa_s = wpa_s->parent;
1035 if (!wpa_s->dbus_new_path)
1038 if (request || !status) {
1039 if (config_methods & WPS_CONFIG_DISPLAY)
1041 "ProvisionDiscoveryRequestDisplayPin" :
1042 "ProvisionDiscoveryResponseEnterPin";
1043 else if (config_methods & WPS_CONFIG_KEYPAD)
1045 "ProvisionDiscoveryRequestEnterPin" :
1046 "ProvisionDiscoveryResponseDisplayPin";
1047 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1048 _signal = request ? "ProvisionDiscoveryPBCRequest" :
1049 "ProvisionDiscoveryPBCResponse";
1051 return; /* Unknown or un-supported method */
1053 /* Explicit check for failure response */
1054 _signal = "ProvisionDiscoveryFailure";
1057 add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
1058 (!request && !status &&
1059 (config_methods & WPS_CONFIG_KEYPAD)));
1062 os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
1066 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1067 WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
1071 /* Check if this is a known peer */
1072 if (!p2p_peer_known(wpa_s->global->p2p, dev_addr))
1075 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1076 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1078 wpa_s->dbus_new_path, MAC2STR(dev_addr));
1080 path = peer_obj_path;
1082 dbus_message_iter_init_append(msg, &iter);
1084 if (!dbus_message_iter_append_basic(&iter,
1085 DBUS_TYPE_OBJECT_PATH,
1089 if (!request && status)
1090 /* Attach status to ProvisionDiscoveryFailure */
1091 error_ret = !dbus_message_iter_append_basic(&iter,
1095 error_ret = (add_pin &&
1096 !dbus_message_iter_append_basic(&iter,
1102 dbus_connection_send(iface->con, msg, NULL);
1104 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1106 dbus_message_unref(msg);
1111 * wpas_dbus_signal_p2p_go_neg_req - Signal P2P GO Negotiation Request RX
1112 * @wpa_s: %wpa_supplicant network interface data
1113 * @src: Source address of the message triggering this notification
1114 * @dev_passwd_id: WPS Device Password Id
1115 * @go_intent: Peer's GO Intent value
1117 * Sends signal to notify that a peer P2P Device is requesting group owner
1118 * negotiation with us.
1120 void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
1121 const u8 *src, u16 dev_passwd_id,
1125 DBusMessageIter iter;
1126 struct wpas_dbus_priv *iface;
1127 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1129 iface = wpa_s->global->dbus;
1131 /* Do nothing if the control interface is not turned on */
1135 if (wpa_s->p2p_mgmt)
1136 wpa_s = wpa_s->parent;
1137 if (!wpa_s->dbus_new_path)
1140 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1141 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1142 wpa_s->dbus_new_path, MAC2STR(src));
1143 path = peer_obj_path;
1145 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1146 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1147 "GONegotiationRequest");
1151 dbus_message_iter_init_append(msg, &iter);
1153 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1155 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
1157 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE,
1159 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1161 dbus_connection_send(iface->con, msg, NULL);
1163 dbus_message_unref(msg);
1167 static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
1168 const struct wpa_ssid *ssid,
1169 char *group_obj_path)
1173 if (!wpa_s->dbus_new_path ||
1174 os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
1177 os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
1178 group_name[2] = '\0';
1180 os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1181 "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
1182 wpa_s->dbus_new_path, group_name);
1188 struct group_changed_data {
1189 struct wpa_supplicant *wpa_s;
1190 struct p2p_peer_info *info;
1194 static int match_group_where_peer_is_client(struct p2p_group *group,
1197 struct group_changed_data *data = user_data;
1198 const struct p2p_group_config *cfg;
1199 struct wpa_supplicant *wpa_s_go;
1201 if (!p2p_group_is_client_connected(group, data->info->p2p_device_addr))
1204 cfg = p2p_group_get_config(group);
1206 wpa_s_go = wpas_get_p2p_go_iface(data->wpa_s, cfg->ssid,
1208 if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
1209 wpas_dbus_signal_peer_groups_changed(
1210 data->wpa_s->p2pdev, data->info->p2p_device_addr);
1218 static void signal_peer_groups_changed(struct p2p_peer_info *info,
1221 struct group_changed_data *data = user_data;
1222 struct wpa_supplicant *wpa_s_go;
1224 wpa_s_go = wpas_get_p2p_client_iface(data->wpa_s,
1225 info->p2p_device_addr);
1226 if (wpa_s_go != NULL && wpa_s_go == data->wpa_s) {
1227 wpas_dbus_signal_peer_groups_changed(data->wpa_s->p2pdev,
1228 info->p2p_device_addr);
1233 p2p_loop_on_all_groups(data->wpa_s->global->p2p,
1234 match_group_where_peer_is_client, data);
1239 static void peer_groups_changed(struct wpa_supplicant *wpa_s)
1241 struct group_changed_data data;
1243 os_memset(&data, 0, sizeof(data));
1246 p2p_loop_on_known_peers(wpa_s->global->p2p,
1247 signal_peer_groups_changed, &data);
1252 * wpas_dbus_signal_p2p_group_started - Signals P2P group has
1253 * started. Emitted when a group is successfully started
1254 * irrespective of the role (client/GO) of the current device
1256 * @wpa_s: %wpa_supplicant network interface data
1257 * @client: this device is P2P client
1258 * @persistent: 0 - non persistent group, 1 - persistent group
1260 void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
1261 int client, int persistent)
1264 DBusMessageIter iter, dict_iter;
1265 struct wpas_dbus_priv *iface;
1266 struct wpa_supplicant *parent;
1268 parent = wpa_s->parent;
1269 if (parent->p2p_mgmt)
1270 parent = parent->parent;
1272 iface = parent->global->dbus;
1274 /* Do nothing if the control interface is not turned on */
1275 if (iface == NULL || !parent->dbus_new_path || !wpa_s->dbus_new_path)
1278 if (wpa_s->dbus_groupobj_path == NULL)
1281 /* New interface has been created for this group */
1282 msg = dbus_message_new_signal(parent->dbus_new_path,
1283 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1288 dbus_message_iter_init_append(msg, &iter);
1290 * In case the device supports creating a separate interface the
1291 * DBus client will need to know the object path for the interface
1292 * object this group was created on, so include it here.
1294 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1295 !wpa_dbus_dict_append_object_path(&dict_iter,
1297 wpa_s->dbus_new_path) ||
1298 !wpa_dbus_dict_append_string(&dict_iter, "role",
1299 client ? "client" : "GO") ||
1300 !wpa_dbus_dict_append_bool(&dict_iter, "persistent", persistent) ||
1301 !wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
1302 wpa_s->dbus_groupobj_path) ||
1303 !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
1304 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1306 dbus_connection_send(iface->con, msg, NULL);
1308 peer_groups_changed(wpa_s);
1310 dbus_message_unref(msg);
1315 * wpas_dbus_signal_p2p_go_neg_resp - Emit GONegotiation Success/Failure signal
1316 * @wpa_s: %wpa_supplicant network interface data
1317 * @res: Result of the GO Neg Request
1319 void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s,
1320 struct p2p_go_neg_results *res)
1323 DBusMessageIter iter, dict_iter;
1324 DBusMessageIter iter_dict_entry, iter_dict_val, iter_dict_array;
1325 struct wpas_dbus_priv *iface;
1326 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1327 dbus_int32_t freqs[P2P_MAX_CHANNELS];
1328 dbus_int32_t *f_array = freqs;
1331 iface = wpa_s->global->dbus;
1333 if (wpa_s->p2p_mgmt)
1334 wpa_s = wpa_s->parent;
1336 os_memset(freqs, 0, sizeof(freqs));
1337 /* Do nothing if the control interface is not turned on */
1338 if (iface == NULL || !wpa_s->dbus_new_path)
1341 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1342 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
1343 wpa_s->dbus_new_path, MAC2STR(res->peer_device_addr));
1344 path = peer_obj_path;
1346 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1347 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1348 res->status ? "GONegotiationFailure" :
1349 "GONegotiationSuccess");
1353 dbus_message_iter_init_append(msg, &iter);
1354 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1355 !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1357 !wpa_dbus_dict_append_int32(&dict_iter, "status", res->status))
1362 int freq_list_num = 0;
1364 if ((res->role_go &&
1365 !wpa_dbus_dict_append_string(&dict_iter, "passphrase",
1366 res->passphrase)) ||
1367 !wpa_dbus_dict_append_string(&dict_iter, "role_go",
1368 res->role_go ? "GO" :
1370 !wpa_dbus_dict_append_int32(&dict_iter, "frequency",
1372 !wpa_dbus_dict_append_byte_array(&dict_iter, "ssid",
1373 (const char *) res->ssid,
1375 !wpa_dbus_dict_append_byte_array(&dict_iter,
1378 res->peer_device_addr,
1380 !wpa_dbus_dict_append_byte_array(&dict_iter,
1381 "peer_interface_addr",
1383 res->peer_interface_addr,
1385 !wpa_dbus_dict_append_string(&dict_iter, "wps_method",
1386 p2p_wps_method_text(
1390 for (i = 0; i < P2P_MAX_CHANNELS; i++) {
1391 if (res->freq_list[i]) {
1392 freqs[i] = res->freq_list[i];
1397 if (!wpa_dbus_dict_begin_array(&dict_iter,
1399 DBUS_TYPE_INT32_AS_STRING,
1402 &iter_dict_array) ||
1403 !dbus_message_iter_append_fixed_array(&iter_dict_array,
1407 !wpa_dbus_dict_end_array(&dict_iter,
1410 &iter_dict_array) ||
1411 !wpa_dbus_dict_append_int32(&dict_iter, "persistent_group",
1412 res->persistent_group) ||
1413 !wpa_dbus_dict_append_uint32(&dict_iter,
1414 "peer_config_timeout",
1415 res->peer_config_timeout))
1419 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1422 dbus_connection_send(iface->con, msg, NULL);
1424 dbus_message_unref(msg);
1429 * wpas_dbus_signal_p2p_invitation_result - Emit InvitationResult signal
1430 * @wpa_s: %wpa_supplicant network interface data
1431 * @status: Status of invitation process
1432 * @bssid: Basic Service Set Identifier
1434 void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
1435 int status, const u8 *bssid)
1438 DBusMessageIter iter, dict_iter;
1439 struct wpas_dbus_priv *iface;
1441 wpa_printf(MSG_DEBUG, "%s", __func__);
1443 iface = wpa_s->global->dbus;
1444 /* Do nothing if the control interface is not turned on */
1448 if (wpa_s->p2p_mgmt)
1449 wpa_s = wpa_s->parent;
1450 if (!wpa_s->dbus_new_path)
1453 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1454 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1455 "InvitationResult");
1460 dbus_message_iter_init_append(msg, &iter);
1461 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1462 !wpa_dbus_dict_append_int32(&dict_iter, "status", status) ||
1464 !wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
1465 (const char *) bssid,
1467 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1468 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1470 dbus_connection_send(iface->con, msg, NULL);
1471 dbus_message_unref(msg);
1477 * Method to emit a signal for a peer joining the group.
1478 * The signal will carry path to the group member object
1479 * constructed using p2p i/f addr used for connecting.
1481 * @wpa_s: %wpa_supplicant network interface data
1482 * @peer_addr: P2P Device Address of the peer joining the group
1484 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
1485 const u8 *peer_addr)
1487 struct wpas_dbus_priv *iface;
1489 DBusMessageIter iter;
1490 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1491 struct wpa_supplicant *parent;
1493 iface = wpa_s->global->dbus;
1495 /* Do nothing if the control interface is not turned on */
1499 if (!wpa_s->dbus_groupobj_path)
1502 parent = wpa_s->parent;
1503 if (parent->p2p_mgmt)
1504 parent = parent->parent;
1505 if (!parent->dbus_new_path)
1508 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1509 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1511 parent->dbus_new_path, MAC2STR(peer_addr));
1513 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1514 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1519 dbus_message_iter_init_append(msg, &iter);
1520 path = peer_obj_path;
1521 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1523 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1525 dbus_connection_send(iface->con, msg, NULL);
1526 wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
1528 dbus_message_unref(msg);
1534 * Method to emit a signal for a peer disconnecting the group.
1535 * The signal will carry path to the group member object
1536 * constructed using the P2P Device Address of the peer.
1538 * @wpa_s: %wpa_supplicant network interface data
1539 * @peer_addr: P2P Device Address of the peer joining the group
1541 void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
1542 const u8 *peer_addr)
1544 struct wpas_dbus_priv *iface;
1546 DBusMessageIter iter;
1547 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1548 struct wpa_supplicant *parent;
1550 iface = wpa_s->global->dbus;
1552 /* Do nothing if the control interface is not turned on */
1556 if (!wpa_s->dbus_groupobj_path)
1559 parent = wpa_s->parent;
1560 if (parent->p2p_mgmt)
1561 parent = parent->parent;
1562 if (!parent->dbus_new_path)
1565 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1566 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1568 parent->dbus_new_path, MAC2STR(peer_addr));
1570 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1571 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1572 "PeerDisconnected");
1576 dbus_message_iter_init_append(msg, &iter);
1577 path = peer_obj_path;
1578 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1580 wpa_printf(MSG_ERROR,
1581 "dbus: Failed to construct PeerDisconnected signal");
1583 dbus_connection_send(iface->con, msg, NULL);
1584 wpas_dbus_signal_peer_groups_changed(parent, peer_addr);
1586 dbus_message_unref(msg);
1592 * Method to emit a signal for a service discovery request.
1593 * The signal will carry station address, frequency, dialog token,
1594 * update indicator and it tlvs
1596 * @wpa_s: %wpa_supplicant network interface data
1597 * @sa: station addr (p2p i/f) of the peer
1598 * @dialog_token: service discovery request dialog token
1599 * @update_indic: service discovery request update indicator
1600 * @tlvs: service discovery request genrated byte array of tlvs
1601 * @tlvs_len: service discovery request tlvs length
1603 void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
1604 int freq, const u8 *sa, u8 dialog_token,
1605 u16 update_indic, const u8 *tlvs,
1609 DBusMessageIter iter, dict_iter;
1610 struct wpas_dbus_priv *iface;
1611 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1613 iface = wpa_s->global->dbus;
1615 /* Do nothing if the control interface is not turned on */
1619 if (wpa_s->p2p_mgmt)
1620 wpa_s = wpa_s->parent;
1621 if (!wpa_s->dbus_new_path)
1624 /* Check if this is a known peer */
1625 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1628 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1629 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1630 "ServiceDiscoveryRequest");
1634 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1635 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1636 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1638 path = peer_obj_path;
1640 dbus_message_iter_init_append(msg, &iter);
1641 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1642 !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1644 !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
1645 !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
1647 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1649 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1650 (const char *) tlvs,
1652 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1653 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1655 dbus_connection_send(iface->con, msg, NULL);
1656 dbus_message_unref(msg);
1662 * Method to emit a signal for a service discovery response.
1663 * The signal will carry station address, update indicator and it
1666 * @wpa_s: %wpa_supplicant network interface data
1667 * @sa: station addr (p2p i/f) of the peer
1668 * @update_indic: service discovery request update indicator
1669 * @tlvs: service discovery request genrated byte array of tlvs
1670 * @tlvs_len: service discovery request tlvs length
1672 void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
1673 const u8 *sa, u16 update_indic,
1674 const u8 *tlvs, size_t tlvs_len)
1677 DBusMessageIter iter, dict_iter;
1678 struct wpas_dbus_priv *iface;
1679 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1681 iface = wpa_s->global->dbus;
1683 /* Do nothing if the control interface is not turned on */
1687 if (wpa_s->p2p_mgmt)
1688 wpa_s = wpa_s->parent;
1689 if (!wpa_s->dbus_new_path)
1692 /* Check if this is a known peer */
1693 if (!p2p_peer_known(wpa_s->global->p2p, sa))
1696 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1697 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1698 "ServiceDiscoveryResponse");
1702 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1703 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1704 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1706 path = peer_obj_path;
1708 dbus_message_iter_init_append(msg, &iter);
1709 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1710 !wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1712 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1714 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1715 (const char *) tlvs,
1717 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1718 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1720 dbus_connection_send(iface->con, msg, NULL);
1721 dbus_message_unref(msg);
1726 * wpas_dbus_signal_persistent_group - Send a persistent group related
1728 * @wpa_s: %wpa_supplicant network interface data
1729 * @id: new persistent group id
1730 * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
1731 * @properties: determines if add second argument with object properties
1733 * Notify listeners about an event related to persistent groups.
1735 static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
1736 int id, const char *sig_name,
1739 struct wpas_dbus_priv *iface;
1741 DBusMessageIter iter;
1742 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1744 iface = wpa_s->global->dbus;
1746 /* Do nothing if the control interface is not turned on */
1750 if (wpa_s->p2p_mgmt)
1751 wpa_s = wpa_s->parent;
1752 if (!wpa_s->dbus_new_path)
1755 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1756 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
1757 wpa_s->dbus_new_path, id);
1759 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1760 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1765 dbus_message_iter_init_append(msg, &iter);
1766 path = pgrp_obj_path;
1767 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1770 !wpa_dbus_get_object_properties(
1771 iface, pgrp_obj_path,
1772 WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter)))
1773 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1775 dbus_connection_send(iface->con, msg, NULL);
1777 dbus_message_unref(msg);
1782 * wpas_dbus_signal_persistent_group_added - Send a persistent_group
1784 * @wpa_s: %wpa_supplicant network interface data
1785 * @id: new persistent group id
1787 * Notify listeners about addition of a new persistent group.
1789 static void wpas_dbus_signal_persistent_group_added(
1790 struct wpa_supplicant *wpa_s, int id)
1792 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
1798 * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
1800 * @wpa_s: %wpa_supplicant network interface data
1801 * @id: persistent group id
1803 * Notify listeners about removal of a persistent group.
1805 static void wpas_dbus_signal_persistent_group_removed(
1806 struct wpa_supplicant *wpa_s, int id)
1808 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
1814 * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
1815 * @wpa_s: %wpa_supplicant network interface data
1816 * @fail: WPS failure information
1818 * Sends Event dbus signal with name "fail" and dictionary containing
1819 * "msg" field with fail message number (int32) as arguments
1821 void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
1822 struct wps_event_fail *fail)
1826 DBusMessageIter iter, dict_iter;
1827 struct wpas_dbus_priv *iface;
1830 iface = wpa_s->global->dbus;
1832 /* Do nothing if the control interface is not turned on */
1836 if (wpa_s->p2p_mgmt)
1837 wpa_s = wpa_s->parent;
1839 if (!wpa_s->dbus_new_path)
1841 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1842 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1847 dbus_message_iter_init_append(msg, &iter);
1849 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
1850 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1851 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
1852 !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
1853 fail->config_error) ||
1854 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1855 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1857 dbus_connection_send(iface->con, msg, NULL);
1859 dbus_message_unref(msg);
1864 * wpas_dbus_signal_p2p_group_formation_failure - Signals GroupFormationFailure event
1865 * @wpa_s: %wpa_supplicant network interface data
1866 * @reason: indicates the reason code for group formation failure
1868 * Sends Event dbus signal and string reason code when available.
1870 void wpas_dbus_signal_p2p_group_formation_failure(struct wpa_supplicant *wpa_s,
1874 struct wpas_dbus_priv *iface;
1876 iface = wpa_s->global->dbus;
1878 /* Do nothing if the control interface is not turned on */
1882 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1883 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1884 "GroupFormationFailure");
1888 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &reason,
1890 dbus_connection_send(iface->con, msg, NULL);
1892 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1894 dbus_message_unref(msg);
1899 * wpas_dbus_signal_p2p_invitation_received - Emit InvitationReceived signal
1900 * @wpa_s: %wpa_supplicant network interface data
1901 * @sa: Source address of the Invitation Request
1902 * @dev_add: GO Device Address
1903 * @bssid: P2P Group BSSID or %NULL if not received
1904 * @id: Persistent group id or %0 if not persistent group
1905 * @op_freq: Operating frequency for the group
1908 void wpas_dbus_signal_p2p_invitation_received(struct wpa_supplicant *wpa_s,
1909 const u8 *sa, const u8 *dev_addr,
1910 const u8 *bssid, int id,
1914 DBusMessageIter iter, dict_iter;
1915 struct wpas_dbus_priv *iface;
1917 iface = wpa_s->global->dbus;
1919 /* Do nothing if the control interface is not turned on */
1923 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1924 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1925 "InvitationReceived");
1929 dbus_message_iter_init_append(msg, &iter);
1930 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1932 !wpa_dbus_dict_append_byte_array(&dict_iter, "sa",
1933 (const char *) sa, ETH_ALEN)) ||
1935 !wpa_dbus_dict_append_byte_array(&dict_iter, "go_dev_addr",
1936 (const char *) dev_addr,
1939 !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
1940 (const char *) bssid,
1943 !wpa_dbus_dict_append_int32(&dict_iter, "persistent_id", id)) ||
1944 !wpa_dbus_dict_append_int32(&dict_iter, "op_freq", op_freq) ||
1945 !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
1946 dbus_message_unref(msg);
1950 dbus_connection_send(iface->con, msg, NULL);
1951 dbus_message_unref(msg);
1955 #endif /* CONFIG_P2P */
1959 * wpas_dbus_signal_prop_changed - Signals change of property
1960 * @wpa_s: %wpa_supplicant network interface data
1961 * @property: indicates which property has changed
1963 * Sends PropertyChanged signals with path, interface and arguments
1964 * depending on which property has changed.
1966 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
1967 enum wpas_dbus_prop property)
1972 if (wpa_s->dbus_new_path == NULL)
1973 return; /* Skip signal since D-Bus setup is not yet ready */
1977 case WPAS_DBUS_PROP_AP_SCAN:
1980 case WPAS_DBUS_PROP_SCANNING:
1983 case WPAS_DBUS_PROP_STATE:
1986 case WPAS_DBUS_PROP_CURRENT_BSS:
1987 prop = "CurrentBSS";
1989 case WPAS_DBUS_PROP_CURRENT_NETWORK:
1990 prop = "CurrentNetwork";
1992 case WPAS_DBUS_PROP_BSSS:
1995 case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
1996 prop = "CurrentAuthMode";
1998 case WPAS_DBUS_PROP_DISCONNECT_REASON:
1999 prop = "DisconnectReason";
2002 case WPAS_DBUS_PROP_ASSOC_STATUS_CODE:
2003 prop = "AssocStatusCode";
2007 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
2008 __func__, property);
2012 wpa_dbus_mark_property_changed(wpa_s->global->dbus,
2013 wpa_s->dbus_new_path,
2014 WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
2016 wpa_dbus_flush_object_changed_properties(
2017 wpa_s->global->dbus->con, wpa_s->dbus_new_path);
2023 * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
2024 * @wpa_s: %wpa_supplicant network interface data
2025 * @property: indicates which property has changed
2026 * @id: unique BSS identifier
2028 * Sends PropertyChanged signals with path, interface, and arguments depending
2029 * on which property has changed.
2031 void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
2032 enum wpas_dbus_bss_prop property,
2035 char path[WPAS_DBUS_OBJECT_PATH_MAX];
2038 if (!wpa_s->dbus_new_path)
2042 case WPAS_DBUS_BSS_PROP_SIGNAL:
2045 case WPAS_DBUS_BSS_PROP_FREQ:
2048 case WPAS_DBUS_BSS_PROP_MODE:
2051 case WPAS_DBUS_BSS_PROP_PRIVACY:
2054 case WPAS_DBUS_BSS_PROP_RATES:
2057 case WPAS_DBUS_BSS_PROP_WPA:
2060 case WPAS_DBUS_BSS_PROP_RSN:
2063 case WPAS_DBUS_BSS_PROP_WPS:
2066 case WPAS_DBUS_BSS_PROP_IES:
2069 case WPAS_DBUS_BSS_PROP_AGE:
2073 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
2074 __func__, property);
2078 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
2079 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2080 wpa_s->dbus_new_path, id);
2082 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
2083 WPAS_DBUS_NEW_IFACE_BSS, prop);
2088 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
2089 * @global: wpa_global structure
2091 * Sends PropertyChanged signals informing that debug level has changed.
2093 void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
2095 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
2096 WPAS_DBUS_NEW_INTERFACE,
2102 * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
2103 * @global: wpa_global structure
2105 * Sends PropertyChanged signals informing that debug timestamp has changed.
2107 void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
2109 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
2110 WPAS_DBUS_NEW_INTERFACE,
2116 * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
2117 * @global: wpa_global structure
2119 * Sends PropertyChanged signals informing that debug show_keys has changed.
2121 void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
2123 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
2124 WPAS_DBUS_NEW_INTERFACE,
2129 static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
2131 WPADBusArgumentFreeFunction priv_free,
2132 const struct wpa_dbus_method_desc *methods,
2133 const struct wpa_dbus_property_desc *properties,
2134 const struct wpa_dbus_signal_desc *signals)
2138 obj_desc->user_data = priv;
2139 obj_desc->user_data_free_func = priv_free;
2140 obj_desc->methods = methods;
2141 obj_desc->properties = properties;
2142 obj_desc->signals = signals;
2144 for (n = 0; properties && properties->dbus_property; properties++)
2147 obj_desc->prop_changed_flags = os_zalloc(n);
2148 if (!obj_desc->prop_changed_flags)
2149 wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
2154 static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
2155 { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
2156 (WPADBusMethodHandler) wpas_dbus_handler_create_interface,
2158 { "args", "a{sv}", ARG_IN },
2159 { "path", "o", ARG_OUT },
2163 { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
2164 (WPADBusMethodHandler) wpas_dbus_handler_remove_interface,
2166 { "path", "o", ARG_IN },
2170 { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
2171 (WPADBusMethodHandler) wpas_dbus_handler_get_interface,
2173 { "ifname", "s", ARG_IN },
2174 { "path", "o", ARG_OUT },
2178 { "ExpectDisconnect", WPAS_DBUS_NEW_INTERFACE,
2179 (WPADBusMethodHandler) wpas_dbus_handler_expect_disconnect,
2184 { NULL, NULL, NULL, { END_ARGS } }
2187 static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
2188 { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
2189 wpas_dbus_getter_debug_level,
2190 wpas_dbus_setter_debug_level,
2193 { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
2194 wpas_dbus_getter_debug_timestamp,
2195 wpas_dbus_setter_debug_timestamp,
2198 { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
2199 wpas_dbus_getter_debug_show_keys,
2200 wpas_dbus_setter_debug_show_keys,
2203 { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
2204 wpas_dbus_getter_interfaces,
2208 { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
2209 wpas_dbus_getter_eap_methods,
2213 { "Capabilities", WPAS_DBUS_NEW_INTERFACE, "as",
2214 wpas_dbus_getter_global_capabilities,
2218 #ifdef CONFIG_WIFI_DISPLAY
2219 { "WFDIEs", WPAS_DBUS_NEW_INTERFACE, "ay",
2220 wpas_dbus_getter_global_wfd_ies,
2221 wpas_dbus_setter_global_wfd_ies,
2224 #endif /* CONFIG_WIFI_DISPLAY */
2225 { NULL, NULL, NULL, NULL, NULL, NULL }
2228 static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
2229 { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
2231 { "path", "o", ARG_OUT },
2232 { "properties", "a{sv}", ARG_OUT },
2236 { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
2238 { "path", "o", ARG_OUT },
2242 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2243 { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
2245 { "properties", "a{sv}", ARG_OUT },
2249 { NULL, NULL, { END_ARGS } }
2253 static char * uscore_to_dbus(const char *uscore)
2255 const char *p = uscore;
2257 dbus_bool_t last_was_uscore = TRUE;
2259 s = str = os_zalloc(os_strlen(uscore) + 1);
2264 last_was_uscore = TRUE;
2266 *s++ = last_was_uscore ? toupper(*p) : *p;
2267 last_was_uscore = FALSE;
2276 static int wpa_dbus_ctrl_iface_props_init(struct wpas_dbus_priv *priv);
2279 static void wpa_dbus_ctrl_iface_props_deinit(struct wpas_dbus_priv *priv)
2281 int idx = priv->globals_start;
2283 /* Free all allocated property values */
2284 while (priv->all_interface_properties[idx].dbus_property)
2286 priv->all_interface_properties[idx++].dbus_property);
2287 os_free((char *) priv->all_interface_properties);
2292 * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
2293 * @global: Pointer to global data from wpa_supplicant_init()
2294 * Returns: 0 on success or -1 on failure
2296 * Initialize the dbus control interface for wpa_supplicant and start
2297 * receiving commands from external programs over the bus.
2299 int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
2301 struct wpa_dbus_object_desc *obj_desc;
2304 ret = wpa_dbus_ctrl_iface_props_init(priv);
2306 wpa_printf(MSG_ERROR,
2307 "dbus: Not enough memory to init interface properties");
2311 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2313 wpa_printf(MSG_ERROR,
2314 "Not enough memory to create object description");
2318 wpas_dbus_register(obj_desc, priv->global, NULL,
2319 wpas_dbus_global_methods,
2320 wpas_dbus_global_properties,
2321 wpas_dbus_global_signals);
2323 wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
2324 WPAS_DBUS_NEW_PATH);
2325 ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
2326 WPAS_DBUS_NEW_SERVICE,
2329 free_dbus_object_desc(obj_desc);
2333 priv->dbus_new_initialized = 1;
2337 wpa_dbus_ctrl_iface_props_deinit(priv);
2343 * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
2345 * @priv: Pointer to dbus private data from wpas_dbus_init()
2347 * Deinitialize the dbus control interface that was initialized with
2348 * wpas_dbus_ctrl_iface_init().
2350 void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *priv)
2352 if (!priv->dbus_new_initialized)
2354 wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
2355 WPAS_DBUS_NEW_PATH);
2356 dbus_connection_unregister_object_path(priv->con, WPAS_DBUS_NEW_PATH);
2357 wpa_dbus_ctrl_iface_props_deinit(priv);
2361 static void wpa_dbus_free(void *ptr)
2367 static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
2368 { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
2369 wpas_dbus_getter_network_properties,
2370 wpas_dbus_setter_network_properties,
2373 { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
2374 wpas_dbus_getter_enabled,
2375 wpas_dbus_setter_enabled,
2378 { NULL, NULL, NULL, NULL, NULL, NULL }
2382 static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
2383 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2384 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
2386 { "properties", "a{sv}", ARG_OUT },
2390 { NULL, NULL, { END_ARGS } }
2395 * wpas_dbus_register_network - Register a configured network with dbus
2396 * @wpa_s: wpa_supplicant interface structure
2397 * @ssid: network configuration data
2398 * Returns: 0 on success, -1 on failure
2400 * Registers network representing object with dbus
2402 int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
2403 struct wpa_ssid *ssid)
2405 struct wpas_dbus_priv *ctrl_iface;
2406 struct wpa_dbus_object_desc *obj_desc;
2407 struct network_handler_args *arg;
2408 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2412 * If it is a persistent group register it as such.
2413 * This is to handle cases where an interface is being initialized
2414 * with a list of networks read from config.
2416 if (network_is_persistent_group(ssid))
2417 return wpas_dbus_register_persistent_group(wpa_s, ssid);
2418 #endif /* CONFIG_P2P */
2420 /* Do nothing if the control interface is not turned on */
2421 if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
2423 ctrl_iface = wpa_s->global->dbus;
2424 if (ctrl_iface == NULL)
2427 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2428 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2429 wpa_s->dbus_new_path, ssid->id);
2431 wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
2433 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2435 wpa_printf(MSG_ERROR,
2436 "Not enough memory to create object description");
2440 /* allocate memory for handlers arguments */
2441 arg = os_zalloc(sizeof(struct network_handler_args));
2443 wpa_printf(MSG_ERROR,
2444 "Not enough memory to create arguments for method");
2451 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2452 wpas_dbus_network_properties,
2453 wpas_dbus_network_signals);
2455 if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
2456 wpa_s->ifname, obj_desc))
2459 wpas_dbus_signal_network_added(wpa_s, ssid->id);
2464 free_dbus_object_desc(obj_desc);
2470 * wpas_dbus_unregister_network - Unregister a configured network from dbus
2471 * @wpa_s: wpa_supplicant interface structure
2473 * Returns: 0 on success, -1 on failure
2475 * Unregisters network representing object from dbus
2477 int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
2479 struct wpas_dbus_priv *ctrl_iface;
2480 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2483 struct wpa_ssid *ssid;
2485 ssid = wpa_config_get_network(wpa_s->conf, nid);
2487 /* If it is a persistent group unregister it as such */
2488 if (ssid && network_is_persistent_group(ssid))
2489 return wpas_dbus_unregister_persistent_group(wpa_s, nid);
2490 #endif /* CONFIG_P2P */
2492 /* Do nothing if the control interface is not turned on */
2493 if (wpa_s->global == NULL || wpa_s->dbus_new_path == NULL)
2495 ctrl_iface = wpa_s->global->dbus;
2496 if (ctrl_iface == NULL)
2499 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2500 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2501 wpa_s->dbus_new_path, nid);
2503 wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
2505 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
2508 wpas_dbus_signal_network_removed(wpa_s, nid);
2514 static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
2515 { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2516 wpas_dbus_getter_bss_ssid,
2520 { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2521 wpas_dbus_getter_bss_bssid,
2525 { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
2526 wpas_dbus_getter_bss_privacy,
2530 { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
2531 wpas_dbus_getter_bss_mode,
2535 { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
2536 wpas_dbus_getter_bss_signal,
2540 { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
2541 wpas_dbus_getter_bss_frequency,
2545 { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
2546 wpas_dbus_getter_bss_rates,
2550 { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2551 wpas_dbus_getter_bss_wpa,
2555 { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2556 wpas_dbus_getter_bss_rsn,
2560 { "WPS", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
2561 wpas_dbus_getter_bss_wps,
2565 { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
2566 wpas_dbus_getter_bss_ies,
2570 { "Age", WPAS_DBUS_NEW_IFACE_BSS, "u",
2571 wpas_dbus_getter_bss_age,
2575 { NULL, NULL, NULL, NULL, NULL, NULL }
2579 static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
2580 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
2581 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
2583 { "properties", "a{sv}", ARG_OUT },
2587 { NULL, NULL, { END_ARGS } }
2592 * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
2593 * @wpa_s: wpa_supplicant interface structure
2594 * @bssid: scanned network bssid
2595 * @id: unique BSS identifier
2596 * Returns: 0 on success, -1 on failure
2598 * Unregisters BSS representing object from dbus
2600 int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
2601 u8 bssid[ETH_ALEN], unsigned int id)
2603 struct wpas_dbus_priv *ctrl_iface;
2604 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2606 /* Do nothing if the control interface is not turned on */
2607 if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
2609 ctrl_iface = wpa_s->global->dbus;
2610 if (ctrl_iface == NULL)
2613 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2614 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2615 wpa_s->dbus_new_path, id);
2617 wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
2619 if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
2620 wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
2625 wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
2626 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2633 * wpas_dbus_register_bss - Register a scanned BSS with dbus
2634 * @wpa_s: wpa_supplicant interface structure
2635 * @bssid: scanned network bssid
2636 * @id: unique BSS identifier
2637 * Returns: 0 on success, -1 on failure
2639 * Registers BSS representing object with dbus
2641 int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
2642 u8 bssid[ETH_ALEN], unsigned int id)
2644 struct wpas_dbus_priv *ctrl_iface;
2645 struct wpa_dbus_object_desc *obj_desc;
2646 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2647 struct bss_handler_args *arg;
2649 /* Do nothing if the control interface is not turned on */
2650 if (wpa_s == NULL || wpa_s->global == NULL || !wpa_s->dbus_new_path)
2652 ctrl_iface = wpa_s->global->dbus;
2653 if (ctrl_iface == NULL)
2656 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2657 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2658 wpa_s->dbus_new_path, id);
2660 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2662 wpa_printf(MSG_ERROR,
2663 "Not enough memory to create object description");
2667 arg = os_zalloc(sizeof(struct bss_handler_args));
2669 wpa_printf(MSG_ERROR,
2670 "Not enough memory to create arguments for handler");
2676 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2677 wpas_dbus_bss_properties,
2678 wpas_dbus_bss_signals);
2680 wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
2682 if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
2683 wpa_s->ifname, obj_desc)) {
2684 wpa_printf(MSG_ERROR,
2685 "Cannot register BSSID dbus object %s.",
2690 wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
2691 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2696 free_dbus_object_desc(obj_desc);
2701 static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
2702 { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2703 (WPADBusMethodHandler) wpas_dbus_handler_scan,
2705 { "args", "a{sv}", ARG_IN },
2709 { "SignalPoll", WPAS_DBUS_NEW_IFACE_INTERFACE,
2710 (WPADBusMethodHandler) wpas_dbus_handler_signal_poll,
2712 { "args", "a{sv}", ARG_OUT },
2716 { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2717 (WPADBusMethodHandler) wpas_dbus_handler_disconnect,
2722 { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2723 (WPADBusMethodHandler) wpas_dbus_handler_add_network,
2725 { "args", "a{sv}", ARG_IN },
2726 { "path", "o", ARG_OUT },
2730 { "Reassociate", WPAS_DBUS_NEW_IFACE_INTERFACE,
2731 (WPADBusMethodHandler) wpas_dbus_handler_reassociate,
2736 { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
2737 (WPADBusMethodHandler) wpas_dbus_handler_reattach,
2742 { "Reconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2743 (WPADBusMethodHandler) wpas_dbus_handler_reconnect,
2748 { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2749 (WPADBusMethodHandler) wpas_dbus_handler_remove_network,
2751 { "path", "o", ARG_IN },
2755 { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
2756 (WPADBusMethodHandler) wpas_dbus_handler_remove_all_networks,
2761 { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2762 (WPADBusMethodHandler) wpas_dbus_handler_select_network,
2764 { "path", "o", ARG_IN },
2768 { "NetworkReply", WPAS_DBUS_NEW_IFACE_INTERFACE,
2769 (WPADBusMethodHandler) wpas_dbus_handler_network_reply,
2771 { "path", "o", ARG_IN },
2772 { "field", "s", ARG_IN },
2773 { "value", "s", ARG_IN },
2777 #ifndef CONFIG_NO_CONFIG_BLOBS
2778 { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2779 (WPADBusMethodHandler) wpas_dbus_handler_add_blob,
2781 { "name", "s", ARG_IN },
2782 { "data", "ay", ARG_IN },
2786 { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2787 (WPADBusMethodHandler) wpas_dbus_handler_get_blob,
2789 { "name", "s", ARG_IN },
2790 { "data", "ay", ARG_OUT },
2794 { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2795 (WPADBusMethodHandler) wpas_dbus_handler_remove_blob,
2797 { "name", "s", ARG_IN },
2801 #endif /* CONFIG_NO_CONFIG_BLOBS */
2802 { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
2803 (WPADBusMethodHandler)
2804 wpas_dbus_handler_set_pkcs11_engine_and_module_path,
2806 { "pkcs11_engine_path", "s", ARG_IN },
2807 { "pkcs11_module_path", "s", ARG_IN },
2812 { "Start", WPAS_DBUS_NEW_IFACE_WPS,
2813 (WPADBusMethodHandler) wpas_dbus_handler_wps_start,
2815 { "args", "a{sv}", ARG_IN },
2816 { "output", "a{sv}", ARG_OUT },
2820 { "Cancel", WPAS_DBUS_NEW_IFACE_WPS,
2821 (WPADBusMethodHandler) wpas_dbus_handler_wps_cancel,
2826 #endif /* CONFIG_WPS */
2828 { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2829 (WPADBusMethodHandler) wpas_dbus_handler_p2p_find,
2831 { "args", "a{sv}", ARG_IN },
2835 { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2836 (WPADBusMethodHandler) wpas_dbus_handler_p2p_stop_find,
2841 { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2842 (WPADBusMethodHandler) wpas_dbus_handler_p2p_listen,
2844 { "timeout", "i", ARG_IN },
2848 { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2849 (WPADBusMethodHandler) wpas_dbus_handler_p2p_extendedlisten,
2851 { "args", "a{sv}", ARG_IN },
2855 { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2856 (WPADBusMethodHandler) wpas_dbus_handler_p2p_presence_request,
2858 { "args", "a{sv}", ARG_IN },
2862 { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2863 (WPADBusMethodHandler) wpas_dbus_handler_p2p_prov_disc_req,
2865 { "peer", "o", ARG_IN },
2866 { "config_method", "s", ARG_IN },
2870 { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2871 (WPADBusMethodHandler) wpas_dbus_handler_p2p_connect,
2873 { "args", "a{sv}", ARG_IN },
2874 { "generated_pin", "s", ARG_OUT },
2878 { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2879 (WPADBusMethodHandler) wpas_dbus_handler_p2p_group_add,
2881 { "args", "a{sv}", ARG_IN },
2885 { "Cancel", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2886 (WPADBusMethodHandler) wpas_dbus_handler_p2p_cancel,
2891 { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2892 (WPADBusMethodHandler) wpas_dbus_handler_p2p_invite,
2894 { "args", "a{sv}", ARG_IN },
2898 { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2899 (WPADBusMethodHandler) wpas_dbus_handler_p2p_disconnect,
2904 { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2905 (WPADBusMethodHandler) wpas_dbus_handler_p2p_rejectpeer,
2907 { "peer", "o", ARG_IN },
2911 { "RemoveClient", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2912 (WPADBusMethodHandler) wpas_dbus_handler_p2p_remove_client,
2914 { "args", "a{sv}", ARG_IN },
2918 { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2919 (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush,
2924 { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2925 (WPADBusMethodHandler) wpas_dbus_handler_p2p_add_service,
2927 { "args", "a{sv}", ARG_IN },
2931 { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2932 (WPADBusMethodHandler) wpas_dbus_handler_p2p_delete_service,
2934 { "args", "a{sv}", ARG_IN },
2938 { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2939 (WPADBusMethodHandler) wpas_dbus_handler_p2p_flush_service,
2944 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2945 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_req,
2947 { "args", "a{sv}", ARG_IN },
2948 { "ref", "t", ARG_OUT },
2952 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2953 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_res,
2955 { "args", "a{sv}", ARG_IN },
2959 { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2960 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_sd_cancel_req,
2962 { "args", "t", ARG_IN },
2966 { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2967 (WPADBusMethodHandler) wpas_dbus_handler_p2p_service_update,
2972 { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2973 (WPADBusMethodHandler) wpas_dbus_handler_p2p_serv_disc_external,
2975 { "arg", "i", ARG_IN },
2979 { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2980 (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
2982 { "args", "a{sv}", ARG_IN },
2983 { "path", "o", ARG_OUT },
2987 { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2988 (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
2990 { "path", "o", ARG_IN },
2994 { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2995 (WPADBusMethodHandler)
2996 wpas_dbus_handler_remove_all_persistent_groups,
3001 #endif /* CONFIG_P2P */
3002 { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
3003 (WPADBusMethodHandler) wpas_dbus_handler_flush_bss,
3005 { "age", "u", ARG_IN },
3010 { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
3011 (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
3016 { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
3017 (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
3022 #endif /* CONFIG_AP */
3023 { "EAPLogoff", WPAS_DBUS_NEW_IFACE_INTERFACE,
3024 (WPADBusMethodHandler) wpas_dbus_handler_eap_logoff,
3029 { "EAPLogon", WPAS_DBUS_NEW_IFACE_INTERFACE,
3030 (WPADBusMethodHandler) wpas_dbus_handler_eap_logon,
3035 #ifdef CONFIG_AUTOSCAN
3036 { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
3037 (WPADBusMethodHandler) wpas_dbus_handler_autoscan,
3039 { "arg", "s", ARG_IN },
3043 #endif /* CONFIG_AUTOSCAN */
3045 { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
3046 (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
3048 { "peer_address", "s", ARG_IN },
3052 { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
3053 (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
3055 { "peer_address", "s", ARG_IN },
3059 { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
3060 (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
3062 { "peer_address", "s", ARG_IN },
3063 { "status", "s", ARG_OUT },
3067 { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
3068 (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
3070 { "peer_address", "s", ARG_IN },
3074 #endif /* CONFIG_TDLS */
3075 { "VendorElemAdd", WPAS_DBUS_NEW_IFACE_INTERFACE,
3076 (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_add,
3078 { "frame_id", "i", ARG_IN },
3079 { "ielems", "ay", ARG_IN },
3083 { "VendorElemGet", WPAS_DBUS_NEW_IFACE_INTERFACE,
3084 (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_get,
3086 { "frame_id", "i", ARG_IN },
3087 { "ielems", "ay", ARG_OUT },
3091 { "VendorElemRem", WPAS_DBUS_NEW_IFACE_INTERFACE,
3092 (WPADBusMethodHandler) wpas_dbus_handler_vendor_elem_remove,
3094 { "frame_id", "i", ARG_IN },
3095 { "ielems", "ay", ARG_IN },
3099 #ifndef CONFIG_NO_CONFIG_WRITE
3100 { "SaveConfig", WPAS_DBUS_NEW_IFACE_INTERFACE,
3101 (WPADBusMethodHandler) wpas_dbus_handler_save_config,
3106 #endif /* CONFIG_NO_CONFIG_WRITE */
3107 { NULL, NULL, NULL, { END_ARGS } }
3110 static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
3111 { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
3112 wpas_dbus_getter_capabilities,
3116 { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3117 wpas_dbus_getter_state,
3121 { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
3122 wpas_dbus_getter_scanning,
3126 { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
3127 wpas_dbus_getter_ap_scan,
3128 wpas_dbus_setter_ap_scan,
3131 { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
3132 wpas_dbus_getter_bss_expire_age,
3133 wpas_dbus_setter_bss_expire_age,
3136 { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
3137 wpas_dbus_getter_bss_expire_count,
3138 wpas_dbus_setter_bss_expire_count,
3141 { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3142 wpas_dbus_getter_country,
3143 wpas_dbus_setter_country,
3146 { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3147 wpas_dbus_getter_ifname,
3151 { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3152 wpas_dbus_getter_driver,
3156 { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3157 wpas_dbus_getter_bridge_ifname,
3161 { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
3162 wpas_dbus_getter_current_bss,
3166 { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
3167 wpas_dbus_getter_current_network,
3171 { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3172 wpas_dbus_getter_current_auth_mode,
3176 { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
3177 wpas_dbus_getter_blobs,
3181 { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
3182 wpas_dbus_getter_bsss,
3186 { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
3187 wpas_dbus_getter_networks,
3191 { "FastReauth", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
3192 wpas_dbus_getter_fast_reauth,
3193 wpas_dbus_setter_fast_reauth,
3196 { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
3197 wpas_dbus_getter_scan_interval,
3198 wpas_dbus_setter_scan_interval,
3201 { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3202 wpas_dbus_getter_pkcs11_engine_path,
3206 { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
3207 wpas_dbus_getter_pkcs11_module_path,
3212 { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
3213 wpas_dbus_getter_process_credentials,
3214 wpas_dbus_setter_process_credentials,
3217 { "ConfigMethods", WPAS_DBUS_NEW_IFACE_WPS, "s",
3218 wpas_dbus_getter_config_methods,
3219 wpas_dbus_setter_config_methods,
3222 #endif /* CONFIG_WPS */
3224 { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
3225 wpas_dbus_getter_p2p_device_config,
3226 wpas_dbus_setter_p2p_device_config,
3229 { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
3230 wpas_dbus_getter_p2p_peers,
3234 { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
3235 wpas_dbus_getter_p2p_role,
3239 { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
3240 wpas_dbus_getter_p2p_group,
3244 { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
3245 wpas_dbus_getter_p2p_peergo,
3249 { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
3250 wpas_dbus_getter_persistent_groups,
3254 #endif /* CONFIG_P2P */
3255 { "DisconnectReason", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
3256 wpas_dbus_getter_disconnect_reason,
3260 { "AssocStatusCode", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
3261 wpas_dbus_getter_assoc_status_code,
3265 { NULL, NULL, NULL, NULL, NULL, NULL }
3268 static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
3269 { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
3271 { "success", "b", ARG_OUT },
3275 { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3277 { "path", "o", ARG_OUT },
3278 { "properties", "a{sv}", ARG_OUT },
3282 { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3284 { "path", "o", ARG_OUT },
3288 { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3290 { "name", "s", ARG_OUT },
3294 { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3296 { "name", "s", ARG_OUT },
3300 { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
3302 { "path", "o", ARG_OUT },
3303 { "properties", "a{sv}", ARG_OUT },
3307 { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
3309 { "path", "o", ARG_OUT },
3313 { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
3315 { "path", "o", ARG_OUT },
3319 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3320 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
3322 { "properties", "a{sv}", ARG_OUT },
3327 { "Event", WPAS_DBUS_NEW_IFACE_WPS,
3329 { "name", "s", ARG_OUT },
3330 { "args", "a{sv}", ARG_OUT },
3334 { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
3336 { "credentials", "a{sv}", ARG_OUT },
3340 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3341 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
3343 { "properties", "a{sv}", ARG_OUT },
3347 #endif /* CONFIG_WPS */
3349 { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3351 { "path", "o", ARG_OUT },
3355 { "DeviceFoundProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3357 { "path", "o", ARG_OUT },
3358 { "properties", "a{sv}", ARG_OUT },
3362 { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3364 { "path", "o", ARG_OUT },
3368 { "FindStopped", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3373 { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3375 { "peer_object", "o", ARG_OUT },
3376 { "pin", "s", ARG_OUT },
3380 { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3382 { "peer_object", "o", ARG_OUT },
3383 { "pin", "s", ARG_OUT },
3387 { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3389 { "peer_object", "o", ARG_OUT },
3393 { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3395 { "peer_object", "o", ARG_OUT },
3399 { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3401 { "peer_object", "o", ARG_OUT },
3405 { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3407 { "peer_object", "o", ARG_OUT },
3411 { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3413 { "peer_object", "o", ARG_OUT },
3414 { "status", "i", ARG_OUT },
3418 { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3420 { "properties", "a{sv}", ARG_OUT },
3424 { "GroupFormationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3426 { "reason", "s", ARG_OUT },
3430 { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3432 { "properties", "a{sv}", ARG_OUT },
3436 { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3438 { "properties", "a{sv}", ARG_OUT },
3442 { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3444 { "path", "o", ARG_OUT },
3445 { "dev_passwd_id", "q", ARG_OUT },
3446 { "device_go_intent", "y", ARG_OUT },
3450 { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3452 { "invite_result", "a{sv}", ARG_OUT },
3456 { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3458 { "properties", "a{sv}", ARG_OUT },
3462 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3464 { "sd_request", "a{sv}", ARG_OUT },
3468 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3470 { "sd_response", "a{sv}", ARG_OUT },
3474 { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3476 { "path", "o", ARG_OUT },
3477 { "properties", "a{sv}", ARG_OUT },
3481 { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3483 { "path", "o", ARG_OUT },
3487 { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3489 { "name", "s", ARG_OUT },
3490 { "args", "a{sv}", ARG_OUT },
3494 { "InvitationReceived", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3496 { "properties", "a{sv}", ARG_OUT },
3500 #endif /* CONFIG_P2P */
3502 { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
3504 { "args", "a{sv}", ARG_OUT },
3508 #endif /* CONFIG_AP */
3509 { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
3511 { "certification", "a{sv}", ARG_OUT },
3515 { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
3517 { "status", "s", ARG_OUT },
3518 { "parameter", "s", ARG_OUT },
3522 { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3524 { "name", "s", ARG_OUT },
3528 { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
3530 { "name", "s", ARG_OUT },
3534 { "NetworkRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
3536 { "path", "o", ARG_OUT },
3537 { "field", "s", ARG_OUT },
3538 { "text", "s", ARG_OUT },
3542 { NULL, NULL, { END_ARGS } }
3546 static int wpa_dbus_ctrl_iface_props_init(struct wpas_dbus_priv *priv)
3549 unsigned int i, j, count, num_const, num_globals;
3550 const char *global_name;
3551 static const char * const ignored_globals[] = {
3552 "bss_expiration_age", "bss_expiration_scan_count",
3553 "ap_scan", "country", "fast_reauth",
3554 "pkcs11_engine_path", "pkcs11_module_path"
3557 /* wpas_dbus_interface_properties terminates with a NULL element */
3558 num_const = ARRAY_SIZE(wpas_dbus_interface_properties) - 1;
3560 num_globals = wpa_config_get_num_global_field_names();
3561 priv->globals_start = num_const;
3563 /* allocate enough for all properties + terminating NULL element */
3564 all_size = (num_globals + num_const + 1) *
3565 sizeof(wpas_dbus_interface_properties[0]);
3566 priv->all_interface_properties = os_zalloc(all_size);
3567 if (!priv->all_interface_properties) {
3568 wpa_printf(MSG_ERROR,
3569 "dbus: Not enough memory for interface properties");
3573 /* Copy constant interface properties to the start of the array */
3574 os_memcpy(priv->all_interface_properties,
3575 wpas_dbus_interface_properties,
3576 sizeof(wpas_dbus_interface_properties));
3578 /* Dynamically construct interface global properties */
3579 for (i = 0, count = num_const; i < num_globals; i++) {
3580 struct wpa_dbus_property_desc *desc;
3583 /* ignore globals that are actually just methods */
3584 global_name = wpa_config_get_global_field_name(i, &no_var);
3587 /* Ignore fields already explicitly exposed */
3588 for (j = 0; j < ARRAY_SIZE(ignored_globals); j++) {
3589 if (os_strcmp(global_name, ignored_globals[j]) == 0)
3592 if (j < ARRAY_SIZE(ignored_globals))
3595 desc = &priv->all_interface_properties[count++];
3596 desc->dbus_property = uscore_to_dbus(global_name);
3597 if (!desc->dbus_property) {
3598 wpa_printf(MSG_ERROR,
3599 "dbus: Not enough memory for D-Bus property name");
3602 desc->dbus_interface = WPAS_DBUS_NEW_IFACE_INTERFACE;
3604 desc->getter = wpas_dbus_getter_iface_global;
3605 desc->setter = wpas_dbus_setter_iface_global;
3606 desc->data = global_name;
3612 wpa_dbus_ctrl_iface_props_deinit(priv);
3618 * wpas_dbus_register_interface - Register an interface with D-Bus
3619 * @wpa_s: wpa_supplicant interface structure
3620 * Returns: 0 on success, -1 on failure
3622 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
3624 struct wpa_dbus_object_desc *obj_desc = NULL;
3625 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
3628 /* Do nothing if the control interface is not turned on */
3629 if (ctrl_iface == NULL)
3632 /* Create and set the interface's object path */
3633 wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3634 if (wpa_s->dbus_new_path == NULL)
3636 next = ctrl_iface->next_objid++;
3637 os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
3638 WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
3641 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3643 wpa_printf(MSG_ERROR,
3644 "Not enough memory to create object description");
3648 wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
3649 ctrl_iface->all_interface_properties,
3650 wpas_dbus_interface_signals);
3652 wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
3653 wpa_s->dbus_new_path);
3654 if (wpa_dbus_register_object_per_iface(ctrl_iface,
3655 wpa_s->dbus_new_path,
3656 wpa_s->ifname, obj_desc))
3659 wpas_dbus_signal_interface_added(wpa_s);
3664 os_free(wpa_s->dbus_new_path);
3665 wpa_s->dbus_new_path = NULL;
3666 free_dbus_object_desc(obj_desc);
3672 * wpas_dbus_unregister_interface - Unregister the interface from D-Bus
3673 * @wpa_s: wpa_supplicant interface structure
3674 * Returns: 0 on success, -1 on failure
3676 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
3678 struct wpas_dbus_priv *ctrl_iface;
3680 /* Do nothing if the control interface is not turned on */
3681 if (wpa_s == NULL || wpa_s->global == NULL)
3683 ctrl_iface = wpa_s->global->dbus;
3684 if (ctrl_iface == NULL || wpa_s->dbus_new_path == NULL)
3687 wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
3688 wpa_s->dbus_new_path);
3691 if (wpa_s->preq_notify_peer) {
3692 wpas_dbus_unsubscribe_noc(ctrl_iface);
3693 os_free(wpa_s->preq_notify_peer);
3694 wpa_s->preq_notify_peer = NULL;
3696 #endif /* CONFIG_AP */
3698 if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
3699 wpa_s->dbus_new_path))
3702 wpas_dbus_signal_interface_removed(wpa_s);
3704 os_free(wpa_s->dbus_new_path);
3705 wpa_s->dbus_new_path = NULL;
3712 static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
3713 { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3714 wpas_dbus_getter_p2p_peer_device_name,
3718 { "Manufacturer", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3719 wpas_dbus_getter_p2p_peer_manufacturer,
3723 { "ModelName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3724 wpas_dbus_getter_p2p_peer_modelname,
3728 { "ModelNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3729 wpas_dbus_getter_p2p_peer_modelnumber,
3733 { "SerialNumber", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
3734 wpas_dbus_getter_p2p_peer_serialnumber,
3738 { "PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3739 wpas_dbus_getter_p2p_peer_primary_device_type,
3743 { "config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "q",
3744 wpas_dbus_getter_p2p_peer_config_method,
3748 { "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
3749 wpas_dbus_getter_p2p_peer_level,
3753 { "devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3754 wpas_dbus_getter_p2p_peer_device_capability,
3758 { "groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
3759 wpas_dbus_getter_p2p_peer_group_capability,
3763 { "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3764 wpas_dbus_getter_p2p_peer_secondary_device_types,
3768 { "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
3769 wpas_dbus_getter_p2p_peer_vendor_extension,
3773 { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3774 wpas_dbus_getter_p2p_peer_ies,
3778 { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
3779 wpas_dbus_getter_p2p_peer_device_address,
3783 { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
3784 wpas_dbus_getter_p2p_peer_groups,
3788 { NULL, NULL, NULL, NULL, NULL, NULL }
3791 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
3792 /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
3793 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_P2P_PEER,
3795 { "properties", "a{sv}", ARG_OUT },
3799 { NULL, NULL, { END_ARGS } }
3803 * wpas_dbus_signal_peer - Send a peer related event signal
3804 * @wpa_s: %wpa_supplicant network interface data
3805 * @dev: peer device object
3806 * @interface: name of the interface emitting this signal.
3807 * In case of peer objects, it would be emitted by either
3808 * the "interface object" or by "peer objects"
3809 * @sig_name: signal name - DeviceFound
3810 * @properties: Whether to add a second argument with object properties
3812 * Notify listeners about event related with p2p peer device
3814 static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
3815 const u8 *dev_addr, const char *interface,
3816 const char *sig_name, int properties)
3818 struct wpas_dbus_priv *iface;
3820 DBusMessageIter iter;
3821 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
3823 if (wpa_s->p2p_mgmt)
3824 wpa_s = wpa_s->parent;
3826 iface = wpa_s->global->dbus;
3828 /* Do nothing if the control interface is not turned on */
3829 if (iface == NULL || !wpa_s->dbus_new_path)
3832 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3833 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3834 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3836 msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
3841 dbus_message_iter_init_append(msg, &iter);
3842 path = peer_obj_path;
3843 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
3845 (properties && !wpa_dbus_get_object_properties(
3846 iface, peer_obj_path, WPAS_DBUS_NEW_IFACE_P2P_PEER,
3848 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
3850 dbus_connection_send(iface->con, msg, NULL);
3852 dbus_message_unref(msg);
3857 * wpas_dbus_signal_peer_found - Send a peer found signal
3858 * @wpa_s: %wpa_supplicant network interface data
3859 * @dev_addr: Peer P2P Device Address
3861 * Notify listeners about find a p2p peer device found
3863 void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
3866 wpas_dbus_signal_peer(wpa_s, dev_addr,
3867 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3868 "DeviceFound", FALSE);
3870 wpas_dbus_signal_peer(wpa_s, dev_addr,
3871 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3872 "DeviceFoundProperties", TRUE);
3876 * wpas_dbus_signal_peer_lost - Send a peer lost signal
3877 * @wpa_s: %wpa_supplicant network interface data
3878 * @dev_addr: Peer P2P Device Address
3880 * Notify listeners about lost a p2p peer device
3882 void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
3885 wpas_dbus_signal_peer(wpa_s, dev_addr,
3886 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
3887 "DeviceLost", FALSE);
3891 * wpas_dbus_register_peer - Register a discovered peer object with dbus
3892 * @wpa_s: wpa_supplicant interface structure
3893 * @dev_addr: P2P Device Address of the peer
3894 * Returns: 0 on success, -1 on failure
3896 * Registers network representing object with dbus
3898 int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
3900 struct wpas_dbus_priv *ctrl_iface;
3901 struct wpa_dbus_object_desc *obj_desc;
3902 struct peer_handler_args *arg;
3903 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3905 /* Do nothing if the control interface is not turned on */
3906 if (wpa_s == NULL || wpa_s->global == NULL)
3909 ctrl_iface = wpa_s->global->dbus;
3910 if (ctrl_iface == NULL)
3913 wpa_s = wpa_s->parent->parent;
3914 if (!wpa_s->dbus_new_path)
3917 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3918 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3919 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3921 wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
3923 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3925 wpa_printf(MSG_ERROR,
3926 "Not enough memory to create object description");
3930 /* allocate memory for handlers arguments */
3931 arg = os_zalloc(sizeof(struct peer_handler_args));
3933 wpa_printf(MSG_ERROR,
3934 "Not enough memory to create arguments for method");
3939 os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
3941 wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
3943 wpas_dbus_p2p_peer_properties,
3944 wpas_dbus_p2p_peer_signals);
3946 if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
3947 wpa_s->ifname, obj_desc))
3953 free_dbus_object_desc(obj_desc);
3958 * wpas_dbus_unregister_peer - Unregister a peer object with dbus
3959 * @wpa_s: wpa_supplicant interface structure
3960 * @dev_addr: p2p device addr
3961 * Returns: 0 on success, -1 on failure
3963 * Registers network representing object with dbus
3965 int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
3968 struct wpas_dbus_priv *ctrl_iface;
3969 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3972 /* Do nothing if the control interface is not turned on */
3973 if (wpa_s == NULL || wpa_s->global == NULL)
3976 wpa_s = wpa_s->parent->parent;
3977 if (!wpa_s->dbus_new_path)
3980 ctrl_iface = wpa_s->global->dbus;
3981 if (ctrl_iface == NULL)
3984 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3985 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
3986 wpa_s->dbus_new_path, MAC2STR(dev_addr));
3988 wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
3990 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
3997 * wpas_dbus_signal_p2p_find_stopped - Send P2P Find stopped signal
3998 * @wpa_s: %wpa_supplicant network interface data
4000 * Notify listeners about P2P Find stopped
4002 void wpas_dbus_signal_p2p_find_stopped(struct wpa_supplicant *wpa_s)
4004 struct wpas_dbus_priv *iface;
4007 iface = wpa_s->global->dbus;
4009 /* Do nothing if the control interface is not turned on */
4010 if (iface == NULL || !wpa_s->dbus_new_path)
4013 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
4014 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
4019 dbus_connection_send(iface->con, msg, NULL);
4021 dbus_message_unref(msg);
4026 * wpas_dbus_signal_peer_groups_changed - Send peer group change property signal
4027 * @wpa_s: %wpa_supplicant network interface data
4028 * @dev_addr: P2P Device Address
4030 * Notify listeners about peer Groups property changes.
4032 void wpas_dbus_signal_peer_groups_changed(struct wpa_supplicant *wpa_s,
4035 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
4037 if (wpa_s->p2p_mgmt)
4038 wpa_s = wpa_s->parent;
4040 if (!wpa_s->dbus_new_path)
4042 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
4043 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
4044 wpa_s->dbus_new_path, MAC2STR(dev_addr));
4046 wpa_dbus_mark_property_changed(wpa_s->global->dbus, peer_obj_path,
4047 WPAS_DBUS_NEW_IFACE_P2P_PEER, "Groups");
4051 static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
4052 { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
4053 wpas_dbus_getter_p2p_group_members,
4057 { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
4058 wpas_dbus_getter_p2p_group,
4062 { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
4063 wpas_dbus_getter_p2p_role,
4067 { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
4068 wpas_dbus_getter_p2p_group_ssid,
4072 { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
4073 wpas_dbus_getter_p2p_group_bssid,
4077 { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
4078 wpas_dbus_getter_p2p_group_frequency,
4082 { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
4083 wpas_dbus_getter_p2p_group_passphrase,
4087 { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
4088 wpas_dbus_getter_p2p_group_psk,
4092 { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
4093 wpas_dbus_getter_p2p_group_vendor_ext,
4094 wpas_dbus_setter_p2p_group_vendor_ext,
4097 { NULL, NULL, NULL, NULL, NULL, NULL }
4100 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
4101 { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
4103 { "peer", "o", ARG_OUT },
4107 { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
4109 { "peer", "o", ARG_OUT },
4113 { NULL, NULL, { END_ARGS } }
4117 * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
4118 * @wpa_s: wpa_supplicant interface structure
4119 * @ssid: SSID struct
4120 * Returns: 0 on success, -1 on failure
4122 * Registers p2p group representing object with dbus
4124 void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
4125 struct wpa_ssid *ssid)
4127 struct wpas_dbus_priv *ctrl_iface;
4128 struct wpa_dbus_object_desc *obj_desc;
4129 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
4131 /* Do nothing if the control interface is not turned on */
4132 if (wpa_s == NULL || wpa_s->global == NULL)
4135 ctrl_iface = wpa_s->global->dbus;
4136 if (ctrl_iface == NULL)
4139 if (wpa_s->dbus_groupobj_path) {
4140 wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
4141 __func__, wpa_s->dbus_groupobj_path);
4145 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
4148 wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
4149 if (wpa_s->dbus_groupobj_path == NULL)
4152 wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
4154 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
4156 wpa_printf(MSG_ERROR,
4157 "Not enough memory to create object description");
4161 wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
4162 wpas_dbus_p2p_group_properties,
4163 wpas_dbus_p2p_group_signals);
4165 if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
4166 wpa_s->ifname, obj_desc))
4172 if (wpa_s->dbus_groupobj_path) {
4173 os_free(wpa_s->dbus_groupobj_path);
4174 wpa_s->dbus_groupobj_path = NULL;
4177 free_dbus_object_desc(obj_desc);
4181 * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
4182 * @wpa_s: wpa_supplicant interface structure
4183 * @ssid: network name of the p2p group started
4185 void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
4186 const struct wpa_ssid *ssid)
4188 struct wpas_dbus_priv *ctrl_iface;
4190 /* Do nothing if the control interface is not turned on */
4191 if (wpa_s == NULL || wpa_s->global == NULL)
4194 if (wpa_s->p2p_mgmt)
4195 wpa_s = wpa_s->parent;
4197 ctrl_iface = wpa_s->global->dbus;
4198 if (ctrl_iface == NULL)
4201 if (!wpa_s->dbus_groupobj_path) {
4202 wpa_printf(MSG_DEBUG,
4203 "%s: Group object '%s' already unregistered",
4204 __func__, wpa_s->dbus_groupobj_path);
4208 peer_groups_changed(wpa_s);
4210 wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
4211 wpa_s->dbus_groupobj_path);
4213 wpa_dbus_unregister_object_per_iface(ctrl_iface,
4214 wpa_s->dbus_groupobj_path);
4216 os_free(wpa_s->dbus_groupobj_path);
4217 wpa_s->dbus_groupobj_path = NULL;
4220 static const struct wpa_dbus_property_desc
4221 wpas_dbus_persistent_group_properties[] = {
4222 { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
4223 wpas_dbus_getter_persistent_group_properties,
4224 wpas_dbus_setter_persistent_group_properties,
4227 { NULL, NULL, NULL, NULL, NULL, NULL }
4230 /* No signals intended for persistent group objects */
4233 * wpas_dbus_register_persistent_group - Register a configured(saved)
4234 * persistent group with dbus
4235 * @wpa_s: wpa_supplicant interface structure
4236 * @ssid: persistent group (still represented as a network within wpa)
4237 * configuration data
4238 * Returns: 0 on success, -1 on failure
4240 * Registers a persistent group representing object with dbus.
4242 int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
4243 struct wpa_ssid *ssid)
4245 struct wpas_dbus_priv *ctrl_iface;
4246 struct wpa_dbus_object_desc *obj_desc;
4247 struct network_handler_args *arg;
4248 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
4250 /* Do nothing if the control interface is not turned on */
4251 if (wpa_s == NULL || wpa_s->global == NULL)
4253 wpa_s = wpa_s->parent->parent;
4254 if (!wpa_s->dbus_new_path)
4257 /* Make sure ssid is a persistent group */
4258 if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
4259 return -1; /* should we return w/o complaining? */
4261 if (wpa_s->p2p_mgmt)
4262 wpa_s = wpa_s->parent;
4264 ctrl_iface = wpa_s->global->dbus;
4265 if (ctrl_iface == NULL)
4269 * Intentionally not coming up with different numbering scheme
4270 * for persistent groups.
4272 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
4273 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
4274 wpa_s->dbus_new_path, ssid->id);
4276 wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
4278 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
4280 wpa_printf(MSG_ERROR,
4281 "dbus: Not enough memory to create object description");
4286 * Reusing the same context structure as that for networks
4287 * since these are represented using same data structure.
4289 /* allocate memory for handlers arguments */
4290 arg = os_zalloc(sizeof(struct network_handler_args));
4292 wpa_printf(MSG_ERROR,
4293 "dbus: Not enough memory to create arguments for method");
4300 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
4301 wpas_dbus_persistent_group_properties,
4304 if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
4305 wpa_s->ifname, obj_desc))
4308 wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
4313 free_dbus_object_desc(obj_desc);
4319 * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
4321 * @wpa_s: wpa_supplicant interface structure
4323 * Returns: 0 on success, -1 on failure
4325 * Unregisters persistent group representing object from dbus
4327 * NOTE: There is a slight issue with the semantics here. While the
4328 * implementation simply means the persistent group is unloaded from memory,
4329 * it should not get interpreted as the group is actually being erased/removed
4330 * from persistent storage as well.
4332 int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
4335 struct wpas_dbus_priv *ctrl_iface;
4336 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
4339 /* Do nothing if the control interface is not turned on */
4340 if (wpa_s == NULL || wpa_s->global == NULL)
4343 wpa_s = wpa_s->parent->parent;
4345 ctrl_iface = wpa_s->global->dbus;
4346 if (ctrl_iface == NULL || !wpa_s->dbus_new_path)
4349 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
4350 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
4351 wpa_s->dbus_new_path, nid);
4353 wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
4355 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
4358 wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
4363 #endif /* CONFIG_P2P */