From 1ff4bffc29b8a263497175a45628e98601061c0d Mon Sep 17 00:00:00 2001 From: "taesub.kim" Date: Mon, 5 Oct 2015 17:10:35 +0900 Subject: [PATCH] Sync with Tizen 2.4(v1.1.38) Change-Id: Icfc3ff487dedf07782b11c12fd1484d5e3088c90 Signed-off-by: Taesub Kim --- AUTHORS | 5 - CMakeLists.txt | 0 LICENSE | 0 include/cellular-state.h | 29 +- include/clatd-handler.h | 0 include/emulator.h | 4 +- include/log.h | 5 +- include/netdbus.h | 17 +- include/neterror.h | 1 + include/netsupplicant.h | 0 include/network-accessibility.h | 3 + include/network-clock.h | 0 include/network-state.h | 26 +- include/network-statistics.h | 8 +- include/signal-handler.h | 4 +- include/util.h | 3 + include/wifi-agent.h | 4 +- include/wifi-background-scan.h | 0 include/wifi-config.h | 37 +- include/wifi-dump.h | 0 include/wifi-eap-config.h | 0 include/wifi-eap.h | 6 +- include/wifi-firmware.h | 0 include/wifi-indicator.h | 0 include/wifi-passpoint.h | 0 include/wifi-power.h | 28 +- include/wifi-ssid-scan.h | 13 +- include/wifi-state.h | 57 +- include/wifi-tel-intf.h | 0 include/wifi.h | 7 +- interfaces/netconfig-iface-network-state.xml | 0 interfaces/netconfig-iface-network-statistics.xml | 0 interfaces/netconfig-iface-wifi.xml | 46 +- net-config.manifest | 0 packaging/net-config.spec | 3 +- resources/etc/dbus-1/system.d/net-config.conf | 9 +- resources/etc/resolv.conf | 0 .../opt/etc/dump.d/module.d/network_log_dump.sh | 2 +- .../usr/lib/systemd/system/net-config.service | 0 .../usr/lib/systemd/system/net-config_tv.service | 0 .../usr/lib/udev/rules.d/99-wifiusb-dev.rules | 0 .../share/dbus-1/services/net.netconfig.service | 0 .../dbus-1/system-services/net.netconfig.service | 0 resources/usr/share/wifi_offloading.sql | 0 .../RestoreDir/softreset/network_softreset.sh | 0 .../softreset_post/network_reset_post.sh | 0 .../softreset_prepare/network_reset_pre.sh | 0 src/cellular-state.c | 38 +- src/clatd-handler.c | 0 src/dbus/netdbus.c | 61 +- src/dbus/netsupplicant.c | 15 +- src/main.c | 42 +- src/neterror.c | 19 +- src/network-clock.c | 15 +- src/network-state.c | 34 +- src/network-statistics.c | 47 +- src/signal-handler.c | 150 ++-- src/utils/emulator.c | 7 +- src/utils/log.c | 25 +- src/utils/network-accessibility.c | 168 +++-- src/utils/util.c | 207 +++++- src/wifi-agent.c | 28 +- src/wifi-background-scan.c | 9 +- src/wifi-config.c | 799 +++++++++++++++++---- src/wifi-dump.c | 2 +- src/wifi-eap-config.c | 52 +- src/wifi-eap.c | 113 ++- src/wifi-firmware.c | 26 +- src/wifi-indicator.c | 20 +- src/wifi-passpoint.c | 0 src/wifi-power.c | 585 +++++++++------ src/wifi-ssid-scan.c | 287 ++++---- src/wifi-state.c | 592 ++++++++------- src/wifi-tel-intf.c | 0 src/wifi-wps.c | 51 +- src/wifi.c | 148 ++-- 76 files changed, 2443 insertions(+), 1414 deletions(-) delete mode 100644 AUTHORS mode change 100644 => 100755 CMakeLists.txt mode change 100644 => 100755 LICENSE mode change 100644 => 100755 include/cellular-state.h mode change 100644 => 100755 include/clatd-handler.h mode change 100644 => 100755 include/emulator.h mode change 100644 => 100755 include/log.h mode change 100644 => 100755 include/neterror.h mode change 100644 => 100755 include/netsupplicant.h mode change 100644 => 100755 include/network-accessibility.h mode change 100644 => 100755 include/network-clock.h mode change 100644 => 100755 include/network-statistics.h mode change 100644 => 100755 include/signal-handler.h mode change 100644 => 100755 include/wifi-agent.h mode change 100644 => 100755 include/wifi-background-scan.h mode change 100644 => 100755 include/wifi-config.h mode change 100644 => 100755 include/wifi-dump.h mode change 100644 => 100755 include/wifi-eap-config.h mode change 100644 => 100755 include/wifi-eap.h mode change 100644 => 100755 include/wifi-firmware.h mode change 100644 => 100755 include/wifi-indicator.h mode change 100644 => 100755 include/wifi-passpoint.h mode change 100644 => 100755 include/wifi-ssid-scan.h mode change 100644 => 100755 include/wifi-state.h mode change 100644 => 100755 include/wifi-tel-intf.h mode change 100644 => 100755 include/wifi.h mode change 100644 => 100755 interfaces/netconfig-iface-network-state.xml mode change 100644 => 100755 interfaces/netconfig-iface-network-statistics.xml mode change 100644 => 100755 net-config.manifest mode change 100644 => 100755 resources/etc/dbus-1/system.d/net-config.conf mode change 100644 => 100755 resources/etc/resolv.conf mode change 100644 => 100755 resources/usr/lib/systemd/system/net-config.service mode change 100644 => 100755 resources/usr/lib/systemd/system/net-config_tv.service mode change 100644 => 100755 resources/usr/lib/udev/rules.d/99-wifiusb-dev.rules mode change 100644 => 100755 resources/usr/share/dbus-1/services/net.netconfig.service mode change 100644 => 100755 resources/usr/share/dbus-1/system-services/net.netconfig.service mode change 100644 => 100755 resources/usr/share/wifi_offloading.sql mode change 100644 => 100755 resources/usr/system/RestoreDir/softreset/network_softreset.sh mode change 100644 => 100755 resources/usr/system/RestoreDir/softreset_post/network_reset_post.sh mode change 100644 => 100755 resources/usr/system/RestoreDir/softreset_prepare/network_reset_pre.sh mode change 100644 => 100755 src/cellular-state.c mode change 100644 => 100755 src/clatd-handler.c mode change 100644 => 100755 src/dbus/netdbus.c mode change 100644 => 100755 src/dbus/netsupplicant.c mode change 100644 => 100755 src/neterror.c mode change 100644 => 100755 src/network-clock.c mode change 100644 => 100755 src/signal-handler.c mode change 100644 => 100755 src/utils/emulator.c mode change 100644 => 100755 src/utils/network-accessibility.c mode change 100644 => 100755 src/wifi-agent.c mode change 100644 => 100755 src/wifi-background-scan.c mode change 100644 => 100755 src/wifi-config.c mode change 100644 => 100755 src/wifi-dump.c mode change 100644 => 100755 src/wifi-eap-config.c mode change 100644 => 100755 src/wifi-eap.c mode change 100644 => 100755 src/wifi-passpoint.c mode change 100644 => 100755 src/wifi-ssid-scan.c mode change 100644 => 100755 src/wifi-tel-intf.c diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index df0456d..0000000 --- a/AUTHORS +++ /dev/null @@ -1,5 +0,0 @@ -Danny Jeongseok Seo -Jeik Jaehyun Kim -Sunkey Lee -Sanghoon Cho -DongHoo Park \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/include/cellular-state.h b/include/cellular-state.h old mode 100644 new mode 100755 index a43ae0f..c801730 --- a/include/cellular-state.h +++ b/include/cellular-state.h @@ -24,29 +24,24 @@ extern "C" { #endif -enum netconfig_cellular_service_state { +typedef enum { NETCONFIG_CELLULAR_UNKNOWN = 0x00, NETCONFIG_CELLULAR_IDLE = 0x01, NETCONFIG_CELLULAR_CONNECTING = 0x02, NETCONFIG_CELLULAR_ONLINE = 0x03, -}; +} cellular_service_state_e; -struct netconfig_cellular_state_notifier { - void (*netconfig_cellular_state_changed) - (enum netconfig_cellular_service_state, void *user_data); +typedef struct { + void (*cellular_state_changed)(cellular_service_state_e, void *user_data); void *user_data; -}; - -void netconfig_cellular_state_set_service_state( - enum netconfig_cellular_service_state new_state); -enum netconfig_cellular_service_state - netconfig_cellular_state_get_service_state(void); - -void netconfig_cellular_state_notifier_cleanup(void); -void netconfig_cellular_state_notifier_register( - struct netconfig_cellular_state_notifier *notifier); -void netconfig_cellular_state_notifier_unregister( - struct netconfig_cellular_state_notifier *notifier); +} cellular_state_notifier; + +void cellular_state_set_service_state(cellular_service_state_e new_state); +cellular_service_state_e cellular_state_get_service_state(void); + +void cellular_state_notifier_register(cellular_state_notifier *notifier); +void cellular_state_notifier_unregister(cellular_state_notifier *notifier); +void cellular_state_notifier_cleanup(void); #ifdef __cplusplus } diff --git a/include/clatd-handler.h b/include/clatd-handler.h old mode 100644 new mode 100755 diff --git a/include/emulator.h b/include/emulator.h old mode 100644 new mode 100755 index 3bff8b2..81e1d75 --- a/include/emulator.h +++ b/include/emulator.h @@ -26,8 +26,8 @@ extern "C" { #include -gboolean netconfig_emulator_is_emulated(void); -void netconfig_emulator_test_and_start(void); +gboolean emulator_is_emulated(void); +void emulator_test_and_start(void); #ifdef __cplusplus } diff --git a/include/log.h b/include/log.h old mode 100644 new mode 100755 index 331a5f4..0b4fb6a --- a/include/log.h +++ b/include/log.h @@ -31,12 +31,13 @@ extern "C" { #define NETCONFIG_TAG "NETCONFIG" -void __netconfig_debug(const char *format, ...); +void netconfig_log(const char *format, ...); +void log_cleanup(void); #define __LOG(level, format, arg...) \ do { \ if (NETCONFIG_DEBUG_FILE) { \ - __netconfig_debug("%s(%d) "format"\n", __FUNCTION__, __LINE__, ## arg); \ + netconfig_log("%s(%d) "format"\n", __FUNCTION__, __LINE__, ## arg); \ } \ SLOG(level, NETCONFIG_TAG, format, ## arg); \ } while(0) diff --git a/include/netdbus.h b/include/netdbus.h index 64849bc..b3e40e4 100755 --- a/include/netdbus.h +++ b/include/netdbus.h @@ -70,13 +70,14 @@ typedef enum { NETCONFIG_DBUS_RESULT_DEFAULT_TECHNOLOGY, } netconfig_dbus_result_type; -typedef void (*netconfig_got_name_cb)(void); +typedef void (*got_name_cb)(void); -GDBusObjectManagerServer *netconfig_get_wifi_manager(void); -GDBusObjectManagerServer *netconfig_get_state_manager(void); -GDBusObjectManagerServer *netconfig_get_statistics_manager(void); -GDBusConnection *netconfig_gdbus_get_connection(void); -GCancellable *netconfig_gdbus_get_gdbus_cancellable(void); +GDBusObjectManagerServer *netdbus_get_wifi_manager(void); +GDBusObjectManagerServer *netdbus_get_state_manager(void); +GDBusObjectManagerServer *netdbus_get_statistics_manager(void); + +GDBusConnection *netdbus_get_connection(void); +GCancellable *netdbus_get_cancellable(void); void netconfig_gdbus_pending_call_ref(void); void netconfig_gdbus_pending_call_unref(void); int netconfig_create_gdbus_call(GDBusConnection *conn); @@ -94,8 +95,8 @@ GVariant *netconfig_invoke_dbus_method(const char *dest, const char *path, const char *interface_name, const char *method, GVariant *params); -int netconfig_setup_gdbus(netconfig_got_name_cb cb); -void netconfig_cleanup_gdbus(void); +int setup_gdbus(got_name_cb cb); +void cleanup_gdbus(void); #ifdef __cplusplus } diff --git a/include/neterror.h b/include/neterror.h old mode 100644 new mode 100755 index 177a2ce..df6247b --- a/include/neterror.h +++ b/include/neterror.h @@ -64,6 +64,7 @@ void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context); void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *context); void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context); void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context); +void netconfig_error_fail_save_congifuration(GDBusMethodInvocation *context); void netconfig_error_fail_ethernet_cable_state(GDBusMethodInvocation *context); void netconfig_error_dbus_method_return(GDBusMethodInvocation *context, netconfig_error_e error, const gchar *message); diff --git a/include/netsupplicant.h b/include/netsupplicant.h old mode 100644 new mode 100755 diff --git a/include/network-accessibility.h b/include/network-accessibility.h old mode 100644 new mode 100755 index 23dcc7c..281976f --- a/include/network-accessibility.h +++ b/include/network-accessibility.h @@ -24,6 +24,9 @@ extern "C" { #endif +void netconfig_internet_accessibility_init(void); +void netconfig_internet_accessibility_deinit(void); + void netconfig_check_internet_accessibility(void); void netconfig_stop_internet_check(void); diff --git a/include/network-clock.h b/include/network-clock.h old mode 100644 new mode 100755 diff --git a/include/network-state.h b/include/network-state.h index 417b323..cb892ee 100755 --- a/include/network-state.h +++ b/include/network-state.h @@ -24,20 +24,22 @@ extern "C" { #endif -void netconfig_network_state_create_and_init(void); void netconfig_network_notify_ethernet_cable_state(const char *key); -const char *netconfig_get_default_profile(void); -const char *netconfig_get_default_ifname(void); -const char *netconfig_get_default_ipaddress(void); -const char *netconfig_get_default_ipaddress6(void); -const char *netconfig_get_default_proxy(void); -unsigned int netconfig_get_default_frequency(void); -const char *netconfig_wifi_get_connected_essid(const char *default_profile); - -void netconfig_update_default(void); -void netconfig_update_default_profile(const char *profile); -char *netconfig_network_get_ifname(const char *profile); +const char *netconfig_get_default_profile(void); +const char *netconfig_get_default_ifname(void); +const char *netconfig_get_default_ipaddress(void); +const char *netconfig_get_default_ipaddress6(void); +const char *netconfig_get_default_proxy(void); +unsigned int netconfig_get_default_frequency(void); +const char *netconfig_wifi_get_connected_essid(const char *default_profile); + +void netconfig_update_default(void); +void netconfig_update_default_profile(const char *profile); +char *netconfig_get_ifname(const char *profile); + +void state_object_create_and_init(void); +void state_object_deinit(void); #ifdef __cplusplus } diff --git a/include/network-statistics.h b/include/network-statistics.h old mode 100644 new mode 100755 index 91a79d2..d958676 --- a/include/network-statistics.h +++ b/include/network-statistics.h @@ -28,9 +28,11 @@ extern "C" { #include "wifi-state.h" -void netconfig_network_statistics_create_and_init(void); -gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx); -void netconfig_wifi_statistics_update_powered_off(void); +gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx); +void netconfig_wifi_statistics_update_powered_off(void); + +void statistics_object_create_and_init(void); +void statistics_object_deinit(void); #ifdef __cplusplus } diff --git a/include/signal-handler.h b/include/signal-handler.h old mode 100644 new mode 100755 index 0864452..37a6bff --- a/include/signal-handler.h +++ b/include/signal-handler.h @@ -24,8 +24,8 @@ extern "C" { #endif -void netconfig_register_signal(void); -void netconfig_deregister_signal(void); +void register_gdbus_signal(void); +void deregister_gdbus_signal(void); #ifdef __cplusplus } diff --git a/include/util.h b/include/util.h index 41bd2b0..3c2f9ae 100755 --- a/include/util.h +++ b/include/util.h @@ -68,6 +68,8 @@ int netconfig_execute_file(const char *file_path, char *const args[], char *cons int netconfig_execute_clatd(const char *file_path, char *const args[]); int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len); int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len); +int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family); +int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family); gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context); @@ -82,6 +84,7 @@ int wc_launch_popup(netconfig_wcpopup_type_e type); void netconfig_set_vconf_int(const char * key, int value); void netconfig_set_vconf_str(const char * key, const char * value); char* netconfig_get_env(const char *key); +void netconfig_set_mac_address_from_file(void); #ifdef __cplusplus } diff --git a/include/wifi-agent.h b/include/wifi-agent.h old mode 100644 new mode 100755 index 2c81e18..7631cca --- a/include/wifi-agent.h +++ b/include/wifi-agent.h @@ -26,8 +26,8 @@ extern "C" { #include "wifi.h" -gboolean netconfig_agent_register(void); -gboolean netconfig_agent_unregister(void); +gboolean connman_register_agent(void); +gboolean connman_unregister_agent(void); gboolean netconfig_wifi_set_agent_field_for_eap_network( const char *name, const char *identity, const char *passphrase); diff --git a/include/wifi-background-scan.h b/include/wifi-background-scan.h old mode 100644 new mode 100755 diff --git a/include/wifi-config.h b/include/wifi-config.h old mode 100644 new mode 100755 index 171d26e..891cd0d --- a/include/wifi-config.h +++ b/include/wifi-config.h @@ -26,11 +26,38 @@ extern "C" { #include "wifi.h" -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_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); +// Configuration Field key +#define WIFI_CONFIG_NAME "Name" +#define WIFI_CONFIG_SSID "SSID" +#define WIFI_CONFIG_PASSPHRASE "Passphrase" +#define WIFI_CONFIG_SECURITY_TYPE "Security" +#define WIFI_CONFIG_FAVORITE "Favorite" +#define WIFI_CONFIG_AUTOCONNECT "AutoConnect" +#define WIFI_CONFIG_HIDDEN "Hidden" +#define WIFI_CONFIG_FAILURE "Failure" +#define WIFI_CONFIG_PROXYADDRESS "ProxyAddress" +#define WIFI_CONFIG_PROXY_METHOD "Proxy.Method" +#define WIFI_CONFIG_PROXY_SERVER "Proxy.Servers" +#define WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY "AnonymousIdentity" +#define WIFI_CONFIG_EAP_CACERT "CACertFile" +#define WIFI_CONFIG_EAP_CLIENTCERT "ClientCertFile" +#define WIFI_CONFIG_EAP_PRIVATEKEY "PrivateKeyFile" +#define WIFI_CONFIG_EAP_IDENTITY "Identity" +#define WIFI_CONFIG_EAP_TYPE "EapType" +#define WIFI_CONFIG_EAP_AUTH_TYPE "EapAuthType" +#define WIFI_CONFIG_EAP_SUBJECT_MATCH "SubjectMatch" + +gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id); +gboolean wifi_config_remove_configuration(const gchar *config_id); + +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); #ifdef __cplusplus } diff --git a/include/wifi-dump.h b/include/wifi-dump.h old mode 100644 new mode 100755 diff --git a/include/wifi-eap-config.h b/include/wifi-eap-config.h old mode 100644 new mode 100755 diff --git a/include/wifi-eap.h b/include/wifi-eap.h old mode 100644 new mode 100755 index 58b2f43..ed995f4 --- a/include/wifi-eap.h +++ b/include/wifi-eap.h @@ -27,10 +27,8 @@ extern "C" { #include "wifi.h" gboolean handle_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_req_sim_auth(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *rand_data); -gboolean handle_req_aka_auth(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *rand_data, const gchar *autn_data); +gboolean handle_req_sim_auth(Wifi *wifi, GDBusMethodInvocation *context, GVariant *rand_data); +gboolean handle_req_aka_auth(Wifi *wifi, GDBusMethodInvocation *context, GVariant *rand_data, GVariant *autn_data); gboolean handle_get_sim_auth(Wifi *wifi, GDBusMethodInvocation *context); gboolean handle_get_aka_auth(Wifi *wifi, GDBusMethodInvocation *context); diff --git a/include/wifi-firmware.h b/include/wifi-firmware.h old mode 100644 new mode 100755 diff --git a/include/wifi-indicator.h b/include/wifi-indicator.h old mode 100644 new mode 100755 diff --git a/include/wifi-passpoint.h b/include/wifi-passpoint.h old mode 100644 new mode 100755 diff --git a/include/wifi-power.h b/include/wifi-power.h index ad16403..4929ba4 100755 --- a/include/wifi-power.h +++ b/include/wifi-power.h @@ -26,23 +26,23 @@ extern "C" { #include "wifi.h" -void netconfig_wifi_power_initialize(void); -void netconfig_wifi_power_deinitialize(void); +void wifi_power_initialize(void); +void wifi_power_deinitialize(void); -int netconfig_wifi_on(void); -int netconfig_wifi_off(void); -int netconfig_wifi_driver_and_supplicant(gboolean enable); - -void netconfig_wifi_disable_technology_state_by_only_connman_signal(void); - -void netconfig_wifi_recover_firmware(void); +int wifi_power_on(void); +int wifi_power_off(void); +#if defined TIZEN_WEARABLE +int wifi_power_on_wearable(gboolean device_picker_test); +#endif -gboolean handle_load_driver(Wifi *wifi, - GDBusMethodInvocation *context, gboolean device_picker_test); -gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context); +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); -gboolean handle_load_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context); -gboolean handle_remove_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context); +gboolean handle_load_driver(Wifi *wifi, GDBusMethodInvocation *context, gboolean device_picker_test); +gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context); +gboolean handle_load_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context); +gboolean handle_remove_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context); #if defined TIZEN_TV void __netconfig_set_ether_macaddr(); diff --git a/include/wifi-ssid-scan.h b/include/wifi-ssid-scan.h old mode 100644 new mode 100755 index 22fd1e3..6398bd2 --- a/include/wifi-ssid-scan.h +++ b/include/wifi-ssid-scan.h @@ -26,15 +26,12 @@ extern "C" { #include "wifi.h" -gboolean netconfig_wifi_get_ssid_scan_state(void); +gboolean wifi_ssid_scan(const char *ssid); +gboolean wifi_ssid_scan_get_state(void); +void wifi_ssid_scan_emit_scan_completed(void); +void wifi_ssid_scan_add_bss(GVariant *message); -void netconfig_wifi_notify_ssid_scan_done(void); -void netconfig_wifi_bss_added(GVariant *message); - -gboolean netconfig_wifi_ssid_scan(const char *ssid); - -gboolean handle_request_specific_scan(Wifi *wifi, - GDBusMethodInvocation *context, const gchar *ssid); +gboolean handle_request_specific_scan(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ssid); #ifdef __cplusplus } diff --git a/include/wifi-state.h b/include/wifi-state.h old mode 100644 new mode 100755 index 929b975..f524706 --- a/include/wifi-state.h +++ b/include/wifi-state.h @@ -26,57 +26,56 @@ extern "C" { #include -enum netconfig_wifi_service_state { +typedef enum { NETCONFIG_WIFI_UNKNOWN = 0x00, NETCONFIG_WIFI_IDLE = 0x01, NETCONFIG_WIFI_ASSOCIATION = 0x02, NETCONFIG_WIFI_CONFIGURATION = 0x03, NETCONFIG_WIFI_CONNECTED = 0x04, NETCONFIG_WIFI_FAILURE = 0x05, -}; +} wifi_service_state_e; -enum netconfig_wifi_tech_state { - NETCONFIG_WIFI_TECH_UNKNOWN = 0x00, +typedef enum { + NETCONFIG_WIFI_TECH_UNKNOWN = 0x00, NETCONFIG_WIFI_TECH_OFF = 0x01, NETCONFIG_WIFI_TECH_WPS_ONLY = 0x02, NETCONFIG_WIFI_TECH_POWERED = 0x03, NETCONFIG_WIFI_TECH_CONNECTED = 0x04, NETCONFIG_WIFI_TECH_TETHERED = 0x05, -}; +} wifi_tech_state_e; -struct netconfig_wifi_state_notifier { - void (*netconfig_wifi_state_changed) - (enum netconfig_wifi_service_state, void *user_data); +typedef struct { + void (*wifi_state_changed)(wifi_service_state_e, void *user_data); void *user_data; -}; +} wifi_state_notifier; #define VCONF_WIFI_LAST_POWER_STATE "file/private/wifi/last_power_state" -void netconfig_wifi_set_bss_found(const gboolean found); -gboolean netconfig_wifi_is_bss_found(void); -void netconfig_wifi_state_set_service_state( - enum netconfig_wifi_service_state new_state); -enum netconfig_wifi_service_state - netconfig_wifi_state_get_service_state(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 netconfig_wifi_state_set_technology_state( - enum netconfig_wifi_tech_state new_state); -enum netconfig_wifi_tech_state - netconfig_wifi_state_get_technology_state(void); +char *wifi_get_favorite_service(void); +void wifi_start_timer_network_notification(void); -void netconfig_wifi_notify_power_failed(void); -void netconfig_wifi_notify_power_completed(gboolean power_on); -void netconfig_wifi_update_power_state(gboolean powered); +void wifi_state_notifier_register(wifi_state_notifier *notifier); +void wifi_state_notifier_unregister(wifi_state_notifier *notifier); +void wifi_state_notifier_cleanup(void); -char *netconfig_wifi_get_favorite_service(void); +void wifi_state_set_bss_found(gboolean found); +gboolean wifi_state_is_bss_found(void); -void netconfig_wifi_start_timer_network_notification(void); +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_tech_state(wifi_tech_state_e new_state); +wifi_tech_state_e wifi_state_get_technology_state(void); + +void wifi_state_set_connected_essid(void); +void wifi_state_get_connected_essid(gchar **essid); + +gboolean handle_get_wifi_state(Wifi *wifi, GDBusMethodInvocation *context); -void netconfig_wifi_state_notifier_cleanup(void); -void netconfig_wifi_state_notifier_register( - struct netconfig_wifi_state_notifier *notifier); -void netconfig_wifi_state_notifier_unregister( - struct netconfig_wifi_state_notifier *notifier); #ifdef __cplusplus } diff --git a/include/wifi-tel-intf.h b/include/wifi-tel-intf.h old mode 100644 new mode 100755 diff --git a/include/wifi.h b/include/wifi.h old mode 100644 new mode 100755 index 5026d5d..9163ab7 --- a/include/wifi.h +++ b/include/wifi.h @@ -34,9 +34,10 @@ extern "C" { #define WIFI_CERT_STORAGEDIR "/var/lib/wifi/cert" #define CONNMAN_STORAGEDIR "/var/lib/connman" -void netconfig_wifi_create_and_init(void); -void netconfig_wifi_init(void); -Wifi *get_netconfig_wifi_object(void); +void wifi_object_create_and_init(void); +void wifi_object_deinit(void); + +Wifi *get_wifi_object(void); #ifdef __cplusplus } diff --git a/interfaces/netconfig-iface-network-state.xml b/interfaces/netconfig-iface-network-state.xml old mode 100644 new mode 100755 diff --git a/interfaces/netconfig-iface-network-statistics.xml b/interfaces/netconfig-iface-network-statistics.xml old mode 100644 new mode 100755 diff --git a/interfaces/netconfig-iface-wifi.xml b/interfaces/netconfig-iface-wifi.xml index 6c7bf81..6a5827b 100755 --- a/interfaces/netconfig-iface-wifi.xml +++ b/interfaces/netconfig-iface-wifi.xml @@ -12,6 +12,9 @@ + + + @@ -30,29 +33,36 @@ - - - - + + - + + - - + + - + + + + + + + + + + + + + - - - - @@ -65,12 +75,18 @@ - + + + - - + + + + + + diff --git a/net-config.manifest b/net-config.manifest old mode 100644 new mode 100755 diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 38448ab..cebe4c1 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.40 +Version: 1.1.41 Release: 2 Group: System/Network License: Apache-2.0 @@ -155,6 +155,7 @@ vconftool set -t int memory/private/wifi/frequency 0 -i -s tizen::vconf::platfor #Network logs mkdir -p /opt/usr/data/network chmod 755 /opt/usr/data/network +chsmack -a net-config::logging /opt/usr/data/network #Add net-config.service to systemd extra default dependency ignore list mkdir -p %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/ diff --git a/resources/etc/dbus-1/system.d/net-config.conf b/resources/etc/dbus-1/system.d/net-config.conf old mode 100644 new mode 100755 index a4e61cb..4196cb5 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -31,14 +31,19 @@ + + + + + + + - - diff --git a/resources/etc/resolv.conf b/resources/etc/resolv.conf old mode 100644 new mode 100755 diff --git a/resources/opt/etc/dump.d/module.d/network_log_dump.sh b/resources/opt/etc/dump.d/module.d/network_log_dump.sh index 3f9340d..72399c2 100755 --- a/resources/opt/etc/dump.d/module.d/network_log_dump.sh +++ b/resources/opt/etc/dump.d/module.d/network_log_dump.sh @@ -26,5 +26,5 @@ NETWORK_DEBUG=$1/network /usr/bin/vconftool get file/private/wifi >> ${NETWORK_DEBUG}/status /usr/bin/vconftool get db/wifi >> ${NETWORK_DEBUG}/status /sbin/ifconfig -a > ${NETWORK_DEBUG}/ifconfig -/bin/mv ${NETWORK_ORG}/tcpdump*.pcap $1/../ +/bin/mv ${NETWORK_ORG}/tcpdump*.pcap* $1/../ /bin/tar -czf ${NETWORK_DEBUG}/network.tar.gz -C ${NETWORK_ORG} . diff --git a/resources/usr/lib/systemd/system/net-config.service b/resources/usr/lib/systemd/system/net-config.service old mode 100644 new mode 100755 diff --git a/resources/usr/lib/systemd/system/net-config_tv.service b/resources/usr/lib/systemd/system/net-config_tv.service old mode 100644 new mode 100755 diff --git a/resources/usr/lib/udev/rules.d/99-wifiusb-dev.rules b/resources/usr/lib/udev/rules.d/99-wifiusb-dev.rules old mode 100644 new mode 100755 diff --git a/resources/usr/share/dbus-1/services/net.netconfig.service b/resources/usr/share/dbus-1/services/net.netconfig.service old mode 100644 new mode 100755 diff --git a/resources/usr/share/dbus-1/system-services/net.netconfig.service b/resources/usr/share/dbus-1/system-services/net.netconfig.service old mode 100644 new mode 100755 diff --git a/resources/usr/share/wifi_offloading.sql b/resources/usr/share/wifi_offloading.sql old mode 100644 new mode 100755 diff --git a/resources/usr/system/RestoreDir/softreset/network_softreset.sh b/resources/usr/system/RestoreDir/softreset/network_softreset.sh old mode 100644 new mode 100755 diff --git a/resources/usr/system/RestoreDir/softreset_post/network_reset_post.sh b/resources/usr/system/RestoreDir/softreset_post/network_reset_post.sh old mode 100644 new mode 100755 diff --git a/resources/usr/system/RestoreDir/softreset_prepare/network_reset_pre.sh b/resources/usr/system/RestoreDir/softreset_prepare/network_reset_pre.sh old mode 100644 new mode 100755 diff --git a/src/cellular-state.c b/src/cellular-state.c old mode 100644 new mode 100755 index 43c1de5..d4c0672 --- a/src/cellular-state.c +++ b/src/cellular-state.c @@ -21,60 +21,54 @@ #include "log.h" #include "cellular-state.h" -static enum netconfig_cellular_service_state - cellular_service_state = NETCONFIG_CELLULAR_UNKNOWN; +static cellular_service_state_e cellular_service_state = NETCONFIG_CELLULAR_UNKNOWN; static GSList *notifier_list = NULL; -static void __netconfig_cellular_state_changed( - enum netconfig_cellular_service_state state) +static void _cellular_state_changed(cellular_service_state_e state) { GSList *list; for (list = notifier_list; list; list = list->next) { - struct netconfig_cellular_state_notifier *notifier = list->data; + cellular_state_notifier *notifier = list->data; - if (notifier->netconfig_cellular_state_changed != NULL) - notifier->netconfig_cellular_state_changed(state, notifier->user_data); + if (notifier->cellular_state_changed != NULL) + notifier->cellular_state_changed(state, notifier->user_data); } } -void netconfig_cellular_state_set_service_state( - enum netconfig_cellular_service_state new_state) +void cellular_state_set_service_state(cellular_service_state_e new_state) { - enum netconfig_cellular_service_state old_state = cellular_service_state; + cellular_service_state_e old_state = cellular_service_state; if (old_state == new_state) return; cellular_service_state = new_state; DBG("Cellular state %d ==> %d", old_state, new_state); - __netconfig_cellular_state_changed(new_state); + _cellular_state_changed(new_state); } -enum netconfig_cellular_service_state -netconfig_cellular_state_get_service_state(void) +cellular_service_state_e cellular_state_get_service_state(void) { return cellular_service_state; } -void netconfig_cellular_state_notifier_cleanup(void) -{ - g_slist_free_full(notifier_list, NULL); -} - -void netconfig_cellular_state_notifier_register( - struct netconfig_cellular_state_notifier *notifier) +void cellular_state_notifier_register(cellular_state_notifier *notifier) { DBG("register notifier"); notifier_list = g_slist_append(notifier_list, notifier); } -void netconfig_cellular_state_notifier_unregister( - struct netconfig_cellular_state_notifier *notifier) +void cellular_state_notifier_unregister(cellular_state_notifier *notifier) { DBG("un-register notifier"); notifier_list = g_slist_remove_all(notifier_list, notifier); } + +void cellular_state_notifier_cleanup(void) +{ + g_slist_free_full(notifier_list, NULL); +} diff --git a/src/clatd-handler.c b/src/clatd-handler.c old mode 100644 new mode 100755 diff --git a/src/dbus/netdbus.c b/src/dbus/netdbus.c old mode 100644 new mode 100755 index 211626a..d63397b --- a/src/dbus/netdbus.c +++ b/src/dbus/netdbus.c @@ -42,7 +42,7 @@ static GDBusObjectManagerServer *manager_server_wifi = NULL; static GDBusObjectManagerServer *manager_server_state = NULL; static GDBusObjectManagerServer *manager_server_statistics = NULL; static guint owner_id = 0; -static netconfig_got_name_cb g_callback = NULL; +static got_name_cb g_callback = NULL; struct gdbus_conn_data { GDBusConnection *connection; @@ -52,27 +52,27 @@ struct gdbus_conn_data { static struct gdbus_conn_data gconn_data = {NULL, 0, NULL}; -GDBusObjectManagerServer *netconfig_get_wifi_manager(void) +GDBusObjectManagerServer *netdbus_get_wifi_manager(void) { return manager_server_wifi; } -GDBusObjectManagerServer *netconfig_get_state_manager(void) +GDBusObjectManagerServer *netdbus_get_state_manager(void) { return manager_server_state; } -GDBusObjectManagerServer *netconfig_get_statistics_manager(void) +GDBusObjectManagerServer *netdbus_get_statistics_manager(void) { return manager_server_statistics; } -GDBusConnection *netconfig_gdbus_get_connection(void) +GDBusConnection *netdbus_get_connection(void) { return gconn_data.connection; } -GCancellable *netconfig_gdbus_get_gdbus_cancellable(void) +GCancellable *netdbus_get_cancellable(void) { return gconn_data.cancellable; } @@ -98,7 +98,7 @@ void netconfig_gdbus_pending_call_unref(void) } } -int netconfig_create_gdbus_call(GDBusConnection *conn) +int _create_gdbus_call(GDBusConnection *conn) { if (gconn_data.connection != NULL) { ERR("Connection already set"); @@ -174,7 +174,7 @@ gboolean netconfig_invoke_dbus_method_nonblock(const char *dest, const char *pat DBG("[GDBUS Async] %s %s %s", interface_name, method, path); - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { ERR("Failed to get gdbus connection"); return FALSE; @@ -189,13 +189,10 @@ gboolean netconfig_invoke_dbus_method_nonblock(const char *dest, const char *pat NULL, G_DBUS_CALL_FLAGS_NONE, NETCONFIG_DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), (GAsyncReadyCallback) notify_func, NULL); - if (notify_func != NULL) - netconfig_gdbus_pending_call_ref(); - return TRUE; } @@ -207,7 +204,7 @@ GVariant *netconfig_invoke_dbus_method(const char *dest, const char *path, GVariant *reply = NULL; GDBusConnection *connection; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { ERR("Failed to get GDBusconnection"); return reply; @@ -223,7 +220,7 @@ GVariant *netconfig_invoke_dbus_method(const char *dest, const char *path, NULL, G_DBUS_CALL_FLAGS_NONE, NETCONFIG_DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), &error); if (reply == NULL) { @@ -241,13 +238,13 @@ GVariant *netconfig_invoke_dbus_method(const char *dest, const char *path, return reply; } -static void __netconfig_got_bus_cb(GDBusConnection *conn, const gchar *name, +static void _got_bus_cb(GDBusConnection *conn, const gchar *name, gpointer user_data) { - netconfig_create_gdbus_call(conn); + _create_gdbus_call(conn); } -static void __netconfig_got_name_cb(GDBusConnection *conn, const gchar *name, +static void _got_name_cb(GDBusConnection *conn, const gchar *name, gpointer user_data) { INFO("Got gdbus name: [%s] and gdbus connection: [%p]", name, conn); @@ -257,11 +254,11 @@ static void __netconfig_got_name_cb(GDBusConnection *conn, const gchar *name, } } -static void __netconfig_lost_name_cb(GDBusConnection *conn, const gchar *name, +static void _lost_name_cb(GDBusConnection *conn, const gchar *name, gpointer user_data) { /* May service name is already in use */ - ERR("Service name is already in use"); + ERR("_lost_name_cb [%s]", name); /* The result of DBus name request is only permitted, * such as DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER. @@ -269,35 +266,32 @@ static void __netconfig_lost_name_cb(GDBusConnection *conn, const gchar *name, exit(2); } -int netconfig_setup_gdbus(netconfig_got_name_cb cb) +int setup_gdbus(got_name_cb cb) { g_callback = cb; - manager_server_wifi = g_dbus_object_manager_server_new( - NETCONFIG_WIFI_PATH); + manager_server_wifi = g_dbus_object_manager_server_new(NETCONFIG_WIFI_PATH); if (manager_server_wifi == NULL) { ERR("Manager server for WIFI_PATH not created."); exit(1); } - manager_server_state = g_dbus_object_manager_server_new( - NETCONFIG_NETWORK_STATE_PATH); + manager_server_state = g_dbus_object_manager_server_new(NETCONFIG_NETWORK_STATE_PATH); if (manager_server_state == NULL) { ERR("Manager server for STATE_PATH not created."); exit(1); } - manager_server_statistics = g_dbus_object_manager_server_new( - NETCONFIG_NETWORK_STATISTICS_PATH); + manager_server_statistics = g_dbus_object_manager_server_new(NETCONFIG_NETWORK_STATISTICS_PATH); if (manager_server_statistics == NULL) { ERR("Manager server for STATISTICS_PATH not created."); exit(1); } owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, NETCONFIG_SERVICE, - G_BUS_NAME_OWNER_FLAGS_NONE, __netconfig_got_bus_cb, - __netconfig_got_name_cb, __netconfig_lost_name_cb, - NULL, NULL); + G_BUS_NAME_OWNER_FLAGS_NONE, + _got_bus_cb, _got_name_cb, _lost_name_cb, + NULL, NULL); if (!owner_id) { ERR("Could not get system bus!"); return -EIO; @@ -307,9 +301,10 @@ int netconfig_setup_gdbus(netconfig_got_name_cb cb) return 0; } -void netconfig_cleanup_gdbus(void) +void cleanup_gdbus(void) { - g_bus_unown_name (owner_id); - - return; + g_bus_unown_name(owner_id); + g_object_unref(manager_server_wifi); + g_object_unref(manager_server_state); + g_object_unref(manager_server_statistics); } diff --git a/src/dbus/netsupplicant.c b/src/dbus/netsupplicant.c old mode 100644 new mode 100755 index ea7ffb6..0000da9 --- a/src/dbus/netsupplicant.c +++ b/src/dbus/netsupplicant.c @@ -27,7 +27,7 @@ const char *netconfig_wifi_get_supplicant_interface(void) { GVariant *message = NULL; GVariant *params = NULL; - const char *path; + gchar *path = NULL; static char obj_path[DBUS_OBJECT_PATH_MAX] = { '\0', }; if (obj_path[0] != '\0') @@ -48,6 +48,8 @@ const char *netconfig_wifi_get_supplicant_interface(void) g_strlcpy(obj_path, path, DBUS_OBJECT_PATH_MAX); + if (path) + g_free(path); g_variant_unref(message); return (const char *)obj_path; @@ -62,7 +64,7 @@ GVariant *netconfig_supplicant_invoke_dbus_method(const char *dest, const char * INFO("[DBUS Sync] %s %s %s", interface_name, method, path); - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { ERR("Failed to get GDBus Connection"); return NULL; @@ -78,7 +80,7 @@ GVariant *netconfig_supplicant_invoke_dbus_method(const char *dest, const char * NULL, G_DBUS_CALL_FLAGS_NONE, NETCONFIG_DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), &error); if (reply == NULL) { @@ -105,7 +107,7 @@ gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, INFO("[DBUS Async] %s %s %s", interface_name, method, path); - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { DBG("Failed to get GDBusconnection"); return FALSE; @@ -120,13 +122,10 @@ gboolean netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, NULL, G_DBUS_CALL_FLAGS_NONE, NETCONFIG_DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), (GAsyncReadyCallback) notify_func, NULL); - if (notify_func != NULL) - netconfig_gdbus_pending_call_ref(); - return TRUE; } diff --git a/src/main.c b/src/main.c index 25e1fac..77288a0 100755 --- a/src/main.c +++ b/src/main.c @@ -50,20 +50,28 @@ gboolean __net_ethernet_cable_status_polling_callback(gpointer data) return TRUE; } -void __netconfig_got_name_cb(void) +void _got_name_cb(void) { - netconfig_wifi_create_and_init(); - netconfig_network_state_create_and_init(); - netconfig_network_statistics_create_and_init(); + wifi_object_create_and_init(); + state_object_create_and_init(); + statistics_object_create_and_init(); - netconfig_register_signal(); - netconfig_agent_register(); + register_gdbus_signal(); + connman_register_agent(); #if defined TIZEN_TV __netconfig_set_ether_macaddr(); #endif } +static void _objects_deinit(void) +{ + cleanup_gdbus(); + wifi_object_deinit(); + state_object_deinit(); + statistics_object_deinit(); +} + int main(int argc, char *argv[]) { int ret; @@ -98,7 +106,7 @@ int main(int argc, char *argv[]) return 0; } - ret = netconfig_setup_gdbus(__netconfig_got_name_cb); + ret = setup_gdbus(_got_name_cb); if (ret > 0) { ERR("_netconfig_setup_gdbus is failed\n"); return 0; @@ -111,11 +119,12 @@ int main(int argc, char *argv[]) #endif /* If its environment uses Emulator, network configuration is set by emulator default */ - netconfig_emulator_test_and_start(); + emulator_test_and_start(); + /*In case no emulator, set the ETH0 Mac address*/ #if defined TIZEN_TV - if (netconfig_emulator_is_emulated() == FALSE) + if (emulator_is_emulated() == FALSE) __netconfig_set_ether_macaddr(); #endif @@ -132,20 +141,25 @@ int main(int argc, char *argv[]) g_main_loop_run(main_loop); - netconfig_cleanup_gdbus(); + _objects_deinit(); - netconfig_deregister_signal(); + log_cleanup(); - netconfig_wifi_power_deinitialize(); + deregister_gdbus_signal(); + +#if !defined TIZEN_TELEPHONY_ENABLE + netconfig_clock_deinit(); +#endif - netconfig_wifi_state_notifier_cleanup(); /*remove the Timer*/ if(check_ethernet_monitor_timer >0) g_source_remove(check_ethernet_monitor_timer); + wifi_state_notifier_cleanup(); + /* Unregistering the agent */ - netconfig_agent_unregister(); + connman_unregister_agent(); return 0; } diff --git a/src/neterror.c b/src/neterror.c old mode 100644 new mode 100755 index 49ea946..7afb7e6 --- a/src/neterror.c +++ b/src/neterror.c @@ -21,6 +21,7 @@ #include "netdbus.h" #include "neterror.h" +#include "log.h" #define NETCONFIG_ERROR_INTERFACE NETCONFIG_SERVICE ".Error" #define CONNMAN_AGENT_ERROR_INTERFACE "net.connman.Agent.Error" @@ -47,6 +48,7 @@ GQuark netconfig_connman_agent_error_quark(void) void netconfig_error_no_profile(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_NO_PROFILE, NETCONFIG_ERROR_INTERFACE ".NoProfile"); @@ -54,6 +56,7 @@ void netconfig_error_no_profile(GDBusMethodInvocation *context) void netconfig_error_inprogress(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_INPROGRESS, NETCONFIG_ERROR_INTERFACE ".InProgress"); @@ -61,6 +64,7 @@ void netconfig_error_inprogress(GDBusMethodInvocation *context) void netconfig_error_already_exists(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_ALREADYEXISTS, NETCONFIG_ERROR_INTERFACE ".AlreadyExists"); @@ -68,6 +72,7 @@ void netconfig_error_already_exists(GDBusMethodInvocation *context) void netconfig_error_invalid_parameter(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_INVALID_PARAMETER, NETCONFIG_ERROR_INTERFACE ".InvalidParameter"); @@ -75,6 +80,7 @@ void netconfig_error_invalid_parameter(GDBusMethodInvocation *context) void netconfig_error_permission_denied(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_PERMISSION_DENIED, NETCONFIG_ERROR_INTERFACE ".PermissionDenied"); @@ -82,6 +88,7 @@ void netconfig_error_permission_denied(GDBusMethodInvocation *context) void netconfig_error_wifi_driver_failed(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_DRIVER_FAILURE, NETCONFIG_ERROR_INTERFACE ".WifiDriverFailed"); @@ -89,6 +96,7 @@ void netconfig_error_wifi_driver_failed(GDBusMethodInvocation *context) void netconfig_error_wifi_direct_failed(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_DRIVER_FAILURE, NETCONFIG_ERROR_INTERFACE ".WifiDirectFailed"); @@ -96,6 +104,7 @@ void netconfig_error_wifi_direct_failed(GDBusMethodInvocation *context) void netconfig_error_fail_get_imsi(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_IMSI, NETCONFIG_ERROR_INTERFACE".FailGetSimImsi"); @@ -103,6 +112,7 @@ void netconfig_error_fail_get_imsi(GDBusMethodInvocation *context) void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH, NETCONFIG_ERROR_INTERFACE".FailReqSimAuth"); @@ -110,6 +120,7 @@ void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context) void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM, NETCONFIG_ERROR_INTERFACE".FailReqSimAuthWrongParam"); @@ -117,6 +128,7 @@ void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *contex void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA, NETCONFIG_ERROR_INTERFACE".FailGetSimAuthWrongData"); @@ -124,6 +136,7 @@ void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY, NETCONFIG_ERROR_INTERFACE".FailGetSimAuthDelay"); @@ -131,6 +144,7 @@ void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context) void netconfig_error_fail_save_congifuration(GDBusMethodInvocation *context) { + ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), NETCONFIG_ERROR_INTERNAL, NETCONFIG_ERROR_INTERFACE".FailSaveConfiguration"); @@ -143,12 +157,15 @@ void netconfig_error_fail_ethernet_cable_state(GDBusMethodInvocation *context) NETCONFIG_ERROR_INTERFACE".FailGetEthernetCableState"); } +#include void netconfig_error_dbus_method_return(GDBusMethodInvocation *context, netconfig_error_e error, const gchar *message) { gchar *msg = NULL; + ERR("dbus method return error"); + msg = g_strdup_printf("%s.%s", NETCONFIG_ERROR_INTERFACE, message); - g_dbus_method_invocation_return_error_literal(context, netconfig_error_quark(), error, msg); + g_dbus_method_invocation_return_error(context, netconfig_error_quark(), error,"%s", msg); g_free(msg); } diff --git a/src/network-clock.c b/src/network-clock.c old mode 100644 new mode 100755 index eeaa798..2ec6992 --- a/src/network-clock.c +++ b/src/network-clock.c @@ -40,6 +40,7 @@ static void __netconfig_clock_clear_timeserver(void) g_key_file_remove_key(keyfile, "global", "Timeservers", NULL); netconfig_keyfile_save(keyfile, CONNMAN_GLOBAL_SETTING); + g_key_file_free(keyfile); } static gboolean __netconfig_clock_clear_timeserver_timer(gpointer data) @@ -87,7 +88,7 @@ static void __netconfig_set_timeserver(void) } static void __netconfig_clock( - enum netconfig_wifi_service_state state, void *user_data) + wifi_service_state_e state, void *user_data) { gboolean automatic_time_update = 0; @@ -106,15 +107,15 @@ static void __netconfig_clock( __netconfig_set_timeserver(); } -static struct netconfig_wifi_state_notifier netconfig_clock_notifier = { - .netconfig_wifi_state_changed = __netconfig_clock, +static wifi_state_notifier netconfig_clock_notifier = { + .wifi_state_changed = __netconfig_clock, .user_data = NULL, }; static void __automatic_time_update_changed_cb(keynode_t *node, void *user_data) { gboolean automatic_time_update = FALSE; - enum netconfig_wifi_service_state wifi_state = NETCONFIG_WIFI_UNKNOWN; + wifi_service_state_e wifi_state = NETCONFIG_WIFI_UNKNOWN; if (node != NULL) { automatic_time_update = vconf_keynode_get_bool(node); @@ -127,7 +128,7 @@ static void __automatic_time_update_changed_cb(keynode_t *node, void *user_data) return; } - wifi_state = netconfig_wifi_state_get_service_state(); + wifi_state = wifi_state_get_service_state(); if (wifi_state != NETCONFIG_WIFI_CONNECTED) { INFO("WiFi state is not NETCONFIG_WIFI_CONNECTED"); @@ -143,10 +144,10 @@ void netconfig_clock_init(void) vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, __automatic_time_update_changed_cb, NULL); - netconfig_wifi_state_notifier_register(&netconfig_clock_notifier); + wifi_state_notifier_register(&netconfig_clock_notifier); } void netconfig_clock_deinit(void) { - netconfig_wifi_state_notifier_unregister(&netconfig_clock_notifier); + wifi_state_notifier_unregister(&netconfig_clock_notifier); } diff --git a/src/network-state.c b/src/network-state.c index bb1fc8c..59819b5 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -219,7 +219,7 @@ static void __netconfig_get_default_connection_info(const char *profile) GVariantIter *iter_sub = NULL; if (g_strcmp0(key2, "Servers") == 0) { - if (!g_variant_is_of_type(next, G_VARIANT_TYPE_STRING_ARRAY)) { + if (!g_variant_is_of_type(variant2, G_VARIANT_TYPE_STRING_ARRAY)) { g_free(key2); g_variant_unref(variant2); break; @@ -416,7 +416,7 @@ static void __netconfig_update_default_connection_info(void) const char *proxy_addr = netconfig_get_default_proxy(); unsigned int freq = netconfig_get_default_frequency(); - if (netconfig_emulator_is_emulated() == TRUE) + if (emulator_is_emulated() == TRUE) return; if (profile == NULL) @@ -623,7 +623,7 @@ static void __netconfig_network_notify_result(const char *sig_name, const char * INFO("[Signal] %s %s", sig_name, key); - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { ERR("Failed to get GDBus Connection"); return; @@ -778,8 +778,7 @@ void netconfig_update_default_profile(const char *profile) netconfig_default_connection_info.freq = 0; - if (netconfig_wifi_state_get_service_state() - != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { g_free(netconfig_default_connection_info.essid); netconfig_default_connection_info.essid = NULL; } @@ -815,7 +814,7 @@ void netconfig_update_default(void) __netconfig_adjust_tcp_buffer_size(); } -char *netconfig_network_get_ifname(const char *profile) +char *netconfig_get_ifname(const char *profile) { GVariant *message = NULL, *variant; GVariantIter *iter, *next; @@ -1007,7 +1006,7 @@ static gboolean handle_check_profile_privilege(Network *object, } gboolean handle_ethernet_cable_state(Network *object, - GDBusMethodInvocation *context) + GDBusMethodInvocation *context) { int ret = 0; int state = 0; @@ -1024,22 +1023,22 @@ gboolean handle_ethernet_cable_state(Network *object, return TRUE; } -void netconfig_network_state_create_and_init(void) +void state_object_create_and_init(void) { DBG("Creating network state object"); - GDBusInterfaceSkeleton *interface = NULL; + GDBusInterfaceSkeleton *interface_network = NULL; GDBusConnection *connection = NULL; - GDBusObjectManagerServer *server = netconfig_get_state_manager(); + GDBusObjectManagerServer *server = netdbus_get_state_manager(); if (server == NULL) return; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); g_dbus_object_manager_server_set_connection(server, connection); - /*Interface 1*/ + /*Interface netconfig.network*/ netconfigstate = network_skeleton_new(); - interface = G_DBUS_INTERFACE_SKELETON(netconfigstate); + interface_network = G_DBUS_INTERFACE_SKELETON(netconfigstate); g_signal_connect(netconfigstate, "handle-add-route", G_CALLBACK(handle_add_route), NULL); g_signal_connect(netconfigstate, "handle-check-get-privilege", @@ -1048,11 +1047,14 @@ void netconfig_network_state_create_and_init(void) G_CALLBACK(handle_check_profile_privilege), NULL); g_signal_connect(netconfigstate, "handle-remove-route", G_CALLBACK(handle_remove_route), NULL); - g_signal_connect(netconfigstate, "handle-ethernet-cable-state", - G_CALLBACK(handle_ethernet_cable_state), NULL); - if (!g_dbus_interface_skeleton_export(interface, connection, + if (!g_dbus_interface_skeleton_export(interface_network, connection, NETCONFIG_NETWORK_STATE_PATH, NULL)) { ERR("Export with path failed"); } } + +void state_object_deinit(void) +{ + g_object_unref(netconfigstate); +} diff --git a/src/network-statistics.c b/src/network-statistics.c index 026a206..7a02768 100755 --- a/src/network-statistics.c +++ b/src/network-statistics.c @@ -60,7 +60,8 @@ gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx) p_ifname = buf; while (*p_ifname == ' ') p_ifname++; p_entry = strchr(p_ifname, ':'); - *p_entry++ = '\0'; + if (p_entry != NULL) { + *p_entry++ = '\0'; if (g_strcmp0(p_ifname, WIFI_IFNAME) != 0) continue; @@ -87,7 +88,9 @@ gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx) &lval, /* tx carrier errors */ &lval /* tx compressed */ ); - + } else { + ERR("No matched Iface name in proc file"); + } ret = TRUE; break; } @@ -151,7 +154,7 @@ static gboolean handle_get_wifi_last_tx_bytes( vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val); tx_bytes = (guint64)val; - if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { last_bytes = tx_bytes; network_statistics_complete_get_wifi_last_tx_bytes(object, context, last_bytes); return TRUE; @@ -178,7 +181,7 @@ static gboolean handle_get_wifi_last_rx_bytes( vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val); rx_bytes = (guint64)val; - if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { last_bytes = rx_bytes; network_statistics_complete_get_wifi_last_rx_bytes(object, context, last_bytes); return TRUE; @@ -266,7 +269,7 @@ static gboolean handle_reset_wifi_last_tx_bytes( { guint64 tx = 0, rx = 0; - if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state() != 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; @@ -288,7 +291,7 @@ static gboolean handle_reset_wifi_last_rx_bytes( { guint64 tx = 0, rx = 0; - if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + if (wifi_state_get_service_state() != 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; @@ -327,13 +330,12 @@ void netconfig_wifi_statistics_update_powered_off(void) netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx); } -static void netconfig_wifi_statistics_update_state( - enum netconfig_wifi_service_state state, void *user_data) +static void wifi_statistics_update_state(wifi_service_state_e state, void *user_data) { guint64 tx = 0, rx = 0; guint64 last_tx = 0, last_rx = 0; int val = 0; - static enum netconfig_wifi_service_state prev_state = NETCONFIG_WIFI_UNKNOWN; + static wifi_service_state_e prev_state = NETCONFIG_WIFI_UNKNOWN; if (prev_state == NETCONFIG_WIFI_UNKNOWN) { netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); @@ -369,27 +371,27 @@ static void netconfig_wifi_statistics_update_state( prev_state = state; } -static struct netconfig_wifi_state_notifier state_notifier = { - .netconfig_wifi_state_changed = netconfig_wifi_statistics_update_state, +static wifi_state_notifier state_notifier = { + .wifi_state_changed = wifi_statistics_update_state, .user_data = NULL, }; -void netconfig_network_statistics_create_and_init(void) +void statistics_object_create_and_init(void) { DBG("Creating statistics object"); - GDBusInterfaceSkeleton *interface = NULL; + GDBusInterfaceSkeleton *interface_statistics = NULL; GDBusConnection *connection = NULL; - GDBusObjectManagerServer *server = netconfig_get_statistics_manager(); + GDBusObjectManagerServer *server = netdbus_get_statistics_manager(); if (server == NULL) return; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); g_dbus_object_manager_server_set_connection(server, connection); - /*Interface 1*/ + /*Interface netconfig.network_statistics*/ netconfigstatistics = network_statistics_skeleton_new(); - interface = G_DBUS_INTERFACE_SKELETON(netconfigstatistics); + interface_statistics = G_DBUS_INTERFACE_SKELETON(netconfigstatistics); g_signal_connect(netconfigstatistics, "handle-get-wifi-last-rx-bytes", G_CALLBACK(handle_get_wifi_last_rx_bytes), NULL); g_signal_connect(netconfigstatistics, "handle-get-wifi-last-tx-bytes", @@ -415,13 +417,18 @@ void netconfig_network_statistics_create_and_init(void) g_signal_connect(netconfigstatistics, "handle-reset-wifi-total-tx-bytes", G_CALLBACK(handle_reset_wifi_total_tx_bytes), NULL); - if (!g_dbus_interface_skeleton_export(interface, connection, + if (!g_dbus_interface_skeleton_export(interface_statistics, connection, NETCONFIG_NETWORK_STATISTICS_PATH, NULL)) { ERR("Export with path failed"); } - netconfig_wifi_statistics_update_state(NETCONFIG_WIFI_IDLE, NULL); - netconfig_wifi_state_notifier_register(&state_notifier); + wifi_statistics_update_state(NETCONFIG_WIFI_IDLE, NULL); + wifi_state_notifier_register(&state_notifier); return; } + +void statistics_object_deinit(void) +{ + g_object_unref(netconfigstatistics); +} diff --git a/src/signal-handler.c b/src/signal-handler.c old mode 100644 new mode 100755 index 6067c3b..90fb9b8 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -67,7 +67,7 @@ typedef enum { } SuppSigArrayIndex; static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0}; -static const char supp_signals[SIG_MAX][MAX_SIG_LEN] = { +static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = { SIGNAL_INTERFACE_REMOVED, SIGNAL_PROPERTIES_CHANGED, SIGNAL_BSS_ADDED, @@ -79,20 +79,20 @@ static const char supp_signals[SIG_MAX][MAX_SIG_LEN] = { static int supp_subscription_ids[SIG_MAX] = {0}; static int dumpservice_subscription_id = 0; -typedef void (*netconfig_supplicant_signal_handler)(GDBusConnection *conn, +typedef void (*supplicant_signal_cb)(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data); -typedef void (*netconfig_connman_signal_handler)(GDBusConnection *conn, +typedef void (*connman_signal_cb)(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data); -static void __netconfig_technology_signal_handler(GDBusConnection *conn, +static void _technology_signal_cb(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { - const char *key = NULL; + gchar *key = NULL; gboolean value = FALSE; - GVariant *var; + GVariant *var = NULL; if (param == NULL) return; @@ -103,23 +103,25 @@ static void __netconfig_technology_signal_handler(GDBusConnection *conn, /* Power state */ value = g_variant_get_boolean(var); if (value == TRUE) { - netconfig_wifi_update_power_state(TRUE); + wifi_state_update_power_state(TRUE); } else { - netconfig_wifi_update_power_state(FALSE); + wifi_state_update_power_state(FALSE); } } else if (g_strcmp0(key, "Connected") == 0) { /* Connection state */ - netconfig_wifi_state_set_technology_state( - NETCONFIG_WIFI_TECH_CONNECTED); + wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED); } else if (g_strcmp0(key, "Tethering") == 0) { /* Tethering state */ - netconfig_wifi_state_set_technology_state( - NETCONFIG_WIFI_TECH_TETHERED); + wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED); } + if (key) + g_free(key); + if (var) + g_variant_unref(var); } } -static void __netconfig_service_signal_handler(GDBusConnection *conn, +static void _service_signal_cb(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { @@ -157,18 +159,16 @@ static void __netconfig_service_signal_handler(GDBusConnection *conn, netconfig_update_default_profile(path); - netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED); + wifi_state_set_service_state(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) - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_FAILURE); + wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE); else - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_IDLE); + wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); goto done; } @@ -178,21 +178,17 @@ static void __netconfig_service_signal_handler(GDBusConnection *conn, netconfig_update_default_profile(NULL); if (g_strcmp0(property, "failure") == 0) - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_FAILURE); + wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE); else - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_IDLE); + wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); - } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) { + } 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) - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_ASSOCIATION); + wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION); else - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_CONFIGURATION); + wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION); goto done; } @@ -202,11 +198,9 @@ static void __netconfig_service_signal_handler(GDBusConnection *conn, netconfig_update_default_profile(NULL); if (g_strcmp0(property, "association") == 0) - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_ASSOCIATION); + wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION); else - netconfig_wifi_state_set_service_state( - NETCONFIG_WIFI_CONFIGURATION); + wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION); } } else { @@ -217,16 +211,19 @@ static void __netconfig_service_signal_handler(GDBusConnection *conn, } else { if (netconfig_is_cellular_internet_profile(path)) { netconfig_update_default_profile(path); - netconfig_cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE); } } } + + 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) { if (netconfig_get_default_profile() == NULL) goto done; - if (netconfig_is_cellular_profile(path) == TRUE) - netconfig_cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE); + if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path)) + cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE); if (g_strcmp0(path, netconfig_get_default_profile()) != 0) goto done; @@ -236,8 +233,8 @@ static void __netconfig_service_signal_handler(GDBusConnection *conn, if (netconfig_get_default_profile() == NULL) goto done; - if (netconfig_is_cellular_profile(path) == TRUE) - netconfig_cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING); + if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path)) + cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING); if (g_strcmp0(path, netconfig_get_default_profile()) != 0) goto done; @@ -295,11 +292,13 @@ done: return; } -static void __netconfig_dbus_name_changed_signal_handler(GDBusConnection *conn, +static void _dbus_name_changed_cb(GDBusConnection *conn, const gchar *Name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { - char *name, *old, *new; + gchar *name = NULL; + gchar *old = NULL; + gchar *new = NULL; if (param == NULL) return; @@ -309,13 +308,19 @@ static void __netconfig_dbus_name_changed_signal_handler(GDBusConnection *conn, if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') { DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new); - netconfig_agent_register(); + connman_register_agent(); } + if (name) + g_free(name); + if (old) + g_free(old); + if (new) + g_free(new); return; } -static void __netconfig_supplicant_interface_removed(GDBusConnection *conn, +static void _supplicant_interface_removed(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { @@ -326,7 +331,7 @@ static void __netconfig_supplicant_interface_removed(GDBusConnection *conn, return; } -static void __netconfig_supplicant_properties_changed(GDBusConnection *conn, +static void _supplicant_properties_changed(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { @@ -357,20 +362,20 @@ static void __netconfig_supplicant_properties_changed(GDBusConnection *conn, return; } -static void __netconfig_supplicant_bss_added(GDBusConnection *conn, +static void _supplicant_bss_added(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { DBG("BSS added handling!"); - if (netconfig_wifi_get_ssid_scan_state() == TRUE) - netconfig_wifi_bss_added(param); + if (wifi_ssid_scan_get_state() == TRUE) + wifi_ssid_scan_add_bss(param); else - netconfig_wifi_set_bss_found(TRUE); + wifi_state_set_bss_found(TRUE); return; } -static void __netconfig_supplicant_scan_done(GDBusConnection *conn, +static void _supplicant_scan_done(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { @@ -379,40 +384,39 @@ static void __netconfig_supplicant_scan_done(GDBusConnection *conn, if (netconfig_wifi_is_wps_enabled() == TRUE) { netconfig_wifi_wps_signal_scandone(); - if (netconfig_wifi_state_get_technology_state() < - NETCONFIG_WIFI_TECH_POWERED) + if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED) return; } if (netconfig_wifi_get_bgscan_state() != TRUE) { - if (netconfig_wifi_get_ssid_scan_state() == TRUE) - netconfig_wifi_notify_ssid_scan_done(); + if (wifi_ssid_scan_get_state() == TRUE) + wifi_ssid_scan_emit_scan_completed(); else - netconfig_wifi_ssid_scan(NULL); + wifi_ssid_scan(NULL); } else { - if (netconfig_wifi_state_get_technology_state() >= + if (wifi_state_get_technology_state() >= NETCONFIG_WIFI_TECH_POWERED) netconfig_wifi_bgscan_start(FALSE); - netconfig_wifi_start_timer_network_notification(); + wifi_start_timer_network_notification(); } return; } -static void __netconfig_supplicant_driver_hanged(GDBusConnection *conn, +static void _supplicant_driver_hanged(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { DBG("Driver Hanged handling!"); ERR("Critical. Wi-Fi firmware crashed"); - netconfig_wifi_recover_firmware(); + wifi_power_recover_firmware(); return; } -static void __netconfig_supplicant_session_overlapped(GDBusConnection *conn, +static void _supplicant_session_overlapped(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { @@ -426,13 +430,13 @@ static void __netconfig_supplicant_session_overlapped(GDBusConnection *conn, #endif } -static netconfig_supplicant_signal_handler supp_handlers[SIG_MAX] = { - __netconfig_supplicant_interface_removed, - __netconfig_supplicant_properties_changed, - __netconfig_supplicant_bss_added, - __netconfig_supplicant_scan_done, - __netconfig_supplicant_driver_hanged, - __netconfig_supplicant_session_overlapped +static supplicant_signal_cb supplicant_cbs[SIG_MAX] = { + _supplicant_interface_removed, + _supplicant_properties_changed, + _supplicant_bss_added, + _supplicant_scan_done, + _supplicant_driver_hanged, + _supplicant_session_overlapped }; #if defined TIZEN_DEBUG_DISABLE @@ -449,17 +453,19 @@ static void __netconfig_dumpservice_handler(GDBusConnection *conn, g_variant_get(param, "(io)", &mode, &signal_path); DBG("Path: %s and mode: %d", signal_path, mode); netconfig_dump_log(path); + if (signal_path) + g_free(signal_path); return; } #endif -void netconfig_register_signal(void) +void register_gdbus_signal(void) { GDBusConnection *connection = NULL; const char *interface = NULL; SuppSigArrayIndex sig; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { ERR("Failed to get GDbus Connection"); @@ -476,7 +482,7 @@ void netconfig_register_signal(void) NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, - __netconfig_technology_signal_handler, + _technology_signal_cb, NULL, NULL); @@ -488,7 +494,7 @@ void netconfig_register_signal(void) NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, - __netconfig_service_signal_handler, + _service_signal_cb, NULL, NULL); @@ -500,7 +506,7 @@ void netconfig_register_signal(void) NULL, CONNMAN_SERVICE, G_DBUS_SIGNAL_FLAGS_NONE, - __netconfig_dbus_name_changed_signal_handler, + _dbus_name_changed_cb, NULL, NULL); @@ -517,11 +523,11 @@ void netconfig_register_signal(void) connection, SUPPLICANT_SERVICE, interface, - supp_signals[sig], + supplicant_signals[sig], NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, - supp_handlers[sig], + supplicant_cbs[sig], NULL, NULL); } @@ -553,12 +559,12 @@ void netconfig_register_signal(void) netconfig_update_default(); } -void netconfig_deregister_signal(void) +void deregister_gdbus_signal(void) { GDBusConnection *connection = NULL; int signal; SuppSigArrayIndex sig; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (!connection) { ERR("Already de-registered. Nothing to be done"); return; diff --git a/src/utils/emulator.c b/src/utils/emulator.c old mode 100644 new mode 100755 index 38956c5..844cda0 --- a/src/utils/emulator.c +++ b/src/utils/emulator.c @@ -115,17 +115,16 @@ static void __netconfig_emulator_config_emul_env(void) __netconfig_emulator_set_network_state(); } -gboolean netconfig_emulator_is_emulated(void) +gboolean emulator_is_emulated(void) { return netconfig_is_emulated; } -void netconfig_emulator_test_and_start(void) +void emulator_test_and_start(void) { netconfig_is_emulated = __netconfig_emulator_test_emulation_env(); - DBG("Emulation environment tested: %s", netconfig_is_emulated ? - "It's emulated" : "Not emulated"); + DBG("Emulation environment tested: %s", netconfig_is_emulated ? "It's emulated" : "Not emulated"); if (netconfig_is_emulated == TRUE) __netconfig_emulator_config_emul_env(); diff --git a/src/utils/log.c b/src/utils/log.c index ae8825f..dfe2bb4 100755 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -18,7 +18,7 @@ */ #include -#include +#include #include #include #include @@ -74,18 +74,20 @@ static inline void __netconfig_log_make_backup(void) static inline void __netconfig_log_get_local_time(char *strtime, const int size) { - time_t buf; + struct timeval tv; struct tm *local_ptm; + char buf[32]; - time(&buf); - buf = time(NULL); - local_ptm = localtime(&buf); + gettimeofday(&tv, NULL); + local_ptm = localtime(&tv.tv_sec); if(local_ptm) - strftime(strtime, size, "%m/%d %H:%M:%S", local_ptm); + strftime(buf, sizeof(buf), "%m/%d %H:%M:%S", local_ptm); + + snprintf(strtime, size, "%s.%03ld", buf, tv.tv_usec / 1000); } -void __netconfig_debug(const char *format, ...) +void netconfig_log(const char *format, ...) { va_list ap; int log_size = 0; @@ -125,3 +127,12 @@ void __netconfig_debug(const char *format, ...) va_end(ap); } + +void log_cleanup(void) +{ + if (log_file == NULL) + return; + + fclose(log_file); + log_file = NULL; +} diff --git a/src/utils/network-accessibility.c b/src/utils/network-accessibility.c old mode 100644 new mode 100755 index 94fc160..5cf23b3 --- a/src/utils/network-accessibility.c +++ b/src/utils/network-accessibility.c @@ -48,9 +48,9 @@ #define NETCONFIG_INTERNET_CHECK_TIMEOUT 3 enum netconfig_internet_check_state { - INTERNET_CHECK_STATE_NONE, - INTERNET_CHECK_STATE_DNS_CHECK, - INTERNET_CHECK_STATE_PACKET_CHECK + INTERNET_CHECK_STATE_NONE = 0, + INTERNET_CHECK_STATE_DNS_CHECK = 1, + INTERNET_CHECK_STATE_PACKET_CHECK = 2 }; struct internet_params { @@ -61,7 +61,6 @@ struct internet_params { guint send_watch; gboolean header_done; gboolean request_started; - GCancellable *resolv_cancel; }; const static char* url_list[] = { @@ -73,21 +72,22 @@ const static char* url_list[] = { "www.youtube.com" }; +#define URL_LIST_NUM 6 + static guint timer_id = 0; static const char *proxy_addr = NULL; static gboolean perform_recheck = TRUE; struct internet_params *net_params = NULL; static gboolean is_internet_available = FALSE; -const static int url_list_num = 6; static int url_index = 0; static char * redirect_url1 = NULL; static char * redirect_url2 = NULL; -static enum netconfig_internet_check_state check_state = - INTERNET_CHECK_STATE_NONE; +static enum netconfig_internet_check_state check_state = INTERNET_CHECK_STATE_NONE; + +static GCancellable *cancellable; static void __netconfig_connect_sockets(void); -static void __internet_check_state( - enum netconfig_internet_check_state state); +static void __internet_check_state(enum netconfig_internet_check_state state); gboolean netconfig_get_internet_status() { @@ -143,8 +143,7 @@ static void __netconfig_update_internet_status(unsigned char *reply) static gboolean __netconfig_data_activity_timeout(gpointer data) { DBG("Timer timed-out"); - enum netconfig_internet_check_state prev_state = - (enum netconfig_internet_check_state)data; + enum netconfig_internet_check_state prev_state = (enum netconfig_internet_check_state)GPOINTER_TO_INT(data); INFO("Prev_state: state=%d (1:dns check / 2:packet check)",prev_state); if (net_params == NULL) @@ -171,8 +170,7 @@ static void __netconfig_internet_check_timer_stop(void) netconfig_stop_timer(&timer_id); } -static void __netconfig_internet_check_timer_start( - enum netconfig_internet_check_state state) +static void __netconfig_internet_check_timer_start(enum netconfig_internet_check_state state) { static guint timeout = 0; if (timer_id != 0) { @@ -189,29 +187,32 @@ static void __netconfig_internet_check_timer_start( netconfig_start_timer_seconds(timeout, __netconfig_data_activity_timeout, - (void *)state, + GINT_TO_POINTER(state), &timer_id); } -static void __internet_check_state( - enum netconfig_internet_check_state state) +static void __internet_check_state(enum netconfig_internet_check_state state) { - if (check_state == state) + enum netconfig_internet_check_state prev_state = check_state; + + if (prev_state == state) return; - INFO("state change (%d) -> (%d)", check_state, state); + ERR("state change (%d) -> (%d)", prev_state, state); + check_state = state; + switch (state) { case INTERNET_CHECK_STATE_DNS_CHECK: __netconfig_internet_check_timer_start(state); break; case INTERNET_CHECK_STATE_PACKET_CHECK: - if (check_state == INTERNET_CHECK_STATE_DNS_CHECK) + if (prev_state == INTERNET_CHECK_STATE_DNS_CHECK) __netconfig_internet_check_timer_stop(); __netconfig_internet_check_timer_start(state); break; case INTERNET_CHECK_STATE_NONE: - switch (check_state) { + switch (prev_state) { case INTERNET_CHECK_STATE_DNS_CHECK: case INTERNET_CHECK_STATE_PACKET_CHECK: __netconfig_internet_check_timer_stop(); @@ -222,55 +223,6 @@ static void __internet_check_state( } break; } - check_state = state; -} - -void netconfig_stop_internet_check(void) -{ - if (net_params == NULL) - return; - - net_params->header_done = FALSE; - net_params->request_started = FALSE; - - if (net_params->resolv_cancel != NULL) { - g_cancellable_cancel(net_params->resolv_cancel); - g_object_unref(net_params->resolv_cancel); - net_params->resolv_cancel = NULL; - } - - if (net_params->transport_watch > 0) { - g_source_remove(net_params->transport_watch); - net_params->transport_watch = 0; - } - - if (net_params->send_watch > 0) { - g_source_remove(net_params->send_watch); - net_params->send_watch = 0; - } - - if (net_params->fd > 0) { - close(net_params->fd); - net_params->fd = -1; - } - - if (net_params->addr != NULL) { - g_free(net_params->addr); - net_params->addr = NULL; - } - - g_free(net_params); - net_params = NULL; - - if (redirect_url1) { - g_free(redirect_url1); - redirect_url1 = NULL; - } - - if (redirect_url2) { - g_free(redirect_url2); - redirect_url2 = NULL; - } } static gboolean __received_data_event(GIOChannel *channel, @@ -427,6 +379,7 @@ static void __netconfig_obtain_host_ip_addr_cb(GObject *src, GList *list, *cur; GInetAddress *addr; gchar *str_addr; + GError *error = NULL; if (net_params == NULL) return; @@ -434,7 +387,14 @@ static void __netconfig_obtain_host_ip_addr_cb(GObject *src, if (check_state == INTERNET_CHECK_STATE_NONE) return; - list = g_resolver_lookup_by_name_finish((GResolver *)src, res, NULL); + list = g_resolver_lookup_by_name_finish((GResolver *)src, res, &error); + if (error != NULL) { + if (error->code == G_IO_ERROR_CANCELLED) { + ERR("G_IO_ERROR_CANCELLED is called[%s]", error->message); + } + g_error_free(error); + } + if (!list) { INFO("no data"); goto cleanup; @@ -487,7 +447,7 @@ gboolean __netconfig_obtain_host_ip_addr(void) proxy_addr = netconfig_get_default_proxy(); DBG("Proxy(%s)", proxy_addr); - if (++url_index >= url_list_num) + if (++url_index >= URL_LIST_NUM) url_index = 0; DBG("addr (%s)", url_list[url_index]); @@ -495,12 +455,11 @@ gboolean __netconfig_obtain_host_ip_addr(void) /* FIXME: domain proxy should be resolved */ if (proxy_addr == NULL) { GResolver *r = NULL; - net_params->resolv_cancel = g_cancellable_new(); r = g_resolver_get_default(); g_resolver_lookup_by_name_async(r, url_list[url_index], - net_params->resolv_cancel, + cancellable, __netconfig_obtain_host_ip_addr_cb, NULL); __internet_check_state(INTERNET_CHECK_STATE_DNS_CHECK); @@ -544,7 +503,7 @@ cleanup: void netconfig_check_internet_accessibility(void) { - DBG("::Entry"); + ERR("::Entry"); if (net_params == NULL) { net_params = g_try_malloc0(sizeof(struct internet_params)); @@ -553,8 +512,7 @@ void netconfig_check_internet_accessibility(void) net_params->fd = -1; } - if ((check_state != INTERNET_CHECK_STATE_NONE) || - (net_params->request_started == TRUE)) { + if ((check_state != INTERNET_CHECK_STATE_NONE) || (net_params->request_started == TRUE)) { DBG("Older query in progress"); return; } @@ -566,3 +524,61 @@ void netconfig_check_internet_accessibility(void) __netconfig_connect_sockets(); } } + +void netconfig_stop_internet_check(void) +{ + if (net_params == NULL) + return; + + net_params->header_done = FALSE; + net_params->request_started = FALSE; + + if (g_cancellable_is_cancelled(cancellable) == FALSE) { + g_cancellable_cancel(cancellable); + ERR("g_cancellable_cancel is called and return stop_internet_check"); + return; + } + + if (net_params->transport_watch > 0) { + g_source_remove(net_params->transport_watch); + net_params->transport_watch = 0; + } + + if (net_params->send_watch > 0) { + g_source_remove(net_params->send_watch); + net_params->send_watch = 0; + } + + if (net_params->fd > 0) { + close(net_params->fd); + net_params->fd = -1; + } + + if (net_params->addr != NULL) { + g_free(net_params->addr); + net_params->addr = NULL; + } + + g_free(net_params); + net_params = NULL; + + if (redirect_url1) { + g_free(redirect_url1); + redirect_url1 = NULL; + } + + if (redirect_url2) { + g_free(redirect_url2); + redirect_url2 = NULL; + } +} + +void netconfig_internet_accessibility_init(void) +{ + cancellable = g_cancellable_new(); +} + +void netconfig_internet_accessibility_deinit(void) +{ + g_object_unref(cancellable); +} diff --git a/src/utils/util.c b/src/utils/util.c index 1117802..b4bfc4c 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -42,7 +42,9 @@ #include "neterror.h" #include "wifi-state.h" -#define WC_POPUP_EXTRA_DATA_KEY "http://samsung.com/appcontrol/data/connection_type" +#define WC_POPUP_EXTRA_DATA_KEY "http://tizen.org/appcontrol/data/connection_type" +#define MAC_INFO_FILEPATH "/opt/etc/.mac.info" +#define MAC_ADDRESS_MAX_LEN 18 static gboolean netconfig_device_picker_test = FALSE; @@ -99,8 +101,6 @@ void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname) chmod(pathname, S_IRUSR | S_IWUSR); g_free(keydata); - - g_key_file_free(keyfile); } void netconfig_start_timer_seconds(guint secs, @@ -174,8 +174,9 @@ static gboolean __netconfig_test_device_picker() { char *favorite_wifi_service = NULL; - favorite_wifi_service = netconfig_wifi_get_favorite_service(); + favorite_wifi_service = wifi_get_favorite_service(); if (favorite_wifi_service != NULL) { + ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service); g_free(favorite_wifi_service); return FALSE; } @@ -228,8 +229,7 @@ static gboolean __netconfig_wifi_try_device_picker(gpointer data) return FALSE; } -static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, - guint timer_id) +static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id) { static guint netconfig_wifi_device_picker_service_timer = 0; @@ -275,21 +275,13 @@ void netconfig_wifi_device_picker_service_start(void) #else int wifi_ug_state; - if (netconfig_device_picker_test == TRUE) - netconfig_device_picker_test = FALSE; - else - return; - vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) return; #endif - DBG("Register device picker timer with %d milliseconds", - NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL); - - netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, - __netconfig_wifi_try_device_picker, NULL, &timer_id); + DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL); + netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id); __netconfig_wifi_device_picker_set_timer_id(timer_id); } @@ -493,6 +485,140 @@ int netconfig_execute_clatd(const char *file_path, char *const args[]) return -EIO; } +int __netconfig_get_interface_index(const char *interface_name) +{ + struct ifreq ifr; + int sock = 0; + int result = 0; + + if (interface_name == NULL) { + DBG("Inteface name is NULL"); + return -1; + } + + errno = 0; + sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (sock < 0) { + DBG("Failed to create socket : %s", strerror(errno)); + return -1; + } + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1); + result = ioctl(sock, SIOCGIFINDEX, &ifr); + close(sock); + + if (result < 0) { + DBG("Failed to get ifr index: %s", strerror(errno)); + return -1; + } + + return ifr.ifr_ifindex; +} + +int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family) +{ + struct ifreq ifr; + struct rtentry rt; + struct sockaddr_in addr_in; + int sock; + + memset(&ifr, 0, sizeof(ifr)); + + ifr.ifr_ifindex = __netconfig_get_interface_index(interface); + + if (ifr.ifr_ifindex < 0) + return -1; + + strncpy(ifr.ifr_name, interface, IFNAMSIZ-1); + + memset(&rt, 0, sizeof(rt)); + + rt.rt_flags = RTF_UP | RTF_HOST; + memset(&addr_in, 0, sizeof(struct sockaddr_in)); + addr_in.sin_family = address_family; + addr_in.sin_addr.s_addr = inet_addr(ip_addr); + memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst)); + + memset(&addr_in, 0, sizeof(struct sockaddr_in)); + addr_in.sin_family = address_family; + addr_in.sin_addr.s_addr = INADDR_ANY; + memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway)); + + memset(&addr_in, 0, sizeof(struct sockaddr_in)); + addr_in.sin_family = AF_INET; + addr_in.sin_addr.s_addr = inet_addr(subnet); + memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask)); + + rt.rt_dev = ifr.ifr_name; + + errno = 0; + sock = socket(PF_INET, SOCK_DGRAM, 0); + + if (sock < 0) { + DBG("Failed to create socket : %s", strerror(errno)); + return -1; + } + + if (ioctl(sock, SIOCADDRT, &rt) < 0) { + DBG("Failed to set route address : %s", strerror(errno)); + close(sock); + return -1; + } + + close(sock); + + return 1; +} + +int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family) +{ + struct ifreq ifr; + struct rtentry rt; + struct sockaddr_in addr_in; + int sock; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_ifindex = __netconfig_get_interface_index(interface); + + if (ifr.ifr_ifindex < 0) + return -1; + + strncpy(ifr.ifr_name, interface, IFNAMSIZ-1); + + memset(&rt, 0, sizeof(rt)); + + rt.rt_flags = RTF_UP; + memset(&addr_in, 0, sizeof(struct sockaddr_in)); + addr_in.sin_family = address_family; + addr_in.sin_addr.s_addr = inet_addr(ip_addr); + memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst)); + + memset(&addr_in, 0, sizeof(struct sockaddr_in)); + addr_in.sin_family = address_family; + addr_in.sin_addr.s_addr = inet_addr(subnet); + memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask)); + rt.rt_dev = ifr.ifr_name; + + errno = 0; + sock = socket(PF_INET, SOCK_DGRAM, 0); + + if (sock < 0) { + DBG("Failed to create socket : %s", strerror(errno)); + return -1; + } + + if (ioctl(sock, SIOCDELRT, &rt) < 0) { + DBG("Failed to set route address : %s", strerror(errno)); + close(sock); + return -1; + } + + close(sock); + + return 1; +} + int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len) { struct in6_rtmsg rt; @@ -505,24 +631,27 @@ int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u rt.rtmsg_flags = RTF_UP | RTF_HOST; + errno = 0; if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) { - err = -errno; - return err; + DBG("inet_pton failed : %s", strerror(errno)); + return -1; } if (gateway != NULL) { rt.rtmsg_flags |= RTF_GATEWAY; if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) { - err = -errno; - return err; + DBG("inet_pton failed : %s", strerror(errno)); + return -1; } } rt.rtmsg_metric = 1; fd = socket(AF_INET6, SOCK_DGRAM, 0); - if (fd < 0) + if (fd < 0) { + DBG("Failed to create socket : %s", strerror(errno)); return -1; + } rt.rtmsg_ifindex = 0; @@ -535,7 +664,7 @@ int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u } if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) { - DBG("Failed to add route: %d\n", err); + DBG("Failed to add route: %s", strerror(errno)); close(fd); return -1; } @@ -587,7 +716,7 @@ int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u } if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) { - DBG("Failed to add route: %d\n", err); + DBG("Failed to del route: %d\n", err); close(fd); return -1; } @@ -845,3 +974,35 @@ char* netconfig_get_env(const char *key) fclose(fp); return value; } + +void netconfig_set_mac_address_from_file(void) +{ + FILE *file = NULL; + char mac_str[MAC_ADDRESS_MAX_LEN]; + gchar *mac_lower_str = NULL; + int mac_len = 0; + + file = fopen(MAC_INFO_FILEPATH, "r"); + if (file == NULL) { + ERR("Fail to open %s", MAC_INFO_FILEPATH); + return; + } + if (fgets(mac_str, sizeof(mac_str), file) == NULL ) { + ERR("Fail to read mac address"); + fclose(file); + return; + } + + mac_len = strlen(mac_str); + if (mac_len < 17) { + ERR("mac.info is empty"); + fclose(file); + return; + } + + mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len); + netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str); + + g_free(mac_lower_str); + fclose(file); +} diff --git a/src/wifi-agent.c b/src/wifi-agent.c old mode 100644 new mode 100755 index c9ac420..c4456c7 --- a/src/wifi-agent.c +++ b/src/wifi-agent.c @@ -71,14 +71,14 @@ static void __netconfig_agent_clear_fields(void) agent.wps_pbc = FALSE; } -int netconfig_agent_register(void) +int connman_register_agent(void) { GVariant *reply = NULL; GVariant *params = NULL; GError *error; GDBusConnection *connection = NULL; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { ERR("GDBusconnection is NULL"); return -1; @@ -98,7 +98,7 @@ int netconfig_agent_register(void) NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), &error); if (reply == NULL) { @@ -125,7 +125,7 @@ int netconfig_agent_register(void) return 0; } -int netconfig_agent_unregister(void) +int connman_unregister_agent(void) { gboolean reply = FALSE; GVariant *param = NULL; @@ -486,15 +486,15 @@ static gboolean __check_ignore_portal_list(const char * ssid) return FALSE; } -static void __wifi_state_monitor(enum netconfig_wifi_service_state state, +static void __wifi_state_monitor(wifi_service_state_e state, void *user_data); -static struct netconfig_wifi_state_notifier wifi_state_monitor_notifier = { - .netconfig_wifi_state_changed = __wifi_state_monitor, +static wifi_state_notifier wifi_state_monitor_notifier = { + .wifi_state_changed = __wifi_state_monitor, .user_data = NULL, }; -static void __wifi_state_monitor(enum netconfig_wifi_service_state state, +static void __wifi_state_monitor(wifi_service_state_e state, void *user_data) { DBG("Wi-Fi state: %x", state); @@ -503,7 +503,7 @@ static void __wifi_state_monitor(enum netconfig_wifi_service_state state, return; if (is_monitor_notifier_registered == TRUE) { - netconfig_wifi_state_notifier_unregister(&wifi_state_monitor_notifier); + wifi_state_notifier_unregister(&wifi_state_monitor_notifier); is_monitor_notifier_registered = FALSE; } @@ -534,8 +534,7 @@ static gboolean __netconfig_wifi_portal_login_timeout(gpointer data) if (TRUE == netconfig_get_internet_status()) { if (is_monitor_notifier_registered == TRUE) { - netconfig_wifi_state_notifier_unregister( - &wifi_state_monitor_notifier); + wifi_state_notifier_unregister(&wifi_state_monitor_notifier); is_monitor_notifier_registered = FALSE; } @@ -546,8 +545,7 @@ static gboolean __netconfig_wifi_portal_login_timeout(gpointer data) DBG("Login failed, update ConnMan"); if (is_monitor_notifier_registered == TRUE) { - netconfig_wifi_state_notifier_unregister( - &wifi_state_monitor_notifier); + wifi_state_notifier_unregister(&wifi_state_monitor_notifier); is_monitor_notifier_registered = FALSE; } @@ -566,7 +564,7 @@ static gboolean __netconfig_wifi_portal_login_timeout(gpointer data) } } else { if (NETCONFIG_WIFI_CONNECTED == - netconfig_wifi_state_get_service_state()) { + wifi_state_get_service_state()) { /* check Internet availability by sending and receiving data*/ netconfig_check_internet_accessibility(); /* Returning TRUE itself is enough to restart the timer */ @@ -639,7 +637,7 @@ gboolean handle_request_browser(NetConnmanAgent *connman_agent, } /* Register for Wifi state change notifier*/ if (is_monitor_notifier_registered == FALSE) { - netconfig_wifi_state_notifier_register(&wifi_state_monitor_notifier); + wifi_state_notifier_register(&wifi_state_monitor_notifier); is_monitor_notifier_registered = TRUE; } diff --git a/src/wifi-background-scan.c b/src/wifi-background-scan.c old mode 100644 new mode 100755 index f384239..28f4f7d --- a/src/wifi-background-scan.c +++ b/src/wifi-background-scan.c @@ -88,7 +88,7 @@ static guint __netconfig_wifi_bgscan_get_mode(void) static gboolean __netconfig_wifi_bgscan_request_connman_scan(int retries) { gboolean reply = FALSE; - guint state = netconfig_wifi_state_get_service_state(); + guint state = wifi_state_get_service_state(); if (state == NETCONFIG_WIFI_CONNECTED) if (__netconfig_wifi_bgscan_get_mode() == WIFI_BGSCAN_MODE_EXPONENTIAL) @@ -221,14 +221,14 @@ gboolean netconfig_wifi_is_bgscan_paused(void) void netconfig_wifi_bgscan_start(gboolean immediate_scan) { - enum netconfig_wifi_tech_state wifi_tech_state; + wifi_tech_state_e wifi_tech_state; struct bgscan_timer_data *timer_data = __netconfig_wifi_bgscan_get_bgscan_data(); if (timer_data == NULL) return; - wifi_tech_state = netconfig_wifi_state_get_technology_state(); + wifi_tech_state = wifi_state_get_technology_state(); if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED) return; @@ -271,8 +271,7 @@ void netconfig_wifi_set_scanning(gboolean scanning) netconfig_wifi_scanning = scanning; } -gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, - guint scan_mode) +gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, guint scan_mode) { gint old_mode = 0; int pm_state = VCONFKEY_PM_STATE_NORMAL; diff --git a/src/wifi-config.c b/src/wifi-config.c old mode 100644 new mode 100755 index 54dae24..f6dfe44 --- a/src/wifi-config.c +++ b/src/wifi-config.c @@ -33,26 +33,27 @@ #include "wifi-config.h" #define CONNMAN_STORAGE "/var/lib/connman" -#define WIFI_CONFIG_PREFIX "wifi_" - -#define WIFI_CONFIG_NAME "Name" -#define WIFI_CONFIG_SSID "SSID" -#define WIFI_CONFIG_PASSPHRASE "Passphrase" -#define WIFI_CONFIG_SECURITY_TYPE "Security" -#define WIFI_CONFIG_FAVORITE "Favorite" -#define WIFI_CONFIG_AUTOCONNECT "AutoConnect" -#define WIFI_CONFIG_HIDDEN "Hidden" -#define WIFI_CONFIG_FAILURE "Failure" -#define WIFI_CONFIG_PROXYADDRESS "ProxyAddress" -#define WIFI_CONFIG_PROXY_METHOD "Proxy.Method" -#define WIFI_CONFIG_PROXY_SERVER "Proxy.Servers" #define WIFI_SECURITY_NONE "none" #define WIFI_SECURITY_WEP "wep" #define WIFI_SECURITY_WPA_PSK "psk" #define WIFI_SECURITY_EAP "ieee8021x" -#define WIFI_PREFIX_LENGTH 18 // wifi_485a3f2f506a_ +#define WIFI_CONFIG_PREFIX "wifi_" +#define MAC_ADDRESS_LENGTH 12 +#define WIFI_PREFIX_LENGTH MAC_ADDRESS_LENGTH + 6 // wifi_485a3f2f506a_ +#define PROFILE_PREFIX_LENGTH WIFI_PREFIX_LENGTH + 21 // /net/connman/service/wifi_485a3f2f506a_ + +struct wifi_eap_config { + gchar *anonymous_identity; + gchar *ca_cert; + gchar *client_cert; + gchar *private_key; + gchar *identity; + gchar *eap_type; + gchar *eap_auth_type; + gchar *subject_match; +}; struct wifi_config { gchar *name; @@ -63,10 +64,36 @@ struct wifi_config { gboolean autoconnect; gchar *is_hidden; gchar *proxy_address; + struct wifi_eap_config *eap_config; gchar *last_error; }; -static gint __netconfig_get_mac_address(gchar **mac_address) +static void __free_wifi_configuration(struct wifi_config *conf) +{ + if (conf == NULL) + return; + + g_free(conf->name); + g_free(conf->ssid); + g_free(conf->passphrase); + g_free(conf->security_type); + g_free(conf->is_hidden); + g_free(conf->proxy_address); + if (conf->eap_config) { + g_free(conf->eap_config->anonymous_identity); + g_free(conf->eap_config->ca_cert); + g_free(conf->eap_config->client_cert); + g_free(conf->eap_config->private_key); + g_free(conf->eap_config->identity); + g_free(conf->eap_config->eap_type); + g_free(conf->eap_config->eap_auth_type); + g_free(conf->eap_config->subject_match); + g_free(conf->eap_config); + } + g_free(conf); +} + +static gboolean __get_mac_address(gchar **mac_address) { gchar *tmp_mac = NULL; gchar *tmp = NULL; @@ -77,7 +104,7 @@ static gint __netconfig_get_mac_address(gchar **mac_address) if (tmp_mac == NULL) { ERR("vconf_get_str(WIFI_BSSID_ADDRESS) Failed"); *mac_address = NULL; - return -1; + return FALSE; } tmp = g_ascii_strdown(tmp_mac, (gssize)strlen(tmp_mac)); g_free(tmp_mac); @@ -91,10 +118,82 @@ static gint __netconfig_get_mac_address(gchar **mac_address) mac[12] = '\0'; *mac_address = g_strdup(mac); - return 0; + return TRUE; +} + +static gboolean __get_group_name(const gchar *prefix, const gchar *config_id, gchar **group_name) +{ + gchar *mac_address = NULL; + gchar *g_name = NULL; + gboolean ret = FALSE; + + ret = __get_mac_address(&mac_address); + if ((ret != TRUE) || (strlen(mac_address) == 0)) { + ERR("Cannot get WIFI MAC address"); + return FALSE; + } + + g_name = g_strdup_printf("%s%s_%s", prefix, mac_address, config_id); + if (g_name == NULL) { + g_free(mac_address); + return FALSE; + } + + *group_name = g_strdup(g_name); + + g_free(mac_address); + g_free(g_name); + + return TRUE; +} + +static gboolean __get_security_type(const gchar *config_id, gchar **type) +{ + if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) { + *type = g_strdup(WIFI_SECURITY_NONE); + } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) { + *type = g_strdup(WIFI_SECURITY_WEP); + } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) { + *type = g_strdup(WIFI_SECURITY_WPA_PSK); + } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) { + *type = g_strdup(WIFI_SECURITY_EAP); + } else { + *type = NULL; + return FALSE; + } + + return TRUE; } -static gboolean ___netconfig_remove_file(const gchar *pathname, const gchar *filename) +static gboolean __get_config_id(const gchar *profile, gchar **config_id) +{ + *config_id = g_strdup(profile + PROFILE_PREFIX_LENGTH); + if (*config_id == NULL) { + ERR("OOM"); + return FALSE; + } + + return TRUE; +} + + +static GKeyFile *__get_configuration_keyfile(const gchar *group_name) +{ + GKeyFile *keyfile = NULL; + gchar *path; + + path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name); + + keyfile = netconfig_keyfile_load(path); + if (keyfile == NULL) { + ERR("keyfile[%s] is NULL", path); + g_free(path); + } + + return keyfile; +} + +static gboolean __remove_file(const gchar *pathname, const gchar *filename) { gboolean ret = FALSE; gchar *path; @@ -111,15 +210,15 @@ static gboolean ___netconfig_remove_file(const gchar *pathname, const gchar *fil return ret; } -static gboolean __netconfig_remove_configuration(const gchar *pathname) +static gboolean __remove_configuration(const gchar *pathname) { int ret = 0; - if (___netconfig_remove_file(pathname, "settings") != TRUE) { + if (__remove_file(pathname, "settings") != TRUE) { ERR("Cannot remove [%s/settings]", pathname); return FALSE; } - if (___netconfig_remove_file(pathname, "data") != TRUE) { + if (__remove_file(pathname, "data") != TRUE) { ERR("Cannot remove [%s/data]", pathname); return FALSE; } @@ -133,56 +232,34 @@ static gboolean __netconfig_remove_configuration(const gchar *pathname) return TRUE; } -static gint _netconfig_get_security_type(const gchar *config_id, gchar **type) -{ - int ret = 0; - - if (g_str_has_suffix(config_id, WIFI_SECURITY_NONE) == TRUE) { - *type = g_strdup(WIFI_SECURITY_NONE); - } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WEP) == TRUE) { - *type = g_strdup(WIFI_SECURITY_WEP); - } else if (g_str_has_suffix(config_id, WIFI_SECURITY_WPA_PSK) == TRUE) { - *type = g_strdup(WIFI_SECURITY_WPA_PSK); - } else if (g_str_has_suffix(config_id, WIFI_SECURITY_EAP) == TRUE) { - *type = g_strdup(WIFI_SECURITY_EAP); - } else { - *type = NULL; - ret = -1; - } - - return ret; -} - -static gboolean _netconfig_load_wifi_configuration(const gchar *config_id, - struct wifi_config *config) +static gboolean _load_configuration(const gchar *config_id, struct wifi_config *config) { GKeyFile *keyfile; - gchar *path; gchar *group_name; - gchar *mac_address = NULL; gboolean hidden = FALSE; + gboolean ret = FALSE; - __netconfig_get_mac_address(&mac_address); - if (strlen(mac_address) == 0) { - ERR("mac_address is NULL"); + ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + if (ret != TRUE) { + ERR("Fail to get_wifi_config_group_name"); return FALSE; } - group_name = g_strdup_printf(WIFI_CONFIG_PREFIX "%s_%s", mac_address, config_id); - g_free(mac_address); - path = g_strdup_printf("/var/lib/connman/%s/settings", group_name); - - DBG("group_name %s", group_name); - DBG("path %s", path); - - keyfile = netconfig_keyfile_load(path); + keyfile = __get_configuration_keyfile(group_name); if (keyfile == NULL) { - ERR("keyfile[%s] is NULL", path); + ERR("Fail to __get_configuration_keyfile[%s]", group_name); + g_free(group_name); return FALSE; } + config->name = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL); - config->passphrase = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL); - _netconfig_get_security_type(config_id, &config->security_type); + ret = __get_security_type(config_id, &config->security_type); + if (ret != TRUE) { + ERR("Fail to _get_security_type"); + g_key_file_free(keyfile); + g_free(group_name); + return FALSE; + } config->proxy_address = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL); hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL); if (hidden) { @@ -190,35 +267,42 @@ static gboolean _netconfig_load_wifi_configuration(const gchar *config_id, } else { config->is_hidden = g_strdup("FALSE"); } + + if (g_strcmp0(config->security_type, WIFI_SECURITY_EAP) == 0) { + config->eap_config->anonymous_identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL); + config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL); + config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL); + config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL); + config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL); + config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL); + config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL); + config->eap_config->subject_match = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL); + } + config->last_error = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL); + g_key_file_free(keyfile); g_free(group_name); - g_free(path); return TRUE; } -static gboolean _netconfig_save_wifi_configuration(const gchar *config_id, - const struct wifi_config *config) +static gboolean _save_configuration(const gchar *config_id, GKeyFile *keyfile) { - GKeyFile *keyfile; gchar *dir; gchar *path; gchar *group_name; - gchar *mac_address = NULL; + gboolean ret = FALSE; - __netconfig_get_mac_address(&mac_address); - if (mac_address == NULL) { - ERR("mac_address is NULL"); + ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + if (ret != TRUE) { + ERR("Fail to get_wifi_config_group_name"); return FALSE; } - group_name = g_strdup_printf("wifi_%s_%s", mac_address, config_id); - g_free(mac_address); - dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name); if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) { - if (__netconfig_remove_configuration(dir) != TRUE) { + if (__remove_configuration(dir) != TRUE) { ERR("[%s] is existed, but cannot remove", dir); g_free(group_name); g_free(dir); @@ -233,30 +317,6 @@ static gboolean _netconfig_save_wifi_configuration(const gchar *config_id, return FALSE; } - keyfile = g_key_file_new(); - g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, config->name); - g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, config->ssid); - - if (config->passphrase != NULL) - g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, config->passphrase); - - g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, config->favorite); - g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, config->autoconnect); - - // Optional field - if (config->proxy_address != NULL) { - g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual"); - g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, config->proxy_address); - } - - if (config->is_hidden != NULL) { - gboolean hidden = FALSE; - if (g_strcmp0(config->is_hidden, "TRUE") == 0) { - hidden = TRUE; - } - g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden); - } - path = g_strdup_printf(CONNMAN_STORAGE "/%s/settings", group_name); netconfig_keyfile_save(keyfile, path); g_free(group_name); @@ -266,25 +326,21 @@ static gboolean _netconfig_save_wifi_configuration(const gchar *config_id, return TRUE; } -static gboolean _netconfig_remove_wifi_configuration(const gchar *config_id) +static gboolean _remove_configuration(const gchar *config_id) { gboolean ret = FALSE; gchar *dir; gchar *group_name; - gchar *mac_address = NULL; - __netconfig_get_mac_address(&mac_address); - if (mac_address == NULL) { - ERR("mac_address is NULL"); + ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + if (ret != TRUE) { + ERR("Fail to get_wifi_config_group_name"); return FALSE; } - group_name = g_strdup_printf("wifi_%s_%s", mac_address, config_id); - g_free(mac_address); - dir = g_strdup_printf(CONNMAN_STORAGE "/%s", group_name); if (g_file_test(dir, G_FILE_TEST_IS_DIR) == TRUE) { - if (__netconfig_remove_configuration(dir) != TRUE) { + if (__remove_configuration(dir) != TRUE) { ERR("[%s] is existed, but cannot remove", dir); ret = FALSE; } @@ -301,31 +357,23 @@ static gboolean _netconfig_remove_wifi_configuration(const gchar *config_id) return ret; } -static gboolean _netconfig_set_wifi_config_field(const gchar *config_id, - const gchar *key, const gchar *value) + +static gboolean _set_field(const gchar *config_id, const gchar *key, const gchar *value) { gboolean ret = TRUE; GKeyFile *keyfile; - gchar *path; gchar *group_name; - gchar *mac_address = NULL; - __netconfig_get_mac_address(&mac_address); - if (strlen(mac_address) == 0) { - ERR("mac_address is NULL"); + ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + if (ret != TRUE) { + ERR("Fail to get_wifi_config_group_name"); return FALSE; } - - group_name = g_strdup_printf(WIFI_CONFIG_PREFIX "%s_%s", mac_address, config_id); - g_free(mac_address); - path = g_strdup_printf("/var/lib/connman/%s/settings", group_name); - DBG("group_name %s", group_name); - DBG("path %s", path); - keyfile = netconfig_keyfile_load(path); + keyfile = __get_configuration_keyfile(group_name); if (keyfile == NULL) { - ERR("keyfile[%s] is NULL", path); + ERR("Fail to __get_configuration_keyfile"); return FALSE; } @@ -339,19 +387,102 @@ static gboolean _netconfig_set_wifi_config_field(const gchar *config_id, hidden = TRUE; } g_key_file_set_boolean(keyfile, group_name, key, hidden); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) { + g_key_file_set_string(keyfile, group_name, key, value); } else { ERR("key[%s] is not supported", key); ret = FALSE; } - netconfig_keyfile_save(keyfile, path); + _save_configuration(config_id, keyfile); + + g_key_file_free(keyfile); g_free(group_name); - g_free(path); return ret; } -static GSList *_netconfig_get_wifi_config_list(void) +static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **value) +{ + GKeyFile *keyfile; + gchar *group_name; + gchar *val = NULL; + gboolean hidden = FALSE; + gboolean ret = FALSE; + + ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + if (ret != TRUE) { + ERR("Fail to get_wifi_config_group_name"); + return FALSE; + } + DBG("group_name %s", group_name); + + keyfile = __get_configuration_keyfile(group_name); + if (keyfile == NULL) { + ERR("Fail to __get_configuration_keyfile"); + return FALSE; + } + + if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) { + hidden = g_key_file_get_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, NULL); + if (hidden) { + val = g_strdup("TRUE"); + } else { + val = g_strdup("FALSE"); + } + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_SUBJECT_MATCH, NULL); + } else if (g_strcmp0(key, WIFI_CONFIG_FAILURE) == 0) { + val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_FAILURE, NULL); + } else { + ERR("Invalid key[%s]", key); + val = g_strdup("NOTSUPPORTED"); + } + + *value = g_strdup(val); + g_free(val); + + g_key_file_free(keyfile); + g_free(group_name); + + return TRUE; +} + +static GSList *_get_list(void) { GSList *list = NULL; struct dirent *d; @@ -364,8 +495,7 @@ static GSList *_netconfig_get_wifi_config_list(void) } while ((d = readdir(dir))) { - if (g_strcmp0(d->d_name, ".") == 0 || - g_strcmp0(d->d_name, "..") == 0 || + if (g_strcmp0(d->d_name, ".") == 0 || g_strcmp0(d->d_name, "..") == 0 || strncmp(d->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) { continue; } @@ -378,6 +508,33 @@ static GSList *_netconfig_get_wifi_config_list(void) return list; } +gboolean wifi_config_get_config_id(const gchar *service_profile, gchar **config_id) +{ + gboolean ret = FALSE; + gchar *val = NULL; + + if ((service_profile == NULL) || (config_id == NULL)) { + ERR("Invalid parameter"); + return FALSE; + } + + ret = __get_config_id(service_profile, &val); + *config_id = g_strdup(val); + g_free(val); + + return ret; +} + +gboolean wifi_config_remove_configuration(const gchar *config_id) +{ + gboolean ret = FALSE; + + ret = _remove_configuration(config_id); + + return ret; +} + +// dbus method gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context) { guint i = 0; @@ -387,7 +544,7 @@ gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context) g_return_val_if_fail(wifi != NULL, FALSE); - config_ids = _netconfig_get_wifi_config_list(); + config_ids = _get_list(); if (config_ids == NULL) { netconfig_error_no_profile(context); ERR("Fail to get config list"); @@ -412,49 +569,45 @@ gboolean handle_load_configuration(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id) { gboolean ret = FALSE; - gchar *name = NULL, *passphrase = NULL, *security_type = NULL; - gchar *proxy_address = NULL, *is_hidden = NULL, *last_error = NULL; + GVariantBuilder *b = NULL; struct wifi_config *conf = NULL; g_return_val_if_fail(wifi != NULL, FALSE); conf = g_new0(struct wifi_config, 1); - ret = _netconfig_load_wifi_configuration(config_id, conf); + ret = _load_configuration(config_id, conf); if (ret != TRUE) { g_free(conf); - ERR("No wifi configuration"); + ERR("Fail to _load_configuration"); netconfig_error_no_profile(context); return FALSE; } - name = g_strdup(conf->name); - passphrase = g_strdup(conf->passphrase); - security_type = g_strdup(conf->security_type); - is_hidden = g_strdup(conf->is_hidden); - + b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name)); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type)); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden)); if (conf->proxy_address != NULL) { - proxy_address = g_strdup(conf->proxy_address); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address)); g_free(conf->proxy_address); } else { - proxy_address = g_strdup("NONE"); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE")); } if (conf->last_error != NULL) { - last_error = g_strdup(conf->last_error); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error)); g_free(conf->last_error); } else { - last_error = g_strdup("ERROR_NONE"); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE")); } g_free(conf->name); - g_free(conf->passphrase); g_free(conf->security_type); g_free(conf->is_hidden); g_free(conf); - wifi_complete_load_configuration (wifi, context, name, - passphrase, security_type, proxy_address, is_hidden, last_error); - + wifi_complete_load_configuration(wifi, context, g_variant_builder_end(b)); + g_variant_builder_unref(b); return TRUE; } @@ -463,16 +616,21 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, { gboolean ret = FALSE; struct wifi_config *conf = NULL; + GKeyFile *keyfile = NULL; GVariantIter *iter; GVariant *value; gchar *field; + gchar *group_name = NULL; if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) { - ERR("Invaliad parameter"); + ERR("Invalid parameter"); netconfig_error_invalid_parameter(context); + SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed"); return FALSE; } + ERR("save_configuration [%s]", config_id); + conf = g_new0(struct wifi_config, 1); g_variant_get(configuration, "a{sv}", &iter); @@ -494,7 +652,7 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) { if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { conf->passphrase = g_strdup(g_variant_get_string(value, NULL)); - ERR("passphrase [%s]", conf->passphrase); + ERR("passphrase []"); } else { conf->passphrase = NULL; } @@ -506,16 +664,57 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, conf->is_hidden = NULL; } } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) { - conf->proxy_address = g_strdup(g_variant_get_string(value, NULL)); - ERR("proxy_address [%s]", conf->proxy_address); - } else { - conf->proxy_address = NULL; + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->proxy_address = g_strdup(g_variant_get_string(value, NULL)); + ERR("proxy_address [%s]", conf->proxy_address); + } else { + conf->proxy_address = NULL; + } } } conf->favorite = TRUE; conf->autoconnect = TRUE; - ret = _netconfig_save_wifi_configuration(config_id, conf); + ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + if (ret != TRUE) { + ERR("Fail to get_wifi_config_group_name"); + return FALSE; + } + + keyfile = g_key_file_new(); + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name); + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid); + + if (conf->passphrase != NULL) + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase); + + g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite); + g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect); + + // Optional field + if (conf->proxy_address != NULL) { + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual"); + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address); + } + + if (conf->is_hidden != NULL) { + gboolean hidden = FALSE; + if (g_strcmp0(conf->is_hidden, "TRUE") == 0) { + hidden = TRUE; + } + g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden); + } + + ret = _save_configuration(config_id, keyfile); + if (ret == TRUE) { + SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Succeed"); + wifi_complete_save_configuration(wifi, context); + } else { + SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed"); + netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration"); + } + + g_key_file_free(keyfile); g_free(conf->name); g_free(conf->ssid); g_free(conf->passphrase); @@ -525,12 +724,262 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context, g_variant_iter_free(iter); + return ret; +} + +gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *config_id) +{ + gboolean ret = FALSE; + GVariantBuilder *b = NULL; + struct wifi_config *conf = NULL; + + g_return_val_if_fail(wifi != NULL, FALSE); + + conf = g_new0(struct wifi_config, 1); + conf->eap_config = g_new0(struct wifi_eap_config, 1); + + ret = _load_configuration(config_id, conf); + if (ret != TRUE) { + g_free(conf->eap_config); + g_free(conf); + ERR("Fail to _load_configuration"); + netconfig_error_no_profile(context); + return FALSE; + } + + b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(conf->name)); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_SECURITY_TYPE, g_variant_new_string(conf->security_type)); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string(conf->is_hidden)); + if (conf->proxy_address != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(conf->proxy_address)); + g_free(conf->proxy_address); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string("NONE")); + } + if (conf->last_error != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string(conf->last_error)); + g_free(conf->last_error); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_FAILURE, g_variant_new_string("ERROR_NONE")); + } + if (conf->eap_config != NULL) { + if (conf->eap_config->anonymous_identity != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string(conf->eap_config->anonymous_identity)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, g_variant_new_string("NONE")); + } + if (conf->eap_config->ca_cert != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string(conf->eap_config->ca_cert)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CACERT, g_variant_new_string("NONE")); + } + if (conf->eap_config->client_cert != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string(conf->eap_config->client_cert)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_CLIENTCERT, g_variant_new_string("NONE")); + } + if (conf->eap_config->private_key != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string(conf->eap_config->private_key)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE")); + } + if (conf->eap_config->identity != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string("NONE")); + } + if (conf->eap_config->eap_type != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string(conf->eap_config->eap_type)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_TYPE, g_variant_new_string("NONE")); + } + if (conf->eap_config->eap_auth_type != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string(conf->eap_config->eap_auth_type)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_AUTH_TYPE, g_variant_new_string("NONE")); + } + if (conf->eap_config->subject_match != NULL) { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string(conf->eap_config->subject_match)); + } else { + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_SUBJECT_MATCH, g_variant_new_string("NONE")); + } + } + + __free_wifi_configuration(conf); + + wifi_complete_load_eap_configuration(wifi, context, g_variant_builder_end(b)); + g_variant_builder_unref(b); + return TRUE; +} + +gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *config_id, GVariant *configuration) +{ + gboolean ret = FALSE; + struct wifi_config *conf = NULL; + GKeyFile *keyfile = NULL; + GVariantIter *iter; + GVariant *value; + gchar *field; + gchar *group_name = NULL; + + if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) { + ERR("Invalid parameter"); + netconfig_error_invalid_parameter(context); + SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed"); + return FALSE; + } + + INFO("save [%s]", config_id); + + conf = g_new0(struct wifi_config, 1); + conf->eap_config = g_new0(struct wifi_eap_config, 1); + + g_variant_get(configuration, "a{sv}", &iter); + while (g_variant_iter_loop(iter, "{sv}", &field, &value)) { + if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->name = g_strdup(g_variant_get_string(value, NULL)); + ERR("name [%s]", conf->name); + } else { + conf->name = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_SSID) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->ssid = g_strdup(g_variant_get_string(value, NULL)); + ERR("ssid [%s]", conf->ssid); + } else { + conf->ssid = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->passphrase = g_strdup(g_variant_get_string(value, NULL)); + ERR("passphrase [%s]", conf->passphrase); + } else { + conf->passphrase = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->is_hidden = g_strdup(g_variant_get_string(value, NULL)); + ERR("is_hidden [%s]", conf->is_hidden); + } else { + conf->is_hidden = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_PROXYADDRESS) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->proxy_address = g_strdup(g_variant_get_string(value, NULL)); + ERR("proxy_address [%s]", conf->proxy_address); + } else { + conf->proxy_address = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->anonymous_identity = g_strdup(g_variant_get_string(value, NULL)); + ERR("anonymous_identity [%s]", conf->eap_config->anonymous_identity); + } else { + conf->eap_config->anonymous_identity = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CACERT) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->ca_cert = g_strdup(g_variant_get_string(value, NULL)); + ERR("ca_cert [%s]", conf->eap_config->ca_cert); + } else { + conf->eap_config->ca_cert = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_CLIENTCERT) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->client_cert = g_strdup(g_variant_get_string(value, NULL)); + ERR("client_cert [%s]", conf->eap_config->client_cert); + } else { + conf->eap_config->client_cert = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->private_key = g_strdup(g_variant_get_string(value, NULL)); + ERR("private_key [%s]", conf->eap_config->private_key); + } else { + conf->eap_config->private_key = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL)); + ERR("identity [%s]", conf->eap_config->identity); + } else { + conf->eap_config->identity = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_TYPE) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->eap_type = g_strdup(g_variant_get_string(value, NULL)); + ERR("eap_type [%s]", conf->eap_config->eap_type); + } else { + conf->eap_config->eap_type = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->eap_auth_type = g_strdup(g_variant_get_string(value, NULL)); + ERR("eap_auth_type [%s]", conf->eap_config->eap_auth_type); + } else { + conf->eap_config->eap_auth_type = NULL; + } + } else if (g_strcmp0(field, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) { + if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { + conf->eap_config->subject_match = g_strdup(g_variant_get_string(value, NULL)); + ERR("subject_match [%s]", conf->eap_config->subject_match); + } else { + conf->eap_config->subject_match = NULL; + } + } + } + conf->favorite = TRUE; + conf->autoconnect = TRUE; + + ret = __get_group_name(WIFI_CONFIG_PREFIX, config_id, &group_name); + if (ret != TRUE) { + __free_wifi_configuration(conf); + ERR("Fail to get_wifi_config_group_name"); + return FALSE; + } + + keyfile = g_key_file_new(); + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_NAME, conf->name); + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_SSID, conf->ssid); + + if (conf->passphrase != NULL) + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, conf->passphrase); + + g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite); + g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect); + + // Optional field + if (conf->proxy_address != NULL) { + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual"); + g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, conf->proxy_address); + } + + if (conf->is_hidden != NULL) { + gboolean hidden = FALSE; + if (g_strcmp0(conf->is_hidden, "TRUE") == 0) { + hidden = TRUE; + } + g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_HIDDEN, hidden); + } + + ret = _save_configuration(config_id, keyfile); if (ret == TRUE) { - wifi_complete_save_configuration(wifi, context); + SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Succeed"); + wifi_complete_save_eap_configuration(wifi, context); } else { - netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration"); + SLOG(LOG_INFO, "MDM_LOG_USER", "Object=wifi-profile, AccessType=Create, Result=Failed"); + netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveEapConfiguration"); } + g_key_file_free(keyfile); + __free_wifi_configuration(conf); + + g_variant_iter_free(iter); + return ret; } @@ -539,12 +988,12 @@ gboolean handle_remove_configuration(Wifi *wifi, GDBusMethodInvocation *context, gboolean ret = FALSE; if ((wifi == NULL) || (config_id == NULL)) { - ERR("Invaliad parameter"); + ERR("Invalid parameter"); netconfig_error_invalid_parameter(context); return FALSE; } - ret = _netconfig_remove_wifi_configuration(config_id); + ret = _remove_configuration(config_id); if (ret != TRUE) { // no configuration or error ERR("No [%s] configuration", config_id); @@ -589,7 +1038,7 @@ gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, DBG("Key[%s] Value[%d]", key, value); if (g_strcmp0(key, WIFI_CONFIG_PROXYADDRESS) == 0) { - ret = _netconfig_set_wifi_config_field(config_id, WIFI_CONFIG_PROXY_METHOD, "manual"); + ret = _set_field(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); @@ -598,13 +1047,29 @@ gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_PROXY_SERVER); } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) { keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_HIDDEN); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CACERT) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CACERT); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_CLIENTCERT) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_CLIENTCERT); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_PRIVATEKEY) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_PRIVATEKEY); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_IDENTITY) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_IDENTITY); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_TYPE) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_TYPE); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_AUTH_TYPE) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_AUTH_TYPE); + } else if (g_strcmp0(key, WIFI_CONFIG_EAP_SUBJECT_MATCH) == 0) { + keyfile_key = g_strdup_printf("%s", WIFI_CONFIG_EAP_SUBJECT_MATCH); } else { ERR("Not supported key[%s]", key); netconfig_error_invalid_parameter(context); return FALSE; } - ret = _netconfig_set_wifi_config_field(config_id, keyfile_key, (const gchar *)value); + ret = _set_field(config_id, keyfile_key, (const gchar *)value); if (!ret) { ERR("Fail to [%s]set_wifi_config_field(%s/%s)", config_id, key, value); ret = FALSE; @@ -616,3 +1081,27 @@ gboolean handle_set_config_field(Wifi *wifi, GDBusMethodInvocation *context, wifi_complete_set_config_field(wifi,context); return ret; } + +gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context, const gchar *config_id) +{ + gboolean ret = FALSE; + gchar *passphrase = NULL; + + if ((wifi == NULL) || (config_id == NULL)) { + ERR("Invalid parameter"); + netconfig_error_invalid_parameter(context); + return FALSE; + } + + ret = _get_field(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"); + return FALSE; + } + + wifi_complete_get_config_passphrase(wifi, context, passphrase); + g_free(passphrase); + + return ret; +} diff --git a/src/wifi-dump.c b/src/wifi-dump.c old mode 100644 new mode 100755 index 08dd12e..b98581e --- a/src/wifi-dump.c +++ b/src/wifi-dump.c @@ -49,7 +49,7 @@ static void _send_dump_signal(const gchar *sig_name) GDBusConnection *connection = NULL; GError *error = NULL; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { DBG("GDBusconnection is NULL"); return; diff --git a/src/wifi-eap-config.c b/src/wifi-eap-config.c old mode 100644 new mode 100755 index 1103496..72b0636 --- a/src/wifi-eap-config.c +++ b/src/wifi-eap-config.c @@ -27,6 +27,7 @@ #include "netdbus.h" #include "wifi-agent.h" #include "wifi-state.h" +#include "wifi-config.h" #include "wifi-eap-config.h" #include "neterror.h" @@ -41,6 +42,7 @@ #define CONNMAN_CONFIG_FIELD_CLIENT_CERT_FILE "ClientCertFile" #define CONNMAN_CONFIG_FIELD_PVT_KEY_FILE "PrivateKeyFile" #define CONNMAN_CONFIG_FIELD_PVT_KEY_PASSPHRASE "PrivateKeyPassphrase" +#define CONNMAN_CONFIG_FIELD_KEYMGMT_TYPE "KeymgmtType" static char *__get_encoded_ssid(const char *name) { @@ -271,7 +273,8 @@ static gboolean __netconfig_create_config(GVariant *fields) while (g_variant_iter_loop(iter, "{ss}", &field, &value)) { if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_SSID) == 0 || g_strcmp0(field, CONNMAN_CONFIG_FIELD_EAP_METHOD) == 0 || - g_strcmp0(field, CONNMAN_CONFIG_FIELD_PHASE2) == 0) { + g_strcmp0(field, CONNMAN_CONFIG_FIELD_PHASE2) || + g_strcmp0(field, CONNMAN_CONFIG_FIELD_KEYMGMT_TYPE) == 0) { DBG("field: %s, value: %s", field, value); if (value != NULL) @@ -323,8 +326,7 @@ static gboolean __netconfig_create_config(GVariant *fields) g_free(cert_path); } } else { - //DBG("field: %s, value:", field); - DBG("Temporal field: %s, value: %s", field, value); + DBG("field: %s, value: %s", field, value); if (value != NULL) g_key_file_set_string(keyfile, group_name, field, value); @@ -357,6 +359,30 @@ out: return updated; } +static gboolean _delete_configuration(const gchar *profile) +{ + gboolean ret = FALSE; + gchar *config_id = NULL; + + ret = wifi_config_get_config_id(profile, &config_id); + if (ret != TRUE) { + ERR("Fail to get config_id from [%s]", profile); + return ret; + } + ERR("get config_id [%s] from [%s]", config_id, profile); + + ret = wifi_config_remove_configuration(config_id); + if (ret != TRUE) { + ERR("Fail to wifi_config_remove_configuration [%s]", config_id); + } + + if (config_id != NULL) { + g_free(config_id); + } + + return ret; +} + static gboolean __netconfig_delete_config(const char *profile) { char *wifi_ident = NULL; @@ -371,6 +397,10 @@ static gboolean __netconfig_delete_config(const char *profile) return FALSE; } + if (_delete_configuration(profile) != TRUE) { + ERR("Fail to delete configuration [%s]", profile); + } + wifi_ident = strstr(profile, "wifi_"); if (wifi_ident == NULL) { ERR("Invalid profile name"); @@ -409,20 +439,20 @@ static gboolean __netconfig_delete_config(const char *profile) } static void __netconfig_eap_state( - enum netconfig_wifi_service_state state, void *user_data); + wifi_service_state_e state, void *user_data); -static struct netconfig_wifi_state_notifier netconfig_eap_notifier = { - .netconfig_wifi_state_changed = __netconfig_eap_state, +static wifi_state_notifier netconfig_eap_notifier = { + .wifi_state_changed = __netconfig_eap_state, .user_data = NULL, }; static void __netconfig_eap_state( - enum netconfig_wifi_service_state state, void *user_data) + wifi_service_state_e state, void *user_data) { const char *wifi_profile = (const char *)user_data; if (wifi_profile == NULL) { - netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier); + wifi_state_notifier_unregister(&netconfig_eap_notifier); return; } @@ -435,7 +465,7 @@ static void __netconfig_eap_state( g_free(netconfig_eap_notifier.user_data); netconfig_eap_notifier.user_data = NULL; - netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier); + wifi_state_notifier_unregister(&netconfig_eap_notifier); } gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context, @@ -491,11 +521,11 @@ gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context, g_free(netconfig_eap_notifier.user_data); netconfig_eap_notifier.user_data = NULL; - netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier); + wifi_state_notifier_unregister(&netconfig_eap_notifier); } netconfig_eap_notifier.user_data = g_strdup(service); - netconfig_wifi_state_notifier_register(&netconfig_eap_notifier); + wifi_state_notifier_register(&netconfig_eap_notifier); } else { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments"); } diff --git a/src/wifi-eap.c b/src/wifi-eap.c old mode 100644 new mode 100755 index ff1aebf..0dbf179 --- a/src/wifi-eap.c +++ b/src/wifi-eap.c @@ -255,7 +255,7 @@ static gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data, return TRUE; } -static gboolean __netconfig_wifi_req_aka_auth( +static netconfig_error_e __netconfig_wifi_req_aka_auth( GArray *rand_data, GArray *autn_data, GDBusMethodInvocation *context) { int i; @@ -264,34 +264,30 @@ static gboolean __netconfig_wifi_req_aka_auth( TelSimAuthenticationData_t auth_data; if (rand_data == NULL || autn_data == NULL) - return FALSE; + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; if (rand_data->len != AKA_RAND_DATA_LEN) { ERR("wrong rand data len : [%d]", rand_data->len); - netconfig_error_fail_req_sim_auth_wrong_param(context); - return FALSE; + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; } if (autn_data->len != AKA_AUTN_DATA_LEN) { ERR("wrong autn data len : [%d]", autn_data->len); - netconfig_error_fail_req_sim_auth_wrong_param(context); - return FALSE; + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; } if ((ret = g_array_get_element_size(rand_data)) != 1) { ERR("wrong rand data size : [%d]", ret); - netconfig_error_fail_req_sim_auth_wrong_param(context); - return FALSE; + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; } if ((ret = g_array_get_element_size(autn_data)) != 1) { ERR("wrong autn data size : [%d]", ret); - netconfig_error_fail_req_sim_auth_wrong_param(context); - return FALSE; + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; } memset(&auth_data, 0, sizeof(auth_data)); @@ -308,8 +304,7 @@ static gboolean __netconfig_wifi_req_aka_auth( handle = (TapiHandle *)netconfig_tel_init(); if (handle == NULL) { - netconfig_error_fail_req_sim_auth(context); - return FALSE; + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; } ret = tel_req_sim_authentication(handle, &auth_data, @@ -318,10 +313,9 @@ static gboolean __netconfig_wifi_req_aka_auth( if (ret != TAPI_API_SUCCESS) { ERR("Failed tel_req_sim_authentication() : [%d]", ret); - netconfig_error_fail_req_sim_auth(context); - return FALSE; + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; } - return TRUE; + return NETCONFIG_NO_ERROR; } static gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi, @@ -448,47 +442,100 @@ gboolean handle_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context) return ret; } -gboolean handle_req_sim_auth(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *rand_data) +gboolean handle_req_sim_auth(Wifi *wifi, GDBusMethodInvocation *context, GVariant *rand_data) { gboolean result = TRUE; + GArray *rand_data_garray; + GVariantIter *iter; + gint length; + guchar *out_auth_data; + guchar byte; + int i = 0; DBG("Request SIM Authentication"); g_return_val_if_fail(wifi != NULL, FALSE); - result = __netconfig_wifi_req_sim_auth((GArray *)rand_data, context); + g_variant_get(rand_data, "ay", &iter); + length = g_variant_iter_n_children(iter); + out_auth_data = g_new0(guchar, length); - if (result) + while (g_variant_iter_loop(iter, "y", &byte)) { + *(out_auth_data + i) = byte; + i++; + } + g_variant_iter_free(iter); + + rand_data_garray = g_array_sized_new(FALSE, FALSE, sizeof(guchar), length); + memcpy(rand_data_garray->data, out_auth_data, length); + g_free(out_auth_data); + rand_data_garray->len = length; + + result = __netconfig_wifi_req_sim_auth(rand_data_garray, context); + g_array_free(rand_data_garray, FALSE); + + if (result) { wifi_complete_req_sim_auth(wifi, context, result); + } return result; } -gboolean handle_req_aka_auth(Wifi *wifi, GDBusMethodInvocation *context, - const gchar *rand_data, const gchar *autn_data) +gboolean handle_req_aka_auth(Wifi *wifi, GDBusMethodInvocation *context, GVariant *rand_data, GVariant *autn_data) { - gboolean result = TRUE; + netconfig_error_e ret = NETCONFIG_NO_ERROR; + gboolean result = FALSE; + GVariantIter *iter; + gint length; + guchar *out_auth_data; + guchar byte; + int i = 0; GArray *rand_data_garray; GArray *autn_data_garray; - rand_data_garray = g_array_sized_new(FALSE, FALSE, sizeof(guchar), - strlen(rand_data)); - memcpy(rand_data_garray->data, rand_data, rand_data_garray->len); - - autn_data_garray = g_array_sized_new(FALSE, FALSE, sizeof(guchar), - strlen(autn_data)); - memcpy(autn_data_garray->data, rand_data, autn_data_garray->len); - DBG("Request AKA Authentication"); g_return_val_if_fail(wifi != NULL, FALSE); - result = __netconfig_wifi_req_aka_auth(rand_data_garray, autn_data_garray, context); - if (result) { + g_variant_get(rand_data, "ay", &iter); + length = g_variant_iter_n_children(iter); + out_auth_data = g_new0(guchar, length); + while (g_variant_iter_loop(iter, "y", &byte)) { + *(out_auth_data + i) = byte; + i++; + } + g_variant_iter_free(iter); + + rand_data_garray = g_array_sized_new(FALSE, FALSE, sizeof(guchar), length); + memcpy(rand_data_garray->data, out_auth_data, length); + g_free(out_auth_data); + rand_data_garray->len = length; + + i = 0; + g_variant_get(autn_data, "ay", &iter); + length = g_variant_iter_n_children(iter); + out_auth_data = g_new0(guchar, length); + while (g_variant_iter_loop(iter, "y", &byte)) { + *(out_auth_data + i) = byte; + i++; + } + g_variant_iter_free(iter); + + autn_data_garray = g_array_sized_new(FALSE, FALSE, sizeof(guchar), length); + memcpy(autn_data_garray->data, out_auth_data, length); + g_free(out_auth_data); + autn_data_garray->len = length; + + ret = __netconfig_wifi_req_aka_auth(rand_data_garray, autn_data_garray, context); + if (ret == NETCONFIG_NO_ERROR) { + result = TRUE; wifi_complete_req_aka_auth(wifi, context, result); + } else if (ret == NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM) { + netconfig_error_dbus_method_return(context, + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM, "FailReqSimAuthWrongParam"); } else { - netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_FAILED_REQ_AKA_AUTH, "FailReqAkaAuth"); + netconfig_error_dbus_method_return(context, + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH, "FailReqSimAuth"); } g_array_free(rand_data_garray, FALSE); diff --git a/src/wifi-firmware.c b/src/wifi-firmware.c index 12ee7bf..132b2fd 100755 --- a/src/wifi-firmware.c +++ b/src/wifi-firmware.c @@ -178,7 +178,7 @@ static int __netconfig_softap_firmware_stop(void) static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type) { - if (netconfig_emulator_is_emulated() == TRUE) + if (emulator_is_emulated() == TRUE) return -EIO; switch (type) { @@ -197,7 +197,7 @@ static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type) static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type) { - if (netconfig_emulator_is_emulated() == TRUE) + if (emulator_is_emulated() == TRUE) return -EIO; switch (type) { @@ -235,10 +235,8 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable) return -EALREADY; } else if (current_driver == alias) { #if defined WLAN_CHECK_POWERSAVE - if (type == NETCONFIG_WIFI_STA && - netconfig_wifi_is_powersave_mode() == TRUE) { + if (type == NETCONFIG_WIFI_STA && netconfig_wifi_is_powersave_mode() == TRUE) { netconfig_interface_down(WIFI_IFNAME); - return -EALREADY; } #endif @@ -254,9 +252,7 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable) return -EALREADY; } - if (type == NETCONFIG_WIFI_P2P && - netconfig_wifi_state_get_technology_state() > - NETCONFIG_WIFI_TECH_OFF) { + if (type == NETCONFIG_WIFI_P2P && wifi_state_get_technology_state() > NETCONFIG_WIFI_TECH_OFF) { netconfig_interface_down(WLAN_P2P_IFACE_NAME); return -EALREADY; @@ -277,8 +273,7 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable) if (current_driver > NETCONFIG_WIFI_OFF) { if (current_driver == alias) { #if defined WLAN_CHECK_POWERSAVE - if (type == NETCONFIG_WIFI_STA && - netconfig_wifi_is_powersave_mode() == TRUE) { + if (type == NETCONFIG_WIFI_STA && netconfig_wifi_is_powersave_mode() == TRUE) { netconfig_interface_up(WIFI_IFNAME); return -EALREADY; @@ -326,10 +321,16 @@ gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, co 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) { + wifi_firmware_complete_start(firmware, context); + return TRUE; + } else + netconfig_error_wifi_driver_failed(context); + } else netconfig_error_wifi_driver_failed(context); - wifi_firmware_complete_start(firmware, context); return FALSE; } @@ -358,10 +359,9 @@ gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, con else netconfig_error_wifi_driver_failed(context); - wifi_firmware_complete_start(firmware, context); return FALSE; } - wifi_firmware_complete_start(firmware, context); + wifi_firmware_complete_stop(firmware, context); return TRUE; } diff --git a/src/wifi-indicator.c b/src/wifi-indicator.c index 49cac00..6653d84 100755 --- a/src/wifi-indicator.c +++ b/src/wifi-indicator.c @@ -38,7 +38,11 @@ #define VCONFKEY_WIFI_SNR_MIN -89 -#define NETCONFIG_WIFI_INDICATOR_INTERVAL 1 +#if !defined TIZEN_WEARABLE +#define WIFI_INDICATOR_INTERVAL 1 +#else +#define WIFI_INDICATOR_INTERVAL 10 +#endif #if defined TIZEN_WEARABLE #define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 (19200 * 1024) @@ -272,8 +276,7 @@ static void __netconfig_wifi_update_indicator(void) } if (transfer_state != last_transfer_state) { - netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, - transfer_state); + netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, transfer_state); last_transfer_state = transfer_state; } @@ -310,13 +313,13 @@ static void __netconfig_wifi_update_indicator(void) } } -static gboolean __netconfig_wifi_indicator_monitor(gpointer data) +static gboolean __wifi_indicator_monitor(gpointer data) { int rssi_dbm = 0; int snr_level = 0; int pm_state = VCONFKEY_PM_STATE_NORMAL; - if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) return FALSE; /* In case of LCD off, we don't need to update Wi-Fi indicator */ @@ -339,12 +342,7 @@ void netconfig_wifi_indicator_start(void) INFO("Start Wi-Fi indicator"); netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, VCONFKEY_WIFI_STRENGTH_MAX); - - netconfig_start_timer_seconds( - NETCONFIG_WIFI_INDICATOR_INTERVAL, - __netconfig_wifi_indicator_monitor, - NULL, - &netconfig_wifi_indicator_timer); + netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL, __wifi_indicator_monitor, NULL, &netconfig_wifi_indicator_timer); } void netconfig_wifi_indicator_stop(void) diff --git a/src/wifi-passpoint.c b/src/wifi-passpoint.c old mode 100644 new mode 100755 diff --git a/src/wifi-power.c b/src/wifi-power.c index 1d2309d..c73e447 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -28,10 +28,6 @@ #include #endif -#if defined TIZEN_WEARABLE -#include -#endif - #include "log.h" #include "util.h" #include "netdbus.h" @@ -45,23 +41,28 @@ #include "wifi-firmware.h" #include "wifi-background-scan.h" + #define WLAN_SUPPLICANT_SCRIPT "/usr/sbin/wpa_supp.sh" #define P2P_SUPPLICANT_SCRIPT "/usr/sbin/p2p_supp.sh" -#define VCONF_WIFI_OFF_STATE_BY_AIRPLANE \ - "file/private/wifi/wifi_off_by_airplane" -#define VCONF_WIFI_OFF_STATE_BY_RESTRICTED \ - "file/private/wifi/wifi_off_by_restricted" -#define VCONF_WIFI_OFF_STATE_BY_EMERGENCY \ - "file/private/wifi/wifi_off_by_emergency" #if defined TIZEN_WEARABLE +#include static weconn_h weconn_handle = NULL; -#define VCONF_WIFI_WEARABLE_WIFI_USE "db/private/wifi/wearable_wifi_use" +#endif + +#define VCONF_WIFI_OFF_STATE_BY_AIRPLANE "file/private/wifi/wifi_off_by_airplane" +#define VCONF_WIFI_OFF_STATE_BY_RESTRICTED "file/private/wifi/wifi_off_by_restricted" +#define VCONF_WIFI_OFF_STATE_BY_EMERGENCY "file/private/wifi/wifi_off_by_emergency" +#if defined TIZEN_WEARABLE +#define VCONF_WIFI_WEARABLE_WIFI_USE "db/private/wifi/wearable_wifi_use" +#endif +#if !defined TIZEN_WEARABLE +#define VCONFKEY_SETAPPL_NETWORK_PERMIT_WITH_LCD_OFF_LIMIT "db/setting/network_with_lcd_off_limit" #endif #define WLAN_MAC_INFO "/opt/etc/.mac.info" #define WLAN_MAC_ADDR_MAX 20 -#define VCONF_WIFI_BSSID_ADDRESS "db/wifi/bssid_address" +#define VCONF_WIFI_BSSID_ADDRESS "db/wifi/bssid_address" #if defined TIZEN_TV #define ETH_MAC_ADDR_SIZE 6 @@ -74,8 +75,27 @@ static gboolean connman_wifi_technology_state = FALSE; static gboolean wifi_firmware_recovery_mode = FALSE; static int airplane_mode = 0; -static void __netconfig_wifi_technology_reply(GObject *source_object, - GAsyncResult *res, gpointer user_data) +#if defined TIZEN_WEARABLE +static int psmode_wifi_use = 1; +#endif + +static gboolean __is_wifi_restricted(void) +{ +#if defined TIZEN_WEARABLE + return FALSE; +#endif + int restricted_mode = 0; + + vconf_get_bool(VCONFKEY_SETAPPL_NETWORK_RESTRICT_MODE, &restricted_mode); + if (restricted_mode != 0) { + DBG("network restricted mode[%d]", restricted_mode); + return TRUE; + } + + return FALSE; +} + +static void __technology_reply(GObject *source_object, GAsyncResult *res, gpointer user_data) { GVariant *reply; GDBusConnection *conn = NULL; @@ -86,15 +106,12 @@ static void __netconfig_wifi_technology_reply(GObject *source_object, if (reply == NULL) { if (error != NULL) { - if (g_strcmp0(error->message, - CONNMAN_ERROR_INTERFACE ".AlreadyEnabled") == 0) { - netconfig_wifi_update_power_state(TRUE); - } else if (g_strcmp0(error->message, - CONNMAN_ERROR_INTERFACE ".AlreadyDisabled") == 0) { - netconfig_wifi_update_power_state(FALSE); + if (g_strcmp0(error->message, CONNMAN_ERROR_INTERFACE ".AlreadyEnabled") == 0) { + wifi_state_update_power_state(TRUE); + } else if (g_strcmp0(error->message, CONNMAN_ERROR_INTERFACE ".AlreadyDisabled") == 0) { + wifi_state_update_power_state(FALSE); } else { - ERR("Fail to request status [%d: %s]", - error->code, error->message); + ERR("Fail to request status [%d: %s]", error->code, error->message); } g_error_free(error); } else { @@ -108,64 +125,7 @@ static void __netconfig_wifi_technology_reply(GObject *source_object, netconfig_gdbus_pending_call_unref(); } -static gboolean __netconfig_is_wifi_restricted(void) -{ -#if defined TIZEN_WEARABLE - return FALSE; -#endif - int restricted_mode = 0; - - vconf_get_bool(VCONFKEY_SETAPPL_NETWORK_RESTRICT_MODE, &restricted_mode); - if (restricted_mode != 0) { - DBG("network restricted mode[%d]", restricted_mode); - return TRUE; - } - - return FALSE; -} - -static int __netconfig_wifi_connman_technology(gboolean enable) -{ - gboolean reply = FALSE; - GVariant *param0 = NULL; - GVariant *params = NULL; - char key[] = "Powered"; - gboolean value_enable = TRUE; - gboolean value_disable = FALSE; - - if (connman_wifi_technology_state == enable) - return -EALREADY; - - if (enable == TRUE) - param0 = g_variant_new_boolean(value_enable); - else - param0 = g_variant_new_boolean(value_disable); - - params = g_variant_new("(sv)",key, param0); - - reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, - CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, - "SetProperty", params, __netconfig_wifi_technology_reply); - - 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) - netconfig_wifi_state_set_technology_state(NETCONFIG_WIFI_TECH_WPS_ONLY); - - return 0; -} - -static int __netconfig_wifi_supplicant(gboolean enable) +static int __execute_supplicant(gboolean enable) { int rv = 0; const char *path = WLAN_SUPPLICANT_SCRIPT; @@ -191,6 +151,39 @@ static int __netconfig_wifi_supplicant(gboolean enable) return 0; } +static int _start_supplicant(void) +{ + GVariant *reply = NULL; + GVariant *params = NULL; + + params = g_variant_new("(ss)","wpasupplicant.service", "replace"); + + reply = netconfig_invoke_dbus_method("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnit", params); + if (reply == NULL) { + ERR("Fail to _start_supplicant"); + return -1; + } else { + g_variant_unref(reply); + } + + return 0; +} + +static int _stop_supplicant(void) +{ + GVariant *reply = NULL; + + reply = netconfig_invoke_dbus_method("fi.w1.wpa_supplicant1", "/fi/w1/wpa_supplicant1", "fi.w1.wpa_supplicant1", "Terminate", NULL); + if (reply == NULL) { + ERR("Fail to _stop_supplicant"); + return -1; + } else { + g_variant_unref(reply); + } + + return 0; +} + #if defined TIZEN_P2P_ENABLE && defined WLAN_CONCURRENT_MODE static int __netconfig_p2p_supplicant(gboolean enable) { @@ -219,12 +212,11 @@ void netconfig_wifi_recover_firmware(void) netconfig_wifi_bgscan_stop(); - netconfig_wifi_off(); + wifi_power_off(); } #if defined TIZEN_P2P_ENABLE && !defined WLAN_CONCURRENT_MODE -static void __netconfig_wifi_direct_state_cb(int error_code, - wifi_direct_device_state_e device_state, void *user_data) +static void __netconfig_wifi_direct_state_cb(int error_code, wifi_direct_device_state_e device_state, void *user_data) { int err; @@ -232,12 +224,12 @@ static void __netconfig_wifi_direct_state_cb(int error_code, wifi_direct_deinitialize(); if (device_state == WIFI_DIRECT_DEVICE_STATE_DEACTIVATED) { - err = netconfig_wifi_on(); + err = wifi_power_on(); if (err < 0) { if (err == -EALREADY) - netconfig_wifi_update_power_state(TRUE); + wifi_state_update_power_state(TRUE); else - netconfig_wifi_notify_power_failed(); + wifi_state_emit_power_failed(); } } } @@ -249,8 +241,7 @@ static gboolean __netconfig_wifi_direct_power_off(void) if (wifi_direct_initialize() < 0) return FALSE; - if (wifi_direct_set_device_state_changed_cb( - __netconfig_wifi_direct_state_cb, NULL) < 0) + if (wifi_direct_set_device_state_changed_cb(__netconfig_wifi_direct_state_cb, NULL) < 0) return FALSE; if (wifi_direct_deactivate() < 0) @@ -260,31 +251,31 @@ static gboolean __netconfig_wifi_direct_power_off(void) } #endif -static int __netconfig_wifi_try_to_load_driver_and_supplicant(void) +static int _load_driver_and_supplicant(void) { int err = 0; - enum netconfig_wifi_tech_state wifi_tech_state; + wifi_tech_state_e tech_state; - wifi_tech_state = netconfig_wifi_state_get_technology_state(); - if (wifi_tech_state > NETCONFIG_WIFI_TECH_OFF) + tech_state = wifi_state_get_technology_state(); + if (tech_state > NETCONFIG_WIFI_TECH_OFF) return -EALREADY; - err = __netconfig_wifi_supplicant(TRUE); + err = __execute_supplicant(TRUE); if (err < 0 && err != -EALREADY) return err; err = netconfig_wifi_firmware(NETCONFIG_WIFI_STA, TRUE); if (err < 0 && err != -EALREADY) { - __netconfig_wifi_supplicant(FALSE); + __execute_supplicant(FALSE); return err; } - netconfig_wifi_state_set_technology_state(NETCONFIG_WIFI_TECH_WPS_ONLY); + wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_WPS_ONLY); return 0; } -static int __netconfig_wifi_try_to_remove_driver_and_supplicant(void) +static int _remove_driver_and_supplicant(void) { int err = 0; @@ -298,14 +289,14 @@ static int __netconfig_wifi_try_to_remove_driver_and_supplicant(void) if (err < 0 && err != -EALREADY) return err; - err = __netconfig_wifi_supplicant(FALSE); + err = __execute_supplicant(FALSE); if (err < 0 && err != -EALREADY) return err; - netconfig_wifi_state_set_technology_state(NETCONFIG_WIFI_TECH_OFF); + wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_OFF); if (wifi_firmware_recovery_mode == TRUE) { - if (netconfig_wifi_on() < 0) + if (wifi_power_on() < 0) ERR("Failed to recover Wi-Fi firmware"); wifi_firmware_recovery_mode = FALSE; @@ -314,6 +305,47 @@ static int __netconfig_wifi_try_to_remove_driver_and_supplicant(void) return 0; } +static int _set_connman_technology_power(gboolean enable) +{ + gboolean reply = FALSE; + GVariant *param0 = NULL; + GVariant *params = NULL; + char key[] = "Powered"; + gboolean value_enable = TRUE; + gboolean value_disable = FALSE; + + if (connman_wifi_technology_state == enable) + return -EALREADY; + + if (enable == TRUE) + param0 = g_variant_new_boolean(value_enable); + else + param0 = g_variant_new_boolean(value_disable); + + params = g_variant_new("(sv)",key, param0); + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, + "SetProperty", params, __technology_reply); + + 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); + + return 0; +} + static void __netconfig_set_wifi_bssid(void) { int rv = 0; @@ -350,12 +382,12 @@ int netconfig_wifi_driver_and_supplicant(gboolean enable) * Simple code enables easy maintenance and reduces logical errors. */ if (enable == TRUE) - return __netconfig_wifi_try_to_load_driver_and_supplicant(); + return _load_driver_and_supplicant(); else { if (connman_wifi_technology_state == TRUE) return -ENOSYS; - return __netconfig_wifi_try_to_remove_driver_and_supplicant(); + return _load_driver_and_supplicant(); } } @@ -368,13 +400,13 @@ void netconfig_wifi_disable_technology_state_by_only_connman_signal(void) int netconfig_wifi_on(void) { int err = 0; - enum netconfig_wifi_tech_state wifi_tech_state; + wifi_tech_state_e wifi_tech_state; - wifi_tech_state = netconfig_wifi_state_get_technology_state(); + wifi_tech_state = wifi_state_get_technology_state(); if (wifi_tech_state >= NETCONFIG_WIFI_TECH_POWERED) return -EALREADY; - if (__netconfig_is_wifi_restricted() == TRUE) + if (__is_wifi_restricted() == TRUE) return -EPERM; if (netconfig_is_wifi_tethering_on() == TRUE) { @@ -395,11 +427,11 @@ int netconfig_wifi_on(void) } #endif - err = netconfig_wifi_driver_and_supplicant(TRUE); + err = wifi_power_driver_and_supplicant(TRUE); if (err < 0 && err != -EALREADY) return err; - err = __netconfig_wifi_connman_technology(TRUE); + err = _set_connman_technology_power(TRUE); __netconfig_set_wifi_bssid(); @@ -414,9 +446,9 @@ int netconfig_wifi_off(void) __netconfig_p2p_supplicant(FALSE); #endif - err = __netconfig_wifi_connman_technology(FALSE); + err = _set_connman_technology_power(FALSE); if (err == -EALREADY) - netconfig_wifi_update_power_state(FALSE); + wifi_state_update_power_state(FALSE); return 0; } @@ -430,7 +462,7 @@ int netconfig_wifi_on_wearable(gboolean device_picker_test) enum netconfig_wifi_tech_state wifi_tech_state; weconn_service_state_e weconn_state; - wifi_tech_state = netconfig_wifi_state_get_technology_state(); + wifi_tech_state = wifi_state_get_technology_state(); if (wifi_tech_state >= NETCONFIG_WIFI_TECH_POWERED) return -EALREADY; @@ -461,11 +493,11 @@ int netconfig_wifi_on_wearable(gboolean device_picker_test) return -EPERM; } - err = netconfig_wifi_driver_and_supplicant(TRUE); + err = wifi_power_driver_and_supplicant(TRUE); if (err < 0 && err != -EALREADY) return err; - err = __netconfig_wifi_connman_technology(TRUE); + err = _set_connman_technology_power(TRUE); if (device_picker_test == TRUE) netconfig_wifi_enable_device_picker_test(); @@ -473,28 +505,19 @@ int netconfig_wifi_on_wearable(gboolean device_picker_test) return err; } -static void __netconfig_wifi_wearable_weconn_service_state_changed_cb( - weconn_service_state_e state, void *user_data) +static void __weconn_service_state_changed_cb(weconn_service_state_e state, void *user_data) { - int wifi_state; - - if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state) < 0) { - ERR("Fail to get VCONFKEY_WIFI_STATE"); - return; - } - if (state == W_SERVICE_STATE_CONNECTED) { DBG("SAP is connected"); if (wifi_state > VCONFKEY_WIFI_OFF) - netconfig_wifi_off(); + wifi_power_off(); } else if (state == W_SERVICE_STATE_DISCONNECTED) { DBG("SAP is disconnected"); - netconfig_wifi_on_wearable(TRUE); + wifi_power_on_wearable(FALSE); } } -static int __netconfig_wifi_wearable_set_state_changed_cb(int service_type, - void *user_data) +static int _weconn_set_state_changed_cb(int service_type, void *user_data) { int ret; @@ -509,9 +532,7 @@ static int __netconfig_wifi_wearable_set_state_changed_cb(int service_type, return -1; } - ret = weconn_set_service_state_change_cb(weconn_handle, - __netconfig_wifi_wearable_weconn_service_state_changed_cb, - service_type, user_data); + ret = weconn_set_service_state_change_cb(weconn_handle, __weconn_service_state_changed_cb, service_type, user_data); if (ret < 0) { ERR("Failed weconn_set_service_state_change_cb(%d)", ret); return -1; @@ -520,11 +541,10 @@ static int __netconfig_wifi_wearable_set_state_changed_cb(int service_type, return 0; } -static void __netconfig_wifi_wearable_wifi_use_mode(keynode_t* node, - void* user_data) +static void __wearable_wifi_use_changed_cb(keynode_t* node, void* user_data) { int wifi_state; - int wifi_use; + int wifi_use = 1; gboolean wifi_restrict = FALSE; if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state) < 0) { @@ -550,16 +570,16 @@ static void __netconfig_wifi_wearable_wifi_use_mode(keynode_t* node, netconfig_set_vconf_int(VCONF_WIFI_WEARABLE_WIFI_USE, 0); wc_launch_syspopup(WC_POPUP_TYPE_WIFI_RESTRICT); } else { - netconfig_wifi_on_wearable(TRUE); + wifi_power_on_wearable(TRUE); } } else { - DBG("wifi use off"); + ERR("## wifi use [OFF]"); if (wifi_state == VCONFKEY_WIFI_OFF) { WARN("Wi-Fi is already turned off"); return; } - netconfig_wifi_off(); + wifi_power_off(); } } @@ -637,7 +657,7 @@ static void __netconfig_wifi_airplane_mode(keynode_t *node, void *user_data) if (wifi_state == VCONFKEY_WIFI_OFF) return; - netconfig_wifi_off(); + wifi_power_off(); netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 1); } else { @@ -650,13 +670,11 @@ static void __netconfig_wifi_airplane_mode(keynode_t *node, void *user_data) if (wifi_state > VCONFKEY_WIFI_OFF) return; - netconfig_wifi_on(); + wifi_power_on(); } } #endif -#endif -#if !defined TIZEN_WEARABLE static void __netconfig_wifi_restrict_mode(keynode_t *node, void *user_data) { int wifi_state = 0, restricted = 0; @@ -680,7 +698,7 @@ static void __netconfig_wifi_restrict_mode(keynode_t *node, void *user_data) if (wifi_state == VCONFKEY_WIFI_OFF) return; - netconfig_wifi_off(); + wifi_power_off(); netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_RESTRICTED, 1); } else { @@ -693,21 +711,23 @@ static void __netconfig_wifi_restrict_mode(keynode_t *node, void *user_data) if (wifi_state > VCONFKEY_WIFI_OFF) return; - netconfig_wifi_on(); + wifi_power_on(); } } #endif -static void __netconfig_wifi_emergency_mode(keynode_t *node, void *user_data) +static void __emergency_mode_changed_cb(keynode_t *node, void *user_data) { int wifi_state = 0, emergency = 0; int wifi_off_by_emergency = 0; #if !defined TIZEN_WEARABLE int emergency_by_fmm = 0; #endif +#if defined TIZEN_WEARABLE + int wifi_use = 1; +#endif vconf_get_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, &wifi_off_by_emergency); - vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); #if !defined TIZEN_WEARABLE @@ -723,31 +743,35 @@ static void __netconfig_wifi_emergency_mode(keynode_t *node, void *user_data) 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("Wi-Fi state %d, Wi-Fi was off by emergency mode %s", wifi_state, wifi_off_by_emergency ? "Yes" : "No"); #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 */ + vconf_get_int(VCONF_WIFI_WEARABLE_WIFI_USE, &wifi_use); + psmode_wifi_use = wifi_use; + if (wifi_use != 0) { + netconfig_set_vconf_int(VCONF_WIFI_WEARABLE_WIFI_USE, 0); + } + if (wifi_state == VCONFKEY_WIFI_OFF) return; - netconfig_wifi_off(); - + wifi_power_off(); netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 1); } else { /* power saving mode off */ + netconfig_set_vconf_int(VCONF_WIFI_WEARABLE_WIFI_USE, psmode_wifi_use); if (!wifi_off_by_emergency) return; netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 0); - if (wifi_state > VCONFKEY_WIFI_OFF) return; - netconfig_wifi_on_wearable(TRUE); + wifi_power_on_wearable(TRUE); } #else if (emergency > SETTING_PSMODE_POWERFUL) { @@ -755,7 +779,7 @@ static void __netconfig_wifi_emergency_mode(keynode_t *node, void *user_data) if (wifi_state == VCONFKEY_WIFI_OFF) return; - netconfig_wifi_off(); + wifi_power_off(); netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 1); } else { @@ -768,13 +792,13 @@ static void __netconfig_wifi_emergency_mode(keynode_t *node, void *user_data) if (wifi_state > VCONFKEY_WIFI_OFF) return; - netconfig_wifi_on(); + wifi_power_on(); } #endif } -static void __netconfig_wifi_pm_state_mode(keynode_t* node, void* user_data) +static void __pm_state_changed_cb(keynode_t* node, void* user_data) { int new_state = -1; int wifi_state = 0; @@ -799,8 +823,7 @@ static void __netconfig_wifi_pm_state_mode(keynode_t* node, void* user_data) DBG("wifi state: %d (0 off / 1 on / 2 connected)", wifi_state); DBG("Old PM state: %d, current: %d", prev_state, new_state); - if ((new_state == VCONFKEY_PM_STATE_NORMAL) && - (prev_state >= VCONFKEY_PM_STATE_LCDOFF)) { + if ((new_state == VCONFKEY_PM_STATE_NORMAL) && (prev_state >= VCONFKEY_PM_STATE_LCDOFF)) { netconfig_wifi_bgscan_stop(); netconfig_wifi_bgscan_start(TRUE); } @@ -817,9 +840,9 @@ static void _tapi_noti_sim_status_cb(TapiHandle *handle, const char *noti_id, if (*status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { DBG("Turn Wi-Fi on automatically"); #if defined TIZEN_WEARABLE - netconfig_wifi_on_wearable(TRUE); + wifi_power_on_wearable(TRUE); #else - netconfig_wifi_on(); + wifi_power_on(); #endif netconfig_tel_deinit(); } @@ -828,14 +851,18 @@ static void _tapi_noti_sim_status_cb(TapiHandle *handle, const char *noti_id, static gboolean netconfig_tapi_check_sim_state(void) { int ret, card_changed; - TelSimCardStatus_t status; + TelSimCardStatus_t status = TAPI_SIM_STATUS_UNKNOWN; TapiHandle *tapi_handle = NULL; tapi_handle = (TapiHandle *)netconfig_tel_init(); + if (tapi_handle == NULL) { + ERR("Failed to tapi init"); + return FALSE; + } ret = tel_get_sim_init_info(tapi_handle, &status, &card_changed); if (ret != TAPI_API_SUCCESS) { - ERR("tel_get_sim_init_info() Failed"); + ERR("tel_get_sim_init_info() Failed : [%d]", ret); netconfig_tel_deinit(); return FALSE; } @@ -868,16 +895,16 @@ static gboolean netconfig_tapi_check_sim_state(void) return TRUE; } -static void __netconfig_tapi_state_changed_cb(keynode_t * node, void *data) +static void __netconfig_telephony_ready_changed_cb(keynode_t * node, void *data) { - int tapi_state = 0; + int telephony_ready = 0; if (node != NULL) - tapi_state = vconf_keynode_get_int(node); + telephony_ready = vconf_keynode_get_bool(node); else - vconf_get_bool(VCONFKEY_TELEPHONY_READY, &tapi_state); + vconf_get_bool(VCONFKEY_TELEPHONY_READY, &telephony_ready); - if (tapi_state != FALSE) { + if (telephony_ready != 0) { if (netconfig_tapi_check_sim_state() == FALSE) { DBG("Sim is not initialized yet."); @@ -889,18 +916,145 @@ static void __netconfig_tapi_state_changed_cb(keynode_t * node, void *data) DBG("Turn Wi-Fi on automatically"); #if defined TIZEN_WEARABLE - netconfig_wifi_on_wearable(TRUE); + wifi_power_on_wearable(TRUE); #else - netconfig_wifi_on(); + wifi_power_on(); #endif done: - vconf_ignore_key_changed(VCONFKEY_TELEPHONY_READY, - __netconfig_tapi_state_changed_cb); + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_READY, __netconfig_telephony_ready_changed_cb); +} +#endif + +int wifi_power_driver_and_supplicant(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. + * It probably breaks ConnMan technology operation. + * + * 2. Do not remove driver and wpa_supplicant if ConnMan already enabled. + * It breaks ConnMan technology operation. + * + * 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(); + } else { + if (connman_wifi_technology_state == TRUE) + return -ENOSYS; + + return _remove_driver_and_supplicant(); + } +} + +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) +{ + wifi_firmware_recovery_mode = TRUE; + + netconfig_wifi_bgscan_stop(); + + wifi_power_off(); } + +int wifi_power_on(void) +{ + int err = 0; + wifi_tech_state_e tech_state; + + tech_state = wifi_state_get_technology_state(); + if (tech_state >= NETCONFIG_WIFI_TECH_POWERED) + return -EALREADY; + + if (__is_wifi_restricted() == TRUE) + return -EPERM; + + if (netconfig_is_wifi_tethering_on() == TRUE) { + /* TODO: Wi-Fi tethering turns off here */ + /* return TRUE; */ + ERR("Failed to turn tethering off"); + return -EBUSY; + } + +#if defined TIZEN_P2P_ENABLE && !defined WLAN_CONCURRENT_MODE + if (netconfig_is_wifi_direct_on() == TRUE) { + if (__netconfig_wifi_direct_power_off() == TRUE) + return -EINPROGRESS; + else { + ERR("Failed to turn Wi-Fi direct off"); + return -EBUSY; + } + } #endif -void netconfig_wifi_power_initialize(void) + err = wifi_power_driver_and_supplicant(TRUE); + if (err < 0 && err != -EALREADY) + return err; + + err = _set_connman_technology_power(TRUE); + + return err; +} + +int wifi_power_off(void) +{ + int err; + + err = _set_connman_technology_power(FALSE); + if (err == -EALREADY) + wifi_state_update_power_state(FALSE); + + return 0; +} + +#if defined TIZEN_WEARABLE +int wifi_power_on_wearable(gboolean device_picker_test) +{ + int err = 0; + int wifi_use = 1; + wifi_tech_state_e tech_state; + weconn_service_state_e weconn_state; + + tech_state = wifi_state_get_technology_state(); + if (tech_state >= NETCONFIG_WIFI_TECH_POWERED) + return -EALREADY; + + err = weconn_get_service_state(weconn_handle, W_SERVICE_TYPE_BT, &weconn_state); + if (err == 0 && weconn_state == W_SERVICE_STATE_CONNECTED) { + WARN("Not permitted Wi-Fi on"); + return -EPERM; + } + + if (vconf_get_int(VCONF_WIFI_WEARABLE_WIFI_USE, &wifi_use) < 0) { + ERR("Fail to get VCONF_WIFI_WEARABLE_WIFI_USE"); + return -EIO; + } + + if (wifi_use == 0) { + WARN("VCONF_WIFI_WEARABLE_WIFI_USE is OFF"); + 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; +} +#endif + +void wifi_power_initialize(void) { int wifi_last_power_state = 0; @@ -912,29 +1066,29 @@ void netconfig_wifi_power_initialize(void) /* Update the last Wi-Fi power state */ vconf_get_int(VCONF_WIFI_LAST_POWER_STATE, &wifi_last_power_state); - if (wifi_last_power_state > VCONFKEY_WIFI_OFF && airplane_mode == 0) { + if (wifi_last_power_state > VCONFKEY_WIFI_OFF) { #if defined TIZEN_TELEPHONY_ENABLE - int tapi_state = 0; - vconf_get_bool(VCONFKEY_TELEPHONY_READY, &tapi_state); - if (tapi_state == FALSE) { - DBG("Telephony API is not initialized yet"); - vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY, - __netconfig_tapi_state_changed_cb, NULL); + int telephony_ready = 0; + 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); - goto done; - } else { - if (netconfig_tapi_check_sim_state() == FALSE) { - DBG("SIM is not initialized yet"); + goto done; + } else { + if (netconfig_tapi_check_sim_state() == FALSE) { + DBG("SIM is not initialized yet"); - goto done; - } + goto done; } + } #endif DBG("Turn Wi-Fi on automatically"); #if defined TIZEN_WEARABLE - netconfig_wifi_on_wearable(TRUE); + wifi_power_on_wearable(TRUE); #else - netconfig_wifi_on(); + wifi_power_on(); #endif } @@ -943,10 +1097,8 @@ done: #endif #if defined TIZEN_WEARABLE - __netconfig_wifi_wearable_set_state_changed_cb(W_SERVICE_TYPE_BT, NULL); - - vconf_notify_key_changed(VCONF_WIFI_WEARABLE_WIFI_USE, - __netconfig_wifi_wearable_wifi_use_mode, NULL); + _weconn_set_state_changed_cb(W_SERVICE_TYPE_BT, NULL); + vconf_notify_key_changed(VCONF_WIFI_WEARABLE_WIFI_USE, __wearable_wifi_use_changed_cb, NULL); #if defined TIZEN_TELEPHONY_ENABLE vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, @@ -961,14 +1113,11 @@ done: #endif #endif - vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, - __netconfig_wifi_emergency_mode, NULL); - - vconf_notify_key_changed(VCONFKEY_PM_STATE, - __netconfig_wifi_pm_state_mode, 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); } -void netconfig_wifi_power_deinitialize(void) +void wifi_power_deinitialize(void) { } @@ -982,9 +1131,9 @@ gboolean handle_load_driver(Wifi *wifi, g_return_val_if_fail(wifi != NULL, FALSE); #if defined TIZEN_WEARABLE - err = netconfig_wifi_on_wearable(device_picker_test); + err = wifi_power_on_wearable(device_picker_test); #else - err = netconfig_wifi_on(); + err = wifi_power_on(); if (device_picker_test == TRUE) netconfig_wifi_enable_device_picker_test(); @@ -999,11 +1148,12 @@ gboolean handle_load_driver(Wifi *wifi, else netconfig_error_wifi_driver_failed(context); - return FALSE; + return TRUE; } netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); + __netconfig_set_wifi_bssid(); wifi_complete_load_driver(wifi, context); return TRUE; @@ -1017,7 +1167,7 @@ gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context) g_return_val_if_fail(wifi != NULL, FALSE); - err = netconfig_wifi_off(); + err = wifi_power_off(); if (err < 0) { if (err == -EINPROGRESS) netconfig_error_inprogress(context); @@ -1027,7 +1177,7 @@ gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context) netconfig_error_permission_denied(context); else netconfig_error_wifi_driver_failed(context); - return FALSE; + return TRUE; } netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); @@ -1038,32 +1188,7 @@ gboolean handle_remove_driver(Wifi *wifi, GDBusMethodInvocation *context) gboolean handle_load_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context) { - int err = 0; - - DBG("P2P power on requested"); - - g_return_val_if_fail(wifi != NULL, FALSE); - -#if defined TIZEN_WEARABLE - err = netconfig_wifi_on_wearable(FALSE); -#else - err = netconfig_wifi_on(); -#endif - if (err < 0) - if (err != -EINPROGRESS && err != -EALREADY) { - netconfig_error_inprogress(context); - return FALSE; - } - - netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); - -#if defined TIZEN_P2P_ENABLE && defined WLAN_CONCURRENT_MODE - err = __netconfig_p2p_supplicant(TRUE); - if (err < 0) { - netconfig_error_wifi_direct_failed(context); - return FALSE; - } -#endif + ERR("Deprecated"); wifi_complete_load_p2p_driver(wifi, context); return TRUE; @@ -1071,21 +1196,7 @@ gboolean handle_load_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context) gboolean handle_remove_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context) { -#if defined TIZEN_P2P_ENABLE && defined WLAN_CONCURRENT_MODE - int err = 0; -#endif - - DBG("P2P power off requested"); - - g_return_val_if_fail(wifi != NULL, FALSE); - -#if defined TIZEN_P2P_ENABLE && defined WLAN_CONCURRENT_MODE - err = __netconfig_p2p_supplicant(FALSE); - if (err < 0) { - netconfig_error_wifi_direct_failed(context);; - return FALSE; - } -#endif + ERR("Deprecated"); wifi_complete_remove_p2p_driver(wifi, context); return TRUE; diff --git a/src/wifi-ssid-scan.c b/src/wifi-ssid-scan.c old mode 100644 new mode 100755 index 166feb3..390fe1b --- a/src/wifi-ssid-scan.c +++ b/src/wifi-ssid-scan.c @@ -25,54 +25,100 @@ #include "wifi-ssid-scan.h" #include "wifi-background-scan.h" -enum netconfig_wifi_security { +typedef enum { WIFI_SECURITY_UNKNOWN = 0x00, WIFI_SECURITY_NONE = 0x01, WIFI_SECURITY_WEP = 0x02, WIFI_SECURITY_PSK = 0x03, WIFI_SECURITY_IEEE8021X = 0x04, -}; +} wifi_security_e; -struct bss_info_t { +typedef struct { unsigned char ssid[33]; - enum netconfig_wifi_security security; + wifi_security_e security; gboolean privacy; gboolean wps; -}; +} bss_info_t; -static gboolean wifi_ssid_scan_state = FALSE; -static GSList *wifi_bss_info_list = NULL; -static guint netconfig_wifi_ssid_scan_timer = 0; +static gboolean g_ssid_scan_state = FALSE; +static GSList *bss_info_list = NULL; +static guint ssid_scan_timer = 0; static char *g_ssid = NULL; -static gboolean __netconfig_wifi_ssid_scan_timeout(gpointer data) +static void __check_security(const char *str_keymgmt, bss_info_t *bss_info) { - netconfig_wifi_notify_ssid_scan_done(); + INFO("keymgmt : %s", str_keymgmt); + + if (g_strcmp0(str_keymgmt, "ieee8021x") == 0) { + bss_info->security = WIFI_SECURITY_IEEE8021X; + } else if (g_strcmp0(str_keymgmt, "wpa-psk") == 0) { + bss_info->security = WIFI_SECURITY_PSK; + } else if (g_strcmp0(str_keymgmt, "wpa-psk-sha256") == 0) { + bss_info->security = WIFI_SECURITY_PSK; + } else if (g_strcmp0(str_keymgmt, "wpa-ft-psk") == 0) { + bss_info->security = WIFI_SECURITY_PSK; + } else if (g_strcmp0(str_keymgmt, "wpa-ft-eap") == 0) { + bss_info->security = WIFI_SECURITY_IEEE8021X; + } else if (g_strcmp0(str_keymgmt, "wpa-eap") == 0) { + bss_info->security = WIFI_SECURITY_IEEE8021X; + } else if (g_strcmp0(str_keymgmt, "wpa-eap-sha256") == 0) { + bss_info->security = WIFI_SECURITY_IEEE8021X; + } else if (g_strcmp0(str_keymgmt, "wps") == 0) { + bss_info->wps = TRUE; + } +} + +static gboolean __ssid_scan_timeout(gpointer data) +{ + wifi_ssid_scan_emit_scan_completed(); return FALSE; } -static void __netconfig_wifi_ssid_scan_started(void) +static void _start_ssid_scan_timer(void) { INFO("Wi-Fi SSID scan started"); - wifi_ssid_scan_state = TRUE; + g_ssid_scan_state = TRUE; - netconfig_start_timer_seconds(5, - __netconfig_wifi_ssid_scan_timeout, - NULL, - &netconfig_wifi_ssid_scan_timer); + netconfig_start_timer_seconds(5, __ssid_scan_timeout, NULL, &ssid_scan_timer); } -static void __netconfig_wifi_ssid_scan_finished(void) +static void _stop_ssid_scan_timer(void) { INFO("Wi-Fi SSID scan finished"); - wifi_ssid_scan_state = FALSE; + g_ssid_scan_state = FALSE; - netconfig_stop_timer(&netconfig_wifi_ssid_scan_timer); + netconfig_stop_timer(&ssid_scan_timer); } -static gboolean __netconfig_wifi_invoke_ssid_scan( - const char *object_path, const char *ssid) +static void _parse_keymgmt_message(GVariant *param, bss_info_t *bss_info) +{ + GVariantIter *iter1; + GVariant *var; + gchar *key; + + g_variant_get(param, "a{sv}", &iter1); + while (g_variant_iter_loop(iter1, "{sv}", &key, &var)) { + if (g_strcmp0(key, "KeyMgmt") == 0) {//check this :iterate + GVariantIter *iter2; + g_variant_get(var, "as", &iter2); + char *str; + while (g_variant_iter_loop(iter2, "s", &str)) { + if (str == NULL) { + break; + } + __check_security(str, bss_info); + } + g_variant_iter_free (iter2); + } + } + + g_variant_iter_free (iter1); + + return; +} + +static gboolean _request_ssid_scan(const char *object_path, const char *ssid) { /* TODO: Revise following code */ @@ -89,7 +135,7 @@ static gboolean __netconfig_wifi_invoke_ssid_scan( const gchar *key2 = "SSIDs"; int i = 0; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { DBG("Failed to get GDBusconnection"); return FALSE; @@ -124,7 +170,7 @@ static gboolean __netconfig_wifi_invoke_ssid_scan( NULL, G_DBUS_CALL_FLAGS_NONE, NETCONFIG_DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), &error); if (reply == NULL) { @@ -149,7 +195,7 @@ static gboolean __netconfig_wifi_invoke_ssid_scan( return TRUE; } -static void __netconfig_wifi_notify_ssid_scan_done(void) +static void _emit_ssid_scan_completed(void) { GVariantBuilder *builder = NULL; GSList* list = NULL; @@ -158,32 +204,28 @@ static void __netconfig_wifi_notify_ssid_scan_done(void) const char *prop_wps = "wps"; builder = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}")); - for (list = wifi_bss_info_list; list != NULL; list = list->next) { - struct bss_info_t *bss_info = (struct bss_info_t *)list->data; + for (list = bss_info_list; list != NULL; list = list->next) { + bss_info_t *bss_info = (bss_info_t *)list->data; if (bss_info && g_strcmp0((char *)bss_info->ssid, g_ssid) == 0) { const gchar *ssid = (char *)bss_info->ssid; - enum netconfig_wifi_security security = bss_info->security; + wifi_security_e security = bss_info->security; gboolean wps = bss_info->wps; DBG("BSS found; SSID:%s security:%d WPS:%d", ssid, security, wps); - - /* SSID */ - g_variant_builder_add(builder, "{sv}", prop_ssid, g_variant_new("(s)", ssid)); - /* Security */ + g_variant_builder_add(builder, "{sv}", prop_ssid, g_variant_new_string(ssid)); g_variant_builder_add(builder, "{sv}", prop_security, g_variant_new_int32(security)); /* WPS */ g_variant_builder_add(builder, "{sv}", prop_wps, g_variant_new_boolean(wps)); } } - wifi_emit_specific_scan_completed((Wifi *)get_netconfig_wifi_object(), - g_variant_builder_end(builder)); + wifi_emit_specific_scan_completed((Wifi *)get_wifi_object(), g_variant_builder_end(builder)); if (builder) g_variant_builder_unref(builder); - if (wifi_bss_info_list != NULL) { - g_slist_free_full(wifi_bss_info_list, g_free); - wifi_bss_info_list = NULL; + if (bss_info_list != NULL) { + g_slist_free_full(bss_info_list, g_free); + bss_info_list = NULL; } if (g_ssid != NULL) { @@ -196,80 +238,82 @@ static void __netconfig_wifi_notify_ssid_scan_done(void) return; } -static void __netconfig_wifi_check_security(const char *str_keymgmt, struct bss_info_t *bss_data) +gboolean wifi_ssid_scan(const char *ssid) { - INFO("keymgmt : %s", str_keymgmt); + const char *if_path; + static char *scan_ssid = NULL; + + netconfig_wifi_bgscan_stop(); - if (strcmp(str_keymgmt, "ieee8021x") == 0) { - bss_data->security = WIFI_SECURITY_IEEE8021X; - } else if (strcmp(str_keymgmt, "wpa-psk") == 0) { - bss_data->security = WIFI_SECURITY_PSK; - } else if (strcmp(str_keymgmt, "wpa-psk-sha256") == 0) { - bss_data->security = WIFI_SECURITY_PSK; - } else if (strcmp(str_keymgmt, "wpa-ft-psk") == 0) { - bss_data->security = WIFI_SECURITY_PSK; - } else if (strcmp(str_keymgmt, "wpa-ft-eap") == 0) { - bss_data->security = WIFI_SECURITY_IEEE8021X; - } else if (strcmp(str_keymgmt, "wpa-eap") == 0) { - bss_data->security = WIFI_SECURITY_IEEE8021X; - } else if (strcmp(str_keymgmt, "wpa-eap-sha256") == 0) { - bss_data->security = WIFI_SECURITY_IEEE8021X; - } else if (strcmp(str_keymgmt, "wps") == 0) { - bss_data->wps = TRUE; + if (ssid != NULL) { + if (scan_ssid != NULL) { + g_free(scan_ssid); + } + scan_ssid = g_strdup(ssid); } -} -static void __netconfig_wifi_parse_keymgmt_message(GVariant *param, struct bss_info_t *bss_data) -{ - GVariantIter *iter1; - GVariant *var; - gchar *key; + if (scan_ssid == NULL) + goto error; - g_variant_get(param, "a{sv}", &iter1); - while (g_variant_iter_loop(iter1, "{sv}", &key, &var)) { - if (g_strcmp0(key, "KeyMgmt") == 0) {//check this :iterate - GVariantIter *iter2; - g_variant_get(var, "as", &iter2); - char *str; - while (g_variant_iter_loop(iter2, "s", &str)) { - if (str == NULL) { - break; - } - __netconfig_wifi_check_security(str, bss_data); - } - g_variant_iter_free (iter2); - } + if_path = netconfig_wifi_get_supplicant_interface(); + if (if_path == NULL) { + DBG("Fail to get wpa_supplicant DBus path"); + goto error; } - g_variant_iter_free (iter1); + if (netconfig_wifi_get_scanning() == TRUE) { + DBG("Wi-Fi scan in progress, %s scan will be delayed", scan_ssid); + g_free(scan_ssid); + return TRUE; + } - return; + if (bss_info_list) { + g_slist_free_full(bss_info_list, g_free); + bss_info_list = NULL; + } + + INFO("Start Wi-Fi scan with %s(%d)", scan_ssid, strlen(scan_ssid)); + if (_request_ssid_scan(if_path, (const char *)scan_ssid) == TRUE) { + _start_ssid_scan_timer(); + g_free(scan_ssid); + scan_ssid = NULL; + return TRUE; + } + +error: + if (scan_ssid != NULL) { + g_free(scan_ssid); + scan_ssid = NULL; + } + + netconfig_wifi_bgscan_start(FALSE); + + return FALSE; } -gboolean netconfig_wifi_get_ssid_scan_state(void) +gboolean wifi_ssid_scan_get_state(void) { - return wifi_ssid_scan_state; + return g_ssid_scan_state; } -void netconfig_wifi_notify_ssid_scan_done(void) +void wifi_ssid_scan_emit_scan_completed(void) { - if (netconfig_wifi_get_ssid_scan_state() != TRUE) + if (g_ssid_scan_state != TRUE) return; - __netconfig_wifi_ssid_scan_finished(); - - __netconfig_wifi_notify_ssid_scan_done(); + _stop_ssid_scan_timer(); + _emit_ssid_scan_completed(); } -void netconfig_wifi_bss_added(GVariant *message) +void wifi_ssid_scan_add_bss(GVariant *message) { GVariantIter *iter; GVariant *value; - const gchar *path = NULL; - const gchar *key; - struct bss_info_t *bss_info; + gchar *path = NULL; + gchar *key; + bss_info_t *bss_info; - if (netconfig_wifi_get_ssid_scan_state() != TRUE) + if (g_ssid_scan_state != TRUE) return; INFO("NEW BSS added"); @@ -279,11 +323,10 @@ void netconfig_wifi_bss_added(GVariant *message) return; } - if (path != NULL) INFO("Object path of BSS added is %s",path); - bss_info = g_try_new0(struct bss_info_t, 1); + bss_info = g_try_new0(bss_info_t, 1); if (bss_info == NULL) return; @@ -293,7 +336,7 @@ void netconfig_wifi_bss_added(GVariant *message) const guchar *ssid; gsize ssid_len; ssid = g_variant_get_fixed_array(value, &ssid_len, sizeof(guchar)); - if (ssid_len > 0 && ssid_len < 33) + if (ssid != NULL && ssid_len > 0 && ssid_len < 33) memcpy(bss_info->ssid, ssid, ssid_len); else memset(bss_info->ssid, 0, sizeof(bss_info->ssid)); @@ -302,7 +345,7 @@ void netconfig_wifi_bss_added(GVariant *message) privacy = g_variant_get_boolean(value); bss_info->privacy = privacy; } else if ((g_strcmp0(key, "RSN") == 0) || (g_strcmp0(key, "WPA") == 0)) { - __netconfig_wifi_parse_keymgmt_message(value, bss_info); + _parse_keymgmt_message(value, bss_info); } else if (g_strcmp0(key, "IEs") == 0) { const guchar *ie; gsize ie_len; @@ -312,6 +355,8 @@ void netconfig_wifi_bss_added(GVariant *message) } g_variant_iter_free(iter); + if (path) + g_free(path); if (bss_info->ssid[0] == '\0') { g_free(bss_info); @@ -325,61 +370,7 @@ void netconfig_wifi_bss_added(GVariant *message) bss_info->security = WIFI_SECURITY_NONE; } - wifi_bss_info_list = g_slist_append(wifi_bss_info_list, bss_info); -} - -gboolean netconfig_wifi_ssid_scan(const char *ssid) -{ - const char *if_path; - static char *scan_ssid = NULL; - - netconfig_wifi_bgscan_stop(); - - if (ssid != NULL) { - g_free(scan_ssid); - scan_ssid = g_strdup(ssid); - } - - if (scan_ssid == NULL) - goto error; - - if_path = netconfig_wifi_get_supplicant_interface(); - if (if_path == NULL) { - DBG("Fail to get wpa_supplicant DBus path"); - goto error; - } - - if (netconfig_wifi_get_scanning() == TRUE) { - DBG("Wi-Fi scan in progress, %s scan will be delayed", scan_ssid); - g_free(scan_ssid); - return TRUE; - } - - if (wifi_bss_info_list) { - g_slist_free_full(wifi_bss_info_list, g_free); - wifi_bss_info_list = NULL; - } - - INFO("Start Wi-Fi scan with %s(%d)", scan_ssid, strlen(scan_ssid)); - if (__netconfig_wifi_invoke_ssid_scan(if_path, - (const char *)scan_ssid) == TRUE) { - __netconfig_wifi_ssid_scan_started(); - - g_free(scan_ssid); - scan_ssid = NULL; - - return TRUE; - } - -error: - if (scan_ssid != NULL) { - g_free(scan_ssid); - scan_ssid = NULL; - } - - netconfig_wifi_bgscan_start(FALSE); - - return FALSE; + bss_info_list = g_slist_append(bss_info_list, bss_info); } gboolean handle_request_specific_scan(Wifi *wifi, @@ -390,7 +381,7 @@ gboolean handle_request_specific_scan(Wifi *wifi, g_return_val_if_fail(wifi != NULL, FALSE); g_return_val_if_fail(ssid != NULL, FALSE); - result = netconfig_wifi_ssid_scan((const char *)ssid); + result = wifi_ssid_scan((const char *)ssid); if (result != TRUE) { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSpecificScan"); diff --git a/src/wifi-state.c b/src/wifi-state.c index 1c671e9..01ac8bf 100755 --- a/src/wifi-state.c +++ b/src/wifi-state.c @@ -40,10 +40,8 @@ static gboolean new_bss_found = FALSE; static guint network_noti_timer_id = 0; -static enum netconfig_wifi_service_state - wifi_service_state = NETCONFIG_WIFI_UNKNOWN; -static enum netconfig_wifi_tech_state - wifi_technology_state = NETCONFIG_WIFI_TECH_UNKNOWN; +static wifi_service_state_e g_service_state = NETCONFIG_WIFI_UNKNOWN; +static wifi_tech_state_e g_tech_state = NETCONFIG_WIFI_TECH_UNKNOWN; static GSList *notifier_list = NULL; @@ -68,22 +66,12 @@ static void __netconfig_pop_wifi_connected_poppup(const char *ssid) bundle_free(b); } -static void __netconfig_wifi_state_connected_activation(void) -{ - /* Add activation of services when Wi-Fi is connected */ - bundle *b = NULL; - - b = bundle_create(); - aul_launch_app("com.samsung.keepit-service-standby", b); - bundle_free(b); -} - -static void __netconfig_wifi_set_essid(void) +static void __set_wifi_connected_essid(void) { const char *essid_name = NULL; const char *wifi_profile = netconfig_get_default_profile(); - if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) return; if (wifi_profile == NULL || @@ -99,16 +87,39 @@ static void __netconfig_wifi_set_essid(void) } netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name); - __netconfig_pop_wifi_connected_poppup(essid_name); } -static void __netconfig_wifi_unset_essid(void) +static void __unset_wifi_connected_essid(void) { netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, ""); } -static gboolean __netconfig_is_wifi_profile_available(void) +static const char *__get_wifi_connected_essid(void) +{ + const char *essid_name = NULL; + const char *wifi_profile = NULL; + + if (wifi_state_get_service_state() != 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; + } + + essid_name = netconfig_wifi_get_connected_essid(wifi_profile); + if (essid_name == NULL) { + ERR("Can't get Wi-Fi name"); + return NULL; + } + + return essid_name; +} + +static gboolean __is_wifi_profile_available(void) { GVariant *message = NULL; GVariantIter *iter, *next; @@ -140,7 +151,7 @@ static gboolean __netconfig_is_wifi_profile_available(void) return TRUE; } -static gboolean __netconfig_wifi_is_favorited(GVariantIter *array) +static gboolean __is_favorited(GVariantIter *array) { gboolean is_favorite = FALSE; gchar *key; @@ -164,7 +175,89 @@ static gboolean __netconfig_wifi_is_favorited(GVariantIter *array) return is_favorite; } -static char *__netconfig_wifi_get_connman_favorite_service(void) +static void _wifi_state_connected_activation(void) +{ + /* Add activation of services when Wi-Fi is connected */ + bundle *b = NULL; + + b = bundle_create(); + aul_launch_app("com.samsung.keepit-service-standby", b); + bundle_free(b); +} + +static void _wifi_state_changed(wifi_service_state_e state) +{ + GSList *list; + + for (list = notifier_list; list; list = list->next) { + wifi_state_notifier *notifier = list->data; + + if (notifier->wifi_state_changed != NULL) + notifier->wifi_state_changed(state, notifier->user_data); + } +} + +static void _set_bss_found(gboolean found) +{ + if (found != new_bss_found) + new_bss_found = found; +} + +static gboolean _check_network_notification(gpointer data) +{ + int qs_enable = 0, ug_state = 0; + static gboolean check_again = FALSE; + + wifi_tech_state_e tech_state; + wifi_service_state_e service_state; + + tech_state = wifi_state_get_technology_state(); + 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(); + if (service_state == NETCONFIG_WIFI_CONNECTED) { + DBG("Service state is connected"); + goto cleanup; + } else if (service_state == NETCONFIG_WIFI_ASSOCIATION || + service_state == NETCONFIG_WIFI_CONFIGURATION) { + DBG("Service state is connecting (check again : %d)", check_again); + if (!check_again) { + check_again = TRUE; + return TRUE; + } else + check_again = FALSE; + } + + if (__is_wifi_profile_available() == FALSE) { + netconfig_send_notification_to_net_popup( + NETCONFIG_DEL_FOUND_AP_NOTI, NULL); + goto cleanup; + } + + vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable); + if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) { + DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE"); + goto cleanup; + } + + vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state); + if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) { + goto cleanup; + } + + netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL); + + _set_bss_found(FALSE); + +cleanup: + netconfig_stop_timer(&network_noti_timer_id); + return FALSE; +} + +static char *_get_connman_favorite_service(void) { char *favorite_service = NULL; GVariant *message = NULL; @@ -185,7 +278,7 @@ static char *__netconfig_wifi_get_connman_favorite_service(void) continue; } - if (__netconfig_wifi_is_favorited(next) == TRUE) { + if (__is_favorited(next) == TRUE) { favorite_service = g_strdup(obj); g_free(obj); g_variant_iter_free(next); @@ -199,31 +292,36 @@ static char *__netconfig_wifi_get_connman_favorite_service(void) return favorite_service; } -static void __netconfig_wifi_state_changed( - enum netconfig_wifi_service_state state) +static void __notification_value_changed_cb(keynode_t *node, void *user_data) { - GSList *list; + int value = -1; - for (list = notifier_list; list; list = list->next) { - struct netconfig_wifi_state_notifier *notifier = list->data; + if (vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0) { + return; + } - if (notifier->netconfig_wifi_state_changed != NULL) - notifier->netconfig_wifi_state_changed(state, notifier->user_data); + if (value == VCONFKEY_WIFI_QS_DISABLE) { + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL); } } -void netconfig_wifi_set_bss_found(const gboolean found) +static void _register_network_notification(void) { - if (found != new_bss_found) - new_bss_found = found; +#if defined TIZEN_WEARABLE + return; +#endif + vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb, NULL); } -gboolean netconfig_wifi_is_bss_found(void) +static void _deregister_network_notification(void) { - return new_bss_found; +#if defined TIZEN_WEARABLE + return; +#endif + vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb); } -static void __netconfig_wifi_state_set_power_save(gboolean power_save) +static void _set_power_save(gboolean power_save) { gboolean result; const char *if_path; @@ -260,7 +358,7 @@ static void __netconfig_wifi_state_set_power_save(gboolean power_save) return; } -static void __netconfig_wifi_state_set_power_lock(gboolean power_lock) +static void _set_power_lock(gboolean power_lock) { gint32 ret = 0; GVariant *reply; @@ -309,31 +407,153 @@ static void __netconfig_wifi_state_set_power_lock(gboolean power_lock) else old_state = power_lock; + g_variant_unref(reply); + return; } -void netconfig_wifi_state_set_service_state( - enum netconfig_wifi_service_state new_state) +void wifi_state_emit_power_completed(gboolean power_on) +{ + if (power_on) + wifi_emit_power_on_completed((Wifi *)get_wifi_object()); + else + wifi_emit_power_off_completed((Wifi *)get_wifi_object()); + + DBG("Successfully sent signal [%s]",(power_on)?"powerOn":"powerOff"); +} + +void wifi_state_emit_power_failed(void) +{ + wifi_emit_power_operation_failed((Wifi *)get_wifi_object()); + + DBG("Successfully sent signal [PowerOperationFailed]"); +} + +void wifi_state_update_power_state(gboolean powered) +{ + wifi_tech_state_e tech_state; + + /* It's automatically updated by signal-handler + * DO NOT update manually + * It includes Wi-Fi state configuration + */ + tech_state = wifi_state_get_technology_state(); + + 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_emit_power_completed(TRUE); + + 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); + + netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON); + + netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_start(TRUE); + + /* Add callback to track change in notification setting */ + _register_network_notification(); + } + } 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); + + netconfig_wifi_device_picker_service_stop(); + + wifi_power_disable_technology_state_by_only_connman_signal(); + wifi_power_driver_and_supplicant(FALSE); + + wifi_state_emit_power_completed(FALSE); + + 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); + + netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_OFF); + + netconfig_wifi_set_bgscan_pause(FALSE); + netconfig_wifi_bgscan_stop(); + + _set_bss_found(FALSE); + + /* Inform net-popup to remove the wifi found notification */ + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL); + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL); + + _deregister_network_notification(); + } +} + +char *wifi_get_favorite_service(void) +{ + return _get_connman_favorite_service(); +} + +void wifi_start_timer_network_notification(void) +{ +#if defined TIZEN_WEARABLE + /* In case of wearable device, no need to notify available Wi-Fi APs */ + return ; +#endif + netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT, _check_network_notification, NULL, &network_noti_timer_id); +} + +void wifi_state_notifier_register(wifi_state_notifier *notifier) +{ + DBG("register notifier"); + + notifier_list = g_slist_append(notifier_list, notifier); +} + +void wifi_state_notifier_unregister(wifi_state_notifier *notifier) +{ + DBG("un-register notifier"); + + notifier_list = g_slist_remove_all(notifier_list, notifier); +} + +void wifi_state_notifier_cleanup(void) +{ + g_slist_free_full(notifier_list, NULL); +} + +void wifi_state_set_bss_found(gboolean found) +{ + _set_bss_found(found); +} + +gboolean wifi_state_is_bss_found(void) +{ + return new_bss_found; +} + +void wifi_state_set_service_state(wifi_service_state_e new_state) { static gboolean dhcp_stage = FALSE; - enum netconfig_wifi_service_state old_state = wifi_service_state; + wifi_service_state_e old_state = g_service_state; if (old_state == new_state) return; - wifi_service_state = new_state; + g_service_state = new_state; DBG("Wi-Fi state %d ==> %d", old_state, new_state); /* During DHCP, temporarily disable Wi-Fi power saving */ - if ((old_state < NETCONFIG_WIFI_ASSOCIATION || - old_state == NETCONFIG_WIFI_FAILURE) && - new_state == NETCONFIG_WIFI_CONFIGURATION) { - __netconfig_wifi_state_set_power_lock(TRUE); - __netconfig_wifi_state_set_power_save(FALSE); + if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_CONFIGURATION) { + _set_power_lock(TRUE); + _set_power_save(FALSE); dhcp_stage = TRUE; } else if (dhcp_stage == TRUE) { - __netconfig_wifi_state_set_power_lock(FALSE); - __netconfig_wifi_state_set_power_save(TRUE); + _set_power_lock(FALSE); + _set_power_save(TRUE); dhcp_stage = FALSE; } @@ -341,22 +561,20 @@ void netconfig_wifi_state_set_service_state( 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); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED); netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_CONNECTED); - __netconfig_wifi_set_essid(); + __set_wifi_connected_essid(); netconfig_wifi_indicator_start(); } else if (old_state == NETCONFIG_WIFI_CONNECTED) { netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL); - __netconfig_wifi_unset_essid(); + __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); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON); @@ -366,8 +584,7 @@ void netconfig_wifi_state_set_service_state( netconfig_wifi_bgscan_stop(); netconfig_wifi_bgscan_start(TRUE); - } else if ( (old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) - && new_state == NETCONFIG_WIFI_IDLE){ + } 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_set_bgscan_pause(FALSE); @@ -376,47 +593,45 @@ void netconfig_wifi_state_set_service_state( netconfig_wifi_bgscan_start(TRUE); } - __netconfig_wifi_state_changed(new_state); + _wifi_state_changed(new_state); if (new_state == NETCONFIG_WIFI_CONNECTED){ - __netconfig_wifi_state_connected_activation(); + _wifi_state_connected_activation(); #if defined TIZEN_WEARABLE wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED); #endif } } -enum netconfig_wifi_service_state -netconfig_wifi_state_get_service_state(void) +wifi_service_state_e wifi_state_get_service_state(void) { - return wifi_service_state; + return g_service_state; } -void netconfig_wifi_state_set_technology_state( - enum netconfig_wifi_tech_state new_state) +void wifi_state_set_tech_state(wifi_tech_state_e new_state) { - enum netconfig_wifi_tech_state old_state = wifi_technology_state; + wifi_tech_state_e old_state = g_tech_state; if (old_state == new_state) return; - wifi_technology_state = new_state; + g_tech_state = new_state; DBG("Wi-Fi technology state %d ==> %d", old_state, new_state); } -enum netconfig_wifi_tech_state netconfig_wifi_state_get_technology_state(void) +wifi_tech_state_e wifi_state_get_technology_state(void) { GVariant *message = NULL, *variant; GVariantIter *iter, *next; - enum netconfig_wifi_tech_state ret = NETCONFIG_WIFI_TECH_OFF; + wifi_tech_state_e ret = NETCONFIG_WIFI_TECH_OFF; gboolean wifi_tech_powered = FALSE; gboolean wifi_tech_connected = FALSE; const char *path; gchar *key; - if (wifi_technology_state > NETCONFIG_WIFI_TECH_UNKNOWN) - return wifi_technology_state; + if (g_tech_state > NETCONFIG_WIFI_TECH_UNKNOWN) + return g_tech_state; message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, @@ -465,218 +680,61 @@ enum netconfig_wifi_tech_state netconfig_wifi_state_get_technology_state(void) if (wifi_tech_connected == TRUE) ret = NETCONFIG_WIFI_TECH_CONNECTED; - wifi_technology_state = ret; - - return wifi_technology_state; -} - -void netconfig_wifi_notify_power_failed(void) -{ - wifi_emit_power_operation_failed((Wifi *)get_netconfig_wifi_object()); - - DBG("Successfully sent signal [PowerOperationFailed]"); -} - -void netconfig_wifi_notify_power_completed(gboolean power_on) -{ - if (power_on) - wifi_emit_power_on_completed((Wifi *)get_netconfig_wifi_object()); - else - wifi_emit_power_off_completed((Wifi *)get_netconfig_wifi_object()); - - DBG("Successfully sent signal [%s]",(power_on)?"powerOn":"powerOff"); -} - -static void __netconfig_notification_value_changed_cb( - keynode_t *node, void *user_data) -{ - int value = -1; - - if (vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0) { - return; - } + g_tech_state = ret; - if (value == VCONFKEY_WIFI_QS_DISABLE) { - netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, - NULL); - } + return g_tech_state; } -static void __netconfig_register_network_notification(void) +void wifi_state_set_connected_essid(void) { + __set_wifi_connected_essid(); #if defined TIZEN_WEARABLE - return; + wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED); #endif - vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, - __netconfig_notification_value_changed_cb, NULL); } -static void __netconfig_deregister_network_notification(void) +void wifi_state_get_connected_essid(gchar **essid) { -#if defined TIZEN_WEARABLE - return; -#endif - vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, - __netconfig_notification_value_changed_cb); + *essid = g_strdup(__get_wifi_connected_essid()); } -void netconfig_wifi_update_power_state(gboolean powered) -{ - enum netconfig_wifi_tech_state wifi_tech_state; - - /* It's automatically updated by signal-handler - * DO NOT update manually - * It includes Wi-Fi state configuration - */ - wifi_tech_state = netconfig_wifi_state_get_technology_state(); - - if (powered == TRUE) { - if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED && - netconfig_is_wifi_tethering_on() != TRUE) { - DBG("Wi-Fi turned on or waken up from power-save mode"); - - netconfig_wifi_state_set_technology_state( - NETCONFIG_WIFI_TECH_POWERED); - - netconfig_wifi_notify_power_completed(TRUE); - - 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); - - netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON); - - netconfig_wifi_bgscan_stop(); - netconfig_wifi_bgscan_start(TRUE); - - /* Add callback to track change in notification setting */ - __netconfig_register_network_notification(); - } - } else if (wifi_tech_state > NETCONFIG_WIFI_TECH_OFF) { - DBG("Wi-Fi turned off or in power-save mode"); - - netconfig_wifi_state_set_technology_state( - NETCONFIG_WIFI_TECH_WPS_ONLY); - - netconfig_wifi_device_picker_service_stop(); - - netconfig_wifi_disable_technology_state_by_only_connman_signal(); - netconfig_wifi_driver_and_supplicant(FALSE); - - netconfig_wifi_notify_power_completed(FALSE); - - 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); - - netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_OFF); - - netconfig_wifi_set_bgscan_pause(FALSE); - netconfig_wifi_bgscan_stop(); - - netconfig_wifi_set_bss_found(FALSE); - - /* Inform net-popup to remove the wifi found notification */ - netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL); - netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL); - - __netconfig_deregister_network_notification(); - - } -} - -char *netconfig_wifi_get_favorite_service(void) -{ - return __netconfig_wifi_get_connman_favorite_service(); -} - -static gboolean __netconfig_wifi_check_network_notification(gpointer data) +/* 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 + */ +gboolean handle_get_wifi_state(Wifi *wifi, GDBusMethodInvocation *context) { - int qs_enable = 0, ug_state = 0; - static gboolean check_again = FALSE; - - enum netconfig_wifi_tech_state wifi_tech_state; - enum netconfig_wifi_service_state wifi_service_state; - - wifi_tech_state = netconfig_wifi_state_get_technology_state(); - if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED) { - DBG("Wi-Fi off or WPS only supported[%d]", wifi_tech_state); - goto cleanup; - } - - wifi_service_state = netconfig_wifi_state_get_service_state(); - if (wifi_service_state == NETCONFIG_WIFI_CONNECTED) { - DBG("Service state is connected"); - goto cleanup; - } else if (wifi_service_state == NETCONFIG_WIFI_ASSOCIATION || - wifi_service_state == NETCONFIG_WIFI_CONFIGURATION) { - DBG("Service state is connecting (check again : %d)", check_again); - if (!check_again) { - check_again = TRUE; - return TRUE; - } else - check_again = FALSE; - } - - if (__netconfig_is_wifi_profile_available() == FALSE) { - netconfig_send_notification_to_net_popup( - NETCONFIG_DEL_FOUND_AP_NOTI, NULL); - goto cleanup; - } - - vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable); - if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) { - DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE"); - goto cleanup; - } - - vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state); - if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) { - goto cleanup; + g_return_val_if_fail(wifi != NULL, FALSE); + wifi_service_state_e state = NETCONFIG_WIFI_UNKNOWN; + gint wifi_state = 0; + state = wifi_state_get_service_state(); + + switch (state) { + case NETCONFIG_WIFI_FAILURE: + wifi_state = -1; + break; + case NETCONFIG_WIFI_UNKNOWN: + case NETCONFIG_WIFI_IDLE: + wifi_state = 0; + break; + case NETCONFIG_WIFI_ASSOCIATION: + wifi_state = 1; + break; + case NETCONFIG_WIFI_CONFIGURATION: + wifi_state = 2; + break; + case NETCONFIG_WIFI_CONNECTED: + wifi_state = 3; + break; + default: + wifi_state = 0; } - netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL); - - netconfig_wifi_set_bss_found(FALSE); - -cleanup: - netconfig_stop_timer(&network_noti_timer_id); - return FALSE; -} - -void netconfig_wifi_start_timer_network_notification(void) -{ -#if defined TIZEN_WEARABLE - /* In case of wearable device, no need to notify available Wi-Fi APs */ - return ; -#endif - netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT, - __netconfig_wifi_check_network_notification, NULL, &network_noti_timer_id); -} + g_dbus_method_invocation_return_value(context, g_variant_new("(i)", wifi_state)); -void netconfig_wifi_state_notifier_cleanup(void) -{ - g_slist_free_full(notifier_list, NULL); -} - -void netconfig_wifi_state_notifier_register( - struct netconfig_wifi_state_notifier *notifier) -{ - DBG("register notifier"); - - notifier_list = g_slist_append(notifier_list, notifier); -} - -void netconfig_wifi_state_notifier_unregister( - struct netconfig_wifi_state_notifier *notifier) -{ - DBG("un-register notifier"); - - notifier_list = g_slist_remove_all(notifier_list, notifier); + return TRUE; } diff --git a/src/wifi-tel-intf.c b/src/wifi-tel-intf.c old mode 100644 new mode 100755 diff --git a/src/wifi-wps.c b/src/wifi-wps.c index c28dfcd..3de9452 100755 --- a/src/wifi-wps.c +++ b/src/wifi-wps.c @@ -107,8 +107,7 @@ static void __netconfig_wifi_wps_notify_scan_done(void)//check this } } - wifi_emit_wps_scan_completed((Wifi *)get_netconfig_wifi_object(), - g_variant_builder_end(builder)); + wifi_emit_wps_scan_completed((Wifi *)get_wifi_object(), g_variant_builder_end(builder)); g_variant_builder_unref(builder); if (wps_bss_info_list != NULL) { @@ -161,7 +160,7 @@ static void __netconfig_wifi_wps_get_bss_info_result( gsize ssid_len; ssid = g_variant_get_fixed_array(value, &ssid_len, sizeof(guchar)); - if (ssid_len > 0 && ssid_len <= NETCONFIG_SSID_LEN) { + if (ssid != NULL && ssid_len > 0 && ssid_len <= NETCONFIG_SSID_LEN) { memcpy(bss_info->ssid, ssid, ssid_len); bss_info->ssid_len = ssid_len; } else { @@ -169,7 +168,7 @@ static void __netconfig_wifi_wps_get_bss_info_result( bss_info->ssid_len = 0; } } else if (g_strcmp0(key, "Mode") == 0) { - const gchar *mode = NULL; + gchar *mode = NULL; g_variant_get(value, "s", &mode); if (mode == NULL) @@ -181,6 +180,7 @@ static void __netconfig_wifi_wps_get_bss_info_result( bss_info->mode = 2; else bss_info->mode = 0; + g_free(mode); } } else if (g_strcmp0(key, "Signal") == 0) { gint16 signal; @@ -208,7 +208,7 @@ done: __netconfig_wifi_wps_notify_scan_done(); if (netconfig_is_wps_scan_aborted == FALSE) - netconfig_wifi_driver_and_supplicant(FALSE); + wifi_power_driver_and_supplicant(FALSE); } } @@ -279,7 +279,7 @@ done: __netconfig_wifi_wps_notify_scan_done(); if (netconfig_is_wps_scan_aborted == FALSE) - netconfig_wifi_driver_and_supplicant(FALSE); + wifi_power_driver_and_supplicant(FALSE); } } @@ -346,9 +346,9 @@ static int __netconfig_wifi_wps_request_scan(const char *if_path) return -ESRCH; } - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { - DBG("Failed to get GDBusconnection"); + ERR("Failed to get GDBusconnection"); return -EIO; } @@ -366,10 +366,12 @@ static int __netconfig_wifi_wps_request_scan(const char *if_path) NULL, G_DBUS_CALL_FLAGS_NONE, NETCONFIG_WPS_DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), NULL, NULL); + netconfig_is_device_scanning = TRUE; + g_variant_unref(message); /* Clear bss_info_list for the next scan result */ if (wps_bss_info_list) { @@ -386,7 +388,7 @@ static void __netconfig_wifi_interface_create_result( GObject *source_object, GAsyncResult *res, gpointer user_data) { GVariant *message; - const char *path = NULL; + gchar *path = NULL; GDBusConnection *conn = NULL; GError *error = NULL; @@ -396,14 +398,17 @@ static void __netconfig_wifi_interface_create_result( if (error == NULL) { g_variant_get(message, "(o)", &path); - if (path) + if (path) { __netconfig_wifi_wps_request_scan(path); + g_free(path); + } } else { - DBG("Failed to create interface, Error: %d[%s]", error->code, error->message); + ERR("Failed to create interface, Error: %d[%s]", error->code, error->message); + __netconfig_wps_set_mode(FALSE); + wifi_power_driver_and_supplicant(FALSE); } g_variant_unref(message); - netconfig_gdbus_pending_call_unref(); } static int __netconfig_wifi_wps_create_interface(void) @@ -414,7 +419,7 @@ static int __netconfig_wifi_wps_create_interface(void) const char *key = "Ifname"; const char *val = WIFI_IFNAME; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); if (connection == NULL) { DBG("Failed to get GDBusconnection"); return -EIO; @@ -433,11 +438,10 @@ static int __netconfig_wifi_wps_create_interface(void) NULL, G_DBUS_CALL_FLAGS_NONE, NETCONFIG_WPS_DBUS_REPLY_TIMEOUT, - netconfig_gdbus_get_gdbus_cancellable(), + netdbus_get_cancellable(), (GAsyncReadyCallback) __netconfig_wifi_interface_create_result, NULL); - netconfig_gdbus_pending_call_ref(); g_variant_unref(message); return 0; @@ -446,14 +450,14 @@ static int __netconfig_wifi_wps_create_interface(void) static int __netconfig_wifi_wps_scan(void) { int err = 0; - enum netconfig_wifi_tech_state wifi_tech_state; + wifi_tech_state_e wifi_tech_state; if (netconfig_is_device_scanning == TRUE) return -EINPROGRESS; - wifi_tech_state = netconfig_wifi_state_get_technology_state(); + wifi_tech_state = wifi_state_get_technology_state(); if (wifi_tech_state <= NETCONFIG_WIFI_TECH_OFF) - err = netconfig_wifi_driver_and_supplicant(TRUE); + err = wifi_power_driver_and_supplicant(TRUE); if (err < 0 && err != -EALREADY) return err; @@ -479,7 +483,7 @@ static int __netconfig_wifi_wps_scan(void) gboolean handle_request_wps_scan(Wifi *wifi, GDBusMethodInvocation *context) { int err, enabled = 0; - enum netconfig_wifi_tech_state wifi_tech_state; + wifi_tech_state_e tech_state; g_return_val_if_fail(wifi != NULL, FALSE); @@ -497,11 +501,14 @@ gboolean handle_request_wps_scan(Wifi *wifi, GDBusMethodInvocation *context) } #endif - wifi_tech_state = netconfig_wifi_state_get_technology_state(); - if (wifi_tech_state <= NETCONFIG_WIFI_TECH_OFF) { + tech_state = wifi_state_get_technology_state(); + if (tech_state <= NETCONFIG_WIFI_TECH_OFF) { #if !defined TIZEN_WEARABLE vconf_get_int(VCONF_WIFI_ALWAYS_ALLOW_SCANNING, &enabled); +#else + enabled = 0; #endif + if (enabled == 0) { netconfig_error_permission_denied(context); return FALSE; diff --git a/src/wifi.c b/src/wifi.c index 5353849..2effe8b 100755 --- a/src/wifi.c +++ b/src/wifi.c @@ -30,6 +30,7 @@ #include "wifi-eap.h" #include "wifi-wps.h" #include "wifi-power.h" +#include "wifi-state.h" #include "wifi-agent.h" #include "wifi-firmware.h" #include "wifi-ssid-scan.h" @@ -38,12 +39,12 @@ #include "wifi-background-scan.h" #include "wifi-config.h" -static Wifi *netconfigwifi = NULL; -static NetConnmanAgent *netconnmanagent = NULL; -static WifiFirmware *netconfigwififirmware = NULL; +static Wifi *wifi_object = NULL; +static NetConnmanAgent *connman_agent_object = NULL; +static WifiFirmware *wififirmware_object = NULL; -Wifi *get_netconfig_wifi_object(void){ - return netconfigwifi; +Wifi *get_wifi_object(void){ + return wifi_object; } static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *context, @@ -55,133 +56,164 @@ static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *conte return TRUE; } -void netconfig_wifi_create_and_init(void) +static void _set_wifi_mac_address(void) +{ + gchar *mac_addr = NULL; + + mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS); + if (mac_addr != NULL) { + if (strlen(mac_addr) == 0) + netconfig_set_mac_address_from_file(); + g_free(mac_addr); + } +} + +void wifi_object_create_and_init(void) { DBG("Create wifi object."); - GDBusInterfaceSkeleton *interface = NULL; - GDBusConnection *connection; - GDBusObjectManagerServer *server = netconfig_get_wifi_manager(); + GDBusInterfaceSkeleton *interface_wifi = NULL; + GDBusInterfaceSkeleton *interface_connman_agent = NULL; + GDBusInterfaceSkeleton *interface_wifi_firmware = NULL; + GDBusConnection *connection = NULL; + GDBusObjectManagerServer *server = netdbus_get_wifi_manager(); if (server == NULL) return; - connection = netconfig_gdbus_get_connection(); + connection = netdbus_get_connection(); g_dbus_object_manager_server_set_connection(server, connection); - /*Interface*/ - netconfigwifi = wifi_skeleton_new(); - interface = G_DBUS_INTERFACE_SKELETON(netconfigwifi); + /*Interface netconfig.wifi*/ + wifi_object = wifi_skeleton_new(); + interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object); // WIFI power - g_signal_connect(netconfigwifi, "handle-load-driver", + g_signal_connect(wifi_object, "handle-load-driver", G_CALLBACK(handle_load_driver), NULL); - g_signal_connect(netconfigwifi, "handle-remove-driver", + g_signal_connect(wifi_object, "handle-remove-driver", G_CALLBACK(handle_remove_driver), NULL); - g_signal_connect(netconfigwifi, "handle-load-p2p-driver", + g_signal_connect(wifi_object, "handle-load-p2p-driver", G_CALLBACK(handle_load_p2p_driver), NULL); - g_signal_connect(netconfigwifi, "handle-remove-p2p-driver", + 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(netconfigwifi, "handle-request-specific-scan", + g_signal_connect(wifi_object, "handle-request-specific-scan", G_CALLBACK(handle_request_specific_scan), NULL); - g_signal_connect(netconfigwifi, "handle-request-wps-scan", + g_signal_connect(wifi_object, "handle-request-wps-scan", G_CALLBACK(handle_request_wps_scan), NULL); // WIFI direct - g_signal_connect(netconfigwifi, "handle-launch-direct", + g_signal_connect(wifi_object, "handle-launch-direct", G_CALLBACK(handle_launch_direct), NULL); // EAP config - g_signal_connect(netconfigwifi, "handle-create-eap-config", + g_signal_connect(wifi_object, "handle-create-eap-config", G_CALLBACK(handle_create_eap_config), NULL); - g_signal_connect(netconfigwifi, "handle-delete-eap-config", + g_signal_connect(wifi_object, "handle-delete-eap-config", G_CALLBACK(handle_delete_eap_config), NULL); // WIFI configuration - g_signal_connect(netconfigwifi, "handle-save-configuration", + g_signal_connect(wifi_object, "handle-save-configuration", G_CALLBACK(handle_save_configuration), NULL); - g_signal_connect(netconfigwifi, "handle-remove-configuration", + g_signal_connect(wifi_object, "handle-remove-configuration", G_CALLBACK(handle_remove_configuration), NULL); - g_signal_connect(netconfigwifi, "handle-get-config-ids", + g_signal_connect(wifi_object, "handle-get-config-ids", G_CALLBACK(handle_get_config_ids), NULL); - g_signal_connect(netconfigwifi, "handle-load-configuration", + g_signal_connect(wifi_object, "handle-load-configuration", G_CALLBACK(handle_load_configuration), NULL); - g_signal_connect(netconfigwifi, "handle-set-config-field", + g_signal_connect(wifi_object, "handle-set-config-field", G_CALLBACK(handle_set_config_field), NULL); + g_signal_connect(wifi_object, "handle-get-config-passphrase", + G_CALLBACK(handle_get_config_passphrase), NULL); + // WIFI EAP configuration + g_signal_connect(wifi_object, "handle-save-eap-configuration", + G_CALLBACK(handle_save_eap_configuration), NULL); + g_signal_connect(wifi_object, "handle-load-eap-configuration", + G_CALLBACK(handle_load_eap_configuration), NULL); // BG scan mode - g_signal_connect(netconfigwifi, "handle-set-bgscan", + g_signal_connect(wifi_object, "handle-set-bgscan", G_CALLBACK(handle_set_bgscan), NULL); - g_signal_connect(netconfigwifi, "handle-resume-bgscan", + g_signal_connect(wifi_object, "handle-resume-bgscan", G_CALLBACK(handle_resume_bgscan), NULL); - g_signal_connect(netconfigwifi, "handle-pause-bgscan", + g_signal_connect(wifi_object, "handle-pause-bgscan", G_CALLBACK(handle_pause_bgscan), NULL); // Passpoint - g_signal_connect(netconfigwifi, "handle-set-passpoint", + g_signal_connect(wifi_object, "handle-set-passpoint", G_CALLBACK(handle_set_passpoint), NULL); - g_signal_connect(netconfigwifi, "handle-get-passpoint", + g_signal_connect(wifi_object, "handle-get-passpoint", G_CALLBACK(handle_get_passpoint), NULL); // EAP authentication - g_signal_connect(netconfigwifi, "handle-get-aka-auth", + g_signal_connect(wifi_object, "handle-get-aka-auth", G_CALLBACK(handle_get_aka_auth), NULL); - g_signal_connect(netconfigwifi, "handle-get-sim-auth", + g_signal_connect(wifi_object, "handle-get-sim-auth", G_CALLBACK(handle_get_sim_auth), NULL); - g_signal_connect(netconfigwifi, "handle-get-sim-imsi", + g_signal_connect(wifi_object, "handle-get-sim-imsi", G_CALLBACK(handle_get_sim_imsi), NULL); - g_signal_connect(netconfigwifi, "handle-req-aka-auth", + g_signal_connect(wifi_object, "handle-req-aka-auth", G_CALLBACK(handle_req_aka_auth), NULL); - g_signal_connect(netconfigwifi, "handle-req-sim-auth", + g_signal_connect(wifi_object, "handle-req-sim-auth", G_CALLBACK(handle_req_sim_auth), NULL); // WIFI MDM blacklist - g_signal_connect(netconfigwifi, "handle-check-black-list", + g_signal_connect(wifi_object, "handle-check-black-list", G_CALLBACK(handle_check_black_list), NULL); - if (!g_dbus_interface_skeleton_export(interface, connection, + if (!g_dbus_interface_skeleton_export(interface_wifi, connection, NETCONFIG_WIFI_PATH, NULL)) { ERR("Export WIFI_PATH for wifi failed"); } - interface = NULL; + /*Interface connman.Agent*/ + connman_agent_object = net_connman_agent_skeleton_new(); - /*Interface 2*/ - netconnmanagent = net_connman_agent_skeleton_new(); - - interface = G_DBUS_INTERFACE_SKELETON(netconnmanagent); - g_signal_connect(netconnmanagent, "handle-report-error", + interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object); + g_signal_connect(connman_agent_object, "handle-report-error", G_CALLBACK(handle_report_error), NULL); - g_signal_connect(netconnmanagent, "handle-request-browser", + g_signal_connect(connman_agent_object, "handle-request-browser", G_CALLBACK(handle_request_browser), NULL); - g_signal_connect(netconnmanagent, "handle-request-input", + g_signal_connect(connman_agent_object, "handle-request-input", G_CALLBACK(handle_request_input), NULL); - g_signal_connect(netconnmanagent, "handle-set-field", + g_signal_connect(connman_agent_object, "handle-set-field", G_CALLBACK(handle_set_field), NULL); - if (!g_dbus_interface_skeleton_export(interface, connection, + if (!g_dbus_interface_skeleton_export(interface_connman_agent, connection, NETCONFIG_WIFI_PATH, NULL)) { ERR("Export WIFI_PATH for agent failed"); } - interface = NULL; - - /*Interface 3*/ - netconfigwififirmware = wifi_firmware_skeleton_new(); + /*Interface netconfig.wifi.Firmware*/ + wififirmware_object = wifi_firmware_skeleton_new(); - interface = G_DBUS_INTERFACE_SKELETON(netconfigwififirmware); - g_signal_connect(netconfigwififirmware, "handle-start", + interface_wifi_firmware = G_DBUS_INTERFACE_SKELETON(wififirmware_object); + g_signal_connect(wififirmware_object, "handle-start", G_CALLBACK(handle_start), NULL); - g_signal_connect(netconfigwififirmware, "handle-stop", + g_signal_connect(wififirmware_object, "handle-stop", G_CALLBACK(handle_stop), NULL); - if (!g_dbus_interface_skeleton_export(interface, connection, + if (!g_dbus_interface_skeleton_export(interface_wifi_firmware, connection, NETCONFIG_WIFI_PATH, NULL)) { ERR("Export WIFI_PATH for firmware failed"); } - netconfig_wifi_power_initialize(); + _set_wifi_mac_address(); + + wifi_power_initialize(); return; } +void wifi_object_deinit(void) +{ + g_object_unref(wifi_object); + g_object_unref(connman_agent_object); + g_object_unref(wififirmware_object); + + wifi_power_deinitialize(); +} -- 2.7.4