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