Apply device policy for wifi and wifi profile 34/72234/5 accepted/tizen/common/20160607.194726 accepted/tizen/ivi/20160607.235422 accepted/tizen/mobile/20160607.235359 accepted/tizen/tv/20160607.235413 accepted/tizen/wearable/20160607.235347 submit/tizen/20160607.090155
authorhyunuktak <hyunuk.tak@samsung.com>
Tue, 31 May 2016 08:13:23 +0000 (17:13 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Tue, 7 Jun 2016 05:38:48 +0000 (14:38 +0900)
Change-Id: I9508de92b4cdaeeddbf78e1182acdb27c2116572
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
include/common/network-cm-intf.h
include/wifi/network-wifi-intf.h
packaging/libnet-client.spec
src/include/network-dbus-request.h
src/include/network-internal.h
src/include/network-signal-handler.h
src/network-dbus-request.c
src/network-profile-intf.c
src/network-signal-handler.c
src/network-wifi-intf.c

index eb702ff..23ad969 100755 (executable)
@@ -115,7 +115,7 @@ typedef enum
        /** Reset default cellular profile Response Event */
        NET_EVENT_CELLULAR_RESET_DEFAULT_RSP,
 
-       /** Wi-Fi interface Scanning Indication Event*/
+       /** Wi-Fi interface Scanning Indication Event */
        NET_EVENT_WIFI_SCANNING_IND,
 
        /** Wi-Fi interface Scan Indication Event(WPS scan) */
@@ -127,10 +127,10 @@ typedef enum
        /** Ethernet Cable Detached Event */
        NET_EVENT_ETHERNET_CABLE_DETACHED,
 
-       /** Wi-Fi TDLS Peer Connected EVENT) */
+       /** Wi-Fi TDLS Peer Connected EVENT */
        NET_EVENT_TDLS_CONNECTED_IND,
 
-       /** Wi-Fi TDLS Peer Disconnect EVENT) */
+       /** Wi-Fi TDLS Peer Disconnect EVENT */
        NET_EVENT_TDLS_DISCONNECTED_IND,
 } net_event_t;
 
index 49fc880..569c300 100755 (executable)
@@ -398,7 +398,7 @@ int net_wifi_enroll_wps(const char *profile_name, net_wifi_wps_info_t *wps_info)
  * @return       NET_ERR_NONE on success, negative values for errors
  */
 
-int net_check_get_privilege();
+int net_check_get_privilege(void);
 
 /**
  * @fn   int net_check_profile_privilege()
@@ -414,7 +414,7 @@ int net_check_get_privilege();
  * @return       NET_ERR_NONE on success, negative values for errors
  */
 
-int net_check_profile_privilege();
+int net_check_profile_privilege(void);
 
 #if defined TIZEN_TV
 /**
@@ -442,6 +442,9 @@ int net_wifi_enroll_wps_without_ssid(net_wifi_wps_info_t *wps_info);
 int net_wifi_tdls_disconnect(const char* peer_mac_addr);
 int net_wifi_tdls_connected_peer(char** peer_mac_addr);
 
+int net_get_device_policy_wifi(void);
+int net_get_device_policy_wifi_profile(void);
+
 /**
  * \}
  */
index cdf329f..cc149a2 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          libnet-client
 Summary:       Network Client library (Shared library)
-Version:       1.1.52
+Version:       1.1.53
 Release:       1
 Group:         System/Network
 License:       Flora-1.1
index 997dabb..be4bb83 100755 (executable)
@@ -145,6 +145,9 @@ int _net_dbus_set_agent_wps_pin(const char *wps_pin);
 int _net_dbus_tdls_disconnect(const char* peer_mac_addr);
 int _net_dbus_tdls_connected_peer(char** peer_mac_addr);
 
+int _net_dbus_device_policy_get_wifi(int *state);
+int _net_dbus_device_policy_get_wifi_profile(int *state);
+
 #ifdef __cplusplus
 }
 #endif
