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