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>
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.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
16 #include "utils/includes.h"
18 #include "utils/common.h"
19 #include "utils/eloop.h"
20 #include "dbus_common.h"
21 #include "dbus_common_i.h"
23 #include "dbus_new_helpers.h"
27 * recursive_iter_copy - Reads arguments from one iterator and
28 * writes to another recursively
29 * @from: iterator to read from
30 * @to: iterator to write to
32 * Copies one iterator's elements to another. If any element in
33 * iterator is of container type, its content is copied recursively
35 static void recursive_iter_copy(DBusMessageIter
*from
, DBusMessageIter
*to
)
41 /* iterate over iterator to copy */
42 while ((type
= dbus_message_iter_get_arg_type(from
)) !=
45 /* simply copy basic type entries */
46 if (dbus_type_is_basic(type
)) {
47 if (dbus_type_is_fixed(type
)) {
49 * According to DBus documentation all
50 * fixed-length types are guaranteed to fit
54 dbus_message_iter_get_basic(from
, &v
);
55 dbus_message_iter_append_basic(to
, type
, &v
);
58 dbus_message_iter_get_basic(from
, &v
);
59 dbus_message_iter_append_basic(to
, type
, &v
);
62 /* recursively copy container type entries */
63 DBusMessageIter write_subiter
, read_subiter
;
65 dbus_message_iter_recurse(from
, &read_subiter
);
67 if (type
== DBUS_TYPE_VARIANT
||
68 type
== DBUS_TYPE_ARRAY
) {
69 subtype
= dbus_message_iter_get_signature(
73 dbus_message_iter_open_container(to
, type
, subtype
,
76 recursive_iter_copy(&read_subiter
, &write_subiter
);
78 dbus_message_iter_close_container(to
, &write_subiter
);
83 dbus_message_iter_next(from
);
88 static unsigned int fill_dict_with_properties(
89 DBusMessageIter
*dict_iter
, const struct wpa_dbus_property_desc
*props
,
90 const char *interface
, const void *user_data
)
93 DBusMessageIter entry_iter
, ret_iter
;
94 unsigned int counter
= 0;
95 const struct wpa_dbus_property_desc
*dsc
;
97 for (dsc
= props
; dsc
&& dsc
->dbus_property
; dsc
++) {
98 if (!os_strncmp(dsc
->dbus_interface
, interface
,
99 WPAS_DBUS_INTERFACE_MAX
) &&
100 dsc
->access
!= W
&& dsc
->getter
) {
101 reply
= dsc
->getter(NULL
, user_data
);
105 if (dbus_message_get_type(reply
) ==
106 DBUS_MESSAGE_TYPE_ERROR
) {
107 dbus_message_unref(reply
);
111 dbus_message_iter_init(reply
, &ret_iter
);
113 dbus_message_iter_open_container(dict_iter
,
114 DBUS_TYPE_DICT_ENTRY
,
116 dbus_message_iter_append_basic(
117 &entry_iter
, DBUS_TYPE_STRING
,
118 &dsc
->dbus_property
);
120 recursive_iter_copy(&ret_iter
, &entry_iter
);
122 dbus_message_iter_close_container(dict_iter
,
124 dbus_message_unref(reply
);
134 * get_all_properties - Responds for GetAll properties calls on object
135 * @message: Message with GetAll call
136 * @interface: interface name which properties will be returned
137 * @property_dsc: list of object's properties
138 * Returns: Message with dict of variants as argument with properties values
140 * Iterates over all properties registered with object and execute getters
141 * of those, which are readable and which interface matches interface
142 * specified as argument. Returned message contains one dict argument
143 * with properties names as keys and theirs values as values.
145 static DBusMessage
* get_all_properties(
146 DBusMessage
*message
, char *interface
,
147 struct wpa_dbus_object_desc
*obj_dsc
)
149 /* Create and initialize the return message */
150 DBusMessage
*reply
= dbus_message_new_method_return(message
);
151 DBusMessageIter iter
, dict_iter
;
154 dbus_message_iter_init_append(reply
, &iter
);
156 dbus_message_iter_open_container(&iter
, DBUS_TYPE_ARRAY
,
157 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
158 DBUS_TYPE_STRING_AS_STRING
159 DBUS_TYPE_VARIANT_AS_STRING
160 DBUS_DICT_ENTRY_END_CHAR_AS_STRING
,
163 props_num
= fill_dict_with_properties(&dict_iter
, obj_dsc
->properties
,
164 interface
, obj_dsc
->user_data
);
166 dbus_message_iter_close_container(&iter
, &dict_iter
);
168 if (props_num
== 0) {
169 dbus_message_unref(reply
);
170 reply
= dbus_message_new_error(message
,
171 DBUS_ERROR_INVALID_ARGS
,
172 "No readable properties in "
180 static int is_signature_correct(DBusMessage
*message
,
181 const struct wpa_dbus_method_desc
*method_dsc
)
183 /* According to DBus documentation max length of signature is 255 */
184 #define MAX_SIG_LEN 256
185 char registered_sig
[MAX_SIG_LEN
], *pos
;
186 const char *sig
= dbus_message_get_signature(message
);
188 const struct wpa_dbus_argument
*arg
;
190 pos
= registered_sig
;
193 for (arg
= method_dsc
->args
; arg
&& arg
->name
; arg
++) {
194 if (arg
->dir
== ARG_IN
) {
195 size_t blen
= registered_sig
+ MAX_SIG_LEN
- pos
;
196 ret
= os_snprintf(pos
, blen
, "%s", arg
->type
);
197 if (ret
< 0 || (size_t) ret
>= blen
)
203 return !os_strncmp(registered_sig
, sig
, MAX_SIG_LEN
);
207 static DBusMessage
* properties_get_all(DBusMessage
*message
, char *interface
,
208 struct wpa_dbus_object_desc
*obj_dsc
)
210 if (os_strcmp(dbus_message_get_signature(message
), "s") != 0)
211 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
214 return get_all_properties(message
, interface
, obj_dsc
);
218 static DBusMessage
* properties_get(DBusMessage
*message
,
219 const struct wpa_dbus_property_desc
*dsc
,
222 if (os_strcmp(dbus_message_get_signature(message
), "ss"))
223 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
226 if (dsc
->access
!= W
&& dsc
->getter
)
227 return dsc
->getter(message
, user_data
);
229 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
230 "Property is write-only");
234 static DBusMessage
* properties_set(DBusMessage
*message
,
235 const struct wpa_dbus_property_desc
*dsc
,
238 if (os_strcmp(dbus_message_get_signature(message
), "ssv"))
239 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
242 if (dsc
->access
!= R
&& dsc
->setter
)
243 return dsc
->setter(message
, user_data
);
245 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
246 "Property is read-only");
251 properties_get_or_set(DBusMessage
*message
, DBusMessageIter
*iter
,
253 struct wpa_dbus_object_desc
*obj_dsc
)
255 const struct wpa_dbus_property_desc
*property_dsc
;
259 method
= dbus_message_get_member(message
);
260 property_dsc
= obj_dsc
->properties
;
262 /* Second argument: property name (DBUS_TYPE_STRING) */
263 if (!dbus_message_iter_next(iter
) ||
264 dbus_message_iter_get_arg_type(iter
) != DBUS_TYPE_STRING
) {
265 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
268 dbus_message_iter_get_basic(iter
, &property
);
270 while (property_dsc
&& property_dsc
->dbus_property
) {
271 /* compare property names and
273 if (!os_strncmp(property_dsc
->dbus_property
, property
,
274 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
) &&
275 !os_strncmp(property_dsc
->dbus_interface
, interface
,
276 WPAS_DBUS_INTERFACE_MAX
))
281 if (property_dsc
== NULL
|| property_dsc
->dbus_property
== NULL
) {
282 wpa_printf(MSG_DEBUG
, "no property handler for %s.%s on %s",
284 dbus_message_get_path(message
));
285 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
289 if (os_strncmp(WPA_DBUS_PROPERTIES_GET
, method
,
290 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
) == 0)
291 return properties_get(message
, property_dsc
,
294 return properties_set(message
, property_dsc
, obj_dsc
->user_data
);
298 static DBusMessage
* properties_handler(DBusMessage
*message
,
299 struct wpa_dbus_object_desc
*obj_dsc
)
301 DBusMessageIter iter
;
305 method
= dbus_message_get_member(message
);
306 dbus_message_iter_init(message
, &iter
);
308 if (!os_strncmp(WPA_DBUS_PROPERTIES_GET
, method
,
309 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
) ||
310 !os_strncmp(WPA_DBUS_PROPERTIES_SET
, method
,
311 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
) ||
312 !os_strncmp(WPA_DBUS_PROPERTIES_GETALL
, method
,
313 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
)) {
314 /* First argument: interface name (DBUS_TYPE_STRING) */
315 if (dbus_message_iter_get_arg_type(&iter
) != DBUS_TYPE_STRING
)
317 return dbus_message_new_error(message
,
318 DBUS_ERROR_INVALID_ARGS
,
322 dbus_message_iter_get_basic(&iter
, &interface
);
324 if (!os_strncmp(WPA_DBUS_PROPERTIES_GETALL
, method
,
325 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
)) {
327 return properties_get_all(message
, interface
, obj_dsc
);
330 return properties_get_or_set(message
, &iter
, interface
,
333 return dbus_message_new_error(message
, DBUS_ERROR_UNKNOWN_METHOD
,
338 static DBusMessage
* msg_method_handler(DBusMessage
*message
,
339 struct wpa_dbus_object_desc
*obj_dsc
)
341 const struct wpa_dbus_method_desc
*method_dsc
= obj_dsc
->methods
;
343 const char *msg_interface
;
345 method
= dbus_message_get_member(message
);
346 msg_interface
= dbus_message_get_interface(message
);
348 /* try match call to any registered method */
349 while (method_dsc
&& method_dsc
->dbus_method
) {
350 /* compare method names and interfaces */
351 if (!os_strncmp(method_dsc
->dbus_method
, method
,
352 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
) &&
353 !os_strncmp(method_dsc
->dbus_interface
, msg_interface
,
354 WPAS_DBUS_INTERFACE_MAX
))
359 if (method_dsc
== NULL
|| method_dsc
->dbus_method
== NULL
) {
360 wpa_printf(MSG_DEBUG
, "no method handler for %s.%s on %s",
361 msg_interface
, method
,
362 dbus_message_get_path(message
));
363 return dbus_message_new_error(message
,
364 DBUS_ERROR_UNKNOWN_METHOD
, NULL
);
367 if (!is_signature_correct(message
, method_dsc
)) {
368 return dbus_message_new_error(message
, DBUS_ERROR_INVALID_ARGS
,
372 return method_dsc
->method_handler(message
,
378 * message_handler - Handles incoming DBus messages
379 * @connection: DBus connection on which message was received
380 * @message: Received message
381 * @user_data: pointer to description of object to which message was sent
382 * Returns: Returns information whether message was handled or not
384 * Reads message interface and method name, then checks if they matches one
385 * of the special cases i.e. introspection call or properties get/getall/set
386 * methods and handles it. Else it iterates over registered methods list
387 * and tries to match method's name and interface to those read from message
388 * If appropriate method was found its handler function is called and
389 * response is sent. Otherwise, the DBUS_ERROR_UNKNOWN_METHOD error message
392 static DBusHandlerResult
message_handler(DBusConnection
*connection
,
393 DBusMessage
*message
, void *user_data
)
395 struct wpa_dbus_object_desc
*obj_dsc
= user_data
;
398 const char *msg_interface
;
401 /* get method, interface and path the message is addressed to */
402 method
= dbus_message_get_member(message
);
403 path
= dbus_message_get_path(message
);
404 msg_interface
= dbus_message_get_interface(message
);
405 if (!method
|| !path
|| !msg_interface
)
406 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
408 wpa_printf(MSG_MSGDUMP
, "dbus: %s.%s (%s)",
409 msg_interface
, method
, path
);
411 /* if message is introspection method call */
412 if (!os_strncmp(WPA_DBUS_INTROSPECTION_METHOD
, method
,
413 WPAS_DBUS_METHOD_SIGNAL_PROP_MAX
) &&
414 !os_strncmp(WPA_DBUS_INTROSPECTION_INTERFACE
, msg_interface
,
415 WPAS_DBUS_INTERFACE_MAX
)) {
416 #ifdef CONFIG_CTRL_IFACE_DBUS_INTRO
417 reply
= wpa_dbus_introspect(message
, obj_dsc
);
418 #else /* CONFIG_CTRL_IFACE_DBUS_INTRO */
419 reply
= dbus_message_new_error(
420 message
, DBUS_ERROR_UNKNOWN_METHOD
,
421 "wpa_supplicant was compiled without "
422 "introspection support.");
423 #endif /* CONFIG_CTRL_IFACE_DBUS_INTRO */
424 } else if (!os_strncmp(WPA_DBUS_PROPERTIES_INTERFACE
, msg_interface
,
425 WPAS_DBUS_INTERFACE_MAX
)) {
426 /* if message is properties method call */
427 reply
= properties_handler(message
, obj_dsc
);
429 reply
= msg_method_handler(message
, obj_dsc
);
432 /* If handler succeed returning NULL, reply empty message */
434 reply
= dbus_message_new_method_return(message
);
436 if (!dbus_message_get_no_reply(message
))
437 dbus_connection_send(connection
, reply
, NULL
);
438 dbus_message_unref(reply
);
441 wpa_dbus_flush_all_changed_properties(connection
);
443 return DBUS_HANDLER_RESULT_HANDLED
;
448 * free_dbus_object_desc - Frees object description data structure
449 * @connection: DBus connection
450 * @obj_dsc: Object description to free
452 * Frees each of properties, methods and signals description lists and
453 * the object description structure itself.
455 void free_dbus_object_desc(struct wpa_dbus_object_desc
*obj_dsc
)
460 /* free handler's argument */
461 if (obj_dsc
->user_data_free_func
)
462 obj_dsc
->user_data_free_func(obj_dsc
->user_data
);
464 os_free(obj_dsc
->path
);
465 os_free(obj_dsc
->prop_changed_flags
);
470 static void free_dbus_object_desc_cb(DBusConnection
*connection
, void *obj_dsc
)
472 free_dbus_object_desc(obj_dsc
);
476 * wpa_dbus_ctrl_iface_init - Initialize dbus control interface
477 * @application_data: Pointer to application specific data structure
478 * @dbus_path: DBus path to interface object
479 * @dbus_service: DBus service name to register with
480 * @messageHandler: a pointer to function which will handle dbus messages
481 * coming on interface
482 * Returns: 0 on success, -1 on failure
484 * Initialize the dbus control interface and start receiving commands from
485 * external programs over the bus.
487 int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv
*iface
,
488 char *dbus_path
, char *dbus_service
,
489 struct wpa_dbus_object_desc
*obj_desc
)
493 DBusObjectPathVTable wpa_vtable
= {
494 &free_dbus_object_desc_cb
, &message_handler
,
495 NULL
, NULL
, NULL
, NULL
498 obj_desc
->connection
= iface
->con
;
499 obj_desc
->path
= os_strdup(dbus_path
);
501 /* Register the message handler for the global dbus interface */
502 if (!dbus_connection_register_object_path(iface
->con
,
503 dbus_path
, &wpa_vtable
,
505 wpa_printf(MSG_ERROR
, "dbus: Could not set up message "
510 /* Register our service with the message bus */
511 dbus_error_init(&error
);
512 switch (dbus_bus_request_name(iface
->con
, dbus_service
,
514 case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
:
517 case DBUS_REQUEST_NAME_REPLY_EXISTS
:
518 case DBUS_REQUEST_NAME_REPLY_IN_QUEUE
:
519 case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER
:
520 wpa_printf(MSG_ERROR
, "dbus: Could not request service name: "
521 "already registered");
524 wpa_printf(MSG_ERROR
, "dbus: Could not request service name: "
525 "%s %s", error
.name
, error
.message
);
528 dbus_error_free(&error
);
533 wpa_printf(MSG_DEBUG
, "Providing DBus service '%s'.", dbus_service
);
540 * wpa_dbus_register_object_per_iface - Register a new object with dbus
541 * @ctrl_iface: pointer to dbus private data
542 * @path: DBus path to object
543 * @ifname: interface name
544 * @obj_desc: description of object's methods, signals and properties
545 * Returns: 0 on success, -1 on error
547 * Registers a new interface with dbus and assigns it a dbus object path.
549 int wpa_dbus_register_object_per_iface(
550 struct wpas_dbus_priv
*ctrl_iface
,
551 const char *path
, const char *ifname
,
552 struct wpa_dbus_object_desc
*obj_desc
)
556 DBusObjectPathVTable vtable
= {
557 &free_dbus_object_desc_cb
, &message_handler
,
558 NULL
, NULL
, NULL
, NULL
561 /* Do nothing if the control interface is not turned on */
562 if (ctrl_iface
== NULL
)
565 con
= ctrl_iface
->con
;
566 obj_desc
->connection
= con
;
567 obj_desc
->path
= os_strdup(path
);
569 /* Register the message handler for the interface functions */
570 if (!dbus_connection_register_object_path(con
, path
, &vtable
,
572 wpa_printf(MSG_ERROR
, "dbus: Could not set up message "
573 "handler for interface %s object %s", ifname
, path
);
581 static void flush_object_timeout_handler(void *eloop_ctx
, void *timeout_ctx
);
585 * wpa_dbus_unregister_object_per_iface - Unregisters DBus object
586 * @ctrl_iface: Pointer to dbus private data
587 * @path: DBus path to object which will be unregistered
588 * Returns: Zero on success and -1 on failure
590 * Unregisters DBus object given by its path
592 int wpa_dbus_unregister_object_per_iface(
593 struct wpas_dbus_priv
*ctrl_iface
, const char *path
)
595 DBusConnection
*con
= ctrl_iface
->con
;
596 struct wpa_dbus_object_desc
*obj_desc
= NULL
;
598 dbus_connection_get_object_path_data(con
, path
, (void **) &obj_desc
);
600 wpa_printf(MSG_ERROR
, "dbus: %s: Could not obtain object's "
601 "private data: %s", __func__
, path
);
603 eloop_cancel_timeout(flush_object_timeout_handler
, con
,
607 if (!dbus_connection_unregister_object_path(con
, path
))
614 static void put_changed_properties(const struct wpa_dbus_object_desc
*obj_dsc
,
615 const char *interface
,
616 DBusMessageIter
*dict_iter
)
618 DBusMessage
*getter_reply
;
619 DBusMessageIter prop_iter
, entry_iter
;
620 const struct wpa_dbus_property_desc
*dsc
;
623 for (dsc
= obj_dsc
->properties
, i
= 0; dsc
&& dsc
->dbus_property
;
625 if (obj_dsc
->prop_changed_flags
== NULL
||
626 !obj_dsc
->prop_changed_flags
[i
])
628 if (os_strcmp(dsc
->dbus_interface
, interface
) != 0)
630 obj_dsc
->prop_changed_flags
[i
] = 0;
632 getter_reply
= dsc
->getter(NULL
, obj_dsc
->user_data
);
634 dbus_message_get_type(getter_reply
) ==
635 DBUS_MESSAGE_TYPE_ERROR
) {
636 wpa_printf(MSG_ERROR
, "dbus: %s: Cannot get new value "
637 "of property %s", __func__
,
642 if (!dbus_message_iter_init(getter_reply
, &prop_iter
) ||
643 !dbus_message_iter_open_container(dict_iter
,
644 DBUS_TYPE_DICT_ENTRY
,
645 NULL
, &entry_iter
) ||
646 !dbus_message_iter_append_basic(&entry_iter
,
648 &dsc
->dbus_property
))
651 recursive_iter_copy(&prop_iter
, &entry_iter
);
653 if (!dbus_message_iter_close_container(dict_iter
, &entry_iter
))
656 dbus_message_unref(getter_reply
);
662 wpa_printf(MSG_ERROR
, "dbus: %s: Cannot construct signal", __func__
);
666 static void send_prop_changed_signal(
667 DBusConnection
*con
, const char *path
, const char *interface
,
668 const struct wpa_dbus_object_desc
*obj_dsc
)
671 DBusMessageIter signal_iter
, dict_iter
;
673 msg
= dbus_message_new_signal(path
, interface
, "PropertiesChanged");
677 dbus_message_iter_init_append(msg
, &signal_iter
);
679 if (!dbus_message_iter_open_container(&signal_iter
, DBUS_TYPE_ARRAY
,
683 put_changed_properties(obj_dsc
, interface
, &dict_iter
);
685 if (!dbus_message_iter_close_container(&signal_iter
, &dict_iter
))
688 dbus_connection_send(con
, msg
, NULL
);
691 dbus_message_unref(msg
);
695 wpa_printf(MSG_DEBUG
, "dbus: %s: Failed to construct signal",
701 static void flush_object_timeout_handler(void *eloop_ctx
, void *timeout_ctx
)
703 DBusConnection
*con
= eloop_ctx
;
704 struct wpa_dbus_object_desc
*obj_desc
= timeout_ctx
;
706 wpa_printf(MSG_DEBUG
, "dbus: %s: Timeout - sending changed properties "
707 "of object %s", __func__
, obj_desc
->path
);
708 wpa_dbus_flush_object_changed_properties(con
, obj_desc
->path
);
712 static void recursive_flush_changed_properties(DBusConnection
*con
,
715 char **objects
= NULL
;
716 char subobj_path
[WPAS_DBUS_OBJECT_PATH_MAX
];
719 wpa_dbus_flush_object_changed_properties(con
, path
);
721 if (!dbus_connection_list_registered(con
, path
, &objects
))
724 for (i
= 0; objects
[i
]; i
++) {
725 os_snprintf(subobj_path
, WPAS_DBUS_OBJECT_PATH_MAX
,
726 "%s/%s", path
, objects
[i
]);
727 recursive_flush_changed_properties(con
, subobj_path
);
731 dbus_free_string_array(objects
);
736 * wpa_dbus_flush_all_changed_properties - Send all PropertiesChanged signals
737 * @con: DBus connection
739 * Traverses through all registered objects and sends PropertiesChanged for
742 void wpa_dbus_flush_all_changed_properties(DBusConnection
*con
)
744 recursive_flush_changed_properties(con
, WPAS_DBUS_NEW_PATH
);
749 * wpa_dbus_flush_object_changed_properties - Send PropertiesChanged for object
750 * @con: DBus connection
751 * @path: path to a DBus object for which PropertiesChanged will be sent.
753 * Iterates over all properties registered with object and for each interface
754 * containing properties marked as changed, sends a PropertiesChanged signal
755 * containing names and new values of properties that have changed.
757 * You need to call this function after wpa_dbus_mark_property_changed()
758 * if you want to send PropertiesChanged signal immediately (i.e., without
759 * waiting timeout to expire). PropertiesChanged signal for an object is sent
760 * automatically short time after first marking property as changed. All
761 * PropertiesChanged signals are sent automatically after responding on DBus
762 * message, so if you marked a property changed as a result of DBus call
763 * (e.g., param setter), you usually do not need to call this function.
765 void wpa_dbus_flush_object_changed_properties(DBusConnection
*con
,
768 struct wpa_dbus_object_desc
*obj_desc
= NULL
;
769 const struct wpa_dbus_property_desc
*dsc
;
772 dbus_connection_get_object_path_data(con
, path
, (void **) &obj_desc
);
775 eloop_cancel_timeout(flush_object_timeout_handler
, con
, obj_desc
);
777 dsc
= obj_desc
->properties
;
778 for (dsc
= obj_desc
->properties
, i
= 0; dsc
&& dsc
->dbus_property
;
780 if (obj_desc
->prop_changed_flags
== NULL
||
781 !obj_desc
->prop_changed_flags
[i
])
783 send_prop_changed_signal(con
, path
, dsc
->dbus_interface
,
789 #define WPA_DBUS_SEND_PROP_CHANGED_TIMEOUT 5000
793 * wpa_dbus_mark_property_changed - Mark a property as changed and
794 * @iface: dbus priv struct
795 * @path: path to DBus object which property has changed
796 * @interface: interface containing changed property
797 * @property: property name which has changed
799 * Iterates over all properties registered with an object and marks the one
800 * given in parameters as changed. All parameters registered for an object
801 * within a single interface will be aggregated together and sent in one
802 * PropertiesChanged signal when function
803 * wpa_dbus_flush_object_changed_properties() is called.
805 void wpa_dbus_mark_property_changed(struct wpas_dbus_priv
*iface
,
806 const char *path
, const char *interface
,
807 const char *property
)
809 struct wpa_dbus_object_desc
*obj_desc
= NULL
;
810 const struct wpa_dbus_property_desc
*dsc
;
816 dbus_connection_get_object_path_data(iface
->con
, path
,
817 (void **) &obj_desc
);
819 wpa_printf(MSG_ERROR
, "dbus: wpa_dbus_property_changed: "
820 "could not obtain object's private data: %s", path
);
824 for (dsc
= obj_desc
->properties
; dsc
&& dsc
->dbus_property
; dsc
++, i
++)
825 if (os_strcmp(property
, dsc
->dbus_property
) == 0 &&
826 os_strcmp(interface
, dsc
->dbus_interface
) == 0) {
827 if (obj_desc
->prop_changed_flags
)
828 obj_desc
->prop_changed_flags
[i
] = 1;
832 if (!dsc
|| !dsc
->dbus_property
) {
833 wpa_printf(MSG_ERROR
, "dbus: wpa_dbus_property_changed: "
834 "no property %s in object %s", property
, path
);
838 if (!eloop_is_timeout_registered(flush_object_timeout_handler
,
839 iface
->con
, obj_desc
->path
)) {
840 eloop_register_timeout(0, WPA_DBUS_SEND_PROP_CHANGED_TIMEOUT
,
841 flush_object_timeout_handler
,
842 iface
->con
, obj_desc
);
848 * wpa_dbus_get_object_properties - Put object's properties into dictionary
849 * @iface: dbus priv struct
850 * @path: path to DBus object which properties will be obtained
851 * @interface: interface name which properties will be obtained
852 * @dict_iter: correct, open DBus dictionary iterator.
854 * Iterates over all properties registered with object and execute getters
855 * of those, which are readable and which interface matches interface
856 * specified as argument. Obtained properties values are stored in
857 * dict_iter dictionary.
859 void wpa_dbus_get_object_properties(struct wpas_dbus_priv
*iface
,
860 const char *path
, const char *interface
,
861 DBusMessageIter
*dict_iter
)
863 struct wpa_dbus_object_desc
*obj_desc
= NULL
;
865 dbus_connection_get_object_path_data(iface
->con
, path
,
866 (void **) &obj_desc
);
868 wpa_printf(MSG_ERROR
, "dbus: wpa_dbus_get_object_properties: "
869 "could not obtain object's private data: %s", path
);
873 fill_dict_with_properties(dict_iter
, obj_desc
->properties
,
874 interface
, obj_desc
->user_data
);