index 54a5bd6..3ac164a 100755 (executable)
@@ -135,6 +135,8 @@ extern "C" {
 #define NETCONFIG_SIGNAL_TDLS_DISCONNECTED     "TDLSDisconnect"
 #define NETCONFIG_SIGNAL_TDLS_PEER_FOUND       "TDLSPeerFound"
 #define NETCONFIG_SIGNAL_WIFI_CONNECT_FAIL     "WiFiConnectFail"
+#define NETCONFIG_SIGNAL_DPM_WIFI                      "DPMWifi"
+#define NETCONFIG_SIGNAL_DPM_WIFI_PROFILE      "DPMWifiProfile"
 
 #undef LOG_TAG
 #define        LOG_TAG         "NET_CLIENT"
index 1648fce..1f24340 100755 (executable)
@@ -39,6 +39,11 @@ int _net_deregister_signal(void);
 int _net_register_signal(void);
 int _net_subscribe_signal_wifi(void);
 int _net_init_service_state_table(void);
+int _net_get_dpm_wifi_state(void);
+void _net_set_dpm_wifi_state(int state);
+int _net_get_dpm_wifi_profile_state(void);
+void _net_set_dpm_wifi_profile_state(int state);
+
 
 #ifdef __cplusplus
 }
index dcb6b56..c27e48c 100755 (executable)
@@ -2588,3 +2588,65 @@ int _net_dbus_tdls_connected_peer(char** peer_mac_addr)
 
        return Error;
 }
+
+int _net_dbus_device_policy_get_wifi(int *state)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+
+       if (state == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
+       message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
+                       NETCONFIG_NETWORK_INTERFACE, "DevicePolicyGetWifi", NULL, &Error);
+
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to get wifi device policy\n");
+               return Error;
+       }
+
+       g_variant_get(message, "(i)", state);
+
+       NETWORK_LOG(NETWORK_LOW, "Wifi device policy state [%d]\n", *state);
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+int _net_dbus_device_policy_get_wifi_profile(int *state)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+
+       if (state == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
+       message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
+                       NETCONFIG_NETWORK_INTERFACE, "DevicePolicyGetWifiProfile", NULL, &Error);
+
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to get wifi device policy\n");
+               return Error;
+       }
+
+       g_variant_get(message, "(i)", state);
+
+       NETWORK_LOG(NETWORK_LOW, "Wifi profile device policy state [%d]\n", *state);
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
index 1d62fbf..198fa40 100755 (executable)
@@ -22,6 +22,7 @@
 #include <arpa/inet.h>
 
 #include "network-internal.h"
+#include "network-signal-handler.h"
 #include "network-dbus-request.h"
 
 #define DBUS_OBJECT_PATH_MAX   150
@@ -2685,6 +2686,12 @@ EXPORT_API int net_modify_profile(const char* profile_name, net_profile_info_t*
                return NET_ERR_APP_NOT_REGISTERED;
        }
 
+       if (!_net_get_dpm_wifi_profile_state()) {
+               NETWORK_LOG(NETWORK_ERROR, "Wifi profile device policy restricts");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_SECURITY_RESTRICTED;
+       }
+
        Error = net_get_profile_info(profile_name, &exProfInfo);
        if (Error != NET_ERR_NONE) {
                NETWORK_LOG(NETWORK_ERROR,
index de845b9..4d31124 100755 (executable)
@@ -32,6 +32,8 @@ static __thread guint gdbus_conn_subscribe_id_connman_error = 0;
 static __thread guint gdbus_conn_subscribe_id_supplicant = 0;
 static __thread guint gdbus_conn_subscribe_id_netconfig_wifi = 0;
 static __thread guint gdbus_conn_subscribe_id_netconfig = 0;
+static __thread int net_dpm_wifi_state = -1;
+static __thread int net_dpm_wifi_profile_state = -1;
 
 static int __net_handle_wifi_power_rsp(gboolean value)
 {
@@ -678,6 +680,62 @@ static int __net_handle_ethernet_cable_state_rsp(GVariant *param)
        return NET_ERR_NONE;
 }
 
+static int __net_handle_network_dpm_wifi_event(GVariant *param)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       GVariantIter *iter = NULL;
+       GVariant *value = NULL;
+       const char *key = NULL;
+       const gchar *sig_value = NULL;
+
+       g_variant_get(param, "(a{sv})", &iter);
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (g_strcmp0(key, "key") == 0) {
+                       sig_value = g_variant_get_string(value, NULL);
+                       NETWORK_LOG(NETWORK_LOW, "Wifi device policy : %s",
+                                               sig_value);
+                       if (g_strcmp0(sig_value, "allowed") == 0)
+                               net_dpm_wifi_state = TRUE;
+                       else
+                               net_dpm_wifi_state = FALSE;
+               }
+       }
+       g_variant_iter_free(iter);
+
+       return NET_ERR_NONE;
+       __NETWORK_FUNC_EXIT__;
+}
+
+static int __net_handle_network_dpm_wifi_profile_event(GVariant *param)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       GVariantIter *iter = NULL;
+       GVariant *value = NULL;
+       const char *key = NULL;
+       const gchar *sig_value = NULL;
+
+       g_variant_get(param, "(a{sv})", &iter);
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (g_strcmp0(key, "key") == 0) {
+                       sig_value = g_variant_get_string(value, NULL);
+                       NETWORK_LOG(NETWORK_LOW, "Wifi profile device policy : %s",
+                                               sig_value);
+                       if (g_strcmp0(sig_value, "allowed") == 0)
+                               net_dpm_wifi_profile_state = TRUE;
+                       else
+                               net_dpm_wifi_profile_state = FALSE;
+               }
+       }
+       g_variant_iter_free(iter);
+
+       return NET_ERR_NONE;
+       __NETWORK_FUNC_EXIT__;
+}
+
 static void __net_connman_service_signal_filter(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
@@ -861,11 +919,36 @@ static void __net_netconfig_network_signal_filter(GDBusConnection *conn,
 {
        if (g_strcmp0(sig, NETCONFIG_SIGNAL_ETHERNET_CABLE_STATE) == 0)
                __net_handle_ethernet_cable_state_rsp(param);
+       else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPM_WIFI) == 0)
+               __net_handle_network_dpm_wifi_event(param);
+       else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPM_WIFI_PROFILE) == 0)
+               __net_handle_network_dpm_wifi_profile_event(param);
 }
 
 /*****************************************************************************
  * Global Functions
  *****************************************************************************/
