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 software may be distributed under the terms of the BSD license.
7  * See README for more details.
8  */
9 
10 #ifndef WPA_DBUS_CTRL_H
11 #define WPA_DBUS_CTRL_H
12 
13 #include <dbus/dbus.h>
14 
15 struct wpa_signal_info;
16 
17 typedef DBusMessage * (*WPADBusMethodHandler)(DBusMessage *message,
18                                                         void *user_data);
19 typedef void (*WPADBusArgumentFreeFunction)(void *handler_arg);
20 
21 struct wpa_dbus_property_desc;
22 typedef dbus_bool_t (*WPADBusPropertyAccessor)(
23           const struct wpa_dbus_property_desc *property_desc,
24           DBusMessageIter *iter, DBusError *error, void *user_data);
25 #define DECLARE_ACCESSOR(f) \
26 dbus_bool_t f(const struct wpa_dbus_property_desc *property_desc, \
27                 DBusMessageIter *iter, DBusError *error, void *user_data)
28 
29 struct wpa_dbus_object_desc {
30           DBusConnection *connection;
31           char *path;
32 
33           /* list of methods, properties and signals registered with object */
34           const struct wpa_dbus_method_desc *methods;
35           const struct wpa_dbus_signal_desc *signals;
36           const struct wpa_dbus_property_desc *properties;
37 
38           /* property changed flags */
39           u8 *prop_changed_flags;
40 
41           /* argument for method handlers and properties
42            * getter and setter functions */
43           void *user_data;
44           /* function used to free above argument */
45           WPADBusArgumentFreeFunction user_data_free_func;
46 };
47 
48 enum dbus_arg_direction { ARG_IN, ARG_OUT };
49 
50 struct wpa_dbus_argument {
51           char *name;
52           char *type;
53           enum dbus_arg_direction dir;
54 };
55 
56 #define END_ARGS { NULL, NULL, ARG_IN }
57 
58 /**
59  * struct wpa_dbus_method_desc - DBus method description
60  */
61 struct wpa_dbus_method_desc {
62           /* method name */
63           const char *dbus_method;
64           /* method interface */
65           const char *dbus_interface;
66           /* method handling function */
67           WPADBusMethodHandler method_handler;
68           /* array of arguments */
69           struct wpa_dbus_argument args[4];
70 };
71 
72 /**
73  * struct wpa_dbus_signal_desc - DBus signal description
74  */
75 struct wpa_dbus_signal_desc {
76           /* signal name */
77           const char *dbus_signal;
78           /* signal interface */
79           const char *dbus_interface;
80           /* array of arguments */
81           struct wpa_dbus_argument args[4];
82 };
83 
84 /**
85  * struct wpa_dbus_property_desc - DBus property description
86  */
87 struct wpa_dbus_property_desc {
88           /* property name */
89           const char *dbus_property;
90           /* property interface */
91           const char *dbus_interface;
92           /* property type signature in DBus type notation */
93           const char *type;
94           /* property getter function */
95           WPADBusPropertyAccessor getter;
96           /* property setter function */
97           WPADBusPropertyAccessor setter;
98           /* other data */
99           const char *data;
100 };
101 
102 
103 #define WPAS_DBUS_OBJECT_PATH_MAX 150
104 #define WPAS_DBUS_INTERFACE_MAX 150
105 #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
106 #define WPAS_DBUS_AUTH_MODE_MAX 64
107 
108 #define WPA_DBUS_INTROSPECTION_INTERFACE "org.freedesktop.DBus.Introspectable"
109 #define WPA_DBUS_INTROSPECTION_METHOD "Introspect"
110 #define WPA_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
111 #define WPA_DBUS_PROPERTIES_GET "Get"
112 #define WPA_DBUS_PROPERTIES_SET "Set"
113 #define WPA_DBUS_PROPERTIES_GETALL "GetAll"
114 
115 void free_dbus_object_desc(struct wpa_dbus_object_desc *obj_dsc);
116 
117 int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface, char *dbus_path,
118                                    char *dbus_service,
119                                    struct wpa_dbus_object_desc *obj_desc);
120 
121 int wpa_dbus_register_object_per_iface(
122           struct wpas_dbus_priv *ctrl_iface,
123           const char *path, const char *ifname,
124           struct wpa_dbus_object_desc *obj_desc);
125 
126 int wpa_dbus_unregister_object_per_iface(
127           struct wpas_dbus_priv *ctrl_iface,
128           const char *path);
129 
130 dbus_bool_t wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface,
131                                                      const char *path,
132                                                      const char *interface,
133                                                      DBusMessageIter *iter);
134 
135 
136 void wpa_dbus_flush_all_changed_properties(DBusConnection *con);
137 
138 void wpa_dbus_flush_object_changed_properties(DBusConnection *con,
139                                                         const char *path);
140 
141 void wpa_dbus_mark_property_changed(struct wpas_dbus_priv *iface,
142                                             const char *path, const char *interface,
143                                             const char *property);
144 
145 DBusMessage * wpa_dbus_introspect(DBusMessage *message,
146                                           struct wpa_dbus_object_desc *obj_dsc);
147 
148 char * wpas_dbus_new_decompose_object_path(const char *path, const char *sep,
149                                                      char **item);
150 
151 DBusMessage *wpas_dbus_reply_new_from_error(DBusMessage *message,
152                                                       DBusError *error,
153                                                       const char *fallback_name,
154                                                       const char *fallback_string);
155 
156 int wpas_dbus_new_from_signal_information(DBusMessageIter *iter,
157                                                     struct wpa_signal_info *si);
158 
159 #endif /* WPA_DBUS_CTRL_H */
160