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