+
+int _net_get_dpm_wifi_state(void)
+{
+       return net_dpm_wifi_state;
+}
+
+void _net_set_dpm_wifi_state(int state)
+{
+       net_dpm_wifi_state = state;
+}
+
+gboolean _net_get_dpm_wifi_profile_state()
+{
+       return net_dpm_wifi_profile_state;
+}
+
+void _net_set_dpm_wifi_profile_state(int state)
+{
+       net_dpm_wifi_profile_state = state;
+}
+
 int _net_deregister_signal(void)
 {
        __NETWORK_FUNC_ENTER__;
index 70c4ac2..86434d9 100755 (executable)
@@ -364,6 +364,12 @@ EXPORT_API int net_wifi_power_on(gboolean wifi_picker_test)
                return NET_ERR_APP_NOT_REGISTERED;
        }
 
+       if (!net_get_device_policy_wifi()) {
+               NETWORK_LOG(NETWORK_ERROR, "Wifi profile device policy restricts");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_SECURITY_RESTRICTED;
+       }
+
        vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_state);
        if (hotspot_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
                NETWORK_LOG(NETWORK_ERROR, "Wi-Fi hotspot is enabled!");
@@ -890,3 +896,39 @@ EXPORT_API int net_wifi_tdls_connected_peer(char** peer_mac_addr)
        return Error;
 
 }
+
+EXPORT_API int net_get_device_policy_wifi(void)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       int state = _net_get_dpm_wifi_state();
+       if (state == -1) {
+               net_err_t Error = _net_dbus_device_policy_get_wifi(&state);
+               if (Error != NET_ERR_NONE)
+                       NETWORK_LOG(NETWORK_ERROR, "_net_dbus_device_policy_get_wifi failed\n");
+               else
+                       _net_set_dpm_wifi_state(state);
+       }
+
+       NETWORK_LOG(NETWORK_LOW, "Wifi device policy state [%d]\n", state);
+
+       __NETWORK_FUNC_EXIT__;
+       return state;
+}
+
+EXPORT_API int net_get_device_policy_wifi_profile(void)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       int state = _net_get_dpm_wifi_profile_state();
+       if (state == -1) {
+               net_err_t Error = _net_dbus_device_policy_get_wifi_profile(&state);
+               if (Error != NET_ERR_NONE)
+                       NETWORK_LOG(NETWORK_ERROR, "_net_dbus_device_policy_get_wifi_profile failed\n");
+               else
+                       _net_set_dpm_wifi_profile_state(state);
+       }
+
+       __NETWORK_FUNC_EXIT__;
+       return state;
+}