Apply dpm poilcy for wifi and wifi profile 80/69980/4
authorhyunuktak <hyunuk.tak@samsung.com>
Tue, 17 May 2016 12:51:19 +0000 (21:51 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Thu, 2 Jun 2016 10:43:11 +0000 (19:43 +0900)
Change-Id: If9162f327332a2b5c75aa5806afcea1027b11f2d
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
CMakeLists.txt
include/network-dpm.h [new file with mode: 0755]
include/util.h [changed mode: 0644->0755]
interfaces/netconfig-iface-network-state.xml
src/main.c
src/network-dpm.c [new file with mode: 0755]
src/network-state.c [changed mode: 0644->0755]
src/utils/util.c [changed mode: 0644->0755]
src/wifi-power.c
src/wifi-ssid-scan.c

index 6176e4d..acd9b3a 100755 (executable)
@@ -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 (executable)
index 0000000..fccd1b4
--- /dev/null
@@ -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__ */
old mode 100644 (file)
new mode 100755 (executable)
index e43ec96..46d9ab4
@@ -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);
index 31860f8..698f35b 100644 (file)
@@ -6,7 +6,7 @@
                        <arg type="s" name="netmask" direction="in"/>
                        <arg type="s" name="interface" direction="in"/>
                        <arg type="s" name="gateway" direction="in"/>
-                       <arg  type="i" name="address_family" direction="in"/>
+                       <arg type="i" name="address_family" direction="in"/>
                        <arg type="b" name="result" direction="out"/>
                </method>
                <method name="RemoveRoute">
@@ -14,7 +14,7 @@
                        <arg type="s" name="netmask" direction="in"/>
                        <arg type="s" name="interface" direction="in"/>
                        <arg type="s" name="gateway" direction="in"/>
-                       <arg  type="i" name="address_family" direction="in"/>
+                       <arg type="i" name="address_family" direction="in"/>
                        <arg type="b" name="result" direction="out"/>
                </method>
                <method name="EthernetCableState">
                <method name="LaunchMdns"></method>
                <method name="RefMdns"></method>
                <method name="UnrefMdns"></method>
+               <method name="DevicePolicySetWifi">
+                       <arg type="i" name="state" direction="in"/>
+               </method>
+               <method name="DevicePolicyGetWifi">
+                       <arg type="i" name="state" direction="out"/>
+               </method>
+               <method name="DevicePolicySetWifiProfile">
+                       <arg type="i" name="state" direction="in"/>
+               </method>
+               <method name="DevicePolicyGetWifiProfile">
+                       <arg type="i" name="state" direction="out"/>
+               </method>
        </interface>
-</node>
\ No newline at end of file
+</node>
index a4d21d6..3fa4aaf 100755 (executable)
@@ -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 (executable)
index 0000000..3b45d13
--- /dev/null
@@ -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 <vconf.h>
+#include <vconf-keys.h>
+
+#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;
+}
old mode 100644 (file)
new mode 100755 (executable)
index cfba8d9..ab6051a
@@ -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)) {
old mode 100644 (file)
new mode 100755 (executable)
index 03d5eba..5910448
@@ -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;
index 926ce46..a1c1115 100755 (executable)
@@ -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
index 01fc055..becdd70 100755 (executable)
@@ -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;
 }