WPS ER: Fetch AP's M1 to learn device type and WPS state
[libeap.git] / wpa_supplicant / ctrl_iface_dbus_new_helpers.h
1 /*
2  * WPA Supplicant / dbus-based control interface
3  * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4  * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * Alternatively, this software may be distributed under the terms of BSD
11  * license.
12  *
13  * See README and COPYING for more details.
14  */
15
16 #ifndef WPA_DBUS_CTRL_H
17 #define WPA_DBUS_CTRL_H
18
19 #include <dbus/dbus.h>
20
21 struct ctrl_iface_dbus_new_priv {
22         DBusConnection *con;
23         int should_dispatch;
24         void *application_data;
25
26         u32 next_objid;
27 };
28
29 typedef DBusMessage * (* WPADBusMethodHandler)(DBusMessage *message,
30                                                void *user_data);
31 typedef void (* WPADBusArgumentFreeFunction)(void *handler_arg);
32
33 typedef DBusMessage * (* WPADBusPropertyAccessor)(DBusMessage *message,
34                                                   void *user_data);
35
36 struct wpa_dbus_object_desc {
37         DBusConnection *connection;
38         struct wpa_dbus_method_desc *methods;
39         struct wpa_dbus_signal_desc *signals;
40         struct wpa_dbus_property_desc *properties;
41 };
42
43 enum dbus_prop_access { R, W, RW };
44
45 enum dbus_arg_direction { ARG_IN, ARG_OUT };
46
47 struct wpa_dbus_argument {
48         char *name;
49         char *type;
50         enum dbus_arg_direction dir;
51 };
52
53 #define END_ARGS { NULL, NULL, ARG_IN }
54
55 #ifdef CONFIG_CTRL_IFACE_DBUS_NEW
56
57 #ifndef SIGPOLL
58 #ifdef SIGIO
59 /*
60  * If we do not have SIGPOLL, try to use SIGIO instead. This is needed for
61  * FreeBSD.
62  */
63 #define SIGPOLL SIGIO
64 #endif
65 #endif
66
67 #define WPAS_DBUS_OBJECT_PATH_MAX 150
68 #define WPAS_DBUS_INTERFACE_MAX 150
69 #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
70
71 #define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
72 #define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
73 #define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
74 #define WPA_DBUS_PROPERTIES_GET "Get"
75 #define WPA_DBUS_PROPERTIES_SET "Set"
76 #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
77
78 void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
79
80 struct ctrl_iface_dbus_new_priv *
81 wpa_dbus_ctrl_iface_init(void *application_data, char *dbus_path,
82                          char *dbus_service,
83                          struct wpa_dbus_object_desc *obj_desc);
84
85 void wpa_dbus_ctrl_iface_deinit(struct ctrl_iface_dbus_new_priv *iface);
86
87 int wpa_dbus_register_object_per_iface(
88         struct ctrl_iface_dbus_new_priv *ctrl_iface,
89         const char *path, const char *ifname,
90         struct wpa_dbus_object_desc *obj_desc);
91
92 int wpa_dbus_unregister_object_per_iface(
93         struct ctrl_iface_dbus_new_priv *ctrl_iface,
94         const char *path);
95
96 int wpa_dbus_method_register(struct wpa_dbus_object_desc *obj_dsc,
97                              const char *dbus_interface,
98                              const char *dbus_method,
99                              WPADBusMethodHandler method_handler,
100                              void *handler_argument,
101                              WPADBusArgumentFreeFunction argument_free_func,
102                              const struct wpa_dbus_argument args[]);
103
104 int wpa_dbus_signal_register(struct wpa_dbus_object_desc *obj_dsc,
105                              const char *dbus_interface,
106                              const char *dbus_signal,
107                              const struct wpa_dbus_argument args[]);
108
109 int wpa_dbus_property_register(
110         struct wpa_dbus_object_desc *obj_dsc,
111         const char *dbus_interface, const char *dbus_property,
112         const char *type,
113         WPADBusPropertyAccessor getter,
114         WPADBusPropertyAccessor setter,
115         void *user_data,
116         WPADBusArgumentFreeFunction user_data_free_func,
117         enum dbus_prop_access _access);
118
119 void wpa_dbus_signal_property_changed(struct ctrl_iface_dbus_new_priv *iface,
120                                       WPADBusPropertyAccessor property_getter,
121                                       void *getter_arg,
122                                       const char *path,
123                                       const char *interface_name,
124                                       const char *property_name);
125
126 /* Methods internal to the dbus control interface */
127 u32 wpa_dbus_next_objid(struct ctrl_iface_dbus_new_priv *iface);
128
129
130 #else /* CONFIG_CTRL_IFACE_DBUS_NEW */
131
132 static inline void wpa_dbus_signal_property_changed(
133         struct ctrl_iface_dbus_new_priv *iface,
134         WPADBusPropertyAccessor property_getter, void *getter_arg,
135         const char *path, const char *interface_name,
136         const char *property_name)
137 {
138 }
139
140 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
141
142 #endif /* WPA_DBUS_CTRL_H */