Standardize on a single definition of auth_alg bitfield values
[hostap-gosc2009.git] / wpa_supplicant / dbus / dbus_new.c
blob2b2a24c1996147094cbbb33259df309cbd0cd1c1
1 /*
2 * WPA Supplicant / dbus-based control interface
3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4 * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
5 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
12 * license.
14 * See README and COPYING for more details.
17 #include "includes.h"
19 #include "common.h"
20 #include "wps/wps.h"
21 #include "../config.h"
22 #include "../wpa_supplicant_i.h"
23 #include "../bss.h"
24 #include "dbus_new_helpers.h"
25 #include "dbus_dict_helpers.h"
26 #include "dbus_new.h"
27 #include "dbus_new_handlers.h"
28 #include "dbus_common.h"
29 #include "dbus_common_i.h"
32 /**
33 * wpas_dbus_signal_interface - Send a interface related event signal
34 * @wpa_s: %wpa_supplicant network interface data
35 * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
36 * @properties: Whether to add second argument with object properties
38 * Notify listeners about event related with interface
40 static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
41 const char *sig_name, int properties)
43 struct wpas_dbus_priv *iface;
44 DBusMessage *msg;
45 DBusMessageIter iter, iter_dict;
47 iface = wpa_s->global->dbus;
49 /* Do nothing if the control interface is not turned on */
50 if (iface == NULL)
51 return;
53 msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
54 WPAS_DBUS_NEW_INTERFACE, sig_name);
55 if (msg == NULL)
56 return;
58 dbus_message_iter_init_append(msg, &iter);
59 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
60 &wpa_s->dbus_new_path))
61 goto err;
63 if (properties) {
64 if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
65 goto err;
67 wpa_dbus_get_object_properties(iface, wpa_s->dbus_new_path,
68 WPAS_DBUS_NEW_IFACE_INTERFACE,
69 &iter_dict);
71 if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
72 goto err;
75 dbus_connection_send(iface->con, msg, NULL);
76 dbus_message_unref(msg);
77 return;
79 err:
80 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
81 dbus_message_unref(msg);
85 /**
86 * wpas_dbus_signal_interface_added - Send a interface created signal
87 * @wpa_s: %wpa_supplicant network interface data
89 * Notify listeners about creating new interface
91 static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
93 wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
97 /**
98 * wpas_dbus_signal_interface_removed - Send a interface removed signal
99 * @wpa_s: %wpa_supplicant network interface data
101 * Notify listeners about removing interface
103 static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
105 wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
111 * wpas_dbus_signal_scan_done - send scan done signal
112 * @wpa_s: %wpa_supplicant network interface data
113 * @success: indicates if scanning succeed or failed
115 * Notify listeners about finishing a scan
117 void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
119 struct wpas_dbus_priv *iface;
120 DBusMessage *msg;
121 dbus_bool_t succ;
123 iface = wpa_s->global->dbus;
125 /* Do nothing if the control interface is not turned on */
126 if (iface == NULL)
127 return;
129 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
130 WPAS_DBUS_NEW_IFACE_INTERFACE,
131 "ScanDone");
132 if (msg == NULL)
133 return;
135 succ = success ? TRUE : FALSE;
136 if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
137 DBUS_TYPE_INVALID))
138 dbus_connection_send(iface->con, msg, NULL);
139 else
140 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
141 dbus_message_unref(msg);
146 * wpas_dbus_signal_blob - Send a BSS related event signal
147 * @wpa_s: %wpa_supplicant network interface data
148 * @bss_obj_path: BSS object path
149 * @sig_name: signal name - BSSAdded or BSSRemoved
150 * @properties: Whether to add second argument with object properties
152 * Notify listeners about event related with BSS
154 static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
155 const char *bss_obj_path,
156 const char *sig_name, int properties)
158 struct wpas_dbus_priv *iface;
159 DBusMessage *msg;
160 DBusMessageIter iter, iter_dict;
162 iface = wpa_s->global->dbus;
164 /* Do nothing if the control interface is not turned on */
165 if (iface == NULL)
166 return;
168 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
169 WPAS_DBUS_NEW_IFACE_INTERFACE,
170 sig_name);
171 if (msg == NULL)
172 return;
174 dbus_message_iter_init_append(msg, &iter);
175 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
176 &bss_obj_path))
177 goto err;
179 if (properties) {
180 if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
181 goto err;
183 wpa_dbus_get_object_properties(iface, bss_obj_path,
184 WPAS_DBUS_NEW_IFACE_BSSID,
185 &iter_dict);
187 if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
188 goto err;
191 dbus_connection_send(iface->con, msg, NULL);
192 dbus_message_unref(msg);
193 return;
195 err:
196 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
197 dbus_message_unref(msg);
202 * wpas_dbus_signal_bss_added - Send a BSS added signal
203 * @wpa_s: %wpa_supplicant network interface data
204 * @bss_obj_path: new BSS object path
206 * Notify listeners about adding new BSS
208 static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
209 const char *bss_obj_path)
211 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
216 * wpas_dbus_signal_bss_removed - Send a BSS removed signal
217 * @wpa_s: %wpa_supplicant network interface data
218 * @bss_obj_path: BSS object path
220 * Notify listeners about removing BSS
222 static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
223 const char *bss_obj_path)
225 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
230 * wpas_dbus_signal_blob - Send a blob related event signal
231 * @wpa_s: %wpa_supplicant network interface data
232 * @name: blob name
233 * @sig_name: signal name - BlobAdded or BlobRemoved
235 * Notify listeners about event related with blob
237 static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
238 const char *name, const char *sig_name)
240 struct wpas_dbus_priv *iface;
241 DBusMessage *msg;
243 iface = wpa_s->global->dbus;
245 /* Do nothing if the control interface is not turned on */
246 if (iface == NULL)
247 return;
249 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
250 WPAS_DBUS_NEW_IFACE_INTERFACE,
251 sig_name);
252 if (msg == NULL)
253 return;
255 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
256 DBUS_TYPE_INVALID))
257 dbus_connection_send(iface->con, msg, NULL);
258 else
259 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
260 dbus_message_unref(msg);
265 * wpas_dbus_signal_blob_added - Send a blob added signal
266 * @wpa_s: %wpa_supplicant network interface data
267 * @name: blob name
269 * Notify listeners about adding a new blob
271 void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
272 const char *name)
274 wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
279 * wpas_dbus_signal_blob_removed - Send a blob removed signal
280 * @wpa_s: %wpa_supplicant network interface data
281 * @name: blob name
283 * Notify listeners about removing blob
285 void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
286 const char *name)
288 wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
293 * wpas_dbus_signal_network - Send a network related event signal
294 * @wpa_s: %wpa_supplicant network interface data
295 * @id: new network id
296 * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
297 * @properties: determines if add second argument with object properties
299 * Notify listeners about event related with configured network
301 static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
302 int id, const char *sig_name,
303 int properties)
305 struct wpas_dbus_priv *iface;
306 DBusMessage *msg;
307 DBusMessageIter iter, iter_dict;
308 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
310 iface = wpa_s->global->dbus;
312 /* Do nothing if the control interface is not turned on */
313 if (iface == NULL)
314 return;
316 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
317 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
318 wpa_s->dbus_new_path, id);
320 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
321 WPAS_DBUS_NEW_IFACE_INTERFACE,
322 sig_name);
323 if (msg == NULL)
324 return;
326 dbus_message_iter_init_append(msg, &iter);
327 path = net_obj_path;
328 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
329 &path))
330 goto err;
332 if (properties) {
333 if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
334 goto err;
336 wpa_dbus_get_object_properties(iface, net_obj_path,
337 WPAS_DBUS_NEW_IFACE_NETWORK,
338 &iter_dict);
340 if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
341 goto err;
344 dbus_connection_send(iface->con, msg, NULL);
346 dbus_message_unref(msg);
347 return;
349 err:
350 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
351 dbus_message_unref(msg);
356 * wpas_dbus_signal_network_added - Send a network added signal
357 * @wpa_s: %wpa_supplicant network interface data
358 * @id: new network id
360 * Notify listeners about adding new network
362 static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
363 int id)
365 wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
370 * wpas_dbus_signal_network_removed - Send a network removed signal
371 * @wpa_s: %wpa_supplicant network interface data
372 * @id: network id
374 * Notify listeners about removing a network
376 static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
377 int id)
379 wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
384 * wpas_dbus_signal_network_selected - Send a network selected signal
385 * @wpa_s: %wpa_supplicant network interface data
386 * @id: network id
388 * Notify listeners about selecting a network
390 void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
392 wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
396 static void str_to_lower(char *s)
398 while (*s) {
399 *s = tolower(*s);
400 s++;
406 * wpas_dbus_signal_state_changed - Send a state changed signal
407 * @wpa_s: %wpa_supplicant network interface data
408 * @new_state: new state wpa_supplicant is entering
409 * @old_state: old state wpa_supplicant is leaving
411 * Notify listeners that wpa_supplicant has changed state
413 void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
414 enum wpa_states new_state,
415 enum wpa_states old_state)
417 struct wpas_dbus_priv *iface;
418 DBusMessage *msg;
419 char *new_state_str, *old_state_str;
421 /* Do nothing if the control interface is not turned on */
422 if (wpa_s->global == NULL)
423 return;
424 iface = wpa_s->global->dbus;
425 if (iface == NULL)
426 return;
428 /* Only send signal if state really changed */
429 if (new_state == old_state)
430 return;
432 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
433 WPAS_DBUS_NEW_IFACE_INTERFACE,
434 "StateChanged");
435 if (msg == NULL)
436 return;
438 new_state_str = os_strdup(wpa_supplicant_state_txt(new_state));
439 old_state_str = os_strdup(wpa_supplicant_state_txt(old_state));
440 if (new_state_str == NULL || old_state_str == NULL)
441 goto out;
443 /* make state string lowercase to fit new DBus API convention */
444 str_to_lower(new_state_str);
445 str_to_lower(old_state_str);
447 if (!dbus_message_append_args(msg,
448 DBUS_TYPE_STRING, &new_state_str,
449 DBUS_TYPE_STRING, &old_state_str,
450 DBUS_TYPE_INVALID)) {
451 wpa_printf(MSG_ERROR, "dbus: Failed to construct state change "
452 "signal");
453 goto out;
456 dbus_connection_send(iface->con, msg, NULL);
458 out:
459 dbus_message_unref(msg);
460 os_free(new_state_str);
461 os_free(old_state_str);
466 * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
467 * @wpa_s: %wpa_supplicant network interface data
468 * @ssid: configured network which Enabled property has changed
470 * Sends PropertyChanged signals containing new value of Enabled property
471 * for specified network
473 void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
474 struct wpa_ssid *ssid)
477 struct network_handler_args args = { wpa_s, ssid };
478 char path[WPAS_DBUS_OBJECT_PATH_MAX];
479 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
480 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
481 wpa_s->dbus_new_path, ssid->id);
483 wpa_dbus_signal_property_changed(wpa_s->global->dbus,
484 (WPADBusPropertyAccessor)
485 wpas_dbus_getter_enabled, &args,
486 path, WPAS_DBUS_NEW_IFACE_NETWORK,
487 "Enabled");
491 #ifdef CONFIG_WPS
494 * wpas_dbus_signal_wps_event_success - Signals Success WPS event
495 * @wpa_s: %wpa_supplicant network interface data
497 * Sends Event dbus signal with name "success" and empty dict as arguments
499 void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
502 DBusMessage *msg;
503 DBusMessageIter iter, dict_iter;
504 struct wpas_dbus_priv *iface;
505 char *key = "success";
507 iface = wpa_s->global->dbus;
509 /* Do nothing if the control interface is not turned on */
510 if (iface == NULL)
511 return;
513 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
514 WPAS_DBUS_NEW_IFACE_WPS, "Event");
515 if (msg == NULL)
516 return;
518 dbus_message_iter_init_append(msg, &iter);
520 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
521 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
522 !wpa_dbus_dict_close_write(&iter, &dict_iter))
523 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
524 else
525 dbus_connection_send(iface->con, msg, NULL);
527 dbus_message_unref(msg);
532 * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
533 * @wpa_s: %wpa_supplicant network interface data
535 * Sends Event dbus signal with name "fail" and dictionary containing
536 * "msg field with fail message number (int32) as arguments
538 void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
539 struct wps_event_fail *fail)
542 DBusMessage *msg;
543 DBusMessageIter iter, dict_iter;
544 struct wpas_dbus_priv *iface;
545 char *key = "fail";
547 iface = wpa_s->global->dbus;
549 /* Do nothing if the control interface is not turned on */
550 if (iface == NULL)
551 return;
553 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
554 WPAS_DBUS_NEW_IFACE_WPS, "Event");
555 if (msg == NULL)
556 return;
558 dbus_message_iter_init_append(msg, &iter);
560 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
561 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
562 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
563 !wpa_dbus_dict_close_write(&iter, &dict_iter))
564 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
565 else
566 dbus_connection_send(iface->con, msg, NULL);
568 dbus_message_unref(msg);
573 * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
574 * @wpa_s: %wpa_supplicant network interface data
576 * Sends Event dbus signal with name "m2d" and dictionary containing
577 * fields of wps_event_m2d structure.
579 void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
580 struct wps_event_m2d *m2d)
583 DBusMessage *msg;
584 DBusMessageIter iter, dict_iter;
585 struct wpas_dbus_priv *iface;
586 char *key = "m2d";
588 iface = wpa_s->global->dbus;
590 /* Do nothing if the control interface is not turned on */
591 if (iface == NULL)
592 return;
594 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
595 WPAS_DBUS_NEW_IFACE_WPS, "Event");
596 if (msg == NULL)
597 return;
599 dbus_message_iter_init_append(msg, &iter);
601 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
602 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
603 !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
604 m2d->config_methods) ||
605 !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
606 (const char *) m2d->manufacturer,
607 m2d->manufacturer_len) ||
608 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
609 (const char *) m2d->model_name,
610 m2d->model_name_len) ||
611 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
612 (const char *) m2d->model_number,
613 m2d->model_number_len) ||
614 !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
615 (const char *)
616 m2d->serial_number,
617 m2d->serial_number_len) ||
618 !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
619 (const char *) m2d->dev_name,
620 m2d->dev_name_len) ||
621 !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
622 (const char *)
623 m2d->primary_dev_type, 8) ||
624 !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
625 m2d->config_error) ||
626 !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
627 m2d->dev_password_id) ||
628 !wpa_dbus_dict_close_write(&iter, &dict_iter))
629 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
630 else
631 dbus_connection_send(iface->con, msg, NULL);
633 dbus_message_unref(msg);
638 * wpas_dbus_signal_wps_cred - Signals new credentials
639 * @wpa_s: %wpa_supplicant network interface data
641 * Sends signal with credentials in directory argument
643 void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
644 const struct wps_credential *cred)
646 DBusMessage *msg;
647 DBusMessageIter iter, dict_iter;
648 struct wpas_dbus_priv *iface;
649 char *auth_type[6]; /* we have six possible authorization types */
650 int at_num = 0;
651 char *encr_type[4]; /* we have four possible encryption types */
652 int et_num = 0;
654 iface = wpa_s->global->dbus;
656 /* Do nothing if the control interface is not turned on */
657 if (iface == NULL)
658 return;
660 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
661 WPAS_DBUS_NEW_IFACE_WPS,
662 "Credentials");
663 if (msg == NULL)
664 return;
666 dbus_message_iter_init_append(msg, &iter);
667 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
668 goto nomem;
670 if (cred->auth_type & WPS_AUTH_OPEN)
671 auth_type[at_num++] = "open";
672 if (cred->auth_type & WPS_AUTH_WPAPSK)
673 auth_type[at_num++] = "wpa-psk";
674 if (cred->auth_type & WPS_AUTH_SHARED)
675 auth_type[at_num++] = "shared";
676 if (cred->auth_type & WPS_AUTH_WPA)
677 auth_type[at_num++] = "wpa-eap";
678 if (cred->auth_type & WPS_AUTH_WPA2)
679 auth_type[at_num++] = "wpa2-eap";
680 if (cred->auth_type & WPS_AUTH_WPA2PSK)
681 auth_type[at_num++] =
682 "wpa2-psk";
684 if (cred->encr_type & WPS_ENCR_NONE)
685 encr_type[et_num++] = "none";
686 if (cred->encr_type & WPS_ENCR_WEP)
687 encr_type[et_num++] = "wep";
688 if (cred->encr_type & WPS_ENCR_TKIP)
689 encr_type[et_num++] = "tkip";
690 if (cred->encr_type & WPS_ENCR_AES)
691 encr_type[et_num++] = "aes";
693 if (wpa_s->current_ssid) {
694 if (!wpa_dbus_dict_append_byte_array(
695 &dict_iter, "BSSID",
696 (const char *) wpa_s->current_ssid->bssid,
697 ETH_ALEN))
698 goto nomem;
701 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
702 (const char *) cred->ssid,
703 cred->ssid_len) ||
704 !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
705 (const char **) auth_type,
706 at_num) ||
707 !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
708 (const char **) encr_type,
709 et_num) ||
710 !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
711 (const char *) cred->key,
712 cred->key_len) ||
713 !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
714 cred->key_idx) ||
715 !wpa_dbus_dict_close_write(&iter, &dict_iter))
716 goto nomem;
718 dbus_connection_send(iface->con, msg, NULL);
720 nomem:
721 dbus_message_unref(msg);
724 #endif /* CONFIG_WPS */
728 * wpas_dbus_signal_prop_changed - Signals change of property
729 * @wpa_s: %wpa_supplicant network interface data
730 * @property: indicates which property has changed
732 * Sends ProertyChanged signals with path, interface and arguments
733 * depending on which property has changed.
735 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
736 enum wpas_dbus_prop property)
738 WPADBusPropertyAccessor getter;
739 char *prop;
741 switch (property) {
742 case WPAS_DBUS_PROP_AP_SCAN:
743 getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
744 prop = "ApScan";
745 break;
746 case WPAS_DBUS_PROP_SCANNING:
747 getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
748 prop = "Scanning";
749 break;
750 case WPAS_DBUS_PROP_CURRENT_BSS:
751 getter = (WPADBusPropertyAccessor)
752 wpas_dbus_getter_current_bss;
753 prop = "CurrentBSS";
754 break;
755 case WPAS_DBUS_PROP_CURRENT_NETWORK:
756 getter = (WPADBusPropertyAccessor)
757 wpas_dbus_getter_current_network;
758 prop = "CurrentNetwork";
759 break;
760 default:
761 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
762 __func__, property);
763 return;
766 wpa_dbus_signal_property_changed(wpa_s->global->dbus,
767 getter, wpa_s, wpa_s->dbus_new_path,
768 WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
773 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
774 * @global: wpa_global structure
776 * Sends ProertyChanged signals informing that debug level has changed.
778 void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
780 wpa_dbus_signal_property_changed(global->dbus,
781 (WPADBusPropertyAccessor)
782 wpas_dbus_getter_debug_level,
783 global, WPAS_DBUS_NEW_PATH,
784 WPAS_DBUS_NEW_INTERFACE,
785 "DebugLevel");
790 * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
791 * @global: wpa_global structure
793 * Sends ProertyChanged signals informing that debug timestamp has changed.
795 void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
797 wpa_dbus_signal_property_changed(global->dbus,
798 (WPADBusPropertyAccessor)
799 wpas_dbus_getter_debug_timestamp,
800 global, WPAS_DBUS_NEW_PATH,
801 WPAS_DBUS_NEW_INTERFACE,
802 "DebugTimestamp");
807 * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
808 * @global: wpa_global structure
810 * Sends ProertyChanged signals informing that debug show_keys has changed.
812 void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
814 wpa_dbus_signal_property_changed(global->dbus,
815 (WPADBusPropertyAccessor)
816 wpas_dbus_getter_debug_show_keys,
817 global, WPAS_DBUS_NEW_PATH,
818 WPAS_DBUS_NEW_INTERFACE,
819 "DebugShowKeys");
823 static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
824 void *priv,
825 WPADBusArgumentFreeFunction priv_free,
826 const struct wpa_dbus_method_desc *methods,
827 const struct wpa_dbus_property_desc *properties,
828 const struct wpa_dbus_signal_desc *signals)
830 obj_desc->user_data = priv;
831 obj_desc->user_data_free_func = priv_free;
832 obj_desc->methods = methods;
833 obj_desc->properties = properties;
834 obj_desc->signals = signals;
838 static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
839 { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
840 (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
842 { "args", "a{sv}", ARG_IN },
843 { "path", "o", ARG_OUT },
844 END_ARGS
847 { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
848 (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
850 { "path", "o", ARG_IN },
851 END_ARGS
854 { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
855 (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
857 { "ifname", "s", ARG_IN },
858 { "path", "o", ARG_OUT },
859 END_ARGS
862 { NULL, NULL, NULL, { END_ARGS } }
865 static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
866 { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "y",
867 (WPADBusPropertyAccessor) wpas_dbus_getter_debug_level,
868 (WPADBusPropertyAccessor) wpas_dbus_setter_debug_level,
871 { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
872 (WPADBusPropertyAccessor) wpas_dbus_getter_debug_timestamp,
873 (WPADBusPropertyAccessor) wpas_dbus_setter_debug_timestamp,
876 { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
877 (WPADBusPropertyAccessor) wpas_dbus_getter_debug_show_keys,
878 (WPADBusPropertyAccessor) wpas_dbus_setter_debug_show_keys,
881 { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
882 (WPADBusPropertyAccessor) &wpas_dbus_getter_interfaces,
883 NULL,
886 { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
887 (WPADBusPropertyAccessor) wpas_dbus_getter_eap_methods,
888 NULL,
891 { NULL, NULL, NULL, NULL, NULL, 0 }
894 static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
895 { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
897 { "path", "o", ARG_OUT },
898 { "properties", "a{sv}", ARG_OUT },
899 END_ARGS
902 { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
904 { "path", "o", ARG_OUT },
905 END_ARGS
908 { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
910 { "properties", "a{sv}", ARG_OUT },
911 END_ARGS
914 { NULL, NULL, { END_ARGS } }
919 * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
920 * @global: Pointer to global data from wpa_supplicant_init()
921 * Returns: 0 on success or -1 on failure
923 * Initialize the dbus control interface for wpa_supplicantand and start
924 * receiving commands from external programs over the bus.
926 int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
928 struct wpa_dbus_object_desc *obj_desc;
929 int ret;
931 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
932 if (!obj_desc) {
933 wpa_printf(MSG_ERROR, "Not enough memory "
934 "to create object description");
935 return -1;
938 wpas_dbus_register(obj_desc, priv->global, NULL,
939 wpas_dbus_global_methods,
940 wpas_dbus_global_properties,
941 wpas_dbus_global_signals);
943 wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
944 WPAS_DBUS_NEW_PATH);
945 ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
946 WPAS_DBUS_NEW_SERVICE,
947 obj_desc);
948 if (ret < 0)
949 free_dbus_object_desc(obj_desc);
950 else
951 priv->dbus_new_initialized = 1;
953 return ret;
958 * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
959 * wpa_supplicant
960 * @iface: Pointer to dbus private data from wpas_dbus_init()
962 * Deinitialize the dbus control interface that was initialized with
963 * wpas_dbus_ctrl_iface_init().
965 void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
967 if (!iface->dbus_new_initialized)
968 return;
969 wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
970 WPAS_DBUS_NEW_PATH);
971 dbus_connection_unregister_object_path(iface->con,
972 WPAS_DBUS_NEW_PATH);
976 static void wpa_dbus_free(void *ptr)
978 os_free(ptr);
982 static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
983 { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
984 (WPADBusPropertyAccessor) wpas_dbus_getter_network_properties,
985 (WPADBusPropertyAccessor) wpas_dbus_setter_network_properties,
988 { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
989 (WPADBusPropertyAccessor) wpas_dbus_getter_enabled,
990 (WPADBusPropertyAccessor) wpas_dbus_setter_enabled,
993 { NULL, NULL, NULL, NULL, NULL, 0 }
997 static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
998 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
1000 { "properties", "a{sv}", ARG_OUT },
1001 END_ARGS
1004 { NULL, NULL, { END_ARGS } }
1009 * wpas_dbus_register_network - Register a configured network with dbus
1010 * @wpa_s: wpa_supplicant interface structure
1011 * @ssid: network configuration data
1012 * Returns: 0 on success, -1 on failure
1014 * Registers network representing object with dbus
1016 int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
1017 struct wpa_ssid *ssid)
1019 struct wpas_dbus_priv *ctrl_iface;
1020 struct wpa_dbus_object_desc *obj_desc;
1021 struct network_handler_args *arg;
1022 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1024 /* Do nothing if the control interface is not turned on */
1025 if (wpa_s == NULL || wpa_s->global == NULL)
1026 return 0;
1027 ctrl_iface = wpa_s->global->dbus;
1028 if (ctrl_iface == NULL)
1029 return 0;
1031 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1032 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
1033 wpa_s->dbus_new_path, ssid->id);
1035 wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
1036 net_obj_path);
1037 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
1038 if (!obj_desc) {
1039 wpa_printf(MSG_ERROR, "Not enough memory "
1040 "to create object description");
1041 goto err;
1044 /* allocate memory for handlers arguments */
1045 arg = os_zalloc(sizeof(struct network_handler_args));
1046 if (!arg) {
1047 wpa_printf(MSG_ERROR, "Not enough memory "
1048 "to create arguments for method");
1049 goto err;
1052 arg->wpa_s = wpa_s;
1053 arg->ssid = ssid;
1055 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
1056 wpas_dbus_network_properties,
1057 wpas_dbus_network_signals);
1059 if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
1060 wpa_s->ifname, obj_desc))
1061 goto err;
1063 wpas_dbus_signal_network_added(wpa_s, ssid->id);
1065 return 0;
1067 err:
1068 free_dbus_object_desc(obj_desc);
1069 return -1;
1074 * wpas_dbus_unregister_network - Unregister a configured network from dbus
1075 * @wpa_s: wpa_supplicant interface structure
1076 * @nid: network id
1077 * Returns: 0 on success, -1 on failure
1079 * Unregisters network representing object from dbus
1081 int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
1083 struct wpas_dbus_priv *ctrl_iface;
1084 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1085 int ret;
1087 /* Do nothing if the control interface is not turned on */
1088 if (wpa_s == NULL || wpa_s->global == NULL)
1089 return 0;
1090 ctrl_iface = wpa_s->global->dbus;
1091 if (ctrl_iface == NULL)
1092 return 0;
1094 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1095 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
1096 wpa_s->dbus_new_path, nid);
1098 wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
1099 net_obj_path);
1100 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
1102 if (!ret)
1103 wpas_dbus_signal_network_removed(wpa_s, nid);
1105 return ret;
1109 static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
1110 { "SSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
1111 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ssid,
1112 NULL,
1115 { "BSSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
1116 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_bssid,
1117 NULL,
1120 { "Privacy", WPAS_DBUS_NEW_IFACE_BSSID, "b",
1121 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_privacy,
1122 NULL,
1125 { "Mode", WPAS_DBUS_NEW_IFACE_BSSID, "s",
1126 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_mode,
1127 NULL,
1130 { "Signal", WPAS_DBUS_NEW_IFACE_BSSID, "n",
1131 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_signal,
1132 NULL,
1135 { "Frequency", WPAS_DBUS_NEW_IFACE_BSSID, "q",
1136 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_frequency,
1137 NULL,
1140 { "MaxRate", WPAS_DBUS_NEW_IFACE_BSSID, "q",
1141 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_max_rate,
1142 NULL,
1145 { "WPAIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
1146 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpaie,
1147 NULL,
1150 { "RSNIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
1151 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rsnie,
1152 NULL,
1155 { "WPSIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
1156 (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpsie,
1157 NULL,
1160 { NULL, NULL, NULL, NULL, NULL, 0 }
1164 static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
1165 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSSID,
1167 { "properties", "a{sv}", ARG_OUT },
1168 END_ARGS
1171 { NULL, NULL, { END_ARGS } }
1176 * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
1177 * @wpa_s: wpa_supplicant interface structure
1178 * @bssid: scanned network bssid
1179 * @id: unique BSS identifier
1180 * Returns: 0 on success, -1 on failure
1182 * Unregisters BSS representing object from dbus
1184 int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
1185 u8 bssid[ETH_ALEN], unsigned int id)
1187 struct wpas_dbus_priv *ctrl_iface;
1188 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1190 /* Do nothing if the control interface is not turned on */
1191 if (wpa_s == NULL || wpa_s->global == NULL)
1192 return 0;
1193 ctrl_iface = wpa_s->global->dbus;
1194 if (ctrl_iface == NULL)
1195 return 0;
1197 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1198 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1199 wpa_s->dbus_new_path, id);
1201 wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
1202 bss_obj_path);
1203 if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
1204 wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
1205 bss_obj_path);
1206 return -1;
1209 wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
1211 return 0;
1216 * wpas_dbus_register_bss - Register a scanned BSS with dbus
1217 * @wpa_s: wpa_supplicant interface structure
1218 * @bssid: scanned network bssid
1219 * @id: unique BSS identifier
1220 * Returns: 0 on success, -1 on failure
1222 * Registers BSS representing object with dbus
1224 int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
1225 u8 bssid[ETH_ALEN], unsigned int id)
1227 struct wpas_dbus_priv *ctrl_iface;
1228 struct wpa_dbus_object_desc *obj_desc;
1229 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1230 struct bss_handler_args *arg;
1232 /* Do nothing if the control interface is not turned on */
1233 if (wpa_s == NULL || wpa_s->global == NULL)
1234 return 0;
1235 ctrl_iface = wpa_s->global->dbus;
1236 if (ctrl_iface == NULL)
1237 return 0;
1239 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1240 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1241 wpa_s->dbus_new_path, id);
1243 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
1244 if (!obj_desc) {
1245 wpa_printf(MSG_ERROR, "Not enough memory "
1246 "to create object description");
1247 goto err;
1250 arg = os_zalloc(sizeof(struct bss_handler_args));
1251 if (!arg) {
1252 wpa_printf(MSG_ERROR, "Not enough memory "
1253 "to create arguments for handler");
1254 goto err;
1256 arg->wpa_s = wpa_s;
1257 arg->id = id;
1259 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
1260 wpas_dbus_bss_properties,
1261 wpas_dbus_bss_signals);
1263 wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
1264 bss_obj_path);
1265 if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
1266 wpa_s->ifname, obj_desc)) {
1267 wpa_printf(MSG_ERROR,
1268 "Cannot register BSSID dbus object %s.",
1269 bss_obj_path);
1270 goto err;
1273 wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
1275 return 0;
1277 err:
1278 free_dbus_object_desc(obj_desc);
1279 return -1;
1283 static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
1284 { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
1285 (WPADBusMethodHandler) &wpas_dbus_handler_scan,
1287 { "args", "a{sv}", ARG_IN },
1288 END_ARGS
1291 { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
1292 (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
1294 END_ARGS
1297 { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
1298 (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
1300 { "args", "a{sv}", ARG_IN },
1301 { "path", "o", ARG_OUT },
1302 END_ARGS
1305 { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
1306 (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
1308 { "path", "o", ARG_IN },
1309 END_ARGS
1312 { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
1313 (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
1315 { "path", "o", ARG_IN },
1316 END_ARGS
1319 { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
1320 (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
1322 { "name", "s", ARG_IN },
1323 { "data", "ay", ARG_IN },
1324 END_ARGS
1327 { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
1328 (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
1330 { "name", "s", ARG_IN },
1331 { "data", "ay", ARG_OUT },
1332 END_ARGS
1335 { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
1336 (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
1338 { "name", "s", ARG_IN },
1339 END_ARGS
1342 #ifdef CONFIG_WPS
1343 { "Start", WPAS_DBUS_NEW_IFACE_WPS,
1344 (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
1346 { "args", "a{sv}", ARG_IN },
1347 { "output", "a{sv}", ARG_OUT },
1348 END_ARGS
1351 #endif /* CONFIG_WPS */
1352 { NULL, NULL, NULL, { END_ARGS } }
1355 static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
1356 { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
1357 (WPADBusPropertyAccessor) wpas_dbus_getter_capabilities,
1358 NULL, R
1360 { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
1361 (WPADBusPropertyAccessor) wpas_dbus_getter_state,
1362 NULL, R
1364 { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
1365 (WPADBusPropertyAccessor) wpas_dbus_getter_scanning,
1366 NULL, R
1368 { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
1369 (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan,
1370 (WPADBusPropertyAccessor) wpas_dbus_setter_ap_scan,
1373 { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
1374 (WPADBusPropertyAccessor) wpas_dbus_getter_ifname,
1375 NULL, R
1377 { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
1378 (WPADBusPropertyAccessor) wpas_dbus_getter_driver,
1379 NULL, R
1381 { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
1382 (WPADBusPropertyAccessor) wpas_dbus_getter_bridge_ifname,
1383 NULL, R
1385 { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
1386 (WPADBusPropertyAccessor) wpas_dbus_getter_current_bss,
1387 NULL, R
1389 { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
1390 (WPADBusPropertyAccessor) wpas_dbus_getter_current_network,
1391 NULL, R
1393 { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
1394 (WPADBusPropertyAccessor) wpas_dbus_getter_blobs,
1395 NULL, R
1397 { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
1398 (WPADBusPropertyAccessor) wpas_dbus_getter_bsss,
1399 NULL, R
1401 { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
1402 (WPADBusPropertyAccessor) wpas_dbus_getter_networks,
1403 NULL, R
1405 #ifdef CONFIG_WPS
1406 { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
1407 (WPADBusPropertyAccessor) wpas_dbus_getter_process_credentials,
1408 (WPADBusPropertyAccessor) wpas_dbus_setter_process_credentials,
1411 #endif /* CONFIG_WPS */
1412 { NULL, NULL, NULL, NULL, NULL, 0 }
1415 static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
1416 { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
1418 { "success", "b", ARG_OUT },
1419 END_ARGS
1422 { "StateChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
1424 { "newState", "s", ARG_OUT },
1425 { "oldState", "s", ARG_OUT },
1426 END_ARGS
1429 { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
1431 { "path", "o", ARG_OUT },
1432 { "properties", "a{sv}", ARG_OUT },
1433 END_ARGS
1436 { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
1438 { "path", "o", ARG_OUT },
1439 END_ARGS
1442 { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
1444 { "name", "s", ARG_OUT },
1445 END_ARGS
1448 { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
1450 { "name", "s", ARG_OUT },
1451 END_ARGS
1454 { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
1456 { "path", "o", ARG_OUT },
1457 { "properties", "a{sv}", ARG_OUT },
1458 END_ARGS
1461 { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
1463 { "path", "o", ARG_OUT },
1464 END_ARGS
1467 { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
1469 { "path", "o", ARG_OUT },
1470 END_ARGS
1473 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
1475 { "properties", "a{sv}", ARG_OUT },
1476 END_ARGS
1479 #ifdef CONFIG_WPS
1480 { "Event", WPAS_DBUS_NEW_IFACE_WPS,
1482 { "name", "s", ARG_OUT },
1483 { "args", "a{sv}", ARG_OUT },
1484 END_ARGS
1487 { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
1489 { "credentials", "a{sv}", ARG_OUT },
1490 END_ARGS
1493 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
1495 { "properties", "a{sv}", ARG_OUT },
1496 END_ARGS
1499 #endif /* CONFIG_WPS */
1500 { NULL, NULL, { END_ARGS } }
1504 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
1507 struct wpa_dbus_object_desc *obj_desc = NULL;
1508 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
1509 int next;
1511 /* Do nothing if the control interface is not turned on */
1512 if (ctrl_iface == NULL)
1513 return 0;
1515 /* Create and set the interface's object path */
1516 wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
1517 if (wpa_s->dbus_new_path == NULL)
1518 return -1;
1519 next = ctrl_iface->next_objid++;
1520 os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
1521 WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
1522 next);
1524 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
1525 if (!obj_desc) {
1526 wpa_printf(MSG_ERROR, "Not enough memory "
1527 "to create object description");
1528 goto err;
1531 wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
1532 wpas_dbus_interface_properties,
1533 wpas_dbus_interface_signals);
1535 wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
1536 wpa_s->dbus_new_path);
1537 if (wpa_dbus_register_object_per_iface(ctrl_iface,
1538 wpa_s->dbus_new_path,
1539 wpa_s->ifname, obj_desc))
1540 goto err;
1542 wpas_dbus_signal_interface_added(wpa_s);
1544 return 0;
1546 err:
1547 os_free(wpa_s->dbus_new_path);
1548 wpa_s->dbus_new_path = NULL;
1549 free_dbus_object_desc(obj_desc);
1550 return -1;
1554 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
1556 struct wpas_dbus_priv *ctrl_iface;
1558 /* Do nothing if the control interface is not turned on */
1559 if (wpa_s == NULL || wpa_s->global == NULL)
1560 return 0;
1561 ctrl_iface = wpa_s->global->dbus;
1562 if (ctrl_iface == NULL)
1563 return 0;
1565 wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
1566 wpa_s->dbus_new_path);
1567 if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
1568 wpa_s->dbus_new_path))
1569 return -1;
1571 wpas_dbus_signal_interface_removed(wpa_s);
1573 os_free(wpa_s->dbus_new_path);
1574 wpa_s->dbus_new_path = NULL;
1576 return 0;