]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/dbus/dbus_new.c
D-Bus/P2P: Treat PIN as string
[thirdparty/hostap.git] / wpa_supplicant / dbus / dbus_new.c
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-2010, Witold Sowa <witold.sowa@gmail.com>
5 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
6 *
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.
10 *
11 * Alternatively, this software may be distributed under the terms of BSD
12 * license.
13 *
14 * See README and COPYING for more details.
15 */
16
17 #include "includes.h"
18
19 #include "common.h"
20 #include "common/ieee802_11_defs.h"
21 #include "wps/wps.h"
22 #include "../config.h"
23 #include "../wpa_supplicant_i.h"
24 #include "../bss.h"
25 #include "dbus_new_helpers.h"
26 #include "dbus_dict_helpers.h"
27 #include "dbus_new.h"
28 #include "dbus_new_handlers.h"
29 #include "dbus_common.h"
30 #include "dbus_common_i.h"
31 #include "dbus_new_handlers_p2p.h"
32 #include "p2p/p2p.h"
33
34
35 /**
36 * wpas_dbus_signal_interface - Send a interface related event signal
37 * @wpa_s: %wpa_supplicant network interface data
38 * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
39 * @properties: Whether to add second argument with object properties
40 *
41 * Notify listeners about event related with interface
42 */
43 static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
44 const char *sig_name, int properties)
45 {
46 struct wpas_dbus_priv *iface;
47 DBusMessage *msg;
48 DBusMessageIter iter;
49
50 iface = wpa_s->global->dbus;
51
52 /* Do nothing if the control interface is not turned on */
53 if (iface == NULL)
54 return;
55
56 msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
57 WPAS_DBUS_NEW_INTERFACE, sig_name);
58 if (msg == NULL)
59 return;
60
61 dbus_message_iter_init_append(msg, &iter);
62 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
63 &wpa_s->dbus_new_path))
64 goto err;
65
66 if (properties) {
67 if (!wpa_dbus_get_object_properties(
68 iface, wpa_s->dbus_new_path,
69 WPAS_DBUS_NEW_IFACE_INTERFACE, &iter))
70 goto err;
71 }
72
73 dbus_connection_send(iface->con, msg, NULL);
74 dbus_message_unref(msg);
75 return;
76
77 err:
78 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
79 dbus_message_unref(msg);
80 }
81
82
83 /**
84 * wpas_dbus_signal_interface_added - Send a interface created signal
85 * @wpa_s: %wpa_supplicant network interface data
86 *
87 * Notify listeners about creating new interface
88 */
89 static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
90 {
91 wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
92 }
93
94
95 /**
96 * wpas_dbus_signal_interface_removed - Send a interface removed signal
97 * @wpa_s: %wpa_supplicant network interface data
98 *
99 * Notify listeners about removing interface
100 */
101 static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
102 {
103 wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
104
105 }
106
107
108 /**
109 * wpas_dbus_signal_scan_done - send scan done signal
110 * @wpa_s: %wpa_supplicant network interface data
111 * @success: indicates if scanning succeed or failed
112 *
113 * Notify listeners about finishing a scan
114 */
115 void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
116 {
117 struct wpas_dbus_priv *iface;
118 DBusMessage *msg;
119 dbus_bool_t succ;
120
121 iface = wpa_s->global->dbus;
122
123 /* Do nothing if the control interface is not turned on */
124 if (iface == NULL)
125 return;
126
127 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
128 WPAS_DBUS_NEW_IFACE_INTERFACE,
129 "ScanDone");
130 if (msg == NULL)
131 return;
132
133 succ = success ? TRUE : FALSE;
134 if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
135 DBUS_TYPE_INVALID))
136 dbus_connection_send(iface->con, msg, NULL);
137 else
138 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
139 dbus_message_unref(msg);
140 }
141
142
143 /**
144 * wpas_dbus_signal_blob - Send a BSS related event signal
145 * @wpa_s: %wpa_supplicant network interface data
146 * @bss_obj_path: BSS object path
147 * @sig_name: signal name - BSSAdded or BSSRemoved
148 * @properties: Whether to add second argument with object properties
149 *
150 * Notify listeners about event related with BSS
151 */
152 static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
153 const char *bss_obj_path,
154 const char *sig_name, int properties)
155 {
156 struct wpas_dbus_priv *iface;
157 DBusMessage *msg;
158 DBusMessageIter iter;
159
160 iface = wpa_s->global->dbus;
161
162 /* Do nothing if the control interface is not turned on */
163 if (iface == NULL)
164 return;
165
166 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
167 WPAS_DBUS_NEW_IFACE_INTERFACE,
168 sig_name);
169 if (msg == NULL)
170 return;
171
172 dbus_message_iter_init_append(msg, &iter);
173 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
174 &bss_obj_path))
175 goto err;
176
177 if (properties) {
178 if (!wpa_dbus_get_object_properties(iface, bss_obj_path,
179 WPAS_DBUS_NEW_IFACE_BSS,
180 &iter))
181 goto err;
182 }
183
184 dbus_connection_send(iface->con, msg, NULL);
185 dbus_message_unref(msg);
186 return;
187
188 err:
189 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
190 dbus_message_unref(msg);
191 }
192
193
194 /**
195 * wpas_dbus_signal_bss_added - Send a BSS added signal
196 * @wpa_s: %wpa_supplicant network interface data
197 * @bss_obj_path: new BSS object path
198 *
199 * Notify listeners about adding new BSS
200 */
201 static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
202 const char *bss_obj_path)
203 {
204 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
205 }
206
207
208 /**
209 * wpas_dbus_signal_bss_removed - Send a BSS removed signal
210 * @wpa_s: %wpa_supplicant network interface data
211 * @bss_obj_path: BSS object path
212 *
213 * Notify listeners about removing BSS
214 */
215 static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
216 const char *bss_obj_path)
217 {
218 wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
219 }
220
221
222 /**
223 * wpas_dbus_signal_blob - Send a blob related event signal
224 * @wpa_s: %wpa_supplicant network interface data
225 * @name: blob name
226 * @sig_name: signal name - BlobAdded or BlobRemoved
227 *
228 * Notify listeners about event related with blob
229 */
230 static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
231 const char *name, const char *sig_name)
232 {
233 struct wpas_dbus_priv *iface;
234 DBusMessage *msg;
235
236 iface = wpa_s->global->dbus;
237
238 /* Do nothing if the control interface is not turned on */
239 if (iface == NULL)
240 return;
241
242 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
243 WPAS_DBUS_NEW_IFACE_INTERFACE,
244 sig_name);
245 if (msg == NULL)
246 return;
247
248 if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
249 DBUS_TYPE_INVALID))
250 dbus_connection_send(iface->con, msg, NULL);
251 else
252 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
253 dbus_message_unref(msg);
254 }
255
256
257 /**
258 * wpas_dbus_signal_blob_added - Send a blob added signal
259 * @wpa_s: %wpa_supplicant network interface data
260 * @name: blob name
261 *
262 * Notify listeners about adding a new blob
263 */
264 void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
265 const char *name)
266 {
267 wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
268 }
269
270
271 /**
272 * wpas_dbus_signal_blob_removed - Send a blob removed signal
273 * @wpa_s: %wpa_supplicant network interface data
274 * @name: blob name
275 *
276 * Notify listeners about removing blob
277 */
278 void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
279 const char *name)
280 {
281 wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
282 }
283
284
285 /**
286 * wpas_dbus_signal_network - Send a network related event signal
287 * @wpa_s: %wpa_supplicant network interface data
288 * @id: new network id
289 * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
290 * @properties: determines if add second argument with object properties
291 *
292 * Notify listeners about event related with configured network
293 */
294 static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
295 int id, const char *sig_name,
296 int properties)
297 {
298 struct wpas_dbus_priv *iface;
299 DBusMessage *msg;
300 DBusMessageIter iter;
301 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
302
303 iface = wpa_s->global->dbus;
304
305 /* Do nothing if the control interface is not turned on */
306 if (iface == NULL)
307 return;
308
309 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
310 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
311 wpa_s->dbus_new_path, id);
312
313 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
314 WPAS_DBUS_NEW_IFACE_INTERFACE,
315 sig_name);
316 if (msg == NULL)
317 return;
318
319 dbus_message_iter_init_append(msg, &iter);
320 path = net_obj_path;
321 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
322 &path))
323 goto err;
324
325 if (properties) {
326 if (!wpa_dbus_get_object_properties(
327 iface, net_obj_path, WPAS_DBUS_NEW_IFACE_NETWORK,
328 &iter))
329 goto err;
330 }
331
332 dbus_connection_send(iface->con, msg, NULL);
333
334 dbus_message_unref(msg);
335 return;
336
337 err:
338 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
339 dbus_message_unref(msg);
340 }
341
342
343 /**
344 * wpas_dbus_signal_network_added - Send a network added signal
345 * @wpa_s: %wpa_supplicant network interface data
346 * @id: new network id
347 *
348 * Notify listeners about adding new network
349 */
350 static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
351 int id)
352 {
353 wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
354 }
355
356
357 /**
358 * wpas_dbus_signal_network_removed - Send a network removed signal
359 * @wpa_s: %wpa_supplicant network interface data
360 * @id: network id
361 *
362 * Notify listeners about removing a network
363 */
364 static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
365 int id)
366 {
367 wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
368 }
369
370
371 /**
372 * wpas_dbus_signal_network_selected - Send a network selected signal
373 * @wpa_s: %wpa_supplicant network interface data
374 * @id: network id
375 *
376 * Notify listeners about selecting a network
377 */
378 void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
379 {
380 wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
381 }
382
383
384 /**
385 * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
386 * @wpa_s: %wpa_supplicant network interface data
387 * @ssid: configured network which Enabled property has changed
388 *
389 * Sends PropertyChanged signals containing new value of Enabled property
390 * for specified network
391 */
392 void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
393 struct wpa_ssid *ssid)
394 {
395
396 char path[WPAS_DBUS_OBJECT_PATH_MAX];
397 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
398 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
399 wpa_s->dbus_new_path, ssid->id);
400
401 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
402 WPAS_DBUS_NEW_IFACE_NETWORK, "Enabled");
403 }
404
405
406 #ifdef CONFIG_WPS
407
408 /**
409 * wpas_dbus_signal_wps_event_success - Signals Success WPS event
410 * @wpa_s: %wpa_supplicant network interface data
411 *
412 * Sends Event dbus signal with name "success" and empty dict as arguments
413 */
414 void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
415 {
416
417 DBusMessage *msg;
418 DBusMessageIter iter, dict_iter;
419 struct wpas_dbus_priv *iface;
420 char *key = "success";
421
422 iface = wpa_s->global->dbus;
423
424 /* Do nothing if the control interface is not turned on */
425 if (iface == NULL)
426 return;
427
428 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
429 WPAS_DBUS_NEW_IFACE_WPS, "Event");
430 if (msg == NULL)
431 return;
432
433 dbus_message_iter_init_append(msg, &iter);
434
435 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
436 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
437 !wpa_dbus_dict_close_write(&iter, &dict_iter))
438 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
439 else
440 dbus_connection_send(iface->con, msg, NULL);
441
442 dbus_message_unref(msg);
443 }
444
445
446 /**
447 * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
448 * @wpa_s: %wpa_supplicant network interface data
449 *
450 * Sends Event dbus signal with name "fail" and dictionary containing
451 * "msg field with fail message number (int32) as arguments
452 */
453 void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
454 struct wps_event_fail *fail)
455 {
456
457 DBusMessage *msg;
458 DBusMessageIter iter, dict_iter;
459 struct wpas_dbus_priv *iface;
460 char *key = "fail";
461
462 iface = wpa_s->global->dbus;
463
464 /* Do nothing if the control interface is not turned on */
465 if (iface == NULL)
466 return;
467
468 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
469 WPAS_DBUS_NEW_IFACE_WPS, "Event");
470 if (msg == NULL)
471 return;
472
473 dbus_message_iter_init_append(msg, &iter);
474
475 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
476 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
477 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
478 !wpa_dbus_dict_close_write(&iter, &dict_iter))
479 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
480 else
481 dbus_connection_send(iface->con, msg, NULL);
482
483 dbus_message_unref(msg);
484 }
485
486
487 /**
488 * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
489 * @wpa_s: %wpa_supplicant network interface data
490 *
491 * Sends Event dbus signal with name "m2d" and dictionary containing
492 * fields of wps_event_m2d structure.
493 */
494 void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
495 struct wps_event_m2d *m2d)
496 {
497
498 DBusMessage *msg;
499 DBusMessageIter iter, dict_iter;
500 struct wpas_dbus_priv *iface;
501 char *key = "m2d";
502
503 iface = wpa_s->global->dbus;
504
505 /* Do nothing if the control interface is not turned on */
506 if (iface == NULL)
507 return;
508
509 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
510 WPAS_DBUS_NEW_IFACE_WPS, "Event");
511 if (msg == NULL)
512 return;
513
514 dbus_message_iter_init_append(msg, &iter);
515
516 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
517 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
518 !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
519 m2d->config_methods) ||
520 !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
521 (const char *) m2d->manufacturer,
522 m2d->manufacturer_len) ||
523 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
524 (const char *) m2d->model_name,
525 m2d->model_name_len) ||
526 !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
527 (const char *) m2d->model_number,
528 m2d->model_number_len) ||
529 !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
530 (const char *)
531 m2d->serial_number,
532 m2d->serial_number_len) ||
533 !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
534 (const char *) m2d->dev_name,
535 m2d->dev_name_len) ||
536 !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
537 (const char *)
538 m2d->primary_dev_type, 8) ||
539 !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
540 m2d->config_error) ||
541 !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
542 m2d->dev_password_id) ||
543 !wpa_dbus_dict_close_write(&iter, &dict_iter))
544 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
545 else
546 dbus_connection_send(iface->con, msg, NULL);
547
548 dbus_message_unref(msg);
549 }
550
551
552 /**
553 * wpas_dbus_signal_wps_cred - Signals new credentials
554 * @wpa_s: %wpa_supplicant network interface data
555 *
556 * Sends signal with credentials in directory argument
557 */
558 void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
559 const struct wps_credential *cred)
560 {
561 DBusMessage *msg;
562 DBusMessageIter iter, dict_iter;
563 struct wpas_dbus_priv *iface;
564 char *auth_type[6]; /* we have six possible authorization types */
565 int at_num = 0;
566 char *encr_type[4]; /* we have four possible encryption types */
567 int et_num = 0;
568
569 iface = wpa_s->global->dbus;
570
571 /* Do nothing if the control interface is not turned on */
572 if (iface == NULL)
573 return;
574
575 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
576 WPAS_DBUS_NEW_IFACE_WPS,
577 "Credentials");
578 if (msg == NULL)
579 return;
580
581 dbus_message_iter_init_append(msg, &iter);
582 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
583 goto nomem;
584
585 if (cred->auth_type & WPS_AUTH_OPEN)
586 auth_type[at_num++] = "open";
587 if (cred->auth_type & WPS_AUTH_WPAPSK)
588 auth_type[at_num++] = "wpa-psk";
589 if (cred->auth_type & WPS_AUTH_SHARED)
590 auth_type[at_num++] = "shared";
591 if (cred->auth_type & WPS_AUTH_WPA)
592 auth_type[at_num++] = "wpa-eap";
593 if (cred->auth_type & WPS_AUTH_WPA2)
594 auth_type[at_num++] = "wpa2-eap";
595 if (cred->auth_type & WPS_AUTH_WPA2PSK)
596 auth_type[at_num++] =
597 "wpa2-psk";
598
599 if (cred->encr_type & WPS_ENCR_NONE)
600 encr_type[et_num++] = "none";
601 if (cred->encr_type & WPS_ENCR_WEP)
602 encr_type[et_num++] = "wep";
603 if (cred->encr_type & WPS_ENCR_TKIP)
604 encr_type[et_num++] = "tkip";
605 if (cred->encr_type & WPS_ENCR_AES)
606 encr_type[et_num++] = "aes";
607
608 if (wpa_s->current_ssid) {
609 if (!wpa_dbus_dict_append_byte_array(
610 &dict_iter, "BSSID",
611 (const char *) wpa_s->current_ssid->bssid,
612 ETH_ALEN))
613 goto nomem;
614 }
615
616 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
617 (const char *) cred->ssid,
618 cred->ssid_len) ||
619 !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
620 (const char **) auth_type,
621 at_num) ||
622 !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
623 (const char **) encr_type,
624 et_num) ||
625 !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
626 (const char *) cred->key,
627 cred->key_len) ||
628 !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
629 cred->key_idx) ||
630 !wpa_dbus_dict_close_write(&iter, &dict_iter))
631 goto nomem;
632
633 dbus_connection_send(iface->con, msg, NULL);
634
635 nomem:
636 dbus_message_unref(msg);
637 }
638
639 #endif /* CONFIG_WPS */
640
641 void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
642 int depth, const char *subject,
643 const char *cert_hash,
644 const struct wpabuf *cert)
645 {
646 struct wpas_dbus_priv *iface;
647 DBusMessage *msg;
648 DBusMessageIter iter, dict_iter;
649
650 iface = wpa_s->global->dbus;
651
652 /* Do nothing if the control interface is not turned on */
653 if (iface == NULL)
654 return;
655
656 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
657 WPAS_DBUS_NEW_IFACE_INTERFACE,
658 "Certification");
659 if (msg == NULL)
660 return;
661
662 dbus_message_iter_init_append(msg, &iter);
663 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
664 goto nomem;
665
666 if (!wpa_dbus_dict_append_uint32(&dict_iter, "depth", depth) ||
667 !wpa_dbus_dict_append_string(&dict_iter, "subject", subject))
668 goto nomem;
669
670 if (cert_hash &&
671 !wpa_dbus_dict_append_string(&dict_iter, "cert_hash", cert_hash))
672 goto nomem;
673
674 if (cert &&
675 !wpa_dbus_dict_append_byte_array(&dict_iter, "cert",
676 wpabuf_head(cert),
677 wpabuf_len(cert)))
678 goto nomem;
679
680 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
681 goto nomem;
682
683 dbus_connection_send(iface->con, msg, NULL);
684
685 nomem:
686 dbus_message_unref(msg);
687 }
688
689 #ifdef CONFIG_P2P
690
691 /**
692 * wpas_dbus_signal_p2p_group_removed - Signals P2P group was removed
693 * @wpa_s: %wpa_supplicant network interface data
694 * @role: role of this device (client or GO)
695 * Sends signal with i/f name and role as string arguments
696 */
697 void wpas_dbus_signal_p2p_group_removed(struct wpa_supplicant *wpa_s,
698 const char *role)
699 {
700
701 DBusMessage *msg;
702 DBusMessageIter iter;
703 struct wpas_dbus_priv *iface = wpa_s->global->dbus;
704 char *ifname = wpa_s->ifname;
705
706 /* Do nothing if the control interface is not turned on */
707 if (iface == NULL)
708 return;
709
710 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
711 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
712 "GroupFinished");
713 if (msg == NULL)
714 return;
715
716 dbus_message_iter_init_append(msg, &iter);
717
718 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ifname)) {
719 wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
720 "signal -not enough memory for ifname ");
721 goto err;
722 }
723
724 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &role))
725 wpa_printf(MSG_ERROR, "dbus: Failed to construct GroupFinished"
726 "signal -not enough memory for role ");
727 else
728 dbus_connection_send(iface->con, msg, NULL);
729
730 err:
731 dbus_message_unref(msg);
732 }
733
734
735 /**
736 * wpas_dbus_signal_p2p_provision_discovery - Signals various PD events
737 *
738 * @dev_addr - who sent the request or responded to our request.
739 * @request - Will be 1 if request, 0 for response.
740 * @status - valid only in case of response
741 * @config_methods - wps config methods
742 * @generated_pin - pin to be displayed in case of WPS_CONFIG_DISPLAY method
743 *
744 * Sends following provision discovery related events:
745 * ProvisionDiscoveryRequestDisplayPin
746 * ProvisionDiscoveryResponseDisplayPin
747 * ProvisionDiscoveryRequestEnterPin
748 * ProvisionDiscoveryResponseEnterPin
749 * ProvisionDiscoveryPBCRequest
750 * ProvisionDiscoveryPBCResponse
751 *
752 * TODO::
753 * ProvisionDiscoveryFailure (timeout case)
754 */
755 void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
756 const u8 *dev_addr, int request,
757 enum p2p_prov_disc_status status,
758 u16 config_methods,
759 unsigned int generated_pin)
760 {
761 DBusMessage *msg;
762 DBusMessageIter iter;
763 struct wpas_dbus_priv *iface;
764 char *_signal;
765 int add_pin = 0;
766 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
767 int error_ret = 1;
768 char pin[9], *p_pin = NULL;
769
770 iface = wpa_s->global->dbus;
771
772 /* Do nothing if the control interface is not turned on */
773 if (iface == NULL)
774 return;
775
776 if (request || !status) {
777 if (config_methods & WPS_CONFIG_DISPLAY)
778 _signal = request ?
779 "ProvisionDiscoveryRequestDisplayPin" :
780 "ProvisionDiscoveryResponseEnterPin";
781 else if (config_methods & WPS_CONFIG_KEYPAD)
782 _signal = request ?
783 "ProvisionDiscoveryRequestEnterPin" :
784 "ProvisionDiscoveryResponseDisplayPin";
785 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
786 _signal = request ? "ProvisionDiscoveryPBCRequest" :
787 "ProvisionDiscoveryPBCResponse";
788 else
789 return; /* Unknown or un-supported method */
790 } else if (!request && status)
791 /* Explicit check for failure response */
792 _signal = "ProvisionDiscoveryFailure";
793
794 add_pin = ((request && (config_methods & WPS_CONFIG_DISPLAY)) ||
795 (!request && !status &&
796 (config_methods & WPS_CONFIG_KEYPAD)));
797
798 if (add_pin) {
799 os_snprintf(pin, sizeof(pin), "%08d", generated_pin);
800 p_pin = pin;
801 }
802
803 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
804 WPAS_DBUS_NEW_IFACE_P2PDEVICE, _signal);
805 if (msg == NULL)
806 return;
807
808 /* Check if this is a known peer */
809 if (p2p_get_peer_info(wpa_s->global->p2p, dev_addr, 0, NULL, 0) < 0)
810 goto error;
811
812 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
813 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
814 COMPACT_MACSTR,
815 wpa_s->dbus_new_path, MAC2STR(dev_addr));
816
817 path = peer_obj_path;
818
819 dbus_message_iter_init_append(msg, &iter);
820
821 if (!dbus_message_iter_append_basic(&iter,
822 DBUS_TYPE_OBJECT_PATH,
823 &path))
824 goto error;
825
826 if (!request && status)
827 /* Attach status to ProvisionDiscoveryFailure */
828 error_ret = !dbus_message_iter_append_basic(&iter,
829 DBUS_TYPE_INT32,
830 &status);
831 else
832 error_ret = (add_pin &&
833 !dbus_message_iter_append_basic(&iter,
834 DBUS_TYPE_STRING,
835 &p_pin));
836
837 error:
838 if (!error_ret)
839 dbus_connection_send(iface->con, msg, NULL);
840 else
841 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
842
843 dbus_message_unref(msg);
844 }
845
846
847 void wpas_dbus_signal_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
848 const u8 *src, u16 dev_passwd_id)
849 {
850 DBusMessage *msg;
851 DBusMessageIter iter;
852 struct wpas_dbus_priv *iface;
853 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
854
855 iface = wpa_s->global->dbus;
856
857 /* Do nothing if the control interface is not turned on */
858 if (iface == NULL)
859 return;
860
861 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
862 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
863 wpa_s->dbus_new_path, MAC2STR(src));
864 path = peer_obj_path;
865
866 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
867 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
868 "GONegotiationRequest");
869 if (msg == NULL)
870 return;
871
872 dbus_message_iter_init_append(msg, &iter);
873
874 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
875 &path) ||
876 !dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16,
877 &dev_passwd_id))
878 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
879 else
880 dbus_connection_send(iface->con, msg, NULL);
881
882 dbus_message_unref(msg);
883 }
884
885
886 static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
887 const struct wpa_ssid *ssid,
888 char *group_obj_path)
889 {
890 char group_name[3];
891
892 if (os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
893 return -1;
894
895 memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
896 group_name[2] = '\0';
897
898 os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
899 "%s/" WPAS_DBUS_NEW_P2P_GROUPS_PART "/%s",
900 wpa_s->dbus_new_path, group_name);
901
902 return 0;
903 }
904
905
906 /**
907 * wpas_dbus_signal_p2p_group_started - Signals P2P group has
908 * started. Emitted when a group is successfully started
909 * irrespective of the role (client/GO) of the current device
910 *
911 * @wpa_s: %wpa_supplicant network interface data
912 * @ssid: SSID object
913 * @client: this device is P2P client
914 * @network_id: network id of the group started, use instead of ssid->id
915 * to account for persistent groups
916 */
917 void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
918 const struct wpa_ssid *ssid,
919 int client, int network_id)
920 {
921 DBusMessage *msg;
922 DBusMessageIter iter, dict_iter;
923 struct wpas_dbus_priv *iface;
924 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
925 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
926
927 iface = wpa_s->parent->global->dbus;
928
929 /* Do nothing if the control interface is not turned on */
930 if (iface == NULL)
931 return;
932
933 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
934 return;
935
936 /* New interface has been created for this group */
937 msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
938 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
939 "GroupStarted");
940
941 if (msg == NULL)
942 return;
943
944 dbus_message_iter_init_append(msg, &iter);
945 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
946 goto nomem;
947
948 /*
949 * In case the device supports creating a separate interface the
950 * DBus client will need to know the object path for the interface
951 * object this group was created on, so include it here.
952 */
953 if (!wpa_dbus_dict_append_object_path(&dict_iter,
954 "interface_object",
955 wpa_s->dbus_new_path))
956 goto nomem;
957
958 if (!wpa_dbus_dict_append_string(&dict_iter, "role",
959 client ? "client" : "GO"))
960 goto nomem;
961
962 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
963 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
964 wpa_s->parent->dbus_new_path, network_id);
965
966 if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
967 group_obj_path) ||
968 !wpa_dbus_dict_append_object_path(&dict_iter, "network_object",
969 net_obj_path) ||
970 !wpa_dbus_dict_close_write(&iter, &dict_iter))
971 goto nomem;
972
973 dbus_connection_send(iface->con, msg, NULL);
974
975 nomem:
976 dbus_message_unref(msg);
977 }
978
979
980 /**
981 *
982 * Method to emit GONeogtiation Success or Failure signals based
983 * on status.
984 * @status: Status of the GO neg request. 0 for success, other for errors.
985 */
986 void wpas_dbus_signal_p2p_go_neg_resp(struct wpa_supplicant *wpa_s, int status)
987 {
988 DBusMessage *msg;
989 DBusMessageIter iter;
990 struct wpas_dbus_priv *iface;
991
992 iface = wpa_s->global->dbus;
993
994 /* Do nothing if the control interface is not turned on */
995 if (iface == NULL)
996 return;
997
998 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
999 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1000 status ? "GONegotiationFailure" :
1001 "GONegotiationSuccess");
1002 if (msg == NULL)
1003 return;
1004
1005 if (status) {
1006 dbus_message_iter_init_append(msg, &iter);
1007 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32,
1008 &status)) {
1009 wpa_printf(MSG_ERROR,
1010 "dbus: Failed to construct signal");
1011 goto err;
1012 }
1013 }
1014
1015 dbus_connection_send(iface->con, msg, NULL);
1016 err:
1017 dbus_message_unref(msg);
1018 }
1019
1020
1021 /**
1022 *
1023 * Method to emit Invitation Result signal based on status and
1024 * bssid
1025 * @status: Status of the Invite request. 0 for success, other
1026 * for errors
1027 * @bssid : Basic Service Set Identifier
1028 */
1029 void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
1030 int status, const u8 *bssid)
1031 {
1032 DBusMessage *msg;
1033 DBusMessageIter iter, dict_iter;
1034 struct wpas_dbus_priv *iface;
1035
1036 wpa_printf(MSG_INFO, "%s\n", __func__);
1037
1038 iface = wpa_s->global->dbus;
1039 /* Do nothing if the control interface is not turned on */
1040 if (iface == NULL)
1041 return;
1042
1043 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1044 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1045 "InvitationResult");
1046
1047 if (msg == NULL)
1048 return;
1049
1050 dbus_message_iter_init_append(msg, &iter);
1051 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1052 goto nomem;
1053
1054 if (!wpa_dbus_dict_append_int32(&dict_iter, "status", status))
1055 goto nomem;
1056 if (bssid) {
1057 if (!wpa_dbus_dict_append_byte_array(&dict_iter, "BSSID",
1058 (const char *) bssid,
1059 ETH_ALEN))
1060 goto nomem;
1061 }
1062 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
1063 goto nomem;
1064
1065 dbus_connection_send(iface->con, msg, NULL);
1066
1067 nomem:
1068 dbus_message_unref(msg);
1069 }
1070
1071
1072 /**
1073 *
1074 * Method to emit a signal for a peer joining the group.
1075 * The signal will carry path to the group member object
1076 * constructed using p2p i/f addr used for connecting.
1077 *
1078 * @wpa_s: %wpa_supplicant network interface data
1079 * @member_addr: addr (p2p i/f) of the peer joining the group
1080 */
1081 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
1082 const u8 *member)
1083 {
1084 struct wpas_dbus_priv *iface;
1085 DBusMessage *msg;
1086 DBusMessageIter iter;
1087 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1088
1089 iface = wpa_s->global->dbus;
1090
1091 /* Do nothing if the control interface is not turned on */
1092 if (iface == NULL)
1093 return;
1094
1095 if (!wpa_s->dbus_groupobj_path)
1096 return;
1097
1098 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1099 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
1100 COMPACT_MACSTR,
1101 wpa_s->dbus_groupobj_path, MAC2STR(member));
1102
1103 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1104 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1105 "PeerJoined");
1106 if (msg == NULL)
1107 return;
1108
1109 dbus_message_iter_init_append(msg, &iter);
1110 path = groupmember_obj_path;
1111 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1112 &path))
1113 goto err;
1114
1115 dbus_connection_send(iface->con, msg, NULL);
1116
1117 dbus_message_unref(msg);
1118 return;
1119
1120 err:
1121 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1122 dbus_message_unref(msg);
1123 }
1124
1125
1126 /**
1127 *
1128 * Method to emit a signal for a peer disconnecting the group.
1129 * The signal will carry path to the group member object
1130 * constructed using p2p i/f addr used for connecting.
1131 *
1132 * @wpa_s: %wpa_supplicant network interface data
1133 * @member_addr: addr (p2p i/f) of the peer joining the group
1134 */
1135 void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
1136 const u8 *member)
1137 {
1138 struct wpas_dbus_priv *iface;
1139 DBusMessage *msg;
1140 DBusMessageIter iter;
1141 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1142
1143 iface = wpa_s->global->dbus;
1144
1145 /* Do nothing if the control interface is not turned on */
1146 if (iface == NULL)
1147 return;
1148
1149 if (!wpa_s->dbus_groupobj_path)
1150 return;
1151
1152 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1153 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
1154 COMPACT_MACSTR,
1155 wpa_s->dbus_groupobj_path, MAC2STR(member));
1156
1157 msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
1158 WPAS_DBUS_NEW_IFACE_P2P_GROUP,
1159 "PeerDisconnected");
1160 if (msg == NULL)
1161 return;
1162
1163 dbus_message_iter_init_append(msg, &iter);
1164 path = groupmember_obj_path;
1165 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1166 &path))
1167 goto err;
1168
1169 dbus_connection_send(iface->con, msg, NULL);
1170
1171 dbus_message_unref(msg);
1172 return;
1173
1174 err:
1175 wpa_printf(MSG_ERROR, "dbus: Failed to construct PeerDisconnected "
1176 "signal");
1177 dbus_message_unref(msg);
1178 }
1179
1180
1181 /**
1182 *
1183 * Method to emit a signal for a service discovery request.
1184 * The signal will carry station address, frequency, dialog token,
1185 * update indicator and it tlvs
1186 *
1187 * @wpa_s: %wpa_supplicant network interface data
1188 * @sa: station addr (p2p i/f) of the peer
1189 * @dialog_token: service discovery request dialog token
1190 * @update_indic: service discovery request update indicator
1191 * @tlvs: service discovery request genrated byte array of tlvs
1192 * @tlvs_len: service discovery request tlvs length
1193 */
1194 void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s,
1195 int freq, const u8 *sa, u8 dialog_token,
1196 u16 update_indic, const u8 *tlvs,
1197 size_t tlvs_len)
1198 {
1199 DBusMessage *msg;
1200 DBusMessageIter iter, dict_iter;
1201 struct wpas_dbus_priv *iface;
1202 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1203 iface = wpa_s->global->dbus;
1204
1205 /* Do nothing if the control interface is not turned on */
1206 if (iface == NULL)
1207 return;
1208
1209 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1210 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1211 "ServiceDiscoveryRequest");
1212 if (msg == NULL)
1213 return;
1214
1215 /* Check if this is a known peer */
1216 if (p2p_get_peer_info(wpa_s->global->p2p, sa, 0, NULL, 0) < 0)
1217 goto error;
1218
1219 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1220 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1221 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1222
1223 path = peer_obj_path;
1224
1225 dbus_message_iter_init_append(msg, &iter);
1226 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1227 goto error;
1228
1229
1230 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1231 path) ||
1232 !wpa_dbus_dict_append_int32(&dict_iter, "frequency", freq) ||
1233 !wpa_dbus_dict_append_int32(&dict_iter, "dialog_token",
1234 dialog_token) ||
1235 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1236 update_indic) ||
1237 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1238 (const char *) tlvs,
1239 tlvs_len) ||
1240 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1241 goto error;
1242
1243 dbus_connection_send(iface->con, msg, NULL);
1244 dbus_message_unref(msg);
1245 return;
1246 error:
1247 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1248 dbus_message_unref(msg);
1249 }
1250
1251
1252 /**
1253 *
1254 * Method to emit a signal for a service discovery response.
1255 * The signal will carry station address, update indicator and it
1256 * tlvs
1257 *
1258 * @wpa_s: %wpa_supplicant network interface data
1259 * @sa: station addr (p2p i/f) of the peer
1260 * @update_indic: service discovery request update indicator
1261 * @tlvs: service discovery request genrated byte array of tlvs
1262 * @tlvs_len: service discovery request tlvs length
1263 */
1264 void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
1265 const u8 *sa, u16 update_indic,
1266 const u8 *tlvs, size_t tlvs_len)
1267 {
1268 DBusMessage *msg;
1269 DBusMessageIter iter, dict_iter;
1270 struct wpas_dbus_priv *iface;
1271 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1272 iface = wpa_s->global->dbus;
1273
1274 /* Do nothing if the control interface is not turned on */
1275 if (iface == NULL)
1276 return;
1277
1278 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1279 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1280 "ServiceDiscoveryResponse");
1281 if (msg == NULL)
1282 return;
1283
1284 /* Check if this is a known peer */
1285 if (p2p_get_peer_info(wpa_s->global->p2p, sa, 0, NULL, 0) < 0)
1286 goto error;
1287
1288 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1289 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
1290 COMPACT_MACSTR, wpa_s->dbus_new_path, MAC2STR(sa));
1291
1292 path = peer_obj_path;
1293
1294 dbus_message_iter_init_append(msg, &iter);
1295 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
1296 goto error;
1297
1298 if (!wpa_dbus_dict_append_object_path(&dict_iter, "peer_object",
1299 path) ||
1300 !wpa_dbus_dict_append_uint16(&dict_iter, "update_indicator",
1301 update_indic) ||
1302 !wpa_dbus_dict_append_byte_array(&dict_iter, "tlvs",
1303 (const char *) tlvs,
1304 tlvs_len) ||
1305 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1306 goto error;
1307
1308
1309 dbus_connection_send(iface->con, msg, NULL);
1310 dbus_message_unref(msg);
1311 return;
1312 error:
1313 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1314 dbus_message_unref(msg);
1315 }
1316
1317 /**
1318 * wpas_dbus_signal_persistent_group - Send a persistent group related
1319 * event signal
1320 * @wpa_s: %wpa_supplicant network interface data
1321 * @id: new persistent group id
1322 * @sig_name: signal name - PersistentGroupAdded, PersistentGroupRemoved
1323 * @properties: determines if add second argument with object properties
1324 *
1325 * Notify listeners about an event related to persistent groups.
1326 */
1327 static void wpas_dbus_signal_persistent_group(struct wpa_supplicant *wpa_s,
1328 int id, const char *sig_name,
1329 int properties)
1330 {
1331 struct wpas_dbus_priv *iface;
1332 DBusMessage *msg;
1333 DBusMessageIter iter;
1334 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
1335
1336 iface = wpa_s->global->dbus;
1337
1338 /* Do nothing if the control interface is not turned on */
1339 if (iface == NULL)
1340 return;
1341
1342 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1343 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
1344 wpa_s->dbus_new_path, id);
1345
1346 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1347 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1348 sig_name);
1349 if (msg == NULL)
1350 return;
1351
1352 dbus_message_iter_init_append(msg, &iter);
1353 path = pgrp_obj_path;
1354 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
1355 &path))
1356 goto err;
1357
1358 if (properties) {
1359 if (!wpa_dbus_get_object_properties(
1360 iface, pgrp_obj_path,
1361 WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, &iter))
1362 goto err;
1363 }
1364
1365 dbus_connection_send(iface->con, msg, NULL);
1366
1367 dbus_message_unref(msg);
1368 return;
1369
1370 err:
1371 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1372 dbus_message_unref(msg);
1373 }
1374
1375
1376 /**
1377 * wpas_dbus_signal_persistent_group_added - Send a persistent_group
1378 * added signal
1379 * @wpa_s: %wpa_supplicant network interface data
1380 * @id: new persistent group id
1381 *
1382 * Notify listeners about addition of a new persistent group.
1383 */
1384 static void wpas_dbus_signal_persistent_group_added(
1385 struct wpa_supplicant *wpa_s, int id)
1386 {
1387 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupAdded",
1388 TRUE);
1389 }
1390
1391
1392 /**
1393 * wpas_dbus_signal_persistent_group_removed - Send a persistent_group
1394 * removed signal
1395 * @wpa_s: %wpa_supplicant network interface data
1396 * @id: persistent group id
1397 *
1398 * Notify listeners about removal of a persistent group.
1399 */
1400 static void wpas_dbus_signal_persistent_group_removed(
1401 struct wpa_supplicant *wpa_s, int id)
1402 {
1403 wpas_dbus_signal_persistent_group(wpa_s, id, "PersistentGroupRemoved",
1404 FALSE);
1405 }
1406
1407
1408 /**
1409 * wpas_dbus_signal_p2p_wps_failed - Signals WpsFailed event
1410 * @wpa_s: %wpa_supplicant network interface data
1411 *
1412 * Sends Event dbus signal with name "fail" and dictionary containing
1413 * "msg" field with fail message number (int32) as arguments
1414 */
1415 void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
1416 struct wps_event_fail *fail)
1417 {
1418
1419 DBusMessage *msg;
1420 DBusMessageIter iter, dict_iter;
1421 struct wpas_dbus_priv *iface;
1422 char *key = "fail";
1423
1424 iface = wpa_s->global->dbus;
1425
1426 /* Do nothing if the control interface is not turned on */
1427 if (iface == NULL)
1428 return;
1429
1430 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
1431 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
1432 "WpsFailed");
1433 if (msg == NULL)
1434 return;
1435
1436 dbus_message_iter_init_append(msg, &iter);
1437
1438 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
1439 !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
1440 !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
1441 !wpa_dbus_dict_append_int16(&dict_iter, "config_error",
1442 fail->config_error) ||
1443 !wpa_dbus_dict_close_write(&iter, &dict_iter))
1444 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
1445 else
1446 dbus_connection_send(iface->con, msg, NULL);
1447
1448 dbus_message_unref(msg);
1449 }
1450
1451 #endif /*CONFIG_P2P*/
1452
1453
1454 /**
1455 * wpas_dbus_signal_prop_changed - Signals change of property
1456 * @wpa_s: %wpa_supplicant network interface data
1457 * @property: indicates which property has changed
1458 *
1459 * Sends PropertyChanged signals with path, interface and arguments
1460 * depending on which property has changed.
1461 */
1462 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
1463 enum wpas_dbus_prop property)
1464 {
1465 WPADBusPropertyAccessor getter;
1466 char *prop;
1467
1468 if (wpa_s->dbus_new_path == NULL)
1469 return; /* Skip signal since D-Bus setup is not yet ready */
1470
1471 switch (property) {
1472 case WPAS_DBUS_PROP_AP_SCAN:
1473 getter = wpas_dbus_getter_ap_scan;
1474 prop = "ApScan";
1475 break;
1476 case WPAS_DBUS_PROP_SCANNING:
1477 getter = wpas_dbus_getter_scanning;
1478 prop = "Scanning";
1479 break;
1480 case WPAS_DBUS_PROP_STATE:
1481 getter = wpas_dbus_getter_state;
1482 prop = "State";
1483 break;
1484 case WPAS_DBUS_PROP_CURRENT_BSS:
1485 getter = wpas_dbus_getter_current_bss;
1486 prop = "CurrentBSS";
1487 break;
1488 case WPAS_DBUS_PROP_CURRENT_NETWORK:
1489 getter = wpas_dbus_getter_current_network;
1490 prop = "CurrentNetwork";
1491 break;
1492 case WPAS_DBUS_PROP_BSSS:
1493 getter = wpas_dbus_getter_bsss;
1494 prop = "BSSs";
1495 break;
1496 case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
1497 getter = wpas_dbus_getter_current_auth_mode;
1498 prop = "CurrentAuthMode";
1499 break;
1500 default:
1501 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1502 __func__, property);
1503 return;
1504 }
1505
1506 wpa_dbus_mark_property_changed(wpa_s->global->dbus,
1507 wpa_s->dbus_new_path,
1508 WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
1509 }
1510
1511
1512 /**
1513 * wpas_dbus_bss_signal_prop_changed - Signals change of BSS property
1514 * @wpa_s: %wpa_supplicant network interface data
1515 * @property: indicates which property has changed
1516 * @id: unique BSS identifier
1517 *
1518 * Sends PropertyChanged signals with path, interface, and arguments depending
1519 * on which property has changed.
1520 */
1521 void wpas_dbus_bss_signal_prop_changed(struct wpa_supplicant *wpa_s,
1522 enum wpas_dbus_bss_prop property,
1523 unsigned int id)
1524 {
1525 char path[WPAS_DBUS_OBJECT_PATH_MAX];
1526 char *prop;
1527
1528 switch (property) {
1529 case WPAS_DBUS_BSS_PROP_SIGNAL:
1530 prop = "Signal";
1531 break;
1532 case WPAS_DBUS_BSS_PROP_FREQ:
1533 prop = "Frequency";
1534 break;
1535 case WPAS_DBUS_BSS_PROP_MODE:
1536 prop = "Mode";
1537 break;
1538 case WPAS_DBUS_BSS_PROP_PRIVACY:
1539 prop = "Privacy";
1540 break;
1541 case WPAS_DBUS_BSS_PROP_RATES:
1542 prop = "Rates";
1543 break;
1544 case WPAS_DBUS_BSS_PROP_WPA:
1545 prop = "WPA";
1546 break;
1547 case WPAS_DBUS_BSS_PROP_RSN:
1548 prop = "RSN";
1549 break;
1550 case WPAS_DBUS_BSS_PROP_IES:
1551 prop = "IEs";
1552 break;
1553 default:
1554 wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
1555 __func__, property);
1556 return;
1557 }
1558
1559 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1560 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1561 wpa_s->dbus_new_path, id);
1562
1563 wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
1564 WPAS_DBUS_NEW_IFACE_BSS, prop);
1565 }
1566
1567
1568 /**
1569 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
1570 * @global: wpa_global structure
1571 *
1572 * Sends PropertyChanged signals informing that debug level has changed.
1573 */
1574 void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
1575 {
1576 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1577 WPAS_DBUS_NEW_INTERFACE,
1578 "DebugLevel");
1579 }
1580
1581
1582 /**
1583 * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
1584 * @global: wpa_global structure
1585 *
1586 * Sends PropertyChanged signals informing that debug timestamp has changed.
1587 */
1588 void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
1589 {
1590 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1591 WPAS_DBUS_NEW_INTERFACE,
1592 "DebugTimestamp");
1593 }
1594
1595
1596 /**
1597 * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
1598 * @global: wpa_global structure
1599 *
1600 * Sends PropertyChanged signals informing that debug show_keys has changed.
1601 */
1602 void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
1603 {
1604 wpa_dbus_mark_property_changed(global->dbus, WPAS_DBUS_NEW_PATH,
1605 WPAS_DBUS_NEW_INTERFACE,
1606 "DebugShowKeys");
1607 }
1608
1609
1610 static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
1611 void *priv,
1612 WPADBusArgumentFreeFunction priv_free,
1613 const struct wpa_dbus_method_desc *methods,
1614 const struct wpa_dbus_property_desc *properties,
1615 const struct wpa_dbus_signal_desc *signals)
1616 {
1617 int n;
1618
1619 obj_desc->user_data = priv;
1620 obj_desc->user_data_free_func = priv_free;
1621 obj_desc->methods = methods;
1622 obj_desc->properties = properties;
1623 obj_desc->signals = signals;
1624
1625 for (n = 0; properties && properties->dbus_property; properties++)
1626 n++;
1627
1628 obj_desc->prop_changed_flags = os_zalloc(n);
1629 if (!obj_desc->prop_changed_flags)
1630 wpa_printf(MSG_DEBUG, "dbus: %s: can't register handlers",
1631 __func__);
1632 }
1633
1634
1635 static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
1636 { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
1637 (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
1638 {
1639 { "args", "a{sv}", ARG_IN },
1640 { "path", "o", ARG_OUT },
1641 END_ARGS
1642 }
1643 },
1644 { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
1645 (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
1646 {
1647 { "path", "o", ARG_IN },
1648 END_ARGS
1649 }
1650 },
1651 { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
1652 (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
1653 {
1654 { "ifname", "s", ARG_IN },
1655 { "path", "o", ARG_OUT },
1656 END_ARGS
1657 }
1658 },
1659 { NULL, NULL, NULL, { END_ARGS } }
1660 };
1661
1662 static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
1663 { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
1664 wpas_dbus_getter_debug_level,
1665 wpas_dbus_setter_debug_level
1666 },
1667 { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
1668 wpas_dbus_getter_debug_timestamp,
1669 wpas_dbus_setter_debug_timestamp
1670 },
1671 { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
1672 wpas_dbus_getter_debug_show_keys,
1673 wpas_dbus_setter_debug_show_keys
1674 },
1675 { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
1676 wpas_dbus_getter_interfaces,
1677 NULL
1678 },
1679 { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
1680 wpas_dbus_getter_eap_methods,
1681 NULL
1682 },
1683 { NULL, NULL, NULL, NULL, NULL }
1684 };
1685
1686 static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
1687 { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
1688 {
1689 { "path", "o", ARG_OUT },
1690 { "properties", "a{sv}", ARG_OUT },
1691 END_ARGS
1692 }
1693 },
1694 { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
1695 {
1696 { "path", "o", ARG_OUT },
1697 END_ARGS
1698 }
1699 },
1700 { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
1701 {
1702 { "properties", "a{sv}", ARG_OUT },
1703 END_ARGS
1704 }
1705 },
1706 { NULL, NULL, { END_ARGS } }
1707 };
1708
1709
1710 /**
1711 * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
1712 * @global: Pointer to global data from wpa_supplicant_init()
1713 * Returns: 0 on success or -1 on failure
1714 *
1715 * Initialize the dbus control interface for wpa_supplicantand and start
1716 * receiving commands from external programs over the bus.
1717 */
1718 int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
1719 {
1720 struct wpa_dbus_object_desc *obj_desc;
1721 int ret;
1722
1723 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
1724 if (!obj_desc) {
1725 wpa_printf(MSG_ERROR, "Not enough memory "
1726 "to create object description");
1727 return -1;
1728 }
1729
1730 wpas_dbus_register(obj_desc, priv->global, NULL,
1731 wpas_dbus_global_methods,
1732 wpas_dbus_global_properties,
1733 wpas_dbus_global_signals);
1734
1735 wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
1736 WPAS_DBUS_NEW_PATH);
1737 ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
1738 WPAS_DBUS_NEW_SERVICE,
1739 obj_desc);
1740 if (ret < 0)
1741 free_dbus_object_desc(obj_desc);
1742 else
1743 priv->dbus_new_initialized = 1;
1744
1745 return ret;
1746 }
1747
1748
1749 /**
1750 * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
1751 * wpa_supplicant
1752 * @iface: Pointer to dbus private data from wpas_dbus_init()
1753 *
1754 * Deinitialize the dbus control interface that was initialized with
1755 * wpas_dbus_ctrl_iface_init().
1756 */
1757 void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
1758 {
1759 if (!iface->dbus_new_initialized)
1760 return;
1761 wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
1762 WPAS_DBUS_NEW_PATH);
1763 dbus_connection_unregister_object_path(iface->con,
1764 WPAS_DBUS_NEW_PATH);
1765 }
1766
1767
1768 static void wpa_dbus_free(void *ptr)
1769 {
1770 os_free(ptr);
1771 }
1772
1773
1774 static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
1775 { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
1776 wpas_dbus_getter_network_properties,
1777 wpas_dbus_setter_network_properties
1778 },
1779 { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
1780 wpas_dbus_getter_enabled,
1781 wpas_dbus_setter_enabled
1782 },
1783 { NULL, NULL, NULL, NULL, NULL }
1784 };
1785
1786
1787 static const struct wpa_dbus_signal_desc wpas_dbus_network_signals[] = {
1788 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
1789 {
1790 { "properties", "a{sv}", ARG_OUT },
1791 END_ARGS
1792 }
1793 },
1794 { NULL, NULL, { END_ARGS } }
1795 };
1796
1797
1798 /**
1799 * wpas_dbus_register_network - Register a configured network with dbus
1800 * @wpa_s: wpa_supplicant interface structure
1801 * @ssid: network configuration data
1802 * Returns: 0 on success, -1 on failure
1803 *
1804 * Registers network representing object with dbus
1805 */
1806 int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
1807 struct wpa_ssid *ssid)
1808 {
1809 struct wpas_dbus_priv *ctrl_iface;
1810 struct wpa_dbus_object_desc *obj_desc;
1811 struct network_handler_args *arg;
1812 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1813
1814 #ifdef CONFIG_P2P
1815 /*
1816 * If it is a persistent group register it as such.
1817 * This is to handle cases where an interface is being initialized
1818 * with a list of networks read from config.
1819 */
1820 if (network_is_persistent_group(ssid))
1821 return wpas_dbus_register_persistent_group(wpa_s, ssid);
1822 #endif /* CONFIG_P2P */
1823
1824 /* Do nothing if the control interface is not turned on */
1825 if (wpa_s == NULL || wpa_s->global == NULL)
1826 return 0;
1827 ctrl_iface = wpa_s->global->dbus;
1828 if (ctrl_iface == NULL)
1829 return 0;
1830
1831 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1832 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
1833 wpa_s->dbus_new_path, ssid->id);
1834
1835 wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
1836 net_obj_path);
1837 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
1838 if (!obj_desc) {
1839 wpa_printf(MSG_ERROR, "Not enough memory "
1840 "to create object description");
1841 goto err;
1842 }
1843
1844 /* allocate memory for handlers arguments */
1845 arg = os_zalloc(sizeof(struct network_handler_args));
1846 if (!arg) {
1847 wpa_printf(MSG_ERROR, "Not enough memory "
1848 "to create arguments for method");
1849 goto err;
1850 }
1851
1852 arg->wpa_s = wpa_s;
1853 arg->ssid = ssid;
1854
1855 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
1856 wpas_dbus_network_properties,
1857 wpas_dbus_network_signals);
1858
1859 if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
1860 wpa_s->ifname, obj_desc))
1861 goto err;
1862
1863 wpas_dbus_signal_network_added(wpa_s, ssid->id);
1864
1865 return 0;
1866
1867 err:
1868 free_dbus_object_desc(obj_desc);
1869 return -1;
1870 }
1871
1872
1873 /**
1874 * wpas_dbus_unregister_network - Unregister a configured network from dbus
1875 * @wpa_s: wpa_supplicant interface structure
1876 * @nid: network id
1877 * Returns: 0 on success, -1 on failure
1878 *
1879 * Unregisters network representing object from dbus
1880 */
1881 int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
1882 {
1883 struct wpas_dbus_priv *ctrl_iface;
1884 char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1885 int ret;
1886 struct wpa_ssid *ssid;
1887
1888 ssid = wpa_config_get_network(wpa_s->conf, nid);
1889
1890 #ifdef CONFIG_P2P
1891 /* If it is a persistent group unregister it as such */
1892 if (ssid && network_is_persistent_group(ssid))
1893 return wpas_dbus_unregister_persistent_group(wpa_s, nid);
1894 #endif /* CONFIG_P2P */
1895
1896 /* Do nothing if the control interface is not turned on */
1897 if (wpa_s == NULL || wpa_s->global == NULL ||
1898 wpa_s->dbus_new_path == NULL)
1899 return 0;
1900 ctrl_iface = wpa_s->global->dbus;
1901 if (ctrl_iface == NULL)
1902 return 0;
1903
1904 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1905 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
1906 wpa_s->dbus_new_path, nid);
1907
1908 wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
1909 net_obj_path);
1910 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
1911
1912 if (!ret)
1913 wpas_dbus_signal_network_removed(wpa_s, nid);
1914
1915 return ret;
1916 }
1917
1918
1919 static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
1920 { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
1921 wpas_dbus_getter_bss_ssid,
1922 NULL
1923 },
1924 { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
1925 wpas_dbus_getter_bss_bssid,
1926 NULL
1927 },
1928 { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
1929 wpas_dbus_getter_bss_privacy,
1930 NULL
1931 },
1932 { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
1933 wpas_dbus_getter_bss_mode,
1934 NULL
1935 },
1936 { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
1937 wpas_dbus_getter_bss_signal,
1938 NULL
1939 },
1940 { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
1941 wpas_dbus_getter_bss_frequency,
1942 NULL
1943 },
1944 { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
1945 wpas_dbus_getter_bss_rates,
1946 NULL
1947 },
1948 { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
1949 wpas_dbus_getter_bss_wpa,
1950 NULL
1951 },
1952 { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
1953 wpas_dbus_getter_bss_rsn,
1954 NULL
1955 },
1956 { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
1957 wpas_dbus_getter_bss_ies,
1958 NULL
1959 },
1960 { NULL, NULL, NULL, NULL, NULL }
1961 };
1962
1963
1964 static const struct wpa_dbus_signal_desc wpas_dbus_bss_signals[] = {
1965 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSS,
1966 {
1967 { "properties", "a{sv}", ARG_OUT },
1968 END_ARGS
1969 }
1970 },
1971 { NULL, NULL, { END_ARGS } }
1972 };
1973
1974
1975 /**
1976 * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
1977 * @wpa_s: wpa_supplicant interface structure
1978 * @bssid: scanned network bssid
1979 * @id: unique BSS identifier
1980 * Returns: 0 on success, -1 on failure
1981 *
1982 * Unregisters BSS representing object from dbus
1983 */
1984 int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
1985 u8 bssid[ETH_ALEN], unsigned int id)
1986 {
1987 struct wpas_dbus_priv *ctrl_iface;
1988 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
1989
1990 /* Do nothing if the control interface is not turned on */
1991 if (wpa_s == NULL || wpa_s->global == NULL)
1992 return 0;
1993 ctrl_iface = wpa_s->global->dbus;
1994 if (ctrl_iface == NULL)
1995 return 0;
1996
1997 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
1998 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
1999 wpa_s->dbus_new_path, id);
2000
2001 wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
2002 bss_obj_path);
2003 if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
2004 wpa_printf(MSG_ERROR, "dbus: Cannot unregister BSS object %s",
2005 bss_obj_path);
2006 return -1;
2007 }
2008
2009 wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
2010 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2011
2012 return 0;
2013 }
2014
2015
2016 /**
2017 * wpas_dbus_register_bss - Register a scanned BSS with dbus
2018 * @wpa_s: wpa_supplicant interface structure
2019 * @bssid: scanned network bssid
2020 * @id: unique BSS identifier
2021 * Returns: 0 on success, -1 on failure
2022 *
2023 * Registers BSS representing object with dbus
2024 */
2025 int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
2026 u8 bssid[ETH_ALEN], unsigned int id)
2027 {
2028 struct wpas_dbus_priv *ctrl_iface;
2029 struct wpa_dbus_object_desc *obj_desc;
2030 char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2031 struct bss_handler_args *arg;
2032
2033 /* Do nothing if the control interface is not turned on */
2034 if (wpa_s == NULL || wpa_s->global == NULL)
2035 return 0;
2036 ctrl_iface = wpa_s->global->dbus;
2037 if (ctrl_iface == NULL)
2038 return 0;
2039
2040 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2041 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2042 wpa_s->dbus_new_path, id);
2043
2044 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2045 if (!obj_desc) {
2046 wpa_printf(MSG_ERROR, "Not enough memory "
2047 "to create object description");
2048 goto err;
2049 }
2050
2051 arg = os_zalloc(sizeof(struct bss_handler_args));
2052 if (!arg) {
2053 wpa_printf(MSG_ERROR, "Not enough memory "
2054 "to create arguments for handler");
2055 goto err;
2056 }
2057 arg->wpa_s = wpa_s;
2058 arg->id = id;
2059
2060 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
2061 wpas_dbus_bss_properties,
2062 wpas_dbus_bss_signals);
2063
2064 wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
2065 bss_obj_path);
2066 if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
2067 wpa_s->ifname, obj_desc)) {
2068 wpa_printf(MSG_ERROR,
2069 "Cannot register BSSID dbus object %s.",
2070 bss_obj_path);
2071 goto err;
2072 }
2073
2074 wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
2075 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS);
2076
2077 return 0;
2078
2079 err:
2080 free_dbus_object_desc(obj_desc);
2081 return -1;
2082 }
2083
2084
2085 static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
2086 { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2087 (WPADBusMethodHandler) &wpas_dbus_handler_scan,
2088 {
2089 { "args", "a{sv}", ARG_IN },
2090 END_ARGS
2091 }
2092 },
2093 { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
2094 (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
2095 {
2096 END_ARGS
2097 }
2098 },
2099 { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2100 (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
2101 {
2102 { "args", "a{sv}", ARG_IN },
2103 { "path", "o", ARG_OUT },
2104 END_ARGS
2105 }
2106 },
2107 { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2108 (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
2109 {
2110 { "path", "o", ARG_IN },
2111 END_ARGS
2112 }
2113 },
2114 { "RemoveAllNetworks", WPAS_DBUS_NEW_IFACE_INTERFACE,
2115 (WPADBusMethodHandler) &wpas_dbus_handler_remove_all_networks,
2116 {
2117 END_ARGS
2118 }
2119 },
2120 { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
2121 (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
2122 {
2123 { "path", "o", ARG_IN },
2124 END_ARGS
2125 }
2126 },
2127 { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2128 (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
2129 {
2130 { "name", "s", ARG_IN },
2131 { "data", "ay", ARG_IN },
2132 END_ARGS
2133 }
2134 },
2135 { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2136 (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
2137 {
2138 { "name", "s", ARG_IN },
2139 { "data", "ay", ARG_OUT },
2140 END_ARGS
2141 }
2142 },
2143 { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
2144 (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
2145 {
2146 { "name", "s", ARG_IN },
2147 END_ARGS
2148 }
2149 },
2150 #ifdef CONFIG_WPS
2151 { "Start", WPAS_DBUS_NEW_IFACE_WPS,
2152 (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
2153 {
2154 { "args", "a{sv}", ARG_IN },
2155 { "output", "a{sv}", ARG_OUT },
2156 END_ARGS
2157 }
2158 },
2159 #endif /* CONFIG_WPS */
2160 #ifdef CONFIG_P2P
2161 { "Find", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2162 (WPADBusMethodHandler)wpas_dbus_handler_p2p_find,
2163 {
2164 { "args", "a{sv}", ARG_IN },
2165 END_ARGS
2166 }
2167 },
2168 { "StopFind", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2169 (WPADBusMethodHandler)wpas_dbus_handler_p2p_stop_find,
2170 {
2171 END_ARGS
2172 }
2173 },
2174 { "Listen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2175 (WPADBusMethodHandler)wpas_dbus_handler_p2p_listen,
2176 {
2177 { "timeout", "i", ARG_IN },
2178 END_ARGS
2179 }
2180 },
2181 { "ExtendedListen", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2182 (WPADBusMethodHandler)wpas_dbus_handler_p2p_extendedlisten,
2183 {
2184 { "args", "a{sv}", ARG_IN },
2185 END_ARGS
2186 }
2187 },
2188 { "PresenceRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2189 (WPADBusMethodHandler)wpas_dbus_handler_p2p_presence_request,
2190 {
2191 { "args", "a{sv}", ARG_IN },
2192 END_ARGS
2193 }
2194 },
2195 { "ProvisionDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2196 (WPADBusMethodHandler)wpas_dbus_handler_p2p_prov_disc_req,
2197 {
2198 { "peer", "o", ARG_IN },
2199 { "config_method", "s", ARG_IN },
2200 END_ARGS
2201 }
2202 },
2203 { "Connect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2204 (WPADBusMethodHandler)wpas_dbus_handler_p2p_connect,
2205 {
2206 { "args", "a{sv}", ARG_IN },
2207 { "generated_pin", "s", ARG_OUT },
2208 END_ARGS
2209 }
2210 },
2211 { "GroupAdd", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2212 (WPADBusMethodHandler)wpas_dbus_handler_p2p_group_add,
2213 {
2214 { "args", "a{sv}", ARG_IN },
2215 END_ARGS
2216 }
2217 },
2218 { "Invite", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2219 (WPADBusMethodHandler)wpas_dbus_handler_p2p_invite,
2220 {
2221 { "args", "a{sv}", ARG_IN },
2222 END_ARGS
2223 }
2224 },
2225 { "Disconnect", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2226 (WPADBusMethodHandler)wpas_dbus_handler_p2p_disconnect,
2227 {
2228 END_ARGS
2229 }
2230 },
2231 { "RejectPeer", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2232 (WPADBusMethodHandler)wpas_dbus_handler_p2p_rejectpeer,
2233 {
2234 { "peer", "o", ARG_IN },
2235 END_ARGS
2236 }
2237 },
2238 { "Flush", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2239 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush,
2240 {
2241 END_ARGS
2242 }
2243 },
2244 { "AddService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2245 (WPADBusMethodHandler)wpas_dbus_handler_p2p_add_service,
2246 {
2247 { "args", "a{sv}", ARG_IN },
2248 END_ARGS
2249 }
2250 },
2251 { "DeleteService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2252 (WPADBusMethodHandler)wpas_dbus_handler_p2p_delete_service,
2253 {
2254 { "args", "a{sv}", ARG_IN },
2255 END_ARGS
2256 }
2257 },
2258 { "FlushService", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2259 (WPADBusMethodHandler)wpas_dbus_handler_p2p_flush_service,
2260 {
2261 END_ARGS
2262 }
2263 },
2264 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2265 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
2266 {
2267 { "args", "a{sv}", ARG_IN },
2268 END_ARGS
2269 }
2270 },
2271 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2272 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_res,
2273 {
2274 { "args", "a{sv}", ARG_IN },
2275 END_ARGS
2276 }
2277 },
2278 { "ServiceDiscoveryCancelRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2279 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_cancel_req,
2280 {
2281 { "args", "t", ARG_IN },
2282 END_ARGS
2283 }
2284 },
2285 { "ServiceUpdate", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2286 (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_update,
2287 {
2288 END_ARGS
2289 }
2290 },
2291 { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2292 (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
2293 {
2294 { "arg", "i", ARG_IN },
2295 END_ARGS
2296 }
2297 },
2298 { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2299 (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
2300 {
2301 { "arg", "i", ARG_IN },
2302 END_ARGS
2303 }
2304 },
2305 { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2306 (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
2307 {
2308 { "args", "a{sv}", ARG_IN },
2309 { "path", "o", ARG_OUT },
2310 END_ARGS
2311 }
2312 },
2313 { "RemovePersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2314 (WPADBusMethodHandler) wpas_dbus_handler_remove_persistent_group,
2315 {
2316 { "path", "o", ARG_IN },
2317 END_ARGS
2318 }
2319 },
2320 { "RemoveAllPersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2321 (WPADBusMethodHandler)
2322 wpas_dbus_handler_remove_all_persistent_groups,
2323 {
2324 END_ARGS
2325 }
2326 },
2327 #endif /* CONFIG_P2P */
2328 { "FlushBSS", WPAS_DBUS_NEW_IFACE_INTERFACE,
2329 (WPADBusMethodHandler) &wpas_dbus_handler_flush_bss,
2330 {
2331 { "age", "u", ARG_IN },
2332 END_ARGS
2333 }
2334 },
2335 { NULL, NULL, NULL, { END_ARGS } }
2336 };
2337
2338 static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
2339 { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
2340 wpas_dbus_getter_capabilities,
2341 NULL
2342 },
2343 { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2344 wpas_dbus_getter_state,
2345 NULL
2346 },
2347 { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
2348 wpas_dbus_getter_scanning,
2349 NULL
2350 },
2351 { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2352 wpas_dbus_getter_ap_scan,
2353 wpas_dbus_setter_ap_scan
2354 },
2355 { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2356 wpas_dbus_getter_bss_expire_age,
2357 wpas_dbus_setter_bss_expire_age
2358 },
2359 { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
2360 wpas_dbus_getter_bss_expire_count,
2361 wpas_dbus_setter_bss_expire_count
2362 },
2363 { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2364 wpas_dbus_getter_country,
2365 wpas_dbus_setter_country
2366 },
2367 { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2368 wpas_dbus_getter_ifname,
2369 NULL
2370 },
2371 { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2372 wpas_dbus_getter_driver,
2373 NULL
2374 },
2375 { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2376 wpas_dbus_getter_bridge_ifname,
2377 NULL
2378 },
2379 { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2380 wpas_dbus_getter_current_bss,
2381 NULL
2382 },
2383 { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
2384 wpas_dbus_getter_current_network,
2385 NULL
2386 },
2387 { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
2388 wpas_dbus_getter_current_auth_mode,
2389 NULL
2390 },
2391 { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
2392 wpas_dbus_getter_blobs,
2393 NULL
2394 },
2395 { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2396 wpas_dbus_getter_bsss,
2397 NULL
2398 },
2399 { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
2400 wpas_dbus_getter_networks,
2401 NULL
2402 },
2403 #ifdef CONFIG_WPS
2404 { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
2405 wpas_dbus_getter_process_credentials,
2406 wpas_dbus_setter_process_credentials
2407 },
2408 #endif /* CONFIG_WPS */
2409 #ifdef CONFIG_P2P
2410 { "P2PDeviceProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
2411 wpas_dbus_getter_p2p_device_properties,
2412 wpas_dbus_setter_p2p_device_properties
2413 },
2414 { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2415 wpas_dbus_getter_p2p_peers,
2416 NULL
2417 },
2418 { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
2419 wpas_dbus_getter_p2p_role,
2420 NULL
2421 },
2422 { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2423 wpas_dbus_getter_p2p_group,
2424 NULL
2425 },
2426 { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
2427 wpas_dbus_getter_p2p_peergo,
2428 NULL
2429 },
2430 { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
2431 wpas_dbus_getter_persistent_groups,
2432 NULL
2433 },
2434 #endif /* CONFIG_P2P */
2435 { NULL, NULL, NULL, NULL, NULL }
2436 };
2437
2438 static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
2439 { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
2440 {
2441 { "success", "b", ARG_OUT },
2442 END_ARGS
2443 }
2444 },
2445 { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2446 {
2447 { "path", "o", ARG_OUT },
2448 { "properties", "a{sv}", ARG_OUT },
2449 END_ARGS
2450 }
2451 },
2452 { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2453 {
2454 { "path", "o", ARG_OUT },
2455 END_ARGS
2456 }
2457 },
2458 { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2459 {
2460 { "name", "s", ARG_OUT },
2461 END_ARGS
2462 }
2463 },
2464 { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2465 {
2466 { "name", "s", ARG_OUT },
2467 END_ARGS
2468 }
2469 },
2470 { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
2471 {
2472 { "path", "o", ARG_OUT },
2473 { "properties", "a{sv}", ARG_OUT },
2474 END_ARGS
2475 }
2476 },
2477 { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
2478 {
2479 { "path", "o", ARG_OUT },
2480 END_ARGS
2481 }
2482 },
2483 { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
2484 {
2485 { "path", "o", ARG_OUT },
2486 END_ARGS
2487 }
2488 },
2489 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
2490 {
2491 { "properties", "a{sv}", ARG_OUT },
2492 END_ARGS
2493 }
2494 },
2495 #ifdef CONFIG_WPS
2496 { "Event", WPAS_DBUS_NEW_IFACE_WPS,
2497 {
2498 { "name", "s", ARG_OUT },
2499 { "args", "a{sv}", ARG_OUT },
2500 END_ARGS
2501 }
2502 },
2503 { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
2504 {
2505 { "credentials", "a{sv}", ARG_OUT },
2506 END_ARGS
2507 }
2508 },
2509 { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
2510 {
2511 { "properties", "a{sv}", ARG_OUT },
2512 END_ARGS
2513 }
2514 },
2515 #endif /* CONFIG_WPS */
2516 #ifdef CONFIG_P2P
2517 { "P2PStateChanged", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2518 {
2519 { "states", "a{ss}", ARG_OUT },
2520 END_ARGS
2521 }
2522 },
2523 { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2524 {
2525 { "path", "o", ARG_OUT },
2526 { "properties", "a{sv}", ARG_OUT },
2527 END_ARGS
2528 }
2529 },
2530 { "DeviceLost", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2531 {
2532 { "path", "o", ARG_OUT },
2533 END_ARGS
2534 }
2535 },
2536 { "ProvisionDiscoveryRequestDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2537 {
2538 { "peer_object", "o", ARG_OUT },
2539 { "pin", "s", ARG_OUT },
2540 END_ARGS
2541 }
2542 },
2543 { "ProvisionDiscoveryResponseDisplayPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2544 {
2545 { "peer_object", "o", ARG_OUT },
2546 { "pin", "s", ARG_OUT },
2547 END_ARGS
2548 }
2549 },
2550 { "ProvisionDiscoveryRequestEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2551 {
2552 { "peer_object", "o", ARG_OUT },
2553 END_ARGS
2554 }
2555 },
2556 { "ProvisionDiscoveryResponseEnterPin", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2557 {
2558 { "peer_object", "o", ARG_OUT },
2559 END_ARGS
2560 }
2561 },
2562 { "ProvisionDiscoveryPBCRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2563 {
2564 { "peer_object", "o", ARG_OUT },
2565 END_ARGS
2566 }
2567 },
2568 { "ProvisionDiscoveryPBCResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2569 {
2570 { "peer_object", "o", ARG_OUT },
2571 END_ARGS
2572 }
2573 },
2574 { "ProvisionDiscoveryFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2575 {
2576 { "peer_object", "o", ARG_OUT },
2577 { "status", "i", ARG_OUT },
2578 END_ARGS
2579 }
2580 },
2581 { "GroupStarted", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2582 {
2583 { "properties", "a{sv}", ARG_OUT },
2584 END_ARGS
2585 }
2586 },
2587 { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2588 {
2589 END_ARGS
2590 }
2591 },
2592 { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2593 {
2594 { "status", "i", ARG_OUT },
2595 END_ARGS
2596 }
2597 },
2598 { "GONegotiationRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2599 {
2600 { "path", "o", ARG_OUT },
2601 { "dev_passwd_id", "i", ARG_OUT },
2602 END_ARGS
2603 }
2604 },
2605 { "InvitationResult", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2606 {
2607 { "invite_result", "a{sv}", ARG_OUT },
2608 END_ARGS
2609 }
2610 },
2611 { "GroupFinished", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2612 {
2613 { "ifname", "s", ARG_OUT },
2614 { "role", "s", ARG_OUT },
2615 END_ARGS
2616 }
2617 },
2618 { "ServiceDiscoveryRequest", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2619 {
2620 { "sd_request", "a{sv}", ARG_OUT },
2621 END_ARGS
2622 }
2623 },
2624 { "ServiceDiscoveryResponse", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2625 {
2626 { "sd_response", "a{sv}", ARG_OUT },
2627 END_ARGS
2628 }
2629 },
2630 { "PersistentGroupAdded", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2631 {
2632 { "path", "o", ARG_OUT },
2633 { "properties", "a{sv}", ARG_OUT },
2634 END_ARGS
2635 }
2636 },
2637 { "PersistentGroupRemoved", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2638 {
2639 { "path", "o", ARG_OUT },
2640 END_ARGS
2641 }
2642 },
2643 { "WpsFailed", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2644 {
2645 { "name", "s", ARG_OUT },
2646 { "args", "a{sv}", ARG_OUT },
2647 END_ARGS
2648 }
2649 },
2650 #endif /* CONFIG_P2P */
2651 { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
2652 {
2653 { "certification", "a{sv}", ARG_OUT },
2654 END_ARGS
2655 }
2656 },
2657 { NULL, NULL, { END_ARGS } }
2658 };
2659
2660
2661 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
2662 {
2663
2664 struct wpa_dbus_object_desc *obj_desc = NULL;
2665 struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
2666 int next;
2667
2668 /* Do nothing if the control interface is not turned on */
2669 if (ctrl_iface == NULL)
2670 return 0;
2671
2672 /* Create and set the interface's object path */
2673 wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2674 if (wpa_s->dbus_new_path == NULL)
2675 return -1;
2676 next = ctrl_iface->next_objid++;
2677 os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
2678 WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
2679 next);
2680
2681 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2682 if (!obj_desc) {
2683 wpa_printf(MSG_ERROR, "Not enough memory "
2684 "to create object description");
2685 goto err;
2686 }
2687
2688 wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
2689 wpas_dbus_interface_properties,
2690 wpas_dbus_interface_signals);
2691
2692 wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
2693 wpa_s->dbus_new_path);
2694 if (wpa_dbus_register_object_per_iface(ctrl_iface,
2695 wpa_s->dbus_new_path,
2696 wpa_s->ifname, obj_desc))
2697 goto err;
2698
2699 wpas_dbus_signal_interface_added(wpa_s);
2700
2701 return 0;
2702
2703 err:
2704 os_free(wpa_s->dbus_new_path);
2705 wpa_s->dbus_new_path = NULL;
2706 free_dbus_object_desc(obj_desc);
2707 return -1;
2708 }
2709
2710
2711 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
2712 {
2713 struct wpas_dbus_priv *ctrl_iface;
2714
2715 /* Do nothing if the control interface is not turned on */
2716 if (wpa_s == NULL || wpa_s->global == NULL)
2717 return 0;
2718 ctrl_iface = wpa_s->global->dbus;
2719 if (ctrl_iface == NULL)
2720 return 0;
2721
2722 wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
2723 wpa_s->dbus_new_path);
2724 if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
2725 wpa_s->dbus_new_path))
2726 return -1;
2727
2728 wpas_dbus_signal_interface_removed(wpa_s);
2729
2730 os_free(wpa_s->dbus_new_path);
2731 wpa_s->dbus_new_path = NULL;
2732
2733 return 0;
2734 }
2735
2736 #ifdef CONFIG_P2P
2737
2738 static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
2739 { "Properties", WPAS_DBUS_NEW_IFACE_P2P_PEER, "a{sv}",
2740 wpas_dbus_getter_p2p_peer_properties,
2741 NULL
2742 },
2743 { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
2744 wpas_dbus_getter_p2p_peer_ies,
2745 NULL
2746 },
2747 { NULL, NULL, NULL, NULL, NULL }
2748 };
2749
2750 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
2751
2752 { NULL, NULL, { END_ARGS } }
2753 };
2754
2755 /**
2756 * wpas_dbus_signal_peer - Send a peer related event signal
2757 * @wpa_s: %wpa_supplicant network interface data
2758 * @dev: peer device object
2759 * @interface: name of the interface emitting this signal.
2760 * In case of peer objects, it would be emitted by either
2761 * the "interface object" or by "peer objects"
2762 * @sig_name: signal name - DeviceFound
2763 *
2764 * Notify listeners about event related with newly found p2p peer device
2765 */
2766 static void wpas_dbus_signal_peer(struct wpa_supplicant *wpa_s,
2767 const u8 *dev_addr, const char *interface,
2768 const char *sig_name)
2769 {
2770 struct wpas_dbus_priv *iface;
2771 DBusMessage *msg;
2772 DBusMessageIter iter;
2773 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
2774
2775 iface = wpa_s->global->dbus;
2776
2777 /* Do nothing if the control interface is not turned on */
2778 if (iface == NULL)
2779 return;
2780
2781 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2782 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
2783 wpa_s->dbus_new_path, MAC2STR(dev_addr));
2784
2785 msg = dbus_message_new_signal(wpa_s->dbus_new_path, interface,
2786 sig_name);
2787 if (msg == NULL)
2788 return;
2789
2790 dbus_message_iter_init_append(msg, &iter);
2791 path = peer_obj_path;
2792 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
2793 &path))
2794 goto err;
2795
2796 dbus_connection_send(iface->con, msg, NULL);
2797
2798 dbus_message_unref(msg);
2799 return;
2800
2801 err:
2802 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
2803 dbus_message_unref(msg);
2804 }
2805
2806
2807 /**
2808 * wpas_dbus_signal_peer_found - Send a peer found signal
2809 * @wpa_s: %wpa_supplicant network interface data
2810 * @dev: peer device object
2811 *
2812 * Notify listeners about find a p2p peer device found
2813 */
2814 void wpas_dbus_signal_peer_device_found(struct wpa_supplicant *wpa_s,
2815 const u8 *dev_addr)
2816 {
2817 wpas_dbus_signal_peer(wpa_s, dev_addr,
2818 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2819 "DeviceFound");
2820 }
2821
2822 /**
2823 * wpas_dbus_signal_peer_lost - Send a peer lost signal
2824 * @wpa_s: %wpa_supplicant network interface data
2825 * @dev: peer device object
2826 *
2827 * Notify listeners about lost a p2p peer device
2828 */
2829 void wpas_dbus_signal_peer_device_lost(struct wpa_supplicant *wpa_s,
2830 const u8 *dev_addr)
2831 {
2832 wpas_dbus_signal_peer(wpa_s, dev_addr,
2833 WPAS_DBUS_NEW_IFACE_P2PDEVICE,
2834 "DeviceLost");
2835 }
2836
2837 /**
2838 * wpas_dbus_register_peer - Register a discovered peer object with dbus
2839 * @wpa_s: wpa_supplicant interface structure
2840 * @ssid: network configuration data
2841 * Returns: 0 on success, -1 on failure
2842 *
2843 * Registers network representing object with dbus
2844 */
2845 int wpas_dbus_register_peer(struct wpa_supplicant *wpa_s, const u8 *dev_addr)
2846 {
2847 struct wpas_dbus_priv *ctrl_iface;
2848 struct wpa_dbus_object_desc *obj_desc;
2849 struct peer_handler_args *arg;
2850 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2851
2852 /* Do nothing if the control interface is not turned on */
2853 if (wpa_s == NULL || wpa_s->global == NULL)
2854 return 0;
2855
2856 ctrl_iface = wpa_s->global->dbus;
2857 if (ctrl_iface == NULL)
2858 return 0;
2859
2860 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2861 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
2862 wpa_s->dbus_new_path, MAC2STR(dev_addr));
2863
2864 wpa_printf(MSG_INFO, "dbus: Register peer object '%s'",
2865 peer_obj_path);
2866 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
2867 if (!obj_desc) {
2868 wpa_printf(MSG_ERROR, "Not enough memory "
2869 "to create object description");
2870 goto err;
2871 }
2872
2873 /* allocate memory for handlers arguments */
2874 arg = os_zalloc(sizeof(struct peer_handler_args));
2875 if (!arg) {
2876 wpa_printf(MSG_ERROR, "Not enough memory "
2877 "to create arguments for method");
2878 goto err;
2879 }
2880
2881 arg->wpa_s = wpa_s;
2882 os_memcpy(arg->p2p_device_addr, dev_addr, ETH_ALEN);
2883
2884 wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
2885 NULL,
2886 wpas_dbus_p2p_peer_properties,
2887 wpas_dbus_p2p_peer_signals);
2888
2889 if (wpa_dbus_register_object_per_iface(ctrl_iface, peer_obj_path,
2890 wpa_s->ifname, obj_desc))
2891 goto err;
2892
2893 return 0;
2894
2895 err:
2896 free_dbus_object_desc(obj_desc);
2897 return -1;
2898 }
2899
2900 /**
2901 * wpas_dbus_unregister_peer - Unregister a peer object with dbus
2902 * @wpa_s: wpa_supplicant interface structure
2903 * @dev_addr: p2p device addr
2904 * Returns: 0 on success, -1 on failure
2905 *
2906 * Registers network representing object with dbus
2907 */
2908 int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
2909 const u8 *dev_addr)
2910 {
2911 struct wpas_dbus_priv *ctrl_iface;
2912 char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2913 int ret;
2914
2915 /* Do nothing if the control interface is not turned on */
2916 if (wpa_s == NULL || wpa_s->global == NULL ||
2917 wpa_s->dbus_new_path == NULL)
2918 return 0;
2919 ctrl_iface = wpa_s->global->dbus;
2920 if (ctrl_iface == NULL)
2921 return 0;
2922
2923 os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2924 "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/" COMPACT_MACSTR,
2925 wpa_s->dbus_new_path, MAC2STR(dev_addr));
2926
2927 wpa_printf(MSG_INFO, "dbus: Unregister peer object '%s'",
2928 peer_obj_path);
2929 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, peer_obj_path);
2930
2931 return ret;
2932 }
2933
2934
2935 static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
2936 { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
2937 wpas_dbus_getter_p2p_group_members,
2938 NULL
2939 },
2940 { "Properties",
2941 WPAS_DBUS_NEW_IFACE_P2P_GROUP, "a{sv}",
2942 wpas_dbus_getter_p2p_group_properties,
2943 wpas_dbus_setter_p2p_group_properties
2944 },
2945 { NULL, NULL, NULL, NULL, NULL }
2946 };
2947
2948 static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
2949 { "PeerJoined", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
2950 {
2951 { "peer", "o", ARG_OUT },
2952 END_ARGS
2953 }
2954 },
2955 { "PeerDisconnected", WPAS_DBUS_NEW_IFACE_P2P_GROUP,
2956 {
2957 { "peer", "o", ARG_OUT },
2958 END_ARGS
2959 }
2960 },
2961 { NULL, NULL, { END_ARGS } }
2962 };
2963
2964 /**
2965 * wpas_dbus_register_p2p_group - Register a p2p group object with dbus
2966 * @wpa_s: wpa_supplicant interface structure
2967 * @ssid: SSID struct
2968 * Returns: 0 on success, -1 on failure
2969 *
2970 * Registers p2p group representing object with dbus
2971 */
2972 void wpas_dbus_register_p2p_group(struct wpa_supplicant *wpa_s,
2973 struct wpa_ssid *ssid)
2974 {
2975 struct wpas_dbus_priv *ctrl_iface;
2976 struct wpa_dbus_object_desc *obj_desc;
2977 char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
2978
2979 /* Do nothing if the control interface is not turned on */
2980 if (wpa_s == NULL || wpa_s->global == NULL)
2981 return;
2982
2983 ctrl_iface = wpa_s->global->dbus;
2984 if (ctrl_iface == NULL)
2985 return;
2986
2987 if (wpa_s->dbus_groupobj_path) {
2988 wpa_printf(MSG_INFO, "%s: Group object '%s' already exists",
2989 __func__, wpa_s->dbus_groupobj_path);
2990 return;
2991 }
2992
2993 if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
2994 return;
2995
2996 wpa_s->dbus_groupobj_path = os_strdup(group_obj_path);
2997 if (wpa_s->dbus_groupobj_path == NULL)
2998 return;
2999
3000 wpa_printf(MSG_INFO, "dbus: Register group object '%s'",
3001 group_obj_path);
3002 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3003 if (!obj_desc) {
3004 wpa_printf(MSG_ERROR, "Not enough memory "
3005 "to create object description");
3006 goto err;
3007 }
3008
3009 wpas_dbus_register(obj_desc, wpa_s, NULL, NULL,
3010 wpas_dbus_p2p_group_properties,
3011 wpas_dbus_p2p_group_signals);
3012
3013 if (wpa_dbus_register_object_per_iface(ctrl_iface, group_obj_path,
3014 wpa_s->ifname, obj_desc))
3015 goto err;
3016
3017 return;
3018
3019 err:
3020 if (wpa_s->dbus_groupobj_path) {
3021 os_free(wpa_s->dbus_groupobj_path);
3022 wpa_s->dbus_groupobj_path = NULL;
3023 }
3024
3025 free_dbus_object_desc(obj_desc);
3026 }
3027
3028 /**
3029 * wpas_dbus_unregister_p2p_group - Unregister a p2p group object from dbus
3030 * @wpa_s: wpa_supplicant interface structure
3031 * @ssid: network name of the p2p group started
3032 */
3033 void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
3034 const struct wpa_ssid *ssid)
3035 {
3036 struct wpas_dbus_priv *ctrl_iface;
3037
3038 /* Do nothing if the control interface is not turned on */
3039 if (wpa_s == NULL || wpa_s->global == NULL)
3040 return;
3041
3042 ctrl_iface = wpa_s->global->dbus;
3043 if (ctrl_iface == NULL)
3044 return;
3045
3046 if (!wpa_s->dbus_groupobj_path) {
3047 wpa_printf(MSG_DEBUG,
3048 "%s: Group object '%s' already unregistered",
3049 __func__, wpa_s->dbus_groupobj_path);
3050 return;
3051 }
3052
3053 wpa_printf(MSG_DEBUG, "dbus: Unregister group object '%s'",
3054 wpa_s->dbus_groupobj_path);
3055
3056 wpa_dbus_unregister_object_per_iface(ctrl_iface,
3057 wpa_s->dbus_groupobj_path);
3058
3059 os_free(wpa_s->dbus_groupobj_path);
3060 wpa_s->dbus_groupobj_path = NULL;
3061 }
3062
3063 static const struct wpa_dbus_property_desc
3064 wpas_dbus_p2p_groupmember_properties[] = {
3065 { "Properties", WPAS_DBUS_NEW_IFACE_P2P_GROUPMEMBER, "a{sv}",
3066 wpas_dbus_getter_p2p_group_properties,
3067 NULL
3068 },
3069 { NULL, NULL, NULL, NULL, NULL }
3070 };
3071
3072 /**
3073 * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
3074 * object with dbus
3075 * @wpa_s: wpa_supplicant interface structure
3076 * @p2p_if_addr: i/f addr of the device joining this group
3077 *
3078 * Registers p2p groupmember representing object with dbus
3079 */
3080 void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
3081 const u8 *p2p_if_addr)
3082 {
3083 struct wpas_dbus_priv *ctrl_iface;
3084 struct wpa_dbus_object_desc *obj_desc = NULL;
3085 struct groupmember_handler_args *arg;
3086 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3087
3088 /* Do nothing if the control interface is not turned on */
3089 if (wpa_s == NULL || wpa_s->global == NULL)
3090 return;
3091
3092 ctrl_iface = wpa_s->global->dbus;
3093 if (ctrl_iface == NULL)
3094 return;
3095
3096 if (!wpa_s->dbus_groupobj_path)
3097 return;
3098
3099 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3100 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
3101 wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
3102
3103 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3104 if (!obj_desc) {
3105 wpa_printf(MSG_ERROR, "Not enough memory "
3106 "to create object description");
3107 goto err;
3108 }
3109
3110 /* allocate memory for handlers arguments */
3111 arg = os_zalloc(sizeof(struct groupmember_handler_args));
3112 if (!arg) {
3113 wpa_printf(MSG_ERROR, "Not enough memory "
3114 "to create arguments for method");
3115 goto err;
3116 }
3117
3118 arg->wpa_s = wpa_s;
3119 os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
3120
3121 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3122 wpas_dbus_p2p_groupmember_properties, NULL);
3123
3124 if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
3125 wpa_s->ifname, obj_desc))
3126 goto err;
3127
3128 wpa_printf(MSG_INFO,
3129 "dbus: Registered group member object '%s' successfully",
3130 groupmember_obj_path);
3131 return;
3132
3133 err:
3134 free_dbus_object_desc(obj_desc);
3135 }
3136
3137 /**
3138 * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
3139 * object with dbus
3140 * @wpa_s: wpa_supplicant interface structure
3141 * @p2p_if_addr: i/f addr of the device joining this group
3142 *
3143 * Unregisters p2p groupmember representing object with dbus
3144 */
3145 void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
3146 const u8 *p2p_if_addr)
3147 {
3148 struct wpas_dbus_priv *ctrl_iface;
3149 char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3150
3151 /* Do nothing if the control interface is not turned on */
3152 if (wpa_s == NULL || wpa_s->global == NULL)
3153 return;
3154
3155 ctrl_iface = wpa_s->global->dbus;
3156 if (ctrl_iface == NULL)
3157 return;
3158
3159 if (!wpa_s->dbus_groupobj_path)
3160 return;
3161
3162 os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3163 "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
3164 wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
3165
3166 wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
3167 }
3168
3169
3170 static const struct wpa_dbus_property_desc
3171 wpas_dbus_persistent_group_properties[] = {
3172 { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
3173 wpas_dbus_getter_persistent_group_properties,
3174 wpas_dbus_setter_persistent_group_properties
3175 },
3176 { NULL, NULL, NULL, NULL, NULL }
3177 };
3178
3179 /* No signals intended for persistent group objects */
3180
3181 /**
3182 * wpas_dbus_register_persistent_group - Register a configured(saved)
3183 * persistent group with dbus
3184 * @wpa_s: wpa_supplicant interface structure
3185 * @ssid: persistent group (still represented as a network within wpa)
3186 * configuration data
3187 * Returns: 0 on success, -1 on failure
3188 *
3189 * Registers a persistent group representing object with dbus.
3190 */
3191 int wpas_dbus_register_persistent_group(struct wpa_supplicant *wpa_s,
3192 struct wpa_ssid *ssid)
3193 {
3194 struct wpas_dbus_priv *ctrl_iface;
3195 struct wpa_dbus_object_desc *obj_desc;
3196 struct network_handler_args *arg;
3197 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3198
3199 /* Do nothing if the control interface is not turned on */
3200 if (wpa_s == NULL || wpa_s->global == NULL)
3201 return 0;
3202
3203 /* Make sure ssid is a persistent group */
3204 if (ssid->disabled != 2 && !ssid->p2p_persistent_group)
3205 return -1; /* should we return w/o complaining? */
3206
3207 ctrl_iface = wpa_s->global->dbus;
3208 if (ctrl_iface == NULL)
3209 return 0;
3210
3211 /*
3212 * Intentionally not coming up with different numbering scheme
3213 * for persistent groups.
3214 */
3215 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3216 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3217 wpa_s->dbus_new_path, ssid->id);
3218
3219 wpa_printf(MSG_DEBUG, "dbus: Register persistent group object '%s'",
3220 pgrp_obj_path);
3221 obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
3222 if (!obj_desc) {
3223 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3224 "object description");
3225 goto err;
3226 }
3227
3228 /*
3229 * Reusing the same context structure as that for networks
3230 * since these are represented using same data structure.
3231 */
3232 /* allocate memory for handlers arguments */
3233 arg = os_zalloc(sizeof(struct network_handler_args));
3234 if (!arg) {
3235 wpa_printf(MSG_ERROR, "dbus: Not enough memory to create "
3236 "arguments for method");
3237 goto err;
3238 }
3239
3240 arg->wpa_s = wpa_s;
3241 arg->ssid = ssid;
3242
3243 wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
3244 wpas_dbus_persistent_group_properties,
3245 NULL);
3246
3247 if (wpa_dbus_register_object_per_iface(ctrl_iface, pgrp_obj_path,
3248 wpa_s->ifname, obj_desc))
3249 goto err;
3250
3251 wpas_dbus_signal_persistent_group_added(wpa_s, ssid->id);
3252
3253 return 0;
3254
3255 err:
3256 free_dbus_object_desc(obj_desc);
3257 return -1;
3258 }
3259
3260
3261 /**
3262 * wpas_dbus_unregister_persistent_group - Unregister a persistent_group
3263 * from dbus
3264 * @wpa_s: wpa_supplicant interface structure
3265 * @nid: network id
3266 * Returns: 0 on success, -1 on failure
3267 *
3268 * Unregisters persistent group representing object from dbus
3269 *
3270 * NOTE: There is a slight issue with the semantics here. While the
3271 * implementation simply means the persistent group is unloaded from memory,
3272 * it should not get interpreted as the group is actually being erased/removed
3273 * from persistent storage as well.
3274 */
3275 int wpas_dbus_unregister_persistent_group(struct wpa_supplicant *wpa_s,
3276 int nid)
3277 {
3278 struct wpas_dbus_priv *ctrl_iface;
3279 char pgrp_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
3280 int ret;
3281
3282 /* Do nothing if the control interface is not turned on */
3283 if (wpa_s == NULL || wpa_s->global == NULL ||
3284 wpa_s->dbus_new_path == NULL)
3285 return 0;
3286 ctrl_iface = wpa_s->global->dbus;
3287 if (ctrl_iface == NULL)
3288 return 0;
3289
3290 os_snprintf(pgrp_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3291 "%s/" WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART "/%u",
3292 wpa_s->dbus_new_path, nid);
3293
3294 wpa_printf(MSG_DEBUG, "dbus: Unregister persistent group object '%s'",
3295 pgrp_obj_path);
3296 ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, pgrp_obj_path);
3297
3298 if (!ret)
3299 wpas_dbus_signal_persistent_group_removed(wpa_s, nid);
3300
3301 return ret;
3302 }
3303
3304 #endif /* CONFIG_P2P */