From c632a998a3d4dfbae1a46cbdae39c7870852a329 Mon Sep 17 00:00:00 2001 From: "hyunuk.tak" Date: Thu, 27 Aug 2020 16:38:57 +0900 Subject: [PATCH] Add multi interfaces function Change-Id: I1c7a200a1c627803f10c30f85066e921f10835d3 Signed-off-by: hyunuk.tak --- CMakeLists.txt | 2 + include/ip-conflict-detect.h | 14 +- include/netdbus.h | 2 +- include/netsupplicant.h | 8 +- include/network-state.h | 8 +- include/setting.h | 59 +++ include/util.h | 5 + include/wifi-agent.h | 2 +- include/wifi-background-scan.h | 53 +-- include/wifi-bssid-scan.h | 12 +- include/wifi-config.h | 44 ++- include/wifi-dpp.h | 2 +- include/wifi-extension.h | 3 +- include/wifi-firmware.h | 9 +- include/wifi-indicator.h | 4 +- include/wifi-netlink-scan.h | 5 +- include/wifi-passpoint.h | 4 +- include/wifi-power.h | 19 +- include/wifi-scan.h | 70 ++++ include/wifi-state.h | 71 ++-- include/wifi-tdls.h | 23 +- include/wifi-wps.h | 16 +- interfaces/netconfig-iface-wifi.xml | 72 +++- packaging/net-config.spec | 7 +- resources/var/lib/net-config/settings | 5 + src/clatd-handler.c | 5 +- src/dbus/netdbus.c | 4 +- src/dbus/netsupplicant.c | 27 +- src/ip-conflict-detect.c | 79 ++-- src/main.c | 5 + src/network-dpm.c | 41 +- src/network-state.c | 469 ++++++++--------------- src/network-statistics.c | 33 +- src/signal-handler.c | 467 +++++++++++----------- src/utils/network-accessibility.c | 4 +- src/utils/setting.c | 283 ++++++++++++++ src/utils/util.c | 30 +- src/wifi-agent.c | 296 +++++++++----- src/wifi-background-scan.c | 338 ++-------------- src/wifi-bssid-scan.c | 286 +++++++++----- src/wifi-config.c | 164 ++++---- src/wifi-dpp.c | 17 +- src/wifi-eap-config.c | 85 +++-- src/wifi-eap.c | 4 +- src/wifi-extension.c | 5 +- src/wifi-firmware.c | 101 ++--- src/wifi-indicator.c | 113 +++++- src/wifi-netlink-scan.c | 17 +- src/wifi-passpoint.c | 22 +- src/wifi-power.c | 462 ++++++++++------------ src/wifi-scan.c | 428 +++++++++++++++++++++ src/wifi-state.c | 531 ++++++++++++++++---------- src/wifi-tdls.c | 71 ++-- src/wifi-wps.c | 172 +++++++-- src/wifi.c | 14 +- 55 files changed, 3117 insertions(+), 1975 deletions(-) create mode 100755 include/setting.h mode change 100644 => 100755 include/wifi-dpp.h create mode 100755 include/wifi-scan.h create mode 100644 resources/var/lib/net-config/settings create mode 100755 src/utils/setting.c mode change 100644 => 100755 src/wifi-dpp.c create mode 100755 src/wifi-scan.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c5d0a9a..8a81aac 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ SET(SRCS src/neterror.c src/wifi-eap.c src/wifi-wps.c + src/wifi-scan.c src/wifi-bssid-scan.c src/wifi-netlink-scan.c src/wifi-agent.c @@ -23,6 +24,7 @@ SET(SRCS src/wifi-passpoint.c src/utils/log.c src/utils/util.c + src/utils/setting.c src/vpnsvc.c src/vpnsvc-internal.c src/mptcp.c diff --git a/include/ip-conflict-detect.h b/include/ip-conflict-detect.h index f830a4f..2f67d00 100755 --- a/include/ip-conflict-detect.h +++ b/include/ip-conflict-detect.h @@ -40,13 +40,15 @@ struct sock_data { struct sock_data * start_ip_conflict_mon(void); void stop_ip_conflict_mon(); gboolean handle_ip_conflict_set_enable(Wifi *wifi, GDBusMethodInvocation *context, - bool detect); -gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation *context); + const gchar *ifname, bool detect); +gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, - guint initial_time); -gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation - *context); -gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context); + const gchar *ifname, guint initial_time); +gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); #ifdef __cplusplus diff --git a/include/netdbus.h b/include/netdbus.h index 9bce844..502f865 100755 --- a/include/netdbus.h +++ b/include/netdbus.h @@ -100,7 +100,7 @@ gboolean netconfig_is_bluetooth_profile(const char *profile); gboolean netconfig_invoke_dbus_method_nonblock(const char *dest, const char *path, const char *interface_name, const char *method, GVariant *params, - GAsyncReadyCallback notify_func); + GAsyncReadyCallback notify_func, void *user_data); GVariant *netconfig_invoke_dbus_method(const char *dest, const char *path, const char *interface_name, const char *method, GVariant *params); diff --git a/include/netsupplicant.h b/include/netsupplicant.h index 889a2d5..615ca88 100755 --- a/include/netsupplicant.h +++ b/include/netsupplicant.h @@ -49,7 +49,7 @@ char *netconfig_get_supplicant_interface(const char *ifname); /* Returns Supplicant interface. * Need to release interface using g_free */ -char *netconfig_wifi_get_supplicant_interface(void); +char *netconfig_wifi_get_supplicant_interface_path(const char *interface_name); /* Adhoc solution to use P2P interface */ char *netconfig_wifi_get_supplicant_p2p_interface(void); @@ -60,10 +60,10 @@ GVariant *netconfig_supplicant_invoke_dbus_method(const char *dest, const char * gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, const char *path, const char *interface_name, const char *method, GVariant *params, - GAsyncReadyCallback notify_func); -GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface, + GAsyncReadyCallback notify_func, void *user_data); +GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface_name, const char *key); -gboolean netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface, +gboolean netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface_name, const char *key, GVariant *message, GAsyncReadyCallback notify_func); diff --git a/include/network-state.h b/include/network-state.h index ee624d4..40853a0 100755 --- a/include/network-state.h +++ b/include/network-state.h @@ -36,9 +36,13 @@ unsigned int netconfig_get_default_frequency(void); const char *netconfig_wifi_get_connected_essid(const char *default_profile); gboolean netconfig_get_default_is_metered(void); +void netconfig_set_default_ipaddress(const char *ipaddr); +void netconfig_set_default_ipaddress6(const char *ipaddr); +void netconfig_set_default_proxy(const char *proxy); + void netconfig_update_default(void); -void netconfig_update_default_profile(const char *profile); -char *netconfig_get_ifname(const char *profile); +void netconfig_update_default_profile(void); +const char *netconfig_get_ifname(const char *profile); void state_object_create_and_init(void); void state_object_deinit(void); diff --git a/include/setting.h b/include/setting.h new file mode 100755 index 0000000..120370b --- /dev/null +++ b/include/setting.h @@ -0,0 +1,59 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __NETCONFIG_SETTING_H__ +#define __NETCONFIG_SETTING_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define NETCONFIG_SETTINGS_PATH "/var/lib/net-config/settings" +#define SETTINGS_WIFI_GROUP_NAME "Wifi" + +void netconfig_setting_init(void); +void netconfig_setting_deinit(void); + +int netconfig_setting_save(void); +int netconfig_setting_load(void); + +void netconfig_setting_update_interface_for_last_powered(const char *interface_name, + bool mode); +GSList *netconfig_setting_get_interfaces_for_last_powered(void); + +void netconfig_setting_update_interface_off_for_airplane(const char *interface_name, + bool mode); +GSList *netconfig_setting_get_interfaces_off_by_airplane(void); + +void netconfig_setting_update_interface_off_for_restricted(const char *interface_name, + bool mode); +GSList *netconfig_setting_get_interfaces_off_by_restricted(void); + +void netconfig_setting_update_interface_off_for_emergency(const char *interface_name, + bool mode); +GSList *netconfig_setting_get_interfaces_off_by_emergency(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_SETTING_H__ */ diff --git a/include/util.h b/include/util.h index 9a0442b..1dbc3b5 100755 --- a/include/util.h +++ b/include/util.h @@ -30,8 +30,11 @@ extern "C" { #include "wifi.h" #include "plugin.h" +#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) + #define NETCONFIG_TIZEN_SYSTEM_ENV "/run/tizen-system-env" +#define MAC_ADDRESS_MAX_LEN 18 #define MAX_SIZE_ERROR_BUFFER 256 #define ETHERNET_FEATURE "http://tizen.org/feature/network.ethernet" @@ -49,7 +52,9 @@ typedef enum { bool netconfig_check_feature_supported(netconfig_supported_feature_e feature); +gboolean netconfig_check_mac_address(const char *service, const char *mac_address); gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase); + GKeyFile *netconfig_keyfile_load(const char *pathname); void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname); diff --git a/include/wifi-agent.h b/include/wifi-agent.h index 7631cca..8fc7a14 100755 --- a/include/wifi-agent.h +++ b/include/wifi-agent.h @@ -29,7 +29,7 @@ extern "C" { gboolean connman_register_agent(void); gboolean connman_unregister_agent(void); -gboolean netconfig_wifi_set_agent_field_for_eap_network( +gboolean netconfig_wifi_set_agent_field_for_eap_network(const char *interface_name, const char *name, const char *identity, const char *passphrase); gboolean handle_set_field(NetConnmanAgent *connman_agent, diff --git a/include/wifi-background-scan.h b/include/wifi-background-scan.h index 2874927..412bf79 100755 --- a/include/wifi-background-scan.h +++ b/include/wifi-background-scan.h @@ -26,43 +26,22 @@ extern "C" { #include "wifi.h" -#if defined TIZEN_WEARABLE -#define SCAN_PERIODIC_DELAY 15 -#define SCAN_EXPONENTIAL_MIN 5 -#define SCAN_EXPONENTIAL_MAX 320 -#else -#define SCAN_PERIODIC_DELAY 10 -#define SCAN_EXPONENTIAL_MIN 4 -#define SCAN_EXPONENTIAL_MAX 128 -#endif - -enum { - WIFI_BGSCAN_MODE_EXPONENTIAL = 0x00, - WIFI_BGSCAN_MODE_PERIODIC, - WIFI_BGSCAN_MODE_MAX, -}; - -void netconfig_wifi_bgscan_start(gboolean immediate_scan); -void netconfig_wifi_bgscan_stop(void); -gboolean netconfig_wifi_get_bgscan_state(void); -guint netconfig_wifi_bgscan_get_mode(void); - -gboolean netconfig_wifi_get_scanning(void); -void netconfig_wifi_set_scanning(gboolean scanning); - -gboolean netconfig_wifi_block_bgscan(int status); -void netconfig_wifi_set_bgscan_pause(gboolean pause); -gboolean netconfig_wifi_bgscan_set_interval(guint interval); -void netconfig_wifi_bgscan_get_interval(guint *interval); -gboolean netconfig_wifi_is_bgscan_paused(void); - -gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, guint scan_mode); -gboolean handle_resume_bgscan(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_pause_bgscan(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_reset_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context); - -gboolean handle_get_autoscan(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_get_autoscanmode(Wifi *wifi, GDBusMethodInvocation *context); +void netconfig_wifi_bgscan_start(const char *interface_name, gboolean immediate_scan); +void netconfig_wifi_bgscan_stop(const char *interface_name); + +gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, guint scan_mode); +gboolean handle_resume_bgscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +gboolean handle_pause_bgscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +gboolean handle_reset_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); + +gboolean handle_get_autoscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +gboolean handle_get_autoscanmode(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); diff --git a/include/wifi-bssid-scan.h b/include/wifi-bssid-scan.h index 562da12..67cb243 100755 --- a/include/wifi-bssid-scan.h +++ b/include/wifi-bssid-scan.h @@ -26,13 +26,13 @@ extern "C" { #include "wifi.h" -gboolean netconfig_wifi_is_bssid_scan_started(void); +void netconfig_wifi_bssid_signal_scandone(const char *interface_name); +void netconfig_wifi_bssid_signal_scanaborted(const char *interface_name); -void netconfig_wifi_bssid_signal_scandone(void); -void netconfig_wifi_bssid_signal_scanaborted(void); - -gboolean handle_request_bssid_scan(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_get_bssid_list(Wifi *wifi, GDBusMethodInvocation *context); +gboolean handle_request_bssid_scan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +gboolean handle_get_bssid_list(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); #ifdef __cplusplus } diff --git a/include/wifi-config.h b/include/wifi-config.h index cbe1abe..bb6a47d 100755 --- a/include/wifi-config.h +++ b/include/wifi-config.h @@ -71,26 +71,40 @@ typedef enum { NETCONFIG_VSIE_FRAME_MAX } netconfig_vsie_frames_e; -gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id); -gboolean wifi_config_remove_configuration(const gchar *config_id); -gboolean wifi_config_save_configuration(const gchar *config_id, GKeyFile *keyfile); -gboolean wifi_config_get_group_name(const gchar *prefix, const gchar *config_id, gchar **group_name); +gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id); +gboolean wifi_config_remove_configuration(const gchar *interface_name, + const gchar *config_id); +gboolean wifi_config_save_configuration(const gchar *interface_name, + const gchar *config_id, GKeyFile *keyfile); +gboolean wifi_config_get_group_name(const gchar *prefix, + const gchar *interface_name, const gchar *config_id, gchar **group_name); int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len); int __netconfig_hex_to_byte(const char *hex); int __netconfig_hex_char_to_num(char c); -gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id); -gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id, GVariant *configuration); -gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id); -gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id, GVariant *configuration); -gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id); -gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id, const gchar *key, const gchar *value); -gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id); +gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id); +gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id, GVariant *configuration); +gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id); +gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id, GVariant *configuration); +gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id); +gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id, const gchar *key, const gchar *value); +gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id); -gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context, int frame_id, const gchar *vsie); -gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context, int frame_id); -gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context, int frame_id, const gchar *vsie); +gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, int frame_id, const gchar *vsie); +gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, int frame_id); +gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, int frame_id, const gchar *vsie); #ifdef __cplusplus } diff --git a/include/wifi-dpp.h b/include/wifi-dpp.h old mode 100644 new mode 100755 index 21fd355..8be62a5 --- a/include/wifi-dpp.h +++ b/include/wifi-dpp.h @@ -34,7 +34,7 @@ void netconfig_wifi_dpp_scan_peer_qr_event(GVariant *message); void netconfig_wifi_dpp_network_id_event(GVariant *message); void netconfig_wifi_dpp_conf_sent_event(GVariant *message); void netconfig_wifi_dpp_conf_received_event(GVariant *message); -void netconfig_wifi_dpp_conf_obj_event(GVariant *message); +void netconfig_wifi_dpp_conf_obj_event(const char *interface_name, GVariant *message); gboolean handle_dpp_enter_peer_uri(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info); gboolean handle_dpp_generate_uri(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info); diff --git a/include/wifi-extension.h b/include/wifi-extension.h index e434b51..2e5c1e4 100755 --- a/include/wifi-extension.h +++ b/include/wifi-extension.h @@ -24,7 +24,8 @@ extern "C" { #endif -gboolean handle_flush_bss(Wifi *wifi, GDBusMethodInvocation *context); +gboolean handle_flush_bss(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); #ifdef __cplusplus } diff --git a/include/wifi-firmware.h b/include/wifi-firmware.h index 059ee24..bef9542 100755 --- a/include/wifi-firmware.h +++ b/include/wifi-firmware.h @@ -34,10 +34,13 @@ enum netconfig_wifi_firmware { NETCONFIG_WIFI_SOFTAP = 0x03, }; -int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable); +int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, + const char *interface_name, gboolean enable); -gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device); -gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device); +gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, + const gchar *device, const gchar *ifname); +gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, + const gchar *device, const gchar *ifname); #ifdef __cplusplus } diff --git a/include/wifi-indicator.h b/include/wifi-indicator.h index 46e13e2..53355f5 100755 --- a/include/wifi-indicator.h +++ b/include/wifi-indicator.h @@ -28,8 +28,8 @@ int netconfig_wifi_get_rssi(void); unsigned int netconfig_wifi_get_freq(void); int netconfig_wifi_rssi_level(const int rssi_dbm); -void netconfig_wifi_indicator_start(void); -void netconfig_wifi_indicator_stop(void); +void netconfig_wifi_indicator_start(const char *interface_name); +void netconfig_wifi_indicator_stop(const char *interface_name); #ifdef __cplusplus } diff --git a/include/wifi-netlink-scan.h b/include/wifi-netlink-scan.h index c790392..a926dd2 100755 --- a/include/wifi-netlink-scan.h +++ b/include/wifi-netlink-scan.h @@ -77,8 +77,9 @@ typedef struct { struct nl_msg *msg; } netconfig_nl_global; -void __netconfig_notify_netlink_scan_done(void); -int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *params); +void __netconfig_notify_netlink_scan_done(const char *interface_name); +int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, GVariant *params); #ifdef __cplusplus } diff --git a/include/wifi-passpoint.h b/include/wifi-passpoint.h index 8c007cc..b781dc1 100755 --- a/include/wifi-passpoint.h +++ b/include/wifi-passpoint.h @@ -26,8 +26,8 @@ extern "C" { #include "wifi.h" -gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_set_passpoint(Wifi *wifi, GDBusMethodInvocation *context, gint enable); +gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ifname); +gboolean handle_set_passpoint(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ifname, gint enable); #ifdef __cplusplus } diff --git a/include/wifi-power.h b/include/wifi-power.h index 387a56c..d190f14 100755 --- a/include/wifi-power.h +++ b/include/wifi-power.h @@ -29,19 +29,20 @@ extern "C" { void wifi_power_initialize(void); void wifi_power_deinitialize(void); -int wifi_power_on(void); -int wifi_power_off(void); -void wifi_set_early_suspend(gboolean); +int wifi_power_on(const char *interface_name); +int wifi_power_off(const char *interface_name); +void wifi_set_early_suspend(const char *interface_name, gboolean value); #if defined TIZEN_WEARABLE -int wifi_power_on_wearable(gboolean device_picker_test); +int wifi_power_on_wearable(const char *interface_name, gboolean device_picker_test); #endif -int wifi_power_driver_and_supplicant(gboolean enable); -void wifi_power_disable_technology_state_by_only_connman_signal(void); -void wifi_power_recover_firmware(void); +int wifi_power_driver_and_supplicant(const char *interface_name, gboolean enable); +void wifi_power_recover_firmware(const char *interface_name); -gboolean handle_load_driver(Wifi *wifi, GDBusMethodInvocation *context, gboolean device_picker_test); -gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context); +gboolean handle_load_driver(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, gboolean device_picker_test); +gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); gboolean handle_load_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context); gboolean handle_remove_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context); diff --git a/include/wifi-scan.h b/include/wifi-scan.h new file mode 100755 index 0000000..9c5b090 --- /dev/null +++ b/include/wifi-scan.h @@ -0,0 +1,70 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __NETCONFIG_SCAN_H__ +#define __NETCONFIG_SCAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +#if defined TIZEN_WEARABLE +#define SCAN_PERIODIC_DELAY 15 +#define SCAN_EXPONENTIAL_MIN 5 +#define SCAN_EXPONENTIAL_MAX 320 +#else +#define SCAN_PERIODIC_DELAY 10 +#define SCAN_EXPONENTIAL_MIN 4 +#define SCAN_EXPONENTIAL_MAX 128 +#endif + +enum { + WIFI_BGSCAN_MODE_EXPONENTIAL = 0x00, + WIFI_BGSCAN_MODE_PERIODIC, + WIFI_BGSCAN_MODE_MAX, +}; + +void netconfig_wifi_scan_set_scanning(const char *interface_name, gboolean scanning); +guint netconfig_wifi_scan_get_scanning(const char *interface_name); + +gboolean netconfig_wifi_bgscan_set_mode(const char *interface_name, guint mode); +guint netconfig_wifi_bgscan_get_mode(const char *interface_name); +void netconfig_wifi_bgscan_set_timer_id(const char *interface_name, guint timer_id); +guint netconfig_wifi_bgscan_get_timer_id(const char *interface_name); +gboolean netconfig_wifi_bgscan_set_interval(const char *interface_name, guint interval); +guint netconfig_wifi_bgscan_get_interval(const char *interface_name); +void netconfig_wifi_bgscan_set_pause(const char *interface_name, gboolean pause); +gboolean netconfig_wifi_bgscan_is_paused(const char *interface_name); +void netconfig_wifi_bgscan_start_timer(const char *interface_name, gboolean immediate_scan); +void netconfig_wifi_bgscan_stop_timer(const char *interface_name); + +void netconfig_wifi_bssidscan_set_mode(const char *interface_name, gboolean enable); +gboolean netconfig_wifi_bssidscan_get_mode(const char *interface_name); +void netconfig_wifi_bssidscan_set_aborted(const char *interface_name, gboolean abort); +gboolean netconfig_wifi_bssidscan_get_aborted(const char *interface_name); +void netconfig_wifi_bssidscan_set_scanning(const char *interface_name, gboolean scanning); +guint netconfig_wifi_bssidscan_get_scanning(const char *interface_name); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_SCAN_H__ */ diff --git a/include/wifi-state.h b/include/wifi-state.h index ae39694..9f74014 100755 --- a/include/wifi-state.h +++ b/include/wifi-state.h @@ -44,41 +44,64 @@ typedef enum { NETCONFIG_WIFI_TECH_TETHERED = 0x05, } wifi_tech_state_e; -typedef struct { - void (*wifi_state_changed)(wifi_service_state_e, void *user_data); +typedef struct wifi_state_notifier{ + struct wifi_state_notifier *notifier; + char *service; + void (*wifi_state_changed)(struct wifi_state_notifier *, + char *, wifi_service_state_e, void *); void *user_data; -} wifi_state_notifier; +} wifi_state_notifier_s; + +typedef struct { + char *interface_name; + char *mac_address; + gboolean powered; + gboolean connected; + wifi_tech_state_e tech_state; + wifi_service_state_e service_state; +} wifi_device_data_s; + +char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type); +char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type); + +void wifi_state_update_power_state(const char *interface_name, gboolean powered); +void wifi_state_emit_power_completed(const char *interface_name, gboolean power_on); +void wifi_state_emit_power_failed(const char *interface_name); + +char *wifi_get_favorite_service(void); +void wifi_start_timer_network_notification(const char *interface_name); -#define VCONF_WIFI_LAST_POWER_STATE "file/private/wifi/last_power_state" +void wifi_state_notifier_register(wifi_state_notifier_s *notifier); +void wifi_state_notifier_unregister(wifi_state_notifier_s *notifier); +void wifi_state_notifier_cleanup(void); -void wifi_state_update_power_state(gboolean powered); -void wifi_state_emit_power_completed(gboolean power_on); -void wifi_state_emit_power_failed(void); +void wifi_state_set_bss_found(gboolean found); +gboolean wifi_state_is_bss_found(void); -char *wifi_get_favorite_service(void); -void wifi_start_timer_network_notification(void); +gboolean wifi_state_update_device_list(void); +GSList *wifi_state_get_device_list(void); -void wifi_state_notifier_register(wifi_state_notifier *notifier); -void wifi_state_notifier_unregister(wifi_state_notifier *notifier); -void wifi_state_notifier_cleanup(void); +void wifi_state_set_service_state(const char *interface_name, wifi_service_state_e new_state); +wifi_service_state_e wifi_state_get_service_state(const char *interface_name); -void wifi_state_set_bss_found(gboolean found); -gboolean wifi_state_is_bss_found(void); +void wifi_state_set_technology_state(const char *interface_name, wifi_tech_state_e new_state); +wifi_tech_state_e wifi_state_get_technology_state(const char *interface_name); -void wifi_state_set_service_state(wifi_service_state_e new_state); -wifi_service_state_e wifi_state_get_service_state(void); +void wifi_state_set_powered(const char *interface_name, gboolean powered); +gboolean wifi_state_get_powered(const char *interface_name); -void wifi_state_set_tech_state(wifi_tech_state_e new_state); -wifi_tech_state_e wifi_state_get_technology_state(bool mode); -gboolean wifi_state_is_technology_available(void); +void wifi_state_set_connected(const char *interface_name, gboolean connected); +gboolean wifi_state_get_connected(const char *interface_name); -void wifi_state_set_connected_essid(void); -void wifi_state_get_connected_essid(gchar **essid); +gboolean wifi_state_is_existed(const char *interface_name); +const char *wifi_state_get_interface_name(const char *mac_address); +const char *wifi_state_get_mac_address(const char *interface_name); -gboolean handle_get_wifi_state(Wifi *wifi, GDBusMethodInvocation *context); +void wifi_state_set_connected_essid(void); +void wifi_state_get_connected_essid(gchar **essid); -char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type); -char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type); +void wifi_state_initialize(void); +void wifi_state_deinitialize(void); #ifdef __cplusplus diff --git a/include/wifi-tdls.h b/include/wifi-tdls.h index 9301971..1cab9ab 100755 --- a/include/wifi-tdls.h +++ b/include/wifi-tdls.h @@ -36,18 +36,23 @@ typedef enum { NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH = 0x05, } netconfig_tdls_error_e; -void netconfig_wifi_tdls_peer_found_event(GVariant *message); -void netconfig_wifi_tdls_connected_event(GVariant *message); -void netconfig_wifi_tdls_disconnected_event(GVariant *message); +void netconfig_wifi_tdls_connected_event(const char *interface_name, GVariant *message); +void netconfig_wifi_tdls_disconnected_event(const char *interface_name, GVariant *message); +void netconfig_wifi_tdls_peer_found_event(const char *interface_name, GVariant *message); + void __netconfig_wifi_notify_tdls_connected_event(const char *peer_mac); -gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_addr); -gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_Addr); -gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_Addr); +gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, gchar *peer_mac_addr); +gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, gchar *peer_mac_Addr); +gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, gchar *peer_mac_Addr); gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context, - gchar *peer_mac_Addr, int freq); + const gchar *ifname, gchar *peer_mac_Addr, int freq); gboolean handle_tdls_cancel_channel_switch(Wifi *wifi, GDBusMethodInvocation *context, - gchar *peer_mac_Addr); + const gchar *ifname, gchar *peer_mac_Addr); diff --git a/include/wifi-wps.h b/include/wifi-wps.h index aaa3d6e..81caee4 100755 --- a/include/wifi-wps.h +++ b/include/wifi-wps.h @@ -32,12 +32,16 @@ extern "C" { #define WPS_EI_NO_ERROR 0 #define WPS_EI_OPERATION_FAILED 1 -gboolean handle_request_wps_connect(Wifi *wifi, GDBusMethodInvocation *context, gchar *param); -gboolean handle_request_wps_cancel(Wifi *wifi, GDBusMethodInvocation *context); -void netconfig_wifi_notify_wps_completed(const char *ssid, gsize ssid_len); -void netconfig_wifi_notify_wps_fail_event(int config_error, int error_indication); -void netconfig_wifi_notify_wps_credentials(const char *ssid, gsize ssid_len, const char *wps_key); -gboolean netconfig_get_wps_field(); +gboolean handle_request_wps_connect(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, gchar *param); +gboolean handle_request_wps_cancel(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname); +void netconfig_wifi_notify_wps_completed(const char *interface_name, + const char *ssid, gsize ssid_len); +void netconfig_wifi_notify_wps_fail_event(const char *interface_name, + int config_error, int error_indication); +void netconfig_wifi_notify_wps_credentials(const char *interface_name, + const char *ssid, gsize ssid_len, const char *wps_key); gboolean netconfig_wifi_wps_connect(); #ifdef __cplusplus diff --git a/interfaces/netconfig-iface-wifi.xml b/interfaces/netconfig-iface-wifi.xml index 75ed86b..32d148a 100755 --- a/interfaces/netconfig-iface-wifi.xml +++ b/interfaces/netconfig-iface-wifi.xml @@ -2,11 +2,14 @@ + + + @@ -18,69 +21,91 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -101,6 +126,7 @@ + @@ -134,38 +160,47 @@ + - + - + + + - + + - + - - - + + + + - - + + + + + + @@ -206,21 +241,34 @@ - - - + + + + + + + + + + + + + + + + diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 1f0f48e..bd5d146 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.1.155 +Version: 1.2.0 Release: 3 Group: System/Network License: Apache-2.0 @@ -130,6 +130,10 @@ make %{?_smp_mflags} %install %make_install +#Settings file +mkdir -p %{buildroot}/%{_localstatedir}/lib/net-config +cp resources/var/lib/net-config/settings %{buildroot}/%{_localstatedir}/lib/net-config/settings + #Systemd service file mkdir -p %{buildroot}%{_unitdir} @@ -201,6 +205,7 @@ chown network_fw:network_fw /opt/usr/data/network %attr(644,root,root) /usr/lib/tmpfiles.d/security-network-config.conf %attr(644,root,root) %{_unitdir}/net-config.service %attr(644,root,root) %{_unitdir}/multi-user.target.wants/net-config.service +%attr(644,root,root) /var/lib/net-config/settings %license LICENSE %attr(750,network_fw,network_fw) /opt/etc/dump.d/module.d/network_dump.sh %attr(750,network_fw,network_fw) /opt/var/lib/net-config/network_dump.sh diff --git a/resources/var/lib/net-config/settings b/resources/var/lib/net-config/settings new file mode 100644 index 0000000..bc65ed9 --- /dev/null +++ b/resources/var/lib/net-config/settings @@ -0,0 +1,5 @@ +[Wifi] +LastPoweredInterfaces= +WifiOffByAirplaneInterfaces= +WifiOffByRestrictedInterfaces= +WifiOffByEmergencyInterfaces= diff --git a/src/clatd-handler.c b/src/clatd-handler.c index 814504b..570092f 100755 --- a/src/clatd-handler.c +++ b/src/clatd-handler.c @@ -106,7 +106,8 @@ int netconfig_clatd_enable(void) g_variant_builder_unref(builder); rv = netconfig_invoke_dbus_method_nonblock(CLATD_SERVICE, CLATD_PATH, - CLATD_INTERFACE, "Start", g_variant_new("(@a{is})", params), __netconfig_clatd_async_callback); + CLATD_INTERFACE, "Start", g_variant_new("(@a{is})", params), + __netconfig_clatd_async_callback, NULL); if (!rv) { DBG("Failed to dbus call"); @@ -137,7 +138,7 @@ int netconfig_clatd_disable(void) } rv = netconfig_invoke_dbus_method_nonblock(CLATD_SERVICE, CLATD_PATH, - CLATD_INTERFACE, "Stop", NULL, NULL); + CLATD_INTERFACE, "Stop", NULL, NULL, NULL); g_is_running = FALSE; DBG("clatd disabled[%d]", g_is_running); if (!rv) { diff --git a/src/dbus/netdbus.c b/src/dbus/netdbus.c index 2abc159..4e06230 100755 --- a/src/dbus/netdbus.c +++ b/src/dbus/netdbus.c @@ -186,7 +186,7 @@ gboolean netconfig_is_bluetooth_profile(const char *profile) gboolean netconfig_invoke_dbus_method_nonblock(const char *dest, const char *path, const char *interface_name, const char *method, GVariant *params, - GAsyncReadyCallback notify_func) + GAsyncReadyCallback notify_func, void *user_data) { GDBusConnection *connection = NULL; @@ -209,7 +209,7 @@ gboolean netconfig_invoke_dbus_method_nonblock(const char *dest, const char *pat NETCONFIG_DBUS_REPLY_TIMEOUT, netdbus_get_cancellable(), (GAsyncReadyCallback) notify_func, - NULL); + user_data); if (notify_func) netconfig_gdbus_pending_call_ref(); diff --git a/src/dbus/netsupplicant.c b/src/dbus/netsupplicant.c index ee52eec..a6f59fd 100755 --- a/src/dbus/netsupplicant.c +++ b/src/dbus/netsupplicant.c @@ -48,9 +48,10 @@ char *netconfig_get_supplicant_interface(const char *ifname) return (char *)path; } -char *netconfig_wifi_get_supplicant_interface(void) +char *netconfig_wifi_get_supplicant_interface_path(const char *interface_name) { - return netconfig_get_supplicant_interface(WIFI_IFNAME); + const char *ifname = interface_name ? interface_name : WIFI_IFNAME; + return netconfig_get_supplicant_interface(ifname); } char *netconfig_wifi_get_supplicant_p2p_interface(void) @@ -81,7 +82,8 @@ GVariant *netconfig_supplicant_invoke_dbus_method(const char *dest, const char * GVariant *reply = NULL; GDBusConnection *connection = NULL; - INFO("[DBUS Sync] %s %s %s", interface_name, method, path); + if (g_strcmp0(method, "GetInterface") != 0) + INFO("[DBUS Sync] %s %s %s", interface_name, method, path); connection = netdbus_get_connection(); if (connection == NULL) { @@ -120,7 +122,7 @@ GVariant *netconfig_supplicant_invoke_dbus_method(const char *dest, const char * gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, const char *path, const char *interface_name, const char *method, GVariant *params, - GAsyncReadyCallback notify_func) + GAsyncReadyCallback notify_func, void *user_data) { GDBusConnection *connection = NULL; @@ -143,7 +145,7 @@ gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, NETCONFIG_DBUS_REPLY_TIMEOUT, netdbus_get_cancellable(), (GAsyncReadyCallback) notify_func, - NULL); + user_data); if (notify_func) netconfig_gdbus_pending_call_ref(); @@ -151,7 +153,7 @@ gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, return TRUE; } -GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface, +GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface_name, const char *key) { GVariant *params = NULL; @@ -160,13 +162,13 @@ GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *in ERR("[GDBUS] property_get : %s", key); - path = netconfig_wifi_get_supplicant_interface(); + path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (path == NULL) { DBG("Failed to get wpa_supplicant DBus path"); return NULL; } - params = g_variant_new("(ss)", interface, key); + params = g_variant_new("(ss)", SUPPLICANT_IFACE_INTERFACE, key); reply = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE, path, @@ -183,7 +185,7 @@ GVariant *netconfig_supplicant_invoke_dbus_interface_property_get(const char *in return reply; } -gboolean netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface, +gboolean netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface_name, const char *key, GVariant *var, GAsyncReadyCallback notify_func) { @@ -193,19 +195,20 @@ gboolean netconfig_supplicant_invoke_dbus_interface_property_set(const char *int DBG("[DBUS] property_set : %s", key); - path = netconfig_wifi_get_supplicant_interface(); + path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (path == NULL) { ERR("Failed to get wpa_supplicant DBus path"); return result; } - message = g_variant_new("(ssv)", interface, key, var); + message = g_variant_new("(ssv)", SUPPLICANT_IFACE_INTERFACE, key, var); result = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE, path, DBUS_INTERFACE_PROPERTIES, "Set", message, - notify_func); + notify_func, + NULL); g_free(path); if (result == FALSE) { diff --git a/src/ip-conflict-detect.c b/src/ip-conflict-detect.c index d84a390..4e15614 100755 --- a/src/ip-conflict-detect.c +++ b/src/ip-conflict-detect.c @@ -34,6 +34,7 @@ #include #include +#include "netdbus.h" #include "ip-conflict-detect.h" #include "network-state.h" #include "log.h" @@ -95,8 +96,10 @@ static struct timer_data td = { int ioctl_sock; static bool initial_bursts = true; bool is_ip_conflict_detect_enabled = false; +bool is_ip_conflict_detect_running = false; static gboolean send_arp(gpointer data); -static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac); +static void __netconfig_wifi_notify_ip_conflict(const char *interface_name, + char *state, char *mac); ip_conflict_state_e conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED; struct sock_data *sd; @@ -132,7 +135,8 @@ static gboolean __arp_reply_timeout_cb(gpointer data) sd->iteration == CONFLICT_REMOVE_ITERATION_LIMIT) { sd->iteration = 0; conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED; - __netconfig_wifi_notify_ip_conflict("resolved", GRATUITOUS_ARP_MAC_ADDR); + __netconfig_wifi_notify_ip_conflict(netconfig_get_default_ifname(), + "resolved", GRATUITOUS_ARP_MAC_ADDR); initial_bursts = true; } @@ -178,13 +182,13 @@ static gboolean __netconfig_check_arp_receive(GIOChannel *source, int zero_mac = strcmp(tbuf , GRATUITOUS_ARP_MAC_ADDR); if (zero_mac == 0) { - DBG("Broadcast packet.\n"); + DBG("Broadcast packet."); goto skip; } DBG("our mac= %s source mac= %s target mac= %s", netconfig_get_default_mac_address(), sbuf, tbuf); mac_cmp = strcmp(tbuf , netconfig_get_default_mac_address()); if (mac_cmp != 0) { - INFO("Packet not intended to us.\n"); + INFO("Packet not intended to us."); goto out; } skip: @@ -193,9 +197,11 @@ skip: if ((mac_cmp != 0) && (__convert_uchar_to_uint(arp_recv.s_IPaddr) == target_ip)) { sd->iteration = 0; if (conflict_state != NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED) { - INFO("ip conflict is detected !\n"); + INFO("ip conflict is detected !"); conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED; - __netconfig_wifi_notify_ip_conflict("conflict", sbuf); + __netconfig_wifi_notify_ip_conflict( + netconfig_get_default_ifname(), + "conflict", sbuf); sd->timeout = BURST_ARP_SEND_TIME; } @@ -233,7 +239,7 @@ static int __open_channel_and_sock(struct sock_data *sd) return -1; if ((sd->chk_conflict_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) == -1) { - INFO("socket Failed.\n"); + INFO("socket Failed."); return -1; } @@ -336,7 +342,7 @@ static gboolean send_arp(gpointer data) } if (ioctl(sd->chk_conflict_sd, SIOCGIFINDEX, &net_ifr) == -1) { - INFO("ioctl Failed. Error..... = %s\n", + INFO("ioctl Failed. Error..... = %s", strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER)); goto err; } @@ -351,14 +357,14 @@ static gboolean send_arp(gpointer data) if (sendto(sd->chk_conflict_sd, &arp, sizeof(arp), 0, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - INFO("Sending ARP Packet Failed. Error. = %s\n", + INFO("Sending ARP Packet Failed. Error. = %s", strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER)); __close_channel_and_sock(sd); if (__open_channel_and_sock(sd) == -1) INFO("__open_channel_and_sock failed"); goto err; } else { - DBG("Sent ARP Packet \n"); + /* DBG("Sent ARP Packet"); */ } if (sd->timer_id) { @@ -384,7 +390,12 @@ err: struct sock_data * start_ip_conflict_mon(void) { - if (is_ip_conflict_detect_enabled == true) { + if (is_ip_conflict_detect_enabled == false) { + INFO("ip_conflict_detect is disabled"); + return NULL; + } + + if (is_ip_conflict_detect_running == true) { INFO("detection mode is set to true"); return NULL; } @@ -408,7 +419,7 @@ struct sock_data * start_ip_conflict_mon(void) sd->timeout = td.initial_time; send_arp(sd); - is_ip_conflict_detect_enabled = true; + is_ip_conflict_detect_running = true; conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED; return sd; @@ -430,12 +441,13 @@ void stop_ip_conflict_mon() } g_free(sd); sd = NULL; - is_ip_conflict_detect_enabled = false; + is_ip_conflict_detect_running = false; conflict_state = NETCONFIG_IP_CONFLICT_STATE_UNKNOWN; INFO("Monitoring stopped"); } -static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac) +static void __netconfig_wifi_notify_ip_conflict(const char *interface_name, + char *state, char *mac) { GVariantBuilder *builder = NULL; @@ -443,7 +455,8 @@ static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac) g_variant_builder_add(builder, "{sv}", "state", g_variant_new_string(state)); g_variant_builder_add(builder, "{sv}", "mac", g_variant_new_string(mac)); - wifi_emit_ip_conflict_event((Wifi *)get_wifi_object(), g_variant_builder_end(builder)); + wifi_emit_ip_conflict_event((Wifi *)get_wifi_object(), + interface_name, g_variant_builder_end(builder)); g_variant_builder_unref(builder); /* send notification using net-popup */ @@ -456,24 +469,30 @@ static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac) } gboolean handle_ip_conflict_set_enable(Wifi *wifi, GDBusMethodInvocation *context, - bool detect) + const gchar *ifname, bool detect) { g_return_val_if_fail(wifi != NULL, TRUE); if (detect == false) { - if (sd != NULL) + if (is_ip_conflict_detect_enabled == true) { stop_ip_conflict_mon(); - else { + is_ip_conflict_detect_enabled = false; + } else { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AlreadyExists"); return TRUE; } } else { - if (sd == NULL) { - if (start_ip_conflict_mon() == NULL) { - INFO("Failed to start IP conflict monitoring"); - netconfig_error_dbus_method_return(context, - NETCONFIG_ERROR_INTERNAL, "Failed"); - return TRUE; + if (is_ip_conflict_detect_enabled == false) { + is_ip_conflict_detect_enabled = true; + const char *def_profile = netconfig_get_default_profile(); + if (netconfig_is_wifi_profile(def_profile) || + netconfig_is_ethernet_profile(def_profile)) { + if (start_ip_conflict_mon() == NULL) { + INFO("Failed to start IP conflict monitoring"); + netconfig_error_dbus_method_return(context, + NETCONFIG_ERROR_INTERNAL, "Failed"); + return TRUE; + } } } else { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AlreadyExists"); @@ -485,7 +504,8 @@ gboolean handle_ip_conflict_set_enable(Wifi *wifi, GDBusMethodInvocation *contex return TRUE; } -gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { g_return_val_if_fail(wifi != NULL, TRUE); GVariant *param = NULL; @@ -494,7 +514,8 @@ gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation return TRUE; } -gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, guint initial_time) +gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, guint initial_time) { g_return_val_if_fail(wifi != NULL, TRUE); INFO("%d", initial_time); @@ -512,7 +533,8 @@ gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *contex return TRUE; } -gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { g_return_val_if_fail(wifi != NULL, TRUE); GVariant *param = NULL; @@ -521,7 +543,8 @@ gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation *context return TRUE; } -gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { g_return_val_if_fail(wifi != NULL, TRUE); GVariant *param = NULL; diff --git a/src/main.c b/src/main.c index ba0c6d5..3753fdf 100755 --- a/src/main.c +++ b/src/main.c @@ -26,6 +26,7 @@ #include "log.h" #include "util.h" #include "wifi.h" +#include "setting.h" #include "netdbus.h" #include "emulator.h" #include "neterror.h" @@ -126,6 +127,8 @@ int main(int argc, char *argv[]) return 0; } + netconfig_setting_init(); + netconfig_error_init(); if (TIZEN_NTP_ENABLE) @@ -170,6 +173,8 @@ int main(int argc, char *argv[]) netconfig_dpm_deinit(); + netconfig_setting_deinit(); + if (TIZEN_NTP_ENABLE) netconfig_clock_deinit(); diff --git a/src/network-dpm.c b/src/network-dpm.c index 3b45d13..fcf914f 100755 --- a/src/network-dpm.c +++ b/src/network-dpm.c @@ -24,6 +24,7 @@ #include "util.h" #include "netdbus.h" #include "wifi-power.h" +#include "wifi-state.h" #include "network-dpm.h" #include "network-state.h" @@ -90,29 +91,31 @@ void netconfig_dpm_deinit(void) int netconfig_dpm_update_from_wifi(void) { + GSList *list = wifi_state_get_device_list(); + INFO("DPM update from wifi [%d]", dpm_policy_wifi); if (!dpm_policy_wifi) { - int wifi_state = 0; - vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); - if (wifi_state != VCONFKEY_WIFI_OFF) { - int err = wifi_power_off(); - if (err < 0) { - if (err == -EINPROGRESS) - ERR("wifi power off : InProgress"); - else if (err == -EALREADY) - ERR("wifi power off : AlreadyExists"); - else if (err == -EPERM) - ERR("wifi power off : PermissionDenied"); - else - ERR("wifi power off : WifiDriverFailed"); - } else - DBG("wifi power off : ErrorNone"); - - netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_OFF_BY_AIRPLANE, 0); - netconfig_send_restriction_to_net_popup("Wi-Fi unavailable", - "toast_popup", "wifi"); + for ( ; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + if (device_data->powered == TRUE) { + int err = wifi_power_off(device_data->interface_name); + if (err < 0) { + if (err == -EINPROGRESS) + ERR("wifi power off : InProgress"); + else if (err == -EALREADY) + ERR("wifi power off : AlreadyExists"); + else if (err == -EPERM) + ERR("wifi power off : PermissionDenied"); + else + ERR("wifi power off : WifiDriverFailed"); + } else + DBG("wifi power off : ErrorNone"); + } } + + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_OFF_BY_AIRPLANE, 0); + netconfig_send_restriction_to_net_popup("Wi-Fi unavailable", "toast_popup", "wifi"); } return dpm_policy_wifi; diff --git a/src/network-state.c b/src/network-state.c index dfdc8c0..79ca912 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -139,43 +139,6 @@ static gboolean __netconfig_is_connected(GVariantIter *array) return is_connected; } -static char *__netconfig_get_default_profile(void) -{ - GVariant *message = NULL; - GVariantIter *iter; - GVariantIter *next; - gchar *default_profile = NULL; - gchar *object_path; - - message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, - CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, - "GetServices", NULL); - if (message == NULL) { - ERR("Failed to get profiles"); - return NULL; - } - - g_variant_get(message, "(a(oa{sv}))", &iter); - while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) { - if (object_path == NULL) - continue; - - if (netconfig_is_cellular_profile(object_path) && !netconfig_is_cellular_internet_profile(object_path)) - continue; - - if (__netconfig_is_connected(next) == TRUE) { - default_profile = g_strdup(object_path); - g_free(object_path); - g_variant_iter_free(next); - break; - } - } - g_variant_iter_free(iter); - g_variant_unref(message); - - return default_profile; -} - static int __netconfig_telephony_get_modem_object_path(GSList **modem_path_list) { GVariant *result; @@ -362,56 +325,136 @@ static gboolean __netconfig_telephony_get_metered_info(net_profile_name_t* pdp_n return ret; } -static void __netconfig_get_default_connection_info(const char *profile) +static int __netconfig_reset_ipv4_socket(const char *interface_name) +{ + int ret; + int fd; + struct ifreq ifr; + struct sockaddr_in sai; + const char *ipaddr = netconfig_get_default_ipaddress(); + DBG("ipaddr-[%s]", ipaddr); + + if (!ipaddr) + return -1; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + return -1; + + memset(&sai, 0, sizeof(struct sockaddr_in)); + sai.sin_family = AF_INET; + sai.sin_port = 0; + if (!inet_aton(ipaddr, &sai.sin_addr)) { + DBG("fail to inet_aton()"); + close(fd); + return -1; + } + + memset(&ifr, 0, sizeof(struct ifreq)); + memcpy(&ifr.ifr_addr, &sai, sizeof(sai)); + g_strlcpy((char *)ifr.ifr_name, interface_name, IFNAMSIZ); + +#ifndef SIOCKILLADDR +#define SIOCKILLADDR 0x8939 +#endif + + ret = ioctl(fd, SIOCKILLADDR, &ifr); + if (ret < 0) { + DBG("fail to ioctl[SIOCKILLADDR]"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +static void __netconfig_clear_default_connection_info(void) +{ + static char *old_profile = NULL; + + if (netconfig_default_connection_info.profile != NULL) { + + if (netconfig_is_wifi_profile(netconfig_default_connection_info.profile)) + __netconfig_reset_ipv4_socket(netconfig_default_connection_info.ifname); + + g_free(old_profile); + old_profile = strdup(netconfig_default_connection_info.profile); + + g_free(netconfig_default_connection_info.profile); + netconfig_default_connection_info.profile = NULL; + + g_free(netconfig_default_connection_info.ifname); + netconfig_default_connection_info.ifname = NULL; + + g_free(netconfig_default_connection_info.ipaddress); + netconfig_default_connection_info.ipaddress = NULL; + + g_free(netconfig_default_connection_info.ipaddress6); + netconfig_default_connection_info.ipaddress6 = NULL; + + g_free(netconfig_default_connection_info.proxy); + netconfig_default_connection_info.proxy = NULL; + + g_free(netconfig_default_connection_info.mac_address); + netconfig_default_connection_info.mac_address = NULL; + + netconfig_default_connection_info.freq = 0; + netconfig_default_connection_info.is_metered = FALSE; + + g_free(netconfig_default_connection_info.essid); + netconfig_default_connection_info.essid = NULL; + } +} + +static gboolean __netconfig_get_default_connection_info(void) { GVariant *message = NULL, *variant = NULL, *variant2 = NULL; - GVariantIter *iter = NULL, *iter1 = NULL, *service = NULL; - GVariant *next = NULL; + GVariantIter *iter = NULL, *iter1 = NULL; + GVariant *var = NULL; gchar *obj_path; gchar *key = NULL; gchar *key1 = NULL; gchar *key2 = NULL; - gboolean found_profile = 0; message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, - "GetServices", NULL); + "GetDefaultService", NULL); if (message == NULL) { ERR("Failed to get services informations"); - goto done; + return FALSE; } - g_variant_get(message, "(a(oa{sv}))", &service); - if (service == NULL) { - ERR("Failed to get services iter"); - goto done; + if (!g_variant_is_of_type(message, G_VARIANT_TYPE("(oa{sv})"))) { + DBG("There is no default service"); + g_variant_unref(message); + return FALSE; } - while (g_variant_iter_loop(service, "(oa{sv})", &obj_path, &iter)) { - if (g_strcmp0(obj_path, profile) == 0) { - g_free(obj_path); - found_profile = 1; - break; - } - } + g_variant_get(message, "(oa{sv})", &obj_path, &iter); - if (iter == NULL || found_profile == 0) { - ERR("Profile %s doesn't exist", profile); - goto done; + if (g_strcmp0(obj_path, netconfig_default_connection_info.profile) == 0) { + g_variant_unref(message); + g_variant_iter_free(iter); + return FALSE; } - while (g_variant_iter_loop(iter, "{sv}", &key, &next)) { + __netconfig_clear_default_connection_info(); + + netconfig_default_connection_info.profile = g_strdup(obj_path); + + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { const gchar *value = NULL; guint16 freq = 0; if (g_strcmp0(key, "Name") == 0 && - netconfig_is_wifi_profile(profile) == TRUE) { - if (g_variant_is_of_type(next, G_VARIANT_TYPE_STRING)) { - value = g_variant_get_string(next, NULL); + netconfig_is_wifi_profile(obj_path) == TRUE) { + if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) { + value = g_variant_get_string(var, NULL); netconfig_default_connection_info.essid = g_strdup(value); } } else if (g_strcmp0(key, "Ethernet") == 0) { - g_variant_get(next, "a{sv}", &iter1); + g_variant_get(var, "a{sv}", &iter1); if (iter1 == NULL) continue; while (g_variant_iter_loop(iter1, "{sv}", &key1, &variant)) { @@ -425,7 +468,7 @@ static void __netconfig_get_default_connection_info(const char *profile) } g_variant_iter_free(iter1); } else if (g_strcmp0(key, "IPv4") == 0) { - g_variant_get(next, "a{sv}", &iter1); + g_variant_get(var, "a{sv}", &iter1); if (iter1 == NULL) continue; while (g_variant_iter_loop(iter1, "{sv}", &key1, &variant)) { @@ -436,7 +479,7 @@ static void __netconfig_get_default_connection_info(const char *profile) } g_variant_iter_free(iter1); } else if (g_strcmp0(key, "IPv6") == 0) { - g_variant_get(next, "a{sv}", &iter1); + g_variant_get(var, "a{sv}", &iter1); if (iter1 == NULL) continue; while (g_variant_iter_loop(iter1, "{sv}", &key1, &variant)) { @@ -448,7 +491,7 @@ static void __netconfig_get_default_connection_info(const char *profile) g_variant_iter_free(iter1); } else if (g_strcmp0(key, "Proxy") == 0) { - g_variant_get(next, "a{sv}", &iter1); + g_variant_get(var, "a{sv}", &iter1); if (iter1 == NULL) continue; while (g_variant_iter_loop(iter1, "{sv}", &key2, &variant2)) { @@ -486,34 +529,27 @@ static void __netconfig_get_default_connection_info(const char *profile) } g_variant_iter_free(iter1); } else if (g_strcmp0(key, "Frequency") == 0) { - if (g_variant_is_of_type(next, G_VARIANT_TYPE_UINT16)) { - freq = g_variant_get_uint16(next); + if (g_variant_is_of_type(var, G_VARIANT_TYPE_UINT16)) { + freq = g_variant_get_uint16(var); netconfig_default_connection_info.freq = freq; } } } - if (netconfig_is_cellular_profile(profile) == TRUE) { + if (netconfig_is_cellular_profile(obj_path) == TRUE) { net_profile_name_t pdp_name; int ret; - ret = __netconfig_telephony_search_pdp_profile(profile, &pdp_name); + ret = __netconfig_telephony_search_pdp_profile(obj_path, &pdp_name); if (ret >= 0 && strlen(pdp_name.profile_name) > 0) if (__netconfig_telephony_get_metered_info(&pdp_name)) netconfig_default_connection_info.is_metered = TRUE; } -done: - if (message) - g_variant_unref(message); - - if (iter) - g_variant_iter_free(iter); - - if (service) - g_variant_iter_free(service); + g_variant_unref(message); + g_variant_iter_free(iter); - return; + return TRUE; } static char *__netconfig_get_preferred_ipv6_address(char *profile) @@ -964,73 +1000,6 @@ done: return ret; } -static void __netconfig_update_if_service_connected(void) -{ - GVariant *message = NULL, *var; - GVariantIter *iter, *next; - gchar *path; - gchar *key; - - message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, - CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, - "GetServices", NULL); - - if (message == NULL) { - ERR("Failed to get services"); - return; - } - - g_variant_get(message, "(a(oa{sv}))", &iter); - while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) { - if (path == NULL) - continue; - - if (g_str_has_prefix(path, - CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE) { - if (g_strrstr(path + strlen(CONNMAN_WIFI_SERVICE_PROFILE_PREFIX), - "hidden") != NULL) { - /* skip hidden profiles */ - continue; - } - /* Process this */ - } else if (g_str_has_prefix(path, - CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE) { - /* Process this */ - } else if (g_str_has_prefix(path, - CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE) { - /* Process this */ - } else { - continue; - } - - while (g_variant_iter_loop(next, "{sv}", &key, &var)) { - if (g_strcmp0(key, "State") == 0) { - const gchar *sdata = NULL; - sdata = g_variant_get_string(var, NULL); - DBG("%s [%s: %s]", path, key, sdata); - - if (g_strcmp0(sdata, "online") == 0 || g_strcmp0(sdata, "ready") == 0) { - - /* Found a connected WiFi / 3G service. - * Lets update the default profile info. - */ - netconfig_update_default_profile((const gchar*)path); - g_free(key); - g_free(path); - g_variant_unref(var); - g_variant_iter_free(next); - goto done; - } - } - } - } -done: - g_variant_iter_free(iter); - g_variant_unref(message); - - return; -} - static void __netconfig_network_notify_result(const char *sig_name, const char *key) { GVariantBuilder *builder; @@ -1053,6 +1022,32 @@ static void __netconfig_network_notify_result(const char *sig_name, const char * return; } +static char *__netconfig_get_mac_address(const char *profile) +{ + char mac_str[MAC_ADDRESS_MAX_LEN] = { 0, }; + const char *orgin = NULL; + int org_index, dst_index; + int i; + + org_index = strlen(CONNMAN_WIFI_SERVICE_PROFILE_PREFIX); + dst_index = 0; + + for (i = 0; i < 6; i++) { + orgin = &profile[org_index]; + + memcpy(&mac_str[dst_index], orgin, 2); + if (i < 5) + mac_str[dst_index + 2] = ':'; + else + mac_str[dst_index + 2] = '\0'; + + org_index += 2; + dst_index += 3; + } + + return g_strdup(mac_str); +} + const char *netconfig_get_default_profile(void) { return netconfig_default_connection_info.profile; @@ -1068,6 +1063,7 @@ const char *netconfig_get_default_ipaddress(void) return netconfig_default_connection_info.ipaddress; } + const char *netconfig_get_default_ipaddress6(void) { return netconfig_default_connection_info.ipaddress6; @@ -1107,187 +1103,44 @@ gboolean netconfig_get_default_is_metered(void) return netconfig_default_connection_info.is_metered; } -static int __netconfig_reset_ipv4_socket(void) +void netconfig_set_default_ipaddress(const char *ipaddr) { - int ret; - int fd; - struct ifreq ifr; - struct sockaddr_in sai; - const char *ipaddr = netconfig_get_default_ipaddress(); - DBG("ipaddr-[%s]", ipaddr); - - if (!ipaddr) - return -1; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) - return -1; - - memset(&sai, 0, sizeof(struct sockaddr_in)); - sai.sin_family = AF_INET; - sai.sin_port = 0; - if (!inet_aton(ipaddr, &sai.sin_addr)) { - DBG("fail to inet_aton()"); - close(fd); - return -1; - } - - memset(&ifr, 0, sizeof(struct ifreq)); - memcpy(&ifr.ifr_addr, &sai, sizeof(sai)); - g_strlcpy((char *)ifr.ifr_name, WIFI_IFNAME, IFNAMSIZ); - -#ifndef SIOCKILLADDR -#define SIOCKILLADDR 0x8939 -#endif - - ret = ioctl(fd, SIOCKILLADDR, &ifr); - if (ret < 0) { - DBG("fail to ioctl[SIOCKILLADDR]"); - close(fd); - return -1; - } - - close(fd); - return 0; + netconfig_default_connection_info.ipaddress = g_strdup(ipaddr); } -void netconfig_update_default_profile(const char *profile) +void netconfig_set_default_ipaddress6(const char *ipaddr) { - static char *old_profile = NULL; - - /* It's automatically updated by signal-handler - * DO NOT update manually - * - * It is going to update default connection information - */ - - if (netconfig_default_connection_info.profile != NULL) { - - if (netconfig_is_wifi_profile(netconfig_default_connection_info.profile)) - __netconfig_reset_ipv4_socket(); - - g_free(old_profile); - old_profile = strdup(netconfig_default_connection_info.profile); - - g_free(netconfig_default_connection_info.profile); - netconfig_default_connection_info.profile = NULL; - - g_free(netconfig_default_connection_info.ifname); - netconfig_default_connection_info.ifname = NULL; - - g_free(netconfig_default_connection_info.ipaddress); - netconfig_default_connection_info.ipaddress = NULL; - - g_free(netconfig_default_connection_info.ipaddress6); - netconfig_default_connection_info.ipaddress6 = NULL; - - g_free(netconfig_default_connection_info.proxy); - netconfig_default_connection_info.proxy = NULL; - - g_free(netconfig_default_connection_info.mac_address); - netconfig_default_connection_info.mac_address = NULL; - - netconfig_default_connection_info.freq = 0; - netconfig_default_connection_info.is_metered = FALSE; - - g_free(netconfig_default_connection_info.essid); - netconfig_default_connection_info.essid = NULL; - } - - /* default profile is NULL and new connected profile is NULL */ - if (!profile) { - char *tmp_profile = __netconfig_get_default_profile(); - - if (tmp_profile && netconfig_is_cellular_profile(tmp_profile) && - !netconfig_is_cellular_internet_profile(tmp_profile)) { - DBG("not a default cellular profile"); - g_free(tmp_profile); - tmp_profile = NULL; - } + netconfig_default_connection_info.ipaddress6 = g_strdup(ipaddr); +} - if (!tmp_profile) { - __netconfig_update_default_connection_info(); - return; - } +void netconfig_set_default_proxy(const char *proxy) +{ + netconfig_default_connection_info.proxy = g_strdup(proxy); +} - netconfig_default_connection_info.profile = g_strdup(tmp_profile); - __netconfig_get_default_connection_info(tmp_profile); +void netconfig_update_default_profile(void) +{ + if (__netconfig_get_default_connection_info()) __netconfig_update_default_connection_info(); - g_free(tmp_profile); - return; - } - - netconfig_default_connection_info.profile = g_strdup(profile); - __netconfig_get_default_connection_info(profile); - __netconfig_update_default_connection_info(); } void netconfig_update_default(void) { if (__netconfig_is_tech_state_connected() == TRUE) - __netconfig_update_if_service_connected(); + netconfig_update_default_profile(); else __netconfig_adjust_tcp_buffer_size(); } -char *netconfig_get_ifname(const char *profile) +const char *netconfig_get_ifname(const char *profile) { - GVariant *message = NULL, *variant; - GVariantIter *iter, *next, *service; - gchar *obj_path; - gchar *key; - gchar *key1; - const gchar *value = NULL; - gchar *ifname = NULL; - gboolean found_profile = 0; - - if (profile == NULL) - return NULL; - - message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, - CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, - "GetServices", NULL); - if (message == NULL) { - ERR("Failed to get services informations"); - return NULL; - } - - g_variant_get(message, "(a(oa{sv}))", &service); - while (g_variant_iter_loop(service, "(oa{sv})", &obj_path, &iter)) { - if (g_strcmp0(obj_path, profile) == 0) { - g_free(obj_path); - found_profile = 1; - break; - } - } - - if (found_profile == 0) { - ERR("Profile %s doesn't exist", profile); - g_variant_iter_free(service); - g_variant_unref(message); - return NULL; - } - - while (g_variant_iter_loop(iter, "{sv}", &key, &next)) { - if (g_strcmp0(key, "Ethernet") == 0) { - while (g_variant_iter_loop(next, "{sv}", &key1, &variant)) { - if (g_strcmp0(key1, "Interface") == 0) { - value = g_variant_get_string(variant, NULL); - if (!ifname) - ifname = g_strdup(value); - g_free(key1); - g_variant_unref(variant); - break; - } - } - } - } + const char *ifname = NULL; + char *mac_addr = NULL; - g_variant_unref(message); - - g_variant_iter_free(service); - g_variant_iter_free(iter); + mac_addr = __netconfig_get_mac_address(profile); + ifname = wifi_state_get_interface_name(mac_addr); + g_free(mac_addr); return ifname; } diff --git a/src/network-statistics.c b/src/network-statistics.c index 44f181e..8c303bb 100755 --- a/src/network-statistics.c +++ b/src/network-statistics.c @@ -24,6 +24,7 @@ #include "log.h" #include "util.h" #include "netsupplicant.h" +#include "network-state.h" #include "network-statistics.h" #include "generated-code.h" @@ -32,6 +33,19 @@ static Network_statistics *netconfigstatistics = NULL; +static gboolean __find_wifi_interface_name(const char *interface_name) +{ + GSList *list = wifi_state_get_device_list(); + + for ( ; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + if (g_strcmp0(device_data->interface_name, interface_name) == 0) + return TRUE; + } + + return FALSE; +} + gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx) { gboolean ret = FALSE; @@ -63,7 +77,7 @@ gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx) if (p_entry != NULL) { *p_entry++ = '\0'; - if (g_strcmp0(p_ifname, WIFI_IFNAME) != 0) + if (__find_wifi_interface_name(p_ifname) == FALSE) continue; /* read interface statistics */ @@ -154,7 +168,7 @@ static gboolean handle_get_wifi_last_tx_bytes( netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val); tx_bytes = (guint64)val; - if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) { last_bytes = tx_bytes; network_statistics_complete_get_wifi_last_tx_bytes(object, context, last_bytes); return TRUE; @@ -181,7 +195,7 @@ static gboolean handle_get_wifi_last_rx_bytes( netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val); rx_bytes = (guint64)val; - if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) { last_bytes = rx_bytes; network_statistics_complete_get_wifi_last_rx_bytes(object, context, last_bytes); return TRUE; @@ -269,7 +283,7 @@ static gboolean handle_reset_wifi_last_tx_bytes( { guint64 tx = 0, rx = 0; - if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) { netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); network_statistics_complete_reset_wifi_last_tx_bytes(object, context); return TRUE; @@ -291,7 +305,7 @@ static gboolean handle_reset_wifi_last_rx_bytes( { guint64 tx = 0, rx = 0; - if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) { netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0); network_statistics_complete_reset_wifi_last_rx_bytes(object, context); return TRUE; @@ -330,7 +344,8 @@ void netconfig_wifi_statistics_update_powered_off(void) netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx); } -static void wifi_statistics_update_state(wifi_service_state_e state, void *user_data) +static void wifi_statistics_update_state(wifi_state_notifier_s *notifier, + char *service, wifi_service_state_e state, void *user_data) { guint64 tx = 0, rx = 0; guint64 last_tx = 0, last_rx = 0; @@ -371,7 +386,9 @@ static void wifi_statistics_update_state(wifi_service_state_e state, void *user_ prev_state = state; } -static wifi_state_notifier state_notifier = { +static wifi_state_notifier_s state_notifier = { + .notifier = NULL, + .service = NULL, .wifi_state_changed = wifi_statistics_update_state, .user_data = NULL, }; @@ -422,7 +439,7 @@ void statistics_object_create_and_init(void) ERR("Export with path failed"); } - wifi_statistics_update_state(NETCONFIG_WIFI_IDLE, NULL); + wifi_statistics_update_state(&state_notifier, NULL, NETCONFIG_WIFI_IDLE, NULL); wifi_state_notifier_register(&state_notifier); return; diff --git a/src/signal-handler.c b/src/signal-handler.c index 08fd2a8..30a549b 100755 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -29,15 +29,16 @@ #include "netdbus.h" #include "neterror.h" #include "wifi-wps.h" -#include "wifi-bssid-scan.h" #include "wifi-agent.h" #include "wifi-power.h" #include "wifi-state.h" +#include "wifi-scan.h" +#include "wifi-bssid-scan.h" +#include "wifi-background-scan.h" #include "netsupplicant.h" #include "network-state.h" #include "cellular-state.h" #include "signal-handler.h" -#include "wifi-background-scan.h" #include "wifi-tdls.h" #include "wifi-dpp.h" #include "ip-conflict-detect.h" @@ -78,6 +79,8 @@ #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged" #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged" +#define CONNMAN_SIGNAL_DEVICE_CHANGED "DeviceChanged" +#define CONNMAN_SIGNAL_DEVICE_DETECTED "DeviceDetected" #define SIGNAL_NAME_OWNER_CHANGED "NameOwnerChanged" #define MAX_SIG_LEN 64 @@ -182,6 +185,7 @@ static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary, builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); if (value != NULL) { + netconfig_set_default_ipaddress(value); vconf_set_str(VCONFKEY_NETWORK_IP, value); g_variant_builder_add(builder, "{sv}", "IPv4Address", g_variant_new_string(value)); @@ -227,6 +231,7 @@ static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary, builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); if (value != NULL) { + netconfig_set_default_ipaddress6(value); vconf_set_str(VCONFKEY_NETWORK_IP6, value); g_variant_builder_add(builder, "{sv}", "IPv6Address", g_variant_new_string(value)); @@ -314,39 +319,75 @@ static int _start_dump() } #endif +static char *__supplicant_get_interface_name(const gchar *path, const gchar *interface) +{ + GVariant *params = NULL; + GVariant *reply = NULL, *var = NULL;; + char *interface_name = NULL; + + params = g_variant_new("(ss)", interface, "Ifname"); + + reply = netconfig_supplicant_invoke_dbus_method(SUPPLICANT_SERVICE, + path, DBUS_INTERFACE_PROPERTIES, "Get", params); + if (reply == NULL) { + ERR("Failed to get interface name"); + return NULL; + } + + g_variant_get(reply, "(v)", &var); + + if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) { + interface_name = g_variant_dup_string(var, NULL); + DBG("%s [%s]", path, interface_name); + } + + g_variant_unref(var); + g_variant_unref(reply); + + return interface_name; +} + static void _technology_signal_cb(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { gchar *key = NULL; - gboolean value = FALSE; GVariant *var = NULL; + GVariantIter *iter = NULL; + const gchar *svalue = NULL; + gboolean bvalue = FALSE; + + DBG("%s %s", path, sig); if (param == NULL) return; - if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) { - g_variant_get(param, "(sv)", &key, &var); - if (g_strcmp0(key, "Powered") == 0) { - /* Power state */ - value = g_variant_get_boolean(var); - if (value == TRUE) - wifi_state_update_power_state(TRUE); - else - wifi_state_update_power_state(FALSE); - } else if (g_strcmp0(key, "Connected") == 0) { - /* Connection state */ - value = g_variant_get_boolean(var); - if (value == TRUE) - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED); - else - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED); - } else if (g_strcmp0(key, "Tethering") == 0) { - /* Tethering state */ - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED); + if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != TRUE) + return; + + if (g_strcmp0(sig, CONNMAN_SIGNAL_DEVICE_CHANGED) == 0) { + g_variant_get(param, "(a{sv})", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (g_strcmp0(key, "Ifname") == 0) { + svalue = g_variant_get_string(var, NULL); + DBG("Ifname [%s]", svalue); + } else if (g_strcmp0(key, "Powered") == 0) { + bvalue = g_variant_get_boolean(var); + DBG("Powered [%d]", bvalue); + wifi_state_update_power_state(svalue, bvalue); + } else if (g_strcmp0(key, "Connected") == 0) { + bvalue = g_variant_get_boolean(var); + DBG("Connected [%d]", bvalue); + wifi_state_set_connected(svalue, bvalue); + if (bvalue == TRUE) + wifi_state_set_technology_state(svalue, NETCONFIG_WIFI_TECH_CONNECTED); + else + wifi_state_set_technology_state(svalue, NETCONFIG_WIFI_TECH_POWERED); + } } - g_free(key); - g_variant_unref(var); + g_variant_iter_free(iter); + } else if (g_strcmp0(sig, CONNMAN_SIGNAL_DEVICE_DETECTED) == 0) { + wifi_state_update_device_list(); } } @@ -363,6 +404,7 @@ static void _service_signal_cb(GDBusConnection *conn, struct sock_data *sd = NULL; gchar *pf = NULL; int idx = 0; + const char *interface_name = NULL; if (path == NULL || param == NULL) goto done; @@ -374,6 +416,8 @@ static void _service_signal_cb(GDBusConnection *conn, if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0) goto done; + interface_name = netconfig_get_ifname(path); + if (g_strcmp0(sigvalue, "State") == 0) { g_variant_get(variant, "s", &property); @@ -389,77 +433,45 @@ static void _service_signal_cb(GDBusConnection *conn, } if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) { - if (wifi_state >= VCONFKEY_WIFI_CONNECTED) { - g_free(property); - goto done; - } - - netconfig_update_default_profile(path); + netconfig_update_default_profile(); - wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED); + wifi_state_set_service_state(interface_name, NETCONFIG_WIFI_CONNECTED); - } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) { - if (netconfig_get_default_profile() == NULL || - netconfig_is_wifi_profile(netconfig_get_default_profile()) - != TRUE) { - if (g_strcmp0(property, "failure") == 0) - wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE); - else - wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); - g_free(property); - goto done; - } + } else if (g_strcmp0(property, "failure") == 0 || + g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) { + if (g_strcmp0(property, "failure") == 0) + wifi_state_set_service_state(interface_name, NETCONFIG_WIFI_FAILURE); + else + wifi_state_set_service_state(interface_name, NETCONFIG_WIFI_IDLE); if (g_strcmp0(path, netconfig_get_default_profile()) != 0) { g_free(property); goto done; } - netconfig_update_default_profile(NULL); - - if (g_strcmp0(property, "failure") == 0) - wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE); - else - wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); + netconfig_update_default_profile(); } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) { - if (netconfig_get_default_profile() == NULL || - netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) { - if (g_strcmp0(property, "association") == 0) - wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION); - else - wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION); - g_free(property); - goto done; - } + if (g_strcmp0(property, "association") == 0) + wifi_state_set_service_state(interface_name, NETCONFIG_WIFI_ASSOCIATION); + else + wifi_state_set_service_state(interface_name, NETCONFIG_WIFI_CONFIGURATION); if (g_strcmp0(path, netconfig_get_default_profile()) != 0) { g_free(property); goto done; } - netconfig_update_default_profile(NULL); - - if (g_strcmp0(property, "association") == 0) - wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION); - else - wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION); + netconfig_update_default_profile(); } } else { if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) { - if (netconfig_get_default_profile() == NULL) { - if (!netconfig_is_cellular_profile(path)) { - netconfig_update_default_profile(path); - } else { - if (netconfig_is_cellular_internet_profile(path)) { - netconfig_update_default_profile(path); - } - } - } else { + netconfig_update_default_profile(); + + if (netconfig_is_cellular_profile(netconfig_get_default_profile())) { pf = netconfig_get_connected_cellular_internet_ipv6only_profile(NULL); - if (pf) - { + if (pf) { g_free(pf); /* Enable clatd if it is not in running state */ @@ -471,7 +483,8 @@ static void _service_signal_cb(GDBusConnection *conn, if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path)) cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE); - } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) { + } else if (g_strcmp0(property, "failure") == 0 || + g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) { if (netconfig_get_default_profile() == NULL) { g_free(property); goto done; @@ -490,7 +503,7 @@ static void _service_signal_cb(GDBusConnection *conn, goto done; } - netconfig_update_default_profile(NULL); + netconfig_update_default_profile(); } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) { if (netconfig_get_default_profile() == NULL) { g_free(property); @@ -505,7 +518,7 @@ static void _service_signal_cb(GDBusConnection *conn, goto done; } - netconfig_update_default_profile(NULL); + netconfig_update_default_profile(); } } @@ -525,7 +538,7 @@ static void _service_signal_cb(GDBusConnection *conn, g_free(property); } else if (g_strcmp0(sigvalue, "Proxy") == 0) { - if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0) + if (g_strcmp0(path, netconfig_get_default_profile()) != 0) goto done; if (!g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY)) @@ -538,25 +551,28 @@ static void _service_signal_cb(GDBusConnection *conn, if (g_strcmp0(property, "Servers") == 0) { GVariantIter *iter_sub = NULL; - builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - g_variant_get(var, "as", &iter_sub); g_variant_iter_loop(iter_sub, "s", &value); g_variant_iter_free(iter_sub); DBG("Proxy - [%s]", value); - vconf_set_str(VCONFKEY_NETWORK_PROXY, value); + if (g_strcmp0(value, netconfig_get_default_proxy()) != 0) { + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(builder, "{sv}", "ProxyAddress", - g_variant_new_string(value)); + netconfig_set_default_proxy(value); + vconf_set_str(VCONFKEY_NETWORK_PROXY, value); - sig_params = g_variant_new("(@a{sv})", - g_variant_builder_end(builder)); - g_variant_builder_unref(builder); + g_variant_builder_add(builder, "{sv}", "ProxyAddress", + g_variant_new_string(value)); - netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH, - NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged", - sig_params); + sig_params = g_variant_new("(@a{sv})", + g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged", + sig_params); + } g_free(property); g_variant_unref(var); @@ -566,19 +582,23 @@ static void _service_signal_cb(GDBusConnection *conn, DBG("Method - [%s]", value); if (g_strcmp0(value, "direct") == 0) { - builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + if (g_strcmp0("", netconfig_get_default_proxy()) != 0) { + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - vconf_set_str(VCONFKEY_NETWORK_PROXY, ""); - g_variant_builder_add(builder, "{sv}", "ProxyAddress", - g_variant_new_string("")); + netconfig_set_default_proxy(""); + vconf_set_str(VCONFKEY_NETWORK_PROXY, ""); - sig_params = g_variant_new("(@a{sv})", - g_variant_builder_end(builder)); - g_variant_builder_unref(builder); + g_variant_builder_add(builder, "{sv}", "ProxyAddress", + g_variant_new_string("")); - netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH, - NETCONFIG_NETWORK_INTERFACE, - "NetworkConfigChanged", sig_params); + sig_params = g_variant_new("(@a{sv})", + g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + "NetworkConfigChanged", sig_params); + } } g_free(property); @@ -589,8 +609,14 @@ static void _service_signal_cb(GDBusConnection *conn, g_variant_iter_free(iter); } else if (g_strcmp0(sigvalue, "IPv4") == 0) { + if (g_strcmp0(path, netconfig_get_default_profile()) != 0) + goto done; + __netconfig_extract_ipv4_signal_data(variant, path); } else if (g_strcmp0(sigvalue, "IPv6") == 0) { + if (g_strcmp0(path, netconfig_get_default_profile()) != 0) + goto done; + __netconfig_extract_ipv6_signal_data(variant, path); } else if (g_strcmp0(sigvalue, "Error") == 0) { g_variant_get(variant, "s", &property); @@ -648,82 +674,6 @@ static void _dbus_name_changed_cb(GDBusConnection *conn, return; } -static void _services_changed_cb(GDBusConnection *conn, const gchar *name, - const gchar *path, const gchar *interface, const gchar *sig, - GVariant *param, gpointer user_data) -{ - gchar *property, *value; - gchar *service_path; - GVariant *variant = NULL; - GVariantIter *added = NULL, *removed = NULL, *next = NULL; - - if (path == NULL || param == NULL) - return; - - if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0) - return; - - if (netconfig_get_default_profile() != NULL) - return; - - g_variant_get(param, "(a(oa{sv})ao)", &added, &removed); - - while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) { - gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof; - is_wifi_prof = netconfig_is_wifi_profile(service_path); - is_cell_prof = netconfig_is_cellular_profile(service_path); - is_cell_internet_prof = netconfig_is_cellular_internet_profile( - service_path); - if (service_path != NULL) { - while (next && g_variant_iter_loop(next, "{sv}", &property, - &variant)) { - if (g_strcmp0(property, "State") == 0) { - g_variant_get(variant, "s", &value); - DBG("Profile %s State %s", service_path, - value); - if (g_strcmp0(value, "ready") != 0 && - g_strcmp0(value, - "online") != 0) { - g_free(property); - g_free(value); - g_variant_unref(variant); - break; - } - - if (!is_cell_prof) - netconfig_update_default_profile( - service_path); - else if (is_cell_internet_prof) { - netconfig_update_default_profile( - service_path); - } - if (is_wifi_prof) - wifi_state_set_service_state( - NETCONFIG_WIFI_CONNECTED); - else if (is_cell_prof && - is_cell_internet_prof) - cellular_state_set_service_state( - NETCONFIG_CELLULAR_ONLINE); - g_free(property); - g_free(value); - g_variant_unref(variant); - break; - } - } - } - } - - g_variant_iter_free(added); - - if (next) - g_variant_iter_free(next); - - if (removed) - g_variant_iter_free(removed); - - return; -} - static void _scan_changed_cb(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) @@ -752,10 +702,18 @@ static void _supplicant_interface_removed(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + DBG("Interface removed handling!"); - if (netconfig_wifi_is_bssid_scan_started() == TRUE) - netconfig_wifi_bssid_signal_scanaborted(); + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + + if (netconfig_wifi_bssidscan_get_mode(interface_name) == TRUE) + netconfig_wifi_bssid_signal_scanaborted(interface_name); + + g_free(interface_name); return; } @@ -769,19 +727,24 @@ static void _supplicant_properties_changed(GDBusConnection *conn, GVariantIter *iter = NULL; GVariant *variant = NULL; gboolean scanning = FALSE; + char *interface_name = NULL; if (param == NULL) return; + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + g_variant_get(param, "(a{sv})", &iter); while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) { if (g_strcmp0(key, "Scanning") == 0) { scanning = g_variant_get_boolean(variant); DBG("setting scanning %s", scanning ? "TRUE" : "FALSE"); if (scanning == TRUE) - netconfig_wifi_set_scanning(TRUE); + netconfig_wifi_scan_set_scanning(interface_name, TRUE); else - netconfig_wifi_set_scanning(FALSE); + netconfig_wifi_scan_set_scanning(interface_name, FALSE); g_variant_unref(variant); g_free(key); @@ -791,7 +754,7 @@ static void _supplicant_properties_changed(GDBusConnection *conn, } else if (g_strcmp0(key, "State") == 0) { state = g_variant_get_string(variant, NULL); if (state != NULL) - ERR("Supplicant state : %s", state); + DBG("Supplicant state : %s", state); g_variant_unref(variant); g_free(key); @@ -800,7 +763,7 @@ static void _supplicant_properties_changed(GDBusConnection *conn, break; } else if (g_strcmp0(key, "DisconnectReason") == 0) { int reason = g_variant_get_int32(variant); - ERR("Supplicant DisconnReason : %d", reason); + DBG("Supplicant DisconnReason : %d", reason); g_variant_unref(variant); g_free(key); @@ -817,7 +780,7 @@ static void _supplicant_properties_changed(GDBusConnection *conn, } g_variant_iter_free(iter); - + g_free(interface_name); return; } @@ -835,23 +798,37 @@ static void _supplicant_scan_done(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + DBG("Scan Done handling!"); - netconfig_wifi_set_scanning(FALSE); - if (netconfig_wifi_is_bssid_scan_started() == TRUE) { - netconfig_wifi_bssid_signal_scandone(); - if (wifi_state_get_technology_state(FALSE) < NETCONFIG_WIFI_TECH_POWERED) + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + + netconfig_wifi_scan_set_scanning(interface_name, FALSE); + + if (netconfig_wifi_bssidscan_get_mode(interface_name) == TRUE) { + DBG("%s bssid scan done!", interface_name); + netconfig_wifi_bssid_signal_scandone(interface_name); + if (wifi_state_get_technology_state(interface_name) + < NETCONFIG_WIFI_TECH_POWERED) { + g_free(interface_name); return; + } } - if (netconfig_wifi_get_bgscan_state() == TRUE) { - if (wifi_state_get_technology_state(FALSE) >= - NETCONFIG_WIFI_TECH_POWERED) - netconfig_wifi_bgscan_start(FALSE); + if (netconfig_wifi_bgscan_get_mode(interface_name) == TRUE) { + DBG("%s bgscan done!", interface_name); + if (wifi_state_get_technology_state(interface_name) + >= NETCONFIG_WIFI_TECH_POWERED) { + netconfig_wifi_bgscan_start(interface_name, FALSE); + } - wifi_start_timer_network_notification(); + wifi_start_timer_network_notification(interface_name); } + g_free(interface_name); return; } @@ -859,6 +836,8 @@ static void _supplicant_driver_hanged(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + DBG("Driver Hanged handling!"); ERR("Critical. Wi-Fi firmware crashed"); @@ -866,8 +845,14 @@ static void _supplicant_driver_hanged(GDBusConnection *conn, netconfig_send_message_to_net_popup("Wi-Fi Error", "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL); #endif - wifi_power_recover_firmware(); + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + + wifi_power_recover_firmware(interface_name); + + g_free(interface_name); return; } @@ -912,9 +897,17 @@ static void _supplicant_tdls_connected(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + DBG("Received TDLS Connected Signal"); - netconfig_wifi_tdls_connected_event(param); + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + + netconfig_wifi_tdls_connected_event(interface_name, param); + + g_free(interface_name); return; } @@ -922,9 +915,17 @@ static void _supplicant_tdls_disconnected(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + DBG("Received TDLS Disconnected Signal"); - netconfig_wifi_tdls_disconnected_event(param); + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + + netconfig_wifi_tdls_disconnected_event(interface_name, param); + + g_free(interface_name); return; } @@ -932,8 +933,17 @@ static void _supplicant_tdls_peer_found(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + DBG("Received TDLS Peer Found Signal"); - netconfig_wifi_tdls_peer_found_event(param); + + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + + netconfig_wifi_tdls_peer_found_event(interface_name, param); + + g_free(interface_name); return; } @@ -1013,12 +1023,21 @@ static void _supplicant_dpp_conf_obj(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + DBG("Received DPP Conf Obj Signal"); - netconfig_wifi_dpp_conf_obj_event(param); + + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + + netconfig_wifi_dpp_conf_obj_event(interface_name, param); + + g_free(interface_name); return; } -static void _supplicant_wifi_wps_connected(GVariant *param) +static void _supplicant_wifi_wps_connected(const char *interface_name, GVariant *param) { gchar *key; char ssid[32] = {0, }; @@ -1055,7 +1074,8 @@ static void _supplicant_wifi_wps_connected(GVariant *param) ssid_len = 0; } INFO("WPS PBC Connection completed with AP %s", ssid); - netconfig_wifi_notify_wps_completed(ssid, ssid_len); + netconfig_wifi_notify_wps_completed(interface_name, + ssid, ssid_len); } } @@ -1069,11 +1089,12 @@ error: error_indication = WPS_EI_OPERATION_FAILED; config_error = WPS_CFG_NO_ERROR; ERR("Error Occured! Notifying Fail Event"); - netconfig_wifi_notify_wps_fail_event(config_error, error_indication); + netconfig_wifi_notify_wps_fail_event(interface_name, + config_error, error_indication); } -static void _supplicant_wifi_wps_event(GVariant *param) +static void _supplicant_wifi_wps_event(const char *interface_name, GVariant *param) { gchar *key; gchar *name; @@ -1102,7 +1123,8 @@ static void _supplicant_wifi_wps_event(GVariant *param) ERR("Error Indication %d", error_indication); } } - netconfig_wifi_notify_wps_fail_event(config_error, error_indication); + netconfig_wifi_notify_wps_fail_event(interface_name, + config_error, error_indication); } g_variant_iter_free(iter); @@ -1115,7 +1137,8 @@ error: error_indication = WPS_EI_OPERATION_FAILED; config_error = WPS_CFG_NO_ERROR; ERR("Error Occured! Notifying Fail Event"); - netconfig_wifi_notify_wps_fail_event(config_error, error_indication); + netconfig_wifi_notify_wps_fail_event(interface_name, + config_error, error_indication); } static void _find_service_and_set_passphrase(char *ssid, char *key) @@ -1184,7 +1207,7 @@ static void _find_service_and_set_passphrase(char *ssid, char *key) return; } -static void _supplicant_wifi_wps_credentials(GVariant *param) +static void _supplicant_wifi_wps_credentials(const char *interface_name, GVariant *param) { gchar *key; char ssid[32] = {0, }; @@ -1278,14 +1301,7 @@ static void _supplicant_wifi_wps_credentials(GVariant *param) if (g_strcmp0(key_mgmt, "psk") == 0) _find_service_and_set_passphrase(ssid, wps_key); -#if 0 - /* - * Notify WPS Credentials only when requested through WPS PBC - * In case of WPS PIN connman will take care of notification - */ - if (netconfig_get_wps_field() == TRUE) -#endif - netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key); + netconfig_wifi_notify_wps_credentials(interface_name, ssid, ssid_len, wps_key); return; error: @@ -1293,24 +1309,31 @@ error: error_indication = WPS_EI_OPERATION_FAILED; config_error = WPS_CFG_NO_ERROR; ERR("Error Occured! Notifying Fail Event"); - netconfig_wifi_notify_wps_fail_event(config_error, error_indication); + netconfig_wifi_notify_wps_fail_event(interface_name, config_error, error_indication); } static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { + char *interface_name = NULL; + + interface_name = __supplicant_get_interface_name(path, interface); + if (interface_name == NULL) + return; + if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) { INFO("Received wps CREDENTIALS Signal from Supplicant"); - _supplicant_wifi_wps_credentials(param); + _supplicant_wifi_wps_credentials(interface_name, param); } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) { INFO("Received wps EVENT Signal from Supplicant"); - _supplicant_wifi_wps_event(param); + _supplicant_wifi_wps_event(interface_name, param); } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) { INFO("Received WPSConnected Signal from Supplicant"); - _supplicant_wifi_wps_connected(param); + _supplicant_wifi_wps_connected(interface_name, param); } + g_free(interface_name); return; } @@ -1465,18 +1488,6 @@ void register_gdbus_signal(void) NULL); conn_subscription_ids[3] = g_dbus_connection_signal_subscribe( - connection, - CONNMAN_SERVICE, - CONNMAN_MANAGER_INTERFACE, - CONNMAN_SIGNAL_SERVICES_CHANGED, - NULL, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - _services_changed_cb, - NULL, - NULL); - - conn_subscription_ids[4] = g_dbus_connection_signal_subscribe( connection, CONNMAN_SERVICE, CONNMAN_MANAGER_INTERFACE, @@ -1490,7 +1501,7 @@ void register_gdbus_signal(void) INFO("Successfully register connman DBus signal filters"); - conn_subscription_ids[5] = g_dbus_connection_signal_subscribe( + conn_subscription_ids[4] = g_dbus_connection_signal_subscribe( connection, SUPPLICANT_SERVICE, SUPPLICANT_INTERFACE ".Interface.WPS", diff --git a/src/utils/network-accessibility.c b/src/utils/network-accessibility.c index 9d698db..e3475c0 100755 --- a/src/utils/network-accessibility.c +++ b/src/utils/network-accessibility.c @@ -322,6 +322,7 @@ static void __netconfig_connect_sockets(void) GIOFlags flags; struct sockaddr_in addr; GIOChannel *channel = NULL; + const char *ifname = NULL; int sock; if (net_params == NULL || net_params->addr == NULL) @@ -331,8 +332,9 @@ static void __netconfig_connect_sockets(void) if (sock < 0) goto cleanup; + ifname = netconfig_get_default_ifname(); if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, - WIFI_IFNAME, strlen(WIFI_IFNAME) + 1) < 0) { + ifname, strlen(ifname) + 1) < 0) { ERR("Bind to device error"); close(sock); goto cleanup; diff --git a/src/utils/setting.c b/src/utils/setting.c new file mode 100755 index 0000000..a278a01 --- /dev/null +++ b/src/utils/setting.c @@ -0,0 +1,283 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "setting.h" +#include "util.h" +#include "log.h" + +typedef enum { + SETTING_TYPE_LAST_POWER, + SETTING_TYPE_WIFI_OFF_BY_AIRPLANE, + SETTING_TYPE_WIFI_OFF_BY_RESTRICTED, + SETTING_TYPE_WIFI_OFF_BY_EMERGENCY, +} netconfig_setting_type_e; + +typedef struct { + const char *key; + GSList *string_list; +} netconfig_setting_data_s; + +netconfig_setting_data_s netconfig_setting_data[] = { + { "LastPoweredInterfaces", NULL }, + { "WifiOffByAirplaneInterfaces", NULL }, + { "WifiOffByRestrictedInterfaces", NULL }, + { "WifiOffByEmergencyInterfaces", NULL }, +}; + +void netconfig_setting_init(void) +{ + netconfig_setting_load(); + + INFO("setting is initialized"); + + return; +} + +void netconfig_setting_deinit(void) +{ + int i, size; + + netconfig_setting_save(); + + size = ARRAY_SIZE(netconfig_setting_data); + for (i = 0; i < size; i++) + g_slist_free_full(netconfig_setting_data[i].string_list, g_free); + + INFO("setting is deinitialized"); + + return; +} + +static void __setting_set_string_list(GKeyFile *keyfile, netconfig_setting_type_e type) +{ + GString *string_str = NULL; + char **string_list = NULL; + GSList *list = NULL; + guint length; + + string_str = g_string_new(NULL); + if (string_str) { + list = netconfig_setting_data[type].string_list; + for (; list; list = list->next) { + if (string_str->len > 0) + g_string_append_printf(string_str, " %s", (char *)list->data); + else + g_string_append(string_str, list->data); + } + + if (string_str->len > 0) { + string_list = g_strsplit_set(string_str->str, " ", 0); + length = g_strv_length(string_list); + g_key_file_set_string_list(keyfile, SETTINGS_WIFI_GROUP_NAME, + netconfig_setting_data[type].key, + (const gchar **)string_list, length); + } else { + g_key_file_remove_key(keyfile, SETTINGS_WIFI_GROUP_NAME, + netconfig_setting_data[type].key, NULL); + } + + g_string_free(string_str, TRUE); + } +} + +static void __setting_get_string_list(GKeyFile *keyfile, netconfig_setting_type_e type) +{ + char **string_list = NULL; + gsize length; + int i; + + INFO("Key [%s]", netconfig_setting_data[type].key); + + string_list = g_key_file_get_string_list(keyfile, SETTINGS_WIFI_GROUP_NAME, + netconfig_setting_data[type].key, &length, NULL); + if (string_list && length != 0) { + for (i = 0; string_list[i]; i++) { + netconfig_setting_data[type].string_list = g_slist_append( + netconfig_setting_data[type].string_list, + g_strdup(string_list[i])); + + INFO("%s", string_list[i]); + } + } + + g_strfreev(string_list); +} + +int netconfig_setting_save(void) +{ + GKeyFile *keyfile = NULL; + + INFO("Save setting [%s]", NETCONFIG_SETTINGS_PATH); + + keyfile = netconfig_keyfile_load(NETCONFIG_SETTINGS_PATH); + if (keyfile == NULL) { + ERR("Fail to get settings keyfile"); + return -EIO; + } + + __setting_set_string_list(keyfile, SETTING_TYPE_LAST_POWER); + __setting_set_string_list(keyfile, SETTING_TYPE_WIFI_OFF_BY_AIRPLANE); + __setting_set_string_list(keyfile, SETTING_TYPE_WIFI_OFF_BY_RESTRICTED); + __setting_set_string_list(keyfile, SETTING_TYPE_WIFI_OFF_BY_EMERGENCY); + + netconfig_keyfile_save(keyfile, NETCONFIG_SETTINGS_PATH); + + g_key_file_free(keyfile); + return 0; +} + +int netconfig_setting_load(void) +{ + GKeyFile *keyfile = NULL; + + INFO("Load setting [%s]", NETCONFIG_SETTINGS_PATH); + + keyfile = netconfig_keyfile_load(NETCONFIG_SETTINGS_PATH); + if (keyfile == NULL) { + ERR("Fail to get settings keyfile"); + return -EIO; + } + + __setting_get_string_list(keyfile, SETTING_TYPE_LAST_POWER); + __setting_get_string_list(keyfile, SETTING_TYPE_WIFI_OFF_BY_AIRPLANE); + __setting_get_string_list(keyfile, SETTING_TYPE_WIFI_OFF_BY_RESTRICTED); + __setting_get_string_list(keyfile, SETTING_TYPE_WIFI_OFF_BY_EMERGENCY); + + return 0; +} + +void netconfig_setting_update_interface_for_last_powered(const char *interface_name, + bool mode) +{ + GSList *list = netconfig_setting_data[SETTING_TYPE_LAST_POWER].string_list; + bool find = FALSE; + + for ( ; list; list = list->next) { + const char *ifname = list->data; + if (g_strcmp0(ifname, interface_name) == 0) { + if (mode == FALSE) + netconfig_setting_data[SETTING_TYPE_LAST_POWER].string_list = g_slist_remove( + netconfig_setting_data[SETTING_TYPE_LAST_POWER].string_list, ifname); + + find = TRUE; + break; + } + } + + if (mode == TRUE && find == FALSE) + netconfig_setting_data[SETTING_TYPE_LAST_POWER].string_list = g_slist_append( + netconfig_setting_data[SETTING_TYPE_LAST_POWER].string_list, g_strdup(interface_name)); + + netconfig_setting_save(); +} + +GSList *netconfig_setting_get_interfaces_for_last_powered(void) +{ + return netconfig_setting_data[SETTING_TYPE_LAST_POWER].string_list; +} + +void netconfig_setting_update_interface_off_for_airplane(const char *interface_name, + bool mode) +{ + GSList *list = netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_AIRPLANE].string_list; + bool find = FALSE; + + for ( ; list; list = list->next) { + const char *ifname = list->data; + if (g_strcmp0(ifname, interface_name) == 0) { + if (mode == FALSE) + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_AIRPLANE].string_list = g_slist_remove( + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_AIRPLANE].string_list, ifname); + + find = TRUE; + break; + } + } + + if (mode == TRUE && find == FALSE) + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_AIRPLANE].string_list = g_slist_append( + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_AIRPLANE].string_list, g_strdup(interface_name)); + + netconfig_setting_save(); +} + +GSList *netconfig_setting_get_interfaces_off_by_airplane(void) +{ + return netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_AIRPLANE].string_list; +} + +void netconfig_setting_update_interface_off_for_restricted(const char *interface_name, + bool mode) +{ + GSList *list = netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_RESTRICTED].string_list; + bool find = FALSE; + + for ( ; list; list = list->next) { + const char *ifname = list->data; + if (g_strcmp0(ifname, interface_name) == 0) { + if (mode == FALSE) + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_RESTRICTED].string_list = g_slist_remove( + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_RESTRICTED].string_list, ifname); + + find = TRUE; + break; + } + } + + if (mode == TRUE && find == FALSE) + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_RESTRICTED].string_list = g_slist_append( + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_RESTRICTED].string_list, g_strdup(interface_name)); + + netconfig_setting_save(); +} + +GSList *netconfig_setting_get_interfaces_off_by_restricted(void) +{ + return netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_RESTRICTED].string_list; +} + +void netconfig_setting_update_interface_off_for_emergency(const char *interface_name, + bool mode) +{ + GSList *list = netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_EMERGENCY].string_list; + bool find = FALSE; + + for ( ; list; list = list->next) { + const char *ifname = list->data; + if (g_strcmp0(ifname, interface_name) == 0) { + if (mode == FALSE) + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_EMERGENCY].string_list = g_slist_remove( + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_EMERGENCY].string_list, ifname); + + find = TRUE; + break; + } + } + + if (mode == TRUE && find == FALSE) + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_EMERGENCY].string_list = g_slist_append( + netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_EMERGENCY].string_list, g_strdup(interface_name)); + + netconfig_setting_save(); +} + +GSList *netconfig_setting_get_interfaces_off_by_emergency(void) +{ + return netconfig_setting_data[SETTING_TYPE_WIFI_OFF_BY_EMERGENCY].string_list; +} diff --git a/src/utils/util.c b/src/utils/util.c index 363f6ef..e139ab8 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -50,7 +50,6 @@ #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus" #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_ETC, "/.mac.info") #define MAC_ADDRESS_FILEPATH "/sys/class/net/wlan0/address" -#define MAC_ADDRESS_MAX_LEN 18 #define HEADED_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-headed.so" #define TELEPHONY_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-telephony.so" #define STC_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-stc.so" @@ -79,6 +78,32 @@ static struct netconfig_battery_plugin_t *battery_plugin; static bool is_feature_checked[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, }; static bool feature_supported[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, }; +gboolean netconfig_check_mac_address(const char *service, const char *mac_address) +{ + int service_index = 0; + int mac_index = 0; + const char *org = NULL; + const char *dst = NULL; + int i = 0; + + if (g_str_has_prefix(service, "wifi_") == FALSE) + return FALSE; + + service_index = strlen("wifi_"); + for (i = 0; i < 6; i++) { + org = &service[service_index]; + dst = &mac_address[mac_index]; + + if (g_ascii_strncasecmp(org, dst, 2) != 0) + return FALSE; + + service_index += 2; + mac_index += 3; + } + + return TRUE; +} + gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase) { gsize length; @@ -1277,7 +1302,8 @@ void netconfig_set_vconf_int(const char * key, int value) { int ret = 0; - DBG("[%s: %d]", key, value); + if (g_strcmp0(key, VCONFKEY_WIFI_TRANSFER_STATE) != 0) + DBG("[%s: %d]", key, value); ret = vconf_set_int(key, value); if (ret != VCONF_OK) diff --git a/src/wifi-agent.c b/src/wifi-agent.c index b88ef56..92ae678 100755 --- a/src/wifi-agent.c +++ b/src/wifi-agent.c @@ -48,7 +48,8 @@ #define NETCONFIG_AGENT_ERR_CONNECT_FAILED "connect-failed" -struct netconfig_wifi_agent { +typedef struct { + char *interface_name; GByteArray *ssid; char *name; char *identity; @@ -59,33 +60,59 @@ struct netconfig_wifi_agent { char *password; #endif gboolean wps_pbc; -}; +} netconfig_wifi_agent_s; -static struct netconfig_wifi_agent agent; +static GSList *g_agent_list = NULL; -static void __netconfig_agent_clear_fields(void) +static void __agent_clear_fields(netconfig_wifi_agent_s *agent) { - if (agent.ssid) - g_byte_array_free(agent.ssid, TRUE); - g_free(agent.name); - g_free(agent.identity); - g_free(agent.passphrase); - g_free(agent.wps_pin); + if (!agent) + return; + + g_free(agent->interface_name); + if (agent->ssid) + g_byte_array_free(agent->ssid, TRUE); + g_free(agent->name); + g_free(agent->identity); + g_free(agent->passphrase); + g_free(agent->wps_pin); #if defined TIZEN_CAPTIVE_PORTAL - g_free(agent.username); - g_free(agent.password); + g_free(agent->username); + g_free(agent->password); #endif - agent.ssid = NULL; - agent.name = NULL; - agent.identity = NULL; - agent.passphrase = NULL; - agent.wps_pin = NULL; + agent->interface_name = NULL; + agent->ssid = NULL; + agent->name = NULL; + agent->identity = NULL; + agent->passphrase = NULL; + agent->wps_pin = NULL; #if defined TIZEN_CAPTIVE_PORTAL - agent.username = NULL; - agent.password = NULL; + agent->username = NULL; + agent->password = NULL; #endif - agent.wps_pbc = FALSE; + agent->wps_pbc = FALSE; +} + +static void __agent_free_data(gpointer data) +{ + netconfig_wifi_agent_s *agent = data; + + __agent_clear_fields(agent); + g_free(agent); +} + +static netconfig_wifi_agent_s *__agent_get_data(const char *interface_name) +{ + GSList *list = NULL; + + for (list = g_agent_list; list; list = list->next) { + netconfig_wifi_agent_s *wifi_agent = list->data; + if (g_strcmp0(wifi_agent->interface_name, interface_name) == 0) + return wifi_agent; + } + + return NULL; } int connman_register_agent(void) @@ -121,46 +148,51 @@ int connman_unregister_agent(void) reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, - "UnregisterAgent", param, NULL); + "UnregisterAgent", param, NULL, NULL); if (reply != TRUE) ERR("Fail to unregister agent"); /* Clearing the agent fields */ - __netconfig_agent_clear_fields(); + g_slist_free_full(g_agent_list, __agent_free_data); return reply; } -gboolean netconfig_wifi_set_agent_field_for_eap_network( - const char *name, const char *identity, const char *passphrase) +gboolean netconfig_wifi_set_agent_field_for_eap_network(const char *interface_name, + const char *name, const char *identity, const char *passphrase) { int name_len; + netconfig_wifi_agent_s *wifi_agent = NULL; if (name == NULL) return FALSE; - __netconfig_agent_clear_fields(); + wifi_agent = __agent_get_data(interface_name); + if (wifi_agent == NULL) + return FALSE; + + __agent_clear_fields(wifi_agent); name_len = strlen(name); - agent.ssid = g_byte_array_sized_new(name_len); - agent.ssid->len = name_len; - memcpy(agent.ssid->data, name, name_len + 1); + wifi_agent->ssid = g_byte_array_sized_new(name_len); + wifi_agent->ssid->len = name_len; + memcpy(wifi_agent->ssid->data, name, name_len + 1); if (identity) - agent.identity = g_strdup(identity); + wifi_agent->identity = g_strdup(identity); if (passphrase) - agent.passphrase = g_strdup(passphrase); + wifi_agent->passphrase = g_strdup(passphrase); gchar *enc_data = NULL; - enc_data = _netconfig_encrypt_passphrase(agent.passphrase); + enc_data = _netconfig_encrypt_passphrase(wifi_agent->passphrase); if (!enc_data) { ERR("Failed to encrypt the passphrase"); } else { - g_free(agent.passphrase); - agent.passphrase = enc_data; + g_free(wifi_agent->passphrase); + wifi_agent->passphrase = enc_data; } DBG("Successfully configured for EAP network"); @@ -177,6 +209,8 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent, GVariant *value; gboolean updated = FALSE; gboolean reply = FALSE; + const char *interface_name = NULL; + netconfig_wifi_agent_s *wifi_agent = NULL; g_return_val_if_fail(connman_agent != NULL, TRUE); @@ -193,66 +227,97 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent, return TRUE; } - __netconfig_agent_clear_fields(); + interface_name = netconfig_get_ifname(service); + if (interface_name == NULL) { + error = g_error_new(G_DBUS_ERROR, + G_DBUS_ERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidService"); + + g_dbus_method_invocation_return_gerror(context, error); + g_clear_error(&error); + + return TRUE; + } + + wifi_agent = __agent_get_data(interface_name); + if (wifi_agent == NULL) { + wifi_agent = g_try_malloc0(sizeof(netconfig_wifi_agent_s)); + if (wifi_agent == NULL) { + error = g_error_new(G_DBUS_ERROR, + G_DBUS_ERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".OutOfMemory"); + + g_dbus_method_invocation_return_gerror(context, error); + g_clear_error(&error); + + return TRUE; + } + + g_agent_list = g_slist_append(g_agent_list, wifi_agent); + } + + __agent_clear_fields(wifi_agent); + wifi_agent->interface_name = g_strdup(interface_name); + g_variant_get(fields, "a{sv}", &iter); while (g_variant_iter_loop(iter, "{sv}", &field, &value)) { if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { - agent.passphrase = g_strdup(g_variant_get_string(value, NULL)); + wifi_agent->passphrase = g_strdup(g_variant_get_string(value, NULL)); updated = TRUE; DBG("Field [%s] - []", (gchar *)field); - if (agent.passphrase == NULL) + if (wifi_agent->passphrase == NULL) continue; - if (netconfig_check_passphrase(service, agent.passphrase) == FALSE) { + if (netconfig_check_passphrase(service, wifi_agent->passphrase) == FALSE) { ERR("Invalid passphrase"); - g_free(agent.passphrase); - agent.passphrase = NULL; + g_free(wifi_agent->passphrase); + wifi_agent->passphrase = NULL; updated = FALSE; continue; } gchar *enc_data = NULL; - enc_data = _netconfig_encrypt_passphrase(agent.passphrase); + enc_data = _netconfig_encrypt_passphrase(wifi_agent->passphrase); if (!enc_data) { ERR("Failed to encrypt the passphrase"); continue; } - g_free(agent.passphrase); - agent.passphrase = enc_data; + g_free(wifi_agent->passphrase); + wifi_agent->passphrase = enc_data; } } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PBC) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING) && g_strcmp0(g_variant_get_string(value, NULL), "enable") == 0) { - agent.wps_pbc = TRUE; + wifi_agent->wps_pbc = TRUE; updated = TRUE; - DBG("Field [%s] - [%d]", (gchar *)field, agent.wps_pbc); + DBG("Field [%s] - [%d]", (gchar *)field, wifi_agent->wps_pbc); } } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PIN) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { - agent.wps_pin = g_strdup(g_variant_get_string(value, NULL)); + wifi_agent->wps_pin = g_strdup(g_variant_get_string(value, NULL)); updated = TRUE; - DBG("Field [%s] - [%s]", (gchar *)field, agent.wps_pin); + DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->wps_pin); } } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_NAME) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { - agent.name = g_strdup(g_variant_get_string(value, NULL)); + wifi_agent->name = g_strdup(g_variant_get_string(value, NULL)); updated = TRUE; - DBG("Field [%s] - [%s]", (gchar *)field, agent.name); + DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->name); } } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_SSID) == 0) { - if (agent.ssid != NULL) { - g_byte_array_free(agent.ssid, TRUE); - agent.ssid = NULL; + if (wifi_agent->ssid != NULL) { + g_byte_array_free(wifi_agent->ssid, TRUE); + wifi_agent->ssid = NULL; } if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) { @@ -265,9 +330,9 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent, g_byte_array_append(array, &char_value, 1); g_variant_iter_free(iter1); if (array != NULL && (array->len > 0)) { - agent.ssid = g_byte_array_sized_new(array->len); - agent.ssid->len = array->len; - memcpy(agent.ssid->data, array->data, array->len); + wifi_agent->ssid = g_byte_array_sized_new(array->len); + wifi_agent->ssid->len = array->len; + memcpy(wifi_agent->ssid->data, array->data, array->len); updated = TRUE; DBG("Field [%s] - []", (gchar *)field); @@ -275,25 +340,25 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent, } } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_IDENTITY) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { - agent.identity = g_strdup(g_variant_get_string(value, NULL)); + wifi_agent->identity = g_strdup(g_variant_get_string(value, NULL)); updated = TRUE; - DBG("Field [%s] - [%s]", (gchar *)field, agent.identity); + DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->identity); } #if defined TIZEN_CAPTIVE_PORTAL } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_USERNAME) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { - agent.username = g_strdup(g_variant_get_string(value, NULL)); + wifi_agent->username = g_strdup(g_variant_get_string(value, NULL)); updated = TRUE; - DBG("Field [%s] - [%s]", (gchar *)field, agent.username); + DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->username); } } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSWORD) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { - agent.password = g_strdup(g_variant_get_string(value, NULL)); + wifi_agent->password = g_strdup(g_variant_get_string(value, NULL)); updated = TRUE; - DBG("Field [%s] - [%s]", (gchar *)field, agent.password); + DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->password); } #endif } @@ -304,10 +369,11 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent, if (updated == TRUE) { reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, service, CONNMAN_SERVICE_INTERFACE, "Connect", - NULL, __netconfig_wifi_connect_reply); + NULL, __netconfig_wifi_connect_reply, + g_strdup(interface_name)); if (reply != TRUE) { ERR("Fail to connect Wi-Fi"); - __netconfig_agent_clear_fields(); + __agent_clear_fields(wifi_agent); error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_AUTH_FAILED, CONNMAN_ERROR_INTERFACE ".InvalidArguments"); @@ -318,7 +384,7 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent, } } else { ERR("Fail to connect Wi-Fi"); - __netconfig_agent_clear_fields(); + __agent_clear_fields(wifi_agent); error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_AUTH_FAILED, @@ -342,6 +408,9 @@ gboolean handle_request_input(NetConnmanAgent *connman_agent, GVariant *out_table = NULL; gboolean updated = FALSE; GVariantBuilder *builder = NULL; + GError *error = NULL; + const char *interface_name = NULL; + netconfig_wifi_agent_s *wifi_agent = NULL; g_return_val_if_fail(connman_agent != NULL, TRUE); @@ -350,72 +419,103 @@ gboolean handle_request_input(NetConnmanAgent *connman_agent, DBG("Agent fields requested for service: %s", service); + interface_name = netconfig_get_ifname(service); + if (interface_name == NULL) { + error = g_error_new(G_DBUS_ERROR, + G_DBUS_ERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidService"); + + g_dbus_method_invocation_return_gerror(context, error); + g_clear_error(&error); + + return TRUE; + } + + wifi_agent = __agent_get_data(interface_name); + if (wifi_agent == NULL) { + error = g_error_new(G_DBUS_ERROR, + G_DBUS_ERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidService"); + + g_dbus_method_invocation_return_gerror(context, error); + g_clear_error(&error); + + return TRUE; + } + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); g_variant_get(fields, "a{sv}", &iter); while (g_variant_iter_loop(iter, "{sv}", &field, &r_value)) { if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0 && - agent.passphrase != NULL) { + wifi_agent->passphrase != NULL) { g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_PASSPHRASE, - g_variant_new_string(agent.passphrase)); + g_variant_new_string(wifi_agent->passphrase)); updated = TRUE; - DBG("Setting [%s] - [%s]", field, agent.passphrase); + DBG("Setting [%s] - [%s]", field, wifi_agent->passphrase); } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS) == 0 && - (agent.wps_pbc == TRUE || agent.wps_pin != NULL)) { - if (agent.wps_pbc == TRUE) { + (wifi_agent->wps_pbc == TRUE || wifi_agent->wps_pin != NULL)) { + if (wifi_agent->wps_pbc == TRUE) { /* Sending empty string for WPS push button method */ - g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS, g_variant_new_string("")); + g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS, + g_variant_new_string("")); updated = TRUE; DBG("Setting empty string for [%s]", field); - } else if (agent.wps_pin != NULL) { - g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS, g_variant_new_string(agent.wps_pin)); + } else if (wifi_agent->wps_pin != NULL) { + g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS, + g_variant_new_string(wifi_agent->wps_pin)); updated = TRUE; - DBG("Setting string [%s] - [%s]", field, agent.wps_pin); + DBG("Setting string [%s] - [%s]", field, wifi_agent->wps_pin); } } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_NAME) == 0 && - agent.name != NULL) { - g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_NAME, g_variant_new_string(agent.name)); + wifi_agent->name != NULL) { + g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_NAME, + g_variant_new_string(wifi_agent->name)); updated = TRUE; - DBG("Settings [%s] - [%s]", field, agent.name); + DBG("Settings [%s] - [%s]", field, wifi_agent->name); } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_SSID) == 0 && - agent.ssid != NULL) { + wifi_agent->ssid != NULL) { int i = 0; GVariantBuilder *builder1 = NULL; builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay")); - for (i = 0; i < (agent.ssid->len); i++) - g_variant_builder_add(builder1, "y", agent.ssid->data[i]); + for (i = 0; i < (wifi_agent->ssid->len); i++) + g_variant_builder_add(builder1, "y", wifi_agent->ssid->data[i]); - g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_SSID, g_variant_builder_end(builder1)); + g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_SSID, + g_variant_builder_end(builder1)); if (builder1 != NULL) g_variant_builder_unref(builder1); updated = TRUE; DBG("Settings [%s] - []", field); } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_IDENTITY) == 0 && - agent.identity != NULL) { - g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_IDENTITY, g_variant_new_string(agent.identity)); + wifi_agent->identity != NULL) { + g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_IDENTITY, + g_variant_new_string(wifi_agent->identity)); updated = TRUE; - DBG("Settings [%s] - [%s]", field, agent.identity); + DBG("Settings [%s] - [%s]", field, wifi_agent->identity); #if defined TIZEN_CAPTIVE_PORTAL } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_USERNAME) == 0 && - agent.username != NULL) { - g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_USERNAME, g_variant_new_string(agent.username)); + wifi_agent->username != NULL) { + g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_USERNAME, + g_variant_new_string(wifi_agent->username)); updated = TRUE; - DBG("Settings [%s] - [%s]", field, agent.username); + DBG("Settings [%s] - [%s]", field, wifi_agent->username); } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSWORD) == 0 && - agent.password != NULL) { - g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_PASSWORD, g_variant_new_string(agent.password)); + wifi_agent->password != NULL) { + g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_PASSWORD, + g_variant_new_string(wifi_agent->password)); updated = TRUE; - DBG("Settings [%s] - [%s]", field, agent.password); + DBG("Settings [%s] - [%s]", field, wifi_agent->password); #endif } } @@ -446,7 +546,7 @@ gboolean handle_request_input(NetConnmanAgent *connman_agent, g_clear_error(&error); } - __netconfig_agent_clear_fields(); + __agent_clear_fields(wifi_agent); return TRUE; } @@ -515,16 +615,18 @@ static gboolean __check_ignore_portal_list(const char * ssid) return FALSE; } -static void __wifi_state_monitor(wifi_service_state_e state, - void *user_data); +static void __wifi_state_monitor(wifi_state_notifier_s *notifier, + char *service, wifi_service_state_e state, void *user_data); -static wifi_state_notifier wifi_state_monitor_notifier = { +static wifi_state_notifier_s wifi_state_monitor_notifier = { + .notifier = NULL, + .service = NULL, .wifi_state_changed = __wifi_state_monitor, .user_data = NULL, }; -static void __wifi_state_monitor(wifi_service_state_e state, - void *user_data) +static void __wifi_state_monitor(wifi_state_notifier_s *notifier, + char *service, wifi_service_state_e state, void *user_data) { DBG("Wi-Fi state: %x", state); @@ -579,7 +681,7 @@ static gboolean __netconfig_wifi_portal_login_timeout(gpointer data) } /* Disconnect and forget the AP */ - service_profile = (char*) netconfig_get_default_profile(); + service_profile = (char *)netconfig_get_default_profile(); if (service_profile && netconfig_is_wifi_profile(service_profile)) { /* Now forget the AP*/ reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, @@ -592,8 +694,8 @@ static gboolean __netconfig_wifi_portal_login_timeout(gpointer data) ERR("Failed to forget the AP "); } } else { - if (NETCONFIG_WIFI_CONNECTED == - wifi_state_get_service_state()) { + if (wifi_state_get_service_state(netconfig_get_default_ifname()) + == NETCONFIG_WIFI_CONNECTED) { /* check Internet availability by sending and receiving data*/ netconfig_check_internet_accessibility(); /* Returning TRUE itself is enough to restart the timer */ diff --git a/src/wifi-background-scan.c b/src/wifi-background-scan.c index 55e7423..ef1dd37 100755 --- a/src/wifi-background-scan.c +++ b/src/wifi-background-scan.c @@ -25,385 +25,117 @@ #include "util.h" #include "netdbus.h" #include "wifi-state.h" +#include "wifi-scan.h" #include "wifi-background-scan.h" -struct bgscan_data { - guint time; - guint mode; - guint timer_id; - gboolean paused; -}; - -static gboolean netconfig_wifi_scanning = FALSE; - -static gboolean __netconfig_wifi_bgscan_next_scan(gpointer data); - -static struct bgscan_data *__netconfig_wifi_bgscan_get_data(void) -{ - static struct bgscan_data data = { - SCAN_EXPONENTIAL_MIN, WIFI_BGSCAN_MODE_EXPONENTIAL, 0, FALSE}; - - return &data; -} - -static gboolean __netconfig_wifi_bgscan_set_mode(guint mode) -{ - if (mode != WIFI_BGSCAN_MODE_EXPONENTIAL && mode != WIFI_BGSCAN_MODE_PERIODIC) { - ERR("Invalid scan mode [%d]", mode); - return FALSE; - } - - struct bgscan_data *data = __netconfig_wifi_bgscan_get_data(); - data->mode = mode; - - return TRUE; -} - -static gboolean _set_scan_reset_interval(guint interval) -{ - if ((interval < SCAN_EXPONENTIAL_MIN) || (interval > SCAN_EXPONENTIAL_MAX)) { - ERR("Invalid interval [%d]", interval); - return FALSE; - } - - struct bgscan_data *data = __netconfig_wifi_bgscan_get_data(); - data->time = interval; - return TRUE; -} - -static guint _get_scan_reset_interval(void) -{ - struct bgscan_data *data = __netconfig_wifi_bgscan_get_data(); - - return data->time;; -} - -static void __netconfig_wifi_scan_request_reply(GObject *source_object, - GAsyncResult *res, gpointer user_data) -{ - GVariant *reply; - GDBusConnection *conn = NULL; - GError *error = NULL; - - conn = G_DBUS_CONNECTION(source_object); - reply = g_dbus_connection_call_finish(conn, res, &error); - - if (reply == NULL) { - if (error != NULL) { - ERR("Fail to request status [%d: %s]", error->code, error->message); - netconfig_wifi_set_scanning(FALSE); - g_error_free(error); - } else { - ERR("Fail to request scan"); - netconfig_wifi_set_scanning(FALSE); - } - } else { - DBG("Successfully requested"); - g_variant_unref(reply); - } - - netconfig_gdbus_pending_call_unref(); -} - -static gboolean __netconfig_wifi_bgscan_request_connman_scan(int retries) -{ - gboolean reply = FALSE; - - netconfig_wifi_set_scanning(TRUE); - - reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, - CONNMAN_WIFI_TECHNOLOGY_PREFIX, - CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL, __netconfig_wifi_scan_request_reply); - if (reply != TRUE) { - ERR("Failed to send Scan request to connman"); - netconfig_wifi_set_scanning(FALSE); - } - - return reply; -} - -static gboolean __netconfig_wifi_bgscan_immediate_scan(gpointer data) -{ - static int retries = 0; - guint state = wifi_state_get_service_state(); - -#if !defined TIZEN_WEARABLE - if (netconfig_wifi_is_bgscan_paused()) { - return FALSE; - } -#endif - if (netconfig_wifi_block_bgscan(-1)) - return FALSE; - - if (state == NETCONFIG_WIFI_CONNECTED) { - if (netconfig_wifi_bgscan_get_mode() == WIFI_BGSCAN_MODE_EXPONENTIAL) { - DBG("Wi-Fi state is connected, scan is paused"); - return FALSE; - } - } else if (state == NETCONFIG_WIFI_ASSOCIATION || state == NETCONFIG_WIFI_CONFIGURATION) { - /* During WIFI connecting, WIFI can be disappeared. - * After 1 sec, try scan even if connecting state */ - if (retries < 2) { - retries++; - return TRUE; - } - } - - if (__netconfig_wifi_bgscan_request_connman_scan(retries) == TRUE) { - retries = 0; - return FALSE; - } else if (retries > 2) { - retries = 0; - return FALSE; - } - - retries++; - - return TRUE; -} - -static void __netconfig_wifi_bgscan_start_timer(gboolean immediate_scan) -{ - struct bgscan_data *data = __netconfig_wifi_bgscan_get_data(); - - netconfig_stop_timer(&(data->timer_id)); - - switch (data->mode) { - case WIFI_BGSCAN_MODE_EXPONENTIAL: - if (data->time < SCAN_EXPONENTIAL_MIN || - data->time == SCAN_PERIODIC_DELAY) - data->time = SCAN_EXPONENTIAL_MIN; - break; - case WIFI_BGSCAN_MODE_PERIODIC: - data->time = SCAN_PERIODIC_DELAY; - break; - default: - DBG("Invalid Wi-Fi background scan mode[%d]", data->mode); - return; - } - - if (immediate_scan) - DBG("Scan immediately[%d], mode[%d](0 exponential / 1 periodic)", immediate_scan, data->mode); - else - DBG("Scan immediately[%d], mode[%d](0 exponential / 1 periodic), next[%d]", immediate_scan, data->mode, data->time); - - if (immediate_scan) - g_timeout_add(500, __netconfig_wifi_bgscan_immediate_scan, NULL); - - netconfig_start_timer_seconds(data->time, - __netconfig_wifi_bgscan_next_scan, data, &(data->timer_id)); - if (data->mode == WIFI_BGSCAN_MODE_EXPONENTIAL && immediate_scan) { - data->time = data->time * 2; - if (data->time > SCAN_EXPONENTIAL_MAX) - data->time = SCAN_EXPONENTIAL_MAX; - } - - //DBG("Scan immediately[%d], mode[%d](0 exponential / 1 periodic), next[%d]", immediate_scan, data->mode, data->time); -} - -static void __netconfig_wifi_bgscan_stop_timer(struct bgscan_data *data) -{ - if (data == NULL) - return; - - netconfig_stop_timer(&(data->timer_id)); -} - -static gboolean __netconfig_wifi_bgscan_next_scan(gpointer data) -{ - int pm_state = VCONFKEY_PM_STATE_NORMAL; - - /* In case of LCD off, we don't need Wi-Fi scan */ - netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state); - if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) - return TRUE; - - __netconfig_wifi_bgscan_start_timer(TRUE); - - return FALSE; -} - -gboolean netconfig_wifi_block_bgscan(int status) -{ - static gboolean blocked = FALSE; - - if (status == 1) - blocked = TRUE; - else if (status == 0) - blocked = FALSE; - - return blocked; -} - -void netconfig_wifi_set_bgscan_pause(gboolean pause) -{ - struct bgscan_data *data = __netconfig_wifi_bgscan_get_data(); - DBG("[%s] Wi-Fi background scan", pause ? "Pause" : "Resume"); - data->paused = pause; -} - -gboolean netconfig_wifi_is_bgscan_paused(void) -{ - struct bgscan_data *data = __netconfig_wifi_bgscan_get_data(); - DBG("Wi-Fi background scan is [%s]", data->paused ? "Paused" : "Runable"); - return data->paused; -} - -void netconfig_wifi_bgscan_start(gboolean immediate_scan) +void netconfig_wifi_bgscan_start(const char *interface_name, gboolean immediate_scan) { wifi_tech_state_e wifi_tech_state; wifi_service_state_e wifi_service_state; - struct bgscan_data *data = - __netconfig_wifi_bgscan_get_data(); - - if (data == NULL) - return; - if (data->timer_id > 0) - __netconfig_wifi_bgscan_stop_timer(data); + if (netconfig_wifi_bgscan_get_timer_id(interface_name) > 0) + netconfig_wifi_bgscan_stop_timer(interface_name); - wifi_tech_state = wifi_state_get_technology_state(FALSE); - wifi_service_state = wifi_state_get_service_state(); - DBG("wifi tech state [%s] service state [%s]", + wifi_tech_state = wifi_state_get_technology_state(interface_name); + wifi_service_state = wifi_state_get_service_state(interface_name); + DBG("[%s] Wi-Fi tech state [%s] service state [%s]", interface_name, _convert_wifi_technology_state_to_string(wifi_tech_state), _convert_wifi_service_state_to_string(wifi_service_state)); if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED) return; - if (data->mode == WIFI_BGSCAN_MODE_EXPONENTIAL && + if (netconfig_wifi_bgscan_get_mode(interface_name) == WIFI_BGSCAN_MODE_EXPONENTIAL && wifi_service_state == NETCONFIG_WIFI_CONNECTED) return; - DBG("Wi-Fi background scan started or re-started(%d)", immediate_scan); - __netconfig_wifi_bgscan_start_timer(immediate_scan); -} - -void netconfig_wifi_bgscan_stop(void) -{ - struct bgscan_data *data = - __netconfig_wifi_bgscan_get_data(); - - if (data == NULL) - return; + DBG("[%s] Wi-Fi background scan started or re-started(%d)", + interface_name, immediate_scan); - DBG("Wi-Fi background scan stop [mode:%d]", data->mode); - - data->time = 0; - - __netconfig_wifi_bgscan_stop_timer(data); + netconfig_wifi_bgscan_start_timer(interface_name, immediate_scan); } -gboolean netconfig_wifi_get_bgscan_state(void) +void netconfig_wifi_bgscan_stop(const char *interface_name) { - struct bgscan_data *data = - __netconfig_wifi_bgscan_get_data(); - return ((data->timer_id > (guint)0) ? TRUE : FALSE); + netconfig_wifi_bgscan_stop_timer(interface_name); } -guint netconfig_wifi_bgscan_get_mode(void) -{ - struct bgscan_data *data = __netconfig_wifi_bgscan_get_data(); - - return data->mode; -} - -gboolean netconfig_wifi_bgscan_set_interval(guint interval) -{ - gboolean ret = FALSE; - - ret = _set_scan_reset_interval(interval); - - return ret; -} - -void netconfig_wifi_bgscan_get_interval(guint *interval) -{ - *interval = _get_scan_reset_interval(); -} - -gboolean netconfig_wifi_get_scanning(void) -{ - return netconfig_wifi_scanning; -} - -void netconfig_wifi_set_scanning(gboolean scanning) -{ - if (netconfig_wifi_scanning != scanning) - netconfig_wifi_scanning = scanning; -} - -gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, guint scan_mode) +gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, guint scan_mode) { gint old_mode = 0; int pm_state = VCONFKEY_PM_STATE_NORMAL; - old_mode = netconfig_wifi_bgscan_get_mode(); + old_mode = netconfig_wifi_bgscan_get_mode(ifname); if (old_mode == scan_mode) { wifi_complete_set_bgscan(wifi, context); return TRUE; } - if (__netconfig_wifi_bgscan_set_mode(scan_mode) != TRUE) { + if (netconfig_wifi_bgscan_set_mode(ifname, scan_mode) != TRUE) { ERR("Invalid mode [%d]", scan_mode); netconfig_error_invalid_parameter(context); return TRUE; } - INFO("scan mode is changed [%d]", scan_mode); + INFO("[%s] Wi-Fi scan mode is changed [%d]", ifname, scan_mode); /* In case of LCD off, we don't need Wi-Fi scan right now */ netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state); if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) - netconfig_wifi_bgscan_start(FALSE); + netconfig_wifi_bgscan_start(ifname, FALSE); else - netconfig_wifi_bgscan_start(TRUE); + netconfig_wifi_bgscan_start(ifname, TRUE); wifi_complete_set_bgscan(wifi, context); return TRUE; } -gboolean handle_resume_bgscan(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_resume_bgscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { - netconfig_wifi_set_bgscan_pause(FALSE); + netconfig_wifi_bgscan_set_pause(ifname, FALSE); wifi_complete_resume_bgscan(wifi, context); return TRUE; } -gboolean handle_pause_bgscan(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_pause_bgscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { - netconfig_wifi_set_bgscan_pause(TRUE); + netconfig_wifi_bgscan_set_pause(ifname, TRUE); wifi_complete_pause_bgscan(wifi, context); return TRUE; } -gboolean handle_reset_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_reset_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { - - _set_scan_reset_interval(SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_set_interval(ifname, SCAN_EXPONENTIAL_MIN); wifi_complete_reset_bgscan_interval(wifi, context); return TRUE; } -gboolean handle_get_autoscan(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_get_autoscan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { gboolean autoscan = 0; - autoscan = netconfig_wifi_is_bgscan_paused(); + autoscan = netconfig_wifi_bgscan_is_paused(ifname); wifi_complete_get_autoscan(wifi, context, autoscan); return TRUE; } -gboolean handle_get_autoscanmode(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_get_autoscanmode(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { guint autoscanmode = 0; - autoscanmode = netconfig_wifi_bgscan_get_mode(); + autoscanmode = netconfig_wifi_bgscan_get_mode(ifname); wifi_complete_get_autoscanmode(wifi, context, autoscanmode); return TRUE; diff --git a/src/wifi-bssid-scan.c b/src/wifi-bssid-scan.c index d5804d5..a7597c0 100755 --- a/src/wifi-bssid-scan.c +++ b/src/wifi-bssid-scan.c @@ -25,6 +25,7 @@ #include "util.h" #include "wifi-power.h" #include "wifi-state.h" +#include "wifi-scan.h" #include "wifi-background-scan.h" #define NETCONFIG_SSID_LEN 32 @@ -33,26 +34,117 @@ #define VCONF_WIFI_ALWAYS_ALLOW_SCANNING \ "file/private/wifi/always_allow_scanning" -static gboolean netconfig_is_bssid_scan_started = FALSE; -static gboolean netconfig_is_device_scanning = FALSE; -static gboolean netconfig_is_bssid_scan_aborted = FALSE; -static int bssid_list_count = 0; -static GSList *bssid_info_list = NULL; - -struct bssid_scan_info_t { +typedef struct { unsigned char ssid[NETCONFIG_SSID_LEN + 1]; unsigned char bssid[NETCONFIG_BSSID_LEN + 1]; int ssid_len; int rssi; int mode; -}; +} bssid_scan_info_s; + +typedef struct { + char *interface_name; + int scan_info_count; + GSList *scan_info_list; +} bssid_scan_data_s; + +static GSList *g_bssid_scan_list = NULL; + +static void __free_bssid_scan_data(gpointer data) +{ + bssid_scan_data_s *scan_data = data; + + g_slist_free_full(scan_data->scan_info_list, g_free); + g_free(scan_data->interface_name); + g_free(scan_data); +} + +static bssid_scan_data_s *__create_bssid_scan_data(const char *interface_name) +{ + bssid_scan_data_s *scan_data; + + scan_data = g_try_new0(bssid_scan_data_s, 1); + if (scan_data == NULL) + return NULL; + + scan_data->interface_name = g_strdup(interface_name); + + g_bssid_scan_list = g_slist_append(g_bssid_scan_list, scan_data); + + return scan_data; +} + +static bssid_scan_data_s *__get_bssid_scan_data(const char *interface_name) +{ + GSList *list = NULL; + bssid_scan_data_s *scan_data = NULL; + + for (list = g_bssid_scan_list; list; list = list->next) { + scan_data = list->data; + if (g_strcmp0(scan_data->interface_name, interface_name) == 0) + return scan_data; + } + + scan_data = __create_bssid_scan_data(interface_name); + return scan_data; +} + +static void __update_bssid_scan_info_count(const char *interface_name, + int mode) +{ + bssid_scan_data_s *scan_data; + + scan_data = __get_bssid_scan_data(interface_name); + if (scan_data == NULL) + return; + + if (mode == 0) + scan_data->scan_info_count--; + else + scan_data->scan_info_count++; +} + +static int __get_bssid_scan_info_count(const char *interface_name) +{ + bssid_scan_data_s *scan_data; -gboolean netconfig_wifi_is_bssid_scan_started(void) + scan_data = __get_bssid_scan_data(interface_name); + if (scan_data == NULL) + return 0; + + return scan_data->scan_info_count; +} + +static void __append_bssid_scan_info(const char *interface_name, + bssid_scan_info_s *scan_info) { - return netconfig_is_bssid_scan_started; + bssid_scan_data_s *scan_data; + + scan_data = __get_bssid_scan_data(interface_name); + if (scan_data == NULL) { + scan_data = g_try_new0(bssid_scan_data_s, 1); + if (scan_data == NULL) + return; + + scan_data->interface_name = g_strdup(interface_name); + } + + scan_data->scan_info_list = g_slist_append(scan_data->scan_info_list, scan_info); } -static void __netconfig_wifi_bssid_notify_scan_done(void) +static void __destroy_bssid_scan_data(const char *interface_name) +{ + bssid_scan_data_s *scan_data; + + scan_data = __get_bssid_scan_data(interface_name); + if (scan_data == NULL) + return; + + g_bssid_scan_list = g_slist_remove(g_bssid_scan_list, scan_data); + __free_bssid_scan_data(scan_data); +} + +static void __netconfig_wifi_bssid_notify_scan_done(const char *interface_name) { GVariantBuilder *builder = NULL; GVariantBuilder *builder1 = NULL; @@ -61,10 +153,16 @@ static void __netconfig_wifi_bssid_notify_scan_done(void) const char *prop_bssid = "bssid"; const char *prop_rssi = "rssi"; const char *prop_mode = "mode"; + bssid_scan_data_s *scan_data = NULL; builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - for (list = bssid_info_list; list != NULL; list = list->next) { - struct bssid_scan_info_t *bss_info = (struct bssid_scan_info_t *)list->data; + + scan_data = __get_bssid_scan_data(interface_name); + if (scan_data == NULL) + goto done; + + for (list = scan_data->scan_info_list; list != NULL; list = list->next) { + bssid_scan_info_s *bss_info = (bssid_scan_info_s *)list->data; if (bss_info) { gchar bssid_buff[18] = { 0, }; @@ -92,14 +190,13 @@ static void __netconfig_wifi_bssid_notify_scan_done(void) } } - wifi_emit_bssid_scan_completed((Wifi *)get_wifi_object(), g_variant_builder_end(builder)); +done: + wifi_emit_bssid_scan_completed((Wifi *)get_wifi_object(), + interface_name, g_variant_builder_end(builder)); g_variant_builder_unref(builder); - if (bssid_info_list != NULL) - g_slist_free_full(bssid_info_list, g_free); + __destroy_bssid_scan_data(interface_name); - bssid_info_list = NULL; - bssid_list_count = 0; INFO("BSSIDScanCompleted"); return; @@ -112,9 +209,10 @@ static void __netconfig_wifi_bssid_get_bss_info_result( GVariant *value; GVariantIter *iter; gchar *key; - struct bssid_scan_info_t *bss_info; + bssid_scan_info_s *bss_info; GDBusConnection *conn = NULL; GError *error = NULL; + char *interface_name = user_data; conn = G_DBUS_CONNECTION(source_object); reply = g_dbus_connection_call_finish(conn, res, &error); @@ -125,7 +223,7 @@ static void __netconfig_wifi_bssid_get_bss_info_result( goto done; } - bss_info = g_try_new0(struct bssid_scan_info_t, 1); + bss_info = g_try_new0(bssid_scan_info_s, 1); if (bss_info == NULL) goto done; @@ -178,7 +276,7 @@ static void __netconfig_wifi_bssid_get_bss_info_result( if (bss_info->ssid[0] == '\0') g_free(bss_info); else - bssid_info_list = g_slist_append(bssid_info_list, bss_info); + __append_bssid_scan_info(interface_name, bss_info); g_variant_iter_free(iter); done: @@ -187,16 +285,19 @@ done: netconfig_gdbus_pending_call_unref(); - bssid_list_count--; - if (bssid_list_count <= 0) { - __netconfig_wifi_bssid_notify_scan_done(); + __update_bssid_scan_info_count(interface_name, 0); + if (__get_bssid_scan_info_count(interface_name) <= 0) { + __netconfig_wifi_bssid_notify_scan_done(interface_name); - if (netconfig_is_bssid_scan_aborted == FALSE) - wifi_power_driver_and_supplicant(FALSE); + if (netconfig_wifi_bssidscan_get_aborted(interface_name) == FALSE) + wifi_power_driver_and_supplicant(interface_name, FALSE); } + + g_free(interface_name); } -static void __netconfig_wifi_bssid_get_bss_info(const char *path, int index) +static void __netconfig_wifi_bssid_get_bss_info(const char *interface_name, + const char *path) { gboolean reply = FALSE; GVariant *param = NULL; @@ -204,8 +305,9 @@ static void __netconfig_wifi_bssid_get_bss_info(const char *path, int index) param = g_variant_new("(s)", SUPPLICANT_IFACE_BSS); reply = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE, - path, DBUS_INTERFACE_PROPERTIES, - "GetAll", param, __netconfig_wifi_bssid_get_bss_info_result); + path, DBUS_INTERFACE_PROPERTIES, "GetAll", param, + __netconfig_wifi_bssid_get_bss_info_result, + g_strdup(interface_name)); if (reply != TRUE) ERR("Fail to invoke_dbus_method_nonblock GetAll"); @@ -222,6 +324,7 @@ static void __netconfig_wifi_bssid_get_bss_result(GObject *source_object, gchar *path = NULL; gboolean counter_flag = FALSE; GError *error = NULL; + char *interface_name = user_data; conn = G_DBUS_CONNECTION(source_object); reply = g_dbus_connection_call_finish(conn, res, &error); @@ -236,7 +339,8 @@ static void __netconfig_wifi_bssid_get_bss_result(GObject *source_object, g_variant_get(value, "ao", &iter); while (g_variant_iter_next(iter, "o", &path)) { if (path != NULL && g_strcmp0(path, "/") != 0) { - __netconfig_wifi_bssid_get_bss_info(path, ++bssid_list_count); + __update_bssid_scan_info_count(interface_name, 1); + __netconfig_wifi_bssid_get_bss_info(interface_name, path); counter_flag = TRUE; } @@ -259,21 +363,23 @@ done: netconfig_gdbus_pending_call_unref(); /* Send BssidScanCompleted signal even when the BSS count is 0 */ - if (bssid_list_count <= 0 && counter_flag == FALSE) { - __netconfig_wifi_bssid_notify_scan_done(); + if (__get_bssid_scan_info_count(interface_name) <= 0 && counter_flag == FALSE) { + __netconfig_wifi_bssid_notify_scan_done(interface_name); - if (netconfig_is_bssid_scan_aborted == FALSE) - wifi_power_driver_and_supplicant(FALSE); + if (netconfig_wifi_bssidscan_get_aborted(interface_name) == FALSE) + wifi_power_driver_and_supplicant(interface_name, FALSE); } + + g_free(interface_name); } -static int _netconfig_wifi_bssid_get_bss(void) +static int _netconfig_wifi_bssid_get_bss(const char *interface_name) { gboolean reply = FALSE; char *if_path = NULL; GVariant *params = NULL; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { DBG("Fail to get wpa_supplicant DBus path"); return -ESRCH; @@ -282,8 +388,9 @@ static int _netconfig_wifi_bssid_get_bss(void) params = g_variant_new("(ss)", SUPPLICANT_IFACE_INTERFACE, "BSSs"); reply = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE, - if_path, DBUS_INTERFACE_PROPERTIES, - "Get", params, __netconfig_wifi_bssid_get_bss_result); + if_path, DBUS_INTERFACE_PROPERTIES, "Get", params, + __netconfig_wifi_bssid_get_bss_result, + g_strdup(interface_name)); g_free(if_path); if (reply != TRUE) { @@ -295,34 +402,21 @@ static int _netconfig_wifi_bssid_get_bss(void) return 0; } - -static void __netconfig_set_bssid_scan_mode(gboolean enable) -{ - if (netconfig_is_bssid_scan_started == enable) - return; - - netconfig_is_bssid_scan_started = enable; -} - -void netconfig_wifi_bssid_signal_scandone(void) +void netconfig_wifi_bssid_signal_scandone(const char *interface_name) { - bssid_list_count = 0; - _netconfig_wifi_bssid_get_bss(); - - netconfig_is_device_scanning = FALSE; + _netconfig_wifi_bssid_get_bss(interface_name); - __netconfig_set_bssid_scan_mode(FALSE); + netconfig_wifi_bssidscan_set_scanning(interface_name, FALSE); + netconfig_wifi_bssidscan_set_mode(interface_name, FALSE); } -void netconfig_wifi_bssid_signal_scanaborted(void) +void netconfig_wifi_bssid_signal_scanaborted(const char *interface_name) { - bssid_list_count = 0; - netconfig_is_bssid_scan_aborted = TRUE; - _netconfig_wifi_bssid_get_bss(); + netconfig_wifi_bssidscan_set_aborted(interface_name, TRUE); + _netconfig_wifi_bssid_get_bss(interface_name); - netconfig_is_device_scanning = FALSE; - - __netconfig_set_bssid_scan_mode(FALSE); + netconfig_wifi_bssidscan_set_scanning(interface_name, FALSE); + netconfig_wifi_bssidscan_set_mode(interface_name, FALSE); } static void __netconfig_wifi_bssid_scan_request_reply(GObject *source_object, @@ -350,7 +444,7 @@ static void __netconfig_wifi_bssid_scan_request_reply(GObject *source_object, netconfig_gdbus_pending_call_unref(); } -static int __netconfig_wifi_bssid_request_scan(char *if_path) +static int __netconfig_wifi_bssid_request_scan(const char *interface_name, char *if_path) { GVariant *message = NULL; GVariantBuilder *builder = NULL; @@ -360,7 +454,7 @@ static int __netconfig_wifi_bssid_request_scan(char *if_path) gboolean reply = FALSE; if (if_path == NULL) { - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); is_free_required = TRUE; } @@ -381,26 +475,24 @@ static int __netconfig_wifi_bssid_request_scan(char *if_path) SUPPLICANT_INTERFACE ".Interface", "Scan", message, - (GAsyncReadyCallback) __netconfig_wifi_bssid_scan_request_reply); + (GAsyncReadyCallback) __netconfig_wifi_bssid_scan_request_reply, + NULL); if (reply != TRUE) { ERR("Fail to Scan"); goto out; } - netconfig_is_device_scanning = TRUE; + netconfig_wifi_bssidscan_set_scanning(interface_name, TRUE); out: if (is_free_required) g_free(if_path); /* Clear bss_info_list for the next scan result */ - if (bssid_info_list) { - g_slist_free_full(bssid_info_list, g_free); - bssid_info_list = NULL; - } + __destroy_bssid_scan_data(interface_name); - netconfig_is_bssid_scan_aborted = FALSE; + netconfig_wifi_bssidscan_set_aborted(interface_name, FALSE); return 0; } @@ -412,6 +504,7 @@ static void __netconfig_wifi_interface_create_result( gchar *path = NULL; GDBusConnection *conn = NULL; GError *error = NULL; + char *interface_name = user_data; conn = G_DBUS_CONNECTION(source_object); @@ -420,40 +513,40 @@ static void __netconfig_wifi_interface_create_result( g_variant_get(message, "(o)", &path); if (path) { - __netconfig_wifi_bssid_request_scan(path); + __netconfig_wifi_bssid_request_scan(interface_name, path); g_free(path); } } else if (NULL != strstr(error->message, ".InterfaceExists")) { INFO("Error Message %s %s", error->message, path); g_variant_get(message, "(o)", &path); if (path) { - __netconfig_wifi_bssid_request_scan(path); + __netconfig_wifi_bssid_request_scan(interface_name, path); g_free(path); } else - __netconfig_wifi_bssid_request_scan(NULL); + __netconfig_wifi_bssid_request_scan(interface_name, NULL); g_error_free(error); } else { ERR("Failed to create interface, Error: %d[%s]", error->code, error->message); - __netconfig_set_bssid_scan_mode(FALSE); - wifi_power_driver_and_supplicant(FALSE); + netconfig_wifi_bssidscan_set_mode(interface_name, FALSE); + wifi_power_driver_and_supplicant(interface_name, FALSE); g_error_free(error); } g_variant_unref(message); + g_free(interface_name); netconfig_gdbus_pending_call_unref(); } -static int __netconfig_wifi_bssid_create_interface(void) +static int __netconfig_wifi_bssid_create_interface(const char *interface_name) { GVariant *message = NULL; GVariantBuilder *builder = NULL; const char *key = "Ifname"; - const char *val = WIFI_IFNAME; gboolean reply = FALSE; builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(builder, "{sv}", key, g_variant_new_string(val)); + g_variant_builder_add(builder, "{sv}", key, g_variant_new_string(interface_name)); message = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); g_variant_builder_unref(builder); @@ -464,7 +557,8 @@ static int __netconfig_wifi_bssid_create_interface(void) SUPPLICANT_INTERFACE, "CreateInterface", message, - (GAsyncReadyCallback) __netconfig_wifi_interface_create_result); + (GAsyncReadyCallback) __netconfig_wifi_interface_create_result, + g_strdup(interface_name)); if (reply != TRUE) ERR("Fail to CreateInterface"); @@ -472,40 +566,41 @@ static int __netconfig_wifi_bssid_create_interface(void) return 0; } -static int __netconfig_wifi_bssid_scan(void) +static int __netconfig_wifi_bssid_scan(const char *interface_name) { int err = 0; wifi_tech_state_e wifi_tech_state; - if (netconfig_is_device_scanning == TRUE) + if (netconfig_wifi_bssidscan_get_scanning(interface_name) == TRUE) return -EINPROGRESS; - wifi_tech_state = wifi_state_get_technology_state(FALSE); + wifi_tech_state = wifi_state_get_technology_state(interface_name); if (wifi_tech_state <= NETCONFIG_WIFI_TECH_OFF) - err = wifi_power_driver_and_supplicant(TRUE); + err = wifi_power_driver_and_supplicant(interface_name, TRUE); if (err < 0 && err != -EALREADY) return err; - netconfig_is_device_scanning = TRUE; + netconfig_wifi_bssidscan_set_scanning(interface_name, TRUE); DBG("BSSID scan requested"); if (wifi_tech_state >= NETCONFIG_WIFI_TECH_POWERED) { - if (netconfig_wifi_get_scanning() == TRUE) + if (netconfig_wifi_scan_get_scanning(interface_name) == TRUE) return -EINPROGRESS; - netconfig_wifi_bgscan_start(TRUE); + netconfig_wifi_bgscan_start(interface_name, TRUE); if (wifi_tech_state == NETCONFIG_WIFI_TECH_CONNECTED) - __netconfig_wifi_bssid_request_scan(NULL); + __netconfig_wifi_bssid_request_scan(interface_name, NULL); } else { - err = __netconfig_wifi_bssid_create_interface(); + err = __netconfig_wifi_bssid_create_interface(interface_name); } return err; } -gboolean handle_request_bssid_scan(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_request_bssid_scan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { int err, enabled = 0; wifi_tech_state_e tech_state; @@ -519,14 +614,14 @@ gboolean handle_request_bssid_scan(Wifi *wifi, GDBusMethodInvocation *context) } #if !defined TIZEN_WEARABLE - if (netconfig_wifi_is_bgscan_paused()) { + if (netconfig_wifi_bgscan_is_paused(ifname)) { ERR("Scan is paused"); netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_NO_SERVICE, "ScanPaused"); return TRUE; } #endif - tech_state = wifi_state_get_technology_state(FALSE); + tech_state = wifi_state_get_technology_state(ifname); if (tech_state <= NETCONFIG_WIFI_TECH_OFF) { #if !defined TIZEN_WEARABLE enabled = 1; @@ -540,9 +635,9 @@ gboolean handle_request_bssid_scan(Wifi *wifi, GDBusMethodInvocation *context) } } - __netconfig_set_bssid_scan_mode(TRUE); + netconfig_wifi_bssidscan_set_mode(ifname, TRUE); - err = __netconfig_wifi_bssid_scan(); + err = __netconfig_wifi_bssid_scan(ifname); if (err < 0) { if (err == -EINPROGRESS) netconfig_error_inprogress(context); @@ -556,9 +651,12 @@ gboolean handle_request_bssid_scan(Wifi *wifi, GDBusMethodInvocation *context) return TRUE; } -gboolean handle_get_bssid_list(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_get_bssid_list(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { - _netconfig_wifi_bssid_get_bss(); + __create_bssid_scan_data(ifname); + _netconfig_wifi_bssid_get_bss(ifname); + wifi_complete_get_bssid_list(wifi, context); return TRUE; } diff --git a/src/wifi-config.c b/src/wifi-config.c index 97b9c6d..d1ee392 100755 --- a/src/wifi-config.c +++ b/src/wifi-config.c @@ -35,6 +35,7 @@ #include "util.h" #include "neterror.h" #include "wifi-config.h" +#include "wifi-state.h" #include "netsupplicant.h" #include "wifi-key-encryption.h" @@ -50,8 +51,9 @@ #define WIFI_PREFIX_LENGTH MAC_ADDRESS_LENGTH + 6 /* wifi_485a3f2f506a_ */ #define PROFILE_PREFIX_LENGTH WIFI_PREFIX_LENGTH + 21 /* /net/connman/service/wifi_485a3f2f506a_ */ -#define WIFI_MAC_ADD_LENGTH 17 -#define WIFI_MAC_ADD_PATH "/sys/class/net/wlan0/address" +#define WIFI_MAC_PATH_LENGTH 64 +#define WIFI_MAC_ADDR_LENGTH 17 +#define WIFI_MAC_ADDR_PATH "/sys/class/net/%s/address" #define NET_DNS_ADDR_MAX 2 @@ -138,42 +140,41 @@ static void __free_wifi_configuration(struct wifi_config *conf) g_free(conf); } -static gboolean __get_mac_address(gchar **mac_address) +static gboolean __get_mac_address(const gchar *interface_name, gchar **mac_address) { + FILE *fp = NULL; + char buf[WIFI_MAC_ADDR_LENGTH + 1]; + char path[WIFI_MAC_PATH_LENGTH]; gchar *tmp_mac = NULL; gchar *tmp = NULL; gchar mac[13] = { 0, }; gint i = 0, j = 0; - if (TIZEN_TV) { - FILE *fp = NULL; - char buf[WIFI_MAC_ADD_LENGTH + 1]; - if (0 == access(WIFI_MAC_ADD_PATH, F_OK)) - fp = fopen(WIFI_MAC_ADD_PATH, "r"); + snprintf(path, WIFI_MAC_PATH_LENGTH, WIFI_MAC_ADDR_PATH, interface_name); - if (fp == NULL) { - ERR("Failed to open file %s\n", WIFI_MAC_ADD_PATH); - *mac_address = NULL; - return FALSE; - } + if (0 == access(path, F_OK)) + fp = fopen(path, "r"); + if (fp) { if (fgets(buf, sizeof(buf), fp) == NULL) { - ERR("Failed to get MAC info from %s\n", WIFI_MAC_ADD_PATH); + ERR("Failed to get MAC info from %s\n", path); *mac_address = NULL; fclose(fp); return FALSE; } - tmp_mac = (gchar *)malloc(WIFI_MAC_ADD_LENGTH + 1); + tmp_mac = (gchar *)malloc(WIFI_MAC_ADDR_LENGTH + 1); if (tmp_mac == NULL) { ERR("malloc() failed"); *mac_address = NULL; fclose(fp); return FALSE; } - memset(tmp_mac, 0, WIFI_MAC_ADD_LENGTH + 1); - g_strlcpy(tmp_mac, buf, WIFI_MAC_ADD_LENGTH + 1); + memset(tmp_mac, 0, WIFI_MAC_ADDR_LENGTH + 1); + g_strlcpy(tmp_mac, buf, WIFI_MAC_ADDR_LENGTH + 1); fclose(fp); } else { + ERR("Failed to open file %s\n", path); + tmp_mac = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS); if (tmp_mac == NULL) { ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed"); @@ -181,6 +182,7 @@ static gboolean __get_mac_address(gchar **mac_address) return FALSE; } } + tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac)); free(tmp_mac); while (tmp && tmp[i]) { @@ -195,13 +197,14 @@ static gboolean __get_mac_address(gchar **mac_address) return TRUE; } -gboolean wifi_config_get_group_name(const gchar *prefix, const gchar *config_id, gchar **group_name) +gboolean wifi_config_get_group_name(const gchar *prefix, + const gchar *interface_name, const gchar *config_id, gchar **group_name) { gchar *mac_address = NULL; gchar *g_name = NULL; gboolean ret = FALSE; - ret = __get_mac_address(&mac_address); + ret = __get_mac_address(interface_name, &mac_address); if ((ret != TRUE) || (strlen(mac_address) == 0)) { ERR("Cannot get WIFI MAC address"); g_free(mac_address); @@ -306,14 +309,16 @@ static gboolean __remove_configuration(const gchar *pathname) return TRUE; } -static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config) +static gboolean _load_configuration(const gchar *interface_name, + const gchar *config_id, struct wifi_config *config) { GKeyFile *keyfile; gchar *group_name; gboolean hidden = FALSE; gboolean ret = FALSE; - ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, + interface_name, config_id, &group_name); if (ret != TRUE) { ERR("Fail to get_wifi_config_group_name"); return FALSE; @@ -454,14 +459,16 @@ static gboolean _load_configuration(const gchar *config_id, struct wifi_config * return TRUE; } -gboolean wifi_config_save_configuration(const gchar *config_id, GKeyFile *keyfile) +gboolean wifi_config_save_configuration(const gchar *interface_name, + const gchar *config_id, GKeyFile *keyfile) { gchar *dir; gchar *path; gchar *group_name; gboolean ret = FALSE; - ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, + interface_name, config_id, &group_name); if (ret != TRUE) { ERR("Fail to get_wifi_config_group_name"); return FALSE; @@ -493,13 +500,14 @@ gboolean wifi_config_save_configuration(const gchar *config_id, GKeyFile *keyfil return TRUE; } -static gboolean _remove_configuration(const gchar *config_id) +static gboolean _remove_configuration(const gchar *interface_name, const gchar *config_id) { gboolean ret = FALSE; gchar *dir; gchar *group_name; - ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, + interface_name, config_id, &group_name); if (ret != TRUE) { ERR("Fail to get_wifi_config_group_name"); return FALSE; @@ -525,13 +533,15 @@ static gboolean _remove_configuration(const gchar *config_id) } -static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value) +static gboolean _set_field(const gchar *interface_name, + const gchar *config_id, const gchar *key, const gchar *value) { gboolean ret = TRUE; GKeyFile *keyfile; gchar *group_name; - ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, + interface_name, config_id, &group_name); if (ret != TRUE) { ERR("Fail to get_wifi_config_group_name"); return FALSE; @@ -575,7 +585,7 @@ static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar ret = FALSE; } - wifi_config_save_configuration(config_id, keyfile); + wifi_config_save_configuration(interface_name, config_id, keyfile); g_key_file_free(keyfile); g_free(group_name); @@ -583,7 +593,8 @@ static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar return ret; } -static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value) +static gboolean _get_field(const gchar *interface_name, + const gchar *config_id, const gchar *key, gchar **value) { GKeyFile *keyfile; gchar *group_name; @@ -591,7 +602,8 @@ static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **val gboolean hidden = FALSE; gboolean ret = FALSE; - ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, + interface_name, config_id, &group_name); if (ret != TRUE) { ERR("Fail to get_wifi_config_group_name"); return FALSE; @@ -649,7 +661,7 @@ static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **val return TRUE; } -static GSList *_get_list(void) +static GSList *_get_list(const char *mac_addr) { GSList *list = NULL; struct dirent *dp = NULL; @@ -666,9 +678,15 @@ static GSList *_get_list(void) strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) { continue; } - gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH); - list = g_slist_append(list, g_strdup(config_id)); - g_free(config_id); + + DBG("%s", dp->d_name); + + if (netconfig_check_mac_address(dp->d_name, mac_addr)) { + gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH); + DBG("%s", config_id); + list = g_slist_append(list, g_strdup(config_id)); + g_free(config_id); + } } closedir(dir); @@ -692,11 +710,12 @@ gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_ return ret; } -gboolean wifi_config_remove_configuration(const gchar *config_id) +gboolean wifi_config_remove_configuration(const gchar *interface_name, + const gchar *config_id) { gboolean ret = FALSE; - ret = _remove_configuration(config_id); + ret = _remove_configuration(interface_name, config_id); return ret; } @@ -819,7 +838,7 @@ static int __netconfig_unpack_ay_malloc(unsigned char **dst, GVariantIter *iter) return length; } -gboolean _add_vsie(int frame_id, const char* vsie) +gboolean _add_vsie(const char *interface_name, int frame_id, const char* vsie) { GVariant *params = NULL; GVariant *message = NULL; @@ -863,8 +882,7 @@ gboolean _add_vsie(int frame_id, const char* vsie) params = g_variant_new("(iay)", frame_id, bytearray_builder); g_variant_builder_unref(bytearray_builder); - if_path = netconfig_wifi_get_supplicant_interface(); - + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { ERR("Fail to get wpa_supplicant DBus path"); g_free(bytearray); @@ -887,7 +905,7 @@ gboolean _add_vsie(int frame_id, const char* vsie) return TRUE; } -gboolean _get_vsie(int frame_id, char **vsie) +gboolean _get_vsie(const char *interface_name, int frame_id, char **vsie) { GVariant *params = NULL; GVariant *message = NULL; @@ -898,7 +916,7 @@ gboolean _get_vsie(int frame_id, char **vsie) return FALSE; } - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { ERR("Fail to get wpa_supplicant DBus path"); return FALSE; @@ -947,7 +965,7 @@ gboolean _get_vsie(int frame_id, char **vsie) } -gboolean _remove_vsie(int frame_id, const char *vsie) +gboolean _remove_vsie(const char *interface_name, int frame_id, const char *vsie) { GVariant *params = NULL; GVariant *message = NULL; @@ -991,7 +1009,7 @@ gboolean _remove_vsie(int frame_id, const char *vsie) params = g_variant_new("(iay)", frame_id, bytearray_builder); g_variant_builder_unref(bytearray_builder); - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { ERR("Fail to get wpa_supplicant DBus path"); g_free(bytearray); @@ -1015,16 +1033,20 @@ gboolean _remove_vsie(int frame_id, const char *vsie) } /* dbus method */ -gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { guint i = 0; GSList *config_ids = NULL; guint length; gchar **result = NULL; + const gchar *mac_addr = NULL; g_return_val_if_fail(wifi != NULL, TRUE); - config_ids = _get_list(); + mac_addr = wifi_state_get_mac_address(ifname); + DBG("%s", mac_addr); + config_ids = _get_list(mac_addr); if (config_ids == NULL) { ERR("Fail to get config list"); netconfig_error_no_profile(context); @@ -1054,7 +1076,7 @@ gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context) } gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *config_id) + const gchar *ifname, const gchar *config_id) { gboolean ret = FALSE; GVariantBuilder *b = NULL; @@ -1065,7 +1087,7 @@ gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context, conf = g_new0(struct wifi_config, 1); conf->ip_info = g_new0(wifi_ip_info_s, 1); - ret = _load_configuration(config_id, conf); + ret = _load_configuration(ifname, config_id, conf); if (ret != TRUE) { g_free(conf->ip_info); g_free(conf); @@ -1118,6 +1140,8 @@ gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context, __free_wifi_configuration(conf); + INFO("Success to load configuration [%s:%s]", ifname, config_id); + wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b)); g_variant_builder_unref(b); return TRUE; @@ -1148,7 +1172,7 @@ static unsigned char __netconfig_convert_netmask_to_prefixlen( } gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *config_id, GVariant *configuration) + const gchar *ifname, const gchar *config_id, GVariant *configuration) { gboolean ret = FALSE; struct wifi_config *conf = NULL; @@ -1268,7 +1292,8 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, conf->favorite = TRUE; conf->autoconnect = TRUE; - ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, + ifname, config_id, &group_name); if (ret != TRUE) { __free_wifi_configuration(conf); ERR("Fail to get_wifi_config_group_name"); @@ -1378,7 +1403,7 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, i += 1; } - ret = wifi_config_save_configuration(config_id, keyfile); + ret = wifi_config_save_configuration(ifname, config_id, keyfile); if (ret == TRUE) { INFO("Success to save configuration [%s]", config_id); wifi_complete_save_configuration(wifi, context); @@ -1412,7 +1437,7 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, } gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *config_id) + const gchar *ifname, const gchar *config_id) { gboolean ret = FALSE; GVariantBuilder *b = NULL; @@ -1424,7 +1449,7 @@ gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex conf->eap_config = g_new0(struct wifi_eap_config, 1); conf->ip_info = g_new0(wifi_ip_info_s, 1); - ret = _load_configuration(config_id, conf); + ret = _load_configuration(ifname, config_id, conf); if (ret != TRUE) { g_free(conf->eap_config); g_free(conf->ip_info); @@ -1503,7 +1528,7 @@ gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex } gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *config_id, GVariant *configuration) + const gchar *ifname, const gchar *config_id, GVariant *configuration) { gboolean ret = FALSE; struct wifi_config *conf = NULL; @@ -1634,7 +1659,8 @@ gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex conf->favorite = TRUE; conf->autoconnect = TRUE; - ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + ret = wifi_config_get_group_name(WIFI_CONFIG_PREFIX, + ifname, config_id, &group_name); if (ret != TRUE) { __free_wifi_configuration(conf); ERR("Fail to get_wifi_config_group_name"); @@ -1714,7 +1740,7 @@ gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, conf->eap_config->subject_match); - ret = wifi_config_save_configuration(config_id, keyfile); + ret = wifi_config_save_configuration(ifname, config_id, keyfile); if (ret == TRUE) { INFO("Success to save eap configuration [%s]", config_id); wifi_complete_save_eap_configuration(wifi, context); @@ -1732,7 +1758,8 @@ gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex return TRUE; } -gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id) +gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id) { gboolean ret = FALSE; @@ -1742,7 +1769,7 @@ gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, return TRUE; } - ret = _remove_configuration(config_id); + ret = _remove_configuration(ifname, config_id); if (ret != TRUE) { /* no configuration or error */ ERR("No [%s] configuration", config_id); @@ -1775,7 +1802,7 @@ gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, * Proxy.Servers=trst.com:8888; (O) */ gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *config_id, const gchar *key, const gchar *value) + const gchar *ifname, const gchar *config_id, const gchar *key, const gchar *value) { gboolean ret = FALSE; gchar *keyfile_key = NULL; @@ -1787,7 +1814,7 @@ gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, DBG("Key[%s] Value[%s]", key, value); if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) { - ret = _set_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual"); + ret = _set_field(ifname, config_id, WIFI_CONFIG_PROXY_METHOD, "manual"); if (!ret) { ERR("Fail to [%s]set_wifi_config_field(%s/manual)", config_id, WIFI_CONFIG_PROXY_METHOD); netconfig_error_invalid_parameter(context); @@ -1818,7 +1845,7 @@ gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, return TRUE; } - ret = _set_field(config_id, keyfile_key, (const gchar *)value); + ret = _set_field(ifname, config_id, keyfile_key, (const gchar *)value); if (!ret) { ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value); } @@ -1830,7 +1857,8 @@ gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, return TRUE; } -gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id) +gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *config_id) { gboolean ret = FALSE; gchar *passphrase = NULL; @@ -1841,7 +1869,7 @@ gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context return TRUE; } - ret = _get_field(config_id, WIFI_CONFIG_PASSPHRASE, &passphrase); + ret = _get_field(ifname, config_id, WIFI_CONFIG_PASSPHRASE, &passphrase); if (!ret) { ERR("Fail to [%s] _get_field(%s)", config_id, WIFI_CONFIG_PASSPHRASE); netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed"); @@ -1855,7 +1883,7 @@ gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context } gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context, - int frame_id, const gchar *vsie) + const gchar *ifname, int frame_id, const gchar *vsie) { DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie); @@ -1864,7 +1892,7 @@ gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context, gboolean ret = FALSE; - ret = _add_vsie(frame_id, vsie); + ret = _add_vsie(ifname, frame_id, vsie); if (!ret) { DBG("Failed to add vsie: %s", vsie); netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed"); @@ -1876,7 +1904,7 @@ gboolean handle_add_vsie(Wifi *wifi, GDBusMethodInvocation *context, } gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context, - int frame_id) + const gchar *ifname, int frame_id) { DBG("Frame ID: [%d]", frame_id); @@ -1885,7 +1913,7 @@ gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context, gboolean ret = FALSE; gchar *vsie = NULL; - ret = _get_vsie(frame_id, &vsie); + ret = _get_vsie(ifname, frame_id, &vsie); if (!ret) { DBG("Failed to get vsie for frame:[%d]", frame_id); netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed"); @@ -1899,7 +1927,7 @@ gboolean handle_get_vsie(Wifi *wifi, GDBusMethodInvocation *context, } gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context, - int frame_id, const gchar *vsie) + const gchar *ifname, int frame_id, const gchar *vsie) { DBG("Frame ID: [%d] VSIE: [%s]", frame_id, vsie); @@ -1908,7 +1936,7 @@ gboolean handle_remove_vsie(Wifi *wifi, GDBusMethodInvocation *context, gboolean ret = FALSE; - ret = _remove_vsie(frame_id, vsie); + ret = _remove_vsie(ifname, frame_id, vsie); if (!ret) { DBG("Failed to remove vsie: %s", vsie); netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "OperationFailed"); diff --git a/src/wifi-dpp.c b/src/wifi-dpp.c old mode 100644 new mode 100755 index c7b0c58..1133191 --- a/src/wifi-dpp.c +++ b/src/wifi-dpp.c @@ -228,7 +228,7 @@ static char *__netconfig_dpp_get_supplicant_interface() if (if_path) return if_path; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(NULL); return if_path; } @@ -802,7 +802,7 @@ static gboolean __netconfig_wifi_dpp_invoke_connman_scan() return netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL, - __wifi_dpp_connman_scan_request_reply); + __wifi_dpp_connman_scan_request_reply, NULL); } @@ -815,7 +815,7 @@ static gboolean __netconfig_wifi_invoke_flush_bss() DBG("[TizenMW-->WPAS]: Wi-Fi Flush BSS Request: "); - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(NULL); if (if_path == NULL) { ERR("Fail to get wpa_supplicant DBus path"); return FALSE; @@ -1433,7 +1433,8 @@ gboolean __save_credentials(GKeyFile *keyfile, gchar *group_name, wifi_dpp_conf_ } -static gboolean __save_configuration_object(wifi_dpp_conf_obj *conf_obj) +static gboolean __save_configuration_object(const char *interface_name, + wifi_dpp_conf_obj *conf_obj) { gchar ssid_hex[65] = {0,}; gchar *config_id = NULL; @@ -1457,7 +1458,7 @@ static gboolean __save_configuration_object(wifi_dpp_conf_obj *conf_obj) netconfig_convert_bytes_to_hexstr(conf_obj->ssid, strlen(conf_obj->ssid), ssid_hex); config_id = g_strdup_printf("%s_managed_%s", ssid_hex, conf_obj->akm); - ret = wifi_config_get_group_name("wifi_", config_id, &group_name); + ret = wifi_config_get_group_name("wifi_", interface_name, config_id, &group_name); if (!ret) { ERR("Failed to get Wi-Fi config group name"); g_free(config_id); @@ -1478,7 +1479,7 @@ static gboolean __save_configuration_object(wifi_dpp_conf_obj *conf_obj) g_key_file_set_boolean(keyfile, group_name, "Favorite", TRUE); g_key_file_set_boolean(keyfile, group_name, "AutoConnect", TRUE); - ret = wifi_config_save_configuration(config_id, keyfile); + ret = wifi_config_save_configuration(interface_name, config_id, keyfile); if (ret == TRUE) INFO("Success to save configuration [%s]", config_id); else @@ -1492,7 +1493,7 @@ static gboolean __save_configuration_object(wifi_dpp_conf_obj *conf_obj) } -void netconfig_wifi_dpp_conf_obj_event(GVariant *message) +void netconfig_wifi_dpp_conf_obj_event(const char *interface_name, GVariant *message) { GVariantIter *iter = NULL; gchar *key = NULL; @@ -1522,7 +1523,7 @@ void netconfig_wifi_dpp_conf_obj_event(GVariant *message) g_variant_get(value, "&s", &conf_obj.net_access_key); } - if (!__save_configuration_object(&conf_obj) || !__netconfig_wifi_invoke_flush_bss()) { + if (!__save_configuration_object(interface_name, &conf_obj) || !__netconfig_wifi_invoke_flush_bss()) { g_variant_iter_free(iter); __netconfig_wifi_dpp_notify_dpp_failed(p_dpp_info); return; diff --git a/src/wifi-eap-config.c b/src/wifi-eap-config.c index e085183..3abd475 100755 --- a/src/wifi-eap-config.c +++ b/src/wifi-eap-config.c @@ -29,6 +29,7 @@ #include "wifi-state.h" #include "wifi-config.h" #include "wifi-eap-config.h" +#include "network-state.h" #include "neterror.h" #define CONNMAN_CONFIG_FIELD_TYPE "Type" @@ -358,7 +359,7 @@ out: return updated; } -static gboolean _delete_configuration(const gchar *profile) +static gboolean _delete_configuration(const char *interface_name, const char *profile) { gboolean ret = FALSE; gchar *config_id = NULL; @@ -370,7 +371,7 @@ static gboolean _delete_configuration(const gchar *profile) } ERR("get config_id [%s] from [%s]", config_id, profile); - ret = wifi_config_remove_configuration(config_id); + ret = wifi_config_remove_configuration(interface_name, config_id); if (ret != TRUE) ERR("Fail to wifi_config_remove_configuration [%s]", config_id); @@ -388,13 +389,20 @@ static gboolean __netconfig_delete_config(const char *profile) char *ssid = NULL; int ssid_len = 0; int err = 0; + const char *interface_name = NULL; if (NULL == profile) { ERR("Invalid profile name"); return FALSE; } - if (_delete_configuration(profile) != TRUE) + interface_name = netconfig_get_ifname(profile); + if (interface_name == NULL) { + ERR("Invalid profile name"); + return FALSE; + } + + if (_delete_configuration(interface_name, profile) != TRUE) ERR("Fail to delete configuration [%s]", profile); wifi_ident = strstr(profile, "wifi_"); @@ -434,21 +442,17 @@ static gboolean __netconfig_delete_config(const char *profile) return TRUE; } -static void __netconfig_eap_state( - wifi_service_state_e state, void *user_data); - -static wifi_state_notifier netconfig_eap_notifier = { - .wifi_state_changed = __netconfig_eap_state, - .user_data = NULL, -}; - -static void __netconfig_eap_state( - wifi_service_state_e state, void *user_data) +static void __netconfig_eap_state(wifi_state_notifier_s *notifier, + char *service, wifi_service_state_e state, void *user_data) { - const char *wifi_profile = (const char *)user_data; + if (notifier == NULL) + return; - if (wifi_profile == NULL) { - wifi_state_notifier_unregister(&netconfig_eap_notifier); + if (service == NULL) { + wifi_state_notifier_unregister(notifier); + g_free(notifier->service); + g_free(notifier->user_data); + g_free(notifier); return; } @@ -456,12 +460,12 @@ static void __netconfig_eap_state( return; if (state == NETCONFIG_WIFI_FAILURE) - __netconfig_delete_config(wifi_profile); - - g_free(netconfig_eap_notifier.user_data); - netconfig_eap_notifier.user_data = NULL; + __netconfig_delete_config(service); - wifi_state_notifier_unregister(&netconfig_eap_notifier); + wifi_state_notifier_unregister(notifier); + g_free(notifier->service); + g_free(notifier->user_data); + g_free(notifier->service); } gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context, @@ -469,13 +473,23 @@ gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context, { gboolean updated = FALSE; gboolean result = FALSE; + wifi_state_notifier_s *state_notifier = NULL; + const char *interface_name = NULL; g_return_val_if_fail(wifi != NULL, TRUE); DBG("Set agent fields for %s", service); if (netconfig_is_wifi_profile(service) != TRUE) { - netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_WRONG_PROFILE, "InvalidService"); + netconfig_error_dbus_method_return(context, + NETCONFIG_ERROR_WRONG_PROFILE, "InvalidService"); + return TRUE; + } + + interface_name = netconfig_get_ifname(service); + if (interface_name == NULL) { + netconfig_error_dbus_method_return(context, + NETCONFIG_ERROR_WRONG_PROFILE, "InvalidService"); return TRUE; } @@ -503,25 +517,24 @@ gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context, passphrase = (const char *)value; } - netconfig_wifi_set_agent_field_for_eap_network( - name, identity, passphrase); + netconfig_wifi_set_agent_field_for_eap_network(interface_name, + name, identity, passphrase); g_variant_iter_free(iter); } result = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, service, CONNMAN_SERVICE_INTERFACE, "Connect", - NULL, __netconfig_wifi_connect_reply); - - if (netconfig_eap_notifier.user_data != NULL) { - g_free(netconfig_eap_notifier.user_data); - netconfig_eap_notifier.user_data = NULL; - - wifi_state_notifier_unregister(&netconfig_eap_notifier); + NULL, __netconfig_wifi_connect_reply, + g_strdup(interface_name)); + + state_notifier = g_try_malloc0(sizeof(wifi_state_notifier_s)); + if (state_notifier) { + state_notifier->notifier = state_notifier; + state_notifier->service = g_strdup(service); + state_notifier->wifi_state_changed = __netconfig_eap_state; + wifi_state_notifier_register(state_notifier); } - - netconfig_eap_notifier.user_data = g_strdup(service); - wifi_state_notifier_register(&netconfig_eap_notifier); } else { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments"); } @@ -537,9 +550,9 @@ gboolean handle_delete_eap_config(Wifi *wifi, GDBusMethodInvocation *context, { g_return_val_if_fail(wifi != NULL, TRUE); - wifi_complete_delete_eap_config(wifi, context); + __netconfig_delete_config(profile); - __netconfig_delete_config((const char *)profile); + wifi_complete_delete_eap_config(wifi, context); return TRUE; } diff --git a/src/wifi-eap.c b/src/wifi-eap.c index 48fb5a5..9c6fea6 100755 --- a/src/wifi-eap.c +++ b/src/wifi-eap.c @@ -179,8 +179,8 @@ EXPORT_SYM void netconfig_complete_get_sim_auth(void *wifi, GDBusMethodInvocatio EXPORT_SYM void netconfig_wifi_power_on() { #if defined TIZEN_WEARABLE - wifi_power_on_wearable(TRUE); + wifi_power_on_wearable(NULL, TRUE); #else - wifi_power_on(); + wifi_power_on(NULL); #endif } diff --git a/src/wifi-extension.c b/src/wifi-extension.c index 3a75642..faceb7e 100755 --- a/src/wifi-extension.c +++ b/src/wifi-extension.c @@ -33,7 +33,8 @@ #include "wifi-extension.h" -gboolean handle_flush_bss(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_flush_bss(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { DBG("Wi-Fi flush bss"); @@ -42,7 +43,7 @@ gboolean handle_flush_bss(Wifi *wifi, GDBusMethodInvocation *context) GDBusConnection *connection = NULL; char *if_path = NULL; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(ifname); if (if_path == NULL) { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailFlushBss"); DBG("Fail to get wpa_supplicant DBus path"); diff --git a/src/wifi-firmware.c b/src/wifi-firmware.c index 0c3118f..284973c 100755 --- a/src/wifi-firmware.c +++ b/src/wifi-firmware.c @@ -33,27 +33,23 @@ #include "network-statistics.h" #define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh" -#define WLAN_IFACE_NAME "wlan0" -#define WLAN_P2P_IFACE_NAME_TV "p2p0" -#define WLAN_P2P_IFACE_NAME_COMMON "wlan0" -#define WLAN_P2P_IFACE_NAME ((TIZEN_TV) ? (WLAN_P2P_IFACE_NAME_TV) : (WLAN_P2P_IFACE_NAME_COMMON)) #define QUAD_CPUS_COUNT 4 #define TEMP_BUFFER_LEN 100 #define WIFI_MAC_ADD_PATH "/sys/class/net/wlan0/address" -static int __netconfig_sta_firmware_start(void) +static int __netconfig_sta_firmware_start(const char *interface_name) { int rv = 0; const char *path = WLAN_DRIVER_SCRIPT; - char *const args[] = { "/usr/bin/wlan.sh", "start", NULL }; + char *const args[] = { "/usr/bin/wlan.sh", "start", (char *)interface_name, NULL }; char *const envs[] = { NULL }; rv = netconfig_execute_file(path, args, envs); if (rv < 0) return -EIO; - rv = netconfig_interface_up(WLAN_IFACE_NAME); + rv = netconfig_interface_up(interface_name); if (rv != TRUE) return -EIO; @@ -61,17 +57,17 @@ static int __netconfig_sta_firmware_start(void) return 0; } -static int __netconfig_sta_firmware_stop(void) +static int __netconfig_sta_firmware_stop(const char *interface_name) { int rv = 0; const char *path = WLAN_DRIVER_SCRIPT; - char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const args[] = { "/usr/bin/wlan.sh", "stop", (char *)interface_name, NULL }; char *const envs[] = { NULL }; /* Update statistics before driver remove */ netconfig_wifi_statistics_update_powered_off(); - rv = netconfig_interface_down(WLAN_IFACE_NAME); + rv = netconfig_interface_down(interface_name); if (rv != TRUE) return -EIO; @@ -83,14 +79,14 @@ static int __netconfig_sta_firmware_stop(void) return 0; } -static int __netconfig_p2p_firmware_start(void) +static int __netconfig_p2p_firmware_start(const char *interface_name) { if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) return -ENODEV; int rv = 0; const char *path = WLAN_DRIVER_SCRIPT; - char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL }; + char *const args[] = { "/usr/bin/wlan.sh", "p2p", (char *)interface_name, NULL }; char *const envs[] = { NULL }; rv = netconfig_execute_file(path, args, envs); @@ -98,7 +94,7 @@ static int __netconfig_p2p_firmware_start(void) return -EIO; #if defined TIZEN_WLAN_USE_P2P_INTERFACE - rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME); + rv = netconfig_interface_up(interface_name); if (rv != TRUE) return -EIO; #endif @@ -107,17 +103,17 @@ static int __netconfig_p2p_firmware_start(void) return 0; } -static int __netconfig_p2p_firmware_stop(void) +static int __netconfig_p2p_firmware_stop(const char *interface_name) { if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) return -ENODEV; int rv = 0; const char *path = WLAN_DRIVER_SCRIPT; - char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const args[] = { "/usr/bin/wlan.sh", "stop", (char *)interface_name, NULL }; char *const envs[] = { NULL }; - rv = netconfig_interface_down(WLAN_IFACE_NAME); + rv = netconfig_interface_down(interface_name); if (rv != TRUE) return -EIO; @@ -129,7 +125,7 @@ static int __netconfig_p2p_firmware_stop(void) return 0; } -static int __netconfig_softap_firmware_start(void) +static int __netconfig_softap_firmware_start(const char *interface_name) { if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING) && !netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_SOFTAP)) @@ -137,21 +133,21 @@ static int __netconfig_softap_firmware_start(void) int rv = 0; const char *path = WLAN_DRIVER_SCRIPT; - char *const args[] = { "/usr/bin/wlan.sh", "softap", NULL }; + char *const args[] = { "/usr/bin/wlan.sh", "softap", (char *)interface_name, NULL }; char *const envs[] = { NULL }; rv = netconfig_execute_file(path, args, envs); if (rv < 0) return -EIO; - if (netconfig_interface_up(WLAN_IFACE_NAME) == FALSE) + if (netconfig_interface_up(interface_name) == FALSE) return -EIO; DBG("Successfully loaded softap device driver"); return 0; } -static int __netconfig_softap_firmware_stop(void) +static int __netconfig_softap_firmware_stop(const char *interface_name) { if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING) && !netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_SOFTAP)) @@ -159,10 +155,10 @@ static int __netconfig_softap_firmware_stop(void) int rv = 0; const char *path = WLAN_DRIVER_SCRIPT; - char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const args[] = { "/usr/bin/wlan.sh", "stop", (char *)interface_name, NULL }; char *const envs[] = { NULL }; - rv = netconfig_interface_down(WLAN_IFACE_NAME); + rv = netconfig_interface_down(interface_name); if (rv != TRUE) return -EIO; @@ -174,18 +170,19 @@ static int __netconfig_softap_firmware_stop(void) return 0; } -static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type) +static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type, + const char *interface_name) { if (emulator_is_emulated() == TRUE) return -EIO; switch (type) { case NETCONFIG_WIFI_STA: - return __netconfig_sta_firmware_start(); + return __netconfig_sta_firmware_start(interface_name); case NETCONFIG_WIFI_P2P: - return __netconfig_p2p_firmware_start(); + return __netconfig_p2p_firmware_start(interface_name); case NETCONFIG_WIFI_SOFTAP: - return __netconfig_softap_firmware_start(); + return __netconfig_softap_firmware_start(interface_name); default: break; } @@ -193,18 +190,19 @@ static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type) return -ENXIO; } -static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type) +static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type, + const char *interface_name) { if (emulator_is_emulated() == TRUE) return -EIO; switch (type) { case NETCONFIG_WIFI_STA: - return __netconfig_sta_firmware_stop(); + return __netconfig_sta_firmware_stop(interface_name); case NETCONFIG_WIFI_P2P: - return __netconfig_p2p_firmware_stop(); + return __netconfig_p2p_firmware_stop(interface_name); case NETCONFIG_WIFI_SOFTAP: - return __netconfig_softap_firmware_stop(); + return __netconfig_softap_firmware_stop(interface_name); default: break; } @@ -212,7 +210,7 @@ static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type) return -ENXIO; } -static int __netconfig_set_rps_cpus(void) +static int __netconfig_set_rps_cpus(const char *interface_name) { int fd, curr; ssize_t count; @@ -226,7 +224,9 @@ static int __netconfig_set_rps_cpus(void) DBG("WiFi driver loaded... "); } - snprintf(t_buf, TEMP_BUFFER_LEN, "/sys/class/net/wlan0/queues/rx-0/rps_cpus"); + snprintf(t_buf, TEMP_BUFFER_LEN, + "/sys/class/net/%s/queues/rx-0/rps_cpus", + interface_name); DBG("Command : [%s]", t_buf); curr = 0; @@ -245,7 +245,9 @@ static int __netconfig_set_rps_cpus(void) if (r_buf[0] == 'e') { close(fd); DBG("e is already written"); - snprintf(t_buf, TEMP_BUFFER_LEN, "/sys/class/net/wlan0/queues/rx-%d/rps_cpus", curr); + snprintf(t_buf, TEMP_BUFFER_LEN, + "/sys/class/net/%s/queues/rx-%d/rps_cpus", + interface_name, curr); DBG("Command : [%s]", t_buf); continue; } else { @@ -269,14 +271,17 @@ static int __netconfig_set_rps_cpus(void) } close(fd); - snprintf(t_buf, TEMP_BUFFER_LEN, "/sys/class/net/wlan0/queues/rx-%d/rps_cpus", curr); + snprintf(t_buf, TEMP_BUFFER_LEN, + "/sys/class/net/%s/queues/rx-%d/rps_cpus", + interface_name, curr); DBG("Command : [%s]", t_buf); } return 0; } -int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable) +int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, + const char *interface_name, gboolean enable) { int err; static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF; @@ -290,7 +295,7 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable) return -EALREADY; } else if (current_driver == alias) { - err = __netconfig_wifi_firmware_stop(type); + err = __netconfig_wifi_firmware_stop(type, interface_name); if (err < 0 && err != -EALREADY) return err; @@ -309,19 +314,20 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable) return -EIO; } - err = __netconfig_wifi_firmware_start(type); + err = __netconfig_wifi_firmware_start(type, interface_name); if (err < 0) DBG("Failed to execute script file"); else current_driver = alias; - if (__netconfig_set_rps_cpus() < 0) + if (__netconfig_set_rps_cpus(interface_name) < 0) DBG("Failed to set rps_cpus"); return err; } -gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device) +gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, + const gchar *device, const gchar *ifname) { int err; @@ -330,17 +336,19 @@ gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, co DBG("Wi-Fi firmware start %s", device != NULL ? device : "null"); if (g_strcmp0("p2p", device) == 0) - err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE); + err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, ifname, TRUE); else if (g_strcmp0("softap", device) == 0) - err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE); + err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, ifname, TRUE); else err = -EINVAL; if (err < 0) { if (err == -EALREADY) netconfig_error_already_exists(context); - else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) { - if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) { + else if (g_strcmp0("softap", device) == 0 && + err == -EIO && netconfig_is_wifi_direct_on() == FALSE) { + if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, ifname, FALSE) == 0 && + netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, ifname, TRUE) == 0) { wifi_firmware_complete_start(firmware, context); return TRUE; } else @@ -355,7 +363,8 @@ gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, co return TRUE; } -gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device) +gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, + const gchar *device, const gchar *ifname) { int err; @@ -364,9 +373,9 @@ gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, con DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null"); if (g_strcmp0("p2p", device) == 0) - err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE); + err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, ifname, FALSE); else if (g_strcmp0("softap", device) == 0) - err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE); + err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, ifname, FALSE); else err = -EINVAL; diff --git a/src/wifi-indicator.c b/src/wifi-indicator.c index a47c608..681ee67 100755 --- a/src/wifi-indicator.c +++ b/src/wifi-indicator.c @@ -56,9 +56,56 @@ #endif #define NETCONFIG_PROCWIRELESS "/proc/net/wireless" +typedef struct { + char *interface_name; + int last_snr_level; +} rssi_data_s; + static int netconfig_wifi_rssi = VCONFKEY_WIFI_SNR_MIN; static guint32 netconfig_wifi_freq = 0; static guint netconfig_wifi_indicator_timer = 0; +static GSList *g_rssi_list = NULL; + +static rssi_data_s *__create_rssi_data(const char *interface_name) +{ + rssi_data_s *rssi_data = g_try_malloc0(sizeof(rssi_data_s)); + if (!rssi_data) { + ERR("Memory allocation failed"); + return NULL; + } + + rssi_data->interface_name = g_strdup(interface_name); + + g_rssi_list = g_slist_append(g_rssi_list, rssi_data); + + return rssi_data; +} + +static rssi_data_s *__get_rssi_data(const char *interface_name) +{ + GSList *list; + rssi_data_s *rssi_data = NULL; + + for (list = g_rssi_list; list; list = list->next) { + rssi_data = list->data; + if (g_strcmp0(rssi_data->interface_name, interface_name) == 0) + return rssi_data; + } + + return rssi_data; +} + +static void __destroy_rssi_data(const char *interface_name) +{ + rssi_data_s *rssi_data = __get_rssi_data(interface_name); + + if (!rssi_data) + return; + + g_rssi_list = g_slist_remove(g_rssi_list, rssi_data); + g_free(rssi_data->interface_name); + g_free(rssi_data); +} int netconfig_wifi_get_rssi(void) { @@ -70,7 +117,7 @@ unsigned int netconfig_wifi_get_freq(void) return netconfig_wifi_freq; } -static int __netconfig_wifi_update_and_get_rssi(void) +static int __netconfig_wifi_update_and_get_rssi(const char *interface_name) { char *if_path = NULL; GVariant *message = NULL; @@ -81,7 +128,7 @@ static int __netconfig_wifi_update_and_get_rssi(void) gint32 key_value; int rssi_dbm = VCONFKEY_WIFI_SNR_MIN; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { ERR("Fail to get wpa_supplicant DBus path"); return 0; @@ -103,10 +150,10 @@ static int __netconfig_wifi_update_and_get_rssi(void) if (g_strcmp0(key, "rssi") == 0) { key_value = g_variant_get_int32(variant); rssi_dbm = (int)key_value; - DBG("Currently signal dbm value [%d]", rssi_dbm); + /* DBG("Currently signal dbm value [%d]", rssi_dbm); */ } else if (g_strcmp0(key, "frequency") == 0) { netconfig_wifi_freq = g_variant_get_uint32(variant); - DBG("Currently frequency [%u]", netconfig_wifi_freq); + /* DBG("Currently frequency [%u]", netconfig_wifi_freq); */ } } @@ -191,14 +238,26 @@ int netconfig_wifi_rssi_level(const int rssi_dbm) return snr_level; } -static void __netconfig_wifi_set_rssi_level(const int snr_level) +static void __netconfig_wifi_set_rssi_level(const char *interface_name, + const int snr_level) { - static int last_snr_level = 0; + rssi_data_s *rssi_data = NULL; + const char *default_ifname = NULL; + + rssi_data = __get_rssi_data(interface_name); + if (rssi_data == NULL) + return; + + if (snr_level != rssi_data->last_snr_level) { + wifi_emit_rssi_changed((Wifi *)get_wifi_object(), interface_name, snr_level); + + default_ifname = netconfig_get_default_ifname(); + if (g_strcmp0(default_ifname, interface_name) == 0) + netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, snr_level); - if (snr_level != last_snr_level) { - netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, snr_level); netconfig_battery_update_wifi_rssi(snr_level); - last_snr_level = snr_level; + + rssi_data->last_snr_level = snr_level; } } @@ -241,6 +300,7 @@ static void __netconfig_wifi_data_activity_booster(int level) "org.tizen.system.deviced.PmQos", "WifiThroughput", params, + NULL, NULL); if (reply != TRUE) return; @@ -271,6 +331,7 @@ static void __netconfig_wifi_data_activity_booster(int level) "org.tizen.system.deviced.PmQos", "WifiThroughput", params, + NULL, NULL); if (reply != TRUE) return; @@ -348,36 +409,50 @@ static gboolean __wifi_indicator_monitor(gpointer data) int rssi_dbm = 0; int snr_level = 0; int pm_state = VCONFKEY_PM_STATE_NORMAL; + char *interface_name = data; - if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + if (wifi_state_get_service_state(interface_name) != NETCONFIG_WIFI_CONNECTED) { + g_free(interface_name); return FALSE; + } /* In case of LCD off, we don't need to update Wi-Fi indicator */ netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state); if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) return TRUE; - rssi_dbm = __netconfig_wifi_update_and_get_rssi(); - /* INFO("%d dbm", rssi_dbm); */ + rssi_dbm = __netconfig_wifi_update_and_get_rssi(interface_name); snr_level = netconfig_wifi_rssi_level(rssi_dbm); - __netconfig_wifi_set_rssi_level(snr_level); + __netconfig_wifi_set_rssi_level(interface_name, snr_level); __netconfig_wifi_update_indicator(); return TRUE; } -void netconfig_wifi_indicator_start(void) +void netconfig_wifi_indicator_start(const char *interface_name) { + const char *default_ifname = NULL; + INFO("Start Wi-Fi indicator"); - netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, VCONFKEY_WIFI_STRENGTH_MAX); - __wifi_indicator_monitor(&netconfig_wifi_indicator_timer); + __create_rssi_data(interface_name); + + wifi_emit_rssi_changed((Wifi *)get_wifi_object(), + interface_name, VCONFKEY_WIFI_STRENGTH_MAX); + + default_ifname = netconfig_get_default_ifname(); + if (g_strcmp0(default_ifname, interface_name) == 0) + netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, VCONFKEY_WIFI_STRENGTH_MAX); + + netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL, + __wifi_indicator_monitor, g_strdup(interface_name), + &netconfig_wifi_indicator_timer); + netconfig_battery_update_wifi_rssi(VCONFKEY_WIFI_STRENGTH_MAX); - netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL, __wifi_indicator_monitor, NULL, &netconfig_wifi_indicator_timer); } -void netconfig_wifi_indicator_stop(void) +void netconfig_wifi_indicator_stop(const char *interface_name) { INFO("Stop Wi-Fi indicator"); @@ -385,4 +460,6 @@ void netconfig_wifi_indicator_stop(void) netconfig_wifi_rssi = VCONFKEY_WIFI_SNR_MIN; netconfig_wifi_freq = 0; + + __destroy_rssi_data(interface_name); } diff --git a/src/wifi-netlink-scan.c b/src/wifi-netlink-scan.c index ee64d9b..efc5523 100755 --- a/src/wifi-netlink-scan.c +++ b/src/wifi-netlink-scan.c @@ -48,7 +48,7 @@ static gint __netconfig_compare_bss_by_rssi(gconstpointer a, gconstpointer b) return 0; } -void __netconfig_notify_netlink_scan_done(void) +void __netconfig_notify_netlink_scan_done(const char *interface_name) { GVariantBuilder *builder = NULL; GVariantBuilder *builder1 = NULL; @@ -111,7 +111,8 @@ void __netconfig_notify_netlink_scan_done(void) } } - wifi_emit_netlink_scan_completed((Wifi *)get_wifi_object(), g_variant_builder_end(builder)); + wifi_emit_netlink_scan_completed((Wifi *)get_wifi_object(), + interface_name, g_variant_builder_end(builder)); g_variant_builder_unref(builder); if (bss_info_list != NULL) @@ -764,11 +765,12 @@ static int __netconfig_netlink_scan(netconfig_nl_global *global, GSList *ssid_li return ret; } -static int __netconfig_initialize_nl80211(netconfig_nl_global *global) +static int __netconfig_initialize_nl80211(netconfig_nl_global *global, + const char *interface_name) { int err = 0; - global->if_index = __netconfig_get_interface_index(WIFI_IFNAME); + global->if_index = __netconfig_get_interface_index(interface_name); if (global->if_index < 0) { DBG("Failed to get interface index"); return -1; @@ -885,7 +887,8 @@ static int __netconfig_get_scan_results(netconfig_nl_global *global) return 0; } -int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *params) +int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, GVariant *params) { DBG(""); netconfig_nl_global global = { @@ -896,7 +899,7 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *pa }; /** Initialize netlink socket */ - int ret = __netconfig_initialize_nl80211(&global); + int ret = __netconfig_initialize_nl80211(&global, ifname); if (ret < 0) { DBG("__netconfig_initialize_nl80211() failed, error %d", ret); netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AccessDenied"); @@ -926,7 +929,7 @@ int handle_netlink_scan(Wifi *wifi, GDBusMethodInvocation *context, GVariant *pa } wifi_complete_netlink_scan(wifi, context); - __netconfig_notify_netlink_scan_done(); + __netconfig_notify_netlink_scan_done(ifname); __netconfig_deinitialize_nl80211(&global); return TRUE; diff --git a/src/wifi-passpoint.c b/src/wifi-passpoint.c index 340019d..8509b9f 100755 --- a/src/wifi-passpoint.c +++ b/src/wifi-passpoint.c @@ -27,14 +27,13 @@ #include "wifi-passpoint.h" #if defined TIZEN_WLAN_PASSPOINT -static gboolean netconfig_wifi_get_passpoint(gint32 *enabled) +static gboolean netconfig_wifi_get_passpoint(const char *interface_name, gint32 *enabled) { GVariant *reply, *var = NULL; gboolean value; gboolean result = FALSE; - reply = netconfig_supplicant_invoke_dbus_interface_property_get(SUPPLICANT_IFACE_INTERFACE, - "Passpoint"); + reply = netconfig_supplicant_invoke_dbus_interface_property_get(interface_name, "Passpoint"); if (reply == NULL) { ERR("Error!!! Failed to get passpoint property"); return FALSE; @@ -60,14 +59,13 @@ static gboolean netconfig_wifi_get_passpoint(gint32 *enabled) return result; } -static gboolean netconfig_wifi_set_passpoint(gint32 enable) +static gboolean netconfig_wifi_set_passpoint(const char *interface_name, gint32 enable) { gint32 value = enable ? 1 : 0; gboolean result = FALSE; - result = netconfig_supplicant_invoke_dbus_interface_property_set( - SUPPLICANT_IFACE_INTERFACE, "Passpoint", - g_variant_new_int32(value), NULL); + result = netconfig_supplicant_invoke_dbus_interface_property_set(interface_name, + "Passpoint", g_variant_new_int32(value), NULL); if (result == FALSE) ERR("Fail to set passpoint enable[%d]", enable); @@ -75,13 +73,14 @@ static gboolean netconfig_wifi_set_passpoint(gint32 enable) } #endif -gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context, + const char *ifname) { gint32 enable = 0; g_return_val_if_fail(wifi != NULL, TRUE); #if defined TIZEN_WLAN_PASSPOINT - netconfig_wifi_get_passpoint(&enable);; + netconfig_wifi_get_passpoint(ifname, &enable);; #else enable = 0; #endif @@ -89,12 +88,13 @@ gboolean handle_get_passpoint(Wifi *wifi, GDBusMethodInvocation *context) return TRUE; } -gboolean handle_set_passpoint(Wifi *wifi, GDBusMethodInvocation *context, gint enable) +gboolean handle_set_passpoint(Wifi *wifi, GDBusMethodInvocation *context, + const char *ifname, gint enable) { g_return_val_if_fail(wifi != NULL, TRUE); #if defined TIZEN_WLAN_PASSPOINT - netconfig_wifi_set_passpoint(enable); + netconfig_wifi_set_passpoint(ifname, enable); #endif wifi_complete_set_passpoint(wifi, context); return TRUE; diff --git a/src/wifi-power.c b/src/wifi-power.c index ca109d5..d5c16cc 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -29,9 +29,11 @@ #include "log.h" #include "util.h" +#include "setting.h" #include "netdbus.h" #include "neterror.h" #include "wifi-wps.h" +#include "wifi-scan.h" #include "wifi-bssid-scan.h" #include "wifi-power.h" #include "wifi-state.h" @@ -41,7 +43,6 @@ #include "wifi-firmware.h" #include "wifi-background-scan.h" - #define WLAN_SUPPLICANT_SCRIPT "/usr/bin/wpa_supp.sh" #define P2P_SUPPLICANT_SCRIPT "/usr/bin/p2p_supp.sh" @@ -52,10 +53,7 @@ #define VCONFKEY_SETAPPL_NETWORK_PERMIT_WITH_LCD_OFF_LIMIT "db/setting/network_with_lcd_off_limit" #endif -#define WLAN_MAC_ADDRESS_FILEPATH "/sys/class/net/wlan0/address" -#define WLAN_MAC_ADDR_MAX 20 -#define VCONF_WIFI_BSSID_ADDRESS "db/wifi/bssid_address" - +#define WLAN_MAC_ADDR_MAX 20 #define ETH_MAC_ADDR_SIZE 6 #define VCONF_ETH_MAC_ADDRESS "db/dnet/mac_address" #define NET_EXEC_PATH "/sbin/ifconfig" @@ -66,16 +64,15 @@ #define MAX_DRV_CMD_SIZE 248 #define WLAN_IOCTL_SUSPEND (SIOCDEVPRIVATE + 1) -static gboolean connman_wifi_technology_state = FALSE; -static gboolean wifi_firmware_recovery_mode = FALSE; -static int airplane_mode = 0; - typedef struct { char *buf; int used_len; int total_len; } netconfig_wifi_priv_cmd; +static gboolean wifi_firmware_recovery_mode = FALSE; +static int airplane_mode = 0; + static gboolean __is_wifi_restricted(void) { #if defined TIZEN_WEARABLE @@ -97,6 +94,7 @@ static void __technology_reply(GObject *source_object, GAsyncResult *res, gpoint GVariant *reply; GDBusConnection *conn = NULL; GError *error = NULL; + char *interface_name = user_data; conn = G_DBUS_CONNECTION(source_object); reply = g_dbus_connection_call_finish(conn, res, &error); @@ -105,18 +103,18 @@ static void __technology_reply(GObject *source_object, GAsyncResult *res, gpoint if (error != NULL) { if (g_strstr_len(error->message, strlen(error->message), CONNMAN_ERROR_INTERFACE ".AlreadyEnabled") != NULL) { - wifi_state_update_power_state(TRUE); + wifi_state_update_power_state(interface_name, TRUE); } else if (g_strstr_len(error->message, strlen(error->message), CONNMAN_ERROR_INTERFACE ".AlreadyDisabled") != NULL) { - wifi_state_update_power_state(FALSE); + wifi_state_update_power_state(interface_name, FALSE); } else { ERR("Fail to request status [%d: %s]", error->code, error->message); - wifi_state_update_power_state(FALSE); + wifi_state_update_power_state(interface_name, FALSE); } g_error_free(error); } else { ERR("Fail to request status"); - wifi_state_update_power_state(FALSE); + wifi_state_update_power_state(interface_name, FALSE); } } else { DBG("Successfully requested"); @@ -124,6 +122,7 @@ static void __technology_reply(GObject *source_object, GAsyncResult *res, gpoint } netconfig_gdbus_pending_call_unref(); + g_free(interface_name); } int __execute_supplicant(gboolean enable) @@ -161,21 +160,12 @@ int __execute_supplicant(gboolean enable) return 0; } -void netconfig_wifi_recover_firmware(void) -{ - wifi_firmware_recovery_mode = TRUE; - - netconfig_wifi_bgscan_stop(); - - wifi_power_off(); -} - -static int _load_driver_and_supplicant(void) +static int _load_driver_and_supplicant(const char *interface_name) { int err = 0; wifi_tech_state_e tech_state; - tech_state = wifi_state_get_technology_state(FALSE); + tech_state = wifi_state_get_technology_state(interface_name); if (tech_state > NETCONFIG_WIFI_TECH_OFF) return -EALREADY; @@ -183,29 +173,29 @@ static int _load_driver_and_supplicant(void) if (err < 0 && err != -EALREADY) return err; - err = netconfig_wifi_firmware(NETCONFIG_WIFI_STA, TRUE); + err = netconfig_wifi_firmware(NETCONFIG_WIFI_STA, interface_name, TRUE); if (err < 0 && err != -EALREADY) { __execute_supplicant(FALSE); return err; } - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_WPS_ONLY); + wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_WPS_ONLY); return 0; } -static int _remove_driver_and_supplicant(void) +static int _remove_driver_and_supplicant(const char *interface_name) { int err = 0; DBG("remove driver and supplicant"); if (wifi_firmware_recovery_mode != TRUE && - netconfig_wifi_is_bssid_scan_started() == TRUE) { + netconfig_wifi_bssidscan_get_mode(interface_name) == TRUE) { DBG("Wi-Fi WPS mode"); return 0; } - err = netconfig_wifi_firmware(NETCONFIG_WIFI_STA, FALSE); + err = netconfig_wifi_firmware(NETCONFIG_WIFI_STA, interface_name, FALSE); if (err < 0 && err != -EALREADY) return err; @@ -213,13 +203,13 @@ static int _remove_driver_and_supplicant(void) if (err < 0 && err != -EALREADY) return err; - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_OFF); + wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_OFF); // reset service state - wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); + wifi_state_set_service_state(interface_name, NETCONFIG_WIFI_IDLE); if (wifi_firmware_recovery_mode == TRUE) { - if (wifi_power_on() < 0) + if (wifi_power_on(interface_name) < 0) ERR("Failed to recover Wi-Fi firmware"); wifi_firmware_recovery_mode = FALSE; @@ -231,150 +221,92 @@ static int _remove_driver_and_supplicant(void) static gboolean __check_and_set_technology_enable(gpointer data) { static int retry_count = NETCONFIG_TECH_WAITING_COUNT; + wifi_tech_state_e tech_state = NETCONFIG_WIFI_TECH_UNKNOWN; gboolean value_enable = TRUE; gboolean reply = FALSE; GVariant *params = NULL; - char key[] = "Powered"; + char *interface_name = data; - if (wifi_state_is_technology_available() == FALSE) { + tech_state = wifi_state_get_technology_state(interface_name); + if (tech_state == NETCONFIG_WIFI_TECH_UNKNOWN) { retry_count--; if (retry_count > 0) return TRUE; } - params = g_variant_new("(sv)", key, g_variant_new_boolean(value_enable)); + params = g_variant_new("(sb)", interface_name, value_enable); reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, - "SetProperty", params, __technology_reply); + "SetDevicePower", params, + __technology_reply, + g_strdup(interface_name)); if (reply != TRUE) { ERR("Fail to set technology enable"); - wifi_state_update_power_state(FALSE); + wifi_state_update_power_state(interface_name, FALSE); retry_count = NETCONFIG_TECH_WAITING_COUNT; + g_free(interface_name); return FALSE; } retry_count = NETCONFIG_TECH_WAITING_COUNT; + g_free(interface_name); return FALSE; } -static int _set_connman_technology_power(gboolean enable) +static int _set_connman_technology_power(const char *interface_name, gboolean enable) { gboolean reply = FALSE; GVariant *params = NULL; - char key[] = "Powered"; gboolean value_enable = TRUE; gboolean value_disable = FALSE; + gboolean powered = FALSE; + wifi_tech_state_e tech_state = NETCONFIG_WIFI_TECH_UNKNOWN; - if (connman_wifi_technology_state == enable) + DBG("Set %s technology [%s]", interface_name, enable == TRUE ? "enable" : "disable"); + + powered = wifi_state_get_powered(interface_name); + if (powered == enable) { + DBG("Already %s", enable ? "enabled" : "disabled"); return -EALREADY; + } - if (enable && wifi_state_is_technology_available() == FALSE) { - netconfig_start_timer(NETCONFIG_TECH_WAITING_INTERVAL, - __check_and_set_technology_enable, NULL, NULL); - connman_wifi_technology_state = enable; - return 0; + if (enable == TRUE) { + tech_state = wifi_state_get_technology_state(interface_name); + if (tech_state == NETCONFIG_WIFI_TECH_UNKNOWN) { + netconfig_start_timer(NETCONFIG_TECH_WAITING_INTERVAL, + __check_and_set_technology_enable, g_strdup(interface_name), NULL); + wifi_state_set_powered(interface_name, enable); + return 0; + } } - params = g_variant_new("(sv)", key, (enable == TRUE) ? - g_variant_new_boolean(value_enable) : g_variant_new_boolean(value_disable)); + params = g_variant_new("(sb)", interface_name, (enable == TRUE) ? value_enable : value_disable); reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, - CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, - "SetProperty", params, __technology_reply); + CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, + "SetDevicePower", params, __technology_reply, g_strdup(interface_name)); if (reply != TRUE) { ERR("Fail to set technology %s", enable == TRUE ? "enable" : "disable"); return -ESRCH; } - /* If Wi-Fi powered off, - * Do not remove Wi-Fi driver until ConnMan technology state updated - */ - if (enable == TRUE) - connman_wifi_technology_state = enable; - /* To be keep safe, early disable Wi-Fi tech state */ if (enable != TRUE) - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_WPS_ONLY); + wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_WPS_ONLY); return 0; } -static void __netconfig_set_wifi_bssid(void) -{ - int rv = 0; - char bssid[WLAN_MAC_ADDR_MAX]; - - FILE *fp = fopen(WLAN_MAC_ADDRESS_FILEPATH, "r"); - - if (fp == NULL) { - ERR("Fail to open %s", WLAN_MAC_ADDRESS_FILEPATH); - return; - } - - rv = fseek(fp, 0L, SEEK_SET); - if (rv != 0) { - ERR("Fail to seek file"); - fclose(fp); - return; - } - - rv = fscanf(fp, "%17s", bssid); - if (rv < 0) { - ERR("Fail to read bssid"); - fclose(fp); - return; - } - - netconfig_set_vconf_str(VCONF_WIFI_BSSID_ADDRESS, bssid); - - fclose(fp); -} - -void netconfig_wifi_disable_technology_state_by_only_connman_signal(void) -{ - /* Important: it's only done by ConnMan technology signal update */ - connman_wifi_technology_state = FALSE; -} - -#if defined TIZEN_WEARABLE -int netconfig_wifi_on_wearable(gboolean device_picker_test) -{ - int err = 0; - int ps_mode; - - if (netconfig_vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_mode) < 0) { - ERR("Fail to get VCONFKEY_SETAPPL_PSMODE"); - return -EIO; - } - - if (ps_mode > SETTING_PSMODE_NORMAL) { - WARN("ps mode is on(%d), Not turn on Wi-Fi", ps_mode); - return -EPERM; - } - - err = wifi_power_driver_and_supplicant(TRUE); - if (err < 0 && err != -EALREADY) - return err; - - err = _set_connman_technology_power(TRUE); - - if (device_picker_test == TRUE) - netconfig_wifi_enable_device_picker_test(); - - return err; -} -#else +#if !defined TIZEN_WEARABLE static void __netconfig_wifi_restrict_mode(keynode_t *node, void *user_data) { int wifi_state = 0, restricted = 0; - int wifi_off_by_restricted = 0; - - netconfig_vconf_get_int(VCONF_WIFI_OFF_STATE_BY_RESTRICTED, &wifi_off_by_restricted); + GSList *list = NULL; netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); @@ -384,28 +316,39 @@ static void __netconfig_wifi_restrict_mode(keynode_t *node, void *user_data) netconfig_vconf_get_bool(VCONFKEY_SETAPPL_NETWORK_RESTRICT_MODE, &restricted); DBG("network restricted mode %s", restricted > 0 ? "ON" : "OFF"); - DBG("Wi-Fi state %d, Wi-Fi was off by restricted mode %s", wifi_state, - wifi_off_by_restricted ? "Yes" : "No"); + DBG("wifi state: %d (0 off / 1 on / 2 connected)", wifi_state); if (restricted > 0) { /* network restricted on */ + GSList *device_list = NULL; + if (wifi_state == VCONFKEY_WIFI_OFF) return; - wifi_power_off(); + device_list = wifi_state_get_device_list(); + for (list = device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + wifi_power_off(device_data->interface_name); + netconfig_setting_update_interface_off_for_restricted(device_data->interface_name, TRUE); + } netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_RESTRICTED, 1); } else { /* network restricted off */ - if (!wifi_off_by_restricted) - return; + GSList *ifname_list = NULL; netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_RESTRICTED, 0); - if (wifi_state > VCONFKEY_WIFI_OFF) - return; + ifname_list = netconfig_setting_get_interfaces_off_by_restricted(); + for (list = ifname_list; list; list = list->next) { + char *interface_name = list->data; - wifi_power_on(); + if (wifi_state_get_technology_state(interface_name) > NETCONFIG_WIFI_TECH_OFF) + continue; + + netconfig_setting_update_interface_off_for_restricted(interface_name, FALSE); + wifi_power_on(interface_name); + } } } #endif @@ -413,9 +356,8 @@ static void __netconfig_wifi_restrict_mode(keynode_t *node, void *user_data) static void __netconfig_wifi_airplane_mode(keynode_t *node, void *user_data) { int wifi_state = 0, airplane_state = 0; - int wifi_off_by_airplane = 0; + GSList *list = NULL; - netconfig_vconf_get_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, &wifi_off_by_airplane); netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); if (node != NULL) @@ -424,43 +366,57 @@ static void __netconfig_wifi_airplane_mode(keynode_t *node, void *user_data) netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &airplane_state); DBG("airplane mode %s (prev:%d)", airplane_state > 0 ? "ON" : "OFF", airplane_mode); - DBG("Wi-Fi state(or use) %d, Wi-Fi was off by flight mode %s", wifi_state, - wifi_off_by_airplane ? "Yes" : "No"); + DBG("wifi state: %d (0 off / 1 on / 2 connected)", wifi_state); if (airplane_mode == airplane_state) - return ; + return; airplane_mode = airplane_state; if (airplane_state > 0) { /* airplane mode on */ + GSList *device_list = NULL; + if (wifi_state == VCONFKEY_WIFI_OFF) return; - wifi_power_off(); + device_list = wifi_state_get_device_list(); + for (list = device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + if (device_data->tech_state > NETCONFIG_WIFI_TECH_OFF) { + wifi_power_off(device_data->interface_name); + netconfig_setting_update_interface_off_for_airplane(device_data->interface_name, TRUE); + } + } netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 1); } else { /* airplane mode off */ - if (!wifi_off_by_airplane) - return; + GSList *ifname_list = NULL; netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); - if (wifi_state > VCONFKEY_WIFI_OFF) - return; - wifi_power_on(); + ifname_list = netconfig_setting_get_interfaces_off_by_airplane(); + for (list = ifname_list; list; list = list->next) { + char *interface_name = list->data; + + if (wifi_state_get_technology_state(interface_name) > NETCONFIG_WIFI_TECH_OFF) + continue; + + netconfig_setting_update_interface_off_for_airplane(interface_name, FALSE); + wifi_power_on(interface_name); + } } } static void __emergency_mode_changed_cb(keynode_t *node, void *user_data) { int wifi_state = 0, emergency = 0; - int wifi_off_by_emergency = 0; + GSList *list = NULL; #if !defined TIZEN_WEARABLE int emergency_by_fmm = 0; #endif - netconfig_vconf_get_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, &wifi_off_by_emergency); + netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); #if !defined TIZEN_WEARABLE @@ -476,55 +432,80 @@ static void __emergency_mode_changed_cb(keynode_t *node, void *user_data) netconfig_vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &emergency); DBG("emergency mode %s", emergency > SETTING_PSMODE_POWERFUL ? "ON" : "OFF"); - DBG("Wi-Fi state %d, Wi-Fi was off by emergency mode %s", wifi_state, wifi_off_by_emergency ? "Yes" : "No"); + DBG("wifi state: %d (0 off / 1 on / 2 connected)", wifi_state); #if defined TIZEN_WEARABLE if (emergency == SETTING_PSMODE_WEARABLE) { /* basic power saving mode on */ } else if (emergency == SETTING_PSMODE_WEARABLE_ENHANCED) { /* enhanced power saving mode on */ + GSList *device_list = NULL; + if (wifi_state == VCONFKEY_WIFI_OFF) return; - wifi_power_off(); + device_list = wifi_state_get_device_list(); + for (list = device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + wifi_power_off(device_data->interface_name); + netconfig_setting_update_interface_off_for_emergency(device_data->interface_name, TRUE); + } + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 1); } else { /* power saving mode off */ - if (!wifi_off_by_emergency) - return; + GSList *ifname_list = NULL; netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 0); - if (wifi_state > VCONFKEY_WIFI_OFF) - return; + ifname_list = netconfig_setting_get_interfaces_off_by_emergency(); + for (list = ifname_list; list; list = list->next) { + char *interface_name = list->data; + + if (wifi_state_get_technology_state(interface_name) > NETCONFIG_WIFI_TECH_OFF) + continue; - wifi_power_on_wearable(TRUE); + netconfig_setting_update_interface_off_for_emergency(interface_name, FALSE); + wifi_power_on_wearable(interface_name, TRUE); + } } #else if (emergency > SETTING_PSMODE_POWERFUL) { /* emergency mode on */ + GSList *device_list = NULL; + if (wifi_state == VCONFKEY_WIFI_OFF) return; - wifi_power_off(); + device_list = wifi_state_get_device_list(); + for (list = device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + wifi_power_off(device_data->interface_name); + netconfig_setting_update_interface_off_for_emergency(device_data->interface_name, TRUE); + } netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 1); } else { /* emergency mode off */ - if (!wifi_off_by_emergency) - return; + GSList *ifname_list = NULL; netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 0); - if (wifi_state > VCONFKEY_WIFI_OFF) - return; + ifname_list = netconfig_setting_get_interfaces_off_by_emergency(); + for (list = ifname_list; list; list = list->next) { + char *interface_name = list->data; + + if (wifi_state_get_technology_state(interface_name) > NETCONFIG_WIFI_TECH_OFF) + continue; - wifi_power_on(); + netconfig_setting_update_interface_off_for_emergency(interface_name, FALSE); + wifi_power_on(interface_name); + } } #endif } -void wifi_set_early_suspend(gboolean value) +void wifi_set_early_suspend(const char *interface_name, gboolean value) { static gboolean old_state = FALSE; struct ifreq ifr; @@ -544,7 +525,7 @@ void wifi_set_early_suspend(gboolean value) if (netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state) < 0) ERR("Fail to get VCONFKEY_PM_STATE"); - wifi_state = wifi_state_get_service_state(); + wifi_state = wifi_state_get_service_state(interface_name); if (value == TRUE && (pm_state < VCONFKEY_PM_STATE_LCDOFF || @@ -558,7 +539,7 @@ void wifi_set_early_suspend(gboolean value) snprintf(buf, sizeof(buf), "SETSUSPENDMODE %d", value); memset(&ifr, 0, sizeof(struct ifreq)); - g_strlcpy((char *)ifr.ifr_name, WIFI_IFNAME, IFNAMSIZ); + g_strlcpy((char *)ifr.ifr_name, interface_name, IFNAMSIZ); DBG("Early suspend command: [%s]", buf); @@ -591,6 +572,7 @@ static void __pm_state_changed_cb(keynode_t* node, void* user_data) int new_state = -1; int wifi_state = 0; static int prev_state = VCONFKEY_PM_STATE_NORMAL; + GSList *list = NULL, *device_list = NULL; if (netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state) < 0) { ERR("Fail to get VCONFKEY_WIFI_STATE"); @@ -613,50 +595,33 @@ static void __pm_state_changed_cb(keynode_t* node, void* user_data) if ((new_state == VCONFKEY_PM_STATE_NORMAL) && (prev_state >= VCONFKEY_PM_STATE_LCDOFF)) { /* Send early suspend mode based on LCD state and disallow early suspend count */ - if (wifi_state != VCONFKEY_WIFI_OFF) { - wifi_set_early_suspend(FALSE); - DBG("Unset early suspend"); + device_list = wifi_state_get_device_list(); + for (list = device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + if (device_data->powered == TRUE) { + wifi_set_early_suspend(device_data->interface_name, FALSE); + DBG("Unset early suspend [%s]", device_data->interface_name); + } + netconfig_wifi_bgscan_stop(device_data->interface_name); + netconfig_wifi_bgscan_set_interval(device_data->interface_name, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_start(device_data->interface_name, TRUE); } - - netconfig_wifi_bgscan_stop(); - netconfig_wifi_bgscan_set_interval(SCAN_EXPONENTIAL_MIN); - netconfig_wifi_bgscan_start(TRUE); } else if ((new_state == VCONFKEY_PM_STATE_LCDOFF) && (prev_state < VCONFKEY_PM_STATE_LCDOFF) && (wifi_state != VCONFKEY_WIFI_OFF)) { - wifi_set_early_suspend(TRUE); - DBG("Set early suspend"); + device_list = wifi_state_get_device_list(); + for (list = device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + wifi_set_early_suspend(device_data->interface_name, TRUE); + DBG("Set early suspend [%s]", device_data->interface_name); + } } prev_state = new_state; } -static void __doze_level_changed_cb(keynode_t* node, void* user_data) -{ - int doze_level = -1; - - if (node != NULL) - doze_level = vconf_keynode_get_int(node); - else - netconfig_vconf_get_int(VCONFKEY_SYSMAN_DOZE_MODE_LEVEL, &doze_level); - - if (doze_level < 0) { - DBG("Invalid Doze Level: %d", doze_level); - return; - } - - DBG("Doze Level: %d", doze_level); - - if (doze_level >= 1) { - netconfig_wifi_block_bgscan(1); - DBG("Block BG scan!"); - } else { - netconfig_wifi_block_bgscan(0); - DBG("Unblock BG scan!"); - } -} - -static void __netconfig_telephony_ready_changed_cb(keynode_t * node, void *data) +static void __netconfig_telephony_ready_changed_cb(keynode_t *node, void *data) { int telephony_ready = 0; + char *interface_name = data; if (node != NULL) telephony_ready = vconf_keynode_get_bool(node); @@ -675,16 +640,17 @@ static void __netconfig_telephony_ready_changed_cb(keynode_t * node, void *data) DBG("Turn Wi-Fi on automatically"); #if defined TIZEN_WEARABLE - wifi_power_on_wearable(TRUE); + wifi_power_on_wearable(interface_name, TRUE); #else - wifi_power_on(); + wifi_power_on(interface_name); #endif done: vconf_ignore_key_changed(VCONFKEY_TELEPHONY_READY, __netconfig_telephony_ready_changed_cb); + g_free(interface_name); } -int wifi_power_driver_and_supplicant(gboolean enable) +int wifi_power_driver_and_supplicant(const char *interface_name, gboolean enable) { /* There are 3 thumb rules for Wi-Fi power management * 1. Do not make exposed API to control wpa_supplicant and driver directly. @@ -696,52 +662,34 @@ int wifi_power_driver_and_supplicant(gboolean enable) * 3. Final the best rule: make it as simple as possible. * Simple code enables easy maintenance and reduces logical errors. */ + if (enable == TRUE) { - return _load_driver_and_supplicant(); + return _load_driver_and_supplicant(interface_name); } else { - if (connman_wifi_technology_state == TRUE) + if (wifi_state_get_powered(interface_name) == TRUE) return -ENOSYS; - return _remove_driver_and_supplicant(); + return _remove_driver_and_supplicant(interface_name); } } -void wifi_power_disable_technology_state_by_only_connman_signal(void) -{ - /* Important: it's only done by ConnMan technology signal update */ - connman_wifi_technology_state = FALSE; -} - -void wifi_power_recover_firmware(void) +void wifi_power_recover_firmware(const char *interface_name) { wifi_firmware_recovery_mode = TRUE; - netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_stop(interface_name); - wifi_power_off(); + wifi_power_off(interface_name); } -int wifi_power_on(void) +int wifi_power_on(const char *interface_name) { int err = 0; wifi_tech_state_e tech_state; - tech_state = wifi_state_get_technology_state(TRUE); + tech_state = wifi_state_get_technology_state(interface_name); if (tech_state >= NETCONFIG_WIFI_TECH_POWERED) { - /* There can be a scenario where wifi is automatically * - * activated by connman if wifi was powered in last boot. * - * So we should update connman_wifi_technology_state variable * - * if it is found that wifi_tech_state variable is * - * NETCONFIG_WIFI_TECH_POWERED and connman_wifi_technology_state * - * variable is FALSE. Earlier connman_wifi_technology_state * - * variable was only updated when wifi was Powered on from * - * net-config resulting in variable not getting updated. * - * This caused wifi to not get deactivated after reboot if * - * last power state was activated */ - ERR("Net-Config WiFi connman technology state %d", - connman_wifi_technology_state); - if (connman_wifi_technology_state == FALSE) - connman_wifi_technology_state = TRUE; + INFO("Net-Config WiFi connman technology state %d", tech_state); return -EALREADY; } @@ -755,41 +703,41 @@ int wifi_power_on(void) return -EBUSY; } - err = wifi_power_driver_and_supplicant(TRUE); + err = wifi_power_driver_and_supplicant(interface_name, TRUE); if (err < 0 && err != -EALREADY) return err; - err = _set_connman_technology_power(TRUE); + err = _set_connman_technology_power(interface_name, TRUE); return err; } -int wifi_power_off(void) +int wifi_power_off(const char *interface_name) { int err; - err = _set_connman_technology_power(FALSE); + err = _set_connman_technology_power(interface_name, FALSE); if (err == -EALREADY) - wifi_state_update_power_state(FALSE); + wifi_state_update_power_state(interface_name, FALSE); - return 0; + return err; } #if defined TIZEN_WEARABLE -int wifi_power_on_wearable(gboolean device_picker_test) +int wifi_power_on_wearable(const char *interface_name, gboolean device_picker_test) { int err = 0; wifi_tech_state_e tech_state; - tech_state = wifi_state_get_technology_state(TRUE); + tech_state = wifi_state_get_technology_state(interface_name); if (tech_state >= NETCONFIG_WIFI_TECH_POWERED) return -EALREADY; - err = wifi_power_driver_and_supplicant(TRUE); + err = wifi_power_driver_and_supplicant(interface_name, TRUE); if (err < 0 && err != -EALREADY) return err; - err = _set_connman_technology_power(TRUE); + err = _set_connman_technology_power(interface_name, TRUE); if (device_picker_test == TRUE) netconfig_wifi_enable_device_picker_test(); @@ -800,22 +748,25 @@ int wifi_power_on_wearable(gboolean device_picker_test) void wifi_power_initialize(void) { - int wifi_last_power_state = 0; + GSList *interface_list = NULL; /* Initialize Airplane mode */ netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &airplane_mode); DBG("Airplane[%s]", airplane_mode > 0 ? "ON" : "OFF"); /* Update the last Wi-Fi power state */ - netconfig_vconf_get_int(VCONF_WIFI_LAST_POWER_STATE, &wifi_last_power_state); - if (wifi_last_power_state > VCONFKEY_WIFI_OFF) { + interface_list = netconfig_setting_get_interfaces_for_last_powered(); + for (; interface_list; interface_list = interface_list->next) { + const char *interface_name = interface_list->data; + if (TIZEN_TELEPHONY_ENABLE) { int telephony_ready = 0; netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_READY, &telephony_ready); if (telephony_ready == 0) { DBG("Telephony API is not initialized yet"); vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY, - __netconfig_telephony_ready_changed_cb, NULL); + __netconfig_telephony_ready_changed_cb, + g_strdup(interface_name)); } else { if (netconfig_tapi_check_sim_state() == FALSE) DBG("SIM is not initialized yet"); @@ -823,9 +774,9 @@ void wifi_power_initialize(void) } DBG("Turn Wi-Fi on automatically"); #if defined TIZEN_WEARABLE - wifi_power_on_wearable(TRUE); + wifi_power_on_wearable(interface_name, TRUE); #else - wifi_power_on(); + wifi_power_on(interface_name); #endif } @@ -839,25 +790,22 @@ void wifi_power_initialize(void) __netconfig_wifi_airplane_mode, NULL); #endif - vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, __emergency_mode_changed_cb, NULL); + vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, + __emergency_mode_changed_cb, NULL); vconf_notify_key_changed(VCONFKEY_PM_STATE, __pm_state_changed_cb, NULL); - vconf_notify_key_changed(VCONFKEY_SYSMAN_DOZE_MODE_LEVEL, __doze_level_changed_cb, NULL); - __doze_level_changed_cb(NULL, NULL); } void wifi_power_deinitialize(void) { - vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, __emergency_mode_changed_cb); - vconf_ignore_key_changed(VCONFKEY_PM_STATE, __pm_state_changed_cb); - vconf_ignore_key_changed(VCONFKEY_SYSMAN_DOZE_MODE_LEVEL, __doze_level_changed_cb); } gboolean handle_load_driver(Wifi *wifi, - GDBusMethodInvocation *context, gboolean device_picker_test) + GDBusMethodInvocation *context, + const gchar *ifname, gboolean device_picker_test) { int err; - DBG("Wi-Fi power on requested"); + DBG("Wi-Fi power on requested [%s]", ifname); g_return_val_if_fail(wifi != NULL, TRUE); @@ -871,9 +819,9 @@ gboolean handle_load_driver(Wifi *wifi, wifi_firmware_download(); #if defined TIZEN_WEARABLE - err = wifi_power_on_wearable(device_picker_test); + err = wifi_power_on_wearable(ifname, device_picker_test); #else - err = wifi_power_on(); + err = wifi_power_on(ifname); if (device_picker_test == TRUE) netconfig_wifi_enable_device_picker_test(); @@ -891,21 +839,21 @@ gboolean handle_load_driver(Wifi *wifi, netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); - __netconfig_set_wifi_bssid(); wifi_complete_load_driver(wifi, context); return TRUE; } -gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { int err; - DBG("Wi-Fi power off requested"); + DBG("Wi-Fi power off requested [%s]", ifname); g_return_val_if_fail(wifi != NULL, TRUE); - err = wifi_power_off(); + err = wifi_power_off(ifname); if (err < 0) { if (err == -EINPROGRESS) netconfig_error_inprogress(context); diff --git a/src/wifi-scan.c b/src/wifi-scan.c new file mode 100755 index 0000000..0f8738f --- /dev/null +++ b/src/wifi-scan.c @@ -0,0 +1,428 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-state.h" +#include "wifi-scan.h" + +typedef struct { + const char *interface_name; + + /* background scan */ + guint bg_interval; + guint bg_mode; + guint bg_timer_id; + gboolean bg_paused; + + /* bssid scan*/ + gboolean bssid_enabled; + gboolean bssid_aborted; + gboolean bssid_scanning; + + /* scan */ + gboolean scanning; +} scan_data_s; + +static GSList *g_scan_list = NULL; + +static scan_data_s *__wifi_scan_create_data(const char *interface_name) +{ + scan_data_s *scan_data = g_try_malloc0(sizeof(scan_data_s)); + if (!scan_data) { + ERR("Memory allocation failed"); + return NULL; + } + + scan_data->interface_name = g_strdup(interface_name); + + scan_data->scanning = FALSE; + + scan_data->bg_interval = SCAN_EXPONENTIAL_MIN; + scan_data->bg_mode = WIFI_BGSCAN_MODE_EXPONENTIAL; + scan_data->bg_timer_id = 0; + scan_data->bg_paused = FALSE; + + scan_data->bssid_enabled = FALSE; + scan_data->bssid_aborted = FALSE; + scan_data->bssid_scanning = FALSE; + + g_scan_list = g_slist_append(g_scan_list, scan_data); + + return scan_data; +} + +static scan_data_s *__wifi_scan_get_data(const char *interface_name) +{ + GSList *list; + scan_data_s *scan_data; + + for (list = g_scan_list; list; list = list->next) { + scan_data = list->data; + if (g_strcmp0(scan_data->interface_name, interface_name) == 0) + return scan_data; + } + + scan_data = __wifi_scan_create_data(interface_name); + return scan_data; +} + +void netconfig_wifi_scan_set_scanning(const char *interface_name, gboolean scanning) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return; + + scan_data->scanning = scanning; +} + +guint netconfig_wifi_scan_get_scanning(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return FALSE; + + return scan_data->scanning;; +} + +gboolean netconfig_wifi_bgscan_set_mode(const char *interface_name, guint mode) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return FALSE; + + if (mode != WIFI_BGSCAN_MODE_EXPONENTIAL && mode != WIFI_BGSCAN_MODE_PERIODIC) { + ERR("Invalid scan mode [%d]", mode); + return FALSE; + } + + scan_data->bg_mode = mode; + + return TRUE; +} + +guint netconfig_wifi_bgscan_get_mode(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return 0; + + return scan_data->bg_mode; +} + +void netconfig_wifi_bgscan_set_timer_id(const char *interface_name, guint timer_id) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return; + + scan_data->bg_timer_id = timer_id; +} + +guint netconfig_wifi_bgscan_get_timer_id(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return 0; + + return scan_data->bg_timer_id; +} + +gboolean netconfig_wifi_bgscan_set_interval(const char *interface_name, guint interval) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return FALSE; + + if ((interval < SCAN_EXPONENTIAL_MIN) || (interval > SCAN_EXPONENTIAL_MAX)) { + ERR("Invalid interval [%d]", interval); + return FALSE; + } + + scan_data->bg_interval = interval; + + return TRUE; +} + +guint netconfig_wifi_bgscan_get_interval(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return SCAN_EXPONENTIAL_MIN; + + return scan_data->bg_interval; +} + +void netconfig_wifi_bgscan_set_pause(const char *interface_name, gboolean pause) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + if (!scan_data) + return; + + scan_data->bg_paused = pause; + + DBG("[%s] Wi-Fi background scan [%s]", interface_name, + pause ? "Pause" : "Resume"); +} + +gboolean netconfig_wifi_bgscan_is_paused(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + if (!scan_data) + return FALSE; + + DBG("[%s] Wi-Fi background scan is [%s]", interface_name, + scan_data->bg_paused ? "Paused" : "Runnable"); + + return scan_data->bg_paused; +} + +static void __wifi_scan_request_reply(GObject *source_object, + GAsyncResult *res, gpointer user_data) +{ + GVariant *reply; + GDBusConnection *conn = NULL; + GError *error = NULL; + char *interface_name = user_data; + + conn = G_DBUS_CONNECTION(source_object); + reply = g_dbus_connection_call_finish(conn, res, &error); + + if (reply == NULL) { + if (error != NULL) { + ERR("Fail to request status [%d: %s]", error->code, error->message); + netconfig_wifi_scan_set_scanning(interface_name, FALSE); + g_error_free(error); + } else { + ERR("Fail to request scan"); + netconfig_wifi_scan_set_scanning(interface_name, FALSE); + } + } else { + DBG("Successfully requested"); + g_variant_unref(reply); + } + + netconfig_gdbus_pending_call_unref(); + g_free(interface_name); +} + +static gboolean __wifi_scan_request_connman_scan(const char *interface_name) +{ + GVariant *params = NULL; + gboolean reply = FALSE; + + netconfig_wifi_scan_set_scanning(interface_name, TRUE); + + params = g_variant_new("(s)", interface_name); + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_WIFI_TECHNOLOGY_PREFIX, + CONNMAN_TECHNOLOGY_INTERFACE, "ScanDevice", params, + __wifi_scan_request_reply, g_strdup(interface_name)); + if (reply != TRUE) { + ERR("Failed to send Scan request to connman"); + netconfig_wifi_scan_set_scanning(interface_name, FALSE); + } + + return reply; +} + +static gboolean __wifi_bgscan_immediate_scan(gpointer data) +{ + static int retries = 0; + scan_data_s *scan_data = data; + guint state = 0; + + if (!scan_data) + return FALSE; + + state = wifi_state_get_service_state(scan_data->interface_name); + +#if !defined TIZEN_WEARABLE + if (netconfig_wifi_bgscan_is_paused(scan_data->interface_name)) { + return FALSE; + } +#endif + + if (state == NETCONFIG_WIFI_CONNECTED) { + if (netconfig_wifi_bgscan_get_mode(scan_data->interface_name) == WIFI_BGSCAN_MODE_EXPONENTIAL) { + DBG("[%s] Wi-Fi state is connected, scan is paused", scan_data->interface_name); + return FALSE; + } + } else if (state == NETCONFIG_WIFI_ASSOCIATION || state == NETCONFIG_WIFI_CONFIGURATION) { + /* During WIFI connecting, WIFI can be disappeared. + * After 1 sec, try scan even if connecting state */ + if (retries < 2) { + retries++; + return TRUE; + } + } + + if (__wifi_scan_request_connman_scan(scan_data->interface_name) == TRUE) { + retries = 0; + return FALSE; + } else if (retries > 2) { + retries = 0; + return FALSE; + } + + retries++; + + return TRUE; +} + +static gboolean __wifi_bgscan_next_scan(gpointer data) +{ + int pm_state = VCONFKEY_PM_STATE_NORMAL; + scan_data_s *scan_data = data; + + if (!scan_data) + return FALSE; + + /* In case of LCD off, we don't need Wi-Fi scan */ + netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) + return TRUE; + + netconfig_wifi_bgscan_start_timer(scan_data->interface_name, TRUE); + + return FALSE; +} + +void netconfig_wifi_bgscan_start_timer(const char *interface_name, gboolean immediate_scan) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return; + + netconfig_stop_timer(&(scan_data->bg_timer_id)); + + switch (scan_data->bg_mode) { + case WIFI_BGSCAN_MODE_EXPONENTIAL: + if (scan_data->bg_interval < SCAN_EXPONENTIAL_MIN || + scan_data->bg_interval == SCAN_PERIODIC_DELAY) + scan_data->bg_interval = SCAN_EXPONENTIAL_MIN; + break; + case WIFI_BGSCAN_MODE_PERIODIC: + scan_data->bg_interval = SCAN_PERIODIC_DELAY; + break; + default: + DBG("Invalid Wi-Fi background scan mode[%d]", scan_data->bg_mode); + return; + } + + if (immediate_scan) + DBG("[%s] Scan immediately[%d], mode[%d](0 exponential / 1 periodic)", + interface_name, immediate_scan, scan_data->bg_mode); + else + DBG("[%s] Scan immediately[%d], mode[%d](0 exponential / 1 periodic), next[%d]", + interface_name, immediate_scan, scan_data->bg_mode, scan_data->bg_interval); + + if (immediate_scan) + g_timeout_add(500, __wifi_bgscan_immediate_scan, scan_data); + + netconfig_start_timer_seconds(scan_data->bg_interval, + __wifi_bgscan_next_scan, scan_data, &(scan_data->bg_timer_id)); + + if (scan_data->bg_mode == WIFI_BGSCAN_MODE_EXPONENTIAL && immediate_scan) { + scan_data->bg_interval = scan_data->bg_interval * 2; + if (scan_data->bg_interval > SCAN_EXPONENTIAL_MAX) + scan_data->bg_interval = SCAN_EXPONENTIAL_MAX; + } +} + +void netconfig_wifi_bgscan_stop_timer(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (scan_data) + return; + + netconfig_stop_timer(&(scan_data->bg_timer_id)); +} + +void netconfig_wifi_bssidscan_set_mode(const char *interface_name, gboolean enable) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + if (!scan_data) + return; + + scan_data->bssid_enabled = enable; +} + +gboolean netconfig_wifi_bssidscan_get_mode(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + if (!scan_data) + return FALSE; + + return scan_data->bssid_enabled; +} + +void netconfig_wifi_bssidscan_set_aborted(const char *interface_name, gboolean abort) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + if (!scan_data) + return; + + scan_data->bssid_aborted = abort; +} + +gboolean netconfig_wifi_bssidscan_get_aborted(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + if (!scan_data) + return FALSE; + + return scan_data->bssid_aborted; +} + +void netconfig_wifi_bssidscan_set_scanning(const char *interface_name, gboolean scanning) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return; + + scan_data->bssid_scanning = scanning; +} + +guint netconfig_wifi_bssidscan_get_scanning(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return FALSE; + + return scan_data->bssid_scanning;; +} diff --git a/src/wifi-state.c b/src/wifi-state.c index 68cc0b7..bfcc389 100755 --- a/src/wifi-state.c +++ b/src/wifi-state.c @@ -23,27 +23,67 @@ #include "log.h" #include "util.h" #include "netdbus.h" +#include "setting.h" #include "wifi-state.h" #include "wifi-power.h" +#include "wifi-scan.h" #include "netsupplicant.h" #include "network-state.h" #include "wifi-indicator.h" #include "network-statistics.h" #include "wifi-background-scan.h" +#define NETCONFIG_UPDATE_DEVICE_LIST_TIMEOUT 1 * 1000 #define NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT 15 * 1000 static gboolean new_bss_found = FALSE; -static guint network_noti_timer_id = 0; -static wifi_service_state_e g_service_state = NETCONFIG_WIFI_UNKNOWN; -static wifi_tech_state_e g_tech_state = NETCONFIG_WIFI_TECH_UNKNOWN; +static guint network_update_timer_id = 0; +static guint network_noti_timer_id = 0; -static GSList *notifier_list = NULL; +static GSList *g_device_list = NULL; +static GSList *g_notifier_list = NULL; static guint network_connected_popup_timer_id = 0; static gboolean block_network_connected_popup = FALSE; +static void __device_free_data(gpointer data) +{ + wifi_device_data_s *device_data = data; + + g_free(device_data->interface_name); + g_free(device_data->mac_address); + g_free(device_data); + +} + +static wifi_device_data_s *__device_get_data(const char *interface_name) +{ + GSList *list = NULL; + + for (list = g_device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + if (g_strcmp0(device_data->interface_name, interface_name) == 0) + return device_data; + } + + return NULL; +} + +static wifi_device_data_s *__device_get_data_by_macaddr(const char *macaddr) +{ + GSList *list = NULL; + + for (list = g_device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + if (g_ascii_strncasecmp(device_data->mac_address, + macaddr, MAC_ADDRESS_MAX_LEN) == 0) + return device_data; + } + + return NULL; +} + char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type) { switch (wifi_service_state_type) { @@ -101,8 +141,9 @@ static void __set_wifi_connected_essid(void) { const char *essid_name = NULL; const char *wifi_profile = netconfig_get_default_profile(); + const char *wifi_ifname = netconfig_get_default_ifname(); - if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + if (wifi_state_get_service_state(wifi_ifname) != NETCONFIG_WIFI_CONNECTED) return; if (wifi_profile == NULL || @@ -137,13 +178,12 @@ static void __unset_wifi_connected_essid(void) static const char *__get_wifi_connected_essid(void) { const char *essid_name = NULL; - const char *wifi_profile = NULL; + const char *wifi_profile = netconfig_get_default_profile(); + const char *wifi_ifname = netconfig_get_default_ifname(); - if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + if (wifi_state_get_service_state(wifi_ifname) != NETCONFIG_WIFI_CONNECTED) return NULL; - wifi_profile = netconfig_get_default_profile(); - if (wifi_profile == NULL || netconfig_is_wifi_profile(wifi_profile) != TRUE) { ERR("Can't get Wi-Fi profile"); return NULL; @@ -217,15 +257,25 @@ static void _wifi_state_connected_activation(void) /* Add activation of services when Wi-Fi is connected */ } -static void _wifi_state_changed(wifi_service_state_e state) +static void _wifi_state_changed(const char *interface_name, + wifi_service_state_e state) { GSList *list; + const char *ifname; - for (list = notifier_list; list; list = list->next) { - wifi_state_notifier *notifier = list->data; + for (list = g_notifier_list; list; ) { + wifi_state_notifier_s *notifier = list->data; + list = list->next; + + if (notifier->service) { + ifname = netconfig_get_ifname(notifier->service); + if (g_strcmp0(ifname, interface_name) != 0) + continue; + } if (notifier->wifi_state_changed != NULL) - notifier->wifi_state_changed(state, notifier->user_data); + notifier->wifi_state_changed(notifier->notifier, + notifier->service, state, notifier->user_data); } } @@ -242,14 +292,15 @@ static gboolean _check_network_notification(gpointer data) wifi_tech_state_e tech_state; wifi_service_state_e service_state; + char *interface_name = data; - tech_state = wifi_state_get_technology_state(FALSE); + tech_state = wifi_state_get_technology_state(interface_name); if (tech_state < NETCONFIG_WIFI_TECH_POWERED) { DBG("Wi-Fi off or WPS only supported[%d]", tech_state); goto cleanup; } - service_state = wifi_state_get_service_state(); + service_state = wifi_state_get_service_state(interface_name); if (service_state == NETCONFIG_WIFI_CONNECTED) { DBG("Service state is connected"); goto cleanup; @@ -405,24 +456,49 @@ static void _set_power_lock(gboolean power_lock) return; } -void wifi_state_emit_power_completed(gboolean power_on) +void wifi_state_emit_power_completed(const char *interface_name, gboolean power_on) { if (power_on) - wifi_emit_power_on_completed((Wifi *)get_wifi_object()); + wifi_emit_power_on_completed((Wifi *)get_wifi_object(), interface_name); else - wifi_emit_power_off_completed((Wifi *)get_wifi_object()); + wifi_emit_power_off_completed((Wifi *)get_wifi_object(), interface_name); + + DBG("Successfully sent signal [%s %s]", + interface_name, (power_on) ? "powerOn" : "powerOff"); +} + +void wifi_state_emit_power_failed(const char *interface_name) +{ + wifi_emit_power_operation_failed((Wifi *)get_wifi_object(), interface_name); - DBG("Successfully sent signal [%s]", (power_on) ? "powerOn" : "powerOff"); + DBG("Successfully sent signal [%s PowerOperationFailed]", interface_name); } -void wifi_state_emit_power_failed(void) +static void __update_wifi_state(void) { - wifi_emit_power_operation_failed((Wifi *)get_wifi_object()); + int wifi_state = VCONFKEY_WIFI_OFF; + int network_wifi_state = VCONFKEY_NETWORK_WIFI_OFF; + GSList *list = NULL; - DBG("Successfully sent signal [PowerOperationFailed]"); + for (list = g_device_list; list; list = list->next) { + wifi_device_data_s *device_data = list->data; + if (device_data->powered) { + if (wifi_state < VCONFKEY_WIFI_UNCONNECTED) + wifi_state = VCONFKEY_WIFI_UNCONNECTED; + if (network_wifi_state < VCONFKEY_NETWORK_WIFI_NOT_CONNECTED) + network_wifi_state = VCONFKEY_NETWORK_WIFI_NOT_CONNECTED; + } + if (device_data->connected) { + wifi_state = VCONFKEY_WIFI_CONNECTED; + network_wifi_state = VCONFKEY_NETWORK_WIFI_CONNECTED; + } + } + + netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, wifi_state); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, network_wifi_state); } -void wifi_state_update_power_state(gboolean powered) +void wifi_state_update_power_state(const char *interface_name, gboolean powered) { wifi_tech_state_e tech_state; @@ -430,52 +506,52 @@ void wifi_state_update_power_state(gboolean powered) * DO NOT update manually * It includes Wi-Fi state configuration */ - tech_state = wifi_state_get_technology_state(FALSE); + tech_state = wifi_state_get_technology_state(interface_name); if (powered == TRUE) { if (tech_state < NETCONFIG_WIFI_TECH_POWERED && netconfig_is_wifi_tethering_on() != TRUE) { DBG("Wi-Fi turned on or waken up from power-save mode"); - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED); + wifi_state_set_powered(interface_name, TRUE); + wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_POWERED); - wifi_state_emit_power_completed(TRUE); + wifi_state_emit_power_completed(interface_name, TRUE); netconfig_battery_start_wifi(); netconfig_wifi_device_picker_service_start(); - netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_UNCONNECTED); - netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED); - netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); + __update_wifi_state(); netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON); - netconfig_wifi_bgscan_stop(); - netconfig_wifi_bgscan_set_interval(SCAN_EXPONENTIAL_MIN); - netconfig_wifi_bgscan_start(TRUE); + netconfig_wifi_bgscan_stop(interface_name); + netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_start(interface_name, TRUE); /* Add callback to track change in notification setting */ _register_network_notification(); + + netconfig_setting_update_interface_for_last_powered(interface_name, TRUE); } } else if (tech_state > NETCONFIG_WIFI_TECH_OFF) { DBG("Wi-Fi turned off or in power-save mode"); - wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_WPS_ONLY); + wifi_state_set_powered(interface_name, FALSE); + wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_WPS_ONLY); netconfig_wifi_device_picker_service_stop(); - wifi_power_disable_technology_state_by_only_connman_signal(); - wifi_power_driver_and_supplicant(FALSE); + wifi_power_driver_and_supplicant(interface_name, FALSE); - wifi_state_emit_power_completed(FALSE); + wifi_state_emit_power_completed(interface_name, FALSE); netconfig_battery_end_wifi(); - netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_OFF); - netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF); - netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF); + __update_wifi_state(); netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_OFF); - netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_stop(interface_name); + netconfig_wifi_scan_set_scanning(interface_name, FALSE); _set_bss_found(FALSE); @@ -485,6 +561,8 @@ void wifi_state_update_power_state(gboolean powered) netconfig_send_notification_to_net_popup(NETCONFIG_DEL_IP_CONFLICT_NOTI, NULL); _deregister_network_notification(); + + netconfig_setting_update_interface_for_last_powered(interface_name, FALSE); } } @@ -493,32 +571,33 @@ char *wifi_get_favorite_service(void) return _get_connman_favorite_service(); } -void wifi_start_timer_network_notification(void) +void wifi_start_timer_network_notification(const char *interface_name) { #if defined TIZEN_WEARABLE /* In case of wearable device, no need to notify available Wi-Fi APs */ - return ; + return; #endif - netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT, _check_network_notification, NULL, &network_noti_timer_id); + netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT, + _check_network_notification, g_strdup(interface_name), &network_noti_timer_id); } -void wifi_state_notifier_register(wifi_state_notifier *notifier) +void wifi_state_notifier_register(wifi_state_notifier_s *notifier) { DBG("register notifier"); - notifier_list = g_slist_append(notifier_list, notifier); + g_notifier_list = g_slist_append(g_notifier_list, notifier); } -void wifi_state_notifier_unregister(wifi_state_notifier *notifier) +void wifi_state_notifier_unregister(wifi_state_notifier_s *notifier) { DBG("un-register notifier"); - notifier_list = g_slist_remove_all(notifier_list, notifier); + g_notifier_list = g_slist_remove_all(g_notifier_list, notifier); } void wifi_state_notifier_cleanup(void) { - g_slist_free_full(notifier_list, NULL); + g_slist_free_full(g_notifier_list, NULL); } void wifi_state_set_bss_found(gboolean found) @@ -531,176 +610,280 @@ gboolean wifi_state_is_bss_found(void) return new_bss_found; } -void wifi_state_set_service_state(wifi_service_state_e new_state) +gboolean wifi_state_update_device_list(void) +{ + GVariant *message = NULL, *variant; + GVariantIter *iter, *next; + const char *path; + gchar *key; + gboolean updated = FALSE; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetTechnologies", NULL); + if (message == NULL) { + ERR("Failed to get technologies"); + return updated; + } + + g_slist_free_full(g_device_list, __device_free_data); + g_device_list = NULL; + + g_variant_get(message, "(a(oa{sv}))", &iter); + while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) { + if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0) + continue; + + while (g_variant_iter_loop(next, "{sv}", &key, &variant)) { + if (g_strcmp0(key, "Device.List") == 0) { + GVariantIter *list_iter; + gchar *dev_key; + GVariant *dev_var; + const gchar *sdata; + wifi_device_data_s *device_data = NULL; + + g_variant_get(variant, "a{sv}", &list_iter); + while(g_variant_iter_loop(list_iter, "{sv}", &dev_key, &dev_var)) { + if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_STRING)) { + if (g_strcmp0(dev_key, "Ifname") == 0) { + device_data = g_try_malloc0(sizeof(wifi_device_data_s)); + if (!device_data) { + g_variant_unref(dev_var); + break; + } + + sdata = g_variant_get_string(dev_var, NULL); + device_data->interface_name = g_strdup(sdata); + g_device_list = g_slist_append(g_device_list, device_data); + + updated = TRUE; + + } else if (g_strcmp0(dev_key, "MAC.Address") == 0) { + if (device_data) { + sdata = g_variant_get_string(dev_var, NULL); + device_data->mac_address = g_strdup(sdata); + + DBG("Ifname[%s] MAC[%s] Powered[%d] Connected[%d]", + device_data->interface_name, device_data->mac_address, + device_data->powered, device_data->connected); + } + } + } else if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_BOOLEAN)) { + if (g_strcmp0(dev_key, "Powered") == 0) { + if (device_data) { + device_data->powered = g_variant_get_boolean(dev_var); + if (device_data->powered == TRUE) + device_data->tech_state = NETCONFIG_WIFI_TECH_POWERED; + else + device_data->tech_state = NETCONFIG_WIFI_TECH_OFF; + } + } else if (g_strcmp0(dev_key, "Connected") == 0) { + if (device_data) { + device_data->connected = g_variant_get_boolean(dev_var); + if (device_data->connected == TRUE) + device_data->tech_state = NETCONFIG_WIFI_TECH_CONNECTED; + } + } + } + } + + g_variant_iter_free(list_iter); + } + } + } + + g_variant_unref(message); + + g_variant_iter_free(iter); + + return updated; +} + +GSList *wifi_state_get_device_list(void) +{ + return g_device_list; +} + +static gboolean __state_update_device_list(gpointer data) +{ + if (wifi_state_update_device_list() == FALSE) + return TRUE; + + netconfig_stop_timer(&network_update_timer_id); + return FALSE; +} + +void wifi_state_set_service_state(const char *interface_name, wifi_service_state_e new_state) { static gboolean dhcp_stage = FALSE; - wifi_service_state_e old_state = g_service_state; + wifi_device_data_s *device_data = NULL; + wifi_service_state_e old_state = NETCONFIG_WIFI_UNKNOWN; + + device_data = __device_get_data(interface_name); + if (!device_data) + return; + old_state = device_data->service_state; if (old_state == new_state) return; - g_service_state = new_state; + device_data->service_state = new_state; DBG("Wi-Fi service state, old state[%s] ==> new state[%s]", _convert_wifi_service_state_to_string(old_state), _convert_wifi_service_state_to_string(new_state)); /* From association, temporarily disable Wi-Fi power saving */ if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_ASSOCIATION) { _set_power_lock(TRUE); - wifi_set_early_suspend(FALSE); + wifi_set_early_suspend(interface_name, FALSE); dhcp_stage = TRUE; } else if (dhcp_stage == TRUE && new_state != NETCONFIG_WIFI_CONFIGURATION) { _set_power_lock(FALSE); - wifi_set_early_suspend(TRUE); + wifi_set_early_suspend(interface_name, TRUE); dhcp_stage = FALSE; } if (new_state == NETCONFIG_WIFI_CONNECTED) { netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL); - netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED); - netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED); + __update_wifi_state(); netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_CONNECTED); __set_wifi_connected_essid(); - netconfig_wifi_indicator_start(); + netconfig_wifi_indicator_start(interface_name); } else if (old_state == NETCONFIG_WIFI_CONNECTED) { netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL); __unset_wifi_connected_essid(); - netconfig_set_vconf_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED); - netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); + __update_wifi_state(); netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON); - netconfig_wifi_indicator_stop(); + netconfig_wifi_indicator_stop(interface_name); - netconfig_wifi_bgscan_stop(); - netconfig_wifi_bgscan_set_interval(SCAN_EXPONENTIAL_MIN); - netconfig_wifi_bgscan_start(TRUE); + netconfig_wifi_bgscan_stop(interface_name); + netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_start(interface_name, TRUE); } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE) { /* in ipv6 case disconnect/association -> association */ DBG("reset the bg scan period"); - netconfig_wifi_bgscan_stop(); - netconfig_wifi_bgscan_start(TRUE); + netconfig_wifi_bgscan_stop(interface_name); + netconfig_wifi_bgscan_start(interface_name, TRUE); } - _wifi_state_changed(new_state); + _wifi_state_changed(interface_name, new_state); if (new_state == NETCONFIG_WIFI_CONNECTED) _wifi_state_connected_activation(); } -wifi_service_state_e wifi_state_get_service_state(void) +wifi_service_state_e wifi_state_get_service_state(const char *interface_name) { - return g_service_state; + wifi_device_data_s *device_data = __device_get_data(interface_name); + if (!device_data) + return NETCONFIG_WIFI_UNKNOWN; + + return device_data->service_state; } -void wifi_state_set_tech_state(wifi_tech_state_e new_state) +void wifi_state_set_technology_state(const char *interface_name, wifi_tech_state_e new_state) { - wifi_tech_state_e old_state = g_tech_state; + wifi_device_data_s *device_data = NULL; - if (old_state == new_state) - return; + device_data = __device_get_data(interface_name); + if (device_data) { + if (device_data->tech_state == new_state) + return; - g_tech_state = new_state; + DBG("Wi-Fi %s technology state, old state[%s] ==> new state[%s]", interface_name, + _convert_wifi_technology_state_to_string(device_data->tech_state), + _convert_wifi_technology_state_to_string(new_state)); - DBG("Wi-Fi technology state, old state[%s] ==> new state[%s]", - _convert_wifi_technology_state_to_string(old_state), _convert_wifi_technology_state_to_string(new_state)); + device_data->tech_state = new_state; + } } -wifi_tech_state_e wifi_state_get_technology_state(bool mode) +wifi_tech_state_e wifi_state_get_technology_state(const char *interface_name) { - GVariant *message = NULL, *variant; - GVariantIter *iter, *next; - wifi_tech_state_e ret = NETCONFIG_WIFI_TECH_OFF; - gboolean wifi_tech_powered = FALSE; - gboolean wifi_tech_connected = FALSE; - const char *path; - gchar *key; + wifi_device_data_s *device_data = NULL; - if (!mode && g_tech_state > NETCONFIG_WIFI_TECH_UNKNOWN) - return g_tech_state; + device_data = __device_get_data(interface_name); + if (device_data) { + DBG("Wi-Fi %s technology state [%s]", interface_name, + _convert_wifi_technology_state_to_string(device_data->tech_state)); - message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, - CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, - "GetTechnologies", NULL); - if (message == NULL) { - ERR("Failed to get_technology_state"); - return NETCONFIG_WIFI_TECH_UNKNOWN; + return device_data->tech_state; } - g_variant_get(message, "(a(oa{sv}))", &iter); - while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) { - if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0) - continue; + return NETCONFIG_WIFI_TECH_UNKNOWN; +} - while (g_variant_iter_loop(next, "{sv}", &key, &variant)) { - const gchar *sdata = NULL; - gboolean data; - - if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) { - data = g_variant_get_boolean(variant); - DBG("key-[%s] - %s", key, data ? "True" : "False"); - - if (strcmp(key, "Powered") == 0 && data) - wifi_tech_powered = TRUE; - else if (strcmp(key, "Connected") == 0 && data) - wifi_tech_connected = TRUE; - /* For further use - else if (strcmp(key, "Tethering") == 0 && data) { - } */ - } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) { - sdata = g_variant_get_string(variant, NULL); - DBG("%s", sdata); - } - } +void wifi_state_set_powered(const char *interface_name, gboolean powered) +{ + wifi_device_data_s *device_data = __device_get_data(interface_name); + + if (device_data) { + device_data->powered = powered; + DBG("Wi-Fi %s [%s]", interface_name, powered ? "enabled" : "disabled"); } +} - g_variant_unref(message); +gboolean wifi_state_get_powered(const char *interface_name) +{ + wifi_device_data_s *device_data = __device_get_data(interface_name); + if (!device_data) + return FALSE; - g_variant_iter_free(iter); + return device_data->powered; +} - if (wifi_tech_powered == TRUE) - ret = NETCONFIG_WIFI_TECH_POWERED; +void wifi_state_set_connected(const char *interface_name, gboolean connected) +{ + wifi_device_data_s *device_data = __device_get_data(interface_name); - if (wifi_tech_connected == TRUE) - ret = NETCONFIG_WIFI_TECH_CONNECTED; + if (device_data) { + device_data->connected = connected; + DBG("Wi-Fi %s [%s]", interface_name, connected ? "connected" : "disconnected"); + } +} - g_tech_state = ret; +gboolean wifi_state_get_connected(const char *interface_name) +{ + wifi_device_data_s *device_data = __device_get_data(interface_name); + if (!device_data) + return FALSE; - return g_tech_state; + return device_data->connected; } -gboolean wifi_state_is_technology_available(void) +gboolean wifi_state_is_existed(const char *interface_name) { - GVariant *message = NULL; - GVariantIter *iter, *next; - const char *path; - gboolean ret = FALSE; - - message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, - CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, - "GetTechnologies", NULL); - if (message == NULL) { - ERR("Failed to get_technology_state"); + wifi_device_data_s *device_data = __device_get_data(interface_name); + if (!device_data) return FALSE; - } - g_variant_get(message, "(a(oa{sv}))", &iter); - while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) { - if (path != NULL && g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == 0) - ret = TRUE; - } + return TRUE; +} - g_variant_unref(message); - g_variant_iter_free(iter); +const char *wifi_state_get_interface_name(const char *mac_address) +{ + wifi_device_data_s *device_data = __device_get_data_by_macaddr(mac_address); + if (!device_data) + return NULL; + + return device_data->interface_name; +} - DBG("Wi-Fi technology is %s", ret ? "available" : "unavailable"); - return ret; +const char *wifi_state_get_mac_address(const char *interface_name) +{ + wifi_device_data_s *device_data = __device_get_data(interface_name); + if (!device_data) + return NULL; + + return device_data->mac_address; } void wifi_state_set_connected_essid(void) @@ -713,58 +896,14 @@ void wifi_state_get_connected_essid(gchar **essid) *essid = g_strdup(__get_wifi_connected_essid()); } -/* wifi_connection_state_e in CAPI - * - * WIFI_CONNECTION_STATE_FAILURE = -1 - * WIFI_CONNECTION_STATE_DISCONNECTED = 0 - * WIFI_CONNECTION_STATE_ASSOCIATION = 1 - * WIFI_CONNECTION_STATE_CONFIGURATION = 2 - * WIFI_CONNECTION_STATE_CONNECTED = 3 - */ -/* connection_wifi_state_e in CAPI - * - * CONNECTION_WIFI_STATE_DEACTIVATED = 0 - * CONNECTION_WIFI_STATE_DISCONNECTED = 1 - * CONNECTION_WIFI_STATE_CONNECTED = 2 - */ -gboolean handle_get_wifi_state(Wifi *wifi, GDBusMethodInvocation *context) -{ - g_return_val_if_fail(wifi != NULL, TRUE); - GVariant *param = NULL; - wifi_tech_state_e tech_state = NETCONFIG_WIFI_TECH_UNKNOWN; - wifi_service_state_e service_state = NETCONFIG_WIFI_UNKNOWN; - tech_state = wifi_state_get_technology_state(FALSE); - service_state = wifi_state_get_service_state(); - - if (tech_state == NETCONFIG_WIFI_TECH_UNKNOWN) - param = g_variant_new("(s)", "unknown"); - else if (tech_state == NETCONFIG_WIFI_TECH_OFF || - tech_state == NETCONFIG_WIFI_TECH_WPS_ONLY) - param = g_variant_new("(s)", "deactivated"); - else if (tech_state == NETCONFIG_WIFI_TECH_CONNECTED) - param = g_variant_new("(s)", "connected"); - else { - switch (service_state) { - case NETCONFIG_WIFI_FAILURE: - param = g_variant_new("(s)", "failure"); - break; - case NETCONFIG_WIFI_ASSOCIATION: - param = g_variant_new("(s)", "association"); - break; - case NETCONFIG_WIFI_CONFIGURATION: - param = g_variant_new("(s)", "configuration"); - break; - case NETCONFIG_WIFI_CONNECTED: - param = g_variant_new("(s)", "connected"); - break; - case NETCONFIG_WIFI_UNKNOWN: - case NETCONFIG_WIFI_IDLE: - default: - param = g_variant_new("(s)", "disconnected"); - } - } - - g_dbus_method_invocation_return_value(context, param); +void wifi_state_initialize(void) +{ + if (wifi_state_update_device_list() == FALSE) + netconfig_start_timer(NETCONFIG_UPDATE_DEVICE_LIST_TIMEOUT, + __state_update_device_list, NULL, &network_update_timer_id); +} - return TRUE; +void wifi_state_deinitialize(void) +{ + g_slist_free_full(g_device_list, __device_free_data); } diff --git a/src/wifi-tdls.c b/src/wifi-tdls.c index 60e3a62..f42ed2a 100755 --- a/src/wifi-tdls.c +++ b/src/wifi-tdls.c @@ -52,14 +52,15 @@ static void stop_tdls_timer() } } -void __netconfig_wifi_notify_tdls_event(const char *sig_name, const char *peer_mac) +void __netconfig_wifi_notify_tdls_event(const char *interface_name, + const char *sig_name, const char *peer_mac) { GVariantBuilder *builder; GVariant *params; + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); g_variant_builder_add(builder, "{sv}", "peermac", g_variant_new_string(peer_mac)); - - params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + params = g_variant_new("(s@a{sv})", interface_name, g_variant_builder_end(builder)); g_variant_builder_unref(builder); netconfig_dbus_emit_signal(NULL, @@ -71,16 +72,17 @@ void __netconfig_wifi_notify_tdls_event(const char *sig_name, const char *peer_m INFO("Sent signal (%s) Peer Mac (%s)", sig_name, peer_mac); } -void __netconfig_wifi_notify_tdls_discover_event(const char *peer_mac, int discover_type) +void __netconfig_wifi_notify_tdls_discover_event(const char *interface_name, + const char *peer_mac, int discover_type) { GVariantBuilder *builder; GVariant *params; + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); g_variant_builder_add(builder, "{sv}", "peermac", g_variant_new_string(peer_mac)); g_variant_builder_add(builder, "{sv}", "discover_type", g_variant_new_int32(discover_type)); - - params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + params = g_variant_new("(s@a{sv})", interface_name, g_variant_builder_end(builder)); g_variant_builder_unref(builder); netconfig_dbus_emit_signal(NULL, @@ -94,26 +96,32 @@ void __netconfig_wifi_notify_tdls_discover_event(const char *peer_mac, int disco static gboolean _tdls_timer_discover_event(gpointer user_data) { + char *interface_name = user_data; - if (tdls_timer_id == 0) + if (tdls_timer_id == 0) { + g_free(interface_name); return FALSE; + } INFO("[TDLS Discover Timer Expired"); - __netconfig_wifi_notify_tdls_discover_event("00:00:00:00:00:00", is_discover_broadcast); + __netconfig_wifi_notify_tdls_discover_event(interface_name, + "00:00:00:00:00:00", is_discover_broadcast); is_discover_broadcast = 0; stop_tdls_timer(); is_timer_expired = 1; + g_free(interface_name); return FALSE; } -static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const char *str) +static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char *interface_name, + const char *method, const char *str) { GVariant *message = NULL; char *if_path = NULL; GVariant *params = NULL; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { ERR("Fail to get wpa_supplicant DBus path"); return NULL; @@ -130,7 +138,7 @@ static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const } gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, - gchar *peer_mac_Addr) + const gchar *ifname, gchar *peer_mac_Addr) { DBG("[TizenMW-->WPAS]: TDLS Setup Request: [%s]", peer_mac_Addr); @@ -138,7 +146,7 @@ gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, ERR(" Already TDLS Connection !!!"); } else { GVariant *message = NULL; - message = __netconfig_wifi_tdls_send_dbus_str("TDLSSetup", (const char*)peer_mac_Addr); + message = __netconfig_wifi_tdls_send_dbus_str(ifname, "TDLSSetup", (const char*)peer_mac_Addr); if (message == NULL) { ERR(" TDLS : failed to connect !!!"); @@ -156,7 +164,7 @@ gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, } gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, - gchar *peer_mac_Addr) + const gchar *ifname, gchar *peer_mac_Addr) { DBG("TDLS Discover Request: [%s]", peer_mac_Addr); int discover_timeout = 0; @@ -169,7 +177,7 @@ gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, return TRUE; } - message = __netconfig_wifi_tdls_send_dbus_str("TDLSDiscover", (const char*)peer_mac_Addr); + message = __netconfig_wifi_tdls_send_dbus_str(ifname, "TDLSDiscover", (const char*)peer_mac_Addr); if (message == NULL) { ERR(" TDLS : failed to discover !!!"); @@ -192,14 +200,14 @@ gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, is_timer_expired = 0; tdls_timer_id = g_timeout_add_seconds(discover_timeout, - _tdls_timer_discover_event, NULL); + _tdls_timer_discover_event, g_strdup(ifname)); wifi_complete_tdls_discover(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR); return TRUE; } gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, - gchar *peer_mac_Addr) + const gchar *ifname, gchar *peer_mac_Addr) { DBG("[TizenMW-->WPAS]: TDLS Teardown Request: [%s]", peer_mac_Addr); @@ -208,7 +216,7 @@ gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, wifi_complete_tdls_disconnect(wifi, context, NETCONFIG_ERROR_TDLS_ALREADY_DONE); } else { GVariant *message = NULL; - message = __netconfig_wifi_tdls_send_dbus_str("TDLSTeardown", (const char*)peer_mac_Addr); + message = __netconfig_wifi_tdls_send_dbus_str(ifname, "TDLSTeardown", (const char*)peer_mac_Addr); if (message == NULL) { ERR(" TDLS : failed to disconnect !!!"); @@ -225,7 +233,8 @@ gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, return TRUE; } -gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { DBG("[TizenMW-->WPAS]: TDLS Connected Peer Request: "); @@ -237,7 +246,7 @@ gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context) wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00"); return TRUE; } - message = __netconfig_wifi_tdls_send_dbus_str("TDLSStatus", (const char*)peer_mac); + message = __netconfig_wifi_tdls_send_dbus_str(ifname, "TDLSStatus", (const char*)peer_mac); if (message == NULL) { ERR(" TDLS : No active TDLS Link Setup !!!"); wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00"); @@ -263,7 +272,7 @@ gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context) } gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context, - gchar *peer_mac_Addr, int freq) + const gchar *ifname, gchar *peer_mac_Addr, int freq) { GVariant *message = NULL; GVariantBuilder *builder; @@ -295,7 +304,7 @@ gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context, params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); g_variant_builder_unref(builder); - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(ifname); if (if_path == NULL) { ERR("Fail to get wpa_supplicant DBus path"); @@ -305,7 +314,8 @@ gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context, } message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE, - if_path, SUPPLICANT_INTERFACE ".Interface", "TDLSChannelSwitch", params); + if_path, SUPPLICANT_INTERFACE ".Interface", + "TDLSChannelSwitch", params); g_free(if_path); if (message == NULL) { @@ -324,7 +334,7 @@ gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context, gboolean handle_tdls_cancel_channel_switch(Wifi *wifi, GDBusMethodInvocation *context, - gchar *peer_mac_Addr) + const gchar *ifname, gchar *peer_mac_Addr) { GVariant *message = NULL; @@ -333,7 +343,8 @@ gboolean handle_tdls_cancel_channel_switch(Wifi *wifi, GDBusMethodInvocation *co wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH); return TRUE; } - message = __netconfig_wifi_tdls_send_dbus_str("TDLSCancelChannelSwitch", (const char*)peer_mac_Addr); + message = __netconfig_wifi_tdls_send_dbus_str(ifname, + "TDLSCancelChannelSwitch", (const char*)peer_mac_Addr); if (message == NULL) { ERR(" TDLS : Fail to TDLS Cancel Channel Swicth Request !!!"); wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH); @@ -347,7 +358,7 @@ gboolean handle_tdls_cancel_channel_switch(Wifi *wifi, GDBusMethodInvocation *co return TRUE; } -void netconfig_wifi_tdls_connected_event(GVariant *message) +void netconfig_wifi_tdls_connected_event(const char *interface_name, GVariant *message) { DBG("WiFi TDLS Connected EVENT"); @@ -360,10 +371,10 @@ void netconfig_wifi_tdls_connected_event(GVariant *message) INFO("Peer Mac Address: [%s]", peer_mac); is_connected = 1; - __netconfig_wifi_notify_tdls_event("TDLSConnect", peer_mac); + __netconfig_wifi_notify_tdls_event(interface_name, "TDLSConnect", peer_mac); } -void netconfig_wifi_tdls_disconnected_event(GVariant *message) +void netconfig_wifi_tdls_disconnected_event(const char *interface_name, GVariant *message) { DBG("WiFi TDLS Disconnected EVENT"); const gchar *peer_mac_addr = NULL; @@ -372,13 +383,13 @@ void netconfig_wifi_tdls_disconnected_event(GVariant *message) if (g_strcmp0(peer_mac, peer_mac_addr) == 0) { INFO("TDLS Peer Disconnected Mac Address: [%s]", peer_mac); is_connected = 0; - __netconfig_wifi_notify_tdls_event("TDLSDisconnect", peer_mac); + __netconfig_wifi_notify_tdls_event(interface_name, "TDLSDisconnect", peer_mac); } else INFO("TDLS Peer Disconnected peer_mac(%s) != peer_mac_address(%s)", peer_mac, peer_mac_addr); } -void netconfig_wifi_tdls_peer_found_event(GVariant *message) +void netconfig_wifi_tdls_peer_found_event(const char *interface_name, GVariant *message) { DBG("WiFi TDLS Discovery EVENT Received !!"); const gchar *peer_mac_addr = NULL; @@ -391,7 +402,7 @@ void netconfig_wifi_tdls_peer_found_event(GVariant *message) if (is_discover_broadcast == 0) stop_tdls_timer(); - __netconfig_wifi_notify_tdls_discover_event(peer_mac_addr, is_discover_broadcast); + __netconfig_wifi_notify_tdls_discover_event(interface_name, peer_mac_addr, is_discover_broadcast); } else DBG("Timer expired: Do not process the TDLS Discovery Event"); } diff --git a/src/wifi-wps.c b/src/wifi-wps.c index 2a80959..2704c1b 100755 --- a/src/wifi-wps.c +++ b/src/wifi-wps.c @@ -31,14 +31,97 @@ #include "netsupplicant.h" #include "wifi-background-scan.h" -struct netconfig_wifi_wps { +typedef struct { + char *interface_name; char *pin; gboolean pbc; -}; +} wifi_wps_s; -static struct netconfig_wifi_wps wifi_wps; +GSList *g_wifi_wps_list = NULL; -void netconfig_wifi_notify_wps_credentials(const char *ssid, gsize ssid_len, const char *wps_key) +static void __free_wifi_wps(gpointer data) +{ + wifi_wps_s *wifi_wps = data; + + g_free(wifi_wps->interface_name); + g_free(wifi_wps->pin); + g_free(wifi_wps); +} + +static wifi_wps_s *__get_wifi_wps(const char *interface_name) +{ + GSList *list = NULL; + + for (list = g_wifi_wps_list; list; list = list->next) { + wifi_wps_s *wifi_wps = list->data; + if (g_strcmp0(wifi_wps->interface_name, interface_name) == 0) + return wifi_wps; + } + + return NULL; +} + +static void __destroy_wifi_wps(const char *interface_name) +{ + wifi_wps_s *wifi_wps; + + wifi_wps = __get_wifi_wps(interface_name); + if (wifi_wps == NULL) + return; + + g_wifi_wps_list = g_slist_remove(g_wifi_wps_list, wifi_wps); + __free_wifi_wps(wifi_wps); +} + +static void __create_wifi_wps(const char *interface_name) +{ + wifi_wps_s *wifi_wps; + + wifi_wps = g_try_new0(wifi_wps_s, 1); + if (wifi_wps == NULL) + return; + + wifi_wps->interface_name = g_strdup(interface_name); + g_wifi_wps_list = g_slist_append(g_wifi_wps_list, wifi_wps); +} + +static void __set_wifi_wps(const char *interface_name, gboolean pbc, char *pin) +{ + wifi_wps_s *wifi_wps; + + wifi_wps = __get_wifi_wps(interface_name); + if (wifi_wps == NULL) + return; + + wifi_wps->pbc = pbc; + if (pin) + wifi_wps->pin = g_strdup(pin); +} + +static gboolean __get_wifi_wps_pbc(const char *interface_name) +{ + wifi_wps_s *wifi_wps; + + wifi_wps = __get_wifi_wps(interface_name); + if (wifi_wps == NULL) + return FALSE; + + return wifi_wps->pbc; +} + +static char *__get_wifi_wps_pin(const char *interface_name) +{ + wifi_wps_s *wifi_wps; + + wifi_wps = __get_wifi_wps(interface_name); + if (wifi_wps == NULL) + return NULL; + + return wifi_wps->pin; +} + +void netconfig_wifi_notify_wps_credentials(const char *interface_name, + const char *ssid, gsize ssid_len, const char *wps_key) { GVariantBuilder *builder; GVariant *params; @@ -56,7 +139,8 @@ void netconfig_wifi_notify_wps_credentials(const char *ssid, gsize ssid_len, con g_variant_builder_unref(rawssid_builder); g_variant_builder_add(builder, "{sv}", prop_key, g_variant_new_string(wps_key)); - params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + params = g_variant_new("(s@a{sv})", interface_name, + g_variant_builder_end(builder)); g_variant_builder_unref(builder); netconfig_dbus_emit_signal(NULL, @@ -69,7 +153,8 @@ void netconfig_wifi_notify_wps_credentials(const char *ssid, gsize ssid_len, con return; } -void netconfig_wifi_notify_wps_completed(const char *ssid, gsize ssid_len) +void netconfig_wifi_notify_wps_completed(const char *interface_name, + const char *ssid, gsize ssid_len) { GVariantBuilder *builder; GVariant *params; @@ -85,7 +170,8 @@ void netconfig_wifi_notify_wps_completed(const char *ssid, gsize ssid_len) g_variant_builder_add(builder, "{sv}", prop_ssid, g_variant_new("ay", rawssid_builder)); g_variant_builder_unref(rawssid_builder); - params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + params = g_variant_new("(s@a{sv})", interface_name, + g_variant_builder_end(builder)); g_variant_builder_unref(builder); netconfig_dbus_emit_signal(NULL, @@ -98,7 +184,8 @@ void netconfig_wifi_notify_wps_completed(const char *ssid, gsize ssid_len) return; } -void netconfig_wifi_notify_wps_fail_event(int config_error, int error_indication) +void netconfig_wifi_notify_wps_fail_event(const char *interface_name, + int config_error, int error_indication) { GVariantBuilder *builder; GVariant *params; @@ -110,7 +197,8 @@ void netconfig_wifi_notify_wps_fail_event(int config_error, int error_indication g_variant_builder_add(builder, "{sv}", prop_config_error, g_variant_new_int32(config_error)); g_variant_builder_add(builder, "{sv}", prop_error_indication, g_variant_new_int32(error_indication)); - params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + params = g_variant_new("(s@a{sv})", interface_name, + g_variant_builder_end(builder)); g_variant_builder_unref(builder); netconfig_dbus_emit_signal(NULL, @@ -157,10 +245,12 @@ static void __netconfig_wifi_invoke_wps_connect(GObject *source_object, const char *role = "enrollee", *type, *key; char *if_path = NULL; gboolean reply = FALSE; + char *interface_name = user_data; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { DBG("Fail to get wpa_supplicant DBus path"); + g_free(interface_name); return; } @@ -171,16 +261,17 @@ static void __netconfig_wifi_invoke_wps_connect(GObject *source_object, key = "Type"; - if (wifi_wps.pbc == TRUE) + if (__get_wifi_wps_pbc(interface_name) == TRUE) type = "pbc"; else type = "pin"; g_variant_builder_add(builder, "{sv}", key, g_variant_new_string(type)); - if (wifi_wps.pin != NULL) { + if (__get_wifi_wps_pin(interface_name) != NULL) { key = "Pin"; - g_variant_builder_add(builder, "{sv}", key, g_variant_new_string(wifi_wps.pin)); + g_variant_builder_add(builder, "{sv}", key, + g_variant_new_string(__get_wifi_wps_pin(interface_name))); } message = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); g_variant_builder_unref(builder); @@ -192,16 +283,20 @@ static void __netconfig_wifi_invoke_wps_connect(GObject *source_object, SUPPLICANT_IFACE_WPS, "Start", message, - (GAsyncReadyCallback) interface_wps_start_result); + (GAsyncReadyCallback) interface_wps_start_result, + NULL); - g_free(if_path); if (reply != TRUE) ERR("Fail to Scan"); + __destroy_wifi_wps(interface_name); + g_free(interface_name); + g_free(if_path); return; } -static gboolean __netconfig_wifi_invoke_wps_process_credentials(char *object_path) +static gboolean __netconfig_wifi_invoke_wps_process_credentials(char *object_path, + const char *interface_name) { gboolean reply = FALSE; GVariant *params = NULL; @@ -213,8 +308,8 @@ static gboolean __netconfig_wifi_invoke_wps_process_credentials(char *object_pat INFO("[net-config]: TizenMW-->WPAS: .Set"); reply = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE, - object_path, DBUS_INTERFACE_PROPERTIES, - "Set", params, __netconfig_wifi_invoke_wps_connect); + object_path, DBUS_INTERFACE_PROPERTIES, "Set", params, + __netconfig_wifi_invoke_wps_connect, g_strdup(interface_name)); if (reply != TRUE) ERR("M/W--->WPAS: Interface.WPS.Set Method Failed"); @@ -222,17 +317,17 @@ static gboolean __netconfig_wifi_invoke_wps_process_credentials(char *object_pat return reply; } -gboolean netconfig_wifi_wps_connect() +gboolean netconfig_wifi_wps_connect(const char *interface_name) { char *if_path = NULL; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { DBG("Fail to get wpa_supplicant DBus path"); return FALSE; } - if (__netconfig_wifi_invoke_wps_process_credentials(if_path) == TRUE) { + if (__netconfig_wifi_invoke_wps_process_credentials(if_path, interface_name) == TRUE) { ERR("Wi-Fi WPS Connect started"); g_free(if_path); return TRUE; @@ -268,12 +363,12 @@ static void __interface_wps_cancel_result(GObject *source_object, netconfig_gdbus_pending_call_unref(); } -static gboolean __netconfig_wifi_invoke_wps_cancel() +static gboolean __netconfig_wifi_invoke_wps_cancel(const char *interface_name) { gboolean reply = FALSE; char *if_path = NULL; - if_path = netconfig_wifi_get_supplicant_interface(); + if_path = netconfig_wifi_get_supplicant_interface_path(interface_name); if (if_path == NULL) { DBG("Fail to get wpa_supplicant DBus path"); return -ESRCH; @@ -282,8 +377,8 @@ static gboolean __netconfig_wifi_invoke_wps_cancel() DBG("M/W--->WPAS: Interface.WPS.Cancel Method"); reply = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE, - if_path, SUPPLICANT_IFACE_WPS, - "Cancel", NULL, __interface_wps_cancel_result); + if_path, SUPPLICANT_IFACE_WPS, "Cancel", NULL, + __interface_wps_cancel_result, NULL); if (reply != TRUE) ERR("M/W--->WPAS: Interface.WPS.Cancel Method Failed"); @@ -292,22 +387,19 @@ static gboolean __netconfig_wifi_invoke_wps_cancel() return reply; } -gboolean netconfig_get_wps_field() -{ - return wifi_wps.pbc; -} - -gboolean handle_request_wps_cancel(Wifi *wifi, GDBusMethodInvocation *context) +gboolean handle_request_wps_cancel(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname) { INFO("Received WPS PBC Cancel Request"); g_return_val_if_fail(wifi != NULL, TRUE); - __netconfig_wifi_invoke_wps_cancel(); + __netconfig_wifi_invoke_wps_cancel(ifname); wifi_complete_request_wps_cancel(wifi, context); return TRUE; } -gboolean handle_request_wps_connect(Wifi *wifi, GDBusMethodInvocation *context, gchar *param) +gboolean handle_request_wps_connect(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, gchar *param) { INFO("Received WPS PBC/PIN Connection Request"); @@ -315,16 +407,14 @@ gboolean handle_request_wps_connect(Wifi *wifi, GDBusMethodInvocation *context, /* Checking the value of pin if param have a string "PBC" * in that scenario PBC will trigger otherwise PIN Connection */ + __create_wifi_wps(ifname); - if (g_strcmp0(param, "PBC") == 0) { - wifi_wps.pbc = TRUE; - wifi_wps.pin = NULL; - } else { - wifi_wps.pin = g_strdup(param); - wifi_wps.pbc = FALSE; - } + if (g_strcmp0(param, "PBC") == 0) + __set_wifi_wps(ifname, TRUE, NULL); + else + __set_wifi_wps(ifname, FALSE, param); - netconfig_wifi_wps_connect(); + netconfig_wifi_wps_connect(ifname); wifi_complete_request_wps_connect(wifi, context); return TRUE; diff --git a/src/wifi.c b/src/wifi.c index 2623fbd..60f8092 100755 --- a/src/wifi.c +++ b/src/wifi.c @@ -86,6 +86,8 @@ void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res, { GDBusConnection *conn = NULL; GError *error = NULL; + GVariant *params = NULL; + char *interface_name = user_data; DBG("WiFi Connection Reply"); @@ -99,12 +101,15 @@ void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res, g_error_free(error); DBG("WiFi Connection in Progress"); netconfig_gdbus_pending_call_unref(); + g_free(interface_name); return; } g_error_free(error); + + params = g_variant_new("(s)", interface_name); if (netconfig_dbus_emit_signal(NULL, NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, "WiFiConnectFail", - NULL) == FALSE) + params) == FALSE) ERR("Failed to emit WiFiConnectFail signal"); else DBG("Successfully sent WiFiConnectFail signal"); @@ -112,6 +117,7 @@ void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res, DBG("WiFi Connection has been initiated successfully"); netconfig_gdbus_pending_call_unref(); + g_free(interface_name); return; } @@ -187,10 +193,6 @@ void wifi_object_create_and_init(void) g_signal_connect(wifi_object, "handle-remove-p2p-driver", G_CALLBACK(handle_remove_p2p_driver), NULL); - /* WIFI state */ - g_signal_connect(wifi_object, "handle-get-wifi-state", - G_CALLBACK(handle_get_wifi_state), NULL); - /* WIFI scan */ g_signal_connect(wifi_object, "handle-request-bssid-scan", G_CALLBACK(handle_request_bssid_scan), NULL); @@ -374,6 +376,7 @@ void wifi_object_create_and_init(void) _set_wifi_mac_address(); + wifi_state_initialize(); wifi_power_initialize(); return; @@ -386,4 +389,5 @@ void wifi_object_deinit(void) g_object_unref(wififirmware_object); wifi_power_deinitialize(); + wifi_state_deinitialize(); } -- 2.34.1