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