5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "supplicant-dbus.h"
35 #include "supplicant.h"
37 #define DBG(fmt, arg...) do { \
38 syslog(LOG_DEBUG, "%s() " fmt, __FUNCTION__ , ## arg); \
43 #define IEEE80211_CAP_ESS 0x0001
44 #define IEEE80211_CAP_IBSS 0x0002
45 #define IEEE80211_CAP_PRIVACY 0x0010
47 static DBusConnection *connection;
49 static const struct supplicant_callbacks *callbacks_pointer;
51 static dbus_bool_t system_available = FALSE;
52 static dbus_bool_t system_ready = FALSE;
54 static dbus_int32_t debug_level = 0;
55 static dbus_bool_t debug_timestamp = FALSE;
56 static dbus_bool_t debug_showkeys = FALSE;
58 static const char *debug_strings[] = {
59 "msgdump", "debug", "info", "warning", "error", NULL
62 static unsigned int eap_methods;
69 static struct strvalmap eap_method_map[] = {
70 { "MD5", SUPPLICANT_EAP_METHOD_MD5 },
71 { "TLS", SUPPLICANT_EAP_METHOD_TLS },
72 { "MSCHAPV2", SUPPLICANT_EAP_METHOD_MSCHAPV2 },
73 { "PEAP", SUPPLICANT_EAP_METHOD_PEAP },
74 { "TTLS", SUPPLICANT_EAP_METHOD_TTLS },
75 { "GTC", SUPPLICANT_EAP_METHOD_GTC },
76 { "OTP", SUPPLICANT_EAP_METHOD_OTP },
77 { "LEAP", SUPPLICANT_EAP_METHOD_LEAP },
78 { "WSC", SUPPLICANT_EAP_METHOD_WSC },
82 static struct strvalmap keymgmt_capa_map[] = {
83 { "none", SUPPLICANT_CAPABILITY_KEYMGMT_NONE },
84 { "ieee8021x", SUPPLICANT_CAPABILITY_KEYMGMT_IEEE8021X },
85 { "wpa-none", SUPPLICANT_CAPABILITY_KEYMGMT_WPA_NONE },
86 { "wpa-psk", SUPPLICANT_CAPABILITY_KEYMGMT_WPA_PSK },
87 { "wpa-eap", SUPPLICANT_CAPABILITY_KEYMGMT_WPA_EAP },
88 { "wps", SUPPLICANT_CAPABILITY_KEYMGMT_WPS },
92 static struct strvalmap authalg_capa_map[] = {
93 { "open", SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
94 { "shared", SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
95 { "leap", SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
99 static struct strvalmap proto_capa_map[] = {
100 { "wpa", SUPPLICANT_CAPABILITY_PROTO_WPA },
101 { "rsn", SUPPLICANT_CAPABILITY_PROTO_RSN },
105 static struct strvalmap group_capa_map[] = {
106 { "wep40", SUPPLICANT_CAPABILITY_GROUP_WEP40 },
107 { "wep104", SUPPLICANT_CAPABILITY_GROUP_WEP104 },
108 { "tkip", SUPPLICANT_CAPABILITY_GROUP_TKIP },
109 { "ccmp", SUPPLICANT_CAPABILITY_GROUP_CCMP },
113 static struct strvalmap pairwise_capa_map[] = {
114 { "none", SUPPLICANT_CAPABILITY_PAIRWISE_NONE },
115 { "tkip", SUPPLICANT_CAPABILITY_PAIRWISE_TKIP },
116 { "ccmp", SUPPLICANT_CAPABILITY_PAIRWISE_CCMP },
120 static struct strvalmap scan_capa_map[] = {
121 { "active", SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
122 { "passive", SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
123 { "ssid", SUPPLICANT_CAPABILITY_SCAN_SSID },
127 static struct strvalmap mode_capa_map[] = {
128 { "infrastructure", SUPPLICANT_CAPABILITY_MODE_INFRA },
129 { "ad-hoc", SUPPLICANT_CAPABILITY_MODE_IBSS },
130 { "ap", SUPPLICANT_CAPABILITY_MODE_AP },
134 static GHashTable *interface_table;
135 static GHashTable *bss_mapping;
137 struct supplicant_interface {
139 unsigned int keymgmt_capa;
140 unsigned int authalg_capa;
141 unsigned int proto_capa;
142 unsigned int group_capa;
143 unsigned int pairwise_capa;
144 unsigned int scan_capa;
145 unsigned int mode_capa;
147 enum supplicant_state state;
148 dbus_bool_t scanning;
149 supplicant_interface_scan_callback scan_callback;
155 GHashTable *network_table;
156 GHashTable *net_mapping;
157 GHashTable *bss_mapping;
160 struct supplicant_network {
161 struct supplicant_interface *interface;
165 enum supplicant_mode mode;
166 GHashTable *bss_table;
167 GHashTable *config_table;
170 struct supplicant_bss {
171 struct supplicant_interface *interface;
173 unsigned char bssid[6];
174 unsigned char ssid[32];
175 unsigned int ssid_len;
176 dbus_uint16_t frequency;
177 dbus_uint32_t maxrate;
178 enum supplicant_mode mode;
179 enum supplicant_security security;
182 dbus_bool_t ieee8021x;
185 static enum supplicant_mode string2mode(const char *mode)
188 return SUPPLICANT_MODE_UNKNOWN;
190 if (g_str_equal(mode, "infrastructure") == TRUE)
191 return SUPPLICANT_MODE_INFRA;
192 else if (g_str_equal(mode, "ad-hoc") == TRUE)
193 return SUPPLICANT_MODE_IBSS;
195 return SUPPLICANT_MODE_UNKNOWN;
198 static const char *mode2string(enum supplicant_mode mode)
201 case SUPPLICANT_MODE_UNKNOWN:
203 case SUPPLICANT_MODE_INFRA:
205 case SUPPLICANT_MODE_IBSS:
212 static const char *security2string(enum supplicant_security security)
215 case SUPPLICANT_SECURITY_UNKNOWN:
217 case SUPPLICANT_SECURITY_NONE:
219 case SUPPLICANT_SECURITY_WEP:
221 case SUPPLICANT_SECURITY_PSK:
223 case SUPPLICANT_SECURITY_IEEE8021X:
230 static enum supplicant_state string2state(const char *state)
233 return SUPPLICANT_STATE_UNKNOWN;
235 if (g_str_equal(state, "unknown") == TRUE)
236 return SUPPLICANT_STATE_UNKNOWN;
237 else if (g_str_equal(state, "disconnected") == TRUE)
238 return SUPPLICANT_STATE_DISCONNECTED;
239 else if (g_str_equal(state, "inactive") == TRUE)
240 return SUPPLICANT_STATE_INACTIVE;
241 else if (g_str_equal(state, "scanning") == TRUE)
242 return SUPPLICANT_STATE_SCANNING;
243 else if (g_str_equal(state, "authenticating") == TRUE)
244 return SUPPLICANT_STATE_AUTHENTICATING;
245 else if (g_str_equal(state, "associating") == TRUE)
246 return SUPPLICANT_STATE_ASSOCIATING;
247 else if (g_str_equal(state, "associated") == TRUE)
248 return SUPPLICANT_STATE_ASSOCIATED;
249 else if (g_str_equal(state, "group_handshake") == TRUE)
250 return SUPPLICANT_STATE_GROUP_HANDSHAKE;
251 else if (g_str_equal(state, "4way_handshake") == TRUE)
252 return SUPPLICANT_STATE_4WAY_HANDSHAKE;
253 else if (g_str_equal(state, "completed") == TRUE)
254 return SUPPLICANT_STATE_COMPLETED;
256 return SUPPLICANT_STATE_UNKNOWN;
259 static void callback_system_ready(void)
261 if (system_ready == TRUE)
266 if (callbacks_pointer == NULL)
269 if (callbacks_pointer->system_ready == NULL)
272 callbacks_pointer->system_ready();
275 static void callback_system_killed(void)
277 system_ready = FALSE;
279 if (callbacks_pointer == NULL)
282 if (callbacks_pointer->system_killed == NULL)
285 callbacks_pointer->system_killed();
288 static void callback_interface_added(struct supplicant_interface *interface)
290 if (callbacks_pointer == NULL)
293 if (callbacks_pointer->interface_added == NULL)
296 callbacks_pointer->interface_added(interface);
299 static void callback_interface_removed(struct supplicant_interface *interface)
301 if (callbacks_pointer == NULL)
304 if (callbacks_pointer->interface_removed == NULL)
307 callbacks_pointer->interface_removed(interface);
310 static void callback_scan_started(struct supplicant_interface *interface)
312 if (callbacks_pointer == NULL)
315 if (callbacks_pointer->scan_started == NULL)
318 callbacks_pointer->scan_started(interface);
321 static void callback_scan_finished(struct supplicant_interface *interface)
323 if (callbacks_pointer == NULL)
326 if (callbacks_pointer->scan_finished == NULL)
329 callbacks_pointer->scan_finished(interface);
332 static void callback_network_added(struct supplicant_network *network)
334 if (callbacks_pointer == NULL)
337 if (callbacks_pointer->network_added == NULL)
340 callbacks_pointer->network_added(network);
343 static void callback_network_removed(struct supplicant_network *network)
345 if (callbacks_pointer == NULL)
348 if (callbacks_pointer->network_removed == NULL)
351 callbacks_pointer->network_removed(network);
354 static void remove_interface(gpointer data)
356 struct supplicant_interface *interface = data;
358 g_hash_table_destroy(interface->bss_mapping);
359 g_hash_table_destroy(interface->net_mapping);
360 g_hash_table_destroy(interface->network_table);
362 callback_interface_removed(interface);
364 g_free(interface->path);
365 g_free(interface->ifname);
366 g_free(interface->driver);
367 g_free(interface->bridge);
371 static void remove_network(gpointer data)
373 struct supplicant_network *network = data;
375 g_hash_table_destroy(network->bss_table);
377 callback_network_removed(network);
379 g_hash_table_destroy(network->config_table);
381 g_free(network->group);
382 g_free(network->name);
386 static void remove_bss(gpointer data)
388 struct supplicant_bss *bss = data;
394 static void debug_strvalmap(const char *label, struct strvalmap *map,
399 for (i = 0; map[i].str != NULL; i++) {
400 if (val & map[i].val)
401 DBG("%s: %s", label, map[i].str);
405 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
407 struct supplicant_interface *interface = user_data;
408 const char *str = NULL;
411 dbus_message_iter_get_basic(iter, &str);
415 for (i = 0; keymgmt_capa_map[i].str != NULL; i++)
416 if (strcmp(str, keymgmt_capa_map[i].str) == 0) {
417 interface->keymgmt_capa |= keymgmt_capa_map[i].val;
422 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
424 struct supplicant_interface *interface = user_data;
425 const char *str = NULL;
428 dbus_message_iter_get_basic(iter, &str);
432 for (i = 0; authalg_capa_map[i].str != NULL; i++)
433 if (strcmp(str, authalg_capa_map[i].str) == 0) {
434 interface->authalg_capa |= authalg_capa_map[i].val;
439 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
441 struct supplicant_interface *interface = user_data;
442 const char *str = NULL;
445 dbus_message_iter_get_basic(iter, &str);
449 for (i = 0; proto_capa_map[i].str != NULL; i++)
450 if (strcmp(str, proto_capa_map[i].str) == 0) {
451 interface->proto_capa |= proto_capa_map[i].val;
456 static void interface_capability_pairwise(DBusMessageIter *iter, void *user_data)
458 struct supplicant_interface *interface = user_data;
459 const char *str = NULL;
462 dbus_message_iter_get_basic(iter, &str);
466 for (i = 0; pairwise_capa_map[i].str != NULL; i++)
467 if (strcmp(str, pairwise_capa_map[i].str) == 0) {
468 interface->pairwise_capa |= pairwise_capa_map[i].val;
473 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
475 struct supplicant_interface *interface = user_data;
476 const char *str = NULL;
479 dbus_message_iter_get_basic(iter, &str);
483 for (i = 0; group_capa_map[i].str != NULL; i++)
484 if (strcmp(str, group_capa_map[i].str) == 0) {
485 interface->group_capa |= group_capa_map[i].val;
490 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
492 struct supplicant_interface *interface = user_data;
493 const char *str = NULL;
496 dbus_message_iter_get_basic(iter, &str);
500 for (i = 0; scan_capa_map[i].str != NULL; i++)
501 if (strcmp(str, scan_capa_map[i].str) == 0) {
502 interface->scan_capa |= scan_capa_map[i].val;
507 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
509 struct supplicant_interface *interface = user_data;
510 const char *str = NULL;
513 dbus_message_iter_get_basic(iter, &str);
517 for (i = 0; mode_capa_map[i].str != NULL; i++)
518 if (strcmp(str, mode_capa_map[i].str) == 0) {
519 interface->mode_capa |= mode_capa_map[i].val;
524 static void interface_capability(const char *key, DBusMessageIter *iter,
527 struct supplicant_interface *interface = user_data;
532 if (g_strcmp0(key, "KeyMgmt") == 0)
533 supplicant_dbus_array_foreach(iter,
534 interface_capability_keymgmt, interface);
535 else if (g_strcmp0(key, "AuthAlg") == 0)
536 supplicant_dbus_array_foreach(iter,
537 interface_capability_authalg, interface);
538 else if (g_strcmp0(key, "Protocol") == 0)
539 supplicant_dbus_array_foreach(iter,
540 interface_capability_proto, interface);
541 else if (g_strcmp0(key, "Pairwise") == 0)
542 supplicant_dbus_array_foreach(iter,
543 interface_capability_pairwise, interface);
544 else if (g_strcmp0(key, "Group") == 0)
545 supplicant_dbus_array_foreach(iter,
546 interface_capability_group, interface);
547 else if (g_strcmp0(key, "Scan") == 0)
548 supplicant_dbus_array_foreach(iter,
549 interface_capability_scan, interface);
550 else if (g_strcmp0(key, "Modes") == 0)
551 supplicant_dbus_array_foreach(iter,
552 interface_capability_mode, interface);
554 DBG("key %s type %c",
555 key, dbus_message_iter_get_arg_type(iter));
558 const char *supplicant_interface_get_ifname(struct supplicant_interface *interface)
560 if (interface == NULL)
563 return interface->ifname;
566 const char *supplicant_interface_get_driver(struct supplicant_interface *interface)
568 if (interface == NULL)
571 return interface->driver;
574 struct supplicant_interface *supplicant_network_get_interface(struct supplicant_network *network)
579 return network->interface;
582 const char *supplicant_network_get_name(struct supplicant_network *network)
584 if (network == NULL || network->name == NULL)
587 return network->name;
590 const char *supplicant_network_get_identifier(struct supplicant_network *network)
592 if (network == NULL || network->group == NULL)
595 return network->group;
598 enum supplicant_mode supplicant_network_get_mode(struct supplicant_network *network)
601 return SUPPLICANT_MODE_UNKNOWN;
603 return network->mode;
606 static void merge_network(struct supplicant_network *network)
609 const char *ssid, *mode, *key_mgmt;
610 unsigned int i, ssid_len;
613 ssid = g_hash_table_lookup(network->config_table, "ssid");
614 mode = g_hash_table_lookup(network->config_table, "mode");
615 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
617 DBG("ssid %s mode %s", ssid, mode);
620 ssid_len = strlen(ssid);
624 str = g_string_sized_new((ssid_len * 2) + 24);
628 for (i = 0; i < ssid_len; i++)
629 g_string_append_printf(str, "%02x", ssid[i]);
631 if (g_strcmp0(mode, "0") == 0)
632 g_string_append_printf(str, "_infra");
633 else if (g_strcmp0(mode, "1") == 0)
634 g_string_append_printf(str, "_adhoc");
636 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
637 g_string_append_printf(str, "_psk");
639 group = g_string_free(str, FALSE);
645 g_hash_table_destroy(network->config_table);
647 g_free(network->path);
651 static void network_property(const char *key, DBusMessageIter *iter,
654 struct supplicant_network *network = user_data;
656 if (network->interface == NULL)
660 merge_network(network);
664 if (g_strcmp0(key, "Enabled") == 0) {
665 dbus_bool_t enabled = FALSE;
667 dbus_message_iter_get_basic(iter, &enabled);
668 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
669 const char *str = NULL;
671 dbus_message_iter_get_basic(iter, &str);
673 g_hash_table_replace(network->config_table,
674 g_strdup(key), g_strdup(str));
676 DBG("key %s type %c",
677 key, dbus_message_iter_get_arg_type(iter));
680 static void interface_network_added(DBusMessageIter *iter, void *user_data)
682 struct supplicant_interface *interface = user_data;
683 struct supplicant_network *network;
684 const char *path = NULL;
686 dbus_message_iter_get_basic(iter, &path);
690 if (g_strcmp0(path, "/") == 0)
693 network = g_hash_table_lookup(interface->net_mapping, path);
697 network = g_try_new0(struct supplicant_network, 1);
701 network->interface = interface;
702 network->path = g_strdup(path);
704 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
707 dbus_message_iter_next(iter);
708 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
709 supplicant_dbus_property_foreach(iter, network_property,
711 network_property(NULL, NULL, network);
715 supplicant_dbus_property_get_all(path,
716 SUPPLICANT_INTERFACE ".Interface.Network",
717 network_property, network);
720 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
722 struct supplicant_interface *interface = user_data;
723 struct supplicant_network *network;
724 const char *path = NULL;
726 dbus_message_iter_get_basic(iter, &path);
730 network = g_hash_table_lookup(interface->net_mapping, path);
734 g_hash_table_remove(interface->net_mapping, path);
737 static char *create_name(unsigned char *ssid, int ssid_len)
742 if (ssid_len < 1 || ssid[0] == '\0')
745 name = g_try_malloc0(ssid_len + 1);
750 for (i = 0; i < ssid_len; i++) {
751 if (g_ascii_isprint(ssid[i]))
760 static char *create_group(struct supplicant_bss *bss)
764 const char *mode, *security;
766 str = g_string_sized_new((bss->ssid_len * 2) + 24);
770 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
771 for (i = 0; i < bss->ssid_len; i++)
772 g_string_append_printf(str, "%02x", bss->ssid[i]);
774 g_string_append_printf(str, "hidden");
776 mode = mode2string(bss->mode);
778 g_string_append_printf(str, "_%s", mode);
780 security = security2string(bss->security);
781 if (security != NULL)
782 g_string_append_printf(str, "_%s", security);
784 return g_string_free(str, FALSE);
787 static void add_bss_to_network(struct supplicant_bss *bss)
789 struct supplicant_interface *interface = bss->interface;
790 struct supplicant_network *network;
793 group = create_group(bss);
797 network = g_hash_table_lookup(interface->network_table, group);
798 if (network != NULL) {
803 network = g_try_new0(struct supplicant_network, 1);
804 if (network == NULL) {
809 network->group = group;
810 network->name = create_name(bss->ssid, bss->ssid_len);
811 network->mode = bss->mode;
813 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
816 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
819 g_hash_table_replace(interface->network_table,
820 network->group, network);
822 callback_network_added(network);
825 g_hash_table_replace(interface->bss_mapping, bss->path, network);
826 g_hash_table_replace(network->bss_table, bss->path, bss);
828 g_hash_table_replace(bss_mapping, bss->path, interface);
831 static unsigned char wifi_oui[3] = { 0x00, 0x50, 0xf2 };
832 static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac };
834 static void extract_rsn(struct supplicant_bss *bss,
835 const unsigned char *buf, int len)
854 /* Pairwise cipher */
858 count = buf[0] | (buf[1] << 8);
859 if (2 + (count * 4) > len)
862 buf += 2 + (count * 4);
863 len -= 2 + (count * 4);
869 count = buf[0] | (buf[1] << 8);
870 if (2 + (count * 4) > len)
873 for (i = 0; i < count; i++) {
874 const unsigned char *ptr = buf + 2 + (i * 4);
876 if (memcmp(ptr, wifi_oui, 3) == 0) {
879 bss->ieee8021x = TRUE;
885 } else if (memcmp(ptr, ieee80211_oui, 3) == 0) {
888 bss->ieee8021x = TRUE;
897 buf += 2 + (count * 4);
898 len -= 2 + (count * 4);
901 static void bss_rates(DBusMessageIter *iter, void *user_data)
903 struct supplicant_bss *bss = user_data;
904 dbus_uint32_t rate = 0;
906 dbus_message_iter_get_basic(iter, &rate);
910 if (rate > bss->maxrate)
914 static void bss_property(const char *key, DBusMessageIter *iter,
917 struct supplicant_bss *bss = user_data;
919 if (bss->interface == NULL)
923 if (bss->ieee8021x == TRUE)
924 bss->security = SUPPLICANT_SECURITY_IEEE8021X;
925 else if (bss->psk == TRUE)
926 bss->security = SUPPLICANT_SECURITY_PSK;
927 else if (bss->privacy == TRUE)
928 bss->security = SUPPLICANT_SECURITY_WEP;
930 bss->security = SUPPLICANT_SECURITY_NONE;
932 add_bss_to_network(bss);
936 if (g_strcmp0(key, "BSSID") == 0) {
937 DBusMessageIter array;
941 dbus_message_iter_recurse(iter, &array);
942 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
945 memcpy(bss->bssid, addr, addr_len);
946 } else if (g_strcmp0(key, "SSID") == 0) {
947 DBusMessageIter array;
951 dbus_message_iter_recurse(iter, &array);
952 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
954 if (ssid_len > 0 && ssid_len < 33) {
955 memcpy(bss->ssid, ssid, ssid_len);
956 bss->ssid_len = ssid_len;
958 memset(bss->ssid, 0, sizeof(bss->ssid));
961 } else if (g_strcmp0(key, "Capabilities") == 0) {
962 dbus_uint16_t capabilities = 0x0000;
964 dbus_message_iter_get_basic(iter, &capabilities);
966 if (capabilities & IEEE80211_CAP_ESS)
967 bss->mode = SUPPLICANT_MODE_INFRA;
968 else if (capabilities & IEEE80211_CAP_IBSS)
969 bss->mode = SUPPLICANT_MODE_IBSS;
971 if (capabilities & IEEE80211_CAP_PRIVACY)
973 } else if (g_strcmp0(key, "Mode") == 0) {
974 const char *mode = NULL;
976 dbus_message_iter_get_basic(iter, &mode);
977 bss->mode = string2mode(mode);
978 } else if (g_strcmp0(key, "Frequency") == 0) {
979 dbus_uint16_t frequency = 0;
981 dbus_message_iter_get_basic(iter, &frequency);
982 bss->frequency = frequency;
983 } else if (g_strcmp0(key, "Signal") == 0) {
984 dbus_int16_t signal = 0;
986 dbus_message_iter_get_basic(iter, &signal);
987 } else if (g_strcmp0(key, "Level") == 0) {
988 dbus_int32_t level = 0;
990 dbus_message_iter_get_basic(iter, &level);
991 } else if (g_strcmp0(key, "Rates") == 0) {
992 supplicant_dbus_array_foreach(iter, bss_rates, bss);
993 } else if (g_strcmp0(key, "MaxRate") == 0) {
994 dbus_uint32_t maxrate = 0;
996 dbus_message_iter_get_basic(iter, &maxrate);
998 bss->maxrate =maxrate;
999 } else if (g_strcmp0(key, "Privacy") == 0) {
1000 dbus_bool_t privacy = FALSE;
1002 dbus_message_iter_get_basic(iter, &privacy);
1003 bss->privacy = privacy;
1004 } else if (g_strcmp0(key, "RSNIE") == 0) {
1005 DBusMessageIter array;
1009 dbus_message_iter_recurse(iter, &array);
1010 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
1013 extract_rsn(bss, ie + 2, ie_len - 2);
1014 } else if (g_strcmp0(key, "WPAIE") == 0) {
1015 DBusMessageIter array;
1019 dbus_message_iter_recurse(iter, &array);
1020 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
1023 extract_rsn(bss, ie + 6, ie_len - 6);
1024 } else if (g_strcmp0(key, "WPSIE") == 0) {
1025 DBusMessageIter array;
1029 dbus_message_iter_recurse(iter, &array);
1030 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
1032 DBG("key %s type %c",
1033 key, dbus_message_iter_get_arg_type(iter));
1036 static void interface_bss_added(DBusMessageIter *iter, void *user_data)
1038 struct supplicant_interface *interface = user_data;
1039 struct supplicant_network *network;
1040 struct supplicant_bss *bss;
1041 const char *path = NULL;
1043 dbus_message_iter_get_basic(iter, &path);
1047 if (g_strcmp0(path, "/") == 0)
1050 network = g_hash_table_lookup(interface->bss_mapping, path);
1051 if (network != NULL) {
1052 bss = g_hash_table_lookup(network->bss_table, path);
1057 bss = g_try_new0(struct supplicant_bss, 1);
1061 bss->interface = interface;
1062 bss->path = g_strdup(path);
1064 dbus_message_iter_next(iter);
1065 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
1066 supplicant_dbus_property_foreach(iter, bss_property, bss);
1067 bss_property(NULL, NULL, bss);
1071 supplicant_dbus_property_get_all(path,
1072 SUPPLICANT_INTERFACE ".Interface.BSS",
1076 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
1078 struct supplicant_interface *interface = user_data;
1079 struct supplicant_network *network;
1080 const char *path = NULL;
1082 dbus_message_iter_get_basic(iter, &path);
1086 network = g_hash_table_lookup(interface->bss_mapping, path);
1087 if (network == NULL)
1090 g_hash_table_remove(bss_mapping, path);
1092 g_hash_table_remove(interface->bss_mapping, path);
1093 g_hash_table_remove(network->bss_table, path);
1095 if (g_hash_table_size(network->bss_table) == 0)
1096 g_hash_table_remove(interface->network_table, network->group);
1099 static void interface_property(const char *key, DBusMessageIter *iter,
1102 struct supplicant_interface *interface = user_data;
1104 if (interface == NULL)
1108 debug_strvalmap("KeyMgmt capability", keymgmt_capa_map,
1109 interface->keymgmt_capa);
1110 debug_strvalmap("AuthAlg capability", authalg_capa_map,
1111 interface->authalg_capa);
1112 debug_strvalmap("Protocol capability", proto_capa_map,
1113 interface->proto_capa);
1114 debug_strvalmap("Pairwise capability", pairwise_capa_map,
1115 interface->pairwise_capa);
1116 debug_strvalmap("Group capability", group_capa_map,
1117 interface->group_capa);
1118 debug_strvalmap("Scan capability", scan_capa_map,
1119 interface->scan_capa);
1120 debug_strvalmap("Mode capability", mode_capa_map,
1121 interface->mode_capa);
1123 interface->ready = TRUE;
1124 callback_interface_added(interface);
1128 if (g_strcmp0(key, "Capabilities") == 0) {
1129 supplicant_dbus_property_foreach(iter, interface_capability,
1131 } else if (g_strcmp0(key, "State") == 0) {
1132 const char *str = NULL;
1134 dbus_message_iter_get_basic(iter, &str);
1136 interface->state = string2state(str);
1138 DBG("state %s (%d)", str, interface->state);
1139 } else if (g_strcmp0(key, "Scanning") == 0) {
1140 dbus_bool_t scanning = FALSE;
1142 dbus_message_iter_get_basic(iter, &scanning);
1143 interface->scanning = scanning;
1145 if (interface->ready == TRUE) {
1146 if (interface->scanning == TRUE)
1147 callback_scan_started(interface);
1149 callback_scan_finished(interface);
1151 } else if (g_strcmp0(key, "ApScan") == 0) {
1154 dbus_message_iter_get_basic(iter, &apscan);
1155 interface->apscan = apscan;
1156 } else if (g_strcmp0(key, "Ifname") == 0) {
1157 const char *str = NULL;
1159 dbus_message_iter_get_basic(iter, &str);
1161 interface->ifname = g_strdup(str);
1162 } else if (g_strcmp0(key, "Driver") == 0) {
1163 const char *str = NULL;
1165 dbus_message_iter_get_basic(iter, &str);
1167 interface->driver = g_strdup(str);
1168 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
1169 const char *str = NULL;
1171 dbus_message_iter_get_basic(iter, &str);
1173 interface->bridge = g_strdup(str);
1174 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
1175 interface_bss_added(iter, interface);
1176 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
1177 interface_network_added(iter, interface);
1178 } else if (g_strcmp0(key, "BSSs") == 0) {
1179 supplicant_dbus_array_foreach(iter, interface_bss_added,
1181 } else if (g_strcmp0(key, "Blobs") == 0) {
1182 } else if (g_strcmp0(key, "Networks") == 0) {
1183 supplicant_dbus_array_foreach(iter, interface_network_added,
1186 DBG("key %s type %c",
1187 key, dbus_message_iter_get_arg_type(iter));
1190 static struct supplicant_interface *interface_alloc(const char *path)
1192 struct supplicant_interface *interface;
1194 interface = g_try_new0(struct supplicant_interface, 1);
1195 if (interface == NULL)
1198 interface->path = g_strdup(path);
1200 interface->network_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1201 NULL, remove_network);
1203 interface->net_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
1205 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
1208 g_hash_table_replace(interface_table, interface->path, interface);
1213 static void interface_added(DBusMessageIter *iter, void *user_data)
1215 struct supplicant_interface *interface;
1216 const char *path = NULL;
1218 dbus_message_iter_get_basic(iter, &path);
1222 if (g_strcmp0(path, "/") == 0)
1225 interface = g_hash_table_lookup(interface_table, path);
1226 if (interface != NULL)
1229 interface = interface_alloc(path);
1230 if (interface == NULL)
1233 dbus_message_iter_next(iter);
1234 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
1235 supplicant_dbus_property_foreach(iter, interface_property,
1237 interface_property(NULL, NULL, interface);
1241 supplicant_dbus_property_get_all(path,
1242 SUPPLICANT_INTERFACE ".Interface",
1243 interface_property, interface);
1246 static void interface_removed(DBusMessageIter *iter, void *user_data)
1248 const char *path = NULL;
1250 dbus_message_iter_get_basic(iter, &path);
1254 g_hash_table_remove(interface_table, path);
1257 static void eap_method(DBusMessageIter *iter, void *user_data)
1259 const char *str = NULL;
1262 dbus_message_iter_get_basic(iter, &str);
1266 for (i = 0; eap_method_map[i].str != NULL; i++)
1267 if (strcmp(str, eap_method_map[i].str) == 0) {
1268 eap_methods |= eap_method_map[i].val;
1273 static void service_property(const char *key, DBusMessageIter *iter,
1277 callback_system_ready();
1281 if (g_strcmp0(key, "DebugLevel") == 0) {
1282 const char *str = NULL;
1285 dbus_message_iter_get_basic(iter, &str);
1286 for (i = 0; debug_strings[i] != NULL; i++)
1287 if (g_strcmp0(debug_strings[i], str) == 0) {
1291 DBG("Debug level %d", debug_level);
1292 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
1293 dbus_message_iter_get_basic(iter, &debug_timestamp);
1294 DBG("Debug timestamp %u", debug_timestamp);
1295 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
1296 dbus_message_iter_get_basic(iter, &debug_showkeys);
1297 DBG("Debug show keys %u", debug_showkeys);
1298 } else if (g_strcmp0(key, "Interfaces") == 0) {
1299 supplicant_dbus_array_foreach(iter, interface_added, NULL);
1300 } else if (g_strcmp0(key, "EapMethods") == 0) {
1301 supplicant_dbus_array_foreach(iter, eap_method, NULL);
1302 debug_strvalmap("EAP method", eap_method_map, eap_methods);
1304 DBG("key %s type %c",
1305 key, dbus_message_iter_get_arg_type(iter));
1308 static void supplicant_bootstrap(void)
1310 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
1311 SUPPLICANT_INTERFACE,
1312 service_property, NULL);
1315 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
1317 const char *name = NULL, *old = NULL, *new = NULL;
1319 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
1322 dbus_message_iter_get_basic(iter, &name);
1326 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
1329 dbus_message_iter_next(iter);
1330 dbus_message_iter_get_basic(iter, &old);
1331 dbus_message_iter_next(iter);
1332 dbus_message_iter_get_basic(iter, &new);
1334 if (old == NULL || new == NULL)
1337 if (strlen(old) > 0 && strlen(new) == 0) {
1338 system_available = FALSE;
1339 g_hash_table_remove_all(bss_mapping);
1340 g_hash_table_remove_all(interface_table);
1341 callback_system_killed();
1344 if (strlen(new) > 0 && strlen(old) == 0) {
1345 system_available = TRUE;
1346 supplicant_bootstrap();
1350 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
1352 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
1355 supplicant_dbus_property_foreach(iter, service_property, NULL);
1358 static void signal_interface_added(const char *path, DBusMessageIter *iter)
1360 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
1361 interface_added(iter, NULL);
1364 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
1366 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
1367 interface_removed(iter, NULL);
1370 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
1372 struct supplicant_interface *interface;
1374 interface = g_hash_table_lookup(interface_table, path);
1375 if (interface == NULL)
1378 supplicant_dbus_property_foreach(iter, interface_property, interface);
1381 static void signal_scan_done(const char *path, DBusMessageIter *iter)
1383 struct supplicant_interface *interface;
1384 dbus_bool_t success = FALSE;
1386 interface = g_hash_table_lookup(interface_table, path);
1387 if (interface == NULL)
1390 dbus_message_iter_get_basic(iter, &success);
1392 if (interface->scan_callback != NULL) {
1395 if (success == FALSE)
1398 interface->scan_callback(result, interface->scan_data);
1401 interface->scan_callback = NULL;
1402 interface->scan_data = NULL;
1405 static void signal_bss_added(const char *path, DBusMessageIter *iter)
1407 struct supplicant_interface *interface;
1409 interface = g_hash_table_lookup(interface_table, path);
1410 if (interface == NULL)
1413 interface_bss_added(iter, interface);
1416 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
1418 struct supplicant_interface *interface;
1420 interface = g_hash_table_lookup(interface_table, path);
1421 if (interface == NULL)
1424 interface_bss_removed(iter, interface);
1427 static void signal_network_added(const char *path, DBusMessageIter *iter)
1429 struct supplicant_interface *interface;
1431 interface = g_hash_table_lookup(interface_table, path);
1432 if (interface == NULL)
1435 interface_network_added(iter, interface);
1438 static void signal_network_removed(const char *path, DBusMessageIter *iter)
1440 struct supplicant_interface *interface;
1442 interface = g_hash_table_lookup(interface_table, path);
1443 if (interface == NULL)
1446 interface_network_removed(iter, interface);
1449 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
1451 struct supplicant_interface *interface;
1452 struct supplicant_network *network;
1453 struct supplicant_bss *bss;
1455 interface = g_hash_table_lookup(bss_mapping, path);
1456 if (interface == NULL)
1459 network = g_hash_table_lookup(interface->bss_mapping, path);
1460 if (network == NULL)
1463 bss = g_hash_table_lookup(network->bss_table, path);
1467 supplicant_dbus_property_foreach(iter, bss_property, bss);
1471 const char *interface;
1473 void (*function) (const char *path, DBusMessageIter *iter);
1475 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
1477 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
1478 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
1479 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
1480 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
1482 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
1483 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
1484 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
1485 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
1486 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
1487 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
1489 { SUPPLICANT_INTERFACE ".Interface.BSS", "PropertiesChanged", signal_bss_changed },
1494 static DBusHandlerResult supplicant_filter(DBusConnection *conn,
1495 DBusMessage *message, void *data)
1497 DBusMessageIter iter;
1501 path = dbus_message_get_path(message);
1503 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1505 if (dbus_message_iter_init(message, &iter) == FALSE)
1506 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1508 for (i = 0; signal_map[i].interface != NULL; i++) {
1509 if (dbus_message_has_interface(message,
1510 signal_map[i].interface) == FALSE)
1513 if (dbus_message_has_member(message,
1514 signal_map[i].member) == FALSE)
1517 signal_map[i].function(path, &iter);
1521 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1524 static const char *supplicant_rule0 = "type=signal,"
1525 "path=" DBUS_PATH_DBUS ","
1526 "sender=" DBUS_SERVICE_DBUS ","
1527 "interface=" DBUS_INTERFACE_DBUS ","
1528 "member=NameOwnerChanged,"
1529 "arg0=" SUPPLICANT_SERVICE;
1530 static const char *supplicant_rule1 = "type=signal,"
1531 "interface=" SUPPLICANT_INTERFACE;
1532 static const char *supplicant_rule2 = "type=signal,"
1533 "interface=" SUPPLICANT_INTERFACE ".Interface";
1534 static const char *supplicant_rule3 = "type=signal,"
1535 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
1536 static const char *supplicant_rule4 = "type=signal,"
1537 "interface=" SUPPLICANT_INTERFACE ".Interface.BSS";
1538 static const char *supplicant_rule5 = "type=signal,"
1539 "interface=" SUPPLICANT_INTERFACE ".Interface.Network";
1540 static const char *supplicant_rule6 = "type=signal,"
1541 "interface=" SUPPLICANT_INTERFACE ".Interface.Blob";
1543 int supplicant_register(const struct supplicant_callbacks *callbacks)
1545 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
1546 if (connection == NULL)
1549 if (dbus_connection_add_filter(connection,
1550 supplicant_filter, NULL, NULL) == FALSE) {
1551 dbus_connection_unref(connection);
1556 callbacks_pointer = callbacks;
1559 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1560 NULL, remove_interface);
1562 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
1565 supplicant_dbus_setup(connection);
1567 dbus_bus_add_match(connection, supplicant_rule0, NULL);
1568 dbus_bus_add_match(connection, supplicant_rule1, NULL);
1569 dbus_bus_add_match(connection, supplicant_rule2, NULL);
1570 dbus_bus_add_match(connection, supplicant_rule3, NULL);
1571 dbus_bus_add_match(connection, supplicant_rule4, NULL);
1572 dbus_bus_add_match(connection, supplicant_rule5, NULL);
1573 dbus_bus_add_match(connection, supplicant_rule6, NULL);
1574 dbus_connection_flush(connection);
1576 if (dbus_bus_name_has_owner(connection,
1577 SUPPLICANT_SERVICE, NULL) == TRUE) {
1578 system_available = TRUE;
1579 supplicant_bootstrap();
1585 void supplicant_unregister(const struct supplicant_callbacks *callbacks)
1587 if (connection != NULL) {
1588 dbus_bus_remove_match(connection, supplicant_rule6, NULL);
1589 dbus_bus_remove_match(connection, supplicant_rule5, NULL);
1590 dbus_bus_remove_match(connection, supplicant_rule4, NULL);
1591 dbus_bus_remove_match(connection, supplicant_rule3, NULL);
1592 dbus_bus_remove_match(connection, supplicant_rule2, NULL);
1593 dbus_bus_remove_match(connection, supplicant_rule1, NULL);
1594 dbus_bus_remove_match(connection, supplicant_rule0, NULL);
1595 dbus_connection_flush(connection);
1597 dbus_connection_remove_filter(connection,
1598 supplicant_filter, NULL);
1601 if (bss_mapping != NULL) {
1602 g_hash_table_destroy(bss_mapping);
1606 if (interface_table != NULL) {
1607 g_hash_table_destroy(interface_table);
1608 interface_table = NULL;
1611 if (system_available == TRUE)
1612 callback_system_killed();
1614 if (connection != NULL) {
1615 dbus_connection_unref(connection);
1619 callbacks_pointer = NULL;
1623 static void debug_level_result(const char *error,
1624 DBusMessageIter *iter, void *user_data)
1627 DBG("debug level failure: %s", error);
1630 static void debug_level_params(DBusMessageIter *iter, void *user_data)
1632 guint level = GPOINTER_TO_UINT(user_data);
1638 str = debug_strings[level];
1640 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
1643 void supplicant_set_debug_level(unsigned int level)
1645 if (system_available == FALSE)
1648 supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
1649 "DebugLevel", DBUS_TYPE_STRING_AS_STRING,
1650 debug_level_params, debug_level_result,
1651 GUINT_TO_POINTER(level));
1654 struct interface_create_data {
1657 struct supplicant_interface *interface;
1658 supplicant_interface_create_callback callback;
1662 static void interface_create_property(const char *key, DBusMessageIter *iter,
1665 struct interface_create_data *data = user_data;
1666 struct supplicant_interface *interface = data->interface;
1669 if (data->callback != NULL)
1670 data->callback(0, data->interface, data->user_data);
1675 interface_property(key, iter, interface);
1678 static void interface_create_result(const char *error,
1679 DBusMessageIter *iter, void *user_data)
1681 struct interface_create_data *data = user_data;
1682 const char *path = NULL;
1685 if (error != NULL) {
1690 dbus_message_iter_get_basic(iter, &path);
1696 if (system_available == FALSE) {
1701 data->interface = g_hash_table_lookup(interface_table, path);
1702 if (data->interface == NULL) {
1703 data->interface = interface_alloc(path);
1704 if (data->interface == NULL) {
1710 err = supplicant_dbus_property_get_all(path,
1711 SUPPLICANT_INTERFACE ".Interface",
1712 interface_create_property, data);
1717 if (data->callback != NULL)
1718 data->callback(err, NULL, data->user_data);
1723 static void interface_create_params(DBusMessageIter *iter, void *user_data)
1725 struct interface_create_data *data = user_data;
1726 DBusMessageIter dict;
1728 supplicant_dbus_dict_open(iter, &dict);
1730 supplicant_dbus_dict_append_basic(&dict, "Ifname",
1731 DBUS_TYPE_STRING, &data->ifname);
1733 if (data->driver != NULL)
1734 supplicant_dbus_dict_append_basic(&dict, "Driver",
1735 DBUS_TYPE_STRING, &data->driver);
1737 supplicant_dbus_dict_close(iter, &dict);
1740 static void interface_get_result(const char *error,
1741 DBusMessageIter *iter, void *user_data)
1743 struct interface_create_data *data = user_data;
1744 struct supplicant_interface *interface;
1745 const char *path = NULL;
1748 if (error != NULL) {
1753 dbus_message_iter_get_basic(iter, &path);
1759 interface = g_hash_table_lookup(interface_table, path);
1760 if (interface == NULL) {
1765 if (data->callback != NULL)
1766 data->callback(0, interface, data->user_data);
1773 if (system_available == FALSE) {
1778 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
1779 SUPPLICANT_INTERFACE,
1781 interface_create_params,
1782 interface_create_result, data);
1787 if (data->callback != NULL)
1788 data->callback(err, NULL, data->user_data);
1793 static void interface_get_params(DBusMessageIter *iter, void *user_data)
1795 struct interface_create_data *data = user_data;
1797 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
1800 int supplicant_interface_create(const char *ifname, const char *driver,
1801 supplicant_interface_create_callback callback,
1804 struct interface_create_data *data;
1809 if (system_available == FALSE)
1812 data = dbus_malloc0(sizeof(*data));
1816 data->ifname = ifname;
1817 data->driver = driver;
1818 data->callback = callback;
1819 data->user_data = user_data;
1821 return supplicant_dbus_method_call(SUPPLICANT_PATH,
1822 SUPPLICANT_INTERFACE,
1824 interface_get_params,
1825 interface_get_result, data);
1828 int supplicant_interface_remove(struct supplicant_interface *interface,
1829 supplicant_interface_remove_callback callback,
1832 if (interface == NULL)
1835 if (system_available == FALSE)
1841 struct interface_scan_data {
1842 struct supplicant_interface *interface;
1843 supplicant_interface_scan_callback callback;
1847 static void interface_scan_result(const char *error,
1848 DBusMessageIter *iter, void *user_data)
1850 struct interface_scan_data *data = user_data;
1852 if (error != NULL) {
1853 if (data->callback != NULL)
1854 data->callback(-EIO, data->user_data);
1856 data->interface->scan_callback = data->callback;
1857 data->interface->scan_data = data->user_data;
1863 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
1865 DBusMessageIter dict;
1866 const char *type = "passive";
1868 supplicant_dbus_dict_open(iter, &dict);
1870 supplicant_dbus_dict_append_basic(&dict, "Type",
1871 DBUS_TYPE_STRING, &type);
1873 supplicant_dbus_dict_close(iter, &dict);
1876 int supplicant_interface_scan(struct supplicant_interface *interface,
1877 supplicant_interface_scan_callback callback,
1880 struct interface_scan_data *data;
1882 if (interface == NULL)
1885 if (system_available == FALSE)
1888 if (interface->scanning == TRUE)
1891 data = dbus_malloc0(sizeof(*data));
1895 data->interface = interface;
1896 data->callback = callback;
1897 data->user_data = user_data;
1899 return supplicant_dbus_method_call(interface->path,
1900 SUPPLICANT_INTERFACE ".Interface", "Scan",
1901 interface_scan_params, interface_scan_result, data);
1904 struct interface_disconnect_data {
1905 supplicant_interface_disconnect_callback callback;
1909 static void interface_disconnect_result(const char *error,
1910 DBusMessageIter *iter, void *user_data)
1912 struct interface_disconnect_data *data = user_data;
1918 if (data->callback != NULL)
1919 data->callback(result, data->user_data);
1924 int supplicant_interface_disconnect(struct supplicant_interface *interface,
1925 supplicant_interface_disconnect_callback callback,
1928 struct interface_disconnect_data *data;
1930 if (interface == NULL)
1933 if (system_available == FALSE)
1936 data = dbus_malloc0(sizeof(*data));
1940 data->callback = callback;
1941 data->user_data = user_data;
1943 return supplicant_dbus_method_call(interface->path,
1944 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
1945 NULL, interface_disconnect_result, data);