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;
236 unsigned int keymgmt;
240 struct _GSupplicantPeer {
241 GSupplicantInterface *interface;
243 unsigned char device_address[ETH_ALEN];
244 unsigned char iface_address[ETH_ALEN];
246 unsigned char *widi_ies;
249 unsigned int wps_capabilities;
251 const GSupplicantInterface *current_group_iface;
252 bool connection_requested;
255 struct _GSupplicantGroup {
256 GSupplicantInterface *interface;
257 GSupplicantInterface *orig_interface;
263 static inline void debug(const char *format, ...)
268 if (!callbacks_pointer->debug)
271 va_start(ap, format);
273 if (vsnprintf(str, sizeof(str), format, ap) > 0)
274 callbacks_pointer->debug(str);
279 #define SUPPLICANT_DBG(fmt, arg...) \
280 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
282 static GSupplicantMode string2mode(const char *mode)
285 return G_SUPPLICANT_MODE_UNKNOWN;
287 if (g_str_equal(mode, "infrastructure"))
288 return G_SUPPLICANT_MODE_INFRA;
289 else if (g_str_equal(mode, "ad-hoc"))
290 return G_SUPPLICANT_MODE_IBSS;
292 return G_SUPPLICANT_MODE_UNKNOWN;
295 static const char *mode2string(GSupplicantMode mode)
298 case G_SUPPLICANT_MODE_UNKNOWN:
300 case G_SUPPLICANT_MODE_INFRA:
302 case G_SUPPLICANT_MODE_IBSS:
304 case G_SUPPLICANT_MODE_MASTER:
311 static const char *security2string(GSupplicantSecurity security)
314 case G_SUPPLICANT_SECURITY_UNKNOWN:
316 case G_SUPPLICANT_SECURITY_NONE:
318 case G_SUPPLICANT_SECURITY_WEP:
320 case G_SUPPLICANT_SECURITY_PSK:
322 case G_SUPPLICANT_SECURITY_IEEE8021X:
324 #if defined TIZEN_EXT
325 case G_SUPPLICANT_SECURITY_FT_PSK:
327 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
328 return "ft_ieee8021x";
335 static GSupplicantState string2state(const char *state)
338 return G_SUPPLICANT_STATE_UNKNOWN;
340 if (g_str_equal(state, "unknown"))
341 return G_SUPPLICANT_STATE_UNKNOWN;
342 else if (g_str_equal(state, "interface_disabled"))
343 return G_SUPPLICANT_STATE_DISABLED;
344 else if (g_str_equal(state, "disconnected"))
345 return G_SUPPLICANT_STATE_DISCONNECTED;
346 else if (g_str_equal(state, "inactive"))
347 return G_SUPPLICANT_STATE_INACTIVE;
348 else if (g_str_equal(state, "scanning"))
349 return G_SUPPLICANT_STATE_SCANNING;
350 else if (g_str_equal(state, "authenticating"))
351 return G_SUPPLICANT_STATE_AUTHENTICATING;
352 else if (g_str_equal(state, "associating"))
353 return G_SUPPLICANT_STATE_ASSOCIATING;
354 else if (g_str_equal(state, "associated"))
355 return G_SUPPLICANT_STATE_ASSOCIATED;
356 else if (g_str_equal(state, "group_handshake"))
357 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
358 else if (g_str_equal(state, "4way_handshake"))
359 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
360 else if (g_str_equal(state, "completed"))
361 return G_SUPPLICANT_STATE_COMPLETED;
363 return G_SUPPLICANT_STATE_UNKNOWN;
366 static void callback_system_ready(void)
373 if (!callbacks_pointer)
376 if (!callbacks_pointer->system_ready)
379 callbacks_pointer->system_ready();
382 static void callback_system_killed(void)
384 system_ready = FALSE;
386 if (!callbacks_pointer)
389 if (!callbacks_pointer->system_killed)
392 callbacks_pointer->system_killed();
395 static void callback_interface_added(GSupplicantInterface *interface)
399 if (!callbacks_pointer)
402 if (!callbacks_pointer->interface_added)
405 callbacks_pointer->interface_added(interface);
408 static void callback_interface_state(GSupplicantInterface *interface)
410 if (!callbacks_pointer)
413 if (!callbacks_pointer->interface_state)
416 callbacks_pointer->interface_state(interface);
419 static void callback_interface_removed(GSupplicantInterface *interface)
421 if (!callbacks_pointer)
424 if (!callbacks_pointer->interface_removed)
427 callbacks_pointer->interface_removed(interface);
430 #if !defined TIZEN_EXT
431 static void callback_p2p_support(GSupplicantInterface *interface)
435 if (!interface->p2p_support)
438 if (callbacks_pointer && callbacks_pointer->p2p_support)
439 callbacks_pointer->p2p_support(interface);
443 static void callback_scan_started(GSupplicantInterface *interface)
445 if (!callbacks_pointer)
448 if (!callbacks_pointer->scan_started)
451 callbacks_pointer->scan_started(interface);
454 static void callback_scan_finished(GSupplicantInterface *interface)
456 if (!callbacks_pointer)
459 if (!callbacks_pointer->scan_finished)
462 callbacks_pointer->scan_finished(interface);
465 static void callback_network_added(GSupplicantNetwork *network)
467 if (!callbacks_pointer)
470 if (!callbacks_pointer->network_added)
473 callbacks_pointer->network_added(network);
476 static void callback_network_removed(GSupplicantNetwork *network)
478 if (!callbacks_pointer)
481 if (!callbacks_pointer->network_removed)
484 callbacks_pointer->network_removed(network);
487 #if defined TIZEN_EXT
488 static void callback_network_merged(GSupplicantNetwork *network)
490 if (!callbacks_pointer)
493 if (!callbacks_pointer->network_merged)
496 callbacks_pointer->network_merged(network);
500 static void callback_network_changed(GSupplicantNetwork *network,
501 const char *property)
503 if (!callbacks_pointer)
506 if (!callbacks_pointer->network_changed)
509 callbacks_pointer->network_changed(network, property);
512 static void callback_peer_found(GSupplicantPeer *peer)
514 if (!callbacks_pointer)
517 if (!callbacks_pointer->peer_found)
520 callbacks_pointer->peer_found(peer);
523 static void callback_peer_lost(GSupplicantPeer *peer)
525 if (!callbacks_pointer)
528 if (!callbacks_pointer->peer_lost)
531 callbacks_pointer->peer_lost(peer);
534 static void callback_peer_changed(GSupplicantPeer *peer,
535 GSupplicantPeerState state)
537 if (!callbacks_pointer)
540 if (!callbacks_pointer->peer_changed)
543 callbacks_pointer->peer_changed(peer, state);
546 static void callback_peer_request(GSupplicantPeer *peer)
548 if (!callbacks_pointer)
551 if (!callbacks_pointer->peer_request)
554 peer->connection_requested = true;
556 callbacks_pointer->peer_request(peer);
559 static void remove_group(gpointer data)
561 GSupplicantGroup *group = data;
564 g_slist_free_full(group->members, g_free);
570 static void remove_interface(gpointer data)
572 GSupplicantInterface *interface = data;
574 g_hash_table_destroy(interface->bss_mapping);
575 g_hash_table_destroy(interface->net_mapping);
576 g_hash_table_destroy(interface->network_table);
577 g_hash_table_destroy(interface->peer_table);
578 g_hash_table_destroy(interface->group_table);
580 if (interface->scan_callback) {
581 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
582 interface, interface->scan_callback,
583 interface->scanning);
585 interface->scan_callback(-EIO, interface, interface->scan_data);
586 interface->scan_callback = NULL;
587 interface->scan_data = NULL;
589 if (interface->scanning) {
590 interface->scanning = FALSE;
591 callback_scan_finished(interface);
595 callback_interface_removed(interface);
597 g_free(interface->wps_cred.key);
598 g_free(interface->path);
599 g_free(interface->network_path);
600 #if defined TIZEN_EXT
601 interface->network_path = NULL;
603 g_free(interface->ifname);
604 g_free(interface->driver);
605 g_free(interface->bridge);
609 static void remove_network(gpointer data)
611 GSupplicantNetwork *network = data;
613 g_hash_table_destroy(network->bss_table);
615 callback_network_removed(network);
617 g_hash_table_destroy(network->config_table);
619 g_free(network->path);
620 g_free(network->group);
621 g_free(network->name);
622 #if defined TIZEN_EXT
623 g_free(network->eap);
624 g_free(network->identity);
625 g_free(network->phase2);
630 static void remove_bss(gpointer data)
632 struct g_supplicant_bss *bss = data;
638 static void remove_peer(gpointer data)
640 GSupplicantPeer *peer = data;
642 callback_peer_lost(peer);
645 g_slist_free_full(peer->groups, g_free);
648 g_hash_table_remove(peer_mapping, peer->path);
650 if (pending_peer_connection)
651 g_hash_table_remove(pending_peer_connection, peer->path);
655 g_free(peer->identifier);
660 static void debug_strvalmap(const char *label, struct strvalmap *map,
665 for (i = 0; map[i].str; i++) {
666 if (val & map[i].val)
667 SUPPLICANT_DBG("%s: %s", label, map[i].str);
671 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
673 GSupplicantInterface *interface = user_data;
674 const char *str = NULL;
677 dbus_message_iter_get_basic(iter, &str);
681 for (i = 0; keymgmt_map[i].str; i++)
682 if (strcmp(str, keymgmt_map[i].str) == 0) {
683 interface->keymgmt_capa |= keymgmt_map[i].val;
688 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
690 GSupplicantInterface *interface = user_data;
691 const char *str = NULL;
694 dbus_message_iter_get_basic(iter, &str);
698 for (i = 0; authalg_capa_map[i].str; i++)
699 if (strcmp(str, authalg_capa_map[i].str) == 0) {
700 interface->authalg_capa |= authalg_capa_map[i].val;
705 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
707 GSupplicantInterface *interface = user_data;
708 const char *str = NULL;
711 dbus_message_iter_get_basic(iter, &str);
715 for (i = 0; proto_capa_map[i].str; i++)
716 if (strcmp(str, proto_capa_map[i].str) == 0) {
717 interface->proto_capa |= proto_capa_map[i].val;
722 static void interface_capability_pairwise(DBusMessageIter *iter,
725 GSupplicantInterface *interface = user_data;
726 const char *str = NULL;
729 dbus_message_iter_get_basic(iter, &str);
733 for (i = 0; pairwise_map[i].str; i++)
734 if (strcmp(str, pairwise_map[i].str) == 0) {
735 interface->pairwise_capa |= pairwise_map[i].val;
740 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
742 GSupplicantInterface *interface = user_data;
743 const char *str = NULL;
746 dbus_message_iter_get_basic(iter, &str);
750 for (i = 0; group_map[i].str; i++)
751 if (strcmp(str, group_map[i].str) == 0) {
752 interface->group_capa |= group_map[i].val;
757 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
759 GSupplicantInterface *interface = user_data;
760 const char *str = NULL;
763 dbus_message_iter_get_basic(iter, &str);
767 for (i = 0; scan_capa_map[i].str; i++)
768 if (strcmp(str, scan_capa_map[i].str) == 0) {
769 interface->scan_capa |= scan_capa_map[i].val;
774 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
776 GSupplicantInterface *interface = user_data;
777 const char *str = NULL;
780 dbus_message_iter_get_basic(iter, &str);
784 for (i = 0; mode_capa_map[i].str; i++)
785 if (strcmp(str, mode_capa_map[i].str) == 0) {
786 interface->mode_capa |= mode_capa_map[i].val;
791 static void interface_capability(const char *key, DBusMessageIter *iter,
794 GSupplicantInterface *interface = user_data;
799 if (g_strcmp0(key, "KeyMgmt") == 0)
800 supplicant_dbus_array_foreach(iter,
801 interface_capability_keymgmt, interface);
802 else if (g_strcmp0(key, "AuthAlg") == 0)
803 supplicant_dbus_array_foreach(iter,
804 interface_capability_authalg, interface);
805 else if (g_strcmp0(key, "Protocol") == 0)
806 supplicant_dbus_array_foreach(iter,
807 interface_capability_proto, interface);
808 else if (g_strcmp0(key, "Pairwise") == 0)
809 supplicant_dbus_array_foreach(iter,
810 interface_capability_pairwise, interface);
811 else if (g_strcmp0(key, "Group") == 0)
812 supplicant_dbus_array_foreach(iter,
813 interface_capability_group, interface);
814 else if (g_strcmp0(key, "Scan") == 0)
815 supplicant_dbus_array_foreach(iter,
816 interface_capability_scan, interface);
817 else if (g_strcmp0(key, "Modes") == 0)
818 supplicant_dbus_array_foreach(iter,
819 interface_capability_mode, interface);
820 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
821 dbus_int32_t max_scan_ssid;
823 dbus_message_iter_get_basic(iter, &max_scan_ssid);
824 if (max_scan_ssid < 2)
826 interface->max_scan_ssids = max_scan_ssid;
829 SUPPLICANT_DBG("key %s type %c",
830 key, dbus_message_iter_get_arg_type(iter));
833 static void set_apscan(DBusMessageIter *iter, void *user_data)
835 unsigned int ap_scan = *(unsigned int *)user_data;
837 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
840 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
841 unsigned int ap_scan)
843 return supplicant_dbus_property_set(interface->path,
844 SUPPLICANT_INTERFACE ".Interface",
845 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
846 set_apscan, NULL, &ap_scan, NULL);
849 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
855 interface->data = data;
858 interface->scan_callback = NULL;
861 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
866 return interface->data;
869 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
874 return interface->ifname;
877 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
882 return interface->driver;
885 GSupplicantState g_supplicant_interface_get_state(
886 GSupplicantInterface *interface)
889 return G_SUPPLICANT_STATE_UNKNOWN;
891 return interface->state;
894 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
899 return (const char *)interface->wps_cred.key;
902 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
903 unsigned int *ssid_len)
908 if (!interface || interface->wps_cred.ssid_len == 0) {
913 *ssid_len = interface->wps_cred.ssid_len;
914 return interface->wps_cred.ssid;
917 GSupplicantWpsState g_supplicant_interface_get_wps_state(
918 GSupplicantInterface *interface)
921 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
923 return interface->wps_state;
926 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
931 return interface->mode_capa;
934 unsigned int g_supplicant_interface_get_max_scan_ssids(
935 GSupplicantInterface *interface)
940 if (interface->max_scan_ssids == 0)
941 return WPAS_MAX_SCAN_SSIDS;
943 return interface->max_scan_ssids;
946 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
948 dbus_bool_t enable = *(dbus_bool_t *)user_data;
950 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
953 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
959 if (!interface->network_path)
963 return supplicant_dbus_property_set(interface->network_path,
964 SUPPLICANT_INTERFACE ".Network",
965 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
966 set_network_enabled, NULL, &enable, NULL);
969 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
974 return interface->ready;
977 GSupplicantInterface *g_supplicant_network_get_interface(
978 GSupplicantNetwork *network)
983 return network->interface;
986 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
988 if (!network || !network->name)
991 return network->name;
994 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
996 if (!network || !network->group)
999 return network->group;
1002 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1004 if (!network || !network->path)
1007 return network->path;
1010 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1013 return G_SUPPLICANT_MODE_UNKNOWN;
1015 return mode2string(network->mode);
1018 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1021 return G_SUPPLICANT_SECURITY_UNKNOWN;
1023 return security2string(network->security);
1026 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1027 unsigned int *ssid_len)
1034 *ssid_len = network->ssid_len;
1035 return network->ssid;
1038 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1043 return network->signal;
1046 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1051 return network->frequency;
1054 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1059 return network->wps;
1062 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1067 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1073 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1078 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1084 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1089 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1095 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1100 return peer->interface;
1103 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1111 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1116 return peer->identifier;
1119 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1124 return peer->device_address;
1127 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1132 return peer->iface_address;
1135 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1143 #if defined TIZEN_EXT
1144 unsigned int g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1149 return network->isHS20AP;
1152 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1154 if (!network || !network->eap)
1157 return network->eap;
1160 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1162 if (!network || !network->identity)
1165 return network->identity;
1168 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1170 if (!network || !network->phase2)
1173 return network->phase2;
1176 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1178 if (network == NULL)
1181 return network->keymgmt;
1185 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1188 if (!peer || !length)
1191 *length = peer->widi_ies_length;
1192 return peer->widi_ies;
1195 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1200 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1206 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1211 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1217 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1219 if (!peer || !peer->groups)
1225 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1230 return (GSupplicantInterface *) peer->current_group_iface;
1233 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1235 GSupplicantGroup *group;
1241 for (list = peer->groups; list; list = list->next) {
1242 const char *path = list->data;
1244 group = g_hash_table_lookup(group_mapping, path);
1248 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1249 group->orig_interface != peer->interface)
1252 if (group->interface == peer->current_group_iface)
1259 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1264 return peer->connection_requested;
1267 #if defined TIZEN_EXT
1269 * Description: Network client requires additional wifi specific info
1271 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1273 if (network == NULL || network->best_bss == NULL)
1276 return (const unsigned char *)network->best_bss->bssid;
1279 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1281 if (network == NULL || network->best_bss == NULL)
1284 return network->best_bss->maxrate;
1287 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1289 if (network == NULL || network->best_bss == NULL)
1292 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1293 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1294 unsigned int pairwise;
1296 pairwise = network->best_bss->rsn_pairwise |
1297 network->best_bss->wpa_pairwise;
1299 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1300 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1302 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1304 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1307 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1309 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1315 bool g_supplicant_network_get_rsn_selected(GSupplicantNetwork *network)
1317 if (network == NULL || network->best_bss == NULL)
1320 if (network->best_bss->rsn_selected)
1328 static void merge_network(GSupplicantNetwork *network)
1331 const char *ssid, *mode, *key_mgmt;
1332 #if defined TIZEN_EXT
1333 GSupplicantInterface *interface;
1334 const char *isHS20AP;
1335 const char *eap, *identity, *phase2;
1337 unsigned int i, ssid_len;
1340 ssid = g_hash_table_lookup(network->config_table, "ssid");
1341 mode = g_hash_table_lookup(network->config_table, "mode");
1342 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
1343 #if defined TIZEN_EXT
1344 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
1345 eap = g_hash_table_lookup(network->config_table, "eap");
1346 identity = g_hash_table_lookup(network->config_table, "identity");
1347 phase2 = g_hash_table_lookup(network->config_table, "phase2");
1348 interface = network->interface;
1351 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
1354 ssid_len = strlen(ssid);
1358 str = g_string_sized_new((ssid_len * 2) + 24);
1362 for (i = 0; i < ssid_len; i++)
1363 #if defined TIZEN_EXT
1367 g_string_append_printf(str, "%02x", ssid[i]);
1368 #if defined TIZEN_EXT
1372 if (g_strcmp0(mode, "0") == 0)
1373 g_string_append_printf(str, "_managed");
1374 else if (g_strcmp0(mode, "1") == 0)
1375 g_string_append_printf(str, "_adhoc");
1377 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
1378 g_string_append_printf(str, "_psk");
1379 #if defined TIZEN_EXT
1380 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
1381 g_string_append_printf(str, "_ieee8021x");
1383 g_string_append_printf(str, "_none");
1386 group = g_string_free(str, FALSE);
1388 SUPPLICANT_DBG("%s", group);
1390 #if defined TIZEN_EXT
1391 if (g_strcmp0(isHS20AP, "1") == 0) {
1392 network->isHS20AP = 1;
1394 g_free(network->eap);
1395 network->eap = g_strdup(eap);
1397 if (network->identity)
1398 g_free(network->identity);
1399 network->identity = g_strdup(identity);
1401 if (network->phase2)
1402 g_free(network->phase2);
1403 network->phase2 = g_strdup(phase2);
1405 network->isHS20AP = 0;
1408 interface->network_path = g_strdup(network->path);
1410 network->group = g_strdup(group);
1411 callback_network_merged(network);
1416 g_hash_table_destroy(network->config_table);
1418 g_free(network->path);
1422 static void network_property(const char *key, DBusMessageIter *iter,
1425 GSupplicantNetwork *network = user_data;
1427 if (!network->interface)
1431 merge_network(network);
1435 if (g_strcmp0(key, "Enabled") == 0) {
1436 dbus_bool_t enabled = FALSE;
1438 dbus_message_iter_get_basic(iter, &enabled);
1439 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
1440 const char *str = NULL;
1442 dbus_message_iter_get_basic(iter, &str);
1444 g_hash_table_replace(network->config_table,
1445 g_strdup(key), g_strdup(str));
1448 SUPPLICANT_DBG("key %s type %c",
1449 key, dbus_message_iter_get_arg_type(iter));
1452 static void interface_network_added(DBusMessageIter *iter, void *user_data)
1454 GSupplicantInterface *interface = user_data;
1455 GSupplicantNetwork *network;
1456 const char *path = NULL;
1460 dbus_message_iter_get_basic(iter, &path);
1464 if (g_strcmp0(path, "/") == 0)
1467 network = g_hash_table_lookup(interface->net_mapping, path);
1471 network = g_try_new0(GSupplicantNetwork, 1);
1475 network->interface = interface;
1476 network->path = g_strdup(path);
1478 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1481 dbus_message_iter_next(iter);
1482 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
1483 supplicant_dbus_property_foreach(iter, network_property,
1485 network_property(NULL, NULL, network);
1489 supplicant_dbus_property_get_all(path,
1490 SUPPLICANT_INTERFACE ".Network",
1491 network_property, network, NULL);
1494 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
1496 GSupplicantInterface *interface = user_data;
1497 GSupplicantNetwork *network;
1498 const char *path = NULL;
1500 dbus_message_iter_get_basic(iter, &path);
1504 network = g_hash_table_lookup(interface->net_mapping, path);
1508 g_hash_table_remove(interface->net_mapping, path);
1511 static char *create_name(unsigned char *ssid, int ssid_len)
1514 const gchar *remainder, *invalid;
1515 int valid_bytes, remaining_bytes;
1517 if (ssid_len < 1 || ssid[0] == '\0')
1518 return g_strdup("");
1521 remainder = (const gchar *)ssid;
1522 remaining_bytes = ssid_len;
1524 while (remaining_bytes != 0) {
1525 if (g_utf8_validate(remainder, remaining_bytes,
1530 valid_bytes = invalid - remainder;
1533 string = g_string_sized_new(remaining_bytes);
1535 g_string_append_len(string, remainder, valid_bytes);
1537 /* append U+FFFD REPLACEMENT CHARACTER */
1538 g_string_append(string, "\357\277\275");
1540 remaining_bytes -= valid_bytes + 1;
1541 remainder = invalid + 1;
1545 return g_strndup((const gchar *)ssid, ssid_len + 1);
1547 g_string_append(string, remainder);
1549 return g_string_free(string, FALSE);
1552 static char *create_group(struct g_supplicant_bss *bss)
1556 const char *mode, *security;
1558 str = g_string_sized_new((bss->ssid_len * 2) + 24);
1562 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
1563 for (i = 0; i < bss->ssid_len; i++)
1564 g_string_append_printf(str, "%02x", bss->ssid[i]);
1566 g_string_append_printf(str, "hidden");
1568 mode = mode2string(bss->mode);
1570 g_string_append_printf(str, "_%s", mode);
1572 security = security2string(bss->security);
1574 g_string_append_printf(str, "_%s", security);
1576 return g_string_free(str, FALSE);
1579 static void add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
1581 GSupplicantInterface *interface = bss->interface;
1582 GSupplicantNetwork *network;
1585 group = create_group(bss);
1586 SUPPLICANT_DBG("New group created: %s", group);
1591 network = g_hash_table_lookup(interface->network_table, group);
1594 SUPPLICANT_DBG("Network %s already exist", network->name);
1599 network = g_try_new0(GSupplicantNetwork, 1);
1605 network->interface = interface;
1607 network->path = g_strdup(bss->path);
1608 network->group = group;
1609 network->name = create_name(bss->ssid, bss->ssid_len);
1610 network->mode = bss->mode;
1611 network->security = bss->security;
1612 network->ssid_len = bss->ssid_len;
1613 memcpy(network->ssid, bss->ssid, bss->ssid_len);
1614 network->signal = bss->signal;
1615 network->frequency = bss->frequency;
1616 network->best_bss = bss;
1618 #if defined TIZEN_EXT
1619 network->keymgmt = bss->keymgmt;
1622 SUPPLICANT_DBG("New network %s created", network->name);
1624 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1627 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1630 g_hash_table_replace(interface->network_table,
1631 network->group, network);
1633 callback_network_added(network);
1636 /* We update network's WPS properties if only bss provides WPS. */
1637 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
1638 network->wps = TRUE;
1639 network->wps_capabilities |= bss->wps_capabilities;
1642 if (bss->signal > network->signal) {
1643 network->signal = bss->signal;
1644 network->best_bss = bss;
1645 callback_network_changed(network, "Signal");
1648 g_hash_table_replace(interface->bss_mapping, bss->path, network);
1649 g_hash_table_replace(network->bss_table, bss->path, bss);
1651 g_hash_table_replace(bss_mapping, bss->path, interface);
1654 static void bss_rates(DBusMessageIter *iter, void *user_data)
1656 struct g_supplicant_bss *bss = user_data;
1657 dbus_uint32_t rate = 0;
1659 dbus_message_iter_get_basic(iter, &rate);
1663 if (rate > bss->maxrate)
1664 bss->maxrate = rate;
1667 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
1669 unsigned int *keymgmt = user_data;
1670 const char *str = NULL;
1673 dbus_message_iter_get_basic(iter, &str);
1677 for (i = 0; keymgmt_map[i].str; i++)
1678 if (strcmp(str, keymgmt_map[i].str) == 0) {
1679 SUPPLICANT_DBG("Keymgmt: %s", str);
1680 *keymgmt |= keymgmt_map[i].val;
1685 static void bss_group(DBusMessageIter *iter, void *user_data)
1687 unsigned int *group = user_data;
1688 const char *str = NULL;
1691 dbus_message_iter_get_basic(iter, &str);
1695 for (i = 0; group_map[i].str; i++)
1696 if (strcmp(str, group_map[i].str) == 0) {
1697 SUPPLICANT_DBG("Group: %s", str);
1698 *group |= group_map[i].val;
1703 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
1705 unsigned int *pairwise = user_data;
1706 const char *str = NULL;
1709 dbus_message_iter_get_basic(iter, &str);
1713 for (i = 0; pairwise_map[i].str; i++)
1714 if (strcmp(str, pairwise_map[i].str) == 0) {
1715 SUPPLICANT_DBG("Pairwise: %s", str);
1716 *pairwise |= pairwise_map[i].val;
1721 static void bss_wpa(const char *key, DBusMessageIter *iter,
1724 struct g_supplicant_bss *bss = user_data;
1725 unsigned int value = 0;
1727 SUPPLICANT_DBG("Key: %s", key);
1729 if (g_strcmp0(key, "KeyMgmt") == 0) {
1730 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
1732 if (bss->rsn_selected)
1733 bss->rsn_keymgmt = value;
1735 bss->wpa_keymgmt = value;
1736 } else if (g_strcmp0(key, "Group") == 0) {
1737 supplicant_dbus_array_foreach(iter, bss_group, &value);
1739 if (bss->rsn_selected)
1740 bss->rsn_group = value;
1742 bss->wpa_group = value;
1743 } else if (g_strcmp0(key, "Pairwise") == 0) {
1744 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
1746 if (bss->rsn_selected)
1747 bss->rsn_pairwise = value;
1749 bss->wpa_pairwise = value;
1753 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
1756 unsigned int len = 0;
1758 while (len + 4 < ie_size) {
1759 unsigned int hi = ie[len];
1760 unsigned int lo = ie[len + 1];
1761 unsigned int tmp_type = (hi << 8) + lo;
1762 unsigned int v_len = 0;
1764 /* hi and lo are used to recreate an unsigned int
1765 * based on 2 8bits length unsigned int. */
1769 v_len = (hi << 8) + lo;
1771 if (tmp_type == type) {
1772 unsigned int ret_value = 0;
1773 unsigned char *value = (unsigned char *)&ret_value;
1775 SUPPLICANT_DBG("IE: match type 0x%x", type);
1777 /* Verifying length relevance */
1778 if (v_len > sizeof(unsigned int) ||
1779 len + 4 + v_len > ie_size)
1782 memcpy(value, ie + len + 4, v_len);
1784 SUPPLICANT_DBG("returning 0x%x", ret_value);
1791 SUPPLICANT_DBG("returning 0");
1795 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
1797 struct g_supplicant_bss *bss = user_data;
1798 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
1799 unsigned char *ie, *ie_end;
1800 DBusMessageIter array;
1804 #define WMM_WPA1_WPS_INFO 221
1805 #define WPS_INFO_MIN_LEN 6
1806 #define WPS_VERSION_TLV 0x104A
1807 #define WPS_STATE_TLV 0x1044
1808 #define WPS_METHODS_TLV 0x1012
1809 #define WPS_REGISTRAR_TLV 0x1041
1810 #define WPS_VERSION 0x10
1811 #define WPS_PBC 0x04
1812 #define WPS_PIN 0x00
1813 #define WPS_CONFIGURED 0x02
1815 dbus_message_iter_recurse(iter, &array);
1816 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
1818 if (!ie || ie_len < 2)
1821 bss->wps_capabilities = 0;
1824 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
1827 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
1828 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
1831 SUPPLICANT_DBG("IE: match WPS_OUI");
1833 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
1834 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
1836 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
1838 if (value == WPS_CONFIGURED)
1839 bss->wps_capabilities |=
1840 G_SUPPLICANT_WPS_CONFIGURED;
1843 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
1845 if (GUINT16_FROM_BE(value) == WPS_PBC)
1846 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
1847 if (GUINT16_FROM_BE(value) == WPS_PIN)
1848 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
1850 bss->wps_capabilities |=
1851 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
1853 /* If the AP sends this it means it's advertizing
1854 * as a registrar and the WPS process is launched
1856 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
1857 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
1859 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
1863 static void bss_compute_security(struct g_supplicant_bss *bss)
1866 * Combining RSN and WPA keymgmt
1867 * We combine it since parsing IEs might have set something for WPS. */
1868 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
1870 bss->ieee8021x = FALSE;
1872 #if defined TIZEN_EXT
1873 bss->ft_ieee8021x = FALSE;
1874 bss->ft_psk = FALSE;
1877 #if defined TIZEN_EXT
1879 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
1880 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
1881 bss->ieee8021x = TRUE;
1882 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
1883 bss->ft_ieee8021x = TRUE;
1886 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
1887 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
1888 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
1889 bss->ieee8021x = TRUE;
1892 #if defined TIZEN_EXT
1894 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
1895 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
1897 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
1901 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
1902 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
1903 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
1908 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
1910 bss->security = G_SUPPLICANT_SECURITY_PSK;
1911 #if defined TIZEN_EXT
1912 else if (bss->ft_psk)
1913 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
1914 else if (bss->ft_ieee8021x == TRUE)
1915 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
1917 else if (bss->privacy)
1918 bss->security = G_SUPPLICANT_SECURITY_WEP;
1920 bss->security = G_SUPPLICANT_SECURITY_NONE;
1924 static void bss_property(const char *key, DBusMessageIter *iter,
1927 struct g_supplicant_bss *bss = user_data;
1929 if (!bss->interface)
1932 SUPPLICANT_DBG("key %s", key);
1937 if (g_strcmp0(key, "BSSID") == 0) {
1938 DBusMessageIter array;
1939 unsigned char *addr;
1942 dbus_message_iter_recurse(iter, &array);
1943 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
1946 memcpy(bss->bssid, addr, addr_len);
1947 } else if (g_strcmp0(key, "SSID") == 0) {
1948 DBusMessageIter array;
1949 unsigned char *ssid;
1952 dbus_message_iter_recurse(iter, &array);
1953 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
1955 if (ssid_len > 0 && ssid_len < 33) {
1956 memcpy(bss->ssid, ssid, ssid_len);
1957 bss->ssid_len = ssid_len;
1959 memset(bss->ssid, 0, sizeof(bss->ssid));
1962 } else if (g_strcmp0(key, "Capabilities") == 0) {
1963 dbus_uint16_t capabilities = 0x0000;
1965 dbus_message_iter_get_basic(iter, &capabilities);
1967 if (capabilities & IEEE80211_CAP_ESS)
1968 bss->mode = G_SUPPLICANT_MODE_INFRA;
1969 else if (capabilities & IEEE80211_CAP_IBSS)
1970 bss->mode = G_SUPPLICANT_MODE_IBSS;
1972 if (capabilities & IEEE80211_CAP_PRIVACY)
1973 bss->privacy = TRUE;
1974 } else if (g_strcmp0(key, "Mode") == 0) {
1975 const char *mode = NULL;
1977 dbus_message_iter_get_basic(iter, &mode);
1978 bss->mode = string2mode(mode);
1979 } else if (g_strcmp0(key, "Frequency") == 0) {
1980 dbus_uint16_t frequency = 0;
1982 dbus_message_iter_get_basic(iter, &frequency);
1983 bss->frequency = frequency;
1984 } else if (g_strcmp0(key, "Signal") == 0) {
1985 dbus_int16_t signal = 0;
1987 dbus_message_iter_get_basic(iter, &signal);
1989 bss->signal = signal;
1991 bss->signal = BSS_UNKNOWN_STRENGTH;
1993 } else if (g_strcmp0(key, "Level") == 0) {
1994 dbus_int32_t level = 0;
1996 dbus_message_iter_get_basic(iter, &level);
1997 } else if (g_strcmp0(key, "Rates") == 0) {
1998 supplicant_dbus_array_foreach(iter, bss_rates, bss);
1999 } else if (g_strcmp0(key, "MaxRate") == 0) {
2000 dbus_uint32_t maxrate = 0;
2002 dbus_message_iter_get_basic(iter, &maxrate);
2004 bss->maxrate = maxrate;
2005 } else if (g_strcmp0(key, "Privacy") == 0) {
2006 dbus_bool_t privacy = FALSE;
2008 dbus_message_iter_get_basic(iter, &privacy);
2009 bss->privacy = privacy;
2010 } else if (g_strcmp0(key, "RSN") == 0) {
2011 bss->rsn_selected = TRUE;
2013 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2014 } else if (g_strcmp0(key, "WPA") == 0) {
2015 bss->rsn_selected = FALSE;
2017 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2018 } else if (g_strcmp0(key, "IEs") == 0)
2019 bss_process_ies(iter, bss);
2021 SUPPLICANT_DBG("key %s type %c",
2022 key, dbus_message_iter_get_arg_type(iter));
2025 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
2028 GSupplicantInterface *interface = user_data;
2029 GSupplicantNetwork *network;
2030 struct g_supplicant_bss *bss;
2031 const char *path = NULL;
2035 dbus_message_iter_get_basic(iter, &path);
2039 if (g_strcmp0(path, "/") == 0)
2042 SUPPLICANT_DBG("%s", path);
2044 network = g_hash_table_lookup(interface->bss_mapping, path);
2046 bss = g_hash_table_lookup(network->bss_table, path);
2051 bss = g_try_new0(struct g_supplicant_bss, 1);
2055 bss->interface = interface;
2056 bss->path = g_strdup(path);
2057 bss->signal = BSS_UNKNOWN_STRENGTH;
2062 static void interface_bss_added_with_keys(DBusMessageIter *iter,
2065 struct g_supplicant_bss *bss;
2069 bss = interface_bss_added(iter, user_data);
2073 dbus_message_iter_next(iter);
2075 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
2078 supplicant_dbus_property_foreach(iter, bss_property, bss);
2080 bss_compute_security(bss);
2081 add_or_replace_bss_to_network(bss);
2084 static void interface_bss_added_without_keys(DBusMessageIter *iter,
2087 struct g_supplicant_bss *bss;
2091 bss = interface_bss_added(iter, user_data);
2095 supplicant_dbus_property_get_all(bss->path,
2096 SUPPLICANT_INTERFACE ".BSS",
2097 bss_property, bss, NULL);
2099 bss_compute_security(bss);
2100 add_or_replace_bss_to_network(bss);
2103 static void update_signal(gpointer key, gpointer value,
2106 struct g_supplicant_bss *bss = value;
2107 GSupplicantNetwork *network = user_data;
2109 if (bss->signal > network->signal) {
2110 network->signal = bss->signal;
2111 network->best_bss = bss;
2115 static void update_network_signal(GSupplicantNetwork *network)
2117 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
2120 g_hash_table_foreach(network->bss_table,
2121 update_signal, network);
2123 SUPPLICANT_DBG("New network signal %d", network->signal);
2126 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
2128 GSupplicantInterface *interface = user_data;
2129 GSupplicantNetwork *network;
2130 struct g_supplicant_bss *bss = NULL;
2131 const char *path = NULL;
2133 dbus_message_iter_get_basic(iter, &path);
2137 network = g_hash_table_lookup(interface->bss_mapping, path);
2141 bss = g_hash_table_lookup(network->bss_table, path);
2142 if (network->best_bss == bss) {
2143 network->best_bss = NULL;
2144 network->signal = BSS_UNKNOWN_STRENGTH;
2147 g_hash_table_remove(bss_mapping, path);
2149 g_hash_table_remove(interface->bss_mapping, path);
2150 g_hash_table_remove(network->bss_table, path);
2152 update_network_signal(network);
2154 if (g_hash_table_size(network->bss_table) == 0)
2155 g_hash_table_remove(interface->network_table, network->group);
2158 static void set_config_methods(DBusMessageIter *iter, void *user_data)
2160 const char *config_methods = "push_button";
2162 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
2166 static void interface_property(const char *key, DBusMessageIter *iter,
2169 GSupplicantInterface *interface = user_data;
2174 SUPPLICANT_DBG("%s", key);
2177 debug_strvalmap("KeyMgmt capability", keymgmt_map,
2178 interface->keymgmt_capa);
2179 debug_strvalmap("AuthAlg capability", authalg_capa_map,
2180 interface->authalg_capa);
2181 debug_strvalmap("Protocol capability", proto_capa_map,
2182 interface->proto_capa);
2183 debug_strvalmap("Pairwise capability", pairwise_map,
2184 interface->pairwise_capa);
2185 debug_strvalmap("Group capability", group_map,
2186 interface->group_capa);
2187 debug_strvalmap("Scan capability", scan_capa_map,
2188 interface->scan_capa);
2189 debug_strvalmap("Mode capability", mode_capa_map,
2190 interface->mode_capa);
2193 supplicant_dbus_property_set(interface->path,
2194 SUPPLICANT_INTERFACE ".Interface.WPS",
2195 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
2196 set_config_methods, NULL, NULL, NULL);
2198 if (interface->ready)
2199 callback_interface_added(interface);
2204 if (g_strcmp0(key, "Capabilities") == 0) {
2205 supplicant_dbus_property_foreach(iter, interface_capability,
2207 #if !defined TIZEN_EXT
2208 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
2209 interface->p2p_support = true;
2211 } else if (g_strcmp0(key, "State") == 0) {
2212 const char *str = NULL;
2214 dbus_message_iter_get_basic(iter, &str);
2216 if (string2state(str) != interface->state) {
2217 interface->state = string2state(str);
2218 callback_interface_state(interface);
2220 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
2221 interface->ready = FALSE;
2223 interface->ready = TRUE;
2225 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
2226 } else if (g_strcmp0(key, "Scanning") == 0) {
2227 dbus_bool_t scanning = FALSE;
2229 dbus_message_iter_get_basic(iter, &scanning);
2230 interface->scanning = scanning;
2232 if (interface->ready) {
2233 if (interface->scanning)
2234 callback_scan_started(interface);
2236 callback_scan_finished(interface);
2238 } else if (g_strcmp0(key, "ApScan") == 0) {
2241 dbus_message_iter_get_basic(iter, &apscan);
2242 interface->apscan = apscan;
2243 } else if (g_strcmp0(key, "Ifname") == 0) {
2244 const char *str = NULL;
2246 dbus_message_iter_get_basic(iter, &str);
2248 g_free(interface->ifname);
2249 interface->ifname = g_strdup(str);
2251 } else if (g_strcmp0(key, "Driver") == 0) {
2252 const char *str = NULL;
2254 dbus_message_iter_get_basic(iter, &str);
2256 g_free(interface->driver);
2257 interface->driver = g_strdup(str);
2259 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
2260 const char *str = NULL;
2262 dbus_message_iter_get_basic(iter, &str);
2264 g_free(interface->bridge);
2265 interface->bridge = g_strdup(str);
2267 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
2268 interface_bss_added_without_keys(iter, interface);
2269 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
2270 #if defined TIZEN_EXT
2271 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
2273 interface_network_added(iter, interface);
2274 } else if (g_strcmp0(key, "BSSs") == 0) {
2275 supplicant_dbus_array_foreach(iter,
2276 interface_bss_added_without_keys,
2278 } else if (g_strcmp0(key, "Blobs") == 0) {
2280 } else if (g_strcmp0(key, "Networks") == 0) {
2281 supplicant_dbus_array_foreach(iter, interface_network_added,
2284 SUPPLICANT_DBG("key %s type %c",
2285 key, dbus_message_iter_get_arg_type(iter));
2288 static void scan_network_update(DBusMessageIter *iter, void *user_data)
2290 GSupplicantInterface *interface = user_data;
2291 GSupplicantNetwork *network;
2297 dbus_message_iter_get_basic(iter, &path);
2302 if (g_strcmp0(path, "/") == 0)
2305 /* Update the network details based on scan BSS data */
2306 network = g_hash_table_lookup(interface->bss_mapping, path);
2308 callback_network_added(network);
2311 static void scan_bss_data(const char *key, DBusMessageIter *iter,
2314 GSupplicantInterface *interface = user_data;
2316 /*Fixed : stucking in scanning state when scan failed*/
2317 #if defined TIZEN_EXT
2318 GSupplicantInterfaceCallback scan_callback;
2322 supplicant_dbus_array_foreach(iter, scan_network_update,
2325 #if defined TIZEN_EXT
2326 scan_callback = interface->scan_callback;
2329 if (interface->scan_callback)
2330 interface->scan_callback(0, interface, interface->scan_data);
2332 #if defined TIZEN_EXT
2333 if (interface->scan_callback == scan_callback) {
2335 interface->scan_callback = NULL;
2336 interface->scan_data = NULL;
2337 #if defined TIZEN_EXT
2342 static GSupplicantInterface *interface_alloc(const char *path)
2344 GSupplicantInterface *interface;
2346 interface = g_try_new0(GSupplicantInterface, 1);
2350 interface->path = g_strdup(path);
2352 interface->network_table = g_hash_table_new_full(g_str_hash,
2353 g_str_equal, NULL, remove_network);
2354 interface->peer_table = g_hash_table_new_full(g_str_hash,
2355 g_str_equal, NULL, remove_peer);
2356 interface->group_table = g_hash_table_new_full(g_str_hash,
2357 g_str_equal, NULL, remove_group);
2358 interface->net_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
2360 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
2363 g_hash_table_replace(interface_table, interface->path, interface);
2368 static void interface_added(DBusMessageIter *iter, void *user_data)
2370 GSupplicantInterface *interface;
2371 const char *path = NULL;
2375 dbus_message_iter_get_basic(iter, &path);
2379 if (g_strcmp0(path, "/") == 0)
2382 interface = g_hash_table_lookup(interface_table, path);
2386 interface = interface_alloc(path);
2390 dbus_message_iter_next(iter);
2391 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
2392 supplicant_dbus_property_foreach(iter, interface_property,
2394 interface_property(NULL, NULL, interface);
2398 supplicant_dbus_property_get_all(path,
2399 SUPPLICANT_INTERFACE ".Interface",
2400 interface_property, interface,
2404 static void interface_removed(DBusMessageIter *iter, void *user_data)
2406 const char *path = NULL;
2407 GSupplicantInterface *interface = user_data;
2409 dbus_message_iter_get_basic(iter, &path);
2413 interface = g_hash_table_lookup(interface_table, path);
2414 g_supplicant_interface_cancel(interface);
2416 g_hash_table_remove(interface_table, path);
2419 static void eap_method(DBusMessageIter *iter, void *user_data)
2421 const char *str = NULL;
2424 dbus_message_iter_get_basic(iter, &str);
2428 for (i = 0; eap_method_map[i].str; i++)
2429 if (strcmp(str, eap_method_map[i].str) == 0) {
2430 eap_methods |= eap_method_map[i].val;
2435 static void service_property(const char *key, DBusMessageIter *iter,
2439 callback_system_ready();
2443 if (g_strcmp0(key, "DebugLevel") == 0) {
2444 const char *str = NULL;
2447 dbus_message_iter_get_basic(iter, &str);
2448 for (i = 0; debug_strings[i]; i++)
2449 if (g_strcmp0(debug_strings[i], str) == 0) {
2453 SUPPLICANT_DBG("Debug level %d", debug_level);
2454 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
2455 dbus_message_iter_get_basic(iter, &debug_timestamp);
2456 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
2457 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
2458 dbus_message_iter_get_basic(iter, &debug_showkeys);
2459 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
2460 } else if (g_strcmp0(key, "Interfaces") == 0) {
2461 supplicant_dbus_array_foreach(iter, interface_added, NULL);
2462 } else if (g_strcmp0(key, "EapMethods") == 0) {
2463 supplicant_dbus_array_foreach(iter, eap_method, NULL);
2464 debug_strvalmap("EAP method", eap_method_map, eap_methods);
2465 } else if (g_strcmp0(key, "Country") == 0) {
2466 const char *country = NULL;
2468 dbus_message_iter_get_basic(iter, &country);
2469 SUPPLICANT_DBG("Country %s", country);
2471 SUPPLICANT_DBG("key %s type %c",
2472 key, dbus_message_iter_get_arg_type(iter));
2475 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
2477 const char *name = NULL, *old = NULL, *new = NULL;
2481 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
2484 dbus_message_iter_get_basic(iter, &name);
2488 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
2491 dbus_message_iter_next(iter);
2492 dbus_message_iter_get_basic(iter, &old);
2493 dbus_message_iter_next(iter);
2494 dbus_message_iter_get_basic(iter, &new);
2499 if (strlen(old) > 0 && strlen(new) == 0) {
2500 system_available = FALSE;
2501 g_hash_table_remove_all(bss_mapping);
2502 g_hash_table_remove_all(peer_mapping);
2503 g_hash_table_remove_all(group_mapping);
2504 g_hash_table_remove_all(interface_table);
2505 callback_system_killed();
2508 if (strlen(new) > 0 && strlen(old) == 0) {
2509 system_available = TRUE;
2510 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
2511 SUPPLICANT_INTERFACE,
2512 service_property, NULL, NULL);
2516 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
2520 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
2523 supplicant_dbus_property_foreach(iter, service_property, NULL);
2526 static void signal_interface_added(const char *path, DBusMessageIter *iter)
2528 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
2530 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
2531 interface_added(iter, NULL);
2534 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
2538 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
2539 interface_removed(iter, NULL);
2542 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
2544 GSupplicantInterface *interface;
2548 interface = g_hash_table_lookup(interface_table, path);
2552 supplicant_dbus_property_foreach(iter, interface_property, interface);
2555 static void signal_scan_done(const char *path, DBusMessageIter *iter)
2557 GSupplicantInterface *interface;
2558 dbus_bool_t success = FALSE;
2562 interface = g_hash_table_lookup(interface_table, path);
2566 dbus_message_iter_get_basic(iter, &success);
2568 if (interface->scanning) {
2569 callback_scan_finished(interface);
2570 interface->scanning = FALSE;
2574 * If scan is unsuccessful return -EIO else get the scanned BSSs
2575 * and update the network details accordingly
2578 if (interface->scan_callback)
2579 interface->scan_callback(-EIO, interface,
2580 interface->scan_data);
2582 interface->scan_callback = NULL;
2583 interface->scan_data = NULL;
2588 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
2589 "BSSs", scan_bss_data, interface, interface);
2592 static void signal_bss_added(const char *path, DBusMessageIter *iter)
2594 GSupplicantInterface *interface;
2598 interface = g_hash_table_lookup(interface_table, path);
2602 interface_bss_added_with_keys(iter, interface);
2605 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
2607 GSupplicantInterface *interface;
2611 interface = g_hash_table_lookup(interface_table, path);
2615 interface_bss_removed(iter, interface);
2618 static void signal_network_added(const char *path, DBusMessageIter *iter)
2620 GSupplicantInterface *interface;
2624 interface = g_hash_table_lookup(interface_table, path);
2628 interface_network_added(iter, interface);
2631 static void signal_network_removed(const char *path, DBusMessageIter *iter)
2633 GSupplicantInterface *interface;
2637 interface = g_hash_table_lookup(interface_table, path);
2641 interface_network_removed(iter, interface);
2644 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
2646 GSupplicantInterface *interface;
2647 GSupplicantNetwork *network;
2648 GSupplicantSecurity old_security;
2649 struct g_supplicant_bss *bss;
2653 interface = g_hash_table_lookup(bss_mapping, path);
2657 network = g_hash_table_lookup(interface->bss_mapping, path);
2661 bss = g_hash_table_lookup(network->bss_table, path);
2665 supplicant_dbus_property_foreach(iter, bss_property, bss);
2667 old_security = network->security;
2668 bss_compute_security(bss);
2670 if (old_security != bss->security) {
2671 struct g_supplicant_bss *new_bss;
2673 SUPPLICANT_DBG("New network security for %s", bss->ssid);
2675 /* Security change policy:
2676 * - we first copy the current bss into a new one with
2677 * its own pointer (path)
2678 * - we remove the current bss related network which will
2679 * tell the plugin about such removal. This is done due
2680 * to the fact that a security change means a group change
2681 * so a complete network change.
2682 * (current bss becomes invalid as well)
2683 * - we add the new bss: it adds new network and tell the
2684 * plugin about it. */
2686 new_bss = g_try_new0(struct g_supplicant_bss, 1);
2690 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
2691 new_bss->path = g_strdup(bss->path);
2693 g_hash_table_remove(interface->network_table, network->group);
2695 add_or_replace_bss_to_network(new_bss);
2700 #if defined TIZEN_EXT
2701 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2702 network->wps = TRUE;
2703 network->wps_capabilities |= bss->wps_capabilities;
2705 network->wps = FALSE;
2708 if (bss->signal == network->signal)
2713 callback_network_changed(network, "");
2719 * If the new signal is lower than the SSID signal, we need
2720 * to check for the new maximum.
2722 if (bss->signal < network->signal) {
2723 if (bss != network->best_bss)
2728 callback_network_changed(network, "");
2732 network->signal = bss->signal;
2733 update_network_signal(network);
2735 network->signal = bss->signal;
2736 network->best_bss = bss;
2739 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
2742 callback_network_changed(network, "Signal");
2745 static void wps_credentials(const char *key, DBusMessageIter *iter,
2748 GSupplicantInterface *interface = user_data;
2753 SUPPLICANT_DBG("key %s", key);
2755 if (g_strcmp0(key, "Key") == 0) {
2756 DBusMessageIter array;
2757 unsigned char *key_val;
2760 dbus_message_iter_recurse(iter, &array);
2761 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
2763 g_free(interface->wps_cred.key);
2764 interface->wps_cred.key = g_try_malloc0(
2765 sizeof(char) * key_len + 1);
2767 if (!interface->wps_cred.key)
2770 memcpy(interface->wps_cred.key, key_val,
2771 sizeof(char) * key_len);
2773 SUPPLICANT_DBG("WPS key present");
2774 } else if (g_strcmp0(key, "SSID") == 0) {
2775 DBusMessageIter array;
2776 unsigned char *ssid;
2779 dbus_message_iter_recurse(iter, &array);
2780 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
2782 if (ssid_len > 0 && ssid_len < 33) {
2783 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
2784 interface->wps_cred.ssid_len = ssid_len;
2786 memset(interface->wps_cred.ssid, 0, 32);
2787 interface->wps_cred.ssid_len = 0;
2792 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
2794 GSupplicantInterface *interface;
2798 interface = g_hash_table_lookup(interface_table, path);
2802 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
2805 static void wps_event_args(const char *key, DBusMessageIter *iter,
2808 GSupplicantInterface *interface = user_data;
2810 if (!key || !interface)
2813 SUPPLICANT_DBG("Arg Key %s", key);
2816 static void signal_wps_event(const char *path, DBusMessageIter *iter)
2818 GSupplicantInterface *interface;
2819 const char *name = NULL;
2823 interface = g_hash_table_lookup(interface_table, path);
2827 dbus_message_iter_get_basic(iter, &name);
2829 SUPPLICANT_DBG("Name: %s", name);
2831 if (g_strcmp0(name, "success") == 0)
2832 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
2833 else if (g_strcmp0(name, "failed") == 0)
2834 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
2836 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
2838 if (!dbus_message_iter_has_next(iter))
2841 dbus_message_iter_next(iter);
2843 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
2846 #if defined TIZEN_EXT
2847 static void signal_power_off(const char *path, DBusMessageIter *iter)
2849 int poweroff_state = 0;
2851 dbus_message_iter_get_basic(iter, &poweroff_state);
2853 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
2855 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
2856 if (poweroff_state != 2 && poweroff_state != 3)
2859 if (callbacks_pointer == NULL)
2862 if (callbacks_pointer->system_power_off == NULL)
2865 callbacks_pointer->system_power_off();
2869 static void signal_station_connected(const char *path, DBusMessageIter *iter)
2871 GSupplicantInterface *interface;
2872 const char *sta_mac = NULL;
2874 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
2876 if (callbacks_pointer->add_station == NULL)
2879 if (g_strcmp0(path, "/") == 0)
2882 interface = g_hash_table_lookup(interface_table, path);
2883 if (interface == NULL)
2886 dbus_message_iter_get_basic(iter, &sta_mac);
2887 if (sta_mac == NULL)
2890 SUPPLICANT_DBG("New station %s connected", sta_mac);
2891 callbacks_pointer->add_station(sta_mac);
2894 static void signal_station_disconnected(const char *path, DBusMessageIter *iter)
2896 GSupplicantInterface *interface;
2897 const char *sta_mac = NULL;
2899 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
2901 if (callbacks_pointer->remove_station == NULL)
2904 if (g_strcmp0(path, "/") == 0)
2907 interface = g_hash_table_lookup(interface_table, path);
2908 if (interface == NULL)
2911 dbus_message_iter_get_basic(iter, &sta_mac);
2912 if (sta_mac == NULL)
2915 SUPPLICANT_DBG("Station %s disconnected", sta_mac);
2916 callbacks_pointer->remove_station(sta_mac);
2919 static void create_peer_identifier(GSupplicantPeer *peer)
2921 const unsigned char test[ETH_ALEN] = {};
2926 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
2927 peer->identifier = g_strdup(peer->name);
2931 peer->identifier = g_malloc0(19);
2932 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
2933 peer->device_address[0],
2934 peer->device_address[1],
2935 peer->device_address[2],
2936 peer->device_address[3],
2937 peer->device_address[4],
2938 peer->device_address[5]);
2941 struct peer_property_data {
2942 GSupplicantPeer *peer;
2944 bool groups_changed;
2945 bool services_changed;
2948 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
2950 struct peer_property_data *data = user_data;
2951 GSupplicantPeer *peer = data->peer;
2952 GSupplicantGroup *group;
2953 const char *str = NULL;
2956 dbus_message_iter_get_basic(iter, &str);
2960 group = g_hash_table_lookup(group_mapping, str);
2964 elem = g_slist_find_custom(data->old_groups, str, g_str_equal);
2966 data->old_groups = g_slist_remove_link(data->old_groups, elem);
2967 peer->groups = g_slist_concat(elem, peer->groups);
2969 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
2970 data->groups_changed = true;
2974 static void peer_property(const char *key, DBusMessageIter *iter,
2977 GSupplicantPeer *pending_peer;
2978 struct peer_property_data *data = user_data;
2979 GSupplicantPeer *peer = data->peer;
2981 SUPPLICANT_DBG("key: %s", key);
2983 if (!peer->interface)
2988 create_peer_identifier(peer);
2989 callback_peer_found(peer);
2990 pending_peer = g_hash_table_lookup(
2991 pending_peer_connection, peer->path);
2993 if (pending_peer && pending_peer == peer) {
2994 callback_peer_request(peer);
2995 g_hash_table_remove(pending_peer_connection,
3005 if (g_strcmp0(key, "DeviceAddress") == 0) {
3006 unsigned char *dev_addr;
3007 DBusMessageIter array;
3010 dbus_message_iter_recurse(iter, &array);
3011 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
3013 if (len == ETH_ALEN)
3014 memcpy(peer->device_address, dev_addr, len);
3015 } else if (g_strcmp0(key, "DeviceName") == 0) {
3016 const char *str = NULL;
3018 dbus_message_iter_get_basic(iter, &str);
3020 peer->name = g_strdup(str);
3021 } else if (g_strcmp0(key, "config_method") == 0) {
3022 uint16_t wps_config;
3024 dbus_message_iter_get_basic(iter, &wps_config);
3026 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
3027 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3028 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
3029 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3030 } else if (g_strcmp0(key, "Groups") == 0) {
3031 data->old_groups = peer->groups;
3032 peer->groups = NULL;
3034 supplicant_dbus_array_foreach(iter,
3035 peer_groups_relation, data);
3036 if (g_slist_length(data->old_groups) > 0) {
3037 g_slist_free_full(data->old_groups, g_free);
3038 data->groups_changed = true;
3040 } else if (g_strcmp0(key, "IEs") == 0) {
3041 DBusMessageIter array;
3045 dbus_message_iter_recurse(iter, &array);
3046 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3048 if (!ie || ie_len < 2)
3051 if (peer->widi_ies) {
3052 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
3055 g_free(peer->widi_ies);
3056 peer->widi_ies_length = 0;
3059 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
3061 memcpy(peer->widi_ies, ie, ie_len);
3062 peer->widi_ies_length = ie_len;
3063 data->services_changed = true;
3067 static void signal_peer_found(const char *path, DBusMessageIter *iter)
3069 struct peer_property_data *property_data;
3070 GSupplicantInterface *interface;
3071 const char *obj_path = NULL;
3072 GSupplicantPeer *peer;
3076 interface = g_hash_table_lookup(interface_table, path);
3080 dbus_message_iter_get_basic(iter, &obj_path);
3081 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3084 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3088 peer = g_try_new0(GSupplicantPeer, 1);
3092 peer->interface = interface;
3093 peer->path = g_strdup(obj_path);
3094 g_hash_table_insert(interface->peer_table, peer->path, peer);
3095 g_hash_table_replace(peer_mapping, peer->path, interface);
3097 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3098 property_data->peer = peer;
3100 dbus_message_iter_next(iter);
3101 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3102 supplicant_dbus_property_foreach(iter, peer_property,
3104 peer_property(NULL, NULL, property_data);
3108 supplicant_dbus_property_get_all(obj_path,
3109 SUPPLICANT_INTERFACE ".Peer",
3110 peer_property, property_data, NULL);
3113 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
3115 GSupplicantInterface *interface;
3116 const char *obj_path = NULL;
3117 GSupplicantPeer *peer;
3121 interface = g_hash_table_lookup(interface_table, path);
3125 dbus_message_iter_get_basic(iter, &obj_path);
3126 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3129 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3133 g_hash_table_remove(interface->peer_table, obj_path);
3136 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
3138 struct peer_property_data *property_data;
3139 GSupplicantInterface *interface;
3140 GSupplicantPeer *peer;
3144 interface = g_hash_table_lookup(peer_mapping, path);
3148 peer = g_hash_table_lookup(interface->peer_table, path);
3150 g_hash_table_remove(peer_mapping, path);
3154 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3155 property_data->peer = peer;
3157 supplicant_dbus_property_foreach(iter, peer_property, property_data);
3158 if (property_data->services_changed)
3159 callback_peer_changed(peer,
3160 G_SUPPLICANT_PEER_SERVICES_CHANGED);
3162 if (property_data->groups_changed)
3163 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
3165 dbus_free(property_data);
3167 if (!g_supplicant_peer_is_in_a_group(peer))
3168 peer->connection_requested = false;
3171 struct group_sig_data {
3172 const char *peer_obj_path;
3173 unsigned char iface_address[ETH_ALEN];
3174 const char *interface_obj_path;
3175 const char *group_obj_path;
3179 static void group_sig_property(const char *key, DBusMessageIter *iter,
3182 struct group_sig_data *data = user_data;
3187 if (g_strcmp0(key, "peer_interface_addr") == 0) {
3188 unsigned char *dev_addr;
3189 DBusMessageIter array;
3192 dbus_message_iter_recurse(iter, &array);
3193 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
3195 if (len == ETH_ALEN)
3196 memcpy(data->iface_address, dev_addr, len);
3197 } else if (g_strcmp0(key, "role") == 0) {
3198 const char *str = NULL;
3200 dbus_message_iter_get_basic(iter, &str);
3201 if (g_strcmp0(str, "GO") == 0)
3202 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
3204 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
3205 } else if (g_strcmp0(key, "peer_object") == 0)
3206 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
3207 else if (g_strcmp0(key, "interface_object") == 0)
3208 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
3209 else if (g_strcmp0(key, "group_object") == 0)
3210 dbus_message_iter_get_basic(iter, &data->group_obj_path);
3214 static void signal_group_success(const char *path, DBusMessageIter *iter)
3216 GSupplicantInterface *interface;
3217 struct group_sig_data data = {};
3218 GSupplicantPeer *peer;
3222 interface = g_hash_table_lookup(interface_table, path);
3226 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3227 if (!data.peer_obj_path)
3230 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
3234 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
3235 interface->pending_peer_path = peer->path;
3238 static void signal_group_failure(const char *path, DBusMessageIter *iter)
3240 GSupplicantInterface *interface;
3241 struct group_sig_data data = {};
3242 GSupplicantPeer *peer;
3246 interface = g_hash_table_lookup(interface_table, path);
3250 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3251 if (!data.peer_obj_path)
3254 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
3258 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
3259 peer->connection_requested = false;
3262 static void signal_group_started(const char *path, DBusMessageIter *iter)
3264 GSupplicantInterface *interface, *g_interface;
3265 struct group_sig_data data = {};
3266 GSupplicantGroup *group;
3267 GSupplicantPeer *peer;
3271 interface = g_hash_table_lookup(interface_table, path);
3275 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3276 if (!data.interface_obj_path || !data.group_obj_path)
3279 peer = g_hash_table_lookup(interface->peer_table,
3280 interface->pending_peer_path);
3281 interface->pending_peer_path = NULL;
3285 g_interface = g_hash_table_lookup(interface_table,
3286 data.interface_obj_path);
3290 group = g_hash_table_lookup(interface->group_table,
3291 data.group_obj_path);
3295 group = g_try_new0(GSupplicantGroup, 1);
3299 group->interface = g_interface;
3300 group->orig_interface = interface;
3301 group->path = g_strdup(data.group_obj_path);
3302 group->role = data.role;
3304 g_hash_table_insert(interface->group_table, group->path, group);
3305 g_hash_table_replace(group_mapping, group->path, group);
3307 peer->current_group_iface = g_interface;
3308 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
3311 static void remove_peer_group_interface(GHashTable *group_table,
3314 GSupplicantGroup *group;
3315 GHashTableIter iter;
3316 gpointer value, key;
3321 group = g_hash_table_lookup(group_table, path);
3323 if (!group || !group->orig_interface)
3326 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
3328 while (g_hash_table_iter_next(&iter, &key, &value)) {
3329 GSupplicantPeer *peer = value;
3331 if (peer->current_group_iface == group->interface)
3332 peer->current_group_iface = NULL;
3336 static void signal_group_finished(const char *path, DBusMessageIter *iter)
3338 GSupplicantInterface *interface;
3339 struct group_sig_data data = {};
3343 interface = g_hash_table_lookup(interface_table, path);
3347 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3348 if (!data.interface_obj_path || !data.group_obj_path)
3351 remove_peer_group_interface(interface->group_table, data.group_obj_path);
3353 g_hash_table_remove(group_mapping, data.group_obj_path);
3355 g_hash_table_remove(interface->group_table, data.group_obj_path);
3358 static void signal_group_request(const char *path, DBusMessageIter *iter)
3360 GSupplicantInterface *interface;
3361 GSupplicantPeer *peer;
3362 const char *obj_path;
3366 interface = g_hash_table_lookup(interface_table, path);
3370 dbus_message_iter_get_basic(iter, &obj_path);
3371 if (!obj_path || !g_strcmp0(obj_path, "/"))
3374 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3379 * Peer has been previously found and property set,
3380 * otherwise, defer connection to when peer property
3383 if (peer->identifier)
3384 callback_peer_request(peer);
3386 g_hash_table_replace(pending_peer_connection, peer->path, peer);
3389 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
3391 const char *peer_path = NULL;
3392 GSupplicantInterface *interface;
3393 GSupplicantGroup *group;
3394 GSupplicantPeer *peer;
3398 group = g_hash_table_lookup(group_mapping, path);
3402 dbus_message_iter_get_basic(iter, &peer_path);
3406 interface = g_hash_table_lookup(peer_mapping, peer_path);
3410 peer = g_hash_table_lookup(interface->peer_table, peer_path);
3414 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
3416 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
3419 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
3421 const char *peer_path = NULL;
3422 GSupplicantInterface *interface;
3423 GSupplicantGroup *group;
3424 GSupplicantPeer *peer;
3429 group = g_hash_table_lookup(group_mapping, path);
3433 dbus_message_iter_get_basic(iter, &peer_path);
3437 for (elem = group->members; elem; elem = elem->next) {
3438 if (!g_strcmp0(elem->data, peer_path))
3446 group->members = g_slist_delete_link(group->members, elem);
3448 interface = g_hash_table_lookup(peer_mapping, peer_path);
3452 peer = g_hash_table_lookup(interface->peer_table, peer_path);
3456 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
3457 peer->connection_requested = false;
3461 const char *interface;
3463 void (*function) (const char *path, DBusMessageIter *iter);
3465 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
3467 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
3468 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
3469 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
3470 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
3472 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
3473 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
3474 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
3475 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
3476 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
3477 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
3479 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
3481 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
3482 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
3483 #if defined TIZEN_EXT
3484 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
3487 { SUPPLICANT_INTERFACE".Interface", "StaAuthorized", signal_station_connected },
3488 { SUPPLICANT_INTERFACE".Interface", "StaDeauthorized", signal_station_disconnected },
3490 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
3491 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
3493 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
3495 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
3496 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
3497 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
3498 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
3499 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
3501 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
3502 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
3507 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
3508 DBusMessage *message, void *data)
3510 DBusMessageIter iter;
3514 path = dbus_message_get_path(message);
3516 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3518 if (!dbus_message_iter_init(message, &iter))
3519 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3521 for (i = 0; signal_map[i].interface; i++) {
3522 if (!dbus_message_has_interface(message, signal_map[i].interface))
3525 if (!dbus_message_has_member(message, signal_map[i].member))
3528 signal_map[i].function(path, &iter);
3532 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3535 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
3537 SUPPLICANT_DBG("Cancelling any pending DBus calls");
3538 supplicant_dbus_method_call_cancel_all(interface);
3539 supplicant_dbus_property_call_cancel_all(interface);
3542 struct supplicant_regdom {
3543 GSupplicantCountryCallback callback;
3545 const void *user_data;
3548 static void country_result(const char *error,
3549 DBusMessageIter *iter, void *user_data)
3551 struct supplicant_regdom *regdom = user_data;
3554 SUPPLICANT_DBG("Country setting result");
3560 SUPPLICANT_DBG("Country setting failure %s", error);
3564 if (regdom->callback)
3565 regdom->callback(result, regdom->alpha2,
3566 (void *) regdom->user_data);
3571 static void country_params(DBusMessageIter *iter, void *user_data)
3573 struct supplicant_regdom *regdom = user_data;
3575 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
3579 int g_supplicant_set_country(const char *alpha2,
3580 GSupplicantCountryCallback callback,
3581 const void *user_data)
3583 struct supplicant_regdom *regdom;
3585 SUPPLICANT_DBG("Country setting %s", alpha2);
3587 if (!system_available)
3590 regdom = dbus_malloc0(sizeof(*regdom));
3594 regdom->callback = callback;
3595 regdom->alpha2 = alpha2;
3596 regdom->user_data = user_data;
3598 return supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
3599 "Country", DBUS_TYPE_STRING_AS_STRING,
3600 country_params, country_result,
3604 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
3605 GSupplicantCountryCallback callback,
3609 struct supplicant_regdom *regdom;
3611 regdom = dbus_malloc0(sizeof(*regdom));
3615 regdom->callback = callback;
3616 regdom->alpha2 = alpha2;
3617 regdom->user_data = user_data;
3619 return supplicant_dbus_property_set(interface->path,
3620 SUPPLICANT_INTERFACE ".Interface",
3621 "Country", DBUS_TYPE_STRING_AS_STRING,
3622 country_params, country_result,
3626 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
3631 return interface->p2p_support;
3634 struct supplicant_p2p_dev_config {
3639 static void p2p_device_config_result(const char *error,
3640 DBusMessageIter *iter, void *user_data)
3642 struct supplicant_p2p_dev_config *config = user_data;
3645 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
3648 g_free(config->device_name);
3649 g_free(config->dev_type);
3653 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
3655 int length, pos, end;
3660 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
3667 dev_type[length] = strtol(b, &e, 16);
3668 if (e && *e != '\0')
3677 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
3679 struct supplicant_p2p_dev_config *config = user_data;
3680 DBusMessageIter dict;
3682 supplicant_dbus_dict_open(iter, &dict);
3684 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
3685 DBUS_TYPE_STRING, &config->device_name);
3687 if (config->dev_type) {
3688 unsigned char dev_type[8] = {}, *type;
3691 len = dev_type_str2bin(config->dev_type, dev_type);
3694 supplicant_dbus_dict_append_fixed_array(&dict,
3695 "PrimaryDeviceType",
3696 DBUS_TYPE_BYTE, &type, len);
3700 supplicant_dbus_dict_close(iter, &dict);
3703 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
3704 const char *device_name,
3705 const char *primary_dev_type)
3707 struct supplicant_p2p_dev_config *config;
3710 SUPPLICANT_DBG("P2P Device settings %s/%s",
3711 device_name, primary_dev_type);
3713 config = dbus_malloc0(sizeof(*config));
3717 config->device_name = g_strdup(device_name);
3718 config->dev_type = g_strdup(primary_dev_type);
3720 ret = supplicant_dbus_property_set(interface->path,
3721 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
3723 DBUS_TYPE_ARRAY_AS_STRING
3724 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
3725 DBUS_TYPE_STRING_AS_STRING
3726 DBUS_TYPE_VARIANT_AS_STRING
3727 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
3728 p2p_device_config_params,
3729 p2p_device_config_result, config, NULL);
3731 g_free(config->device_name);
3732 g_free(config->dev_type);
3734 SUPPLICANT_DBG("Unable to set P2P Device configuration");
3740 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
3743 const GSupplicantPeer *peer = value;
3744 const char *identifier = user_data;
3746 if (!g_strcmp0(identifier, peer->identifier))
3752 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
3753 const char *identifier)
3755 GSupplicantPeer *peer;
3757 peer = g_hash_table_find(interface->peer_table,
3758 peer_lookup_by_identifier,
3759 (void *) identifier);
3763 struct interface_data {
3764 GSupplicantInterface *interface;
3765 char *path; /* Interface path cannot be taken from interface (above) as
3766 * it might have been freed already.
3768 GSupplicantInterfaceCallback callback;
3772 struct interface_create_data {
3776 GSupplicantInterface *interface;
3777 GSupplicantInterfaceCallback callback;
3781 struct interface_connect_data {
3782 GSupplicantInterface *interface;
3784 GSupplicantInterfaceCallback callback;
3786 GSupplicantSSID *ssid;
3787 GSupplicantPeerParams *peer;
3792 struct interface_scan_data {
3793 GSupplicantInterface *interface;
3795 GSupplicantInterfaceCallback callback;
3796 GSupplicantScanParams *scan_params;
3800 static void interface_create_data_free(struct interface_create_data *data)
3802 g_free(data->ifname);
3803 g_free(data->driver);
3804 g_free(data->bridge);
3808 static bool interface_exists(GSupplicantInterface *interface,
3811 GSupplicantInterface *tmp;
3813 tmp = g_hash_table_lookup(interface_table, path);
3814 if (tmp && tmp == interface)
3820 static void interface_create_property(const char *key, DBusMessageIter *iter,
3823 struct interface_create_data *data = user_data;
3824 GSupplicantInterface *interface = data->interface;
3827 if (data->callback) {
3828 data->callback(0, data->interface, data->user_data);
3829 #if !defined TIZEN_EXT
3830 callback_p2p_support(interface);
3834 interface_create_data_free(data);
3837 interface_property(key, iter, interface);
3840 static void interface_create_result(const char *error,
3841 DBusMessageIter *iter, void *user_data)
3843 struct interface_create_data *data = user_data;
3844 const char *path = NULL;
3850 g_warning("error %s", error);
3855 dbus_message_iter_get_basic(iter, &path);
3861 if (!system_available) {
3866 data->interface = g_hash_table_lookup(interface_table, path);
3867 if (!data->interface) {
3868 data->interface = interface_alloc(path);
3869 if (!data->interface) {
3875 err = supplicant_dbus_property_get_all(path,
3876 SUPPLICANT_INTERFACE ".Interface",
3877 interface_create_property, data,
3884 data->callback(err, NULL, data->user_data);
3886 interface_create_data_free(data);
3889 static void interface_create_params(DBusMessageIter *iter, void *user_data)
3891 struct interface_create_data *data = user_data;
3892 DBusMessageIter dict;
3896 supplicant_dbus_dict_open(iter, &dict);
3898 supplicant_dbus_dict_append_basic(&dict, "Ifname",
3899 DBUS_TYPE_STRING, &data->ifname);
3902 supplicant_dbus_dict_append_basic(&dict, "Driver",
3903 DBUS_TYPE_STRING, &data->driver);
3906 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
3907 DBUS_TYPE_STRING, &data->bridge);
3909 supplicant_dbus_dict_close(iter, &dict);
3912 static void interface_get_result(const char *error,
3913 DBusMessageIter *iter, void *user_data)
3915 struct interface_create_data *data = user_data;
3916 GSupplicantInterface *interface;
3917 const char *path = NULL;
3923 SUPPLICANT_DBG("Interface not created yet");
3927 dbus_message_iter_get_basic(iter, &path);
3933 interface = g_hash_table_lookup(interface_table, path);
3939 if (data->callback) {
3940 data->callback(0, interface, data->user_data);
3941 #if !defined TIZEN_EXT
3942 callback_p2p_support(interface);
3946 interface_create_data_free(data);
3951 if (!system_available) {
3956 SUPPLICANT_DBG("Creating interface");
3958 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
3959 SUPPLICANT_INTERFACE,
3961 interface_create_params,
3962 interface_create_result, data,
3969 data->callback(err, NULL, data->user_data);
3971 interface_create_data_free(data);
3974 static void interface_get_params(DBusMessageIter *iter, void *user_data)
3976 struct interface_create_data *data = user_data;
3980 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
3983 int g_supplicant_interface_create(const char *ifname, const char *driver,
3985 GSupplicantInterfaceCallback callback,
3988 struct interface_create_data *data;
3991 SUPPLICANT_DBG("ifname %s", ifname);
3996 if (!system_available)
3999 data = dbus_malloc0(sizeof(*data));
4003 data->ifname = g_strdup(ifname);
4004 data->driver = g_strdup(driver);
4005 data->bridge = g_strdup(bridge);
4006 data->callback = callback;
4007 data->user_data = user_data;
4009 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
4010 SUPPLICANT_INTERFACE,
4012 interface_get_params,
4013 interface_get_result, data,
4016 interface_create_data_free(data);
4021 static void interface_remove_result(const char *error,
4022 DBusMessageIter *iter, void *user_data)
4024 struct interface_data *data = user_data;
4032 if (!system_available) {
4038 * The gsupplicant interface is already freed by the InterfaceRemoved
4039 * signal callback. Simply invoke the interface_data callback.
4047 data->callback(err, NULL, data->user_data);
4053 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
4055 struct interface_data *data = user_data;
4057 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
4058 &data->interface->path);
4062 int g_supplicant_interface_remove(GSupplicantInterface *interface,
4063 GSupplicantInterfaceCallback callback,
4066 struct interface_data *data;
4072 if (!system_available)
4075 g_supplicant_interface_cancel(interface);
4077 data = dbus_malloc0(sizeof(*data));
4081 data->interface = interface;
4082 data->path = g_strdup(interface->path);
4083 data->callback = callback;
4084 data->user_data = user_data;
4086 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
4087 SUPPLICANT_INTERFACE,
4089 interface_remove_params,
4090 interface_remove_result, data,
4099 static void interface_scan_result(const char *error,
4100 DBusMessageIter *iter, void *user_data)
4102 struct interface_scan_data *data = user_data;
4106 SUPPLICANT_DBG("error %s", error);
4110 /* A non ready interface cannot send/receive anything */
4111 if (interface_exists(data->interface, data->path)) {
4112 if (!data->interface->ready)
4120 data->callback(err, data->interface, data->user_data);
4122 data->interface->scan_callback = data->callback;
4123 data->interface->scan_data = data->user_data;
4126 if (data->scan_params)
4127 g_supplicant_free_scan_params(data->scan_params);
4132 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
4134 DBusMessageIter data;
4135 unsigned int width = 0; /* Not used by wpa_supplicant atm */
4137 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
4139 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
4140 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
4142 dbus_message_iter_close_container(iter, &data);
4145 static void add_scan_frequencies(DBusMessageIter *iter,
4148 GSupplicantScanParams *scan_data = user_data;
4152 for (i = 0; i < scan_data->num_freqs; i++) {
4153 freq = scan_data->freqs[i];
4157 add_scan_frequency(iter, freq);
4161 static void append_ssid(DBusMessageIter *iter,
4162 const void *ssid, unsigned int len)
4164 DBusMessageIter array;
4166 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
4167 DBUS_TYPE_BYTE_AS_STRING, &array);
4169 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
4171 dbus_message_iter_close_container(iter, &array);
4174 static void append_ssids(DBusMessageIter *iter, void *user_data)
4176 GSupplicantScanParams *scan_data = user_data;
4179 for (list = scan_data->ssids; list; list = list->next) {
4180 struct scan_ssid *scan_ssid = list->data;
4182 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
4186 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
4187 supplicant_dbus_array_function function,
4190 GSupplicantScanParams *scan_params = user_data;
4191 DBusMessageIter entry, value, array;
4192 const char *key = "Channels";
4194 if (scan_params->freqs && scan_params->freqs[0] != 0) {
4195 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
4198 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
4200 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
4201 DBUS_TYPE_ARRAY_AS_STRING
4202 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
4203 DBUS_TYPE_UINT32_AS_STRING
4204 DBUS_TYPE_UINT32_AS_STRING
4205 DBUS_STRUCT_END_CHAR_AS_STRING,
4208 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
4209 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
4210 DBUS_TYPE_UINT32_AS_STRING
4211 DBUS_TYPE_UINT32_AS_STRING
4212 DBUS_STRUCT_END_CHAR_AS_STRING,
4216 function(&array, user_data);
4218 dbus_message_iter_close_container(&value, &array);
4219 dbus_message_iter_close_container(&entry, &value);
4220 dbus_message_iter_close_container(dict, &entry);
4224 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
4226 DBusMessageIter dict;
4227 const char *type = "passive";
4228 struct interface_scan_data *data = user_data;
4230 supplicant_dbus_dict_open(iter, &dict);
4232 if (data && data->scan_params) {
4235 supplicant_dbus_dict_append_basic(&dict, "Type",
4236 DBUS_TYPE_STRING, &type);
4238 supplicant_dbus_dict_append_array(&dict, "SSIDs",
4243 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
4246 supplicant_dbus_dict_append_basic(&dict, "Type",
4247 DBUS_TYPE_STRING, &type);
4249 supplicant_dbus_dict_close(iter, &dict);
4252 static int interface_ready_to_scan(GSupplicantInterface *interface)
4257 if (!system_available)
4260 if (interface->scanning)
4263 switch (interface->state) {
4264 case G_SUPPLICANT_STATE_AUTHENTICATING:
4265 case G_SUPPLICANT_STATE_ASSOCIATING:
4266 case G_SUPPLICANT_STATE_ASSOCIATED:
4267 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
4268 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
4270 case G_SUPPLICANT_STATE_UNKNOWN:
4271 case G_SUPPLICANT_STATE_DISABLED:
4272 case G_SUPPLICANT_STATE_DISCONNECTED:
4273 case G_SUPPLICANT_STATE_INACTIVE:
4274 case G_SUPPLICANT_STATE_SCANNING:
4275 case G_SUPPLICANT_STATE_COMPLETED:
4282 int g_supplicant_interface_scan(GSupplicantInterface *interface,
4283 GSupplicantScanParams *scan_data,
4284 GSupplicantInterfaceCallback callback,
4287 struct interface_scan_data *data;
4290 ret = interface_ready_to_scan(interface);
4294 data = dbus_malloc0(sizeof(*data));
4298 data->interface = interface;
4299 data->path = g_strdup(interface->path);
4300 #if defined TIZEN_EXT
4301 data->interface->scan_callback = data->callback = callback;
4302 data->interface->scan_data = data->user_data = user_data;
4304 data->callback = callback;
4305 data->user_data = user_data;
4307 data->scan_params = scan_data;
4309 interface->scan_callback = callback;
4310 interface->scan_data = user_data;
4312 ret = supplicant_dbus_method_call(interface->path,
4313 SUPPLICANT_INTERFACE ".Interface", "Scan",
4314 interface_scan_params, interface_scan_result, data,
4325 static int parse_supplicant_error(DBusMessageIter *iter)
4327 int err = -ECANCELED;
4333 /* If the given passphrase is malformed wpa_s returns
4334 * "invalid message format" but this error should be interpreted as
4337 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
4338 dbus_message_iter_get_basic(iter, &key);
4339 if (strncmp(key, "psk", 3) == 0 ||
4340 strncmp(key, "wep_key", 7) == 0 ||
4341 strcmp(key, "invalid message format") == 0) {
4345 dbus_message_iter_next(iter);
4351 static void interface_select_network_result(const char *error,
4352 DBusMessageIter *iter, void *user_data)
4354 struct interface_connect_data *data = user_data;
4361 SUPPLICANT_DBG("SelectNetwork error %s", error);
4362 err = parse_supplicant_error(iter);
4368 data->callback(err, data->interface, data->user_data);
4374 static void interface_select_network_params(DBusMessageIter *iter,
4377 struct interface_connect_data *data = user_data;
4378 GSupplicantInterface *interface = data->interface;
4380 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
4381 &interface->network_path);
4384 static void interface_add_network_result(const char *error,
4385 DBusMessageIter *iter, void *user_data)
4387 struct interface_connect_data *data = user_data;
4388 GSupplicantInterface *interface = data->interface;
4395 dbus_message_iter_get_basic(iter, &path);
4399 SUPPLICANT_DBG("PATH: %s", path);
4401 g_free(interface->network_path);
4402 interface->network_path = g_strdup(path);
4404 supplicant_dbus_method_call(data->interface->path,
4405 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
4406 interface_select_network_params,
4407 interface_select_network_result, data,
4413 SUPPLICANT_DBG("AddNetwork error %s", error);
4415 if (interface_exists(data->interface, data->interface->path)) {
4416 err = parse_supplicant_error(iter);
4418 data->callback(err, data->interface, data->user_data);
4420 g_free(interface->network_path);
4421 interface->network_path = NULL;
4429 static void add_network_security_none(DBusMessageIter *dict)
4431 const char *auth_alg = "OPEN";
4433 supplicant_dbus_dict_append_basic(dict, "auth_alg",
4434 DBUS_TYPE_STRING, &auth_alg);
4437 static void add_network_security_wep(DBusMessageIter *dict,
4438 GSupplicantSSID *ssid)
4440 const char *auth_alg = "OPEN SHARED";
4441 dbus_uint32_t key_index = 0;
4443 supplicant_dbus_dict_append_basic(dict, "auth_alg",
4444 DBUS_TYPE_STRING, &auth_alg);
4446 if (ssid->passphrase) {
4447 int size = strlen(ssid->passphrase);
4448 if (size == 10 || size == 26) {
4449 unsigned char *key = g_try_malloc(13);
4453 memset(tmp, 0, sizeof(tmp));
4457 for (i = 0; i < size / 2; i++) {
4458 memcpy(tmp, ssid->passphrase + (i * 2), 2);
4459 key[i] = (unsigned char) strtol(tmp, NULL, 16);
4462 supplicant_dbus_dict_append_fixed_array(dict,
4467 } else if (size == 5 || size == 13) {
4468 unsigned char *key = g_try_malloc(13);
4474 for (i = 0; i < size; i++)
4475 key[i] = (unsigned char) ssid->passphrase[i];
4477 supplicant_dbus_dict_append_fixed_array(dict,
4483 supplicant_dbus_dict_append_basic(dict,
4488 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
4489 DBUS_TYPE_UINT32, &key_index);
4493 static dbus_bool_t is_psk_raw_key(const char *psk)
4497 /* A raw key is always 64 bytes length... */
4498 if (strlen(psk) != 64)
4501 /* ... and its content is in hex representation */
4502 for (i = 0; i < 64; i++)
4503 if (!isxdigit((unsigned char) psk[i]))
4509 static unsigned char hexchar2bin(char c)
4511 if ((c >= '0') && (c <= '9'))
4513 else if ((c >= 'A') && (c <= 'F'))
4514 return c - 'A' + 10;
4515 else if ((c >= 'a') && (c <= 'f'))
4516 return c - 'a' + 10;
4521 static void hexstring2bin(const char *string, unsigned char *data,
4526 for (i = 0; i < data_len; i++)
4527 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
4528 hexchar2bin(string[i * 2 + 1]) << 0);
4531 static void add_network_security_psk(DBusMessageIter *dict,
4532 GSupplicantSSID *ssid)
4534 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
4535 const char *key = "psk";
4537 if (is_psk_raw_key(ssid->passphrase)) {
4538 unsigned char data[32];
4539 unsigned char *datap = data;
4541 /* The above pointer alias is required by D-Bus because
4542 * with D-Bus and GCC, non-heap-allocated arrays cannot
4543 * be passed directly by their base pointer. */
4545 hexstring2bin(ssid->passphrase, datap, sizeof(data));
4547 supplicant_dbus_dict_append_fixed_array(dict,
4548 key, DBUS_TYPE_BYTE,
4549 &datap, sizeof(data));
4551 supplicant_dbus_dict_append_basic(dict,
4552 key, DBUS_TYPE_STRING,
4557 static void add_network_security_tls(DBusMessageIter *dict,
4558 GSupplicantSSID *ssid)
4561 * For TLS, we at least need:
4562 * The client certificate
4563 * The client private key file
4564 * The client private key file password
4566 * The Authority certificate is optional.
4568 if (!ssid->client_cert_path)
4571 if (!ssid->private_key_path)
4574 #if !defined TIZEN_EXT
4575 if (!ssid->private_key_passphrase)
4579 if (ssid->ca_cert_path)
4580 supplicant_dbus_dict_append_basic(dict, "ca_cert",
4581 DBUS_TYPE_STRING, &ssid->ca_cert_path);
4583 supplicant_dbus_dict_append_basic(dict, "private_key",
4585 &ssid->private_key_path);
4586 #if !defined TIZEN_EXT
4587 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
4589 &ssid->private_key_passphrase);
4591 supplicant_dbus_dict_append_basic(dict, "client_cert",
4593 &ssid->client_cert_path);
4596 static void add_network_security_peap(DBusMessageIter *dict,
4597 GSupplicantSSID *ssid)
4602 * For PEAP/TTLS, we at least need
4603 * The authority certificate
4604 * The 2nd phase authentication method
4605 * The 2nd phase passphrase
4607 * The Client certificate is optional although strongly recommended
4608 * When setting it, we need in addition
4609 * The Client private key file
4610 * The Client private key file password
4612 if (!ssid->passphrase)
4615 if (!ssid->phase2_auth)
4618 if (ssid->client_cert_path) {
4619 if (!ssid->private_key_path)
4622 #if !defined TIZEN_EXT
4623 if (!ssid->private_key_passphrase)
4627 supplicant_dbus_dict_append_basic(dict, "client_cert",
4629 &ssid->client_cert_path);
4631 supplicant_dbus_dict_append_basic(dict, "private_key",
4633 &ssid->private_key_path);
4635 #if !defined TIZEN_EXT
4636 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
4638 &ssid->private_key_passphrase);
4643 if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
4644 phase2_auth = g_strdup_printf("autheap=%s",
4645 ssid->phase2_auth + strlen("EAP-"));
4647 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
4649 supplicant_dbus_dict_append_basic(dict, "password",
4653 if (ssid->ca_cert_path)
4654 supplicant_dbus_dict_append_basic(dict, "ca_cert",
4656 &ssid->ca_cert_path);
4658 supplicant_dbus_dict_append_basic(dict, "phase2",
4662 g_free(phase2_auth);
4665 static void add_network_security_eap(DBusMessageIter *dict,
4666 GSupplicantSSID *ssid)
4670 #if defined TIZEN_EXT
4673 if (!ssid->eap || !ssid->identity)
4677 if (g_strcmp0(ssid->eap, "tls") == 0) {
4678 add_network_security_tls(dict, ssid);
4679 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
4680 g_strcmp0(ssid->eap, "ttls") == 0) {
4681 #if defined TIZEN_EXT
4682 if (!ssid->identity)
4685 add_network_security_peap(dict, ssid);
4687 #if defined TIZEN_EXT
4688 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
4689 g_strcmp0(ssid->eap, "aka") == 0) {
4694 eap_value = g_ascii_strup(ssid->eap, -1);
4696 supplicant_dbus_dict_append_basic(dict, "eap",
4699 #if defined TIZEN_EXT
4700 if (ssid->identity != NULL)
4701 supplicant_dbus_dict_append_basic(dict, "identity",
4705 supplicant_dbus_dict_append_basic(dict, "identity",
4713 static void add_network_security_ciphers(DBusMessageIter *dict,
4714 GSupplicantSSID *ssid)
4716 unsigned int p_cipher, g_cipher, i;
4717 char *pairwise, *group;
4718 char *pair_ciphers[4];
4719 char *group_ciphers[5];
4721 p_cipher = ssid->pairwise_cipher;
4722 g_cipher = ssid->group_cipher;
4724 if (p_cipher == 0 && g_cipher == 0)
4729 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
4730 pair_ciphers[i++] = "CCMP";
4732 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
4733 pair_ciphers[i++] = "TKIP";
4735 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
4736 pair_ciphers[i++] = "NONE";
4738 pair_ciphers[i] = NULL;
4742 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
4743 group_ciphers[i++] = "CCMP";
4745 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
4746 group_ciphers[i++] = "TKIP";
4748 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
4749 group_ciphers[i++] = "WEP104";
4751 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
4752 group_ciphers[i++] = "WEP40";
4754 group_ciphers[i] = NULL;
4756 pairwise = g_strjoinv(" ", pair_ciphers);
4757 group = g_strjoinv(" ", group_ciphers);
4759 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
4761 supplicant_dbus_dict_append_basic(dict, "pairwise",
4764 supplicant_dbus_dict_append_basic(dict, "group",
4772 static void add_network_security_proto(DBusMessageIter *dict,
4773 GSupplicantSSID *ssid)
4775 unsigned int protocol, i;
4779 protocol = ssid->protocol;
4786 if (protocol & G_SUPPLICANT_PROTO_RSN)
4787 protos[i++] = "RSN";
4789 if (protocol & G_SUPPLICANT_PROTO_WPA)
4790 protos[i++] = "WPA";
4794 proto = g_strjoinv(" ", protos);
4796 SUPPLICANT_DBG("proto %s", proto);
4798 supplicant_dbus_dict_append_basic(dict, "proto",
4805 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
4809 switch (ssid->security) {
4810 case G_SUPPLICANT_SECURITY_NONE:
4812 add_network_security_none(dict);
4813 add_network_security_ciphers(dict, ssid);
4815 case G_SUPPLICANT_SECURITY_UNKNOWN:
4816 case G_SUPPLICANT_SECURITY_WEP:
4818 add_network_security_wep(dict, ssid);
4819 add_network_security_ciphers(dict, ssid);
4821 case G_SUPPLICANT_SECURITY_PSK:
4822 key_mgmt = "WPA-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_IEEE8021X:
4828 key_mgmt = "WPA-EAP";
4829 add_network_security_eap(dict, ssid);
4830 add_network_security_ciphers(dict, ssid);
4831 add_network_security_proto(dict, ssid);
4833 #if defined TIZEN_EXT
4834 case G_SUPPLICANT_SECURITY_FT_PSK:
4835 key_mgmt = "FT-PSK";
4836 add_network_security_psk(dict, ssid);
4837 add_network_security_ciphers(dict, ssid);
4838 add_network_security_proto(dict, ssid);
4840 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
4841 key_mgmt = "FT-EAP";
4842 add_network_security_eap(dict, ssid);
4843 add_network_security_ciphers(dict, ssid);
4844 add_network_security_proto(dict, ssid);
4849 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
4850 DBUS_TYPE_STRING, &key_mgmt);
4853 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
4857 switch (ssid->mode) {
4858 case G_SUPPLICANT_MODE_UNKNOWN:
4859 case G_SUPPLICANT_MODE_INFRA:
4862 case G_SUPPLICANT_MODE_IBSS:
4865 case G_SUPPLICANT_MODE_MASTER:
4870 supplicant_dbus_dict_append_basic(dict, "mode",
4871 DBUS_TYPE_UINT32, &mode);
4874 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
4876 DBusMessageIter dict;
4877 struct interface_connect_data *data = user_data;
4878 GSupplicantSSID *ssid = data->ssid;
4880 supplicant_dbus_dict_open(iter, &dict);
4882 if (ssid->scan_ssid)
4883 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
4884 DBUS_TYPE_UINT32, &ssid->scan_ssid);
4887 supplicant_dbus_dict_append_basic(&dict, "frequency",
4888 DBUS_TYPE_UINT32, &ssid->freq);
4891 supplicant_dbus_dict_append_basic(&dict, "bgscan",
4892 DBUS_TYPE_STRING, &ssid->bgscan);
4894 add_network_mode(&dict, ssid);
4896 add_network_security(&dict, ssid);
4898 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
4899 DBUS_TYPE_BYTE, &ssid->ssid,
4902 supplicant_dbus_dict_append_basic(&dict, "ignore_broadcast_ssid",
4904 &ssid->ignore_broadcast_ssid);
4906 supplicant_dbus_dict_close(iter, &dict);
4909 static void interface_wps_start_result(const char *error,
4910 DBusMessageIter *iter, void *user_data)
4912 struct interface_connect_data *data = user_data;
4919 SUPPLICANT_DBG("error: %s", error);
4920 err = parse_supplicant_error(iter);
4924 data->callback(err, data->interface, data->user_data);
4931 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
4933 struct interface_connect_data *data = user_data;
4934 GSupplicantSSID *ssid = data->ssid;
4935 const char *role = "enrollee", *type;
4936 DBusMessageIter dict;
4940 supplicant_dbus_dict_open(iter, &dict);
4942 supplicant_dbus_dict_append_basic(&dict, "Role",
4943 DBUS_TYPE_STRING, &role);
4946 if (ssid->pin_wps) {
4948 supplicant_dbus_dict_append_basic(&dict, "Pin",
4949 DBUS_TYPE_STRING, &ssid->pin_wps);
4952 supplicant_dbus_dict_append_basic(&dict, "Type",
4953 DBUS_TYPE_STRING, &type);
4955 #if defined TIZEN_EXT
4957 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
4958 DBUS_TYPE_BYTE, &ssid->bssid, 6);
4961 supplicant_dbus_dict_close(iter, &dict);
4964 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
4966 struct interface_connect_data *data = user_data;
4971 SUPPLICANT_DBG("error: %s", error);
4977 #if defined TIZEN_EXT
4978 GSupplicantSSID *ssid = data->ssid;
4979 if (ssid->pin_wps != NULL) {
4980 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
4981 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
4988 supplicant_dbus_method_call(data->interface->path,
4989 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
4990 interface_add_wps_params,
4991 interface_wps_start_result, data, NULL);
4994 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
4996 dbus_bool_t credentials = TRUE;
5000 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
5004 int g_supplicant_interface_connect(GSupplicantInterface *interface,
5005 GSupplicantSSID *ssid,
5006 GSupplicantInterfaceCallback callback,
5009 struct interface_connect_data *data;
5015 if (!system_available)
5018 /* TODO: Check if we're already connected and switch */
5020 data = dbus_malloc0(sizeof(*data));
5024 data->interface = interface;
5025 data->path = g_strdup(interface->path);
5026 data->callback = callback;
5028 data->user_data = user_data;
5030 if (ssid->use_wps) {
5031 g_free(interface->wps_cred.key);
5032 memset(&interface->wps_cred, 0,
5033 sizeof(struct _GSupplicantWpsCredentials));
5035 ret = supplicant_dbus_property_set(interface->path,
5036 SUPPLICANT_INTERFACE ".Interface.WPS",
5037 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
5038 wps_process_credentials, wps_start, data, interface);
5040 ret = supplicant_dbus_method_call(interface->path,
5041 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
5042 interface_add_network_params,
5043 interface_add_network_result, data,
5052 return -EINPROGRESS;
5055 static void network_remove_result(const char *error,
5056 DBusMessageIter *iter, void *user_data)
5058 struct interface_data *data = user_data;
5065 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
5067 result = -ECONNABORTED;
5073 data->callback(result, data->interface, data->user_data);
5078 static void network_remove_params(DBusMessageIter *iter, void *user_data)
5080 struct interface_data *data = user_data;
5081 const char *path = data->interface->network_path;
5083 SUPPLICANT_DBG("path %s", path);
5085 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
5088 static int network_remove(struct interface_data *data)
5090 GSupplicantInterface *interface = data->interface;
5094 #if defined TIZEN_EXT
5095 GSupplicantInterface *intf = NULL;
5097 * Check if 'interface' is valid
5099 intf = g_hash_table_lookup(interface_table, interface->path);
5104 return supplicant_dbus_method_call(interface->path,
5105 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
5106 network_remove_params, network_remove_result, data,
5110 static void interface_disconnect_result(const char *error,
5111 DBusMessageIter *iter, void *user_data)
5113 struct interface_data *data = user_data;
5120 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
5122 result = -ECONNABORTED;
5125 if (result < 0 && data->callback) {
5126 data->callback(result, data->interface, data->user_data);
5127 data->callback = NULL;
5130 /* If we are disconnecting from previous WPS successful
5131 * association. i.e.: it did not went through AddNetwork,
5132 * and interface->network_path was never set. */
5133 if (!data->interface->network_path) {
5139 if (result != -ECONNABORTED) {
5140 if (network_remove(data) < 0) {
5150 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
5151 GSupplicantInterfaceCallback callback,
5154 struct interface_data *data;
5162 if (!system_available)
5165 data = dbus_malloc0(sizeof(*data));
5169 data->interface = interface;
5170 data->path = g_strdup(interface->path);
5171 data->callback = callback;
5172 data->user_data = user_data;
5174 ret = supplicant_dbus_method_call(interface->path,
5175 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
5176 NULL, interface_disconnect_result, data,
5187 static void interface_p2p_find_result(const char *error,
5188 DBusMessageIter *iter, void *user_data)
5190 struct interface_scan_data *data = user_data;
5193 SUPPLICANT_DBG("error %s", error);
5198 if (interface_exists(data->interface, data->path)) {
5199 if (!data->interface->ready)
5202 data->interface->p2p_finding = true;
5206 data->callback(err, data->interface, data->user_data);
5212 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
5214 DBusMessageIter dict;
5216 supplicant_dbus_dict_open(iter, &dict);
5217 supplicant_dbus_dict_close(iter, &dict);
5220 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
5221 GSupplicantInterfaceCallback callback,
5224 struct interface_scan_data *data;
5227 if (!interface->p2p_support)
5230 ret = interface_ready_to_scan(interface);
5231 if (ret && ret != -EALREADY)
5234 data = dbus_malloc0(sizeof(*data));
5238 data->interface = interface;
5239 data->path = g_strdup(interface->path);
5240 data->callback = callback;
5241 data->user_data = user_data;
5243 ret = supplicant_dbus_method_call(interface->path,
5244 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
5245 interface_p2p_find_params, interface_p2p_find_result,
5255 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
5260 return interface->p2p_finding;
5263 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
5265 if (!interface->p2p_finding)
5270 interface->p2p_finding = false;
5272 return supplicant_dbus_method_call(interface->path,
5273 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
5274 NULL, NULL, NULL, NULL);
5277 static void interface_p2p_connect_result(const char *error,
5278 DBusMessageIter *iter, void *user_data)
5280 struct interface_connect_data *data = user_data;
5286 err = parse_supplicant_error(iter);
5289 data->callback(err, data->interface, data->user_data);
5292 g_free(data->peer->wps_pin);
5293 g_free(data->peer->path);
5298 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
5300 struct interface_connect_data *data = user_data;
5301 const char *wps = "pbc";
5302 DBusMessageIter dict;
5307 supplicant_dbus_dict_open(iter, &dict);
5309 if (data->peer->master)
5312 if (data->peer->wps_pin)
5315 supplicant_dbus_dict_append_basic(&dict, "peer",
5316 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
5317 supplicant_dbus_dict_append_basic(&dict, "wps_method",
5318 DBUS_TYPE_STRING, &wps);
5319 if (data->peer->wps_pin) {
5320 supplicant_dbus_dict_append_basic(&dict, "pin",
5321 DBUS_TYPE_STRING, &data->peer->wps_pin);
5324 supplicant_dbus_dict_append_basic(&dict, "go_intent",
5325 DBUS_TYPE_INT32, &go_intent);
5327 supplicant_dbus_dict_close(iter, &dict);
5330 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
5331 GSupplicantPeerParams *peer_params,
5332 GSupplicantInterfaceCallback callback,
5335 struct interface_connect_data *data;
5340 if (!interface->p2p_support)
5343 data = dbus_malloc0(sizeof(*data));
5344 data->interface = interface;
5345 data->path = g_strdup(interface->path);
5346 data->peer = peer_params;
5347 data->callback = callback;
5348 data->user_data = user_data;
5350 ret = supplicant_dbus_method_call(interface->path,
5351 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
5352 interface_p2p_connect_params, interface_p2p_connect_result,
5360 return -EINPROGRESS;
5363 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
5364 GSupplicantPeerParams *peer_params)
5366 GSupplicantPeer *peer;
5372 if (!interface->p2p_support)
5375 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
5379 for (list = peer->groups; list; list = list->next, count++) {
5380 const char *group_obj_path = list->data;
5381 GSupplicantInterface *g_interface;
5382 GSupplicantGroup *group;
5384 group = g_hash_table_lookup(group_mapping, group_obj_path);
5385 if (!group || !group->interface)
5388 g_interface = group->interface;
5389 supplicant_dbus_method_call(g_interface->path,
5390 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5391 "Disconnect", NULL, NULL, NULL, g_interface);
5394 if (count == 0 && peer->current_group_iface) {
5395 supplicant_dbus_method_call(peer->current_group_iface->path,
5396 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5397 "Disconnect", NULL, NULL, NULL,
5398 peer->current_group_iface->path);
5401 peer->current_group_iface = NULL;
5403 return -EINPROGRESS;
5406 struct p2p_service_data {
5408 GSupplicantInterface *interface;
5409 GSupplicantP2PServiceParams *service;
5410 GSupplicantInterfaceCallback callback;
5414 static void interface_p2p_service_result(const char *error,
5415 DBusMessageIter *iter, void *user_data)
5417 struct p2p_service_data *data = user_data;
5420 SUPPLICANT_DBG("%s result - %s", data->registration ?
5421 "Registration" : "Deletion",
5422 error ? error : "Success");
5427 data->callback(result, data->interface, data->user_data);
5429 g_free(data->service->query);
5430 g_free(data->service->response);
5431 g_free(data->service->service);
5432 g_free(data->service->wfd_ies);
5433 g_free(data->service);
5437 static void interface_p2p_service_params(DBusMessageIter *iter,
5440 struct p2p_service_data *data = user_data;
5441 GSupplicantP2PServiceParams *service;
5442 DBusMessageIter dict;
5447 service = data->service;
5449 supplicant_dbus_dict_open(iter, &dict);
5451 if (service->query && service->response) {
5453 supplicant_dbus_dict_append_basic(&dict, "service_type",
5454 DBUS_TYPE_STRING, &type);
5455 supplicant_dbus_dict_append_fixed_array(&dict, "query",
5456 DBUS_TYPE_BYTE, &service->query,
5457 service->query_length);
5458 supplicant_dbus_dict_append_fixed_array(&dict, "response",
5459 DBUS_TYPE_BYTE, &service->response,
5460 service->response_length);
5461 } else if (service->version && service->service) {
5463 supplicant_dbus_dict_append_basic(&dict, "service_type",
5464 DBUS_TYPE_STRING, &type);
5465 supplicant_dbus_dict_append_basic(&dict, "version",
5466 DBUS_TYPE_INT32, &service->version);
5467 supplicant_dbus_dict_append_basic(&dict, "service",
5468 DBUS_TYPE_STRING, &service->service);
5471 supplicant_dbus_dict_close(iter, &dict);
5474 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
5475 GSupplicantInterfaceCallback callback,
5476 GSupplicantP2PServiceParams *p2p_service_params,
5479 struct p2p_service_data *data;
5484 if (!interface->p2p_support)
5487 data = dbus_malloc0(sizeof(*data));
5488 data->registration = true;
5489 data->interface = interface;
5490 data->service = p2p_service_params;
5491 data->callback = callback;
5492 data->user_data = user_data;
5494 ret = supplicant_dbus_method_call(interface->path,
5495 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
5496 interface_p2p_service_params, interface_p2p_service_result,
5503 return -EINPROGRESS;
5506 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
5507 GSupplicantP2PServiceParams *p2p_service_params)
5509 struct p2p_service_data *data;
5514 if (!interface->p2p_support)
5517 data = dbus_malloc0(sizeof(*data));
5518 data->interface = interface;
5519 data->service = p2p_service_params;
5521 ret = supplicant_dbus_method_call(interface->path,
5522 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
5523 interface_p2p_service_params, interface_p2p_service_result,
5530 return -EINPROGRESS;
5533 struct p2p_listen_data {
5538 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
5540 struct p2p_listen_data *params = user_data;
5541 DBusMessageIter dict;
5543 supplicant_dbus_dict_open(iter, &dict);
5545 supplicant_dbus_dict_append_basic(&dict, "period",
5546 DBUS_TYPE_INT32, ¶ms->period);
5547 supplicant_dbus_dict_append_basic(&dict, "interval",
5548 DBUS_TYPE_INT32, ¶ms->interval);
5549 supplicant_dbus_dict_close(iter, &dict);
5552 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
5553 int period, int interval)
5555 struct p2p_listen_data params;
5559 if (!interface->p2p_support)
5562 params.period = period;
5563 params.interval = interval;
5565 return supplicant_dbus_method_call(interface->path,
5566 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5567 "ExtendedListen", interface_p2p_listen_params,
5568 NULL, ¶ms, NULL);
5571 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
5573 struct p2p_service_data *data = user_data;
5574 GSupplicantP2PServiceParams *service = data->service;
5575 DBusMessageIter array;
5577 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
5579 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
5580 DBUS_TYPE_BYTE_AS_STRING, &array);
5582 if (service->wfd_ies && service->wfd_ies_length > 0) {
5583 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
5584 &service->wfd_ies, service->wfd_ies_length);
5587 dbus_message_iter_close_container(iter, &array);
5590 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
5591 GSupplicantInterfaceCallback callback,
5594 struct p2p_service_data *data;
5599 if (!system_available)
5602 data = dbus_malloc0(sizeof(*data));
5603 data->service = p2p_service_params;
5604 data->callback = callback;
5605 data->user_data = user_data;
5607 if (p2p_service_params->wfd_ies)
5608 data->registration = true;
5610 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
5611 SUPPLICANT_INTERFACE, "WFDIEs",
5612 DBUS_TYPE_ARRAY_AS_STRING
5613 DBUS_TYPE_BYTE_AS_STRING,
5615 interface_p2p_service_result,
5617 if (ret < 0 && ret != -EINPROGRESS) {
5622 return -EINPROGRESS;
5625 #if defined TIZEN_EXT
5626 int g_supplicant_interface_remove_network(GSupplicantInterface *interface)
5628 struct interface_data *data;
5632 if (interface == NULL)
5635 if (system_available == FALSE)
5638 data = dbus_malloc0(sizeof(*data));
5642 data->interface = interface;
5644 return network_remove(data);
5648 static const char *g_supplicant_rule0 = "type=signal,"
5649 "path=" DBUS_PATH_DBUS ","
5650 "sender=" DBUS_SERVICE_DBUS ","
5651 "interface=" DBUS_INTERFACE_DBUS ","
5652 "member=NameOwnerChanged,"
5653 "arg0=" SUPPLICANT_SERVICE;
5654 static const char *g_supplicant_rule1 = "type=signal,"
5655 "interface=" SUPPLICANT_INTERFACE;
5656 static const char *g_supplicant_rule2 = "type=signal,"
5657 "interface=" SUPPLICANT_INTERFACE ".Interface";
5658 static const char *g_supplicant_rule3 = "type=signal,"
5659 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
5660 static const char *g_supplicant_rule4 = "type=signal,"
5661 "interface=" SUPPLICANT_INTERFACE ".BSS";
5662 static const char *g_supplicant_rule5 = "type=signal,"
5663 "interface=" SUPPLICANT_INTERFACE ".Network";
5664 #if !defined TIZEN_EXT
5665 static const char *g_supplicant_rule6 = "type=signal,"
5666 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
5667 static const char *g_supplicant_rule7 = "type=signal,"
5668 "interface=" SUPPLICANT_INTERFACE ".Peer";
5669 static const char *g_supplicant_rule8 = "type=signal,"
5670 "interface=" SUPPLICANT_INTERFACE ".Group";
5673 static void invoke_introspect_method(void)
5675 DBusMessage *message;
5677 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
5679 DBUS_INTERFACE_INTROSPECTABLE,
5685 dbus_message_set_no_reply(message, TRUE);
5686 dbus_connection_send(connection, message, NULL);
5687 dbus_message_unref(message);
5690 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
5692 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
5696 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
5698 dbus_connection_unref(connection);
5703 callbacks_pointer = callbacks;
5706 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
5707 NULL, remove_interface);
5709 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
5711 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
5713 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
5715 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
5718 supplicant_dbus_setup(connection);
5720 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
5721 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
5722 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
5723 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
5724 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
5725 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
5726 #if defined TIZEN_EXT
5727 dbus_bus_add_match(connection,
5728 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
5729 "member=ChangeState", NULL);
5731 #if !defined TIZEN_EXT
5732 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
5733 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
5734 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
5736 dbus_connection_flush(connection);
5738 if (dbus_bus_name_has_owner(connection,
5739 SUPPLICANT_SERVICE, NULL)) {
5740 system_available = TRUE;
5741 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
5742 SUPPLICANT_INTERFACE,
5743 service_property, NULL, NULL);
5745 invoke_introspect_method();
5750 static void unregister_interface_remove_params(DBusMessageIter *iter,
5753 const char *path = user_data;
5755 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
5760 static void unregister_remove_interface(gpointer key, gpointer value,
5763 GSupplicantInterface *interface = value;
5765 supplicant_dbus_method_call(SUPPLICANT_PATH,
5766 SUPPLICANT_INTERFACE,
5768 unregister_interface_remove_params,
5769 NULL, interface->path, NULL);
5772 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
5777 #if !defined TIZEN_EXT
5778 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
5779 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
5780 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
5782 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
5783 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
5784 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
5785 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
5786 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
5787 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
5788 dbus_connection_flush(connection);
5790 dbus_connection_remove_filter(connection,
5791 g_supplicant_filter, NULL);
5795 g_hash_table_destroy(bss_mapping);
5800 g_hash_table_destroy(peer_mapping);
5801 peer_mapping = NULL;
5804 if (group_mapping) {
5805 g_hash_table_destroy(group_mapping);
5806 group_mapping = NULL;
5809 if (interface_table) {
5810 g_hash_table_foreach(interface_table,
5811 unregister_remove_interface, NULL);
5812 g_hash_table_destroy(interface_table);
5813 interface_table = NULL;
5816 if (system_available)
5817 callback_system_killed();
5820 dbus_connection_unref(connection);
5824 callbacks_pointer = NULL;