3 * WPA supplicant library with GLib integration
5 * Copyright (C) 2012-2013 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 <netinet/if_ether.h>
35 #include <netinet/in.h>
41 #include "gsupplicant.h"
43 #define IEEE80211_CAP_ESS 0x0001
44 #define IEEE80211_CAP_IBSS 0x0002
45 #define IEEE80211_CAP_PRIVACY 0x0010
47 #define BSS_UNKNOWN_STRENGTH -90
49 static DBusConnection *connection;
51 static const GSupplicantCallbacks *callbacks_pointer;
53 static dbus_bool_t system_available = FALSE;
54 static dbus_bool_t system_ready = FALSE;
56 static dbus_int32_t debug_level;
57 static dbus_bool_t debug_timestamp = FALSE;
58 static dbus_bool_t debug_showkeys = FALSE;
60 static const char *debug_strings[] = {
61 "msgdump", "debug", "info", "warning", "error", NULL
64 static unsigned int eap_methods;
71 static struct strvalmap eap_method_map[] = {
72 { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 },
73 { "TLS", G_SUPPLICANT_EAP_METHOD_TLS },
74 { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 },
75 { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP },
76 { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS },
77 { "GTC", G_SUPPLICANT_EAP_METHOD_GTC },
78 { "OTP", G_SUPPLICANT_EAP_METHOD_OTP },
79 { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP },
80 { "WSC", G_SUPPLICANT_EAP_METHOD_WSC },
84 static struct strvalmap keymgmt_map[] = {
85 { "none", G_SUPPLICANT_KEYMGMT_NONE },
86 { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X },
87 { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE },
88 { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK },
89 { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 },
90 { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK },
91 { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP },
92 { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP },
93 { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 },
94 { "wps", G_SUPPLICANT_KEYMGMT_WPS },
98 static struct strvalmap authalg_capa_map[] = {
99 { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
100 { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
101 { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
105 static struct strvalmap proto_capa_map[] = {
106 { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA },
107 { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN },
111 static struct strvalmap group_map[] = {
112 { "wep40", G_SUPPLICANT_GROUP_WEP40 },
113 { "wep104", G_SUPPLICANT_GROUP_WEP104 },
114 { "tkip", G_SUPPLICANT_GROUP_TKIP },
115 { "ccmp", G_SUPPLICANT_GROUP_CCMP },
119 static struct strvalmap pairwise_map[] = {
120 { "none", G_SUPPLICANT_PAIRWISE_NONE },
121 { "tkip", G_SUPPLICANT_PAIRWISE_TKIP },
122 { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP },
126 static struct strvalmap scan_capa_map[] = {
127 { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
128 { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
129 { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID },
133 static struct strvalmap mode_capa_map[] = {
134 { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA },
135 { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS },
136 { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP },
137 { "p2p", G_SUPPLICANT_CAPABILITY_MODE_P2P },
141 static GHashTable *interface_table;
142 static GHashTable *bss_mapping;
143 static GHashTable *peer_mapping;
144 static GHashTable *group_mapping;
145 static GHashTable *pending_peer_connection;
147 struct _GSupplicantWpsCredentials {
148 unsigned char ssid[32];
149 unsigned int ssid_len;
153 struct _GSupplicantInterface {
156 unsigned int keymgmt_capa;
157 unsigned int authalg_capa;
158 unsigned int proto_capa;
159 unsigned int group_capa;
160 unsigned int pairwise_capa;
161 unsigned int scan_capa;
162 unsigned int mode_capa;
163 unsigned int max_scan_ssids;
167 GSupplicantState state;
168 dbus_bool_t scanning;
169 GSupplicantInterfaceCallback scan_callback;
175 struct _GSupplicantWpsCredentials wps_cred;
176 GSupplicantWpsState wps_state;
177 GHashTable *network_table;
178 GHashTable *peer_table;
179 GHashTable *group_table;
180 GHashTable *net_mapping;
181 GHashTable *bss_mapping;
183 const char *pending_peer_path;
186 struct g_supplicant_bss {
187 GSupplicantInterface *interface;
189 unsigned char bssid[6];
190 unsigned char ssid[32];
191 unsigned int ssid_len;
192 dbus_uint16_t frequency;
193 dbus_uint32_t maxrate;
195 GSupplicantMode mode;
196 GSupplicantSecurity security;
197 dbus_bool_t rsn_selected;
198 unsigned int wpa_keymgmt;
199 unsigned int wpa_pairwise;
200 unsigned int wpa_group;
201 unsigned int rsn_keymgmt;
202 unsigned int rsn_pairwise;
203 unsigned int rsn_group;
204 unsigned int keymgmt;
207 dbus_bool_t ieee8021x;
208 #if defined TIZEN_EXT
210 dbus_bool_t ft_ieee8021x;
212 unsigned int wps_capabilities;
215 struct _GSupplicantNetwork {
216 GSupplicantInterface *interface;
220 unsigned char ssid[32];
221 unsigned int ssid_len;
223 dbus_uint16_t frequency;
224 struct g_supplicant_bss *best_bss;
225 GSupplicantMode mode;
226 GSupplicantSecurity security;
228 unsigned int wps_capabilities;
229 GHashTable *bss_table;
230 GHashTable *config_table;
231 #if defined TIZEN_EXT
232 unsigned int isHS20AP;
239 struct _GSupplicantPeer {
240 GSupplicantInterface *interface;
242 unsigned char device_address[ETH_ALEN];
243 unsigned char iface_address[ETH_ALEN];
245 unsigned char *widi_ies;
248 unsigned int wps_capabilities;
250 const GSupplicantInterface *current_group_iface;
251 bool connection_requested;
254 struct _GSupplicantGroup {
255 GSupplicantInterface *interface;
256 GSupplicantInterface *orig_interface;
262 static inline void debug(const char *format, ...)
267 if (!callbacks_pointer->debug)
270 va_start(ap, format);
272 if (vsnprintf(str, sizeof(str), format, ap) > 0)
273 callbacks_pointer->debug(str);
278 #define SUPPLICANT_DBG(fmt, arg...) \
279 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
281 static GSupplicantMode string2mode(const char *mode)
284 return G_SUPPLICANT_MODE_UNKNOWN;
286 if (g_str_equal(mode, "infrastructure"))
287 return G_SUPPLICANT_MODE_INFRA;
288 else if (g_str_equal(mode, "ad-hoc"))
289 return G_SUPPLICANT_MODE_IBSS;
291 return G_SUPPLICANT_MODE_UNKNOWN;
294 static const char *mode2string(GSupplicantMode mode)
297 case G_SUPPLICANT_MODE_UNKNOWN:
299 case G_SUPPLICANT_MODE_INFRA:
301 case G_SUPPLICANT_MODE_IBSS:
303 case G_SUPPLICANT_MODE_MASTER:
310 static const char *security2string(GSupplicantSecurity security)
313 case G_SUPPLICANT_SECURITY_UNKNOWN:
315 case G_SUPPLICANT_SECURITY_NONE:
317 case G_SUPPLICANT_SECURITY_WEP:
319 case G_SUPPLICANT_SECURITY_PSK:
321 case G_SUPPLICANT_SECURITY_IEEE8021X:
323 #if defined TIZEN_EXT
324 case G_SUPPLICANT_SECURITY_FT_PSK:
326 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
327 return "ft_ieee8021x";
334 static GSupplicantState string2state(const char *state)
337 return G_SUPPLICANT_STATE_UNKNOWN;
339 if (g_str_equal(state, "unknown"))
340 return G_SUPPLICANT_STATE_UNKNOWN;
341 else if (g_str_equal(state, "interface_disabled"))
342 return G_SUPPLICANT_STATE_DISABLED;
343 else if (g_str_equal(state, "disconnected"))
344 return G_SUPPLICANT_STATE_DISCONNECTED;
345 else if (g_str_equal(state, "inactive"))
346 return G_SUPPLICANT_STATE_INACTIVE;
347 else if (g_str_equal(state, "scanning"))
348 return G_SUPPLICANT_STATE_SCANNING;
349 else if (g_str_equal(state, "authenticating"))
350 return G_SUPPLICANT_STATE_AUTHENTICATING;
351 else if (g_str_equal(state, "associating"))
352 return G_SUPPLICANT_STATE_ASSOCIATING;
353 else if (g_str_equal(state, "associated"))
354 return G_SUPPLICANT_STATE_ASSOCIATED;
355 else if (g_str_equal(state, "group_handshake"))
356 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
357 else if (g_str_equal(state, "4way_handshake"))
358 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
359 else if (g_str_equal(state, "completed"))
360 return G_SUPPLICANT_STATE_COMPLETED;
362 return G_SUPPLICANT_STATE_UNKNOWN;
365 static void callback_system_ready(void)
372 if (!callbacks_pointer)
375 if (!callbacks_pointer->system_ready)
378 callbacks_pointer->system_ready();
381 static void callback_system_killed(void)
383 system_ready = FALSE;
385 if (!callbacks_pointer)
388 if (!callbacks_pointer->system_killed)
391 callbacks_pointer->system_killed();
394 static void callback_interface_added(GSupplicantInterface *interface)
398 if (!callbacks_pointer)
401 if (!callbacks_pointer->interface_added)
404 callbacks_pointer->interface_added(interface);
407 static void callback_interface_state(GSupplicantInterface *interface)
409 if (!callbacks_pointer)
412 if (!callbacks_pointer->interface_state)
415 callbacks_pointer->interface_state(interface);
418 static void callback_interface_removed(GSupplicantInterface *interface)
420 if (!callbacks_pointer)
423 if (!callbacks_pointer->interface_removed)
426 callbacks_pointer->interface_removed(interface);
429 #if !defined TIZEN_EXT
430 static void callback_p2p_support(GSupplicantInterface *interface)
434 if (!interface->p2p_support)
437 if (callbacks_pointer && callbacks_pointer->p2p_support)
438 callbacks_pointer->p2p_support(interface);
442 static void callback_scan_started(GSupplicantInterface *interface)
444 if (!callbacks_pointer)
447 if (!callbacks_pointer->scan_started)
450 callbacks_pointer->scan_started(interface);
453 static void callback_scan_finished(GSupplicantInterface *interface)
455 if (!callbacks_pointer)
458 if (!callbacks_pointer->scan_finished)
461 callbacks_pointer->scan_finished(interface);
464 static void callback_network_added(GSupplicantNetwork *network)
466 if (!callbacks_pointer)
469 if (!callbacks_pointer->network_added)
472 callbacks_pointer->network_added(network);
475 static void callback_network_removed(GSupplicantNetwork *network)
477 if (!callbacks_pointer)
480 if (!callbacks_pointer->network_removed)
483 callbacks_pointer->network_removed(network);
486 #if defined TIZEN_EXT
487 static void callback_network_merged(GSupplicantNetwork *network)
489 if (!callbacks_pointer)
492 if (!callbacks_pointer->network_merged)
495 callbacks_pointer->network_merged(network);
499 static void callback_network_changed(GSupplicantNetwork *network,
500 const char *property)
502 if (!callbacks_pointer)
505 if (!callbacks_pointer->network_changed)
508 callbacks_pointer->network_changed(network, property);
511 static void callback_peer_found(GSupplicantPeer *peer)
513 if (!callbacks_pointer)
516 if (!callbacks_pointer->peer_found)
519 callbacks_pointer->peer_found(peer);
522 static void callback_peer_lost(GSupplicantPeer *peer)
524 if (!callbacks_pointer)
527 if (!callbacks_pointer->peer_lost)
530 callbacks_pointer->peer_lost(peer);
533 static void callback_peer_changed(GSupplicantPeer *peer,
534 GSupplicantPeerState state)
536 if (!callbacks_pointer)
539 if (!callbacks_pointer->peer_changed)
542 callbacks_pointer->peer_changed(peer, state);
545 static void callback_peer_request(GSupplicantPeer *peer)
547 if (!callbacks_pointer)
550 if (!callbacks_pointer->peer_request)
553 peer->connection_requested = true;
555 callbacks_pointer->peer_request(peer);
558 static void remove_group(gpointer data)
560 GSupplicantGroup *group = data;
563 g_slist_free_full(group->members, g_free);
569 static void remove_interface(gpointer data)
571 GSupplicantInterface *interface = data;
573 g_hash_table_destroy(interface->bss_mapping);
574 g_hash_table_destroy(interface->net_mapping);
575 g_hash_table_destroy(interface->network_table);
576 g_hash_table_destroy(interface->peer_table);
577 g_hash_table_destroy(interface->group_table);
579 if (interface->scan_callback) {
580 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
581 interface, interface->scan_callback,
582 interface->scanning);
584 interface->scan_callback(-EIO, interface, interface->scan_data);
585 interface->scan_callback = NULL;
586 interface->scan_data = NULL;
588 if (interface->scanning) {
589 interface->scanning = FALSE;
590 callback_scan_finished(interface);
594 callback_interface_removed(interface);
596 g_free(interface->wps_cred.key);
597 g_free(interface->path);
598 g_free(interface->network_path);
599 #if defined TIZEN_EXT
600 interface->network_path = NULL;
602 g_free(interface->ifname);
603 g_free(interface->driver);
604 g_free(interface->bridge);
608 static void remove_network(gpointer data)
610 GSupplicantNetwork *network = data;
612 g_hash_table_destroy(network->bss_table);
614 callback_network_removed(network);
616 g_hash_table_destroy(network->config_table);
618 g_free(network->path);
619 g_free(network->group);
620 g_free(network->name);
621 #if defined TIZEN_EXT
622 g_free(network->eap);
623 g_free(network->identity);
624 g_free(network->phase2);
629 static void remove_bss(gpointer data)
631 struct g_supplicant_bss *bss = data;
637 static void remove_peer(gpointer data)
639 GSupplicantPeer *peer = data;
641 callback_peer_lost(peer);
644 g_slist_free_full(peer->groups, g_free);
647 g_hash_table_remove(peer_mapping, peer->path);
649 if (pending_peer_connection)
650 g_hash_table_remove(pending_peer_connection, peer->path);
654 g_free(peer->identifier);
659 static void debug_strvalmap(const char *label, struct strvalmap *map,
664 for (i = 0; map[i].str; i++) {
665 if (val & map[i].val)
666 SUPPLICANT_DBG("%s: %s", label, map[i].str);
670 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
672 GSupplicantInterface *interface = user_data;
673 const char *str = NULL;
676 dbus_message_iter_get_basic(iter, &str);
680 for (i = 0; keymgmt_map[i].str; i++)
681 if (strcmp(str, keymgmt_map[i].str) == 0) {
682 interface->keymgmt_capa |= keymgmt_map[i].val;
687 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
689 GSupplicantInterface *interface = user_data;
690 const char *str = NULL;
693 dbus_message_iter_get_basic(iter, &str);
697 for (i = 0; authalg_capa_map[i].str; i++)
698 if (strcmp(str, authalg_capa_map[i].str) == 0) {
699 interface->authalg_capa |= authalg_capa_map[i].val;
704 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
706 GSupplicantInterface *interface = user_data;
707 const char *str = NULL;
710 dbus_message_iter_get_basic(iter, &str);
714 for (i = 0; proto_capa_map[i].str; i++)
715 if (strcmp(str, proto_capa_map[i].str) == 0) {
716 interface->proto_capa |= proto_capa_map[i].val;
721 static void interface_capability_pairwise(DBusMessageIter *iter,
724 GSupplicantInterface *interface = user_data;
725 const char *str = NULL;
728 dbus_message_iter_get_basic(iter, &str);
732 for (i = 0; pairwise_map[i].str; i++)
733 if (strcmp(str, pairwise_map[i].str) == 0) {
734 interface->pairwise_capa |= pairwise_map[i].val;
739 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
741 GSupplicantInterface *interface = user_data;
742 const char *str = NULL;
745 dbus_message_iter_get_basic(iter, &str);
749 for (i = 0; group_map[i].str; i++)
750 if (strcmp(str, group_map[i].str) == 0) {
751 interface->group_capa |= group_map[i].val;
756 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
758 GSupplicantInterface *interface = user_data;
759 const char *str = NULL;
762 dbus_message_iter_get_basic(iter, &str);
766 for (i = 0; scan_capa_map[i].str; i++)
767 if (strcmp(str, scan_capa_map[i].str) == 0) {
768 interface->scan_capa |= scan_capa_map[i].val;
773 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
775 GSupplicantInterface *interface = user_data;
776 const char *str = NULL;
779 dbus_message_iter_get_basic(iter, &str);
783 for (i = 0; mode_capa_map[i].str; i++)
784 if (strcmp(str, mode_capa_map[i].str) == 0) {
785 interface->mode_capa |= mode_capa_map[i].val;
790 static void interface_capability(const char *key, DBusMessageIter *iter,
793 GSupplicantInterface *interface = user_data;
798 if (g_strcmp0(key, "KeyMgmt") == 0)
799 supplicant_dbus_array_foreach(iter,
800 interface_capability_keymgmt, interface);
801 else if (g_strcmp0(key, "AuthAlg") == 0)
802 supplicant_dbus_array_foreach(iter,
803 interface_capability_authalg, interface);
804 else if (g_strcmp0(key, "Protocol") == 0)
805 supplicant_dbus_array_foreach(iter,
806 interface_capability_proto, interface);
807 else if (g_strcmp0(key, "Pairwise") == 0)
808 supplicant_dbus_array_foreach(iter,
809 interface_capability_pairwise, interface);
810 else if (g_strcmp0(key, "Group") == 0)
811 supplicant_dbus_array_foreach(iter,
812 interface_capability_group, interface);
813 else if (g_strcmp0(key, "Scan") == 0)
814 supplicant_dbus_array_foreach(iter,
815 interface_capability_scan, interface);
816 else if (g_strcmp0(key, "Modes") == 0)
817 supplicant_dbus_array_foreach(iter,
818 interface_capability_mode, interface);
819 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
820 dbus_int32_t max_scan_ssid;
822 dbus_message_iter_get_basic(iter, &max_scan_ssid);
823 if (max_scan_ssid < 2)
825 interface->max_scan_ssids = max_scan_ssid;
828 SUPPLICANT_DBG("key %s type %c",
829 key, dbus_message_iter_get_arg_type(iter));
832 static void set_apscan(DBusMessageIter *iter, void *user_data)
834 unsigned int ap_scan = *(unsigned int *)user_data;
836 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
839 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
840 unsigned int ap_scan)
842 return supplicant_dbus_property_set(interface->path,
843 SUPPLICANT_INTERFACE ".Interface",
844 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
845 set_apscan, NULL, &ap_scan, NULL);
848 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
854 interface->data = data;
857 interface->scan_callback = NULL;
860 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
865 return interface->data;
868 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
873 return interface->ifname;
876 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
881 return interface->driver;
884 GSupplicantState g_supplicant_interface_get_state(
885 GSupplicantInterface *interface)
888 return G_SUPPLICANT_STATE_UNKNOWN;
890 return interface->state;
893 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
898 return (const char *)interface->wps_cred.key;
901 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
902 unsigned int *ssid_len)
907 if (!interface || interface->wps_cred.ssid_len == 0) {
912 *ssid_len = interface->wps_cred.ssid_len;
913 return interface->wps_cred.ssid;
916 GSupplicantWpsState g_supplicant_interface_get_wps_state(
917 GSupplicantInterface *interface)
920 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
922 return interface->wps_state;
925 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
930 return interface->mode_capa;
933 unsigned int g_supplicant_interface_get_max_scan_ssids(
934 GSupplicantInterface *interface)
939 if (interface->max_scan_ssids == 0)
940 return WPAS_MAX_SCAN_SSIDS;
942 return interface->max_scan_ssids;
945 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
947 dbus_bool_t enable = *(dbus_bool_t *)user_data;
949 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
952 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
958 if (!interface->network_path)
962 return supplicant_dbus_property_set(interface->network_path,
963 SUPPLICANT_INTERFACE ".Network",
964 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
965 set_network_enabled, NULL, &enable, NULL);
968 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
973 return interface->ready;
976 GSupplicantInterface *g_supplicant_network_get_interface(
977 GSupplicantNetwork *network)
982 return network->interface;
985 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
987 if (!network || !network->name)
990 return network->name;
993 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
995 if (!network || !network->group)
998 return network->group;
1001 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1003 if (!network || !network->path)
1006 return network->path;
1009 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1012 return G_SUPPLICANT_MODE_UNKNOWN;
1014 return mode2string(network->mode);
1017 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1020 return G_SUPPLICANT_SECURITY_UNKNOWN;
1022 return security2string(network->security);
1025 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1026 unsigned int *ssid_len)
1033 *ssid_len = network->ssid_len;
1034 return network->ssid;
1037 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1042 return network->signal;
1045 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1050 return network->frequency;
1053 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1058 return network->wps;
1061 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1066 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1072 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1077 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1083 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1088 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1094 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1099 return peer->interface;
1102 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1110 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1115 return peer->identifier;
1118 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1123 return peer->device_address;
1126 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1131 return peer->iface_address;
1134 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1142 #if defined TIZEN_EXT
1143 unsigned int g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1148 return network->isHS20AP;
1151 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1153 if (!network || !network->eap)
1156 return network->eap;
1159 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1161 if (!network || !network->identity)
1164 return network->identity;
1167 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1169 if (!network || !network->phase2)
1172 return network->phase2;
1176 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1179 if (!peer || !length)
1182 *length = peer->widi_ies_length;
1183 return peer->widi_ies;
1186 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1191 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1197 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1202 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1208 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1210 if (!peer || !peer->groups)
1216 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1221 return (GSupplicantInterface *) peer->current_group_iface;
1224 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1226 GSupplicantGroup *group;
1232 for (list = peer->groups; list; list = list->next) {
1233 const char *path = list->data;
1235 group = g_hash_table_lookup(group_mapping, path);
1239 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1240 group->orig_interface != peer->interface)
1243 if (group->interface == peer->current_group_iface)
1250 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1255 return peer->connection_requested;
1258 #if defined TIZEN_EXT
1260 * Description: Network client requires additional wifi specific info
1262 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1264 if (network == NULL || network->best_bss == NULL)
1267 return (const unsigned char *)network->best_bss->bssid;
1270 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1272 if (network == NULL || network->best_bss == NULL)
1275 return network->best_bss->maxrate;
1278 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1280 if (network == NULL || network->best_bss == NULL)
1283 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1284 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1285 unsigned int pairwise;
1287 pairwise = network->best_bss->rsn_pairwise |
1288 network->best_bss->wpa_pairwise;
1290 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1291 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1293 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1295 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1298 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1300 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1306 bool g_supplicant_network_get_rsn_selected(GSupplicantNetwork *network)
1308 if (network == NULL || network->best_bss == NULL)
1311 if (network->best_bss->rsn_selected)
1319 static void merge_network(GSupplicantNetwork *network)
1322 const char *ssid, *mode, *key_mgmt;
1323 #if defined TIZEN_EXT
1324 GSupplicantInterface *interface;
1325 const char *isHS20AP;
1326 const char *eap, *identity, *phase2;
1328 unsigned int i, ssid_len;
1331 ssid = g_hash_table_lookup(network->config_table, "ssid");
1332 mode = g_hash_table_lookup(network->config_table, "mode");
1333 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
1334 #if defined TIZEN_EXT
1335 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
1336 eap = g_hash_table_lookup(network->config_table, "eap");
1337 identity = g_hash_table_lookup(network->config_table, "identity");
1338 phase2 = g_hash_table_lookup(network->config_table, "phase2");
1339 interface = network->interface;
1342 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
1345 ssid_len = strlen(ssid);
1349 str = g_string_sized_new((ssid_len * 2) + 24);
1353 for (i = 0; i < ssid_len; i++)
1354 #if defined TIZEN_EXT
1358 g_string_append_printf(str, "%02x", ssid[i]);
1359 #if defined TIZEN_EXT
1363 if (g_strcmp0(mode, "0") == 0)
1364 g_string_append_printf(str, "_managed");
1365 else if (g_strcmp0(mode, "1") == 0)
1366 g_string_append_printf(str, "_adhoc");
1368 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
1369 g_string_append_printf(str, "_psk");
1370 #if defined TIZEN_EXT
1371 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
1372 g_string_append_printf(str, "_ieee8021x");
1374 g_string_append_printf(str, "_none");
1377 group = g_string_free(str, FALSE);
1379 SUPPLICANT_DBG("%s", group);
1381 #if defined TIZEN_EXT
1382 if (g_strcmp0(isHS20AP, "1") == 0) {
1383 network->isHS20AP = 1;
1385 g_free(network->eap);
1386 network->eap = g_strdup(eap);
1388 if (network->identity)
1389 g_free(network->identity);
1390 network->identity = g_strdup(identity);
1392 if (network->phase2)
1393 g_free(network->phase2);
1394 network->phase2 = g_strdup(phase2);
1396 network->isHS20AP = 0;
1399 interface->network_path = g_strdup(network->path);
1401 network->group = g_strdup(group);
1402 callback_network_merged(network);
1407 g_hash_table_destroy(network->config_table);
1409 g_free(network->path);
1413 static void network_property(const char *key, DBusMessageIter *iter,
1416 GSupplicantNetwork *network = user_data;
1418 if (!network->interface)
1422 merge_network(network);
1426 if (g_strcmp0(key, "Enabled") == 0) {
1427 dbus_bool_t enabled = FALSE;
1429 dbus_message_iter_get_basic(iter, &enabled);
1430 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
1431 const char *str = NULL;
1433 dbus_message_iter_get_basic(iter, &str);
1435 g_hash_table_replace(network->config_table,
1436 g_strdup(key), g_strdup(str));
1439 SUPPLICANT_DBG("key %s type %c",
1440 key, dbus_message_iter_get_arg_type(iter));
1443 static void interface_network_added(DBusMessageIter *iter, void *user_data)
1445 GSupplicantInterface *interface = user_data;
1446 GSupplicantNetwork *network;
1447 const char *path = NULL;
1451 dbus_message_iter_get_basic(iter, &path);
1455 if (g_strcmp0(path, "/") == 0)
1458 network = g_hash_table_lookup(interface->net_mapping, path);
1462 network = g_try_new0(GSupplicantNetwork, 1);
1466 network->interface = interface;
1467 network->path = g_strdup(path);
1469 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1472 dbus_message_iter_next(iter);
1473 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
1474 supplicant_dbus_property_foreach(iter, network_property,
1476 network_property(NULL, NULL, network);
1480 supplicant_dbus_property_get_all(path,
1481 SUPPLICANT_INTERFACE ".Network",
1482 network_property, network, NULL);
1485 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
1487 GSupplicantInterface *interface = user_data;
1488 GSupplicantNetwork *network;
1489 const char *path = NULL;
1491 dbus_message_iter_get_basic(iter, &path);
1495 network = g_hash_table_lookup(interface->net_mapping, path);
1499 g_hash_table_remove(interface->net_mapping, path);
1502 static char *create_name(unsigned char *ssid, int ssid_len)
1505 const gchar *remainder, *invalid;
1506 int valid_bytes, remaining_bytes;
1508 if (ssid_len < 1 || ssid[0] == '\0')
1509 return g_strdup("");
1512 remainder = (const gchar *)ssid;
1513 remaining_bytes = ssid_len;
1515 while (remaining_bytes != 0) {
1516 if (g_utf8_validate(remainder, remaining_bytes,
1521 valid_bytes = invalid - remainder;
1524 string = g_string_sized_new(remaining_bytes);
1526 g_string_append_len(string, remainder, valid_bytes);
1528 /* append U+FFFD REPLACEMENT CHARACTER */
1529 g_string_append(string, "\357\277\275");
1531 remaining_bytes -= valid_bytes + 1;
1532 remainder = invalid + 1;
1536 return g_strndup((const gchar *)ssid, ssid_len + 1);
1538 g_string_append(string, remainder);
1540 return g_string_free(string, FALSE);
1543 static char *create_group(struct g_supplicant_bss *bss)
1547 const char *mode, *security;
1549 str = g_string_sized_new((bss->ssid_len * 2) + 24);
1553 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
1554 for (i = 0; i < bss->ssid_len; i++)
1555 g_string_append_printf(str, "%02x", bss->ssid[i]);
1557 g_string_append_printf(str, "hidden");
1559 mode = mode2string(bss->mode);
1561 g_string_append_printf(str, "_%s", mode);
1563 security = security2string(bss->security);
1565 g_string_append_printf(str, "_%s", security);
1567 return g_string_free(str, FALSE);
1570 static void add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
1572 GSupplicantInterface *interface = bss->interface;
1573 GSupplicantNetwork *network;
1576 group = create_group(bss);
1577 SUPPLICANT_DBG("New group created: %s", group);
1582 network = g_hash_table_lookup(interface->network_table, group);
1585 SUPPLICANT_DBG("Network %s already exist", network->name);
1590 network = g_try_new0(GSupplicantNetwork, 1);
1596 network->interface = interface;
1598 network->path = g_strdup(bss->path);
1599 network->group = group;
1600 network->name = create_name(bss->ssid, bss->ssid_len);
1601 network->mode = bss->mode;
1602 network->security = bss->security;
1603 network->ssid_len = bss->ssid_len;
1604 memcpy(network->ssid, bss->ssid, bss->ssid_len);
1605 network->signal = bss->signal;
1606 network->frequency = bss->frequency;
1607 network->best_bss = bss;
1609 SUPPLICANT_DBG("New network %s created", network->name);
1611 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1614 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1617 g_hash_table_replace(interface->network_table,
1618 network->group, network);
1620 callback_network_added(network);
1623 /* We update network's WPS properties if only bss provides WPS. */
1624 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
1625 network->wps = TRUE;
1626 network->wps_capabilities |= bss->wps_capabilities;
1629 if (bss->signal > network->signal) {
1630 network->signal = bss->signal;
1631 network->best_bss = bss;
1632 callback_network_changed(network, "Signal");
1635 g_hash_table_replace(interface->bss_mapping, bss->path, network);
1636 g_hash_table_replace(network->bss_table, bss->path, bss);
1638 g_hash_table_replace(bss_mapping, bss->path, interface);
1641 static void bss_rates(DBusMessageIter *iter, void *user_data)
1643 struct g_supplicant_bss *bss = user_data;
1644 dbus_uint32_t rate = 0;
1646 dbus_message_iter_get_basic(iter, &rate);
1650 if (rate > bss->maxrate)
1651 bss->maxrate = rate;
1654 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
1656 unsigned int *keymgmt = user_data;
1657 const char *str = NULL;
1660 dbus_message_iter_get_basic(iter, &str);
1664 for (i = 0; keymgmt_map[i].str; i++)
1665 if (strcmp(str, keymgmt_map[i].str) == 0) {
1666 SUPPLICANT_DBG("Keymgmt: %s", str);
1667 *keymgmt |= keymgmt_map[i].val;
1672 static void bss_group(DBusMessageIter *iter, void *user_data)
1674 unsigned int *group = user_data;
1675 const char *str = NULL;
1678 dbus_message_iter_get_basic(iter, &str);
1682 for (i = 0; group_map[i].str; i++)
1683 if (strcmp(str, group_map[i].str) == 0) {
1684 SUPPLICANT_DBG("Group: %s", str);
1685 *group |= group_map[i].val;
1690 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
1692 unsigned int *pairwise = user_data;
1693 const char *str = NULL;
1696 dbus_message_iter_get_basic(iter, &str);
1700 for (i = 0; pairwise_map[i].str; i++)
1701 if (strcmp(str, pairwise_map[i].str) == 0) {
1702 SUPPLICANT_DBG("Pairwise: %s", str);
1703 *pairwise |= pairwise_map[i].val;
1708 static void bss_wpa(const char *key, DBusMessageIter *iter,
1711 struct g_supplicant_bss *bss = user_data;
1712 unsigned int value = 0;
1714 SUPPLICANT_DBG("Key: %s", key);
1716 if (g_strcmp0(key, "KeyMgmt") == 0) {
1717 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
1719 if (bss->rsn_selected)
1720 bss->rsn_keymgmt = value;
1722 bss->wpa_keymgmt = value;
1723 } else if (g_strcmp0(key, "Group") == 0) {
1724 supplicant_dbus_array_foreach(iter, bss_group, &value);
1726 if (bss->rsn_selected)
1727 bss->rsn_group = value;
1729 bss->wpa_group = value;
1730 } else if (g_strcmp0(key, "Pairwise") == 0) {
1731 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
1733 if (bss->rsn_selected)
1734 bss->rsn_pairwise = value;
1736 bss->wpa_pairwise = value;
1740 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
1743 unsigned int len = 0;
1745 while (len + 4 < ie_size) {
1746 unsigned int hi = ie[len];
1747 unsigned int lo = ie[len + 1];
1748 unsigned int tmp_type = (hi << 8) + lo;
1749 unsigned int v_len = 0;
1751 /* hi and lo are used to recreate an unsigned int
1752 * based on 2 8bits length unsigned int. */
1756 v_len = (hi << 8) + lo;
1758 if (tmp_type == type) {
1759 unsigned int ret_value = 0;
1760 unsigned char *value = (unsigned char *)&ret_value;
1762 SUPPLICANT_DBG("IE: match type 0x%x", type);
1764 /* Verifying length relevance */
1765 if (v_len > sizeof(unsigned int) ||
1766 len + 4 + v_len > ie_size)
1769 memcpy(value, ie + len + 4, v_len);
1771 SUPPLICANT_DBG("returning 0x%x", ret_value);
1778 SUPPLICANT_DBG("returning 0");
1782 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
1784 struct g_supplicant_bss *bss = user_data;
1785 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
1786 unsigned char *ie, *ie_end;
1787 DBusMessageIter array;
1791 #define WMM_WPA1_WPS_INFO 221
1792 #define WPS_INFO_MIN_LEN 6
1793 #define WPS_VERSION_TLV 0x104A
1794 #define WPS_STATE_TLV 0x1044
1795 #define WPS_METHODS_TLV 0x1012
1796 #define WPS_REGISTRAR_TLV 0x1041
1797 #define WPS_VERSION 0x10
1798 #define WPS_PBC 0x04
1799 #define WPS_PIN 0x00
1800 #define WPS_CONFIGURED 0x02
1802 dbus_message_iter_recurse(iter, &array);
1803 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
1805 if (!ie || ie_len < 2)
1808 bss->wps_capabilities = 0;
1811 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
1814 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
1815 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
1818 SUPPLICANT_DBG("IE: match WPS_OUI");
1820 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
1821 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
1823 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
1825 if (value == WPS_CONFIGURED)
1826 bss->wps_capabilities |=
1827 G_SUPPLICANT_WPS_CONFIGURED;
1830 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
1832 if (GUINT16_FROM_BE(value) == WPS_PBC)
1833 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
1834 if (GUINT16_FROM_BE(value) == WPS_PIN)
1835 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
1837 bss->wps_capabilities |=
1838 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
1840 /* If the AP sends this it means it's advertizing
1841 * as a registrar and the WPS process is launched
1843 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
1844 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
1846 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
1850 static void bss_compute_security(struct g_supplicant_bss *bss)
1853 * Combining RSN and WPA keymgmt
1854 * We combine it since parsing IEs might have set something for WPS. */
1855 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
1857 bss->ieee8021x = FALSE;
1859 #if defined TIZEN_EXT
1860 bss->ft_ieee8021x = FALSE;
1861 bss->ft_psk = FALSE;
1864 #if defined TIZEN_EXT
1866 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
1867 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
1868 bss->ieee8021x = TRUE;
1869 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
1870 bss->ft_ieee8021x = TRUE;
1873 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
1874 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
1875 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
1876 bss->ieee8021x = TRUE;
1879 #if defined TIZEN_EXT
1881 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
1882 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
1884 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
1888 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
1889 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
1890 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
1895 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
1897 bss->security = G_SUPPLICANT_SECURITY_PSK;
1898 #if defined TIZEN_EXT
1899 else if (bss->ft_psk)
1900 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
1901 else if (bss->ft_ieee8021x == TRUE)
1902 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
1904 else if (bss->privacy)
1905 bss->security = G_SUPPLICANT_SECURITY_WEP;
1907 bss->security = G_SUPPLICANT_SECURITY_NONE;
1911 static void bss_property(const char *key, DBusMessageIter *iter,
1914 struct g_supplicant_bss *bss = user_data;
1916 if (!bss->interface)
1919 SUPPLICANT_DBG("key %s", key);
1924 if (g_strcmp0(key, "BSSID") == 0) {
1925 DBusMessageIter array;
1926 unsigned char *addr;
1929 dbus_message_iter_recurse(iter, &array);
1930 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
1933 memcpy(bss->bssid, addr, addr_len);
1934 } else if (g_strcmp0(key, "SSID") == 0) {
1935 DBusMessageIter array;
1936 unsigned char *ssid;
1939 dbus_message_iter_recurse(iter, &array);
1940 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
1942 if (ssid_len > 0 && ssid_len < 33) {
1943 memcpy(bss->ssid, ssid, ssid_len);
1944 bss->ssid_len = ssid_len;
1946 memset(bss->ssid, 0, sizeof(bss->ssid));
1949 } else if (g_strcmp0(key, "Capabilities") == 0) {
1950 dbus_uint16_t capabilities = 0x0000;
1952 dbus_message_iter_get_basic(iter, &capabilities);
1954 if (capabilities & IEEE80211_CAP_ESS)
1955 bss->mode = G_SUPPLICANT_MODE_INFRA;
1956 else if (capabilities & IEEE80211_CAP_IBSS)
1957 bss->mode = G_SUPPLICANT_MODE_IBSS;
1959 if (capabilities & IEEE80211_CAP_PRIVACY)
1960 bss->privacy = TRUE;
1961 } else if (g_strcmp0(key, "Mode") == 0) {
1962 const char *mode = NULL;
1964 dbus_message_iter_get_basic(iter, &mode);
1965 bss->mode = string2mode(mode);
1966 } else if (g_strcmp0(key, "Frequency") == 0) {
1967 dbus_uint16_t frequency = 0;
1969 dbus_message_iter_get_basic(iter, &frequency);
1970 bss->frequency = frequency;
1971 } else if (g_strcmp0(key, "Signal") == 0) {
1972 dbus_int16_t signal = 0;
1974 dbus_message_iter_get_basic(iter, &signal);
1976 bss->signal = signal;
1978 bss->signal = BSS_UNKNOWN_STRENGTH;
1980 } else if (g_strcmp0(key, "Level") == 0) {
1981 dbus_int32_t level = 0;
1983 dbus_message_iter_get_basic(iter, &level);
1984 } else if (g_strcmp0(key, "Rates") == 0) {
1985 supplicant_dbus_array_foreach(iter, bss_rates, bss);
1986 } else if (g_strcmp0(key, "MaxRate") == 0) {
1987 dbus_uint32_t maxrate = 0;
1989 dbus_message_iter_get_basic(iter, &maxrate);
1991 bss->maxrate = maxrate;
1992 } else if (g_strcmp0(key, "Privacy") == 0) {
1993 dbus_bool_t privacy = FALSE;
1995 dbus_message_iter_get_basic(iter, &privacy);
1996 bss->privacy = privacy;
1997 } else if (g_strcmp0(key, "RSN") == 0) {
1998 bss->rsn_selected = TRUE;
2000 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2001 } else if (g_strcmp0(key, "WPA") == 0) {
2002 bss->rsn_selected = FALSE;
2004 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2005 } else if (g_strcmp0(key, "IEs") == 0)
2006 bss_process_ies(iter, bss);
2008 SUPPLICANT_DBG("key %s type %c",
2009 key, dbus_message_iter_get_arg_type(iter));
2012 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
2015 GSupplicantInterface *interface = user_data;
2016 GSupplicantNetwork *network;
2017 struct g_supplicant_bss *bss;
2018 const char *path = NULL;
2022 dbus_message_iter_get_basic(iter, &path);
2026 if (g_strcmp0(path, "/") == 0)
2029 SUPPLICANT_DBG("%s", path);
2031 network = g_hash_table_lookup(interface->bss_mapping, path);
2033 bss = g_hash_table_lookup(network->bss_table, path);
2038 bss = g_try_new0(struct g_supplicant_bss, 1);
2042 bss->interface = interface;
2043 bss->path = g_strdup(path);
2044 bss->signal = BSS_UNKNOWN_STRENGTH;
2049 static void interface_bss_added_with_keys(DBusMessageIter *iter,
2052 struct g_supplicant_bss *bss;
2056 bss = interface_bss_added(iter, user_data);
2060 dbus_message_iter_next(iter);
2062 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
2065 supplicant_dbus_property_foreach(iter, bss_property, bss);
2067 bss_compute_security(bss);
2068 add_or_replace_bss_to_network(bss);
2071 static void interface_bss_added_without_keys(DBusMessageIter *iter,
2074 struct g_supplicant_bss *bss;
2078 bss = interface_bss_added(iter, user_data);
2082 supplicant_dbus_property_get_all(bss->path,
2083 SUPPLICANT_INTERFACE ".BSS",
2084 bss_property, bss, NULL);
2086 bss_compute_security(bss);
2087 add_or_replace_bss_to_network(bss);
2090 static void update_signal(gpointer key, gpointer value,
2093 struct g_supplicant_bss *bss = value;
2094 GSupplicantNetwork *network = user_data;
2096 if (bss->signal > network->signal) {
2097 network->signal = bss->signal;
2098 network->best_bss = bss;
2102 static void update_network_signal(GSupplicantNetwork *network)
2104 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
2107 g_hash_table_foreach(network->bss_table,
2108 update_signal, network);
2110 SUPPLICANT_DBG("New network signal %d", network->signal);
2113 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
2115 GSupplicantInterface *interface = user_data;
2116 GSupplicantNetwork *network;
2117 struct g_supplicant_bss *bss = NULL;
2118 const char *path = NULL;
2120 dbus_message_iter_get_basic(iter, &path);
2124 network = g_hash_table_lookup(interface->bss_mapping, path);
2128 bss = g_hash_table_lookup(network->bss_table, path);
2129 if (network->best_bss == bss) {
2130 network->best_bss = NULL;
2131 network->signal = BSS_UNKNOWN_STRENGTH;
2134 g_hash_table_remove(bss_mapping, path);
2136 g_hash_table_remove(interface->bss_mapping, path);
2137 g_hash_table_remove(network->bss_table, path);
2139 update_network_signal(network);
2141 if (g_hash_table_size(network->bss_table) == 0)
2142 g_hash_table_remove(interface->network_table, network->group);
2145 static void set_config_methods(DBusMessageIter *iter, void *user_data)
2147 const char *config_methods = "push_button";
2149 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2153 static void interface_property(const char *key, DBusMessageIter *iter,
2156 GSupplicantInterface *interface = user_data;
2161 SUPPLICANT_DBG("%s", key);
2164 debug_strvalmap("KeyMgmt capability", keymgmt_map,
2165 interface->keymgmt_capa);
2166 debug_strvalmap("AuthAlg capability", authalg_capa_map,
2167 interface->authalg_capa);
2168 debug_strvalmap("Protocol capability", proto_capa_map,
2169 interface->proto_capa);
2170 debug_strvalmap("Pairwise capability", pairwise_map,
2171 interface->pairwise_capa);
2172 debug_strvalmap("Group capability", group_map,
2173 interface->group_capa);
2174 debug_strvalmap("Scan capability", scan_capa_map,
2175 interface->scan_capa);
2176 debug_strvalmap("Mode capability", mode_capa_map,
2177 interface->mode_capa);
2180 supplicant_dbus_property_set(interface->path,
2181 SUPPLICANT_INTERFACE ".Interface.WPS",
2182 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
2183 set_config_methods, NULL, NULL, NULL);
2185 if (interface->ready)
2186 callback_interface_added(interface);
2191 if (g_strcmp0(key, "Capabilities") == 0) {
2192 supplicant_dbus_property_foreach(iter, interface_capability,
2194 #if !defined TIZEN_EXT
2195 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
2196 interface->p2p_support = true;
2198 } else if (g_strcmp0(key, "State") == 0) {
2199 const char *str = NULL;
2201 dbus_message_iter_get_basic(iter, &str);
2203 if (string2state(str) != interface->state) {
2204 interface->state = string2state(str);
2205 callback_interface_state(interface);
2207 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
2208 interface->ready = FALSE;
2210 interface->ready = TRUE;
2212 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
2213 } else if (g_strcmp0(key, "Scanning") == 0) {
2214 dbus_bool_t scanning = FALSE;
2216 dbus_message_iter_get_basic(iter, &scanning);
2217 interface->scanning = scanning;
2219 if (interface->ready) {
2220 if (interface->scanning)
2221 callback_scan_started(interface);
2223 callback_scan_finished(interface);
2225 } else if (g_strcmp0(key, "ApScan") == 0) {
2228 dbus_message_iter_get_basic(iter, &apscan);
2229 interface->apscan = apscan;
2230 } else if (g_strcmp0(key, "Ifname") == 0) {
2231 const char *str = NULL;
2233 dbus_message_iter_get_basic(iter, &str);
2235 g_free(interface->ifname);
2236 interface->ifname = g_strdup(str);
2238 } else if (g_strcmp0(key, "Driver") == 0) {
2239 const char *str = NULL;
2241 dbus_message_iter_get_basic(iter, &str);
2243 g_free(interface->driver);
2244 interface->driver = g_strdup(str);
2246 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
2247 const char *str = NULL;
2249 dbus_message_iter_get_basic(iter, &str);
2251 g_free(interface->bridge);
2252 interface->bridge = g_strdup(str);
2254 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
2255 interface_bss_added_without_keys(iter, interface);
2256 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
2257 #if defined TIZEN_EXT
2258 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
2260 interface_network_added(iter, interface);
2261 } else if (g_strcmp0(key, "BSSs") == 0) {
2262 supplicant_dbus_array_foreach(iter,
2263 interface_bss_added_without_keys,
2265 } else if (g_strcmp0(key, "Blobs") == 0) {
2267 } else if (g_strcmp0(key, "Networks") == 0) {
2268 supplicant_dbus_array_foreach(iter, interface_network_added,
2271 SUPPLICANT_DBG("key %s type %c",
2272 key, dbus_message_iter_get_arg_type(iter));
2275 static void scan_network_update(DBusMessageIter *iter, void *user_data)
2277 GSupplicantInterface *interface = user_data;
2278 GSupplicantNetwork *network;
2284 dbus_message_iter_get_basic(iter, &path);
2289 if (g_strcmp0(path, "/") == 0)
2292 /* Update the network details based on scan BSS data */
2293 network = g_hash_table_lookup(interface->bss_mapping, path);
2295 callback_network_added(network);
2298 static void scan_bss_data(const char *key, DBusMessageIter *iter,
2301 GSupplicantInterface *interface = user_data;
2303 /*Fixed : stucking in scanning state when scan failed*/
2304 #if defined TIZEN_EXT
2305 GSupplicantInterfaceCallback scan_callback;
2309 supplicant_dbus_array_foreach(iter, scan_network_update,
2312 #if defined TIZEN_EXT
2313 scan_callback = interface->scan_callback;
2316 if (interface->scan_callback)
2317 interface->scan_callback(0, interface, interface->scan_data);
2319 #if defined TIZEN_EXT
2320 if (interface->scan_callback == scan_callback) {
2322 interface->scan_callback = NULL;
2323 interface->scan_data = NULL;
2324 #if defined TIZEN_EXT
2329 static GSupplicantInterface *interface_alloc(const char *path)
2331 GSupplicantInterface *interface;
2333 interface = g_try_new0(GSupplicantInterface, 1);
2337 interface->path = g_strdup(path);
2339 interface->network_table = g_hash_table_new_full(g_str_hash,
2340 g_str_equal, NULL, remove_network);
2341 interface->peer_table = g_hash_table_new_full(g_str_hash,
2342 g_str_equal, NULL, remove_peer);
2343 interface->group_table = g_hash_table_new_full(g_str_hash,
2344 g_str_equal, NULL, remove_group);
2345 interface->net_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
2347 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
2350 g_hash_table_replace(interface_table, interface->path, interface);
2355 static void interface_added(DBusMessageIter *iter, void *user_data)
2357 GSupplicantInterface *interface;
2358 const char *path = NULL;
2362 dbus_message_iter_get_basic(iter, &path);
2366 if (g_strcmp0(path, "/") == 0)
2369 interface = g_hash_table_lookup(interface_table, path);
2373 interface = interface_alloc(path);
2377 dbus_message_iter_next(iter);
2378 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
2379 supplicant_dbus_property_foreach(iter, interface_property,
2381 interface_property(NULL, NULL, interface);
2385 supplicant_dbus_property_get_all(path,
2386 SUPPLICANT_INTERFACE ".Interface",
2387 interface_property, interface,
2391 static void interface_removed(DBusMessageIter *iter, void *user_data)
2393 const char *path = NULL;
2394 GSupplicantInterface *interface = user_data;
2396 dbus_message_iter_get_basic(iter, &path);
2400 interface = g_hash_table_lookup(interface_table, path);
2401 g_supplicant_interface_cancel(interface);
2403 g_hash_table_remove(interface_table, path);
2406 static void eap_method(DBusMessageIter *iter, void *user_data)
2408 const char *str = NULL;
2411 dbus_message_iter_get_basic(iter, &str);
2415 for (i = 0; eap_method_map[i].str; i++)
2416 if (strcmp(str, eap_method_map[i].str) == 0) {
2417 eap_methods |= eap_method_map[i].val;
2422 static void service_property(const char *key, DBusMessageIter *iter,
2426 callback_system_ready();
2430 if (g_strcmp0(key, "DebugLevel") == 0) {
2431 const char *str = NULL;
2434 dbus_message_iter_get_basic(iter, &str);
2435 for (i = 0; debug_strings[i]; i++)
2436 if (g_strcmp0(debug_strings[i], str) == 0) {
2440 SUPPLICANT_DBG("Debug level %d", debug_level);
2441 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
2442 dbus_message_iter_get_basic(iter, &debug_timestamp);
2443 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
2444 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
2445 dbus_message_iter_get_basic(iter, &debug_showkeys);
2446 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
2447 } else if (g_strcmp0(key, "Interfaces") == 0) {
2448 supplicant_dbus_array_foreach(iter, interface_added, NULL);
2449 } else if (g_strcmp0(key, "EapMethods") == 0) {
2450 supplicant_dbus_array_foreach(iter, eap_method, NULL);
2451 debug_strvalmap("EAP method", eap_method_map, eap_methods);
2452 } else if (g_strcmp0(key, "Country") == 0) {
2453 const char *country = NULL;
2455 dbus_message_iter_get_basic(iter, &country);
2456 SUPPLICANT_DBG("Country %s", country);
2458 SUPPLICANT_DBG("key %s type %c",
2459 key, dbus_message_iter_get_arg_type(iter));
2462 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
2464 const char *name = NULL, *old = NULL, *new = NULL;
2468 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
2471 dbus_message_iter_get_basic(iter, &name);
2475 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
2478 dbus_message_iter_next(iter);
2479 dbus_message_iter_get_basic(iter, &old);
2480 dbus_message_iter_next(iter);
2481 dbus_message_iter_get_basic(iter, &new);
2486 if (strlen(old) > 0 && strlen(new) == 0) {
2487 system_available = FALSE;
2488 g_hash_table_remove_all(bss_mapping);
2489 g_hash_table_remove_all(peer_mapping);
2490 g_hash_table_remove_all(group_mapping);
2491 g_hash_table_remove_all(interface_table);
2492 callback_system_killed();
2495 if (strlen(new) > 0 && strlen(old) == 0) {
2496 system_available = TRUE;
2497 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
2498 SUPPLICANT_INTERFACE,
2499 service_property, NULL, NULL);
2503 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
2507 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
2510 supplicant_dbus_property_foreach(iter, service_property, NULL);
2513 static void signal_interface_added(const char *path, DBusMessageIter *iter)
2515 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
2517 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
2518 interface_added(iter, NULL);
2521 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
2525 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
2526 interface_removed(iter, NULL);
2529 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
2531 GSupplicantInterface *interface;
2535 interface = g_hash_table_lookup(interface_table, path);
2539 supplicant_dbus_property_foreach(iter, interface_property, interface);
2542 static void signal_scan_done(const char *path, DBusMessageIter *iter)
2544 GSupplicantInterface *interface;
2545 dbus_bool_t success = FALSE;
2549 interface = g_hash_table_lookup(interface_table, path);
2553 dbus_message_iter_get_basic(iter, &success);
2555 if (interface->scanning) {
2556 callback_scan_finished(interface);
2557 interface->scanning = FALSE;
2561 * If scan is unsuccessful return -EIO else get the scanned BSSs
2562 * and update the network details accordingly
2565 if (interface->scan_callback)
2566 interface->scan_callback(-EIO, interface,
2567 interface->scan_data);
2569 interface->scan_callback = NULL;
2570 interface->scan_data = NULL;
2575 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
2576 "BSSs", scan_bss_data, interface, interface);
2579 static void signal_bss_added(const char *path, DBusMessageIter *iter)
2581 GSupplicantInterface *interface;
2585 interface = g_hash_table_lookup(interface_table, path);
2589 interface_bss_added_with_keys(iter, interface);
2592 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
2594 GSupplicantInterface *interface;
2598 interface = g_hash_table_lookup(interface_table, path);
2602 interface_bss_removed(iter, interface);
2605 static void signal_network_added(const char *path, DBusMessageIter *iter)
2607 GSupplicantInterface *interface;
2611 interface = g_hash_table_lookup(interface_table, path);
2615 interface_network_added(iter, interface);
2618 static void signal_network_removed(const char *path, DBusMessageIter *iter)
2620 GSupplicantInterface *interface;
2624 interface = g_hash_table_lookup(interface_table, path);
2628 interface_network_removed(iter, interface);
2631 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
2633 GSupplicantInterface *interface;
2634 GSupplicantNetwork *network;
2635 GSupplicantSecurity old_security;
2636 struct g_supplicant_bss *bss;
2640 interface = g_hash_table_lookup(bss_mapping, path);
2644 network = g_hash_table_lookup(interface->bss_mapping, path);
2648 bss = g_hash_table_lookup(network->bss_table, path);
2652 supplicant_dbus_property_foreach(iter, bss_property, bss);
2654 old_security = network->security;
2655 bss_compute_security(bss);
2657 if (old_security != bss->security) {
2658 struct g_supplicant_bss *new_bss;
2660 SUPPLICANT_DBG("New network security for %s", bss->ssid);
2662 /* Security change policy:
2663 * - we first copy the current bss into a new one with
2664 * its own pointer (path)
2665 * - we remove the current bss related network which will
2666 * tell the plugin about such removal. This is done due
2667 * to the fact that a security change means a group change
2668 * so a complete network change.
2669 * (current bss becomes invalid as well)
2670 * - we add the new bss: it adds new network and tell the
2671 * plugin about it. */
2673 new_bss = g_try_new0(struct g_supplicant_bss, 1);
2677 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
2678 new_bss->path = g_strdup(bss->path);
2680 g_hash_table_remove(interface->network_table, network->group);
2682 add_or_replace_bss_to_network(new_bss);
2687 #if defined TIZEN_EXT
2688 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2689 network->wps = TRUE;
2690 network->wps_capabilities |= bss->wps_capabilities;
2692 network->wps = FALSE;
2695 if (bss->signal == network->signal)
2700 callback_network_changed(network, "");
2706 * If the new signal is lower than the SSID signal, we need
2707 * to check for the new maximum.
2709 if (bss->signal < network->signal) {
2710 if (bss != network->best_bss)
2715 callback_network_changed(network, "");
2719 network->signal = bss->signal;
2720 update_network_signal(network);
2722 network->signal = bss->signal;
2723 network->best_bss = bss;
2726 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
2729 callback_network_changed(network, "Signal");
2732 static void wps_credentials(const char *key, DBusMessageIter *iter,
2735 GSupplicantInterface *interface = user_data;
2740 SUPPLICANT_DBG("key %s", key);
2742 if (g_strcmp0(key, "Key") == 0) {
2743 DBusMessageIter array;
2744 unsigned char *key_val;
2747 dbus_message_iter_recurse(iter, &array);
2748 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
2750 g_free(interface->wps_cred.key);
2751 interface->wps_cred.key = g_try_malloc0(
2752 sizeof(char) * key_len + 1);
2754 if (!interface->wps_cred.key)
2757 memcpy(interface->wps_cred.key, key_val,
2758 sizeof(char) * key_len);
2760 SUPPLICANT_DBG("WPS key present");
2761 } else if (g_strcmp0(key, "SSID") == 0) {
2762 DBusMessageIter array;
2763 unsigned char *ssid;
2766 dbus_message_iter_recurse(iter, &array);
2767 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
2769 if (ssid_len > 0 && ssid_len < 33) {
2770 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
2771 interface->wps_cred.ssid_len = ssid_len;
2773 memset(interface->wps_cred.ssid, 0, 32);
2774 interface->wps_cred.ssid_len = 0;
2779 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
2781 GSupplicantInterface *interface;
2785 interface = g_hash_table_lookup(interface_table, path);
2789 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
2792 static void wps_event_args(const char *key, DBusMessageIter *iter,
2795 GSupplicantInterface *interface = user_data;
2797 if (!key || !interface)
2800 SUPPLICANT_DBG("Arg Key %s", key);
2803 static void signal_wps_event(const char *path, DBusMessageIter *iter)
2805 GSupplicantInterface *interface;
2806 const char *name = NULL;
2810 interface = g_hash_table_lookup(interface_table, path);
2814 dbus_message_iter_get_basic(iter, &name);
2816 SUPPLICANT_DBG("Name: %s", name);
2818 if (g_strcmp0(name, "success") == 0)
2819 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
2820 else if (g_strcmp0(name, "failed") == 0)
2821 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
2823 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
2825 if (!dbus_message_iter_has_next(iter))
2828 dbus_message_iter_next(iter);
2830 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
2833 #if defined TIZEN_EXT
2834 static void signal_power_off(const char *path, DBusMessageIter *iter)
2836 int poweroff_state = 0;
2838 dbus_message_iter_get_basic(iter, &poweroff_state);
2840 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
2842 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
2843 if (poweroff_state != 2 && poweroff_state != 3)
2846 if (callbacks_pointer == NULL)
2849 if (callbacks_pointer->system_power_off == NULL)
2852 callbacks_pointer->system_power_off();
2856 static void signal_station_connected(const char *path, DBusMessageIter *iter)
2858 GSupplicantInterface *interface;
2859 const char *sta_mac = NULL;
2861 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
2863 if (callbacks_pointer->add_station == NULL)
2866 if (g_strcmp0(path, "/") == 0)
2869 interface = g_hash_table_lookup(interface_table, path);
2870 if (interface == NULL)
2873 dbus_message_iter_get_basic(iter, &sta_mac);
2874 if (sta_mac == NULL)
2877 SUPPLICANT_DBG("New station %s connected", sta_mac);
2878 callbacks_pointer->add_station(sta_mac);
2881 static void signal_station_disconnected(const char *path, DBusMessageIter *iter)
2883 GSupplicantInterface *interface;
2884 const char *sta_mac = NULL;
2886 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
2888 if (callbacks_pointer->remove_station == NULL)
2891 if (g_strcmp0(path, "/") == 0)
2894 interface = g_hash_table_lookup(interface_table, path);
2895 if (interface == NULL)
2898 dbus_message_iter_get_basic(iter, &sta_mac);
2899 if (sta_mac == NULL)
2902 SUPPLICANT_DBG("Station %s disconnected", sta_mac);
2903 callbacks_pointer->remove_station(sta_mac);
2906 static void create_peer_identifier(GSupplicantPeer *peer)
2908 const unsigned char test[ETH_ALEN] = {};
2913 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
2914 peer->identifier = g_strdup(peer->name);
2918 peer->identifier = g_malloc0(19);
2919 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
2920 peer->device_address[0],
2921 peer->device_address[1],
2922 peer->device_address[2],
2923 peer->device_address[3],
2924 peer->device_address[4],
2925 peer->device_address[5]);
2928 struct peer_property_data {
2929 GSupplicantPeer *peer;
2931 bool groups_changed;
2932 bool services_changed;
2935 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
2937 struct peer_property_data *data = user_data;
2938 GSupplicantPeer *peer = data->peer;
2939 GSupplicantGroup *group;
2940 const char *str = NULL;
2943 dbus_message_iter_get_basic(iter, &str);
2947 group = g_hash_table_lookup(group_mapping, str);
2951 elem = g_slist_find_custom(data->old_groups, str, g_str_equal);
2953 data->old_groups = g_slist_remove_link(data->old_groups, elem);
2954 peer->groups = g_slist_concat(elem, peer->groups);
2956 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
2957 data->groups_changed = true;
2961 static void peer_property(const char *key, DBusMessageIter *iter,
2964 GSupplicantPeer *pending_peer;
2965 struct peer_property_data *data = user_data;
2966 GSupplicantPeer *peer = data->peer;
2968 SUPPLICANT_DBG("key: %s", key);
2970 if (!peer->interface)
2975 create_peer_identifier(peer);
2976 callback_peer_found(peer);
2977 pending_peer = g_hash_table_lookup(
2978 pending_peer_connection, peer->path);
2980 if (pending_peer && pending_peer == peer) {
2981 callback_peer_request(peer);
2982 g_hash_table_remove(pending_peer_connection,
2992 if (g_strcmp0(key, "DeviceAddress") == 0) {
2993 unsigned char *dev_addr;
2994 DBusMessageIter array;
2997 dbus_message_iter_recurse(iter, &array);
2998 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
3000 if (len == ETH_ALEN)
3001 memcpy(peer->device_address, dev_addr, len);
3002 } else if (g_strcmp0(key, "DeviceName") == 0) {
3003 const char *str = NULL;
3005 dbus_message_iter_get_basic(iter, &str);
3007 peer->name = g_strdup(str);
3008 } else if (g_strcmp0(key, "config_method") == 0) {
3009 uint16_t wps_config;
3011 dbus_message_iter_get_basic(iter, &wps_config);
3013 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
3014 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3015 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
3016 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3017 } else if (g_strcmp0(key, "Groups") == 0) {
3018 data->old_groups = peer->groups;
3019 peer->groups = NULL;
3021 supplicant_dbus_array_foreach(iter,
3022 peer_groups_relation, data);
3023 if (g_slist_length(data->old_groups) > 0) {
3024 g_slist_free_full(data->old_groups, g_free);
3025 data->groups_changed = true;
3027 } else if (g_strcmp0(key, "IEs") == 0) {
3028 DBusMessageIter array;
3032 dbus_message_iter_recurse(iter, &array);
3033 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3035 if (!ie || ie_len < 2)
3038 if (peer->widi_ies) {
3039 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
3042 g_free(peer->widi_ies);
3043 peer->widi_ies_length = 0;
3046 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
3048 memcpy(peer->widi_ies, ie, ie_len);
3049 peer->widi_ies_length = ie_len;
3050 data->services_changed = true;
3054 static void signal_peer_found(const char *path, DBusMessageIter *iter)
3056 struct peer_property_data *property_data;
3057 GSupplicantInterface *interface;
3058 const char *obj_path = NULL;
3059 GSupplicantPeer *peer;
3063 interface = g_hash_table_lookup(interface_table, path);
3067 dbus_message_iter_get_basic(iter, &obj_path);
3068 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3071 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3075 peer = g_try_new0(GSupplicantPeer, 1);
3079 peer->interface = interface;
3080 peer->path = g_strdup(obj_path);
3081 g_hash_table_insert(interface->peer_table, peer->path, peer);
3082 g_hash_table_replace(peer_mapping, peer->path, interface);
3084 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3085 property_data->peer = peer;
3087 dbus_message_iter_next(iter);
3088 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3089 supplicant_dbus_property_foreach(iter, peer_property,
3091 peer_property(NULL, NULL, property_data);
3095 supplicant_dbus_property_get_all(obj_path,
3096 SUPPLICANT_INTERFACE ".Peer",
3097 peer_property, property_data, NULL);
3100 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
3102 GSupplicantInterface *interface;
3103 const char *obj_path = NULL;
3104 GSupplicantPeer *peer;
3108 interface = g_hash_table_lookup(interface_table, path);
3112 dbus_message_iter_get_basic(iter, &obj_path);
3113 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3116 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3120 g_hash_table_remove(interface->peer_table, obj_path);
3123 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
3125 struct peer_property_data *property_data;
3126 GSupplicantInterface *interface;
3127 GSupplicantPeer *peer;
3131 interface = g_hash_table_lookup(peer_mapping, path);
3135 peer = g_hash_table_lookup(interface->peer_table, path);
3137 g_hash_table_remove(peer_mapping, path);
3141 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3142 property_data->peer = peer;
3144 supplicant_dbus_property_foreach(iter, peer_property, property_data);
3145 if (property_data->services_changed)
3146 callback_peer_changed(peer,
3147 G_SUPPLICANT_PEER_SERVICES_CHANGED);
3149 if (property_data->groups_changed)
3150 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
3152 dbus_free(property_data);
3154 if (!g_supplicant_peer_is_in_a_group(peer))
3155 peer->connection_requested = false;
3158 struct group_sig_data {
3159 const char *peer_obj_path;
3160 unsigned char iface_address[ETH_ALEN];
3161 const char *interface_obj_path;
3162 const char *group_obj_path;
3166 static void group_sig_property(const char *key, DBusMessageIter *iter,
3169 struct group_sig_data *data = user_data;
3174 if (g_strcmp0(key, "peer_interface_addr") == 0) {
3175 unsigned char *dev_addr;
3176 DBusMessageIter array;
3179 dbus_message_iter_recurse(iter, &array);
3180 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
3182 if (len == ETH_ALEN)
3183 memcpy(data->iface_address, dev_addr, len);
3184 } else if (g_strcmp0(key, "role") == 0) {
3185 const char *str = NULL;
3187 dbus_message_iter_get_basic(iter, &str);
3188 if (g_strcmp0(str, "GO") == 0)
3189 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
3191 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
3192 } else if (g_strcmp0(key, "peer_object") == 0)
3193 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
3194 else if (g_strcmp0(key, "interface_object") == 0)
3195 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
3196 else if (g_strcmp0(key, "group_object") == 0)
3197 dbus_message_iter_get_basic(iter, &data->group_obj_path);
3201 static void signal_group_success(const char *path, DBusMessageIter *iter)
3203 GSupplicantInterface *interface;
3204 struct group_sig_data data = {};
3205 GSupplicantPeer *peer;
3209 interface = g_hash_table_lookup(interface_table, path);
3213 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3214 if (!data.peer_obj_path)
3217 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
3221 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
3222 interface->pending_peer_path = peer->path;
3225 static void signal_group_failure(const char *path, DBusMessageIter *iter)
3227 GSupplicantInterface *interface;
3228 struct group_sig_data data = {};
3229 GSupplicantPeer *peer;
3233 interface = g_hash_table_lookup(interface_table, path);
3237 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3238 if (!data.peer_obj_path)
3241 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
3245 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
3246 peer->connection_requested = false;
3249 static void signal_group_started(const char *path, DBusMessageIter *iter)
3251 GSupplicantInterface *interface, *g_interface;
3252 struct group_sig_data data = {};
3253 GSupplicantGroup *group;
3254 GSupplicantPeer *peer;
3258 interface = g_hash_table_lookup(interface_table, path);
3262 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3263 if (!data.interface_obj_path || !data.group_obj_path)
3266 peer = g_hash_table_lookup(interface->peer_table,
3267 interface->pending_peer_path);
3268 interface->pending_peer_path = NULL;
3272 g_interface = g_hash_table_lookup(interface_table,
3273 data.interface_obj_path);
3277 group = g_hash_table_lookup(interface->group_table,
3278 data.group_obj_path);
3282 group = g_try_new0(GSupplicantGroup, 1);
3286 group->interface = g_interface;
3287 group->orig_interface = interface;
3288 group->path = g_strdup(data.group_obj_path);
3289 group->role = data.role;
3291 g_hash_table_insert(interface->group_table, group->path, group);
3292 g_hash_table_replace(group_mapping, group->path, group);
3294 peer->current_group_iface = g_interface;
3295 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
3298 static void remove_peer_group_interface(GHashTable *group_table,
3301 GSupplicantGroup *group;
3302 GHashTableIter iter;
3303 gpointer value, key;
3308 group = g_hash_table_lookup(group_table, path);
3310 if (!group || !group->orig_interface)
3313 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
3315 while (g_hash_table_iter_next(&iter, &key, &value)) {
3316 GSupplicantPeer *peer = value;
3318 if (peer->current_group_iface == group->interface)
3319 peer->current_group_iface = NULL;
3323 static void signal_group_finished(const char *path, DBusMessageIter *iter)
3325 GSupplicantInterface *interface;
3326 struct group_sig_data data = {};
3330 interface = g_hash_table_lookup(interface_table, path);
3334 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3335 if (!data.interface_obj_path || !data.group_obj_path)
3338 remove_peer_group_interface(interface->group_table, data.group_obj_path);
3340 g_hash_table_remove(group_mapping, data.group_obj_path);
3342 g_hash_table_remove(interface->group_table, data.group_obj_path);
3345 static void signal_group_request(const char *path, DBusMessageIter *iter)
3347 GSupplicantInterface *interface;
3348 GSupplicantPeer *peer;
3349 const char *obj_path;
3353 interface = g_hash_table_lookup(interface_table, path);
3357 dbus_message_iter_get_basic(iter, &obj_path);
3358 if (!obj_path || !g_strcmp0(obj_path, "/"))
3361 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3366 * Peer has been previously found and property set,
3367 * otherwise, defer connection to when peer property
3370 if (peer->identifier)
3371 callback_peer_request(peer);
3373 g_hash_table_replace(pending_peer_connection, peer->path, peer);
3376 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
3378 const char *peer_path = NULL;
3379 GSupplicantInterface *interface;
3380 GSupplicantGroup *group;
3381 GSupplicantPeer *peer;
3385 group = g_hash_table_lookup(group_mapping, path);
3389 dbus_message_iter_get_basic(iter, &peer_path);
3393 interface = g_hash_table_lookup(peer_mapping, peer_path);
3397 peer = g_hash_table_lookup(interface->peer_table, peer_path);
3401 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
3403 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
3406 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
3408 const char *peer_path = NULL;
3409 GSupplicantInterface *interface;
3410 GSupplicantGroup *group;
3411 GSupplicantPeer *peer;
3416 group = g_hash_table_lookup(group_mapping, path);
3420 dbus_message_iter_get_basic(iter, &peer_path);
3424 for (elem = group->members; elem; elem = elem->next) {
3425 if (!g_strcmp0(elem->data, peer_path))
3433 group->members = g_slist_delete_link(group->members, elem);
3435 interface = g_hash_table_lookup(peer_mapping, peer_path);
3439 peer = g_hash_table_lookup(interface->peer_table, peer_path);
3443 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
3444 peer->connection_requested = false;
3448 const char *interface;
3450 void (*function) (const char *path, DBusMessageIter *iter);
3452 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
3454 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
3455 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
3456 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
3457 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
3459 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
3460 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
3461 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
3462 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
3463 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
3464 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
3466 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
3468 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
3469 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
3470 #if defined TIZEN_EXT
3471 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
3474 { SUPPLICANT_INTERFACE".Interface", "StaAuthorized", signal_station_connected },
3475 { SUPPLICANT_INTERFACE".Interface", "StaDeauthorized", signal_station_disconnected },
3477 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
3478 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
3480 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
3482 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
3483 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
3484 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
3485 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
3486 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
3488 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
3489 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
3494 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
3495 DBusMessage *message, void *data)
3497 DBusMessageIter iter;
3501 path = dbus_message_get_path(message);
3503 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3505 if (!dbus_message_iter_init(message, &iter))
3506 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3508 for (i = 0; signal_map[i].interface; i++) {
3509 if (!dbus_message_has_interface(message, signal_map[i].interface))
3512 if (!dbus_message_has_member(message, signal_map[i].member))
3515 signal_map[i].function(path, &iter);
3519 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3522 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
3524 SUPPLICANT_DBG("Cancelling any pending DBus calls");
3525 supplicant_dbus_method_call_cancel_all(interface);
3526 supplicant_dbus_property_call_cancel_all(interface);
3529 struct supplicant_regdom {
3530 GSupplicantCountryCallback callback;
3532 const void *user_data;
3535 static void country_result(const char *error,
3536 DBusMessageIter *iter, void *user_data)
3538 struct supplicant_regdom *regdom = user_data;
3541 SUPPLICANT_DBG("Country setting result");
3547 SUPPLICANT_DBG("Country setting failure %s", error);
3551 if (regdom->callback)
3552 regdom->callback(result, regdom->alpha2,
3553 (void *) regdom->user_data);
3558 static void country_params(DBusMessageIter *iter, void *user_data)
3560 struct supplicant_regdom *regdom = user_data;
3562 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
3566 int g_supplicant_set_country(const char *alpha2,
3567 GSupplicantCountryCallback callback,
3568 const void *user_data)
3570 struct supplicant_regdom *regdom;
3572 SUPPLICANT_DBG("Country setting %s", alpha2);
3574 if (!system_available)
3577 regdom = dbus_malloc0(sizeof(*regdom));
3581 regdom->callback = callback;
3582 regdom->alpha2 = alpha2;
3583 regdom->user_data = user_data;
3585 return supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
3586 "Country", DBUS_TYPE_STRING_AS_STRING,
3587 country_params, country_result,
3591 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
3592 GSupplicantCountryCallback callback,
3596 struct supplicant_regdom *regdom;
3598 regdom = dbus_malloc0(sizeof(*regdom));
3602 regdom->callback = callback;
3603 regdom->alpha2 = alpha2;
3604 regdom->user_data = user_data;
3606 return supplicant_dbus_property_set(interface->path,
3607 SUPPLICANT_INTERFACE ".Interface",
3608 "Country", DBUS_TYPE_STRING_AS_STRING,
3609 country_params, country_result,
3613 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
3618 return interface->p2p_support;
3621 struct supplicant_p2p_dev_config {
3626 static void p2p_device_config_result(const char *error,
3627 DBusMessageIter *iter, void *user_data)
3629 struct supplicant_p2p_dev_config *config = user_data;
3632 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
3635 g_free(config->device_name);
3636 g_free(config->dev_type);
3640 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
3642 int length, pos, end;
3647 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
3654 dev_type[length] = strtol(b, &e, 16);
3655 if (e && *e != '\0')
3664 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
3666 struct supplicant_p2p_dev_config *config = user_data;
3667 DBusMessageIter dict;
3669 supplicant_dbus_dict_open(iter, &dict);
3671 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
3672 DBUS_TYPE_STRING, &config->device_name);
3674 if (config->dev_type) {
3675 unsigned char dev_type[8] = {}, *type;
3678 len = dev_type_str2bin(config->dev_type, dev_type);
3681 supplicant_dbus_dict_append_fixed_array(&dict,
3682 "PrimaryDeviceType",
3683 DBUS_TYPE_BYTE, &type, len);
3687 supplicant_dbus_dict_close(iter, &dict);
3690 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
3691 const char *device_name,
3692 const char *primary_dev_type)
3694 struct supplicant_p2p_dev_config *config;
3697 SUPPLICANT_DBG("P2P Device settings %s/%s",
3698 device_name, primary_dev_type);
3700 config = dbus_malloc0(sizeof(*config));
3704 config->device_name = g_strdup(device_name);
3705 config->dev_type = g_strdup(primary_dev_type);
3707 ret = supplicant_dbus_property_set(interface->path,
3708 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
3710 DBUS_TYPE_ARRAY_AS_STRING
3711 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
3712 DBUS_TYPE_STRING_AS_STRING
3713 DBUS_TYPE_VARIANT_AS_STRING
3714 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
3715 p2p_device_config_params,
3716 p2p_device_config_result, config, NULL);
3718 g_free(config->device_name);
3719 g_free(config->dev_type);
3721 SUPPLICANT_DBG("Unable to set P2P Device configuration");
3727 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
3730 const GSupplicantPeer *peer = value;
3731 const char *identifier = user_data;
3733 if (!g_strcmp0(identifier, peer->identifier))
3739 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
3740 const char *identifier)
3742 GSupplicantPeer *peer;
3744 peer = g_hash_table_find(interface->peer_table,
3745 peer_lookup_by_identifier,
3746 (void *) identifier);
3750 struct interface_data {
3751 GSupplicantInterface *interface;
3752 char *path; /* Interface path cannot be taken from interface (above) as
3753 * it might have been freed already.
3755 GSupplicantInterfaceCallback callback;
3759 struct interface_create_data {
3763 GSupplicantInterface *interface;
3764 GSupplicantInterfaceCallback callback;
3768 struct interface_connect_data {
3769 GSupplicantInterface *interface;
3771 GSupplicantInterfaceCallback callback;
3773 GSupplicantSSID *ssid;
3774 GSupplicantPeerParams *peer;
3779 struct interface_scan_data {
3780 GSupplicantInterface *interface;
3782 GSupplicantInterfaceCallback callback;
3783 GSupplicantScanParams *scan_params;
3787 static void interface_create_data_free(struct interface_create_data *data)
3789 g_free(data->ifname);
3790 g_free(data->driver);
3791 g_free(data->bridge);
3795 static bool interface_exists(GSupplicantInterface *interface,
3798 GSupplicantInterface *tmp;
3800 tmp = g_hash_table_lookup(interface_table, path);
3801 if (tmp && tmp == interface)
3807 static void interface_create_property(const char *key, DBusMessageIter *iter,
3810 struct interface_create_data *data = user_data;
3811 GSupplicantInterface *interface = data->interface;
3814 if (data->callback) {
3815 data->callback(0, data->interface, data->user_data);
3816 #if !defined TIZEN_EXT
3817 callback_p2p_support(interface);
3821 interface_create_data_free(data);
3824 interface_property(key, iter, interface);
3827 static void interface_create_result(const char *error,
3828 DBusMessageIter *iter, void *user_data)
3830 struct interface_create_data *data = user_data;
3831 const char *path = NULL;
3837 g_warning("error %s", error);
3842 dbus_message_iter_get_basic(iter, &path);
3848 if (!system_available) {
3853 data->interface = g_hash_table_lookup(interface_table, path);
3854 if (!data->interface) {
3855 data->interface = interface_alloc(path);
3856 if (!data->interface) {
3862 err = supplicant_dbus_property_get_all(path,
3863 SUPPLICANT_INTERFACE ".Interface",
3864 interface_create_property, data,
3871 data->callback(err, NULL, data->user_data);
3873 interface_create_data_free(data);
3876 static void interface_create_params(DBusMessageIter *iter, void *user_data)
3878 struct interface_create_data *data = user_data;
3879 DBusMessageIter dict;
3883 supplicant_dbus_dict_open(iter, &dict);
3885 supplicant_dbus_dict_append_basic(&dict, "Ifname",
3886 DBUS_TYPE_STRING, &data->ifname);
3889 supplicant_dbus_dict_append_basic(&dict, "Driver",
3890 DBUS_TYPE_STRING, &data->driver);
3893 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
3894 DBUS_TYPE_STRING, &data->bridge);
3896 supplicant_dbus_dict_close(iter, &dict);
3899 static void interface_get_result(const char *error,
3900 DBusMessageIter *iter, void *user_data)
3902 struct interface_create_data *data = user_data;
3903 GSupplicantInterface *interface;
3904 const char *path = NULL;
3910 SUPPLICANT_DBG("Interface not created yet");
3914 dbus_message_iter_get_basic(iter, &path);
3920 interface = g_hash_table_lookup(interface_table, path);
3926 if (data->callback) {
3927 data->callback(0, interface, data->user_data);
3928 #if !defined TIZEN_EXT
3929 callback_p2p_support(interface);
3933 interface_create_data_free(data);
3938 if (!system_available) {
3943 SUPPLICANT_DBG("Creating interface");
3945 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
3946 SUPPLICANT_INTERFACE,
3948 interface_create_params,
3949 interface_create_result, data,
3956 data->callback(err, NULL, data->user_data);
3958 interface_create_data_free(data);
3961 static void interface_get_params(DBusMessageIter *iter, void *user_data)
3963 struct interface_create_data *data = user_data;
3967 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
3970 int g_supplicant_interface_create(const char *ifname, const char *driver,
3972 GSupplicantInterfaceCallback callback,
3975 struct interface_create_data *data;
3978 SUPPLICANT_DBG("ifname %s", ifname);
3983 if (!system_available)
3986 data = dbus_malloc0(sizeof(*data));
3990 data->ifname = g_strdup(ifname);
3991 data->driver = g_strdup(driver);
3992 data->bridge = g_strdup(bridge);
3993 data->callback = callback;
3994 data->user_data = user_data;
3996 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
3997 SUPPLICANT_INTERFACE,
3999 interface_get_params,
4000 interface_get_result, data,
4003 interface_create_data_free(data);
4008 static void interface_remove_result(const char *error,
4009 DBusMessageIter *iter, void *user_data)
4011 struct interface_data *data = user_data;
4019 if (!system_available) {
4025 * The gsupplicant interface is already freed by the InterfaceRemoved
4026 * signal callback. Simply invoke the interface_data callback.
4034 data->callback(err, NULL, data->user_data);
4040 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
4042 struct interface_data *data = user_data;
4044 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
4045 &data->interface->path);
4049 int g_supplicant_interface_remove(GSupplicantInterface *interface,
4050 GSupplicantInterfaceCallback callback,
4053 struct interface_data *data;
4059 if (!system_available)
4062 g_supplicant_interface_cancel(interface);
4064 data = dbus_malloc0(sizeof(*data));
4068 data->interface = interface;
4069 data->path = g_strdup(interface->path);
4070 data->callback = callback;
4071 data->user_data = user_data;
4073 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
4074 SUPPLICANT_INTERFACE,
4076 interface_remove_params,
4077 interface_remove_result, data,
4086 static void interface_scan_result(const char *error,
4087 DBusMessageIter *iter, void *user_data)
4089 struct interface_scan_data *data = user_data;
4093 SUPPLICANT_DBG("error %s", error);
4097 /* A non ready interface cannot send/receive anything */
4098 if (interface_exists(data->interface, data->path)) {
4099 if (!data->interface->ready)
4107 data->callback(err, data->interface, data->user_data);
4109 data->interface->scan_callback = data->callback;
4110 data->interface->scan_data = data->user_data;
4113 if (data->scan_params)
4114 g_supplicant_free_scan_params(data->scan_params);
4119 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
4121 DBusMessageIter data;
4122 unsigned int width = 0; /* Not used by wpa_supplicant atm */
4124 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
4126 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
4127 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
4129 dbus_message_iter_close_container(iter, &data);
4132 static void add_scan_frequencies(DBusMessageIter *iter,
4135 GSupplicantScanParams *scan_data = user_data;
4139 for (i = 0; i < scan_data->num_freqs; i++) {
4140 freq = scan_data->freqs[i];
4144 add_scan_frequency(iter, freq);
4148 static void append_ssid(DBusMessageIter *iter,
4149 const void *ssid, unsigned int len)
4151 DBusMessageIter array;
4153 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
4154 DBUS_TYPE_BYTE_AS_STRING, &array);
4156 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
4158 dbus_message_iter_close_container(iter, &array);
4161 static void append_ssids(DBusMessageIter *iter, void *user_data)
4163 GSupplicantScanParams *scan_data = user_data;
4166 for (list = scan_data->ssids; list; list = list->next) {
4167 struct scan_ssid *scan_ssid = list->data;
4169 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
4173 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
4174 supplicant_dbus_array_function function,
4177 GSupplicantScanParams *scan_params = user_data;
4178 DBusMessageIter entry, value, array;
4179 const char *key = "Channels";
4181 if (scan_params->freqs && scan_params->freqs[0] != 0) {
4182 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
4185 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
4187 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
4188 DBUS_TYPE_ARRAY_AS_STRING
4189 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
4190 DBUS_TYPE_UINT32_AS_STRING
4191 DBUS_TYPE_UINT32_AS_STRING
4192 DBUS_STRUCT_END_CHAR_AS_STRING,
4195 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
4196 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
4197 DBUS_TYPE_UINT32_AS_STRING
4198 DBUS_TYPE_UINT32_AS_STRING
4199 DBUS_STRUCT_END_CHAR_AS_STRING,
4203 function(&array, user_data);
4205 dbus_message_iter_close_container(&value, &array);
4206 dbus_message_iter_close_container(&entry, &value);
4207 dbus_message_iter_close_container(dict, &entry);
4211 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
4213 DBusMessageIter dict;
4214 const char *type = "passive";
4215 struct interface_scan_data *data = user_data;
4217 supplicant_dbus_dict_open(iter, &dict);
4219 if (data && data->scan_params) {
4222 supplicant_dbus_dict_append_basic(&dict, "Type",
4223 DBUS_TYPE_STRING, &type);
4225 supplicant_dbus_dict_append_array(&dict, "SSIDs",
4230 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
4233 supplicant_dbus_dict_append_basic(&dict, "Type",
4234 DBUS_TYPE_STRING, &type);
4236 supplicant_dbus_dict_close(iter, &dict);
4239 static int interface_ready_to_scan(GSupplicantInterface *interface)
4244 if (!system_available)
4247 if (interface->scanning)
4250 switch (interface->state) {
4251 case G_SUPPLICANT_STATE_AUTHENTICATING:
4252 case G_SUPPLICANT_STATE_ASSOCIATING:
4253 case G_SUPPLICANT_STATE_ASSOCIATED:
4254 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4255 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4257 case G_SUPPLICANT_STATE_UNKNOWN:
4258 case G_SUPPLICANT_STATE_DISABLED:
4259 case G_SUPPLICANT_STATE_DISCONNECTED:
4260 case G_SUPPLICANT_STATE_INACTIVE:
4261 case G_SUPPLICANT_STATE_SCANNING:
4262 case G_SUPPLICANT_STATE_COMPLETED:
4269 int g_supplicant_interface_scan(GSupplicantInterface *interface,
4270 GSupplicantScanParams *scan_data,
4271 GSupplicantInterfaceCallback callback,
4274 struct interface_scan_data *data;
4277 ret = interface_ready_to_scan(interface);
4281 data = dbus_malloc0(sizeof(*data));
4285 data->interface = interface;
4286 data->path = g_strdup(interface->path);
4287 #if defined TIZEN_EXT
4288 data->interface->scan_callback = data->callback = callback;
4289 data->interface->scan_data = data->user_data = user_data;
4291 data->callback = callback;
4292 data->user_data = user_data;
4294 data->scan_params = scan_data;
4296 interface->scan_callback = callback;
4297 interface->scan_data = user_data;
4299 ret = supplicant_dbus_method_call(interface->path,
4300 SUPPLICANT_INTERFACE ".Interface", "Scan",
4301 interface_scan_params, interface_scan_result, data,
4312 static int parse_supplicant_error(DBusMessageIter *iter)
4314 int err = -ECANCELED;
4320 /* If the given passphrase is malformed wpa_s returns
4321 * "invalid message format" but this error should be interpreted as
4324 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
4325 dbus_message_iter_get_basic(iter, &key);
4326 if (strncmp(key, "psk", 3) == 0 ||
4327 strncmp(key, "wep_key", 7) == 0 ||
4328 strcmp(key, "invalid message format") == 0) {
4332 dbus_message_iter_next(iter);
4338 static void interface_select_network_result(const char *error,
4339 DBusMessageIter *iter, void *user_data)
4341 struct interface_connect_data *data = user_data;
4348 SUPPLICANT_DBG("SelectNetwork error %s", error);
4349 err = parse_supplicant_error(iter);
4355 data->callback(err, data->interface, data->user_data);
4361 static void interface_select_network_params(DBusMessageIter *iter,
4364 struct interface_connect_data *data = user_data;
4365 GSupplicantInterface *interface = data->interface;
4367 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
4368 &interface->network_path);
4371 static void interface_add_network_result(const char *error,
4372 DBusMessageIter *iter, void *user_data)
4374 struct interface_connect_data *data = user_data;
4375 GSupplicantInterface *interface = data->interface;
4382 dbus_message_iter_get_basic(iter, &path);
4386 SUPPLICANT_DBG("PATH: %s", path);
4388 g_free(interface->network_path);
4389 interface->network_path = g_strdup(path);
4391 supplicant_dbus_method_call(data->interface->path,
4392 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
4393 interface_select_network_params,
4394 interface_select_network_result, data,
4400 SUPPLICANT_DBG("AddNetwork error %s", error);
4402 if (interface_exists(data->interface, data->interface->path)) {
4403 err = parse_supplicant_error(iter);
4405 data->callback(err, data->interface, data->user_data);
4407 g_free(interface->network_path);
4408 interface->network_path = NULL;
4416 static void add_network_security_none(DBusMessageIter *dict)
4418 const char *auth_alg = "OPEN";
4420 supplicant_dbus_dict_append_basic(dict, "auth_alg",
4421 DBUS_TYPE_STRING, &auth_alg);
4424 static void add_network_security_wep(DBusMessageIter *dict,
4425 GSupplicantSSID *ssid)
4427 const char *auth_alg = "OPEN SHARED";
4428 dbus_uint32_t key_index = 0;
4430 supplicant_dbus_dict_append_basic(dict, "auth_alg",
4431 DBUS_TYPE_STRING, &auth_alg);
4433 if (ssid->passphrase) {
4434 int size = strlen(ssid->passphrase);
4435 if (size == 10 || size == 26) {
4436 unsigned char *key = g_try_malloc(13);
4440 memset(tmp, 0, sizeof(tmp));
4444 for (i = 0; i < size / 2; i++) {
4445 memcpy(tmp, ssid->passphrase + (i * 2), 2);
4446 key[i] = (unsigned char) strtol(tmp, NULL, 16);
4449 supplicant_dbus_dict_append_fixed_array(dict,
4454 } else if (size == 5 || size == 13) {
4455 unsigned char *key = g_try_malloc(13);
4461 for (i = 0; i < size; i++)
4462 key[i] = (unsigned char) ssid->passphrase[i];
4464 supplicant_dbus_dict_append_fixed_array(dict,
4470 supplicant_dbus_dict_append_basic(dict,
4475 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
4476 DBUS_TYPE_UINT32, &key_index);
4480 static dbus_bool_t is_psk_raw_key(const char *psk)
4484 /* A raw key is always 64 bytes length... */
4485 if (strlen(psk) != 64)
4488 /* ... and its content is in hex representation */
4489 for (i = 0; i < 64; i++)
4490 if (!isxdigit((unsigned char) psk[i]))
4496 static unsigned char hexchar2bin(char c)
4498 if ((c >= '0') && (c <= '9'))
4500 else if ((c >= 'A') && (c <= 'F'))
4501 return c - 'A' + 10;
4502 else if ((c >= 'a') && (c <= 'f'))
4503 return c - 'a' + 10;
4508 static void hexstring2bin(const char *string, unsigned char *data,
4513 for (i = 0; i < data_len; i++)
4514 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
4515 hexchar2bin(string[i * 2 + 1]) << 0);
4518 static void add_network_security_psk(DBusMessageIter *dict,
4519 GSupplicantSSID *ssid)
4521 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
4522 const char *key = "psk";
4524 if (is_psk_raw_key(ssid->passphrase)) {
4525 unsigned char data[32];
4526 unsigned char *datap = data;
4528 /* The above pointer alias is required by D-Bus because
4529 * with D-Bus and GCC, non-heap-allocated arrays cannot
4530 * be passed directly by their base pointer. */
4532 hexstring2bin(ssid->passphrase, datap, sizeof(data));
4534 supplicant_dbus_dict_append_fixed_array(dict,
4535 key, DBUS_TYPE_BYTE,
4536 &datap, sizeof(data));
4538 supplicant_dbus_dict_append_basic(dict,
4539 key, DBUS_TYPE_STRING,
4544 static void add_network_security_tls(DBusMessageIter *dict,
4545 GSupplicantSSID *ssid)
4548 * For TLS, we at least need:
4549 * The client certificate
4550 * The client private key file
4551 * The client private key file password
4553 * The Authority certificate is optional.
4555 if (!ssid->client_cert_path)
4558 if (!ssid->private_key_path)
4561 #if !defined TIZEN_EXT
4562 if (!ssid->private_key_passphrase)
4566 if (ssid->ca_cert_path)
4567 supplicant_dbus_dict_append_basic(dict, "ca_cert",
4568 DBUS_TYPE_STRING, &ssid->ca_cert_path);
4570 supplicant_dbus_dict_append_basic(dict, "private_key",
4572 &ssid->private_key_path);
4573 #if !defined TIZEN_EXT
4574 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
4576 &ssid->private_key_passphrase);
4578 supplicant_dbus_dict_append_basic(dict, "client_cert",
4580 &ssid->client_cert_path);
4583 static void add_network_security_peap(DBusMessageIter *dict,
4584 GSupplicantSSID *ssid)
4589 * For PEAP/TTLS, we at least need
4590 * The authority certificate
4591 * The 2nd phase authentication method
4592 * The 2nd phase passphrase
4594 * The Client certificate is optional although strongly recommended
4595 * When setting it, we need in addition
4596 * The Client private key file
4597 * The Client private key file password
4599 if (!ssid->passphrase)
4602 if (!ssid->phase2_auth)
4605 if (ssid->client_cert_path) {
4606 if (!ssid->private_key_path)
4609 #if !defined TIZEN_EXT
4610 if (!ssid->private_key_passphrase)
4614 supplicant_dbus_dict_append_basic(dict, "client_cert",
4616 &ssid->client_cert_path);
4618 supplicant_dbus_dict_append_basic(dict, "private_key",
4620 &ssid->private_key_path);
4622 #if !defined TIZEN_EXT
4623 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
4625 &ssid->private_key_passphrase);
4630 if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
4631 phase2_auth = g_strdup_printf("autheap=%s",
4632 ssid->phase2_auth + strlen("EAP-"));
4634 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
4636 supplicant_dbus_dict_append_basic(dict, "password",
4640 if (ssid->ca_cert_path)
4641 supplicant_dbus_dict_append_basic(dict, "ca_cert",
4643 &ssid->ca_cert_path);
4645 supplicant_dbus_dict_append_basic(dict, "phase2",
4649 g_free(phase2_auth);
4652 static void add_network_security_eap(DBusMessageIter *dict,
4653 GSupplicantSSID *ssid)
4657 #if defined TIZEN_EXT
4660 if (!ssid->eap || !ssid->identity)
4664 if (g_strcmp0(ssid->eap, "tls") == 0) {
4665 add_network_security_tls(dict, ssid);
4666 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
4667 g_strcmp0(ssid->eap, "ttls") == 0) {
4668 #if defined TIZEN_EXT
4669 if (!ssid->identity)
4672 add_network_security_peap(dict, ssid);
4674 #if defined TIZEN_EXT
4675 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
4676 g_strcmp0(ssid->eap, "aka") == 0) {
4681 eap_value = g_ascii_strup(ssid->eap, -1);
4683 supplicant_dbus_dict_append_basic(dict, "eap",
4686 #if defined TIZEN_EXT
4687 if (ssid->identity != NULL)
4688 supplicant_dbus_dict_append_basic(dict, "identity",
4692 supplicant_dbus_dict_append_basic(dict, "identity",
4700 static void add_network_security_ciphers(DBusMessageIter *dict,
4701 GSupplicantSSID *ssid)
4703 unsigned int p_cipher, g_cipher, i;
4704 char *pairwise, *group;
4705 char *pair_ciphers[4];
4706 char *group_ciphers[5];
4708 p_cipher = ssid->pairwise_cipher;
4709 g_cipher = ssid->group_cipher;
4711 if (p_cipher == 0 && g_cipher == 0)
4716 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
4717 pair_ciphers[i++] = "CCMP";
4719 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
4720 pair_ciphers[i++] = "TKIP";
4722 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
4723 pair_ciphers[i++] = "NONE";
4725 pair_ciphers[i] = NULL;
4729 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
4730 group_ciphers[i++] = "CCMP";
4732 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
4733 group_ciphers[i++] = "TKIP";
4735 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
4736 group_ciphers[i++] = "WEP104";
4738 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
4739 group_ciphers[i++] = "WEP40";
4741 group_ciphers[i] = NULL;
4743 pairwise = g_strjoinv(" ", pair_ciphers);
4744 group = g_strjoinv(" ", group_ciphers);
4746 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
4748 supplicant_dbus_dict_append_basic(dict, "pairwise",
4751 supplicant_dbus_dict_append_basic(dict, "group",
4759 static void add_network_security_proto(DBusMessageIter *dict,
4760 GSupplicantSSID *ssid)
4762 unsigned int protocol, i;
4766 protocol = ssid->protocol;
4773 if (protocol & G_SUPPLICANT_PROTO_RSN)
4774 protos[i++] = "RSN";
4776 if (protocol & G_SUPPLICANT_PROTO_WPA)
4777 protos[i++] = "WPA";
4781 proto = g_strjoinv(" ", protos);
4783 SUPPLICANT_DBG("proto %s", proto);
4785 supplicant_dbus_dict_append_basic(dict, "proto",
4792 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
4796 switch (ssid->security) {
4797 case G_SUPPLICANT_SECURITY_NONE:
4799 add_network_security_none(dict);
4800 add_network_security_ciphers(dict, ssid);
4802 case G_SUPPLICANT_SECURITY_UNKNOWN:
4803 case G_SUPPLICANT_SECURITY_WEP:
4805 add_network_security_wep(dict, ssid);
4806 add_network_security_ciphers(dict, ssid);
4808 case G_SUPPLICANT_SECURITY_PSK:
4809 key_mgmt = "WPA-PSK";
4810 add_network_security_psk(dict, ssid);
4811 add_network_security_ciphers(dict, ssid);
4812 add_network_security_proto(dict, ssid);
4814 case G_SUPPLICANT_SECURITY_IEEE8021X:
4815 key_mgmt = "WPA-EAP";
4816 add_network_security_eap(dict, ssid);
4817 add_network_security_ciphers(dict, ssid);
4818 add_network_security_proto(dict, ssid);
4820 #if defined TIZEN_EXT
4821 case G_SUPPLICANT_SECURITY_FT_PSK:
4822 key_mgmt = "FT-PSK";
4823 add_network_security_psk(dict, ssid);
4824 add_network_security_ciphers(dict, ssid);
4825 add_network_security_proto(dict, ssid);
4827 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
4828 key_mgmt = "FT-EAP";
4829 add_network_security_eap(dict, ssid);
4830 add_network_security_ciphers(dict, ssid);
4831 add_network_security_proto(dict, ssid);
4836 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
4837 DBUS_TYPE_STRING, &key_mgmt);
4840 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
4844 switch (ssid->mode) {
4845 case G_SUPPLICANT_MODE_UNKNOWN:
4846 case G_SUPPLICANT_MODE_INFRA:
4849 case G_SUPPLICANT_MODE_IBSS:
4852 case G_SUPPLICANT_MODE_MASTER:
4857 supplicant_dbus_dict_append_basic(dict, "mode",
4858 DBUS_TYPE_UINT32, &mode);
4861 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
4863 DBusMessageIter dict;
4864 struct interface_connect_data *data = user_data;
4865 GSupplicantSSID *ssid = data->ssid;
4867 supplicant_dbus_dict_open(iter, &dict);
4869 if (ssid->scan_ssid)
4870 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
4871 DBUS_TYPE_UINT32, &ssid->scan_ssid);
4874 supplicant_dbus_dict_append_basic(&dict, "frequency",
4875 DBUS_TYPE_UINT32, &ssid->freq);
4878 supplicant_dbus_dict_append_basic(&dict, "bgscan",
4879 DBUS_TYPE_STRING, &ssid->bgscan);
4881 add_network_mode(&dict, ssid);
4883 add_network_security(&dict, ssid);
4885 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
4886 DBUS_TYPE_BYTE, &ssid->ssid,
4889 supplicant_dbus_dict_append_basic(&dict, "ignore_broadcast_ssid",
4891 &ssid->ignore_broadcast_ssid);
4893 supplicant_dbus_dict_close(iter, &dict);
4896 static void interface_wps_start_result(const char *error,
4897 DBusMessageIter *iter, void *user_data)
4899 struct interface_connect_data *data = user_data;
4906 SUPPLICANT_DBG("error: %s", error);
4907 err = parse_supplicant_error(iter);
4911 data->callback(err, data->interface, data->user_data);
4918 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
4920 struct interface_connect_data *data = user_data;
4921 GSupplicantSSID *ssid = data->ssid;
4922 const char *role = "enrollee", *type;
4923 DBusMessageIter dict;
4927 supplicant_dbus_dict_open(iter, &dict);
4929 supplicant_dbus_dict_append_basic(&dict, "Role",
4930 DBUS_TYPE_STRING, &role);
4933 if (ssid->pin_wps) {
4935 supplicant_dbus_dict_append_basic(&dict, "Pin",
4936 DBUS_TYPE_STRING, &ssid->pin_wps);
4939 supplicant_dbus_dict_append_basic(&dict, "Type",
4940 DBUS_TYPE_STRING, &type);
4942 #if defined TIZEN_EXT
4944 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
4945 DBUS_TYPE_BYTE, &ssid->bssid, 6);
4948 supplicant_dbus_dict_close(iter, &dict);
4951 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
4953 struct interface_connect_data *data = user_data;
4958 SUPPLICANT_DBG("error: %s", error);
4964 #if defined TIZEN_EXT
4965 GSupplicantSSID *ssid = data->ssid;
4966 if (ssid->pin_wps != NULL) {
4967 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
4968 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
4975 supplicant_dbus_method_call(data->interface->path,
4976 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
4977 interface_add_wps_params,
4978 interface_wps_start_result, data, NULL);
4981 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
4983 dbus_bool_t credentials = TRUE;
4987 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
4991 int g_supplicant_interface_connect(GSupplicantInterface *interface,
4992 GSupplicantSSID *ssid,
4993 GSupplicantInterfaceCallback callback,
4996 struct interface_connect_data *data;
5002 if (!system_available)
5005 /* TODO: Check if we're already connected and switch */
5007 data = dbus_malloc0(sizeof(*data));
5011 data->interface = interface;
5012 data->path = g_strdup(interface->path);
5013 data->callback = callback;
5015 data->user_data = user_data;
5017 if (ssid->use_wps) {
5018 g_free(interface->wps_cred.key);
5019 memset(&interface->wps_cred, 0,
5020 sizeof(struct _GSupplicantWpsCredentials));
5022 ret = supplicant_dbus_property_set(interface->path,
5023 SUPPLICANT_INTERFACE ".Interface.WPS",
5024 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
5025 wps_process_credentials, wps_start, data, interface);
5027 ret = supplicant_dbus_method_call(interface->path,
5028 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
5029 interface_add_network_params,
5030 interface_add_network_result, data,
5039 return -EINPROGRESS;
5042 static void network_remove_result(const char *error,
5043 DBusMessageIter *iter, void *user_data)
5045 struct interface_data *data = user_data;
5052 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
5054 result = -ECONNABORTED;
5060 data->callback(result, data->interface, data->user_data);
5065 static void network_remove_params(DBusMessageIter *iter, void *user_data)
5067 struct interface_data *data = user_data;
5068 const char *path = data->interface->network_path;
5070 SUPPLICANT_DBG("path %s", path);
5072 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
5075 static int network_remove(struct interface_data *data)
5077 GSupplicantInterface *interface = data->interface;
5081 #if defined TIZEN_EXT
5082 GSupplicantInterface *intf = NULL;
5084 * Check if 'interface' is valid
5086 intf = g_hash_table_lookup(interface_table, interface->path);
5091 return supplicant_dbus_method_call(interface->path,
5092 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
5093 network_remove_params, network_remove_result, data,
5097 static void interface_disconnect_result(const char *error,
5098 DBusMessageIter *iter, void *user_data)
5100 struct interface_data *data = user_data;
5107 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
5109 result = -ECONNABORTED;
5112 if (result < 0 && data->callback) {
5113 data->callback(result, data->interface, data->user_data);
5114 data->callback = NULL;
5117 /* If we are disconnecting from previous WPS successful
5118 * association. i.e.: it did not went through AddNetwork,
5119 * and interface->network_path was never set. */
5120 if (!data->interface->network_path) {
5126 if (result != -ECONNABORTED) {
5127 if (network_remove(data) < 0) {
5137 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
5138 GSupplicantInterfaceCallback callback,
5141 struct interface_data *data;
5149 if (!system_available)
5152 data = dbus_malloc0(sizeof(*data));
5156 data->interface = interface;
5157 data->path = g_strdup(interface->path);
5158 data->callback = callback;
5159 data->user_data = user_data;
5161 ret = supplicant_dbus_method_call(interface->path,
5162 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
5163 NULL, interface_disconnect_result, data,
5174 static void interface_p2p_find_result(const char *error,
5175 DBusMessageIter *iter, void *user_data)
5177 struct interface_scan_data *data = user_data;
5180 SUPPLICANT_DBG("error %s", error);
5185 if (interface_exists(data->interface, data->path)) {
5186 if (!data->interface->ready)
5189 data->interface->p2p_finding = true;
5193 data->callback(err, data->interface, data->user_data);
5199 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
5201 DBusMessageIter dict;
5203 supplicant_dbus_dict_open(iter, &dict);
5204 supplicant_dbus_dict_close(iter, &dict);
5207 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
5208 GSupplicantInterfaceCallback callback,
5211 struct interface_scan_data *data;
5214 if (!interface->p2p_support)
5217 ret = interface_ready_to_scan(interface);
5218 if (ret && ret != -EALREADY)
5221 data = dbus_malloc0(sizeof(*data));
5225 data->interface = interface;
5226 data->path = g_strdup(interface->path);
5227 data->callback = callback;
5228 data->user_data = user_data;
5230 ret = supplicant_dbus_method_call(interface->path,
5231 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
5232 interface_p2p_find_params, interface_p2p_find_result,
5242 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
5247 return interface->p2p_finding;
5250 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
5252 if (!interface->p2p_finding)
5257 interface->p2p_finding = false;
5259 return supplicant_dbus_method_call(interface->path,
5260 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
5261 NULL, NULL, NULL, NULL);
5264 static void interface_p2p_connect_result(const char *error,
5265 DBusMessageIter *iter, void *user_data)
5267 struct interface_connect_data *data = user_data;
5273 err = parse_supplicant_error(iter);
5276 data->callback(err, data->interface, data->user_data);
5279 g_free(data->peer->wps_pin);
5280 g_free(data->peer->path);
5285 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
5287 struct interface_connect_data *data = user_data;
5288 const char *wps = "pbc";
5289 DBusMessageIter dict;
5294 supplicant_dbus_dict_open(iter, &dict);
5296 if (data->peer->master)
5299 if (data->peer->wps_pin)
5302 supplicant_dbus_dict_append_basic(&dict, "peer",
5303 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
5304 supplicant_dbus_dict_append_basic(&dict, "wps_method",
5305 DBUS_TYPE_STRING, &wps);
5306 if (data->peer->wps_pin) {
5307 supplicant_dbus_dict_append_basic(&dict, "pin",
5308 DBUS_TYPE_STRING, &data->peer->wps_pin);
5311 supplicant_dbus_dict_append_basic(&dict, "go_intent",
5312 DBUS_TYPE_INT32, &go_intent);
5314 supplicant_dbus_dict_close(iter, &dict);
5317 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
5318 GSupplicantPeerParams *peer_params,
5319 GSupplicantInterfaceCallback callback,
5322 struct interface_connect_data *data;
5327 if (!interface->p2p_support)
5330 data = dbus_malloc0(sizeof(*data));
5331 data->interface = interface;
5332 data->path = g_strdup(interface->path);
5333 data->peer = peer_params;
5334 data->callback = callback;
5335 data->user_data = user_data;
5337 ret = supplicant_dbus_method_call(interface->path,
5338 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
5339 interface_p2p_connect_params, interface_p2p_connect_result,
5347 return -EINPROGRESS;
5350 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
5351 GSupplicantPeerParams *peer_params)
5353 GSupplicantPeer *peer;
5359 if (!interface->p2p_support)
5362 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
5366 for (list = peer->groups; list; list = list->next, count++) {
5367 const char *group_obj_path = list->data;
5368 GSupplicantInterface *g_interface;
5369 GSupplicantGroup *group;
5371 group = g_hash_table_lookup(group_mapping, group_obj_path);
5372 if (!group || !group->interface)
5375 g_interface = group->interface;
5376 supplicant_dbus_method_call(g_interface->path,
5377 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5378 "Disconnect", NULL, NULL, NULL, g_interface);
5381 if (count == 0 && peer->current_group_iface) {
5382 supplicant_dbus_method_call(peer->current_group_iface->path,
5383 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5384 "Disconnect", NULL, NULL, NULL,
5385 peer->current_group_iface->path);
5388 peer->current_group_iface = NULL;
5390 return -EINPROGRESS;
5393 struct p2p_service_data {
5395 GSupplicantInterface *interface;
5396 GSupplicantP2PServiceParams *service;
5397 GSupplicantInterfaceCallback callback;
5401 static void interface_p2p_service_result(const char *error,
5402 DBusMessageIter *iter, void *user_data)
5404 struct p2p_service_data *data = user_data;
5407 SUPPLICANT_DBG("%s result - %s", data->registration ?
5408 "Registration" : "Deletion",
5409 error ? error : "Success");
5414 data->callback(result, data->interface, data->user_data);
5416 g_free(data->service->query);
5417 g_free(data->service->response);
5418 g_free(data->service->service);
5419 g_free(data->service->wfd_ies);
5420 g_free(data->service);
5424 static void interface_p2p_service_params(DBusMessageIter *iter,
5427 struct p2p_service_data *data = user_data;
5428 GSupplicantP2PServiceParams *service;
5429 DBusMessageIter dict;
5434 service = data->service;
5436 supplicant_dbus_dict_open(iter, &dict);
5438 if (service->query && service->response) {
5440 supplicant_dbus_dict_append_basic(&dict, "service_type",
5441 DBUS_TYPE_STRING, &type);
5442 supplicant_dbus_dict_append_fixed_array(&dict, "query",
5443 DBUS_TYPE_BYTE, &service->query,
5444 service->query_length);
5445 supplicant_dbus_dict_append_fixed_array(&dict, "response",
5446 DBUS_TYPE_BYTE, &service->response,
5447 service->response_length);
5448 } else if (service->version && service->service) {
5450 supplicant_dbus_dict_append_basic(&dict, "service_type",
5451 DBUS_TYPE_STRING, &type);
5452 supplicant_dbus_dict_append_basic(&dict, "version",
5453 DBUS_TYPE_INT32, &service->version);
5454 supplicant_dbus_dict_append_basic(&dict, "service",
5455 DBUS_TYPE_STRING, &service->service);
5458 supplicant_dbus_dict_close(iter, &dict);
5461 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
5462 GSupplicantInterfaceCallback callback,
5463 GSupplicantP2PServiceParams *p2p_service_params,
5466 struct p2p_service_data *data;
5471 if (!interface->p2p_support)
5474 data = dbus_malloc0(sizeof(*data));
5475 data->registration = true;
5476 data->interface = interface;
5477 data->service = p2p_service_params;
5478 data->callback = callback;
5479 data->user_data = user_data;
5481 ret = supplicant_dbus_method_call(interface->path,
5482 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
5483 interface_p2p_service_params, interface_p2p_service_result,
5490 return -EINPROGRESS;
5493 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
5494 GSupplicantP2PServiceParams *p2p_service_params)
5496 struct p2p_service_data *data;
5501 if (!interface->p2p_support)
5504 data = dbus_malloc0(sizeof(*data));
5505 data->interface = interface;
5506 data->service = p2p_service_params;
5508 ret = supplicant_dbus_method_call(interface->path,
5509 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
5510 interface_p2p_service_params, interface_p2p_service_result,
5517 return -EINPROGRESS;
5520 struct p2p_listen_data {
5525 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
5527 struct p2p_listen_data *params = user_data;
5528 DBusMessageIter dict;
5530 supplicant_dbus_dict_open(iter, &dict);
5532 supplicant_dbus_dict_append_basic(&dict, "period",
5533 DBUS_TYPE_INT32, ¶ms->period);
5534 supplicant_dbus_dict_append_basic(&dict, "interval",
5535 DBUS_TYPE_INT32, ¶ms->interval);
5536 supplicant_dbus_dict_close(iter, &dict);
5539 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
5540 int period, int interval)
5542 struct p2p_listen_data params;
5546 if (!interface->p2p_support)
5549 params.period = period;
5550 params.interval = interval;
5552 return supplicant_dbus_method_call(interface->path,
5553 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5554 "ExtendedListen", interface_p2p_listen_params,
5555 NULL, ¶ms, NULL);
5558 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
5560 struct p2p_service_data *data = user_data;
5561 GSupplicantP2PServiceParams *service = data->service;
5562 DBusMessageIter array;
5564 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
5566 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
5567 DBUS_TYPE_BYTE_AS_STRING, &array);
5569 if (service->wfd_ies && service->wfd_ies_length > 0) {
5570 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
5571 &service->wfd_ies, service->wfd_ies_length);
5574 dbus_message_iter_close_container(iter, &array);
5577 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
5578 GSupplicantInterfaceCallback callback,
5581 struct p2p_service_data *data;
5586 if (!system_available)
5589 data = dbus_malloc0(sizeof(*data));
5590 data->service = p2p_service_params;
5591 data->callback = callback;
5592 data->user_data = user_data;
5594 if (p2p_service_params->wfd_ies)
5595 data->registration = true;
5597 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
5598 SUPPLICANT_INTERFACE, "WFDIEs",
5599 DBUS_TYPE_ARRAY_AS_STRING
5600 DBUS_TYPE_BYTE_AS_STRING,
5602 interface_p2p_service_result,
5604 if (ret < 0 && ret != -EINPROGRESS) {
5609 return -EINPROGRESS;
5612 #if defined TIZEN_EXT
5613 int g_supplicant_interface_remove_network(GSupplicantInterface *interface)
5615 struct interface_data *data;
5619 if (interface == NULL)
5622 if (system_available == FALSE)
5625 data = dbus_malloc0(sizeof(*data));
5629 data->interface = interface;
5631 return network_remove(data);
5635 static const char *g_supplicant_rule0 = "type=signal,"
5636 "path=" DBUS_PATH_DBUS ","
5637 "sender=" DBUS_SERVICE_DBUS ","
5638 "interface=" DBUS_INTERFACE_DBUS ","
5639 "member=NameOwnerChanged,"
5640 "arg0=" SUPPLICANT_SERVICE;
5641 static const char *g_supplicant_rule1 = "type=signal,"
5642 "interface=" SUPPLICANT_INTERFACE;
5643 static const char *g_supplicant_rule2 = "type=signal,"
5644 "interface=" SUPPLICANT_INTERFACE ".Interface";
5645 static const char *g_supplicant_rule3 = "type=signal,"
5646 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
5647 static const char *g_supplicant_rule4 = "type=signal,"
5648 "interface=" SUPPLICANT_INTERFACE ".BSS";
5649 static const char *g_supplicant_rule5 = "type=signal,"
5650 "interface=" SUPPLICANT_INTERFACE ".Network";
5651 #if !defined TIZEN_EXT
5652 static const char *g_supplicant_rule6 = "type=signal,"
5653 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
5654 static const char *g_supplicant_rule7 = "type=signal,"
5655 "interface=" SUPPLICANT_INTERFACE ".Peer";
5656 static const char *g_supplicant_rule8 = "type=signal,"
5657 "interface=" SUPPLICANT_INTERFACE ".Group";
5660 static void invoke_introspect_method(void)
5662 DBusMessage *message;
5664 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
5666 DBUS_INTERFACE_INTROSPECTABLE,
5672 dbus_message_set_no_reply(message, TRUE);
5673 dbus_connection_send(connection, message, NULL);
5674 dbus_message_unref(message);
5677 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
5679 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
5683 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
5685 dbus_connection_unref(connection);
5690 callbacks_pointer = callbacks;
5693 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
5694 NULL, remove_interface);
5696 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
5698 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
5700 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
5702 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
5705 supplicant_dbus_setup(connection);
5707 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
5708 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
5709 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
5710 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
5711 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
5712 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
5713 #if defined TIZEN_EXT
5714 dbus_bus_add_match(connection,
5715 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
5716 "member=ChangeState", NULL);
5718 #if !defined TIZEN_EXT
5719 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
5720 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
5721 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
5723 dbus_connection_flush(connection);
5725 if (dbus_bus_name_has_owner(connection,
5726 SUPPLICANT_SERVICE, NULL)) {
5727 system_available = TRUE;
5728 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
5729 SUPPLICANT_INTERFACE,
5730 service_property, NULL, NULL);
5732 invoke_introspect_method();
5737 static void unregister_interface_remove_params(DBusMessageIter *iter,
5740 const char *path = user_data;
5742 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
5747 static void unregister_remove_interface(gpointer key, gpointer value,
5750 GSupplicantInterface *interface = value;
5752 supplicant_dbus_method_call(SUPPLICANT_PATH,
5753 SUPPLICANT_INTERFACE,
5755 unregister_interface_remove_params,
5756 NULL, interface->path, NULL);
5759 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
5764 #if !defined TIZEN_EXT
5765 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
5766 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
5767 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
5769 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
5770 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
5771 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
5772 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
5773 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
5774 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
5775 dbus_connection_flush(connection);
5777 dbus_connection_remove_filter(connection,
5778 g_supplicant_filter, NULL);
5782 g_hash_table_destroy(bss_mapping);
5787 g_hash_table_destroy(peer_mapping);
5788 peer_mapping = NULL;
5791 if (group_mapping) {
5792 g_hash_table_destroy(group_mapping);
5793 group_mapping = NULL;
5796 if (interface_table) {
5797 g_hash_table_foreach(interface_table,
5798 unregister_remove_interface, NULL);
5799 g_hash_table_destroy(interface_table);
5800 interface_table = NULL;
5803 if (system_available)
5804 callback_system_killed();
5807 dbus_connection_unref(connection);
5811 callbacks_pointer = NULL;