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-2010, Witold Sowa <witold.sowa@gmail.com>
5 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
6 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
10
11#include "includes.h"
12
13#include "common.h"
14#include "common/ieee802_11_defs.h"
15#include "eap_peer/eap_methods.h"
16#include "eapol_supp/eapol_supp_sm.h"
17#include "rsn_supp/wpa.h"
18#include "../config.h"
19#include "../wpa_supplicant_i.h"
20#include "../driver_i.h"
21#include "../notify.h"
22#include "../bss.h"
23#include "../scan.h"
24#include "../autoscan.h"
25#include "dbus_new_helpers.h"
26#include "dbus_new.h"
27#include "dbus_new_handlers.h"
28#include "dbus_dict_helpers.h"
29#include "dbus_common_i.h"
30
31extern int wpa_debug_level;
32extern int wpa_debug_show_keys;
33extern int wpa_debug_timestamp;
34
35static const char *debug_strings[] = {
36 "excessive", "msgdump", "debug", "info", "warning", "error", NULL
37};
38
39
40/**
41 * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
42 * @message: Pointer to incoming dbus message this error refers to
43 * @arg: Optional string appended to error message
44 * Returns: a dbus error message
45 *
46 * Convenience function to create and return an UnknownError
47 */
48DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
49 const char *arg)
50{
51 /*
52 * This function can be called as a result of a failure
53 * within internal getter calls, which will call this function
54 * with a NULL message parameter. However, dbus_message_new_error
55 * looks very unkindly (i.e, abort()) on a NULL message, so
56 * in this case, we should not call it.
57 */
58 if (message == NULL) {
59 wpa_printf(MSG_INFO, "dbus: wpas_dbus_error_unknown_error "
60 "called with NULL message (arg=%s)",
61 arg ? arg : "N/A");
62 return NULL;
63 }
64
65 return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
66 arg);
67}
68
69
70/**
71 * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
72 * @message: Pointer to incoming dbus message this error refers to
--- 45 unchanged lines hidden (view full) ---
118
119 return reply;
120}
121
122
123static const char *dont_quote[] = {
124 "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
125 "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
126 "bssid", "scan_freq", "freq_list", NULL
127};
128
129static dbus_bool_t should_quote_opt(const char *key)
130{
131 int i = 0;
132 while (dont_quote[i] != NULL) {
133 if (os_strcmp(key, dont_quote[i]) == 0)
134 return FALSE;
--- 18 unchanged lines hidden (view full) ---
153 return wpa_s;
154 }
155 return NULL;
156}
157
158
159/**
160 * set_network_properties - Set properties of a configured network
161 * @wpa_s: wpa_supplicant structure for a network interface
162 * @ssid: wpa_ssid structure for a configured network
163 * @iter: DBus message iterator containing dictionary of network
164 * properties to set.
165 * @error: On failure, an error describing the failure
166 * Returns: TRUE if the request succeeds, FALSE if it failed
167 *
168 * Sets network configuration with parameters given id DBus dictionary
169 */
170dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s,
171 struct wpa_ssid *ssid,
172 DBusMessageIter *iter,
173 DBusError *error)
174{
175 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
176 DBusMessageIter iter_dict;
177 char *value = NULL;
178
179 if (!wpa_dbus_dict_open_read(iter, &iter_dict, error))
180 return FALSE;
181
182 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
183 size_t size = 50;
184 int ret;
185
186 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
187 goto error;
188
189 value = NULL;
190 if (entry.type == DBUS_TYPE_ARRAY &&
191 entry.array_type == DBUS_TYPE_BYTE) {
192 if (entry.array_len <= 0)
193 goto error;
194
195 size = entry.array_len * 2 + 1;
196 value = os_zalloc(size);
197 if (value == NULL)
--- 45 unchanged lines hidden (view full) ---
243 } else
244 goto error;
245
246 if (wpa_config_set(ssid, entry.key, value, 0) < 0)
247 goto error;
248
249 if ((os_strcmp(entry.key, "psk") == 0 &&
250 value[0] == '"' && ssid->ssid_len) ||
251 (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
252 wpa_config_update_psk(ssid);
253 else if (os_strcmp(entry.key, "priority") == 0)
254 wpa_config_update_prio_list(wpa_s->conf);
255
256 os_free(value);
257 wpa_dbus_dict_entry_clear(&entry);
258 }
259
260 return TRUE;
261
262error:
263 os_free(value);
264 wpa_dbus_dict_entry_clear(&entry);
265 dbus_set_error_const(error, DBUS_ERROR_INVALID_ARGS,
266 "invalid message format");
267 return FALSE;
268}
269
270
271/**
272 * wpas_dbus_simple_property_getter - Get basic type property
273 * @iter: Message iter to use when appending arguments
274 * @type: DBus type of property (must be basic type)
275 * @val: pointer to place holding property value
276 * @error: On failure an error describing the failure
277 * Returns: TRUE if the request was successful, FALSE if it failed
278 *
279 * Generic getter for basic type properties. Type is required to be basic.
280 */
281dbus_bool_t wpas_dbus_simple_property_getter(DBusMessageIter *iter,
282 const int type,
283 const void *val,
284 DBusError *error)
285{
286 DBusMessageIter variant_iter;
287
288 if (!dbus_type_is_basic(type)) {
289 dbus_set_error(error, DBUS_ERROR_FAILED,
290 "%s: given type is not basic", __func__);
291 return FALSE;
292 }
293
294 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
295 wpa_dbus_type_as_string(type),
296 &variant_iter))
297 goto error;
298
299 if (!dbus_message_iter_append_basic(&variant_iter, type, val))
300 goto error;
301
302 if (!dbus_message_iter_close_container(iter, &variant_iter))
303 goto error;
304
305 return TRUE;
306
307error:
308 dbus_set_error(error, DBUS_ERROR_FAILED,
309 "%s: error constructing reply", __func__);
310 return FALSE;
311}
312
313
314/**
315 * wpas_dbus_simple_property_setter - Set basic type property
316 * @message: Pointer to incoming dbus message
317 * @type: DBus type of property (must be basic type)
318 * @val: pointer to place where value being set will be stored
319 * Returns: TRUE if the request was successful, FALSE if it failed
320 *
321 * Generic setter for basic type properties. Type is required to be basic.
322 */
323dbus_bool_t wpas_dbus_simple_property_setter(DBusMessageIter *iter,
324 DBusError *error,
325 const int type, void *val)
326{
327 DBusMessageIter variant_iter;
328
329 if (!dbus_type_is_basic(type)) {
330 dbus_set_error(error, DBUS_ERROR_FAILED,
331 "%s: given type is not basic", __func__);
332 return FALSE;
333 }
334
335 /* Look at the new value */
336 dbus_message_iter_recurse(iter, &variant_iter);
337 if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
338 dbus_set_error_const(error, DBUS_ERROR_FAILED,
339 "wrong property type");
340 return FALSE;
341 }
342 dbus_message_iter_get_basic(&variant_iter, val);
343
344 return TRUE;
345}
346
347
348/**
349 * wpas_dbus_simple_array_property_getter - Get array type property
350 * @iter: Pointer to incoming dbus message iterator
351 * @type: DBus type of property array elements (must be basic type)
352 * @array: pointer to array of elements to put into response message
353 * @array_len: length of above array
354 * @error: a pointer to an error to fill on failure
355 * Returns: TRUE if the request succeeded, FALSE if it failed
356 *
357 * Generic getter for array type properties. Array elements type is
358 * required to be basic.
359 */
360dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
361 const int type,
362 const void *array,
363 size_t array_len,
364 DBusError *error)
365{
366 DBusMessageIter variant_iter, array_iter;
367 char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
368 const char *sub_type_str;
369 size_t element_size, i;
370
371 if (!dbus_type_is_basic(type)) {
372 dbus_set_error(error, DBUS_ERROR_FAILED,
373 "%s: given type is not basic", __func__);
374 return FALSE;
375 }
376
377 sub_type_str = wpa_dbus_type_as_string(type);
378 type_str[1] = sub_type_str[0];
379
380 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
381 type_str, &variant_iter)) {
382 dbus_set_error(error, DBUS_ERROR_FAILED,
383 "%s: failed to construct message 1", __func__);
384 return FALSE;
385 }
386
387 if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
388 sub_type_str, &array_iter)) {
389 dbus_set_error(error, DBUS_ERROR_FAILED,
390 "%s: failed to construct message 2", __func__);
391 return FALSE;
392 }
393
394 switch(type) {
395 case DBUS_TYPE_BYTE:
396 case DBUS_TYPE_BOOLEAN:
397 element_size = 1;
398 break;
399 case DBUS_TYPE_INT16:
--- 11 unchanged lines hidden (view full) ---
411 case DBUS_TYPE_DOUBLE:
412 element_size = sizeof(double);
413 break;
414 case DBUS_TYPE_STRING:
415 case DBUS_TYPE_OBJECT_PATH:
416 element_size = sizeof(char *);
417 break;
418 default:
419 dbus_set_error(error, DBUS_ERROR_FAILED,
420 "%s: unknown element type %d", __func__, type);
421 return FALSE;
422 }
423
424 for (i = 0; i < array_len; i++) {
425 dbus_message_iter_append_basic(&array_iter, type,
426 array + i * element_size);
427 }
428
429 if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
430 dbus_set_error(error, DBUS_ERROR_FAILED,
431 "%s: failed to construct message 3", __func__);
432 return FALSE;
433 }
434
435 if (!dbus_message_iter_close_container(iter, &variant_iter)) {
436 dbus_set_error(error, DBUS_ERROR_FAILED,
437 "%s: failed to construct message 4", __func__);
438 return FALSE;
439 }
440
441 return TRUE;
442}
443
444
445/**
446 * wpas_dbus_simple_array_array_property_getter - Get array array type property
447 * @iter: Pointer to incoming dbus message iterator
448 * @type: DBus type of property array elements (must be basic type)
449 * @array: pointer to array of elements to put into response message
450 * @array_len: length of above array
451 * @error: a pointer to an error to fill on failure
452 * Returns: TRUE if the request succeeded, FALSE if it failed
453 *
454 * Generic getter for array type properties. Array elements type is
455 * required to be basic.
456 */
457dbus_bool_t wpas_dbus_simple_array_array_property_getter(DBusMessageIter *iter,
458 const int type,
459 struct wpabuf **array,
460 size_t array_len,
461 DBusError *error)
462{
463 DBusMessageIter variant_iter, array_iter;
464 char type_str[] = "aa?";
465 char inner_type_str[] = "a?";
466 const char *sub_type_str;
467 size_t i;
468
469 if (!dbus_type_is_basic(type)) {
470 dbus_set_error(error, DBUS_ERROR_FAILED,
471 "%s: given type is not basic", __func__);
472 return FALSE;
473 }
474
475 sub_type_str = wpa_dbus_type_as_string(type);
476 type_str[2] = sub_type_str[0];
477 inner_type_str[1] = sub_type_str[0];
478
479 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
480 type_str, &variant_iter)) {
481 dbus_set_error(error, DBUS_ERROR_FAILED,
482 "%s: failed to construct message 1", __func__);
483 return FALSE;
484 }
485 if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
486 inner_type_str, &array_iter)) {
487 dbus_set_error(error, DBUS_ERROR_FAILED,
488 "%s: failed to construct message 2", __func__);
489 return FALSE;
490 }
491
492 for (i = 0; i < array_len; i++) {
493 wpa_dbus_dict_bin_array_add_element(&array_iter,
494 wpabuf_head(array[i]),
495 wpabuf_len(array[i]));
496
497 }
498
499 if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
500 dbus_set_error(error, DBUS_ERROR_FAILED,
501 "%s: failed to close message 2", __func__);
502 return FALSE;
503 }
504
505 if (!dbus_message_iter_close_container(iter, &variant_iter)) {
506 dbus_set_error(error, DBUS_ERROR_FAILED,
507 "%s: failed to close message 1", __func__);
508 return FALSE;
509 }
510
511 return TRUE;
512}
513
514
515/**
516 * wpas_dbus_handler_create_interface - Request registration of a network iface
517 * @message: Pointer to incoming dbus message
518 * @global: %wpa_supplicant global data structure
519 * Returns: The object path of the new interface object,
520 * or a dbus error message with more information
521 *
522 * Handler function for "CreateInterface" method call. Handles requests
523 * by dbus clients to register a network interface that wpa_supplicant
524 * will manage.
525 */
526DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
527 struct wpa_global *global)
528{
529 DBusMessageIter iter_dict;
530 DBusMessage *reply = NULL;
531 DBusMessageIter iter;
532 struct wpa_dbus_dict_entry entry;
533 char *driver = NULL;
534 char *ifname = NULL;
535 char *confname = NULL;
536 char *bridge_ifname = NULL;
537
538 dbus_message_iter_init(message, &iter);
539
540 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
541 goto error;
542 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
543 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
544 goto error;
545 if (!os_strcmp(entry.key, "Driver") &&
546 (entry.type == DBUS_TYPE_STRING)) {
547 driver = os_strdup(entry.str_value);
548 wpa_dbus_dict_entry_clear(&entry);
549 if (driver == NULL)
550 goto error;
551 } else if (!os_strcmp(entry.key, "Ifname") &&
552 (entry.type == DBUS_TYPE_STRING)) {
553 ifname = os_strdup(entry.str_value);
554 wpa_dbus_dict_entry_clear(&entry);
555 if (ifname == NULL)
556 goto error;
557 } else if (!os_strcmp(entry.key, "ConfigFile") &&
558 (entry.type == DBUS_TYPE_STRING)) {
559 confname = os_strdup(entry.str_value);
560 wpa_dbus_dict_entry_clear(&entry);
561 if (confname == NULL)
562 goto error;
563 } else if (!os_strcmp(entry.key, "BridgeIfname") &&
564 (entry.type == DBUS_TYPE_STRING)) {
565 bridge_ifname = os_strdup(entry.str_value);
566 wpa_dbus_dict_entry_clear(&entry);
567 if (bridge_ifname == NULL)
568 goto error;
569 } else {
570 wpa_dbus_dict_entry_clear(&entry);
571 goto error;
572 }
--- 12 unchanged lines hidden (view full) ---
585 "wpa_supplicant already "
586 "controls this interface.");
587 } else {
588 struct wpa_supplicant *wpa_s;
589 struct wpa_interface iface;
590 os_memset(&iface, 0, sizeof(iface));
591 iface.driver = driver;
592 iface.ifname = ifname;
593 iface.confname = confname;
594 iface.bridge_ifname = bridge_ifname;
595 /* Otherwise, have wpa_supplicant attach to it. */
596 if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
597 const char *path = wpa_s->dbus_new_path;
598 reply = dbus_message_new_method_return(message);
599 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
600 &path, DBUS_TYPE_INVALID);
601 } else {
602 reply = wpas_dbus_error_unknown_error(
603 message, "wpa_supplicant couldn't grab this "
604 "interface.");
605 }
606 }
607
608out:
609 os_free(driver);
610 os_free(ifname);
611 os_free(confname);
612 os_free(bridge_ifname);
613 return reply;
614
615error:
616 reply = wpas_dbus_error_invalid_args(message, NULL);
617 goto out;
618}
619
--- 17 unchanged lines hidden (view full) ---
637 DBusMessage *reply = NULL;
638
639 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
640 DBUS_TYPE_INVALID);
641
642 wpa_s = get_iface_by_dbus_path(global, path);
643 if (wpa_s == NULL)
644 reply = wpas_dbus_error_iface_unknown(message);
645 else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) {
646 reply = wpas_dbus_error_unknown_error(
647 message, "wpa_supplicant couldn't remove this "
648 "interface.");
649 }
650
651 return reply;
652}
653
--- 35 unchanged lines hidden (view full) ---
689 }
690
691 return reply;
692}
693
694
695/**
696 * wpas_dbus_getter_debug_level - Get debug level
697 * @iter: Pointer to incoming dbus message iter
698 * @error: Location to store error on failure
699 * @user_data: Function specific data
700 * Returns: TRUE on success, FALSE on failure
701 *
702 * Getter for "DebugLevel" property.
703 */
704dbus_bool_t wpas_dbus_getter_debug_level(DBusMessageIter *iter,
705 DBusError *error,
706 void *user_data)
707{
708 const char *str;
709 int idx = wpa_debug_level;
710
711 if (idx < 0)
712 idx = 0;
713 if (idx > 5)
714 idx = 5;
715 str = debug_strings[idx];
716 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
717 &str, error);
718}
719
720
721/**
722 * wpas_dbus_getter_debug_timestamp - Get debug timestamp
723 * @iter: Pointer to incoming dbus message iter
724 * @error: Location to store error on failure
725 * @user_data: Function specific data
726 * Returns: TRUE on success, FALSE on failure
727 *
728 * Getter for "DebugTimestamp" property.
729 */
730dbus_bool_t wpas_dbus_getter_debug_timestamp(DBusMessageIter *iter,
731 DBusError *error,
732 void *user_data)
733{
734 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
735 &wpa_debug_timestamp, error);
736
737}
738
739
740/**
741 * wpas_dbus_getter_debug_show_keys - Get debug show keys
742 * @iter: Pointer to incoming dbus message iter
743 * @error: Location to store error on failure
744 * @user_data: Function specific data
745 * Returns: TRUE on success, FALSE on failure
746 *
747 * Getter for "DebugShowKeys" property.
748 */
749dbus_bool_t wpas_dbus_getter_debug_show_keys(DBusMessageIter *iter,
750 DBusError *error,
751 void *user_data)
752{
753 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
754 &wpa_debug_show_keys, error);
755
756}
757
758/**
759 * wpas_dbus_setter_debug_level - Set debug level
760 * @iter: Pointer to incoming dbus message iter
761 * @error: Location to store error on failure
762 * @user_data: Function specific data
763 * Returns: TRUE on success, FALSE on failure
764 *
765 * Setter for "DebugLevel" property.
766 */
767dbus_bool_t wpas_dbus_setter_debug_level(DBusMessageIter *iter,
768 DBusError *error, void *user_data)
769{
770 struct wpa_global *global = user_data;
771 const char *str = NULL;
772 int i, val = -1;
773
774 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
775 &str))
776 return FALSE;
777
778 for (i = 0; debug_strings[i]; i++)
779 if (os_strcmp(debug_strings[i], str) == 0) {
780 val = i;
781 break;
782 }
783
784 if (val < 0 ||
785 wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
786 wpa_debug_show_keys)) {
787 dbus_set_error_const(error, DBUS_ERROR_FAILED, "wrong debug "
788 "level value");
789 return FALSE;
790 }
791
792 return TRUE;
793}
794
795
796/**
797 * wpas_dbus_setter_debug_timestamp - Set debug timestamp
798 * @iter: Pointer to incoming dbus message iter
799 * @error: Location to store error on failure
800 * @user_data: Function specific data
801 * Returns: TRUE on success, FALSE on failure
802 *
803 * Setter for "DebugTimestamp" property.
804 */
805dbus_bool_t wpas_dbus_setter_debug_timestamp(DBusMessageIter *iter,
806 DBusError *error,
807 void *user_data)
808{
809 struct wpa_global *global = user_data;
810 dbus_bool_t val;
811
812 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
813 &val))
814 return FALSE;
815
816 wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
817 wpa_debug_show_keys);
818 return TRUE;
819}
820
821
822/**
823 * wpas_dbus_setter_debug_show_keys - Set debug show keys
824 * @iter: Pointer to incoming dbus message iter
825 * @error: Location to store error on failure
826 * @user_data: Function specific data
827 * Returns: TRUE on success, FALSE on failure
828 *
829 * Setter for "DebugShowKeys" property.
830 */
831dbus_bool_t wpas_dbus_setter_debug_show_keys(DBusMessageIter *iter,
832 DBusError *error,
833 void *user_data)
834{
835 struct wpa_global *global = user_data;
836 dbus_bool_t val;
837
838 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
839 &val))
840 return FALSE;
841
842 wpa_supplicant_set_debug_params(global, wpa_debug_level,
843 wpa_debug_timestamp,
844 val ? 1 : 0);
845 return TRUE;
846}
847
848
849/**
850 * wpas_dbus_getter_interfaces - Request registered interfaces list
851 * @iter: Pointer to incoming dbus message iter
852 * @error: Location to store error on failure
853 * @user_data: Function specific data
854 * Returns: TRUE on success, FALSE on failure
855 *
856 * Getter for "Interfaces" property. Handles requests
857 * by dbus clients to return list of registered interfaces objects
858 * paths
859 */
860dbus_bool_t wpas_dbus_getter_interfaces(DBusMessageIter *iter,
861 DBusError *error,
862 void *user_data)
863{
864 struct wpa_global *global = user_data;
865 struct wpa_supplicant *wpa_s;
866 const char **paths;
867 unsigned int i = 0, num = 0;
868 dbus_bool_t success;
869
870 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
871 num++;
872
873 paths = os_calloc(num, sizeof(char *));
874 if (!paths) {
875 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
876 return FALSE;
877 }
878
879 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
880 paths[i++] = wpa_s->dbus_new_path;
881
882 success = wpas_dbus_simple_array_property_getter(iter,
883 DBUS_TYPE_OBJECT_PATH,
884 paths, num, error);
885
886 os_free(paths);
887 return success;
888}
889
890
891/**
892 * wpas_dbus_getter_eap_methods - Request supported EAP methods list
893 * @iter: Pointer to incoming dbus message iter
894 * @error: Location to store error on failure
895 * @user_data: Function specific data
896 * Returns: TRUE on success, FALSE on failure
897 *
898 * Getter for "EapMethods" property. Handles requests
899 * by dbus clients to return list of strings with supported EAP methods
900 */
901dbus_bool_t wpas_dbus_getter_eap_methods(DBusMessageIter *iter,
902 DBusError *error, void *user_data)
903{
904 char **eap_methods;
905 size_t num_items = 0;
906 dbus_bool_t success;
907
908 eap_methods = eap_get_names_as_string_array(&num_items);
909 if (!eap_methods) {
910 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
911 return FALSE;
912 }
913
914 success = wpas_dbus_simple_array_property_getter(iter,
915 DBUS_TYPE_STRING,
916 eap_methods,
917 num_items, error);
918
919 while (num_items)
920 os_free(eap_methods[--num_items]);
921 os_free(eap_methods);
922 return success;
923}
924
925
926/**
927 * wpas_dbus_getter_global_capabilities - Request supported global capabilities
928 * @iter: Pointer to incoming dbus message iter
929 * @error: Location to store error on failure
930 * @user_data: Function specific data
931 * Returns: TRUE on success, FALSE on failure
932 *
933 * Getter for "Capabilities" property. Handles requests by dbus clients to
934 * return a list of strings with supported capabilities like AP, RSN IBSS,
935 * and P2P that are determined at compile time.
936 */
937dbus_bool_t wpas_dbus_getter_global_capabilities(DBusMessageIter *iter,
938 DBusError *error,
939 void *user_data)
940{
941 const char *capabilities[5] = { NULL, NULL, NULL, NULL, NULL };
942 size_t num_items = 0;
943
944#ifdef CONFIG_AP
945 capabilities[num_items++] = "ap";
946#endif /* CONFIG_AP */
947#ifdef CONFIG_IBSS_RSN
948 capabilities[num_items++] = "ibss-rsn";
949#endif /* CONFIG_IBSS_RSN */
950#ifdef CONFIG_P2P
951 capabilities[num_items++] = "p2p";
952#endif /* CONFIG_P2P */
953#ifdef CONFIG_INTERWORKING
954 capabilities[num_items++] = "interworking";
955#endif /* CONFIG_INTERWORKING */
956
957 return wpas_dbus_simple_array_property_getter(iter,
958 DBUS_TYPE_STRING,
959 capabilities,
960 num_items, error);
961}
962
963
964static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
965 char **type, DBusMessage **reply)
966{
967 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
968 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
969 "Type must be a string");
970 *reply = wpas_dbus_error_invalid_args(
971 message, "Wrong Type value type. String required");
--- 47 unchanged lines hidden (view full) ---
1019 message, "Too many ssids specified. Specify "
1020 "at most four");
1021 return -1;
1022 }
1023
1024 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1025
1026 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1027
1028 if (len > MAX_SSID_LEN) {
1029 wpa_printf(MSG_DEBUG,
1030 "wpas_dbus_handler_scan[dbus]: "
1031 "SSID too long (len=%d max_len=%d)",
1032 len, MAX_SSID_LEN);
1033 *reply = wpas_dbus_error_invalid_args(
1034 message, "Invalid SSID: too long");
1035 return -1;
1036 }
1037
1038 if (len != 0) {
1039 ssid = os_malloc(len);
1040 if (ssid == NULL) {
1041 wpa_printf(MSG_DEBUG,
1042 "wpas_dbus_handler_scan[dbus]: "
1043 "out of memory. Cannot allocate "
1044 "memory for SSID");
1045 *reply = dbus_message_new_error(
1046 message, DBUS_ERROR_NO_MEMORY, NULL);
1047 return -1;
1048 }
1049 os_memcpy(ssid, val, len);
1050 } else {
1051 /* Allow zero-length SSIDs */
1052 ssid = NULL;
1053 }
1054
1055 ssids[ssids_num].ssid = ssid;
1056 ssids[ssids_num].ssid_len = len;
1057
1058 dbus_message_iter_next(&array_iter);
1059 ssids_num++;
1060 }
1061
1062 params->num_ssids = ssids_num;
--- 128 unchanged lines hidden (view full) ---
1191 os_free(freqs);
1192 return -1;
1193 }
1194
1195 dbus_message_iter_get_basic(&sub_array_iter, &width);
1196
1197#define FREQS_ALLOC_CHUNK 32
1198 if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
1199 nfreqs = os_realloc_array(
1200 freqs, freqs_num + FREQS_ALLOC_CHUNK,
1201 sizeof(int));
1202 if (nfreqs == NULL)
1203 os_free(freqs);
1204 freqs = nfreqs;
1205 }
1206 if (freqs == NULL) {
1207 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1208 "out of memory. can't allocate memory for "
1209 "freqs");
1210 *reply = dbus_message_new_error(
1211 message, DBUS_ERROR_NO_MEMORY, NULL);
1212 return -1;
1213 }
1214
1215 freqs[freqs_num] = freq;
1216
1217 freqs_num++;
1218 dbus_message_iter_next(&array_iter);
1219 }
1220
1221 nfreqs = os_realloc_array(freqs, freqs_num + 1, sizeof(int));
1222 if (nfreqs == NULL)
1223 os_free(freqs);
1224 freqs = nfreqs;
1225 if (freqs == NULL) {
1226 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1227 "out of memory. Can't allocate memory for freqs");
1228 *reply = dbus_message_new_error(
1229 message, DBUS_ERROR_NO_MEMORY, NULL);
--- 75 unchanged lines hidden (view full) ---
1305 if (params.num_ssids || params.extra_ies_len) {
1306 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1307 "SSIDs or IEs specified for passive scan.");
1308 reply = wpas_dbus_error_invalid_args(
1309 message, "You can specify only Channels in "
1310 "passive scan");
1311 goto out;
1312 } else if (params.freqs && params.freqs[0]) {
1313 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1314 } else {
1315 wpa_s->scan_req = MANUAL_SCAN_REQ;
1316 wpa_supplicant_req_scan(wpa_s, 0, 0);
1317 }
1318 } else if (!os_strcmp(type, "active")) {
1319 if (!params.num_ssids) {
1320 /* Add wildcard ssid */
1321 params.num_ssids++;
1322 }
1323#ifdef CONFIG_AUTOSCAN
1324 autoscan_deinit(wpa_s);
1325#endif /* CONFIG_AUTOSCAN */
1326 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1327 } else {
1328 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1329 "Unknown scan type: %s", type);
1330 reply = wpas_dbus_error_invalid_args(message,
1331 "Wrong scan type");
1332 goto out;
1333 }
--- 42 unchanged lines hidden (view full) ---
1376 */
1377DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
1378 struct wpa_supplicant *wpa_s)
1379{
1380 DBusMessage *reply = NULL;
1381 DBusMessageIter iter;
1382 struct wpa_ssid *ssid = NULL;
1383 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
1384 DBusError error;
1385
1386 dbus_message_iter_init(message, &iter);
1387
1388 ssid = wpa_config_add_network(wpa_s->conf);
1389 if (ssid == NULL) {
1390 wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
1391 "can't add new interface.");
1392 reply = wpas_dbus_error_unknown_error(
1393 message,
1394 "wpa_supplicant could not add "
1395 "a network on this interface.");
1396 goto err;
1397 }
1398 wpas_notify_network_added(wpa_s, ssid);
1399 ssid->disabled = 1;
1400 wpa_config_set_network_defaults(ssid);
1401
1402 dbus_error_init(&error);
1403 if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
1404 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
1405 "control interface couldn't set network "
1406 "properties");
1407 reply = wpas_dbus_reply_new_from_error(message, &error,
1408 DBUS_ERROR_INVALID_ARGS,
1409 "Failed to add network");
1410 dbus_error_free(&error);
1411 goto err;
1412 }
1413
1414 /* Construct the object path for this network. */
1415 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1416 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
1417 wpa_s->dbus_new_path, ssid->id);
1418
--- 18 unchanged lines hidden (view full) ---
1437 wpas_notify_network_removed(wpa_s, ssid);
1438 wpa_config_remove_network(wpa_s->conf, ssid->id);
1439 }
1440 return reply;
1441}
1442
1443
1444/**
1445 * wpas_dbus_handler_reassociate - Reassociate to current AP
1446 * @message: Pointer to incoming dbus message
1447 * @wpa_s: wpa_supplicant structure for a network interface
1448 * Returns: NotConnected DBus error message if not connected
1449 * or NULL otherwise.
1450 *
1451 * Handler function for "Reassociate" method call of network interface.
1452 */
1453DBusMessage * wpas_dbus_handler_reassociate(DBusMessage *message,
1454 struct wpa_supplicant *wpa_s)
1455{
1456 if (wpa_s->current_ssid != NULL) {
1457 wpas_request_connection(wpa_s);
1458 return NULL;
1459 }
1460
1461 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
1462 "This interface is not connected");
1463}
1464
1465
1466/**
1467 * wpas_dbus_handler_remove_network - Remove a configured network
1468 * @message: Pointer to incoming dbus message
1469 * @wpa_s: wpa_supplicant structure for a network interface
1470 * Returns: NULL on success or dbus error on failure
1471 *
1472 * Handler function for "RemoveNetwork" method call of a network interface.
1473 */
1474DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
--- 5 unchanged lines hidden (view full) ---
1480 int id;
1481 struct wpa_ssid *ssid;
1482
1483 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1484 DBUS_TYPE_INVALID);
1485
1486 /* Extract the network ID and ensure the network */
1487 /* is actually a child of this interface */
1488 iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
1489 if (iface == NULL || net_id == NULL ||
1490 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1491 reply = wpas_dbus_error_invalid_args(message, op);
1492 goto out;
1493 }
1494
1495 errno = 0;
1496 id = strtoul(net_id, NULL, 10);
1497 if (errno != 0) {
1498 reply = wpas_dbus_error_invalid_args(message, op);
1499 goto out;
1500 }
1501
1502 ssid = wpa_config_get_network(wpa_s->conf, id);
1503 if (ssid == NULL) {
1504 reply = wpas_dbus_error_network_unknown(message);
1505 goto out;
--- 17 unchanged lines hidden (view full) ---
1523
1524out:
1525 os_free(iface);
1526 os_free(net_id);
1527 return reply;
1528}
1529
1530
1531static void remove_network(void *arg, struct wpa_ssid *ssid)
1532{
1533 struct wpa_supplicant *wpa_s = arg;
1534
1535 wpas_notify_network_removed(wpa_s, ssid);
1536
1537 if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) {
1538 wpa_printf(MSG_ERROR,
1539 "wpas_dbus_handler_remove_all_networks[dbus]: "
1540 "error occurred when removing network %d",
1541 ssid->id);
1542 return;
1543 }
1544
1545 if (ssid == wpa_s->current_ssid)
1546 wpa_supplicant_deauthenticate(wpa_s,
1547 WLAN_REASON_DEAUTH_LEAVING);
1548}
1549
1550
1551/**
1552 * wpas_dbus_handler_remove_all_networks - Remove all configured networks
1553 * @message: Pointer to incoming dbus message
1554 * @wpa_s: wpa_supplicant structure for a network interface
1555 * Returns: NULL on success or dbus error on failure
1556 *
1557 * Handler function for "RemoveAllNetworks" method call of a network interface.
1558 */
1559DBusMessage * wpas_dbus_handler_remove_all_networks(
1560 DBusMessage *message, struct wpa_supplicant *wpa_s)
1561{
1562 /* NB: could check for failure and return an error */
1563 wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s);
1564 return NULL;
1565}
1566
1567
1568/**
1569 * wpas_dbus_handler_select_network - Attempt association with a network
1570 * @message: Pointer to incoming dbus message
1571 * @wpa_s: wpa_supplicant structure for a network interface
1572 * Returns: NULL on success or dbus error on failure
1573 *
1574 * Handler function for "SelectNetwork" method call of network interface.
1575 */
1576DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
--- 5 unchanged lines hidden (view full) ---
1582 int id;
1583 struct wpa_ssid *ssid;
1584
1585 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1586 DBUS_TYPE_INVALID);
1587
1588 /* Extract the network ID and ensure the network */
1589 /* is actually a child of this interface */
1590 iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
1591 if (iface == NULL || net_id == NULL ||
1592 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1593 reply = wpas_dbus_error_invalid_args(message, op);
1594 goto out;
1595 }
1596
1597 errno = 0;
1598 id = strtoul(net_id, NULL, 10);
1599 if (errno != 0) {
1600 reply = wpas_dbus_error_invalid_args(message, op);
1601 goto out;
1602 }
1603
1604 ssid = wpa_config_get_network(wpa_s->conf, id);
1605 if (ssid == NULL) {
1606 reply = wpas_dbus_error_network_unknown(message);
1607 goto out;
--- 5 unchanged lines hidden (view full) ---
1613out:
1614 os_free(iface);
1615 os_free(net_id);
1616 return reply;
1617}
1618
1619
1620/**
1621 * wpas_dbus_handler_network_reply - Reply to a NetworkRequest signal
1622 * @message: Pointer to incoming dbus message
1623 * @wpa_s: wpa_supplicant structure for a network interface
1624 * Returns: NULL on success or dbus error on failure
1625 *
1626 * Handler function for "NetworkReply" method call of network interface.
1627 */
1628DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message,
1629 struct wpa_supplicant *wpa_s)
1630{
1631#ifdef IEEE8021X_EAPOL
1632 DBusMessage *reply = NULL;
1633 const char *op, *field, *value;
1634 char *iface = NULL, *net_id = NULL;
1635 int id;
1636 struct wpa_ssid *ssid;
1637
1638 if (!dbus_message_get_args(message, NULL,
1639 DBUS_TYPE_OBJECT_PATH, &op,
1640 DBUS_TYPE_STRING, &field,
1641 DBUS_TYPE_STRING, &value,
1642 DBUS_TYPE_INVALID))
1643 return wpas_dbus_error_invalid_args(message, NULL);
1644
1645 /* Extract the network ID and ensure the network */
1646 /* is actually a child of this interface */
1647 iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
1648 if (iface == NULL || net_id == NULL ||
1649 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1650 reply = wpas_dbus_error_invalid_args(message, op);
1651 goto out;
1652 }
1653
1654 errno = 0;
1655 id = strtoul(net_id, NULL, 10);
1656 if (errno != 0) {
1657 reply = wpas_dbus_error_invalid_args(message, net_id);
1658 goto out;
1659 }
1660
1661 ssid = wpa_config_get_network(wpa_s->conf, id);
1662 if (ssid == NULL) {
1663 reply = wpas_dbus_error_network_unknown(message);
1664 goto out;
1665 }
1666
1667 if (wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid,
1668 field, value) < 0)
1669 reply = wpas_dbus_error_invalid_args(message, field);
1670 else {
1671 /* Tell EAP to retry immediately */
1672 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1673 }
1674
1675out:
1676 os_free(iface);
1677 os_free(net_id);
1678 return reply;
1679#else /* IEEE8021X_EAPOL */
1680 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1681 return wpas_dbus_error_unknown_error(message, "802.1X not included");
1682#endif /* IEEE8021X_EAPOL */
1683}
1684
1685
1686/**
1687 * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
1688 * @message: Pointer to incoming dbus message
1689 * @wpa_s: %wpa_supplicant data structure
1690 * Returns: A dbus message containing an error on failure or NULL on success
1691 *
1692 * Asks wpa_supplicant to internally store a binary blobs.
1693 */
1694DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
--- 147 unchanged lines hidden (view full) ---
1842 "Blob id not set");
1843 }
1844 wpas_notify_blob_removed(wpa_s, blob_name);
1845
1846 return reply;
1847
1848}
1849
1850/*
1851 * wpas_dbus_handler_flush_bss - Flush the BSS cache
1852 * @message: Pointer to incoming dbus message
1853 * @wpa_s: wpa_supplicant structure for a network interface
1854 * Returns: NULL
1855 *
1856 * Handler function for "FlushBSS" method call of network interface.
1857 */
1858DBusMessage * wpas_dbus_handler_flush_bss(DBusMessage *message,
1859 struct wpa_supplicant *wpa_s)
1860{
1861 dbus_uint32_t age;
1862
1863 dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &age,
1864 DBUS_TYPE_INVALID);
1865
1866 if (age == 0)
1867 wpa_bss_flush(wpa_s);
1868 else
1869 wpa_bss_flush_by_age(wpa_s, age);
1870
1871 return NULL;
1872}
1873
1874
1875#ifdef CONFIG_AUTOSCAN
1876/**
1877 * wpas_dbus_handler_autoscan - Set autoscan parameters for the interface
1878 * @message: Pointer to incoming dbus message
1879 * @wpa_s: wpa_supplicant structure for a network interface
1880 * Returns: NULL
1881 *
1882 * Handler function for "AutoScan" method call of network interface.
1883 */
1884DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message,
1885 struct wpa_supplicant *wpa_s)
1886{
1887 DBusMessage *reply = NULL;
1888 enum wpa_states state = wpa_s->wpa_state;
1889 char *arg;
1890
1891 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg,
1892 DBUS_TYPE_INVALID);
1893
1894 if (arg != NULL && os_strlen(arg) > 0) {
1895 char *tmp;
1896 tmp = os_strdup(arg);
1897 if (tmp == NULL) {
1898 reply = dbus_message_new_error(message,
1899 DBUS_ERROR_NO_MEMORY,
1900 NULL);
1901 } else {
1902 os_free(wpa_s->conf->autoscan);
1903 wpa_s->conf->autoscan = tmp;
1904 if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
1905 autoscan_init(wpa_s, 1);
1906 else if (state == WPA_SCANNING)
1907 wpa_supplicant_reinit_autoscan(wpa_s);
1908 }
1909 } else if (arg != NULL && os_strlen(arg) == 0) {
1910 os_free(wpa_s->conf->autoscan);
1911 wpa_s->conf->autoscan = NULL;
1912 autoscan_deinit(wpa_s);
1913 } else
1914 reply = dbus_message_new_error(message,
1915 DBUS_ERROR_INVALID_ARGS,
1916 NULL);
1917
1918 return reply;
1919}
1920#endif /* CONFIG_AUTOSCAN */
1921
1922
1923/**
1924 * wpas_dbus_getter_capabilities - Return interface capabilities
1925 * @iter: Pointer to incoming dbus message iter
1926 * @error: Location to store error on failure
1927 * @user_data: Function specific data
1928 * Returns: TRUE on success, FALSE on failure
1929 *
1930 * Getter for "Capabilities" property of an interface.
1931 */
1932dbus_bool_t wpas_dbus_getter_capabilities(DBusMessageIter *iter,
1933 DBusError *error, void *user_data)
1934{
1935 struct wpa_supplicant *wpa_s = user_data;
1936 struct wpa_driver_capa capa;
1937 int res;
1938 DBusMessageIter iter_dict, iter_dict_entry, iter_dict_val, iter_array,
1939 variant_iter;
1940 const char *scans[] = { "active", "passive", "ssid" };
1941
1942 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
1943 "a{sv}", &variant_iter))
1944 goto nomem;
1945
1946 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
1947 goto nomem;
1948
1949 res = wpa_drv_get_capa(wpa_s, &capa);
1950
--- 12 unchanged lines hidden (view full) ---
1963 goto nomem;
1964
1965 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1966 if (!wpa_dbus_dict_string_array_add_element(
1967 &iter_array, "ccmp"))
1968 goto nomem;
1969 }
1970
1971 if (capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) {
1972 if (!wpa_dbus_dict_string_array_add_element(
1973 &iter_array, "gcmp"))
1974 goto nomem;
1975 }
1976
1977 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1978 if (!wpa_dbus_dict_string_array_add_element(
1979 &iter_array, "tkip"))
1980 goto nomem;
1981 }
1982
1983 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1984 if (!wpa_dbus_dict_string_array_add_element(
--- 25 unchanged lines hidden (view full) ---
2010 goto nomem;
2011
2012 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2013 if (!wpa_dbus_dict_string_array_add_element(
2014 &iter_array, "ccmp"))
2015 goto nomem;
2016 }
2017
2018 if (capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2019 if (!wpa_dbus_dict_string_array_add_element(
2020 &iter_array, "gcmp"))
2021 goto nomem;
2022 }
2023
2024 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2025 if (!wpa_dbus_dict_string_array_add_element(
2026 &iter_array, "tkip"))
2027 goto nomem;
2028 }
2029
2030 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
2031 if (!wpa_dbus_dict_string_array_add_element(
--- 175 unchanged lines hidden (view full) ---
2207 }
2208
2209 /***** Scan */
2210 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
2211 sizeof(scans) / sizeof(char *)))
2212 goto nomem;
2213
2214 /***** Modes */
2215 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Modes",
2216 &iter_dict_entry,
2217 &iter_dict_val,
2218 &iter_array))
2219 goto nomem;
2220
2221 if (!wpa_dbus_dict_string_array_add_element(
2222 &iter_array, "infrastructure"))
2223 goto nomem;
2224
2225 if (!wpa_dbus_dict_string_array_add_element(
2226 &iter_array, "ad-hoc"))
2227 goto nomem;
2228
2229 if (res >= 0) {
2230 if (capa.flags & (WPA_DRIVER_FLAGS_AP)) {
2231 if (!wpa_dbus_dict_string_array_add_element(
2232 &iter_array, "ap"))
2233 goto nomem;
2234 }
2235
2236 if (capa.flags & (WPA_DRIVER_FLAGS_P2P_CAPABLE)) {
2237 if (!wpa_dbus_dict_string_array_add_element(
2238 &iter_array, "p2p"))
2239 goto nomem;
2240 }
2241 }
2242
2243 if (!wpa_dbus_dict_end_string_array(&iter_dict,
2244 &iter_dict_entry,
2245 &iter_dict_val,
2246 &iter_array))
2247 goto nomem;
2248 /***** Modes end */
2249
2250 if (res >= 0) {
2251 dbus_int32_t max_scan_ssid = capa.max_scan_ssids;
2252
2253 if (!wpa_dbus_dict_append_int32(&iter_dict, "MaxScanSSID",
2254 max_scan_ssid))
2255 goto nomem;
2256 }
2257
2258 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
2259 goto nomem;
2260 if (!dbus_message_iter_close_container(iter, &variant_iter))
2261 goto nomem;
2262
2263 return TRUE;
2264
2265nomem:
2266 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2267 return FALSE;
2268}
2269
2270
2271/**
2272 * wpas_dbus_getter_state - Get interface state
2273 * @iter: Pointer to incoming dbus message iter
2274 * @error: Location to store error on failure
2275 * @user_data: Function specific data
2276 * Returns: TRUE on success, FALSE on failure
2277 *
2278 * Getter for "State" property.
2279 */
2280dbus_bool_t wpas_dbus_getter_state(DBusMessageIter *iter, DBusError *error,
2281 void *user_data)
2282{
2283 struct wpa_supplicant *wpa_s = user_data;
2284 const char *str_state;
2285 char *state_ls, *tmp;
2286 dbus_bool_t success = FALSE;
2287
2288 str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
2289
2290 /* make state string lowercase to fit new DBus API convention
2291 */
2292 state_ls = tmp = os_strdup(str_state);
2293 if (!tmp) {
2294 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2295 return FALSE;
2296 }
2297 while (*tmp) {
2298 *tmp = tolower(*tmp);
2299 tmp++;
2300 }
2301
2302 success = wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2303 &state_ls, error);
2304
2305 os_free(state_ls);
2306
2307 return success;
2308}
2309
2310
2311/**
2312 * wpas_dbus_new_iface_get_scanning - Get interface scanning state
2313 * @iter: Pointer to incoming dbus message iter
2314 * @error: Location to store error on failure
2315 * @user_data: Function specific data
2316 * Returns: TRUE on success, FALSE on failure
2317 *
2318 * Getter for "scanning" property.
2319 */
2320dbus_bool_t wpas_dbus_getter_scanning(DBusMessageIter *iter, DBusError *error,
2321 void *user_data)
2322{
2323 struct wpa_supplicant *wpa_s = user_data;
2324 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
2325
2326 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
2327 &scanning, error);
2328}
2329
2330
2331/**
2332 * wpas_dbus_getter_ap_scan - Control roaming mode
2333 * @iter: Pointer to incoming dbus message iter
2334 * @error: Location to store error on failure
2335 * @user_data: Function specific data
2336 * Returns: TRUE on success, FALSE on failure
2337 *
2338 * Getter function for "ApScan" property.
2339 */
2340dbus_bool_t wpas_dbus_getter_ap_scan(DBusMessageIter *iter, DBusError *error,
2341 void *user_data)
2342{
2343 struct wpa_supplicant *wpa_s = user_data;
2344 dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
2345
2346 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2347 &ap_scan, error);
2348}
2349
2350
2351/**
2352 * wpas_dbus_setter_ap_scan - Control roaming mode
2353 * @iter: Pointer to incoming dbus message iter
2354 * @error: Location to store error on failure
2355 * @user_data: Function specific data
2356 * Returns: TRUE on success, FALSE on failure
2357 *
2358 * Setter function for "ApScan" property.
2359 */
2360dbus_bool_t wpas_dbus_setter_ap_scan(DBusMessageIter *iter, DBusError *error,
2361 void *user_data)
2362{
2363 struct wpa_supplicant *wpa_s = user_data;
2364 dbus_uint32_t ap_scan;
2365
2366 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2367 &ap_scan))
2368 return FALSE;
2369
2370 if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
2371 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2372 "ap_scan must be 0, 1, or 2");
2373 return FALSE;
2374 }
2375 return TRUE;
2376}
2377
2378
2379/**
2380 * wpas_dbus_getter_fast_reauth - Control fast
2381 * reauthentication (TLS session resumption)
2382 * @iter: Pointer to incoming dbus message iter
2383 * @error: Location to store error on failure
2384 * @user_data: Function specific data
2385 * Returns: TRUE on success, FALSE on failure
2386 *
2387 * Getter function for "FastReauth" property.
2388 */
2389dbus_bool_t wpas_dbus_getter_fast_reauth(DBusMessageIter *iter,
2390 DBusError *error,
2391 void *user_data)
2392{
2393 struct wpa_supplicant *wpa_s = user_data;
2394 dbus_bool_t fast_reauth = wpa_s->conf->fast_reauth ? TRUE : FALSE;
2395
2396 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
2397 &fast_reauth, error);
2398}
2399
2400
2401/**
2402 * wpas_dbus_setter_fast_reauth - Control fast
2403 * reauthentication (TLS session resumption)
2404 * @iter: Pointer to incoming dbus message iter
2405 * @error: Location to store error on failure
2406 * @user_data: Function specific data
2407 * Returns: TRUE on success, FALSE on failure
2408 *
2409 * Setter function for "FastReauth" property.
2410 */
2411dbus_bool_t wpas_dbus_setter_fast_reauth(DBusMessageIter *iter,
2412 DBusError *error,
2413 void *user_data)
2414{
2415 struct wpa_supplicant *wpa_s = user_data;
2416 dbus_bool_t fast_reauth;
2417
2418 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
2419 &fast_reauth))
2420 return FALSE;
2421
2422 wpa_s->conf->fast_reauth = fast_reauth;
2423 return TRUE;
2424}
2425
2426
2427/**
2428 * wpas_dbus_getter_disconnect_reason - Get most recent reason for disconnect
2429 * @iter: Pointer to incoming dbus message iter
2430 * @error: Location to store error on failure
2431 * @user_data: Function specific data
2432 * Returns: TRUE on success, FALSE on failure
2433 *
2434 * Getter for "DisconnectReason" property. The reason is negative if it is
2435 * locally generated.
2436 */
2437dbus_bool_t wpas_dbus_getter_disconnect_reason(DBusMessageIter *iter,
2438 DBusError *error,
2439 void *user_data)
2440{
2441 struct wpa_supplicant *wpa_s = user_data;
2442 dbus_int32_t reason = wpa_s->disconnect_reason;
2443 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
2444 &reason, error);
2445}
2446
2447
2448/**
2449 * wpas_dbus_getter_bss_expire_age - Get BSS entry expiration age
2450 * @iter: Pointer to incoming dbus message iter
2451 * @error: Location to store error on failure
2452 * @user_data: Function specific data
2453 * Returns: TRUE on success, FALSE on failure
2454 *
2455 * Getter function for "BSSExpireAge" property.
2456 */
2457dbus_bool_t wpas_dbus_getter_bss_expire_age(DBusMessageIter *iter,
2458 DBusError *error,
2459 void *user_data)
2460{
2461 struct wpa_supplicant *wpa_s = user_data;
2462 dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age;
2463
2464 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2465 &expire_age, error);
2466}
2467
2468
2469/**
2470 * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age
2471 * @iter: Pointer to incoming dbus message iter
2472 * @error: Location to store error on failure
2473 * @user_data: Function specific data
2474 * Returns: TRUE on success, FALSE on failure
2475 *
2476 * Setter function for "BSSExpireAge" property.
2477 */
2478dbus_bool_t wpas_dbus_setter_bss_expire_age(DBusMessageIter *iter,
2479 DBusError *error,
2480 void *user_data)
2481{
2482 struct wpa_supplicant *wpa_s = user_data;
2483 dbus_uint32_t expire_age;
2484
2485 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2486 &expire_age))
2487 return FALSE;
2488
2489 if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) {
2490 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2491 "BSSExpireAge must be >= 10");
2492 return FALSE;
2493 }
2494 return TRUE;
2495}
2496
2497
2498/**
2499 * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count
2500 * @iter: Pointer to incoming dbus message iter
2501 * @error: Location to store error on failure
2502 * @user_data: Function specific data
2503 * Returns: TRUE on success, FALSE on failure
2504 *
2505 * Getter function for "BSSExpireCount" property.
2506 */
2507dbus_bool_t wpas_dbus_getter_bss_expire_count(DBusMessageIter *iter,
2508 DBusError *error,
2509 void *user_data)
2510{
2511 struct wpa_supplicant *wpa_s = user_data;
2512 dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_scan_count;
2513
2514 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2515 &expire_count, error);
2516}
2517
2518
2519/**
2520 * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count
2521 * @iter: Pointer to incoming dbus message iter
2522 * @error: Location to store error on failure
2523 * @user_data: Function specific data
2524 * Returns: TRUE on success, FALSE on failure
2525 *
2526 * Setter function for "BSSExpireCount" property.
2527 */
2528dbus_bool_t wpas_dbus_setter_bss_expire_count(DBusMessageIter *iter,
2529 DBusError *error,
2530 void *user_data)
2531{
2532 struct wpa_supplicant *wpa_s = user_data;
2533 dbus_uint32_t expire_count;
2534
2535 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2536 &expire_count))
2537 return FALSE;
2538
2539 if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) {
2540 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2541 "BSSExpireCount must be > 0");
2542 return FALSE;
2543 }
2544 return TRUE;
2545}
2546
2547
2548/**
2549 * wpas_dbus_getter_country - Control country code
2550 * @iter: Pointer to incoming dbus message iter
2551 * @error: Location to store error on failure
2552 * @user_data: Function specific data
2553 * Returns: TRUE on success, FALSE on failure
2554 *
2555 * Getter function for "Country" property.
2556 */
2557dbus_bool_t wpas_dbus_getter_country(DBusMessageIter *iter, DBusError *error,
2558 void *user_data)
2559{
2560 struct wpa_supplicant *wpa_s = user_data;
2561 char country[3];
2562 char *str = country;
2563
2564 country[0] = wpa_s->conf->country[0];
2565 country[1] = wpa_s->conf->country[1];
2566 country[2] = '\0';
2567
2568 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2569 &str, error);
2570}
2571
2572
2573/**
2574 * wpas_dbus_setter_country - Control country code
2575 * @iter: Pointer to incoming dbus message iter
2576 * @error: Location to store error on failure
2577 * @user_data: Function specific data
2578 * Returns: TRUE on success, FALSE on failure
2579 *
2580 * Setter function for "Country" property.
2581 */
2582dbus_bool_t wpas_dbus_setter_country(DBusMessageIter *iter, DBusError *error,
2583 void *user_data)
2584{
2585 struct wpa_supplicant *wpa_s = user_data;
2586 const char *country;
2587
2588 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
2589 &country))
2590 return FALSE;
2591
2592 if (!country[0] || !country[1]) {
2593 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2594 "invalid country code");
2595 return FALSE;
2596 }
2597
2598 if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) {
2599 wpa_printf(MSG_DEBUG, "Failed to set country");
2600 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2601 "failed to set country code");
2602 return FALSE;
2603 }
2604
2605 wpa_s->conf->country[0] = country[0];
2606 wpa_s->conf->country[1] = country[1];
2607 return TRUE;
2608}
2609
2610
2611/**
2612 * wpas_dbus_getter_scan_interval - Get scan interval
2613 * @iter: Pointer to incoming dbus message iter
2614 * @error: Location to store error on failure
2615 * @user_data: Function specific data
2616 * Returns: TRUE on success, FALSE on failure
2617 *
2618 * Getter function for "ScanInterval" property.
2619 */
2620dbus_bool_t wpas_dbus_getter_scan_interval(DBusMessageIter *iter,
2621 DBusError *error,
2622 void *user_data)
2623{
2624 struct wpa_supplicant *wpa_s = user_data;
2625 dbus_int32_t scan_interval = wpa_s->scan_interval;
2626
2627 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
2628 &scan_interval, error);
2629}
2630
2631
2632/**
2633 * wpas_dbus_setter_scan_interval - Control scan interval
2634 * @iter: Pointer to incoming dbus message iter
2635 * @error: Location to store error on failure
2636 * @user_data: Function specific data
2637 * Returns: TRUE on success, FALSE on failure
2638 *
2639 * Setter function for "ScanInterval" property.
2640 */
2641dbus_bool_t wpas_dbus_setter_scan_interval(DBusMessageIter *iter,
2642 DBusError *error,
2643 void *user_data)
2644{
2645 struct wpa_supplicant *wpa_s = user_data;
2646 dbus_int32_t scan_interval;
2647
2648 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_INT32,
2649 &scan_interval))
2650 return FALSE;
2651
2652 if (wpa_supplicant_set_scan_interval(wpa_s, scan_interval)) {
2653 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2654 "scan_interval must be >= 0");
2655 return FALSE;
2656 }
2657 return TRUE;
2658}
2659
2660
2661/**
2662 * wpas_dbus_getter_ifname - Get interface name
2663 * @iter: Pointer to incoming dbus message iter
2664 * @error: Location to store error on failure
2665 * @user_data: Function specific data
2666 * Returns: TRUE on success, FALSE on failure
2667 *
2668 * Getter for "Ifname" property.
2669 */
2670dbus_bool_t wpas_dbus_getter_ifname(DBusMessageIter *iter, DBusError *error,
2671 void *user_data)
2672{
2673 struct wpa_supplicant *wpa_s = user_data;
2674 const char *ifname = wpa_s->ifname;
2675
2676 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2677 &ifname, error);
2678}
2679
2680
2681/**
2682 * wpas_dbus_getter_driver - Get interface name
2683 * @iter: Pointer to incoming dbus message iter
2684 * @error: Location to store error on failure
2685 * @user_data: Function specific data
2686 * Returns: TRUE on success, FALSE on failure
2687 *
2688 * Getter for "Driver" property.
2689 */
2690dbus_bool_t wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error,
2691 void *user_data)
2692{
2693 struct wpa_supplicant *wpa_s = user_data;
2694 const char *driver;
2695
2696 if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
2697 wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
2698 "wpa_s has no driver set");
2699 dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
2700 __func__);
2701 return FALSE;
2702 }
2703
2704 driver = wpa_s->driver->name;
2705 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2706 &driver, error);
2707}
2708
2709
2710/**
2711 * wpas_dbus_getter_current_bss - Get current bss object path
2712 * @iter: Pointer to incoming dbus message iter
2713 * @error: Location to store error on failure
2714 * @user_data: Function specific data
2715 * Returns: TRUE on success, FALSE on failure
2716 *
2717 * Getter for "CurrentBSS" property.
2718 */
2719dbus_bool_t wpas_dbus_getter_current_bss(DBusMessageIter *iter,
2720 DBusError *error,
2721 void *user_data)
2722{
2723 struct wpa_supplicant *wpa_s = user_data;
2724 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
2725
2726 if (wpa_s->current_bss)
2727 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2728 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2729 wpa_s->dbus_new_path, wpa_s->current_bss->id);
2730 else
2731 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2732
2733 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
2734 &bss_obj_path, error);
2735}
2736
2737
2738/**
2739 * wpas_dbus_getter_current_network - Get current network object path
2740 * @iter: Pointer to incoming dbus message iter
2741 * @error: Location to store error on failure
2742 * @user_data: Function specific data
2743 * Returns: TRUE on success, FALSE on failure
2744 *
2745 * Getter for "CurrentNetwork" property.
2746 */
2747dbus_bool_t wpas_dbus_getter_current_network(DBusMessageIter *iter,
2748 DBusError *error,
2749 void *user_data)
2750{
2751 struct wpa_supplicant *wpa_s = user_data;
2752 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
2753
2754 if (wpa_s->current_ssid)
2755 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2756 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2757 wpa_s->dbus_new_path, wpa_s->current_ssid->id);
2758 else
2759 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2760
2761 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
2762 &net_obj_path, error);
2763}
2764
2765
2766/**
2767 * wpas_dbus_getter_current_auth_mode - Get current authentication type
2768 * @iter: Pointer to incoming dbus message iter
2769 * @error: Location to store error on failure
2770 * @user_data: Function specific data
2771 * Returns: TRUE on success, FALSE on failure
2772 *
2773 * Getter for "CurrentAuthMode" property.
2774 */
2775dbus_bool_t wpas_dbus_getter_current_auth_mode(DBusMessageIter *iter,
2776 DBusError *error,
2777 void *user_data)
2778{
2779 struct wpa_supplicant *wpa_s = user_data;
2780 const char *eap_mode;
2781 const char *auth_mode;
2782 char eap_mode_buf[WPAS_DBUS_AUTH_MODE_MAX];
2783
2784 if (wpa_s->wpa_state != WPA_COMPLETED) {
2785 auth_mode = "INACTIVE";
2786 } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
2787 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2788 eap_mode = wpa_supplicant_get_eap_mode(wpa_s);
2789 os_snprintf(eap_mode_buf, WPAS_DBUS_AUTH_MODE_MAX,
2790 "EAP-%s", eap_mode);
2791 auth_mode = eap_mode_buf;
2792
2793 } else {
2794 auth_mode = wpa_key_mgmt_txt(wpa_s->key_mgmt,
2795 wpa_s->current_ssid->proto);
2796 }
2797
2798 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2799 &auth_mode, error);
2800}
2801
2802
2803/**
2804 * wpas_dbus_getter_bridge_ifname - Get interface name
2805 * @iter: Pointer to incoming dbus message iter
2806 * @error: Location to store error on failure
2807 * @user_data: Function specific data
2808 * Returns: TRUE on success, FALSE on failure
2809 *
2810 * Getter for "BridgeIfname" property.
2811 */
2812dbus_bool_t wpas_dbus_getter_bridge_ifname(DBusMessageIter *iter,
2813 DBusError *error,
2814 void *user_data)
2815{
2816 struct wpa_supplicant *wpa_s = user_data;
2817 const char *bridge_ifname = wpa_s->bridge_ifname;
2818 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2819 &bridge_ifname, error);
2820}
2821
2822
2823/**
2824 * wpas_dbus_getter_bsss - Get array of BSSs objects
2825 * @iter: Pointer to incoming dbus message iter
2826 * @error: Location to store error on failure
2827 * @user_data: Function specific data
2828 * Returns: TRUE on success, FALSE on failure
2829 *
2830 * Getter for "BSSs" property.
2831 */
2832dbus_bool_t wpas_dbus_getter_bsss(DBusMessageIter *iter, DBusError *error,
2833 void *user_data)
2834{
2835 struct wpa_supplicant *wpa_s = user_data;
2836 struct wpa_bss *bss;
2837 char **paths;
2838 unsigned int i = 0;
2839 dbus_bool_t success = FALSE;
2840
2841 paths = os_calloc(wpa_s->num_bss, sizeof(char *));
2842 if (!paths) {
2843 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2844 return FALSE;
2845 }
2846
2847 /* Loop through scan results and append each result's object path */
2848 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2849 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2850 if (paths[i] == NULL) {
2851 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
2852 "no memory");
2853 goto out;
2854 }
2855 /* Construct the object path for this BSS. */
2856 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2857 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2858 wpa_s->dbus_new_path, bss->id);
2859 }
2860
2861 success = wpas_dbus_simple_array_property_getter(iter,
2862 DBUS_TYPE_OBJECT_PATH,
2863 paths, wpa_s->num_bss,
2864 error);
2865
2866out:
2867 while (i)
2868 os_free(paths[--i]);
2869 os_free(paths);
2870 return success;
2871}
2872
2873
2874/**
2875 * wpas_dbus_getter_networks - Get array of networks objects
2876 * @iter: Pointer to incoming dbus message iter
2877 * @error: Location to store error on failure
2878 * @user_data: Function specific data
2879 * Returns: TRUE on success, FALSE on failure
2880 *
2881 * Getter for "Networks" property.
2882 */
2883dbus_bool_t wpas_dbus_getter_networks(DBusMessageIter *iter, DBusError *error,
2884 void *user_data)
2885{
2886 struct wpa_supplicant *wpa_s = user_data;
2887 struct wpa_ssid *ssid;
2888 char **paths;
2889 unsigned int i = 0, num = 0;
2890 dbus_bool_t success = FALSE;
2891
2892 if (wpa_s->conf == NULL) {
2893 wpa_printf(MSG_ERROR, "%s[dbus]: An error occurred getting "
2894 "networks list.", __func__);
2895 dbus_set_error(error, DBUS_ERROR_FAILED, "%s: an error "
2896 "occurred getting the networks list", __func__);
2897 return FALSE;
2898 }
2899
2900 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
2901 if (!network_is_persistent_group(ssid))
2902 num++;
2903
2904 paths = os_calloc(num, sizeof(char *));
2905 if (!paths) {
2906 dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
2907 return FALSE;
2908 }
2909
2910 /* Loop through configured networks and append object path of each */
2911 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
2912 if (network_is_persistent_group(ssid))
2913 continue;
2914 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2915 if (paths[i] == NULL) {
2916 dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
2917 goto out;
2918 }
2919
2920 /* Construct the object path for this network. */
2921 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2922 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
2923 wpa_s->dbus_new_path, ssid->id);
2924 }
2925
2926 success = wpas_dbus_simple_array_property_getter(iter,
2927 DBUS_TYPE_OBJECT_PATH,
2928 paths, num, error);
2929
2930out:
2931 while (i)
2932 os_free(paths[--i]);
2933 os_free(paths);
2934 return success;
2935}
2936
2937
2938/**
2939 * wpas_dbus_getter_blobs - Get all blobs defined for this interface
2940 * @iter: Pointer to incoming dbus message iter
2941 * @error: Location to store error on failure
2942 * @user_data: Function specific data
2943 * Returns: TRUE on success, FALSE on failure
2944 *
2945 * Getter for "Blobs" property.
2946 */
2947dbus_bool_t wpas_dbus_getter_blobs(DBusMessageIter *iter, DBusError *error,
2948 void *user_data)
2949{
2950 struct wpa_supplicant *wpa_s = user_data;
2951 DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter;
2952 struct wpa_config_blob *blob;
2953
2954 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
2955 "a{say}", &variant_iter) ||
2956 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
2957 "{say}", &dict_iter)) {
2958 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2959 return FALSE;
2960 }
2961
2962 blob = wpa_s->conf->blobs;
2963 while (blob) {
2964 if (!dbus_message_iter_open_container(&dict_iter,
2965 DBUS_TYPE_DICT_ENTRY,
2966 NULL, &entry_iter) ||
2967 !dbus_message_iter_append_basic(&entry_iter,
--- 6 unchanged lines hidden (view full) ---
2974 !dbus_message_iter_append_fixed_array(&array_iter,
2975 DBUS_TYPE_BYTE,
2976 &(blob->data),
2977 blob->len) ||
2978 !dbus_message_iter_close_container(&entry_iter,
2979 &array_iter) ||
2980 !dbus_message_iter_close_container(&dict_iter,
2981 &entry_iter)) {
2982 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
2983 "no memory");
2984 return FALSE;
2985 }
2986
2987 blob = blob->next;
2988 }
2989
2990 if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
2991 !dbus_message_iter_close_container(iter, &variant_iter)) {
2992 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2993 return FALSE;
2994 }
2995
2996 return TRUE;
2997}
2998
2999
3000static struct wpa_bss * get_bss_helper(struct bss_handler_args *args,
3001 DBusError *error, const char *func_name)
3002{
3003 struct wpa_bss *res = wpa_bss_get_id(args->wpa_s, args->id);
3004
3005 if (!res) {
3006 wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found",
3007 func_name, args->id);
3008 dbus_set_error(error, DBUS_ERROR_FAILED,
3009 "%s: BSS %d not found",
3010 func_name, args->id);
3011 }
3012
3013 return res;
3014}
3015
3016
3017/**
3018 * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
3019 * @iter: Pointer to incoming dbus message iter
3020 * @error: Location to store error on failure
3021 * @user_data: Function specific data
3022 * Returns: TRUE on success, FALSE on failure
3023 *
3024 * Getter for "BSSID" property.
3025 */
3026dbus_bool_t wpas_dbus_getter_bss_bssid(DBusMessageIter *iter, DBusError *error,
3027 void *user_data)
3028{
3029 struct bss_handler_args *args = user_data;
3030 struct wpa_bss *res;
3031
3032 res = get_bss_helper(args, error, __func__);
3033 if (!res)
3034 return FALSE;
3035
3036 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3037 res->bssid, ETH_ALEN,
3038 error);
3039}
3040
3041
3042/**
3043 * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
3044 * @iter: Pointer to incoming dbus message iter
3045 * @error: Location to store error on failure
3046 * @user_data: Function specific data
3047 * Returns: TRUE on success, FALSE on failure
3048 *
3049 * Getter for "SSID" property.
3050 */
3051dbus_bool_t wpas_dbus_getter_bss_ssid(DBusMessageIter *iter, DBusError *error,
3052 void *user_data)
3053{
3054 struct bss_handler_args *args = user_data;
3055 struct wpa_bss *res;
3056
3057 res = get_bss_helper(args, error, __func__);
3058 if (!res)
3059 return FALSE;
3060
3061 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3062 res->ssid, res->ssid_len,
3063 error);
3064}
3065
3066
3067/**
3068 * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
3069 * @iter: Pointer to incoming dbus message iter
3070 * @error: Location to store error on failure
3071 * @user_data: Function specific data
3072 * Returns: TRUE on success, FALSE on failure
3073 *
3074 * Getter for "Privacy" property.
3075 */
3076dbus_bool_t wpas_dbus_getter_bss_privacy(DBusMessageIter *iter,
3077 DBusError *error, void *user_data)
3078{
3079 struct bss_handler_args *args = user_data;
3080 struct wpa_bss *res;
3081 dbus_bool_t privacy;
3082
3083 res = get_bss_helper(args, error, __func__);
3084 if (!res)
3085 return FALSE;
3086
3087 privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
3088 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
3089 &privacy, error);
3090}
3091
3092
3093/**
3094 * wpas_dbus_getter_bss_mode - Return the mode of a BSS
3095 * @iter: Pointer to incoming dbus message iter
3096 * @error: Location to store error on failure
3097 * @user_data: Function specific data
3098 * Returns: TRUE on success, FALSE on failure
3099 *
3100 * Getter for "Mode" property.
3101 */
3102dbus_bool_t wpas_dbus_getter_bss_mode(DBusMessageIter *iter, DBusError *error,
3103 void *user_data)
3104{
3105 struct bss_handler_args *args = user_data;
3106 struct wpa_bss *res;
3107 const char *mode;
3108
3109 res = get_bss_helper(args, error, __func__);
3110 if (!res)
3111 return FALSE;
3112
3113 if (res->caps & IEEE80211_CAP_IBSS)
3114 mode = "ad-hoc";
3115 else
3116 mode = "infrastructure";
3117
3118 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3119 &mode, error);
3120}
3121
3122
3123/**
3124 * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
3125 * @iter: Pointer to incoming dbus message iter
3126 * @error: Location to store error on failure
3127 * @user_data: Function specific data
3128 * Returns: TRUE on success, FALSE on failure
3129 *
3130 * Getter for "Level" property.
3131 */
3132dbus_bool_t wpas_dbus_getter_bss_signal(DBusMessageIter *iter,
3133 DBusError *error, void *user_data)
3134{
3135 struct bss_handler_args *args = user_data;
3136 struct wpa_bss *res;
3137 s16 level;
3138
3139 res = get_bss_helper(args, error, __func__);
3140 if (!res)
3141 return FALSE;
3142
3143 level = (s16) res->level;
3144 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16,
3145 &level, error);
3146}
3147
3148
3149/**
3150 * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
3151 * @iter: Pointer to incoming dbus message iter
3152 * @error: Location to store error on failure
3153 * @user_data: Function specific data
3154 * Returns: TRUE on success, FALSE on failure
3155 *
3156 * Getter for "Frequency" property.
3157 */
3158dbus_bool_t wpas_dbus_getter_bss_frequency(DBusMessageIter *iter,
3159 DBusError *error, void *user_data)
3160{
3161 struct bss_handler_args *args = user_data;
3162 struct wpa_bss *res;
3163 u16 freq;
3164
3165 res = get_bss_helper(args, error, __func__);
3166 if (!res)
3167 return FALSE;
3168
3169 freq = (u16) res->freq;
3170 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
3171 &freq, error);
3172}
3173
3174
3175static int cmp_u8s_desc(const void *a, const void *b)
3176{
3177 return (*(u8 *) b - *(u8 *) a);
3178}
3179
3180
3181/**
3182 * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
3183 * @iter: Pointer to incoming dbus message iter
3184 * @error: Location to store error on failure
3185 * @user_data: Function specific data
3186 * Returns: TRUE on success, FALSE on failure
3187 *
3188 * Getter for "Rates" property.
3189 */
3190dbus_bool_t wpas_dbus_getter_bss_rates(DBusMessageIter *iter,
3191 DBusError *error, void *user_data)
3192{
3193 struct bss_handler_args *args = user_data;
3194 struct wpa_bss *res;
3195 u8 *ie_rates = NULL;
3196 u32 *real_rates;
3197 int rates_num, i;
3198 dbus_bool_t success = FALSE;
3199
3200 res = get_bss_helper(args, error, __func__);
3201 if (!res)
3202 return FALSE;
3203
3204 rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
3205 if (rates_num < 0)
3206 return FALSE;
3207
3208 qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
3209
3210 real_rates = os_malloc(sizeof(u32) * rates_num);
3211 if (!real_rates) {
3212 os_free(ie_rates);
3213 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3214 return FALSE;
3215 }
3216
3217 for (i = 0; i < rates_num; i++)
3218 real_rates[i] = ie_rates[i] * 500000;
3219
3220 success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32,
3221 real_rates, rates_num,
3222 error);
3223
3224 os_free(ie_rates);
3225 os_free(real_rates);
3226 return success;
3227}
3228
3229
3230static dbus_bool_t wpas_dbus_get_bss_security_prop(DBusMessageIter *iter,
3231 struct wpa_ie_data *ie_data,
3232 DBusError *error)
3233{
3234 DBusMessageIter iter_dict, variant_iter;
3235 const char *group;
3236 const char *pairwise[3]; /* max 3 pairwise ciphers is supported */
3237 const char *key_mgmt[7]; /* max 7 key managements may be supported */
3238 int n;
3239
3240 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
3241 "a{sv}", &variant_iter))
3242 goto nomem;
3243
3244 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
3245 goto nomem;
3246
3247 /* KeyMgmt */
3248 n = 0;
--- 22 unchanged lines hidden (view full) ---
3271 group = "wep40";
3272 break;
3273 case WPA_CIPHER_TKIP:
3274 group = "tkip";
3275 break;
3276 case WPA_CIPHER_CCMP:
3277 group = "ccmp";
3278 break;
3279 case WPA_CIPHER_GCMP:
3280 group = "gcmp";
3281 break;
3282 case WPA_CIPHER_WEP104:
3283 group = "wep104";
3284 break;
3285 default:
3286 group = "";
3287 break;
3288 }
3289
3290 if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
3291 goto nomem;
3292
3293 /* Pairwise */
3294 n = 0;
3295 if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
3296 pairwise[n++] = "tkip";
3297 if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
3298 pairwise[n++] = "ccmp";
3299 if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP)
3300 pairwise[n++] = "gcmp";
3301
3302 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
3303 pairwise, n))
3304 goto nomem;
3305
3306 /* Management group (RSN only) */
3307 if (ie_data->proto == WPA_PROTO_RSN) {
3308 switch (ie_data->mgmt_group_cipher) {
--- 9 unchanged lines hidden (view full) ---
3318
3319 if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
3320 group))
3321 goto nomem;
3322 }
3323
3324 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
3325 goto nomem;
3326 if (!dbus_message_iter_close_container(iter, &variant_iter))
3327 goto nomem;
3328
3329 return TRUE;
3330
3331nomem:
3332 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3333 return FALSE;
3334}
3335
3336
3337/**
3338 * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
3339 * @iter: Pointer to incoming dbus message iter
3340 * @error: Location to store error on failure
3341 * @user_data: Function specific data
3342 * Returns: TRUE on success, FALSE on failure
3343 *
3344 * Getter for "WPA" property.
3345 */
3346dbus_bool_t wpas_dbus_getter_bss_wpa(DBusMessageIter *iter, DBusError *error,
3347 void *user_data)
3348{
3349 struct bss_handler_args *args = user_data;
3350 struct wpa_bss *res;
3351 struct wpa_ie_data wpa_data;
3352 const u8 *ie;
3353
3354 res = get_bss_helper(args, error, __func__);
3355 if (!res)
3356 return FALSE;
3357
3358 os_memset(&wpa_data, 0, sizeof(wpa_data));
3359 ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
3360 if (ie) {
3361 if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
3362 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3363 "failed to parse WPA IE");
3364 return FALSE;
3365 }
3366 }
3367
3368 return wpas_dbus_get_bss_security_prop(iter, &wpa_data, error);
3369}
3370
3371
3372/**
3373 * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
3374 * @iter: Pointer to incoming dbus message iter
3375 * @error: Location to store error on failure
3376 * @user_data: Function specific data
3377 * Returns: TRUE on success, FALSE on failure
3378 *
3379 * Getter for "RSN" property.
3380 */
3381dbus_bool_t wpas_dbus_getter_bss_rsn(DBusMessageIter *iter, DBusError *error,
3382 void *user_data)
3383{
3384 struct bss_handler_args *args = user_data;
3385 struct wpa_bss *res;
3386 struct wpa_ie_data wpa_data;
3387 const u8 *ie;
3388
3389 res = get_bss_helper(args, error, __func__);
3390 if (!res)
3391 return FALSE;
3392
3393 os_memset(&wpa_data, 0, sizeof(wpa_data));
3394 ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
3395 if (ie) {
3396 if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
3397 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3398 "failed to parse RSN IE");
3399 return FALSE;
3400 }
3401 }
3402
3403 return wpas_dbus_get_bss_security_prop(iter, &wpa_data, error);
3404}
3405
3406
3407/**
3408 * wpas_dbus_getter_bss_wps - Return the WPS options of a BSS
3409 * @iter: Pointer to incoming dbus message iter
3410 * @error: Location to store error on failure
3411 * @user_data: Function specific data
3412 * Returns: TRUE on success, FALSE on failure
3413 *
3414 * Getter for "WPS" property.
3415 */
3416dbus_bool_t wpas_dbus_getter_bss_wps(DBusMessageIter *iter, DBusError *error,
3417 void *user_data)
3418{
3419 struct bss_handler_args *args = user_data;
3420 struct wpa_bss *res;
3421#ifdef CONFIG_WPS
3422 struct wpabuf *wps_ie;
3423#endif /* CONFIG_WPS */
3424 DBusMessageIter iter_dict, variant_iter;
3425 const char *type = "";
3426
3427 res = get_bss_helper(args, error, __func__);
3428 if (!res)
3429 return FALSE;
3430
3431 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
3432 "a{sv}", &variant_iter))
3433 goto nomem;
3434
3435 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
3436 goto nomem;
3437
3438#ifdef CONFIG_WPS
3439 wps_ie = wpa_bss_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
3440 if (wps_ie) {
3441 if (wps_is_selected_pbc_registrar(wps_ie))
3442 type = "pbc";
3443 else if (wps_is_selected_pin_registrar(wps_ie))
3444 type = "pin";
3445 }
3446#endif /* CONFIG_WPS */
3447
3448 if (!wpa_dbus_dict_append_string(&iter_dict, "Type", type))
3449 goto nomem;
3450
3451 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
3452 goto nomem;
3453 if (!dbus_message_iter_close_container(iter, &variant_iter))
3454 goto nomem;
3455
3456 return TRUE;
3457
3458nomem:
3459 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3460 return FALSE;
3461}
3462
3463
3464/**
3465 * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
3466 * @iter: Pointer to incoming dbus message iter
3467 * @error: Location to store error on failure
3468 * @user_data: Function specific data
3469 * Returns: TRUE on success, FALSE on failure
3470 *
3471 * Getter for "IEs" property.
3472 */
3473dbus_bool_t wpas_dbus_getter_bss_ies(DBusMessageIter *iter, DBusError *error,
3474 void *user_data)
3475{
3476 struct bss_handler_args *args = user_data;
3477 struct wpa_bss *res;
3478
3479 res = get_bss_helper(args, error, __func__);
3480 if (!res)
3481 return FALSE;
3482
3483 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3484 res + 1, res->ie_len,
3485 error);
3486}
3487
3488
3489/**
3490 * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
3491 * @iter: Pointer to incoming dbus message iter
3492 * @error: Location to store error on failure
3493 * @user_data: Function specific data
3494 * Returns: TRUE on success, FALSE on failure
3495 *
3496 * Getter for "enabled" property of a configured network.
3497 */
3498dbus_bool_t wpas_dbus_getter_enabled(DBusMessageIter *iter, DBusError *error,
3499 void *user_data)
3500{
3501 struct network_handler_args *net = user_data;
3502 dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
3503
3504 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
3505 &enabled, error);
3506}
3507
3508
3509/**
3510 * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
3511 * @iter: Pointer to incoming dbus message iter
3512 * @error: Location to store error on failure
3513 * @user_data: Function specific data
3514 * Returns: TRUE on success, FALSE on failure
3515 *
3516 * Setter for "Enabled" property of a configured network.
3517 */
3518dbus_bool_t wpas_dbus_setter_enabled(DBusMessageIter *iter, DBusError *error,
3519 void *user_data)
3520{
3521 struct network_handler_args *net = user_data;
3522 struct wpa_supplicant *wpa_s;
3523 struct wpa_ssid *ssid;
3524 dbus_bool_t enable;
3525
3526 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
3527 &enable))
3528 return FALSE;
3529
3530 wpa_s = net->wpa_s;
3531 ssid = net->ssid;
3532
3533 if (enable)
3534 wpa_supplicant_enable_network(wpa_s, ssid);
3535 else
3536 wpa_supplicant_disable_network(wpa_s, ssid);
3537
3538 return TRUE;
3539}
3540
3541
3542/**
3543 * wpas_dbus_getter_network_properties - Get options for a configured network
3544 * @iter: Pointer to incoming dbus message iter
3545 * @error: Location to store error on failure
3546 * @user_data: Function specific data
3547 * Returns: TRUE on success, FALSE on failure
3548 *
3549 * Getter for "Properties" property of a configured network.
3550 */
3551dbus_bool_t wpas_dbus_getter_network_properties(DBusMessageIter *iter,
3552 DBusError *error,
3553 void *user_data)
3554{
3555 struct network_handler_args *net = user_data;
3556 DBusMessageIter variant_iter, dict_iter;
3557 char **iterator;
3558 char **props = wpa_config_get_all(net->ssid, 1);
3559 dbus_bool_t success = FALSE;
3560
3561 if (!props) {
3562 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3563 return FALSE;
3564 }
3565
3566 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
3567 &variant_iter) ||
3568 !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
3569 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3570 goto out;
3571 }
3572
3573 iterator = props;
3574 while (*iterator) {
3575 if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
3576 *(iterator + 1))) {
3577 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3578 "no memory");
3579 goto out;
3580 }
3581 iterator += 2;
3582 }
3583
3584
3585 if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
3586 !dbus_message_iter_close_container(iter, &variant_iter)) {
3587 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3588 goto out;
3589 }
3590
3591 success = TRUE;
3592
3593out:
3594 iterator = props;
3595 while (*iterator) {
3596 os_free(*iterator);
3597 iterator++;
3598 }
3599 os_free(props);
3600 return success;
3601}
3602
3603
3604/**
3605 * wpas_dbus_setter_network_properties - Set options for a configured network
3606 * @iter: Pointer to incoming dbus message iter
3607 * @error: Location to store error on failure
3608 * @user_data: Function specific data
3609 * Returns: TRUE on success, FALSE on failure
3610 *
3611 * Setter for "Properties" property of a configured network.
3612 */
3613dbus_bool_t wpas_dbus_setter_network_properties(DBusMessageIter *iter,
3614 DBusError *error,
3615 void *user_data)
3616{
3617 struct network_handler_args *net = user_data;
3618 struct wpa_ssid *ssid = net->ssid;
3619 DBusMessageIter variant_iter;
3620
3621 dbus_message_iter_recurse(iter, &variant_iter);
3622 return set_network_properties(net->wpa_s, ssid, &variant_iter, error);
3623}
3624
3625
3626#ifdef CONFIG_AP
3627
3628DBusMessage * wpas_dbus_handler_subscribe_preq(
3629 DBusMessage *message, struct wpa_supplicant *wpa_s)
3630{
3631 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
3632 char *name;
3633
3634 if (wpa_s->preq_notify_peer != NULL) {
3635 if (os_strcmp(dbus_message_get_sender(message),
3636 wpa_s->preq_notify_peer) == 0)
3637 return NULL;
3638
3639 return dbus_message_new_error(message,
3640 WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE,
3641 "Another application is already subscribed");
3642 }
3643
3644 name = os_strdup(dbus_message_get_sender(message));
3645 if (!name)
3646 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
3647 "out of memory");
3648
3649 wpa_s->preq_notify_peer = name;
3650
3651 /* Subscribe to clean up if application closes socket */
3652 wpas_dbus_subscribe_noc(priv);
3653
3654 /*
3655 * Double-check it's still alive to make sure that we didn't
3656 * miss the NameOwnerChanged signal, e.g. while strdup'ing.
3657 */
3658 if (!dbus_bus_name_has_owner(priv->con, name, NULL)) {
3659 /*
3660 * Application no longer exists, clean up.
3661 * The return value is irrelevant now.
3662 *
3663 * Need to check if the NameOwnerChanged handling
3664 * already cleaned up because we have processed
3665 * DBus messages while checking if the name still
3666 * has an owner.
3667 */
3668 if (!wpa_s->preq_notify_peer)
3669 return NULL;
3670 os_free(wpa_s->preq_notify_peer);
3671 wpa_s->preq_notify_peer = NULL;
3672 wpas_dbus_unsubscribe_noc(priv);
3673 }
3674
3675 return NULL;
3676}
3677
3678
3679DBusMessage * wpas_dbus_handler_unsubscribe_preq(
3680 DBusMessage *message, struct wpa_supplicant *wpa_s)
3681{
3682 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
3683
3684 if (!wpa_s->preq_notify_peer)
3685 return dbus_message_new_error(message,
3686 WPAS_DBUS_ERROR_NO_SUBSCRIPTION,
3687 "Not subscribed");
3688
3689 if (os_strcmp(wpa_s->preq_notify_peer,
3690 dbus_message_get_sender(message)))
3691 return dbus_message_new_error(message,
3692 WPAS_DBUS_ERROR_SUBSCRIPTION_EPERM,
3693 "Can't unsubscribe others");
3694
3695 os_free(wpa_s->preq_notify_peer);
3696 wpa_s->preq_notify_peer = NULL;
3697 wpas_dbus_unsubscribe_noc(priv);
3698 return NULL;
3699}
3700
3701
3702void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s,
3703 const u8 *addr, const u8 *dst, const u8 *bssid,
3704 const u8 *ie, size_t ie_len, u32 ssi_signal)
3705{
3706 DBusMessage *msg;
3707 DBusMessageIter iter, dict_iter;
3708 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
3709
3710 /* Do nothing if the control interface is not turned on */
3711 if (priv == NULL)
3712 return;
3713
3714 if (wpa_s->preq_notify_peer == NULL)
3715 return;
3716
3717 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
3718 WPAS_DBUS_NEW_IFACE_INTERFACE,
3719 "ProbeRequest");
3720 if (msg == NULL)
3721 return;
3722
3723 dbus_message_set_destination(msg, wpa_s->preq_notify_peer);
3724
3725 dbus_message_iter_init_append(msg, &iter);
3726
3727 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
3728 goto fail;
3729 if (addr && !wpa_dbus_dict_append_byte_array(&dict_iter, "addr",
3730 (const char *) addr,
3731 ETH_ALEN))
3732 goto fail;
3733 if (dst && !wpa_dbus_dict_append_byte_array(&dict_iter, "dst",
3734 (const char *) dst,
3735 ETH_ALEN))
3736 goto fail;
3737 if (bssid && !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
3738 (const char *) bssid,
3739 ETH_ALEN))
3740 goto fail;
3741 if (ie && ie_len && !wpa_dbus_dict_append_byte_array(&dict_iter, "ies",
3742 (const char *) ie,
3743 ie_len))
3744 goto fail;
3745 if (ssi_signal && !wpa_dbus_dict_append_int32(&dict_iter, "signal",
3746 ssi_signal))
3747 goto fail;
3748 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
3749 goto fail;
3750
3751 dbus_connection_send(priv->con, msg, NULL);
3752 goto out;
3753fail:
3754 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
3755out:
3756 dbus_message_unref(msg);
3757}
3758
3759#endif /* CONFIG_AP */
2 * WPA Supplicant / dbus-based control interface
3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4 * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
5 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
6 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
10
11#include "includes.h"
12
13#include "common.h"
14#include "common/ieee802_11_defs.h"
15#include "eap_peer/eap_methods.h"
16#include "eapol_supp/eapol_supp_sm.h"
17#include "rsn_supp/wpa.h"
18#include "../config.h"
19#include "../wpa_supplicant_i.h"
20#include "../driver_i.h"
21#include "../notify.h"
22#include "../bss.h"
23#include "../scan.h"
24#include "../autoscan.h"
25#include "dbus_new_helpers.h"
26#include "dbus_new.h"
27#include "dbus_new_handlers.h"
28#include "dbus_dict_helpers.h"
29#include "dbus_common_i.h"
30
31extern int wpa_debug_level;
32extern int wpa_debug_show_keys;
33extern int wpa_debug_timestamp;
34
35static const char *debug_strings[] = {
36 "excessive", "msgdump", "debug", "info", "warning", "error", NULL
37};
38
39
40/**
41 * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
42 * @message: Pointer to incoming dbus message this error refers to
43 * @arg: Optional string appended to error message
44 * Returns: a dbus error message
45 *
46 * Convenience function to create and return an UnknownError
47 */
48DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
49 const char *arg)
50{
51 /*
52 * This function can be called as a result of a failure
53 * within internal getter calls, which will call this function
54 * with a NULL message parameter. However, dbus_message_new_error
55 * looks very unkindly (i.e, abort()) on a NULL message, so
56 * in this case, we should not call it.
57 */
58 if (message == NULL) {
59 wpa_printf(MSG_INFO, "dbus: wpas_dbus_error_unknown_error "
60 "called with NULL message (arg=%s)",
61 arg ? arg : "N/A");
62 return NULL;
63 }
64
65 return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
66 arg);
67}
68
69
70/**
71 * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
72 * @message: Pointer to incoming dbus message this error refers to
--- 45 unchanged lines hidden (view full) ---
118
119 return reply;
120}
121
122
123static const char *dont_quote[] = {
124 "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
125 "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
126 "bssid", "scan_freq", "freq_list", NULL
127};
128
129static dbus_bool_t should_quote_opt(const char *key)
130{
131 int i = 0;
132 while (dont_quote[i] != NULL) {
133 if (os_strcmp(key, dont_quote[i]) == 0)
134 return FALSE;
--- 18 unchanged lines hidden (view full) ---
153 return wpa_s;
154 }
155 return NULL;
156}
157
158
159/**
160 * set_network_properties - Set properties of a configured network
161 * @wpa_s: wpa_supplicant structure for a network interface
162 * @ssid: wpa_ssid structure for a configured network
163 * @iter: DBus message iterator containing dictionary of network
164 * properties to set.
165 * @error: On failure, an error describing the failure
166 * Returns: TRUE if the request succeeds, FALSE if it failed
167 *
168 * Sets network configuration with parameters given id DBus dictionary
169 */
170dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s,
171 struct wpa_ssid *ssid,
172 DBusMessageIter *iter,
173 DBusError *error)
174{
175 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
176 DBusMessageIter iter_dict;
177 char *value = NULL;
178
179 if (!wpa_dbus_dict_open_read(iter, &iter_dict, error))
180 return FALSE;
181
182 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
183 size_t size = 50;
184 int ret;
185
186 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
187 goto error;
188
189 value = NULL;
190 if (entry.type == DBUS_TYPE_ARRAY &&
191 entry.array_type == DBUS_TYPE_BYTE) {
192 if (entry.array_len <= 0)
193 goto error;
194
195 size = entry.array_len * 2 + 1;
196 value = os_zalloc(size);
197 if (value == NULL)
--- 45 unchanged lines hidden (view full) ---
243 } else
244 goto error;
245
246 if (wpa_config_set(ssid, entry.key, value, 0) < 0)
247 goto error;
248
249 if ((os_strcmp(entry.key, "psk") == 0 &&
250 value[0] == '"' && ssid->ssid_len) ||
251 (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
252 wpa_config_update_psk(ssid);
253 else if (os_strcmp(entry.key, "priority") == 0)
254 wpa_config_update_prio_list(wpa_s->conf);
255
256 os_free(value);
257 wpa_dbus_dict_entry_clear(&entry);
258 }
259
260 return TRUE;
261
262error:
263 os_free(value);
264 wpa_dbus_dict_entry_clear(&entry);
265 dbus_set_error_const(error, DBUS_ERROR_INVALID_ARGS,
266 "invalid message format");
267 return FALSE;
268}
269
270
271/**
272 * wpas_dbus_simple_property_getter - Get basic type property
273 * @iter: Message iter to use when appending arguments
274 * @type: DBus type of property (must be basic type)
275 * @val: pointer to place holding property value
276 * @error: On failure an error describing the failure
277 * Returns: TRUE if the request was successful, FALSE if it failed
278 *
279 * Generic getter for basic type properties. Type is required to be basic.
280 */
281dbus_bool_t wpas_dbus_simple_property_getter(DBusMessageIter *iter,
282 const int type,
283 const void *val,
284 DBusError *error)
285{
286 DBusMessageIter variant_iter;
287
288 if (!dbus_type_is_basic(type)) {
289 dbus_set_error(error, DBUS_ERROR_FAILED,
290 "%s: given type is not basic", __func__);
291 return FALSE;
292 }
293
294 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
295 wpa_dbus_type_as_string(type),
296 &variant_iter))
297 goto error;
298
299 if (!dbus_message_iter_append_basic(&variant_iter, type, val))
300 goto error;
301
302 if (!dbus_message_iter_close_container(iter, &variant_iter))
303 goto error;
304
305 return TRUE;
306
307error:
308 dbus_set_error(error, DBUS_ERROR_FAILED,
309 "%s: error constructing reply", __func__);
310 return FALSE;
311}
312
313
314/**
315 * wpas_dbus_simple_property_setter - Set basic type property
316 * @message: Pointer to incoming dbus message
317 * @type: DBus type of property (must be basic type)
318 * @val: pointer to place where value being set will be stored
319 * Returns: TRUE if the request was successful, FALSE if it failed
320 *
321 * Generic setter for basic type properties. Type is required to be basic.
322 */
323dbus_bool_t wpas_dbus_simple_property_setter(DBusMessageIter *iter,
324 DBusError *error,
325 const int type, void *val)
326{
327 DBusMessageIter variant_iter;
328
329 if (!dbus_type_is_basic(type)) {
330 dbus_set_error(error, DBUS_ERROR_FAILED,
331 "%s: given type is not basic", __func__);
332 return FALSE;
333 }
334
335 /* Look at the new value */
336 dbus_message_iter_recurse(iter, &variant_iter);
337 if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
338 dbus_set_error_const(error, DBUS_ERROR_FAILED,
339 "wrong property type");
340 return FALSE;
341 }
342 dbus_message_iter_get_basic(&variant_iter, val);
343
344 return TRUE;
345}
346
347
348/**
349 * wpas_dbus_simple_array_property_getter - Get array type property
350 * @iter: Pointer to incoming dbus message iterator
351 * @type: DBus type of property array elements (must be basic type)
352 * @array: pointer to array of elements to put into response message
353 * @array_len: length of above array
354 * @error: a pointer to an error to fill on failure
355 * Returns: TRUE if the request succeeded, FALSE if it failed
356 *
357 * Generic getter for array type properties. Array elements type is
358 * required to be basic.
359 */
360dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
361 const int type,
362 const void *array,
363 size_t array_len,
364 DBusError *error)
365{
366 DBusMessageIter variant_iter, array_iter;
367 char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
368 const char *sub_type_str;
369 size_t element_size, i;
370
371 if (!dbus_type_is_basic(type)) {
372 dbus_set_error(error, DBUS_ERROR_FAILED,
373 "%s: given type is not basic", __func__);
374 return FALSE;
375 }
376
377 sub_type_str = wpa_dbus_type_as_string(type);
378 type_str[1] = sub_type_str[0];
379
380 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
381 type_str, &variant_iter)) {
382 dbus_set_error(error, DBUS_ERROR_FAILED,
383 "%s: failed to construct message 1", __func__);
384 return FALSE;
385 }
386
387 if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
388 sub_type_str, &array_iter)) {
389 dbus_set_error(error, DBUS_ERROR_FAILED,
390 "%s: failed to construct message 2", __func__);
391 return FALSE;
392 }
393
394 switch(type) {
395 case DBUS_TYPE_BYTE:
396 case DBUS_TYPE_BOOLEAN:
397 element_size = 1;
398 break;
399 case DBUS_TYPE_INT16:
--- 11 unchanged lines hidden (view full) ---
411 case DBUS_TYPE_DOUBLE:
412 element_size = sizeof(double);
413 break;
414 case DBUS_TYPE_STRING:
415 case DBUS_TYPE_OBJECT_PATH:
416 element_size = sizeof(char *);
417 break;
418 default:
419 dbus_set_error(error, DBUS_ERROR_FAILED,
420 "%s: unknown element type %d", __func__, type);
421 return FALSE;
422 }
423
424 for (i = 0; i < array_len; i++) {
425 dbus_message_iter_append_basic(&array_iter, type,
426 array + i * element_size);
427 }
428
429 if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
430 dbus_set_error(error, DBUS_ERROR_FAILED,
431 "%s: failed to construct message 3", __func__);
432 return FALSE;
433 }
434
435 if (!dbus_message_iter_close_container(iter, &variant_iter)) {
436 dbus_set_error(error, DBUS_ERROR_FAILED,
437 "%s: failed to construct message 4", __func__);
438 return FALSE;
439 }
440
441 return TRUE;
442}
443
444
445/**
446 * wpas_dbus_simple_array_array_property_getter - Get array array type property
447 * @iter: Pointer to incoming dbus message iterator
448 * @type: DBus type of property array elements (must be basic type)
449 * @array: pointer to array of elements to put into response message
450 * @array_len: length of above array
451 * @error: a pointer to an error to fill on failure
452 * Returns: TRUE if the request succeeded, FALSE if it failed
453 *
454 * Generic getter for array type properties. Array elements type is
455 * required to be basic.
456 */
457dbus_bool_t wpas_dbus_simple_array_array_property_getter(DBusMessageIter *iter,
458 const int type,
459 struct wpabuf **array,
460 size_t array_len,
461 DBusError *error)
462{
463 DBusMessageIter variant_iter, array_iter;
464 char type_str[] = "aa?";
465 char inner_type_str[] = "a?";
466 const char *sub_type_str;
467 size_t i;
468
469 if (!dbus_type_is_basic(type)) {
470 dbus_set_error(error, DBUS_ERROR_FAILED,
471 "%s: given type is not basic", __func__);
472 return FALSE;
473 }
474
475 sub_type_str = wpa_dbus_type_as_string(type);
476 type_str[2] = sub_type_str[0];
477 inner_type_str[1] = sub_type_str[0];
478
479 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
480 type_str, &variant_iter)) {
481 dbus_set_error(error, DBUS_ERROR_FAILED,
482 "%s: failed to construct message 1", __func__);
483 return FALSE;
484 }
485 if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
486 inner_type_str, &array_iter)) {
487 dbus_set_error(error, DBUS_ERROR_FAILED,
488 "%s: failed to construct message 2", __func__);
489 return FALSE;
490 }
491
492 for (i = 0; i < array_len; i++) {
493 wpa_dbus_dict_bin_array_add_element(&array_iter,
494 wpabuf_head(array[i]),
495 wpabuf_len(array[i]));
496
497 }
498
499 if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
500 dbus_set_error(error, DBUS_ERROR_FAILED,
501 "%s: failed to close message 2", __func__);
502 return FALSE;
503 }
504
505 if (!dbus_message_iter_close_container(iter, &variant_iter)) {
506 dbus_set_error(error, DBUS_ERROR_FAILED,
507 "%s: failed to close message 1", __func__);
508 return FALSE;
509 }
510
511 return TRUE;
512}
513
514
515/**
516 * wpas_dbus_handler_create_interface - Request registration of a network iface
517 * @message: Pointer to incoming dbus message
518 * @global: %wpa_supplicant global data structure
519 * Returns: The object path of the new interface object,
520 * or a dbus error message with more information
521 *
522 * Handler function for "CreateInterface" method call. Handles requests
523 * by dbus clients to register a network interface that wpa_supplicant
524 * will manage.
525 */
526DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
527 struct wpa_global *global)
528{
529 DBusMessageIter iter_dict;
530 DBusMessage *reply = NULL;
531 DBusMessageIter iter;
532 struct wpa_dbus_dict_entry entry;
533 char *driver = NULL;
534 char *ifname = NULL;
535 char *confname = NULL;
536 char *bridge_ifname = NULL;
537
538 dbus_message_iter_init(message, &iter);
539
540 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
541 goto error;
542 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
543 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
544 goto error;
545 if (!os_strcmp(entry.key, "Driver") &&
546 (entry.type == DBUS_TYPE_STRING)) {
547 driver = os_strdup(entry.str_value);
548 wpa_dbus_dict_entry_clear(&entry);
549 if (driver == NULL)
550 goto error;
551 } else if (!os_strcmp(entry.key, "Ifname") &&
552 (entry.type == DBUS_TYPE_STRING)) {
553 ifname = os_strdup(entry.str_value);
554 wpa_dbus_dict_entry_clear(&entry);
555 if (ifname == NULL)
556 goto error;
557 } else if (!os_strcmp(entry.key, "ConfigFile") &&
558 (entry.type == DBUS_TYPE_STRING)) {
559 confname = os_strdup(entry.str_value);
560 wpa_dbus_dict_entry_clear(&entry);
561 if (confname == NULL)
562 goto error;
563 } else if (!os_strcmp(entry.key, "BridgeIfname") &&
564 (entry.type == DBUS_TYPE_STRING)) {
565 bridge_ifname = os_strdup(entry.str_value);
566 wpa_dbus_dict_entry_clear(&entry);
567 if (bridge_ifname == NULL)
568 goto error;
569 } else {
570 wpa_dbus_dict_entry_clear(&entry);
571 goto error;
572 }
--- 12 unchanged lines hidden (view full) ---
585 "wpa_supplicant already "
586 "controls this interface.");
587 } else {
588 struct wpa_supplicant *wpa_s;
589 struct wpa_interface iface;
590 os_memset(&iface, 0, sizeof(iface));
591 iface.driver = driver;
592 iface.ifname = ifname;
593 iface.confname = confname;
594 iface.bridge_ifname = bridge_ifname;
595 /* Otherwise, have wpa_supplicant attach to it. */
596 if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
597 const char *path = wpa_s->dbus_new_path;
598 reply = dbus_message_new_method_return(message);
599 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
600 &path, DBUS_TYPE_INVALID);
601 } else {
602 reply = wpas_dbus_error_unknown_error(
603 message, "wpa_supplicant couldn't grab this "
604 "interface.");
605 }
606 }
607
608out:
609 os_free(driver);
610 os_free(ifname);
611 os_free(confname);
612 os_free(bridge_ifname);
613 return reply;
614
615error:
616 reply = wpas_dbus_error_invalid_args(message, NULL);
617 goto out;
618}
619
--- 17 unchanged lines hidden (view full) ---
637 DBusMessage *reply = NULL;
638
639 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
640 DBUS_TYPE_INVALID);
641
642 wpa_s = get_iface_by_dbus_path(global, path);
643 if (wpa_s == NULL)
644 reply = wpas_dbus_error_iface_unknown(message);
645 else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) {
646 reply = wpas_dbus_error_unknown_error(
647 message, "wpa_supplicant couldn't remove this "
648 "interface.");
649 }
650
651 return reply;
652}
653
--- 35 unchanged lines hidden (view full) ---
689 }
690
691 return reply;
692}
693
694
695/**
696 * wpas_dbus_getter_debug_level - Get debug level
697 * @iter: Pointer to incoming dbus message iter
698 * @error: Location to store error on failure
699 * @user_data: Function specific data
700 * Returns: TRUE on success, FALSE on failure
701 *
702 * Getter for "DebugLevel" property.
703 */
704dbus_bool_t wpas_dbus_getter_debug_level(DBusMessageIter *iter,
705 DBusError *error,
706 void *user_data)
707{
708 const char *str;
709 int idx = wpa_debug_level;
710
711 if (idx < 0)
712 idx = 0;
713 if (idx > 5)
714 idx = 5;
715 str = debug_strings[idx];
716 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
717 &str, error);
718}
719
720
721/**
722 * wpas_dbus_getter_debug_timestamp - Get debug timestamp
723 * @iter: Pointer to incoming dbus message iter
724 * @error: Location to store error on failure
725 * @user_data: Function specific data
726 * Returns: TRUE on success, FALSE on failure
727 *
728 * Getter for "DebugTimestamp" property.
729 */
730dbus_bool_t wpas_dbus_getter_debug_timestamp(DBusMessageIter *iter,
731 DBusError *error,
732 void *user_data)
733{
734 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
735 &wpa_debug_timestamp, error);
736
737}
738
739
740/**
741 * wpas_dbus_getter_debug_show_keys - Get debug show keys
742 * @iter: Pointer to incoming dbus message iter
743 * @error: Location to store error on failure
744 * @user_data: Function specific data
745 * Returns: TRUE on success, FALSE on failure
746 *
747 * Getter for "DebugShowKeys" property.
748 */
749dbus_bool_t wpas_dbus_getter_debug_show_keys(DBusMessageIter *iter,
750 DBusError *error,
751 void *user_data)
752{
753 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
754 &wpa_debug_show_keys, error);
755
756}
757
758/**
759 * wpas_dbus_setter_debug_level - Set debug level
760 * @iter: Pointer to incoming dbus message iter
761 * @error: Location to store error on failure
762 * @user_data: Function specific data
763 * Returns: TRUE on success, FALSE on failure
764 *
765 * Setter for "DebugLevel" property.
766 */
767dbus_bool_t wpas_dbus_setter_debug_level(DBusMessageIter *iter,
768 DBusError *error, void *user_data)
769{
770 struct wpa_global *global = user_data;
771 const char *str = NULL;
772 int i, val = -1;
773
774 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
775 &str))
776 return FALSE;
777
778 for (i = 0; debug_strings[i]; i++)
779 if (os_strcmp(debug_strings[i], str) == 0) {
780 val = i;
781 break;
782 }
783
784 if (val < 0 ||
785 wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
786 wpa_debug_show_keys)) {
787 dbus_set_error_const(error, DBUS_ERROR_FAILED, "wrong debug "
788 "level value");
789 return FALSE;
790 }
791
792 return TRUE;
793}
794
795
796/**
797 * wpas_dbus_setter_debug_timestamp - Set debug timestamp
798 * @iter: Pointer to incoming dbus message iter
799 * @error: Location to store error on failure
800 * @user_data: Function specific data
801 * Returns: TRUE on success, FALSE on failure
802 *
803 * Setter for "DebugTimestamp" property.
804 */
805dbus_bool_t wpas_dbus_setter_debug_timestamp(DBusMessageIter *iter,
806 DBusError *error,
807 void *user_data)
808{
809 struct wpa_global *global = user_data;
810 dbus_bool_t val;
811
812 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
813 &val))
814 return FALSE;
815
816 wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
817 wpa_debug_show_keys);
818 return TRUE;
819}
820
821
822/**
823 * wpas_dbus_setter_debug_show_keys - Set debug show keys
824 * @iter: Pointer to incoming dbus message iter
825 * @error: Location to store error on failure
826 * @user_data: Function specific data
827 * Returns: TRUE on success, FALSE on failure
828 *
829 * Setter for "DebugShowKeys" property.
830 */
831dbus_bool_t wpas_dbus_setter_debug_show_keys(DBusMessageIter *iter,
832 DBusError *error,
833 void *user_data)
834{
835 struct wpa_global *global = user_data;
836 dbus_bool_t val;
837
838 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
839 &val))
840 return FALSE;
841
842 wpa_supplicant_set_debug_params(global, wpa_debug_level,
843 wpa_debug_timestamp,
844 val ? 1 : 0);
845 return TRUE;
846}
847
848
849/**
850 * wpas_dbus_getter_interfaces - Request registered interfaces list
851 * @iter: Pointer to incoming dbus message iter
852 * @error: Location to store error on failure
853 * @user_data: Function specific data
854 * Returns: TRUE on success, FALSE on failure
855 *
856 * Getter for "Interfaces" property. Handles requests
857 * by dbus clients to return list of registered interfaces objects
858 * paths
859 */
860dbus_bool_t wpas_dbus_getter_interfaces(DBusMessageIter *iter,
861 DBusError *error,
862 void *user_data)
863{
864 struct wpa_global *global = user_data;
865 struct wpa_supplicant *wpa_s;
866 const char **paths;
867 unsigned int i = 0, num = 0;
868 dbus_bool_t success;
869
870 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
871 num++;
872
873 paths = os_calloc(num, sizeof(char *));
874 if (!paths) {
875 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
876 return FALSE;
877 }
878
879 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
880 paths[i++] = wpa_s->dbus_new_path;
881
882 success = wpas_dbus_simple_array_property_getter(iter,
883 DBUS_TYPE_OBJECT_PATH,
884 paths, num, error);
885
886 os_free(paths);
887 return success;
888}
889
890
891/**
892 * wpas_dbus_getter_eap_methods - Request supported EAP methods list
893 * @iter: Pointer to incoming dbus message iter
894 * @error: Location to store error on failure
895 * @user_data: Function specific data
896 * Returns: TRUE on success, FALSE on failure
897 *
898 * Getter for "EapMethods" property. Handles requests
899 * by dbus clients to return list of strings with supported EAP methods
900 */
901dbus_bool_t wpas_dbus_getter_eap_methods(DBusMessageIter *iter,
902 DBusError *error, void *user_data)
903{
904 char **eap_methods;
905 size_t num_items = 0;
906 dbus_bool_t success;
907
908 eap_methods = eap_get_names_as_string_array(&num_items);
909 if (!eap_methods) {
910 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
911 return FALSE;
912 }
913
914 success = wpas_dbus_simple_array_property_getter(iter,
915 DBUS_TYPE_STRING,
916 eap_methods,
917 num_items, error);
918
919 while (num_items)
920 os_free(eap_methods[--num_items]);
921 os_free(eap_methods);
922 return success;
923}
924
925
926/**
927 * wpas_dbus_getter_global_capabilities - Request supported global capabilities
928 * @iter: Pointer to incoming dbus message iter
929 * @error: Location to store error on failure
930 * @user_data: Function specific data
931 * Returns: TRUE on success, FALSE on failure
932 *
933 * Getter for "Capabilities" property. Handles requests by dbus clients to
934 * return a list of strings with supported capabilities like AP, RSN IBSS,
935 * and P2P that are determined at compile time.
936 */
937dbus_bool_t wpas_dbus_getter_global_capabilities(DBusMessageIter *iter,
938 DBusError *error,
939 void *user_data)
940{
941 const char *capabilities[5] = { NULL, NULL, NULL, NULL, NULL };
942 size_t num_items = 0;
943
944#ifdef CONFIG_AP
945 capabilities[num_items++] = "ap";
946#endif /* CONFIG_AP */
947#ifdef CONFIG_IBSS_RSN
948 capabilities[num_items++] = "ibss-rsn";
949#endif /* CONFIG_IBSS_RSN */
950#ifdef CONFIG_P2P
951 capabilities[num_items++] = "p2p";
952#endif /* CONFIG_P2P */
953#ifdef CONFIG_INTERWORKING
954 capabilities[num_items++] = "interworking";
955#endif /* CONFIG_INTERWORKING */
956
957 return wpas_dbus_simple_array_property_getter(iter,
958 DBUS_TYPE_STRING,
959 capabilities,
960 num_items, error);
961}
962
963
964static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
965 char **type, DBusMessage **reply)
966{
967 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
968 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
969 "Type must be a string");
970 *reply = wpas_dbus_error_invalid_args(
971 message, "Wrong Type value type. String required");
--- 47 unchanged lines hidden (view full) ---
1019 message, "Too many ssids specified. Specify "
1020 "at most four");
1021 return -1;
1022 }
1023
1024 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1025
1026 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1027
1028 if (len > MAX_SSID_LEN) {
1029 wpa_printf(MSG_DEBUG,
1030 "wpas_dbus_handler_scan[dbus]: "
1031 "SSID too long (len=%d max_len=%d)",
1032 len, MAX_SSID_LEN);
1033 *reply = wpas_dbus_error_invalid_args(
1034 message, "Invalid SSID: too long");
1035 return -1;
1036 }
1037
1038 if (len != 0) {
1039 ssid = os_malloc(len);
1040 if (ssid == NULL) {
1041 wpa_printf(MSG_DEBUG,
1042 "wpas_dbus_handler_scan[dbus]: "
1043 "out of memory. Cannot allocate "
1044 "memory for SSID");
1045 *reply = dbus_message_new_error(
1046 message, DBUS_ERROR_NO_MEMORY, NULL);
1047 return -1;
1048 }
1049 os_memcpy(ssid, val, len);
1050 } else {
1051 /* Allow zero-length SSIDs */
1052 ssid = NULL;
1053 }
1054
1055 ssids[ssids_num].ssid = ssid;
1056 ssids[ssids_num].ssid_len = len;
1057
1058 dbus_message_iter_next(&array_iter);
1059 ssids_num++;
1060 }
1061
1062 params->num_ssids = ssids_num;
--- 128 unchanged lines hidden (view full) ---
1191 os_free(freqs);
1192 return -1;
1193 }
1194
1195 dbus_message_iter_get_basic(&sub_array_iter, &width);
1196
1197#define FREQS_ALLOC_CHUNK 32
1198 if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
1199 nfreqs = os_realloc_array(
1200 freqs, freqs_num + FREQS_ALLOC_CHUNK,
1201 sizeof(int));
1202 if (nfreqs == NULL)
1203 os_free(freqs);
1204 freqs = nfreqs;
1205 }
1206 if (freqs == NULL) {
1207 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1208 "out of memory. can't allocate memory for "
1209 "freqs");
1210 *reply = dbus_message_new_error(
1211 message, DBUS_ERROR_NO_MEMORY, NULL);
1212 return -1;
1213 }
1214
1215 freqs[freqs_num] = freq;
1216
1217 freqs_num++;
1218 dbus_message_iter_next(&array_iter);
1219 }
1220
1221 nfreqs = os_realloc_array(freqs, freqs_num + 1, sizeof(int));
1222 if (nfreqs == NULL)
1223 os_free(freqs);
1224 freqs = nfreqs;
1225 if (freqs == NULL) {
1226 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1227 "out of memory. Can't allocate memory for freqs");
1228 *reply = dbus_message_new_error(
1229 message, DBUS_ERROR_NO_MEMORY, NULL);
--- 75 unchanged lines hidden (view full) ---
1305 if (params.num_ssids || params.extra_ies_len) {
1306 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1307 "SSIDs or IEs specified for passive scan.");
1308 reply = wpas_dbus_error_invalid_args(
1309 message, "You can specify only Channels in "
1310 "passive scan");
1311 goto out;
1312 } else if (params.freqs && params.freqs[0]) {
1313 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1314 } else {
1315 wpa_s->scan_req = MANUAL_SCAN_REQ;
1316 wpa_supplicant_req_scan(wpa_s, 0, 0);
1317 }
1318 } else if (!os_strcmp(type, "active")) {
1319 if (!params.num_ssids) {
1320 /* Add wildcard ssid */
1321 params.num_ssids++;
1322 }
1323#ifdef CONFIG_AUTOSCAN
1324 autoscan_deinit(wpa_s);
1325#endif /* CONFIG_AUTOSCAN */
1326 wpa_supplicant_trigger_scan(wpa_s, ¶ms);
1327 } else {
1328 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
1329 "Unknown scan type: %s", type);
1330 reply = wpas_dbus_error_invalid_args(message,
1331 "Wrong scan type");
1332 goto out;
1333 }
--- 42 unchanged lines hidden (view full) ---
1376 */
1377DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
1378 struct wpa_supplicant *wpa_s)
1379{
1380 DBusMessage *reply = NULL;
1381 DBusMessageIter iter;
1382 struct wpa_ssid *ssid = NULL;
1383 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
1384 DBusError error;
1385
1386 dbus_message_iter_init(message, &iter);
1387
1388 ssid = wpa_config_add_network(wpa_s->conf);
1389 if (ssid == NULL) {
1390 wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
1391 "can't add new interface.");
1392 reply = wpas_dbus_error_unknown_error(
1393 message,
1394 "wpa_supplicant could not add "
1395 "a network on this interface.");
1396 goto err;
1397 }
1398 wpas_notify_network_added(wpa_s, ssid);
1399 ssid->disabled = 1;
1400 wpa_config_set_network_defaults(ssid);
1401
1402 dbus_error_init(&error);
1403 if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
1404 wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
1405 "control interface couldn't set network "
1406 "properties");
1407 reply = wpas_dbus_reply_new_from_error(message, &error,
1408 DBUS_ERROR_INVALID_ARGS,
1409 "Failed to add network");
1410 dbus_error_free(&error);
1411 goto err;
1412 }
1413
1414 /* Construct the object path for this network. */
1415 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1416 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
1417 wpa_s->dbus_new_path, ssid->id);
1418
--- 18 unchanged lines hidden (view full) ---
1437 wpas_notify_network_removed(wpa_s, ssid);
1438 wpa_config_remove_network(wpa_s->conf, ssid->id);
1439 }
1440 return reply;
1441}
1442
1443
1444/**
1445 * wpas_dbus_handler_reassociate - Reassociate to current AP
1446 * @message: Pointer to incoming dbus message
1447 * @wpa_s: wpa_supplicant structure for a network interface
1448 * Returns: NotConnected DBus error message if not connected
1449 * or NULL otherwise.
1450 *
1451 * Handler function for "Reassociate" method call of network interface.
1452 */
1453DBusMessage * wpas_dbus_handler_reassociate(DBusMessage *message,
1454 struct wpa_supplicant *wpa_s)
1455{
1456 if (wpa_s->current_ssid != NULL) {
1457 wpas_request_connection(wpa_s);
1458 return NULL;
1459 }
1460
1461 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
1462 "This interface is not connected");
1463}
1464
1465
1466/**
1467 * wpas_dbus_handler_remove_network - Remove a configured network
1468 * @message: Pointer to incoming dbus message
1469 * @wpa_s: wpa_supplicant structure for a network interface
1470 * Returns: NULL on success or dbus error on failure
1471 *
1472 * Handler function for "RemoveNetwork" method call of a network interface.
1473 */
1474DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
--- 5 unchanged lines hidden (view full) ---
1480 int id;
1481 struct wpa_ssid *ssid;
1482
1483 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1484 DBUS_TYPE_INVALID);
1485
1486 /* Extract the network ID and ensure the network */
1487 /* is actually a child of this interface */
1488 iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
1489 if (iface == NULL || net_id == NULL ||
1490 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1491 reply = wpas_dbus_error_invalid_args(message, op);
1492 goto out;
1493 }
1494
1495 errno = 0;
1496 id = strtoul(net_id, NULL, 10);
1497 if (errno != 0) {
1498 reply = wpas_dbus_error_invalid_args(message, op);
1499 goto out;
1500 }
1501
1502 ssid = wpa_config_get_network(wpa_s->conf, id);
1503 if (ssid == NULL) {
1504 reply = wpas_dbus_error_network_unknown(message);
1505 goto out;
--- 17 unchanged lines hidden (view full) ---
1523
1524out:
1525 os_free(iface);
1526 os_free(net_id);
1527 return reply;
1528}
1529
1530
1531static void remove_network(void *arg, struct wpa_ssid *ssid)
1532{
1533 struct wpa_supplicant *wpa_s = arg;
1534
1535 wpas_notify_network_removed(wpa_s, ssid);
1536
1537 if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) {
1538 wpa_printf(MSG_ERROR,
1539 "wpas_dbus_handler_remove_all_networks[dbus]: "
1540 "error occurred when removing network %d",
1541 ssid->id);
1542 return;
1543 }
1544
1545 if (ssid == wpa_s->current_ssid)
1546 wpa_supplicant_deauthenticate(wpa_s,
1547 WLAN_REASON_DEAUTH_LEAVING);
1548}
1549
1550
1551/**
1552 * wpas_dbus_handler_remove_all_networks - Remove all configured networks
1553 * @message: Pointer to incoming dbus message
1554 * @wpa_s: wpa_supplicant structure for a network interface
1555 * Returns: NULL on success or dbus error on failure
1556 *
1557 * Handler function for "RemoveAllNetworks" method call of a network interface.
1558 */
1559DBusMessage * wpas_dbus_handler_remove_all_networks(
1560 DBusMessage *message, struct wpa_supplicant *wpa_s)
1561{
1562 /* NB: could check for failure and return an error */
1563 wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s);
1564 return NULL;
1565}
1566
1567
1568/**
1569 * wpas_dbus_handler_select_network - Attempt association with a network
1570 * @message: Pointer to incoming dbus message
1571 * @wpa_s: wpa_supplicant structure for a network interface
1572 * Returns: NULL on success or dbus error on failure
1573 *
1574 * Handler function for "SelectNetwork" method call of network interface.
1575 */
1576DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
--- 5 unchanged lines hidden (view full) ---
1582 int id;
1583 struct wpa_ssid *ssid;
1584
1585 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1586 DBUS_TYPE_INVALID);
1587
1588 /* Extract the network ID and ensure the network */
1589 /* is actually a child of this interface */
1590 iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
1591 if (iface == NULL || net_id == NULL ||
1592 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1593 reply = wpas_dbus_error_invalid_args(message, op);
1594 goto out;
1595 }
1596
1597 errno = 0;
1598 id = strtoul(net_id, NULL, 10);
1599 if (errno != 0) {
1600 reply = wpas_dbus_error_invalid_args(message, op);
1601 goto out;
1602 }
1603
1604 ssid = wpa_config_get_network(wpa_s->conf, id);
1605 if (ssid == NULL) {
1606 reply = wpas_dbus_error_network_unknown(message);
1607 goto out;
--- 5 unchanged lines hidden (view full) ---
1613out:
1614 os_free(iface);
1615 os_free(net_id);
1616 return reply;
1617}
1618
1619
1620/**
1621 * wpas_dbus_handler_network_reply - Reply to a NetworkRequest signal
1622 * @message: Pointer to incoming dbus message
1623 * @wpa_s: wpa_supplicant structure for a network interface
1624 * Returns: NULL on success or dbus error on failure
1625 *
1626 * Handler function for "NetworkReply" method call of network interface.
1627 */
1628DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message,
1629 struct wpa_supplicant *wpa_s)
1630{
1631#ifdef IEEE8021X_EAPOL
1632 DBusMessage *reply = NULL;
1633 const char *op, *field, *value;
1634 char *iface = NULL, *net_id = NULL;
1635 int id;
1636 struct wpa_ssid *ssid;
1637
1638 if (!dbus_message_get_args(message, NULL,
1639 DBUS_TYPE_OBJECT_PATH, &op,
1640 DBUS_TYPE_STRING, &field,
1641 DBUS_TYPE_STRING, &value,
1642 DBUS_TYPE_INVALID))
1643 return wpas_dbus_error_invalid_args(message, NULL);
1644
1645 /* Extract the network ID and ensure the network */
1646 /* is actually a child of this interface */
1647 iface = wpas_dbus_new_decompose_object_path(op, 0, &net_id, NULL);
1648 if (iface == NULL || net_id == NULL ||
1649 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1650 reply = wpas_dbus_error_invalid_args(message, op);
1651 goto out;
1652 }
1653
1654 errno = 0;
1655 id = strtoul(net_id, NULL, 10);
1656 if (errno != 0) {
1657 reply = wpas_dbus_error_invalid_args(message, net_id);
1658 goto out;
1659 }
1660
1661 ssid = wpa_config_get_network(wpa_s->conf, id);
1662 if (ssid == NULL) {
1663 reply = wpas_dbus_error_network_unknown(message);
1664 goto out;
1665 }
1666
1667 if (wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid,
1668 field, value) < 0)
1669 reply = wpas_dbus_error_invalid_args(message, field);
1670 else {
1671 /* Tell EAP to retry immediately */
1672 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1673 }
1674
1675out:
1676 os_free(iface);
1677 os_free(net_id);
1678 return reply;
1679#else /* IEEE8021X_EAPOL */
1680 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1681 return wpas_dbus_error_unknown_error(message, "802.1X not included");
1682#endif /* IEEE8021X_EAPOL */
1683}
1684
1685
1686/**
1687 * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
1688 * @message: Pointer to incoming dbus message
1689 * @wpa_s: %wpa_supplicant data structure
1690 * Returns: A dbus message containing an error on failure or NULL on success
1691 *
1692 * Asks wpa_supplicant to internally store a binary blobs.
1693 */
1694DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
--- 147 unchanged lines hidden (view full) ---
1842 "Blob id not set");
1843 }
1844 wpas_notify_blob_removed(wpa_s, blob_name);
1845
1846 return reply;
1847
1848}
1849
1850/*
1851 * wpas_dbus_handler_flush_bss - Flush the BSS cache
1852 * @message: Pointer to incoming dbus message
1853 * @wpa_s: wpa_supplicant structure for a network interface
1854 * Returns: NULL
1855 *
1856 * Handler function for "FlushBSS" method call of network interface.
1857 */
1858DBusMessage * wpas_dbus_handler_flush_bss(DBusMessage *message,
1859 struct wpa_supplicant *wpa_s)
1860{
1861 dbus_uint32_t age;
1862
1863 dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &age,
1864 DBUS_TYPE_INVALID);
1865
1866 if (age == 0)
1867 wpa_bss_flush(wpa_s);
1868 else
1869 wpa_bss_flush_by_age(wpa_s, age);
1870
1871 return NULL;
1872}
1873
1874
1875#ifdef CONFIG_AUTOSCAN
1876/**
1877 * wpas_dbus_handler_autoscan - Set autoscan parameters for the interface
1878 * @message: Pointer to incoming dbus message
1879 * @wpa_s: wpa_supplicant structure for a network interface
1880 * Returns: NULL
1881 *
1882 * Handler function for "AutoScan" method call of network interface.
1883 */
1884DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message,
1885 struct wpa_supplicant *wpa_s)
1886{
1887 DBusMessage *reply = NULL;
1888 enum wpa_states state = wpa_s->wpa_state;
1889 char *arg;
1890
1891 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg,
1892 DBUS_TYPE_INVALID);
1893
1894 if (arg != NULL && os_strlen(arg) > 0) {
1895 char *tmp;
1896 tmp = os_strdup(arg);
1897 if (tmp == NULL) {
1898 reply = dbus_message_new_error(message,
1899 DBUS_ERROR_NO_MEMORY,
1900 NULL);
1901 } else {
1902 os_free(wpa_s->conf->autoscan);
1903 wpa_s->conf->autoscan = tmp;
1904 if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
1905 autoscan_init(wpa_s, 1);
1906 else if (state == WPA_SCANNING)
1907 wpa_supplicant_reinit_autoscan(wpa_s);
1908 }
1909 } else if (arg != NULL && os_strlen(arg) == 0) {
1910 os_free(wpa_s->conf->autoscan);
1911 wpa_s->conf->autoscan = NULL;
1912 autoscan_deinit(wpa_s);
1913 } else
1914 reply = dbus_message_new_error(message,
1915 DBUS_ERROR_INVALID_ARGS,
1916 NULL);
1917
1918 return reply;
1919}
1920#endif /* CONFIG_AUTOSCAN */
1921
1922
1923/**
1924 * wpas_dbus_getter_capabilities - Return interface capabilities
1925 * @iter: Pointer to incoming dbus message iter
1926 * @error: Location to store error on failure
1927 * @user_data: Function specific data
1928 * Returns: TRUE on success, FALSE on failure
1929 *
1930 * Getter for "Capabilities" property of an interface.
1931 */
1932dbus_bool_t wpas_dbus_getter_capabilities(DBusMessageIter *iter,
1933 DBusError *error, void *user_data)
1934{
1935 struct wpa_supplicant *wpa_s = user_data;
1936 struct wpa_driver_capa capa;
1937 int res;
1938 DBusMessageIter iter_dict, iter_dict_entry, iter_dict_val, iter_array,
1939 variant_iter;
1940 const char *scans[] = { "active", "passive", "ssid" };
1941
1942 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
1943 "a{sv}", &variant_iter))
1944 goto nomem;
1945
1946 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
1947 goto nomem;
1948
1949 res = wpa_drv_get_capa(wpa_s, &capa);
1950
--- 12 unchanged lines hidden (view full) ---
1963 goto nomem;
1964
1965 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1966 if (!wpa_dbus_dict_string_array_add_element(
1967 &iter_array, "ccmp"))
1968 goto nomem;
1969 }
1970
1971 if (capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) {
1972 if (!wpa_dbus_dict_string_array_add_element(
1973 &iter_array, "gcmp"))
1974 goto nomem;
1975 }
1976
1977 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1978 if (!wpa_dbus_dict_string_array_add_element(
1979 &iter_array, "tkip"))
1980 goto nomem;
1981 }
1982
1983 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1984 if (!wpa_dbus_dict_string_array_add_element(
--- 25 unchanged lines hidden (view full) ---
2010 goto nomem;
2011
2012 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2013 if (!wpa_dbus_dict_string_array_add_element(
2014 &iter_array, "ccmp"))
2015 goto nomem;
2016 }
2017
2018 if (capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2019 if (!wpa_dbus_dict_string_array_add_element(
2020 &iter_array, "gcmp"))
2021 goto nomem;
2022 }
2023
2024 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2025 if (!wpa_dbus_dict_string_array_add_element(
2026 &iter_array, "tkip"))
2027 goto nomem;
2028 }
2029
2030 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
2031 if (!wpa_dbus_dict_string_array_add_element(
--- 175 unchanged lines hidden (view full) ---
2207 }
2208
2209 /***** Scan */
2210 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
2211 sizeof(scans) / sizeof(char *)))
2212 goto nomem;
2213
2214 /***** Modes */
2215 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Modes",
2216 &iter_dict_entry,
2217 &iter_dict_val,
2218 &iter_array))
2219 goto nomem;
2220
2221 if (!wpa_dbus_dict_string_array_add_element(
2222 &iter_array, "infrastructure"))
2223 goto nomem;
2224
2225 if (!wpa_dbus_dict_string_array_add_element(
2226 &iter_array, "ad-hoc"))
2227 goto nomem;
2228
2229 if (res >= 0) {
2230 if (capa.flags & (WPA_DRIVER_FLAGS_AP)) {
2231 if (!wpa_dbus_dict_string_array_add_element(
2232 &iter_array, "ap"))
2233 goto nomem;
2234 }
2235
2236 if (capa.flags & (WPA_DRIVER_FLAGS_P2P_CAPABLE)) {
2237 if (!wpa_dbus_dict_string_array_add_element(
2238 &iter_array, "p2p"))
2239 goto nomem;
2240 }
2241 }
2242
2243 if (!wpa_dbus_dict_end_string_array(&iter_dict,
2244 &iter_dict_entry,
2245 &iter_dict_val,
2246 &iter_array))
2247 goto nomem;
2248 /***** Modes end */
2249
2250 if (res >= 0) {
2251 dbus_int32_t max_scan_ssid = capa.max_scan_ssids;
2252
2253 if (!wpa_dbus_dict_append_int32(&iter_dict, "MaxScanSSID",
2254 max_scan_ssid))
2255 goto nomem;
2256 }
2257
2258 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
2259 goto nomem;
2260 if (!dbus_message_iter_close_container(iter, &variant_iter))
2261 goto nomem;
2262
2263 return TRUE;
2264
2265nomem:
2266 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2267 return FALSE;
2268}
2269
2270
2271/**
2272 * wpas_dbus_getter_state - Get interface state
2273 * @iter: Pointer to incoming dbus message iter
2274 * @error: Location to store error on failure
2275 * @user_data: Function specific data
2276 * Returns: TRUE on success, FALSE on failure
2277 *
2278 * Getter for "State" property.
2279 */
2280dbus_bool_t wpas_dbus_getter_state(DBusMessageIter *iter, DBusError *error,
2281 void *user_data)
2282{
2283 struct wpa_supplicant *wpa_s = user_data;
2284 const char *str_state;
2285 char *state_ls, *tmp;
2286 dbus_bool_t success = FALSE;
2287
2288 str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
2289
2290 /* make state string lowercase to fit new DBus API convention
2291 */
2292 state_ls = tmp = os_strdup(str_state);
2293 if (!tmp) {
2294 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2295 return FALSE;
2296 }
2297 while (*tmp) {
2298 *tmp = tolower(*tmp);
2299 tmp++;
2300 }
2301
2302 success = wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2303 &state_ls, error);
2304
2305 os_free(state_ls);
2306
2307 return success;
2308}
2309
2310
2311/**
2312 * wpas_dbus_new_iface_get_scanning - Get interface scanning state
2313 * @iter: Pointer to incoming dbus message iter
2314 * @error: Location to store error on failure
2315 * @user_data: Function specific data
2316 * Returns: TRUE on success, FALSE on failure
2317 *
2318 * Getter for "scanning" property.
2319 */
2320dbus_bool_t wpas_dbus_getter_scanning(DBusMessageIter *iter, DBusError *error,
2321 void *user_data)
2322{
2323 struct wpa_supplicant *wpa_s = user_data;
2324 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
2325
2326 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
2327 &scanning, error);
2328}
2329
2330
2331/**
2332 * wpas_dbus_getter_ap_scan - Control roaming mode
2333 * @iter: Pointer to incoming dbus message iter
2334 * @error: Location to store error on failure
2335 * @user_data: Function specific data
2336 * Returns: TRUE on success, FALSE on failure
2337 *
2338 * Getter function for "ApScan" property.
2339 */
2340dbus_bool_t wpas_dbus_getter_ap_scan(DBusMessageIter *iter, DBusError *error,
2341 void *user_data)
2342{
2343 struct wpa_supplicant *wpa_s = user_data;
2344 dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
2345
2346 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2347 &ap_scan, error);
2348}
2349
2350
2351/**
2352 * wpas_dbus_setter_ap_scan - Control roaming mode
2353 * @iter: Pointer to incoming dbus message iter
2354 * @error: Location to store error on failure
2355 * @user_data: Function specific data
2356 * Returns: TRUE on success, FALSE on failure
2357 *
2358 * Setter function for "ApScan" property.
2359 */
2360dbus_bool_t wpas_dbus_setter_ap_scan(DBusMessageIter *iter, DBusError *error,
2361 void *user_data)
2362{
2363 struct wpa_supplicant *wpa_s = user_data;
2364 dbus_uint32_t ap_scan;
2365
2366 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2367 &ap_scan))
2368 return FALSE;
2369
2370 if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
2371 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2372 "ap_scan must be 0, 1, or 2");
2373 return FALSE;
2374 }
2375 return TRUE;
2376}
2377
2378
2379/**
2380 * wpas_dbus_getter_fast_reauth - Control fast
2381 * reauthentication (TLS session resumption)
2382 * @iter: Pointer to incoming dbus message iter
2383 * @error: Location to store error on failure
2384 * @user_data: Function specific data
2385 * Returns: TRUE on success, FALSE on failure
2386 *
2387 * Getter function for "FastReauth" property.
2388 */
2389dbus_bool_t wpas_dbus_getter_fast_reauth(DBusMessageIter *iter,
2390 DBusError *error,
2391 void *user_data)
2392{
2393 struct wpa_supplicant *wpa_s = user_data;
2394 dbus_bool_t fast_reauth = wpa_s->conf->fast_reauth ? TRUE : FALSE;
2395
2396 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
2397 &fast_reauth, error);
2398}
2399
2400
2401/**
2402 * wpas_dbus_setter_fast_reauth - Control fast
2403 * reauthentication (TLS session resumption)
2404 * @iter: Pointer to incoming dbus message iter
2405 * @error: Location to store error on failure
2406 * @user_data: Function specific data
2407 * Returns: TRUE on success, FALSE on failure
2408 *
2409 * Setter function for "FastReauth" property.
2410 */
2411dbus_bool_t wpas_dbus_setter_fast_reauth(DBusMessageIter *iter,
2412 DBusError *error,
2413 void *user_data)
2414{
2415 struct wpa_supplicant *wpa_s = user_data;
2416 dbus_bool_t fast_reauth;
2417
2418 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
2419 &fast_reauth))
2420 return FALSE;
2421
2422 wpa_s->conf->fast_reauth = fast_reauth;
2423 return TRUE;
2424}
2425
2426
2427/**
2428 * wpas_dbus_getter_disconnect_reason - Get most recent reason for disconnect
2429 * @iter: Pointer to incoming dbus message iter
2430 * @error: Location to store error on failure
2431 * @user_data: Function specific data
2432 * Returns: TRUE on success, FALSE on failure
2433 *
2434 * Getter for "DisconnectReason" property. The reason is negative if it is
2435 * locally generated.
2436 */
2437dbus_bool_t wpas_dbus_getter_disconnect_reason(DBusMessageIter *iter,
2438 DBusError *error,
2439 void *user_data)
2440{
2441 struct wpa_supplicant *wpa_s = user_data;
2442 dbus_int32_t reason = wpa_s->disconnect_reason;
2443 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
2444 &reason, error);
2445}
2446
2447
2448/**
2449 * wpas_dbus_getter_bss_expire_age - Get BSS entry expiration age
2450 * @iter: Pointer to incoming dbus message iter
2451 * @error: Location to store error on failure
2452 * @user_data: Function specific data
2453 * Returns: TRUE on success, FALSE on failure
2454 *
2455 * Getter function for "BSSExpireAge" property.
2456 */
2457dbus_bool_t wpas_dbus_getter_bss_expire_age(DBusMessageIter *iter,
2458 DBusError *error,
2459 void *user_data)
2460{
2461 struct wpa_supplicant *wpa_s = user_data;
2462 dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age;
2463
2464 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2465 &expire_age, error);
2466}
2467
2468
2469/**
2470 * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age
2471 * @iter: Pointer to incoming dbus message iter
2472 * @error: Location to store error on failure
2473 * @user_data: Function specific data
2474 * Returns: TRUE on success, FALSE on failure
2475 *
2476 * Setter function for "BSSExpireAge" property.
2477 */
2478dbus_bool_t wpas_dbus_setter_bss_expire_age(DBusMessageIter *iter,
2479 DBusError *error,
2480 void *user_data)
2481{
2482 struct wpa_supplicant *wpa_s = user_data;
2483 dbus_uint32_t expire_age;
2484
2485 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2486 &expire_age))
2487 return FALSE;
2488
2489 if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) {
2490 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2491 "BSSExpireAge must be >= 10");
2492 return FALSE;
2493 }
2494 return TRUE;
2495}
2496
2497
2498/**
2499 * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count
2500 * @iter: Pointer to incoming dbus message iter
2501 * @error: Location to store error on failure
2502 * @user_data: Function specific data
2503 * Returns: TRUE on success, FALSE on failure
2504 *
2505 * Getter function for "BSSExpireCount" property.
2506 */
2507dbus_bool_t wpas_dbus_getter_bss_expire_count(DBusMessageIter *iter,
2508 DBusError *error,
2509 void *user_data)
2510{
2511 struct wpa_supplicant *wpa_s = user_data;
2512 dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_scan_count;
2513
2514 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2515 &expire_count, error);
2516}
2517
2518
2519/**
2520 * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count
2521 * @iter: Pointer to incoming dbus message iter
2522 * @error: Location to store error on failure
2523 * @user_data: Function specific data
2524 * Returns: TRUE on success, FALSE on failure
2525 *
2526 * Setter function for "BSSExpireCount" property.
2527 */
2528dbus_bool_t wpas_dbus_setter_bss_expire_count(DBusMessageIter *iter,
2529 DBusError *error,
2530 void *user_data)
2531{
2532 struct wpa_supplicant *wpa_s = user_data;
2533 dbus_uint32_t expire_count;
2534
2535 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
2536 &expire_count))
2537 return FALSE;
2538
2539 if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) {
2540 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2541 "BSSExpireCount must be > 0");
2542 return FALSE;
2543 }
2544 return TRUE;
2545}
2546
2547
2548/**
2549 * wpas_dbus_getter_country - Control country code
2550 * @iter: Pointer to incoming dbus message iter
2551 * @error: Location to store error on failure
2552 * @user_data: Function specific data
2553 * Returns: TRUE on success, FALSE on failure
2554 *
2555 * Getter function for "Country" property.
2556 */
2557dbus_bool_t wpas_dbus_getter_country(DBusMessageIter *iter, DBusError *error,
2558 void *user_data)
2559{
2560 struct wpa_supplicant *wpa_s = user_data;
2561 char country[3];
2562 char *str = country;
2563
2564 country[0] = wpa_s->conf->country[0];
2565 country[1] = wpa_s->conf->country[1];
2566 country[2] = '\0';
2567
2568 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2569 &str, error);
2570}
2571
2572
2573/**
2574 * wpas_dbus_setter_country - Control country code
2575 * @iter: Pointer to incoming dbus message iter
2576 * @error: Location to store error on failure
2577 * @user_data: Function specific data
2578 * Returns: TRUE on success, FALSE on failure
2579 *
2580 * Setter function for "Country" property.
2581 */
2582dbus_bool_t wpas_dbus_setter_country(DBusMessageIter *iter, DBusError *error,
2583 void *user_data)
2584{
2585 struct wpa_supplicant *wpa_s = user_data;
2586 const char *country;
2587
2588 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
2589 &country))
2590 return FALSE;
2591
2592 if (!country[0] || !country[1]) {
2593 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2594 "invalid country code");
2595 return FALSE;
2596 }
2597
2598 if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) {
2599 wpa_printf(MSG_DEBUG, "Failed to set country");
2600 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2601 "failed to set country code");
2602 return FALSE;
2603 }
2604
2605 wpa_s->conf->country[0] = country[0];
2606 wpa_s->conf->country[1] = country[1];
2607 return TRUE;
2608}
2609
2610
2611/**
2612 * wpas_dbus_getter_scan_interval - Get scan interval
2613 * @iter: Pointer to incoming dbus message iter
2614 * @error: Location to store error on failure
2615 * @user_data: Function specific data
2616 * Returns: TRUE on success, FALSE on failure
2617 *
2618 * Getter function for "ScanInterval" property.
2619 */
2620dbus_bool_t wpas_dbus_getter_scan_interval(DBusMessageIter *iter,
2621 DBusError *error,
2622 void *user_data)
2623{
2624 struct wpa_supplicant *wpa_s = user_data;
2625 dbus_int32_t scan_interval = wpa_s->scan_interval;
2626
2627 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
2628 &scan_interval, error);
2629}
2630
2631
2632/**
2633 * wpas_dbus_setter_scan_interval - Control scan interval
2634 * @iter: Pointer to incoming dbus message iter
2635 * @error: Location to store error on failure
2636 * @user_data: Function specific data
2637 * Returns: TRUE on success, FALSE on failure
2638 *
2639 * Setter function for "ScanInterval" property.
2640 */
2641dbus_bool_t wpas_dbus_setter_scan_interval(DBusMessageIter *iter,
2642 DBusError *error,
2643 void *user_data)
2644{
2645 struct wpa_supplicant *wpa_s = user_data;
2646 dbus_int32_t scan_interval;
2647
2648 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_INT32,
2649 &scan_interval))
2650 return FALSE;
2651
2652 if (wpa_supplicant_set_scan_interval(wpa_s, scan_interval)) {
2653 dbus_set_error_const(error, DBUS_ERROR_FAILED,
2654 "scan_interval must be >= 0");
2655 return FALSE;
2656 }
2657 return TRUE;
2658}
2659
2660
2661/**
2662 * wpas_dbus_getter_ifname - Get interface name
2663 * @iter: Pointer to incoming dbus message iter
2664 * @error: Location to store error on failure
2665 * @user_data: Function specific data
2666 * Returns: TRUE on success, FALSE on failure
2667 *
2668 * Getter for "Ifname" property.
2669 */
2670dbus_bool_t wpas_dbus_getter_ifname(DBusMessageIter *iter, DBusError *error,
2671 void *user_data)
2672{
2673 struct wpa_supplicant *wpa_s = user_data;
2674 const char *ifname = wpa_s->ifname;
2675
2676 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2677 &ifname, error);
2678}
2679
2680
2681/**
2682 * wpas_dbus_getter_driver - Get interface name
2683 * @iter: Pointer to incoming dbus message iter
2684 * @error: Location to store error on failure
2685 * @user_data: Function specific data
2686 * Returns: TRUE on success, FALSE on failure
2687 *
2688 * Getter for "Driver" property.
2689 */
2690dbus_bool_t wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error,
2691 void *user_data)
2692{
2693 struct wpa_supplicant *wpa_s = user_data;
2694 const char *driver;
2695
2696 if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
2697 wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
2698 "wpa_s has no driver set");
2699 dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
2700 __func__);
2701 return FALSE;
2702 }
2703
2704 driver = wpa_s->driver->name;
2705 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2706 &driver, error);
2707}
2708
2709
2710/**
2711 * wpas_dbus_getter_current_bss - Get current bss object path
2712 * @iter: Pointer to incoming dbus message iter
2713 * @error: Location to store error on failure
2714 * @user_data: Function specific data
2715 * Returns: TRUE on success, FALSE on failure
2716 *
2717 * Getter for "CurrentBSS" property.
2718 */
2719dbus_bool_t wpas_dbus_getter_current_bss(DBusMessageIter *iter,
2720 DBusError *error,
2721 void *user_data)
2722{
2723 struct wpa_supplicant *wpa_s = user_data;
2724 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
2725
2726 if (wpa_s->current_bss)
2727 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2728 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2729 wpa_s->dbus_new_path, wpa_s->current_bss->id);
2730 else
2731 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2732
2733 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
2734 &bss_obj_path, error);
2735}
2736
2737
2738/**
2739 * wpas_dbus_getter_current_network - Get current network object path
2740 * @iter: Pointer to incoming dbus message iter
2741 * @error: Location to store error on failure
2742 * @user_data: Function specific data
2743 * Returns: TRUE on success, FALSE on failure
2744 *
2745 * Getter for "CurrentNetwork" property.
2746 */
2747dbus_bool_t wpas_dbus_getter_current_network(DBusMessageIter *iter,
2748 DBusError *error,
2749 void *user_data)
2750{
2751 struct wpa_supplicant *wpa_s = user_data;
2752 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
2753
2754 if (wpa_s->current_ssid)
2755 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
2756 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
2757 wpa_s->dbus_new_path, wpa_s->current_ssid->id);
2758 else
2759 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
2760
2761 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
2762 &net_obj_path, error);
2763}
2764
2765
2766/**
2767 * wpas_dbus_getter_current_auth_mode - Get current authentication type
2768 * @iter: Pointer to incoming dbus message iter
2769 * @error: Location to store error on failure
2770 * @user_data: Function specific data
2771 * Returns: TRUE on success, FALSE on failure
2772 *
2773 * Getter for "CurrentAuthMode" property.
2774 */
2775dbus_bool_t wpas_dbus_getter_current_auth_mode(DBusMessageIter *iter,
2776 DBusError *error,
2777 void *user_data)
2778{
2779 struct wpa_supplicant *wpa_s = user_data;
2780 const char *eap_mode;
2781 const char *auth_mode;
2782 char eap_mode_buf[WPAS_DBUS_AUTH_MODE_MAX];
2783
2784 if (wpa_s->wpa_state != WPA_COMPLETED) {
2785 auth_mode = "INACTIVE";
2786 } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
2787 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2788 eap_mode = wpa_supplicant_get_eap_mode(wpa_s);
2789 os_snprintf(eap_mode_buf, WPAS_DBUS_AUTH_MODE_MAX,
2790 "EAP-%s", eap_mode);
2791 auth_mode = eap_mode_buf;
2792
2793 } else {
2794 auth_mode = wpa_key_mgmt_txt(wpa_s->key_mgmt,
2795 wpa_s->current_ssid->proto);
2796 }
2797
2798 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2799 &auth_mode, error);
2800}
2801
2802
2803/**
2804 * wpas_dbus_getter_bridge_ifname - Get interface name
2805 * @iter: Pointer to incoming dbus message iter
2806 * @error: Location to store error on failure
2807 * @user_data: Function specific data
2808 * Returns: TRUE on success, FALSE on failure
2809 *
2810 * Getter for "BridgeIfname" property.
2811 */
2812dbus_bool_t wpas_dbus_getter_bridge_ifname(DBusMessageIter *iter,
2813 DBusError *error,
2814 void *user_data)
2815{
2816 struct wpa_supplicant *wpa_s = user_data;
2817 const char *bridge_ifname = wpa_s->bridge_ifname;
2818 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2819 &bridge_ifname, error);
2820}
2821
2822
2823/**
2824 * wpas_dbus_getter_bsss - Get array of BSSs objects
2825 * @iter: Pointer to incoming dbus message iter
2826 * @error: Location to store error on failure
2827 * @user_data: Function specific data
2828 * Returns: TRUE on success, FALSE on failure
2829 *
2830 * Getter for "BSSs" property.
2831 */
2832dbus_bool_t wpas_dbus_getter_bsss(DBusMessageIter *iter, DBusError *error,
2833 void *user_data)
2834{
2835 struct wpa_supplicant *wpa_s = user_data;
2836 struct wpa_bss *bss;
2837 char **paths;
2838 unsigned int i = 0;
2839 dbus_bool_t success = FALSE;
2840
2841 paths = os_calloc(wpa_s->num_bss, sizeof(char *));
2842 if (!paths) {
2843 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2844 return FALSE;
2845 }
2846
2847 /* Loop through scan results and append each result's object path */
2848 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2849 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2850 if (paths[i] == NULL) {
2851 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
2852 "no memory");
2853 goto out;
2854 }
2855 /* Construct the object path for this BSS. */
2856 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2857 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
2858 wpa_s->dbus_new_path, bss->id);
2859 }
2860
2861 success = wpas_dbus_simple_array_property_getter(iter,
2862 DBUS_TYPE_OBJECT_PATH,
2863 paths, wpa_s->num_bss,
2864 error);
2865
2866out:
2867 while (i)
2868 os_free(paths[--i]);
2869 os_free(paths);
2870 return success;
2871}
2872
2873
2874/**
2875 * wpas_dbus_getter_networks - Get array of networks objects
2876 * @iter: Pointer to incoming dbus message iter
2877 * @error: Location to store error on failure
2878 * @user_data: Function specific data
2879 * Returns: TRUE on success, FALSE on failure
2880 *
2881 * Getter for "Networks" property.
2882 */
2883dbus_bool_t wpas_dbus_getter_networks(DBusMessageIter *iter, DBusError *error,
2884 void *user_data)
2885{
2886 struct wpa_supplicant *wpa_s = user_data;
2887 struct wpa_ssid *ssid;
2888 char **paths;
2889 unsigned int i = 0, num = 0;
2890 dbus_bool_t success = FALSE;
2891
2892 if (wpa_s->conf == NULL) {
2893 wpa_printf(MSG_ERROR, "%s[dbus]: An error occurred getting "
2894 "networks list.", __func__);
2895 dbus_set_error(error, DBUS_ERROR_FAILED, "%s: an error "
2896 "occurred getting the networks list", __func__);
2897 return FALSE;
2898 }
2899
2900 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
2901 if (!network_is_persistent_group(ssid))
2902 num++;
2903
2904 paths = os_calloc(num, sizeof(char *));
2905 if (!paths) {
2906 dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
2907 return FALSE;
2908 }
2909
2910 /* Loop through configured networks and append object path of each */
2911 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
2912 if (network_is_persistent_group(ssid))
2913 continue;
2914 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
2915 if (paths[i] == NULL) {
2916 dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
2917 goto out;
2918 }
2919
2920 /* Construct the object path for this network. */
2921 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
2922 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
2923 wpa_s->dbus_new_path, ssid->id);
2924 }
2925
2926 success = wpas_dbus_simple_array_property_getter(iter,
2927 DBUS_TYPE_OBJECT_PATH,
2928 paths, num, error);
2929
2930out:
2931 while (i)
2932 os_free(paths[--i]);
2933 os_free(paths);
2934 return success;
2935}
2936
2937
2938/**
2939 * wpas_dbus_getter_blobs - Get all blobs defined for this interface
2940 * @iter: Pointer to incoming dbus message iter
2941 * @error: Location to store error on failure
2942 * @user_data: Function specific data
2943 * Returns: TRUE on success, FALSE on failure
2944 *
2945 * Getter for "Blobs" property.
2946 */
2947dbus_bool_t wpas_dbus_getter_blobs(DBusMessageIter *iter, DBusError *error,
2948 void *user_data)
2949{
2950 struct wpa_supplicant *wpa_s = user_data;
2951 DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter;
2952 struct wpa_config_blob *blob;
2953
2954 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
2955 "a{say}", &variant_iter) ||
2956 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
2957 "{say}", &dict_iter)) {
2958 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2959 return FALSE;
2960 }
2961
2962 blob = wpa_s->conf->blobs;
2963 while (blob) {
2964 if (!dbus_message_iter_open_container(&dict_iter,
2965 DBUS_TYPE_DICT_ENTRY,
2966 NULL, &entry_iter) ||
2967 !dbus_message_iter_append_basic(&entry_iter,
--- 6 unchanged lines hidden (view full) ---
2974 !dbus_message_iter_append_fixed_array(&array_iter,
2975 DBUS_TYPE_BYTE,
2976 &(blob->data),
2977 blob->len) ||
2978 !dbus_message_iter_close_container(&entry_iter,
2979 &array_iter) ||
2980 !dbus_message_iter_close_container(&dict_iter,
2981 &entry_iter)) {
2982 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
2983 "no memory");
2984 return FALSE;
2985 }
2986
2987 blob = blob->next;
2988 }
2989
2990 if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
2991 !dbus_message_iter_close_container(iter, &variant_iter)) {
2992 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2993 return FALSE;
2994 }
2995
2996 return TRUE;
2997}
2998
2999
3000static struct wpa_bss * get_bss_helper(struct bss_handler_args *args,
3001 DBusError *error, const char *func_name)
3002{
3003 struct wpa_bss *res = wpa_bss_get_id(args->wpa_s, args->id);
3004
3005 if (!res) {
3006 wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found",
3007 func_name, args->id);
3008 dbus_set_error(error, DBUS_ERROR_FAILED,
3009 "%s: BSS %d not found",
3010 func_name, args->id);
3011 }
3012
3013 return res;
3014}
3015
3016
3017/**
3018 * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
3019 * @iter: Pointer to incoming dbus message iter
3020 * @error: Location to store error on failure
3021 * @user_data: Function specific data
3022 * Returns: TRUE on success, FALSE on failure
3023 *
3024 * Getter for "BSSID" property.
3025 */
3026dbus_bool_t wpas_dbus_getter_bss_bssid(DBusMessageIter *iter, DBusError *error,
3027 void *user_data)
3028{
3029 struct bss_handler_args *args = user_data;
3030 struct wpa_bss *res;
3031
3032 res = get_bss_helper(args, error, __func__);
3033 if (!res)
3034 return FALSE;
3035
3036 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3037 res->bssid, ETH_ALEN,
3038 error);
3039}
3040
3041
3042/**
3043 * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
3044 * @iter: Pointer to incoming dbus message iter
3045 * @error: Location to store error on failure
3046 * @user_data: Function specific data
3047 * Returns: TRUE on success, FALSE on failure
3048 *
3049 * Getter for "SSID" property.
3050 */
3051dbus_bool_t wpas_dbus_getter_bss_ssid(DBusMessageIter *iter, DBusError *error,
3052 void *user_data)
3053{
3054 struct bss_handler_args *args = user_data;
3055 struct wpa_bss *res;
3056
3057 res = get_bss_helper(args, error, __func__);
3058 if (!res)
3059 return FALSE;
3060
3061 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3062 res->ssid, res->ssid_len,
3063 error);
3064}
3065
3066
3067/**
3068 * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
3069 * @iter: Pointer to incoming dbus message iter
3070 * @error: Location to store error on failure
3071 * @user_data: Function specific data
3072 * Returns: TRUE on success, FALSE on failure
3073 *
3074 * Getter for "Privacy" property.
3075 */
3076dbus_bool_t wpas_dbus_getter_bss_privacy(DBusMessageIter *iter,
3077 DBusError *error, void *user_data)
3078{
3079 struct bss_handler_args *args = user_data;
3080 struct wpa_bss *res;
3081 dbus_bool_t privacy;
3082
3083 res = get_bss_helper(args, error, __func__);
3084 if (!res)
3085 return FALSE;
3086
3087 privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
3088 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
3089 &privacy, error);
3090}
3091
3092
3093/**
3094 * wpas_dbus_getter_bss_mode - Return the mode of a BSS
3095 * @iter: Pointer to incoming dbus message iter
3096 * @error: Location to store error on failure
3097 * @user_data: Function specific data
3098 * Returns: TRUE on success, FALSE on failure
3099 *
3100 * Getter for "Mode" property.
3101 */
3102dbus_bool_t wpas_dbus_getter_bss_mode(DBusMessageIter *iter, DBusError *error,
3103 void *user_data)
3104{
3105 struct bss_handler_args *args = user_data;
3106 struct wpa_bss *res;
3107 const char *mode;
3108
3109 res = get_bss_helper(args, error, __func__);
3110 if (!res)
3111 return FALSE;
3112
3113 if (res->caps & IEEE80211_CAP_IBSS)
3114 mode = "ad-hoc";
3115 else
3116 mode = "infrastructure";
3117
3118 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3119 &mode, error);
3120}
3121
3122
3123/**
3124 * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
3125 * @iter: Pointer to incoming dbus message iter
3126 * @error: Location to store error on failure
3127 * @user_data: Function specific data
3128 * Returns: TRUE on success, FALSE on failure
3129 *
3130 * Getter for "Level" property.
3131 */
3132dbus_bool_t wpas_dbus_getter_bss_signal(DBusMessageIter *iter,
3133 DBusError *error, void *user_data)
3134{
3135 struct bss_handler_args *args = user_data;
3136 struct wpa_bss *res;
3137 s16 level;
3138
3139 res = get_bss_helper(args, error, __func__);
3140 if (!res)
3141 return FALSE;
3142
3143 level = (s16) res->level;
3144 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16,
3145 &level, error);
3146}
3147
3148
3149/**
3150 * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
3151 * @iter: Pointer to incoming dbus message iter
3152 * @error: Location to store error on failure
3153 * @user_data: Function specific data
3154 * Returns: TRUE on success, FALSE on failure
3155 *
3156 * Getter for "Frequency" property.
3157 */
3158dbus_bool_t wpas_dbus_getter_bss_frequency(DBusMessageIter *iter,
3159 DBusError *error, void *user_data)
3160{
3161 struct bss_handler_args *args = user_data;
3162 struct wpa_bss *res;
3163 u16 freq;
3164
3165 res = get_bss_helper(args, error, __func__);
3166 if (!res)
3167 return FALSE;
3168
3169 freq = (u16) res->freq;
3170 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
3171 &freq, error);
3172}
3173
3174
3175static int cmp_u8s_desc(const void *a, const void *b)
3176{
3177 return (*(u8 *) b - *(u8 *) a);
3178}
3179
3180
3181/**
3182 * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
3183 * @iter: Pointer to incoming dbus message iter
3184 * @error: Location to store error on failure
3185 * @user_data: Function specific data
3186 * Returns: TRUE on success, FALSE on failure
3187 *
3188 * Getter for "Rates" property.
3189 */
3190dbus_bool_t wpas_dbus_getter_bss_rates(DBusMessageIter *iter,
3191 DBusError *error, void *user_data)
3192{
3193 struct bss_handler_args *args = user_data;
3194 struct wpa_bss *res;
3195 u8 *ie_rates = NULL;
3196 u32 *real_rates;
3197 int rates_num, i;
3198 dbus_bool_t success = FALSE;
3199
3200 res = get_bss_helper(args, error, __func__);
3201 if (!res)
3202 return FALSE;
3203
3204 rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
3205 if (rates_num < 0)
3206 return FALSE;
3207
3208 qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
3209
3210 real_rates = os_malloc(sizeof(u32) * rates_num);
3211 if (!real_rates) {
3212 os_free(ie_rates);
3213 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3214 return FALSE;
3215 }
3216
3217 for (i = 0; i < rates_num; i++)
3218 real_rates[i] = ie_rates[i] * 500000;
3219
3220 success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32,
3221 real_rates, rates_num,
3222 error);
3223
3224 os_free(ie_rates);
3225 os_free(real_rates);
3226 return success;
3227}
3228
3229
3230static dbus_bool_t wpas_dbus_get_bss_security_prop(DBusMessageIter *iter,
3231 struct wpa_ie_data *ie_data,
3232 DBusError *error)
3233{
3234 DBusMessageIter iter_dict, variant_iter;
3235 const char *group;
3236 const char *pairwise[3]; /* max 3 pairwise ciphers is supported */
3237 const char *key_mgmt[7]; /* max 7 key managements may be supported */
3238 int n;
3239
3240 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
3241 "a{sv}", &variant_iter))
3242 goto nomem;
3243
3244 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
3245 goto nomem;
3246
3247 /* KeyMgmt */
3248 n = 0;
--- 22 unchanged lines hidden (view full) ---
3271 group = "wep40";
3272 break;
3273 case WPA_CIPHER_TKIP:
3274 group = "tkip";
3275 break;
3276 case WPA_CIPHER_CCMP:
3277 group = "ccmp";
3278 break;
3279 case WPA_CIPHER_GCMP:
3280 group = "gcmp";
3281 break;
3282 case WPA_CIPHER_WEP104:
3283 group = "wep104";
3284 break;
3285 default:
3286 group = "";
3287 break;
3288 }
3289
3290 if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
3291 goto nomem;
3292
3293 /* Pairwise */
3294 n = 0;
3295 if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
3296 pairwise[n++] = "tkip";
3297 if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
3298 pairwise[n++] = "ccmp";
3299 if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP)
3300 pairwise[n++] = "gcmp";
3301
3302 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
3303 pairwise, n))
3304 goto nomem;
3305
3306 /* Management group (RSN only) */
3307 if (ie_data->proto == WPA_PROTO_RSN) {
3308 switch (ie_data->mgmt_group_cipher) {
--- 9 unchanged lines hidden (view full) ---
3318
3319 if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
3320 group))
3321 goto nomem;
3322 }
3323
3324 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
3325 goto nomem;
3326 if (!dbus_message_iter_close_container(iter, &variant_iter))
3327 goto nomem;
3328
3329 return TRUE;
3330
3331nomem:
3332 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3333 return FALSE;
3334}
3335
3336
3337/**
3338 * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
3339 * @iter: Pointer to incoming dbus message iter
3340 * @error: Location to store error on failure
3341 * @user_data: Function specific data
3342 * Returns: TRUE on success, FALSE on failure
3343 *
3344 * Getter for "WPA" property.
3345 */
3346dbus_bool_t wpas_dbus_getter_bss_wpa(DBusMessageIter *iter, DBusError *error,
3347 void *user_data)
3348{
3349 struct bss_handler_args *args = user_data;
3350 struct wpa_bss *res;
3351 struct wpa_ie_data wpa_data;
3352 const u8 *ie;
3353
3354 res = get_bss_helper(args, error, __func__);
3355 if (!res)
3356 return FALSE;
3357
3358 os_memset(&wpa_data, 0, sizeof(wpa_data));
3359 ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
3360 if (ie) {
3361 if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
3362 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3363 "failed to parse WPA IE");
3364 return FALSE;
3365 }
3366 }
3367
3368 return wpas_dbus_get_bss_security_prop(iter, &wpa_data, error);
3369}
3370
3371
3372/**
3373 * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
3374 * @iter: Pointer to incoming dbus message iter
3375 * @error: Location to store error on failure
3376 * @user_data: Function specific data
3377 * Returns: TRUE on success, FALSE on failure
3378 *
3379 * Getter for "RSN" property.
3380 */
3381dbus_bool_t wpas_dbus_getter_bss_rsn(DBusMessageIter *iter, DBusError *error,
3382 void *user_data)
3383{
3384 struct bss_handler_args *args = user_data;
3385 struct wpa_bss *res;
3386 struct wpa_ie_data wpa_data;
3387 const u8 *ie;
3388
3389 res = get_bss_helper(args, error, __func__);
3390 if (!res)
3391 return FALSE;
3392
3393 os_memset(&wpa_data, 0, sizeof(wpa_data));
3394 ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
3395 if (ie) {
3396 if (wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
3397 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3398 "failed to parse RSN IE");
3399 return FALSE;
3400 }
3401 }
3402
3403 return wpas_dbus_get_bss_security_prop(iter, &wpa_data, error);
3404}
3405
3406
3407/**
3408 * wpas_dbus_getter_bss_wps - Return the WPS options of a BSS
3409 * @iter: Pointer to incoming dbus message iter
3410 * @error: Location to store error on failure
3411 * @user_data: Function specific data
3412 * Returns: TRUE on success, FALSE on failure
3413 *
3414 * Getter for "WPS" property.
3415 */
3416dbus_bool_t wpas_dbus_getter_bss_wps(DBusMessageIter *iter, DBusError *error,
3417 void *user_data)
3418{
3419 struct bss_handler_args *args = user_data;
3420 struct wpa_bss *res;
3421#ifdef CONFIG_WPS
3422 struct wpabuf *wps_ie;
3423#endif /* CONFIG_WPS */
3424 DBusMessageIter iter_dict, variant_iter;
3425 const char *type = "";
3426
3427 res = get_bss_helper(args, error, __func__);
3428 if (!res)
3429 return FALSE;
3430
3431 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
3432 "a{sv}", &variant_iter))
3433 goto nomem;
3434
3435 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
3436 goto nomem;
3437
3438#ifdef CONFIG_WPS
3439 wps_ie = wpa_bss_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
3440 if (wps_ie) {
3441 if (wps_is_selected_pbc_registrar(wps_ie))
3442 type = "pbc";
3443 else if (wps_is_selected_pin_registrar(wps_ie))
3444 type = "pin";
3445 }
3446#endif /* CONFIG_WPS */
3447
3448 if (!wpa_dbus_dict_append_string(&iter_dict, "Type", type))
3449 goto nomem;
3450
3451 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict))
3452 goto nomem;
3453 if (!dbus_message_iter_close_container(iter, &variant_iter))
3454 goto nomem;
3455
3456 return TRUE;
3457
3458nomem:
3459 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3460 return FALSE;
3461}
3462
3463
3464/**
3465 * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
3466 * @iter: Pointer to incoming dbus message iter
3467 * @error: Location to store error on failure
3468 * @user_data: Function specific data
3469 * Returns: TRUE on success, FALSE on failure
3470 *
3471 * Getter for "IEs" property.
3472 */
3473dbus_bool_t wpas_dbus_getter_bss_ies(DBusMessageIter *iter, DBusError *error,
3474 void *user_data)
3475{
3476 struct bss_handler_args *args = user_data;
3477 struct wpa_bss *res;
3478
3479 res = get_bss_helper(args, error, __func__);
3480 if (!res)
3481 return FALSE;
3482
3483 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3484 res + 1, res->ie_len,
3485 error);
3486}
3487
3488
3489/**
3490 * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
3491 * @iter: Pointer to incoming dbus message iter
3492 * @error: Location to store error on failure
3493 * @user_data: Function specific data
3494 * Returns: TRUE on success, FALSE on failure
3495 *
3496 * Getter for "enabled" property of a configured network.
3497 */
3498dbus_bool_t wpas_dbus_getter_enabled(DBusMessageIter *iter, DBusError *error,
3499 void *user_data)
3500{
3501 struct network_handler_args *net = user_data;
3502 dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
3503
3504 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
3505 &enabled, error);
3506}
3507
3508
3509/**
3510 * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
3511 * @iter: Pointer to incoming dbus message iter
3512 * @error: Location to store error on failure
3513 * @user_data: Function specific data
3514 * Returns: TRUE on success, FALSE on failure
3515 *
3516 * Setter for "Enabled" property of a configured network.
3517 */
3518dbus_bool_t wpas_dbus_setter_enabled(DBusMessageIter *iter, DBusError *error,
3519 void *user_data)
3520{
3521 struct network_handler_args *net = user_data;
3522 struct wpa_supplicant *wpa_s;
3523 struct wpa_ssid *ssid;
3524 dbus_bool_t enable;
3525
3526 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
3527 &enable))
3528 return FALSE;
3529
3530 wpa_s = net->wpa_s;
3531 ssid = net->ssid;
3532
3533 if (enable)
3534 wpa_supplicant_enable_network(wpa_s, ssid);
3535 else
3536 wpa_supplicant_disable_network(wpa_s, ssid);
3537
3538 return TRUE;
3539}
3540
3541
3542/**
3543 * wpas_dbus_getter_network_properties - Get options for a configured network
3544 * @iter: Pointer to incoming dbus message iter
3545 * @error: Location to store error on failure
3546 * @user_data: Function specific data
3547 * Returns: TRUE on success, FALSE on failure
3548 *
3549 * Getter for "Properties" property of a configured network.
3550 */
3551dbus_bool_t wpas_dbus_getter_network_properties(DBusMessageIter *iter,
3552 DBusError *error,
3553 void *user_data)
3554{
3555 struct network_handler_args *net = user_data;
3556 DBusMessageIter variant_iter, dict_iter;
3557 char **iterator;
3558 char **props = wpa_config_get_all(net->ssid, 1);
3559 dbus_bool_t success = FALSE;
3560
3561 if (!props) {
3562 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3563 return FALSE;
3564 }
3565
3566 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
3567 &variant_iter) ||
3568 !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
3569 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3570 goto out;
3571 }
3572
3573 iterator = props;
3574 while (*iterator) {
3575 if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
3576 *(iterator + 1))) {
3577 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3578 "no memory");
3579 goto out;
3580 }
3581 iterator += 2;
3582 }
3583
3584
3585 if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
3586 !dbus_message_iter_close_container(iter, &variant_iter)) {
3587 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3588 goto out;
3589 }
3590
3591 success = TRUE;
3592
3593out:
3594 iterator = props;
3595 while (*iterator) {
3596 os_free(*iterator);
3597 iterator++;
3598 }
3599 os_free(props);
3600 return success;
3601}
3602
3603
3604/**
3605 * wpas_dbus_setter_network_properties - Set options for a configured network
3606 * @iter: Pointer to incoming dbus message iter
3607 * @error: Location to store error on failure
3608 * @user_data: Function specific data
3609 * Returns: TRUE on success, FALSE on failure
3610 *
3611 * Setter for "Properties" property of a configured network.
3612 */
3613dbus_bool_t wpas_dbus_setter_network_properties(DBusMessageIter *iter,
3614 DBusError *error,
3615 void *user_data)
3616{
3617 struct network_handler_args *net = user_data;
3618 struct wpa_ssid *ssid = net->ssid;
3619 DBusMessageIter variant_iter;
3620
3621 dbus_message_iter_recurse(iter, &variant_iter);
3622 return set_network_properties(net->wpa_s, ssid, &variant_iter, error);
3623}
3624
3625
3626#ifdef CONFIG_AP
3627
3628DBusMessage * wpas_dbus_handler_subscribe_preq(
3629 DBusMessage *message, struct wpa_supplicant *wpa_s)
3630{
3631 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
3632 char *name;
3633
3634 if (wpa_s->preq_notify_peer != NULL) {
3635 if (os_strcmp(dbus_message_get_sender(message),
3636 wpa_s->preq_notify_peer) == 0)
3637 return NULL;
3638
3639 return dbus_message_new_error(message,
3640 WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE,
3641 "Another application is already subscribed");
3642 }
3643
3644 name = os_strdup(dbus_message_get_sender(message));
3645 if (!name)
3646 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
3647 "out of memory");
3648
3649 wpa_s->preq_notify_peer = name;
3650
3651 /* Subscribe to clean up if application closes socket */
3652 wpas_dbus_subscribe_noc(priv);
3653
3654 /*
3655 * Double-check it's still alive to make sure that we didn't
3656 * miss the NameOwnerChanged signal, e.g. while strdup'ing.
3657 */
3658 if (!dbus_bus_name_has_owner(priv->con, name, NULL)) {
3659 /*
3660 * Application no longer exists, clean up.
3661 * The return value is irrelevant now.
3662 *
3663 * Need to check if the NameOwnerChanged handling
3664 * already cleaned up because we have processed
3665 * DBus messages while checking if the name still
3666 * has an owner.
3667 */
3668 if (!wpa_s->preq_notify_peer)
3669 return NULL;
3670 os_free(wpa_s->preq_notify_peer);
3671 wpa_s->preq_notify_peer = NULL;
3672 wpas_dbus_unsubscribe_noc(priv);
3673 }
3674
3675 return NULL;
3676}
3677
3678
3679DBusMessage * wpas_dbus_handler_unsubscribe_preq(
3680 DBusMessage *message, struct wpa_supplicant *wpa_s)
3681{
3682 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
3683
3684 if (!wpa_s->preq_notify_peer)
3685 return dbus_message_new_error(message,
3686 WPAS_DBUS_ERROR_NO_SUBSCRIPTION,
3687 "Not subscribed");
3688
3689 if (os_strcmp(wpa_s->preq_notify_peer,
3690 dbus_message_get_sender(message)))
3691 return dbus_message_new_error(message,
3692 WPAS_DBUS_ERROR_SUBSCRIPTION_EPERM,
3693 "Can't unsubscribe others");
3694
3695 os_free(wpa_s->preq_notify_peer);
3696 wpa_s->preq_notify_peer = NULL;
3697 wpas_dbus_unsubscribe_noc(priv);
3698 return NULL;
3699}
3700
3701
3702void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s,
3703 const u8 *addr, const u8 *dst, const u8 *bssid,
3704 const u8 *ie, size_t ie_len, u32 ssi_signal)
3705{
3706 DBusMessage *msg;
3707 DBusMessageIter iter, dict_iter;
3708 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
3709
3710 /* Do nothing if the control interface is not turned on */
3711 if (priv == NULL)
3712 return;
3713
3714 if (wpa_s->preq_notify_peer == NULL)
3715 return;
3716
3717 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
3718 WPAS_DBUS_NEW_IFACE_INTERFACE,
3719 "ProbeRequest");
3720 if (msg == NULL)
3721 return;
3722
3723 dbus_message_set_destination(msg, wpa_s->preq_notify_peer);
3724
3725 dbus_message_iter_init_append(msg, &iter);
3726
3727 if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
3728 goto fail;
3729 if (addr && !wpa_dbus_dict_append_byte_array(&dict_iter, "addr",
3730 (const char *) addr,
3731 ETH_ALEN))
3732 goto fail;
3733 if (dst && !wpa_dbus_dict_append_byte_array(&dict_iter, "dst",
3734 (const char *) dst,
3735 ETH_ALEN))
3736 goto fail;
3737 if (bssid && !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
3738 (const char *) bssid,
3739 ETH_ALEN))
3740 goto fail;
3741 if (ie && ie_len && !wpa_dbus_dict_append_byte_array(&dict_iter, "ies",
3742 (const char *) ie,
3743 ie_len))
3744 goto fail;
3745 if (ssi_signal && !wpa_dbus_dict_append_int32(&dict_iter, "signal",
3746 ssi_signal))
3747 goto fail;
3748 if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
3749 goto fail;
3750
3751 dbus_connection_send(priv->con, msg, NULL);
3752 goto out;
3753fail:
3754 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
3755out:
3756 dbus_message_unref(msg);
3757}
3758
3759#endif /* CONFIG_AP */