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"
47 #define IEEE80211_CAP_ESS 0x0001
48 #define IEEE80211_CAP_IBSS 0x0002
49 #define IEEE80211_CAP_PRIVACY 0x0010
52 #define WLAN_EID_HT_CAP 45
53 #define WLAN_EID_VHT_CAP 191
54 #define WLAN_EID_SUPP_RATES 1
55 #define WLAN_EID_EXT_SUPP_RATES 50
56 #define COUNTRY_CODE_LENGTH 2
60 #define LAST_CONNECTED_TIMEOUT (5 * 60)
61 #define ASSOC_REJECT_TIMEOUT 10
62 #define FREQ_RANGE_24GHZ_CHANNEL_1 2412
63 #define FREQ_RANGE_24GHZ_CHANNEL_14 2484
64 #define FREQ_RANGE_5GHZ_CHANNEL_32 5160
65 #define FREQ_RANGE_5GHZ_CHANNEL_165 5825
67 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
68 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
71 #define BSS_UNKNOWN_STRENGTH -90
73 static DBusConnection *connection;
75 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
76 static GSupplicantCallbacks *callbacks_pointer;
77 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
78 static const GSupplicantCallbacks *callbacks_pointer;
79 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
81 static dbus_bool_t system_available = FALSE;
82 static dbus_bool_t system_ready = FALSE;
84 static dbus_int32_t debug_level;
85 static dbus_bool_t debug_timestamp = FALSE;
86 static dbus_bool_t debug_showkeys = FALSE;
88 static const char *debug_strings[] = {
89 "msgdump", "debug", "info", "warning", "error", NULL
92 static unsigned int eap_methods;
99 static struct strvalmap eap_method_map[] = {
100 { "MD5", G_SUPPLICANT_EAP_METHOD_MD5 },
101 { "TLS", G_SUPPLICANT_EAP_METHOD_TLS },
102 { "MSCHAPV2", G_SUPPLICANT_EAP_METHOD_MSCHAPV2 },
103 { "PEAP", G_SUPPLICANT_EAP_METHOD_PEAP },
104 { "TTLS", G_SUPPLICANT_EAP_METHOD_TTLS },
105 { "GTC", G_SUPPLICANT_EAP_METHOD_GTC },
106 { "OTP", G_SUPPLICANT_EAP_METHOD_OTP },
107 { "LEAP", G_SUPPLICANT_EAP_METHOD_LEAP },
108 { "WSC", G_SUPPLICANT_EAP_METHOD_WSC },
112 static struct strvalmap keymgmt_map[] = {
113 { "none", G_SUPPLICANT_KEYMGMT_NONE },
114 { "ieee8021x", G_SUPPLICANT_KEYMGMT_IEEE8021X },
115 { "wpa-none", G_SUPPLICANT_KEYMGMT_WPA_NONE },
116 { "wpa-psk", G_SUPPLICANT_KEYMGMT_WPA_PSK },
117 { "wpa-psk-sha256", G_SUPPLICANT_KEYMGMT_WPA_PSK_256 },
118 { "wpa-ft-psk", G_SUPPLICANT_KEYMGMT_WPA_FT_PSK },
119 { "wpa-ft-eap", G_SUPPLICANT_KEYMGMT_WPA_FT_EAP },
120 { "wpa-eap", G_SUPPLICANT_KEYMGMT_WPA_EAP },
121 { "wpa-eap-sha256", G_SUPPLICANT_KEYMGMT_WPA_EAP_256 },
122 { "wps", G_SUPPLICANT_KEYMGMT_WPS },
123 #if defined TIZEN_EXT
124 { "sae", G_SUPPLICANT_KEYMGMT_SAE },
125 { "ft-sae", G_SUPPLICANT_KEYMGMT_FT_SAE },
126 { "owe", G_SUPPLICANT_KEYMGMT_OWE },
127 { "dpp", G_SUPPLICANT_KEYMGMT_DPP },
132 static struct strvalmap authalg_capa_map[] = {
133 { "open", G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN },
134 { "shared", G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED },
135 { "leap", G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP },
139 static struct strvalmap proto_capa_map[] = {
140 { "wpa", G_SUPPLICANT_CAPABILITY_PROTO_WPA },
141 { "rsn", G_SUPPLICANT_CAPABILITY_PROTO_RSN },
145 static struct strvalmap group_map[] = {
146 { "wep40", G_SUPPLICANT_GROUP_WEP40 },
147 { "wep104", G_SUPPLICANT_GROUP_WEP104 },
148 { "tkip", G_SUPPLICANT_GROUP_TKIP },
149 { "ccmp", G_SUPPLICANT_GROUP_CCMP },
153 static struct strvalmap pairwise_map[] = {
154 { "none", G_SUPPLICANT_PAIRWISE_NONE },
155 { "tkip", G_SUPPLICANT_PAIRWISE_TKIP },
156 { "ccmp", G_SUPPLICANT_PAIRWISE_CCMP },
160 static struct strvalmap scan_capa_map[] = {
161 { "active", G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE },
162 { "passive", G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE },
163 { "ssid", G_SUPPLICANT_CAPABILITY_SCAN_SSID },
167 static struct strvalmap mode_capa_map[] = {
168 { "infrastructure", G_SUPPLICANT_CAPABILITY_MODE_INFRA },
169 { "ad-hoc", G_SUPPLICANT_CAPABILITY_MODE_IBSS },
170 { "ap", G_SUPPLICANT_CAPABILITY_MODE_AP },
171 { "p2p", G_SUPPLICANT_CAPABILITY_MODE_P2P },
172 #if defined TIZEN_EXT_WIFI_MESH
173 { "mesh", G_SUPPLICANT_CAPABILITY_MODE_MESH },
178 #if defined TIZEN_EXT
179 struct _GSupplicantINSSettings {
180 GSupplicantINSPreferredFreq preferred_freq_bssid;
181 unsigned int preferred_freq_bssid_score;
182 bool last_connected_bssid;
183 unsigned int last_connected_bssid_score;
185 unsigned int assoc_reject_score;
187 int signal_level3_5ghz;
188 int signal_level3_24ghz;
191 static struct _GSupplicantINSSettings ins_settings;
193 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
196 #endif /* defined TIZEN_EXT */
198 static GHashTable *interface_table;
199 static GHashTable *bss_mapping;
200 static GHashTable *peer_mapping;
201 static GHashTable *group_mapping;
202 static GHashTable *pending_peer_connection;
203 static GHashTable *config_file_table;
205 struct _GSupplicantWpsCredentials {
206 unsigned char ssid[32];
207 unsigned int ssid_len;
211 struct added_network_information {
213 GSupplicantSecurity security;
215 char * private_passphrase;
216 #if defined TIZEN_EXT
219 char *net_access_key;
223 #if defined TIZEN_EXT_WIFI_MESH
224 struct _GSupplicantMeshGroupInfo {
225 unsigned char ssid[32];
226 unsigned int ssid_len;
227 int disconnect_reason;
231 struct _GSupplicantInterface {
234 unsigned int keymgmt_capa;
235 unsigned int authalg_capa;
236 unsigned int proto_capa;
237 unsigned int group_capa;
238 unsigned int pairwise_capa;
239 unsigned int scan_capa;
240 unsigned int mode_capa;
241 unsigned int max_scan_ssids;
244 bool ap_create_in_progress;
246 GSupplicantState state;
247 dbus_bool_t scanning;
248 GSupplicantInterfaceCallback scan_callback;
254 struct _GSupplicantWpsCredentials wps_cred;
255 GSupplicantWpsState wps_state;
256 GHashTable *network_table;
257 GHashTable *peer_table;
258 GHashTable *group_table;
259 GHashTable *bss_mapping;
261 const char *pending_peer_path;
262 GSupplicantNetwork *current_network;
263 struct added_network_information network_info;
264 #if defined TIZEN_EXT
265 dbus_bool_t is_5_0_Ghz_supported;
266 dbus_bool_t is_6_0_Ghz_supported;
267 int disconnect_reason;
269 #if defined TIZEN_EXT
270 unsigned char add_network_bssid[WIFI_BSSID_LEN_MAX];
271 unsigned char connected_bssid[WIFI_BSSID_LEN_MAX];
273 #if defined TIZEN_EXT_WIFI_MESH
275 struct _GSupplicantMeshGroupInfo group_info;
279 struct g_supplicant_bss {
280 GSupplicantInterface *interface;
282 unsigned char bssid[6];
283 unsigned char ssid[32];
284 unsigned int ssid_len;
285 dbus_uint16_t frequency;
286 dbus_uint32_t maxrate;
288 GSupplicantMode mode;
289 GSupplicantSecurity security;
290 dbus_bool_t rsn_selected;
291 unsigned int wpa_keymgmt;
292 unsigned int wpa_pairwise;
293 unsigned int wpa_group;
294 unsigned int rsn_keymgmt;
295 unsigned int rsn_pairwise;
296 unsigned int rsn_group;
297 unsigned int keymgmt;
300 dbus_bool_t ieee8021x;
301 #if defined TIZEN_EXT
303 dbus_bool_t ft_ieee8021x;
306 unsigned char country_code[COUNTRY_CODE_LENGTH];
307 GSupplicantPhy_mode phy_mode;
309 dbus_uint32_t est_throughput;
310 dbus_bool_t psk_sha256;
312 unsigned int wps_capabilities;
313 #if defined TIZEN_EXT
317 dbus_bool_t owe_transition_mode;
318 unsigned int transition_mode_ssid_len;
319 unsigned char transition_mode_bssid[6];
320 unsigned char transition_mode_ssid[32];
321 dbus_bool_t pmf_required;
325 struct _GSupplicantNetwork {
326 GSupplicantInterface *interface;
330 unsigned char ssid[32];
331 unsigned int ssid_len;
333 dbus_uint16_t frequency;
334 struct g_supplicant_bss *best_bss;
335 GSupplicantMode mode;
336 GSupplicantSecurity security;
338 unsigned int wps_capabilities;
339 GHashTable *bss_table;
340 GHashTable *config_table;
341 #if defined TIZEN_EXT
346 unsigned int keymgmt;
348 unsigned char country_code[COUNTRY_CODE_LENGTH];
349 GSupplicantPhy_mode phy_mode;
350 dbus_bool_t owe_transition_mode;
352 unsigned int transition_mode_ssid_len;
353 unsigned char transition_mode_bssid[6];
354 unsigned char transition_mode_ssid[32];
355 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
356 GHashTable *assoc_reject_table;
360 struct _GSupplicantPeer {
361 GSupplicantInterface *interface;
363 unsigned char device_address[ETH_ALEN];
364 unsigned char iface_address[ETH_ALEN];
366 unsigned char *widi_ies;
369 unsigned int wps_capabilities;
371 const GSupplicantInterface *current_group_iface;
372 bool connection_requested;
375 struct _GSupplicantGroup {
376 GSupplicantInterface *interface;
377 GSupplicantInterface *orig_interface;
383 struct interface_data {
384 GSupplicantInterface *interface;
385 char *path; /* Interface path cannot be taken from interface (above) as
386 * it might have been freed already.
388 GSupplicantInterfaceCallback callback;
390 bool network_remove_in_progress;
391 GSupplicantSSID *ssid;
394 #if defined TIZEN_EXT
395 struct interface_signalpoll_data {
396 GSupplicantInterface *interface;
398 GSupplicantMaxSpeedCallback callback;
403 struct interface_create_data {
407 #if defined TIZEN_EXT
408 unsigned int mac_addr;
409 unsigned int preassoc_mac_addr;
410 unsigned int random_mac_lifetime;
411 #endif /* TIZEN_EXT */
412 #if defined TIZEN_EXT_WIFI_MESH
414 bool is_mesh_interface;
416 GSupplicantInterface *interface;
417 GSupplicantInterfaceCallback callback;
421 struct interface_connect_data {
422 GSupplicantInterface *interface;
424 GSupplicantInterfaceCallback callback;
427 GSupplicantSSID *ssid;
428 GSupplicantPeerParams *peer;
432 struct interface_scan_data {
433 GSupplicantInterface *interface;
435 GSupplicantInterfaceCallback callback;
436 GSupplicantScanParams *scan_params;
440 #if defined TIZEN_EXT
441 struct update_bssid_data {
442 GSupplicantNetwork *network;
443 unsigned char last_connected_bssid[WIFI_BSSID_LEN_MAX];
444 GHashTable *assoc_reject_table;
448 struct assoc_reject_data {
450 GSList *reject_time_list;
453 struct assoc_count_data {
458 static unsigned int last_connected_bss_timeout = 0;
459 static bool simplified_log = true;
462 static int network_remove(struct interface_data *data);
464 #if defined TIZEN_EXT_WIFI_MESH
465 struct _GSupplicantMeshPeer {
466 GSupplicantInterface *interface;
468 int disconnect_reason;
472 static inline void debug(const char *format, ...)
477 if (!callbacks_pointer || !callbacks_pointer->debug)
480 va_start(ap, format);
482 if (vsnprintf(str, sizeof(str), format, ap) > 0)
483 callbacks_pointer->debug(str);
488 #define SUPPLICANT_DBG(fmt, arg...) \
489 debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
491 static GSupplicantMode string2mode(const char *mode)
494 return G_SUPPLICANT_MODE_UNKNOWN;
496 if (g_str_equal(mode, "infrastructure"))
497 return G_SUPPLICANT_MODE_INFRA;
498 else if (g_str_equal(mode, "ad-hoc"))
499 return G_SUPPLICANT_MODE_IBSS;
500 #if defined TIZEN_EXT_WIFI_MESH
501 else if (g_str_equal(mode, "mesh"))
502 return G_SUPPLICANT_MODE_MESH;
505 return G_SUPPLICANT_MODE_UNKNOWN;
508 static const char *mode2string(GSupplicantMode mode)
511 case G_SUPPLICANT_MODE_UNKNOWN:
513 case G_SUPPLICANT_MODE_INFRA:
515 case G_SUPPLICANT_MODE_IBSS:
517 case G_SUPPLICANT_MODE_MASTER:
519 #if defined TIZEN_EXT_WIFI_MESH
520 case G_SUPPLICANT_MODE_MESH:
528 static const char *security2string(GSupplicantSecurity security)
531 case G_SUPPLICANT_SECURITY_UNKNOWN:
533 case G_SUPPLICANT_SECURITY_NONE:
535 case G_SUPPLICANT_SECURITY_WEP:
537 case G_SUPPLICANT_SECURITY_PSK:
539 case G_SUPPLICANT_SECURITY_IEEE8021X:
541 #if defined TIZEN_EXT
542 case G_SUPPLICANT_SECURITY_PSK_SHA256:
544 case G_SUPPLICANT_SECURITY_FT_PSK:
546 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
547 return "ft_ieee8021x";
548 case G_SUPPLICANT_SECURITY_SAE:
550 case G_SUPPLICANT_SECURITY_OWE:
552 case G_SUPPLICANT_SECURITY_DPP:
560 static GSupplicantState string2state(const char *state)
563 return G_SUPPLICANT_STATE_UNKNOWN;
565 if (g_str_equal(state, "unknown"))
566 return G_SUPPLICANT_STATE_UNKNOWN;
567 else if (g_str_equal(state, "interface_disabled"))
568 return G_SUPPLICANT_STATE_DISABLED;
569 else if (g_str_equal(state, "disconnected"))
570 return G_SUPPLICANT_STATE_DISCONNECTED;
571 else if (g_str_equal(state, "inactive"))
572 return G_SUPPLICANT_STATE_INACTIVE;
573 else if (g_str_equal(state, "scanning"))
574 return G_SUPPLICANT_STATE_SCANNING;
575 else if (g_str_equal(state, "authenticating"))
576 return G_SUPPLICANT_STATE_AUTHENTICATING;
577 else if (g_str_equal(state, "associating"))
578 return G_SUPPLICANT_STATE_ASSOCIATING;
579 else if (g_str_equal(state, "associated"))
580 return G_SUPPLICANT_STATE_ASSOCIATED;
581 else if (g_str_equal(state, "group_handshake"))
582 return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
583 else if (g_str_equal(state, "4way_handshake"))
584 return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
585 else if (g_str_equal(state, "completed"))
586 return G_SUPPLICANT_STATE_COMPLETED;
588 return G_SUPPLICANT_STATE_UNKNOWN;
591 static bool compare_network_parameters(GSupplicantInterface *interface,
592 GSupplicantSSID *ssid)
594 #if defined TIZEN_EXT
595 if (!interface->network_info.ssid)
599 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
602 if (interface->network_info.security != ssid->security)
605 if (interface->network_info.passphrase &&
606 g_strcmp0(interface->network_info.passphrase,
607 ssid->passphrase) != 0) {
611 if (interface->network_info.private_passphrase &&
612 g_strcmp0(interface->network_info.private_passphrase,
613 ssid->private_key_passphrase) != 0) {
617 #if defined TIZEN_EXT
618 if (interface->network_info.connector &&
619 g_strcmp0(interface->network_info.connector,
620 ssid->connector) != 0) {
623 if (interface->network_info.c_sign_key &&
624 g_strcmp0(interface->network_info.c_sign_key,
625 ssid->c_sign_key) != 0) {
628 if (interface->network_info.net_access_key &&
629 g_strcmp0(interface->network_info.net_access_key,
630 ssid->net_access_key) != 0) {
637 static void remove_network_information(GSupplicantInterface * interface)
639 g_free(interface->network_info.ssid);
640 g_free(interface->network_info.passphrase);
641 g_free(interface->network_info.private_passphrase);
642 #if defined TIZEN_EXT
643 g_free(interface->network_info.connector);
644 g_free(interface->network_info.c_sign_key);
645 g_free(interface->network_info.net_access_key);
647 interface->network_info.ssid = NULL;
648 interface->network_info.passphrase = NULL;
649 interface->network_info.private_passphrase = NULL;
650 #if defined TIZEN_EXT
651 interface->network_info.connector = NULL;
652 interface->network_info.c_sign_key = NULL;
653 interface->network_info.net_access_key = NULL;
657 static int store_network_information(GSupplicantInterface * interface,
658 GSupplicantSSID *ssid)
660 interface->network_info.ssid = g_malloc(ssid->ssid_len + 1);
661 if (interface->network_info.ssid != NULL) {
662 memcpy(interface->network_info.ssid, ssid->ssid,
664 interface->network_info.ssid[ssid->ssid_len] = '\0';
669 interface->network_info.security = ssid->security;
671 if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
672 ssid->security == G_SUPPLICANT_SECURITY_PSK ||
673 #if defined TIZEN_EXT
674 ssid->security == G_SUPPLICANT_SECURITY_SAE ||
675 ssid->security == G_SUPPLICANT_SECURITY_PSK_SHA256 ||
677 ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
679 interface->network_info.passphrase = g_strdup(ssid->passphrase);
682 if (ssid->security == G_SUPPLICANT_SECURITY_IEEE8021X &&
683 ssid->private_key_passphrase) {
684 interface->network_info.private_passphrase =
685 g_strdup(ssid->private_key_passphrase);
691 static void callback_system_ready(void)
698 if (!callbacks_pointer)
701 if (!callbacks_pointer->system_ready)
704 callbacks_pointer->system_ready();
707 static void callback_system_killed(void)
709 system_ready = FALSE;
711 if (!callbacks_pointer)
714 if (!callbacks_pointer->system_killed)
717 callbacks_pointer->system_killed();
720 static void callback_interface_added(GSupplicantInterface *interface)
724 if (!callbacks_pointer)
727 if (!callbacks_pointer->interface_added)
730 callbacks_pointer->interface_added(interface);
733 static void callback_interface_state(GSupplicantInterface *interface)
735 if (!callbacks_pointer)
738 if (!callbacks_pointer->interface_state)
741 callbacks_pointer->interface_state(interface);
744 static void callback_interface_removed(GSupplicantInterface *interface)
746 if (!callbacks_pointer)
749 if (!callbacks_pointer->interface_removed)
752 callbacks_pointer->interface_removed(interface);
755 #if !defined TIZEN_EXT
756 static void callback_p2p_support(GSupplicantInterface *interface)
760 if (!interface->p2p_support)
763 if (callbacks_pointer && callbacks_pointer->p2p_support)
764 callbacks_pointer->p2p_support(interface);
768 #if defined TIZEN_EXT_WIFI_MESH
769 static void callback_mesh_support(GSupplicantInterface *interface)
773 if (!interface->mesh_support)
776 if (callbacks_pointer && callbacks_pointer->mesh_support)
777 callbacks_pointer->mesh_support(interface);
780 bool g_supplicant_interface_has_mesh(GSupplicantInterface *interface)
785 return interface->mesh_support;
789 static void callback_scan_started(GSupplicantInterface *interface)
791 if (!callbacks_pointer)
794 if (!callbacks_pointer->scan_started)
797 callbacks_pointer->scan_started(interface);
800 static void callback_ap_create_fail(GSupplicantInterface *interface)
802 if (!callbacks_pointer)
805 if (!callbacks_pointer->ap_create_fail)
808 callbacks_pointer->ap_create_fail(interface);
811 static void callback_scan_finished(GSupplicantInterface *interface)
813 if (!callbacks_pointer)
816 if (!callbacks_pointer->scan_finished)
819 callbacks_pointer->scan_finished(interface);
822 static void callback_network_added(GSupplicantNetwork *network)
824 if (!callbacks_pointer)
827 if (!callbacks_pointer->network_added)
830 callbacks_pointer->network_added(network);
833 static void callback_network_removed(GSupplicantNetwork *network)
835 if (!callbacks_pointer)
838 if (!callbacks_pointer->network_removed)
841 callbacks_pointer->network_removed(network);
844 #if defined TIZEN_EXT
845 static void callback_network_merged(GSupplicantNetwork *network)
847 if (!callbacks_pointer)
850 if (!callbacks_pointer->network_merged)
853 callbacks_pointer->network_merged(network);
856 static void callback_assoc_failed(void *user_data)
858 if (!callbacks_pointer)
861 if (!callbacks_pointer->assoc_failed)
864 callbacks_pointer->assoc_failed(user_data);
867 static void callback_scan_done(GSupplicantInterface *interface)
869 if (!callbacks_pointer)
872 if (!callbacks_pointer->scan_done)
875 callbacks_pointer->scan_done(interface);
879 static void callback_network_changed(GSupplicantNetwork *network,
880 const char *property)
882 if (!callbacks_pointer)
885 if (!callbacks_pointer->network_changed)
888 callbacks_pointer->network_changed(network, property);
891 static void callback_network_associated(GSupplicantNetwork *network)
893 if (!callbacks_pointer)
896 if (!callbacks_pointer->network_associated)
899 callbacks_pointer->network_associated(network);
902 static void callback_sta_authorized(GSupplicantInterface *interface,
905 if (!callbacks_pointer)
908 if (!callbacks_pointer->sta_authorized)
911 callbacks_pointer->sta_authorized(interface, addr);
914 static void callback_sta_deauthorized(GSupplicantInterface *interface,
917 if (!callbacks_pointer)
920 if (!callbacks_pointer->sta_deauthorized)
923 callbacks_pointer->sta_deauthorized(interface, addr);
926 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
927 static void callback_eap(GSupplicantInterface *interface, bool status)
929 if (!callbacks_pointer)
932 if (!callbacks_pointer->eap)
935 callbacks_pointer->eap(interface, status);
937 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
939 static void callback_peer_found(GSupplicantPeer *peer)
941 if (!callbacks_pointer)
944 if (!callbacks_pointer->peer_found)
947 callbacks_pointer->peer_found(peer);
950 static void callback_peer_lost(GSupplicantPeer *peer)
952 if (!callbacks_pointer)
955 if (!callbacks_pointer->peer_lost)
958 callbacks_pointer->peer_lost(peer);
961 static void callback_peer_changed(GSupplicantPeer *peer,
962 GSupplicantPeerState state)
964 if (!callbacks_pointer)
967 if (!callbacks_pointer->peer_changed)
970 callbacks_pointer->peer_changed(peer, state);
973 static void callback_peer_request(GSupplicantPeer *peer)
975 if (!callbacks_pointer)
978 if (!callbacks_pointer->peer_request)
981 peer->connection_requested = true;
983 callbacks_pointer->peer_request(peer);
986 static void callback_disconnect_reason_code(GSupplicantInterface *interface,
989 if (!callbacks_pointer)
992 if (!callbacks_pointer->disconnect_reasoncode)
995 if (reason_code != 0)
996 callbacks_pointer->disconnect_reasoncode(interface,
1000 static void callback_assoc_status_code(GSupplicantInterface *interface,
1003 if (!callbacks_pointer)
1006 if (!callbacks_pointer->assoc_status_code)
1009 callbacks_pointer->assoc_status_code(interface, status_code);
1013 static void remove_group(gpointer data)
1015 GSupplicantGroup *group = data;
1018 g_slist_free_full(group->members, g_free);
1020 g_free(group->path);
1024 static void remove_interface(gpointer data)
1026 GSupplicantInterface *interface = data;
1028 g_hash_table_destroy(interface->bss_mapping);
1029 g_hash_table_destroy(interface->network_table);
1030 g_hash_table_destroy(interface->peer_table);
1031 g_hash_table_destroy(interface->group_table);
1033 if (interface->scan_callback) {
1034 SUPPLICANT_DBG("call interface %p callback %p scanning %d",
1035 interface, interface->scan_callback,
1036 interface->scanning);
1038 interface->scan_callback(-EIO, interface, interface->scan_data);
1039 interface->scan_callback = NULL;
1040 interface->scan_data = NULL;
1042 if (interface->scanning) {
1043 interface->scanning = FALSE;
1044 callback_scan_finished(interface);
1048 callback_interface_removed(interface);
1050 g_free(interface->wps_cred.key);
1051 g_free(interface->path);
1052 g_free(interface->network_path);
1053 #if defined TIZEN_EXT
1054 interface->network_path = NULL;
1056 g_free(interface->ifname);
1057 g_free(interface->driver);
1058 g_free(interface->bridge);
1059 remove_network_information(interface);
1063 static void remove_network(gpointer data)
1065 GSupplicantNetwork *network = data;
1067 g_hash_table_destroy(network->bss_table);
1069 callback_network_removed(network);
1071 g_hash_table_destroy(network->config_table);
1072 #if defined TIZEN_EXT
1073 g_hash_table_destroy(network->assoc_reject_table);
1076 g_free(network->path);
1077 g_free(network->group);
1078 g_free(network->name);
1079 #if defined TIZEN_EXT
1080 g_free(network->eap);
1081 g_free(network->identity);
1082 g_free(network->phase2);
1084 #if defined TIZEN_EXT
1085 g_slist_free_full(network->vsie_list, g_free);
1091 static void remove_bss(gpointer data)
1093 struct g_supplicant_bss *bss = data;
1095 supplicant_dbus_property_call_cancel_all(bss);
1098 #if defined TIZEN_EXT
1099 g_slist_free_full(bss->vsie_list, g_free);
1104 static void remove_peer(gpointer data)
1106 GSupplicantPeer *peer = data;
1108 callback_peer_lost(peer);
1111 g_slist_free_full(peer->groups, g_free);
1114 g_hash_table_remove(peer_mapping, peer->path);
1116 if (pending_peer_connection)
1117 g_hash_table_remove(pending_peer_connection, peer->path);
1121 g_free(peer->identifier);
1122 g_free(peer->widi_ies);
1127 #if defined TIZEN_EXT
1128 static void remove_assoc_data(gpointer data)
1130 struct assoc_reject_data *assoc_data = data;
1132 g_free(assoc_data->bssid);
1133 g_slist_free(assoc_data->reject_time_list);
1139 static void debug_strvalmap(const char *label, struct strvalmap *map,
1143 #if defined TIZEN_EXT
1144 if (!simplified_log)
1146 for (i = 0; map[i].str; i++) {
1147 if (val & map[i].val)
1148 SUPPLICANT_DBG("%s: %s", label, map[i].str);
1152 static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
1154 GSupplicantInterface *interface = user_data;
1155 const char *str = NULL;
1158 dbus_message_iter_get_basic(iter, &str);
1162 for (i = 0; keymgmt_map[i].str; i++)
1163 if (strcmp(str, keymgmt_map[i].str) == 0) {
1164 interface->keymgmt_capa |= keymgmt_map[i].val;
1169 static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
1171 GSupplicantInterface *interface = user_data;
1172 const char *str = NULL;
1175 dbus_message_iter_get_basic(iter, &str);
1179 for (i = 0; authalg_capa_map[i].str; i++)
1180 if (strcmp(str, authalg_capa_map[i].str) == 0) {
1181 interface->authalg_capa |= authalg_capa_map[i].val;
1186 static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
1188 GSupplicantInterface *interface = user_data;
1189 const char *str = NULL;
1192 dbus_message_iter_get_basic(iter, &str);
1196 for (i = 0; proto_capa_map[i].str; i++)
1197 if (strcmp(str, proto_capa_map[i].str) == 0) {
1198 interface->proto_capa |= proto_capa_map[i].val;
1203 static void interface_capability_pairwise(DBusMessageIter *iter,
1206 GSupplicantInterface *interface = user_data;
1207 const char *str = NULL;
1210 dbus_message_iter_get_basic(iter, &str);
1214 for (i = 0; pairwise_map[i].str; i++)
1215 if (strcmp(str, pairwise_map[i].str) == 0) {
1216 interface->pairwise_capa |= pairwise_map[i].val;
1221 static void interface_capability_group(DBusMessageIter *iter, void *user_data)
1223 GSupplicantInterface *interface = user_data;
1224 const char *str = NULL;
1227 dbus_message_iter_get_basic(iter, &str);
1231 for (i = 0; group_map[i].str; i++)
1232 if (strcmp(str, group_map[i].str) == 0) {
1233 interface->group_capa |= group_map[i].val;
1238 static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
1240 GSupplicantInterface *interface = user_data;
1241 const char *str = NULL;
1244 dbus_message_iter_get_basic(iter, &str);
1248 for (i = 0; scan_capa_map[i].str; i++)
1249 if (strcmp(str, scan_capa_map[i].str) == 0) {
1250 interface->scan_capa |= scan_capa_map[i].val;
1255 static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
1257 GSupplicantInterface *interface = user_data;
1258 const char *str = NULL;
1261 dbus_message_iter_get_basic(iter, &str);
1265 for (i = 0; mode_capa_map[i].str; i++)
1266 if (strcmp(str, mode_capa_map[i].str) == 0) {
1267 interface->mode_capa |= mode_capa_map[i].val;
1272 static void interface_capability(const char *key, DBusMessageIter *iter,
1275 GSupplicantInterface *interface = user_data;
1280 if (g_strcmp0(key, "KeyMgmt") == 0)
1281 supplicant_dbus_array_foreach(iter,
1282 interface_capability_keymgmt, interface);
1283 else if (g_strcmp0(key, "AuthAlg") == 0)
1284 supplicant_dbus_array_foreach(iter,
1285 interface_capability_authalg, interface);
1286 else if (g_strcmp0(key, "Protocol") == 0)
1287 supplicant_dbus_array_foreach(iter,
1288 interface_capability_proto, interface);
1289 else if (g_strcmp0(key, "Pairwise") == 0)
1290 supplicant_dbus_array_foreach(iter,
1291 interface_capability_pairwise, interface);
1292 else if (g_strcmp0(key, "Group") == 0)
1293 supplicant_dbus_array_foreach(iter,
1294 interface_capability_group, interface);
1295 else if (g_strcmp0(key, "Scan") == 0)
1296 supplicant_dbus_array_foreach(iter,
1297 interface_capability_scan, interface);
1298 else if (g_strcmp0(key, "Modes") == 0)
1299 supplicant_dbus_array_foreach(iter,
1300 interface_capability_mode, interface);
1301 else if (g_strcmp0(key, "MaxScanSSID") == 0) {
1302 dbus_int32_t max_scan_ssid;
1304 dbus_message_iter_get_basic(iter, &max_scan_ssid);
1305 if (max_scan_ssid < 2)
1307 interface->max_scan_ssids = max_scan_ssid;
1308 #if defined TIZEN_EXT
1309 } else if (g_strcmp0(key, "Is5GhzSupported") == 0) {
1310 dbus_bool_t is_5_0_Ghz_supported;
1312 dbus_message_iter_get_basic(iter, &is_5_0_Ghz_supported);
1313 interface->is_5_0_Ghz_supported = is_5_0_Ghz_supported;
1314 } else if (g_strcmp0(key, "Is6GhzSupported") == 0) {
1315 dbus_bool_t is_6_0_Ghz_supported;
1317 dbus_message_iter_get_basic(iter, &is_6_0_Ghz_supported);
1318 interface->is_6_0_Ghz_supported = is_6_0_Ghz_supported;
1321 SUPPLICANT_DBG("key %s type %c",
1322 key, dbus_message_iter_get_arg_type(iter));
1325 static void set_bss_expiration_age(DBusMessageIter *iter, void *user_data)
1327 unsigned int bss_expiration_age = GPOINTER_TO_UINT(user_data);
1329 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32,
1330 &bss_expiration_age);
1333 int g_supplicant_interface_set_bss_expiration_age(GSupplicantInterface *interface,
1334 unsigned int bss_expiration_age)
1336 return supplicant_dbus_property_set(interface->path,
1337 SUPPLICANT_INTERFACE ".Interface",
1338 "BSSExpireAge", DBUS_TYPE_UINT32_AS_STRING,
1339 set_bss_expiration_age, NULL,
1340 GUINT_TO_POINTER(bss_expiration_age), NULL);
1343 struct set_apscan_data
1345 unsigned int ap_scan;
1346 GSupplicantInterface *interface;
1349 static void set_apscan(DBusMessageIter *iter, void *user_data)
1351 struct set_apscan_data *data = user_data;
1352 unsigned int ap_scan = data->ap_scan;
1354 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
1357 static void set_apscan_complete(const char *error,
1358 DBusMessageIter *iter, void *user_data)
1360 struct set_apscan_data *data = user_data;
1361 GSupplicantInterface *interface = data->interface;
1364 interface->ap_create_in_progress = false;
1365 SUPPLICANT_DBG("Set AP scan error %s", error);
1369 interface->ap_create_in_progress = true;
1374 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
1375 unsigned int ap_scan)
1377 struct set_apscan_data *data;
1380 data = dbus_malloc0(sizeof(*data));
1385 data->ap_scan = ap_scan;
1386 data->interface = interface;
1388 ret = supplicant_dbus_property_set(interface->path,
1389 SUPPLICANT_INTERFACE ".Interface",
1390 "ApScan", DBUS_TYPE_UINT32_AS_STRING,
1391 set_apscan, set_apscan_complete, data, NULL);
1398 void g_supplicant_interface_set_data(GSupplicantInterface *interface,
1404 interface->data = data;
1407 interface->scan_callback = NULL;
1410 void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
1415 return interface->data;
1418 const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
1423 return interface->ifname;
1426 #if defined TIZEN_EXT
1427 bool g_supplicant_interface_get_is_5_0_ghz_supported(GSupplicantInterface *interface)
1432 return interface->is_5_0_Ghz_supported;
1435 bool g_supplicant_interface_get_is_6_0_ghz_supported(GSupplicantInterface *interface)
1440 return interface->is_6_0_Ghz_supported;
1443 unsigned char *g_supplicant_interface_get_add_network_bssid(GSupplicantInterface *interface)
1448 return (unsigned char *)interface->add_network_bssid;
1452 const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
1457 return interface->driver;
1460 GSupplicantState g_supplicant_interface_get_state(
1461 GSupplicantInterface *interface)
1464 return G_SUPPLICANT_STATE_UNKNOWN;
1466 return interface->state;
1469 const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
1474 return (const char *)interface->wps_cred.key;
1477 const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
1478 unsigned int *ssid_len)
1483 if (!interface || interface->wps_cred.ssid_len == 0) {
1488 *ssid_len = interface->wps_cred.ssid_len;
1489 return interface->wps_cred.ssid;
1492 GSupplicantWpsState g_supplicant_interface_get_wps_state(
1493 GSupplicantInterface *interface)
1496 return G_SUPPLICANT_WPS_STATE_UNKNOWN;
1498 return interface->wps_state;
1501 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
1506 return interface->mode_capa;
1509 unsigned int g_supplicant_interface_get_max_scan_ssids(
1510 GSupplicantInterface *interface)
1515 if (interface->max_scan_ssids == 0)
1516 return WPAS_MAX_SCAN_SSIDS;
1518 return interface->max_scan_ssids;
1521 static void set_network_enabled(DBusMessageIter *iter, void *user_data)
1523 dbus_bool_t enable = *(dbus_bool_t *)user_data;
1525 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
1528 int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
1534 if (!interface->network_path)
1537 SUPPLICANT_DBG(" ");
1538 return supplicant_dbus_property_set(interface->network_path,
1539 SUPPLICANT_INTERFACE ".Network",
1540 "Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
1541 set_network_enabled, NULL, &enable, NULL);
1544 dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
1549 return interface->ready;
1552 GSupplicantInterface *g_supplicant_network_get_interface(
1553 GSupplicantNetwork *network)
1558 return network->interface;
1561 const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
1563 if (!network || !network->name)
1566 return network->name;
1569 const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
1571 if (!network || !network->group)
1574 return network->group;
1577 const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
1579 if (!network || !network->path)
1582 return network->path;
1585 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
1590 return mode2string(network->mode);
1593 const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
1598 return security2string(network->security);
1601 const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
1602 unsigned int *ssid_len)
1609 *ssid_len = network->ssid_len;
1610 return network->ssid;
1613 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
1618 return network->signal;
1621 #if defined TIZEN_EXT
1622 void g_supplicant_network_set_signal(GSupplicantNetwork *network, int signal)
1627 network->signal = (dbus_int16_t)signal;
1630 void g_supplicant_network_set_bss_signal(GSupplicantNetwork *network,
1631 int signal, int snr)
1633 struct g_supplicant_bss *best_bss;
1638 best_bss = network->best_bss;
1642 best_bss->signal = (dbus_int16_t)signal;
1643 best_bss->snr = (dbus_int16_t)snr;
1647 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
1652 return network->frequency;
1655 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
1660 return network->wps;
1663 dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
1668 if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
1674 dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
1679 if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1685 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
1690 if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
1697 GSupplicantPhy_mode g_supplicant_network_get_phy_mode(GSupplicantNetwork *network)
1700 return G_SUPPLICANT_MODE_IEEE80211_UNKNOWN;
1702 return network->phy_mode;
1706 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
1711 return peer->interface;
1714 const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
1722 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
1727 return peer->identifier;
1730 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
1735 return peer->device_address;
1738 const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
1743 return peer->iface_address;
1746 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
1754 #if defined TIZEN_EXT
1755 bool g_supplicant_network_is_hs20AP(GSupplicantNetwork *network)
1760 return network->isHS20AP;
1763 const char *g_supplicant_network_get_eap(GSupplicantNetwork *network)
1765 if (!network || !network->eap)
1768 return network->eap;
1771 const char *g_supplicant_network_get_identity(GSupplicantNetwork *network)
1773 if (!network || !network->identity)
1776 return network->identity;
1779 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network)
1781 if (!network || !network->phase2)
1784 return network->phase2;
1787 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
1792 return network->keymgmt;
1795 dbus_bool_t g_supplicant_network_get_privacy(GSupplicantNetwork *network)
1800 return network->privacy;
1803 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
1809 return network->country_code;
1812 dbus_bool_t g_supplicant_network_is_pmf_required(GSupplicantNetwork *network)
1814 if (!network || !network->best_bss)
1817 return network->best_bss->pmf_required;
1821 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
1824 if (!peer || !length)
1827 *length = peer->widi_ies_length;
1828 return peer->widi_ies;
1831 bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
1836 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
1842 bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
1847 if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
1853 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
1855 if (!peer || !peer->groups)
1861 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
1866 return (GSupplicantInterface *) peer->current_group_iface;
1869 bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
1871 GSupplicantGroup *group;
1877 for (list = peer->groups; list; list = list->next) {
1878 const char *path = list->data;
1880 group = g_hash_table_lookup(group_mapping, path);
1884 if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
1885 group->orig_interface != peer->interface)
1888 if (group->interface == peer->current_group_iface)
1895 bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
1900 return peer->connection_requested;
1903 #if defined TIZEN_EXT
1905 * Description: Network client requires additional wifi specific info
1907 const unsigned char *g_supplicant_network_get_bssid(GSupplicantNetwork *network)
1909 if (network == NULL || network->best_bss == NULL)
1912 return (const unsigned char *)network->best_bss->bssid;
1915 dbus_bool_t g_supplicant_network_get_transition_mode(GSupplicantNetwork *network)
1917 if (network == NULL)
1920 return network->owe_transition_mode;
1923 const unsigned char *g_supplicant_network_get_transition_mode_bssid(GSupplicantNetwork *network)
1925 if (network == NULL)
1928 return (const unsigned char *)network->transition_mode_bssid;
1931 const void *g_supplicant_network_get_transition_mode_ssid(GSupplicantNetwork *network,
1932 unsigned int *transition_mode_ssid_len)
1935 *transition_mode_ssid_len = 0;
1939 *transition_mode_ssid_len = network->transition_mode_ssid_len;
1940 return network->transition_mode_ssid;
1943 unsigned int g_supplicant_network_get_maxrate(GSupplicantNetwork *network)
1945 if (network == NULL || network->best_bss == NULL)
1948 return network->best_bss->maxrate;
1951 const char *g_supplicant_network_get_enc_mode(GSupplicantNetwork *network)
1953 if (network == NULL || network->best_bss == NULL)
1956 if (network->best_bss->security == G_SUPPLICANT_SECURITY_PSK ||
1957 network->best_bss->security == G_SUPPLICANT_SECURITY_SAE ||
1958 network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1959 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP ||
1960 network->best_bss->security == G_SUPPLICANT_SECURITY_PSK_SHA256 ||
1961 network->best_bss->security == G_SUPPLICANT_SECURITY_IEEE8021X) {
1962 unsigned int pairwise;
1964 pairwise = network->best_bss->rsn_pairwise |
1965 network->best_bss->wpa_pairwise;
1967 if ((pairwise & G_SUPPLICANT_PAIRWISE_CCMP) &&
1968 (pairwise & G_SUPPLICANT_PAIRWISE_TKIP))
1970 else if (pairwise & G_SUPPLICANT_PAIRWISE_CCMP)
1972 else if (pairwise & G_SUPPLICANT_PAIRWISE_TKIP)
1975 } else if (network->best_bss->security == G_SUPPLICANT_SECURITY_WEP)
1977 else if (network->best_bss->security == G_SUPPLICANT_SECURITY_NONE)
1983 bool g_supplicant_network_get_rsn_mode(GSupplicantNetwork *network)
1985 if (network == NULL || network->best_bss == NULL)
1988 if (network->best_bss->security == G_SUPPLICANT_SECURITY_OWE ||
1989 network->best_bss->security == G_SUPPLICANT_SECURITY_DPP)
1992 if (network->best_bss->rsn_selected) {
1993 const char *mode = g_supplicant_network_get_enc_mode(network);
1994 if (g_strcmp0(mode, "aes") == 0 ||
1995 g_strcmp0(mode, "mixed") == 0)
2003 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
2005 GSList *vsie_list = NULL;
2010 if (g_slist_length(network->vsie_list) > 0) {
2011 GSList *list = NULL;
2012 unsigned char *vsie = NULL;
2013 for (list = network->vsie_list; list; list = list->next) {
2014 unsigned char *ie = (unsigned char *)list->data;
2017 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2020 memcpy(vsie, ie, ie[1]+2);
2021 vsie_list = g_slist_append(vsie_list, vsie);
2023 SUPPLICANT_DBG("Failed to allocate memory");
2030 static bool compare_bssid(unsigned char *bssid_a, unsigned char *bssid_b)
2032 if (!memcmp(bssid_a, bssid_b, WIFI_BSSID_LEN_MAX))
2038 static gchar *convert_bssid_to_str(unsigned char *bssid)
2043 bssid_str = g_string_sized_new(18);
2047 for (i = 0; i < WIFI_BSSID_LEN_MAX; i++) {
2048 g_string_append_printf(bssid_str, "%02x", bssid[i]);
2049 if (i < WIFI_BSSID_LEN_MAX - 1)
2050 g_string_append(bssid_str, ":");
2053 return g_string_free(bssid_str, FALSE);
2056 static void count_assoc_reject(gpointer data, gpointer user_data)
2058 time_t assoc_reject_time = GPOINTER_TO_INT(data);
2059 struct assoc_count_data *assoc_count = user_data;
2061 if (assoc_reject_time > assoc_count->ref_time)
2062 assoc_count->assoc_count++;
2065 static uint16_t get_assoc_reject_cnt(GHashTable *assoc_reject_table, unsigned char *bssid)
2068 struct assoc_reject_data *assoc_data;
2069 struct assoc_count_data assoc_count;
2071 struct tm* timeinfo;
2073 if (g_hash_table_size(assoc_reject_table) < 1)
2079 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2082 bssid_str = convert_bssid_to_str(bssid);
2086 assoc_data = g_hash_table_lookup(assoc_reject_table, bssid_str);
2092 if (g_slist_length(assoc_data->reject_time_list) < 1) {
2097 /* Only events that occur within one hour are appened. */
2098 curr_time = time(NULL);
2099 timeinfo = localtime(&curr_time);
2100 timeinfo->tm_hour -= 1;
2102 assoc_count.ref_time = mktime(timeinfo);
2103 assoc_count.assoc_count = 0;
2105 g_slist_foreach(assoc_data->reject_time_list, count_assoc_reject, &assoc_count);
2108 return assoc_count.assoc_count;
2111 static int calculate_score_last_connected_bssid(bool is_last_connected)
2115 if (ins_settings.last_connected_bssid) {
2116 if (is_last_connected)
2117 score += ins_settings.last_connected_bssid_score;
2123 static int calculate_score_assoc_reject(uint16_t assoc_reject_cnt)
2127 if (ins_settings.assoc_reject)
2128 score -= (assoc_reject_cnt * ins_settings.assoc_reject_score);
2133 static int calculate_score_frequency(dbus_int16_t strength, dbus_uint16_t frequency)
2137 switch (ins_settings.preferred_freq_bssid) {
2138 case G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ:
2139 if ((frequency >= FREQ_RANGE_24GHZ_CHANNEL_1 &&
2140 frequency <= FREQ_RANGE_24GHZ_CHANNEL_14) &&
2141 (strength > ins_settings.signal_level3_24ghz))
2142 score += ins_settings.preferred_freq_bssid_score;
2145 case G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ:
2146 if ((frequency >= FREQ_RANGE_5GHZ_CHANNEL_32 &&
2147 frequency <= FREQ_RANGE_5GHZ_CHANNEL_165) &&
2148 (strength > ins_settings.signal_level3_5ghz))
2149 score += ins_settings.preferred_freq_bssid_score;
2159 static int calculate_score_strength(dbus_int16_t strength)
2163 if (ins_settings.signal_bssid)
2164 score += (((strength > -60) ? -60 : strength) + 85);
2169 static int calculate_score_est_throughput(dbus_uint32_t est_throughput)
2173 if (est_throughput >= 10000)
2174 score = est_throughput / 10000;
2182 static int calculate_score(bool is_last_connected, uint16_t assoc_reject_cnt,
2183 dbus_uint16_t frequency, dbus_int16_t strength,
2184 dbus_int16_t snr, dbus_uint32_t est_throughput)
2188 score += calculate_score_last_connected_bssid(is_last_connected);
2189 score += calculate_score_assoc_reject(assoc_reject_cnt);
2190 score += calculate_score_frequency(strength, frequency);
2191 score += calculate_score_strength(strength);
2193 score += calculate_score_est_throughput(est_throughput);
2198 static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
2200 struct g_supplicant_bss *bss = value;
2201 struct g_connman_bssids *bssids = NULL;
2202 struct update_bssid_data *bssid_data = (struct update_bssid_data *)user_data;
2204 bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
2207 memcpy(bssids->bssid, bss->bssid, WIFI_BSSID_LEN_MAX);
2209 bssids->strength = bss->signal;
2210 bssids->strength += 120;
2212 if (bssids->strength > 100)
2213 bssids->strength = 100;
2215 bssids->frequency = bss->frequency;
2216 bssids->est_throughput = bss->est_throughput;
2217 bssids->score_snr = (int)bss->snr;
2219 if (TIZEN_INS_ENABLED) {
2220 bssids->assoc_reject_cnt = get_assoc_reject_cnt(bssid_data->assoc_reject_table, bssids->bssid);
2221 bssids->is_last_connected = compare_bssid(bssids->bssid, bssid_data->last_connected_bssid);
2223 bssids->score_last_connected_bssid = calculate_score_last_connected_bssid(bssids->is_last_connected);
2224 bssids->score_assoc_reject = calculate_score_assoc_reject(bssids->assoc_reject_cnt);
2225 bssids->score_frequency = calculate_score_frequency(bss->signal, bssids->frequency);
2226 bssids->score_strength = calculate_score_strength(bss->signal);
2227 bssids->score_est_throughput = calculate_score_est_throughput(bss->est_throughput);
2229 bssids->ins_score = calculate_score(bssids->is_last_connected,
2230 bssids->assoc_reject_cnt, bssids->frequency, bss->signal,
2231 bss->snr, bss->est_throughput);
2233 bssids->ins_score = bss->signal;
2236 bssid_data->bssid_list = g_slist_append(bssid_data->bssid_list, bssids);
2238 SUPPLICANT_DBG("Failed to allocate memory");
2241 static gint cmp_bss(gconstpointer a, gconstpointer b)
2243 struct g_connman_bssids *entry_a = (struct g_connman_bssids *)a;
2244 struct g_connman_bssids *entry_b = (struct g_connman_bssids *)b;
2246 if (entry_a->ins_score > entry_b->ins_score)
2249 if (entry_a->ins_score < entry_b->ins_score)
2252 if (entry_a->ins_score == entry_b->ins_score) {
2253 if (entry_a->strength >= entry_b->strength)
2262 static void print_bssid_sort(gpointer data, gpointer user_data)
2264 struct g_connman_bssids *bssids = data;
2266 GSupplicantNetwork *network = (GSupplicantNetwork *) user_data;
2268 if (!bssids || !network)
2271 SUPPLICANT_DBG("ssid [%-20s] bssid[" MACSTR "] total[%2d] freq[%2d] "
2272 "last_conn[%2d] assoc_reject[%2d] strength[%2d] rssi[%2d]",
2273 network->ssid, MAC2STR(bssids->bssid), bssids->ins_score,
2274 bssids->score_frequency, bssids->score_last_connected_bssid,
2275 bssids->score_assoc_reject, bssids->score_strength, bssids->strength - 120);
2278 void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
2280 struct update_bssid_data bssid_data;
2282 if (g_hash_table_size(network->bss_table) < 1)
2285 bssid_data.network = network;
2286 memset(&bssid_data, 0, sizeof(bssid_data));
2287 memcpy(bssid_data.last_connected_bssid, network->last_connected_bssid, WIFI_BSSID_LEN_MAX);
2288 bssid_data.assoc_reject_table = network->assoc_reject_table;
2290 g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_data);
2291 bssid_data.bssid_list = g_slist_sort(bssid_data.bssid_list, cmp_bss);
2292 if (TIZEN_INS_ENABLED && !simplified_log)
2293 g_slist_foreach(bssid_data.bssid_list, print_bssid_sort, (gpointer)network);
2295 return bssid_data.bssid_list;
2298 void g_supplicant_network_set_last_connected_bssid(GSupplicantNetwork *network, const unsigned char *bssid)
2303 if (!memcmp(bssid, invalid_bssid, WIFI_BSSID_LEN_MAX))
2306 memcpy(network->last_connected_bssid, bssid, WIFI_BSSID_LEN_MAX);
2308 SUPPLICANT_DBG("last connected bssid [" MACSTR "]", MAC2STR(bssid));
2311 const unsigned char *g_supplicant_network_get_last_connected_bssid(GSupplicantNetwork *network)
2313 if (network == NULL)
2316 return (const unsigned char *)network->last_connected_bssid;
2319 void g_supplicant_network_update_assoc_reject(GSupplicantInterface *interface,
2320 GSupplicantNetwork *network)
2322 struct assoc_reject_data *assoc_data;
2329 bssid_str = convert_bssid_to_str(interface->add_network_bssid);
2333 assoc_data = g_hash_table_lookup(network->assoc_reject_table, bssid_str);
2335 assoc_data = g_try_new0(struct assoc_reject_data, 1);
2341 assoc_data->bssid = g_strdup(bssid_str);
2342 g_hash_table_insert(network->assoc_reject_table, assoc_data->bssid, assoc_data);
2345 curr_time = time(NULL);
2346 assoc_data->reject_time_list = g_slist_append(assoc_data->reject_time_list, GINT_TO_POINTER(curr_time));
2348 SUPPLICANT_DBG("bssid [%s] time [%u]", bssid_str, curr_time);
2352 callback_network_changed(network, "UpdateAssocReject");
2355 GHashTable *g_supplicant_network_get_assoc_reject_table(GSupplicantNetwork *network)
2360 return network->assoc_reject_table;
2363 static void copy_assoc_reject(gpointer key, gpointer value, gpointer user_data)
2365 struct assoc_reject_data *cloned_assoc_data;
2366 struct assoc_reject_data *assoc_data = value;
2367 GHashTable *cloned_assoc_reject_table = user_data;
2369 if (assoc_data && cloned_assoc_reject_table) {
2370 cloned_assoc_data = g_try_new0(struct assoc_reject_data, 1);
2371 if (!cloned_assoc_data)
2374 cloned_assoc_data->bssid = g_strdup(assoc_data->bssid);
2375 cloned_assoc_data->reject_time_list = g_slist_copy(assoc_data->reject_time_list);
2376 g_hash_table_insert(cloned_assoc_reject_table,
2377 cloned_assoc_data->bssid, cloned_assoc_data);
2381 GHashTable *g_supplicant_network_clone_assoc_reject_table(GSupplicantNetwork *network)
2383 GHashTable *cloned_assoc_reject_table;
2388 GHashTable *assoc_reject_table = g_supplicant_network_get_assoc_reject_table(network);
2389 if (!assoc_reject_table)
2392 cloned_assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2393 NULL, remove_assoc_data);
2394 g_hash_table_foreach(assoc_reject_table, copy_assoc_reject, cloned_assoc_reject_table);
2396 return cloned_assoc_reject_table;
2399 GSupplicantNetwork *g_supplicant_interface_get_network(GSupplicantInterface *interface,
2405 return g_hash_table_lookup(interface->network_table, group);
2407 #endif /* defined TIZEN_EXT */
2409 static void merge_network(GSupplicantNetwork *network)
2412 const char *ssid, *mode, *key_mgmt;
2413 #if defined TIZEN_EXT
2414 const char *isHS20AP;
2415 const char *eap, *identity, *phase2;
2417 unsigned int i, ssid_len;
2420 ssid = g_hash_table_lookup(network->config_table, "ssid");
2421 mode = g_hash_table_lookup(network->config_table, "mode");
2422 key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
2423 #if defined TIZEN_EXT
2424 isHS20AP = g_hash_table_lookup(network->config_table, "isHS20AP");
2425 eap = g_hash_table_lookup(network->config_table, "eap");
2426 identity = g_hash_table_lookup(network->config_table, "identity");
2427 phase2 = g_hash_table_lookup(network->config_table, "phase2");
2430 SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
2433 ssid_len = strlen(ssid);
2437 str = g_string_sized_new((ssid_len * 2) + 24);
2441 for (i = 0; i < ssid_len; i++)
2442 #if defined TIZEN_EXT
2446 g_string_append_printf(str, "%02x", ssid[i]);
2447 #if defined TIZEN_EXT
2451 if (g_strcmp0(mode, "0") == 0)
2452 g_string_append_printf(str, "_managed");
2453 else if (g_strcmp0(mode, "1") == 0)
2454 g_string_append_printf(str, "_adhoc");
2455 #if defined TIZEN_EXT_WIFI_MESH
2456 else if (g_strcmp0(mode, "5") == 0)
2457 g_string_append_printf(str, "_mesh");
2460 #if defined TIZEN_EXT
2461 if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
2462 g_string_append_printf(str, "_psk");
2463 else if (g_strcmp0(key_mgmt, "SAE") == 0)
2464 g_string_append_printf(str, "_sae");
2466 if ((g_strcmp0(key_mgmt, "WPA-PSK") == 0) ||
2467 (g_strcmp0(key_mgmt, "SAE") == 0))
2468 g_string_append_printf(str, "_psk");
2470 #if defined TIZEN_EXT
2471 else if (g_strcmp0(key_mgmt, "WPA-EAP") == 0)
2472 g_string_append_printf(str, "_ieee8021x");
2474 g_string_append_printf(str, "_none");
2477 group = g_string_free(str, FALSE);
2479 SUPPLICANT_DBG("%s", group);
2481 #if defined TIZEN_EXT
2482 if (g_strcmp0(isHS20AP, "1") == 0) {
2483 network->isHS20AP = 1;
2485 g_free(network->eap);
2486 network->eap = g_strdup(eap);
2488 if (network->identity)
2489 g_free(network->identity);
2490 network->identity = g_strdup(identity);
2492 if (network->phase2)
2493 g_free(network->phase2);
2494 network->phase2 = g_strdup(phase2);
2496 network->isHS20AP = 0;
2498 network->group = g_strdup(group);
2499 callback_network_merged(network);
2500 g_free(network->group);
2505 g_hash_table_destroy(network->config_table);
2507 g_free(network->path);
2511 static void network_property(const char *key, DBusMessageIter *iter,
2514 GSupplicantNetwork *network = user_data;
2516 if (!network->interface)
2520 merge_network(network);
2524 if (g_strcmp0(key, "Enabled") == 0) {
2525 dbus_bool_t enabled = FALSE;
2527 dbus_message_iter_get_basic(iter, &enabled);
2528 } else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
2529 const char *str = NULL;
2531 dbus_message_iter_get_basic(iter, &str);
2533 g_hash_table_replace(network->config_table,
2534 g_strdup(key), g_strdup(str));
2537 SUPPLICANT_DBG("key %s type %c",
2538 key, dbus_message_iter_get_arg_type(iter));
2541 static void interface_network_added(DBusMessageIter *iter, void *user_data)
2543 GSupplicantInterface *interface = user_data;
2544 GSupplicantNetwork *network;
2545 const char *path = NULL;
2549 dbus_message_iter_get_basic(iter, &path);
2553 if (g_strcmp0(path, "/") == 0)
2556 network = g_try_new0(GSupplicantNetwork, 1);
2560 network->interface = interface;
2561 network->path = g_strdup(path);
2563 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2566 dbus_message_iter_next(iter);
2567 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
2568 supplicant_dbus_property_foreach(iter, network_property,
2570 network_property(NULL, NULL, network);
2574 supplicant_dbus_property_get_all(path,
2575 SUPPLICANT_INTERFACE ".Network",
2576 network_property, network, NULL);
2579 static void interface_network_removed(DBusMessageIter *iter, void *user_data)
2584 static char *create_name(unsigned char *ssid, int ssid_len)
2587 const gchar *remainder, *invalid;
2588 int valid_bytes, remaining_bytes;
2590 if (ssid_len < 1 || ssid[0] == '\0')
2591 return g_strdup("");
2594 remainder = (const gchar *)ssid;
2595 remaining_bytes = ssid_len;
2597 while (remaining_bytes != 0) {
2598 if (g_utf8_validate(remainder, remaining_bytes,
2603 valid_bytes = invalid - remainder;
2606 string = g_string_sized_new(remaining_bytes);
2608 g_string_append_len(string, remainder, valid_bytes);
2610 /* append U+FFFD REPLACEMENT CHARACTER */
2611 g_string_append(string, "\357\277\275");
2613 remaining_bytes -= valid_bytes + 1;
2614 remainder = invalid + 1;
2618 return g_strndup((const gchar *)ssid, ssid_len + 1);
2620 g_string_append(string, remainder);
2622 return g_string_free(string, FALSE);
2625 static char *create_group(struct g_supplicant_bss *bss)
2629 const char *mode, *security;
2631 str = g_string_sized_new((bss->ssid_len * 2) + 24);
2635 if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
2636 for (i = 0; i < bss->ssid_len; i++)
2637 g_string_append_printf(str, "%02x", bss->ssid[i]);
2639 g_string_append_printf(str, "hidden");
2641 mode = mode2string(bss->mode);
2643 g_string_append_printf(str, "_%s", mode);
2645 #if defined TIZEN_EXT
2646 if (bss->security == G_SUPPLICANT_SECURITY_PSK_SHA256)
2649 security = security2string(bss->security);
2651 security = security2string(bss->security);
2654 g_string_append_printf(str, "_%s", security);
2656 return g_string_free(str, FALSE);
2658 #if defined TIZEN_EXT
2659 static void update_network_with_best_bss(GSupplicantNetwork *network,
2660 struct g_supplicant_bss *best_bss)
2663 * Do not change best BSS if we are connected.
2665 if (network->interface->state == G_SUPPLICANT_STATE_COMPLETED && network->best_bss)
2668 network->signal = best_bss->signal;
2669 network->frequency = best_bss->frequency;
2670 network->phy_mode = best_bss->phy_mode;
2671 network->best_bss = best_bss;
2674 static bool update_best_bss(GSupplicantNetwork *network,
2675 struct g_supplicant_bss *bss, struct g_supplicant_bss *best_bss)
2680 if (network->best_bss == NULL) {
2681 update_network_with_best_bss(network, bss);
2685 if (TIZEN_INS_ENABLED) {
2686 score_new = calculate_score(
2687 compare_bssid(bss->bssid, network->last_connected_bssid),
2688 get_assoc_reject_cnt(network->assoc_reject_table, bss->bssid),
2689 bss->frequency, bss->signal, bss->snr, bss->est_throughput);
2691 score_best = calculate_score(
2692 compare_bssid(network->best_bss->bssid, network->last_connected_bssid),
2693 get_assoc_reject_cnt(network->assoc_reject_table, network->best_bss->bssid),
2694 network->best_bss->frequency, network->best_bss->signal,
2695 network->best_bss->snr, network->best_bss->est_throughput);
2697 score_new = bss->signal;
2698 score_best = network->best_bss->signal;
2701 if (score_new > score_best) {
2702 SUPPLICANT_DBG("new[" MACSTR "][%d] : best[" MACSTR "][%d]",
2703 MAC2STR(bss->bssid), score_new,
2704 MAC2STR(network->best_bss->bssid), score_best);
2706 update_network_with_best_bss(network, bss);
2708 SUPPLICANT_DBG("Update best BSS for %s", network->name);
2716 static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
2718 GSupplicantInterface *interface = bss->interface;
2719 GSupplicantNetwork *network;
2721 bool is_new_network;
2723 group = create_group(bss);
2724 SUPPLICANT_DBG("New group created: %s", group);
2729 network = g_hash_table_lookup(interface->network_table, group);
2732 SUPPLICANT_DBG("Network %s already exist", network->name);
2733 is_new_network = false;
2738 is_new_network = true;
2740 network = g_try_new0(GSupplicantNetwork, 1);
2746 network->interface = interface;
2748 network->path = g_strdup(bss->path);
2749 network->group = group;
2750 network->name = create_name(bss->ssid, bss->ssid_len);
2751 network->mode = bss->mode;
2752 network->security = bss->security;
2753 network->keymgmt = bss->keymgmt;
2754 network->ssid_len = bss->ssid_len;
2755 memcpy(network->ssid, bss->ssid, bss->ssid_len);
2756 network->signal = bss->signal;
2757 network->frequency = bss->frequency;
2758 network->best_bss = bss;
2760 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2761 network->wps = TRUE;
2762 network->wps_capabilities = bss->wps_capabilities;
2765 #if defined TIZEN_EXT
2766 network->owe_transition_mode = bss->owe_transition_mode;
2767 network->privacy = bss->privacy;
2768 memcpy(network->transition_mode_ssid, bss->transition_mode_ssid, bss->transition_mode_ssid_len);
2769 memcpy(network->transition_mode_bssid, bss->transition_mode_bssid, WIFI_BSSID_LEN_MAX);
2771 network->keymgmt = bss->keymgmt;
2773 if (g_slist_length(bss->vsie_list) > 0) {
2774 GSList *list = NULL;
2775 unsigned char *vsie = NULL;
2776 for (list = bss->vsie_list; list; list = list->next) {
2777 unsigned char *ie = (unsigned char *)list->data;
2778 vsie = (unsigned char *)g_try_malloc0(ie[1]+2); // tag number size(1), tag length size(1)
2781 memcpy(vsie, ie, ie[1]+2);
2782 network->vsie_list = g_slist_append(network->vsie_list, vsie);
2784 SUPPLICANT_DBG("Failed to allocate memory.");
2788 network->isHS20AP = bss->hs20;
2789 memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
2790 network->phy_mode = bss->phy_mode;
2793 SUPPLICANT_DBG("New network %s created", network->name);
2795 network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2798 network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2801 #if defined TIZEN_EXT
2802 network->assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
2803 NULL, remove_assoc_data);
2806 g_hash_table_replace(interface->network_table,
2807 network->group, network);
2809 callback_network_added(network);
2812 /* We update network's WPS properties if only bss provides WPS. */
2813 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
2814 network->wps = TRUE;
2815 network->wps_capabilities = bss->wps_capabilities;
2817 if (!is_new_network)
2818 callback_network_changed(network, "WPSCapabilities");
2822 * Do not change best BSS if we are connected. It will be done through
2823 * CurrentBSS property in case of misalignment with wpa_s or roaming.
2825 #if defined TIZEN_EXT
2826 if (network != interface->current_network) {
2827 if (update_best_bss(network, bss, network->best_bss))
2828 callback_network_changed(network, "Signal");
2831 if (network != interface->current_network &&
2832 bss->signal > network->signal) {
2833 network->signal = bss->signal;
2834 network->best_bss = bss;
2835 callback_network_changed(network, "Signal");
2839 g_hash_table_replace(interface->bss_mapping, bss->path, network);
2840 g_hash_table_replace(network->bss_table, bss->path, bss);
2842 g_hash_table_replace(bss_mapping, bss->path, interface);
2847 static void bss_rates(DBusMessageIter *iter, void *user_data)
2849 struct g_supplicant_bss *bss = user_data;
2850 dbus_uint32_t rate = 0;
2852 dbus_message_iter_get_basic(iter, &rate);
2856 if (rate > bss->maxrate)
2857 bss->maxrate = rate;
2860 static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
2862 unsigned int *keymgmt = user_data;
2863 const char *str = NULL;
2866 dbus_message_iter_get_basic(iter, &str);
2870 for (i = 0; keymgmt_map[i].str; i++)
2871 if (strcmp(str, keymgmt_map[i].str) == 0) {
2872 SUPPLICANT_DBG("Keymgmt: %s", str);
2873 *keymgmt |= keymgmt_map[i].val;
2878 static void bss_group(DBusMessageIter *iter, void *user_data)
2880 unsigned int *group = user_data;
2881 const char *str = NULL;
2884 dbus_message_iter_get_basic(iter, &str);
2888 for (i = 0; group_map[i].str; i++)
2889 if (strcmp(str, group_map[i].str) == 0) {
2890 SUPPLICANT_DBG("Group: %s", str);
2891 *group |= group_map[i].val;
2896 static void bss_pairwise(DBusMessageIter *iter, void *user_data)
2898 unsigned int *pairwise = user_data;
2899 const char *str = NULL;
2902 dbus_message_iter_get_basic(iter, &str);
2906 for (i = 0; pairwise_map[i].str; i++)
2907 if (strcmp(str, pairwise_map[i].str) == 0) {
2908 SUPPLICANT_DBG("Pairwise: %s", str);
2909 *pairwise |= pairwise_map[i].val;
2914 static void bss_wpa(const char *key, DBusMessageIter *iter,
2917 struct g_supplicant_bss *bss = user_data;
2918 unsigned int value = 0;
2920 SUPPLICANT_DBG("Key: %s", key);
2922 if (g_strcmp0(key, "KeyMgmt") == 0) {
2923 supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
2925 if (bss->rsn_selected)
2926 bss->rsn_keymgmt = value;
2928 bss->wpa_keymgmt = value;
2929 } else if (g_strcmp0(key, "Group") == 0) {
2930 supplicant_dbus_array_foreach(iter, bss_group, &value);
2932 if (bss->rsn_selected)
2933 bss->rsn_group = value;
2935 bss->wpa_group = value;
2936 } else if (g_strcmp0(key, "Pairwise") == 0) {
2937 supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
2939 if (bss->rsn_selected)
2940 bss->rsn_pairwise = value;
2942 bss->wpa_pairwise = value;
2946 static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
2949 unsigned int len = 0;
2951 while (len + 4 < ie_size) {
2952 unsigned int hi = ie[len];
2953 unsigned int lo = ie[len + 1];
2954 unsigned int tmp_type = (hi << 8) + lo;
2955 unsigned int v_len = 0;
2957 /* hi and lo are used to recreate an unsigned int
2958 * based on 2 8bits length unsigned int. */
2962 v_len = (hi << 8) + lo;
2964 if (tmp_type == type) {
2965 unsigned int ret_value = 0;
2966 unsigned char *value = (unsigned char *)&ret_value;
2968 SUPPLICANT_DBG("IE: match type 0x%x", type);
2970 /* Verifying length relevance */
2971 if (v_len > sizeof(unsigned int) ||
2972 len + 4 + v_len > ie_size)
2975 memcpy(value, ie + len + 4, v_len);
2977 SUPPLICANT_DBG("returning 0x%x", ret_value);
2984 SUPPLICANT_DBG("returning 0");
2988 #if defined TIZEN_EXT
2989 static void get_bss_phy_mode(unsigned int max_rate,
2990 unsigned int max_ext_rate, bool ht, bool vht, void *data)
2992 struct g_supplicant_bss *bss = data;
2993 unsigned int freq = bss->frequency;
2995 /* Following conditions are used to determine
2996 * IEEE 802.11 Protocol Modes:-
2998 * 1. If “Supported rates” is only till 11 Mbps,
2999 * and frequency is in 2.4GHz band, then protocol is 11B.
3000 * 2. If “Supported rates” is till 54Mbps or
3001 * “Extended supported rates” are present,
3002 * and frequency is in 2.4GHz band, then protocol is 11G.
3003 * 3. If “Supported rates” is only till 54 Mbps,
3004 * frequency is in 5GHz band , then protocol is 11A.
3005 * 4. If “HT capabilities” is supported , then protocol is 11N.
3006 * 5. If “HT capabilities” & “VHT” is supported and
3007 * frequency is in 5 GHz band, then protocol is 11AC.
3010 if (freq >= 2412 && freq <= 2484) { /* 2.4 Ghz Band */
3011 if (max_rate <= 11 && max_ext_rate <= 0 && !ht)
3012 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211B;
3013 else if ((max_rate <= 54 || max_ext_rate > 0) && !ht)
3014 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BG;
3015 else if ((max_rate >= 54 || max_ext_rate > 0) && ht)
3016 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211BGN;
3018 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
3019 } else if (freq >= 5180 && freq <= 5825) { /* 5 Ghz Band */
3020 if (max_rate <= 54 && !ht)
3021 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211A;
3022 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && !vht)
3023 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211AN;
3024 else if ((max_rate >= 54 || max_ext_rate > 0) && ht && vht)
3025 bss->phy_mode = G_SUPPLICANT_MODE_IEEE80211ANAC;
3027 bss->phy_mode = G_SUPPLICANT_MODE_UNKNOWN;
3032 static void bss_process_ies(DBusMessageIter *iter, void *user_data)
3034 struct g_supplicant_bss *bss = user_data;
3035 const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
3036 unsigned char *ie, *ie_end;
3037 DBusMessageIter array;
3040 #if defined TIZEN_EXT
3041 const unsigned char OWE_WFA_OUI[] = { 0x50, 0x6f, 0x9a, 0x1c };
3043 unsigned char *rates = NULL;
3044 unsigned char *ext_rates = NULL;
3045 unsigned int max_rate = 0;
3046 unsigned int max_ext_rate = 0;
3047 unsigned int offset = 0;
3052 #define WMM_WPA1_WPS_INFO 221
3053 #define WPS_INFO_MIN_LEN 6
3054 #define WPS_VERSION_TLV 0x104A
3055 #define WPS_STATE_TLV 0x1044
3056 #define WPS_METHODS_TLV 0x1012
3057 #define WPS_REGISTRAR_TLV 0x1041
3058 #define WPS_VERSION 0x10
3059 #define WPS_PBC 0x04
3060 #define WPS_PIN 0x00
3061 #define WPS_CONFIGURED 0x02
3062 #if defined TIZEN_EXT
3063 #define VENDOR_SPECIFIC_INFO 0xDD
3064 #define WLAN_EID_COUNTRY 7
3065 #define WLAN_EID_RSN_INFO 48
3066 #define RSN_CAPABILITY_MFP_REQ (1 << 6)
3069 dbus_message_iter_recurse(iter, &array);
3070 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
3072 if (!ie || ie_len < 2)
3075 bss->wps_capabilities = 0;
3078 for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
3080 #if defined TIZEN_EXT
3081 unsigned char *vsie;
3084 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
3085 SUPPLICANT_DBG("IE: match vendor specific data : OWE Transition Mode");
3088 Tag: Vendor Specific: Wi-Fi Alliance: OWE Transition Mode
3089 Tag Number: Vendor Specific (221) -> ie[0]
3090 Tag length: 26 -> ie[1]
3091 OUI: 50:6f:9a (Wi-Fi Alliance) -> ie[2]
3092 Vendor Specific OUI Type: 28 -> ie[5]
3093 BSSID: 92:fd:f0:20:2b:09 -> ie[6]
3094 SSID length: 15 -> ie[12]
3095 SSID: Wi-Fi-5.2.3-owe -> ie[13]
3097 0000 dd 1a 50 6f 9a 1c 92 fd f0 20 2b 09 0f 57 69 2d ..Po..... +..Wi-
3098 0010 46 69 2d 35 2e 32 2e 33 2d 6f 77 65 Fi-5.2.3-owe
3101 bss->owe_transition_mode = TRUE;
3102 if (ie[1] >= 11) { // Tag length is at least up to ssid length position.
3103 memcpy(bss->transition_mode_bssid, ie+6, WIFI_BSSID_LEN_MAX);
3104 if (ie[12] > 0 && ie[12] < 32) {
3105 memcpy(bss->transition_mode_ssid, ie+13, ie[12]);
3106 bss->transition_mode_ssid_len = ie[12];
3108 bss->transition_mode_ssid_len = 0;
3110 bss->owe_transition_mode = FALSE;
3114 if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
3116 if (!simplified_log)
3117 SUPPLICANT_DBG("IE: match vendor specific data");
3119 vsie_len = ie[1]+2; // tag number size(1), tag length size(1)
3120 vsie = (unsigned char *)g_try_malloc0(vsie_len);
3123 memcpy(vsie, ie, vsie_len);
3124 bss->vsie_list = g_slist_append(bss->vsie_list, vsie);
3126 SUPPLICANT_DBG("Failed to allocate memory");
3130 if (ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
3131 /* Add country code only if it is a valid alphabet */
3132 if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
3133 memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
3138 if (ie[0] == WLAN_EID_HT_CAP && ie[1]) {
3143 if (ie[0] == WLAN_EID_VHT_CAP && ie[1]) {
3148 if (ie[0] == WLAN_EID_SUPP_RATES && ie[1]) {
3150 rates = g_malloc0(r_len);
3154 for (j = 0; ie && j < r_len; j++) {
3155 rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3156 if (max_rate < rates[j])
3157 max_rate = rates[j];
3162 if (ie[0] == WLAN_EID_EXT_SUPP_RATES && ie[1] > 0) {
3164 ext_rates = g_malloc0(r_len);
3168 for (j = 0; ie && j < r_len; j++) {
3169 ext_rates[j] = ((ie[j + 2] & 0x7f) * 500000)/1000000;
3170 if (max_ext_rate < ext_rates[j])
3171 max_ext_rate = ext_rates[j];
3176 if (ie[0] == WLAN_EID_RSN_INFO && ie[1] >= 20) {
3178 offset = 10 + ie[8] * 4;
3179 offset += ie[offset] * 4 + 2;
3181 if (offset <= r_len + 1 &&
3182 (ie[offset] & RSN_CAPABILITY_MFP_REQ) != 0)
3183 bss->pmf_required = TRUE;
3188 if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
3189 memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
3192 SUPPLICANT_DBG("IE: match WPS_OUI");
3194 value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
3195 if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
3197 bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
3199 if (value == WPS_CONFIGURED)
3200 bss->wps_capabilities |=
3201 G_SUPPLICANT_WPS_CONFIGURED;
3204 value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
3206 if (GUINT16_FROM_BE(value) == WPS_PBC)
3207 bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
3208 if (GUINT16_FROM_BE(value) == WPS_PIN)
3209 bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
3211 bss->wps_capabilities |=
3212 G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
3214 /* If the AP sends this it means it's advertizing
3215 * as a registrar and the WPS process is launched
3217 if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
3218 bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
3220 SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
3223 get_bss_phy_mode(max_rate, max_ext_rate, ht, vht, user_data);
3231 static void bss_compute_security(struct g_supplicant_bss *bss)
3234 * Combining RSN and WPA keymgmt
3235 * We combine it since parsing IEs might have set something for WPS. */
3236 bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
3238 bss->ieee8021x = FALSE;
3240 #if defined TIZEN_EXT
3241 bss->ft_ieee8021x = FALSE;
3242 bss->ft_psk = FALSE;
3245 #if defined TIZEN_EXT
3247 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3248 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3249 bss->ieee8021x = TRUE;
3250 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_EAP)
3251 bss->ft_ieee8021x = TRUE;
3254 (G_SUPPLICANT_KEYMGMT_WPA_EAP |
3255 G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
3256 G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
3257 bss->ieee8021x = TRUE;
3260 #if defined TIZEN_EXT
3262 G_SUPPLICANT_KEYMGMT_WPA_PSK_256) {
3263 bss->psk_sha256 = TRUE;
3267 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3268 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3270 else if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
3274 (G_SUPPLICANT_KEYMGMT_WPA_PSK |
3275 G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
3276 G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
3280 #if defined TIZEN_EXT
3282 (G_SUPPLICANT_KEYMGMT_SAE |
3283 G_SUPPLICANT_KEYMGMT_FT_SAE))
3285 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_OWE)
3287 if (bss->keymgmt & G_SUPPLICANT_KEYMGMT_DPP)
3292 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3293 #if defined TIZEN_EXT
3294 else if (bss->ft_ieee8021x)
3295 bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
3297 bss->security = G_SUPPLICANT_SECURITY_SAE;
3298 else if (bss->psk_sha256)
3299 bss->security = G_SUPPLICANT_SECURITY_PSK_SHA256;
3302 bss->security = G_SUPPLICANT_SECURITY_PSK;
3303 #if defined TIZEN_EXT
3304 else if (bss->ft_psk)
3305 bss->security = G_SUPPLICANT_SECURITY_FT_PSK;
3306 else if (bss->owe || bss->owe_transition_mode)
3307 bss->security = G_SUPPLICANT_SECURITY_OWE;
3309 bss->security = G_SUPPLICANT_SECURITY_DPP;
3311 else if (bss->privacy)
3312 bss->security = G_SUPPLICANT_SECURITY_WEP;
3314 bss->security = G_SUPPLICANT_SECURITY_NONE;
3318 static void bss_property(const char *key, DBusMessageIter *iter,
3321 struct g_supplicant_bss *bss = user_data;
3323 if (!bss->interface)
3325 #if defined TIZEN_EXT
3326 if (!simplified_log)
3328 SUPPLICANT_DBG("key %s", key);
3333 if (g_strcmp0(key, "BSSID") == 0) {
3334 DBusMessageIter array;
3335 unsigned char *addr;
3338 dbus_message_iter_recurse(iter, &array);
3339 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
3342 memcpy(bss->bssid, addr, addr_len);
3343 } else if (g_strcmp0(key, "SSID") == 0) {
3344 DBusMessageIter array;
3345 unsigned char *ssid;
3348 dbus_message_iter_recurse(iter, &array);
3349 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
3351 if (ssid_len > 0 && ssid_len < 33) {
3352 memcpy(bss->ssid, ssid, ssid_len);
3353 bss->ssid_len = ssid_len;
3355 memset(bss->ssid, 0, sizeof(bss->ssid));
3358 } else if (g_strcmp0(key, "Capabilities") == 0) {
3359 dbus_uint16_t capabilities = 0x0000;
3361 dbus_message_iter_get_basic(iter, &capabilities);
3363 if (capabilities & IEEE80211_CAP_ESS)
3364 bss->mode = G_SUPPLICANT_MODE_INFRA;
3365 else if (capabilities & IEEE80211_CAP_IBSS)
3366 bss->mode = G_SUPPLICANT_MODE_IBSS;
3368 if (capabilities & IEEE80211_CAP_PRIVACY)
3369 bss->privacy = TRUE;
3370 } else if (g_strcmp0(key, "Mode") == 0) {
3371 const char *mode = NULL;
3373 dbus_message_iter_get_basic(iter, &mode);
3374 bss->mode = string2mode(mode);
3375 } else if (g_strcmp0(key, "Frequency") == 0) {
3376 dbus_uint16_t frequency = 0;
3378 dbus_message_iter_get_basic(iter, &frequency);
3379 bss->frequency = frequency;
3380 } else if (g_strcmp0(key, "Signal") == 0) {
3381 dbus_int16_t signal = 0;
3383 dbus_message_iter_get_basic(iter, &signal);
3385 bss->signal = signal;
3387 bss->signal = BSS_UNKNOWN_STRENGTH;
3389 } else if (g_strcmp0(key, "Level") == 0) {
3390 dbus_int32_t level = 0;
3392 dbus_message_iter_get_basic(iter, &level);
3393 } else if (g_strcmp0(key, "Rates") == 0) {
3394 supplicant_dbus_array_foreach(iter, bss_rates, bss);
3395 } else if (g_strcmp0(key, "MaxRate") == 0) {
3396 dbus_uint32_t maxrate = 0;
3398 dbus_message_iter_get_basic(iter, &maxrate);
3400 bss->maxrate = maxrate;
3401 } else if (g_strcmp0(key, "Privacy") == 0) {
3402 dbus_bool_t privacy = FALSE;
3404 dbus_message_iter_get_basic(iter, &privacy);
3405 bss->privacy = privacy;
3406 } else if (g_strcmp0(key, "RSN") == 0) {
3407 bss->rsn_selected = TRUE;
3409 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3410 } else if (g_strcmp0(key, "WPA") == 0) {
3411 bss->rsn_selected = FALSE;
3413 supplicant_dbus_property_foreach(iter, bss_wpa, bss);
3414 #if defined TIZEN_EXT
3415 } else if (g_strcmp0(key, "HS20") == 0) {
3416 dbus_bool_t hs20 = FALSE;
3417 dbus_message_iter_get_basic(iter, &hs20);
3419 } else if (g_strcmp0(key, "SNR") == 0) {
3420 dbus_int16_t snr = 0;
3422 dbus_message_iter_get_basic(iter, &snr);
3424 } else if (g_strcmp0(key, "EstThroughput") == 0) {
3425 dbus_uint32_t est_throughput = 0;
3427 dbus_message_iter_get_basic(iter, &est_throughput);
3428 if (est_throughput != 0)
3429 bss->est_throughput = est_throughput;
3431 } else if (g_strcmp0(key, "IEs") == 0)
3432 bss_process_ies(iter, bss);
3434 SUPPLICANT_DBG("key %s type %c",
3435 key, dbus_message_iter_get_arg_type(iter));
3438 static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
3441 GSupplicantInterface *interface = user_data;
3442 GSupplicantNetwork *network;
3443 struct g_supplicant_bss *bss;
3444 const char *path = NULL;
3445 #if defined TIZEN_EXT
3446 if (!simplified_log)
3450 dbus_message_iter_get_basic(iter, &path);
3454 if (g_strcmp0(path, "/") == 0)
3456 #if defined TIZEN_EXT
3457 if (!simplified_log)
3459 SUPPLICANT_DBG("%s", path);
3461 network = g_hash_table_lookup(interface->bss_mapping, path);
3463 bss = g_hash_table_lookup(network->bss_table, path);
3468 bss = g_try_new0(struct g_supplicant_bss, 1);
3472 bss->interface = interface;
3473 bss->path = g_strdup(path);
3474 bss->signal = BSS_UNKNOWN_STRENGTH;
3479 static void interface_bss_added_with_keys(DBusMessageIter *iter,
3482 struct g_supplicant_bss *bss;
3483 #if defined TIZEN_EXT
3484 if (!simplified_log)
3488 bss = interface_bss_added(iter, user_data);
3492 dbus_message_iter_next(iter);
3494 if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
3495 #if defined TIZEN_EXT
3505 supplicant_dbus_property_foreach(iter, bss_property, bss);
3507 bss_compute_security(bss);
3508 if (add_or_replace_bss_to_network(bss) < 0)
3509 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3512 static void interface_bss_added_without_keys(DBusMessageIter *iter,
3515 struct g_supplicant_bss *bss;
3516 #if defined TIZEN_EXT
3517 if (!simplified_log)
3521 bss = interface_bss_added(iter, user_data);
3525 supplicant_dbus_property_get_all(bss->path,
3526 SUPPLICANT_INTERFACE ".BSS",
3527 bss_property, bss, bss);
3529 bss_compute_security(bss);
3530 if (add_or_replace_bss_to_network(bss) < 0)
3531 SUPPLICANT_DBG("add_or_replace_bss_to_network failed");
3534 static void update_signal(gpointer key, gpointer value,
3537 struct g_supplicant_bss *bss = value;
3538 GSupplicantNetwork *network = user_data;
3540 #if defined TIZEN_EXT
3541 if (!network->best_bss || (network->best_bss == bss)) {
3542 if (bss->signal > network->signal) {
3543 network->signal = bss->signal;
3544 network->frequency = bss->frequency;
3545 network->phy_mode = bss->phy_mode;
3546 network->best_bss = bss;
3551 update_best_bss(network, bss, network->best_bss);
3553 if (bss->signal > network->signal) {
3554 network->signal = bss->signal;
3555 network->best_bss = bss;
3560 static void update_network_signal(GSupplicantNetwork *network)
3562 if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
3565 g_hash_table_foreach(network->bss_table,
3566 update_signal, network);
3568 SUPPLICANT_DBG("New network signal %d", network->signal);
3571 #if defined TIZEN_EXT
3572 static gboolean last_connected_timeout(gpointer data)
3574 GSupplicantInterface *interface = data;
3575 GSupplicantNetwork *current_network = interface->current_network;
3577 SUPPLICANT_DBG("Timeout last connected bss");
3579 if (current_network && current_network->best_bss) {
3580 if (compare_bssid(current_network->best_bss->bssid, interface->connected_bssid)) {
3581 g_supplicant_network_set_last_connected_bssid(current_network, interface->connected_bssid);
3582 callback_network_changed(current_network, "LastConnectedBSSID");
3586 last_connected_bss_timeout = 0;
3590 static void add_timer_for_last_connected(GSupplicantInterface *interface)
3592 GSupplicantNetwork *current_network = interface->current_network;
3594 if (interface->state == G_SUPPLICANT_STATE_COMPLETED) {
3595 if (current_network) {
3596 struct g_supplicant_bss *best_bss = current_network->best_bss;
3598 memcpy(interface->connected_bssid, best_bss->bssid, WIFI_BSSID_LEN_MAX);
3600 if (last_connected_bss_timeout)
3601 g_source_remove(last_connected_bss_timeout);
3603 last_connected_bss_timeout = g_timeout_add_seconds(LAST_CONNECTED_TIMEOUT,
3604 last_connected_timeout, interface);
3606 SUPPLICANT_DBG("Add timer for last connected bssid [" MACSTR "]",
3607 MAC2STR(best_bss->bssid));
3612 static void remove_timer_for_last_connected(GSupplicantInterface *interface)
3614 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED) {
3615 if (last_connected_bss_timeout != 0) {
3616 g_source_remove(last_connected_bss_timeout);
3617 last_connected_bss_timeout = 0;
3618 SUPPLICANT_DBG("Remove timer for last connected bss");
3622 #endif /* defined TIZEN_EXT */
3624 static void interface_current_bss(GSupplicantInterface *interface,
3625 DBusMessageIter *iter)
3627 GSupplicantNetwork *network;
3628 struct g_supplicant_bss *bss;
3630 #if defined TIZEN_EXT
3631 char curr_bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3632 char best_bssid_buff[WIFI_BSSID_STR_LEN] = {0,};
3633 char *curr_bssid_str = curr_bssid_buff;
3634 char *best_bssid_str = best_bssid_buff;
3635 gboolean update = FALSE;
3638 dbus_message_iter_get_basic(iter, &path);
3639 if (g_strcmp0(path, "/") == 0) {
3640 interface->current_network = NULL;
3644 interface_bss_added_without_keys(iter, interface);
3646 network = g_hash_table_lookup(interface->bss_mapping, path);
3650 bss = g_hash_table_lookup(network->bss_table, path);
3654 interface->current_network = network;
3655 #if defined TIZEN_EXT
3656 snprintf(curr_bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bss->bssid));
3657 snprintf(best_bssid_str, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(network->best_bss->bssid));
3659 SUPPLICANT_DBG("current network [%p], Passed bss %s, best bss %s",
3660 interface->current_network, curr_bssid_str, best_bssid_str);
3662 if (network->frequency != bss->frequency) {
3663 network->frequency = bss->frequency;
3664 network->phy_mode = bss->phy_mode;
3669 if (bss != network->best_bss) {
3671 * This is the case where either wpa_s got associated
3672 * to a BSS different than the one ConnMan considers
3673 * the best, or we are roaming.
3675 SUPPLICANT_DBG("Update best BSS for %s", network->name);
3677 network->best_bss = bss;
3679 if (network->signal != bss->signal) {
3680 SUPPLICANT_DBG("New network signal %d dBm",
3683 network->signal = bss->signal;
3684 callback_network_changed(network, "Signal");
3685 #if defined TIZEN_EXT
3693 #if defined TIZEN_EXT
3695 callback_network_changed(network, "");
3699 * wpa_s could notify about CurrentBSS in any state once
3700 * it got associated. It is not sure such notification will
3701 * arrive together with transition to ASSOCIATED state.
3702 * In fact, for networks with security WEP or OPEN, it
3703 * always arrives together with transition to COMPLETED.
3705 switch (interface->state) {
3706 case G_SUPPLICANT_STATE_UNKNOWN:
3707 case G_SUPPLICANT_STATE_DISABLED:
3708 case G_SUPPLICANT_STATE_DISCONNECTED:
3709 case G_SUPPLICANT_STATE_INACTIVE:
3710 case G_SUPPLICANT_STATE_SCANNING:
3711 case G_SUPPLICANT_STATE_AUTHENTICATING:
3712 case G_SUPPLICANT_STATE_ASSOCIATING:
3714 case G_SUPPLICANT_STATE_ASSOCIATED:
3715 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
3716 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
3717 case G_SUPPLICANT_STATE_COMPLETED:
3718 callback_network_associated(network);
3719 #if defined TIZEN_EXT
3720 if (TIZEN_INS_ENABLED)
3721 add_timer_for_last_connected(interface);
3727 static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
3729 GSupplicantInterface *interface = user_data;
3730 GSupplicantNetwork *network;
3731 struct g_supplicant_bss *bss = NULL;
3732 const char *path = NULL;
3733 bool is_current_network_bss = false;
3735 dbus_message_iter_get_basic(iter, &path);
3739 network = g_hash_table_lookup(interface->bss_mapping, path);
3743 bss = g_hash_table_lookup(network->bss_table, path);
3744 if (network->best_bss == bss) {
3745 network->best_bss = NULL;
3746 network->signal = BSS_UNKNOWN_STRENGTH;
3747 is_current_network_bss = true;
3750 g_hash_table_remove(bss_mapping, path);
3752 g_hash_table_remove(interface->bss_mapping, path);
3753 g_hash_table_remove(network->bss_table, path);
3755 update_network_signal(network);
3757 if (g_hash_table_size(network->bss_table) == 0) {
3758 g_hash_table_remove(interface->network_table, network->group);
3760 if (is_current_network_bss && network->best_bss)
3761 #if defined TIZEN_EXT
3762 callback_network_changed(network, "CheckMultiBssidConnect");
3764 callback_network_changed(network, "");
3769 static void set_config_methods(DBusMessageIter *iter, void *user_data)
3771 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
3774 static void wps_property(const char *key, DBusMessageIter *iter,
3777 GSupplicantInterface *interface = user_data;
3781 #if defined TIZEN_EXT
3782 if (!simplified_log)
3784 SUPPLICANT_DBG("key: %s", key);
3786 if (g_strcmp0(key, "ConfigMethods") == 0) {
3787 const char *config_methods = "push_button", *str = NULL;
3789 dbus_message_iter_get_basic(iter, &str);
3790 if (str && strlen(str) > 0) {
3791 /* It was already set at wpa_s level, don't modify it. */
3792 SUPPLICANT_DBG("%s", str);
3796 supplicant_dbus_property_set(interface->path,
3797 SUPPLICANT_INTERFACE ".Interface.WPS",
3798 "ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
3799 set_config_methods, NULL, &config_methods, NULL);
3801 SUPPLICANT_DBG("No value. Set %s", config_methods);
3806 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
3807 void g_supplicant_replace_config_file(const char *ifname, const char *config_file)
3815 SUPPLICANT_DBG("New {%s, %s}", ifname, config_file);
3816 g_hash_table_replace(config_file_table,
3817 g_strdup(ifname), g_strdup(config_file));
3819 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
3821 static void interface_property(const char *key, DBusMessageIter *iter,
3824 GSupplicantInterface *interface = user_data;
3828 #if defined TIZEN_EXT
3829 if (!simplified_log)
3831 SUPPLICANT_DBG("%s", key);
3834 debug_strvalmap("KeyMgmt capability", keymgmt_map,
3835 interface->keymgmt_capa);
3836 debug_strvalmap("AuthAlg capability", authalg_capa_map,
3837 interface->authalg_capa);
3838 debug_strvalmap("Protocol capability", proto_capa_map,
3839 interface->proto_capa);
3840 debug_strvalmap("Pairwise capability", pairwise_map,
3841 interface->pairwise_capa);
3842 debug_strvalmap("Group capability", group_map,
3843 interface->group_capa);
3844 debug_strvalmap("Scan capability", scan_capa_map,
3845 interface->scan_capa);
3846 debug_strvalmap("Mode capability", mode_capa_map,
3847 interface->mode_capa);
3849 supplicant_dbus_property_get_all(interface->path,
3850 SUPPLICANT_INTERFACE ".Interface.WPS",
3851 wps_property, interface, interface);
3853 if (interface->ready)
3854 callback_interface_added(interface);
3859 if (g_strcmp0(key, "Capabilities") == 0) {
3860 supplicant_dbus_property_foreach(iter, interface_capability,
3862 #if !defined TIZEN_EXT
3863 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
3864 interface->p2p_support = true;
3866 #if defined TIZEN_EXT_WIFI_MESH
3867 if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_MESH)
3868 interface->mesh_support = true;
3870 } else if (g_strcmp0(key, "State") == 0) {
3871 const char *str = NULL;
3873 dbus_message_iter_get_basic(iter, &str);
3875 if (string2state(str) != interface->state) {
3876 interface->state = string2state(str);
3877 callback_interface_state(interface);
3879 #if defined TIZEN_EXT
3880 if (TIZEN_INS_ENABLED) {
3881 switch (interface->state) {
3882 case G_SUPPLICANT_STATE_COMPLETED:
3883 add_timer_for_last_connected(interface);
3885 case G_SUPPLICANT_STATE_DISCONNECTED:
3886 remove_timer_for_last_connected(interface);
3893 if (interface->ap_create_in_progress) {
3894 if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
3895 callback_ap_create_fail(interface);
3897 interface->ap_create_in_progress = false;
3900 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
3901 interface->ready = FALSE;
3903 interface->ready = TRUE;
3905 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
3906 } else if (g_strcmp0(key, "Scanning") == 0) {
3907 dbus_bool_t scanning = FALSE;
3909 dbus_message_iter_get_basic(iter, &scanning);
3910 interface->scanning = scanning;
3912 if (interface->ready) {
3913 if (interface->scanning)
3914 callback_scan_started(interface);
3916 callback_scan_finished(interface);
3918 } else if (g_strcmp0(key, "ApScan") == 0) {
3921 dbus_message_iter_get_basic(iter, &apscan);
3922 interface->apscan = apscan;
3923 } else if (g_strcmp0(key, "Ifname") == 0) {
3924 const char *str = NULL;
3926 dbus_message_iter_get_basic(iter, &str);
3928 g_free(interface->ifname);
3929 interface->ifname = g_strdup(str);
3931 } else if (g_strcmp0(key, "Driver") == 0) {
3932 const char *str = NULL;
3934 dbus_message_iter_get_basic(iter, &str);
3936 g_free(interface->driver);
3937 interface->driver = g_strdup(str);
3939 } else if (g_strcmp0(key, "BridgeIfname") == 0) {
3940 const char *str = NULL;
3942 dbus_message_iter_get_basic(iter, &str);
3944 g_free(interface->bridge);
3945 interface->bridge = g_strdup(str);
3947 } else if (g_strcmp0(key, "ConfigFile") == 0) {
3948 const char *str = NULL;
3950 dbus_message_iter_get_basic(iter, &str);
3951 if (str && strlen(str) > 0 && interface->ifname) {
3952 SUPPLICANT_DBG("New {%s, %s}", interface->ifname, str);
3953 g_hash_table_replace(config_file_table,
3954 g_strdup(interface->ifname), g_strdup(str));
3956 } else if (g_strcmp0(key, "CurrentBSS") == 0) {
3957 interface_current_bss(interface, iter);
3958 } else if (g_strcmp0(key, "CurrentNetwork") == 0) {
3959 #if defined TIZEN_EXT
3960 if (interface->state != G_SUPPLICANT_STATE_COMPLETED)
3962 interface_network_added(iter, interface);
3963 } else if (g_strcmp0(key, "BSSs") == 0) {
3964 supplicant_dbus_array_foreach(iter,
3965 interface_bss_added_without_keys,
3967 } else if (g_strcmp0(key, "Blobs") == 0) {
3969 } else if (g_strcmp0(key, "Networks") == 0) {
3970 supplicant_dbus_array_foreach(iter, interface_network_added,
3972 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
3974 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3975 dbus_message_iter_get_basic(iter, &reason_code);
3976 callback_disconnect_reason_code(interface, reason_code);
3977 #if defined TIZEN_EXT
3978 SUPPLICANT_DBG("reason code (%d)", reason_code);
3981 } else if (g_strcmp0(key, "AssocStatusCode") == 0) {
3983 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
3984 dbus_message_iter_get_basic(iter, &status_code);
3985 callback_assoc_status_code(interface, status_code);
3986 #if defined TIZEN_EXT
3987 SUPPLICANT_DBG("status code (%d)", status_code);
3991 SUPPLICANT_DBG("key %s type %c",
3992 key, dbus_message_iter_get_arg_type(iter));
3996 static void scan_network_update(DBusMessageIter *iter, void *user_data)
3998 GSupplicantInterface *interface = user_data;
3999 GSupplicantNetwork *network;
4005 dbus_message_iter_get_basic(iter, &path);
4010 if (g_strcmp0(path, "/") == 0)
4013 /* Update the network details based on scan BSS data */
4014 network = g_hash_table_lookup(interface->bss_mapping, path);
4016 callback_network_added(network);
4019 static void scan_bss_data(const char *key, DBusMessageIter *iter,
4022 GSupplicantInterface *interface = user_data;
4024 /*Fixed : stucking in scanning state when scan failed*/
4025 #if defined TIZEN_EXT
4026 GSupplicantInterfaceCallback scan_callback;
4031 supplicant_dbus_array_foreach(iter, scan_network_update,
4034 #if defined TIZEN_EXT
4035 scan_callback = interface->scan_callback;
4036 callback_scan_done(interface);
4039 if (interface->scan_callback)
4040 interface->scan_callback(0, interface, interface->scan_data);
4042 #if defined TIZEN_EXT
4043 if (interface->scan_callback == scan_callback) {
4045 interface->scan_callback = NULL;
4046 interface->scan_data = NULL;
4047 #if defined TIZEN_EXT
4052 static GSupplicantInterface *interface_alloc(const char *path)
4054 GSupplicantInterface *interface;
4056 interface = g_try_new0(GSupplicantInterface, 1);
4060 interface->path = g_strdup(path);
4062 interface->network_table = g_hash_table_new_full(g_str_hash,
4063 g_str_equal, NULL, remove_network);
4064 interface->peer_table = g_hash_table_new_full(g_str_hash,
4065 g_str_equal, NULL, remove_peer);
4066 interface->group_table = g_hash_table_new_full(g_str_hash,
4067 g_str_equal, NULL, remove_group);
4068 interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
4071 g_hash_table_replace(interface_table, interface->path, interface);
4076 static void interface_added(DBusMessageIter *iter, void *user_data)
4078 GSupplicantInterface *interface;
4079 const char *path = NULL;
4080 bool properties_appended = GPOINTER_TO_UINT(user_data);
4084 dbus_message_iter_get_basic(iter, &path);
4088 if (g_strcmp0(path, "/") == 0)
4091 interface = g_hash_table_lookup(interface_table, path);
4095 interface = interface_alloc(path);
4099 if (!properties_appended) {
4100 supplicant_dbus_property_get_all(path,
4101 SUPPLICANT_INTERFACE ".Interface",
4102 interface_property, interface,
4107 dbus_message_iter_next(iter);
4108 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4109 supplicant_dbus_property_foreach(iter, interface_property,
4111 interface_property(NULL, NULL, interface);
4115 static void interface_removed(DBusMessageIter *iter, void *user_data)
4117 const char *path = NULL;
4118 GSupplicantInterface *interface = user_data;
4120 dbus_message_iter_get_basic(iter, &path);
4124 interface = g_hash_table_lookup(interface_table, path);
4125 g_supplicant_interface_cancel(interface);
4127 g_hash_table_remove(interface_table, path);
4130 static void eap_method(DBusMessageIter *iter, void *user_data)
4132 const char *str = NULL;
4135 dbus_message_iter_get_basic(iter, &str);
4139 for (i = 0; eap_method_map[i].str; i++)
4140 if (strcmp(str, eap_method_map[i].str) == 0) {
4141 eap_methods |= eap_method_map[i].val;
4146 static void service_property(const char *key, DBusMessageIter *iter,
4150 callback_system_ready();
4154 if (g_strcmp0(key, "DebugLevel") == 0) {
4155 const char *str = NULL;
4158 dbus_message_iter_get_basic(iter, &str);
4159 for (i = 0; debug_strings[i]; i++)
4160 if (g_strcmp0(debug_strings[i], str) == 0) {
4164 SUPPLICANT_DBG("Debug level %d", debug_level);
4165 } else if (g_strcmp0(key, "DebugTimestamp") == 0) {
4166 dbus_message_iter_get_basic(iter, &debug_timestamp);
4167 SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
4168 } else if (g_strcmp0(key, "DebugShowKeys") == 0) {
4169 dbus_message_iter_get_basic(iter, &debug_showkeys);
4170 SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
4171 } else if (g_strcmp0(key, "Interfaces") == 0) {
4172 supplicant_dbus_array_foreach(iter, interface_added, NULL);
4173 } else if (g_strcmp0(key, "EapMethods") == 0) {
4174 supplicant_dbus_array_foreach(iter, eap_method, NULL);
4175 debug_strvalmap("EAP method", eap_method_map, eap_methods);
4176 } else if (g_strcmp0(key, "Country") == 0) {
4177 const char *country = NULL;
4179 dbus_message_iter_get_basic(iter, &country);
4180 SUPPLICANT_DBG("Country %s", country);
4182 SUPPLICANT_DBG("key %s type %c",
4183 key, dbus_message_iter_get_arg_type(iter));
4186 static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
4188 const char *name = NULL, *old = NULL, *new = NULL;
4192 if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
4195 dbus_message_iter_get_basic(iter, &name);
4199 if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
4202 dbus_message_iter_next(iter);
4203 dbus_message_iter_get_basic(iter, &old);
4204 dbus_message_iter_next(iter);
4205 dbus_message_iter_get_basic(iter, &new);
4210 if (strlen(old) > 0 && strlen(new) == 0) {
4211 system_available = FALSE;
4212 g_hash_table_remove_all(bss_mapping);
4213 g_hash_table_remove_all(peer_mapping);
4214 g_hash_table_remove_all(group_mapping);
4215 g_hash_table_remove_all(config_file_table);
4216 g_hash_table_remove_all(interface_table);
4217 callback_system_killed();
4220 if (strlen(new) > 0 && strlen(old) == 0) {
4221 system_available = TRUE;
4222 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
4223 SUPPLICANT_INTERFACE,
4224 service_property, NULL, NULL);
4228 static void signal_properties_changed(const char *path, DBusMessageIter *iter)
4232 if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
4235 supplicant_dbus_property_foreach(iter, service_property, NULL);
4238 static void signal_interface_added(const char *path, DBusMessageIter *iter)
4240 SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
4242 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4243 interface_added(iter, GUINT_TO_POINTER(true));
4246 static void signal_interface_removed(const char *path, DBusMessageIter *iter)
4250 if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
4251 interface_removed(iter, NULL);
4254 static void signal_interface_changed(const char *path, DBusMessageIter *iter)
4256 GSupplicantInterface *interface;
4257 #if defined TIZEN_EXT
4258 if (!simplified_log)
4262 interface = g_hash_table_lookup(interface_table, path);
4266 supplicant_dbus_property_foreach(iter, interface_property, interface);
4269 static void signal_scan_done(const char *path, DBusMessageIter *iter)
4271 GSupplicantInterface *interface;
4272 dbus_bool_t success = FALSE;
4276 interface = g_hash_table_lookup(interface_table, path);
4280 dbus_message_iter_get_basic(iter, &success);
4282 if (interface->scanning) {
4283 callback_scan_finished(interface);
4284 interface->scanning = FALSE;
4288 * If scan is unsuccessful return -EIO else get the scanned BSSs
4289 * and update the network details accordingly
4292 if (interface->scan_callback)
4293 interface->scan_callback(-EIO, interface,
4294 interface->scan_data);
4296 interface->scan_callback = NULL;
4297 interface->scan_data = NULL;
4302 supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
4303 "BSSs", scan_bss_data, interface, interface);
4306 static void signal_bss_added(const char *path, DBusMessageIter *iter)
4308 GSupplicantInterface *interface;
4309 #if defined TIZEN_EXT
4310 if (!simplified_log)
4314 interface = g_hash_table_lookup(interface_table, path);
4318 interface_bss_added_with_keys(iter, interface);
4321 static void signal_bss_removed(const char *path, DBusMessageIter *iter)
4323 GSupplicantInterface *interface;
4327 interface = g_hash_table_lookup(interface_table, path);
4331 interface_bss_removed(iter, interface);
4334 static void signal_network_added(const char *path, DBusMessageIter *iter)
4336 GSupplicantInterface *interface;
4340 interface = g_hash_table_lookup(interface_table, path);
4344 interface_network_added(iter, interface);
4347 static void signal_network_removed(const char *path, DBusMessageIter *iter)
4349 GSupplicantInterface *interface;
4353 interface = g_hash_table_lookup(interface_table, path);
4357 interface_network_removed(iter, interface);
4359 #if defined TIZEN_EXT
4360 void *copy_vsie_list(gconstpointer src, gpointer data)
4362 return g_strdup(src);
4367 static void signal_sta_authorized(const char *path, DBusMessageIter *iter)
4369 GSupplicantInterface *interface;
4370 const char *addr = NULL;
4374 interface = g_hash_table_lookup(interface_table, path);
4378 dbus_message_iter_get_basic(iter, &addr);
4382 callback_sta_authorized(interface, addr);
4385 static void signal_sta_deauthorized(const char *path, DBusMessageIter *iter)
4387 GSupplicantInterface *interface;
4388 const char *addr = NULL;
4392 interface = g_hash_table_lookup(interface_table, path);
4396 dbus_message_iter_get_basic(iter, &addr);
4400 callback_sta_deauthorized(interface, addr);
4403 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
4404 static void signal_eap(const char *path, DBusMessageIter *iter)
4406 GSupplicantInterface *interface;
4407 const char *str = NULL;
4409 SUPPLICANT_DBG("EAPOL_DEBUG callback eap signal");
4411 interface = g_hash_table_lookup(interface_table, path);
4415 // TODO: Identify EAP fail condition, currently timeout is used for failure.
4417 dbus_message_iter_get_basic(iter, &str);
4421 if (g_strcmp0("completion", str))
4424 dbus_message_iter_next(iter);
4426 dbus_message_iter_get_basic(iter, &str);
4430 if (!g_strcmp0("success", str))
4431 callback_eap(interface, true);
4433 callback_eap(interface, false);
4435 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
4437 static void signal_bss_changed(const char *path, DBusMessageIter *iter)
4439 GSupplicantInterface *interface;
4440 GSupplicantNetwork *network;
4441 GSupplicantSecurity old_security;
4442 unsigned int old_wps_capabilities;
4443 struct g_supplicant_bss *bss;
4445 #if defined TIZEN_EXT
4446 if (!simplified_log)
4450 interface = g_hash_table_lookup(bss_mapping, path);
4454 network = g_hash_table_lookup(interface->bss_mapping, path);
4458 bss = g_hash_table_lookup(network->bss_table, path);
4462 supplicant_dbus_property_foreach(iter, bss_property, bss);
4464 #if defined TIZEN_EXT
4465 if (network->interface->state != G_SUPPLICANT_STATE_COMPLETED &&
4466 bss == network->best_bss) {
4467 network->frequency = bss->frequency;
4468 network->phy_mode = bss->phy_mode;
4471 old_security = network->security;
4472 bss_compute_security(bss);
4474 if (old_security != bss->security) {
4475 struct g_supplicant_bss *new_bss;
4477 SUPPLICANT_DBG("New network security for %s with path %s",
4478 bss->ssid, bss->path);
4481 * Security change policy:
4482 * - We first copy the current bss into a new one with
4483 * its own pointer (path)
4484 * - Clear the old bss pointer and remove the network completely
4485 * if there are no more BSSs in the bss table.
4486 * - The new bss will be added either to an existing network
4487 * or an additional network will be created
4490 new_bss = g_try_new0(struct g_supplicant_bss, 1);
4494 memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
4495 new_bss->path = g_strdup(bss->path);
4496 #if defined TIZEN_EXT
4497 new_bss->vsie_list = g_slist_copy_deep(bss->vsie_list, copy_vsie_list, NULL);
4500 if (network->best_bss == bss) {
4501 network->best_bss = NULL;
4502 network->signal = BSS_UNKNOWN_STRENGTH;
4505 g_hash_table_remove(bss_mapping, path);
4507 g_hash_table_remove(interface->bss_mapping, path);
4508 g_hash_table_remove(network->bss_table, path);
4510 update_network_signal(network);
4512 if (g_hash_table_size(network->bss_table) == 0)
4513 g_hash_table_remove(interface->network_table,
4516 if (add_or_replace_bss_to_network(new_bss) < 0) {
4518 * Prevent a memory leak on failure in
4519 * add_or_replace_bss_to_network
4521 SUPPLICANT_DBG("Failed to add bss %s to network table",
4523 g_free(new_bss->path);
4530 old_wps_capabilities = network->wps_capabilities;
4532 if (old_wps_capabilities != bss->wps_capabilities) {
4533 network->wps_capabilities = bss->wps_capabilities;
4534 callback_network_changed(network, "WPSCapabilities");
4537 #if defined TIZEN_EXT
4538 if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
4539 network->wps = TRUE;
4540 network->wps_capabilities |= bss->wps_capabilities;
4542 network->wps = FALSE;
4545 /* Consider only property changes of the connected BSS */
4546 if (network == interface->current_network && bss != network->best_bss)
4549 if (bss->signal == network->signal)
4554 callback_network_changed(network, "");
4560 * If the new signal is lower than the SSID signal, we need
4561 * to check for the new maximum.
4563 #if defined TIZEN_EXT
4564 if (!update_best_bss(network, bss, network->best_bss)) {
4565 if (bss != network->best_bss) {
4566 callback_network_changed(network, "");
4570 network->signal = bss->signal;
4571 update_network_signal(network);
4574 if (bss->signal < network->signal) {
4575 if (bss != network->best_bss)
4578 network->signal = bss->signal;
4579 update_network_signal(network);
4581 network->signal = bss->signal;
4582 network->best_bss = bss;
4586 SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
4589 callback_network_changed(network, "Signal");
4592 static void wps_credentials(const char *key, DBusMessageIter *iter,
4595 GSupplicantInterface *interface = user_data;
4600 SUPPLICANT_DBG("key %s", key);
4602 if (g_strcmp0(key, "Key") == 0) {
4603 DBusMessageIter array;
4604 unsigned char *key_val;
4607 dbus_message_iter_recurse(iter, &array);
4608 dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
4610 g_free(interface->wps_cred.key);
4611 interface->wps_cred.key = g_try_malloc0(
4612 sizeof(char) * key_len + 1);
4614 if (!interface->wps_cred.key)
4617 memcpy(interface->wps_cred.key, key_val,
4618 sizeof(char) * key_len);
4620 SUPPLICANT_DBG("WPS key present");
4621 } else if (g_strcmp0(key, "SSID") == 0) {
4622 DBusMessageIter array;
4623 unsigned char *ssid;
4626 dbus_message_iter_recurse(iter, &array);
4627 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
4629 if (ssid_len > 0 && ssid_len < 33) {
4630 memcpy(interface->wps_cred.ssid, ssid, ssid_len);
4631 interface->wps_cred.ssid_len = ssid_len;
4633 memset(interface->wps_cred.ssid, 0, 32);
4634 interface->wps_cred.ssid_len = 0;
4639 static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
4641 GSupplicantInterface *interface;
4645 interface = g_hash_table_lookup(interface_table, path);
4649 supplicant_dbus_property_foreach(iter, wps_credentials, interface);
4652 static void wps_event_args(const char *key, DBusMessageIter *iter,
4655 GSupplicantInterface *interface = user_data;
4657 if (!key || !interface)
4660 SUPPLICANT_DBG("Arg Key %s", key);
4663 static void signal_wps_event(const char *path, DBusMessageIter *iter)
4665 GSupplicantInterface *interface;
4666 const char *name = NULL;
4670 interface = g_hash_table_lookup(interface_table, path);
4674 dbus_message_iter_get_basic(iter, &name);
4676 SUPPLICANT_DBG("Name: %s", name);
4678 if (g_strcmp0(name, "success") == 0)
4679 interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
4680 else if (g_strcmp0(name, "fail") == 0)
4681 interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
4683 interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
4685 if (!dbus_message_iter_has_next(iter))
4688 dbus_message_iter_next(iter);
4690 supplicant_dbus_property_foreach(iter, wps_event_args, interface);
4693 #if defined TIZEN_EXT
4694 static void signal_power_off(const char *path, DBusMessageIter *iter)
4696 int poweroff_state = 0;
4698 dbus_message_iter_get_basic(iter, &poweroff_state);
4700 SUPPLICANT_DBG("poweroff_state(%d)", poweroff_state);
4702 /* POWER_OFF_DIRECT 2 && POWER_OFF_RESTART 3 */
4703 if (poweroff_state != 2 && poweroff_state != 3)
4706 if (callbacks_pointer == NULL)
4709 if (callbacks_pointer->system_power_off == NULL)
4712 callbacks_pointer->system_power_off();
4716 static void create_peer_identifier(GSupplicantPeer *peer)
4718 const unsigned char test[ETH_ALEN] = {};
4723 if (!memcmp(peer->device_address, test, ETH_ALEN)) {
4724 peer->identifier = g_strdup(peer->name);
4728 peer->identifier = g_malloc0(19);
4729 snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
4730 peer->device_address[0],
4731 peer->device_address[1],
4732 peer->device_address[2],
4733 peer->device_address[3],
4734 peer->device_address[4],
4735 peer->device_address[5]);
4738 struct peer_property_data {
4739 GSupplicantPeer *peer;
4741 bool groups_changed;
4742 bool services_changed;
4745 static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
4747 struct peer_property_data *data = user_data;
4748 GSupplicantPeer *peer = data->peer;
4749 GSupplicantGroup *group;
4750 const char *str = NULL;
4753 dbus_message_iter_get_basic(iter, &str);
4757 group = g_hash_table_lookup(group_mapping, str);
4761 elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
4763 data->old_groups = g_slist_remove_link(data->old_groups, elem);
4764 peer->groups = g_slist_concat(elem, peer->groups);
4766 peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
4767 data->groups_changed = true;
4771 static void peer_property(const char *key, DBusMessageIter *iter,
4774 GSupplicantPeer *pending_peer;
4775 struct peer_property_data *data = user_data;
4776 GSupplicantPeer *peer = data->peer;
4778 SUPPLICANT_DBG("key: %s", key);
4780 if (!peer->interface)
4785 create_peer_identifier(peer);
4786 callback_peer_found(peer);
4787 pending_peer = g_hash_table_lookup(
4788 pending_peer_connection, peer->path);
4790 if (pending_peer && pending_peer == peer) {
4791 callback_peer_request(peer);
4792 g_hash_table_remove(pending_peer_connection,
4802 if (g_strcmp0(key, "DeviceAddress") == 0) {
4803 unsigned char *dev_addr;
4804 DBusMessageIter array;
4807 dbus_message_iter_recurse(iter, &array);
4808 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4810 if (len == ETH_ALEN)
4811 memcpy(peer->device_address, dev_addr, len);
4812 } else if (g_strcmp0(key, "DeviceName") == 0) {
4813 const char *str = NULL;
4815 dbus_message_iter_get_basic(iter, &str);
4817 peer->name = g_strdup(str);
4818 } else if (g_strcmp0(key, "config_method") == 0) {
4819 uint16_t wps_config;
4821 dbus_message_iter_get_basic(iter, &wps_config);
4823 if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
4824 peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
4825 if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
4826 peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
4827 } else if (g_strcmp0(key, "Groups") == 0) {
4828 data->old_groups = peer->groups;
4829 peer->groups = NULL;
4831 supplicant_dbus_array_foreach(iter,
4832 peer_groups_relation, data);
4833 if (g_slist_length(data->old_groups) > 0) {
4834 g_slist_free_full(data->old_groups, g_free);
4835 data->groups_changed = true;
4837 } else if (g_strcmp0(key, "IEs") == 0) {
4838 DBusMessageIter array;
4842 dbus_message_iter_recurse(iter, &array);
4843 dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
4845 if (!ie || ie_len < 2)
4848 if (peer->widi_ies) {
4849 if (memcmp(peer->widi_ies, ie, ie_len) == 0)
4852 g_free(peer->widi_ies);
4853 peer->widi_ies_length = 0;
4856 peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
4858 memcpy(peer->widi_ies, ie, ie_len);
4859 peer->widi_ies_length = ie_len;
4860 data->services_changed = true;
4864 static void signal_peer_found(const char *path, DBusMessageIter *iter)
4866 struct peer_property_data *property_data;
4867 GSupplicantInterface *interface;
4868 const char *obj_path = NULL;
4869 GSupplicantPeer *peer;
4873 interface = g_hash_table_lookup(interface_table, path);
4877 dbus_message_iter_get_basic(iter, &obj_path);
4878 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4881 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4885 peer = g_try_new0(GSupplicantPeer, 1);
4889 peer->interface = interface;
4890 peer->path = g_strdup(obj_path);
4891 g_hash_table_insert(interface->peer_table, peer->path, peer);
4892 g_hash_table_replace(peer_mapping, peer->path, interface);
4894 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4895 property_data->peer = peer;
4897 dbus_message_iter_next(iter);
4898 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
4899 supplicant_dbus_property_foreach(iter, peer_property,
4901 peer_property(NULL, NULL, property_data);
4905 supplicant_dbus_property_get_all(obj_path,
4906 SUPPLICANT_INTERFACE ".Peer",
4907 peer_property, property_data, NULL);
4910 static void signal_peer_lost(const char *path, DBusMessageIter *iter)
4912 GSupplicantInterface *interface;
4913 const char *obj_path = NULL;
4914 GSupplicantPeer *peer;
4918 interface = g_hash_table_lookup(interface_table, path);
4922 dbus_message_iter_get_basic(iter, &obj_path);
4923 if (!obj_path || g_strcmp0(obj_path, "/") == 0)
4926 peer = g_hash_table_lookup(interface->peer_table, obj_path);
4930 g_hash_table_remove(interface->peer_table, obj_path);
4933 static void signal_peer_changed(const char *path, DBusMessageIter *iter)
4935 struct peer_property_data *property_data;
4936 GSupplicantInterface *interface;
4937 GSupplicantPeer *peer;
4941 interface = g_hash_table_lookup(peer_mapping, path);
4945 peer = g_hash_table_lookup(interface->peer_table, path);
4947 g_hash_table_remove(peer_mapping, path);
4951 property_data = dbus_malloc0(sizeof(struct peer_property_data));
4952 property_data->peer = peer;
4954 supplicant_dbus_property_foreach(iter, peer_property, property_data);
4955 if (property_data->services_changed)
4956 callback_peer_changed(peer,
4957 G_SUPPLICANT_PEER_SERVICES_CHANGED);
4959 if (property_data->groups_changed)
4960 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
4962 dbus_free(property_data);
4964 if (!g_supplicant_peer_is_in_a_group(peer))
4965 peer->connection_requested = false;
4968 struct group_sig_data {
4969 const char *peer_obj_path;
4970 unsigned char iface_address[ETH_ALEN];
4971 const char *interface_obj_path;
4972 const char *group_obj_path;
4976 static void group_sig_property(const char *key, DBusMessageIter *iter,
4979 struct group_sig_data *data = user_data;
4984 if (g_strcmp0(key, "peer_interface_addr") == 0) {
4985 unsigned char *dev_addr;
4986 DBusMessageIter array;
4989 dbus_message_iter_recurse(iter, &array);
4990 dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
4992 if (len == ETH_ALEN)
4993 memcpy(data->iface_address, dev_addr, len);
4994 } else if (g_strcmp0(key, "role") == 0) {
4995 const char *str = NULL;
4997 dbus_message_iter_get_basic(iter, &str);
4998 if (g_strcmp0(str, "GO") == 0)
4999 data->role = G_SUPPLICANT_GROUP_ROLE_GO;
5001 data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
5002 } else if (g_strcmp0(key, "peer_object") == 0)
5003 dbus_message_iter_get_basic(iter, &data->peer_obj_path);
5004 else if (g_strcmp0(key, "interface_object") == 0)
5005 dbus_message_iter_get_basic(iter, &data->interface_obj_path);
5006 else if (g_strcmp0(key, "group_object") == 0)
5007 dbus_message_iter_get_basic(iter, &data->group_obj_path);
5011 static void signal_group_success(const char *path, DBusMessageIter *iter)
5013 GSupplicantInterface *interface;
5014 struct group_sig_data data = {};
5015 GSupplicantPeer *peer;
5019 interface = g_hash_table_lookup(interface_table, path);
5023 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5024 if (!data.peer_obj_path)
5027 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
5031 memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
5032 interface->pending_peer_path = peer->path;
5035 static void signal_group_failure(const char *path, DBusMessageIter *iter)
5037 GSupplicantInterface *interface;
5038 struct group_sig_data data = {};
5039 GSupplicantPeer *peer;
5043 interface = g_hash_table_lookup(interface_table, path);
5047 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5048 if (!data.peer_obj_path)
5051 peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
5055 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
5056 peer->connection_requested = false;
5059 static void signal_group_started(const char *path, DBusMessageIter *iter)
5061 GSupplicantInterface *interface, *g_interface;
5062 struct group_sig_data data = {};
5063 GSupplicantGroup *group;
5064 GSupplicantPeer *peer;
5068 interface = g_hash_table_lookup(interface_table, path);
5072 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5073 if (!data.interface_obj_path || !data.group_obj_path)
5076 peer = g_hash_table_lookup(interface->peer_table,
5077 interface->pending_peer_path);
5078 interface->pending_peer_path = NULL;
5082 g_interface = g_hash_table_lookup(interface_table,
5083 data.interface_obj_path);
5087 group = g_hash_table_lookup(interface->group_table,
5088 data.group_obj_path);
5092 group = g_try_new0(GSupplicantGroup, 1);
5096 group->interface = g_interface;
5097 group->orig_interface = interface;
5098 group->path = g_strdup(data.group_obj_path);
5099 group->role = data.role;
5101 g_hash_table_insert(interface->group_table, group->path, group);
5102 g_hash_table_replace(group_mapping, group->path, group);
5104 peer->current_group_iface = g_interface;
5105 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
5108 static void remove_peer_group_interface(GHashTable *group_table,
5111 GSupplicantGroup *group;
5112 GHashTableIter iter;
5113 gpointer value, key;
5118 group = g_hash_table_lookup(group_table, path);
5120 if (!group || !group->orig_interface)
5123 g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
5125 while (g_hash_table_iter_next(&iter, &key, &value)) {
5126 GSupplicantPeer *peer = value;
5128 if (peer->current_group_iface == group->interface)
5129 peer->current_group_iface = NULL;
5133 static void signal_group_finished(const char *path, DBusMessageIter *iter)
5135 GSupplicantInterface *interface;
5136 struct group_sig_data data = {};
5140 interface = g_hash_table_lookup(interface_table, path);
5144 supplicant_dbus_property_foreach(iter, group_sig_property, &data);
5145 if (!data.interface_obj_path || !data.group_obj_path)
5148 remove_peer_group_interface(interface->group_table, data.group_obj_path);
5150 g_hash_table_remove(group_mapping, data.group_obj_path);
5152 g_hash_table_remove(interface->group_table, data.group_obj_path);
5155 static void signal_group_request(const char *path, DBusMessageIter *iter)
5157 GSupplicantInterface *interface;
5158 GSupplicantPeer *peer;
5159 const char *obj_path;
5163 interface = g_hash_table_lookup(interface_table, path);
5167 dbus_message_iter_get_basic(iter, &obj_path);
5168 if (!obj_path || !g_strcmp0(obj_path, "/"))
5171 peer = g_hash_table_lookup(interface->peer_table, obj_path);
5176 * Peer has been previously found and property set,
5177 * otherwise, defer connection to when peer property
5180 if (peer->identifier)
5181 callback_peer_request(peer);
5183 g_hash_table_replace(pending_peer_connection, peer->path, peer);
5186 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
5188 const char *peer_path = NULL;
5189 GSupplicantInterface *interface;
5190 GSupplicantGroup *group;
5191 GSupplicantPeer *peer;
5195 group = g_hash_table_lookup(group_mapping, path);
5199 dbus_message_iter_get_basic(iter, &peer_path);
5203 interface = g_hash_table_lookup(peer_mapping, peer_path);
5207 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5211 group->members = g_slist_prepend(group->members, g_strdup(peer_path));
5213 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
5216 static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
5218 const char *peer_path = NULL;
5219 GSupplicantInterface *interface;
5220 GSupplicantGroup *group;
5221 GSupplicantPeer *peer;
5226 group = g_hash_table_lookup(group_mapping, path);
5230 dbus_message_iter_get_basic(iter, &peer_path);
5234 for (elem = group->members; elem; elem = elem->next) {
5235 if (!g_strcmp0(elem->data, peer_path))
5243 group->members = g_slist_delete_link(group->members, elem);
5245 interface = g_hash_table_lookup(peer_mapping, peer_path);
5249 peer = g_hash_table_lookup(interface->peer_table, peer_path);
5253 callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
5254 peer->connection_requested = false;
5257 #if defined TIZEN_EXT_WIFI_MESH
5258 const void *g_supplicant_interface_get_mesh_group_ssid(
5259 GSupplicantInterface *interface,
5260 unsigned int *ssid_len)
5265 if (!interface || interface->group_info.ssid_len == 0) {
5270 *ssid_len = interface->group_info.ssid_len;
5271 return interface->group_info.ssid;
5274 int g_supplicant_mesh_get_disconnect_reason(GSupplicantInterface *interface)
5279 return interface->group_info.disconnect_reason;
5282 const char *g_supplicant_mesh_peer_get_address(GSupplicantMeshPeer *mesh_peer)
5284 if (!mesh_peer || !mesh_peer->peer_address)
5287 return mesh_peer->peer_address;
5290 int g_supplicant_mesh_peer_get_disconnect_reason(GSupplicantMeshPeer *mesh_peer)
5295 return mesh_peer->disconnect_reason;
5298 static void callback_mesh_group_started(GSupplicantInterface *interface)
5300 if (!callbacks_pointer)
5303 if (!callbacks_pointer->mesh_group_started)
5306 callbacks_pointer->mesh_group_started(interface);
5309 static void callback_mesh_group_removed(GSupplicantInterface *interface)
5311 if (!callbacks_pointer)
5314 if (!callbacks_pointer->mesh_group_removed)
5317 callbacks_pointer->mesh_group_removed(interface);
5320 static void mesh_group_info(const char *key, DBusMessageIter *iter,
5323 GSupplicantInterface *interface = user_data;
5327 if (g_strcmp0(key, "SSID") == 0) {
5328 DBusMessageIter array;
5329 unsigned char *ssid;
5332 dbus_message_iter_recurse(iter, &array);
5333 dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
5335 if (ssid_len > 0 && ssid_len < 33) {
5336 memcpy(interface->group_info.ssid, ssid, ssid_len);
5337 interface->group_info.ssid_len = ssid_len;
5339 memset(interface->group_info.ssid, 0, 32);
5340 interface->group_info.ssid_len = 0;
5342 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5343 int disconnect_reason = 0;
5344 dbus_message_iter_get_basic(iter, &disconnect_reason);
5345 interface->group_info.disconnect_reason = disconnect_reason;
5349 static void signal_mesh_group_started(const char *path, DBusMessageIter *iter)
5351 GSupplicantInterface *interface;
5353 interface = g_hash_table_lookup(interface_table, path);
5357 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5359 callback_mesh_group_started(interface);
5362 static void signal_mesh_group_removed(const char *path, DBusMessageIter *iter)
5364 GSupplicantInterface *interface;
5366 interface = g_hash_table_lookup(interface_table, path);
5370 supplicant_dbus_property_foreach(iter, mesh_group_info, interface);
5372 callback_mesh_group_removed(interface);
5375 static void callback_mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
5377 if (!callbacks_pointer)
5380 if (!callbacks_pointer->mesh_peer_connected)
5383 callbacks_pointer->mesh_peer_connected(mesh_peer);
5386 static void callback_mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
5388 if (!callbacks_pointer)
5391 if (!callbacks_pointer->mesh_peer_disconnected)
5394 callbacks_pointer->mesh_peer_disconnected(mesh_peer);
5397 static void mesh_peer_info(const char *key, DBusMessageIter *iter,
5400 GSupplicantMeshPeer *mesh_peer = user_data;
5404 if (g_strcmp0(key, "PeerAddress") == 0) {
5405 DBusMessageIter array;
5406 unsigned char *addr;
5409 dbus_message_iter_recurse(iter, &array);
5410 dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
5412 if (addr_len == 6) {
5413 mesh_peer->peer_address = g_malloc0(19);
5414 snprintf(mesh_peer->peer_address, 19,
5415 "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1],
5416 addr[2], addr[3], addr[4], addr[5]);
5418 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
5419 int disconnect_reason = 0;
5420 dbus_message_iter_get_basic(iter, &disconnect_reason);
5421 mesh_peer->disconnect_reason = disconnect_reason;
5425 static void signal_mesh_peer_connected(const char *path, DBusMessageIter *iter)
5427 GSupplicantInterface *interface;
5428 GSupplicantMeshPeer *mesh_peer;
5430 interface = g_hash_table_lookup(interface_table, path);
5434 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5435 mesh_peer->interface = interface;
5437 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5439 callback_mesh_peer_connected(mesh_peer);
5440 g_free(mesh_peer->peer_address);
5444 static void signal_mesh_peer_disconnected(const char *path,
5445 DBusMessageIter *iter)
5447 GSupplicantInterface *interface;
5448 GSupplicantMeshPeer *mesh_peer;
5450 interface = g_hash_table_lookup(interface_table, path);
5454 mesh_peer = dbus_malloc0(sizeof(GSupplicantMeshPeer));
5455 mesh_peer->interface = interface;
5457 supplicant_dbus_property_foreach(iter, mesh_peer_info, mesh_peer);
5459 callback_mesh_peer_disconnected(mesh_peer);
5460 g_free(mesh_peer->peer_address);
5466 const char *interface;
5468 void (*function) (const char *path, DBusMessageIter *iter);
5470 { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
5472 { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
5473 { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
5474 { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
5475 { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
5477 { SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
5478 { SUPPLICANT_INTERFACE ".Interface", "ScanDone", signal_scan_done },
5479 { SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
5480 { SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
5481 { SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
5482 { SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
5483 { SUPPLICANT_INTERFACE ".Interface", "StaAuthorized", signal_sta_authorized },
5484 { SUPPLICANT_INTERFACE ".Interface", "StaDeauthorized", signal_sta_deauthorized },
5486 { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
5488 { SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
5489 { SUPPLICANT_INTERFACE ".Interface.WPS", "Event", signal_wps_event },
5490 #if defined TIZEN_EXT
5491 { "org.tizen.system.deviced.PowerOff", "ChangeState", signal_power_off },
5494 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
5495 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost", signal_peer_lost },
5497 { SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
5499 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
5500 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
5501 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
5502 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
5503 { SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
5505 { SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
5506 { SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
5507 #if defined TIZEN_EXT_WIFI_MESH
5508 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupStarted",
5509 signal_mesh_group_started },
5510 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshGroupRemoved",
5511 signal_mesh_group_removed },
5512 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerConnected",
5513 signal_mesh_peer_connected },
5514 { SUPPLICANT_INTERFACE ".Interface.Mesh", "MeshPeerDisconnected",
5515 signal_mesh_peer_disconnected },
5518 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
5519 { SUPPLICANT_INTERFACE ".Interface", "EAP", signal_eap },
5520 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
5525 static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
5526 DBusMessage *message, void *data)
5528 DBusMessageIter iter;
5532 path = dbus_message_get_path(message);
5534 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5536 if (!dbus_message_iter_init(message, &iter))
5537 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5539 for (i = 0; signal_map[i].interface; i++) {
5540 if (!dbus_message_has_interface(message, signal_map[i].interface))
5543 if (!dbus_message_has_member(message, signal_map[i].member))
5546 signal_map[i].function(path, &iter);
5550 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
5553 void g_supplicant_interface_cancel(GSupplicantInterface *interface)
5555 SUPPLICANT_DBG("Cancelling any pending DBus calls");
5556 supplicant_dbus_method_call_cancel_all(interface);
5557 supplicant_dbus_property_call_cancel_all(interface);
5560 struct supplicant_regdom {
5561 GSupplicantCountryCallback callback;
5563 const void *user_data;
5566 static void country_result(const char *error,
5567 DBusMessageIter *iter, void *user_data)
5569 struct supplicant_regdom *regdom = user_data;
5572 SUPPLICANT_DBG("Country setting result");
5578 SUPPLICANT_DBG("Country setting failure %s", error);
5582 if (regdom->callback)
5583 regdom->callback(result, regdom->alpha2,
5584 (void *) regdom->user_data);
5589 static void country_params(DBusMessageIter *iter, void *user_data)
5591 struct supplicant_regdom *regdom = user_data;
5593 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
5597 int g_supplicant_set_country(const char *alpha2,
5598 GSupplicantCountryCallback callback,
5599 const void *user_data)
5601 struct supplicant_regdom *regdom;
5604 SUPPLICANT_DBG("Country setting %s", alpha2);
5606 if (!system_available)
5609 regdom = dbus_malloc0(sizeof(*regdom));
5613 regdom->callback = callback;
5614 regdom->alpha2 = alpha2;
5615 regdom->user_data = user_data;
5617 ret = supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
5618 "Country", DBUS_TYPE_STRING_AS_STRING,
5619 country_params, country_result,
5623 SUPPLICANT_DBG("Unable to set Country configuration");
5628 int g_supplicant_interface_set_country(GSupplicantInterface *interface,
5629 GSupplicantCountryCallback callback,
5633 struct supplicant_regdom *regdom;
5636 regdom = dbus_malloc0(sizeof(*regdom));
5640 regdom->callback = callback;
5641 regdom->alpha2 = alpha2;
5642 regdom->user_data = user_data;
5644 ret = supplicant_dbus_property_set(interface->path,
5645 SUPPLICANT_INTERFACE ".Interface",
5646 "Country", DBUS_TYPE_STRING_AS_STRING,
5647 country_params, country_result,
5651 SUPPLICANT_DBG("Unable to set Country configuration");
5657 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
5662 return interface->p2p_support;
5665 struct supplicant_p2p_dev_config {
5670 static void p2p_device_config_result(const char *error,
5671 DBusMessageIter *iter, void *user_data)
5673 struct supplicant_p2p_dev_config *config = user_data;
5676 SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
5679 g_free(config->device_name);
5680 g_free(config->dev_type);
5684 static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
5686 int length, pos, end;
5691 for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
5698 dev_type[length] = strtol(b, &e, 16);
5699 if (e && *e != '\0')
5708 static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
5710 struct supplicant_p2p_dev_config *config = user_data;
5711 DBusMessageIter dict;
5713 supplicant_dbus_dict_open(iter, &dict);
5715 supplicant_dbus_dict_append_basic(&dict, "DeviceName",
5716 DBUS_TYPE_STRING, &config->device_name);
5718 if (config->dev_type) {
5719 unsigned char dev_type[8] = {}, *type;
5722 len = dev_type_str2bin(config->dev_type, dev_type);
5725 supplicant_dbus_dict_append_fixed_array(&dict,
5726 "PrimaryDeviceType",
5727 DBUS_TYPE_BYTE, &type, len);
5731 supplicant_dbus_dict_close(iter, &dict);
5734 int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
5735 const char *device_name,
5736 const char *primary_dev_type)
5738 struct supplicant_p2p_dev_config *config;
5741 SUPPLICANT_DBG("P2P Device settings %s/%s",
5742 device_name, primary_dev_type);
5744 config = dbus_malloc0(sizeof(*config));
5748 config->device_name = g_strdup(device_name);
5749 config->dev_type = g_strdup(primary_dev_type);
5751 ret = supplicant_dbus_property_set(interface->path,
5752 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
5754 DBUS_TYPE_ARRAY_AS_STRING
5755 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
5756 DBUS_TYPE_STRING_AS_STRING
5757 DBUS_TYPE_VARIANT_AS_STRING
5758 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
5759 p2p_device_config_params,
5760 p2p_device_config_result, config, NULL);
5762 g_free(config->device_name);
5763 g_free(config->dev_type);
5765 SUPPLICANT_DBG("Unable to set P2P Device configuration");
5771 static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
5774 const GSupplicantPeer *peer = value;
5775 const char *identifier = user_data;
5777 if (!g_strcmp0(identifier, peer->identifier))
5783 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
5784 const char *identifier)
5786 GSupplicantPeer *peer;
5788 peer = g_hash_table_find(interface->peer_table,
5789 peer_lookup_by_identifier,
5790 (void *) identifier);
5794 static void interface_create_data_free(struct interface_create_data *data)
5796 g_free(data->ifname);
5797 g_free(data->driver);
5798 g_free(data->bridge);
5799 #if defined TIZEN_EXT_WIFI_MESH
5800 g_free(data->parent_ifname);
5805 static bool interface_exists(GSupplicantInterface *interface,
5808 GSupplicantInterface *tmp;
5810 tmp = g_hash_table_lookup(interface_table, path);
5811 if (tmp && tmp == interface)
5817 static void interface_create_property(const char *key, DBusMessageIter *iter,
5820 struct interface_create_data *data = user_data;
5821 GSupplicantInterface *interface = data->interface;
5824 if (data->callback) {
5825 data->callback(0, data->interface, data->user_data);
5826 #if !defined TIZEN_EXT
5827 callback_p2p_support(interface);
5829 #if defined TIZEN_EXT_WIFI_MESH
5830 callback_mesh_support(interface);
5834 interface_create_data_free(data);
5837 interface_property(key, iter, interface);
5840 static void interface_create_result(const char *error,
5841 DBusMessageIter *iter, void *user_data)
5843 struct interface_create_data *data = user_data;
5844 const char *path = NULL;
5850 g_warning("error %s", error);
5855 dbus_message_iter_get_basic(iter, &path);
5861 if (!system_available) {
5866 data->interface = g_hash_table_lookup(interface_table, path);
5867 if (!data->interface) {
5868 data->interface = interface_alloc(path);
5869 if (!data->interface) {
5875 err = supplicant_dbus_property_get_all(path,
5876 SUPPLICANT_INTERFACE ".Interface",
5877 interface_create_property, data,
5884 data->callback(err, NULL, data->user_data);
5886 interface_create_data_free(data);
5889 static void interface_create_params(DBusMessageIter *iter, void *user_data)
5891 struct interface_create_data *data = user_data;
5892 DBusMessageIter dict;
5893 char *config_file = NULL;
5897 supplicant_dbus_dict_open(iter, &dict);
5899 supplicant_dbus_dict_append_basic(&dict, "Ifname",
5900 DBUS_TYPE_STRING, &data->ifname);
5903 supplicant_dbus_dict_append_basic(&dict, "Driver",
5904 DBUS_TYPE_STRING, &data->driver);
5907 supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
5908 DBUS_TYPE_STRING, &data->bridge);
5910 config_file = g_hash_table_lookup(config_file_table, data->ifname);
5912 SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
5914 supplicant_dbus_dict_append_basic(&dict, "ConfigFile",
5915 DBUS_TYPE_STRING, &config_file);
5919 if (data->driver && g_strstr_len(data->driver, strlen(data->driver), "nl80211")) {
5920 supplicant_dbus_dict_append_basic(&dict, "MacAddr",
5921 DBUS_TYPE_UINT32, &data->mac_addr);
5923 supplicant_dbus_dict_append_basic(&dict, "PreassocMacAddr",
5924 DBUS_TYPE_UINT32, &data->preassoc_mac_addr);
5926 supplicant_dbus_dict_append_basic(&dict, "RandAddrLifetime",
5927 DBUS_TYPE_UINT32, &data->random_mac_lifetime);
5929 #endif /* TIZEN_EXT */
5931 #if defined TIZEN_EXT_WIFI_MESH
5932 if (data->is_mesh_interface) {
5933 if (data->parent_ifname)
5934 supplicant_dbus_dict_append_basic(&dict, "ParentIfname",
5935 DBUS_TYPE_STRING, &data->parent_ifname);
5937 supplicant_dbus_dict_append_basic(&dict, "IsMeshInterface",
5938 DBUS_TYPE_BOOLEAN, &data->is_mesh_interface);
5942 supplicant_dbus_dict_close(iter, &dict);
5945 #if defined TIZEN_EXT
5946 static void interface_get_state(const char *key, DBusMessageIter *iter,
5949 struct interface_create_data *data = user_data;
5950 GSupplicantInterface *interface = NULL;
5951 const char *str = NULL;
5953 SUPPLICANT_DBG("key[%s]", key);
5956 SUPPLICANT_DBG("data is NULL");
5960 interface = data->interface;
5962 SUPPLICANT_DBG("interface is NULL");
5967 dbus_message_iter_get_basic(iter, &str);
5970 if (string2state(str) != interface->state)
5971 interface->state = string2state(str);
5974 if (interface->state == G_SUPPLICANT_STATE_DISABLED)
5975 interface->ready = FALSE;
5977 interface->ready = TRUE;
5979 SUPPLICANT_DBG("state %s (%d)", str, interface->state);
5981 if (data->callback) {
5982 data->callback(0, interface, data->user_data);
5983 #if defined TIZEN_EXT_WIFI_MESH
5984 callback_mesh_support(interface);
5988 interface_create_data_free(data);
5992 static void interface_get_result(const char *error,
5993 DBusMessageIter *iter, void *user_data)
5995 struct interface_create_data *data = user_data;
5996 GSupplicantInterface *interface;
5997 const char *path = NULL;
6000 #if defined TIZEN_EXT
6001 if (!simplified_log)
6006 SUPPLICANT_DBG("Interface not created yet");
6010 dbus_message_iter_get_basic(iter, &path);
6016 interface = g_hash_table_lookup(interface_table, path);
6022 #if defined TIZEN_EXT
6023 data->interface = interface;
6024 err = supplicant_dbus_property_get(path,
6025 SUPPLICANT_INTERFACE ".Interface",
6026 "State", interface_get_state, data, NULL);
6032 if (data->callback) {
6033 data->callback(0, interface, data->user_data);
6034 #if !defined TIZEN_EXT
6035 callback_p2p_support(interface);
6037 #if defined TIZEN_EXT_WIFI_MESH
6038 callback_mesh_support(interface);
6042 interface_create_data_free(data);
6047 if (!system_available) {
6052 SUPPLICANT_DBG("Creating interface");
6054 err = supplicant_dbus_method_call(SUPPLICANT_PATH,
6055 SUPPLICANT_INTERFACE,
6057 interface_create_params,
6058 interface_create_result, data,
6065 data->callback(err, NULL, data->user_data);
6067 interface_create_data_free(data);
6070 static void interface_get_params(DBusMessageIter *iter, void *user_data)
6072 struct interface_create_data *data = user_data;
6073 #if defined TIZEN_EXT
6074 if (!simplified_log)
6078 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
6081 #if defined TIZEN_EXT_WIFI_MESH
6082 int g_supplicant_mesh_interface_create(const char *ifname, const char *driver,
6083 const char *bridge, const char *parent_ifname,
6084 GSupplicantInterfaceCallback callback, void *user_data)
6086 struct interface_create_data *data;
6089 SUPPLICANT_DBG("ifname %s", ifname);
6091 if (!ifname || !parent_ifname)
6094 if (!system_available)
6097 data = dbus_malloc0(sizeof(*data));
6101 data->ifname = g_strdup(ifname);
6102 data->driver = g_strdup(driver);
6103 data->bridge = g_strdup(bridge);
6104 data->is_mesh_interface = true;
6105 data->parent_ifname = g_strdup(parent_ifname);
6106 data->callback = callback;
6107 data->user_data = user_data;
6109 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6110 SUPPLICANT_INTERFACE,
6112 interface_create_params,
6113 interface_create_result, data,
6118 struct interface_mesh_peer_data {
6121 GSupplicantInterface *interface;
6122 GSupplicantInterfaceCallback callback;
6126 static void interface_mesh_change_peer_params(DBusMessageIter *iter,
6129 struct interface_mesh_peer_data *data = user_data;
6133 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->peer_address);
6136 static void interface_mesh_change_peer_result(const char *error,
6137 DBusMessageIter *iter, void *user_data)
6139 struct interface_mesh_peer_data *data = user_data;
6142 SUPPLICANT_DBG("%s", data->method);
6146 SUPPLICANT_DBG("error %s", error);
6150 data->callback(err, data->interface, data->user_data);
6152 g_free(data->peer_address);
6153 g_free(data->method);
6157 int g_supplicant_interface_mesh_peer_change_status(
6158 GSupplicantInterface *interface,
6159 GSupplicantInterfaceCallback callback, const char *peer_address,
6160 const char *method, void *user_data)
6162 struct interface_mesh_peer_data *data;
6168 data = dbus_malloc0(sizeof(*data));
6172 data->peer_address = g_strdup(peer_address);
6173 data->method = g_strdup(method);
6174 data->interface = interface;
6175 data->callback = callback;
6176 data->user_data = user_data;
6178 ret = supplicant_dbus_method_call(interface->path,
6179 SUPPLICANT_INTERFACE ".Interface.Mesh",
6180 method, interface_mesh_change_peer_params,
6181 interface_mesh_change_peer_result, data, NULL);
6183 g_free(data->peer_address);
6184 g_free(data->method);
6192 int g_supplicant_interface_create(const char *ifname, const char *driver,
6195 unsigned int mac_policy,
6196 unsigned int preassoc_mac_policy,
6197 unsigned int random_mac_lifetime,
6198 #endif /* TIZEN_EXT */
6199 GSupplicantInterfaceCallback callback,
6202 struct interface_create_data *data;
6205 SUPPLICANT_DBG("ifname %s", ifname);
6210 if (!system_available)
6213 data = dbus_malloc0(sizeof(*data));
6217 data->ifname = g_strdup(ifname);
6218 data->driver = g_strdup(driver);
6219 data->bridge = g_strdup(bridge);
6220 data->callback = callback;
6222 data->mac_addr = mac_policy;
6223 data->preassoc_mac_addr = preassoc_mac_policy;
6224 data->random_mac_lifetime = random_mac_lifetime;
6225 #endif /* TIZEN_EXT */
6226 data->user_data = user_data;
6228 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6229 SUPPLICANT_INTERFACE,
6231 interface_get_params,
6232 interface_get_result, data,
6235 interface_create_data_free(data);
6240 static void interface_remove_result(const char *error,
6241 DBusMessageIter *iter, void *user_data)
6243 struct interface_data *data = user_data;
6248 SUPPLICANT_DBG("error: %s", error);
6252 if (!system_available) {
6258 * The gsupplicant interface is already freed by the InterfaceRemoved
6259 * signal callback. Simply invoke the interface_data callback.
6267 data->callback(err, NULL, data->user_data);
6273 static void interface_remove_params(DBusMessageIter *iter, void *user_data)
6275 struct interface_data *data = user_data;
6277 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6278 &data->interface->path);
6281 int g_supplicant_interface_remove(GSupplicantInterface *interface,
6282 GSupplicantInterfaceCallback callback,
6285 struct interface_data *data;
6291 if (!system_available)
6294 g_supplicant_interface_cancel(interface);
6296 data = dbus_malloc0(sizeof(*data));
6300 data->interface = interface;
6301 data->path = g_strdup(interface->path);
6302 data->callback = callback;
6303 data->user_data = user_data;
6305 ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
6306 SUPPLICANT_INTERFACE,
6308 interface_remove_params,
6309 interface_remove_result, data,
6318 static void interface_scan_result(const char *error,
6319 DBusMessageIter *iter, void *user_data)
6321 struct interface_scan_data *data = user_data;
6325 SUPPLICANT_DBG("error %s", error);
6329 /* A non ready interface cannot send/receive anything */
6330 if (interface_exists(data->interface, data->path)) {
6331 if (!data->interface->ready)
6339 data->callback(err, data->interface, data->user_data);
6341 data->interface->scan_callback = data->callback;
6342 data->interface->scan_data = data->user_data;
6345 if (data->scan_params)
6346 g_supplicant_free_scan_params(data->scan_params);
6351 static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
6353 DBusMessageIter data;
6354 unsigned int width = 0; /* Not used by wpa_supplicant atm */
6356 dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
6358 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
6359 dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
6361 dbus_message_iter_close_container(iter, &data);
6364 static void add_scan_frequencies(DBusMessageIter *iter,
6367 GSupplicantScanParams *scan_data = user_data;
6371 for (i = 0; i < scan_data->num_freqs; i++) {
6372 freq = scan_data->freqs[i];
6376 add_scan_frequency(iter, freq);
6380 static void append_ssid(DBusMessageIter *iter,
6381 const void *ssid, unsigned int len)
6383 DBusMessageIter array;
6385 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
6386 DBUS_TYPE_BYTE_AS_STRING, &array);
6388 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
6390 dbus_message_iter_close_container(iter, &array);
6393 static void append_ssids(DBusMessageIter *iter, void *user_data)
6395 GSupplicantScanParams *scan_data = user_data;
6398 for (list = scan_data->ssids; list; list = list->next) {
6399 struct scan_ssid *scan_ssid = list->data;
6401 append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
6405 static void supplicant_add_scan_frequency(DBusMessageIter *dict,
6406 supplicant_dbus_array_function function,
6409 GSupplicantScanParams *scan_params = user_data;
6410 DBusMessageIter entry, value, array;
6411 const char *key = "Channels";
6413 if (scan_params->freqs && scan_params->freqs[0] != 0) {
6414 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
6417 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
6419 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
6420 DBUS_TYPE_ARRAY_AS_STRING
6421 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6422 DBUS_TYPE_UINT32_AS_STRING
6423 DBUS_TYPE_UINT32_AS_STRING
6424 DBUS_STRUCT_END_CHAR_AS_STRING,
6427 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
6428 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
6429 DBUS_TYPE_UINT32_AS_STRING
6430 DBUS_TYPE_UINT32_AS_STRING
6431 DBUS_STRUCT_END_CHAR_AS_STRING,
6435 function(&array, user_data);
6437 dbus_message_iter_close_container(&value, &array);
6438 dbus_message_iter_close_container(&entry, &value);
6439 dbus_message_iter_close_container(dict, &entry);
6443 static void interface_scan_params(DBusMessageIter *iter, void *user_data)
6445 DBusMessageIter dict;
6446 const char *type = "passive";
6447 struct interface_scan_data *data = user_data;
6449 supplicant_dbus_dict_open(iter, &dict);
6451 if (data && data->scan_params) {
6454 supplicant_dbus_dict_append_basic(&dict, "Type",
6455 DBUS_TYPE_STRING, &type);
6457 #if defined TIZEN_EXT
6458 SUPPLICANT_DBG("[specific_scan] num_ssids %d",
6459 data->scan_params->num_ssids);
6462 if (data->scan_params->ssids) {
6463 supplicant_dbus_dict_append_array(&dict, "SSIDs",
6468 supplicant_add_scan_frequency(&dict, add_scan_frequencies,
6471 supplicant_dbus_dict_append_basic(&dict, "Type",
6472 DBUS_TYPE_STRING, &type);
6474 supplicant_dbus_dict_close(iter, &dict);
6477 static int interface_ready_to_scan(GSupplicantInterface *interface)
6482 if (!system_available)
6485 if (interface->scanning)
6488 switch (interface->state) {
6489 case G_SUPPLICANT_STATE_AUTHENTICATING:
6490 case G_SUPPLICANT_STATE_ASSOCIATING:
6491 case G_SUPPLICANT_STATE_ASSOCIATED:
6492 case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
6493 case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
6495 #if defined TIZEN_EXT
6496 case G_SUPPLICANT_STATE_DISABLED:
6498 case G_SUPPLICANT_STATE_UNKNOWN:
6500 case G_SUPPLICANT_STATE_UNKNOWN:
6501 case G_SUPPLICANT_STATE_DISABLED:
6503 case G_SUPPLICANT_STATE_DISCONNECTED:
6504 case G_SUPPLICANT_STATE_INACTIVE:
6505 case G_SUPPLICANT_STATE_SCANNING:
6506 case G_SUPPLICANT_STATE_COMPLETED:
6513 #if defined TIZEN_EXT_WIFI_MESH
6514 static void interface_abort_scan_result(const char *error,
6515 DBusMessageIter *iter, void *user_data)
6517 struct interface_scan_data *data = user_data;
6521 SUPPLICANT_DBG("error %s", error);
6528 data->callback(err, data->interface, data->user_data);
6533 int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
6534 GSupplicantInterfaceCallback callback, void *user_data)
6536 struct interface_scan_data *data;
6539 if (!interface->scanning)
6542 data = dbus_malloc0(sizeof(*data));
6546 data->interface = interface;
6547 data->path = g_strdup(interface->path);
6548 data->callback = callback;
6549 data->user_data = user_data;
6551 ret = supplicant_dbus_method_call(interface->path,
6552 SUPPLICANT_INTERFACE ".Interface", "AbortScan", NULL,
6553 interface_abort_scan_result, data, interface);
6564 int g_supplicant_interface_scan(GSupplicantInterface *interface,
6565 GSupplicantScanParams *scan_data,
6566 GSupplicantInterfaceCallback callback,
6569 struct interface_scan_data *data;
6572 ret = interface_ready_to_scan(interface);
6576 data = dbus_malloc0(sizeof(*data));
6580 data->interface = interface;
6581 data->path = g_strdup(interface->path);
6582 #if defined TIZEN_EXT
6583 data->interface->scan_callback = data->callback = callback;
6584 data->interface->scan_data = data->user_data = user_data;
6586 data->callback = callback;
6587 data->user_data = user_data;
6589 data->scan_params = scan_data;
6591 interface->scan_callback = callback;
6592 interface->scan_data = user_data;
6594 ret = supplicant_dbus_method_call(interface->path,
6595 SUPPLICANT_INTERFACE ".Interface", "Scan",
6596 interface_scan_params, interface_scan_result, data,
6607 #if defined TIZEN_EXT
6608 static void interface_signalpoll_result(const char *error,
6609 DBusMessageIter *iter, void *user_data)
6611 struct interface_signalpoll_data *data = user_data;
6613 dbus_int32_t maxspeed = 0;
6614 dbus_int32_t strength = 0;
6615 dbus_int32_t snr = 0;
6616 dbus_uint32_t est_throughput = 0;
6617 DBusMessageIter sub_iter, dict;
6621 SUPPLICANT_DBG("error: %s", error);
6625 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
6627 SUPPLICANT_DBG("invalid reply");
6631 dbus_message_iter_recurse(iter, &sub_iter);
6632 dbus_message_iter_recurse(&sub_iter, &dict);
6634 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
6635 DBusMessageIter entry, value;
6638 dbus_message_iter_recurse(&dict, &entry);
6639 dbus_message_iter_get_basic(&entry, &key);
6640 dbus_message_iter_next(&entry);
6641 dbus_message_iter_recurse(&entry, &value);
6643 switch (dbus_message_iter_get_arg_type(&value)) {
6644 case DBUS_TYPE_INT32:
6645 if (g_strcmp0(key, "linkspeed") == 0) {
6646 dbus_message_iter_get_basic(&value, &maxspeed);
6647 SUPPLICANT_DBG("linkspeed = %d", maxspeed);
6648 } else if (g_strcmp0(key, "rssi") == 0) {
6649 dbus_message_iter_get_basic(&value, &strength);
6650 SUPPLICANT_DBG("Strength = %d", strength);
6651 } else if (g_strcmp0(key, "SNR") == 0) {
6652 dbus_message_iter_get_basic(&value, &snr);
6653 SUPPLICANT_DBG("SNR = %d", snr);
6656 case DBUS_TYPE_UINT32:
6657 if (g_strcmp0(key, "est_throughput") == 0) {
6658 dbus_message_iter_get_basic(&value, &est_throughput);
6659 SUPPLICANT_DBG("est_throughput = %u", est_throughput);
6663 dbus_message_iter_next(&dict);
6668 data->callback(err, maxspeed, strength, snr, data->user_data, est_throughput);
6674 int g_supplicant_interface_signalpoll(GSupplicantInterface *interface,
6675 GSupplicantMaxSpeedCallback callback,
6678 struct interface_signalpoll_data *data;
6684 if (!system_available)
6687 data = dbus_malloc0(sizeof(*data));
6691 data->interface = interface;
6692 data->path = g_strdup(interface->path);
6693 data->callback = callback;
6694 data->user_data = user_data;
6696 ret = supplicant_dbus_method_call(interface->path,
6697 SUPPLICANT_INTERFACE ".Interface", "SignalPoll",
6698 NULL, interface_signalpoll_result, data,
6710 static int parse_supplicant_error(DBusMessageIter *iter)
6712 int err = -ECONNABORTED;
6718 /* If the given passphrase is malformed wpa_s returns
6719 * "invalid message format" but this error should be interpreted as
6722 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
6723 dbus_message_iter_get_basic(iter, &key);
6724 if (strncmp(key, "psk", 3) == 0 ||
6725 strncmp(key, "wep_key", 7) == 0 ||
6726 strcmp(key, "invalid message format") == 0) {
6730 dbus_message_iter_next(iter);
6736 static void interface_select_network_result(const char *error,
6737 DBusMessageIter *iter, void *user_data)
6739 struct interface_connect_data *data = user_data;
6746 #if defined TIZEN_EXT
6747 SUPPLICANT_DBG("SelectNetwork errorFreq %s", error);
6749 SUPPLICANT_DBG("SelectNetwork error %s", error);
6751 err = parse_supplicant_error(iter);
6757 data->callback(err, data->interface, data->user_data);
6759 #if defined TIZEN_EXT
6760 g_free(data->ssid->ssid);
6761 if (data->ssid->is_passphrase_alloc)
6762 g_free((char *)data->ssid->passphrase);
6763 if (data->ssid->is_connector_alloc)
6764 g_free((char *)data->ssid->connector);
6765 if (data->ssid->is_c_sign_key_alloc)
6766 g_free((char *)data->ssid->c_sign_key);
6767 if (data->ssid->is_net_access_key_alloc)
6768 g_free((char *)data->ssid->net_access_key);
6774 static void interface_select_network_params(DBusMessageIter *iter,
6777 struct interface_connect_data *data = user_data;
6778 GSupplicantInterface *interface = data->interface;
6779 #if defined TIZEN_EXT
6780 GSupplicantSSID *ssid = data->ssid;
6783 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
6784 &interface->network_path);
6785 #if defined TIZEN_EXT
6786 if (!ssid->bssid_for_connect_len)
6787 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
6791 static void interface_add_network_result(const char *error,
6792 DBusMessageIter *iter, void *user_data)
6794 struct interface_connect_data *data = user_data;
6795 GSupplicantInterface *interface = data->interface;
6802 dbus_message_iter_get_basic(iter, &path);
6806 SUPPLICANT_DBG("PATH: %s", path);
6808 #if defined TIZEN_EXT
6809 if (interface->network_path)
6810 g_free(interface->network_path);
6812 interface->network_path = g_strdup(path);
6814 store_network_information(interface, data->ssid);
6816 #if defined TIZEN_EXT
6817 SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
6818 GSupplicantSSID *ssid = data->ssid;
6820 if (!ssid->bssid_for_connect_len)
6821 supplicant_dbus_method_call(data->interface->path,
6822 SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
6823 interface_select_network_params,
6824 interface_select_network_result, data,
6827 supplicant_dbus_method_call(data->interface->path,
6828 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6829 interface_select_network_params,
6830 interface_select_network_result, data,
6833 supplicant_dbus_method_call(data->interface->path,
6834 SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
6835 interface_select_network_params,
6836 interface_select_network_result, data,
6843 SUPPLICANT_DBG("AddNetwork error %s", error);
6845 if (interface_exists(data->interface, data->interface->path)) {
6846 err = parse_supplicant_error(iter);
6848 data->callback(err, data->interface, data->user_data);
6850 g_free(interface->network_path);
6851 interface->network_path = NULL;
6855 #if defined TIZEN_EXT
6856 g_free(data->ssid->ssid);
6857 if (data->ssid->is_passphrase_alloc)
6858 g_free((char *)data->ssid->passphrase);
6859 if (data->ssid->is_connector_alloc)
6860 g_free((char *)data->ssid->connector);
6861 if (data->ssid->is_c_sign_key_alloc)
6862 g_free((char *)data->ssid->c_sign_key);
6863 if (data->ssid->is_net_access_key_alloc)
6864 g_free((char *)data->ssid->net_access_key);
6870 static void add_network_security_none(DBusMessageIter *dict)
6872 const char *auth_alg = "OPEN";
6874 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6875 DBUS_TYPE_STRING, &auth_alg);
6878 static void add_network_security_wep(DBusMessageIter *dict,
6879 GSupplicantSSID *ssid)
6881 const char *auth_alg = "OPEN SHARED";
6882 dbus_uint32_t key_index = 0;
6884 supplicant_dbus_dict_append_basic(dict, "auth_alg",
6885 DBUS_TYPE_STRING, &auth_alg);
6887 if (ssid->passphrase) {
6888 int size = strlen(ssid->passphrase);
6889 if (size == 10 || size == 26) {
6890 unsigned char *key = g_try_malloc(13);
6894 memset(tmp, 0, sizeof(tmp));
6898 for (i = 0; i < size / 2; i++) {
6899 memcpy(tmp, ssid->passphrase + (i * 2), 2);
6900 key[i] = (unsigned char) strtol(tmp, NULL, 16);
6903 supplicant_dbus_dict_append_fixed_array(dict,
6908 } else if (size == 5 || size == 13) {
6909 unsigned char *key = g_try_malloc(13);
6915 for (i = 0; i < size; i++)
6916 key[i] = (unsigned char) ssid->passphrase[i];
6918 supplicant_dbus_dict_append_fixed_array(dict,
6924 supplicant_dbus_dict_append_basic(dict,
6929 supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
6930 DBUS_TYPE_UINT32, &key_index);
6934 static dbus_bool_t is_psk_raw_key(const char *psk)
6938 /* A raw key is always 64 bytes length... */
6939 if (strlen(psk) != 64)
6942 /* ... and its content is in hex representation */
6943 for (i = 0; i < 64; i++)
6944 if (!isxdigit((unsigned char) psk[i]))
6950 static unsigned char hexchar2bin(char c)
6952 if ((c >= '0') && (c <= '9'))
6954 else if ((c >= 'A') && (c <= 'F'))
6955 return c - 'A' + 10;
6956 else if ((c >= 'a') && (c <= 'f'))
6957 return c - 'a' + 10;
6962 static void hexstring2bin(const char *string, unsigned char *data,
6967 for (i = 0; i < data_len; i++)
6968 data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
6969 hexchar2bin(string[i * 2 + 1]) << 0);
6972 static void add_network_security_psk(DBusMessageIter *dict,
6973 GSupplicantSSID *ssid)
6975 if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
6976 const char *key = "psk";
6978 if (is_psk_raw_key(ssid->passphrase)) {
6979 unsigned char data[32];
6980 unsigned char *datap = data;
6982 /* The above pointer alias is required by D-Bus because
6983 * with D-Bus and GCC, non-heap-allocated arrays cannot
6984 * be passed directly by their base pointer. */
6986 hexstring2bin(ssid->passphrase, datap, sizeof(data));
6988 supplicant_dbus_dict_append_fixed_array(dict,
6989 key, DBUS_TYPE_BYTE,
6990 &datap, sizeof(data));
6992 supplicant_dbus_dict_append_basic(dict,
6993 key, DBUS_TYPE_STRING,
6998 static void add_network_security_tls(DBusMessageIter *dict,
6999 GSupplicantSSID *ssid)
7002 * For TLS, we at least need:
7003 * The client certificate
7004 * The client private key file
7005 * The client private key file password
7007 * The Authority certificate is optional.
7009 if (!ssid->client_cert_path)
7012 if (!ssid->private_key_path)
7015 if (!ssid->private_key_passphrase)
7018 if (ssid->ca_cert_path)
7019 supplicant_dbus_dict_append_basic(dict, "ca_cert",
7020 DBUS_TYPE_STRING, &ssid->ca_cert_path);
7022 supplicant_dbus_dict_append_basic(dict, "private_key",
7024 &ssid->private_key_path);
7025 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
7027 &ssid->private_key_passphrase);
7028 supplicant_dbus_dict_append_basic(dict, "client_cert",
7030 &ssid->client_cert_path);
7033 static void add_network_security_peap(DBusMessageIter *dict,
7034 GSupplicantSSID *ssid)
7039 * For PEAP/TTLS, we at least need
7040 * The authority certificate
7041 * The 2nd phase authentication method
7042 * The 2nd phase passphrase
7044 * The Client certificate is optional although strongly recommended
7045 * When setting it, we need in addition
7046 * The Client private key file
7047 * The Client private key file password
7049 if (!ssid->passphrase)
7052 if (!ssid->phase2_auth)
7055 if (ssid->client_cert_path) {
7056 if (!ssid->private_key_path)
7059 #if !defined TIZEN_EXT
7060 if (!ssid->private_key_passphrase)
7064 supplicant_dbus_dict_append_basic(dict, "client_cert",
7066 &ssid->client_cert_path);
7068 supplicant_dbus_dict_append_basic(dict, "private_key",
7070 &ssid->private_key_path);
7072 #if !defined TIZEN_EXT
7073 supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
7075 &ssid->private_key_passphrase);
7080 if(g_strcmp0(ssid->phase2_auth, "GTC") == 0 && g_strcmp0(ssid->eap, "ttls") == 0)
7081 phase2_auth = g_strdup_printf("autheap=%s", ssid->phase2_auth);
7082 else if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
7083 phase2_auth = g_strdup_printf("autheap=%s",
7084 ssid->phase2_auth + strlen("EAP-"));
7086 phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
7088 supplicant_dbus_dict_append_basic(dict, "password",
7092 if (ssid->ca_cert_path)
7093 supplicant_dbus_dict_append_basic(dict, "ca_cert",
7095 &ssid->ca_cert_path);
7097 supplicant_dbus_dict_append_basic(dict, "phase2",
7101 g_free(phase2_auth);
7104 #if defined TIZEN_EXT
7105 static void add_network_security_aka_sim(DBusMessageIter *dict,
7106 GSupplicantSSID *ssid)
7108 if (!ssid->passphrase)
7111 supplicant_dbus_dict_append_basic(dict, "password",
7116 static void add_network_security_fast(DBusMessageIter *dict,
7117 GSupplicantSSID *ssid)
7120 * For FAST, we at least need:
7122 * phase1 (provisiong information)
7126 /* Allow provisioing both authenticated and unauthenticated */
7127 const char *phase1 = "fast_provisioning=2";
7128 supplicant_dbus_dict_append_basic(dict, "phase1",
7132 SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
7134 supplicant_dbus_dict_append_basic(dict, "pac_file",
7138 supplicant_dbus_dict_append_basic(dict, "password",
7144 static void add_network_security_eap(DBusMessageIter *dict,
7145 GSupplicantSSID *ssid)
7149 #if defined TIZEN_EXT
7152 if (!ssid->eap || !ssid->identity)
7156 if (g_strcmp0(ssid->eap, "tls") == 0) {
7157 add_network_security_tls(dict, ssid);
7158 } else if (g_strcmp0(ssid->eap, "peap") == 0 ||
7159 g_strcmp0(ssid->eap, "ttls") == 0) {
7160 #if defined TIZEN_EXT
7161 if (!ssid->identity)
7164 add_network_security_peap(dict, ssid);
7166 #if defined TIZEN_EXT
7167 } else if (g_strcmp0(ssid->eap, "sim") == 0 ||
7168 g_strcmp0(ssid->eap, "aka") == 0 ||
7169 g_strcmp0(ssid->eap, "aka'") == 0) {
7170 add_network_security_aka_sim(dict, ssid);
7171 } else if (g_strcmp0(ssid->eap, "pwd") == 0) {
7172 if(!ssid->passphrase)
7174 supplicant_dbus_dict_append_basic(dict, "password",
7177 } else if (g_strcmp0(ssid->eap, "fast") == 0){
7178 if (!ssid->identity || !ssid->passphrase)
7181 add_network_security_fast(dict, ssid);
7186 eap_value = g_ascii_strup(ssid->eap, -1);
7188 supplicant_dbus_dict_append_basic(dict, "eap",
7191 #if defined TIZEN_EXT
7192 if (ssid->identity != NULL)
7193 supplicant_dbus_dict_append_basic(dict, "identity",
7197 supplicant_dbus_dict_append_basic(dict, "identity",
7201 if(ssid->anonymous_identity)
7202 supplicant_dbus_dict_append_basic(dict, "anonymous_identity",
7204 &ssid->anonymous_identity);
7206 if(ssid->subject_match)
7207 supplicant_dbus_dict_append_basic(dict, "subject_match",
7209 &ssid->subject_match);
7211 if(ssid->altsubject_match)
7212 supplicant_dbus_dict_append_basic(dict, "altsubject_match",
7214 &ssid->altsubject_match);
7216 if(ssid->domain_suffix_match)
7217 supplicant_dbus_dict_append_basic(dict, "domain_suffix_match",
7219 &ssid->domain_suffix_match);
7221 if(ssid->domain_match)
7222 supplicant_dbus_dict_append_basic(dict, "domain_match",
7224 &ssid->domain_match);
7229 static void add_network_security_ciphers(DBusMessageIter *dict,
7230 GSupplicantSSID *ssid)
7232 unsigned int p_cipher, g_cipher, i;
7233 char *pairwise, *group;
7234 char *pair_ciphers[4];
7235 char *group_ciphers[5];
7237 p_cipher = ssid->pairwise_cipher;
7238 g_cipher = ssid->group_cipher;
7240 if (p_cipher == 0 && g_cipher == 0)
7245 if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
7246 pair_ciphers[i++] = "CCMP";
7248 if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
7249 pair_ciphers[i++] = "TKIP";
7251 if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
7252 pair_ciphers[i++] = "NONE";
7254 pair_ciphers[i] = NULL;
7258 if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
7259 group_ciphers[i++] = "CCMP";
7261 if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
7262 group_ciphers[i++] = "TKIP";
7264 if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
7265 group_ciphers[i++] = "WEP104";
7267 if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
7268 group_ciphers[i++] = "WEP40";
7270 group_ciphers[i] = NULL;
7272 pairwise = g_strjoinv(" ", pair_ciphers);
7273 group = g_strjoinv(" ", group_ciphers);
7275 SUPPLICANT_DBG("cipher %s %s", pairwise, group);
7277 supplicant_dbus_dict_append_basic(dict, "pairwise",
7280 supplicant_dbus_dict_append_basic(dict, "group",
7288 static void add_network_security_proto(DBusMessageIter *dict,
7289 GSupplicantSSID *ssid)
7291 unsigned int protocol, i;
7295 protocol = ssid->protocol;
7302 if (protocol & G_SUPPLICANT_PROTO_RSN)
7303 protos[i++] = "RSN";
7305 if (protocol & G_SUPPLICANT_PROTO_WPA)
7306 protos[i++] = "WPA";
7310 proto = g_strjoinv(" ", protos);
7312 SUPPLICANT_DBG("proto %s", proto);
7314 supplicant_dbus_dict_append_basic(dict, "proto",
7321 #if defined TIZEN_EXT
7322 static void add_network_security_connector(DBusMessageIter *dict, GSupplicantSSID *ssid)
7324 if (ssid->connector && strlen(ssid->connector) > 0) {
7325 const char *key = "dpp_connector";
7327 supplicant_dbus_dict_append_basic(dict,
7328 key, DBUS_TYPE_STRING,
7333 static size_t convert_hexstr_to_bin(const char *hex_str, unsigned char **bin)
7335 unsigned char *bin_res = NULL;
7336 unsigned int i, j, hex;
7339 if (!hex_str || strlen(hex_str) == 0)
7342 hex_str_len = strlen(hex_str);
7343 bin_res = g_try_malloc0(hex_str_len / 2);
7348 for (i = 0; i < hex_str_len; i+=2) {
7349 sscanf(hex_str + i, "%02x", &hex);
7354 return hex_str_len / 2;
7357 static void add_network_security_c_sign_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7359 if (ssid->c_sign_key && strlen(ssid->c_sign_key) > 0) {
7360 const char *key = "dpp_csign";
7361 unsigned char *bin_csign = NULL;
7362 size_t bin_csign_len = convert_hexstr_to_bin(ssid->c_sign_key, &bin_csign);
7363 if (bin_csign_len != 0)
7364 supplicant_dbus_dict_append_fixed_array(dict,
7365 key, DBUS_TYPE_BYTE,
7366 &bin_csign, bin_csign_len);
7371 static void add_network_security_net_access_key(DBusMessageIter *dict, GSupplicantSSID *ssid)
7373 if (ssid->net_access_key && strlen(ssid->net_access_key) > 0) {
7374 const char *key = "dpp_netaccesskey";
7375 unsigned char *bin_netaccesskey = NULL;
7376 size_t bin_netaccesskey_len = convert_hexstr_to_bin(ssid->net_access_key, &bin_netaccesskey);
7377 if (bin_netaccesskey_len != 0)
7378 supplicant_dbus_dict_append_fixed_array(dict,
7379 key, DBUS_TYPE_BYTE,
7380 &bin_netaccesskey, bin_netaccesskey_len);
7381 g_free(bin_netaccesskey);
7387 static void add_network_ieee80211w(DBusMessageIter *dict, GSupplicantSSID *ssid,
7388 GSupplicantMfpOptions ieee80211w)
7390 supplicant_dbus_dict_append_basic(dict, "ieee80211w", DBUS_TYPE_UINT32,
7394 static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
7396 GSupplicantMfpOptions ieee80211w;
7399 switch (ssid->security) {
7400 case G_SUPPLICANT_SECURITY_NONE:
7402 add_network_security_none(dict);
7403 add_network_security_ciphers(dict, ssid);
7405 case G_SUPPLICANT_SECURITY_UNKNOWN:
7406 case G_SUPPLICANT_SECURITY_WEP:
7408 add_network_security_wep(dict, ssid);
7409 add_network_security_ciphers(dict, ssid);
7411 case G_SUPPLICANT_SECURITY_PSK:
7412 #if defined TIZEN_EXT
7413 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_FT_PSK)
7414 key_mgmt = "FT-PSK WPA-PSK";
7416 key_mgmt = "WPA-PSK";
7418 key_mgmt = "WPA-PSK";
7420 add_network_security_psk(dict, ssid);
7421 add_network_security_ciphers(dict, ssid);
7422 add_network_security_proto(dict, ssid);
7424 case G_SUPPLICANT_SECURITY_IEEE8021X:
7425 key_mgmt = "WPA-EAP";
7426 add_network_security_eap(dict, ssid);
7427 add_network_security_ciphers(dict, ssid);
7428 add_network_security_proto(dict, ssid);
7430 #if defined TIZEN_EXT
7431 case G_SUPPLICANT_SECURITY_PSK_SHA256:
7432 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK)
7433 key_mgmt = "WPA-PSK-SHA256 WPA-PSK";
7435 key_mgmt = "WPA-PSK-SHA256";
7436 add_network_security_psk(dict, ssid);
7437 add_network_security_ciphers(dict, ssid);
7438 add_network_security_proto(dict, ssid);
7440 case G_SUPPLICANT_SECURITY_FT_PSK:
7441 key_mgmt = "FT-PSK";
7442 add_network_security_psk(dict, ssid);
7443 add_network_security_ciphers(dict, ssid);
7444 add_network_security_proto(dict, ssid);
7446 case G_SUPPLICANT_SECURITY_FT_IEEE8021X:
7447 key_mgmt = "FT-EAP";
7448 add_network_security_eap(dict, ssid);
7449 add_network_security_ciphers(dict, ssid);
7450 add_network_security_proto(dict, ssid);
7452 case G_SUPPLICANT_SECURITY_SAE:
7453 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_FT_SAE) {
7454 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_SAE)
7455 key_mgmt = "FT-SAE SAE";
7457 key_mgmt = "FT-SAE";
7459 if (ssid->keymgmt & G_SUPPLICANT_KEYMGMT_WPA_PSK) {
7460 key_mgmt = "SAE WPA-PSK";
7461 ieee80211w = G_SUPPLICANT_MFP_OPTIONAL;
7464 ieee80211w = G_SUPPLICANT_MFP_REQUIRED;
7466 add_network_ieee80211w(dict, ssid, ieee80211w);
7468 add_network_security_psk(dict, ssid);
7469 add_network_security_ciphers(dict, ssid);
7470 add_network_security_proto(dict, ssid);
7472 case G_SUPPLICANT_SECURITY_OWE:
7474 add_network_security_ciphers(dict, ssid);
7475 add_network_security_proto(dict, ssid);
7477 case G_SUPPLICANT_SECURITY_DPP:
7479 add_network_security_connector(dict, ssid);
7480 add_network_security_c_sign_key(dict, ssid);
7481 add_network_security_net_access_key(dict, ssid);
7486 supplicant_dbus_dict_append_basic(dict, "key_mgmt",
7487 DBUS_TYPE_STRING, &key_mgmt);
7490 static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
7494 switch (ssid->mode) {
7495 case G_SUPPLICANT_MODE_UNKNOWN:
7496 case G_SUPPLICANT_MODE_INFRA:
7499 case G_SUPPLICANT_MODE_IBSS:
7502 case G_SUPPLICANT_MODE_MASTER:
7505 #if defined TIZEN_EXT_WIFI_MESH
7506 case G_SUPPLICANT_MODE_MESH:
7512 supplicant_dbus_dict_append_basic(dict, "mode",
7513 DBUS_TYPE_UINT32, &mode);
7516 static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
7518 DBusMessageIter dict;
7519 struct interface_connect_data *data = user_data;
7520 GSupplicantSSID *ssid = data->ssid;
7521 #if defined TIZEN_EXT
7522 GSupplicantInterface *interface = data->interface;
7525 supplicant_dbus_dict_open(iter, &dict);
7527 if (ssid->scan_ssid)
7528 supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
7529 DBUS_TYPE_UINT32, &ssid->scan_ssid);
7532 supplicant_dbus_dict_append_basic(&dict, "frequency",
7533 DBUS_TYPE_UINT32, &ssid->freq);
7536 supplicant_dbus_dict_append_basic(&dict, "bgscan",
7537 DBUS_TYPE_STRING, &ssid->bgscan);
7539 add_network_mode(&dict, ssid);
7541 add_network_security(&dict, ssid);
7543 supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
7544 DBUS_TYPE_BYTE, &ssid->ssid,
7547 #if defined TIZEN_EXT
7548 bool owe_transition_mode = FALSE;
7549 if ((ssid->security == G_SUPPLICANT_SECURITY_OWE) && !(ssid->keymgmt & G_SUPPLICANT_KEYMGMT_OWE))
7550 owe_transition_mode = TRUE;
7552 if (ssid->bssid && !owe_transition_mode) {
7554 bssid = g_try_malloc0(18);
7555 if (bssid == NULL) {
7556 SUPPLICANT_DBG("memory allocation error");
7557 supplicant_dbus_dict_close(iter, &dict);
7561 if (ssid->bssid_for_connect_len) {
7562 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid_for_connect));
7563 memcpy(interface->add_network_bssid, ssid->bssid_for_connect, WIFI_BSSID_LEN_MAX);
7565 snprintf(bssid, 18, MACSTR, MAC2STR(ssid->bssid));
7566 memcpy(interface->add_network_bssid, ssid->bssid, WIFI_BSSID_LEN_MAX);
7569 SUPPLICANT_DBG("bssid [" MACSTR "]", MAC2STR(interface->add_network_bssid));
7571 supplicant_dbus_dict_append_basic(&dict, "bssid",
7572 DBUS_TYPE_STRING, &bssid);
7577 supplicant_dbus_dict_close(iter, &dict);
7580 static void interface_wps_start_result(const char *error,
7581 DBusMessageIter *iter, void *user_data)
7583 struct interface_connect_data *data = user_data;
7590 SUPPLICANT_DBG("error: %s", error);
7591 err = parse_supplicant_error(iter);
7595 data->callback(err, data->interface, data->user_data);
7602 static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
7604 struct interface_connect_data *data = user_data;
7605 GSupplicantSSID *ssid = data->ssid;
7606 const char *role = "enrollee", *type;
7607 DBusMessageIter dict;
7611 supplicant_dbus_dict_open(iter, &dict);
7613 supplicant_dbus_dict_append_basic(&dict, "Role",
7614 DBUS_TYPE_STRING, &role);
7617 if (ssid->pin_wps) {
7619 supplicant_dbus_dict_append_basic(&dict, "Pin",
7620 DBUS_TYPE_STRING, &ssid->pin_wps);
7623 supplicant_dbus_dict_append_basic(&dict, "Type",
7624 DBUS_TYPE_STRING, &type);
7626 #if defined TIZEN_EXT
7628 supplicant_dbus_dict_append_fixed_array(&dict, "Bssid",
7629 DBUS_TYPE_BYTE, &ssid->bssid, 6);
7632 supplicant_dbus_dict_close(iter, &dict);
7635 static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
7637 struct interface_connect_data *data = user_data;
7642 SUPPLICANT_DBG("error: %s", error);
7649 #if defined TIZEN_EXT
7650 GSupplicantSSID *ssid = data->ssid;
7651 if (ssid->pin_wps != NULL) {
7652 if (!g_utf8_validate(ssid->pin_wps, 8, NULL)) {
7653 SUPPLICANT_DBG("Invalid characters in WPS_PIN");
7660 supplicant_dbus_method_call(data->interface->path,
7661 SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
7662 interface_add_wps_params,
7663 interface_wps_start_result, data, NULL);
7666 static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
7668 dbus_bool_t credentials = TRUE;
7672 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
7676 #if defined TIZEN_EXT
7677 #define NETCONFIG_SERVICE "net.netconfig"
7678 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
7679 #define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
7681 struct dec_method_call_data {
7682 struct interface_connect_data *data;
7683 DBusPendingCall *pending_call;
7686 static struct dec_method_call_data decrypt_request_data;
7688 static void crypt_method_call_cancel(void)
7690 if (decrypt_request_data.pending_call) {
7691 dbus_pending_call_cancel(decrypt_request_data.pending_call);
7692 dbus_pending_call_unref(decrypt_request_data.pending_call);
7693 decrypt_request_data.pending_call = NULL;
7696 g_free(decrypt_request_data.data->path);
7697 g_free(decrypt_request_data.data->ssid);
7698 dbus_free(decrypt_request_data.data);
7699 decrypt_request_data.data = NULL;
7702 static void decryption_request_reply(DBusPendingCall *call,
7707 DBusMessageIter args;
7710 struct interface_connect_data *data = user_data;
7714 reply = dbus_pending_call_steal_reply(call);
7716 dbus_error_init(&error);
7717 if (dbus_set_error_from_message(&error, reply)) {
7718 SUPPLICANT_DBG("decryption_request_reply() %s %s", error.name, error.message);
7719 dbus_error_free(&error);
7724 if (!g_str_has_prefix(data->interface->path, "/")) {
7725 SUPPLICANT_DBG("Invalid path %s", data->interface->path);
7730 if (dbus_message_iter_init(reply, &args) == FALSE) {
7731 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7736 dbus_message_iter_get_basic(&args, &out_data);
7737 data->ssid->passphrase = g_strdup((const gchar *)out_data);
7738 data->ssid->is_passphrase_alloc = true;
7740 ret = supplicant_dbus_method_call(data->interface->path,
7741 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7742 interface_add_network_params,
7743 interface_add_network_result, data,
7748 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7749 callback_assoc_failed(decrypt_request_data.data->user_data);
7751 g_free(data->ssid->ssid);
7752 if (data->ssid->is_passphrase_alloc)
7753 g_free((char *)data->ssid->passphrase);
7754 if (data->ssid->is_connector_alloc)
7755 g_free((char *)data->ssid->connector);
7756 if (data->ssid->is_c_sign_key_alloc)
7757 g_free((char *)data->ssid->c_sign_key);
7758 if (data->ssid->is_net_access_key_alloc)
7759 g_free((char *)data->ssid->net_access_key);
7764 dbus_message_unref(reply);
7765 dbus_pending_call_unref(call);
7767 decrypt_request_data.pending_call = NULL;
7768 decrypt_request_data.data = NULL;
7771 static int send_decryption_request(const char *passphrase,
7772 struct interface_connect_data *data)
7774 DBusMessage *msg = NULL;
7775 DBusPendingCall *call;
7777 SUPPLICANT_DBG("Decryption request");
7780 SUPPLICANT_DBG("Invalid parameter");
7787 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7788 NETCONFIG_WIFI_INTERFACE, "DecryptPassphrase");
7792 #if defined TIZEN_EXT
7793 if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7794 DBUS_TYPE_INVALID)) {
7795 SUPPLICANT_DBG("Could not fulfill decryption request");
7799 dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
7803 if (!dbus_connection_send_with_reply(connection, msg,
7804 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7805 dbus_message_unref(msg);
7810 dbus_message_unref(msg);
7814 decrypt_request_data.pending_call = call;
7815 decrypt_request_data.data = data;
7817 dbus_pending_call_set_notify(call, decryption_request_reply, data, NULL);
7818 dbus_message_unref(msg);
7820 SUPPLICANT_DBG("Decryption request succeeded");
7825 static void decrypt_conf_obj_reply(DBusPendingCall *call,
7830 DBusMessageIter iter, dict;
7833 struct interface_connect_data *data = user_data;
7835 reply = dbus_pending_call_steal_reply(call);
7837 dbus_error_init(&error);
7838 if (dbus_set_error_from_message(&error, reply)) {
7839 SUPPLICANT_DBG("decryption_conf_obj_reply() %s %s", error.name, error.message);
7840 dbus_error_free(&error);
7845 if (dbus_message_iter_init(reply, &iter) == FALSE) {
7846 SUPPLICANT_DBG("dbus_message_iter_init() failed");
7851 dbus_message_iter_recurse(&iter, &dict);
7853 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
7854 DBusMessageIter entry, value;
7857 dbus_message_iter_recurse(&dict, &entry);
7858 dbus_message_iter_get_basic(&entry, &key);
7859 dbus_message_iter_next(&entry);
7860 dbus_message_iter_recurse(&entry, &value);
7861 if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
7862 if (g_strcmp0(key, "connector") == 0) {
7863 dbus_message_iter_get_basic(&value, &out_data);
7864 data->ssid->connector = g_strdup((const gchar *)out_data);
7865 data->ssid->is_connector_alloc = true;
7866 SUPPLICANT_DBG("connector %s", data->ssid->connector);
7867 } else if (g_strcmp0(key, "c_sign_key") == 0) {
7868 dbus_message_iter_get_basic(&value, &out_data);
7869 data->ssid->c_sign_key = g_strdup((const gchar *)out_data);
7870 data->ssid->is_c_sign_key_alloc = true;
7871 SUPPLICANT_DBG("c_sign_key %s", data->ssid->c_sign_key);
7872 } else if (g_strcmp0(key, "net_access_key") == 0) {
7873 dbus_message_iter_get_basic(&value, &out_data);
7874 data->ssid->net_access_key = g_strdup((const gchar *)out_data);
7875 data->ssid->is_net_access_key_alloc = true;
7876 SUPPLICANT_DBG("net_access_key %s", data->ssid->net_access_key);
7879 dbus_message_iter_next(&dict);
7882 ret = supplicant_dbus_method_call(data->interface->path,
7883 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
7884 interface_add_network_params,
7885 interface_add_network_result, data,
7890 SUPPLICANT_DBG("AddNetwork failed %d", ret);
7891 callback_assoc_failed(decrypt_request_data.data->user_data);
7893 g_free(data->ssid->ssid);
7894 if (data->ssid->is_connector_alloc)
7895 g_free((char *)data->ssid->connector);
7896 if (data->ssid->is_c_sign_key_alloc)
7897 g_free((char *)data->ssid->c_sign_key);
7898 if (data->ssid->is_net_access_key_alloc)
7899 g_free((char *)data->ssid->net_access_key);
7904 dbus_message_unref(reply);
7905 dbus_pending_call_unref(call);
7907 decrypt_request_data.pending_call = NULL;
7908 decrypt_request_data.data = NULL;
7911 static int send_decryption_conf_obj_request(GSupplicantSSID *ssid,
7912 struct interface_connect_data *data)
7914 DBusMessage *msg = NULL;
7915 DBusPendingCall *call;
7917 SUPPLICANT_DBG("Decryption configuration object request");
7920 SUPPLICANT_DBG("Invalid parameter");
7927 msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
7928 NETCONFIG_WIFI_INTERFACE, "DecryptConfObj");
7932 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->connector,
7934 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->c_sign_key,
7936 dbus_message_append_args(msg, DBUS_TYPE_STRING, &ssid->net_access_key,
7939 if (!dbus_connection_send_with_reply(connection, msg,
7940 &call, DBUS_TIMEOUT_USE_DEFAULT)) {
7941 dbus_message_unref(msg);
7946 dbus_message_unref(msg);
7950 decrypt_request_data.pending_call = call;
7951 decrypt_request_data.data = data;
7953 dbus_pending_call_set_notify(call, decrypt_conf_obj_reply, data, NULL);
7954 dbus_message_unref(msg);
7956 SUPPLICANT_DBG("Decrypt Conf Obj request succeeded");
7961 static bool is_valid_config_object(GSupplicantSSID *ssid)
7963 return ((ssid->connector &&
7964 g_strcmp0(ssid->connector, "") != 0) &&
7965 (ssid->c_sign_key &&
7966 g_strcmp0(ssid->c_sign_key, "") != 0) &&
7967 (ssid->net_access_key &&
7968 g_strcmp0(ssid->net_access_key, "") != 0));
7972 int g_supplicant_interface_connect(GSupplicantInterface *interface,
7973 GSupplicantSSID *ssid,
7974 GSupplicantInterfaceCallback callback,
7977 struct interface_connect_data *data;
7978 struct interface_data *intf_data;
7986 if (!system_available)
7989 /* TODO: Check if we're already connected and switch */
7991 data = dbus_malloc0(sizeof(*data));
7995 data->interface = interface;
7996 data->path = g_strdup(interface->path);
7997 data->callback = callback;
7999 data->user_data = user_data;
8001 if (ssid->use_wps) {
8002 g_free(interface->wps_cred.key);
8003 memset(&interface->wps_cred, 0,
8004 sizeof(struct _GSupplicantWpsCredentials));
8006 ret = supplicant_dbus_property_set(interface->path,
8007 SUPPLICANT_INTERFACE ".Interface.WPS",
8008 "ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
8009 wps_process_credentials, wps_start, data, interface);
8011 /* By the time there is a request for connect and the network
8012 * path is not NULL it means that connman has not removed the
8013 * previous network pointer. This can happen in the case AP
8014 * deauthenticated client and connman does not remove the
8015 * previously connected network pointer. This causes supplicant
8016 * to reallocate the memory for struct wpa_ssid again even if it
8017 * is the same SSID. This causes memory usage of wpa_supplicnat
8018 * to go high. The idea here is that if the previously connected
8019 * network is not removed at the time of next connection attempt
8020 * check if the network path is not NULL. In case it is non-NULL
8021 * first remove the network and then once removal is successful, add
8025 if (interface->network_path != NULL) {
8030 * If this add network is for the same network for
8031 * which wpa_supplicant already has a profile then do
8032 * not need to add another profile. Only if the
8033 * profile that needs to get added is different from
8034 * what is there in wpa_s delete the current one. A
8035 * network is identified by its SSID, security_type
8036 * and passphrase (private passphrase in case security
8039 if (compare_network_parameters(interface, ssid)) {
8043 intf_data = dbus_malloc0(sizeof(*intf_data));
8047 intf_data->interface = interface;
8048 intf_data->path = g_strdup(interface->path);
8049 intf_data->callback = callback;
8050 intf_data->ssid = ssid;
8051 intf_data->user_data = user_data;
8052 intf_data->network_remove_in_progress = TRUE;
8053 network_remove(intf_data);
8055 #if defined TIZEN_EXT
8056 if (ssid->passphrase &&
8057 g_strcmp0(ssid->passphrase, "") != 0 &&
8058 #if defined TIZEN_EXT_WIFI_MESH
8059 ssid->mode != G_SUPPLICANT_MODE_MESH &&
8062 ret = send_decryption_request(ssid->passphrase, data);
8064 SUPPLICANT_DBG("Decryption request failed %d", ret);
8065 } else if (is_valid_config_object(ssid)) {
8066 ret = send_decryption_conf_obj_request(ssid, data);
8068 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
8072 ret = supplicant_dbus_method_call(interface->path,
8073 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
8074 interface_add_network_params,
8075 interface_add_network_result, data,
8086 return -EINPROGRESS;
8089 static void network_remove_result(const char *error,
8090 DBusMessageIter *iter, void *user_data)
8092 struct interface_data *data = user_data;
8093 struct interface_connect_data *connect_data;
8100 SUPPLICANT_DBG("error: %s", error);
8102 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8104 result = -ECONNABORTED;
8107 g_free(data->interface->network_path);
8108 data->interface->network_path = NULL;
8110 remove_network_information(data->interface);
8112 if (data->network_remove_in_progress == TRUE) {
8113 data->network_remove_in_progress = FALSE;
8114 connect_data = dbus_malloc0(sizeof(*connect_data));
8118 connect_data->interface = data->interface;
8119 connect_data->path = g_strdup(data->path);
8120 connect_data->callback = data->callback;
8121 connect_data->ssid = data->ssid;
8122 connect_data->user_data = data->user_data;
8124 #if defined TIZEN_EXT
8126 if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
8127 && !data->ssid->eap) {
8128 ret = send_decryption_request(data->ssid->passphrase, connect_data);
8130 SUPPLICANT_DBG("Decryption request failed %d", ret);
8131 g_free(connect_data->ssid);
8132 g_free(connect_data->path);
8133 dbus_free(connect_data);
8135 } else if (is_valid_config_object(data->ssid)) {
8136 ret = send_decryption_conf_obj_request(data->ssid, connect_data);
8138 SUPPLICANT_DBG("Decryption Conf Obj request failed %d", ret);
8139 g_free(connect_data->ssid);
8140 g_free(connect_data->path);
8141 dbus_free(connect_data);
8145 supplicant_dbus_method_call(data->interface->path,
8146 SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
8147 interface_add_network_params,
8148 interface_add_network_result, connect_data,
8149 connect_data->interface);
8152 data->callback(result, data->interface, data->user_data);
8158 static void network_remove_params(DBusMessageIter *iter, void *user_data)
8160 struct interface_data *data = user_data;
8161 const char *path = data->interface->network_path;
8163 SUPPLICANT_DBG("path %s", path);
8165 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
8168 static int network_remove(struct interface_data *data)
8170 GSupplicantInterface *interface = data->interface;
8174 #if defined TIZEN_EXT
8175 GSupplicantInterface *intf = NULL;
8177 * Check if 'interface' is valid
8179 intf = g_hash_table_lookup(interface_table, interface->path);
8184 return supplicant_dbus_method_call(interface->path,
8185 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8186 network_remove_params, network_remove_result, data,
8190 static void interface_disconnect_result(const char *error,
8191 DBusMessageIter *iter, void *user_data)
8193 struct interface_data *data = user_data;
8200 SUPPLICANT_DBG("error: %s", error);
8202 if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
8204 result = -ECONNABORTED;
8207 /* If we are disconnecting from previous WPS successful
8208 * association. i.e.: it did not went through AddNetwork,
8209 * and interface->network_path was never set. */
8210 if (!data->interface->network_path) {
8212 data->callback(result, data->interface,
8220 if (result < 0 && data->callback) {
8221 data->callback(result, data->interface, data->user_data);
8222 data->callback = NULL;
8225 if (result != -ECONNABORTED) {
8226 if (network_remove(data) < 0) {
8236 int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
8237 GSupplicantInterfaceCallback callback,
8240 struct interface_data *data;
8248 if (!system_available)
8250 #if defined TIZEN_EXT
8251 if (decrypt_request_data.pending_call &&
8252 decrypt_request_data.data &&
8253 decrypt_request_data.data->user_data == user_data) {
8255 callback_assoc_failed(decrypt_request_data.data->user_data);
8256 crypt_method_call_cancel();
8261 data = dbus_malloc0(sizeof(*data));
8265 data->interface = interface;
8266 data->path = g_strdup(interface->path);
8267 data->callback = callback;
8268 data->user_data = user_data;
8270 ret = supplicant_dbus_method_call(interface->path,
8271 SUPPLICANT_INTERFACE ".Interface", "Disconnect",
8272 NULL, interface_disconnect_result, data,
8283 #if defined TIZEN_EXT
8284 void g_supplicant_interface_remove_network(GSupplicantInterface *interface,
8285 GSupplicantSSID *ssid)
8287 struct interface_data *data;
8295 if (interface->network_path == NULL)
8298 if (!interface->network_info.ssid)
8301 if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
8304 if (interface->network_info.security != ssid->security)
8307 data = dbus_malloc0(sizeof(*data));
8311 data->interface = interface;
8312 data->path = g_strdup(interface->path);
8314 ret = supplicant_dbus_method_call(interface->path,
8315 SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
8316 network_remove_params, network_remove_result, data,
8326 static void interface_p2p_find_result(const char *error,
8327 DBusMessageIter *iter, void *user_data)
8329 struct interface_scan_data *data = user_data;
8332 SUPPLICANT_DBG("error %s", error);
8337 if (interface_exists(data->interface, data->path)) {
8338 if (!data->interface->ready)
8341 data->interface->p2p_finding = true;
8345 data->callback(err, data->interface, data->user_data);
8351 static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
8353 DBusMessageIter dict;
8355 supplicant_dbus_dict_open(iter, &dict);
8356 supplicant_dbus_dict_close(iter, &dict);
8359 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
8360 GSupplicantInterfaceCallback callback,
8363 struct interface_scan_data *data;
8366 if (!interface->p2p_support)
8369 ret = interface_ready_to_scan(interface);
8370 if (ret && ret != -EALREADY)
8373 data = dbus_malloc0(sizeof(*data));
8377 data->interface = interface;
8378 data->path = g_strdup(interface->path);
8379 data->callback = callback;
8380 data->user_data = user_data;
8382 ret = supplicant_dbus_method_call(interface->path,
8383 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
8384 interface_p2p_find_params, interface_p2p_find_result,
8394 bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
8399 return interface->p2p_finding;
8402 int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
8404 if (!interface->p2p_finding)
8409 interface->p2p_finding = false;
8411 return supplicant_dbus_method_call(interface->path,
8412 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
8413 NULL, NULL, NULL, NULL);
8416 static void interface_p2p_connect_result(const char *error,
8417 DBusMessageIter *iter, void *user_data)
8419 struct interface_connect_data *data = user_data;
8425 SUPPLICANT_DBG("error: %s", error);
8426 err = parse_supplicant_error(iter);
8430 data->callback(err, data->interface, data->user_data);
8433 g_free(data->peer->wps_pin);
8434 g_free(data->peer->path);
8439 static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
8441 struct interface_connect_data *data = user_data;
8442 const char *wps = "pbc";
8443 DBusMessageIter dict;
8448 supplicant_dbus_dict_open(iter, &dict);
8450 if (data->peer->master)
8453 if (data->peer->wps_pin)
8456 supplicant_dbus_dict_append_basic(&dict, "peer",
8457 DBUS_TYPE_OBJECT_PATH, &data->peer->path);
8458 supplicant_dbus_dict_append_basic(&dict, "wps_method",
8459 DBUS_TYPE_STRING, &wps);
8460 if (data->peer->wps_pin) {
8461 supplicant_dbus_dict_append_basic(&dict, "pin",
8462 DBUS_TYPE_STRING, &data->peer->wps_pin);
8465 supplicant_dbus_dict_append_basic(&dict, "go_intent",
8466 DBUS_TYPE_INT32, &go_intent);
8468 supplicant_dbus_dict_close(iter, &dict);
8471 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
8472 GSupplicantPeerParams *peer_params,
8473 GSupplicantInterfaceCallback callback,
8476 struct interface_connect_data *data;
8481 if (!interface->p2p_support)
8484 data = dbus_malloc0(sizeof(*data));
8488 data->interface = interface;
8489 data->path = g_strdup(interface->path);
8490 data->peer = peer_params;
8491 data->callback = callback;
8492 data->user_data = user_data;
8494 ret = supplicant_dbus_method_call(interface->path,
8495 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
8496 interface_p2p_connect_params, interface_p2p_connect_result,
8504 return -EINPROGRESS;
8507 int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
8508 GSupplicantPeerParams *peer_params)
8510 GSupplicantPeer *peer;
8516 if (!interface->p2p_support)
8519 peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
8523 for (list = peer->groups; list; list = list->next, count++) {
8524 const char *group_obj_path = list->data;
8525 GSupplicantInterface *g_interface;
8526 GSupplicantGroup *group;
8528 group = g_hash_table_lookup(group_mapping, group_obj_path);
8529 if (!group || !group->interface)
8532 g_interface = group->interface;
8533 supplicant_dbus_method_call(g_interface->path,
8534 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8535 "Disconnect", NULL, NULL, NULL, g_interface);
8538 if (count == 0 && peer->current_group_iface) {
8539 supplicant_dbus_method_call(peer->current_group_iface->path,
8540 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8541 "Disconnect", NULL, NULL, NULL,
8542 peer->current_group_iface->path);
8545 peer->current_group_iface = NULL;
8547 return -EINPROGRESS;
8550 struct p2p_service_data {
8552 GSupplicantInterface *interface;
8553 GSupplicantP2PServiceParams *service;
8554 GSupplicantInterfaceCallback callback;
8558 static void interface_p2p_service_result(const char *error,
8559 DBusMessageIter *iter, void *user_data)
8561 struct p2p_service_data *data = user_data;
8564 SUPPLICANT_DBG("%s result - %s", data->registration ?
8565 "Registration" : "Deletion",
8566 error ? error : "Success");
8571 data->callback(result, data->interface, data->user_data);
8573 g_free(data->service->query);
8574 g_free(data->service->response);
8575 g_free(data->service->service);
8576 g_free(data->service->wfd_ies);
8577 g_free(data->service);
8581 static void interface_p2p_service_params(DBusMessageIter *iter,
8584 struct p2p_service_data *data = user_data;
8585 GSupplicantP2PServiceParams *service;
8586 DBusMessageIter dict;
8591 service = data->service;
8593 supplicant_dbus_dict_open(iter, &dict);
8595 if (service->query && service->response) {
8597 supplicant_dbus_dict_append_basic(&dict, "service_type",
8598 DBUS_TYPE_STRING, &type);
8599 supplicant_dbus_dict_append_fixed_array(&dict, "query",
8600 DBUS_TYPE_BYTE, &service->query,
8601 service->query_length);
8602 supplicant_dbus_dict_append_fixed_array(&dict, "response",
8603 DBUS_TYPE_BYTE, &service->response,
8604 service->response_length);
8605 } else if (service->version && service->service) {
8607 supplicant_dbus_dict_append_basic(&dict, "service_type",
8608 DBUS_TYPE_STRING, &type);
8609 supplicant_dbus_dict_append_basic(&dict, "version",
8610 DBUS_TYPE_INT32, &service->version);
8611 supplicant_dbus_dict_append_basic(&dict, "service",
8612 DBUS_TYPE_STRING, &service->service);
8615 supplicant_dbus_dict_close(iter, &dict);
8618 int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
8619 GSupplicantInterfaceCallback callback,
8620 GSupplicantP2PServiceParams *p2p_service_params,
8623 struct p2p_service_data *data;
8628 if (!interface->p2p_support)
8631 data = dbus_malloc0(sizeof(*data));
8635 data->registration = true;
8636 data->interface = interface;
8637 data->service = p2p_service_params;
8638 data->callback = callback;
8639 data->user_data = user_data;
8641 ret = supplicant_dbus_method_call(interface->path,
8642 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
8643 interface_p2p_service_params, interface_p2p_service_result,
8650 return -EINPROGRESS;
8653 int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
8654 GSupplicantP2PServiceParams *p2p_service_params)
8656 struct p2p_service_data *data;
8661 if (!interface->p2p_support)
8664 data = dbus_malloc0(sizeof(*data));
8668 data->interface = interface;
8669 data->service = p2p_service_params;
8671 ret = supplicant_dbus_method_call(interface->path,
8672 SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
8673 interface_p2p_service_params, interface_p2p_service_result,
8680 return -EINPROGRESS;
8683 struct p2p_listen_data {
8688 static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
8690 struct p2p_listen_data *params = user_data;
8691 DBusMessageIter dict;
8693 supplicant_dbus_dict_open(iter, &dict);
8695 supplicant_dbus_dict_append_basic(&dict, "period",
8696 DBUS_TYPE_INT32, ¶ms->period);
8697 supplicant_dbus_dict_append_basic(&dict, "interval",
8698 DBUS_TYPE_INT32, ¶ms->interval);
8699 supplicant_dbus_dict_close(iter, &dict);
8702 int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
8703 int period, int interval)
8705 struct p2p_listen_data params;
8709 if (!interface->p2p_support)
8712 params.period = period;
8713 params.interval = interval;
8715 return supplicant_dbus_method_call(interface->path,
8716 SUPPLICANT_INTERFACE ".Interface.P2PDevice",
8717 "ExtendedListen", interface_p2p_listen_params,
8718 NULL, ¶ms, NULL);
8721 static void widi_ies_params(DBusMessageIter *iter, void *user_data)
8723 struct p2p_service_data *data = user_data;
8724 GSupplicantP2PServiceParams *service = data->service;
8725 DBusMessageIter array;
8727 SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
8729 dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
8730 DBUS_TYPE_BYTE_AS_STRING, &array);
8732 if (service->wfd_ies && service->wfd_ies_length > 0) {
8733 dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
8734 &service->wfd_ies, service->wfd_ies_length);
8737 dbus_message_iter_close_container(iter, &array);
8740 int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
8741 GSupplicantInterfaceCallback callback,
8744 struct p2p_service_data *data;
8749 if (!system_available)
8752 data = dbus_malloc0(sizeof(*data));
8756 data->service = p2p_service_params;
8757 data->callback = callback;
8758 data->user_data = user_data;
8760 if (p2p_service_params->wfd_ies)
8761 data->registration = true;
8763 ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
8764 SUPPLICANT_INTERFACE, "WFDIEs",
8765 DBUS_TYPE_ARRAY_AS_STRING
8766 DBUS_TYPE_BYTE_AS_STRING,
8768 interface_p2p_service_result,
8770 if (ret < 0 && ret != -EINPROGRESS) {
8775 return -EINPROGRESS;
8779 static const char *g_supplicant_rule0 = "type=signal,"
8780 "path=" DBUS_PATH_DBUS ","
8781 "sender=" DBUS_SERVICE_DBUS ","
8782 "interface=" DBUS_INTERFACE_DBUS ","
8783 "member=NameOwnerChanged,"
8784 "arg0=" SUPPLICANT_SERVICE;
8785 static const char *g_supplicant_rule1 = "type=signal,"
8786 "interface=" SUPPLICANT_INTERFACE;
8787 static const char *g_supplicant_rule2 = "type=signal,"
8788 "interface=" SUPPLICANT_INTERFACE ".Interface";
8789 static const char *g_supplicant_rule3 = "type=signal,"
8790 "interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
8791 static const char *g_supplicant_rule4 = "type=signal,"
8792 "interface=" SUPPLICANT_INTERFACE ".BSS";
8793 static const char *g_supplicant_rule5 = "type=signal,"
8794 "interface=" SUPPLICANT_INTERFACE ".Network";
8795 #if !defined TIZEN_EXT
8796 static const char *g_supplicant_rule6 = "type=signal,"
8797 "interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
8798 static const char *g_supplicant_rule7 = "type=signal,"
8799 "interface=" SUPPLICANT_INTERFACE ".Peer";
8800 static const char *g_supplicant_rule8 = "type=signal,"
8801 "interface=" SUPPLICANT_INTERFACE ".Group";
8803 #if defined TIZEN_EXT_WIFI_MESH
8804 static const char *g_supplicant_rule9 = "type=signal,"
8805 "interface=" SUPPLICANT_INTERFACE ".Interface.Mesh";
8808 static void invoke_introspect_method(void)
8810 DBusMessage *message;
8812 message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
8814 DBUS_INTERFACE_INTROSPECTABLE,
8820 dbus_message_set_no_reply(message, TRUE);
8821 dbus_connection_send(connection, message, NULL);
8822 dbus_message_unref(message);
8825 #if defined TIZEN_EXT
8826 void g_supplicant_set_ins_settings(GSupplicantINSPreferredFreq preferred_freq_bssid,
8827 bool last_connected_bssid, bool assoc_reject, bool signal_bssid,
8828 unsigned int preferred_freq_bssid_score, unsigned int last_connected_bssid_score,
8829 unsigned int assoc_reject_score, int signal_level3_5ghz, int signal_level3_24ghz)
8831 ins_settings.preferred_freq_bssid = preferred_freq_bssid;
8832 ins_settings.last_connected_bssid = last_connected_bssid;
8833 ins_settings.assoc_reject = assoc_reject;
8834 ins_settings.signal_bssid = signal_bssid;
8835 ins_settings.preferred_freq_bssid_score = preferred_freq_bssid_score;
8836 ins_settings.last_connected_bssid_score = last_connected_bssid_score;
8837 ins_settings.assoc_reject_score = assoc_reject_score;
8838 ins_settings.signal_level3_5ghz = signal_level3_5ghz;
8839 ins_settings.signal_level3_24ghz = signal_level3_24ghz;
8841 SUPPLICANT_DBG("preferred_freq_bssid [%s]", preferred_freq_bssid ? "true" : "false");
8842 SUPPLICANT_DBG("preferred_freq_bssid_score [%d]", preferred_freq_bssid_score);
8843 SUPPLICANT_DBG("last_connected_bssid [%s]", last_connected_bssid ? "true" : "false");
8844 SUPPLICANT_DBG("last_connected_bssid_score [%d]", last_connected_bssid_score);
8845 SUPPLICANT_DBG("assoc_reject [%s]", assoc_reject ? "true" : "false");
8846 SUPPLICANT_DBG("assoc_reject_score [%d]", assoc_reject_score);
8847 SUPPLICANT_DBG("signal_bssid [%s]", signal_bssid ? "true" : "false");
8848 SUPPLICANT_DBG("signal_level3_5ghz [%d]", signal_level3_5ghz);
8849 SUPPLICANT_DBG("signal_level3_24ghz [%d]", signal_level3_24ghz);
8851 #endif /* defined TIZEN_EXT */
8853 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8854 void g_supplicant_register_eap_callback(g_supplicant_eap_callback cb)
8856 SUPPLICANT_DBG("g_supplicant_register_eap_callback %p", cb);
8858 if (!callbacks_pointer) {
8859 SUPPLICANT_DBG("callbacks_pointer is NULL");
8863 callbacks_pointer->eap = cb;
8866 void g_supplicant_unregister_eap_callback(void)
8868 SUPPLICANT_DBG("g_supplicant_unregister_eap_callback");
8870 if (!callbacks_pointer) {
8871 SUPPLICANT_DBG("callbacks_pointer is NULL");
8875 callbacks_pointer->eap = NULL;
8877 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8879 #if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
8880 int g_supplicant_register(GSupplicantCallbacks *callbacks)
8881 #else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8882 int g_supplicant_register(const GSupplicantCallbacks *callbacks)
8883 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
8885 connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8889 if (!dbus_connection_add_filter(connection, g_supplicant_filter,
8891 dbus_connection_unref(connection);
8895 #if defined TIZEN_EXT
8896 simplified_log = connman_setting_get_bool("SimplifiedLog");
8898 callbacks_pointer = callbacks;
8901 interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8902 NULL, remove_interface);
8904 bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8906 peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8908 group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
8910 pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
8912 config_file_table = g_hash_table_new_full(g_str_hash, g_str_equal,
8915 supplicant_dbus_setup(connection);
8917 dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
8918 dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
8919 dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
8920 dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
8921 dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
8922 dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
8923 #if defined TIZEN_EXT
8924 dbus_bus_add_match(connection,
8925 "type=signal,interface=org.tizen.system.deviced.PowerOff,"
8926 "member=ChangeState", NULL);
8928 #if !defined TIZEN_EXT
8929 dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
8930 dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
8931 dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
8933 #if defined TIZEN_EXT_WIFI_MESH
8934 dbus_bus_add_match(connection, g_supplicant_rule9, NULL);
8936 dbus_connection_flush(connection);
8938 if (dbus_bus_name_has_owner(connection,
8939 SUPPLICANT_SERVICE, NULL)) {
8940 system_available = TRUE;
8941 supplicant_dbus_property_get_all(SUPPLICANT_PATH,
8942 SUPPLICANT_INTERFACE,
8943 service_property, NULL, NULL);
8945 invoke_introspect_method();
8947 SUPPLICANT_DBG("supplicant dbus setup completed");
8951 static void unregister_interface_remove_params(DBusMessageIter *iter,
8954 const char *path = user_data;
8956 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
8961 static void unregister_remove_interface(gpointer key, gpointer value,
8964 GSupplicantInterface *interface = value;
8966 supplicant_dbus_method_call(SUPPLICANT_PATH,
8967 SUPPLICANT_INTERFACE,
8969 unregister_interface_remove_params,
8970 NULL, interface->path, NULL);
8973 void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
8978 #if defined TIZEN_EXT_WIFI_MESH
8979 dbus_bus_remove_match(connection, g_supplicant_rule9, NULL);
8981 #if !defined TIZEN_EXT
8982 dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
8983 dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
8984 dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
8986 dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
8987 dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
8988 dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
8989 dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
8990 dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
8991 dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
8992 dbus_connection_flush(connection);
8994 dbus_connection_remove_filter(connection,
8995 g_supplicant_filter, NULL);
8998 if (config_file_table) {
8999 g_hash_table_destroy(config_file_table);
9000 config_file_table = NULL;
9004 g_hash_table_destroy(bss_mapping);
9009 g_hash_table_destroy(peer_mapping);
9010 peer_mapping = NULL;
9013 if (group_mapping) {
9014 g_hash_table_destroy(group_mapping);
9015 group_mapping = NULL;
9018 if (interface_table) {
9019 g_hash_table_foreach(interface_table,
9020 unregister_remove_interface, NULL);
9021 g_hash_table_destroy(interface_table);
9022 interface_table = NULL;
9025 if (system_available)
9026 callback_system_killed();
9029 dbus_connection_unref(connection);
9033 callbacks_pointer = NULL;
9038 struct supplicant_mac_policy {
9039 GSupplicantMacPolicyCallback callback;
9040 dbus_uint32_t policy;
9041 const void *user_data;
9044 static void mac_policy_result(const char *error,
9045 DBusMessageIter *iter, void *user_data)
9047 struct supplicant_mac_policy *data = user_data;
9054 SUPPLICANT_DBG("Mac policy setting failure %s", error);
9059 data->callback(result, data->policy,
9060 (void *) data->user_data);
9065 static void mac_policy_params(DBusMessageIter *iter, void *user_data)
9067 struct supplicant_mac_policy *data = user_data;
9069 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(data->policy));
9072 int g_supplicant_interface_set_mac_policy(GSupplicantInterface *interface,
9073 GSupplicantMacPolicyCallback callback,
9074 unsigned int policy,
9077 struct supplicant_mac_policy *data = NULL;
9080 if (!system_available)
9086 data = dbus_malloc0(sizeof(*data));
9090 data->callback = callback;
9091 data->policy = policy;
9092 data->user_data = user_data;
9094 ret = supplicant_dbus_property_set(interface->path,
9095 SUPPLICANT_INTERFACE ".Interface",
9096 "MacAddr", DBUS_TYPE_INT32_AS_STRING,
9097 mac_policy_params, mac_policy_result, data, NULL);
9099 SUPPLICANT_DBG("Unable to set MacAddr configuration");
9106 int g_supplicant_interface_set_preassoc_mac_policy(GSupplicantInterface *interface,
9107 GSupplicantMacPolicyCallback callback,
9108 unsigned int policy,
9111 struct supplicant_mac_policy *data;
9114 if (!system_available)
9120 data = dbus_malloc0(sizeof(*data));
9124 data->callback = callback;
9125 data->policy = policy;
9126 data->user_data = user_data;
9128 ret = supplicant_dbus_property_set(interface->path,
9129 SUPPLICANT_INTERFACE ".Interface",
9130 "PreassocMacAddr", DBUS_TYPE_INT32_AS_STRING,
9131 mac_policy_params, mac_policy_result, data, NULL);
9133 SUPPLICANT_DBG("Unable to set PreassocMacAddr configuration");
9140 struct supplicant_random_mac_lifetime {
9141 GSupplicantRandomMaclifetimeCallback callback;
9142 dbus_uint32_t lifetime;
9143 const void *user_data;
9146 static void random_mac_lifetime_result(const char *error,
9147 DBusMessageIter *iter, void *user_data)
9149 struct supplicant_random_mac_lifetime *data = user_data;
9156 SUPPLICANT_DBG("Random Mac lifetime setting failure %s", error);
9161 data->callback(result, data->lifetime,
9162 (void *) data->user_data);
9167 static void random_mac_lifetime_params(DBusMessageIter *iter, void *user_data)
9169 struct supplicant_random_mac_lifetime *data = user_data;
9171 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &(data->lifetime));
9174 int g_supplicant_interface_set_random_mac_lifetime(GSupplicantInterface *interface,
9175 GSupplicantRandomMaclifetimeCallback callback,
9176 unsigned int lifetime,
9179 struct supplicant_random_mac_lifetime *data;
9182 if (!system_available)
9188 data = dbus_malloc0(sizeof(*data));
9192 data->callback = callback;
9193 data->lifetime = lifetime;
9194 data->user_data = user_data;
9196 ret = supplicant_dbus_property_set(interface->path,
9197 SUPPLICANT_INTERFACE ".Interface",
9198 "RandAddrLifetime", DBUS_TYPE_UINT32_AS_STRING,
9199 random_mac_lifetime_params, random_mac_lifetime_result,
9202 SUPPLICANT_DBG("Unable to set RandAddrLifetime configuration");