xref: /freebsd/contrib/wpa/wpa_supplicant/dbus/dbus_new_helpers.h (revision eef8b03ca023b906cef9f8b85212e61ae9d95d0b)
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 typedef DBusMessage * (* WPADBusMethodHandler)(DBusMessage *message,
22 					       void *user_data);
23 typedef void (* WPADBusArgumentFreeFunction)(void *handler_arg);
24 
25 typedef DBusMessage * (* WPADBusPropertyAccessor)(DBusMessage *message,
26 						  const void *user_data);
27 
28 struct wpa_dbus_object_desc {
29 	DBusConnection *connection;
30 	char *path;
31 
32 	/* list of methods, properties and signals registered with object */
33 	const struct wpa_dbus_method_desc *methods;
34 	const struct wpa_dbus_signal_desc *signals;
35 	const struct wpa_dbus_property_desc *properties;
36 
37 	/* property changed flags */
38 	u8 *prop_changed_flags;
39 
40 	/* argument for method handlers and properties
41 	 * getter and setter functions */
42 	void *user_data;
43 	/* function used to free above argument */
44 	WPADBusArgumentFreeFunction user_data_free_func;
45 };
46 
47 enum dbus_prop_access { R, W, RW };
48 
49 enum dbus_arg_direction { ARG_IN, ARG_OUT };
50 
51 struct wpa_dbus_argument {
52 	char *name;
53 	char *type;
54 	enum dbus_arg_direction dir;
55 };
56 
57 #define END_ARGS { NULL, NULL, ARG_IN }
58 
59 /**
60  * struct wpa_dbus_method_desc - DBus method description
61  */
62 struct wpa_dbus_method_desc {
63 	/* method name */
64 	const char *dbus_method;
65 	/* method interface */
66 	const char *dbus_interface;
67 	/* method handling function */
68 	WPADBusMethodHandler method_handler;
69 	/* array of arguments */
70 	struct wpa_dbus_argument args[3];
71 };
72 
73 /**
74  * struct wpa_dbus_signal_desc - DBus signal description
75  */
76 struct wpa_dbus_signal_desc {
77 	/* signal name */
78 	const char *dbus_signal;
79 	/* signal interface */
80 	const char *dbus_interface;
81 	/* array of arguments */
82 	struct wpa_dbus_argument args[3];
83 };
84 
85 /**
86  * struct wpa_dbus_property_desc - DBus property description
87  */
88 struct wpa_dbus_property_desc {
89 	/* property name */
90 	const char *dbus_property;
91 	/* property interface */
92 	const char *dbus_interface;
93 	/* property type signature in DBus type notation */
94 	const char *type;
95 	/* property getter function */
96 	WPADBusPropertyAccessor getter;
97 	/* property setter function */
98 	WPADBusPropertyAccessor setter;
99 	/* property access permissions */
100 	enum dbus_prop_access access;
101 };
102 
103 
104 #define WPAS_DBUS_OBJECT_PATH_MAX 150
105 #define WPAS_DBUS_INTERFACE_MAX 150
106 #define WPAS_DBUS_METHOD_SIGNAL_PROP_MAX 50
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 void wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface,
131 				    const char *path, const char *interface,
132 				    DBusMessageIter *dict_iter);
133 
134 
135 void wpa_dbus_flush_all_changed_properties(DBusConnection *con);
136 
137 void wpa_dbus_flush_object_changed_properties(DBusConnection *con,
138 					      const char *path);
139 
140 void wpa_dbus_mark_property_changed(struct wpas_dbus_priv *iface,
141 				    const char *path, const char *interface,
142 				    const char *property);
143 
144 DBusMessage * wpa_dbus_introspect(DBusMessage *message,
145 				  struct wpa_dbus_object_desc *obj_dsc);
146 
147 #endif /* WPA_DBUS_CTRL_H */
148