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
48 #define WLAN_EID_HT_CAP 45
49 #define WLAN_EID_VHT_CAP 191
50 #define WLAN_EID_SUPP_RATES 1
51 #define WLAN_EID_EXT_SUPP_RATES 50
52 #define COUNTRY_CODE_LENGTH 2
53 #define WIFI_BSSID_LEN_MAX 6
56 #define BSS_UNKNOWN_STRENGTH -90
58 static DBusConnection *connection;
60 static const GSupplicantCallbacks *callbacks_pointer;
62 static dbus_bool_t system_available = FALSE;
63 static dbus_bool_t system_ready = FALSE;
65 static dbus_int32_t debug_level;
66 static dbus_bool_t debug_timestamp = FALSE;
67 static dbus_bool_t debug_showkeys = FALSE;
69 static const char *debug_strings[] = {
70 "msgdump", "debug", "info", "warning", "error", NULL
73 static unsigned int eap_methods;
80 static struct strvalmap eap_method_map[] = {
81 { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 },
82 { "TLS", G_SUPPLICANT_EAP_METHOD_TLS },
83 { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 },
84 { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP },
85 { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS },
86 { "GTC", G_SUPPLICANT_EAP_METHOD_GTC },
87 { "OTP", G_SUPPLICANT_EAP_METHOD_OTP },
88 { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP },
89 { "WSC", G_SUPPLICANT_EAP_METHOD_WSC },
93 static struct strvalmap keymgmt_map[] = {
94 { "none", G_SUPPLICANT_KEYMGMT_NONE },
95 { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X },
96 { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE },
97 { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK },
98 { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 },
99 { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK },
100 { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP },
101 { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP },
102 { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 },
103 { "wps", G_SUPPLICANT_KEYMGMT_WPS },
104 #if defined TIZEN_EXT_WIFI_MESH
105 { "sae", G_SUPPLICANT_KEYMGMT_SAE },
110 static struct strvalmap authalg_capa_map[] = {
111 { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
112 { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
113 { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
117 static struct strvalmap proto_capa_map[] = {
118 { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA },
119 { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN },
123 static struct strvalmap group_map[] = {
124 { "wep40", G_SUPPLICANT_GROUP_WEP40 },
125 { "wep104", G_SUPPLICANT_GROUP_WEP104 },
126 { "tkip", G_SUPPLICANT_GROUP_TKIP },
127 { "ccmp", G_SUPPLICANT_GROUP_CCMP },
131 static struct strvalmap pairwise_map[] = {
132 { "none", G_SUPPLICANT_PAIRWISE_NONE },
133 { "tkip", G_SUPPLICANT_PAIRWISE_TKIP },
134 { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP },
138 static struct strvalmap scan_capa_map[] = {
139 { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
140 { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
141 { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID },
145 static struct strvalmap mode_capa_map[] = {
146 { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA },
147 { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS },
148 { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP },
149 { "p2p", G_SUPPLICANT_CAPABILITY_MODE_P2P },
150 #if defined TIZEN_EXT_WIFI_MESH
151 { "mesh", G_SUPPLICANT_CAPABILITY_MODE_MESH },
156 static GHashTable *interface_table;
157 static GHashTable *bss_mapping;
158 static GHashTable *peer_mapping;
159 static GHashTable *group_mapping;
160 static GHashTable *pending_peer_connection;
161 static GHashTable *config_file_table;
163 struct _GSupplicantWpsCredentials {
164 unsigned char ssid[32];
165 unsigned int ssid_len;
169 struct added_network_information {
171 GSupplicantSecurity security;
173 char * private_passphrase;
176 #if defined TIZEN_EXT_WIFI_MESH
177 struct _GSupplicantMeshGroupInfo {
178 unsigned char ssid[32];
179 unsigned int ssid_len;
180 int disconnect_reason;
184 struct _GSupplicantInterface {
187 unsigned int keymgmt_capa;
188 unsigned int authalg_capa;
189 unsigned int proto_capa;
190 unsigned int group_capa;
191 unsigned int pairwise_capa;
192 unsigned int scan_capa;
193 unsigned int mode_capa;
194 unsigned int max_scan_ssids;
197 bool ap_create_in_progress;
199 GSupplicantState state;
200 dbus_bool_t scanning;
201 GSupplicantInterfaceCallback scan_callback;
207 struct _GSupplicantWpsCredentials wps_cred;
208 GSupplicantWpsState wps_state;
209 GHashTable *network_table;
210 GHashTable *peer_table;
211 GHashTable *group_table;
212 GHashTable *bss_mapping;
214 const char *pending_peer_path;
215 GSupplicantNetwork *current_network;
216 struct added_network_information network_info;
217 #if defined TIZEN_EXT
218 dbus_bool_t is_5_0_Ghz_supported;
219 int disconnect_reason;
221 #if defined TIZEN_EXT_WIFI_MESH
223 struct _GSupplicantMeshGroupInfo group_info;
227 struct g_supplicant_bss {
228 GSupplicantInterface *interface;
230 unsigned char bssid[6];
231 unsigned char ssid[32];
232 unsigned int ssid_len;
233 dbus_uint16_t frequency;
234 dbus_uint32_t maxrate;
236 GSupplicantMode mode;
237 GSupplicantSecurity security;
238 dbus_bool_t rsn_selected;
239 unsigned int wpa_keymgmt;
240 unsigned int wpa_pairwise;
241 unsigned int wpa_group;
242 unsigned int rsn_keymgmt;
243 unsigned int rsn_pairwise;
244 unsigned int rsn_group;
245 unsigned int keymgmt;
248 dbus_bool_t ieee8021x;
249 #if defined TIZEN_EXT
251 dbus_bool_t ft_ieee8021x;
254 unsigned char country_code[COUNTRY_CODE_LENGTH];
255 GSupplicantPhy_mode phy_mode;
257 unsigned int wps_capabilities;
258 #if defined TIZEN_EXT_WIFI_MESH
263 struct _GSupplicantNetwork {
264 GSupplicantInterface *interface;
268 unsigned char ssid[32];
269 unsigned int ssid_len;
271 dbus_uint16_t frequency;
272 struct g_supplicant_bss *best_bss;
273 GSupplicantMode mode;
274 GSupplicantSecurity security;
276 unsigned int wps_capabilities;
277 GHashTable *bss_table;
278 GHashTable *config_table;
279 #if defined TIZEN_EXT
284 unsigned int keymgmt;
286 unsigned char country_code[COUNTRY_CODE_LENGTH];
287 GSupplicantPhy_mode phy_mode;
291 struct _GSupplicantPeer {
292 GSupplicantInterface *interface;
294 unsigned char device_address[ETH_ALEN];
295 unsigned char iface_address[ETH_ALEN];
297 unsigned char *widi_ies;
300 unsigned int wps_capabilities;
302 const GSupplicantInterface *current_group_iface;
303 bool connection_requested;
306 struct _GSupplicantGroup {
307 GSupplicantInterface *interface;
308 GSupplicantInterface *orig_interface;
314 struct interface_data {
315 GSupplicantInterface *interface;
316 char *path; /* Interface path cannot be taken from interface (above) as
317 * it might have been freed already.
319 GSupplicantInterfaceCallback callback;
321 bool network_remove_in_progress;
322 GSupplicantSSID *ssid;
325 #if defined TIZEN_EXT
326 struct interface_signalpoll_data {
327 GSupplicantInterface *interface;
329 GSupplicantMaxSpeedCallback callback;
334 struct interface_create_data {
338 #if defined TIZEN_EXT_WIFI_MESH
340 bool is_mesh_interface;
342 GSupplicantInterface *interface;
343 GSupplicantInterfaceCallback callback;
347 struct interface_connect_data {
348 GSupplicantInterface *interface;
350 GSupplicantInterfaceCallback callback;
353 GSupplicantSSID *ssid;
354 GSupplicantPeerParams *peer;
358 struct interface_scan_data {
359 GSupplicantInterface *interface;
361 GSupplicantInterfaceCallback callback;
362 GSupplicantScanParams *scan_params;
366 #if defined TIZEN_EXT
367 struct g_connman_bssids {
368 unsigned char bssid[WIFI_BSSID_LEN_MAX];
374 static int network_remove(struct interface_data *data);
376 #if defined TIZEN_EXT_WIFI_MESH
377 struct _GSupplicantMeshPeer {
378 GSupplicantInterface *interface;
380 int disconnect_reason;
384 static inline void debug(const char *format, ...)
389 if (!callbacks_pointer || !callbacks_pointer->debug)
392 va_start(ap, format);
394 if (vsnprintf(str, sizeof(str), format, ap) > 0)
395 callbacks_pointer->debug(str);
400 #define SUPPLICANT_DBG(fmt, arg...) \
401 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
403 static GSupplicantMode string2mode(const char *mode)
406 return G_SUPPLICANT_MODE_UNKNOWN;
408 if (g_str_equal(mode, "infrastructure"))
409 return G_SUPPLICANT_MODE_INFRA;
410 else if (g_str_equal(mode, "ad-hoc"))
411 return G_SUPPLICANT_MODE_IBSS;
412 #if defined TIZEN_EXT_WIFI_MESH
413 else if (g_str_equal(mode, "mesh"))
414 return G_SUPPLICANT_MODE_MESH;
417 return G_SUPPLICANT_MODE_UNKNOWN;
420 static const char *mode2string(GSupplicantMode mode)
423 case G_SUPPLICANT_MODE_UNKNOWN:
425 case G_SUPPLICANT_MODE_INFRA:
427 case G_SUPPLICANT_MODE_IBSS:
429 case G_SUPPLICANT_MODE_MASTER:
431 #if defined TIZEN_EXT_WIFI_MESH
432 case G_SUPPLICANT_MODE_MESH:
440 static const char *security2string(GSupplicantSecurity security)
443 case G_SUPPLICANT_SECURITY_UNKNOWN:
445 case G_SUPPLICANT_SECURITY_NONE:
447 case G_SUPPLICANT_SECURITY_WEP:
449 case G_SUPPLICANT_SECURITY_PSK:
451 case G_SUPPLICANT_SECURITY_IEEE8021X:
453 #if defined TIZEN_EXT
454 case G_SUPPLICANT_SECURITY_FT_PSK:
456 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
457 return "ft_ieee8021x";
459 #if defined TIZEN_EXT_WIFI_MESH
460 case G_SUPPLICANT_SECURITY_SAE:
468 static GSupplicantState string2state(const char *state)
471 return G_SUPPLICANT_STATE_UNKNOWN;
473 if (g_str_equal(state, "unknown"))
474 return G_SUPPLICANT_STATE_UNKNOWN;
475 else if (g_str_equal(state, "interface_disabled"))
476 return G_SUPPLICANT_STATE_DISABLED;
477 else if (g_str_equal(state, "disconnected"))
478 return G_SUPPLICANT_STATE_DISCONNECTED;
479 else if (g_str_equal(state, "inactive"))
480 return G_SUPPLICANT_STATE_INACTIVE;
481 else if (g_str_equal(state, "scanning"))
482 return G_SUPPLICANT_STATE_SCANNING;
483 else if (g_str_equal(state, "authenticating"))
484 return G_SUPPLICANT_STATE_AUTHENTICATING;
485 else if (g_str_equal(state, "associating"))
486 return G_SUPPLICANT_STATE_ASSOCIATING;
487 else if (g_str_equal(state, "associated"))
488 return G_SUPPLICANT_STATE_ASSOCIATED;
489 else if (g_str_equal(state, "group_handshake"))
490 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
491 else if (g_str_equal(state, "4way_handshake"))
492 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
493 else if (g_str_equal(state, "completed"))
494 return G_SUPPLICANT_STATE_COMPLETED;
496 return G_SUPPLICANT_STATE_UNKNOWN;
499 static bool compare_network_parameters(GSupplicantInterface *interface,
500 GSupplicantSSID *ssid)
502 #if defined TIZEN_EXT
503 if (!interface->network_info.ssid)
507 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
510 if (interface->network_info.security != ssid->security)
513 if (interface->network_info.passphrase &&
514 g_strcmp0(interface->network_info.passphrase,
515 ssid->passphrase) != 0) {
519 if (interface->network_info.private_passphrase &&
520 g_strcmp0(interface->network_info.private_passphrase,
521 ssid->private_key_passphrase) != 0) {
528 static void remove_network_information(GSupplicantInterface * interface)
530 g_free(interface->network_info.ssid);
531 g_free(interface->network_info.passphrase);
532 g_free(interface->network_info.private_passphrase);
533 interface->network_info.ssid = NULL;
534 interface->network_info.passphrase = NULL;
535 interface->network_info.private_passphrase = NULL;
538 static int store_network_information(GSupplicantInterface * interface,
539 GSupplicantSSID *ssid)
541 interface->network_info.ssid = g_malloc(ssid->ssid_len + 1);
542 if (interface->network_info.ssid != NULL) {
543 memcpy(interface->network_info.ssid, ssid->ssid,
545 interface->network_info.ssid[ssid->ssid_len] = '\0';
550 interface->network_info.security = ssid->security;
552 if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
553 ssid->security == G_SUPPLICANT_SECURITY_PSK ||
554 ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
556 interface->network_info.passphrase = g_strdup(ssid->passphrase);
559 if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X &&
560 ssid->private_key_passphrase) {
561 interface->network_info.private_passphrase =
562 g_strdup(ssid->private_key_passphrase);
568 static void callback_system_ready(void)
575 if (!callbacks_pointer)
578 if (!callbacks_pointer->system_ready)
581 callbacks_pointer->system_ready();
584 static void callback_system_killed(void)
586 system_ready = FALSE;
588 if (!callbacks_pointer)
591 if (!callbacks_pointer->system_killed)
594 callbacks_pointer->system_killed();
597 static void callback_interface_added(GSupplicantInterface *interface)
601 if (!callbacks_pointer)
604 if (!callbacks_pointer->interface_added)
607 callbacks_pointer->interface_added(interface);
610 static void callback_interface_state(GSupplicantInterface *interface)
612 if (!callbacks_pointer)
615 if (!callbacks_pointer->interface_state)
618 callbacks_pointer->interface_state(interface);
621 static void callback_interface_removed(GSupplicantInterface *interface)
623 if (!callbacks_pointer)
626 if (!callbacks_pointer->interface_removed)
629 callbacks_pointer->interface_removed(interface);
632 #if !defined TIZEN_EXT
633 static void callback_p2p_support(GSupplicantInterface *interface)
637 if (!interface->p2p_support)
640 if (callbacks_pointer && callbacks_pointer->p2p_support)
641 callbacks_pointer->p2p_support(interface);
645 #if defined TIZEN_EXT_WIFI_MESH
646 static void callback_mesh_support(GSupplicantInterface *interface)
650 if (!interface->mesh_support)
653 if (callbacks_pointer && callbacks_pointer->mesh_support)
654 callbacks_pointer->mesh_support(interface);
657 bool g_supplicant_interface_has_mesh(GSupplicantInterface *interface)
662 return interface->mesh_support;
666 static void callback_scan_started(GSupplicantInterface *interface)
668 if (!callbacks_pointer)
671 if (!callbacks_pointer->scan_started)
674 callbacks_pointer->scan_started(interface);
677 static void callback_ap_create_fail(GSupplicantInterface *interface)
679 if (!callbacks_pointer)
682 if (!callbacks_pointer->ap_create_fail)
685 callbacks_pointer->ap_create_fail(interface);
688 static void callback_scan_finished(GSupplicantInterface *interface)
690 if (!callbacks_pointer)
693 if (!callbacks_pointer->scan_finished)
696 callbacks_pointer->scan_finished(interface);
699 static void callback_network_added(GSupplicantNetwork *network)
701 if (!callbacks_pointer)
704 if (!callbacks_pointer->network_added)
707 callbacks_pointer->network_added(network);
710 static void callback_network_removed(GSupplicantNetwork *network)
712 if (!callbacks_pointer)
715 if (!callbacks_pointer->network_removed)
718 callbacks_pointer->network_removed(network);
721 #if defined TIZEN_EXT
722 static void callback_network_merged(GSupplicantNetwork *network)
724 if (!callbacks_pointer)
727 if (!callbacks_pointer->network_merged)
730 callbacks_pointer->network_merged(network);
733 static void callback_assoc_failed(void *user_data)
735 if (!callbacks_pointer)
738 if (!callbacks_pointer->assoc_failed)
741 callbacks_pointer->assoc_failed(user_data);
745 static void callback_network_changed(GSupplicantNetwork *network,
746 const char *property)
748 if (!callbacks_pointer)
751 if (!callbacks_pointer->network_changed)
754 callbacks_pointer->network_changed(network, property);
757 static void callback_network_associated(GSupplicantNetwork *network)
759 if (!callbacks_pointer)
762 if (!callbacks_pointer->network_associated)
765 callbacks_pointer->network_associated(network);
768 static void callback_peer_found(GSupplicantPeer *peer)
770 if (!callbacks_pointer)
773 if (!callbacks_pointer->peer_found)
776 callbacks_pointer->peer_found(peer);
779 static void callback_peer_lost(GSupplicantPeer *peer)
781 if (!callbacks_pointer)
784 if (!callbacks_pointer->peer_lost)
787 callbacks_pointer->peer_lost(peer);
790 static void callback_peer_changed(GSupplicantPeer *peer,
791 GSupplicantPeerState state)
793 if (!callbacks_pointer)
796 if (!callbacks_pointer->peer_changed)
799 callbacks_pointer->peer_changed(peer, state);
802 static void callback_peer_request(GSupplicantPeer *peer)
804 if (!callbacks_pointer)
807 if (!callbacks_pointer->peer_request)
810 peer->connection_requested = true;
812 callbacks_pointer->peer_request(peer);
815 static void callback_disconnect_reason_code(GSupplicantInterface *interface,
818 if (!callbacks_pointer)
821 if (!callbacks_pointer->disconnect_reasoncode)
824 if (reason_code != 0)
825 callbacks_pointer->disconnect_reasoncode(interface,
829 static void callback_assoc_status_code(GSupplicantInterface *interface,
832 if (!callbacks_pointer)
835 if (!callbacks_pointer->assoc_status_code)
838 callbacks_pointer->assoc_status_code(interface, status_code);
842 static void remove_group(gpointer data)
844 GSupplicantGroup *group = data;
847 g_slist_free_full(group->members, g_free);
853 static void remove_interface(gpointer data)
855 GSupplicantInterface *interface = data;
857 g_hash_table_destroy(interface->bss_mapping);
858 g_hash_table_destroy(interface->network_table);
859 g_hash_table_destroy(interface->peer_table);
860 g_hash_table_destroy(interface->group_table);
862 if (interface->scan_callback) {
863 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
864 interface, interface->scan_callback,
865 interface->scanning);
867 interface->scan_callback(-EIO, interface, interface->scan_data);
868 interface->scan_callback = NULL;
869 interface->scan_data = NULL;
871 if (interface->scanning) {
872 interface->scanning = FALSE;
873 callback_scan_finished(interface);
877 callback_interface_removed(interface);
879 g_free(interface->wps_cred.key);
880 g_free(interface->path);
881 g_free(interface->network_path);
882 #if defined TIZEN_EXT
883 interface->network_path = NULL;
885 g_free(interface->ifname);
886 g_free(interface->driver);
887 g_free(interface->bridge);
888 remove_network_information(interface);
892 static void remove_network(gpointer data)
894 GSupplicantNetwork *network = data;
896 g_hash_table_destroy(network->bss_table);
898 callback_network_removed(network);
900 g_hash_table_destroy(network->config_table);
902 g_free(network->path);
903 g_free(network->group);
904 g_free(network->name);
905 #if defined TIZEN_EXT
906 g_free(network->eap);
907 g_free(network->identity);
908 g_free(network->phase2);
910 #if defined TIZEN_EXT
911 g_slist_free_full(network->vsie_list, g_free);
917 static void remove_bss(gpointer data)
919 struct g_supplicant_bss *bss = data;
922 #if defined TIZEN_EXT
923 g_slist_free_full(bss->vsie_list, g_free);
928 static void remove_peer(gpointer data)
930 GSupplicantPeer *peer = data;
932 callback_peer_lost(peer);
935 g_slist_free_full(peer->groups, g_free);
938 g_hash_table_remove(peer_mapping, peer->path);
940 if (pending_peer_connection)
941 g_hash_table_remove(pending_peer_connection, peer->path);
945 g_free(peer->identifier);
946 g_free(peer->widi_ies);
951 static void debug_strvalmap(const char *label, struct strvalmap *map,
956 for (i = 0; map[i].str; i++) {
957 if (val & map[i].val)
958 SUPPLICANT_DBG("%s: %s", label, map[i].str);
962 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
964 GSupplicantInterface *interface = user_data;
965 const char *str = NULL;
968 dbus_message_iter_get_basic(iter, &str);
972 for (i = 0; keymgmt_map[i].str; i++)
973 if (strcmp(str, keymgmt_map[i].str) == 0) {
974 interface->keymgmt_capa |= keymgmt_map[i].val;
979 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
981 GSupplicantInterface *interface = user_data;
982 const char *str = NULL;
985 dbus_message_iter_get_basic(iter, &str);
989 for (i = 0; authalg_capa_map[i].str; i++)
990 if (strcmp(str, authalg_capa_map[i].str) == 0) {
991 interface->authalg_capa |= authalg_capa_map[i].val;
996 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
998 GSupplicantInterface *interface = user_data;
999 const char *str = NULL;
1002 dbus_message_iter_get_basic(iter, &str);
1006 for (i = 0; proto_capa_map[i].str; i++)
1007 if (strcmp(str, proto_capa_map[i].str) == 0) {
1008 interface->proto_capa |= proto_capa_map[i].val;
1013 static void interface_capability_pairwise(DBusMessageIter *iter,
1016 GSupplicantInterface *interface = user_data;
1017 const char *str = NULL;
1020 dbus_message_iter_get_basic(iter, &str);
1024 for (i = 0; pairwise_map[i].str; i++)
1025 if (strcmp(str, pairwise_map[i].str) == 0) {
1026 interface->pairwise_capa |= pairwise_map[i].val;
1031 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
1033 GSupplicantInterface *interface = user_data;
1034 const char *str = NULL;
1037 dbus_message_iter_get_basic(iter, &str);
1041 for (i = 0; group_map[i].str; i++)
1042 if (strcmp(str, group_map[i].str) == 0) {
1043 interface->group_capa |= group_map[i].val;
1048 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
1050 GSupplicantInterface *interface = user_data;
1051 const char *str = NULL;
1054 dbus_message_iter_get_basic(iter, &str);
1058 for (i = 0; scan_capa_map[i].str; i++)
1059 if (strcmp(str, scan_capa_map[i].str) == 0) {
1060 interface->scan_capa |= scan_capa_map[i].val;
1065 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
1067 GSupplicantInterface *interface = user_data;
1068 const char *str = NULL;
1071 dbus_message_iter_get_basic(iter, &str);
1075 for (i = 0; mode_capa_map[i].str; i++)
1076 if (strcmp(str, mode_capa_map[i].str) == 0) {
1077 interface->mode_capa |= mode_capa_map[i].val;
1082 static void interface_capability(const char *key, DBusMessageIter *iter,
1085 GSupplicantInterface *interface = user_data;
1090 if (g_strcmp0(key, "KeyMgmt") == 0)
1091 supplicant_dbus_array_foreach(iter,
1092 interface_capability_keymgmt, interface);
1093 else if (g_strcmp0(key, "AuthAlg") == 0)
1094 supplicant_dbus_array_foreach(iter,
1095 interface_capability_authalg, interface);
1096 else if (g_strcmp0(key, "Protocol") == 0)
1097 supplicant_dbus_array_foreach(iter,
1098 interface_capability_proto, interface);
1099 else if (g_strcmp0(key, "Pairwise") == 0)
1100 supplicant_dbus_array_foreach(iter,
1101 interface_capability_pairwise, interface);
1102 else if (g_strcmp0(key, "Group") == 0)
1103 supplicant_dbus_array_foreach(iter,
1104 interface_capability_group, interface);
1105 else if (g_strcmp0(key, "Scan") == 0)
1106 supplicant_dbus_array_foreach(iter,
1107 interface_capability_scan, interface);
1108 else if (g_strcmp0(key, "Modes") == 0)
1109 supplicant_dbus_array_foreach(iter,
1110 interface_capability_mode, interface);
1111 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
1112 dbus_int32_t max_scan_ssid;
1114 dbus_message_iter_get_basic(iter, &max_scan_ssid);
1115 if (max_scan_ssid < 2)
1117 interface->max_scan_ssids = max_scan_ssid;
1118 #if defined TIZEN_EXT
1119 } else if (g_strcmp0(key, "Is5GhzSupported") == 0) {
1120 dbus_bool_t is_5_0_Ghz_supported;
1122 dbus_message_iter_get_basic(iter, &is_5_0_Ghz_supported);
1123 interface->is_5_0_Ghz_supported = is_5_0_Ghz_supported;
1126 SUPPLICANT_DBG("key %s type %c",
1127 key, dbus_message_iter_get_arg_type(iter));
1130 struct set_apscan_data
1132 unsigned int ap_scan;
1133 GSupplicantInterface *interface;
1136 static void set_apscan(DBusMessageIter *iter, void *user_data)
1138 struct set_apscan_data *data = user_data;
1139 unsigned int ap_scan = data->ap_scan;
1141 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
1144 static void set_apscan_complete(const char *error,
1145 DBusMessageIter *iter, void *user_data)
1147 struct set_apscan_data *data = user_data;
1148 GSupplicantInterface *interface = data->interface;
1151 interface->ap_create_in_progress = false;
1152 SUPPLICANT_DBG("Set AP scan error %s", error);
1156 interface->ap_create_in_progress = true;
1161 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
1162 unsigned int ap_scan)
1164 struct set_apscan_data *data;
1167 data = dbus_malloc0(sizeof(*data));
1172 data->ap_scan = ap_scan;
1173 data->interface = interface;
1175 ret = supplicant_dbus_property_set(interface->path,
1176 SUPPLICANT_INTERFACE ".Interface",
1177 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
1178 set_apscan, set_apscan_complete, data, NULL);
1185 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
1191 interface->data = data;
1194 interface->scan_callback = NULL;
1197 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
1202 return interface->data;
1205 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
1210 return interface->ifname;
1213 #if defined TIZEN_EXT
1214 bool g_supplicant_interface_get_is_5_0_ghz_supported(GSupplicantInterface *interface)
1219 return interface->is_5_0_Ghz_supported;
1223 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
1228 return interface->driver;
1231 GSupplicantState g_supplicant_interface_get_state(
1232 GSupplicantInterface *interface)
1235 return G_SUPPLICANT_STATE_UNKNOWN;
1237 return interface->state;
1240 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
1245 return (const char *)interface->wps_cred.key;
1248 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
1249 unsigned int *ssid_len)
1254 if (!interface || interface->wps_cred.ssid_len == 0) {
1259 *ssid_len = interface->wps_cred.ssid_len;
1260 return interface->wps_cred.ssid;
1263 GSupplicantWpsState g_supplicant_interface_get_wps_state(
1264 GSupplicantInterface *interface)
1267 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
1269 return interface->wps_state;
1272 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
1277 return interface->mode_capa;
1280 unsigned int g_supplicant_interface_get_max_scan_ssids(
1281 GSupplicantInterface *interface)
1286 if (interface->max_scan_ssids == 0)
1287 return WPAS_MAX_SCAN_SSIDS;
1289 return interface->max_scan_ssids;
1292 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
1294 dbus_bool_t enable = *(dbus_bool_t *)user_data;
1296 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
1299 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
1305 if (!interface->network_path)
1308 SUPPLICANT_DBG(" ");
1309 return supplicant_dbus_property_set(interface->network_path,
1310 SUPPLICANT_INTERFACE ".Network",
1311 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
1312 set_network_enabled, NULL, &enable, NULL);
1315 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
1320 return interface->ready;
1323 GSupplicantInterface *g_supplicant_network_get_interface(
1324 GSupplicantNetwork *network)
1329 return network->interface;
1332 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
1334 if (!network || !network->name)
1337 return network->name;
1340 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
1342 if (!network || !network->group)
1345 return network->group;
1348 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1350 if (!network || !network->path)
1353 return network->path;
1356 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1359 return G_SUPPLICANT_MODE_UNKNOWN;
1361 return mode2string(network->mode);
1364 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1367 return G_SUPPLICANT_SECURITY_UNKNOWN;
1369 return security2string(network->security);
1372 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1373 unsigned int *ssid_len)
1380 *ssid_len = network->ssid_len;
1381 return network->ssid;
1384 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1389 return network->signal;
1392 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1397 return network->frequency;
1400 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1405 return network->wps;
1408 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1413 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1419 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1424 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1430 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1435 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1442 GSupplicantPhy_mode g_supplicant_network_get_phy_mode(GSupplicantNetwork *network)
1445 return G_SUPPLICANT_MODE_IEEE80211_UNKNOWN;
1447 return network->phy_mode;
1451 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1456 return peer->interface;
1459 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1467 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1472 return peer->identifier;
1475 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1480 return peer->device_address;
1483 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1488 return peer->iface_address;
1491 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1499 #if defined TIZEN_EXT
1500 bool g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1505 return network->isHS20AP;
1508 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1510 if (!network || !network->eap)
1513 return network->eap;
1516 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1518 if (!network || !network->identity)
1521 return network->identity;
1524 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1526 if (!network || !network->phase2)
1529 return network->phase2;
1532 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1534 if (network == NULL)
1537 return network->keymgmt;
1540 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
1546 return network->country_code;
1550 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1553 if (!peer || !length)
1556 *length = peer->widi_ies_length;
1557 return peer->widi_ies;
1560 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1565 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1571 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1576 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1582 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1584 if (!peer || !peer->groups)
1590 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1595 return (GSupplicantInterface *) peer->current_group_iface;
1598 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1600 GSupplicantGroup *group;
1606 for (list = peer->groups; list; list = list->next) {
1607 const char *path = list->data;
1609 group = g_hash_table_lookup(group_mapping, path);
1613 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1614 group->orig_interface != peer->interface)
1617 if (group->interface == peer->current_group_iface)
1624 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1629 return peer->connection_requested;
1632 #if defined TIZEN_EXT
1634 * Description: Network client requires additional wifi specific info
1636 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1638 if (network == NULL || network->best_bss == NULL)
1641 return (const unsigned char *)network->best_bss->bssid;
1644 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1646 if (network == NULL || network->best_bss == NULL)
1649 return network->best_bss->maxrate;
1652 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1654 if (network == NULL || network->best_bss == NULL)
1657 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1658 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1659 unsigned int pairwise;
1661 pairwise = network->best_bss->rsn_pairwise |
1662 network->best_bss->wpa_pairwise;
1664 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1665 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1667 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1669 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1672 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1674 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1680 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network)
1682 if (network == NULL || network->best_bss == NULL)
1685 if (network->best_bss->rsn_selected) {
1686 const char *mode = g_supplicant_network_get_enc_mode(network);
1687 if (g_strcmp0(mode, "aes") == 0 ||
1688 g_strcmp0(mode, "mixed") == 0)
1696 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
1698 GSList *vsie_list = NULL;
1703 if (g_slist_length(network->vsie_list) > 0) {
1704 GSList *list = NULL;
1705 unsigned char *vsie = NULL;
1706 for (list = network->vsie_list; list; list = list->next) {
1707 unsigned char *ie = (unsigned char *)list->data;
1710 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
1713 memcpy(vsie, ie, ie[1]+2);
1714 vsie_list = g_slist_append(vsie_list, vsie);
1716 SUPPLICANT_DBG("Failed to allocate memory");
1723 static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
1725 struct g_supplicant_bss *bss = value;
1726 struct g_connman_bssids *bssids = NULL;
1727 GSList **list = (GSList **)user_data;
1729 bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
1732 memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
1734 bssids->strength = bss->signal;
1735 bssids->strength += 120;
1737 if (bssids->strength > 100)
1738 bssids->strength = 100;
1740 bssids->frequency = bss->frequency;
1741 *list = g_slist_append(*list, bssids);
1743 SUPPLICANT_DBG("Failed to allocate memory");
1746 static gint cmp_bss(gconstpointer a, gconstpointer b)
1748 struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
1749 struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
1751 if (entry_a->strength > entry_b->strength)
1754 if (entry_a->strength < entry_b->strength)
1760 void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
1762 GSList *bssid_list = NULL;
1764 if (g_hash_table_size(network->bss_table) < 1)
1767 g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_list);
1768 bssid_list = g_slist_sort(bssid_list, cmp_bss);
1774 static void merge_network(GSupplicantNetwork *network)
1777 const char *ssid, *mode, *key_mgmt;
1778 #if defined TIZEN_EXT
1779 const char *isHS20AP;
1780 const char *eap, *identity, *phase2;
1782 unsigned int i, ssid_len;
1785 ssid = g_hash_table_lookup(network->config_table, "ssid");
1786 mode = g_hash_table_lookup(network->config_table, "mode");
1787 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
1788 #if defined TIZEN_EXT
1789 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
1790 eap = g_hash_table_lookup(network->config_table, "eap");
1791 identity = g_hash_table_lookup(network->config_table, "identity");
1792 phase2 = g_hash_table_lookup(network->config_table, "phase2");
1795 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
1798 ssid_len = strlen(ssid);
1802 str = g_string_sized_new((ssid_len * 2) + 24);
1806 for (i = 0; i < ssid_len; i++)
1807 #if defined TIZEN_EXT
1811 g_string_append_printf(str, "%02x", ssid[i]);
1812 #if defined TIZEN_EXT
1816 if (g_strcmp0(mode, "0") == 0)
1817 g_string_append_printf(str, "_managed");
1818 else if (g_strcmp0(mode, "1") == 0)
1819 g_string_append_printf(str, "_adhoc");
1820 #if defined TIZEN_EXT_WIFI_MESH
1821 else if (g_strcmp0(mode, "5") == 0)
1822 g_string_append_printf(str, "_mesh");
1825 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
1826 g_string_append_printf(str, "_psk");
1827 #if defined TIZEN_EXT
1828 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
1829 g_string_append_printf(str, "_ieee8021x");
1831 g_string_append_printf(str, "_none");
1834 group = g_string_free(str, FALSE);
1836 SUPPLICANT_DBG("%s", group);
1838 #if defined TIZEN_EXT
1839 if (g_strcmp0(isHS20AP, "1") == 0) {
1840 network->isHS20AP = 1;
1842 g_free(network->eap);
1843 network->eap = g_strdup(eap);
1845 if (network->identity)
1846 g_free(network->identity);
1847 network->identity = g_strdup(identity);
1849 if (network->phase2)
1850 g_free(network->phase2);
1851 network->phase2 = g_strdup(phase2);
1853 network->isHS20AP = 0;
1855 network->group = g_strdup(group);
1856 callback_network_merged(network);
1857 g_free(network->group);
1862 g_hash_table_destroy(network->config_table);
1864 g_free(network->path);
1868 static void network_property(const char *key, DBusMessageIter *iter,
1871 GSupplicantNetwork *network = user_data;
1873 if (!network->interface)
1877 merge_network(network);
1881 if (g_strcmp0(key, "Enabled") == 0) {
1882 dbus_bool_t enabled = FALSE;
1884 dbus_message_iter_get_basic(iter, &enabled);
1885 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
1886 const char *str = NULL;
1888 dbus_message_iter_get_basic(iter, &str);
1890 g_hash_table_replace(network->config_table,
1891 g_strdup(key), g_strdup(str));
1894 SUPPLICANT_DBG("key %s type %c",
1895 key, dbus_message_iter_get_arg_type(iter));
1898 static void interface_network_added(DBusMessageIter *iter, void *user_data)
1900 GSupplicantInterface *interface = user_data;
1901 GSupplicantNetwork *network;
1902 const char *path = NULL;
1906 dbus_message_iter_get_basic(iter, &path);
1910 if (g_strcmp0(path, "/") == 0)
1913 network = g_try_new0(GSupplicantNetwork, 1);
1917 network->interface = interface;
1918 network->path = g_strdup(path);
1920 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1923 dbus_message_iter_next(iter);
1924 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
1925 supplicant_dbus_property_foreach(iter, network_property,
1927 network_property(NULL, NULL, network);
1931 supplicant_dbus_property_get_all(path,
1932 SUPPLICANT_INTERFACE ".Network",
1933 network_property, network, NULL);
1936 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
1942 static char *create_name(unsigned char *ssid, int ssid_len)
1945 const gchar *remainder, *invalid;
1946 int valid_bytes, remaining_bytes;
1948 if (ssid_len < 1 || ssid[0] == '\0')
1949 return g_strdup("");
1952 remainder = (const gchar *)ssid;
1953 remaining_bytes = ssid_len;
1955 while (remaining_bytes != 0) {
1956 if (g_utf8_validate(remainder, remaining_bytes,
1961 valid_bytes = invalid - remainder;
1964 string = g_string_sized_new(remaining_bytes);
1966 g_string_append_len(string, remainder, valid_bytes);
1968 /* append U+FFFD REPLACEMENT CHARACTER */
1969 g_string_append(string, "\357\277\275");
1971 remaining_bytes -= valid_bytes + 1;
1972 remainder = invalid + 1;
1976 return g_strndup((const gchar *)ssid, ssid_len + 1);
1978 g_string_append(string, remainder);
1980 return g_string_free(string, FALSE);
1983 static char *create_group(struct g_supplicant_bss *bss)
1987 const char *mode, *security;
1989 str = g_string_sized_new((bss->ssid_len * 2) + 24);
1993 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
1994 for (i = 0; i < bss->ssid_len; i++)
1995 g_string_append_printf(str, "%02x", bss->ssid[i]);
1997 g_string_append_printf(str, "hidden");
1999 mode = mode2string(bss->mode);
2001 g_string_append_printf(str, "_%s", mode);
2003 security = security2string(bss->security);
2005 g_string_append_printf(str, "_%s", security);
2007 return g_string_free(str, FALSE);
2010 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2012 GSupplicantInterface *interface = bss->interface;
2013 GSupplicantNetwork *network;
2016 group = create_group(bss);
2017 SUPPLICANT_DBG("New group created: %s", group);
2022 network = g_hash_table_lookup(interface->network_table, group);
2025 SUPPLICANT_DBG("Network %s already exist", network->name);
2030 network = g_try_new0(GSupplicantNetwork, 1);
2036 network->interface = interface;
2038 network->path = g_strdup(bss->path);
2039 network->group = group;
2040 network->name = create_name(bss->ssid, bss->ssid_len);
2041 network->mode = bss->mode;
2042 network->security = bss->security;
2043 network->ssid_len = bss->ssid_len;
2044 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2045 network->signal = bss->signal;
2046 network->frequency = bss->frequency;
2047 network->best_bss = bss;
2049 #if defined TIZEN_EXT
2050 network->keymgmt = bss->keymgmt;
2052 if (g_slist_length(bss->vsie_list) > 0) {
2053 GSList *list = NULL;
2054 unsigned char *vsie = NULL;
2055 for (list = bss->vsie_list; list; list = list->next) {
2056 unsigned char *ie = (unsigned char *)list->data;
2057 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2060 memcpy(vsie, ie, ie[1]+2);
2061 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2063 SUPPLICANT_DBG("Failed to allocate memory.");
2067 network->isHS20AP = bss->hs20;
2068 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2069 network->phy_mode = bss->phy_mode;
2072 SUPPLICANT_DBG("New network %s created", network->name);
2074 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2077 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2080 g_hash_table_replace(interface->network_table,
2081 network->group, network);
2083 callback_network_added(network);
2086 /* We update network's WPS properties if only bss provides WPS. */
2087 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2088 network->wps = TRUE;
2089 network->wps_capabilities |= bss->wps_capabilities;
2093 * Do not change best BSS if we are connected. It will be done through
2094 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2096 if (network != interface->current_network &&
2097 bss->signal > network->signal) {
2098 network->signal = bss->signal;
2099 network->best_bss = bss;
2100 callback_network_changed(network, "Signal");
2103 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2104 g_hash_table_replace(network->bss_table, bss->path, bss);
2106 g_hash_table_replace(bss_mapping, bss->path, interface);
2111 static void bss_rates(DBusMessageIter *iter, void *user_data)
2113 struct g_supplicant_bss *bss = user_data;
2114 dbus_uint32_t rate = 0;
2116 dbus_message_iter_get_basic(iter, &rate);
2120 if (rate > bss->maxrate)
2121 bss->maxrate = rate;
2124 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2126 unsigned int *keymgmt = user_data;
2127 const char *str = NULL;
2130 dbus_message_iter_get_basic(iter, &str);
2134 for (i = 0; keymgmt_map[i].str; i++)
2135 if (strcmp(str, keymgmt_map[i].str) == 0) {
2136 SUPPLICANT_DBG("Keymgmt: %s", str);
2137 *keymgmt |= keymgmt_map[i].val;
2142 static void bss_group(DBusMessageIter *iter, void *user_data)
2144 unsigned int *group = user_data;
2145 const char *str = NULL;
2148 dbus_message_iter_get_basic(iter, &str);
2152 for (i = 0; group_map[i].str; i++)
2153 if (strcmp(str, group_map[i].str) == 0) {
2154 SUPPLICANT_DBG("Group: %s", str);
2155 *group |= group_map[i].val;
2160 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2162 unsigned int *pairwise = user_data;
2163 const char *str = NULL;
2166 dbus_message_iter_get_basic(iter, &str);
2170 for (i = 0; pairwise_map[i].str; i++)
2171 if (strcmp(str, pairwise_map[i].str) == 0) {
2172 SUPPLICANT_DBG("Pairwise: %s", str);
2173 *pairwise |= pairwise_map[i].val;
2178 static void bss_wpa(const char *key, DBusMessageIter *iter,
2181 struct g_supplicant_bss *bss = user_data;
2182 unsigned int value = 0;
2184 SUPPLICANT_DBG("Key: %s", key);
2186 if (g_strcmp0(key, "KeyMgmt") == 0) {
2187 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2189 if (bss->rsn_selected)
2190 bss->rsn_keymgmt = value;
2192 bss->wpa_keymgmt = value;
2193 } else if (g_strcmp0(key, "Group") == 0) {
2194 supplicant_dbus_array_foreach(iter, bss_group, &value);
2196 if (bss->rsn_selected)
2197 bss->rsn_group = value;
2199 bss->wpa_group = value;
2200 } else if (g_strcmp0(key, "Pairwise") == 0) {
2201 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2203 if (bss->rsn_selected)
2204 bss->rsn_pairwise = value;
2206 bss->wpa_pairwise = value;
2210 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2213 unsigned int len = 0;
2215 while (len + 4 < ie_size) {
2216 unsigned int hi = ie[len];
2217 unsigned int lo = ie[len + 1];
2218 unsigned int tmp_type = (hi << 8) + lo;
2219 unsigned int v_len = 0;
2221 /* hi and lo are used to recreate an unsigned int
2222 * based on 2 8bits length unsigned int. */
2226 v_len = (hi << 8) + lo;
2228 if (tmp_type == type) {
2229 unsigned int ret_value = 0;
2230 unsigned char *value = (unsigned char *)&ret_value;
2232 SUPPLICANT_DBG("IE: match type 0x%x", type);
2234 /* Verifying length relevance */
2235 if (v_len > sizeof(unsigned int) ||
2236 len + 4 + v_len > ie_size)
2239 memcpy(value, ie + len + 4, v_len);
2241 SUPPLICANT_DBG("returning 0x%x", ret_value);
2248 SUPPLICANT_DBG("returning 0");
2252 #if defined TIZEN_EXT
2253 static void get_bss_phy_mode(unsigned int max_rate,
2254 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2256 struct g_supplicant_bss *bss = data;
2257 unsigned int freq = bss->frequency;
2259 /* Following conditions are used to determine
2260 * IEEE 802.11 Protocol Modes:-
2262 * 1. If “Supported rates” is only till 11 Mbps,
2263 * and frequency is in 2.4GHz band, then protocol is 11B.
2264 * 2. If “Supported rates” is till 54Mbps or
2265 * “Extended supported rates” are present,
2266 * and frequency is in 2.4GHz band, then protocol is 11G.
2267 * 3. If “Supported rates” is only till 54 Mbps,
2268 * frequency is in 5GHz band , then protocol is 11A.
2269 * 4. If “HT capabilities” is supported , then protocol is 11N.
2270 * 5. If “HT capabilities” & “VHT” is supported and
2271 * frequency is in 5 GHz band, then protocol is 11AC.
2274 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
2275 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
2276 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
2277 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
2278 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
2279 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
2280 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
2282 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2283 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
2284 if (max_rate <= 54 && !ht)
2285 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
2286 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
2287 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
2288 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
2289 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
2291 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
2296 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
2298 struct g_supplicant_bss *bss = user_data;
2299 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
2300 unsigned char *ie, *ie_end;
2301 DBusMessageIter array;
2304 #if defined TIZEN_EXT
2306 unsigned char *rates = NULL;
2307 unsigned char *ext_rates = NULL;
2308 unsigned int max_rate = 0;
2309 unsigned int max_ext_rate = 0;
2314 #define WMM_WPA1_WPS_INFO 221
2315 #define WPS_INFO_MIN_LEN 6
2316 #define WPS_VERSION_TLV 0x104A
2317 #define WPS_STATE_TLV 0x1044
2318 #define WPS_METHODS_TLV 0x1012
2319 #define WPS_REGISTRAR_TLV 0x1041
2320 #define WPS_VERSION 0x10
2321 #define WPS_PBC 0x04
2322 #define WPS_PIN 0x00
2323 #define WPS_CONFIGURED 0x02
2324 #if defined TIZEN_EXT
2325 #define VENDOR_SPECIFIC_INFO 0xDD
2326 #define WLAN_EID_COUNTRY 7
2329 dbus_message_iter_recurse(iter, &array);
2330 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
2332 if (!ie || ie_len < 2)
2335 bss->wps_capabilities = 0;
2337 memset(bss->country_code, 0, COUNTRY_CODE_LENGTH);
2339 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
2341 #if defined TIZEN_EXT
2342 unsigned char *vsie;
2344 if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
2345 SUPPLICANT_DBG("IE: match vendor specific data");
2347 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
2348 vsie = (unsigned char *)g_try_malloc0(vsie_len);
2351 memcpy(vsie, ie, vsie_len);
2352 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
2354 SUPPLICANT_DBG("Failed to allocate memory");
2358 if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
2359 /* Add country code only if it is a valid alphabet */
2360 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
2361 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
2366 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
2371 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
2376 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
2378 rates = g_malloc0(r_len);
2382 for (j = 0; ie && j < r_len; j++) {
2383 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
2384 if (max_rate < rates[j])
2385 max_rate = rates[j];
2390 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
2392 ext_rates = g_malloc0(r_len);
2396 for (j = 0; ie && j < r_len; j++) {
2397 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
2398 if (max_ext_rate < ext_rates[j])
2399 max_ext_rate = ext_rates[j];
2404 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
2405 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
2408 SUPPLICANT_DBG("IE: match WPS_OUI");
2410 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
2411 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
2413 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
2415 if (value == WPS_CONFIGURED)
2416 bss->wps_capabilities |=
2417 G_SUPPLICANT_WPS_CONFIGURED;
2420 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
2422 if (GUINT16_FROM_BE(value) == WPS_PBC)
2423 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
2424 if (GUINT16_FROM_BE(value) == WPS_PIN)
2425 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
2427 bss->wps_capabilities |=
2428 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
2430 /* If the AP sends this it means it's advertizing
2431 * as a registrar and the WPS process is launched
2433 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
2434 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
2436 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
2439 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
2447 static void bss_compute_security(struct g_supplicant_bss *bss)
2450 * Combining RSN and WPA keymgmt
2451 * We combine it since parsing IEs might have set something for WPS. */
2452 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
2454 bss->ieee8021x = FALSE;
2456 #if defined TIZEN_EXT
2457 bss->ft_ieee8021x = FALSE;
2458 bss->ft_psk = FALSE;
2461 #if defined TIZEN_EXT
2463 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
2464 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
2465 bss->ieee8021x = TRUE;
2466 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
2467 bss->ft_ieee8021x = TRUE;
2470 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
2471 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
2472 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
2473 bss->ieee8021x = TRUE;
2476 #if defined TIZEN_EXT
2478 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
2479 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
2481 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
2485 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
2486 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
2487 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
2491 #if defined TIZEN_EXT_WIFI_MESH
2492 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
2497 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
2499 bss->security = G_SUPPLICANT_SECURITY_PSK;
2500 #if defined TIZEN_EXT
2501 else if (bss->ft_psk)
2502 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
2503 else if (bss->ft_ieee8021x == TRUE)
2504 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
2506 #if defined TIZEN_EXT_WIFI_MESH
2508 bss->security = G_SUPPLICANT_SECURITY_SAE;
2510 else if (bss->privacy)
2511 bss->security = G_SUPPLICANT_SECURITY_WEP;
2513 bss->security = G_SUPPLICANT_SECURITY_NONE;
2517 static void bss_property(const char *key, DBusMessageIter *iter,
2520 struct g_supplicant_bss *bss = user_data;
2522 if (!bss->interface)
2525 SUPPLICANT_DBG("key %s", key);
2530 if (g_strcmp0(key, "BSSID") == 0) {
2531 DBusMessageIter array;
2532 unsigned char *addr;
2535 dbus_message_iter_recurse(iter, &array);
2536 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
2539 memcpy(bss->bssid, addr, addr_len);
2540 } else if (g_strcmp0(key, "SSID") == 0) {
2541 DBusMessageIter array;
2542 unsigned char *ssid;
2545 dbus_message_iter_recurse(iter, &array);
2546 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
2548 if (ssid_len > 0 && ssid_len < 33) {
2549 memcpy(bss->ssid, ssid, ssid_len);
2550 bss->ssid_len = ssid_len;
2552 memset(bss->ssid, 0, sizeof(bss->ssid));
2555 } else if (g_strcmp0(key, "Capabilities") == 0) {
2556 dbus_uint16_t capabilities = 0x0000;
2558 dbus_message_iter_get_basic(iter, &capabilities);
2560 if (capabilities & IEEE80211_CAP_ESS)
2561 bss->mode = G_SUPPLICANT_MODE_INFRA;
2562 else if (capabilities & IEEE80211_CAP_IBSS)
2563 bss->mode = G_SUPPLICANT_MODE_IBSS;
2565 if (capabilities & IEEE80211_CAP_PRIVACY)
2566 bss->privacy = TRUE;
2567 } else if (g_strcmp0(key, "Mode") == 0) {
2568 const char *mode = NULL;
2570 dbus_message_iter_get_basic(iter, &mode);
2571 bss->mode = string2mode(mode);
2572 } else if (g_strcmp0(key, "Frequency") == 0) {
2573 dbus_uint16_t frequency = 0;
2575 dbus_message_iter_get_basic(iter, &frequency);
2576 bss->frequency = frequency;
2577 } else if (g_strcmp0(key, "Signal") == 0) {
2578 dbus_int16_t signal = 0;
2580 dbus_message_iter_get_basic(iter, &signal);
2582 bss->signal = signal;
2584 bss->signal = BSS_UNKNOWN_STRENGTH;
2586 } else if (g_strcmp0(key, "Level") == 0) {
2587 dbus_int32_t level = 0;
2589 dbus_message_iter_get_basic(iter, &level);
2590 } else if (g_strcmp0(key, "Rates") == 0) {
2591 supplicant_dbus_array_foreach(iter, bss_rates, bss);
2592 } else if (g_strcmp0(key, "MaxRate") == 0) {
2593 dbus_uint32_t maxrate = 0;
2595 dbus_message_iter_get_basic(iter, &maxrate);
2597 bss->maxrate = maxrate;
2598 } else if (g_strcmp0(key, "Privacy") == 0) {
2599 dbus_bool_t privacy = FALSE;
2601 dbus_message_iter_get_basic(iter, &privacy);
2602 bss->privacy = privacy;
2603 } else if (g_strcmp0(key, "RSN") == 0) {
2604 bss->rsn_selected = TRUE;
2606 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2607 } else if (g_strcmp0(key, "WPA") == 0) {
2608 bss->rsn_selected = FALSE;
2610 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
2611 #if defined TIZEN_EXT
2612 } else if (g_strcmp0(key, "HS20") == 0) {
2613 dbus_bool_t hs20 = FALSE;
2614 dbus_message_iter_get_basic(iter, &hs20);
2617 } else if (g_strcmp0(key, "IEs") == 0)
2618 bss_process_ies(iter, bss);
2620 SUPPLICANT_DBG("key %s type %c",
2621 key, dbus_message_iter_get_arg_type(iter));
2624 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
2627 GSupplicantInterface *interface = user_data;
2628 GSupplicantNetwork *network;
2629 struct g_supplicant_bss *bss;
2630 const char *path = NULL;
2634 dbus_message_iter_get_basic(iter, &path);
2638 if (g_strcmp0(path, "/") == 0)
2641 SUPPLICANT_DBG("%s", path);
2643 network = g_hash_table_lookup(interface->bss_mapping, path);
2645 bss = g_hash_table_lookup(network->bss_table, path);
2650 bss = g_try_new0(struct g_supplicant_bss, 1);
2654 bss->interface = interface;
2655 bss->path = g_strdup(path);
2656 bss->signal = BSS_UNKNOWN_STRENGTH;
2661 static void interface_bss_added_with_keys(DBusMessageIter *iter,
2664 struct g_supplicant_bss *bss;
2668 bss = interface_bss_added(iter, user_data);
2672 dbus_message_iter_next(iter);
2674 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
2677 supplicant_dbus_property_foreach(iter, bss_property, bss);
2679 bss_compute_security(bss);
2680 if (add_or_replace_bss_to_network(bss) < 0)
2681 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
2684 static void interface_bss_added_without_keys(DBusMessageIter *iter,
2687 struct g_supplicant_bss *bss;
2691 bss = interface_bss_added(iter, user_data);
2695 supplicant_dbus_property_get_all(bss->path,
2696 SUPPLICANT_INTERFACE ".BSS",
2697 bss_property, bss, NULL);
2699 bss_compute_security(bss);
2700 if (add_or_replace_bss_to_network(bss) < 0)
2701 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
2704 static void update_signal(gpointer key, gpointer value,
2707 struct g_supplicant_bss *bss = value;
2708 GSupplicantNetwork *network = user_data;
2710 if (bss->signal > network->signal) {
2711 network->signal = bss->signal;
2712 network->best_bss = bss;
2716 static void update_network_signal(GSupplicantNetwork *network)
2718 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
2721 g_hash_table_foreach(network->bss_table,
2722 update_signal, network);
2724 SUPPLICANT_DBG("New network signal %d", network->signal);
2727 static void interface_current_bss(GSupplicantInterface *interface,
2728 DBusMessageIter *iter)
2730 GSupplicantNetwork *network;
2731 struct g_supplicant_bss *bss;
2734 dbus_message_iter_get_basic(iter, &path);
2735 if (g_strcmp0(path, "/") == 0) {
2736 interface->current_network = NULL;
2740 interface_bss_added_without_keys(iter, interface);
2742 network = g_hash_table_lookup(interface->bss_mapping, path);
2746 bss = g_hash_table_lookup(network->bss_table, path);
2750 interface->current_network = network;
2752 if (bss != network->best_bss) {
2754 * This is the case where either wpa_s got associated
2755 * to a BSS different than the one ConnMan considers
2756 * the best, or we are roaming.
2758 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2760 network->best_bss = bss;
2762 if (network->signal != bss->signal) {
2763 SUPPLICANT_DBG("New network signal %d dBm",
2766 network->signal = bss->signal;
2767 callback_network_changed(network, "Signal");
2772 * wpa_s could notify about CurrentBSS in any state once
2773 * it got associated. It is not sure such notification will
2774 * arrive together with transition to ASSOCIATED state.
2775 * In fact, for networks with security WEP or OPEN, it
2776 * always arrives together with transition to COMPLETED.
2778 switch (interface->state) {
2779 case G_SUPPLICANT_STATE_UNKNOWN:
2780 case G_SUPPLICANT_STATE_DISABLED:
2781 case G_SUPPLICANT_STATE_DISCONNECTED:
2782 case G_SUPPLICANT_STATE_INACTIVE:
2783 case G_SUPPLICANT_STATE_SCANNING:
2784 case G_SUPPLICANT_STATE_AUTHENTICATING:
2785 case G_SUPPLICANT_STATE_ASSOCIATING:
2787 case G_SUPPLICANT_STATE_ASSOCIATED:
2788 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
2789 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
2790 case G_SUPPLICANT_STATE_COMPLETED:
2791 callback_network_associated(network);
2796 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
2798 GSupplicantInterface *interface = user_data;
2799 GSupplicantNetwork *network;
2800 struct g_supplicant_bss *bss = NULL;
2801 const char *path = NULL;
2802 bool is_current_network_bss = false;
2804 dbus_message_iter_get_basic(iter, &path);
2808 network = g_hash_table_lookup(interface->bss_mapping, path);
2812 bss = g_hash_table_lookup(network->bss_table, path);
2813 if (network->best_bss == bss) {
2814 network->best_bss = NULL;
2815 network->signal = BSS_UNKNOWN_STRENGTH;
2816 is_current_network_bss = true;
2819 g_hash_table_remove(bss_mapping, path);
2821 g_hash_table_remove(interface->bss_mapping, path);
2822 g_hash_table_remove(network->bss_table, path);
2824 update_network_signal(network);
2826 if (g_hash_table_size(network->bss_table) == 0) {
2827 g_hash_table_remove(interface->network_table, network->group);
2829 if (is_current_network_bss && network->best_bss)
2830 #if defined TIZEN_EXT
2831 callback_network_changed(network, "CheckMultiBssidConnect");
2833 callback_network_changed(network, "");
2838 static void set_config_methods(DBusMessageIter *iter, void *user_data)
2840 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
2843 static void wps_property(const char *key, DBusMessageIter *iter,
2846 GSupplicantInterface *interface = user_data;
2851 SUPPLICANT_DBG("key: %s", key);
2853 if (g_strcmp0(key, "ConfigMethods") == 0) {
2854 const char *config_methods = "push_button", *str = NULL;
2856 dbus_message_iter_get_basic(iter, &str);
2857 if (str && strlen(str) > 0) {
2858 /* It was already set at wpa_s level, don't modify it. */
2859 SUPPLICANT_DBG("%s", str);
2863 supplicant_dbus_property_set(interface->path,
2864 SUPPLICANT_INTERFACE ".Interface.WPS",
2865 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
2866 set_config_methods, NULL, &config_methods, NULL);
2868 SUPPLICANT_DBG("No value. Set %s", config_methods);
2873 static void interface_property(const char *key, DBusMessageIter *iter,
2876 GSupplicantInterface *interface = user_data;
2881 SUPPLICANT_DBG("%s", key);
2884 debug_strvalmap("KeyMgmt capability", keymgmt_map,
2885 interface->keymgmt_capa);
2886 debug_strvalmap("AuthAlg capability", authalg_capa_map,
2887 interface->authalg_capa);
2888 debug_strvalmap("Protocol capability", proto_capa_map,
2889 interface->proto_capa);
2890 debug_strvalmap("Pairwise capability", pairwise_map,
2891 interface->pairwise_capa);
2892 debug_strvalmap("Group capability", group_map,
2893 interface->group_capa);
2894 debug_strvalmap("Scan capability", scan_capa_map,
2895 interface->scan_capa);
2896 debug_strvalmap("Mode capability", mode_capa_map,
2897 interface->mode_capa);
2899 supplicant_dbus_property_get_all(interface->path,
2900 SUPPLICANT_INTERFACE ".Interface.WPS",
2901 wps_property, interface, interface);
2903 if (interface->ready)
2904 callback_interface_added(interface);
2909 if (g_strcmp0(key, "Capabilities") == 0) {
2910 supplicant_dbus_property_foreach(iter, interface_capability,
2912 #if !defined TIZEN_EXT
2913 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
2914 interface->p2p_support = true;
2916 #if defined TIZEN_EXT_WIFI_MESH
2917 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
2918 interface->mesh_support = true;
2920 } else if (g_strcmp0(key, "State") == 0) {
2921 const char *str = NULL;
2923 dbus_message_iter_get_basic(iter, &str);
2925 if (string2state(str) != interface->state) {
2926 interface->state = string2state(str);
2927 callback_interface_state(interface);
2930 if (interface->ap_create_in_progress) {
2931 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
2932 callback_ap_create_fail(interface);
2934 interface->ap_create_in_progress = false;
2937 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
2938 interface->ready = FALSE;
2940 interface->ready = TRUE;
2942 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
2943 } else if (g_strcmp0(key, "Scanning") == 0) {
2944 dbus_bool_t scanning = FALSE;
2946 dbus_message_iter_get_basic(iter, &scanning);
2947 interface->scanning = scanning;
2949 if (interface->ready) {
2950 if (interface->scanning)
2951 callback_scan_started(interface);
2953 callback_scan_finished(interface);
2955 } else if (g_strcmp0(key, "ApScan") == 0) {
2958 dbus_message_iter_get_basic(iter, &apscan);
2959 interface->apscan = apscan;
2960 } else if (g_strcmp0(key, "Ifname") == 0) {
2961 const char *str = NULL;
2963 dbus_message_iter_get_basic(iter, &str);
2965 g_free(interface->ifname);
2966 interface->ifname = g_strdup(str);
2968 } else if (g_strcmp0(key, "Driver") == 0) {
2969 const char *str = NULL;
2971 dbus_message_iter_get_basic(iter, &str);
2973 g_free(interface->driver);
2974 interface->driver = g_strdup(str);
2976 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
2977 const char *str = NULL;
2979 dbus_message_iter_get_basic(iter, &str);
2981 g_free(interface->bridge);
2982 interface->bridge = g_strdup(str);
2984 } else if (g_strcmp0(key, "ConfigFile") == 0) {
2985 const char *str = NULL;
2987 dbus_message_iter_get_basic(iter, &str);
2988 if (str && strlen(str) > 0 && interface->ifname) {
2989 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
2990 g_hash_table_replace(config_file_table,
2991 g_strdup(interface->ifname), g_strdup(str));
2993 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
2994 interface_current_bss(interface, iter);
2995 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
2996 #if defined TIZEN_EXT
2997 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
2999 interface_network_added(iter, interface);
3000 } else if (g_strcmp0(key, "BSSs") == 0) {
3001 supplicant_dbus_array_foreach(iter,
3002 interface_bss_added_without_keys,
3004 } else if (g_strcmp0(key, "Blobs") == 0) {
3006 } else if (g_strcmp0(key, "Networks") == 0) {
3007 supplicant_dbus_array_foreach(iter, interface_network_added,
3009 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3011 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3012 dbus_message_iter_get_basic(iter, &reason_code);
3013 callback_disconnect_reason_code(interface, reason_code);
3015 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3017 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3018 dbus_message_iter_get_basic(iter, &status_code);
3019 callback_assoc_status_code(interface, status_code);
3022 SUPPLICANT_DBG("key %s type %c",
3023 key, dbus_message_iter_get_arg_type(iter));
3027 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3029 GSupplicantInterface *interface = user_data;
3030 GSupplicantNetwork *network;
3036 dbus_message_iter_get_basic(iter, &path);
3041 if (g_strcmp0(path, "/") == 0)
3044 /* Update the network details based on scan BSS data */
3045 network = g_hash_table_lookup(interface->bss_mapping, path);
3047 callback_network_added(network);
3050 static void scan_bss_data(const char *key, DBusMessageIter *iter,
3053 GSupplicantInterface *interface = user_data;
3055 /*Fixed : stucking in scanning state when scan failed*/
3056 #if defined TIZEN_EXT
3057 GSupplicantInterfaceCallback scan_callback;
3061 supplicant_dbus_array_foreach(iter, scan_network_update,
3064 #if defined TIZEN_EXT
3065 scan_callback = interface->scan_callback;
3068 if (interface->scan_callback)
3069 interface->scan_callback(0, interface, interface->scan_data);
3071 #if defined TIZEN_EXT
3072 if (interface->scan_callback == scan_callback) {
3074 interface->scan_callback = NULL;
3075 interface->scan_data = NULL;
3076 #if defined TIZEN_EXT
3081 static GSupplicantInterface *interface_alloc(const char *path)
3083 GSupplicantInterface *interface;
3085 interface = g_try_new0(GSupplicantInterface, 1);
3089 interface->path = g_strdup(path);
3091 interface->network_table = g_hash_table_new_full(g_str_hash,
3092 g_str_equal, NULL, remove_network);
3093 interface->peer_table = g_hash_table_new_full(g_str_hash,
3094 g_str_equal, NULL, remove_peer);
3095 interface->group_table = g_hash_table_new_full(g_str_hash,
3096 g_str_equal, NULL, remove_group);
3097 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
3100 g_hash_table_replace(interface_table, interface->path, interface);
3105 static void interface_added(DBusMessageIter *iter, void *user_data)
3107 GSupplicantInterface *interface;
3108 const char *path = NULL;
3109 bool properties_appended = GPOINTER_TO_UINT(user_data);
3113 dbus_message_iter_get_basic(iter, &path);
3117 if (g_strcmp0(path, "/") == 0)
3120 interface = g_hash_table_lookup(interface_table, path);
3124 interface = interface_alloc(path);
3128 if (!properties_appended) {
3129 supplicant_dbus_property_get_all(path,
3130 SUPPLICANT_INTERFACE ".Interface",
3131 interface_property, interface,
3136 dbus_message_iter_next(iter);
3137 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3138 supplicant_dbus_property_foreach(iter, interface_property,
3140 interface_property(NULL, NULL, interface);
3144 static void interface_removed(DBusMessageIter *iter, void *user_data)
3146 const char *path = NULL;
3147 GSupplicantInterface *interface = user_data;
3149 dbus_message_iter_get_basic(iter, &path);
3153 interface = g_hash_table_lookup(interface_table, path);
3154 g_supplicant_interface_cancel(interface);
3156 g_hash_table_remove(interface_table, path);
3159 static void eap_method(DBusMessageIter *iter, void *user_data)
3161 const char *str = NULL;
3164 dbus_message_iter_get_basic(iter, &str);
3168 for (i = 0; eap_method_map[i].str; i++)
3169 if (strcmp(str, eap_method_map[i].str) == 0) {
3170 eap_methods |= eap_method_map[i].val;
3175 static void service_property(const char *key, DBusMessageIter *iter,
3179 callback_system_ready();
3183 if (g_strcmp0(key, "DebugLevel") == 0) {
3184 const char *str = NULL;
3187 dbus_message_iter_get_basic(iter, &str);
3188 for (i = 0; debug_strings[i]; i++)
3189 if (g_strcmp0(debug_strings[i], str) == 0) {
3193 SUPPLICANT_DBG("Debug level %d", debug_level);
3194 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
3195 dbus_message_iter_get_basic(iter, &debug_timestamp);
3196 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
3197 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
3198 dbus_message_iter_get_basic(iter, &debug_showkeys);
3199 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
3200 } else if (g_strcmp0(key, "Interfaces") == 0) {
3201 supplicant_dbus_array_foreach(iter, interface_added, NULL);
3202 } else if (g_strcmp0(key, "EapMethods") == 0) {
3203 supplicant_dbus_array_foreach(iter, eap_method, NULL);
3204 debug_strvalmap("EAP method", eap_method_map, eap_methods);
3205 } else if (g_strcmp0(key, "Country") == 0) {
3206 const char *country = NULL;
3208 dbus_message_iter_get_basic(iter, &country);
3209 SUPPLICANT_DBG("Country %s", country);
3211 SUPPLICANT_DBG("key %s type %c",
3212 key, dbus_message_iter_get_arg_type(iter));
3215 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
3217 const char *name = NULL, *old = NULL, *new = NULL;
3221 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
3224 dbus_message_iter_get_basic(iter, &name);
3228 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
3231 dbus_message_iter_next(iter);
3232 dbus_message_iter_get_basic(iter, &old);
3233 dbus_message_iter_next(iter);
3234 dbus_message_iter_get_basic(iter, &new);
3239 if (strlen(old) > 0 && strlen(new) == 0) {
3240 system_available = FALSE;
3241 g_hash_table_remove_all(bss_mapping);
3242 g_hash_table_remove_all(peer_mapping);
3243 g_hash_table_remove_all(group_mapping);
3244 g_hash_table_remove_all(config_file_table);
3245 g_hash_table_remove_all(interface_table);
3246 callback_system_killed();
3249 if (strlen(new) > 0 && strlen(old) == 0) {
3250 system_available = TRUE;
3251 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
3252 SUPPLICANT_INTERFACE,
3253 service_property, NULL, NULL);
3257 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
3261 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
3264 supplicant_dbus_property_foreach(iter, service_property, NULL);
3267 static void signal_interface_added(const char *path, DBusMessageIter *iter)
3269 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
3271 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
3272 interface_added(iter, GUINT_TO_POINTER(true));
3275 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
3279 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
3280 interface_removed(iter, NULL);
3283 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
3285 GSupplicantInterface *interface;
3289 interface = g_hash_table_lookup(interface_table, path);
3293 supplicant_dbus_property_foreach(iter, interface_property, interface);
3296 static void signal_scan_done(const char *path, DBusMessageIter *iter)
3298 GSupplicantInterface *interface;
3299 dbus_bool_t success = FALSE;
3303 interface = g_hash_table_lookup(interface_table, path);
3307 dbus_message_iter_get_basic(iter, &success);
3309 if (interface->scanning) {
3310 callback_scan_finished(interface);
3311 interface->scanning = FALSE;
3315 * If scan is unsuccessful return -EIO else get the scanned BSSs
3316 * and update the network details accordingly
3319 if (interface->scan_callback)
3320 interface->scan_callback(-EIO, interface,
3321 interface->scan_data);
3323 interface->scan_callback = NULL;
3324 interface->scan_data = NULL;
3329 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
3330 "BSSs", scan_bss_data, interface, interface);
3333 static void signal_bss_added(const char *path, DBusMessageIter *iter)
3335 GSupplicantInterface *interface;
3339 interface = g_hash_table_lookup(interface_table, path);
3343 interface_bss_added_with_keys(iter, interface);
3346 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
3348 GSupplicantInterface *interface;
3352 interface = g_hash_table_lookup(interface_table, path);
3356 interface_bss_removed(iter, interface);
3359 static void signal_network_added(const char *path, DBusMessageIter *iter)
3361 GSupplicantInterface *interface;
3365 interface = g_hash_table_lookup(interface_table, path);
3369 interface_network_added(iter, interface);
3372 static void signal_network_removed(const char *path, DBusMessageIter *iter)
3374 GSupplicantInterface *interface;
3378 interface = g_hash_table_lookup(interface_table, path);
3382 interface_network_removed(iter, interface);
3384 #if defined TIZEN_EXT
3385 void *copy_vsie_list(gconstpointer src, gpointer data)
3387 return g_strdup(src);
3392 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
3394 GSupplicantInterface *interface;
3395 GSupplicantNetwork *network;
3396 GSupplicantSecurity old_security;
3397 struct g_supplicant_bss *bss;
3401 interface = g_hash_table_lookup(bss_mapping, path);
3405 network = g_hash_table_lookup(interface->bss_mapping, path);
3409 bss = g_hash_table_lookup(network->bss_table, path);
3413 supplicant_dbus_property_foreach(iter, bss_property, bss);
3414 #if defined TIZEN_EXT
3415 network->frequency = bss->frequency;
3416 network->phy_mode = bss->phy_mode;
3418 old_security = network->security;
3419 bss_compute_security(bss);
3421 if (old_security != bss->security) {
3422 struct g_supplicant_bss *new_bss;
3424 SUPPLICANT_DBG("New network security for %s", bss->ssid);
3426 /* Security change policy:
3427 * - we first copy the current bss into a new one with
3428 * its own pointer (path)
3429 * - we remove the current bss related network which will
3430 * tell the plugin about such removal. This is done due
3431 * to the fact that a security change means a group change
3432 * so a complete network change.
3433 * (current bss becomes invalid as well)
3434 * - we add the new bss: it adds new network and tell the
3435 * plugin about it. */
3437 new_bss = g_try_new0(struct g_supplicant_bss, 1);
3441 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
3442 new_bss->path = g_strdup(bss->path);
3443 #if defined TIZEN_EXT
3444 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
3447 g_hash_table_remove(interface->network_table, network->group);
3449 if (add_or_replace_bss_to_network(new_bss) < 0) {
3450 /* Remove entries in hash tables to handle the
3451 * failure in add_or_replace_bss_to_network
3453 g_hash_table_remove(bss_mapping, path);
3454 g_hash_table_remove(interface->bss_mapping, path);
3455 g_hash_table_remove(network->bss_table, path);
3461 #if defined TIZEN_EXT
3462 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
3463 network->wps = TRUE;
3464 network->wps_capabilities |= bss->wps_capabilities;
3466 network->wps = FALSE;
3469 /* Consider only property changes of the connected BSS */
3470 if (network == interface->current_network && bss != network->best_bss)
3473 if (bss->signal == network->signal)
3478 callback_network_changed(network, "");
3484 * If the new signal is lower than the SSID signal, we need
3485 * to check for the new maximum.
3487 if (bss->signal < network->signal) {
3488 if (bss != network->best_bss)
3493 callback_network_changed(network, "");
3497 network->signal = bss->signal;
3498 update_network_signal(network);
3500 network->signal = bss->signal;
3501 network->best_bss = bss;
3504 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
3507 callback_network_changed(network, "Signal");
3510 static void wps_credentials(const char *key, DBusMessageIter *iter,
3513 GSupplicantInterface *interface = user_data;
3518 SUPPLICANT_DBG("key %s", key);
3520 if (g_strcmp0(key, "Key") == 0) {
3521 DBusMessageIter array;
3522 unsigned char *key_val;
3525 dbus_message_iter_recurse(iter, &array);
3526 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
3528 g_free(interface->wps_cred.key);
3529 interface->wps_cred.key = g_try_malloc0(
3530 sizeof(char) * key_len + 1);
3532 if (!interface->wps_cred.key)
3535 memcpy(interface->wps_cred.key, key_val,
3536 sizeof(char) * key_len);
3538 SUPPLICANT_DBG("WPS key present");
3539 } else if (g_strcmp0(key, "SSID") == 0) {
3540 DBusMessageIter array;
3541 unsigned char *ssid;
3544 dbus_message_iter_recurse(iter, &array);
3545 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3547 if (ssid_len > 0 && ssid_len < 33) {
3548 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
3549 interface->wps_cred.ssid_len = ssid_len;
3551 memset(interface->wps_cred.ssid, 0, 32);
3552 interface->wps_cred.ssid_len = 0;
3557 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
3559 GSupplicantInterface *interface;
3563 interface = g_hash_table_lookup(interface_table, path);
3567 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
3570 static void wps_event_args(const char *key, DBusMessageIter *iter,
3573 GSupplicantInterface *interface = user_data;
3575 if (!key || !interface)
3578 SUPPLICANT_DBG("Arg Key %s", key);
3581 static void signal_wps_event(const char *path, DBusMessageIter *iter)
3583 GSupplicantInterface *interface;
3584 const char *name = NULL;
3588 interface = g_hash_table_lookup(interface_table, path);
3592 dbus_message_iter_get_basic(iter, &name);
3594 SUPPLICANT_DBG("Name: %s", name);
3596 if (g_strcmp0(name, "success") == 0)
3597 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
3598 else if (g_strcmp0(name, "failed") == 0)
3599 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
3601 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
3603 if (!dbus_message_iter_has_next(iter))
3606 dbus_message_iter_next(iter);
3608 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
3611 #if defined TIZEN_EXT
3612 static void signal_power_off(const char *path, DBusMessageIter *iter)
3614 int poweroff_state = 0;
3616 dbus_message_iter_get_basic(iter, &poweroff_state);
3618 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
3620 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
3621 if (poweroff_state != 2 && poweroff_state != 3)
3624 if (callbacks_pointer == NULL)
3627 if (callbacks_pointer->system_power_off == NULL)
3630 callbacks_pointer->system_power_off();
3634 static void signal_station_connected(const char *path, DBusMessageIter *iter)
3636 GSupplicantInterface *interface;
3637 const char *sta_mac = NULL;
3639 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
3641 if (callbacks_pointer->add_station == NULL)
3644 if (g_strcmp0(path, "/") == 0)
3647 interface = g_hash_table_lookup(interface_table, path);
3648 if (interface == NULL)
3651 dbus_message_iter_get_basic(iter, &sta_mac);
3652 if (sta_mac == NULL)
3655 SUPPLICANT_DBG("New station %s connected", sta_mac);
3656 callbacks_pointer->add_station(sta_mac);
3659 static void signal_station_disconnected(const char *path, DBusMessageIter *iter)
3661 GSupplicantInterface *interface;
3662 const char *sta_mac = NULL;
3664 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
3666 if (callbacks_pointer->remove_station == NULL)
3669 if (g_strcmp0(path, "/") == 0)
3672 interface = g_hash_table_lookup(interface_table, path);
3673 if (interface == NULL)
3676 dbus_message_iter_get_basic(iter, &sta_mac);
3677 if (sta_mac == NULL)
3680 SUPPLICANT_DBG("Station %s disconnected", sta_mac);
3681 callbacks_pointer->remove_station(sta_mac);
3684 static void create_peer_identifier(GSupplicantPeer *peer)
3686 const unsigned char test[ETH_ALEN] = {};
3691 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
3692 peer->identifier = g_strdup(peer->name);
3696 peer->identifier = g_malloc0(19);
3697 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
3698 peer->device_address[0],
3699 peer->device_address[1],
3700 peer->device_address[2],
3701 peer->device_address[3],
3702 peer->device_address[4],
3703 peer->device_address[5]);
3706 struct peer_property_data {
3707 GSupplicantPeer *peer;
3709 bool groups_changed;
3710 bool services_changed;
3713 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
3715 struct peer_property_data *data = user_data;
3716 GSupplicantPeer *peer = data->peer;
3717 GSupplicantGroup *group;
3718 const char *str = NULL;
3721 dbus_message_iter_get_basic(iter, &str);
3725 group = g_hash_table_lookup(group_mapping, str);
3729 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
3731 data->old_groups = g_slist_remove_link(data->old_groups, elem);
3732 peer->groups = g_slist_concat(elem, peer->groups);
3734 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
3735 data->groups_changed = true;
3739 static void peer_property(const char *key, DBusMessageIter *iter,
3742 GSupplicantPeer *pending_peer;
3743 struct peer_property_data *data = user_data;
3744 GSupplicantPeer *peer = data->peer;
3746 SUPPLICANT_DBG("key: %s", key);
3748 if (!peer->interface)
3753 create_peer_identifier(peer);
3754 callback_peer_found(peer);
3755 pending_peer = g_hash_table_lookup(
3756 pending_peer_connection, peer->path);
3758 if (pending_peer && pending_peer == peer) {
3759 callback_peer_request(peer);
3760 g_hash_table_remove(pending_peer_connection,
3770 if (g_strcmp0(key, "DeviceAddress") == 0) {
3771 unsigned char *dev_addr;
3772 DBusMessageIter array;
3775 dbus_message_iter_recurse(iter, &array);
3776 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
3778 if (len == ETH_ALEN)
3779 memcpy(peer->device_address, dev_addr, len);
3780 } else if (g_strcmp0(key, "DeviceName") == 0) {
3781 const char *str = NULL;
3783 dbus_message_iter_get_basic(iter, &str);
3785 peer->name = g_strdup(str);
3786 } else if (g_strcmp0(key, "config_method") == 0) {
3787 uint16_t wps_config;
3789 dbus_message_iter_get_basic(iter, &wps_config);
3791 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
3792 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3793 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
3794 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3795 } else if (g_strcmp0(key, "Groups") == 0) {
3796 data->old_groups = peer->groups;
3797 peer->groups = NULL;
3799 supplicant_dbus_array_foreach(iter,
3800 peer_groups_relation, data);
3801 if (g_slist_length(data->old_groups) > 0) {
3802 g_slist_free_full(data->old_groups, g_free);
3803 data->groups_changed = true;
3805 } else if (g_strcmp0(key, "IEs") == 0) {
3806 DBusMessageIter array;
3810 dbus_message_iter_recurse(iter, &array);
3811 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3813 if (!ie || ie_len < 2)
3816 if (peer->widi_ies) {
3817 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
3820 g_free(peer->widi_ies);
3821 peer->widi_ies_length = 0;
3824 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
3826 memcpy(peer->widi_ies, ie, ie_len);
3827 peer->widi_ies_length = ie_len;
3828 data->services_changed = true;
3832 static void signal_peer_found(const char *path, DBusMessageIter *iter)
3834 struct peer_property_data *property_data;
3835 GSupplicantInterface *interface;
3836 const char *obj_path = NULL;
3837 GSupplicantPeer *peer;
3841 interface = g_hash_table_lookup(interface_table, path);
3845 dbus_message_iter_get_basic(iter, &obj_path);
3846 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3849 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3853 peer = g_try_new0(GSupplicantPeer, 1);
3857 peer->interface = interface;
3858 peer->path = g_strdup(obj_path);
3859 g_hash_table_insert(interface->peer_table, peer->path, peer);
3860 g_hash_table_replace(peer_mapping, peer->path, interface);
3862 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3863 property_data->peer = peer;
3865 dbus_message_iter_next(iter);
3866 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3867 supplicant_dbus_property_foreach(iter, peer_property,
3869 peer_property(NULL, NULL, property_data);
3873 supplicant_dbus_property_get_all(obj_path,
3874 SUPPLICANT_INTERFACE ".Peer",
3875 peer_property, property_data, NULL);
3878 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
3880 GSupplicantInterface *interface;
3881 const char *obj_path = NULL;
3882 GSupplicantPeer *peer;
3886 interface = g_hash_table_lookup(interface_table, path);
3890 dbus_message_iter_get_basic(iter, &obj_path);
3891 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
3894 peer = g_hash_table_lookup(interface->peer_table, obj_path);
3898 g_hash_table_remove(interface->peer_table, obj_path);
3901 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
3903 struct peer_property_data *property_data;
3904 GSupplicantInterface *interface;
3905 GSupplicantPeer *peer;
3909 interface = g_hash_table_lookup(peer_mapping, path);
3913 peer = g_hash_table_lookup(interface->peer_table, path);
3915 g_hash_table_remove(peer_mapping, path);
3919 property_data = dbus_malloc0(sizeof(struct peer_property_data));
3920 property_data->peer = peer;
3922 supplicant_dbus_property_foreach(iter, peer_property, property_data);
3923 if (property_data->services_changed)
3924 callback_peer_changed(peer,
3925 G_SUPPLICANT_PEER_SERVICES_CHANGED);
3927 if (property_data->groups_changed)
3928 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
3930 dbus_free(property_data);
3932 if (!g_supplicant_peer_is_in_a_group(peer))
3933 peer->connection_requested = false;
3936 struct group_sig_data {
3937 const char *peer_obj_path;
3938 unsigned char iface_address[ETH_ALEN];
3939 const char *interface_obj_path;
3940 const char *group_obj_path;
3944 static void group_sig_property(const char *key, DBusMessageIter *iter,
3947 struct group_sig_data *data = user_data;
3952 if (g_strcmp0(key, "peer_interface_addr") == 0) {
3953 unsigned char *dev_addr;
3954 DBusMessageIter array;
3957 dbus_message_iter_recurse(iter, &array);
3958 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
3960 if (len == ETH_ALEN)
3961 memcpy(data->iface_address, dev_addr, len);
3962 } else if (g_strcmp0(key, "role") == 0) {
3963 const char *str = NULL;
3965 dbus_message_iter_get_basic(iter, &str);
3966 if (g_strcmp0(str, "GO") == 0)
3967 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
3969 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
3970 } else if (g_strcmp0(key, "peer_object") == 0)
3971 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
3972 else if (g_strcmp0(key, "interface_object") == 0)
3973 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
3974 else if (g_strcmp0(key, "group_object") == 0)
3975 dbus_message_iter_get_basic(iter, &data->group_obj_path);
3979 static void signal_group_success(const char *path, DBusMessageIter *iter)
3981 GSupplicantInterface *interface;
3982 struct group_sig_data data = {};
3983 GSupplicantPeer *peer;
3987 interface = g_hash_table_lookup(interface_table, path);
3991 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
3992 if (!data.peer_obj_path)
3995 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
3999 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
4000 interface->pending_peer_path = peer->path;
4003 static void signal_group_failure(const char *path, DBusMessageIter *iter)
4005 GSupplicantInterface *interface;
4006 struct group_sig_data data = {};
4007 GSupplicantPeer *peer;
4011 interface = g_hash_table_lookup(interface_table, path);
4015 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4016 if (!data.peer_obj_path)
4019 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
4023 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
4024 peer->connection_requested = false;
4027 static void signal_group_started(const char *path, DBusMessageIter *iter)
4029 GSupplicantInterface *interface, *g_interface;
4030 struct group_sig_data data = {};
4031 GSupplicantGroup *group;
4032 GSupplicantPeer *peer;
4036 interface = g_hash_table_lookup(interface_table, path);
4040 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4041 if (!data.interface_obj_path || !data.group_obj_path)
4044 peer = g_hash_table_lookup(interface->peer_table,
4045 interface->pending_peer_path);
4046 interface->pending_peer_path = NULL;
4050 g_interface = g_hash_table_lookup(interface_table,
4051 data.interface_obj_path);
4055 group = g_hash_table_lookup(interface->group_table,
4056 data.group_obj_path);
4060 group = g_try_new0(GSupplicantGroup, 1);
4064 group->interface = g_interface;
4065 group->orig_interface = interface;
4066 group->path = g_strdup(data.group_obj_path);
4067 group->role = data.role;
4069 g_hash_table_insert(interface->group_table, group->path, group);
4070 g_hash_table_replace(group_mapping, group->path, group);
4072 peer->current_group_iface = g_interface;
4073 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
4076 static void remove_peer_group_interface(GHashTable *group_table,
4079 GSupplicantGroup *group;
4080 GHashTableIter iter;
4081 gpointer value, key;
4086 group = g_hash_table_lookup(group_table, path);
4088 if (!group || !group->orig_interface)
4091 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
4093 while (g_hash_table_iter_next(&iter, &key, &value)) {
4094 GSupplicantPeer *peer = value;
4096 if (peer->current_group_iface == group->interface)
4097 peer->current_group_iface = NULL;
4101 static void signal_group_finished(const char *path, DBusMessageIter *iter)
4103 GSupplicantInterface *interface;
4104 struct group_sig_data data = {};
4108 interface = g_hash_table_lookup(interface_table, path);
4112 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
4113 if (!data.interface_obj_path || !data.group_obj_path)
4116 remove_peer_group_interface(interface->group_table, data.group_obj_path);
4118 g_hash_table_remove(group_mapping, data.group_obj_path);
4120 g_hash_table_remove(interface->group_table, data.group_obj_path);
4123 static void signal_group_request(const char *path, DBusMessageIter *iter)
4125 GSupplicantInterface *interface;
4126 GSupplicantPeer *peer;
4127 const char *obj_path;
4131 interface = g_hash_table_lookup(interface_table, path);
4135 dbus_message_iter_get_basic(iter, &obj_path);
4136 if (!obj_path || !g_strcmp0(obj_path, "/"))
4139 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4144 * Peer has been previously found and property set,
4145 * otherwise, defer connection to when peer property
4148 if (peer->identifier)
4149 callback_peer_request(peer);
4151 g_hash_table_replace(pending_peer_connection, peer->path, peer);
4154 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
4156 const char *peer_path = NULL;
4157 GSupplicantInterface *interface;
4158 GSupplicantGroup *group;
4159 GSupplicantPeer *peer;
4163 group = g_hash_table_lookup(group_mapping, path);
4167 dbus_message_iter_get_basic(iter, &peer_path);
4171 interface = g_hash_table_lookup(peer_mapping, peer_path);
4175 peer = g_hash_table_lookup(interface->peer_table, peer_path);
4179 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
4181 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
4184 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
4186 const char *peer_path = NULL;
4187 GSupplicantInterface *interface;
4188 GSupplicantGroup *group;
4189 GSupplicantPeer *peer;
4194 group = g_hash_table_lookup(group_mapping, path);
4198 dbus_message_iter_get_basic(iter, &peer_path);
4202 for (elem = group->members; elem; elem = elem->next) {
4203 if (!g_strcmp0(elem->data, peer_path))
4211 group->members = g_slist_delete_link(group->members, elem);
4213 interface = g_hash_table_lookup(peer_mapping, peer_path);
4217 peer = g_hash_table_lookup(interface->peer_table, peer_path);
4221 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
4222 peer->connection_requested = false;
4225 #if defined TIZEN_EXT_WIFI_MESH
4226 const void *g_supplicant_interface_get_mesh_group_ssid(
4227 GSupplicantInterface *interface,
4228 unsigned int *ssid_len)
4233 if (!interface || interface->group_info.ssid_len == 0) {
4238 *ssid_len = interface->group_info.ssid_len;
4239 return interface->group_info.ssid;
4242 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
4247 return interface->group_info.disconnect_reason;
4250 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
4252 if (!mesh_peer || !mesh_peer->peer_address)
4255 return mesh_peer->peer_address;
4258 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
4263 return mesh_peer->disconnect_reason;
4266 static void callback_mesh_group_started(GSupplicantInterface *interface)
4268 if (!callbacks_pointer)
4271 if (!callbacks_pointer->mesh_group_started)
4274 callbacks_pointer->mesh_group_started(interface);
4277 static void callback_mesh_group_removed(GSupplicantInterface *interface)
4279 if (!callbacks_pointer)
4282 if (!callbacks_pointer->mesh_group_removed)
4285 callbacks_pointer->mesh_group_removed(interface);
4288 static void mesh_group_info(const char *key, DBusMessageIter *iter,
4291 GSupplicantInterface *interface = user_data;
4295 if (g_strcmp0(key, "SSID") == 0) {
4296 DBusMessageIter array;
4297 unsigned char *ssid;
4300 dbus_message_iter_recurse(iter, &array);
4301 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4303 if (ssid_len > 0 && ssid_len < 33) {
4304 memcpy(interface->group_info.ssid, ssid, ssid_len);
4305 interface->group_info.ssid_len = ssid_len;
4307 memset(interface->group_info.ssid, 0, 32);
4308 interface->group_info.ssid_len = 0;
4310 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
4311 int disconnect_reason = 0;
4312 dbus_message_iter_get_basic(iter, &disconnect_reason);
4313 interface->group_info.disconnect_reason = disconnect_reason;
4317 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
4319 GSupplicantInterface *interface;
4321 interface = g_hash_table_lookup(interface_table, path);
4325 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
4327 callback_mesh_group_started(interface);
4330 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
4332 GSupplicantInterface *interface;
4334 interface = g_hash_table_lookup(interface_table, path);
4338 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
4340 callback_mesh_group_removed(interface);
4343 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
4345 if (!callbacks_pointer)
4348 if (!callbacks_pointer->mesh_peer_connected)
4351 callbacks_pointer->mesh_peer_connected(mesh_peer);
4354 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
4356 if (!callbacks_pointer)
4359 if (!callbacks_pointer->mesh_peer_disconnected)
4362 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
4365 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
4368 GSupplicantMeshPeer *mesh_peer = user_data;
4372 if (g_strcmp0(key, "PeerAddress") == 0) {
4373 DBusMessageIter array;
4374 unsigned char *addr;
4377 dbus_message_iter_recurse(iter, &array);
4378 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
4380 if (addr_len == 6) {
4381 mesh_peer->peer_address = g_malloc0(19);
4382 snprintf(mesh_peer->peer_address, 19,
4383 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
4384 addr[2], addr[3], addr[4], addr[5]);
4386 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
4387 int disconnect_reason = 0;
4388 dbus_message_iter_get_basic(iter, &disconnect_reason);
4389 mesh_peer->disconnect_reason = disconnect_reason;
4393 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
4395 GSupplicantInterface *interface;
4396 GSupplicantMeshPeer *mesh_peer;
4398 interface = g_hash_table_lookup(interface_table, path);
4402 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
4403 mesh_peer->interface = interface;
4405 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
4407 callback_mesh_peer_connected(mesh_peer);
4408 g_free(mesh_peer->peer_address);
4412 static void signal_mesh_peer_disconnected(const char *path,
4413 DBusMessageIter *iter)
4415 GSupplicantInterface *interface;
4416 GSupplicantMeshPeer *mesh_peer;
4418 interface = g_hash_table_lookup(interface_table, path);
4422 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
4423 mesh_peer->interface = interface;
4425 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
4427 callback_mesh_peer_disconnected(mesh_peer);
4428 g_free(mesh_peer->peer_address);
4434 const char *interface;
4436 void (*function) (const char *path, DBusMessageIter *iter);
4438 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
4440 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
4441 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
4442 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
4443 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
4445 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
4446 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
4447 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
4448 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
4449 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
4450 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
4452 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
4454 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
4455 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
4456 #if defined TIZEN_EXT
4457 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
4460 { SUPPLICANT_INTERFACE".Interface", "StaAuthorized", signal_station_connected },
4461 { SUPPLICANT_INTERFACE".Interface", "StaDeauthorized", signal_station_disconnected },
4463 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
4464 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
4466 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
4468 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
4469 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
4470 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
4471 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
4472 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
4474 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
4475 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
4476 #if defined TIZEN_EXT_WIFI_MESH
4477 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
4478 signal_mesh_group_started },
4479 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
4480 signal_mesh_group_removed },
4481 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
4482 signal_mesh_peer_connected },
4483 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
4484 signal_mesh_peer_disconnected },
4490 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
4491 DBusMessage *message, void *data)
4493 DBusMessageIter iter;
4497 path = dbus_message_get_path(message);
4499 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4501 if (!dbus_message_iter_init(message, &iter))
4502 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4504 for (i = 0; signal_map[i].interface; i++) {
4505 if (!dbus_message_has_interface(message, signal_map[i].interface))
4508 if (!dbus_message_has_member(message, signal_map[i].member))
4511 signal_map[i].function(path, &iter);
4515 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4518 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
4520 SUPPLICANT_DBG("Cancelling any pending DBus calls");
4521 supplicant_dbus_method_call_cancel_all(interface);
4522 supplicant_dbus_property_call_cancel_all(interface);
4525 struct supplicant_regdom {
4526 GSupplicantCountryCallback callback;
4528 const void *user_data;
4531 static void country_result(const char *error,
4532 DBusMessageIter *iter, void *user_data)
4534 struct supplicant_regdom *regdom = user_data;
4537 SUPPLICANT_DBG("Country setting result");
4543 SUPPLICANT_DBG("Country setting failure %s", error);
4547 if (regdom->callback)
4548 regdom->callback(result, regdom->alpha2,
4549 (void *) regdom->user_data);
4554 static void country_params(DBusMessageIter *iter, void *user_data)
4556 struct supplicant_regdom *regdom = user_data;
4558 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
4562 int g_supplicant_set_country(const char *alpha2,
4563 GSupplicantCountryCallback callback,
4564 const void *user_data)
4566 struct supplicant_regdom *regdom;
4569 SUPPLICANT_DBG("Country setting %s", alpha2);
4571 if (!system_available)
4574 regdom = dbus_malloc0(sizeof(*regdom));
4578 regdom->callback = callback;
4579 regdom->alpha2 = alpha2;
4580 regdom->user_data = user_data;
4582 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
4583 "Country", DBUS_TYPE_STRING_AS_STRING,
4584 country_params, country_result,
4588 SUPPLICANT_DBG("Unable to set Country configuration");
4593 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
4594 GSupplicantCountryCallback callback,
4598 struct supplicant_regdom *regdom;
4601 regdom = dbus_malloc0(sizeof(*regdom));
4605 regdom->callback = callback;
4606 regdom->alpha2 = alpha2;
4607 regdom->user_data = user_data;
4609 ret = supplicant_dbus_property_set(interface->path,
4610 SUPPLICANT_INTERFACE ".Interface",
4611 "Country", DBUS_TYPE_STRING_AS_STRING,
4612 country_params, country_result,
4616 SUPPLICANT_DBG("Unable to set Country configuration");
4622 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
4627 return interface->p2p_support;
4630 struct supplicant_p2p_dev_config {
4635 static void p2p_device_config_result(const char *error,
4636 DBusMessageIter *iter, void *user_data)
4638 struct supplicant_p2p_dev_config *config = user_data;
4641 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
4644 g_free(config->device_name);
4645 g_free(config->dev_type);
4649 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
4651 int length, pos, end;
4656 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
4663 dev_type[length] = strtol(b, &e, 16);
4664 if (e && *e != '\0')
4673 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
4675 struct supplicant_p2p_dev_config *config = user_data;
4676 DBusMessageIter dict;
4678 supplicant_dbus_dict_open(iter, &dict);
4680 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
4681 DBUS_TYPE_STRING, &config->device_name);
4683 if (config->dev_type) {
4684 unsigned char dev_type[8] = {}, *type;
4687 len = dev_type_str2bin(config->dev_type, dev_type);
4690 supplicant_dbus_dict_append_fixed_array(&dict,
4691 "PrimaryDeviceType",
4692 DBUS_TYPE_BYTE, &type, len);
4696 supplicant_dbus_dict_close(iter, &dict);
4699 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
4700 const char *device_name,
4701 const char *primary_dev_type)
4703 struct supplicant_p2p_dev_config *config;
4706 SUPPLICANT_DBG("P2P Device settings %s/%s",
4707 device_name, primary_dev_type);
4709 config = dbus_malloc0(sizeof(*config));
4713 config->device_name = g_strdup(device_name);
4714 config->dev_type = g_strdup(primary_dev_type);
4716 ret = supplicant_dbus_property_set(interface->path,
4717 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
4719 DBUS_TYPE_ARRAY_AS_STRING
4720 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
4721 DBUS_TYPE_STRING_AS_STRING
4722 DBUS_TYPE_VARIANT_AS_STRING
4723 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
4724 p2p_device_config_params,
4725 p2p_device_config_result, config, NULL);
4727 g_free(config->device_name);
4728 g_free(config->dev_type);
4730 SUPPLICANT_DBG("Unable to set P2P Device configuration");
4736 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
4739 const GSupplicantPeer *peer = value;
4740 const char *identifier = user_data;
4742 if (!g_strcmp0(identifier, peer->identifier))
4748 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
4749 const char *identifier)
4751 GSupplicantPeer *peer;
4753 peer = g_hash_table_find(interface->peer_table,
4754 peer_lookup_by_identifier,
4755 (void *) identifier);
4759 static void interface_create_data_free(struct interface_create_data *data)
4761 g_free(data->ifname);
4762 g_free(data->driver);
4763 g_free(data->bridge);
4764 #if defined TIZEN_EXT_WIFI_MESH
4765 g_free(data->parent_ifname);
4770 static bool interface_exists(GSupplicantInterface *interface,
4773 GSupplicantInterface *tmp;
4775 tmp = g_hash_table_lookup(interface_table, path);
4776 if (tmp && tmp == interface)
4782 static void interface_create_property(const char *key, DBusMessageIter *iter,
4785 struct interface_create_data *data = user_data;
4786 GSupplicantInterface *interface = data->interface;
4789 if (data->callback) {
4790 data->callback(0, data->interface, data->user_data);
4791 #if !defined TIZEN_EXT
4792 callback_p2p_support(interface);
4794 #if defined TIZEN_EXT_WIFI_MESH
4795 callback_mesh_support(interface);
4799 interface_create_data_free(data);
4802 interface_property(key, iter, interface);
4805 static void interface_create_result(const char *error,
4806 DBusMessageIter *iter, void *user_data)
4808 struct interface_create_data *data = user_data;
4809 const char *path = NULL;
4815 g_warning("error %s", error);
4820 dbus_message_iter_get_basic(iter, &path);
4826 if (!system_available) {
4831 data->interface = g_hash_table_lookup(interface_table, path);
4832 if (!data->interface) {
4833 data->interface = interface_alloc(path);
4834 if (!data->interface) {
4840 err = supplicant_dbus_property_get_all(path,
4841 SUPPLICANT_INTERFACE ".Interface",
4842 interface_create_property, data,
4849 data->callback(err, NULL, data->user_data);
4851 interface_create_data_free(data);
4854 static void interface_create_params(DBusMessageIter *iter, void *user_data)
4856 struct interface_create_data *data = user_data;
4857 DBusMessageIter dict;
4858 char *config_file = NULL;
4862 supplicant_dbus_dict_open(iter, &dict);
4864 supplicant_dbus_dict_append_basic(&dict, "Ifname",
4865 DBUS_TYPE_STRING, &data->ifname);
4868 supplicant_dbus_dict_append_basic(&dict, "Driver",
4869 DBUS_TYPE_STRING, &data->driver);
4872 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
4873 DBUS_TYPE_STRING, &data->bridge);
4875 config_file = g_hash_table_lookup(config_file_table, data->ifname);
4877 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
4879 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
4880 DBUS_TYPE_STRING, &config_file);
4883 #if defined TIZEN_EXT_WIFI_MESH
4884 if (data->is_mesh_interface) {
4885 if (data->parent_ifname)
4886 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
4887 DBUS_TYPE_STRING, &data->parent_ifname);
4889 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
4890 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
4894 supplicant_dbus_dict_close(iter, &dict);
4897 static void interface_get_result(const char *error,
4898 DBusMessageIter *iter, void *user_data)
4900 struct interface_create_data *data = user_data;
4901 GSupplicantInterface *interface;
4902 const char *path = NULL;
4908 SUPPLICANT_DBG("Interface not created yet");
4912 dbus_message_iter_get_basic(iter, &path);
4918 interface = g_hash_table_lookup(interface_table, path);
4924 if (data->callback) {
4925 data->callback(0, interface, data->user_data);
4926 #if !defined TIZEN_EXT
4927 callback_p2p_support(interface);
4929 #if defined TIZEN_EXT_WIFI_MESH
4930 callback_mesh_support(interface);
4934 interface_create_data_free(data);
4939 if (!system_available) {
4944 SUPPLICANT_DBG("Creating interface");
4946 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
4947 SUPPLICANT_INTERFACE,
4949 interface_create_params,
4950 interface_create_result, data,
4957 data->callback(err, NULL, data->user_data);
4959 interface_create_data_free(data);
4962 static void interface_get_params(DBusMessageIter *iter, void *user_data)
4964 struct interface_create_data *data = user_data;
4968 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
4971 #if defined TIZEN_EXT_WIFI_MESH
4972 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
4973 const char *bridge, const char *parent_ifname,
4974 GSupplicantInterfaceCallback callback, void *user_data)
4976 struct interface_create_data *data;
4979 SUPPLICANT_DBG("ifname %s", ifname);
4981 if (!ifname || !parent_ifname)
4984 if (!system_available)
4987 data = dbus_malloc0(sizeof(*data));
4991 data->ifname = g_strdup(ifname);
4992 data->driver = g_strdup(driver);
4993 data->bridge = g_strdup(bridge);
4994 data->is_mesh_interface = true;
4995 data->parent_ifname = g_strdup(parent_ifname);
4996 data->callback = callback;
4997 data->user_data = user_data;
4999 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5000 SUPPLICANT_INTERFACE,
5002 interface_create_params,
5003 interface_create_result, data,
5008 struct interface_mesh_peer_data {
5011 GSupplicantInterface *interface;
5012 GSupplicantInterfaceCallback callback;
5016 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
5019 struct interface_mesh_peer_data *data = user_data;
5023 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
5026 static void interface_mesh_change_peer_result(const char *error,
5027 DBusMessageIter *iter, void *user_data)
5029 struct interface_mesh_peer_data *data = user_data;
5032 SUPPLICANT_DBG("%s", data->method);
5036 SUPPLICANT_DBG("error %s", error);
5040 data->callback(err, data->interface, data->user_data);
5042 g_free(data->peer_address);
5043 g_free(data->method);
5047 int g_supplicant_interface_mesh_peer_change_status(
5048 GSupplicantInterface *interface,
5049 GSupplicantInterfaceCallback callback, const char *peer_address,
5050 const char *method, void *user_data)
5052 struct interface_mesh_peer_data *data;
5058 data = dbus_malloc0(sizeof(*data));
5062 data->peer_address = g_strdup(peer_address);
5063 data->method = g_strdup(method);
5064 data->interface = interface;
5065 data->callback = callback;
5066 data->user_data = user_data;
5068 ret = supplicant_dbus_method_call(interface->path,
5069 SUPPLICANT_INTERFACE ".Interface.Mesh",
5070 method, interface_mesh_change_peer_params,
5071 interface_mesh_change_peer_result, data, NULL);
5073 g_free(data->peer_address);
5074 g_free(data->method);
5082 int g_supplicant_interface_create(const char *ifname, const char *driver,
5084 GSupplicantInterfaceCallback callback,
5087 struct interface_create_data *data;
5090 SUPPLICANT_DBG("ifname %s", ifname);
5095 if (!system_available)
5098 data = dbus_malloc0(sizeof(*data));
5102 data->ifname = g_strdup(ifname);
5103 data->driver = g_strdup(driver);
5104 data->bridge = g_strdup(bridge);
5105 data->callback = callback;
5106 data->user_data = user_data;
5108 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5109 SUPPLICANT_INTERFACE,
5111 interface_get_params,
5112 interface_get_result, data,
5115 interface_create_data_free(data);
5120 static void interface_remove_result(const char *error,
5121 DBusMessageIter *iter, void *user_data)
5123 struct interface_data *data = user_data;
5128 SUPPLICANT_DBG("error: %s", error);
5132 if (!system_available) {
5138 * The gsupplicant interface is already freed by the InterfaceRemoved
5139 * signal callback. Simply invoke the interface_data callback.
5147 data->callback(err, NULL, data->user_data);
5153 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
5155 struct interface_data *data = user_data;
5157 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
5158 &data->interface->path);
5162 int g_supplicant_interface_remove(GSupplicantInterface *interface,
5163 GSupplicantInterfaceCallback callback,
5166 struct interface_data *data;
5172 if (!system_available)
5175 g_supplicant_interface_cancel(interface);
5177 data = dbus_malloc0(sizeof(*data));
5181 data->interface = interface;
5182 data->path = g_strdup(interface->path);
5183 data->callback = callback;
5184 data->user_data = user_data;
5186 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
5187 SUPPLICANT_INTERFACE,
5189 interface_remove_params,
5190 interface_remove_result, data,
5199 static void interface_scan_result(const char *error,
5200 DBusMessageIter *iter, void *user_data)
5202 struct interface_scan_data *data = user_data;
5206 SUPPLICANT_DBG("error %s", error);
5210 /* A non ready interface cannot send/receive anything */
5211 if (interface_exists(data->interface, data->path)) {
5212 if (!data->interface->ready)
5220 data->callback(err, data->interface, data->user_data);
5222 data->interface->scan_callback = data->callback;
5223 data->interface->scan_data = data->user_data;
5226 if (data->scan_params)
5227 g_supplicant_free_scan_params(data->scan_params);
5232 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
5234 DBusMessageIter data;
5235 unsigned int width = 0; /* Not used by wpa_supplicant atm */
5237 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
5239 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
5240 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
5242 dbus_message_iter_close_container(iter, &data);
5245 static void add_scan_frequencies(DBusMessageIter *iter,
5248 GSupplicantScanParams *scan_data = user_data;
5252 for (i = 0; i < scan_data->num_freqs; i++) {
5253 freq = scan_data->freqs[i];
5257 add_scan_frequency(iter, freq);
5261 static void append_ssid(DBusMessageIter *iter,
5262 const void *ssid, unsigned int len)
5264 DBusMessageIter array;
5266 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
5267 DBUS_TYPE_BYTE_AS_STRING, &array);
5269 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
5271 dbus_message_iter_close_container(iter, &array);
5274 static void append_ssids(DBusMessageIter *iter, void *user_data)
5276 GSupplicantScanParams *scan_data = user_data;
5279 for (list = scan_data->ssids; list; list = list->next) {
5280 struct scan_ssid *scan_ssid = list->data;
5282 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
5286 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
5287 supplicant_dbus_array_function function,
5290 GSupplicantScanParams *scan_params = user_data;
5291 DBusMessageIter entry, value, array;
5292 const char *key = "Channels";
5294 if (scan_params->freqs && scan_params->freqs[0] != 0) {
5295 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
5298 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
5300 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
5301 DBUS_TYPE_ARRAY_AS_STRING
5302 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
5303 DBUS_TYPE_UINT32_AS_STRING
5304 DBUS_TYPE_UINT32_AS_STRING
5305 DBUS_STRUCT_END_CHAR_AS_STRING,
5308 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
5309 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
5310 DBUS_TYPE_UINT32_AS_STRING
5311 DBUS_TYPE_UINT32_AS_STRING
5312 DBUS_STRUCT_END_CHAR_AS_STRING,
5316 function(&array, user_data);
5318 dbus_message_iter_close_container(&value, &array);
5319 dbus_message_iter_close_container(&entry, &value);
5320 dbus_message_iter_close_container(dict, &entry);
5324 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
5326 DBusMessageIter dict;
5327 const char *type = "passive";
5328 struct interface_scan_data *data = user_data;
5330 supplicant_dbus_dict_open(iter, &dict);
5332 if (data && data->scan_params) {
5335 supplicant_dbus_dict_append_basic(&dict, "Type",
5336 DBUS_TYPE_STRING, &type);
5338 #if defined TIZEN_EXT
5339 SUPPLICANT_DBG("[specific_scan] num_ssids %d", data->scan_params->num_ssids);
5340 if (data->scan_params->num_ssids != 0)
5342 supplicant_dbus_dict_append_array(&dict, "SSIDs",
5347 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
5350 supplicant_dbus_dict_append_basic(&dict, "Type",
5351 DBUS_TYPE_STRING, &type);
5353 supplicant_dbus_dict_close(iter, &dict);
5356 static int interface_ready_to_scan(GSupplicantInterface *interface)
5361 if (!system_available)
5364 if (interface->scanning)
5367 switch (interface->state) {
5368 case G_SUPPLICANT_STATE_AUTHENTICATING:
5369 case G_SUPPLICANT_STATE_ASSOCIATING:
5370 case G_SUPPLICANT_STATE_ASSOCIATED:
5371 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
5372 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
5374 #if defined TIZEN_EXT
5375 case G_SUPPLICANT_STATE_DISABLED:
5377 case G_SUPPLICANT_STATE_UNKNOWN:
5379 case G_SUPPLICANT_STATE_UNKNOWN:
5380 case G_SUPPLICANT_STATE_DISABLED:
5382 case G_SUPPLICANT_STATE_DISCONNECTED:
5383 case G_SUPPLICANT_STATE_INACTIVE:
5384 case G_SUPPLICANT_STATE_SCANNING:
5385 case G_SUPPLICANT_STATE_COMPLETED:
5392 #if defined TIZEN_EXT_WIFI_MESH
5393 static void interface_abort_scan_result(const char *error,
5394 DBusMessageIter *iter, void *user_data)
5396 struct interface_scan_data *data = user_data;
5400 SUPPLICANT_DBG("error %s", error);
5407 data->callback(err, data->interface, data->user_data);
5412 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
5413 GSupplicantInterfaceCallback callback, void *user_data)
5415 struct interface_scan_data *data;
5418 if (!interface->scanning)
5421 data = dbus_malloc0(sizeof(*data));
5425 data->interface = interface;
5426 data->path = g_strdup(interface->path);
5427 data->callback = callback;
5428 data->user_data = user_data;
5430 ret = supplicant_dbus_method_call(interface->path,
5431 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
5432 interface_abort_scan_result, data, interface);
5443 int g_supplicant_interface_scan(GSupplicantInterface *interface,
5444 GSupplicantScanParams *scan_data,
5445 GSupplicantInterfaceCallback callback,
5448 struct interface_scan_data *data;
5451 ret = interface_ready_to_scan(interface);
5455 data = dbus_malloc0(sizeof(*data));
5459 data->interface = interface;
5460 data->path = g_strdup(interface->path);
5461 #if defined TIZEN_EXT
5462 data->interface->scan_callback = data->callback = callback;
5463 data->interface->scan_data = data->user_data = user_data;
5465 data->callback = callback;
5466 data->user_data = user_data;
5468 data->scan_params = scan_data;
5470 interface->scan_callback = callback;
5471 interface->scan_data = user_data;
5473 ret = supplicant_dbus_method_call(interface->path,
5474 SUPPLICANT_INTERFACE ".Interface", "Scan",
5475 interface_scan_params, interface_scan_result, data,
5486 #if defined TIZEN_EXT
5487 static void interface_signalpoll_result(const char *error,
5488 DBusMessageIter *iter, void *user_data)
5490 struct interface_signalpoll_data *data = user_data;
5492 dbus_int32_t maxspeed = 0;
5493 DBusMessageIter sub_iter, dict;
5497 SUPPLICANT_DBG("error: %s", error);
5501 dbus_message_iter_get_arg_type(iter);
5502 dbus_message_iter_recurse(iter, &sub_iter);
5503 dbus_message_iter_recurse(&sub_iter, &dict);
5505 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
5506 DBusMessageIter entry, value;
5509 dbus_message_iter_recurse(&dict, &entry);
5510 dbus_message_iter_get_basic(&entry, &key);
5511 dbus_message_iter_next(&entry);
5512 dbus_message_iter_recurse(&entry, &value);
5514 switch (dbus_message_iter_get_arg_type(&value)) {
5515 case DBUS_TYPE_INT32:
5516 if (g_strcmp0(key, "linkspeed") == 0) {
5517 dbus_message_iter_get_basic(&value, &maxspeed);
5518 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
5522 dbus_message_iter_next(&dict);
5527 data->callback(err, maxspeed, data->user_data);
5533 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
5534 GSupplicantMaxSpeedCallback callback,
5537 struct interface_signalpoll_data *data;
5543 if (!system_available)
5546 data = dbus_malloc0(sizeof(*data));
5550 data->interface = interface;
5551 data->path = g_strdup(interface->path);
5552 data->callback = callback;
5553 data->user_data = user_data;
5555 ret = supplicant_dbus_method_call(interface->path,
5556 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
5557 NULL, interface_signalpoll_result, data,
5569 static int parse_supplicant_error(DBusMessageIter *iter)
5571 int err = -ECONNABORTED;
5577 /* If the given passphrase is malformed wpa_s returns
5578 * "invalid message format" but this error should be interpreted as
5581 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
5582 dbus_message_iter_get_basic(iter, &key);
5583 if (strncmp(key, "psk", 3) == 0 ||
5584 strncmp(key, "wep_key", 7) == 0 ||
5585 strcmp(key, "invalid message format") == 0) {
5589 dbus_message_iter_next(iter);
5595 static void interface_select_network_result(const char *error,
5596 DBusMessageIter *iter, void *user_data)
5598 struct interface_connect_data *data = user_data;
5605 #if defined TIZEN_EXT
5606 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
5608 SUPPLICANT_DBG("SelectNetwork error %s", error);
5610 err = parse_supplicant_error(iter);
5616 data->callback(err, data->interface, data->user_data);
5618 #if defined TIZEN_EXT
5619 g_free(data->ssid->ssid);
5620 g_free((char *)data->ssid->passphrase);
5626 static void interface_select_network_params(DBusMessageIter *iter,
5629 struct interface_connect_data *data = user_data;
5630 GSupplicantInterface *interface = data->interface;
5631 #if defined TIZEN_EXT
5632 GSupplicantSSID *ssid = data->ssid;
5635 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
5636 &interface->network_path);
5637 #if defined TIZEN_EXT
5638 if (!ssid->bssid_for_connect_len)
5639 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
5643 static void interface_add_network_result(const char *error,
5644 DBusMessageIter *iter, void *user_data)
5646 struct interface_connect_data *data = user_data;
5647 GSupplicantInterface *interface = data->interface;
5654 dbus_message_iter_get_basic(iter, &path);
5658 SUPPLICANT_DBG("PATH: %s", path);
5660 #if defined TIZEN_EXT
5661 if (interface->network_path)
5662 g_free(interface->network_path);
5664 interface->network_path = g_strdup(path);
5666 store_network_information(interface, data->ssid);
5668 #if defined TIZEN_EXT
5669 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
5670 GSupplicantSSID *ssid = data->ssid;
5672 if (!ssid->bssid_for_connect_len)
5673 supplicant_dbus_method_call(data->interface->path,
5674 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
5675 interface_select_network_params,
5676 interface_select_network_result, data,
5679 supplicant_dbus_method_call(data->interface->path,
5680 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
5681 interface_select_network_params,
5682 interface_select_network_result, data,
5685 supplicant_dbus_method_call(data->interface->path,
5686 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
5687 interface_select_network_params,
5688 interface_select_network_result, data,
5695 SUPPLICANT_DBG("AddNetwork error %s", error);
5697 if (interface_exists(data->interface, data->interface->path)) {
5698 err = parse_supplicant_error(iter);
5700 data->callback(err, data->interface, data->user_data);
5702 g_free(interface->network_path);
5703 interface->network_path = NULL;
5707 #if defined TIZEN_EXT
5708 g_free(data->ssid->ssid);
5709 g_free((char *)data->ssid->passphrase);
5715 static void add_network_security_none(DBusMessageIter *dict)
5717 const char *auth_alg = "OPEN";
5719 supplicant_dbus_dict_append_basic(dict, "auth_alg",
5720 DBUS_TYPE_STRING, &auth_alg);
5723 static void add_network_security_wep(DBusMessageIter *dict,
5724 GSupplicantSSID *ssid)
5726 const char *auth_alg = "OPEN SHARED";
5727 dbus_uint32_t key_index = 0;
5729 supplicant_dbus_dict_append_basic(dict, "auth_alg",
5730 DBUS_TYPE_STRING, &auth_alg);
5732 if (ssid->passphrase) {
5733 int size = strlen(ssid->passphrase);
5734 if (size == 10 || size == 26) {
5735 unsigned char *key = g_try_malloc(13);
5739 memset(tmp, 0, sizeof(tmp));
5743 for (i = 0; i < size / 2; i++) {
5744 memcpy(tmp, ssid->passphrase + (i * 2), 2);
5745 key[i] = (unsigned char) strtol(tmp, NULL, 16);
5748 supplicant_dbus_dict_append_fixed_array(dict,
5753 } else if (size == 5 || size == 13) {
5754 unsigned char *key = g_try_malloc(13);
5760 for (i = 0; i < size; i++)
5761 key[i] = (unsigned char) ssid->passphrase[i];
5763 supplicant_dbus_dict_append_fixed_array(dict,
5769 supplicant_dbus_dict_append_basic(dict,
5774 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
5775 DBUS_TYPE_UINT32, &key_index);
5779 static dbus_bool_t is_psk_raw_key(const char *psk)
5783 /* A raw key is always 64 bytes length... */
5784 if (strlen(psk) != 64)
5787 /* ... and its content is in hex representation */
5788 for (i = 0; i < 64; i++)
5789 if (!isxdigit((unsigned char) psk[i]))
5795 static unsigned char hexchar2bin(char c)
5797 if ((c >= '0') && (c <= '9'))
5799 else if ((c >= 'A') && (c <= 'F'))
5800 return c - 'A' + 10;
5801 else if ((c >= 'a') && (c <= 'f'))
5802 return c - 'a' + 10;
5807 static void hexstring2bin(const char *string, unsigned char *data,
5812 for (i = 0; i < data_len; i++)
5813 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
5814 hexchar2bin(string[i * 2 + 1]) << 0);
5817 static void add_network_security_psk(DBusMessageIter *dict,
5818 GSupplicantSSID *ssid)
5820 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
5821 const char *key = "psk";
5823 if (is_psk_raw_key(ssid->passphrase)) {
5824 unsigned char data[32];
5825 unsigned char *datap = data;
5827 /* The above pointer alias is required by D-Bus because
5828 * with D-Bus and GCC, non-heap-allocated arrays cannot
5829 * be passed directly by their base pointer. */
5831 hexstring2bin(ssid->passphrase, datap, sizeof(data));
5833 supplicant_dbus_dict_append_fixed_array(dict,
5834 key, DBUS_TYPE_BYTE,
5835 &datap, sizeof(data));
5837 supplicant_dbus_dict_append_basic(dict,
5838 key, DBUS_TYPE_STRING,
5843 static void add_network_security_tls(DBusMessageIter *dict,
5844 GSupplicantSSID *ssid)
5847 * For TLS, we at least need:
5848 * The client certificate
5849 * The client private key file
5850 * The client private key file password
5852 * The Authority certificate is optional.
5854 if (!ssid->client_cert_path)
5857 if (!ssid->private_key_path)
5860 #if !defined TIZEN_EXT
5861 if (!ssid->private_key_passphrase)
5865 if (ssid->ca_cert_path)
5866 supplicant_dbus_dict_append_basic(dict, "ca_cert",
5867 DBUS_TYPE_STRING, &ssid->ca_cert_path);
5869 supplicant_dbus_dict_append_basic(dict, "private_key",
5871 &ssid->private_key_path);
5872 #if !defined TIZEN_EXT
5873 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
5875 &ssid->private_key_passphrase);
5877 supplicant_dbus_dict_append_basic(dict, "client_cert",
5879 &ssid->client_cert_path);
5882 static void add_network_security_peap(DBusMessageIter *dict,
5883 GSupplicantSSID *ssid)
5888 * For PEAP/TTLS, we at least need
5889 * The authority certificate
5890 * The 2nd phase authentication method
5891 * The 2nd phase passphrase
5893 * The Client certificate is optional although strongly recommended
5894 * When setting it, we need in addition
5895 * The Client private key file
5896 * The Client private key file password
5898 if (!ssid->passphrase)
5901 if (!ssid->phase2_auth)
5904 if (ssid->client_cert_path) {
5905 if (!ssid->private_key_path)
5908 #if !defined TIZEN_EXT
5909 if (!ssid->private_key_passphrase)
5913 supplicant_dbus_dict_append_basic(dict, "client_cert",
5915 &ssid->client_cert_path);
5917 supplicant_dbus_dict_append_basic(dict, "private_key",
5919 &ssid->private_key_path);
5921 #if !defined TIZEN_EXT
5922 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
5924 &ssid->private_key_passphrase);
5929 if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
5930 phase2_auth = g_strdup_printf("autheap=%s",
5931 ssid->phase2_auth + strlen("EAP-"));
5933 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
5935 supplicant_dbus_dict_append_basic(dict, "password",
5939 if (ssid->ca_cert_path)
5940 supplicant_dbus_dict_append_basic(dict, "ca_cert",
5942 &ssid->ca_cert_path);
5944 supplicant_dbus_dict_append_basic(dict, "phase2",
5948 g_free(phase2_auth);
5951 #if defined TIZEN_EXT
5952 static void add_network_security_aka_sim(DBusMessageIter *dict,
5953 GSupplicantSSID *ssid)
5955 if (!ssid->passphrase)
5958 supplicant_dbus_dict_append_basic(dict, "password",
5963 static void add_network_security_fast(DBusMessageIter *dict,
5964 GSupplicantSSID *ssid)
5967 * For FAST, we at least need:
5969 * phase1 (provisiong information)
5973 /* Allow provisioing both authenticated and unauthenticated */
5974 const char *phase1 = "fast_provisioning=2";
5975 supplicant_dbus_dict_append_basic(dict, "phase1",
5979 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
5981 supplicant_dbus_dict_append_basic(dict, "pac_file",
5985 supplicant_dbus_dict_append_basic(dict, "password",
5991 static void add_network_security_eap(DBusMessageIter *dict,
5992 GSupplicantSSID *ssid)
5996 #if defined TIZEN_EXT
5999 if (!ssid->eap || !ssid->identity)
6003 if (g_strcmp0(ssid->eap, "tls") == 0) {
6004 add_network_security_tls(dict, ssid);
6005 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
6006 g_strcmp0(ssid->eap, "ttls") == 0) {
6007 #if defined TIZEN_EXT
6008 if (!ssid->identity)
6011 add_network_security_peap(dict, ssid);
6013 #if defined TIZEN_EXT
6014 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
6015 g_strcmp0(ssid->eap, "aka") == 0 ||
6016 g_strcmp0(ssid->eap, "aka'") == 0) {
6017 add_network_security_aka_sim(dict, ssid);
6018 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
6019 if(!ssid->passphrase)
6021 supplicant_dbus_dict_append_basic(dict, "password",
6024 } else if (g_strcmp0(ssid->eap, "fast") == 0){
6025 if (!ssid->identity || !ssid->passphrase)
6028 add_network_security_fast(dict, ssid);
6033 eap_value = g_ascii_strup(ssid->eap, -1);
6035 supplicant_dbus_dict_append_basic(dict, "eap",
6038 #if defined TIZEN_EXT
6039 if (ssid->identity != NULL)
6040 supplicant_dbus_dict_append_basic(dict, "identity",
6044 supplicant_dbus_dict_append_basic(dict, "identity",
6048 if(ssid->anonymous_identity)
6049 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
6051 &ssid->anonymous_identity);
6053 if(ssid->subject_match)
6054 supplicant_dbus_dict_append_basic(dict, "subject_match",
6056 &ssid->subject_match);
6058 if(ssid->altsubject_match)
6059 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
6061 &ssid->altsubject_match);
6063 if(ssid->domain_suffix_match)
6064 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
6066 &ssid->domain_suffix_match);
6068 if(ssid->domain_match)
6069 supplicant_dbus_dict_append_basic(dict, "domain_match",
6071 &ssid->domain_match);
6076 static void add_network_security_ciphers(DBusMessageIter *dict,
6077 GSupplicantSSID *ssid)
6079 unsigned int p_cipher, g_cipher, i;
6080 char *pairwise, *group;
6081 char *pair_ciphers[4];
6082 char *group_ciphers[5];
6084 p_cipher = ssid->pairwise_cipher;
6085 g_cipher = ssid->group_cipher;
6087 if (p_cipher == 0 && g_cipher == 0)
6092 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
6093 pair_ciphers[i++] = "CCMP";
6095 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
6096 pair_ciphers[i++] = "TKIP";
6098 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
6099 pair_ciphers[i++] = "NONE";
6101 pair_ciphers[i] = NULL;
6105 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
6106 group_ciphers[i++] = "CCMP";
6108 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
6109 group_ciphers[i++] = "TKIP";
6111 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
6112 group_ciphers[i++] = "WEP104";
6114 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
6115 group_ciphers[i++] = "WEP40";
6117 group_ciphers[i] = NULL;
6119 pairwise = g_strjoinv(" ", pair_ciphers);
6120 group = g_strjoinv(" ", group_ciphers);
6122 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
6124 supplicant_dbus_dict_append_basic(dict, "pairwise",
6127 supplicant_dbus_dict_append_basic(dict, "group",
6135 static void add_network_security_proto(DBusMessageIter *dict,
6136 GSupplicantSSID *ssid)
6138 unsigned int protocol, i;
6142 protocol = ssid->protocol;
6149 if (protocol & G_SUPPLICANT_PROTO_RSN)
6150 protos[i++] = "RSN";
6152 if (protocol & G_SUPPLICANT_PROTO_WPA)
6153 protos[i++] = "WPA";
6157 proto = g_strjoinv(" ", protos);
6159 SUPPLICANT_DBG("proto %s", proto);
6161 supplicant_dbus_dict_append_basic(dict, "proto",
6168 #if defined TIZEN_EXT_WIFI_MESH
6169 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid)
6171 if (ssid->security != G_SUPPLICANT_SECURITY_SAE)
6174 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
6179 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
6183 switch (ssid->security) {
6184 case G_SUPPLICANT_SECURITY_NONE:
6186 add_network_security_none(dict);
6187 add_network_security_ciphers(dict, ssid);
6189 case G_SUPPLICANT_SECURITY_UNKNOWN:
6190 case G_SUPPLICANT_SECURITY_WEP:
6192 add_network_security_wep(dict, ssid);
6193 add_network_security_ciphers(dict, ssid);
6195 case G_SUPPLICANT_SECURITY_PSK:
6196 key_mgmt = "WPA-PSK";
6197 add_network_security_psk(dict, ssid);
6198 add_network_security_ciphers(dict, ssid);
6199 add_network_security_proto(dict, ssid);
6201 case G_SUPPLICANT_SECURITY_IEEE8021X:
6202 key_mgmt = "WPA-EAP";
6203 add_network_security_eap(dict, ssid);
6204 add_network_security_ciphers(dict, ssid);
6205 add_network_security_proto(dict, ssid);
6207 #if defined TIZEN_EXT
6208 case G_SUPPLICANT_SECURITY_FT_PSK:
6209 key_mgmt = "FT-PSK";
6210 add_network_security_psk(dict, ssid);
6211 add_network_security_ciphers(dict, ssid);
6212 add_network_security_proto(dict, ssid);
6214 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
6215 key_mgmt = "FT-EAP";
6216 add_network_security_eap(dict, ssid);
6217 add_network_security_ciphers(dict, ssid);
6218 add_network_security_proto(dict, ssid);
6221 #if defined TIZEN_EXT_WIFI_MESH
6222 case G_SUPPLICANT_SECURITY_SAE:
6224 add_network_security_psk(dict, ssid);
6229 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
6230 DBUS_TYPE_STRING, &key_mgmt);
6233 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
6237 switch (ssid->mode) {
6238 case G_SUPPLICANT_MODE_UNKNOWN:
6239 case G_SUPPLICANT_MODE_INFRA:
6242 case G_SUPPLICANT_MODE_IBSS:
6245 case G_SUPPLICANT_MODE_MASTER:
6248 #if defined TIZEN_EXT_WIFI_MESH
6249 case G_SUPPLICANT_MODE_MESH:
6255 supplicant_dbus_dict_append_basic(dict, "mode",
6256 DBUS_TYPE_UINT32, &mode);
6259 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
6261 DBusMessageIter dict;
6262 struct interface_connect_data *data = user_data;
6263 GSupplicantSSID *ssid = data->ssid;
6265 supplicant_dbus_dict_open(iter, &dict);
6267 if (ssid->scan_ssid)
6268 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
6269 DBUS_TYPE_UINT32, &ssid->scan_ssid);
6272 supplicant_dbus_dict_append_basic(&dict, "frequency",
6273 DBUS_TYPE_UINT32, &ssid->freq);
6276 supplicant_dbus_dict_append_basic(&dict, "bgscan",
6277 DBUS_TYPE_STRING, &ssid->bgscan);
6279 add_network_mode(&dict, ssid);
6281 add_network_security(&dict, ssid);
6283 #if defined TIZEN_EXT_WIFI_MESH
6284 add_network_ieee80211w(&dict, ssid);
6287 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
6288 DBUS_TYPE_BYTE, &ssid->ssid,
6291 supplicant_dbus_dict_append_basic(&dict, "ignore_broadcast_ssid",
6293 &ssid->ignore_broadcast_ssid);
6295 #if defined TIZEN_EXT
6298 bssid = g_try_malloc0(18);
6299 if (bssid == NULL) {
6300 SUPPLICANT_DBG("memory allocation error");
6301 supplicant_dbus_dict_close(iter, &dict);
6305 if (ssid->bssid_for_connect_len)
6306 snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
6307 ssid->bssid_for_connect[0], ssid->bssid_for_connect[1], ssid->bssid_for_connect[2],
6308 ssid->bssid_for_connect[3], ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
6310 snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
6311 ssid->bssid[0], ssid->bssid[1], ssid->bssid[2],
6312 ssid->bssid[3], ssid->bssid[4], ssid->bssid[5]);
6314 supplicant_dbus_dict_append_basic(&dict, "bssid",
6315 DBUS_TYPE_STRING, &bssid);
6320 supplicant_dbus_dict_close(iter, &dict);
6323 static void interface_wps_start_result(const char *error,
6324 DBusMessageIter *iter, void *user_data)
6326 struct interface_connect_data *data = user_data;
6333 SUPPLICANT_DBG("error: %s", error);
6334 err = parse_supplicant_error(iter);
6338 data->callback(err, data->interface, data->user_data);
6345 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
6347 struct interface_connect_data *data = user_data;
6348 GSupplicantSSID *ssid = data->ssid;
6349 const char *role = "enrollee", *type;
6350 DBusMessageIter dict;
6354 supplicant_dbus_dict_open(iter, &dict);
6356 supplicant_dbus_dict_append_basic(&dict, "Role",
6357 DBUS_TYPE_STRING, &role);
6360 if (ssid->pin_wps) {
6362 supplicant_dbus_dict_append_basic(&dict, "Pin",
6363 DBUS_TYPE_STRING, &ssid->pin_wps);
6366 supplicant_dbus_dict_append_basic(&dict, "Type",
6367 DBUS_TYPE_STRING, &type);
6369 #if defined TIZEN_EXT
6371 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
6372 DBUS_TYPE_BYTE, &ssid->bssid, 6);
6375 supplicant_dbus_dict_close(iter, &dict);
6378 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
6380 struct interface_connect_data *data = user_data;
6385 SUPPLICANT_DBG("error: %s", error);
6391 #if defined TIZEN_EXT
6392 GSupplicantSSID *ssid = data->ssid;
6393 if (ssid->pin_wps != NULL) {
6394 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
6395 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
6402 supplicant_dbus_method_call(data->interface->path,
6403 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
6404 interface_add_wps_params,
6405 interface_wps_start_result, data, NULL);
6408 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
6410 dbus_bool_t credentials = TRUE;
6414 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
6418 #if defined TIZEN_EXT
6419 #define NETCONFIG_SERVICE "net.netconfig"
6420 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
6421 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
6423 struct dec_method_call_data {
6424 struct interface_connect_data *data;
6425 DBusPendingCall *pending_call;
6428 static struct dec_method_call_data decrypt_request_data;
6430 static void crypt_method_call_cancel(void)
6432 if (decrypt_request_data.pending_call) {
6433 dbus_pending_call_cancel(decrypt_request_data.pending_call);
6434 dbus_pending_call_unref(decrypt_request_data.pending_call);
6435 decrypt_request_data.pending_call = NULL;
6438 g_free(decrypt_request_data.data->path);
6439 g_free(decrypt_request_data.data->ssid);
6440 dbus_free(decrypt_request_data.data);
6441 decrypt_request_data.data = NULL;
6444 static void decryption_request_reply(DBusPendingCall *call,
6449 DBusMessageIter args;
6452 struct interface_connect_data *data = user_data;
6456 reply = dbus_pending_call_steal_reply(call);
6458 dbus_error_init(&error);
6459 if (dbus_set_error_from_message(&error, reply)) {
6460 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
6461 dbus_error_free(&error);
6466 if (dbus_message_iter_init(reply, &args) == FALSE) {
6467 SUPPLICANT_DBG("dbus_message_iter_init() failed");
6472 dbus_message_iter_get_basic(&args, &out_data);
6473 data->ssid->passphrase = g_strdup((const gchar *)out_data);
6475 ret = supplicant_dbus_method_call(data->interface->path,
6476 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
6477 interface_add_network_params,
6478 interface_add_network_result, data,
6483 SUPPLICANT_DBG("AddNetwork failed %d", ret);
6484 callback_assoc_failed(decrypt_request_data.data->user_data);
6486 g_free(data->ssid->ssid);
6487 g_free((char *)data->ssid->passphrase);
6492 dbus_message_unref(reply);
6493 dbus_pending_call_unref(call);
6495 decrypt_request_data.pending_call = NULL;
6496 decrypt_request_data.data = NULL;
6499 static int send_decryption_request(const char *passphrase,
6500 struct interface_connect_data *data)
6502 DBusMessage *msg = NULL;
6503 DBusPendingCall *call;
6505 SUPPLICANT_DBG("Decryption request");
6508 SUPPLICANT_DBG("Invalid parameter");
6515 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
6516 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
6520 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
6523 if (!dbus_connection_send_with_reply(connection, msg,
6524 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
6525 dbus_message_unref(msg);
6530 dbus_message_unref(msg);
6534 decrypt_request_data.pending_call = call;
6535 decrypt_request_data.data = data;
6537 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
6538 dbus_message_unref(msg);
6540 SUPPLICANT_DBG("Decryption request succeeded");
6546 int g_supplicant_interface_connect(GSupplicantInterface *interface,
6547 GSupplicantSSID *ssid,
6548 GSupplicantInterfaceCallback callback,
6551 struct interface_connect_data *data;
6552 struct interface_data *intf_data;
6560 if (!system_available)
6563 /* TODO: Check if we're already connected and switch */
6565 data = dbus_malloc0(sizeof(*data));
6569 data->interface = interface;
6570 data->path = g_strdup(interface->path);
6571 data->callback = callback;
6573 data->user_data = user_data;
6575 if (ssid->use_wps) {
6576 g_free(interface->wps_cred.key);
6577 memset(&interface->wps_cred, 0,
6578 sizeof(struct _GSupplicantWpsCredentials));
6580 ret = supplicant_dbus_property_set(interface->path,
6581 SUPPLICANT_INTERFACE ".Interface.WPS",
6582 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
6583 wps_process_credentials, wps_start, data, interface);
6585 /* By the time there is a request for connect and the network
6586 * path is not NULL it means that connman has not removed the
6587 * previous network pointer. This can happen in the case AP
6588 * deauthenticated client and connman does not remove the
6589 * previously connected network pointer. This causes supplicant
6590 * to reallocate the memory for struct wpa_ssid again even if it
6591 * is the same SSID. This causes memory usage of wpa_supplicnat
6592 * to go high. The idea here is that if the previously connected
6593 * network is not removed at the time of next connection attempt
6594 * check if the network path is not NULL. In case it is non-NULL
6595 * first remove the network and then once removal is successful, add
6599 if (interface->network_path != NULL) {
6604 * If this add network is for the same network for
6605 * which wpa_supplicant already has a profile then do
6606 * not need to add another profile. Only if the
6607 * profile that needs to get added is different from
6608 * what is there in wpa_s delete the current one. A
6609 * network is identified by its SSID, security_type
6610 * and passphrase (private passphrase in case security
6613 if (compare_network_parameters(interface, ssid)) {
6617 intf_data = dbus_malloc0(sizeof(*intf_data));
6621 intf_data->interface = interface;
6622 intf_data->path = g_strdup(interface->path);
6623 intf_data->callback = callback;
6624 intf_data->ssid = ssid;
6625 intf_data->user_data = user_data;
6626 intf_data->network_remove_in_progress = TRUE;
6627 network_remove(intf_data);
6629 #if defined TIZEN_EXT
6630 if (ssid->passphrase &&
6631 g_strcmp0(ssid->passphrase, "") != 0 &&
6632 #if defined TIZEN_EXT_WIFI_MESH
6633 ssid->mode != G_SUPPLICANT_MODE_MESH &&
6636 ret = send_decryption_request(ssid->passphrase, data);
6638 SUPPLICANT_DBG("Decryption request failed %d", ret);
6641 ret = supplicant_dbus_method_call(interface->path,
6642 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
6643 interface_add_network_params,
6644 interface_add_network_result, data,
6654 return -EINPROGRESS;
6657 static void network_remove_result(const char *error,
6658 DBusMessageIter *iter, void *user_data)
6660 struct interface_data *data = user_data;
6661 struct interface_connect_data *connect_data;
6668 SUPPLICANT_DBG("error: %s", error);
6670 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
6672 result = -ECONNABORTED;
6675 g_free(data->interface->network_path);
6676 data->interface->network_path = NULL;
6678 remove_network_information(data->interface);
6680 if (data->network_remove_in_progress == TRUE) {
6681 data->network_remove_in_progress = FALSE;
6682 connect_data = dbus_malloc0(sizeof(*connect_data));
6686 connect_data->interface = data->interface;
6687 connect_data->path = g_strdup(data->path);
6688 connect_data->callback = data->callback;
6689 connect_data->ssid = data->ssid;
6690 connect_data->user_data = data->user_data;
6692 #if defined TIZEN_EXT
6694 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
6695 && !data->ssid->eap) {
6696 ret = send_decryption_request(data->ssid->passphrase, connect_data);
6698 SUPPLICANT_DBG("Decryption request failed %d", ret);
6699 g_free(connect_data->ssid);
6700 g_free(connect_data->path);
6701 dbus_free(connect_data);
6705 supplicant_dbus_method_call(data->interface->path,
6706 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
6707 interface_add_network_params,
6708 interface_add_network_result, connect_data,
6709 connect_data->interface);
6712 data->callback(result, data->interface, data->user_data);
6718 static void network_remove_params(DBusMessageIter *iter, void *user_data)
6720 struct interface_data *data = user_data;
6721 const char *path = data->interface->network_path;
6723 SUPPLICANT_DBG("path %s", path);
6725 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
6728 static int network_remove(struct interface_data *data)
6730 GSupplicantInterface *interface = data->interface;
6734 #if defined TIZEN_EXT
6735 GSupplicantInterface *intf = NULL;
6737 * Check if 'interface' is valid
6739 intf = g_hash_table_lookup(interface_table, interface->path);
6744 return supplicant_dbus_method_call(interface->path,
6745 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
6746 network_remove_params, network_remove_result, data,
6750 static void interface_disconnect_result(const char *error,
6751 DBusMessageIter *iter, void *user_data)
6753 struct interface_data *data = user_data;
6760 SUPPLICANT_DBG("error: %s", error);
6762 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
6764 result = -ECONNABORTED;
6767 /* If we are disconnecting from previous WPS successful
6768 * association. i.e.: it did not went through AddNetwork,
6769 * and interface->network_path was never set. */
6770 if (!data->interface->network_path) {
6772 data->callback(result, data->interface,
6780 if (result < 0 && data->callback) {
6781 data->callback(result, data->interface, data->user_data);
6782 data->callback = NULL;
6785 if (result != -ECONNABORTED) {
6786 if (network_remove(data) < 0) {
6796 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
6797 GSupplicantInterfaceCallback callback,
6800 struct interface_data *data;
6808 if (!system_available)
6810 #if defined TIZEN_EXT
6811 if (decrypt_request_data.pending_call &&
6812 decrypt_request_data.data &&
6813 decrypt_request_data.data->user_data == user_data) {
6815 callback_assoc_failed(decrypt_request_data.data->user_data);
6816 crypt_method_call_cancel();
6821 data = dbus_malloc0(sizeof(*data));
6825 data->interface = interface;
6826 data->path = g_strdup(interface->path);
6827 data->callback = callback;
6828 data->user_data = user_data;
6830 ret = supplicant_dbus_method_call(interface->path,
6831 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
6832 NULL, interface_disconnect_result, data,
6843 static void interface_p2p_find_result(const char *error,
6844 DBusMessageIter *iter, void *user_data)
6846 struct interface_scan_data *data = user_data;
6849 SUPPLICANT_DBG("error %s", error);
6854 if (interface_exists(data->interface, data->path)) {
6855 if (!data->interface->ready)
6858 data->interface->p2p_finding = true;
6862 data->callback(err, data->interface, data->user_data);
6868 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
6870 DBusMessageIter dict;
6872 supplicant_dbus_dict_open(iter, &dict);
6873 supplicant_dbus_dict_close(iter, &dict);
6876 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
6877 GSupplicantInterfaceCallback callback,
6880 struct interface_scan_data *data;
6883 if (!interface->p2p_support)
6886 ret = interface_ready_to_scan(interface);
6887 if (ret && ret != -EALREADY)
6890 data = dbus_malloc0(sizeof(*data));
6894 data->interface = interface;
6895 data->path = g_strdup(interface->path);
6896 data->callback = callback;
6897 data->user_data = user_data;
6899 ret = supplicant_dbus_method_call(interface->path,
6900 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
6901 interface_p2p_find_params, interface_p2p_find_result,
6911 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
6916 return interface->p2p_finding;
6919 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
6921 if (!interface->p2p_finding)
6926 interface->p2p_finding = false;
6928 return supplicant_dbus_method_call(interface->path,
6929 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
6930 NULL, NULL, NULL, NULL);
6933 static void interface_p2p_connect_result(const char *error,
6934 DBusMessageIter *iter, void *user_data)
6936 struct interface_connect_data *data = user_data;
6942 SUPPLICANT_DBG("error: %s", error);
6943 err = parse_supplicant_error(iter);
6947 data->callback(err, data->interface, data->user_data);
6950 g_free(data->peer->wps_pin);
6951 g_free(data->peer->path);
6956 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
6958 struct interface_connect_data *data = user_data;
6959 const char *wps = "pbc";
6960 DBusMessageIter dict;
6965 supplicant_dbus_dict_open(iter, &dict);
6967 if (data->peer->master)
6970 if (data->peer->wps_pin)
6973 supplicant_dbus_dict_append_basic(&dict, "peer",
6974 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
6975 supplicant_dbus_dict_append_basic(&dict, "wps_method",
6976 DBUS_TYPE_STRING, &wps);
6977 if (data->peer->wps_pin) {
6978 supplicant_dbus_dict_append_basic(&dict, "pin",
6979 DBUS_TYPE_STRING, &data->peer->wps_pin);
6982 supplicant_dbus_dict_append_basic(&dict, "go_intent",
6983 DBUS_TYPE_INT32, &go_intent);
6985 supplicant_dbus_dict_close(iter, &dict);
6988 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
6989 GSupplicantPeerParams *peer_params,
6990 GSupplicantInterfaceCallback callback,
6993 struct interface_connect_data *data;
6998 if (!interface->p2p_support)
7001 data = dbus_malloc0(sizeof(*data));
7005 data->interface = interface;
7006 data->path = g_strdup(interface->path);
7007 data->peer = peer_params;
7008 data->callback = callback;
7009 data->user_data = user_data;
7011 ret = supplicant_dbus_method_call(interface->path,
7012 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
7013 interface_p2p_connect_params, interface_p2p_connect_result,
7021 return -EINPROGRESS;
7024 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
7025 GSupplicantPeerParams *peer_params)
7027 GSupplicantPeer *peer;
7033 if (!interface->p2p_support)
7036 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
7040 for (list = peer->groups; list; list = list->next, count++) {
7041 const char *group_obj_path = list->data;
7042 GSupplicantInterface *g_interface;
7043 GSupplicantGroup *group;
7045 group = g_hash_table_lookup(group_mapping, group_obj_path);
7046 if (!group || !group->interface)
7049 g_interface = group->interface;
7050 supplicant_dbus_method_call(g_interface->path,
7051 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
7052 "Disconnect", NULL, NULL, NULL, g_interface);
7055 if (count == 0 && peer->current_group_iface) {
7056 supplicant_dbus_method_call(peer->current_group_iface->path,
7057 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
7058 "Disconnect", NULL, NULL, NULL,
7059 peer->current_group_iface->path);
7062 peer->current_group_iface = NULL;
7064 return -EINPROGRESS;
7067 struct p2p_service_data {
7069 GSupplicantInterface *interface;
7070 GSupplicantP2PServiceParams *service;
7071 GSupplicantInterfaceCallback callback;
7075 static void interface_p2p_service_result(const char *error,
7076 DBusMessageIter *iter, void *user_data)
7078 struct p2p_service_data *data = user_data;
7081 SUPPLICANT_DBG("%s result - %s", data->registration ?
7082 "Registration" : "Deletion",
7083 error ? error : "Success");
7088 data->callback(result, data->interface, data->user_data);
7090 g_free(data->service->query);
7091 g_free(data->service->response);
7092 g_free(data->service->service);
7093 g_free(data->service->wfd_ies);
7094 g_free(data->service);
7098 static void interface_p2p_service_params(DBusMessageIter *iter,
7101 struct p2p_service_data *data = user_data;
7102 GSupplicantP2PServiceParams *service;
7103 DBusMessageIter dict;
7108 service = data->service;
7110 supplicant_dbus_dict_open(iter, &dict);
7112 if (service->query && service->response) {
7114 supplicant_dbus_dict_append_basic(&dict, "service_type",
7115 DBUS_TYPE_STRING, &type);
7116 supplicant_dbus_dict_append_fixed_array(&dict, "query",
7117 DBUS_TYPE_BYTE, &service->query,
7118 service->query_length);
7119 supplicant_dbus_dict_append_fixed_array(&dict, "response",
7120 DBUS_TYPE_BYTE, &service->response,
7121 service->response_length);
7122 } else if (service->version && service->service) {
7124 supplicant_dbus_dict_append_basic(&dict, "service_type",
7125 DBUS_TYPE_STRING, &type);
7126 supplicant_dbus_dict_append_basic(&dict, "version",
7127 DBUS_TYPE_INT32, &service->version);
7128 supplicant_dbus_dict_append_basic(&dict, "service",
7129 DBUS_TYPE_STRING, &service->service);
7132 supplicant_dbus_dict_close(iter, &dict);
7135 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
7136 GSupplicantInterfaceCallback callback,
7137 GSupplicantP2PServiceParams *p2p_service_params,
7140 struct p2p_service_data *data;
7145 if (!interface->p2p_support)
7148 data = dbus_malloc0(sizeof(*data));
7152 data->registration = true;
7153 data->interface = interface;
7154 data->service = p2p_service_params;
7155 data->callback = callback;
7156 data->user_data = user_data;
7158 ret = supplicant_dbus_method_call(interface->path,
7159 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
7160 interface_p2p_service_params, interface_p2p_service_result,
7167 return -EINPROGRESS;
7170 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
7171 GSupplicantP2PServiceParams *p2p_service_params)
7173 struct p2p_service_data *data;
7178 if (!interface->p2p_support)
7181 data = dbus_malloc0(sizeof(*data));
7185 data->interface = interface;
7186 data->service = p2p_service_params;
7188 ret = supplicant_dbus_method_call(interface->path,
7189 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
7190 interface_p2p_service_params, interface_p2p_service_result,
7197 return -EINPROGRESS;
7200 struct p2p_listen_data {
7205 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
7207 struct p2p_listen_data *params = user_data;
7208 DBusMessageIter dict;
7210 supplicant_dbus_dict_open(iter, &dict);
7212 supplicant_dbus_dict_append_basic(&dict, "period",
7213 DBUS_TYPE_INT32, ¶ms->period);
7214 supplicant_dbus_dict_append_basic(&dict, "interval",
7215 DBUS_TYPE_INT32, ¶ms->interval);
7216 supplicant_dbus_dict_close(iter, &dict);
7219 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
7220 int period, int interval)
7222 struct p2p_listen_data params;
7226 if (!interface->p2p_support)
7229 params.period = period;
7230 params.interval = interval;
7232 return supplicant_dbus_method_call(interface->path,
7233 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
7234 "ExtendedListen", interface_p2p_listen_params,
7235 NULL, ¶ms, NULL);
7238 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
7240 struct p2p_service_data *data = user_data;
7241 GSupplicantP2PServiceParams *service = data->service;
7242 DBusMessageIter array;
7244 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
7246 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
7247 DBUS_TYPE_BYTE_AS_STRING, &array);
7249 if (service->wfd_ies && service->wfd_ies_length > 0) {
7250 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
7251 &service->wfd_ies, service->wfd_ies_length);
7254 dbus_message_iter_close_container(iter, &array);
7257 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
7258 GSupplicantInterfaceCallback callback,
7261 struct p2p_service_data *data;
7266 if (!system_available)
7269 data = dbus_malloc0(sizeof(*data));
7273 data->service = p2p_service_params;
7274 data->callback = callback;
7275 data->user_data = user_data;
7277 if (p2p_service_params->wfd_ies)
7278 data->registration = true;
7280 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
7281 SUPPLICANT_INTERFACE, "WFDIEs",
7282 DBUS_TYPE_ARRAY_AS_STRING
7283 DBUS_TYPE_BYTE_AS_STRING,
7285 interface_p2p_service_result,
7287 if (ret < 0 && ret != -EINPROGRESS) {
7292 return -EINPROGRESS;
7295 static const char *g_supplicant_rule0 = "type=signal,"
7296 "path=" DBUS_PATH_DBUS ","
7297 "sender=" DBUS_SERVICE_DBUS ","
7298 "interface=" DBUS_INTERFACE_DBUS ","
7299 "member=NameOwnerChanged,"
7300 "arg0=" SUPPLICANT_SERVICE;
7301 static const char *g_supplicant_rule1 = "type=signal,"
7302 "interface=" SUPPLICANT_INTERFACE;
7303 static const char *g_supplicant_rule2 = "type=signal,"
7304 "interface=" SUPPLICANT_INTERFACE ".Interface";
7305 static const char *g_supplicant_rule3 = "type=signal,"
7306 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
7307 static const char *g_supplicant_rule4 = "type=signal,"
7308 "interface=" SUPPLICANT_INTERFACE ".BSS";
7309 static const char *g_supplicant_rule5 = "type=signal,"
7310 "interface=" SUPPLICANT_INTERFACE ".Network";
7311 #if !defined TIZEN_EXT
7312 static const char *g_supplicant_rule6 = "type=signal,"
7313 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
7314 static const char *g_supplicant_rule7 = "type=signal,"
7315 "interface=" SUPPLICANT_INTERFACE ".Peer";
7316 static const char *g_supplicant_rule8 = "type=signal,"
7317 "interface=" SUPPLICANT_INTERFACE ".Group";
7319 #if defined TIZEN_EXT_WIFI_MESH
7320 static const char *g_supplicant_rule9 = "type=signal,"
7321 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
7324 static void invoke_introspect_method(void)
7326 DBusMessage *message;
7328 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
7330 DBUS_INTERFACE_INTROSPECTABLE,
7336 dbus_message_set_no_reply(message, TRUE);
7337 dbus_connection_send(connection, message, NULL);
7338 dbus_message_unref(message);
7341 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
7343 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
7347 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
7349 dbus_connection_unref(connection);
7354 callbacks_pointer = callbacks;
7357 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
7358 NULL, remove_interface);
7360 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
7362 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
7364 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
7366 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
7368 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
7371 supplicant_dbus_setup(connection);
7373 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
7374 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
7375 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
7376 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
7377 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
7378 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
7379 #if defined TIZEN_EXT
7380 dbus_bus_add_match(connection,
7381 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
7382 "member=ChangeState", NULL);
7384 #if !defined TIZEN_EXT
7385 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
7386 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
7387 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
7389 #if defined TIZEN_EXT_WIFI_MESH
7390 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
7392 dbus_connection_flush(connection);
7394 if (dbus_bus_name_has_owner(connection,
7395 SUPPLICANT_SERVICE, NULL)) {
7396 system_available = TRUE;
7397 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
7398 SUPPLICANT_INTERFACE,
7399 service_property, NULL, NULL);
7401 invoke_introspect_method();
7406 static void unregister_interface_remove_params(DBusMessageIter *iter,
7409 const char *path = user_data;
7411 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
7416 static void unregister_remove_interface(gpointer key, gpointer value,
7419 GSupplicantInterface *interface = value;
7421 supplicant_dbus_method_call(SUPPLICANT_PATH,
7422 SUPPLICANT_INTERFACE,
7424 unregister_interface_remove_params,
7425 NULL, interface->path, NULL);
7428 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
7433 #if defined TIZEN_EXT_WIFI_MESH
7434 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
7436 #if !defined TIZEN_EXT
7437 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
7438 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
7439 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
7441 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
7442 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
7443 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
7444 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
7445 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
7446 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
7447 dbus_connection_flush(connection);
7449 dbus_connection_remove_filter(connection,
7450 g_supplicant_filter, NULL);
7453 if (config_file_table) {
7454 g_hash_table_destroy(config_file_table);
7455 config_file_table = NULL;
7459 g_hash_table_destroy(bss_mapping);
7464 g_hash_table_destroy(peer_mapping);
7465 peer_mapping = NULL;
7468 if (group_mapping) {
7469 g_hash_table_destroy(group_mapping);
7470 group_mapping = NULL;
7473 if (interface_table) {
7474 g_hash_table_foreach(interface_table,
7475 unregister_remove_interface, NULL);
7476 g_hash_table_destroy(interface_table);
7477 interface_table = NULL;
7480 if (system_available)
7481 callback_system_killed();
7484 dbus_connection_unref(connection);
7488 callbacks_pointer = NULL;