From 33fa3563ae3761f31c4eb3cd28ffbfe0b6ffc95b Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Tue, 17 May 2016 21:51:19 +0900 Subject: [PATCH] Apply dpm poilcy for wifi and wifi profile Change-Id: If9162f327332a2b5c75aa5806afcea1027b11f2d Signed-off-by: hyunuktak --- CMakeLists.txt | 1 + include/network-dpm.h | 46 +++++++ include/util.h | 2 + interfaces/netconfig-iface-network-state.xml | 18 ++- src/main.c | 5 + src/network-dpm.c | 183 +++++++++++++++++++++++++++ src/network-state.c | 9 ++ src/utils/util.c | 18 +++ src/wifi-power.c | 7 + src/wifi-ssid-scan.c | 2 +- 10 files changed, 287 insertions(+), 4 deletions(-) create mode 100755 include/network-dpm.h mode change 100644 => 100755 include/util.h create mode 100755 src/network-dpm.c mode change 100644 => 100755 src/network-state.c mode change 100644 => 100755 src/utils/util.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6176e4d..acd9b3a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ SET(SRCS src/dbus/netdbus.c src/network-clock.c src/network-state.c + src/network-dpm.c src/network-monitor.c src/wifi-firmware.c src/wifi-indicator.c diff --git a/include/network-dpm.h b/include/network-dpm.h new file mode 100755 index 0000000..fccd1b4 --- /dev/null +++ b/include/network-dpm.h @@ -0,0 +1,46 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __NETCONFIG_NETWORK_DPM_H__ +#define __NETCONFIG_NETWORK_DPM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void netconfig_dpm_init(void); +void netconfig_dpm_deinit(void); +int netconfig_dpm_update_from_wifi(void); +int netconfig_dpm_update_from_wifi_profile(void); + +gboolean handle_device_policy_set_wifi( + Network *object, GDBusMethodInvocation *context, gint state); +gboolean handle_device_policy_get_wifi( + Network *object, GDBusMethodInvocation *context); + +gboolean handle_device_policy_set_wifi_profile( + Network *object, GDBusMethodInvocation *context, gint state); +gboolean handle_device_policy_get_wifi_profile( + Network *object, GDBusMethodInvocation *context); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETWORK_DPM_H__ */ diff --git a/include/util.h b/include/util.h old mode 100644 new mode 100755 index e43ec96..46d9ab4 --- a/include/util.h +++ b/include/util.h @@ -79,6 +79,8 @@ gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context); gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * data); int netconfig_send_message_to_net_popup(const char *title, const char *content, const char *type, const char *ssid); +int netconfig_send_restriction_to_net_popup(const char *title, + const char *type, const char *restriction); void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val); #if defined TIZEN_WEARABLE int wc_launch_syspopup(netconfig_wcpopup_type_e type); diff --git a/interfaces/netconfig-iface-network-state.xml b/interfaces/netconfig-iface-network-state.xml index 31860f8..698f35b 100644 --- a/interfaces/netconfig-iface-network-state.xml +++ b/interfaces/netconfig-iface-network-state.xml @@ -6,7 +6,7 @@ - + @@ -14,7 +14,7 @@ - + @@ -25,5 +25,17 @@ + + + + + + + + + + + + - \ No newline at end of file + diff --git a/src/main.c b/src/main.c index a4d21d6..3fa4aaf 100755 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,7 @@ #include "wifi-agent.h" #include "wifi-power.h" #include "network-clock.h" +#include "network-dpm.h" #include "network-state.h" #include "network-monitor.h" #include "signal-handler.h" @@ -121,6 +122,8 @@ int main(int argc, char *argv[]) /* If its environment uses Emulator, network configuration is set by emulator default */ emulator_test_and_start(); + /* For device policy manager */ + netconfig_dpm_init(); /*In case no emulator, set the ETH0 Mac address*/ #if defined TIZEN_TV @@ -147,6 +150,8 @@ int main(int argc, char *argv[]) deregister_gdbus_signal(); + netconfig_dpm_deinit(); + #if !defined TIZEN_TELEPHONY_ENABLE netconfig_clock_deinit(); #endif diff --git a/src/network-dpm.c b/src/network-dpm.c new file mode 100755 index 0000000..3b45d13 --- /dev/null +++ b/src/network-dpm.c @@ -0,0 +1,183 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-power.h" +#include "network-dpm.h" +#include "network-state.h" + +#define NETCONFIG_SIGNAL_DPM_WIFI "DPMWifi" +#define NETCONFIG_SIGNAL_DPM_WIFI_PROFILE "DPMWifiProfile" + +static int dpm_policy_wifi = 1; +static int dpm_policy_wifi_profile = 1; + +static void __netconfig_dpm_notify_result(const char *sig_name, const char *key) +{ + gboolean reply; + GVariant *params; + GVariantBuilder *builder = NULL; + GDBusConnection *connection = NULL; + GError *error = NULL; + const char *prop_key = "key"; + + INFO("[Signal] %s %s", sig_name, key); + + connection = netdbus_get_connection(); + if (connection == NULL) { + ERR("Failed to get GDBus Connection"); + return; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", prop_key, g_variant_new_string(key)); + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + + g_variant_builder_unref(builder); + + reply = g_dbus_connection_emit_signal(connection, + NULL, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + sig_name, + params, + &error); + + if (reply != TRUE) { + if (error != NULL) { + ERR("Failed to send signal [%s]", error->message); + g_error_free(error); + } + return; + } + + INFO("Sent signal (%s), key (%s)", sig_name, key); + return; +} + +void netconfig_dpm_init(void) +{ + INFO("DPM initialized"); + return; +} + +void netconfig_dpm_deinit(void) +{ + INFO("DPM deinitialized"); + return; +} + +int netconfig_dpm_update_from_wifi(void) +{ + INFO("DPM update from wifi [%d]", dpm_policy_wifi); + + if (!dpm_policy_wifi) { + int wifi_state = 0; + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + if (wifi_state != VCONFKEY_WIFI_OFF) { + int err = wifi_power_off(); + if (err < 0) { + if (err == -EINPROGRESS) + ERR("wifi power off : InProgress"); + else if (err == -EALREADY) + ERR("wifi power off : AlreadyExists"); + else if (err == -EPERM) + ERR("wifi power off : PermissionDenied"); + else + ERR("wifi power off : WifiDriverFailed"); + } else + DBG("wifi power off : ErrorNone"); + + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_OFF_BY_AIRPLANE, 0); + netconfig_send_restriction_to_net_popup("Wi-Fi unavailable", + "toast_popup", "wifi"); + } + } + + return dpm_policy_wifi; +} + +int netconfig_dpm_update_from_wifi_profile(void) +{ + INFO("DPM update from wifi profile [%d]", dpm_policy_wifi_profile); + return dpm_policy_wifi_profile; +} + +gboolean handle_device_policy_set_wifi( + Network *object, + GDBusMethodInvocation *context, + gint state) +{ + INFO("DPM device policy wifi changed : [%d -> %d]", + dpm_policy_wifi, state); + + dpm_policy_wifi = state; + netconfig_dpm_update_from_wifi(); + __netconfig_dpm_notify_result(NETCONFIG_SIGNAL_DPM_WIFI, + state ? "allowed" : "disallowed"); + + network_complete_device_policy_set_wifi(object, context); + return TRUE; +} + +gboolean handle_device_policy_get_wifi( + Network *object, + GDBusMethodInvocation *context) +{ + INFO("Successfully get wifi device policy [%d]", + dpm_policy_wifi); + + network_complete_device_policy_get_wifi(object, + context, dpm_policy_wifi); + return TRUE; +} + +gboolean handle_device_policy_set_wifi_profile( + Network *object, + GDBusMethodInvocation *context, + gint state) +{ + INFO("DPM device policy wifi profile changed : [%d -> %d]", + dpm_policy_wifi_profile, state); + + dpm_policy_wifi_profile = state; + netconfig_dpm_update_from_wifi_profile(); + __netconfig_dpm_notify_result(NETCONFIG_SIGNAL_DPM_WIFI_PROFILE, + state ? "allowed" : "disallowed"); + + network_complete_device_policy_set_wifi_profile(object, context); + return TRUE; +} + +gboolean handle_device_policy_get_wifi_profile( + Network *object, + GDBusMethodInvocation *context) +{ + INFO("Successfully get wifi profile device policy [%d]", + dpm_policy_wifi_profile); + + network_complete_device_policy_get_wifi(object, + context, dpm_policy_wifi_profile); + return TRUE; +} diff --git a/src/network-state.c b/src/network-state.c old mode 100644 new mode 100755 index cfba8d9..ab6051a --- a/src/network-state.c +++ b/src/network-state.c @@ -40,6 +40,7 @@ #include "wifi-state.h" #include "wifi-power.h" #include "network-state.h" +#include "network-dpm.h" #include "network-monitor.h" #include "netsupplicant.h" #include "wifi-tel-intf.h" @@ -1060,6 +1061,14 @@ void state_object_create_and_init(void) G_CALLBACK(handle_ref_mdns), NULL); g_signal_connect(netconfigstate, "handle-unref-mdns", G_CALLBACK(handle_unref_mdns), NULL); + g_signal_connect(netconfigstate, "handle-device-policy-set-wifi", + G_CALLBACK(handle_device_policy_set_wifi), NULL); + g_signal_connect(netconfigstate, "handle-device-policy-get-wifi", + G_CALLBACK(handle_device_policy_get_wifi), NULL); + g_signal_connect(netconfigstate, "handle-device-policy-set-wifi-profile", + G_CALLBACK(handle_device_policy_set_wifi_profile), NULL); + g_signal_connect(netconfigstate, "handle-device-policy-get-wifi-profile", + G_CALLBACK(handle_device_policy_get_wifi_profile), NULL); if (!g_dbus_interface_skeleton_export(interface_network, connection, NETCONFIG_NETWORK_STATE_PATH, NULL)) { diff --git a/src/utils/util.c b/src/utils/util.c old mode 100644 new mode 100755 index 03d5eba..5910448 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -909,6 +909,24 @@ int netconfig_send_message_to_net_popup(const char *title, return ret; } +int netconfig_send_restriction_to_net_popup(const char *title, + const char *type, const char *restriction) +{ + int ret = 0; + bundle *b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", title); + bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction"); + bundle_add(b, "_SYSPOPUP_TYPE_", type); + bundle_add(b, "_RESTRICTED_TYPE_", restriction); + + ret = syspopup_launch("net-popup", b); + + bundle_free(b); + + return ret; +} + void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val) { bundle *b = NULL; diff --git a/src/wifi-power.c b/src/wifi-power.c index 926ce46..a1c1115 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -39,6 +39,7 @@ #include "wifi-tel-intf.h" #include "netsupplicant.h" #include "network-state.h" +#include "network-dpm.h" #include "wifi-firmware.h" #include "wifi-background-scan.h" @@ -1087,6 +1088,12 @@ gboolean handle_load_driver(Wifi *wifi, g_return_val_if_fail(wifi != NULL, FALSE); + if (!netconfig_dpm_update_from_wifi()) { + DBG("DPM policy restricts Wi-Fi"); + netconfig_error_permission_denied(context); + return TRUE; + } + #if defined TIZEN_WEARABLE err = wifi_power_on_wearable(device_picker_test); #else diff --git a/src/wifi-ssid-scan.c b/src/wifi-ssid-scan.c index 01fc055..becdd70 100755 --- a/src/wifi-ssid-scan.c +++ b/src/wifi-ssid-scan.c @@ -380,7 +380,7 @@ gboolean handle_request_specific_scan(Wifi *wifi, if (result != TRUE) netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSpecificScan"); else - wifi_complete_request_wps_scan(wifi, context); + wifi_complete_request_specific_scan(wifi, context); return result; } -- 2.7.4