]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/dbus/dbus_new_handlers.c
dbus: Export roam time, roam complete, and session length
[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_expire_age - Get BSS entry expiration age
3183 * @iter: Pointer to incoming dbus message iter
3184 * @error: Location to store error on failure
3185 * @user_data: Function specific data
3186 * Returns: TRUE on success, FALSE on failure
3187 *
3188 * Getter function for "BSSExpireAge" property.
3189 */
3190 dbus_bool_t wpas_dbus_getter_bss_expire_age(
3191 const struct wpa_dbus_property_desc *property_desc,
3192 DBusMessageIter *iter, DBusError *error, void *user_data)
3193 {
3194 struct wpa_supplicant *wpa_s = user_data;
3195 dbus_uint32_t expire_age = wpa_s->conf->bss_expiration_age;
3196
3197 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
3198 &expire_age, error);
3199 }
3200
3201
3202 /**
3203 * wpas_dbus_setter_bss_expire_age - Control BSS entry expiration age
3204 * @iter: Pointer to incoming dbus message iter
3205 * @error: Location to store error on failure
3206 * @user_data: Function specific data
3207 * Returns: TRUE on success, FALSE on failure
3208 *
3209 * Setter function for "BSSExpireAge" property.
3210 */
3211 dbus_bool_t wpas_dbus_setter_bss_expire_age(
3212 const struct wpa_dbus_property_desc *property_desc,
3213 DBusMessageIter *iter, DBusError *error, void *user_data)
3214 {
3215 struct wpa_supplicant *wpa_s = user_data;
3216 dbus_uint32_t expire_age;
3217
3218 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
3219 &expire_age))
3220 return FALSE;
3221
3222 if (wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age)) {
3223 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3224 "BSSExpireAge must be >= 10");
3225 return FALSE;
3226 }
3227 return TRUE;
3228 }
3229
3230
3231 /**
3232 * wpas_dbus_getter_bss_expire_count - Get BSS entry expiration scan count
3233 * @iter: Pointer to incoming dbus message iter
3234 * @error: Location to store error on failure
3235 * @user_data: Function specific data
3236 * Returns: TRUE on success, FALSE on failure
3237 *
3238 * Getter function for "BSSExpireCount" property.
3239 */
3240 dbus_bool_t wpas_dbus_getter_bss_expire_count(
3241 const struct wpa_dbus_property_desc *property_desc,
3242 DBusMessageIter *iter, DBusError *error, void *user_data)
3243 {
3244 struct wpa_supplicant *wpa_s = user_data;
3245 dbus_uint32_t expire_count = wpa_s->conf->bss_expiration_scan_count;
3246
3247 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32,
3248 &expire_count, error);
3249 }
3250
3251
3252 /**
3253 * wpas_dbus_setter_bss_expire_count - Control BSS entry expiration scan count
3254 * @iter: Pointer to incoming dbus message iter
3255 * @error: Location to store error on failure
3256 * @user_data: Function specific data
3257 * Returns: TRUE on success, FALSE on failure
3258 *
3259 * Setter function for "BSSExpireCount" property.
3260 */
3261 dbus_bool_t wpas_dbus_setter_bss_expire_count(
3262 const struct wpa_dbus_property_desc *property_desc,
3263 DBusMessageIter *iter, DBusError *error, void *user_data)
3264 {
3265 struct wpa_supplicant *wpa_s = user_data;
3266 dbus_uint32_t expire_count;
3267
3268 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_UINT32,
3269 &expire_count))
3270 return FALSE;
3271
3272 if (wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count)) {
3273 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3274 "BSSExpireCount must be > 0");
3275 return FALSE;
3276 }
3277 return TRUE;
3278 }
3279
3280
3281 /**
3282 * wpas_dbus_getter_country - Control country code
3283 * @iter: Pointer to incoming dbus message iter
3284 * @error: Location to store error on failure
3285 * @user_data: Function specific data
3286 * Returns: TRUE on success, FALSE on failure
3287 *
3288 * Getter function for "Country" property.
3289 */
3290 dbus_bool_t wpas_dbus_getter_country(
3291 const struct wpa_dbus_property_desc *property_desc,
3292 DBusMessageIter *iter, DBusError *error, void *user_data)
3293 {
3294 struct wpa_supplicant *wpa_s = user_data;
3295 char country[3];
3296 char *str = country;
3297
3298 country[0] = wpa_s->conf->country[0];
3299 country[1] = wpa_s->conf->country[1];
3300 country[2] = '\0';
3301
3302 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3303 &str, error);
3304 }
3305
3306
3307 /**
3308 * wpas_dbus_setter_country - Control country code
3309 * @iter: Pointer to incoming dbus message iter
3310 * @error: Location to store error on failure
3311 * @user_data: Function specific data
3312 * Returns: TRUE on success, FALSE on failure
3313 *
3314 * Setter function for "Country" property.
3315 */
3316 dbus_bool_t wpas_dbus_setter_country(
3317 const struct wpa_dbus_property_desc *property_desc,
3318 DBusMessageIter *iter, DBusError *error, void *user_data)
3319 {
3320 struct wpa_supplicant *wpa_s = user_data;
3321 const char *country;
3322
3323 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
3324 &country))
3325 return FALSE;
3326
3327 if (!country[0] || !country[1]) {
3328 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3329 "invalid country code");
3330 return FALSE;
3331 }
3332
3333 if (wpa_s->drv_priv != NULL && wpa_drv_set_country(wpa_s, country)) {
3334 wpa_printf(MSG_DEBUG, "Failed to set country");
3335 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3336 "failed to set country code");
3337 return FALSE;
3338 }
3339
3340 wpa_s->conf->country[0] = country[0];
3341 wpa_s->conf->country[1] = country[1];
3342 return TRUE;
3343 }
3344
3345
3346 /**
3347 * wpas_dbus_getter_scan_interval - Get scan interval
3348 * @iter: Pointer to incoming dbus message iter
3349 * @error: Location to store error on failure
3350 * @user_data: Function specific data
3351 * Returns: TRUE on success, FALSE on failure
3352 *
3353 * Getter function for "ScanInterval" property.
3354 */
3355 dbus_bool_t wpas_dbus_getter_scan_interval(
3356 const struct wpa_dbus_property_desc *property_desc,
3357 DBusMessageIter *iter, DBusError *error, void *user_data)
3358 {
3359 struct wpa_supplicant *wpa_s = user_data;
3360 dbus_int32_t scan_interval = wpa_s->scan_interval;
3361
3362 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
3363 &scan_interval, error);
3364 }
3365
3366
3367 /**
3368 * wpas_dbus_setter_scan_interval - Control scan interval
3369 * @iter: Pointer to incoming dbus message iter
3370 * @error: Location to store error on failure
3371 * @user_data: Function specific data
3372 * Returns: TRUE on success, FALSE on failure
3373 *
3374 * Setter function for "ScanInterval" property.
3375 */
3376 dbus_bool_t wpas_dbus_setter_scan_interval(
3377 const struct wpa_dbus_property_desc *property_desc,
3378 DBusMessageIter *iter, DBusError *error, void *user_data)
3379 {
3380 struct wpa_supplicant *wpa_s = user_data;
3381 dbus_int32_t scan_interval;
3382
3383 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_INT32,
3384 &scan_interval))
3385 return FALSE;
3386
3387 if (wpa_supplicant_set_scan_interval(wpa_s, scan_interval)) {
3388 dbus_set_error_const(error, DBUS_ERROR_FAILED,
3389 "scan_interval must be >= 0");
3390 return FALSE;
3391 }
3392 return TRUE;
3393 }
3394
3395
3396 /**
3397 * wpas_dbus_getter_ifname - Get interface name
3398 * @iter: Pointer to incoming dbus message iter
3399 * @error: Location to store error on failure
3400 * @user_data: Function specific data
3401 * Returns: TRUE on success, FALSE on failure
3402 *
3403 * Getter for "Ifname" property.
3404 */
3405 dbus_bool_t wpas_dbus_getter_ifname(
3406 const struct wpa_dbus_property_desc *property_desc,
3407 DBusMessageIter *iter, DBusError *error, void *user_data)
3408 {
3409 struct wpa_supplicant *wpa_s = user_data;
3410
3411 return wpas_dbus_string_property_getter(iter, wpa_s->ifname, error);
3412 }
3413
3414
3415 /**
3416 * wpas_dbus_getter_driver - Get interface name
3417 * @iter: Pointer to incoming dbus message iter
3418 * @error: Location to store error on failure
3419 * @user_data: Function specific data
3420 * Returns: TRUE on success, FALSE on failure
3421 *
3422 * Getter for "Driver" property.
3423 */
3424 dbus_bool_t wpas_dbus_getter_driver(
3425 const struct wpa_dbus_property_desc *property_desc,
3426 DBusMessageIter *iter, DBusError *error, void *user_data)
3427 {
3428 struct wpa_supplicant *wpa_s = user_data;
3429
3430 if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
3431 wpa_printf(MSG_DEBUG, "%s[dbus]: wpa_s has no driver set",
3432 __func__);
3433 dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
3434 __func__);
3435 return FALSE;
3436 }
3437
3438 return wpas_dbus_string_property_getter(iter, wpa_s->driver->name,
3439 error);
3440 }
3441
3442
3443 /**
3444 * wpas_dbus_getter_current_bss - Get current bss object path
3445 * @iter: Pointer to incoming dbus message iter
3446 * @error: Location to store error on failure
3447 * @user_data: Function specific data
3448 * Returns: TRUE on success, FALSE on failure
3449 *
3450 * Getter for "CurrentBSS" property.
3451 */
3452 dbus_bool_t wpas_dbus_getter_current_bss(
3453 const struct wpa_dbus_property_desc *property_desc,
3454 DBusMessageIter *iter, DBusError *error, void *user_data)
3455 {
3456 struct wpa_supplicant *wpa_s = user_data;
3457 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
3458
3459 if (wpa_s->current_bss && wpa_s->dbus_new_path)
3460 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3461 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
3462 wpa_s->dbus_new_path, wpa_s->current_bss->id);
3463 else
3464 os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
3465
3466 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
3467 &bss_obj_path, error);
3468 }
3469
3470
3471 /**
3472 * wpas_dbus_getter_current_network - Get current network object path
3473 * @iter: Pointer to incoming dbus message iter
3474 * @error: Location to store error on failure
3475 * @user_data: Function specific data
3476 * Returns: TRUE on success, FALSE on failure
3477 *
3478 * Getter for "CurrentNetwork" property.
3479 */
3480 dbus_bool_t wpas_dbus_getter_current_network(
3481 const struct wpa_dbus_property_desc *property_desc,
3482 DBusMessageIter *iter, DBusError *error, void *user_data)
3483 {
3484 struct wpa_supplicant *wpa_s = user_data;
3485 char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
3486
3487 if (wpa_s->current_ssid && wpa_s->dbus_new_path)
3488 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
3489 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
3490 wpa_s->dbus_new_path, wpa_s->current_ssid->id);
3491 else
3492 os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "/");
3493
3494 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_OBJECT_PATH,
3495 &net_obj_path, error);
3496 }
3497
3498
3499 /**
3500 * wpas_dbus_getter_current_auth_mode - Get current authentication type
3501 * @iter: Pointer to incoming dbus message iter
3502 * @error: Location to store error on failure
3503 * @user_data: Function specific data
3504 * Returns: TRUE on success, FALSE on failure
3505 *
3506 * Getter for "CurrentAuthMode" property.
3507 */
3508 dbus_bool_t wpas_dbus_getter_current_auth_mode(
3509 const struct wpa_dbus_property_desc *property_desc,
3510 DBusMessageIter *iter, DBusError *error, void *user_data)
3511 {
3512 struct wpa_supplicant *wpa_s = user_data;
3513 const char *eap_mode;
3514 const char *auth_mode;
3515 char eap_mode_buf[WPAS_DBUS_AUTH_MODE_MAX];
3516
3517 if (wpa_s->wpa_state != WPA_COMPLETED) {
3518 auth_mode = "INACTIVE";
3519 } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
3520 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
3521 eap_mode = wpa_supplicant_get_eap_mode(wpa_s);
3522 os_snprintf(eap_mode_buf, WPAS_DBUS_AUTH_MODE_MAX,
3523 "EAP-%s", eap_mode);
3524 auth_mode = eap_mode_buf;
3525
3526 } else if (wpa_s->current_ssid) {
3527 auth_mode = wpa_key_mgmt_txt(wpa_s->key_mgmt,
3528 wpa_s->current_ssid->proto);
3529 } else {
3530 auth_mode = "UNKNOWN";
3531 }
3532
3533 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
3534 &auth_mode, error);
3535 }
3536
3537
3538 /**
3539 * wpas_dbus_getter_bridge_ifname - Get interface name
3540 * @iter: Pointer to incoming dbus message iter
3541 * @error: Location to store error on failure
3542 * @user_data: Function specific data
3543 * Returns: TRUE on success, FALSE on failure
3544 *
3545 * Getter for "BridgeIfname" property.
3546 */
3547 dbus_bool_t wpas_dbus_getter_bridge_ifname(
3548 const struct wpa_dbus_property_desc *property_desc,
3549 DBusMessageIter *iter, DBusError *error, void *user_data)
3550 {
3551 struct wpa_supplicant *wpa_s = user_data;
3552
3553 return wpas_dbus_string_property_getter(iter, wpa_s->bridge_ifname,
3554 error);
3555 }
3556
3557
3558 /**
3559 * wpas_dbus_getter_config_file - Get interface configuration file path
3560 * @iter: Pointer to incoming dbus message iter
3561 * @error: Location to store error on failure
3562 * @user_data: Function specific data
3563 * Returns: TRUE on success, FALSE on failure
3564 *
3565 * Getter for "ConfigFile" property.
3566 */
3567 dbus_bool_t wpas_dbus_getter_config_file(
3568 const struct wpa_dbus_property_desc *property_desc,
3569 DBusMessageIter *iter, DBusError *error, void *user_data)
3570 {
3571 struct wpa_supplicant *wpa_s = user_data;
3572
3573 return wpas_dbus_string_property_getter(iter, wpa_s->confname, error);
3574 }
3575
3576
3577 /**
3578 * wpas_dbus_getter_bsss - Get array of BSSs objects
3579 * @iter: Pointer to incoming dbus message iter
3580 * @error: Location to store error on failure
3581 * @user_data: Function specific data
3582 * Returns: TRUE on success, FALSE on failure
3583 *
3584 * Getter for "BSSs" property.
3585 */
3586 dbus_bool_t wpas_dbus_getter_bsss(
3587 const struct wpa_dbus_property_desc *property_desc,
3588 DBusMessageIter *iter, DBusError *error, void *user_data)
3589 {
3590 struct wpa_supplicant *wpa_s = user_data;
3591 struct wpa_bss *bss;
3592 char **paths;
3593 unsigned int i = 0;
3594 dbus_bool_t success = FALSE;
3595
3596 if (!wpa_s->dbus_new_path) {
3597 dbus_set_error(error, DBUS_ERROR_FAILED,
3598 "%s: no D-Bus interface", __func__);
3599 return FALSE;
3600 }
3601
3602 paths = os_calloc(wpa_s->num_bss, sizeof(char *));
3603 if (!paths) {
3604 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3605 return FALSE;
3606 }
3607
3608 /* Loop through scan results and append each result's object path */
3609 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3610 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3611 if (paths[i] == NULL) {
3612 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3613 "no memory");
3614 goto out;
3615 }
3616 /* Construct the object path for this BSS. */
3617 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3618 "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
3619 wpa_s->dbus_new_path, bss->id);
3620 }
3621
3622 success = wpas_dbus_simple_array_property_getter(iter,
3623 DBUS_TYPE_OBJECT_PATH,
3624 paths, wpa_s->num_bss,
3625 error);
3626
3627 out:
3628 while (i)
3629 os_free(paths[--i]);
3630 os_free(paths);
3631 return success;
3632 }
3633
3634
3635 /**
3636 * wpas_dbus_getter_networks - Get array of networks objects
3637 * @iter: Pointer to incoming dbus message iter
3638 * @error: Location to store error on failure
3639 * @user_data: Function specific data
3640 * Returns: TRUE on success, FALSE on failure
3641 *
3642 * Getter for "Networks" property.
3643 */
3644 dbus_bool_t wpas_dbus_getter_networks(
3645 const struct wpa_dbus_property_desc *property_desc,
3646 DBusMessageIter *iter, DBusError *error, void *user_data)
3647 {
3648 struct wpa_supplicant *wpa_s = user_data;
3649 struct wpa_ssid *ssid;
3650 char **paths;
3651 unsigned int i = 0, num = 0;
3652 dbus_bool_t success = FALSE;
3653
3654 if (!wpa_s->dbus_new_path) {
3655 dbus_set_error(error, DBUS_ERROR_FAILED,
3656 "%s: no D-Bus interface", __func__);
3657 return FALSE;
3658 }
3659
3660 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
3661 if (!network_is_persistent_group(ssid))
3662 num++;
3663
3664 paths = os_calloc(num, sizeof(char *));
3665 if (!paths) {
3666 dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
3667 return FALSE;
3668 }
3669
3670 /* Loop through configured networks and append object path of each */
3671 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
3672 if (network_is_persistent_group(ssid))
3673 continue;
3674 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3675 if (paths[i] == NULL) {
3676 dbus_set_error(error, DBUS_ERROR_NO_MEMORY,
3677 "no memory");
3678 goto out;
3679 }
3680
3681 /* Construct the object path for this network. */
3682 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3683 "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
3684 wpa_s->dbus_new_path, ssid->id);
3685 }
3686
3687 success = wpas_dbus_simple_array_property_getter(iter,
3688 DBUS_TYPE_OBJECT_PATH,
3689 paths, num, error);
3690
3691 out:
3692 while (i)
3693 os_free(paths[--i]);
3694 os_free(paths);
3695 return success;
3696 }
3697
3698
3699 /**
3700 * wpas_dbus_getter_pkcs11_engine_path - Get PKCS #11 engine path
3701 * @iter: Pointer to incoming dbus message iter
3702 * @error: Location to store error on failure
3703 * @user_data: Function specific data
3704 * Returns: A dbus message containing the PKCS #11 engine path
3705 *
3706 * Getter for "PKCS11EnginePath" property.
3707 */
3708 dbus_bool_t wpas_dbus_getter_pkcs11_engine_path(
3709 const struct wpa_dbus_property_desc *property_desc,
3710 DBusMessageIter *iter, DBusError *error, void *user_data)
3711 {
3712 struct wpa_supplicant *wpa_s = user_data;
3713
3714 return wpas_dbus_string_property_getter(iter,
3715 wpa_s->conf->pkcs11_engine_path,
3716 error);
3717 }
3718
3719
3720 /**
3721 * wpas_dbus_getter_pkcs11_module_path - Get PKCS #11 module path
3722 * @iter: Pointer to incoming dbus message iter
3723 * @error: Location to store error on failure
3724 * @user_data: Function specific data
3725 * Returns: A dbus message containing the PKCS #11 module path
3726 *
3727 * Getter for "PKCS11ModulePath" property.
3728 */
3729 dbus_bool_t wpas_dbus_getter_pkcs11_module_path(
3730 const struct wpa_dbus_property_desc *property_desc,
3731 DBusMessageIter *iter, DBusError *error, void *user_data)
3732 {
3733 struct wpa_supplicant *wpa_s = user_data;
3734
3735 return wpas_dbus_string_property_getter(iter,
3736 wpa_s->conf->pkcs11_module_path,
3737 error);
3738 }
3739
3740
3741 /**
3742 * wpas_dbus_getter_blobs - Get all blobs defined for this interface
3743 * @iter: Pointer to incoming dbus message iter
3744 * @error: Location to store error on failure
3745 * @user_data: Function specific data
3746 * Returns: TRUE on success, FALSE on failure
3747 *
3748 * Getter for "Blobs" property.
3749 */
3750 dbus_bool_t wpas_dbus_getter_blobs(
3751 const struct wpa_dbus_property_desc *property_desc,
3752 DBusMessageIter *iter, DBusError *error, void *user_data)
3753 {
3754 struct wpa_supplicant *wpa_s = user_data;
3755 DBusMessageIter variant_iter, dict_iter, entry_iter, array_iter;
3756 struct wpa_config_blob *blob;
3757
3758 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
3759 "a{say}", &variant_iter) ||
3760 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
3761 "{say}", &dict_iter)) {
3762 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3763 return FALSE;
3764 }
3765
3766 blob = wpa_s->conf->blobs;
3767 while (blob) {
3768 if (!dbus_message_iter_open_container(&dict_iter,
3769 DBUS_TYPE_DICT_ENTRY,
3770 NULL, &entry_iter) ||
3771 !dbus_message_iter_append_basic(&entry_iter,
3772 DBUS_TYPE_STRING,
3773 &(blob->name)) ||
3774 !dbus_message_iter_open_container(&entry_iter,
3775 DBUS_TYPE_ARRAY,
3776 DBUS_TYPE_BYTE_AS_STRING,
3777 &array_iter) ||
3778 !dbus_message_iter_append_fixed_array(&array_iter,
3779 DBUS_TYPE_BYTE,
3780 &(blob->data),
3781 blob->len) ||
3782 !dbus_message_iter_close_container(&entry_iter,
3783 &array_iter) ||
3784 !dbus_message_iter_close_container(&dict_iter,
3785 &entry_iter)) {
3786 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3787 "no memory");
3788 return FALSE;
3789 }
3790
3791 blob = blob->next;
3792 }
3793
3794 if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
3795 !dbus_message_iter_close_container(iter, &variant_iter)) {
3796 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3797 return FALSE;
3798 }
3799
3800 return TRUE;
3801 }
3802
3803
3804 dbus_bool_t wpas_dbus_getter_iface_global(
3805 const struct wpa_dbus_property_desc *property_desc,
3806 DBusMessageIter *iter, DBusError *error, void *user_data)
3807 {
3808 struct wpa_supplicant *wpa_s = user_data;
3809 int ret;
3810 char buf[250];
3811 char *p = buf;
3812
3813 if (!property_desc->data) {
3814 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
3815 "Unhandled interface property %s",
3816 property_desc->dbus_property);
3817 return FALSE;
3818 }
3819
3820 ret = wpa_config_get_value(property_desc->data, wpa_s->conf, buf,
3821 sizeof(buf));
3822 if (ret < 0)
3823 *p = '\0';
3824
3825 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, &p,
3826 error);
3827 }
3828
3829
3830 dbus_bool_t wpas_dbus_setter_iface_global(
3831 const struct wpa_dbus_property_desc *property_desc,
3832 DBusMessageIter *iter, DBusError *error, void *user_data)
3833 {
3834 struct wpa_supplicant *wpa_s = user_data;
3835 const char *new_value = NULL;
3836 char buf[250];
3837 size_t combined_len;
3838 int ret;
3839
3840 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_STRING,
3841 &new_value))
3842 return FALSE;
3843
3844 combined_len = os_strlen(property_desc->data) + os_strlen(new_value) +
3845 3;
3846 if (combined_len >= sizeof(buf)) {
3847 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
3848 "Interface property %s value too large",
3849 property_desc->dbus_property);
3850 return FALSE;
3851 }
3852
3853 if (!new_value[0])
3854 new_value = "NULL";
3855
3856 ret = os_snprintf(buf, combined_len, "%s=%s", property_desc->data,
3857 new_value);
3858 if (os_snprintf_error(combined_len, ret)) {
3859 dbus_set_error(error, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
3860 "Failed to construct new interface property %s",
3861 property_desc->dbus_property);
3862 return FALSE;
3863 }
3864
3865 if (wpa_config_process_global(wpa_s->conf, buf, -1)) {
3866 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
3867 "Failed to set interface property %s",
3868 property_desc->dbus_property);
3869 return FALSE;
3870 }
3871
3872 wpa_supplicant_update_config(wpa_s);
3873 return TRUE;
3874 }
3875
3876
3877 /**
3878 * wpas_dbus_getter_stas - Get connected stations for an interface
3879 * @iter: Pointer to incoming dbus message iter
3880 * @error: Location to store error on failure
3881 * @user_data: Function specific data
3882 * Returns: a list of stations
3883 *
3884 * Getter for "Stations" property.
3885 */
3886 dbus_bool_t wpas_dbus_getter_stas(
3887 const struct wpa_dbus_property_desc *property_desc,
3888 DBusMessageIter *iter, DBusError *error, void *user_data)
3889 {
3890 struct wpa_supplicant *wpa_s = user_data;
3891 struct sta_info *sta = NULL;
3892 char **paths = NULL;
3893 unsigned int i = 0, num = 0;
3894 dbus_bool_t success = FALSE;
3895
3896 if (!wpa_s->dbus_new_path) {
3897 dbus_set_error(error, DBUS_ERROR_FAILED,
3898 "%s: no D-Bus interface", __func__);
3899 return FALSE;
3900 }
3901
3902 #ifdef CONFIG_AP
3903 if (wpa_s->ap_iface) {
3904 struct hostapd_data *hapd;
3905
3906 hapd = wpa_s->ap_iface->bss[0];
3907 sta = hapd->sta_list;
3908 num = hapd->num_sta;
3909 }
3910 #endif /* CONFIG_AP */
3911
3912 paths = os_calloc(num, sizeof(char *));
3913 if (!paths) {
3914 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
3915 return FALSE;
3916 }
3917
3918 /* Loop through scan results and append each result's object path */
3919 for (; sta; sta = sta->next) {
3920 paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
3921 if (!paths[i]) {
3922 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
3923 "no memory");
3924 goto out;
3925 }
3926 /* Construct the object path for this BSS. */
3927 os_snprintf(paths[i++], WPAS_DBUS_OBJECT_PATH_MAX,
3928 "%s/" WPAS_DBUS_NEW_STAS_PART "/" COMPACT_MACSTR,
3929 wpa_s->dbus_new_path, MAC2STR(sta->addr));
3930 }
3931
3932 success = wpas_dbus_simple_array_property_getter(iter,
3933 DBUS_TYPE_OBJECT_PATH,
3934 paths, num,
3935 error);
3936
3937 out:
3938 while (i)
3939 os_free(paths[--i]);
3940 os_free(paths);
3941 return success;
3942 }
3943
3944
3945 /**
3946 * wpas_dbus_getter_sta_address - Return the address of a connected station
3947 * @iter: Pointer to incoming dbus message iter
3948 * @error: Location to store error on failure
3949 * @user_data: Function specific data
3950 * Returns: TRUE on success, FALSE on failure
3951 *
3952 * Getter for "Address" property.
3953 */
3954 dbus_bool_t wpas_dbus_getter_sta_address(
3955 const struct wpa_dbus_property_desc *property_desc,
3956 DBusMessageIter *iter, DBusError *error, void *user_data)
3957 {
3958 #ifdef CONFIG_AP
3959 struct sta_handler_args *args = user_data;
3960 struct sta_info *sta;
3961
3962 sta = ap_get_sta(args->wpa_s->ap_iface->bss[0], args->sta);
3963 if (!sta)
3964 return FALSE;
3965
3966 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
3967 sta->addr, ETH_ALEN,
3968 error);
3969 #else /* CONFIG_AP */
3970 return FALSE;
3971 #endif /* CONFIG_AP */
3972 }
3973
3974
3975 /**
3976 * wpas_dbus_getter_sta_aid - Return the AID of a connected station
3977 * @iter: Pointer to incoming dbus message iter
3978 * @error: Location to store error on failure
3979 * @user_data: Function specific data
3980 * Returns: TRUE on success, FALSE on failure
3981 *
3982 * Getter for "AID" property.
3983 */
3984 dbus_bool_t wpas_dbus_getter_sta_aid(
3985 const struct wpa_dbus_property_desc *property_desc,
3986 DBusMessageIter *iter, DBusError *error, void *user_data)
3987 {
3988 #ifdef CONFIG_AP
3989 struct sta_handler_args *args = user_data;
3990 struct sta_info *sta;
3991
3992 sta = ap_get_sta(args->wpa_s->ap_iface->bss[0], args->sta);
3993 if (!sta)
3994 return FALSE;
3995
3996 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
3997 &sta->aid,
3998 error);
3999 #else /* CONFIG_AP */
4000 return FALSE;
4001 #endif /* CONFIG_AP */
4002 }
4003
4004
4005 /**
4006 * wpas_dbus_getter_sta_caps - Return the capabilities of a station
4007 * @iter: Pointer to incoming dbus message iter
4008 * @error: Location to store error on failure
4009 * @user_data: Function specific data
4010 * Returns: TRUE on success, FALSE on failure
4011 *
4012 * Getter for "Capabilities" property.
4013 */
4014 dbus_bool_t wpas_dbus_getter_sta_caps(
4015 const struct wpa_dbus_property_desc *property_desc,
4016 DBusMessageIter *iter, DBusError *error, void *user_data)
4017 {
4018 #ifdef CONFIG_AP
4019 struct sta_handler_args *args = user_data;
4020 struct sta_info *sta;
4021
4022 sta = ap_get_sta(args->wpa_s->ap_iface->bss[0], args->sta);
4023 if (!sta)
4024 return FALSE;
4025
4026 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
4027 &sta->capability,
4028 error);
4029 #else /* CONFIG_AP */
4030 return FALSE;
4031 #endif /* CONFIG_AP */
4032 }
4033
4034
4035 /**
4036 * wpas_dbus_getter_rx_packets - Return the received packets for a station
4037 * @iter: Pointer to incoming dbus message iter
4038 * @error: Location to store error on failure
4039 * @user_data: Function specific data
4040 * Returns: TRUE on success, FALSE on failure
4041 *
4042 * Getter for "RxPackets" property.
4043 */
4044 dbus_bool_t wpas_dbus_getter_sta_rx_packets(
4045 const struct wpa_dbus_property_desc *property_desc,
4046 DBusMessageIter *iter, DBusError *error, void *user_data)
4047 {
4048 #ifdef CONFIG_AP
4049 struct sta_handler_args *args = user_data;
4050 struct sta_info *sta;
4051 struct hostap_sta_driver_data data;
4052 struct hostapd_data *hapd;
4053
4054 if (!args->wpa_s->ap_iface)
4055 return FALSE;
4056
4057 hapd = args->wpa_s->ap_iface->bss[0];
4058 sta = ap_get_sta(hapd, args->sta);
4059 if (!sta)
4060 return FALSE;
4061
4062 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4063 return FALSE;
4064
4065 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4066 &data.rx_packets,
4067 error);
4068 #else /* CONFIG_AP */
4069 return FALSE;
4070 #endif /* CONFIG_AP */
4071 }
4072
4073
4074 /**
4075 * wpas_dbus_getter_tx_packets - Return the transmitted packets for a station
4076 * @iter: Pointer to incoming dbus message iter
4077 * @error: Location to store error on failure
4078 * @user_data: Function specific data
4079 * Returns: TRUE on success, FALSE on failure
4080 *
4081 * Getter for "TxPackets" property.
4082 */
4083 dbus_bool_t wpas_dbus_getter_sta_tx_packets(
4084 const struct wpa_dbus_property_desc *property_desc,
4085 DBusMessageIter *iter, DBusError *error, void *user_data)
4086 {
4087 #ifdef CONFIG_AP
4088 struct sta_handler_args *args = user_data;
4089 struct sta_info *sta;
4090 struct hostap_sta_driver_data data;
4091 struct hostapd_data *hapd;
4092
4093 if (!args->wpa_s->ap_iface)
4094 return FALSE;
4095
4096 hapd = args->wpa_s->ap_iface->bss[0];
4097 sta = ap_get_sta(hapd, args->sta);
4098 if (!sta)
4099 return FALSE;
4100
4101 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4102 return FALSE;
4103
4104 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4105 &data.tx_packets,
4106 error);
4107 #else /* CONFIG_AP */
4108 return FALSE;
4109 #endif /* CONFIG_AP */
4110 }
4111
4112
4113 /**
4114 * wpas_dbus_getter_tx_bytes - Return the transmitted bytes for a station
4115 * @iter: Pointer to incoming dbus message iter
4116 * @error: Location to store error on failure
4117 * @user_data: Function specific data
4118 * Returns: TRUE on success, FALSE on failure
4119 *
4120 * Getter for "TxBytes" property.
4121 */
4122 dbus_bool_t wpas_dbus_getter_sta_tx_bytes(
4123 const struct wpa_dbus_property_desc *property_desc,
4124 DBusMessageIter *iter, DBusError *error, void *user_data)
4125 {
4126 #ifdef CONFIG_AP
4127 struct sta_handler_args *args = user_data;
4128 struct sta_info *sta;
4129 struct hostap_sta_driver_data data;
4130 struct hostapd_data *hapd;
4131
4132 if (!args->wpa_s->ap_iface)
4133 return FALSE;
4134
4135 hapd = args->wpa_s->ap_iface->bss[0];
4136 sta = ap_get_sta(hapd, args->sta);
4137 if (!sta)
4138 return FALSE;
4139
4140 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4141 return FALSE;
4142
4143 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4144 &data.tx_bytes,
4145 error);
4146 #else /* CONFIG_AP */
4147 return FALSE;
4148 #endif /* CONFIG_AP */
4149 }
4150
4151
4152 /**
4153 * wpas_dbus_getter_rx_bytes - Return the received bytes for a station
4154 * @iter: Pointer to incoming dbus message iter
4155 * @error: Location to store error on failure
4156 * @user_data: Function specific data
4157 * Returns: TRUE on success, FALSE on failure
4158 *
4159 * Getter for "RxBytes" property.
4160 */
4161 dbus_bool_t wpas_dbus_getter_sta_rx_bytes(
4162 const struct wpa_dbus_property_desc *property_desc,
4163 DBusMessageIter *iter, DBusError *error, void *user_data)
4164 {
4165 #ifdef CONFIG_AP
4166 struct sta_handler_args *args = user_data;
4167 struct sta_info *sta;
4168 struct hostap_sta_driver_data data;
4169 struct hostapd_data *hapd;
4170
4171 if (!args->wpa_s->ap_iface)
4172 return FALSE;
4173
4174 hapd = args->wpa_s->ap_iface->bss[0];
4175 sta = ap_get_sta(hapd, args->sta);
4176 if (!sta)
4177 return FALSE;
4178
4179 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
4180 return FALSE;
4181
4182 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT64,
4183 &data.rx_bytes,
4184 error);
4185 #else /* CONFIG_AP */
4186 return FALSE;
4187 #endif /* CONFIG_AP */
4188 }
4189
4190
4191 static struct wpa_bss * get_bss_helper(struct bss_handler_args *args,
4192 DBusError *error, const char *func_name)
4193 {
4194 struct wpa_bss *res = wpa_bss_get_id(args->wpa_s, args->id);
4195
4196 if (!res) {
4197 wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found",
4198 func_name, args->id);
4199 dbus_set_error(error, DBUS_ERROR_FAILED,
4200 "%s: BSS %d not found",
4201 func_name, args->id);
4202 }
4203
4204 return res;
4205 }
4206
4207
4208 /**
4209 * wpas_dbus_getter_bss_bssid - Return the BSSID of a BSS
4210 * @iter: Pointer to incoming dbus message iter
4211 * @error: Location to store error on failure
4212 * @user_data: Function specific data
4213 * Returns: TRUE on success, FALSE on failure
4214 *
4215 * Getter for "BSSID" property.
4216 */
4217 dbus_bool_t wpas_dbus_getter_bss_bssid(
4218 const struct wpa_dbus_property_desc *property_desc,
4219 DBusMessageIter *iter, DBusError *error, void *user_data)
4220 {
4221 struct bss_handler_args *args = user_data;
4222 struct wpa_bss *res;
4223
4224 res = get_bss_helper(args, error, __func__);
4225 if (!res)
4226 return FALSE;
4227
4228 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
4229 res->bssid, ETH_ALEN,
4230 error);
4231 }
4232
4233
4234 /**
4235 * wpas_dbus_getter_bss_ssid - Return the SSID of a BSS
4236 * @iter: Pointer to incoming dbus message iter
4237 * @error: Location to store error on failure
4238 * @user_data: Function specific data
4239 * Returns: TRUE on success, FALSE on failure
4240 *
4241 * Getter for "SSID" property.
4242 */
4243 dbus_bool_t wpas_dbus_getter_bss_ssid(
4244 const struct wpa_dbus_property_desc *property_desc,
4245 DBusMessageIter *iter, DBusError *error, void *user_data)
4246 {
4247 struct bss_handler_args *args = user_data;
4248 struct wpa_bss *res;
4249
4250 res = get_bss_helper(args, error, __func__);
4251 if (!res)
4252 return FALSE;
4253
4254 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
4255 res->ssid, res->ssid_len,
4256 error);
4257 }
4258
4259
4260 /**
4261 * wpas_dbus_getter_bss_privacy - Return the privacy flag of a BSS
4262 * @iter: Pointer to incoming dbus message iter
4263 * @error: Location to store error on failure
4264 * @user_data: Function specific data
4265 * Returns: TRUE on success, FALSE on failure
4266 *
4267 * Getter for "Privacy" property.
4268 */
4269 dbus_bool_t wpas_dbus_getter_bss_privacy(
4270 const struct wpa_dbus_property_desc *property_desc,
4271 DBusMessageIter *iter, DBusError *error, void *user_data)
4272 {
4273 struct bss_handler_args *args = user_data;
4274 struct wpa_bss *res;
4275 dbus_bool_t privacy;
4276
4277 res = get_bss_helper(args, error, __func__);
4278 if (!res)
4279 return FALSE;
4280
4281 privacy = (res->caps & IEEE80211_CAP_PRIVACY) ? TRUE : FALSE;
4282 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
4283 &privacy, error);
4284 }
4285
4286
4287 /**
4288 * wpas_dbus_getter_bss_mode - Return the mode of a BSS
4289 * @iter: Pointer to incoming dbus message iter
4290 * @error: Location to store error on failure
4291 * @user_data: Function specific data
4292 * Returns: TRUE on success, FALSE on failure
4293 *
4294 * Getter for "Mode" property.
4295 */
4296 dbus_bool_t wpas_dbus_getter_bss_mode(
4297 const struct wpa_dbus_property_desc *property_desc,
4298 DBusMessageIter *iter, DBusError *error, void *user_data)
4299 {
4300 struct bss_handler_args *args = user_data;
4301 struct wpa_bss *res;
4302 const char *mode;
4303 const u8 *mesh;
4304
4305 res = get_bss_helper(args, error, __func__);
4306 if (!res)
4307 return FALSE;
4308 if (bss_is_dmg(res)) {
4309 switch (res->caps & IEEE80211_CAP_DMG_MASK) {
4310 case IEEE80211_CAP_DMG_PBSS:
4311 case IEEE80211_CAP_DMG_IBSS:
4312 mode = "ad-hoc";
4313 break;
4314 case IEEE80211_CAP_DMG_AP:
4315 mode = "infrastructure";
4316 break;
4317 default:
4318 mode = "";
4319 break;
4320 }
4321 } else {
4322 mesh = wpa_bss_get_ie(res, WLAN_EID_MESH_ID);
4323 if (mesh)
4324 mode = "mesh";
4325 else if (res->caps & IEEE80211_CAP_IBSS)
4326 mode = "ad-hoc";
4327 else
4328 mode = "infrastructure";
4329 }
4330
4331 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
4332 &mode, error);
4333 }
4334
4335
4336 /**
4337 * wpas_dbus_getter_bss_level - Return the signal strength of a BSS
4338 * @iter: Pointer to incoming dbus message iter
4339 * @error: Location to store error on failure
4340 * @user_data: Function specific data
4341 * Returns: TRUE on success, FALSE on failure
4342 *
4343 * Getter for "Level" property.
4344 */
4345 dbus_bool_t wpas_dbus_getter_bss_signal(
4346 const struct wpa_dbus_property_desc *property_desc,
4347 DBusMessageIter *iter, DBusError *error, void *user_data)
4348 {
4349 struct bss_handler_args *args = user_data;
4350 struct wpa_bss *res;
4351 s16 level;
4352
4353 res = get_bss_helper(args, error, __func__);
4354 if (!res)
4355 return FALSE;
4356
4357 level = (s16) res->level;
4358 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT16,
4359 &level, error);
4360 }
4361
4362
4363 /**
4364 * wpas_dbus_getter_bss_frequency - Return the frequency of a BSS
4365 * @iter: Pointer to incoming dbus message iter
4366 * @error: Location to store error on failure
4367 * @user_data: Function specific data
4368 * Returns: TRUE on success, FALSE on failure
4369 *
4370 * Getter for "Frequency" property.
4371 */
4372 dbus_bool_t wpas_dbus_getter_bss_frequency(
4373 const struct wpa_dbus_property_desc *property_desc,
4374 DBusMessageIter *iter, DBusError *error, void *user_data)
4375 {
4376 struct bss_handler_args *args = user_data;
4377 struct wpa_bss *res;
4378 u16 freq;
4379
4380 res = get_bss_helper(args, error, __func__);
4381 if (!res)
4382 return FALSE;
4383
4384 freq = (u16) res->freq;
4385 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
4386 &freq, error);
4387 }
4388
4389
4390 static int cmp_u8s_desc(const void *a, const void *b)
4391 {
4392 return (*(u8 *) b - *(u8 *) a);
4393 }
4394
4395
4396 /**
4397 * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
4398 * @iter: Pointer to incoming dbus message iter
4399 * @error: Location to store error on failure
4400 * @user_data: Function specific data
4401 * Returns: TRUE on success, FALSE on failure
4402 *
4403 * Getter for "Rates" property.
4404 */
4405 dbus_bool_t wpas_dbus_getter_bss_rates(
4406 const struct wpa_dbus_property_desc *property_desc,
4407 DBusMessageIter *iter, DBusError *error, void *user_data)
4408 {
4409 struct bss_handler_args *args = user_data;
4410 struct wpa_bss *res;
4411 u8 *ie_rates = NULL;
4412 u32 *real_rates;
4413 int rates_num, i;
4414 dbus_bool_t success = FALSE;
4415
4416 res = get_bss_helper(args, error, __func__);
4417 if (!res)
4418 return FALSE;
4419
4420 rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
4421 if (rates_num < 0)
4422 return FALSE;
4423
4424 qsort(ie_rates, rates_num, 1, cmp_u8s_desc);
4425
4426 real_rates = os_malloc(sizeof(u32) * rates_num);
4427 if (!real_rates) {
4428 os_free(ie_rates);
4429 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4430 return FALSE;
4431 }
4432
4433 for (i = 0; i < rates_num; i++)
4434 real_rates[i] = ie_rates[i] * 500000;
4435
4436 success = wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_UINT32,
4437 real_rates, rates_num,
4438 error);
4439
4440 os_free(ie_rates);
4441 os_free(real_rates);
4442 return success;
4443 }
4444
4445
4446 static dbus_bool_t wpas_dbus_get_bss_security_prop(
4447 const struct wpa_dbus_property_desc *property_desc,
4448 DBusMessageIter *iter, struct wpa_ie_data *ie_data, DBusError *error)
4449 {
4450 DBusMessageIter iter_dict, variant_iter;
4451 const char *group;
4452 const char *pairwise[5]; /* max 5 pairwise ciphers is supported */
4453 const char *key_mgmt[13]; /* max 13 key managements may be supported */
4454 int n;
4455
4456 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
4457 "a{sv}", &variant_iter))
4458 goto nomem;
4459
4460 if (!wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
4461 goto nomem;
4462
4463 /* KeyMgmt */
4464 n = 0;
4465 if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK)
4466 key_mgmt[n++] = "wpa-psk";
4467 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_PSK)
4468 key_mgmt[n++] = "wpa-ft-psk";
4469 if (ie_data->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
4470 key_mgmt[n++] = "wpa-psk-sha256";
4471 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X)
4472 key_mgmt[n++] = "wpa-eap";
4473 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
4474 key_mgmt[n++] = "wpa-ft-eap";
4475 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
4476 key_mgmt[n++] = "wpa-eap-sha256";
4477 #ifdef CONFIG_SUITEB
4478 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B)
4479 key_mgmt[n++] = "wpa-eap-suite-b";
4480 #endif /* CONFIG_SUITEB */
4481 #ifdef CONFIG_SUITEB192
4482 if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
4483 key_mgmt[n++] = "wpa-eap-suite-b-192";
4484 #endif /* CONFIG_SUITEB192 */
4485 #ifdef CONFIG_FILS
4486 if (ie_data->key_mgmt & WPA_KEY_MGMT_FILS_SHA256)
4487 key_mgmt[n++] = "wpa-fils-sha256";
4488 if (ie_data->key_mgmt & WPA_KEY_MGMT_FILS_SHA384)
4489 key_mgmt[n++] = "wpa-fils-sha384";
4490 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256)
4491 key_mgmt[n++] = "wpa-ft-fils-sha256";
4492 if (ie_data->key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384)
4493 key_mgmt[n++] = "wpa-ft-fils-sha384";
4494 #endif /* CONFIG_FILS */
4495 if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
4496 key_mgmt[n++] = "wpa-none";
4497
4498 if (!wpa_dbus_dict_append_string_array(&iter_dict, "KeyMgmt",
4499 key_mgmt, n))
4500 goto nomem;
4501
4502 /* Group */
4503 switch (ie_data->group_cipher) {
4504 case WPA_CIPHER_WEP40:
4505 group = "wep40";
4506 break;
4507 case WPA_CIPHER_TKIP:
4508 group = "tkip";
4509 break;
4510 case WPA_CIPHER_CCMP:
4511 group = "ccmp";
4512 break;
4513 case WPA_CIPHER_GCMP:
4514 group = "gcmp";
4515 break;
4516 case WPA_CIPHER_WEP104:
4517 group = "wep104";
4518 break;
4519 case WPA_CIPHER_CCMP_256:
4520 group = "ccmp-256";
4521 break;
4522 case WPA_CIPHER_GCMP_256:
4523 group = "gcmp-256";
4524 break;
4525 default:
4526 group = "";
4527 break;
4528 }
4529
4530 if (!wpa_dbus_dict_append_string(&iter_dict, "Group", group))
4531 goto nomem;
4532
4533 /* Pairwise */
4534 n = 0;
4535 if (ie_data->pairwise_cipher & WPA_CIPHER_TKIP)
4536 pairwise[n++] = "tkip";
4537 if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP)
4538 pairwise[n++] = "ccmp";
4539 if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP)
4540 pairwise[n++] = "gcmp";
4541 if (ie_data->pairwise_cipher & WPA_CIPHER_CCMP_256)
4542 pairwise[n++] = "ccmp-256";
4543 if (ie_data->pairwise_cipher & WPA_CIPHER_GCMP_256)
4544 pairwise[n++] = "gcmp-256";
4545
4546 if (!wpa_dbus_dict_append_string_array(&iter_dict, "Pairwise",
4547 pairwise, n))
4548 goto nomem;
4549
4550 /* Management group (RSN only) */
4551 if (ie_data->proto == WPA_PROTO_RSN) {
4552 switch (ie_data->mgmt_group_cipher) {
4553 #ifdef CONFIG_IEEE80211W
4554 case WPA_CIPHER_AES_128_CMAC:
4555 group = "aes128cmac";
4556 break;
4557 #endif /* CONFIG_IEEE80211W */
4558 default:
4559 group = "";
4560 break;
4561 }
4562
4563 if (!wpa_dbus_dict_append_string(&iter_dict, "MgmtGroup",
4564 group))
4565 goto nomem;
4566 }
4567
4568 if (!wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
4569 !dbus_message_iter_close_container(iter, &variant_iter))
4570 goto nomem;
4571
4572 return TRUE;
4573
4574 nomem:
4575 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4576 return FALSE;
4577 }
4578
4579
4580 /**
4581 * wpas_dbus_getter_bss_wpa - Return the WPA options of a BSS
4582 * @iter: Pointer to incoming dbus message iter
4583 * @error: Location to store error on failure
4584 * @user_data: Function specific data
4585 * Returns: TRUE on success, FALSE on failure
4586 *
4587 * Getter for "WPA" property.
4588 */
4589 dbus_bool_t wpas_dbus_getter_bss_wpa(
4590 const struct wpa_dbus_property_desc *property_desc,
4591 DBusMessageIter *iter, DBusError *error, void *user_data)
4592 {
4593 struct bss_handler_args *args = user_data;
4594 struct wpa_bss *res;
4595 struct wpa_ie_data wpa_data;
4596 const u8 *ie;
4597
4598 res = get_bss_helper(args, error, __func__);
4599 if (!res)
4600 return FALSE;
4601
4602 os_memset(&wpa_data, 0, sizeof(wpa_data));
4603 ie = wpa_bss_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
4604 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
4605 dbus_set_error_const(error, DBUS_ERROR_FAILED,
4606 "failed to parse WPA IE");
4607 return FALSE;
4608 }
4609
4610 return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
4611 }
4612
4613
4614 /**
4615 * wpas_dbus_getter_bss_rsn - Return the RSN options of a BSS
4616 * @iter: Pointer to incoming dbus message iter
4617 * @error: Location to store error on failure
4618 * @user_data: Function specific data
4619 * Returns: TRUE on success, FALSE on failure
4620 *
4621 * Getter for "RSN" property.
4622 */
4623 dbus_bool_t wpas_dbus_getter_bss_rsn(
4624 const struct wpa_dbus_property_desc *property_desc,
4625 DBusMessageIter *iter, DBusError *error, void *user_data)
4626 {
4627 struct bss_handler_args *args = user_data;
4628 struct wpa_bss *res;
4629 struct wpa_ie_data wpa_data;
4630 const u8 *ie;
4631
4632 res = get_bss_helper(args, error, __func__);
4633 if (!res)
4634 return FALSE;
4635
4636 os_memset(&wpa_data, 0, sizeof(wpa_data));
4637 ie = wpa_bss_get_ie(res, WLAN_EID_RSN);
4638 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &wpa_data) < 0) {
4639 dbus_set_error_const(error, DBUS_ERROR_FAILED,
4640 "failed to parse RSN IE");
4641 return FALSE;
4642 }
4643
4644 return wpas_dbus_get_bss_security_prop(property_desc, iter, &wpa_data, error);
4645 }
4646
4647
4648 /**
4649 * wpas_dbus_getter_bss_wps - Return the WPS options of a BSS
4650 * @iter: Pointer to incoming dbus message iter
4651 * @error: Location to store error on failure
4652 * @user_data: Function specific data
4653 * Returns: TRUE on success, FALSE on failure
4654 *
4655 * Getter for "WPS" property.
4656 */
4657 dbus_bool_t wpas_dbus_getter_bss_wps(
4658 const struct wpa_dbus_property_desc *property_desc,
4659 DBusMessageIter *iter, DBusError *error, void *user_data)
4660 {
4661 struct bss_handler_args *args = user_data;
4662 struct wpa_bss *res;
4663 #ifdef CONFIG_WPS
4664 struct wpabuf *wps_ie;
4665 #endif /* CONFIG_WPS */
4666 DBusMessageIter iter_dict, variant_iter;
4667 int wps_support = 0;
4668 const char *type = "";
4669
4670 res = get_bss_helper(args, error, __func__);
4671 if (!res)
4672 return FALSE;
4673
4674 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
4675 "a{sv}", &variant_iter) ||
4676 !wpa_dbus_dict_open_write(&variant_iter, &iter_dict))
4677 goto nomem;
4678
4679 #ifdef CONFIG_WPS
4680 wps_ie = wpa_bss_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
4681 if (wps_ie) {
4682 wps_support = 1;
4683 if (wps_is_selected_pbc_registrar(wps_ie))
4684 type = "pbc";
4685 else if (wps_is_selected_pin_registrar(wps_ie))
4686 type = "pin";
4687
4688 wpabuf_free(wps_ie);
4689 }
4690 #endif /* CONFIG_WPS */
4691
4692 if ((wps_support && !wpa_dbus_dict_append_string(&iter_dict, "Type", type)) ||
4693 !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
4694 !dbus_message_iter_close_container(iter, &variant_iter))
4695 goto nomem;
4696
4697 return TRUE;
4698
4699 nomem:
4700 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4701 return FALSE;
4702 }
4703
4704
4705 /**
4706 * wpas_dbus_getter_bss_ies - Return all IEs of a BSS
4707 * @iter: Pointer to incoming dbus message iter
4708 * @error: Location to store error on failure
4709 * @user_data: Function specific data
4710 * Returns: TRUE on success, FALSE on failure
4711 *
4712 * Getter for "IEs" property.
4713 */
4714 dbus_bool_t wpas_dbus_getter_bss_ies(
4715 const struct wpa_dbus_property_desc *property_desc,
4716 DBusMessageIter *iter, DBusError *error, void *user_data)
4717 {
4718 struct bss_handler_args *args = user_data;
4719 struct wpa_bss *res;
4720
4721 res = get_bss_helper(args, error, __func__);
4722 if (!res)
4723 return FALSE;
4724
4725 return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
4726 res + 1, res->ie_len,
4727 error);
4728 }
4729
4730
4731 /**
4732 * wpas_dbus_getter_bss_age - Return time in seconds since BSS was last seen
4733 * @iter: Pointer to incoming dbus message iter
4734 * @error: Location to store error on failure
4735 * @user_data: Function specific data
4736 * Returns: TRUE on success, FALSE on failure
4737 *
4738 * Getter for BSS age
4739 */
4740 dbus_bool_t wpas_dbus_getter_bss_age(
4741 const struct wpa_dbus_property_desc *property_desc,
4742 DBusMessageIter *iter, DBusError *error, void *user_data)
4743 {
4744 struct bss_handler_args *args = user_data;
4745 struct wpa_bss *res;
4746 struct os_reltime now, diff = { 0, 0 };
4747 u32 age;
4748
4749 res = get_bss_helper(args, error, __func__);
4750 if (!res)
4751 return FALSE;
4752
4753 os_get_reltime(&now);
4754 os_reltime_sub(&now, &res->last_update, &diff);
4755 age = diff.sec > 0 ? diff.sec : 0;
4756 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT32, &age,
4757 error);
4758 }
4759
4760
4761 /**
4762 * wpas_dbus_getter_enabled - Check whether network is enabled or disabled
4763 * @iter: Pointer to incoming dbus message iter
4764 * @error: Location to store error on failure
4765 * @user_data: Function specific data
4766 * Returns: TRUE on success, FALSE on failure
4767 *
4768 * Getter for "enabled" property of a configured network.
4769 */
4770 dbus_bool_t wpas_dbus_getter_enabled(
4771 const struct wpa_dbus_property_desc *property_desc,
4772 DBusMessageIter *iter, DBusError *error, void *user_data)
4773 {
4774 struct network_handler_args *net = user_data;
4775 dbus_bool_t enabled = net->ssid->disabled ? FALSE : TRUE;
4776
4777 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
4778 &enabled, error);
4779 }
4780
4781
4782 /**
4783 * wpas_dbus_setter_enabled - Mark a configured network as enabled or disabled
4784 * @iter: Pointer to incoming dbus message iter
4785 * @error: Location to store error on failure
4786 * @user_data: Function specific data
4787 * Returns: TRUE on success, FALSE on failure
4788 *
4789 * Setter for "Enabled" property of a configured network.
4790 */
4791 dbus_bool_t wpas_dbus_setter_enabled(
4792 const struct wpa_dbus_property_desc *property_desc,
4793 DBusMessageIter *iter, DBusError *error, void *user_data)
4794 {
4795 struct network_handler_args *net = user_data;
4796 struct wpa_supplicant *wpa_s;
4797 struct wpa_ssid *ssid;
4798 dbus_bool_t enable;
4799
4800 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN,
4801 &enable))
4802 return FALSE;
4803
4804 wpa_s = net->wpa_s;
4805 ssid = net->ssid;
4806
4807 if (enable)
4808 wpa_supplicant_enable_network(wpa_s, ssid);
4809 else
4810 wpa_supplicant_disable_network(wpa_s, ssid);
4811
4812 return TRUE;
4813 }
4814
4815
4816 /**
4817 * wpas_dbus_getter_network_properties - Get options for a configured network
4818 * @iter: Pointer to incoming dbus message iter
4819 * @error: Location to store error on failure
4820 * @user_data: Function specific data
4821 * Returns: TRUE on success, FALSE on failure
4822 *
4823 * Getter for "Properties" property of a configured network.
4824 */
4825 dbus_bool_t wpas_dbus_getter_network_properties(
4826 const struct wpa_dbus_property_desc *property_desc,
4827 DBusMessageIter *iter, DBusError *error, void *user_data)
4828 {
4829 struct network_handler_args *net = user_data;
4830 DBusMessageIter variant_iter, dict_iter;
4831 char **iterator;
4832 char **props = wpa_config_get_all(net->ssid, 1);
4833 dbus_bool_t success = FALSE;
4834
4835 if (!props) {
4836 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4837 return FALSE;
4838 }
4839
4840 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
4841 &variant_iter) ||
4842 !wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
4843 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4844 goto out;
4845 }
4846
4847 iterator = props;
4848 while (*iterator) {
4849 if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
4850 *(iterator + 1))) {
4851 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY,
4852 "no memory");
4853 goto out;
4854 }
4855 iterator += 2;
4856 }
4857
4858
4859 if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
4860 !dbus_message_iter_close_container(iter, &variant_iter)) {
4861 dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
4862 goto out;
4863 }
4864
4865 success = TRUE;
4866
4867 out:
4868 iterator = props;
4869 while (*iterator) {
4870 os_free(*iterator);
4871 iterator++;
4872 }
4873 os_free(props);
4874 return success;
4875 }
4876
4877
4878 /**
4879 * wpas_dbus_setter_network_properties - Set options for a configured network
4880 * @iter: Pointer to incoming dbus message iter
4881 * @error: Location to store error on failure
4882 * @user_data: Function specific data
4883 * Returns: TRUE on success, FALSE on failure
4884 *
4885 * Setter for "Properties" property of a configured network.
4886 */
4887 dbus_bool_t wpas_dbus_setter_network_properties(
4888 const struct wpa_dbus_property_desc *property_desc,
4889 DBusMessageIter *iter, DBusError *error, void *user_data)
4890 {
4891 struct network_handler_args *net = user_data;
4892 struct wpa_ssid *ssid = net->ssid;
4893 DBusMessageIter variant_iter;
4894
4895 dbus_message_iter_recurse(iter, &variant_iter);
4896 return set_network_properties(net->wpa_s, ssid, &variant_iter, error);
4897 }
4898
4899
4900 #ifdef CONFIG_AP
4901
4902 DBusMessage * wpas_dbus_handler_subscribe_preq(
4903 DBusMessage *message, struct wpa_supplicant *wpa_s)
4904 {
4905 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
4906 char *name;
4907
4908 if (wpa_s->preq_notify_peer != NULL) {
4909 if (os_strcmp(dbus_message_get_sender(message),
4910 wpa_s->preq_notify_peer) == 0)
4911 return NULL;
4912
4913 return dbus_message_new_error(message,
4914 WPAS_DBUS_ERROR_SUBSCRIPTION_IN_USE,
4915 "Another application is already subscribed");
4916 }
4917
4918 name = os_strdup(dbus_message_get_sender(message));
4919 if (!name)
4920 return wpas_dbus_error_no_memory(message);
4921
4922 wpa_s->preq_notify_peer = name;
4923
4924 /* Subscribe to clean up if application closes socket */
4925 wpas_dbus_subscribe_noc(priv);
4926
4927 /*
4928 * Double-check it's still alive to make sure that we didn't
4929 * miss the NameOwnerChanged signal, e.g. while strdup'ing.
4930 */
4931 if (!dbus_bus_name_has_owner(priv->con, name, NULL)) {
4932 /*
4933 * Application no longer exists, clean up.
4934 * The return value is irrelevant now.
4935 *
4936 * Need to check if the NameOwnerChanged handling
4937 * already cleaned up because we have processed
4938 * DBus messages while checking if the name still
4939 * has an owner.
4940 */
4941 if (!wpa_s->preq_notify_peer)
4942 return NULL;
4943 os_free(wpa_s->preq_notify_peer);
4944 wpa_s->preq_notify_peer = NULL;
4945 wpas_dbus_unsubscribe_noc(priv);
4946 }
4947
4948 return NULL;
4949 }
4950
4951
4952 DBusMessage * wpas_dbus_handler_unsubscribe_preq(
4953 DBusMessage *message, struct wpa_supplicant *wpa_s)
4954 {
4955 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
4956
4957 if (!wpa_s->preq_notify_peer)
4958 return dbus_message_new_error(message,
4959 WPAS_DBUS_ERROR_NO_SUBSCRIPTION,
4960 "Not subscribed");
4961
4962 if (os_strcmp(wpa_s->preq_notify_peer,
4963 dbus_message_get_sender(message)))
4964 return dbus_message_new_error(message,
4965 WPAS_DBUS_ERROR_SUBSCRIPTION_EPERM,
4966 "Can't unsubscribe others");
4967
4968 os_free(wpa_s->preq_notify_peer);
4969 wpa_s->preq_notify_peer = NULL;
4970 wpas_dbus_unsubscribe_noc(priv);
4971 return NULL;
4972 }
4973
4974
4975 void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s,
4976 const u8 *addr, const u8 *dst, const u8 *bssid,
4977 const u8 *ie, size_t ie_len, u32 ssi_signal)
4978 {
4979 DBusMessage *msg;
4980 DBusMessageIter iter, dict_iter;
4981 struct wpas_dbus_priv *priv = wpa_s->global->dbus;
4982
4983 /* Do nothing if the control interface is not turned on */
4984 if (priv == NULL || !wpa_s->dbus_new_path)
4985 return;
4986
4987 if (wpa_s->preq_notify_peer == NULL)
4988 return;
4989
4990 msg = dbus_message_new_signal(wpa_s->dbus_new_path,
4991 WPAS_DBUS_NEW_IFACE_INTERFACE,
4992 "ProbeRequest");
4993 if (msg == NULL)
4994 return;
4995
4996 dbus_message_set_destination(msg, wpa_s->preq_notify_peer);
4997
4998 dbus_message_iter_init_append(msg, &iter);
4999
5000 if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
5001 (addr && !wpa_dbus_dict_append_byte_array(&dict_iter, "addr",
5002 (const char *) addr,
5003 ETH_ALEN)) ||
5004 (dst && !wpa_dbus_dict_append_byte_array(&dict_iter, "dst",
5005 (const char *) dst,
5006 ETH_ALEN)) ||
5007 (bssid && !wpa_dbus_dict_append_byte_array(&dict_iter, "bssid",
5008 (const char *) bssid,
5009 ETH_ALEN)) ||
5010 (ie && ie_len && !wpa_dbus_dict_append_byte_array(&dict_iter, "ies",
5011 (const char *) ie,
5012 ie_len)) ||
5013 (ssi_signal && !wpa_dbus_dict_append_int32(&dict_iter, "signal",
5014 ssi_signal)) ||
5015 !wpa_dbus_dict_close_write(&iter, &dict_iter))
5016 goto fail;
5017
5018 dbus_connection_send(priv->con, msg, NULL);
5019 goto out;
5020 fail:
5021 wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
5022 out:
5023 dbus_message_unref(msg);
5024 }
5025
5026 #endif /* CONFIG_AP */
5027
5028
5029 DBusMessage * wpas_dbus_handler_vendor_elem_add(DBusMessage *message,
5030 struct wpa_supplicant *wpa_s)
5031 {
5032 u8 *ielems;
5033 int len;
5034 struct ieee802_11_elems elems;
5035 dbus_int32_t frame_id;
5036 DBusMessageIter iter, array;
5037
5038 dbus_message_iter_init(message, &iter);
5039 dbus_message_iter_get_basic(&iter, &frame_id);
5040 if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
5041 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5042 "Invalid ID");
5043 }
5044
5045 dbus_message_iter_next(&iter);
5046 dbus_message_iter_recurse(&iter, &array);
5047 dbus_message_iter_get_fixed_array(&array, &ielems, &len);
5048 if (!ielems || len == 0) {
5049 return dbus_message_new_error(
5050 message, DBUS_ERROR_INVALID_ARGS, "Invalid value");
5051 }
5052
5053 if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) {
5054 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5055 "Parse error");
5056 }
5057
5058 wpa_s = wpas_vendor_elem(wpa_s, frame_id);
5059 if (!wpa_s->vendor_elem[frame_id]) {
5060 wpa_s->vendor_elem[frame_id] = wpabuf_alloc_copy(ielems, len);
5061 wpas_vendor_elem_update(wpa_s);
5062 return NULL;
5063 }
5064
5065 if (wpabuf_resize(&wpa_s->vendor_elem[frame_id], len) < 0) {
5066 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5067 "Resize error");
5068 }
5069
5070 wpabuf_put_data(wpa_s->vendor_elem[frame_id], ielems, len);
5071 wpas_vendor_elem_update(wpa_s);
5072 return NULL;
5073 }
5074
5075
5076 DBusMessage * wpas_dbus_handler_vendor_elem_get(DBusMessage *message,
5077 struct wpa_supplicant *wpa_s)
5078 {
5079 DBusMessage *reply;
5080 DBusMessageIter iter, array_iter;
5081 dbus_int32_t frame_id;
5082 const u8 *elem;
5083 size_t elem_len;
5084
5085 dbus_message_iter_init(message, &iter);
5086 dbus_message_iter_get_basic(&iter, &frame_id);
5087
5088 if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
5089 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5090 "Invalid ID");
5091 }
5092
5093 wpa_s = wpas_vendor_elem(wpa_s, frame_id);
5094 if (!wpa_s->vendor_elem[frame_id]) {
5095 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5096 "ID value does not exist");
5097 }
5098
5099 reply = dbus_message_new_method_return(message);
5100 if (!reply)
5101 return wpas_dbus_error_no_memory(message);
5102
5103 dbus_message_iter_init_append(reply, &iter);
5104
5105 elem = wpabuf_head_u8(wpa_s->vendor_elem[frame_id]);
5106 elem_len = wpabuf_len(wpa_s->vendor_elem[frame_id]);
5107
5108 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
5109 DBUS_TYPE_BYTE_AS_STRING,
5110 &array_iter) ||
5111 !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
5112 &elem, elem_len) ||
5113 !dbus_message_iter_close_container(&iter, &array_iter)) {
5114 dbus_message_unref(reply);
5115 reply = wpas_dbus_error_no_memory(message);
5116 }
5117
5118 return reply;
5119 }
5120
5121
5122 DBusMessage * wpas_dbus_handler_vendor_elem_remove(DBusMessage *message,
5123 struct wpa_supplicant *wpa_s)
5124 {
5125 u8 *ielems;
5126 int len;
5127 struct ieee802_11_elems elems;
5128 DBusMessageIter iter, array;
5129 dbus_int32_t frame_id;
5130
5131 dbus_message_iter_init(message, &iter);
5132 dbus_message_iter_get_basic(&iter, &frame_id);
5133 if (frame_id < 0 || frame_id >= NUM_VENDOR_ELEM_FRAMES) {
5134 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5135 "Invalid ID");
5136 }
5137
5138 dbus_message_iter_next(&iter);
5139 dbus_message_iter_recurse(&iter, &array);
5140 dbus_message_iter_get_fixed_array(&array, &ielems, &len);
5141 if (!ielems || len == 0) {
5142 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5143 "Invalid value");
5144 }
5145
5146 wpa_s = wpas_vendor_elem(wpa_s, frame_id);
5147
5148 if (len == 1 && *ielems == '*') {
5149 wpabuf_free(wpa_s->vendor_elem[frame_id]);
5150 wpa_s->vendor_elem[frame_id] = NULL;
5151 wpas_vendor_elem_update(wpa_s);
5152 return NULL;
5153 }
5154
5155 if (!wpa_s->vendor_elem[frame_id]) {
5156 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5157 "ID value does not exist");
5158 }
5159
5160 if (ieee802_11_parse_elems(ielems, len, &elems, 0) == ParseFailed) {
5161 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5162 "Parse error");
5163 }
5164
5165 if (wpas_vendor_elem_remove(wpa_s, frame_id, ielems, len) == 0)
5166 return NULL;
5167
5168 return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
5169 "Not found");
5170 }
5171
5172
5173 #ifdef CONFIG_MESH
5174
5175 /**
5176 * wpas_dbus_getter_mesh_peers - Get connected mesh peers
5177 * @iter: Pointer to incoming dbus message iter
5178 * @error: Location to store error on failure
5179 * @user_data: Function specific data
5180 * Returns: TRUE on success, FALSE on failure
5181 *
5182 * Getter for "MeshPeers" property.
5183 */
5184 dbus_bool_t wpas_dbus_getter_mesh_peers(
5185 const struct wpa_dbus_property_desc *property_desc,
5186 DBusMessageIter *iter, DBusError *error, void *user_data)
5187 {
5188 struct wpa_supplicant *wpa_s = user_data;
5189 struct hostapd_data *hapd;
5190 struct sta_info *sta;
5191 DBusMessageIter variant_iter, array_iter;
5192 int i;
5193 DBusMessageIter inner_array_iter;
5194
5195 if (!wpa_s->ifmsh)
5196 return FALSE;
5197 hapd = wpa_s->ifmsh->bss[0];
5198
5199 if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
5200 DBUS_TYPE_ARRAY_AS_STRING
5201 DBUS_TYPE_ARRAY_AS_STRING
5202 DBUS_TYPE_BYTE_AS_STRING,
5203 &variant_iter) ||
5204 !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
5205 DBUS_TYPE_ARRAY_AS_STRING
5206 DBUS_TYPE_BYTE_AS_STRING,
5207 &array_iter))
5208 return FALSE;
5209
5210 for (sta = hapd->sta_list; sta; sta = sta->next) {
5211 if (!dbus_message_iter_open_container(
5212 &array_iter, DBUS_TYPE_ARRAY,
5213 DBUS_TYPE_BYTE_AS_STRING,
5214 &inner_array_iter))
5215 return FALSE;
5216
5217 for (i = 0; i < ETH_ALEN; i++) {
5218 if (!dbus_message_iter_append_basic(&inner_array_iter,
5219 DBUS_TYPE_BYTE,
5220 &(sta->addr[i])))
5221 return FALSE;
5222 }
5223
5224 if (!dbus_message_iter_close_container(
5225 &array_iter, &inner_array_iter))
5226 return FALSE;
5227 }
5228
5229 if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
5230 !dbus_message_iter_close_container(iter, &variant_iter))
5231 return FALSE;
5232
5233 return TRUE;
5234 }
5235
5236
5237 /**
5238 * wpas_dbus_getter_mesh_group - Get mesh group
5239 * @iter: Pointer to incoming dbus message iter
5240 * @error: Location to store error on failure
5241 * @user_data: Function specific data
5242 * Returns: TRUE on success, FALSE on failure
5243 *
5244 * Getter for "MeshGroup" property.
5245 */
5246 dbus_bool_t wpas_dbus_getter_mesh_group(
5247 const struct wpa_dbus_property_desc *property_desc,
5248 DBusMessageIter *iter, DBusError *error, void *user_data)
5249 {
5250 struct wpa_supplicant *wpa_s = user_data;
5251 struct wpa_ssid *ssid = wpa_s->current_ssid;
5252
5253 if (!wpa_s->ifmsh || !ssid)
5254 return FALSE;
5255
5256 if (!wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
5257 (char *) ssid->ssid,
5258 ssid->ssid_len, error)) {
5259 dbus_set_error(error, DBUS_ERROR_FAILED,
5260 "%s: error constructing reply", __func__);
5261 return FALSE;
5262 }
5263
5264 return TRUE;
5265 }
5266
5267 #endif /* CONFIG_MESH */