]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/dbus/dbus_new_handlers.c
dbus: Export BSS Transition Management status
[thirdparty/hostap.git] / wpa_supplicant / dbus / dbus_new_handlers.c
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-2015, 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 "ap/hostapd.h"
19 #include "ap/sta_info.h"
20 #include "ap/ap_drv_ops.h"
21 #include "../config.h"
22 #include "../wpa_supplicant_i.h"
23 #include "../driver_i.h"
24 #include "../notify.h"
25 #include "../bss.h"
26 #include "../scan.h"
27 #include "../autoscan.h"
28 #include "../ap.h"
29 #include "dbus_new_helpers.h"
30 #include "dbus_new.h"
31 #include "dbus_new_handlers.h"
32 #include "dbus_dict_helpers.h"
33 #include "dbus_common_i.h"
34 #include "drivers/driver.h"
35 #ifdef CONFIG_MESH
36 #include "ap/hostapd.h"
37 #include "ap/sta_info.h"
38 #endif /* CONFIG_MESH */
39
40 static const char * const debug_strings[] = {
41 "excessive", "msgdump", "debug", "info", "warning", "error", NULL
42 };
43
44
45 /**
46 * wpas_dbus_error_unknown_error - Return a new UnknownError error message
47 * @message: Pointer to incoming dbus message this error refers to
48 * @arg: Optional string appended to error message
49 * Returns: a dbus error message
50 *
51 * Convenience function to create and return an UnknownError
52 */
53 DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
54 const char *arg)
55 {
56 return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
57 arg);
58 }
59
60
61 /**
62 * wpas_dbus_error_iface_unknown - Return a new invalid interface error message
63 * @message: Pointer to incoming dbus message this error refers to
64 * Returns: A dbus error message
65 *
66 * Convenience function to create and return an invalid interface error
67 */
68 static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
69 {
70 return dbus_message_new_error(
71 message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
72 "wpa_supplicant knows nothing about this interface.");
73 }
74
75
76 /**
77 * wpas_dbus_error_network_unknown - Return a new NetworkUnknown error message
78 * @message: Pointer to incoming dbus message this error refers to
79 * Returns: a dbus error message
80 *
81 * Convenience function to create and return an invalid network error
82 */
83 static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
84 {
85 return dbus_message_new_error(
86 message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
87 "There is no such a network in this interface.");
88 }
89
90
91 /**
92 * wpas_dbus_error_invalid_args - Return a new InvalidArgs error message
93 * @message: Pointer to incoming dbus message this error refers to
94 * Returns: a dbus error message
95 *
96 * Convenience function to create and return an invalid options error
97 */
98 DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
99 const char *arg)
100 {
101 DBusMessage *reply;
102
103 reply = dbus_message_new_error(
104 message, WPAS_DBUS_ERROR_INVALID_ARGS,
105 "Did not receive correct message arguments.");
106 if (arg != NULL)
107 dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
108 DBUS_TYPE_INVALID);
109
110 return reply;
111 }
112
113
114 /**
115 * wpas_dbus_error_scan_error - Return a new ScanError error message
116 * @message: Pointer to incoming dbus message this error refers to
117 * @error: Optional string to be used as the error message
118 * Returns: a dbus error message
119 *
120 * Convenience function to create and return a scan error
121 */
122 static DBusMessage * wpas_dbus_error_scan_error(DBusMessage *message,
123 const char *error)
124 {
125 return dbus_message_new_error(message,
126 WPAS_DBUS_ERROR_IFACE_SCAN_ERROR,
127 error);
128 }
129
130
131 DBusMessage * wpas_dbus_error_no_memory(DBusMessage *message)
132 {
133 wpa_printf(MSG_DEBUG, "dbus: Failed to allocate memory");
134 return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
135 }
136
137
138 static const char * const dont_quote[] = {
139 "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
140 "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
141 "bssid", "scan_freq", "freq_list", NULL
142 };
143
144 static dbus_bool_t should_quote_opt(const char *key)
145 {
146 int i = 0;
147
148 while (dont_quote[i] != NULL) {
149 if (os_strcmp(key, dont_quote[i]) == 0)
150 return FALSE;
151 i++;
152 }
153 return TRUE;
154 }
155
156 /**
157 * get_iface_by_dbus_path - Get a new network interface
158 * @global: Pointer to global data from wpa_supplicant_init()
159 * @path: Pointer to a dbus object path representing an interface
160 * Returns: Pointer to the interface or %NULL if not found
161 */
162 static struct wpa_supplicant * get_iface_by_dbus_path(
163 struct wpa_global *global, const char *path)
164 {
165 struct wpa_supplicant *wpa_s;
166
167 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
168 if (wpa_s->dbus_new_path &&
169 os_strcmp(wpa_s->dbus_new_path, path) == 0)
170 return wpa_s;
171 }
172 return NULL;
173 }
174
175
176 /**
177 * set_network_properties - Set properties of a configured network
178 * @wpa_s: wpa_supplicant structure for a network interface
179 * @ssid: wpa_ssid structure for a configured network
180 * @iter: DBus message iterator containing dictionary of network
181 * properties to set.
182 * @error: On failure, an error describing the failure
183 * Returns: TRUE if the request succeeds, FALSE if it failed
184 *
185 * Sets network configuration with parameters given id DBus dictionary
186 */
187 dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s,
188 struct wpa_ssid *ssid,
189 DBusMessageIter *iter,
190 DBusError *error)
191 {
192 struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING };
193 DBusMessageIter iter_dict;
194 char *value = NULL;
195
196 if (!wpa_dbus_dict_open_read(iter, &iter_dict, error))
197 return FALSE;
198
199 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
200 size_t size = 50;
201 int ret;
202
203 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
204 goto error;
205
206 value = NULL;
207 if (entry.type == DBUS_TYPE_ARRAY &&
208 entry.array_type == DBUS_TYPE_BYTE) {
209 if (entry.array_len <= 0)
210 goto error;
211
212 size = entry.array_len * 2 + 1;
213 value = os_zalloc(size);
214 if (value == NULL)
215 goto error;
216
217 ret = wpa_snprintf_hex(value, size,
218 (u8 *) entry.bytearray_value,
219 entry.array_len);
220 if (ret <= 0)
221 goto error;
222 } else if (entry.type == DBUS_TYPE_STRING) {
223 if (should_quote_opt(entry.key)) {
224 size = os_strlen(entry.str_value);
225 if (size == 0)
226 goto error;
227
228 size += 3;
229 value = os_zalloc(size);
230 if (value == NULL)
231 goto error;
232
233 ret = os_snprintf(value, size, "\"%s\"",
234 entry.str_value);
235 if (os_snprintf_error(size, ret))
236 goto error;
237 } else {
238 value = os_strdup(entry.str_value);
239 if (value == NULL)
240 goto error;
241 }
242 } else if (entry.type == DBUS_TYPE_UINT32) {
243 value = os_zalloc(size);
244 if (value == NULL)
245 goto error;
246
247 ret = os_snprintf(value, size, "%u",
248 entry.uint32_value);
249 if (os_snprintf_error(size, ret))
250 goto error;
251 } else if (entry.type == DBUS_TYPE_INT32) {
252 value = os_zalloc(size);
253 if (value == NULL)
254 goto error;
255
256 ret = os_snprintf(value, size, "%d",
257 entry.int32_value);
258 if (os_snprintf_error(size, ret))
259 goto error;
260 } else
261 goto error;
262
263 if (wpa_config_set(ssid, entry.key, value, 0) < 0)
264 goto error;
265
266 if (os_strcmp(entry.key, "bssid") != 0 &&
267 os_strcmp(entry.key, "priority") != 0)
268 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
269
270 if (wpa_s->current_ssid == ssid ||
271 wpa_s->current_ssid == NULL) {
272 /*
273 * Invalidate the EAP session cache if anything in the
274 * current or previously used configuration changes.
275 */
276 eapol_sm_invalidate_cached_session(wpa_s->eapol);
277 }
278
279 if ((os_strcmp(entry.key, "psk") == 0 &&
280 value[0] == '"' && ssid->ssid_len) ||
281 (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
282 wpa_config_update_psk(ssid);
283 else if (os_strcmp(entry.key, "priority") == 0)
284 wpa_config_update_prio_list(wpa_s->conf);
285
286 os_free(value);
287 value = NULL;
288 wpa_dbus_dict_entry_clear(&entry);
289 }
290
291 return TRUE;
292
293 error:
294 os_free(value);
295 wpa_dbus_dict_entry_clear(&entry);
296 dbus_set_error_const(error, DBUS_ERROR_INVALID_ARGS,
297 "invalid message format");
298 return FALSE;
299 }
300
301
302 /**
303 * wpas_dbus_simple_property_getter - Get basic type property
304 * @iter: Message iter to use when appending arguments
305 * @type: DBus type of property (must be basic type)
306 * @val: pointer to place holding property value
307 * @error: On failure an error describing the failure
308 * Returns: TRUE if the request was successful, FALSE if it failed
309 *
310 * Generic getter for basic type properties. Type is required to be basic.
311 */
312 dbus_bool_t wpas_dbus_simple_property_getter(DBusMessageIter *iter,
313 const int type,
314 const void *val,
315 DBusError *error)
316 {
317 DBusMessageIter variant_iter;
318
319 if (!dbus_type_is_basic(type)) {
320 dbus_set_error(error, DBUS_ERROR_FAILED,
321 "%s: given type is not basic", __func__);
322 return FALSE;
323 }
324
325 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
326 wpa_dbus_type_as_string(type),
327 &variant_iter) ||
328 !dbus_message_iter_append_basic(&variant_iter, type, val) ||
329 !dbus_message_iter_close_container(iter, &variant_iter)) {
330 dbus_set_error(error, DBUS_ERROR_FAILED,
331 "%s: error constructing reply", __func__);
332 return FALSE;
333 }
334
335 return TRUE;
336 }
337
338
339 /**
340 * wpas_dbus_simple_property_setter - Set basic type property
341 * @message: Pointer to incoming dbus message
342 * @type: DBus type of property (must be basic type)
343 * @val: pointer to place where value being set will be stored
344 * Returns: TRUE if the request was successful, FALSE if it failed
345 *
346 * Generic setter for basic type properties. Type is required to be basic.
347 */
348 dbus_bool_t wpas_dbus_simple_property_setter(DBusMessageIter *iter,
349 DBusError *error,
350 const int type, void *val)
351 {
352 DBusMessageIter variant_iter;
353
354 if (!dbus_type_is_basic(type)) {
355 dbus_set_error(error, DBUS_ERROR_FAILED,
356 "%s: given type is not basic", __func__);
357 return FALSE;
358 }
359
360 /* Look at the new value */
361 dbus_message_iter_recurse(iter, &variant_iter);
362 if (dbus_message_iter_get_arg_type(&variant_iter) != type) {
363 dbus_set_error_const(error, DBUS_ERROR_FAILED,
364 "wrong property type");
365 return FALSE;
366 }
367 dbus_message_iter_get_basic(&variant_iter, val);
368
369 return TRUE;
370 }
371
372
373 /**
374 * wpas_dbus_simple_array_property_getter - Get array type property
375 * @iter: Pointer to incoming dbus message iterator
376 * @type: DBus type of property array elements (must be basic type)
377 * @array: pointer to array of elements to put into response message
378 * @array_len: length of above array
379 * @error: a pointer to an error to fill on failure
380 * Returns: TRUE if the request succeeded, FALSE if it failed
381 *
382 * Generic getter for array type properties. Array elements type is
383 * required to be basic.
384 */
385 dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
386 const int type,
387 const void *array,
388 size_t array_len,
389 DBusError *error)
390 {
391 DBusMessageIter variant_iter, array_iter;
392 char type_str[] = "a?"; /* ? will be replaced with subtype letter; */
393 const char *sub_type_str;
394 size_t element_size, i;
395
396 if (!dbus_type_is_basic(type)) {
397 dbus_set_error(error, DBUS_ERROR_FAILED,
398 "%s: given type is not basic", __func__);
399 return FALSE;
400 }
401
402 sub_type_str = wpa_dbus_type_as_string(type);
403 type_str[1] = sub_type_str[0];
404
405 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
406 type_str, &variant_iter) ||
407 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
408 sub_type_str, &array_iter)) {
409 dbus_set_error(error, DBUS_ERROR_FAILED,
410 "%s: failed to construct message", __func__);
411 return FALSE;
412 }
413
414 switch (type) {
415 case DBUS_TYPE_BYTE:
416 case DBUS_TYPE_BOOLEAN:
417 element_size = 1;
418 break;
419 case DBUS_TYPE_INT16:
420 case DBUS_TYPE_UINT16:
421 element_size = sizeof(uint16_t);
422 break;
423 case DBUS_TYPE_INT32:
424 case DBUS_TYPE_UINT32:
425 element_size = sizeof(uint32_t);
426 break;
427 case DBUS_TYPE_INT64:
428 case DBUS_TYPE_UINT64:
429 element_size = sizeof(uint64_t);
430 break;
431 case DBUS_TYPE_DOUBLE:
432 element_size = sizeof(double);
433 break;
434 case DBUS_TYPE_STRING:
435 case DBUS_TYPE_OBJECT_PATH:
436 element_size = sizeof(char *);
437 break;
438 default:
439 dbus_set_error(error, DBUS_ERROR_FAILED,
440 "%s: unknown element type %d", __func__, type);
441 return FALSE;
442 }
443
444 for (i = 0; i < array_len; i++) {
445 if (!dbus_message_iter_append_basic(&array_iter, type,
446 (const char *) array +
447 i * element_size)) {
448 dbus_set_error(error, DBUS_ERROR_FAILED,
449 "%s: failed to construct message 2.5",
450 __func__);
451 return FALSE;
452 }
453 }
454
455 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
456 !dbus_message_iter_close_container(iter, &variant_iter)) {
457 dbus_set_error(error, DBUS_ERROR_FAILED,
458 "%s: failed to construct message 3", __func__);
459 return FALSE;
460 }
461
462 return TRUE;
463 }
464
465
466 /**
467 * wpas_dbus_simple_array_array_property_getter - Get array array type property
468 * @iter: Pointer to incoming dbus message iterator
469 * @type: DBus type of property array elements (must be basic type)
470 * @array: pointer to array of elements to put into response message
471 * @array_len: length of above array
472 * @error: a pointer to an error to fill on failure
473 * Returns: TRUE if the request succeeded, FALSE if it failed
474 *
475 * Generic getter for array type properties. Array elements type is
476 * required to be basic.
477 */
478 dbus_bool_t wpas_dbus_simple_array_array_property_getter(DBusMessageIter *iter,
479 const int type,
480 struct wpabuf **array,
481 size_t array_len,
482 DBusError *error)
483 {
484 DBusMessageIter variant_iter, array_iter;
485 char type_str[] = "aa?";
486 char inner_type_str[] = "a?";
487 const char *sub_type_str;
488 size_t i;
489
490 if (!dbus_type_is_basic(type)) {
491 dbus_set_error(error, DBUS_ERROR_FAILED,
492 "%s: given type is not basic", __func__);
493 return FALSE;
494 }
495
496 sub_type_str = wpa_dbus_type_as_string(type);
497 type_str[2] = sub_type_str[0];
498 inner_type_str[1] = sub_type_str[0];
499
500 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
501 type_str, &variant_iter) ||
502 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
503 inner_type_str, &array_iter)) {
504 dbus_set_error(error, DBUS_ERROR_FAILED,
505 "%s: failed to construct message", __func__);
506 return FALSE;
507 }
508
509 for (i = 0; i < array_len && array[i]; i++) {
510 wpa_dbus_dict_bin_array_add_element(&array_iter,
511 wpabuf_head(array[i]),
512 wpabuf_len(array[i]));
513
514 }
515
516 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
517 !dbus_message_iter_close_container(iter, &variant_iter)) {
518 dbus_set_error(error, DBUS_ERROR_FAILED,
519 "%s: failed to close message", __func__);
520 return FALSE;
521 }
522
523 return TRUE;
524 }
525
526
527 /**
528 * wpas_dbus_string_property_getter - Get string type property
529 * @iter: Message iter to use when appending arguments
530 * @val: Pointer to place holding property value, can be %NULL
531 * @error: On failure an error describing the failure
532 * Returns: TRUE if the request was successful, FALSE if it failed
533 *
534 * Generic getter for string type properties. %NULL is converted to an empty
535 * string.
536 */
537 dbus_bool_t wpas_dbus_string_property_getter(DBusMessageIter *iter,
538 const void *val,
539 DBusError *error)
540 {
541 if (!val)
542 val = "";
543 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
544 &val, error);
545 }
546
547
548 /**
549 * wpas_dbus_handler_create_interface - Request registration of a network iface
550 * @message: Pointer to incoming dbus message
551 * @global: %wpa_supplicant global data structure
552 * Returns: The object path of the new interface object,
553 * or a dbus error message with more information
554 *
555 * Handler function for "CreateInterface" method call. Handles requests
556 * by dbus clients to register a network interface that wpa_supplicant
557 * will manage.
558 */
559 DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
560 struct wpa_global *global)
561 {
562 DBusMessageIter iter_dict;
563 DBusMessage *reply = NULL;
564 DBusMessageIter iter;
565 struct wpa_dbus_dict_entry entry;
566 char *driver = NULL;
567 char *ifname = NULL;
568 char *confname = NULL;
569 char *bridge_ifname = NULL;
570
571 dbus_message_iter_init(message, &iter);
572
573 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
574 goto error;
575 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
576 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
577 goto error;
578 if (os_strcmp(entry.key, "Driver") == 0 &&
579 entry.type == DBUS_TYPE_STRING) {
580 os_free(driver);
581 driver = os_strdup(entry.str_value);
582 wpa_dbus_dict_entry_clear(&entry);
583 if (driver == NULL)
584 goto oom;
585 } else if (os_strcmp(entry.key, "Ifname") == 0 &&
586 entry.type == DBUS_TYPE_STRING) {
587 os_free(ifname);
588 ifname = os_strdup(entry.str_value);
589 wpa_dbus_dict_entry_clear(&entry);
590 if (ifname == NULL)
591 goto oom;
592 } else if (os_strcmp(entry.key, "ConfigFile") == 0 &&
593 entry.type == DBUS_TYPE_STRING) {
594 os_free(confname);
595 confname = os_strdup(entry.str_value);
596 wpa_dbus_dict_entry_clear(&entry);
597 if (confname == NULL)
598 goto oom;
599 } else if (os_strcmp(entry.key, "BridgeIfname") == 0 &&
600 entry.type == DBUS_TYPE_STRING) {
601 os_free(bridge_ifname);
602 bridge_ifname = os_strdup(entry.str_value);
603 wpa_dbus_dict_entry_clear(&entry);
604 if (bridge_ifname == NULL)
605 goto oom;
606 } else {
607 wpa_dbus_dict_entry_clear(&entry);
608 goto error;
609 }
610 }
611
612 if (ifname == NULL)
613 goto error; /* Required Ifname argument missing */
614
615 /*
616 * Try to get the wpa_supplicant record for this iface, return
617 * an error if we already control it.
618 */
619 if (wpa_supplicant_get_iface(global, ifname) != NULL) {
620 reply = dbus_message_new_error(
621 message, WPAS_DBUS_ERROR_IFACE_EXISTS,
622 "wpa_supplicant already controls this interface.");
623 } else {
624 struct wpa_supplicant *wpa_s;
625 struct wpa_interface iface;
626
627 os_memset(&iface, 0, sizeof(iface));
628 iface.driver = driver;
629 iface.ifname = ifname;
630 iface.confname = confname;
631 iface.bridge_ifname = bridge_ifname;
632 /* Otherwise, have wpa_supplicant attach to it. */
633 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
634 if (wpa_s && wpa_s->dbus_new_path) {
635 const char *path = wpa_s->dbus_new_path;
636
637 reply = dbus_message_new_method_return(message);
638 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
639 &path, DBUS_TYPE_INVALID);
640 } else {
641 reply = wpas_dbus_error_unknown_error(
642 message,
643 "wpa_supplicant couldn't grab this interface.");
644 }
645 }
646
647 out:
648 os_free(driver);
649 os_free(ifname);
650 os_free(confname);
651 os_free(bridge_ifname);
652 return reply;
653
654 error:
655 reply = wpas_dbus_error_invalid_args(message, NULL);
656 goto out;
657 oom:
658 reply = wpas_dbus_error_no_memory(message);
659 goto out;
660 }
661
662
663 /**
664 * wpas_dbus_handler_remove_interface - Request deregistration of an interface
665 * @message: Pointer to incoming dbus message
666 * @global: wpa_supplicant global data structure
667 * Returns: a dbus message containing a UINT32 indicating success (1) or
668 * failure (0), or returns a dbus error message with more information
669 *
670 * Handler function for "removeInterface" method call. Handles requests
671 * by dbus clients to deregister a network interface that wpa_supplicant
672 * currently manages.
673 */
674 DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
675 struct wpa_global *global)
676 {
677 struct wpa_supplicant *wpa_s;
678 char *path;
679 DBusMessage *reply = NULL;
680
681 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
682 DBUS_TYPE_INVALID);
683
684 wpa_s = get_iface_by_dbus_path(global, path);
685 if (wpa_s == NULL)
686 reply = wpas_dbus_error_iface_unknown(message);
687 else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) {
688 reply = wpas_dbus_error_unknown_error(
689 message,
690 "wpa_supplicant couldn't remove this interface.");
691 }
692
693 return reply;
694 }
695
696
697 /**
698 * wpas_dbus_handler_get_interface - Get the object path for an interface name
699 * @message: Pointer to incoming dbus message
700 * @global: %wpa_supplicant global data structure
701 * Returns: The object path of the interface object,
702 * or a dbus error message with more information
703 *
704 * Handler function for "getInterface" method call.
705 */
706 DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
707 struct wpa_global *global)
708 {
709 DBusMessage *reply = NULL;
710 const char *ifname;
711 const char *path;
712 struct wpa_supplicant *wpa_s;
713
714 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &ifname,
715 DBUS_TYPE_INVALID);
716
717 wpa_s = wpa_supplicant_get_iface(global, ifname);
718 if (wpa_s == NULL || wpa_s->dbus_new_path == NULL)
719 return wpas_dbus_error_iface_unknown(message);
720
721 path = wpa_s->dbus_new_path;
722 reply = dbus_message_new_method_return(message);
723 if (reply == NULL)
724 return wpas_dbus_error_no_memory(message);
725 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
726 DBUS_TYPE_INVALID)) {
727 dbus_message_unref(reply);
728 return wpas_dbus_error_no_memory(message);
729 }
730
731 return reply;
732 }
733
734
735 /**
736 * wpas_dbus_getter_debug_level - Get debug level
737 * @iter: Pointer to incoming dbus message iter
738 * @error: Location to store error on failure
739 * @user_data: Function specific data
740 * Returns: TRUE on success, FALSE on failure
741 *
742 * Getter for "DebugLevel" property.
743 */
744 dbus_bool_t wpas_dbus_getter_debug_level(
745 const struct wpa_dbus_property_desc *property_desc,
746 DBusMessageIter *iter, DBusError *error, void *user_data)
747 {
748 const char *str;
749 int idx = wpa_debug_level;
750
751 if (idx < 0)
752 idx = 0;
753 if (idx > 5)
754 idx = 5;
755 str = debug_strings[idx];
756 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
757 &str, error);
758 }
759
760
761 /**
762 * wpas_dbus_getter_debug_timestamp - Get debug timestamp
763 * @iter: Pointer to incoming dbus message iter
764 * @error: Location to store error on failure
765 * @user_data: Function specific data
766 * Returns: TRUE on success, FALSE on failure
767 *
768 * Getter for "DebugTimestamp" property.
769 */
770 dbus_bool_t wpas_dbus_getter_debug_timestamp(
771 const struct wpa_dbus_property_desc *property_desc,
772 DBusMessageIter *iter, DBusError *error, void *user_data)
773 {
774 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
775 &wpa_debug_timestamp, error);
776
777 }
778
779
780 /**
781 * wpas_dbus_getter_debug_show_keys - Get debug show keys
782 * @iter: Pointer to incoming dbus message iter
783 * @error: Location to store error on failure
784 * @user_data: Function specific data
785 * Returns: TRUE on success, FALSE on failure
786 *
787 * Getter for "DebugShowKeys" property.
788 */
789 dbus_bool_t wpas_dbus_getter_debug_show_keys(
790 const struct wpa_dbus_property_desc *property_desc,
791 DBusMessageIter *iter, DBusError *error, void *user_data)
792 {
793 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
794 &wpa_debug_show_keys, error);
795
796 }
797
798 /**
799 * wpas_dbus_setter_debug_level - Set debug level
800 * @iter: Pointer to incoming dbus message iter
801 * @error: Location to store error on failure
802 * @user_data: Function specific data
803 * Returns: TRUE on success, FALSE on failure
804 *
805 * Setter for "DebugLevel" property.
806 */
807 dbus_bool_t wpas_dbus_setter_debug_level(
808 const struct wpa_dbus_property_desc *property_desc,
809 DBusMessageIter *iter, DBusError *error, void *user_data)
810 {
811 struct wpa_global *global = user_data;
812 const char *str = NULL;
813 int i, val = -1;
814
815 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
816 &str))
817 return FALSE;
818
819 for (i = 0; debug_strings[i]; i++)
820 if (os_strcmp(debug_strings[i], str) == 0) {
821 val = i;
822 break;
823 }
824
825 if (val < 0 ||
826 wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
827 wpa_debug_show_keys)) {
828 dbus_set_error_const(error, DBUS_ERROR_FAILED,
829 "wrong debug level value");
830 return FALSE;
831 }
832
833 return TRUE;
834 }
835
836
837 /**
838 * wpas_dbus_setter_debug_timestamp - Set debug timestamp
839 * @iter: Pointer to incoming dbus message iter
840 * @error: Location to store error on failure
841 * @user_data: Function specific data
842 * Returns: TRUE on success, FALSE on failure
843 *
844 * Setter for "DebugTimestamp" property.
845 */
846 dbus_bool_t wpas_dbus_setter_debug_timestamp(
847 const struct wpa_dbus_property_desc *property_desc,
848 DBusMessageIter *iter, DBusError *error, void *user_data)
849 {
850 struct wpa_global *global = user_data;
851 dbus_bool_t val;
852
853 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
854 &val))
855 return FALSE;
856
857 wpa_supplicant_set_debug_params(global, wpa_debug_level, val ? 1 : 0,
858 wpa_debug_show_keys);
859 return TRUE;
860 }
861
862
863 /**
864 * wpas_dbus_setter_debug_show_keys - Set debug show keys
865 * @iter: Pointer to incoming dbus message iter
866 * @error: Location to store error on failure
867 * @user_data: Function specific data
868 * Returns: TRUE on success, FALSE on failure
869 *
870 * Setter for "DebugShowKeys" property.
871 */
872 dbus_bool_t wpas_dbus_setter_debug_show_keys(
873 const struct wpa_dbus_property_desc *property_desc,
874 DBusMessageIter *iter, DBusError *error, void *user_data)
875 {
876 struct wpa_global *global = user_data;
877 dbus_bool_t val;
878
879 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
880 &val))
881 return FALSE;
882
883 wpa_supplicant_set_debug_params(global, wpa_debug_level,
884 wpa_debug_timestamp,
885 val ? 1 : 0);
886 return TRUE;
887 }
888
889
890 /**
891 * wpas_dbus_getter_interfaces - Request registered interfaces list
892 * @iter: Pointer to incoming dbus message iter
893 * @error: Location to store error on failure
894 * @user_data: Function specific data
895 * Returns: TRUE on success, FALSE on failure
896 *
897 * Getter for "Interfaces" property. Handles requests
898 * by dbus clients to return list of registered interfaces objects
899 * paths
900 */
901 dbus_bool_t wpas_dbus_getter_interfaces(
902 const struct wpa_dbus_property_desc *property_desc,
903 DBusMessageIter *iter, DBusError *error, void *user_data)
904 {
905 struct wpa_global *global = user_data;
906 struct wpa_supplicant *wpa_s;
907 const char **paths;
908 unsigned int i = 0, num = 0;
909 dbus_bool_t success;
910
911 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
912 if (wpa_s->dbus_new_path)
913 num++;
914 }
915
916 paths = os_calloc(num, sizeof(char *));
917 if (!paths) {
918 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
919 return FALSE;
920 }
921
922 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
923 if (wpa_s->dbus_new_path)
924 paths[i++] = wpa_s->dbus_new_path;
925 }
926
927 success = wpas_dbus_simple_array_property_getter(iter,
928 DBUS_TYPE_OBJECT_PATH,
929 paths, num, error);
930
931 os_free(paths);
932 return success;
933 }
934
935
936 /**
937 * wpas_dbus_getter_eap_methods - Request supported EAP methods list
938 * @iter: Pointer to incoming dbus message iter
939 * @error: Location to store error on failure
940 * @user_data: Function specific data
941 * Returns: TRUE on success, FALSE on failure
942 *
943 * Getter for "EapMethods" property. Handles requests
944 * by dbus clients to return list of strings with supported EAP methods
945 */
946 dbus_bool_t wpas_dbus_getter_eap_methods(
947 const struct wpa_dbus_property_desc *property_desc,
948 DBusMessageIter *iter, DBusError *error, void *user_data)
949 {
950 char **eap_methods;
951 size_t num_items = 0;
952 dbus_bool_t success;
953
954 eap_methods = eap_get_names_as_string_array(&num_items);
955 if (!eap_methods) {
956 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
957 return FALSE;
958 }
959
960 success = wpas_dbus_simple_array_property_getter(iter,
961 DBUS_TYPE_STRING,
962 eap_methods,
963 num_items, error);
964
965 while (num_items)
966 os_free(eap_methods[--num_items]);
967 os_free(eap_methods);
968 return success;
969 }
970
971
972 /**
973 * wpas_dbus_getter_global_capabilities - Request supported global capabilities
974 * @iter: Pointer to incoming dbus message iter
975 * @error: Location to store error on failure
976 * @user_data: Function specific data
977 * Returns: TRUE on success, FALSE on failure
978 *
979 * Getter for "Capabilities" property. Handles requests by dbus clients to
980 * return a list of strings with supported capabilities like AP, RSN IBSS,
981 * and P2P that are determined at compile time.
982 */
983 dbus_bool_t wpas_dbus_getter_global_capabilities(
984 const struct wpa_dbus_property_desc *property_desc,
985 DBusMessageIter *iter, DBusError *error, void *user_data)
986 {
987 const char *capabilities[10] = { NULL, NULL, NULL, NULL, NULL, NULL,
988 NULL, NULL, NULL, NULL };
989 size_t num_items = 0;
990 #ifdef CONFIG_FILS
991 struct wpa_global *global = user_data;
992 struct wpa_supplicant *wpa_s;
993 int fils_supported = 0, fils_sk_pfs_supported = 0;
994
995 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
996 if (wpa_is_fils_supported(wpa_s))
997 fils_supported = 1;
998 if (wpa_is_fils_sk_pfs_supported(wpa_s))
999 fils_sk_pfs_supported = 1;
1000 }
1001 #endif /* CONFIG_FILS */
1002
1003 #ifdef CONFIG_AP
1004 capabilities[num_items++] = "ap";
1005 #endif /* CONFIG_AP */
1006 #ifdef CONFIG_IBSS_RSN
1007 capabilities[num_items++] = "ibss-rsn";
1008 #endif /* CONFIG_IBSS_RSN */
1009 #ifdef CONFIG_P2P
1010 capabilities[num_items++] = "p2p";
1011 #endif /* CONFIG_P2P */
1012 #ifdef CONFIG_INTERWORKING
1013 capabilities[num_items++] = "interworking";
1014 #endif /* CONFIG_INTERWORKING */
1015 #ifdef CONFIG_IEEE80211W
1016 capabilities[num_items++] = "pmf";
1017 #endif /* CONFIG_IEEE80211W */
1018 #ifdef CONFIG_MESH
1019 capabilities[num_items++] = "mesh";
1020 #endif /* CONFIG_MESH */
1021 #ifdef CONFIG_FILS
1022 if (fils_supported)
1023 capabilities[num_items++] = "fils";
1024 if (fils_sk_pfs_supported)
1025 capabilities[num_items++] = "fils_sk_pfs";
1026 #endif /* CONFIG_FILS */
1027 #ifdef CONFIG_IEEE80211R
1028 capabilities[num_items++] = "ft";
1029 #endif /* CONFIG_IEEE80211R */
1030 #ifdef CONFIG_SHA384
1031 capabilities[num_items++] = "sha384";
1032 #endif /* CONFIG_SHA384 */
1033
1034 return wpas_dbus_simple_array_property_getter(iter,
1035 DBUS_TYPE_STRING,
1036 capabilities,
1037 num_items, error);
1038 }
1039
1040
1041 static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
1042 char **type, DBusMessage **reply)
1043 {
1044 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
1045 wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a string",
1046 __func__);
1047 *reply = wpas_dbus_error_invalid_args(
1048 message, "Wrong Type value type. String required");
1049 return -1;
1050 }
1051 dbus_message_iter_get_basic(var, type);
1052 return 0;
1053 }
1054
1055
1056 static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
1057 struct wpa_driver_scan_params *params,
1058 DBusMessage **reply)
1059 {
1060 struct wpa_driver_scan_ssid *ssids = params->ssids;
1061 size_t ssids_num = 0;
1062 u8 *ssid;
1063 DBusMessageIter array_iter, sub_array_iter;
1064 char *val;
1065 int len;
1066
1067 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1068 wpa_printf(MSG_DEBUG,
1069 "%s[dbus]: ssids must be an array of arrays of bytes",
1070 __func__);
1071 *reply = wpas_dbus_error_invalid_args(
1072 message,
1073 "Wrong SSIDs value type. Array of arrays of bytes required");
1074 return -1;
1075 }
1076
1077 dbus_message_iter_recurse(var, &array_iter);
1078
1079 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
1080 dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE) {
1081 wpa_printf(MSG_DEBUG,
1082 "%s[dbus]: ssids must be an array of arrays of bytes",
1083 __func__);
1084 *reply = wpas_dbus_error_invalid_args(
1085 message,
1086 "Wrong SSIDs value type. Array of arrays of bytes required");
1087 return -1;
1088 }
1089
1090 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) {
1091 if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
1092 wpa_printf(MSG_DEBUG,
1093 "%s[dbus]: Too many ssids specified on scan dbus call",
1094 __func__);
1095 *reply = wpas_dbus_error_invalid_args(
1096 message,
1097 "Too many ssids specified. Specify at most four");
1098 return -1;
1099 }
1100
1101 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1102
1103 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1104
1105 if (len > SSID_MAX_LEN) {
1106 wpa_printf(MSG_DEBUG,
1107 "%s[dbus]: SSID too long (len=%d max_len=%d)",
1108 __func__, len, SSID_MAX_LEN);
1109 *reply = wpas_dbus_error_invalid_args(
1110 message, "Invalid SSID: too long");
1111 return -1;
1112 }
1113
1114 if (len != 0) {
1115 ssid = os_memdup(val, len);
1116 if (ssid == NULL) {
1117 *reply = wpas_dbus_error_no_memory(message);
1118 return -1;
1119 }
1120 } else {
1121 /* Allow zero-length SSIDs */
1122 ssid = NULL;
1123 }
1124
1125 ssids[ssids_num].ssid = ssid;
1126 ssids[ssids_num].ssid_len = len;
1127
1128 dbus_message_iter_next(&array_iter);
1129 ssids_num++;
1130 }
1131
1132 params->num_ssids = ssids_num;
1133 return 0;
1134 }
1135
1136
1137 static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
1138 struct wpa_driver_scan_params *params,
1139 DBusMessage **reply)
1140 {
1141 u8 *ies = NULL, *nies;
1142 int ies_len = 0;
1143 DBusMessageIter array_iter, sub_array_iter;
1144 char *val;
1145 int len;
1146
1147 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1148 wpa_printf(MSG_DEBUG,
1149 "%s[dbus]: ies must be an array of arrays of bytes",
1150 __func__);
1151 *reply = wpas_dbus_error_invalid_args(
1152 message,
1153 "Wrong IEs value type. Array of arrays of bytes required");
1154 return -1;
1155 }
1156
1157 dbus_message_iter_recurse(var, &array_iter);
1158
1159 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
1160 dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE) {
1161 wpa_printf(MSG_DEBUG,
1162 "%s[dbus]: ies must be an array of arrays of bytes",
1163 __func__);
1164 *reply = wpas_dbus_error_invalid_args(
1165 message, "Wrong IEs value type. Array required");
1166 return -1;
1167 }
1168
1169 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) {
1170 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1171
1172 dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
1173 if (len == 0) {
1174 dbus_message_iter_next(&array_iter);
1175 continue;
1176 }
1177
1178 nies = os_realloc(ies, ies_len + len);
1179 if (nies == NULL) {
1180 os_free(ies);
1181 *reply = wpas_dbus_error_no_memory(message);
1182 return -1;
1183 }
1184 ies = nies;
1185 os_memcpy(ies + ies_len, val, len);
1186 ies_len += len;
1187
1188 dbus_message_iter_next(&array_iter);
1189 }
1190
1191 params->extra_ies = ies;
1192 params->extra_ies_len = ies_len;
1193 return 0;
1194 }
1195
1196
1197 static int wpas_dbus_get_scan_channels(DBusMessage *message,
1198 DBusMessageIter *var,
1199 struct wpa_driver_scan_params *params,
1200 DBusMessage **reply)
1201 {
1202 DBusMessageIter array_iter, sub_array_iter;
1203 int *freqs = NULL, *nfreqs;
1204 int freqs_num = 0;
1205
1206 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
1207 wpa_printf(MSG_DEBUG,
1208 "%s[dbus]: Channels must be an array of structs",
1209 __func__);
1210 *reply = wpas_dbus_error_invalid_args(
1211 message,
1212 "Wrong Channels value type. Array of structs required");
1213 return -1;
1214 }
1215
1216 dbus_message_iter_recurse(var, &array_iter);
1217
1218 if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
1219 wpa_printf(MSG_DEBUG,
1220 "%s[dbus]: Channels must be an array of structs",
1221 __func__);
1222 *reply = wpas_dbus_error_invalid_args(
1223 message,
1224 "Wrong Channels value type. Array of structs required");
1225 return -1;
1226 }
1227
1228 while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_STRUCT)
1229 {
1230 int freq, width;
1231
1232 dbus_message_iter_recurse(&array_iter, &sub_array_iter);
1233
1234 if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
1235 DBUS_TYPE_UINT32) {
1236 wpa_printf(MSG_DEBUG,
1237 "%s[dbus]: Channel must by specified by struct of two UINT32s %c",
1238 __func__,
1239 dbus_message_iter_get_arg_type(
1240 &sub_array_iter));
1241 *reply = wpas_dbus_error_invalid_args(
1242 message,
1243 "Wrong Channel struct. Two UINT32s required");
1244 os_free(freqs);
1245 return -1;
1246 }
1247 dbus_message_iter_get_basic(&sub_array_iter, &freq);
1248
1249 if (!dbus_message_iter_next(&sub_array_iter) ||
1250 dbus_message_iter_get_arg_type(&sub_array_iter) !=
1251 DBUS_TYPE_UINT32) {
1252 wpa_printf(MSG_DEBUG,
1253 "%s[dbus]: Channel must by specified by struct of two UINT32s",
1254 __func__);
1255 *reply = wpas_dbus_error_invalid_args(
1256 message,
1257 "Wrong Channel struct. Two UINT32s required");
1258 os_free(freqs);
1259 return -1;
1260 }
1261
1262 dbus_message_iter_get_basic(&sub_array_iter, &width);
1263
1264 #define FREQS_ALLOC_CHUNK 32
1265 if (freqs_num % FREQS_ALLOC_CHUNK == 0) {
1266 nfreqs = os_realloc_array(
1267 freqs, freqs_num + FREQS_ALLOC_CHUNK,
1268 sizeof(int));
1269 if (nfreqs == NULL)
1270 os_free(freqs);
1271 freqs = nfreqs;
1272 }
1273 if (freqs == NULL) {
1274 *reply = wpas_dbus_error_no_memory(message);
1275 return -1;
1276 }
1277
1278 freqs[freqs_num] = freq;
1279
1280 freqs_num++;
1281 dbus_message_iter_next(&array_iter);
1282 }
1283
1284 nfreqs = os_realloc_array(freqs, freqs_num + 1, sizeof(int));
1285 if (nfreqs == NULL)
1286 os_free(freqs);
1287 freqs = nfreqs;
1288 if (freqs == NULL) {
1289 *reply = wpas_dbus_error_no_memory(message);
1290 return -1;
1291 }
1292 freqs[freqs_num] = 0;
1293
1294 params->freqs = freqs;
1295 return 0;
1296 }
1297
1298
1299 static int wpas_dbus_get_scan_allow_roam(DBusMessage *message,
1300 DBusMessageIter *var,
1301 dbus_bool_t *allow,
1302 DBusMessage **reply)
1303 {
1304 if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN) {
1305 wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a boolean",
1306 __func__);
1307 *reply = wpas_dbus_error_invalid_args(
1308 message, "Wrong Type value type. Boolean required");
1309 return -1;
1310 }
1311 dbus_message_iter_get_basic(var, allow);
1312 return 0;
1313 }
1314
1315
1316 /**
1317 * wpas_dbus_handler_scan - Request a wireless scan on an interface
1318 * @message: Pointer to incoming dbus message
1319 * @wpa_s: wpa_supplicant structure for a network interface
1320 * Returns: NULL indicating success or DBus error message on failure
1321 *
1322 * Handler function for "Scan" method call of a network device. Requests
1323 * that wpa_supplicant perform a wireless scan as soon as possible
1324 * on a particular wireless interface.
1325 */
1326 DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
1327 struct wpa_supplicant *wpa_s)
1328 {
1329 DBusMessage *reply = NULL;
1330 DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
1331 char *key = NULL, *type = NULL;
1332 struct wpa_driver_scan_params params;
1333 size_t i;
1334 dbus_bool_t allow_roam = 1;
1335
1336 os_memset(&params, 0, sizeof(params));
1337
1338 dbus_message_iter_init(message, &iter);
1339
1340 dbus_message_iter_recurse(&iter, &dict_iter);
1341
1342 while (dbus_message_iter_get_arg_type(&dict_iter) ==
1343 DBUS_TYPE_DICT_ENTRY) {
1344 dbus_message_iter_recurse(&dict_iter, &entry_iter);
1345 dbus_message_iter_get_basic(&entry_iter, &key);
1346 dbus_message_iter_next(&entry_iter);
1347 dbus_message_iter_recurse(&entry_iter, &variant_iter);
1348
1349 if (os_strcmp(key, "Type") == 0) {
1350 if (wpas_dbus_get_scan_type(message, &variant_iter,
1351 &type, &reply) < 0)
1352 goto out;
1353 } else if (os_strcmp(key, "SSIDs") == 0) {
1354 if (wpas_dbus_get_scan_ssids(message, &variant_iter,
1355 &params, &reply) < 0)
1356 goto out;
1357 } else if (os_strcmp(key, "IEs") == 0) {
1358 if (wpas_dbus_get_scan_ies(message, &variant_iter,
1359 &params, &reply) < 0)
1360 goto out;
1361 } else if (os_strcmp(key, "Channels") == 0) {
1362 if (wpas_dbus_get_scan_channels(message, &variant_iter,
1363 &params, &reply) < 0)
1364 goto out;
1365 } else if (os_strcmp(key, "AllowRoam") == 0) {
1366 if (wpas_dbus_get_scan_allow_roam(message,
1367 &variant_iter,
1368 &allow_roam,
1369 &reply) < 0)
1370 goto out;
1371 } else {
1372 wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown argument %s",
1373 __func__, key);
1374 reply = wpas_dbus_error_invalid_args(message, key);
1375 goto out;
1376 }
1377
1378 dbus_message_iter_next(&dict_iter);
1379 }
1380
1381 if (!type) {
1382 wpa_printf(MSG_DEBUG, "%s[dbus]: Scan type not specified",
1383 __func__);
1384 reply = wpas_dbus_error_invalid_args(message, key);
1385 goto out;
1386 }
1387
1388 if (os_strcmp(type, "passive") == 0) {
1389 if (params.num_ssids || params.extra_ies_len) {
1390 wpa_printf(MSG_DEBUG,
1391 "%s[dbus]: SSIDs or IEs specified for passive scan.",
1392 __func__);
1393 reply = wpas_dbus_error_invalid_args(
1394 message,
1395 "You can specify only Channels in passive scan");
1396 goto out;
1397 } else {
1398 if (wpa_s->sched_scanning) {
1399 wpa_printf(MSG_DEBUG,
1400 "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed",
1401 __func__);
1402 wpa_supplicant_cancel_sched_scan(wpa_s);
1403 }
1404
1405 if (params.freqs && params.freqs[0]) {
1406 wpa_s->last_scan_req = MANUAL_SCAN_REQ;
1407 if (wpa_supplicant_trigger_scan(wpa_s,
1408 &params)) {
1409 reply = wpas_dbus_error_scan_error(
1410 message,
1411 "Scan request rejected");
1412 }
1413 } else {
1414 wpa_s->scan_req = MANUAL_SCAN_REQ;
1415 wpa_supplicant_req_scan(wpa_s, 0, 0);
1416 }
1417 }
1418 } else if (os_strcmp(type, "active") == 0) {
1419 if (!params.num_ssids) {
1420 /* Add wildcard ssid */
1421 params.num_ssids++;
1422 }
1423 #ifdef CONFIG_AUTOSCAN
1424 autoscan_deinit(wpa_s);
1425 #endif /* CONFIG_AUTOSCAN */
1426 if (wpa_s->sched_scanning) {
1427 wpa_printf(MSG_DEBUG,
1428 "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed",
1429 __func__);
1430 wpa_supplicant_cancel_sched_scan(wpa_s);
1431 }
1432
1433 wpa_s->last_scan_req = MANUAL_SCAN_REQ;
1434 if (wpa_supplicant_trigger_scan(wpa_s, &params)) {
1435 reply = wpas_dbus_error_scan_error(
1436 message, "Scan request rejected");
1437 }
1438 } else {
1439 wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown scan type: %s",
1440 __func__, type);
1441 reply = wpas_dbus_error_invalid_args(message,
1442 "Wrong scan type");
1443 goto out;
1444 }
1445
1446 if (!allow_roam)
1447 wpa_s->scan_res_handler = scan_only_handler;
1448
1449 out:
1450 for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
1451 os_free((u8 *) params.ssids[i].ssid);
1452 os_free((u8 *) params.extra_ies);
1453 os_free(params.freqs);
1454 return reply;
1455 }
1456
1457
1458 /*
1459 * wpas_dbus_handler_abort_scan - Request an ongoing scan to be aborted
1460 * @message: Pointer to incoming dbus message
1461 * @wpa_s: wpa_supplicant structure for a network interface
1462 * Returns: Abort failed or no scan in progress DBus error message on failure
1463 * or NULL otherwise.
1464 *
1465 * Handler function for "AbortScan" method call of network interface.
1466 */
1467 DBusMessage * wpas_dbus_handler_abort_scan(DBusMessage *message,
1468 struct wpa_supplicant *wpa_s)
1469 {
1470 if (wpas_abort_ongoing_scan(wpa_s) < 0)
1471 return dbus_message_new_error(
1472 message, WPAS_DBUS_ERROR_IFACE_SCAN_ERROR,
1473 "Abort failed or no scan in progress");
1474
1475 return NULL;
1476 }
1477
1478
1479 /**
1480 * wpas_dbus_handler_signal_poll - Request immediate signal properties
1481 * @message: Pointer to incoming dbus message
1482 * @wpa_s: wpa_supplicant structure for a network interface
1483 * Returns: NULL indicating success or DBus error message on failure
1484 *
1485 * Handler function for "SignalPoll" method call of a network device. Requests
1486 * that wpa_supplicant read signal properties like RSSI, noise, and link
1487 * speed and return them.
1488 */
1489 DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message,
1490 struct wpa_supplicant *wpa_s)
1491 {
1492 struct wpa_signal_info si;
1493 DBusMessage *reply = NULL;
1494 DBusMessageIter iter, iter_dict, variant_iter;
1495 int ret;
1496
1497 ret = wpa_drv_signal_poll(wpa_s, &si);
1498 if (ret) {
1499 return dbus_message_new_error(message, DBUS_ERROR_FAILED,
1500 "Failed to read signal");
1501 }
1502
1503 reply = dbus_message_new_method_return(message);
1504 if (reply == NULL)
1505 goto nomem;
1506
1507 dbus_message_iter_init_append(reply, &iter);
1508
1509 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
1510 "a{sv}", &variant_iter) ||
1511 !wpa_dbus_dict_open_write(&variant_iter, &iter_dict) ||
1512 !wpa_dbus_dict_append_int32(&iter_dict, "rssi",
1513 si.current_signal) ||
1514 !wpa_dbus_dict_append_int32(&iter_dict, "linkspeed",
1515 si.current_txrate / 1000) ||
1516 !wpa_dbus_dict_append_int32(&iter_dict, "noise",
1517 si.current_noise) ||
1518 !wpa_dbus_dict_append_uint32(&iter_dict, "frequency",
1519 si.frequency) ||
1520 (si.chanwidth != CHAN_WIDTH_UNKNOWN &&
1521 !wpa_dbus_dict_append_string(
1522 &iter_dict, "width",
1523 channel_width_to_string(si.chanwidth))) ||
1524 (si.center_frq1 > 0 && si.center_frq2 > 0 &&
1525 (!wpa_dbus_dict_append_int32(&iter_dict, "center-frq1",
1526 si.center_frq1) ||
1527 !wpa_dbus_dict_append_int32(&iter_dict, "center-frq2",
1528 si.center_frq2))) ||
1529 (si.avg_signal &&
1530 !wpa_dbus_dict_append_int32(&iter_dict, "avg-rssi",
1531 si.avg_signal)) ||
1532 !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
1533 !dbus_message_iter_close_container(&iter, &variant_iter))
1534 goto nomem;
1535
1536 return reply;
1537
1538 nomem:
1539 if (reply)
1540 dbus_message_unref(reply);
1541 return wpas_dbus_error_no_memory(message);
1542 }
1543
1544
1545 /*
1546 * wpas_dbus_handler_disconnect - Terminate the current connection
1547 * @message: Pointer to incoming dbus message
1548 * @wpa_s: wpa_supplicant structure for a network interface
1549 * Returns: NotConnected DBus error message if already not connected
1550 * or NULL otherwise.
1551 *
1552 * Handler function for "Disconnect" method call of network interface.
1553 */
1554 DBusMessage * wpas_dbus_handler_disconnect(DBusMessage *message,
1555 struct wpa_supplicant *wpa_s)
1556 {
1557 if (wpa_s->current_ssid != NULL) {
1558 wpas_request_disconnection(wpa_s);
1559 return NULL;
1560 }
1561
1562 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
1563 "This interface is not connected");
1564 }
1565
1566
1567 /**
1568 * wpas_dbus_new_iface_add_network - Add a new configured network
1569 * @message: Pointer to incoming dbus message
1570 * @wpa_s: wpa_supplicant structure for a network interface
1571 * Returns: A dbus message containing the object path of the new network
1572 *
1573 * Handler function for "AddNetwork" method call of a network interface.
1574 */
1575 DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
1576 struct wpa_supplicant *wpa_s)
1577 {
1578 DBusMessage *reply = NULL;
1579 DBusMessageIter iter;
1580 struct wpa_ssid *ssid = NULL;
1581 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *path = path_buf;
1582 DBusError error;
1583
1584 dbus_message_iter_init(message, &iter);
1585
1586 if (wpa_s->dbus_new_path)
1587 ssid = wpa_supplicant_add_network(wpa_s);
1588 if (ssid == NULL) {
1589 wpa_printf(MSG_ERROR, "%s[dbus]: can't add new interface.",
1590 __func__);
1591 reply = wpas_dbus_error_unknown_error(
1592 message,
1593 "wpa_supplicant could not add a network on this interface.");
1594 goto err;
1595 }
1596
1597 dbus_error_init(&error);
1598 if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
1599 wpa_printf(MSG_DEBUG,
1600 "%s[dbus]: control interface couldn't set network properties",
1601 __func__);
1602 reply = wpas_dbus_reply_new_from_error(message, &error,
1603 DBUS_ERROR_INVALID_ARGS,
1604 "Failed to add network");
1605 dbus_error_free(&error);
1606 goto err;
1607 }
1608
1609 /* Construct the object path for this network. */
1610 os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
1611 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
1612 wpa_s->dbus_new_path, ssid->id);
1613
1614 reply = dbus_message_new_method_return(message);
1615 if (reply == NULL) {
1616 reply = wpas_dbus_error_no_memory(message);
1617 goto err;
1618 }
1619 if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
1620 DBUS_TYPE_INVALID)) {
1621 dbus_message_unref(reply);
1622 reply = wpas_dbus_error_no_memory(message);
1623 goto err;
1624 }
1625
1626 return reply;
1627
1628 err:
1629 if (ssid) {
1630 wpas_notify_network_removed(wpa_s, ssid);
1631 wpa_config_remove_network(wpa_s->conf, ssid->id);
1632 }
1633 return reply;
1634 }
1635
1636
1637 /**
1638 * wpas_dbus_handler_reassociate - Reassociate
1639 * @message: Pointer to incoming dbus message
1640 * @wpa_s: wpa_supplicant structure for a network interface
1641 * Returns: InterfaceDisabled DBus error message if disabled
1642 * or NULL otherwise.
1643 *
1644 * Handler function for "Reassociate" method call of network interface.
1645 */
1646 DBusMessage * wpas_dbus_handler_reassociate(DBusMessage *message,
1647 struct wpa_supplicant *wpa_s)
1648 {
1649 if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) {
1650 wpas_request_connection(wpa_s);
1651 return NULL;
1652 }
1653
1654 return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_DISABLED,
1655 "This interface is disabled");
1656 }
1657
1658
1659 /**
1660 * wpas_dbus_handler_expect_disconnect - ExpectDisconnect
1661 * @message: Pointer to incoming dbus message
1662 * @global: %wpa_supplicant global data structure
1663 * Returns: NULL
1664 *
1665 * Handler function for notifying system there will be a expected disconnect.
1666 * This will prevent wpa_supplicant from adding blacklists upon next disconnect..
1667 */
1668 DBusMessage * wpas_dbus_handler_expect_disconnect(DBusMessage *message,
1669 struct wpa_global *global)
1670 {
1671 struct wpa_supplicant *wpa_s = global->ifaces;
1672
1673 for (; wpa_s; wpa_s = wpa_s->next)
1674 if (wpa_s->wpa_state >= WPA_ASSOCIATED)
1675 wpa_s->own_disconnect_req = 1;
1676 return NULL;
1677 }
1678
1679
1680 /**
1681 * wpas_dbus_handler_reattach - Reattach to current AP
1682 * @message: Pointer to incoming dbus message
1683 * @wpa_s: wpa_supplicant structure for a network interface
1684 * Returns: NotConnected DBus error message if not connected
1685 * or NULL otherwise.
1686 *
1687 * Handler function for "Reattach" method call of network interface.
1688 */
1689 DBusMessage * wpas_dbus_handler_reattach(DBusMessage *message,
1690 struct wpa_supplicant *wpa_s)
1691 {
1692 if (wpa_s->current_ssid != NULL) {
1693 wpa_s->reattach = 1;
1694 wpas_request_connection(wpa_s);
1695 return NULL;
1696 }
1697
1698 return dbus_message_new_error(message, WPAS_DBUS_ERROR_NOT_CONNECTED,
1699 "This interface is not connected");
1700 }
1701
1702
1703 /**
1704 * wpas_dbus_handler_reconnect - Reconnect if disconnected
1705 * @message: Pointer to incoming dbus message
1706 * @wpa_s: wpa_supplicant structure for a network interface
1707 * Returns: InterfaceDisabled DBus error message if disabled
1708 * or NULL otherwise.
1709 *
1710 * Handler function for "Reconnect" method call of network interface.
1711 */
1712 DBusMessage * wpas_dbus_handler_reconnect(DBusMessage *message,
1713 struct wpa_supplicant *wpa_s)
1714 {
1715 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
1716 return dbus_message_new_error(message,
1717 WPAS_DBUS_ERROR_IFACE_DISABLED,
1718 "This interface is disabled");
1719 }
1720
1721 if (wpa_s->disconnected)
1722 wpas_request_connection(wpa_s);
1723 return NULL;
1724 }
1725
1726
1727 /**
1728 * wpas_dbus_handler_remove_network - Remove a configured network
1729 * @message: Pointer to incoming dbus message
1730 * @wpa_s: wpa_supplicant structure for a network interface
1731 * Returns: NULL on success or dbus error on failure
1732 *
1733 * Handler function for "RemoveNetwork" method call of a network interface.
1734 */
1735 DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
1736 struct wpa_supplicant *wpa_s)
1737 {
1738 DBusMessage *reply = NULL;
1739 const char *op;
1740 char *iface, *net_id;
1741 int id;
1742 int result;
1743
1744 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1745 DBUS_TYPE_INVALID);
1746
1747 /* Extract the network ID and ensure the network */
1748 /* is actually a child of this interface */
1749 iface = wpas_dbus_new_decompose_object_path(op,
1750 WPAS_DBUS_NEW_NETWORKS_PART,
1751 &net_id);
1752 if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
1753 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1754 reply = wpas_dbus_error_invalid_args(message, op);
1755 goto out;
1756 }
1757
1758 errno = 0;
1759 id = strtoul(net_id, NULL, 10);
1760 if (errno != 0) {
1761 reply = wpas_dbus_error_invalid_args(message, op);
1762 goto out;
1763 }
1764
1765 result = wpa_supplicant_remove_network(wpa_s, id);
1766 if (result == -1) {
1767 reply = wpas_dbus_error_network_unknown(message);
1768 goto out;
1769 }
1770 if (result == -2) {
1771 wpa_printf(MSG_ERROR,
1772 "%s[dbus]: error occurred when removing network %d",
1773 __func__, id);
1774 reply = wpas_dbus_error_unknown_error(
1775 message,
1776 "error removing the specified network on is interface.");
1777 goto out;
1778 }
1779
1780 out:
1781 os_free(iface);
1782 return reply;
1783 }
1784
1785
1786 static void remove_network(void *arg, struct wpa_ssid *ssid)
1787 {
1788 struct wpa_supplicant *wpa_s = arg;
1789
1790 wpas_notify_network_removed(wpa_s, ssid);
1791
1792 if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) {
1793 wpa_printf(MSG_ERROR,
1794 "%s[dbus]: error occurred when removing network %d",
1795 __func__, ssid->id);
1796 return;
1797 }
1798
1799 if (ssid == wpa_s->current_ssid)
1800 wpa_supplicant_deauthenticate(wpa_s,
1801 WLAN_REASON_DEAUTH_LEAVING);
1802 }
1803
1804
1805 /**
1806 * wpas_dbus_handler_remove_all_networks - Remove all configured networks
1807 * @message: Pointer to incoming dbus message
1808 * @wpa_s: wpa_supplicant structure for a network interface
1809 * Returns: NULL on success or dbus error on failure
1810 *
1811 * Handler function for "RemoveAllNetworks" method call of a network interface.
1812 */
1813 DBusMessage * wpas_dbus_handler_remove_all_networks(
1814 DBusMessage *message, struct wpa_supplicant *wpa_s)
1815 {
1816 if (wpa_s->sched_scanning)
1817 wpa_supplicant_cancel_sched_scan(wpa_s);
1818
1819 /* NB: could check for failure and return an error */
1820 wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s);
1821 return NULL;
1822 }
1823
1824
1825 /**
1826 * wpas_dbus_handler_select_network - Attempt association with a network
1827 * @message: Pointer to incoming dbus message
1828 * @wpa_s: wpa_supplicant structure for a network interface
1829 * Returns: NULL on success or dbus error on failure
1830 *
1831 * Handler function for "SelectNetwork" method call of network interface.
1832 */
1833 DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
1834 struct wpa_supplicant *wpa_s)
1835 {
1836 DBusMessage *reply = NULL;
1837 const char *op;
1838 char *iface, *net_id;
1839 int id;
1840 struct wpa_ssid *ssid;
1841
1842 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &op,
1843 DBUS_TYPE_INVALID);
1844
1845 /* Extract the network ID and ensure the network */
1846 /* is actually a child of this interface */
1847 iface = wpas_dbus_new_decompose_object_path(op,
1848 WPAS_DBUS_NEW_NETWORKS_PART,
1849 &net_id);
1850 if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
1851 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1852 reply = wpas_dbus_error_invalid_args(message, op);
1853 goto out;
1854 }
1855
1856 errno = 0;
1857 id = strtoul(net_id, NULL, 10);
1858 if (errno != 0) {
1859 reply = wpas_dbus_error_invalid_args(message, op);
1860 goto out;
1861 }
1862
1863 ssid = wpa_config_get_network(wpa_s->conf, id);
1864 if (ssid == NULL) {
1865 reply = wpas_dbus_error_network_unknown(message);
1866 goto out;
1867 }
1868
1869 /* Finally, associate with the network */
1870 wpa_supplicant_select_network(wpa_s, ssid);
1871
1872 out:
1873 os_free(iface);
1874 return reply;
1875 }
1876
1877
1878 /**
1879 * wpas_dbus_handler_network_reply - Reply to a NetworkRequest signal
1880 * @message: Pointer to incoming dbus message
1881 * @wpa_s: wpa_supplicant structure for a network interface
1882 * Returns: NULL on success or dbus error on failure
1883 *
1884 * Handler function for "NetworkReply" method call of network interface.
1885 */
1886 DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message,
1887 struct wpa_supplicant *wpa_s)
1888 {
1889 #ifdef IEEE8021X_EAPOL
1890 DBusMessage *reply = NULL;
1891 const char *op, *field, *value;
1892 char *iface, *net_id;
1893 int id;
1894 struct wpa_ssid *ssid;
1895
1896 if (!dbus_message_get_args(message, NULL,
1897 DBUS_TYPE_OBJECT_PATH, &op,
1898 DBUS_TYPE_STRING, &field,
1899 DBUS_TYPE_STRING, &value,
1900 DBUS_TYPE_INVALID))
1901 return wpas_dbus_error_invalid_args(message, NULL);
1902
1903 /* Extract the network ID and ensure the network */
1904 /* is actually a child of this interface */
1905 iface = wpas_dbus_new_decompose_object_path(op,
1906 WPAS_DBUS_NEW_NETWORKS_PART,
1907 &net_id);
1908 if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
1909 os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
1910 reply = wpas_dbus_error_invalid_args(message, op);
1911 goto out;
1912 }
1913
1914 errno = 0;
1915 id = strtoul(net_id, NULL, 10);
1916 if (errno != 0) {
1917 reply = wpas_dbus_error_invalid_args(message, net_id);
1918 goto out;
1919 }
1920
1921 ssid = wpa_config_get_network(wpa_s->conf, id);
1922 if (ssid == NULL) {
1923 reply = wpas_dbus_error_network_unknown(message);
1924 goto out;
1925 }
1926
1927 if (wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid,
1928 field, value) < 0)
1929 reply = wpas_dbus_error_invalid_args(message, field);
1930 else {
1931 /* Tell EAP to retry immediately */
1932 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1933 }
1934
1935 out:
1936 os_free(iface);
1937 return reply;
1938 #else /* IEEE8021X_EAPOL */
1939 wpa_printf(MSG_DEBUG, "dbus: 802.1X not included");
1940 return wpas_dbus_error_unknown_error(message, "802.1X not included");
1941 #endif /* IEEE8021X_EAPOL */
1942 }
1943
1944
1945 #ifndef CONFIG_NO_CONFIG_BLOBS
1946
1947 /**
1948 * wpas_dbus_handler_add_blob - Store named binary blob (ie, for certificates)
1949 * @message: Pointer to incoming dbus message
1950 * @wpa_s: %wpa_supplicant data structure
1951 * Returns: A dbus message containing an error on failure or NULL on success
1952 *
1953 * Asks wpa_supplicant to internally store a binary blobs.
1954 */
1955 DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
1956 struct wpa_supplicant *wpa_s)
1957 {
1958 DBusMessage *reply = NULL;
1959 DBusMessageIter iter, array_iter;
1960
1961 char *blob_name;
1962 u8 *blob_data;
1963 int blob_len;
1964 struct wpa_config_blob *blob = NULL;
1965
1966 dbus_message_iter_init(message, &iter);
1967 dbus_message_iter_get_basic(&iter, &blob_name);
1968
1969 if (wpa_config_get_blob(wpa_s->conf, blob_name)) {
1970 return dbus_message_new_error(message,
1971 WPAS_DBUS_ERROR_BLOB_EXISTS,
1972 NULL);
1973 }
1974
1975 dbus_message_iter_next(&iter);
1976 dbus_message_iter_recurse(&iter, &array_iter);
1977
1978 dbus_message_iter_get_fixed_array(&array_iter, &blob_data, &blob_len);
1979
1980 blob = os_zalloc(sizeof(*blob));
1981 if (!blob) {
1982 reply = wpas_dbus_error_no_memory(message);
1983 goto err;
1984 }
1985
1986 blob->data = os_memdup(blob_data, blob_len);
1987 blob->name = os_strdup(blob_name);
1988 if (!blob->data || !blob->name) {
1989 reply = wpas_dbus_error_no_memory(message);
1990 goto err;
1991 }
1992 blob->len = blob_len;
1993
1994 wpa_config_set_blob(wpa_s->conf, blob);
1995 wpas_notify_blob_added(wpa_s, blob->name);
1996
1997 return reply;
1998
1999 err:
2000 if (blob) {
2001 os_free(blob->name);
2002 os_free(blob->data);
2003 os_free(blob);
2004 }
2005 return reply;
2006 }
2007
2008
2009 /**
2010 * wpas_dbus_handler_get_blob - Get named binary blob (ie, for certificates)
2011 * @message: Pointer to incoming dbus message
2012 * @wpa_s: %wpa_supplicant data structure
2013 * Returns: A dbus message containing array of bytes (blob)
2014 *
2015 * Gets one wpa_supplicant's binary blobs.
2016 */
2017 DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
2018 struct wpa_supplicant *wpa_s)
2019 {
2020 DBusMessage *reply = NULL;
2021 DBusMessageIter iter, array_iter;
2022
2023 char *blob_name;
2024 const struct wpa_config_blob *blob;
2025
2026 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
2027 DBUS_TYPE_INVALID);
2028
2029 blob = wpa_config_get_blob(wpa_s->conf, blob_name);
2030 if (!blob) {
2031 return dbus_message_new_error(message,
2032 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
2033 "Blob id not set");
2034 }
2035
2036 reply = dbus_message_new_method_return(message);
2037 if (!reply)
2038 return wpas_dbus_error_no_memory(message);
2039
2040 dbus_message_iter_init_append(reply, &iter);
2041
2042 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
2043 DBUS_TYPE_BYTE_AS_STRING,
2044 &array_iter) ||
2045 !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
2046 &(blob->data), blob->len) ||
2047 !dbus_message_iter_close_container(&iter, &array_iter)) {
2048 dbus_message_unref(reply);
2049 reply = wpas_dbus_error_no_memory(message);
2050 }
2051
2052 return reply;
2053 }
2054
2055
2056 /**
2057 * wpas_remove_handler_remove_blob - Remove named binary blob
2058 * @message: Pointer to incoming dbus message
2059 * @wpa_s: %wpa_supplicant data structure
2060 * Returns: NULL on success or dbus error
2061 *
2062 * Asks wpa_supplicant to internally remove a binary blobs.
2063 */
2064 DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
2065 struct wpa_supplicant *wpa_s)
2066 {
2067 DBusMessage *reply = NULL;
2068 char *blob_name;
2069
2070 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &blob_name,
2071 DBUS_TYPE_INVALID);
2072
2073 if (wpa_config_remove_blob(wpa_s->conf, blob_name)) {
2074 return dbus_message_new_error(message,
2075 WPAS_DBUS_ERROR_BLOB_UNKNOWN,
2076 "Blob id not set");
2077 }
2078 wpas_notify_blob_removed(wpa_s, blob_name);
2079
2080 return reply;
2081
2082 }
2083
2084 #endif /* CONFIG_NO_CONFIG_BLOBS */
2085
2086
2087 /*
2088 * wpas_dbus_handler_flush_bss - Flush the BSS cache
2089 * @message: Pointer to incoming dbus message
2090 * @wpa_s: wpa_supplicant structure for a network interface
2091 * Returns: NULL
2092 *
2093 * Handler function for "FlushBSS" method call of network interface.
2094 */
2095 DBusMessage * wpas_dbus_handler_flush_bss(DBusMessage *message,
2096 struct wpa_supplicant *wpa_s)
2097 {
2098 dbus_uint32_t age;
2099
2100 dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &age,
2101 DBUS_TYPE_INVALID);
2102
2103 if (age == 0)
2104 wpa_bss_flush(wpa_s);
2105 else
2106 wpa_bss_flush_by_age(wpa_s, age);
2107
2108 return NULL;
2109 }
2110
2111
2112 #ifdef CONFIG_AUTOSCAN
2113 /**
2114 * wpas_dbus_handler_autoscan - Set autoscan parameters for the interface
2115 * @message: Pointer to incoming dbus message
2116 * @wpa_s: wpa_supplicant structure for a network interface
2117 * Returns: NULL
2118 *
2119 * Handler function for "AutoScan" method call of network interface.
2120 */
2121 DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message,
2122 struct wpa_supplicant *wpa_s)
2123 {
2124 DBusMessage *reply = NULL;
2125 enum wpa_states state = wpa_s->wpa_state;
2126 char *arg;
2127
2128 dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg,
2129 DBUS_TYPE_INVALID);
2130
2131 if (arg != NULL && os_strlen(arg) > 0) {
2132 char *tmp;
2133
2134 tmp = os_strdup(arg);
2135 if (tmp == NULL) {
2136 reply = wpas_dbus_error_no_memory(message);
2137 } else {
2138 os_free(wpa_s->conf->autoscan);
2139 wpa_s->conf->autoscan = tmp;
2140 if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
2141 autoscan_init(wpa_s, 1);
2142 else if (state == WPA_SCANNING)
2143 wpa_supplicant_reinit_autoscan(wpa_s);
2144 }
2145 } else if (arg != NULL && os_strlen(arg) == 0) {
2146 os_free(wpa_s->conf->autoscan);
2147 wpa_s->conf->autoscan = NULL;
2148 autoscan_deinit(wpa_s);
2149 } else
2150 reply = dbus_message_new_error(message,
2151 DBUS_ERROR_INVALID_ARGS,
2152 NULL);
2153
2154 return reply;
2155 }
2156 #endif /* CONFIG_AUTOSCAN */
2157
2158
2159 /*
2160 * wpas_dbus_handler_eap_logoff - IEEE 802.1X EAPOL state machine logoff
2161 * @message: Pointer to incoming dbus message
2162 * @wpa_s: wpa_supplicant structure for a network interface
2163 * Returns: NULL
2164 *
2165 * Handler function for "EAPLogoff" method call of network interface.
2166 */
2167 DBusMessage * wpas_dbus_handler_eap_logoff(DBusMessage *message,
2168 struct wpa_supplicant *wpa_s)
2169 {
2170 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
2171 return NULL;
2172 }
2173
2174
2175 /*
2176 * wpas_dbus_handler_eap_logon - IEEE 802.1X EAPOL state machine logon
2177 * @message: Pointer to incoming dbus message
2178 * @wpa_s: wpa_supplicant structure for a network interface
2179 * Returns: NULL
2180 *
2181 * Handler function for "EAPLogin" method call of network interface.
2182 */
2183 DBusMessage * wpas_dbus_handler_eap_logon(DBusMessage *message,
2184 struct wpa_supplicant *wpa_s)
2185 {
2186 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
2187 return NULL;
2188 }
2189
2190
2191 #ifdef CONFIG_TDLS
2192
2193 static int get_peer_hwaddr_helper(DBusMessage *message, const char *func_name,
2194 u8 *peer_address, DBusMessage **error)
2195 {
2196 const char *peer_string;
2197
2198 *error = NULL;
2199
2200 if (!dbus_message_get_args(message, NULL,
2201 DBUS_TYPE_STRING, &peer_string,
2202 DBUS_TYPE_INVALID)) {
2203 *error = wpas_dbus_error_invalid_args(message, NULL);
2204 return -1;
2205 }
2206
2207 if (hwaddr_aton(peer_string, peer_address)) {
2208 wpa_printf(MSG_DEBUG, "%s: invalid address '%s'",
2209 func_name, peer_string);
2210 *error = wpas_dbus_error_invalid_args(
2211 message, "Invalid hardware address format");
2212 return -1;
2213 }
2214
2215 return 0;
2216 }
2217
2218
2219 /*
2220 * wpas_dbus_handler_tdls_discover - Discover TDLS peer
2221 * @message: Pointer to incoming dbus message
2222 * @wpa_s: wpa_supplicant structure for a network interface
2223 * Returns: NULL indicating success or DBus error message on failure
2224 *
2225 * Handler function for "TDLSDiscover" method call of network interface.
2226 */
2227 DBusMessage * wpas_dbus_handler_tdls_discover(DBusMessage *message,
2228 struct wpa_supplicant *wpa_s)
2229 {
2230 u8 peer[ETH_ALEN];
2231 DBusMessage *error_reply;
2232 int ret;
2233
2234 if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
2235 return error_reply;
2236
2237 wpa_printf(MSG_DEBUG, "DBUS TDLS_DISCOVER " MACSTR, MAC2STR(peer));
2238
2239 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2240 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
2241 else
2242 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
2243
2244 if (ret) {
2245 return wpas_dbus_error_unknown_error(
2246 message, "error performing TDLS discovery");
2247 }
2248
2249 return NULL;
2250 }
2251
2252
2253 /*
2254 * wpas_dbus_handler_tdls_setup - Setup TDLS session
2255 * @message: Pointer to incoming dbus message
2256 * @wpa_s: wpa_supplicant structure for a network interface
2257 * Returns: NULL indicating success or DBus error message on failure
2258 *
2259 * Handler function for "TDLSSetup" method call of network interface.
2260 */
2261 DBusMessage * wpas_dbus_handler_tdls_setup(DBusMessage *message,
2262 struct wpa_supplicant *wpa_s)
2263 {
2264 u8 peer[ETH_ALEN];
2265 DBusMessage *error_reply;
2266 int ret;
2267
2268 if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
2269 return error_reply;
2270
2271 wpa_printf(MSG_DEBUG, "DBUS TDLS_SETUP " MACSTR, MAC2STR(peer));
2272
2273 wpa_tdls_remove(wpa_s->wpa, peer);
2274 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2275 ret = wpa_tdls_start(wpa_s->wpa, peer);
2276 else
2277 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
2278
2279 if (ret) {
2280 return wpas_dbus_error_unknown_error(
2281 message, "error performing TDLS setup");
2282 }
2283
2284 return NULL;
2285 }
2286
2287
2288 /*
2289 * wpas_dbus_handler_tdls_status - Return TDLS session status
2290 * @message: Pointer to incoming dbus message
2291 * @wpa_s: wpa_supplicant structure for a network interface
2292 * Returns: A string representing the state of the link to this TDLS peer
2293 *
2294 * Handler function for "TDLSStatus" method call of network interface.
2295 */
2296 DBusMessage * wpas_dbus_handler_tdls_status(DBusMessage *message,
2297 struct wpa_supplicant *wpa_s)
2298 {
2299 u8 peer[ETH_ALEN];
2300 DBusMessage *reply;
2301 const char *tdls_status;
2302
2303 if (get_peer_hwaddr_helper(message, __func__, peer, &reply) < 0)
2304 return reply;
2305
2306 wpa_printf(MSG_DEBUG, "DBUS TDLS_STATUS " MACSTR, MAC2STR(peer));
2307
2308 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
2309
2310 reply = dbus_message_new_method_return(message);
2311 dbus_message_append_args(reply, DBUS_TYPE_STRING,
2312 &tdls_status, DBUS_TYPE_INVALID);
2313 return reply;
2314 }
2315
2316
2317 /*
2318 * wpas_dbus_handler_tdls_teardown - Teardown TDLS session
2319 * @message: Pointer to incoming dbus message
2320 * @wpa_s: wpa_supplicant structure for a network interface
2321 * Returns: NULL indicating success or DBus error message on failure
2322 *
2323 * Handler function for "TDLSTeardown" method call of network interface.
2324 */
2325 DBusMessage * wpas_dbus_handler_tdls_teardown(DBusMessage *message,
2326 struct wpa_supplicant *wpa_s)
2327 {
2328 u8 peer[ETH_ALEN];
2329 DBusMessage *error_reply;
2330 int ret;
2331
2332 if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
2333 return error_reply;
2334
2335 wpa_printf(MSG_DEBUG, "DBUS TDLS_TEARDOWN " MACSTR, MAC2STR(peer));
2336
2337 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2338 ret = wpa_tdls_teardown_link(
2339 wpa_s->wpa, peer,
2340 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
2341 else
2342 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
2343
2344 if (ret) {
2345 return wpas_dbus_error_unknown_error(
2346 message, "error performing TDLS teardown");
2347 }
2348
2349 return NULL;
2350 }
2351
2352 /*
2353 * wpas_dbus_handler_tdls_channel_switch - Enable channel switching with TDLS peer
2354 * @message: Pointer to incoming dbus message
2355 * @wpa_s: wpa_supplicant structure for a network interface
2356 * Returns: NULL indicating success or DBus error message on failure
2357 *
2358 * Handler function for "TDLSChannelSwitch" method call of network interface.
2359 */
2360 DBusMessage *
2361 wpas_dbus_handler_tdls_channel_switch(DBusMessage *message,
2362 struct wpa_supplicant *wpa_s)
2363 {
2364 DBusMessageIter iter, iter_dict;
2365 struct wpa_dbus_dict_entry entry;
2366 u8 peer[ETH_ALEN];
2367 struct hostapd_freq_params freq_params;
2368 u8 oper_class = 0;
2369 int ret;
2370 int is_peer_present = 0;
2371
2372 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
2373 wpa_printf(MSG_INFO,
2374 "tdls_chanswitch: Only supported with external setup");
2375 return wpas_dbus_error_unknown_error(message, "TDLS is not using external setup");
2376 }
2377
2378 os_memset(&freq_params, 0, sizeof(freq_params));
2379
2380 dbus_message_iter_init(message, &iter);
2381
2382 if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
2383 return wpas_dbus_error_invalid_args(message, NULL);
2384
2385 while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
2386 if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
2387 return wpas_dbus_error_invalid_args(message, NULL);
2388
2389 if (os_strcmp(entry.key, "PeerAddress") == 0 &&
2390 entry.type == DBUS_TYPE_STRING) {
2391 if (hwaddr_aton(entry.str_value, peer)) {
2392 wpa_printf(MSG_DEBUG,
2393 "tdls_chanswitch: Invalid address '%s'",
2394 entry.str_value);
2395 wpa_dbus_dict_entry_clear(&entry);
2396 return wpas_dbus_error_invalid_args(message,
2397 NULL);
2398 }
2399
2400 is_peer_present = 1;
2401 } else if (os_strcmp(entry.key, "OperClass") == 0 &&
2402 entry.type == DBUS_TYPE_BYTE) {
2403 oper_class = entry.byte_value;
2404 } else if (os_strcmp(entry.key, "Frequency") == 0 &&
2405 entry.type == DBUS_TYPE_UINT32) {
2406 freq_params.freq = entry.uint32_value;
2407 } else if (os_strcmp(entry.key, "SecChannelOffset") == 0 &&
2408 entry.type == DBUS_TYPE_UINT32) {
2409 freq_params.sec_channel_offset = entry.uint32_value;
2410 } else if (os_strcmp(entry.key, "CenterFrequency1") == 0 &&
2411 entry.type == DBUS_TYPE_UINT32) {
2412 freq_params.center_freq1 = entry.uint32_value;
2413 } else if (os_strcmp(entry.key, "CenterFrequency2") == 0 &&
2414 entry.type == DBUS_TYPE_UINT32) {
2415 freq_params.center_freq2 = entry.uint32_value;
2416 } else if (os_strcmp(entry.key, "Bandwidth") == 0 &&
2417 entry.type == DBUS_TYPE_UINT32) {
2418 freq_params.bandwidth = entry.uint32_value;
2419 } else if (os_strcmp(entry.key, "HT") == 0 &&
2420 entry.type == DBUS_TYPE_BOOLEAN) {
2421 freq_params.ht_enabled = entry.bool_value;
2422 } else if (os_strcmp(entry.key, "VHT") == 0 &&
2423 entry.type == DBUS_TYPE_BOOLEAN) {
2424 freq_params.vht_enabled = entry.bool_value;
2425 } else {
2426 wpa_dbus_dict_entry_clear(&entry);
2427 return wpas_dbus_error_invalid_args(message, NULL);
2428 }
2429
2430 wpa_dbus_dict_entry_clear(&entry);
2431 }
2432
2433 if (oper_class == 0) {
2434 wpa_printf(MSG_INFO,
2435 "tdls_chanswitch: Invalid op class provided");
2436 return wpas_dbus_error_invalid_args(
2437 message, "Invalid op class provided");
2438 }
2439
2440 if (freq_params.freq == 0) {
2441 wpa_printf(MSG_INFO,
2442 "tdls_chanswitch: Invalid freq provided");
2443 return wpas_dbus_error_invalid_args(message,
2444 "Invalid freq provided");
2445 }
2446
2447 if (is_peer_present == 0) {
2448 wpa_printf(MSG_DEBUG,
2449 "tdls_chanswitch: peer address not provided");
2450 return wpas_dbus_error_invalid_args(
2451 message, "peer address not provided");
2452 }
2453
2454 wpa_printf(MSG_DEBUG, "dbus: TDLS_CHAN_SWITCH " MACSTR
2455 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
2456 MAC2STR(peer), oper_class, freq_params.freq,
2457 freq_params.center_freq1, freq_params.center_freq2,
2458 freq_params.bandwidth, freq_params.sec_channel_offset,
2459 freq_params.ht_enabled ? " HT" : "",
2460 freq_params.vht_enabled ? " VHT" : "");
2461
2462 ret = wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
2463 &freq_params);
2464 if (ret)
2465 return wpas_dbus_error_unknown_error(
2466 message, "error processing TDLS channel switch");
2467
2468 return NULL;
2469 }
2470
2471 /*
2472 * wpas_dbus_handler_tdls_cancel_channel_switch - Disable channel switching with TDLS peer
2473 * @message: Pointer to incoming dbus message
2474 * @wpa_s: wpa_supplicant structure for a network interface
2475 * Returns: NULL indicating success or DBus error message on failure
2476 *
2477 * Handler function for "TDLSCancelChannelSwitch" method call of network
2478 * interface.
2479 */
2480 DBusMessage *
2481 wpas_dbus_handler_tdls_cancel_channel_switch(DBusMessage *message,
2482 struct wpa_supplicant *wpa_s)
2483 {
2484 u8 peer[ETH_ALEN];
2485 DBusMessage *error_reply;
2486 int ret;
2487
2488 if (get_peer_hwaddr_helper(message, __func__, peer, &error_reply) < 0)
2489 return error_reply;
2490
2491 wpa_printf(MSG_DEBUG, "dbus: TDLS_CANCEL_CHAN_SWITCH " MACSTR,
2492 MAC2STR(peer));
2493
2494 ret = wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
2495 if (ret)
2496 return wpas_dbus_error_unknown_error(
2497 message, "error canceling TDLS channel switch");
2498
2499 return NULL;
2500 }
2501
2502 #endif /* CONFIG_TDLS */
2503
2504
2505 #ifndef CONFIG_NO_CONFIG_WRITE
2506 /**
2507 * wpas_dbus_handler_save_config - Save configuration to configuration file
2508 * @message: Pointer to incoming dbus message
2509 * @wpa_s: wpa_supplicant structure for a network interface
2510 * Returns: NULL on Success, Otherwise errror message
2511 *
2512 * Handler function for "SaveConfig" method call of network interface.
2513 */
2514 DBusMessage * wpas_dbus_handler_save_config(DBusMessage *message,
2515 struct wpa_supplicant *wpa_s)
2516 {
2517 int ret;
2518
2519 if (!wpa_s->conf->update_config) {
2520 return wpas_dbus_error_unknown_error(
2521 message,
2522 "Not allowed to update configuration (update_config=0)");
2523 }
2524
2525 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2526 if (ret)
2527 return wpas_dbus_error_unknown_error(
2528 message, "Failed to update configuration");
2529 return NULL;
2530 }
2531 #endif /* CONFIG_NO_CONFIG_WRITE */
2532
2533
2534 /**
2535 * wpas_dbus_handler_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
2536 * @message: Pointer to incoming dbus message
2537 * @wpa_s: %wpa_supplicant data structure
2538 * Returns: A dbus message containing an error on failure or NULL on success
2539 *
2540 * Sets the PKCS #11 engine and module path.
2541 */
2542 DBusMessage * wpas_dbus_handler_set_pkcs11_engine_and_module_path(
2543 DBusMessage *message, struct wpa_supplicant *wpa_s)
2544 {
2545 DBusMessageIter iter;
2546 char *value = NULL;
2547 char *pkcs11_engine_path = NULL;
2548 char *pkcs11_module_path = NULL;
2549
2550 dbus_message_iter_init(message, &iter);
2551 dbus_message_iter_get_basic(&iter, &value);
2552 if (value == NULL) {
2553 return dbus_message_new_error(
2554 message, DBUS_ERROR_INVALID_ARGS,
2555 "Invalid pkcs11_engine_path argument");
2556 }
2557 /* Empty path defaults to NULL */
2558 if (os_strlen(value))
2559 pkcs11_engine_path = value;
2560
2561 dbus_message_iter_next(&iter);
2562 dbus_message_iter_get_basic(&iter, &value);
2563 if (value == NULL) {
2564 os_free(pkcs11_engine_path);
2565 return dbus_message_new_error(
2566 message, DBUS_ERROR_INVALID_ARGS,
2567 "Invalid pkcs11_module_path argument");
2568 }
2569 /* Empty path defaults to NULL */
2570 if (os_strlen(value))
2571 pkcs11_module_path = value;
2572
2573 if (wpas_set_pkcs11_engine_and_module_path(wpa_s, pkcs11_engine_path,
2574 pkcs11_module_path))
2575 return dbus_message_new_error(
2576 message, DBUS_ERROR_FAILED,
2577 "Reinit of the EAPOL state machine with the new PKCS #11 engine and module path failed.");
2578
2579 if (wpa_s->dbus_new_path) {
2580 wpa_dbus_mark_property_changed(
2581 wpa_s->global->dbus, wpa_s->dbus_new_path,
2582 WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11EnginePath");
2583 wpa_dbus_mark_property_changed(
2584 wpa_s->global->dbus, wpa_s->dbus_new_path,
2585 WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11ModulePath");
2586 }
2587
2588 return NULL;
2589 }
2590
2591
2592 /**
2593 * wpas_dbus_getter_capabilities - Return interface capabilities
2594 * @iter: Pointer to incoming dbus message iter
2595 * @error: Location to store error on failure
2596 * @user_data: Function specific data
2597 * Returns: TRUE on success, FALSE on failure
2598 *
2599 * Getter for "Capabilities" property of an interface.
2600 */
2601 dbus_bool_t wpas_dbus_getter_capabilities(
2602 const struct wpa_dbus_property_desc *property_desc,
2603 DBusMessageIter *iter, DBusError *error, void *user_data)
2604 {
2605 struct wpa_supplicant *wpa_s = user_data;
2606 struct wpa_driver_capa capa;
2607 int res;
2608 DBusMessageIter iter_dict, iter_dict_entry, iter_dict_val, iter_array,
2609 variant_iter;
2610 const char *scans[] = { "active", "passive", "ssid" };
2611
2612 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
2613 "a{sv}", &variant_iter) ||
2614 !wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
2615 goto nomem;
2616
2617 res = wpa_drv_get_capa(wpa_s, &capa);
2618
2619 /***** pairwise cipher */
2620 if (res < 0) {
2621 const char *args[] = {"ccmp", "tkip", "none"};
2622
2623 if (!wpa_dbus_dict_append_string_array(
2624 &iter_dict, "Pairwise", args,
2625 ARRAY_SIZE(args)))
2626 goto nomem;
2627 } else {
2628 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Pairwise",
2629 &iter_dict_entry,
2630 &iter_dict_val,
2631 &iter_array) ||
2632 ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP_256) &&
2633 !wpa_dbus_dict_string_array_add_element(
2634 &iter_array, "ccmp-256")) ||
2635 ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP_256) &&
2636 !wpa_dbus_dict_string_array_add_element(
2637 &iter_array, "gcmp-256")) ||
2638 ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) &&
2639 !wpa_dbus_dict_string_array_add_element(
2640 &iter_array, "ccmp")) ||
2641 ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) &&
2642 !wpa_dbus_dict_string_array_add_element(
2643 &iter_array, "gcmp")) ||
2644 ((capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) &&
2645 !wpa_dbus_dict_string_array_add_element(
2646 &iter_array, "tkip")) ||
2647 ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) &&
2648 !wpa_dbus_dict_string_array_add_element(
2649 &iter_array, "none")) ||
2650 !wpa_dbus_dict_end_string_array(&iter_dict,
2651 &iter_dict_entry,
2652 &iter_dict_val,
2653 &iter_array))
2654 goto nomem;
2655 }
2656
2657 /***** group cipher */
2658 if (res < 0) {
2659 const char *args[] = {
2660 "ccmp", "tkip", "wep104", "wep40"
2661 };
2662
2663 if (!wpa_dbus_dict_append_string_array(
2664 &iter_dict, "Group", args,
2665 ARRAY_SIZE(args)))
2666 goto nomem;
2667 } else {
2668 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Group",
2669 &iter_dict_entry,
2670 &iter_dict_val,
2671 &iter_array) ||
2672 ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP_256) &&
2673 !wpa_dbus_dict_string_array_add_element(
2674 &iter_array, "ccmp-256")) ||
2675 ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP_256) &&
2676 !wpa_dbus_dict_string_array_add_element(
2677 &iter_array, "gcmp-256")) ||
2678 ((capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) &&
2679 !wpa_dbus_dict_string_array_add_element(
2680 &iter_array, "ccmp")) ||
2681 ((capa.enc & WPA_DRIVER_CAPA_ENC_GCMP) &&
2682 !wpa_dbus_dict_string_array_add_element(
2683 &iter_array, "gcmp")) ||
2684 ((capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) &&
2685 !wpa_dbus_dict_string_array_add_element(
2686 &iter_array, "tkip")) ||
2687 ((capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) &&
2688 !wpa_dbus_dict_string_array_add_element(
2689 &iter_array, "wep104")) ||
2690 ((capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) &&
2691 !wpa_dbus_dict_string_array_add_element(
2692 &iter_array, "wep40")) ||
2693 !wpa_dbus_dict_end_string_array(&iter_dict,
2694 &iter_dict_entry,
2695 &iter_dict_val,
2696 &iter_array))
2697 goto nomem;
2698 }
2699
2700 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "GroupMgmt",
2701 &iter_dict_entry,
2702 &iter_dict_val,
2703 &iter_array) ||
2704 (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP) &&
2705 !wpa_dbus_dict_string_array_add_element(
2706 &iter_array, "aes-128-cmac")) ||
2707 (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP_GMAC_128) &&
2708 !wpa_dbus_dict_string_array_add_element(
2709 &iter_array, "bip-gmac-128")) ||
2710 (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP_GMAC_256) &&
2711 !wpa_dbus_dict_string_array_add_element(
2712 &iter_array, "bip-gmac-256")) ||
2713 (res == 0 && (capa.enc & WPA_DRIVER_CAPA_ENC_BIP_CMAC_256) &&
2714 !wpa_dbus_dict_string_array_add_element(
2715 &iter_array, "bip-cmac-256")) ||
2716 !wpa_dbus_dict_end_string_array(&iter_dict,
2717 &iter_dict_entry,
2718 &iter_dict_val,
2719 &iter_array))
2720 goto nomem;
2721
2722 /***** key management */
2723 if (res < 0) {
2724 const char *args[] = {
2725 "wpa-psk", "wpa-eap", "ieee8021x", "wpa-none",
2726 #ifdef CONFIG_WPS
2727 "wps",
2728 #endif /* CONFIG_WPS */
2729 "none"
2730 };
2731 if (!wpa_dbus_dict_append_string_array(
2732 &iter_dict, "KeyMgmt", args,
2733 ARRAY_SIZE(args)))
2734 goto nomem;
2735 } else {
2736 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "KeyMgmt",
2737 &iter_dict_entry,
2738 &iter_dict_val,
2739 &iter_array) ||
2740 !wpa_dbus_dict_string_array_add_element(&iter_array,
2741 "none") ||
2742 !wpa_dbus_dict_string_array_add_element(&iter_array,
2743 "ieee8021x"))
2744 goto nomem;
2745
2746 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2747 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2748 if (!wpa_dbus_dict_string_array_add_element(
2749 &iter_array, "wpa-eap") ||
2750 ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) &&
2751 !wpa_dbus_dict_string_array_add_element(
2752 &iter_array, "wpa-ft-eap")))
2753 goto nomem;
2754
2755 /* TODO: Ensure that driver actually supports sha256 encryption. */
2756 #ifdef CONFIG_IEEE80211W
2757 if (!wpa_dbus_dict_string_array_add_element(
2758 &iter_array, "wpa-eap-sha256"))
2759 goto nomem;
2760 #endif /* CONFIG_IEEE80211W */
2761 }
2762
2763 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2764 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2765 if (!wpa_dbus_dict_string_array_add_element(
2766 &iter_array, "wpa-psk") ||
2767 ((capa.key_mgmt &
2768 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) &&
2769 !wpa_dbus_dict_string_array_add_element(
2770 &iter_array, "wpa-ft-psk")))
2771 goto nomem;
2772
2773 /* TODO: Ensure that driver actually supports sha256 encryption. */
2774 #ifdef CONFIG_IEEE80211W
2775 if (!wpa_dbus_dict_string_array_add_element(
2776 &iter_array, "wpa-psk-sha256"))
2777 goto nomem;
2778 #endif /* CONFIG_IEEE80211W */
2779 }
2780
2781 if ((capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) &&
2782 !wpa_dbus_dict_string_array_add_element(&iter_array,
2783 "wpa-none"))
2784 goto nomem;
2785
2786
2787 #ifdef CONFIG_WPS
2788 if (!wpa_dbus_dict_string_array_add_element(&iter_array,
2789 "wps"))
2790 goto nomem;
2791 #endif /* CONFIG_WPS */
2792
2793 if (!wpa_dbus_dict_end_string_array(&iter_dict,
2794 &iter_dict_entry,
2795 &iter_dict_val,
2796 &iter_array))
2797 goto nomem;
2798 }
2799
2800 /***** WPA protocol */
2801 if (res < 0) {
2802 const char *args[] = { "rsn", "wpa" };
2803
2804 if (!wpa_dbus_dict_append_string_array(
2805 &iter_dict, "Protocol", args,
2806 ARRAY_SIZE(args)))
2807 goto nomem;
2808 } else {
2809 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Protocol",
2810 &iter_dict_entry,
2811 &iter_dict_val,
2812 &iter_array) ||
2813 ((capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2814 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) &&
2815 !wpa_dbus_dict_string_array_add_element(
2816 &iter_array, "rsn")) ||
2817 ((capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2818 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) &&
2819 !wpa_dbus_dict_string_array_add_element(
2820 &iter_array, "wpa")) ||
2821 !wpa_dbus_dict_end_string_array(&iter_dict,
2822 &iter_dict_entry,
2823 &iter_dict_val,
2824 &iter_array))
2825 goto nomem;
2826 }
2827
2828 /***** auth alg */
2829 if (res < 0) {
2830 const char *args[] = { "open", "shared", "leap" };
2831
2832 if (!wpa_dbus_dict_append_string_array(
2833 &iter_dict, "AuthAlg", args,
2834 ARRAY_SIZE(args)))
2835 goto nomem;
2836 } else {
2837 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "AuthAlg",
2838 &iter_dict_entry,
2839 &iter_dict_val,
2840 &iter_array))
2841 goto nomem;
2842
2843 if (((capa.auth & WPA_DRIVER_AUTH_OPEN) &&
2844 !wpa_dbus_dict_string_array_add_element(
2845 &iter_array, "open")) ||
2846 ((capa.auth & WPA_DRIVER_AUTH_SHARED) &&
2847 !wpa_dbus_dict_string_array_add_element(
2848 &iter_array, "shared")) ||
2849 ((capa.auth & WPA_DRIVER_AUTH_LEAP) &&
2850 !wpa_dbus_dict_string_array_add_element(
2851 &iter_array, "leap")) ||
2852 !wpa_dbus_dict_end_string_array(&iter_dict,
2853 &iter_dict_entry,
2854 &iter_dict_val,
2855 &iter_array))
2856 goto nomem;
2857 }
2858
2859 /***** Scan */
2860 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Scan", scans,
2861 ARRAY_SIZE(scans)))
2862 goto nomem;
2863
2864 /***** Modes */
2865 if (!wpa_dbus_dict_begin_string_array(&iter_dict, "Modes",
2866 &iter_dict_entry,
2867 &iter_dict_val,
2868 &iter_array) ||
2869 !wpa_dbus_dict_string_array_add_element(
2870 &iter_array, "infrastructure") ||
2871 (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_IBSS) &&
2872 !wpa_dbus_dict_string_array_add_element(
2873 &iter_array, "ad-hoc")) ||
2874 (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_AP) &&
2875 !wpa_dbus_dict_string_array_add_element(
2876 &iter_array, "ap")) ||
2877 (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) &&
2878 !wpa_s->conf->p2p_disabled &&
2879 !wpa_dbus_dict_string_array_add_element(
2880 &iter_array, "p2p")) ||
2881 #ifdef CONFIG_MESH
2882 (res >= 0 && (capa.flags & WPA_DRIVER_FLAGS_MESH) &&
2883 !wpa_dbus_dict_string_array_add_element(
2884 &iter_array, "mesh")) ||
2885 #endif /* CONFIG_MESH */
2886 !wpa_dbus_dict_end_string_array(&iter_dict,
2887 &iter_dict_entry,
2888 &iter_dict_val,
2889 &iter_array))
2890 goto nomem;
2891 /***** Modes end */
2892
2893 if (res >= 0) {
2894 dbus_int32_t max_scan_ssid = capa.max_scan_ssids;
2895
2896 if (!wpa_dbus_dict_append_int32(&iter_dict, "MaxScanSSID",
2897 max_scan_ssid))
2898 goto nomem;
2899 }
2900
2901 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
2902 !dbus_message_iter_close_container(iter, &variant_iter))
2903 goto nomem;
2904
2905 return TRUE;
2906
2907 nomem:
2908 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2909 return FALSE;
2910 }
2911
2912
2913 /**
2914 * wpas_dbus_getter_state - Get interface state
2915 * @iter: Pointer to incoming dbus message iter
2916 * @error: Location to store error on failure
2917 * @user_data: Function specific data
2918 * Returns: TRUE on success, FALSE on failure
2919 *
2920 * Getter for "State" property.
2921 */
2922 dbus_bool_t wpas_dbus_getter_state(
2923 const struct wpa_dbus_property_desc *property_desc,
2924 DBusMessageIter *iter, DBusError *error, void *user_data)
2925 {
2926 struct wpa_supplicant *wpa_s = user_data;
2927 const char *str_state;
2928 char *state_ls, *tmp;
2929 dbus_bool_t success = FALSE;
2930
2931 str_state = wpa_supplicant_state_txt(wpa_s->wpa_state);
2932
2933 /* make state string lowercase to fit new DBus API convention
2934 */
2935 state_ls = tmp = os_strdup(str_state);
2936 if (!tmp) {
2937 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
2938 return FALSE;
2939 }
2940 while (*tmp) {
2941 *tmp = tolower(*tmp);
2942 tmp++;
2943 }
2944
2945 success = wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
2946 &state_ls, error);
2947
2948 os_free(state_ls);
2949
2950 return success;
2951 }
2952
2953
2954 /**
2955 * wpas_dbus_new_iface_get_scanning - Get interface scanning state
2956 * @iter: Pointer to incoming dbus message iter
2957 * @error: Location to store error on failure
2958 * @user_data: Function specific data
2959 * Returns: TRUE on success, FALSE on failure
2960 *
2961 * Getter for "scanning" property.
2962 */
2963 dbus_bool_t wpas_dbus_getter_scanning(
2964 const struct wpa_dbus_property_desc *property_desc,
2965 DBusMessageIter *iter, DBusError *error, void *user_data)
2966 {
2967 struct wpa_supplicant *wpa_s = user_data;
2968 dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
2969
2970 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
2971 &scanning, error);
2972 }
2973
2974
2975 /**
2976 * wpas_dbus_getter_ap_scan - Control roaming mode
2977 * @iter: Pointer to incoming dbus message iter
2978 * @error: Location to store error on failure
2979 * @user_data: Function specific data
2980 * Returns: TRUE on success, FALSE on failure
2981 *
2982 * Getter function for "ApScan" property.
2983 */
2984 dbus_bool_t wpas_dbus_getter_ap_scan(
2985 const struct wpa_dbus_property_desc *property_desc,
2986 DBusMessageIter *iter, DBusError *error, void *user_data)
2987 {
2988 struct wpa_supplicant *wpa_s = user_data;
2989 dbus_uint32_t ap_scan = wpa_s->conf->ap_scan;
2990
2991 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
2992 &ap_scan, error);
2993 }
2994
2995
2996 /**
2997 * wpas_dbus_setter_ap_scan - Control roaming mode
2998 * @iter: Pointer to incoming dbus message iter
2999 * @error: Location to store error on failure
3000 * @user_data: Function specific data
3001 * Returns: TRUE on success, FALSE on failure
3002 *
3003 * Setter function for "ApScan" property.
3004 */
3005 dbus_bool_t wpas_dbus_setter_ap_scan(
3006 const struct wpa_dbus_property_desc *property_desc,
3007 DBusMessageIter *iter, DBusError *error, void *user_data)
3008 {
3009 struct wpa_supplicant *wpa_s = user_data;
3010 dbus_uint32_t ap_scan;
3011
3012 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
3013 &ap_scan))
3014 return FALSE;
3015
3016 if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
3017 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3018 "ap_scan must be 0, 1, or 2");
3019 return FALSE;
3020 }
3021 return TRUE;
3022 }
3023
3024
3025 /**
3026 * wpas_dbus_getter_fast_reauth - Control fast
3027 * reauthentication (TLS session resumption)
3028 * @iter: Pointer to incoming dbus message iter
3029 * @error: Location to store error on failure
3030 * @user_data: Function specific data
3031 * Returns: TRUE on success, FALSE on failure
3032 *
3033 * Getter function for "FastReauth" property.
3034 */
3035 dbus_bool_t wpas_dbus_getter_fast_reauth(
3036 const struct wpa_dbus_property_desc *property_desc,
3037 DBusMessageIter *iter, DBusError *error, void *user_data)
3038 {
3039 struct wpa_supplicant *wpa_s = user_data;
3040 dbus_bool_t fast_reauth = wpa_s->conf->fast_reauth ? TRUE : FALSE;
3041
3042 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
3043 &fast_reauth, error);
3044 }
3045
3046
3047 /**
3048 * wpas_dbus_setter_fast_reauth - Control fast
3049 * reauthentication (TLS session resumption)
3050 * @iter: Pointer to incoming dbus message iter
3051 * @error: Location to store error on failure
3052 * @user_data: Function specific data
3053 * Returns: TRUE on success, FALSE on failure
3054 *
3055 * Setter function for "FastReauth" property.
3056 */
3057 dbus_bool_t wpas_dbus_setter_fast_reauth(
3058 const struct wpa_dbus_property_desc *property_desc,
3059 DBusMessageIter *iter, DBusError *error, void *user_data)
3060 {
3061 struct wpa_supplicant *wpa_s = user_data;
3062 dbus_bool_t fast_reauth;
3063
3064 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
3065 &fast_reauth))
3066 return FALSE;
3067
3068 wpa_s->conf->fast_reauth = fast_reauth;
3069 return TRUE;
3070 }
3071
3072
3073 /**
3074 * wpas_dbus_getter_disconnect_reason - Get most recent reason for disconnect
3075 * @iter: Pointer to incoming dbus message iter
3076 * @error: Location to store error on failure
3077 * @user_data: Function specific data
3078 * Returns: TRUE on success, FALSE on failure
3079 *
3080 * Getter for "DisconnectReason" property. The reason is negative if it is
3081 * locally generated.
3082 */
3083 dbus_bool_t wpas_dbus_getter_disconnect_reason(
3084 const struct wpa_dbus_property_desc *property_desc,
3085 DBusMessageIter *iter, DBusError *error, void *user_data)
3086 {
3087 struct wpa_supplicant *wpa_s = user_data;
3088 dbus_int32_t reason = wpa_s->disconnect_reason;
3089
3090 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
3091 &reason, error);
3092 }
3093
3094
3095 /**
3096 * wpas_dbus_getter_assoc_status_code - Get most recent failed assoc status code
3097 * @iter: Pointer to incoming dbus message iter
3098 * @error: Location to store error on failure
3099 * @user_data: Function specific data
3100 * Returns: TRUE on success, FALSE on failure
3101 *
3102 * Getter for "AssocStatusCode" property.
3103 */
3104 dbus_bool_t wpas_dbus_getter_assoc_status_code(
3105 const struct wpa_dbus_property_desc *property_desc,
3106 DBusMessageIter *iter, DBusError *error, void *user_data)
3107 {
3108 struct wpa_supplicant *wpa_s = user_data;
3109 dbus_int32_t status_code = wpa_s->assoc_status_code;
3110
3111 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
3112 &status_code, error);
3113 }
3114
3115
3116 /**
3117 * wpas_dbus_getter_roam_time - Get most recent roam time
3118 * @iter: Pointer to incoming dbus message iter
3119 * @error: Location to store error on failure
3120 * @user_data: Function specific data
3121 * Returns: TRUE on success, FALSE on failure
3122 *
3123 * Getter for "RoamTime" property.
3124 */
3125 dbus_bool_t wpas_dbus_getter_roam_time(
3126 const struct wpa_dbus_property_desc *property_desc,
3127 DBusMessageIter *iter, DBusError *error, void *user_data)
3128 {
3129 struct wpa_supplicant *wpa_s = user_data;
3130 dbus_uint32_t roam_time = wpa_s->roam_time.sec * 1000 +
3131 wpa_s->roam_time.usec / 1000;
3132
3133 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
3134 &roam_time, error);
3135 }
3136
3137
3138 /**
3139 * wpas_dbus_getter_roam_complete - Get most recent roam success or failure
3140 * @iter: Pointer to incoming dbus message iter
3141 * @error: Location to store error on failure
3142 * @user_data: Function specific data
3143 * Returns: TRUE on success, FALSE on failure
3144 *
3145 * Getter for "RoamComplete" property.
3146 */
3147 dbus_bool_t wpas_dbus_getter_roam_complete(
3148 const struct wpa_dbus_property_desc *property_desc,
3149 DBusMessageIter *iter, DBusError *error, void *user_data)
3150 {
3151 struct wpa_supplicant *wpa_s = user_data;
3152 dbus_bool_t roam_complete = os_reltime_initialized(&wpa_s->roam_time);
3153
3154 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
3155 &roam_complete, error);
3156 }
3157
3158
3159 /**
3160 * wpas_dbus_getter_session_length - Get most recent BSS session length
3161 * @iter: Pointer to incoming dbus message iter
3162 * @error: Location to store error on failure
3163 * @user_data: Function specific data
3164 * Returns: TRUE on success, FALSE on failure
3165 *
3166 * Getter for "SessionLength" property.
3167 */
3168 dbus_bool_t wpas_dbus_getter_session_length(
3169 const struct wpa_dbus_property_desc *property_desc,
3170 DBusMessageIter *iter, DBusError *error, void *user_data)
3171 {
3172 struct wpa_supplicant *wpa_s = user_data;
3173 dbus_uint32_t session_length = wpa_s->session_length.sec * 1000 +
3174 wpa_s->session_length.usec / 1000;
3175
3176 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
3177 &session_length, error);
3178 }
3179
3180
3181 /**
3182 * wpas_dbus_getter_bss_tm_status - Get most BSS Transition Management request
3183 * status code
3184 * @iter: Pointer to incoming dbus message iter
3185 * @error: Location to store error on failure
3186 * @user_data: Function specific data
3187 * Returns: TRUE on success, FALSE on failure
3188 *
3189 * Getter for "BSSTMStatus" property.
3190 */
3191 dbus_bool_t wpas_dbus_getter_bss_tm_status(
3192 const struct wpa_dbus_property_desc *property_desc,
3193 DBusMessageIter *iter, DBusError *error, void *user_data)
3194 {
3195 struct wpa_supplicant *wpa_s = user_data;
3196 dbus_uint32_t bss_tm_status = wpa_s->bss_tm_status;
3197
3198 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
3199 &bss_tm_status, error);
3200 }
3201
3202
3203 /**
3204 * wpas_dbus_getter_bss_expire_age - Get BSS entry expiration age
3205 * @iter: Pointer to incoming dbus message iter
3206 * @error: Location to store error on failure
3207 * @user_data: Function specific data
3208 * Returns: TRUE on success, FALSE on failure
3209 *
3210 * Getter function for "BSSExpireAge" property.
3211 */
3212 dbus_bool_t wpas_dbus_getter_bss_expire_age(
3213 const struct wpa_dbus_property_desc *property_desc,
3214 DBusMessageIter *iter, DBusError *error, void *user_data)
3215 {
3216 struct wpa_supplicant *wpa_s = user_data;
3217 dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age;
3218
3219 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
3220 &expire_age, error);
3221 }
3222
3223
3224 /**
3225 * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age
3226 * @iter: Pointer to incoming dbus message iter
3227 * @error: Location to store error on failure
3228 * @user_data: Function specific data
3229 * Returns: TRUE on success, FALSE on failure
3230 *
3231 * Setter function for "BSSExpireAge" property.
3232 */
3233 dbus_bool_t wpas_dbus_setter_bss_expire_age(
3234 const struct wpa_dbus_property_desc *property_desc,
3235 DBusMessageIter *iter, DBusError *error, void *user_data)
3236 {
3237 struct wpa_supplicant *wpa_s = user_data;
3238 dbus_uint32_t expire_age;
3239
3240 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
3241 &expire_age))
3242 return FALSE;
3243
3244 if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) {
3245 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3246 "BSSExpireAge must be >= 10");
3247 return FALSE;
3248 }
3249 return TRUE;
3250 }
3251
3252
3253 /**
3254 * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count
3255 * @iter: Pointer to incoming dbus message iter
3256 * @error: Location to store error on failure
3257 * @user_data: Function specific data
3258 * Returns: TRUE on success, FALSE on failure
3259 *
3260 * Getter function for "BSSExpireCount" property.
3261 */
3262 dbus_bool_t wpas_dbus_getter_bss_expire_count(
3263 const struct wpa_dbus_property_desc *property_desc,
3264 DBusMessageIter *iter, DBusError *error, void *user_data)
3265 {
3266 struct wpa_supplicant *wpa_s = user_data;
3267 dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_scan_count;
3268
3269 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
3270 &expire_count, error);
3271 }
3272
3273
3274 /**
3275 * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count
3276 * @iter: Pointer to incoming dbus message iter
3277 * @error: Location to store error on failure
3278 * @user_data: Function specific data
3279 * Returns: TRUE on success, FALSE on failure
3280 *
3281 * Setter function for "BSSExpireCount" property.
3282 */
3283 dbus_bool_t wpas_dbus_setter_bss_expire_count(
3284 const struct wpa_dbus_property_desc *property_desc,
3285 DBusMessageIter *iter, DBusError *error, void *user_data)
3286 {
3287 struct wpa_supplicant *wpa_s = user_data;
3288 dbus_uint32_t expire_count;
3289
3290 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
3291 &expire_count))
3292 return FALSE;
3293
3294 if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) {
3295 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3296 "BSSExpireCount must be > 0");
3297 return FALSE;
3298 }
3299 return TRUE;
3300 }
3301
3302
3303 /**
3304 * wpas_dbus_getter_country - Control country code
3305 * @iter: Pointer to incoming dbus message iter
3306 * @error: Location to store error on failure
3307 * @user_data: Function specific data
3308 * Returns: TRUE on success, FALSE on failure
3309 *
3310 * Getter function for "Country" property.
3311 */
3312 dbus_bool_t wpas_dbus_getter_country(
3313 const struct wpa_dbus_property_desc *property_desc,
3314 DBusMessageIter *iter, DBusError *error, void *user_data)
3315 {
3316 struct wpa_supplicant *wpa_s = user_data;
3317 char country[3];
3318 char *str = country;
3319
3320 country[0] = wpa_s->conf->country[0];
3321 country[1] = wpa_s->conf->country[1];
3322 country[2] = '\0';
3323
3324 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3325 &str, error);
3326 }
3327
3328
3329 /**
3330 * wpas_dbus_setter_country - Control country code
3331 * @iter: Pointer to incoming dbus message iter
3332 * @error: Location to store error on failure
3333 * @user_data: Function specific data
3334 * Returns: TRUE on success, FALSE on failure
3335 *
3336 * Setter function for "Country" property.
3337 */
3338 dbus_bool_t wpas_dbus_setter_country(
3339 const struct wpa_dbus_property_desc *property_desc,
3340 DBusMessageIter *iter, DBusError *error, void *user_data)
3341 {
3342 struct wpa_supplicant *wpa_s = user_data;
3343 const char *country;
3344
3345 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
3346 &country))
3347 return FALSE;
3348
3349 if (!country[0] || !country[1]) {
3350 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3351 "invalid country code");
3352 return FALSE;
3353 }
3354
3355 if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) {
3356 wpa_printf(MSG_DEBUG, "Failed to set country");
3357 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3358 "failed to set country code");
3359 return FALSE;
3360 }
3361
3362 wpa_s->conf->country[0] = country[0];
3363 wpa_s->conf->country[1] = country[1];
3364 return TRUE;
3365 }
3366
3367
3368 /**
3369 * wpas_dbus_getter_scan_interval - Get scan interval
3370 * @iter: Pointer to incoming dbus message iter
3371 * @error: Location to store error on failure
3372 * @user_data: Function specific data
3373 * Returns: TRUE on success, FALSE on failure
3374 *
3375 * Getter function for "ScanInterval" property.
3376 */
3377 dbus_bool_t wpas_dbus_getter_scan_interval(
3378 const struct wpa_dbus_property_desc *property_desc,
3379 DBusMessageIter *iter, DBusError *error, void *user_data)
3380 {
3381 struct wpa_supplicant *wpa_s = user_data;
3382 dbus_int32_t scan_interval = wpa_s->scan_interval;
3383
3384 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
3385 &scan_interval, error);
3386 }
3387
3388
3389 /**
3390 * wpas_dbus_setter_scan_interval - Control scan interval
3391 * @iter: Pointer to incoming dbus message iter
3392 * @error: Location to store error on failure
3393 * @user_data: Function specific data
3394 * Returns: TRUE on success, FALSE on failure
3395 *
3396 * Setter function for "ScanInterval" property.
3397 */
3398 dbus_bool_t wpas_dbus_setter_scan_interval(
3399 const struct wpa_dbus_property_desc *property_desc,
3400 DBusMessageIter *iter, DBusError *error, void *user_data)
3401 {
3402 struct wpa_supplicant *wpa_s = user_data;
3403 dbus_int32_t scan_interval;
3404
3405 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_INT32,
3406 &scan_interval))
3407 return FALSE;
3408
3409 if (wpa_supplicant_set_scan_interval(wpa_s, scan_interval)) {
3410 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3411 "scan_interval must be >= 0");
3412 return FALSE;
3413 }
3414 return TRUE;
3415 }
3416
3417
3418 /**
3419 * wpas_dbus_getter_ifname - Get interface name
3420 * @iter: Pointer to incoming dbus message iter
3421 * @error: Location to store error on failure
3422 * @user_data: Function specific data
3423 * Returns: TRUE on success, FALSE on failure
3424 *
3425 * Getter for "Ifname" property.
3426 */
3427 dbus_bool_t wpas_dbus_getter_ifname(
3428 const struct wpa_dbus_property_desc *property_desc,
3429 DBusMessageIter *iter, DBusError *error, void *user_data)
3430 {
3431 struct wpa_supplicant *wpa_s = user_data;
3432
3433 return wpas_dbus_string_property_getter(iter, wpa_s->ifname, error);
3434 }
3435
3436
3437 /**
3438 * wpas_dbus_getter_driver - Get interface name
3439 * @iter: Pointer to incoming dbus message iter
3440 * @error: Location to store error on failure
3441 * @user_data: Function specific data
3442 * Returns: TRUE on success, FALSE on failure
3443 *
3444 * Getter for "Driver" property.
3445 */
3446 dbus_bool_t wpas_dbus_getter_driver(
3447 const struct wpa_dbus_property_desc *property_desc,
3448 DBusMessageIter *iter, DBusError *error, void *user_data)
3449 {
3450 struct wpa_supplicant *wpa_s = user_data;
3451
3452 if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
3453 wpa_printf(MSG_DEBUG, "%s[dbus]: wpa_s has no driver set",
3454 __func__);
3455 dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
3456 __func__);
3457 return FALSE;
3458 }
3459
3460 return wpas_dbus_string_property_getter(iter, wpa_s->driver->name,
3461 error);
3462 }
3463
3464
3465 /**
3466 * wpas_dbus_getter_current_bss - Get current bss object path
3467 * @iter: Pointer to incoming dbus message iter
3468 * @error: Location to store error on failure
3469 * @user_data: Function specific data
3470 * Returns: TRUE on success, FALSE on failure
3471 *
3472 * Getter for "CurrentBSS" property.
3473 */
3474 dbus_bool_t wpas_dbus_getter_current_bss(
3475 const struct wpa_dbus_property_desc *property_desc,
3476 DBusMessageIter *iter, DBusError *error, void *user_data)
3477 {
3478 struct wpa_supplicant *wpa_s = user_data;
3479 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
3480
3481 if (wpa_s->current_bss && wpa_s->dbus_new_path)
3482 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3483 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
3484 wpa_s->dbus_new_path, wpa_s->current_bss->id);
3485 else
3486 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
3487
3488 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
3489 &bss_obj_path, error);
3490 }
3491
3492
3493 /**
3494 * wpas_dbus_getter_current_network - Get current network object path
3495 * @iter: Pointer to incoming dbus message iter
3496 * @error: Location to store error on failure
3497 * @user_data: Function specific data
3498 * Returns: TRUE on success, FALSE on failure
3499 *
3500 * Getter for "CurrentNetwork" property.
3501 */
3502 dbus_bool_t wpas_dbus_getter_current_network(
3503 const struct wpa_dbus_property_desc *property_desc,
3504 DBusMessageIter *iter, DBusError *error, void *user_data)
3505 {
3506 struct wpa_supplicant *wpa_s = user_data;
3507 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
3508
3509 if (wpa_s->current_ssid && wpa_s->dbus_new_path)
3510 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3511 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
3512 wpa_s->dbus_new_path, wpa_s->current_ssid->id);
3513 else
3514 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
3515
3516 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
3517 &net_obj_path, error);
3518 }
3519
3520
3521 /**
3522 * wpas_dbus_getter_current_auth_mode - Get current authentication type
3523 * @iter: Pointer to incoming dbus message iter
3524 * @error: Location to store error on failure
3525 * @user_data: Function specific data
3526 * Returns: TRUE on success, FALSE on failure
3527 *
3528 * Getter for "CurrentAuthMode" property.
3529 */
3530 dbus_bool_t wpas_dbus_getter_current_auth_mode(
3531 const struct wpa_dbus_property_desc *property_desc,
3532 DBusMessageIter *iter, DBusError *error, void *user_data)
3533 {
3534 struct wpa_supplicant *wpa_s = user_data;
3535 const char *eap_mode;
3536 const char *auth_mode;
3537 char eap_mode_buf[WPAS_DBUS_AUTH_MODE_MAX];
3538
3539 if (wpa_s->wpa_state != WPA_COMPLETED) {
3540 auth_mode = "INACTIVE";
3541 } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
3542 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
3543 eap_mode = wpa_supplicant_get_eap_mode(wpa_s);
3544 os_snprintf(eap_mode_buf, WPAS_DBUS_AUTH_MODE_MAX,
3545 "EAP-%s", eap_mode);
3546 auth_mode = eap_mode_buf;
3547
3548 } else if (wpa_s->current_ssid) {
3549 auth_mode = wpa_key_mgmt_txt(wpa_s->key_mgmt,
3550 wpa_s->current_ssid->proto);
3551 } else {
3552 auth_mode = "UNKNOWN";
3553 }
3554
3555 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3556 &auth_mode, error);
3557 }
3558
3559
3560 /**
3561 * wpas_dbus_getter_bridge_ifname - Get interface name
3562 * @iter: Pointer to incoming dbus message iter
3563 * @error: Location to store error on failure
3564 * @user_data: Function specific data
3565 * Returns: TRUE on success, FALSE on failure
3566 *
3567 * Getter for "BridgeIfname" property.
3568 */
3569 dbus_bool_t wpas_dbus_getter_bridge_ifname(
3570 const struct wpa_dbus_property_desc *property_desc,
3571 DBusMessageIter *iter, DBusError *error, void *user_data)
3572 {
3573 struct wpa_supplicant *wpa_s = user_data;
3574
3575 return wpas_dbus_string_property_getter(iter, wpa_s->bridge_ifname,
3576 error);
3577 }
3578
3579
3580 /**
3581 * wpas_dbus_getter_config_file - Get interface configuration file path
3582 * @iter: Pointer to incoming dbus message iter
3583 * @error: Location to store error on failure
3584 * @user_data: Function specific data
3585 * Returns: TRUE on success, FALSE on failure
3586 *
3587 * Getter for "ConfigFile" property.
3588 */
3589 dbus_bool_t wpas_dbus_getter_config_file(
3590 const struct wpa_dbus_property_desc *property_desc,
3591 DBusMessageIter *iter, DBusError *error, void *user_data)
3592 {
3593 struct wpa_supplicant *wpa_s = user_data;
3594
3595 return wpas_dbus_string_property_getter(iter, wpa_s->confname, error);
3596 }
3597
3598
3599 /**
3600 * wpas_dbus_getter_bsss - Get array of BSSs objects
3601 * @iter: Pointer to incoming dbus message iter
3602 * @error: Location to store error on failure
3603 * @user_data: Function specific data
3604 * Returns: TRUE on success, FALSE on failure
3605 *
3606 * Getter for "BSSs" property.
3607 */
3608 dbus_bool_t wpas_dbus_getter_bsss(
3609 const struct wpa_dbus_property_desc *property_desc,
3610 DBusMessageIter *iter, DBusError *error, void *user_data)
3611 {
3612 struct wpa_supplicant *wpa_s = user_data;
3613 struct wpa_bss *bss;
3614 char **paths;
3615 unsigned int i = 0;
3616 dbus_bool_t success = FALSE;
3617
3618 if (!wpa_s->dbus_new_path) {
3619 dbus_set_error(error, DBUS_ERROR_FAILED,
3620 "%s: no D-Bus interface", __func__);
3621 return FALSE;
3622 }
3623
3624 paths = os_calloc(wpa_s->num_bss, sizeof(char *));
3625 if (!paths) {
3626 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3627 return FALSE;
3628 }
3629
3630 /* Loop through scan results and append each result's object path */
3631 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3632 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3633 if (paths[i] == NULL) {
3634 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3635 "no memory");
3636 goto out;
3637 }
3638 /* Construct the object path for this BSS. */
3639 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3640 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
3641 wpa_s->dbus_new_path, bss->id);
3642 }
3643
3644 success = wpas_dbus_simple_array_property_getter(iter,
3645 DBUS_TYPE_OBJECT_PATH,
3646 paths, wpa_s->num_bss,
3647 error);
3648
3649 out:
3650 while (i)
3651 os_free(paths[--i]);
3652 os_free(paths);
3653 return success;
3654 }
3655
3656
3657 /**
3658 * wpas_dbus_getter_networks - Get array of networks objects
3659 * @iter: Pointer to incoming dbus message iter
3660 * @error: Location to store error on failure
3661 * @user_data: Function specific data
3662 * Returns: TRUE on success, FALSE on failure
3663 *
3664 * Getter for "Networks" property.
3665 */
3666 dbus_bool_t wpas_dbus_getter_networks(
3667 const struct wpa_dbus_property_desc *property_desc,
3668 DBusMessageIter *iter, DBusError *error, void *user_data)
3669 {
3670 struct wpa_supplicant *wpa_s = user_data;
3671 struct wpa_ssid *ssid;
3672 char **paths;
3673 unsigned int i = 0, num = 0;
3674 dbus_bool_t success = FALSE;
3675
3676 if (!wpa_s->dbus_new_path) {
3677 dbus_set_error(error, DBUS_ERROR_FAILED,
3678 "%s: no D-Bus interface", __func__);
3679 return FALSE;
3680 }
3681
3682 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
3683 if (!network_is_persistent_group(ssid))
3684 num++;
3685
3686 paths = os_calloc(num, sizeof(char *));
3687 if (!paths) {
3688 dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
3689 return FALSE;
3690 }
3691
3692 /* Loop through configured networks and append object path of each */
3693 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
3694 if (network_is_persistent_group(ssid))
3695 continue;
3696 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3697 if (paths[i] == NULL) {
3698 dbus_set_error(error, DBUS_ERROR_NO_MEMORY,
3699 "no memory");
3700 goto out;
3701 }
3702
3703 /* Construct the object path for this network. */
3704 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3705 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
3706 wpa_s->dbus_new_path, ssid->id);
3707 }
3708
3709 success = wpas_dbus_simple_array_property_getter(iter,
3710 DBUS_TYPE_OBJECT_PATH,
3711 paths, num, error);
3712
3713 out:
3714 while (i)
3715 os_free(paths[--i]);
3716 os_free(paths);
3717 return success;
3718 }
3719
3720
3721 /**
3722 * wpas_dbus_getter_pkcs11_engine_path - Get PKCS #11 engine path
3723 * @iter: Pointer to incoming dbus message iter
3724 * @error: Location to store error on failure
3725 * @user_data: Function specific data
3726 * Returns: A dbus message containing the PKCS #11 engine path
3727 *
3728 * Getter for "PKCS11EnginePath" property.
3729 */
3730 dbus_bool_t wpas_dbus_getter_pkcs11_engine_path(
3731 const struct wpa_dbus_property_desc *property_desc,
3732 DBusMessageIter *iter, DBusError *error, void *user_data)
3733 {
3734 struct wpa_supplicant *wpa_s = user_data;
3735
3736 return wpas_dbus_string_property_getter(iter,
3737 wpa_s->conf->pkcs11_engine_path,
3738 error);
3739 }
3740
3741
3742 /**
3743 * wpas_dbus_getter_pkcs11_module_path - Get PKCS #11 module path
3744 * @iter: Pointer to incoming dbus message iter
3745 * @error: Location to store error on failure
3746 * @user_data: Function specific data
3747 * Returns: A dbus message containing the PKCS #11 module path
3748 *
3749 * Getter for "PKCS11ModulePath" property.
3750 */
3751 dbus_bool_t wpas_dbus_getter_pkcs11_module_path(
3752 const struct wpa_dbus_property_desc *property_desc,
3753 DBusMessageIter *iter, DBusError *error, void *user_data)
3754 {
3755 struct wpa_supplicant *wpa_s = user_data;
3756
3757 return wpas_dbus_string_property_getter(iter,
3758 wpa_s->conf->pkcs11_module_path,
3759 error);
3760 }
3761
3762
3763 /**
3764 * wpas_dbus_getter_blobs - Get all blobs defined for this interface
3765 * @iter: Pointer to incoming dbus message iter
3766 * @error: Location to store error on failure
3767 * @user_data: Function specific data
3768 * Returns: TRUE on success, FALSE on failure
3769 *
3770 * Getter for "Blobs" property.
3771 */
3772 dbus_bool_t wpas_dbus_getter_blobs(
3773 const struct wpa_dbus_property_desc *property_desc,
3774 DBusMessageIter *iter, DBusError *error, void *user_data)
3775 {
3776 struct wpa_supplicant *wpa_s = user_data;
3777 DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter;
3778 struct wpa_config_blob *blob;
3779
3780 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
3781 "a{say}", &variant_iter) ||
3782 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
3783 "{say}", &dict_iter)) {
3784 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3785 return FALSE;
3786 }
3787
3788 blob = wpa_s->conf->blobs;
3789 while (blob) {
3790 if (!dbus_message_iter_open_container(&dict_iter,
3791 DBUS_TYPE_DICT_ENTRY,
3792 NULL, &entry_iter) ||
3793 !dbus_message_iter_append_basic(&entry_iter,
3794 DBUS_TYPE_STRING,
3795 &(blob->name)) ||
3796 !dbus_message_iter_open_container(&entry_iter,
3797 DBUS_TYPE_ARRAY,
3798 DBUS_TYPE_BYTE_AS_STRING,
3799 &array_iter) ||
3800 !dbus_message_iter_append_fixed_array(&array_iter,
3801 DBUS_TYPE_BYTE,
3802 &(blob->data),
3803 blob->len) ||
3804 !dbus_message_iter_close_container(&entry_iter,
3805 &array_iter) ||
3806 !dbus_message_iter_close_container(&dict_iter,
3807 &entry_iter)) {
3808 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3809 "no memory");
3810 return FALSE;
3811 }
3812
3813 blob = blob->next;
3814 }
3815
3816 if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
3817 !dbus_message_iter_close_container(iter, &variant_iter)) {
3818 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3819 return FALSE;
3820 }
3821
3822 return TRUE;
3823 }
3824
3825
3826 dbus_bool_t wpas_dbus_getter_iface_global(
3827 const struct wpa_dbus_property_desc *property_desc,
3828 DBusMessageIter *iter, DBusError *error, void *user_data)
3829 {
3830 struct wpa_supplicant *wpa_s = user_data;
3831 int ret;
3832 char buf[250];
3833 char *p = buf;
3834
3835 if (!property_desc->data) {
3836 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
3837 "Unhandled interface property %s",
3838 property_desc->dbus_property);
3839 return FALSE;
3840 }
3841
3842 ret = wpa_config_get_value(property_desc->data, wpa_s->conf, buf,
3843 sizeof(buf));
3844 if (ret < 0)
3845 *p = '\0';
3846
3847 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, &p,
3848 error);
3849 }
3850
3851
3852 dbus_bool_t wpas_dbus_setter_iface_global(
3853 const struct wpa_dbus_property_desc *property_desc,
3854 DBusMessageIter *iter, DBusError *error, void *user_data)
3855 {
3856 struct wpa_supplicant *wpa_s = user_data;
3857 const char *new_value = NULL;
3858 char buf[250];
3859 size_t combined_len;
3860 int ret;
3861
3862 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
3863 &new_value))
3864 return FALSE;
3865
3866 combined_len = os_strlen(property_desc->data) + os_strlen(new_value) +
3867 3;
3868 if (combined_len >= sizeof(buf)) {
3869 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
3870 "Interface property %s value too large",
3871 property_desc->dbus_property);
3872 return FALSE;
3873 }
3874
3875 if (!new_value[0])
3876 new_value = "NULL";
3877
3878 ret = os_snprintf(buf, combined_len, "%s=%s", property_desc->data,
3879 new_value);
3880 if (os_snprintf_error(combined_len, ret)) {
3881 dbus_set_error(error, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
3882 "Failed to construct new interface property %s",
3883 property_desc->dbus_property);
3884 return FALSE;
3885 }
3886
3887 if (wpa_config_process_global(wpa_s->conf, buf, -1)) {
3888 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
3889 "Failed to set interface property %s",
3890 property_desc->dbus_property);
3891 return FALSE;
3892 }
3893
3894 wpa_supplicant_update_config(wpa_s);
3895 return TRUE;
3896 }
3897
3898
3899 /**
3900 * wpas_dbus_getter_stas - Get connected stations for an interface
3901 * @iter: Pointer to incoming dbus message iter
3902 * @error: Location to store error on failure
3903 * @user_data: Function specific data
3904 * Returns: a list of stations
3905 *
3906 * Getter for "Stations" property.
3907 */
3908 dbus_bool_t wpas_dbus_getter_stas(
3909 const struct wpa_dbus_property_desc *property_desc,
3910 DBusMessageIter *iter, DBusError *error, void *user_data)
3911 {
3912 struct wpa_supplicant *wpa_s = user_data;
3913 struct sta_info *sta = NULL;
3914 char **paths = NULL;
3915 unsigned int i = 0, num = 0;
3916 dbus_bool_t success = FALSE;
3917
3918 if (!wpa_s->dbus_new_path) {
3919 dbus_set_error(error, DBUS_ERROR_FAILED,
3920 "%s: no D-Bus interface", __func__);
3921 return FALSE;
3922 }
3923
3924 #ifdef CONFIG_AP
3925 if (wpa_s->ap_iface) {
3926 struct hostapd_data *hapd;
3927
3928 hapd = wpa_s->ap_iface->bss[0];
3929 sta = hapd->sta_list;
3930 num = hapd->num_sta;
3931 }
3932 #endif /* CONFIG_AP */
3933
3934 paths = os_calloc(num, sizeof(char *));
3935 if (!paths) {
3936 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3937 return FALSE;
3938 }
3939
3940 /* Loop through scan results and append each result's object path */
3941 for (; sta; sta = sta->next) {
3942 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3943 if (!paths[i]) {
3944 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3945 "no memory");
3946 goto out;
3947 }
3948 /* Construct the object path for this BSS. */
3949 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3950 "%s/" WPAS_DBUS_NEW_STAS_PART "/" COMPACT_MACSTR,
3951 wpa_s->dbus_new_path, MAC2STR(sta->addr));
3952 }
3953
3954 success = wpas_dbus_simple_array_property_getter(iter,
3955 DBUS_TYPE_OBJECT_PATH,
3956 paths, num,
3957 error);
3958
3959 out:
3960 while (i)
3961 os_free(paths[--i]);
3962 os_free(paths);
3963 return success;
3964 }
3965
3966
3967 /**
3968 * wpas_dbus_getter_sta_address - Return the address of a connected station
3969 * @iter: Pointer to incoming dbus message iter
3970 * @error: Location to store error on failure
3971 * @user_data: Function specific data
3972 * Returns: TRUE on success, FALSE on failure
3973 *
3974 * Getter for "Address" property.
3975 */
3976 dbus_bool_t wpas_dbus_getter_sta_address(
3977 const struct wpa_dbus_property_desc *property_desc,
3978 DBusMessageIter *iter, DBusError *error, void *user_data)
3979 {
3980 #ifdef CONFIG_AP
3981 struct sta_handler_args *args = user_data;
3982 struct sta_info *sta;
3983
3984 sta = ap_get_sta(args->wpa_s->ap_iface->bss[0], args->sta);
3985 if (!sta)
3986 return FALSE;
3987
3988 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3989 sta->addr, ETH_ALEN,
3990 error);
3991 #else /* CONFIG_AP */
3992 return FALSE;
3993 #endif /* CONFIG_AP */
3994 }
3995
3996
3997 /**
3998 * wpas_dbus_getter_sta_aid - Return the AID of a connected station
3999 * @iter: Pointer to incoming dbus message iter
4000 * @error: Location to store error on failure
4001 * @user_data: Function specific data
4002 * Returns: TRUE on success, FALSE on failure
4003 *
4004 * Getter for "AID" property.
4005 */
4006 dbus_bool_t wpas_dbus_getter_sta_aid(
4007 const struct wpa_dbus_property_desc *property_desc,
4008 DBusMessageIter *iter, DBusError *error, void *user_data)
4009 {
4010 #ifdef CONFIG_AP
4011 struct sta_handler_args *args = user_data;
4012 struct sta_info *sta;
4013
4014 sta = ap_get_sta(args->wpa_s->ap_iface->bss[0], args->sta);
4015 if (!sta)
4016 return FALSE;
4017
4018 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
4019 &sta->aid,
4020 error);
4021 #else /* CONFIG_AP */
4022 return FALSE;
4023 #endif /* CONFIG_AP */
4024 }
4025
4026
4027 /**
4028 * wpas_dbus_getter_sta_caps - Return the capabilities of a station
4029 * @iter: Pointer to incoming dbus message iter
4030 * @error: Location to store error on failure
4031 * @user_data: Function specific data
4032 * Returns: TRUE on success, FALSE on failure
4033 *
4034 * Getter for "Capabilities" property.
4035 */
4036 dbus_bool_t wpas_dbus_getter_sta_caps(
4037 const struct wpa_dbus_property_desc *property_desc,
4038 DBusMessageIter *iter, DBusError *error, void *user_data)
4039 {
4040 #ifdef CONFIG_AP
4041 struct sta_handler_args *args = user_data;
4042 struct sta_info *sta;
4043
4044 sta = ap_get_sta(args->wpa_s->ap_iface->bss[0], args->sta);
4045 if (!sta)
4046 return FALSE;
4047
4048 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
4049 &sta->capability,
4050 error);
4051 #else /* CONFIG_AP */
4052 return FALSE;
4053 #endif /* CONFIG_AP */
4054 }
4055
4056
4057 /**
4058 * wpas_dbus_getter_rx_packets - Return the received packets for a station
4059 * @iter: Pointer to incoming dbus message iter
4060 * @error: Location to store error on failure
4061 * @user_data: Function specific data
4062 * Returns: TRUE on success, FALSE on failure
4063 *
4064 * Getter for "RxPackets" property.
4065 */
4066 dbus_bool_t wpas_dbus_getter_sta_rx_packets(
4067 const struct wpa_dbus_property_desc *property_desc,
4068 DBusMessageIter *iter, DBusError *error, void *user_data)
4069 {
4070 #ifdef CONFIG_AP
4071 struct sta_handler_args *args = user_data;
4072 struct sta_info *sta;
4073 struct hostap_sta_driver_data data;
4074 struct hostapd_data *hapd;
4075
4076 if (!args->wpa_s->ap_iface)
4077 return FALSE;
4078
4079 hapd = args->wpa_s->ap_iface->bss[0];
4080 sta = ap_get_sta(hapd, args->sta);
4081 if (!sta)
4082 return FALSE;
4083
4084 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4085 return FALSE;
4086
4087 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4088 &data.rx_packets,
4089 error);
4090 #else /* CONFIG_AP */
4091 return FALSE;
4092 #endif /* CONFIG_AP */
4093 }
4094
4095
4096 /**
4097 * wpas_dbus_getter_tx_packets - Return the transmitted packets for a station
4098 * @iter: Pointer to incoming dbus message iter
4099 * @error: Location to store error on failure
4100 * @user_data: Function specific data
4101 * Returns: TRUE on success, FALSE on failure
4102 *
4103 * Getter for "TxPackets" property.
4104 */
4105 dbus_bool_t wpas_dbus_getter_sta_tx_packets(
4106 const struct wpa_dbus_property_desc *property_desc,
4107 DBusMessageIter *iter, DBusError *error, void *user_data)
4108 {
4109 #ifdef CONFIG_AP
4110 struct sta_handler_args *args = user_data;
4111 struct sta_info *sta;
4112 struct hostap_sta_driver_data data;
4113 struct hostapd_data *hapd;
4114
4115 if (!args->wpa_s->ap_iface)
4116 return FALSE;
4117
4118 hapd = args->wpa_s->ap_iface->bss[0];
4119 sta = ap_get_sta(hapd, args->sta);
4120 if (!sta)
4121 return FALSE;
4122
4123 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4124 return FALSE;
4125
4126 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4127 &data.tx_packets,
4128 error);
4129 #else /* CONFIG_AP */
4130 return FALSE;
4131 #endif /* CONFIG_AP */
4132 }
4133
4134
4135 /**
4136 * wpas_dbus_getter_tx_bytes - Return the transmitted bytes for a station
4137 * @iter: Pointer to incoming dbus message iter
4138 * @error: Location to store error on failure
4139 * @user_data: Function specific data
4140 * Returns: TRUE on success, FALSE on failure
4141 *
4142 * Getter for "TxBytes" property.
4143 */
4144 dbus_bool_t wpas_dbus_getter_sta_tx_bytes(
4145 const struct wpa_dbus_property_desc *property_desc,
4146 DBusMessageIter *iter, DBusError *error, void *user_data)
4147 {
4148 #ifdef CONFIG_AP
4149 struct sta_handler_args *args = user_data;
4150 struct sta_info *sta;
4151 struct hostap_sta_driver_data data;
4152 struct hostapd_data *hapd;
4153
4154 if (!args->wpa_s->ap_iface)
4155 return FALSE;
4156
4157 hapd = args->wpa_s->ap_iface->bss[0];
4158 sta = ap_get_sta(hapd, args->sta);
4159 if (!sta)
4160 return FALSE;
4161
4162 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4163 return FALSE;
4164
4165 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4166 &data.tx_bytes,
4167 error);
4168 #else /* CONFIG_AP */
4169 return FALSE;
4170 #endif /* CONFIG_AP */
4171 }
4172
4173
4174 /**
4175 * wpas_dbus_getter_rx_bytes - Return the received bytes for a station
4176 * @iter: Pointer to incoming dbus message iter
4177 * @error: Location to store error on failure
4178 * @user_data: Function specific data
4179 * Returns: TRUE on success, FALSE on failure
4180 *
4181 * Getter for "RxBytes" property.
4182 */
4183 dbus_bool_t wpas_dbus_getter_sta_rx_bytes(
4184 const struct wpa_dbus_property_desc *property_desc,
4185 DBusMessageIter *iter, DBusError *error, void *user_data)
4186 {
4187 #ifdef CONFIG_AP
4188 struct sta_handler_args *args = user_data;
4189 struct sta_info *sta;
4190 struct hostap_sta_driver_data data;
4191 struct hostapd_data *hapd;
4192
4193 if (!args->wpa_s->ap_iface)
4194 return FALSE;
4195
4196 hapd = args->wpa_s->ap_iface->bss[0];
4197 sta = ap_get_sta(hapd, args->sta);
4198 if (!sta)
4199 return FALSE;
4200
4201 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4202 return FALSE;
4203
4204 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4205 &data.rx_bytes,
4206 error);
4207 #else /* CONFIG_AP */
4208 return FALSE;
4209 #endif /* CONFIG_AP */
4210 }
4211
4212
4213 static struct wpa_bss * get_bss_helper(struct bss_handler_args *args,
4214 DBusError *error, const char *func_name)
4215 {
4216 struct wpa_bss *res = wpa_bss_get_id(args->wpa_s, args->id);
4217
4218 if (!res) {
4219 wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found",
4220 func_name, args->id);
4221 dbus_set_error(error, DBUS_ERROR_FAILED,
4222 "%s: BSS %d not found",
4223 func_name, args->id);
4224 }
4225
4226 return res;
4227 }
4228
4229
4230 /**
4231 * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
4232 * @iter: Pointer to incoming dbus message iter
4233 * @error: Location to store error on failure
4234 * @user_data: Function specific data
4235 * Returns: TRUE on success, FALSE on failure
4236 *
4237 * Getter for "BSSID" property.
4238 */
4239 dbus_bool_t wpas_dbus_getter_bss_bssid(
4240 const struct wpa_dbus_property_desc *property_desc,
4241 DBusMessageIter *iter, DBusError *error, void *user_data)
4242 {
4243 struct bss_handler_args *args = user_data;
4244 struct wpa_bss *res;
4245
4246 res = get_bss_helper(args, error, __func__);
4247 if (!res)
4248 return FALSE;
4249
4250 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
4251 res->bssid, ETH_ALEN,
4252 error);
4253 }
4254
4255
4256 /**
4257 * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
4258 * @iter: Pointer to incoming dbus message iter
4259 * @error: Location to store error on failure
4260 * @user_data: Function specific data
4261 * Returns: TRUE on success, FALSE on failure
4262 *
4263 * Getter for "SSID" property.
4264 */
4265 dbus_bool_t wpas_dbus_getter_bss_ssid(
4266 const struct wpa_dbus_property_desc *property_desc,
4267 DBusMessageIter *iter, DBusError *error, void *user_data)
4268 {
4269 struct bss_handler_args *args = user_data;
4270 struct wpa_bss *res;
4271
4272 res = get_bss_helper(args, error, __func__);
4273 if (!res)
4274 return FALSE;
4275
4276 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
4277 res->ssid, res->ssid_len,
4278 error);
4279 }
4280
4281
4282 /**
4283 * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
4284 * @iter: Pointer to incoming dbus message iter
4285 * @error: Location to store error on failure
4286 * @user_data: Function specific data
4287 * Returns: TRUE on success, FALSE on failure
4288 *
4289 * Getter for "Privacy" property.
4290 */
4291 dbus_bool_t wpas_dbus_getter_bss_privacy(
4292 const struct wpa_dbus_property_desc *property_desc,
4293 DBusMessageIter *iter, DBusError *error, void *user_data)
4294 {
4295 struct bss_handler_args *args = user_data;
4296 struct wpa_bss *res;
4297 dbus_bool_t privacy;
4298
4299 res = get_bss_helper(args, error, __func__);
4300 if (!res)
4301 return FALSE;
4302
4303 privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
4304 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
4305 &privacy, error);
4306 }
4307
4308
4309 /**
4310 * wpas_dbus_getter_bss_mode - Return the mode of a BSS
4311 * @iter: Pointer to incoming dbus message iter
4312 * @error: Location to store error on failure
4313 * @user_data: Function specific data
4314 * Returns: TRUE on success, FALSE on failure
4315 *
4316 * Getter for "Mode" property.
4317 */
4318 dbus_bool_t wpas_dbus_getter_bss_mode(
4319 const struct wpa_dbus_property_desc *property_desc,
4320 DBusMessageIter *iter, DBusError *error, void *user_data)
4321 {
4322 struct bss_handler_args *args = user_data;
4323 struct wpa_bss *res;
4324 const char *mode;
4325 const u8 *mesh;
4326
4327 res = get_bss_helper(args, error, __func__);
4328 if (!res)
4329 return FALSE;
4330 if (bss_is_dmg(res)) {
4331 switch (res->caps & IEEE80211_CAP_DMG_MASK) {
4332 case IEEE80211_CAP_DMG_PBSS:
4333 case IEEE80211_CAP_DMG_IBSS:
4334 mode = "ad-hoc";
4335 break;
4336 case IEEE80211_CAP_DMG_AP:
4337 mode = "infrastructure";
4338 break;
4339 default:
4340 mode = "";
4341 break;
4342 }
4343 } else {
4344 mesh = wpa_bss_get_ie(res, WLAN_EID_MESH_ID);
4345 if (mesh)
4346 mode = "mesh";
4347 else if (res->caps & IEEE80211_CAP_IBSS)
4348 mode = "ad-hoc";
4349 else
4350 mode = "infrastructure";
4351 }
4352
4353 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
4354 &mode, error);
4355 }
4356
4357
4358 /**
4359 * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
4360 * @iter: Pointer to incoming dbus message iter
4361 * @error: Location to store error on failure
4362 * @user_data: Function specific data
4363 * Returns: TRUE on success, FALSE on failure
4364 *
4365 * Getter for "Level" property.
4366 */
4367 dbus_bool_t wpas_dbus_getter_bss_signal(
4368 const struct wpa_dbus_property_desc *property_desc,
4369 DBusMessageIter *iter, DBusError *error, void *user_data)
4370 {
4371 struct bss_handler_args *args = user_data;
4372 struct wpa_bss *res;
4373 s16 level;
4374
4375 res = get_bss_helper(args, error, __func__);
4376 if (!res)
4377 return FALSE;
4378
4379 level = (s16) res->level;
4380 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16,
4381 &level, error);
4382 }
4383
4384
4385 /**
4386 * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
4387 * @iter: Pointer to incoming dbus message iter
4388 * @error: Location to store error on failure
4389 * @user_data: Function specific data
4390 * Returns: TRUE on success, FALSE on failure
4391 *
4392 * Getter for "Frequency" property.
4393 */
4394 dbus_bool_t wpas_dbus_getter_bss_frequency(
4395 const struct wpa_dbus_property_desc *property_desc,
4396 DBusMessageIter *iter, DBusError *error, void *user_data)
4397 {
4398 struct bss_handler_args *args = user_data;
4399 struct wpa_bss *res;
4400 u16 freq;
4401
4402 res = get_bss_helper(args, error, __func__);
4403 if (!res)
4404 return FALSE;
4405
4406 freq = (u16) res->freq;
4407 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
4408 &freq, error);
4409 }
4410
4411
4412 static int cmp_u8s_desc(const void *a, const void *b)
4413 {
4414 return (*(u8 *) b - *(u8 *) a);
4415 }
4416
4417
4418 /**
4419 * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
4420 * @iter: Pointer to incoming dbus message iter
4421 * @error: Location to store error on failure
4422 * @user_data: Function specific data
4423 * Returns: TRUE on success, FALSE on failure
4424 *
4425 * Getter for "Rates" property.
4426 */
4427 dbus_bool_t wpas_dbus_getter_bss_rates(
4428 const struct wpa_dbus_property_desc *property_desc,
4429 DBusMessageIter *iter, DBusError *error, void *user_data)
4430 {
4431 struct bss_handler_args *args = user_data;
4432 struct wpa_bss *res;
4433 u8 *ie_rates = NULL;
4434 u32 *real_rates;
4435 int rates_num, i;
4436 dbus_bool_t success = FALSE;
4437
4438 res = get_bss_helper(args, error, __func__);
4439 if (!res)
4440 return FALSE;
4441
4442 rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
4443 if (rates_num < 0)
4444 return FALSE;
4445
4446 qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
4447
4448 real_rates = os_malloc(sizeof(u32) * rates_num);
4449 if (!real_rates) {
4450 os_free(ie_rates);
4451 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4452 return FALSE;
4453 }
4454
4455 for (i = 0; i < rates_num; i++)
4456 real_rates[i] = ie_rates[i] * 500000;
4457
4458 success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32,
4459 real_rates, rates_num,
4460 error);
4461
4462 os_free(ie_rates);
4463 os_free(real_rates);
4464 return success;
4465 }
4466
4467
4468 static dbus_bool_t wpas_dbus_get_bss_security_prop(
4469 const struct wpa_dbus_property_desc *property_desc,
4470 DBusMessageIter *iter, struct wpa_ie_data *ie_data, DBusError *error)
4471 {
4472 DBusMessageIter iter_dict, variant_iter;
4473 const char *group;
4474 const char *pairwise[5]; /* max 5 pairwise ciphers is supported */
4475 const char *key_mgmt[13]; /* max 13 key managements may be supported */
4476 int n;
4477
4478 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
4479 "a{sv}", &variant_iter))
4480 goto nomem;
4481
4482 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
4483 goto nomem;
4484
4485 /* KeyMgmt */
4486 n = 0;
4487 if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK)
4488 key_mgmt[n++] = "wpa-psk";
4489 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK)
4490 key_mgmt[n++] = "wpa-ft-psk";
4491 if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
4492 key_mgmt[n++] = "wpa-psk-sha256";
4493 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X)
4494 key_mgmt[n++] = "wpa-eap";
4495 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
4496 key_mgmt[n++] = "wpa-ft-eap";
4497 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
4498 key_mgmt[n++] = "wpa-eap-sha256";
4499 #ifdef CONFIG_SUITEB
4500 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B)
4501 key_mgmt[n++] = "wpa-eap-suite-b";
4502 #endif /* CONFIG_SUITEB */
4503 #ifdef CONFIG_SUITEB192
4504 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
4505 key_mgmt[n++] = "wpa-eap-suite-b-192";
4506 #endif /* CONFIG_SUITEB192 */
4507 #ifdef CONFIG_FILS
4508 if (ie_data->key_mgmt & WPA_KEY_MGMT_FILS_SHA256)
4509 key_mgmt[n++] = "wpa-fils-sha256";
4510 if (ie_data->key_mgmt & WPA_KEY_MGMT_FILS_SHA384)
4511 key_mgmt[n++] = "wpa-fils-sha384";
4512 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256)
4513 key_mgmt[n++] = "wpa-ft-fils-sha256";
4514 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384)
4515 key_mgmt[n++] = "wpa-ft-fils-sha384";
4516 #endif /* CONFIG_FILS */
4517 if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
4518 key_mgmt[n++] = "wpa-none";
4519
4520 if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt",
4521 key_mgmt, n))
4522 goto nomem;
4523
4524 /* Group */
4525 switch (ie_data->group_cipher) {
4526 case WPA_CIPHER_WEP40:
4527 group = "wep40";
4528 break;
4529 case WPA_CIPHER_TKIP:
4530 group = "tkip";
4531 break;
4532 case WPA_CIPHER_CCMP:
4533 group = "ccmp";
4534 break;
4535 case WPA_CIPHER_GCMP:
4536 group = "gcmp";
4537 break;
4538 case WPA_CIPHER_WEP104:
4539 group = "wep104";
4540 break;
4541 case WPA_CIPHER_CCMP_256:
4542 group = "ccmp-256";
4543 break;
4544 case WPA_CIPHER_GCMP_256:
4545 group = "gcmp-256";
4546 break;
4547 default:
4548 group = "";
4549 break;
4550 }
4551
4552 if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
4553 goto nomem;
4554
4555 /* Pairwise */
4556 n = 0;
4557 if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
4558 pairwise[n++] = "tkip";
4559 if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
4560 pairwise[n++] = "ccmp";
4561 if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP)
4562 pairwise[n++] = "gcmp";
4563 if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP_256)
4564 pairwise[n++] = "ccmp-256";
4565 if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP_256)
4566 pairwise[n++] = "gcmp-256";
4567
4568 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
4569 pairwise, n))
4570 goto nomem;
4571
4572 /* Management group (RSN only) */
4573 if (ie_data->proto == WPA_PROTO_RSN) {
4574 switch (ie_data->mgmt_group_cipher) {
4575 #ifdef CONFIG_IEEE80211W
4576 case WPA_CIPHER_AES_128_CMAC:
4577 group = "aes128cmac";
4578 break;
4579 #endif /* CONFIG_IEEE80211W */
4580 default:
4581 group = "";
4582 break;
4583 }
4584
4585 if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
4586 group))
4587 goto nomem;
4588 }
4589
4590 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
4591 !dbus_message_iter_close_container(iter, &variant_iter))
4592 goto nomem;
4593
4594 return TRUE;
4595
4596 nomem:
4597 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4598 return FALSE;
4599 }
4600
4601
4602 /**
4603 * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
4604 * @iter: Pointer to incoming dbus message iter
4605 * @error: Location to store error on failure
4606 * @user_data: Function specific data
4607 * Returns: TRUE on success, FALSE on failure
4608 *
4609 * Getter for "WPA" property.
4610 */
4611 dbus_bool_t wpas_dbus_getter_bss_wpa(
4612 const struct wpa_dbus_property_desc *property_desc,
4613 DBusMessageIter *iter, DBusError *error, void *user_data)
4614 {
4615 struct bss_handler_args *args = user_data;
4616 struct wpa_bss *res;
4617 struct wpa_ie_data wpa_data;
4618 const u8 *ie;
4619
4620 res = get_bss_helper(args, error, __func__);
4621 if (!res)
4622 return FALSE;
4623
4624 os_memset(&wpa_data, 0, sizeof(wpa_data));
4625 ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
4626 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
4627 dbus_set_error_const(error, DBUS_ERROR_FAILED,
4628 "failed to parse WPA IE");
4629 return FALSE;
4630 }
4631
4632 return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
4633 }
4634
4635
4636 /**
4637 * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
4638 * @iter: Pointer to incoming dbus message iter
4639 * @error: Location to store error on failure
4640 * @user_data: Function specific data
4641 * Returns: TRUE on success, FALSE on failure
4642 *
4643 * Getter for "RSN" property.
4644 */
4645 dbus_bool_t wpas_dbus_getter_bss_rsn(
4646 const struct wpa_dbus_property_desc *property_desc,
4647 DBusMessageIter *iter, DBusError *error, void *user_data)
4648 {
4649 struct bss_handler_args *args = user_data;
4650 struct wpa_bss *res;
4651 struct wpa_ie_data wpa_data;
4652 const u8 *ie;
4653
4654 res = get_bss_helper(args, error, __func__);
4655 if (!res)
4656 return FALSE;
4657
4658 os_memset(&wpa_data, 0, sizeof(wpa_data));
4659 ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
4660 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
4661 dbus_set_error_const(error, DBUS_ERROR_FAILED,
4662 "failed to parse RSN IE");
4663 return FALSE;
4664 }
4665
4666 return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
4667 }
4668
4669
4670 /**
4671 * wpas_dbus_getter_bss_wps - Return the WPS options of a BSS
4672 * @iter: Pointer to incoming dbus message iter
4673 * @error: Location to store error on failure
4674 * @user_data: Function specific data
4675 * Returns: TRUE on success, FALSE on failure
4676 *
4677 * Getter for "WPS" property.
4678 */
4679 dbus_bool_t wpas_dbus_getter_bss_wps(
4680 const struct wpa_dbus_property_desc *property_desc,
4681 DBusMessageIter *iter, DBusError *error, void *user_data)
4682 {
4683 struct bss_handler_args *args = user_data;
4684 struct wpa_bss *res;
4685 #ifdef CONFIG_WPS
4686 struct wpabuf *wps_ie;
4687 #endif /* CONFIG_WPS */
4688 DBusMessageIter iter_dict, variant_iter;
4689 int wps_support = 0;
4690 const char *type = "";
4691
4692 res = get_bss_helper(args, error, __func__);
4693 if (!res)
4694 return FALSE;
4695
4696 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
4697 "a{sv}", &variant_iter) ||
4698 !wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
4699 goto nomem;
4700
4701 #ifdef CONFIG_WPS
4702 wps_ie = wpa_bss_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
4703 if (wps_ie) {
4704 wps_support = 1;
4705 if (wps_is_selected_pbc_registrar(wps_ie))
4706 type = "pbc";
4707 else if (wps_is_selected_pin_registrar(wps_ie))
4708 type = "pin";
4709
4710 wpabuf_free(wps_ie);
4711 }
4712 #endif /* CONFIG_WPS */
4713
4714 if ((wps_support && !wpa_dbus_dict_append_string(&iter_dict, "Type", type)) ||
4715 !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
4716 !dbus_message_iter_close_container(iter, &variant_iter))
4717 goto nomem;
4718
4719 return TRUE;
4720
4721 nomem:
4722 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4723 return FALSE;
4724 }
4725
4726
4727 /**
4728 * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
4729 * @iter: Pointer to incoming dbus message iter
4730 * @error: Location to store error on failure
4731 * @user_data: Function specific data
4732 * Returns: TRUE on success, FALSE on failure
4733 *
4734 * Getter for "IEs" property.
4735 */
4736 dbus_bool_t wpas_dbus_getter_bss_ies(
4737 const struct wpa_dbus_property_desc *property_desc,
4738 DBusMessageIter *iter, DBusError *error, void *user_data)
4739 {
4740 struct bss_handler_args *args = user_data;
4741 struct wpa_bss *res;
4742
4743 res = get_bss_helper(args, error, __func__);
4744 if (!res)
4745 return FALSE;
4746
4747 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
4748 res + 1, res->ie_len,
4749 error);
4750 }
4751
4752
4753 /**
4754 * wpas_dbus_getter_bss_age - Return time in seconds since BSS was last seen
4755 * @iter: Pointer to incoming dbus message iter
4756 * @error: Location to store error on failure
4757 * @user_data: Function specific data
4758 * Returns: TRUE on success, FALSE on failure
4759 *
4760 * Getter for BSS age
4761 */
4762 dbus_bool_t wpas_dbus_getter_bss_age(
4763 const struct wpa_dbus_property_desc *property_desc,
4764 DBusMessageIter *iter, DBusError *error, void *user_data)
4765 {
4766 struct bss_handler_args *args = user_data;
4767 struct wpa_bss *res;
4768 struct os_reltime now, diff = { 0, 0 };
4769 u32 age;
4770
4771 res = get_bss_helper(args, error, __func__);
4772 if (!res)
4773 return FALSE;
4774
4775 os_get_reltime(&now);
4776 os_reltime_sub(&now, &res->last_update, &diff);
4777 age = diff.sec > 0 ? diff.sec : 0;
4778 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32, &age,
4779 error);
4780 }
4781
4782
4783 /**
4784 * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
4785 * @iter: Pointer to incoming dbus message iter
4786 * @error: Location to store error on failure
4787 * @user_data: Function specific data
4788 * Returns: TRUE on success, FALSE on failure
4789 *
4790 * Getter for "enabled" property of a configured network.
4791 */
4792 dbus_bool_t wpas_dbus_getter_enabled(
4793 const struct wpa_dbus_property_desc *property_desc,
4794 DBusMessageIter *iter, DBusError *error, void *user_data)
4795 {
4796 struct network_handler_args *net = user_data;
4797 dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
4798
4799 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
4800 &enabled, error);
4801 }
4802
4803
4804 /**
4805 * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
4806 * @iter: Pointer to incoming dbus message iter
4807 * @error: Location to store error on failure
4808 * @user_data: Function specific data
4809 * Returns: TRUE on success, FALSE on failure
4810 *
4811 * Setter for "Enabled" property of a configured network.
4812 */
4813 dbus_bool_t wpas_dbus_setter_enabled(
4814 const struct wpa_dbus_property_desc *property_desc,
4815 DBusMessageIter *iter, DBusError *error, void *user_data)
4816 {
4817 struct network_handler_args *net = user_data;
4818 struct wpa_supplicant *wpa_s;
4819 struct wpa_ssid *ssid;
4820 dbus_bool_t enable;
4821
4822 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
4823 &enable))
4824 return FALSE;
4825
4826 wpa_s = net->wpa_s;
4827 ssid = net->ssid;
4828
4829 if (enable)
4830 wpa_supplicant_enable_network(wpa_s, ssid);
4831 else
4832 wpa_supplicant_disable_network(wpa_s, ssid);
4833
4834 return TRUE;
4835 }
4836
4837
4838 /**
4839 * wpas_dbus_getter_network_properties - Get options for a configured network
4840 * @iter: Pointer to incoming dbus message iter
4841 * @error: Location to store error on failure
4842 * @user_data: Function specific data
4843 * Returns: TRUE on success, FALSE on failure
4844 *
4845 * Getter for "Properties" property of a configured network.
4846 */
4847 dbus_bool_t wpas_dbus_getter_network_properties(
4848 const struct wpa_dbus_property_desc *property_desc,
4849 DBusMessageIter *iter, DBusError *error, void *user_data)
4850 {
4851 struct network_handler_args *net = user_data;
4852 DBusMessageIter variant_iter, dict_iter;
4853 char **iterator;
4854 char **props = wpa_config_get_all(net->ssid, 1);
4855 dbus_bool_t success = FALSE;
4856
4857 if (!props) {
4858 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4859 return FALSE;
4860 }
4861
4862 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
4863 &variant_iter) ||
4864 !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
4865 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4866 goto out;
4867 }
4868
4869 iterator = props;
4870 while (*iterator) {
4871 if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
4872 *(iterator + 1))) {
4873 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
4874 "no memory");
4875 goto out;
4876 }
4877 iterator += 2;
4878 }
4879
4880
4881 if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
4882 !dbus_message_iter_close_container(iter, &variant_iter)) {
4883 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4884 goto out;
4885 }
4886
4887 success = TRUE;
4888
4889 out:
4890 iterator = props;
4891 while (*iterator) {
4892 os_free(*iterator);
4893 iterator++;
4894 }
4895 os_free(props);
4896 return success;
4897 }
4898
4899
4900 /**
4901 * wpas_dbus_setter_network_properties - Set options for a configured network
4902 * @iter: Pointer to incoming dbus message iter
4903 * @error: Location to store error on failure
4904 * @user_data: Function specific data
4905 * Returns: TRUE on success, FALSE on failure
4906 *
4907 * Setter for "Properties" property of a configured network.
4908 */
4909 dbus_bool_t wpas_dbus_setter_network_properties(
4910 const struct wpa_dbus_property_desc *property_desc,
4911 DBusMessageIter *iter, DBusError *error, void *user_data)
4912 {
4913 struct network_handler_args *net = user_data;
4914 struct wpa_ssid *ssid = net->ssid;
4915 DBusMessageIter variant_iter;
4916
4917 dbus_message_iter_recurse(iter, &variant_iter);
4918 return set_network_properties(net->wpa_s, ssid, &variant_iter, error);
4919 }
4920
4921
4922 #ifdef CONFIG_AP
4923
4924 DBusMessage * wpas_dbus_handler_subscribe_preq(
4925 DBusMessage *message, struct wpa_supplicant *wpa_s)
4926 {
4927 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
4928 char *name;
4929
4930 if (wpa_s->preq_notify_peer != NULL) {
4931 if (os_strcmp(dbus_message_get_sender(message),
4932 wpa_s->preq_notify_peer) == 0)
4933 return NULL;
4934
4935 return dbus_message_new_error(message,
4936 WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE,
4937 "Another application is already subscribed");
4938 }
4939
4940 name = os_strdup(dbus_message_get_sender(message));
4941 if (!name)
4942 return wpas_dbus_error_no_memory(message);
4943
4944 wpa_s->preq_notify_peer = name;
4945
4946 /* Subscribe to clean up if application closes socket */
4947 wpas_dbus_subscribe_noc(priv);
4948
4949 /*
4950 * Double-check it's still alive to make sure that we didn't
4951 * miss the NameOwnerChanged signal, e.g. while strdup'ing.
4952 */
4953 if (!dbus_bus_name_has_owner(priv->con, name, NULL)) {
4954 /*
4955 * Application no longer exists, clean up.
4956 * The return value is irrelevant now.
4957 *
4958 * Need to check if the NameOwnerChanged handling
4959 * already cleaned up because we have processed
4960 * DBus messages while checking if the name still
4961 * has an owner.
4962 */
4963 if (!wpa_s->preq_notify_peer)
4964 return NULL;
4965 os_free(wpa_s->preq_notify_peer);
4966 wpa_s->preq_notify_peer = NULL;
4967 wpas_dbus_unsubscribe_noc(priv);
4968 }
4969
4970 return NULL;
4971 }
4972
4973
4974 DBusMessage * wpas_dbus_handler_unsubscribe_preq(
4975 DBusMessage *message, struct wpa_supplicant *wpa_s)
4976 {
4977 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
4978
4979 if (!wpa_s->preq_notify_peer)
4980 return dbus_message_new_error(message,
4981 WPAS_DBUS_ERROR_NO_SUBSCRIPTION,
4982 "Not subscribed");
4983
4984 if (os_strcmp(wpa_s->preq_notify_peer,
4985 dbus_message_get_sender(message)))
4986 return dbus_message_new_error(message,
4987 WPAS_DBUS_ERROR_SUBSCRIPTION_EPERM,
4988 "Can't unsubscribe others");
4989
4990 os_free(wpa_s->preq_notify_peer);
4991 wpa_s->preq_notify_peer = NULL;
4992 wpas_dbus_unsubscribe_noc(priv);
4993 return NULL;
4994 }
4995
4996
4997 void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s,
4998 const u8 *addr, const u8 *dst, const u8 *bssid,
4999 const u8 *ie, size_t ie_len, u32 ssi_signal)
5000 {
5001 DBusMessage *msg;
5002 DBusMessageIter iter, dict_iter;
5003 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
5004
5005 /* Do nothing if the control interface is not turned on */
5006 if (priv == NULL || !wpa_s->dbus_new_path)
5007 return;
5008
5009 if (wpa_s->preq_notify_peer == NULL)
5010 return;
5011
5012 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
5013 WPAS_DBUS_NEW_IFACE_INTERFACE,
5014 "ProbeRequest");
5015 if (msg == NULL)
5016 return;
5017
5018 dbus_message_set_destination(msg, wpa_s->preq_notify_peer);
5019
5020 dbus_message_iter_init_append(msg, &iter);
5021
5022 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
5023 (addr && !wpa_dbus_dict_append_byte_array(&dict_iter, "addr",
5024 (const char *) addr,
5025 ETH_ALEN)) ||
5026 (dst && !wpa_dbus_dict_append_byte_array(&dict_iter, "dst",
5027 (const char *) dst,
5028 ETH_ALEN)) ||
5029 (bssid && !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
5030 (const char *) bssid,
5031 ETH_ALEN)) ||
5032 (ie && ie_len && !wpa_dbus_dict_append_byte_array(&dict_iter, "ies",
5033 (const char *) ie,
5034 ie_len)) ||
5035 (ssi_signal && !wpa_dbus_dict_append_int32(&dict_iter, "signal",
5036 ssi_signal)) ||
5037 !wpa_dbus_dict_close_write(&iter, &dict_iter))
5038 goto fail;
5039
5040 dbus_connection_send(priv->con, msg, NULL);
5041 goto out;
5042 fail:
5043 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
5044 out:
5045 dbus_message_unref(msg);
5046 }
5047
5048 #endif /* CONFIG_AP */
5049
5050
5051 DBusMessage * wpas_dbus_handler_vendor_elem_add(DBusMessage *message,
5052 struct wpa_supplicant *wpa_s)
5053 {
5054 u8 *ielems;
5055 int len;
5056 struct ieee802_11_elems elems;
5057 dbus_int32_t frame_id;
5058 DBusMessageIter iter, array;
5059
5060 dbus_message_iter_init(message, &iter);
5061 dbus_message_iter_get_basic(&iter, &frame_id);
5062 if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
5063 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5064 "Invalid ID");
5065 }
5066
5067 dbus_message_iter_next(&iter);
5068 dbus_message_iter_recurse(&iter, &array);
5069 dbus_message_iter_get_fixed_array(&array, &ielems, &len);
5070 if (!ielems || len == 0) {
5071 return dbus_message_new_error(
5072 message, DBUS_ERROR_INVALID_ARGS, "Invalid value");
5073 }
5074
5075 if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) {
5076 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5077 "Parse error");
5078 }
5079
5080 wpa_s = wpas_vendor_elem(wpa_s, frame_id);
5081 if (!wpa_s->vendor_elem[frame_id]) {
5082 wpa_s->vendor_elem[frame_id] = wpabuf_alloc_copy(ielems, len);
5083 wpas_vendor_elem_update(wpa_s);
5084 return NULL;
5085 }
5086
5087 if (wpabuf_resize(&wpa_s->vendor_elem[frame_id], len) < 0) {
5088 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5089 "Resize error");
5090 }
5091
5092 wpabuf_put_data(wpa_s->vendor_elem[frame_id], ielems, len);
5093 wpas_vendor_elem_update(wpa_s);
5094 return NULL;
5095 }
5096
5097
5098 DBusMessage * wpas_dbus_handler_vendor_elem_get(DBusMessage *message,
5099 struct wpa_supplicant *wpa_s)
5100 {
5101 DBusMessage *reply;
5102 DBusMessageIter iter, array_iter;
5103 dbus_int32_t frame_id;
5104 const u8 *elem;
5105 size_t elem_len;
5106
5107 dbus_message_iter_init(message, &iter);
5108 dbus_message_iter_get_basic(&iter, &frame_id);
5109
5110 if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
5111 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5112 "Invalid ID");
5113 }
5114
5115 wpa_s = wpas_vendor_elem(wpa_s, frame_id);
5116 if (!wpa_s->vendor_elem[frame_id]) {
5117 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5118 "ID value does not exist");
5119 }
5120
5121 reply = dbus_message_new_method_return(message);
5122 if (!reply)
5123 return wpas_dbus_error_no_memory(message);
5124
5125 dbus_message_iter_init_append(reply, &iter);
5126
5127 elem = wpabuf_head_u8(wpa_s->vendor_elem[frame_id]);
5128 elem_len = wpabuf_len(wpa_s->vendor_elem[frame_id]);
5129
5130 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
5131 DBUS_TYPE_BYTE_AS_STRING,
5132 &array_iter) ||
5133 !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
5134 &elem, elem_len) ||
5135 !dbus_message_iter_close_container(&iter, &array_iter)) {
5136 dbus_message_unref(reply);
5137 reply = wpas_dbus_error_no_memory(message);
5138 }
5139
5140 return reply;
5141 }
5142
5143
5144 DBusMessage * wpas_dbus_handler_vendor_elem_remove(DBusMessage *message,
5145 struct wpa_supplicant *wpa_s)
5146 {
5147 u8 *ielems;
5148 int len;
5149 struct ieee802_11_elems elems;
5150 DBusMessageIter iter, array;
5151 dbus_int32_t frame_id;
5152
5153 dbus_message_iter_init(message, &iter);
5154 dbus_message_iter_get_basic(&iter, &frame_id);
5155 if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
5156 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5157 "Invalid ID");
5158 }
5159
5160 dbus_message_iter_next(&iter);
5161 dbus_message_iter_recurse(&iter, &array);
5162 dbus_message_iter_get_fixed_array(&array, &ielems, &len);
5163 if (!ielems || len == 0) {
5164 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5165 "Invalid value");
5166 }
5167
5168 wpa_s = wpas_vendor_elem(wpa_s, frame_id);
5169
5170 if (len == 1 && *ielems == '*') {
5171 wpabuf_free(wpa_s->vendor_elem[frame_id]);
5172 wpa_s->vendor_elem[frame_id] = NULL;
5173 wpas_vendor_elem_update(wpa_s);
5174 return NULL;
5175 }
5176
5177 if (!wpa_s->vendor_elem[frame_id]) {
5178 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5179 "ID value does not exist");
5180 }
5181
5182 if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) {
5183 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5184 "Parse error");
5185 }
5186
5187 if (wpas_vendor_elem_remove(wpa_s, frame_id, ielems, len) == 0)
5188 return NULL;
5189
5190 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5191 "Not found");
5192 }
5193
5194
5195 #ifdef CONFIG_MESH
5196
5197 /**
5198 * wpas_dbus_getter_mesh_peers - Get connected mesh peers
5199 * @iter: Pointer to incoming dbus message iter
5200 * @error: Location to store error on failure
5201 * @user_data: Function specific data
5202 * Returns: TRUE on success, FALSE on failure
5203 *
5204 * Getter for "MeshPeers" property.
5205 */
5206 dbus_bool_t wpas_dbus_getter_mesh_peers(
5207 const struct wpa_dbus_property_desc *property_desc,
5208 DBusMessageIter *iter, DBusError *error, void *user_data)
5209 {
5210 struct wpa_supplicant *wpa_s = user_data;
5211 struct hostapd_data *hapd;
5212 struct sta_info *sta;
5213 DBusMessageIter variant_iter, array_iter;
5214 int i;
5215 DBusMessageIter inner_array_iter;
5216
5217 if (!wpa_s->ifmsh)
5218 return FALSE;
5219 hapd = wpa_s->ifmsh->bss[0];
5220
5221 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
5222 DBUS_TYPE_ARRAY_AS_STRING
5223 DBUS_TYPE_ARRAY_AS_STRING
5224 DBUS_TYPE_BYTE_AS_STRING,
5225 &variant_iter) ||
5226 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
5227 DBUS_TYPE_ARRAY_AS_STRING
5228 DBUS_TYPE_BYTE_AS_STRING,
5229 &array_iter))
5230 return FALSE;
5231
5232 for (sta = hapd->sta_list; sta; sta = sta->next) {
5233 if (!dbus_message_iter_open_container(
5234 &array_iter, DBUS_TYPE_ARRAY,
5235 DBUS_TYPE_BYTE_AS_STRING,
5236 &inner_array_iter))
5237 return FALSE;
5238
5239 for (i = 0; i < ETH_ALEN; i++) {
5240 if (!dbus_message_iter_append_basic(&inner_array_iter,
5241 DBUS_TYPE_BYTE,
5242 &(sta->addr[i])))
5243 return FALSE;
5244 }
5245
5246 if (!dbus_message_iter_close_container(
5247 &array_iter, &inner_array_iter))
5248 return FALSE;
5249 }
5250
5251 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
5252 !dbus_message_iter_close_container(iter, &variant_iter))
5253 return FALSE;
5254
5255 return TRUE;
5256 }
5257
5258
5259 /**
5260 * wpas_dbus_getter_mesh_group - Get mesh group
5261 * @iter: Pointer to incoming dbus message iter
5262 * @error: Location to store error on failure
5263 * @user_data: Function specific data
5264 * Returns: TRUE on success, FALSE on failure
5265 *
5266 * Getter for "MeshGroup" property.
5267 */
5268 dbus_bool_t wpas_dbus_getter_mesh_group(
5269 const struct wpa_dbus_property_desc *property_desc,
5270 DBusMessageIter *iter, DBusError *error, void *user_data)
5271 {
5272 struct wpa_supplicant *wpa_s = user_data;
5273 struct wpa_ssid *ssid = wpa_s->current_ssid;
5274
5275 if (!wpa_s->ifmsh || !ssid)
5276 return FALSE;
5277
5278 if (!wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
5279 (char *) ssid->ssid,
5280 ssid->ssid_len, error)) {
5281 dbus_set_error(error, DBUS_ERROR_FAILED,
5282 "%s: error constructing reply", __func__);
5283 return FALSE;
5284 }
5285
5286 return TRUE;
5287 }
5288
5289 #endif /* CONFIG_MESH */