Add Wi-Fi Policy 37/65637/9
authorJaemin Ryu <jm77.ryu@samsung.com>
Tue, 12 Apr 2016 02:51:47 +0000 (11:51 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Thu, 14 Apr 2016 08:37:56 +0000 (01:37 -0700)
Change-Id: I147a993b78f9d1ecb316bd26a45db844c3f6473a
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
libs/CMakeLists.txt
libs/dpm/wifi.cpp [new file with mode: 0644]
libs/dpm/wifi.h [new file with mode: 0644]
libs/wifi.cpp [new file with mode: 0644]
policy/wifi.hxx [new file with mode: 0644]
server/wifi.cpp [new file with mode: 0644]

index 6536da0..8eae33d 100755 (executable)
@@ -24,10 +24,12 @@ SET(SOURCES policy-client.cpp
                        administration.cpp
                        security.cpp
                        password.cpp
+                       wifi.cpp
                        zone.cpp
                        dpm/client-handle.cpp
             dpm/security.cpp
                        dpm/password.cpp
+                       dpm/wifi.cpp
                        dpm/zone.cpp
 )
 
@@ -35,6 +37,7 @@ SET(CAPI_INCLUDE_FILES  dpm/dpm.h
                                                dpm/device-policy-client.h
                                                dpm/security.h
                                                dpm/password.h
+                                               dpm/wifi.h
                                                dpm/zone.h
 )
 
diff --git a/libs/dpm/wifi.cpp b/libs/dpm/wifi.cpp
new file mode 100644 (file)
index 0000000..5007ddb
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ *  Copyright (c) 2015 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 "wifi.h"
+#include "wifi.hxx"
+
+#include "capi-assert.h"
+#include "policy-client.h"
+
+using namespace DevicePolicyManager;
+
+int dpm_set_wifi_state_change_restriction(dpm_client_h handle, int enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    return wifi.setStateChangeRestriction(enable);
+}
+
+int dpm_is_wifi_state_change_restricted(dpm_client_h handle, int *enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    *enable = wifi.isStateChangeRestricted();
+    return DPM_ERROR_NONE;
+}
+
+int dpm_set_wifi_setting_changes_restriction(dpm_client_h handle, int enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    return wifi.setSettingChangesRestriction(enable);
+}
+
+int dpm_is_wifi_setting_changes_restricted(dpm_client_h handle, int *enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    *enable = wifi.isSettingChangesRestricted();
+    return DPM_ERROR_NONE;
+}
+
+int dpm_allow_wifi_hotspot_restriction(dpm_client_h handle, int enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    return wifi.setHotspotRestriction(enable);
+}
+
+int dpm_is_wifi_hotspot_restricted(dpm_client_h handle, int *enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    *enable = wifi.isHotspotRestricted();
+    return DPM_ERROR_NONE;
+}
+
+int dpm_set_wifi_network_access_restriction(dpm_client_h handle, int enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    return wifi.setNetworkAccessRestriction(enable);
+}
+
+int dpm_is_wifi_network_access_restricted(dpm_client_h handle, int *enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    *enable = wifi.isNetworkAccessRestricted();
+    return DPM_ERROR_NONE;
+}
+
+int dpm_add_wifi_ssid_to_blocklist(dpm_client_h handle, const char* ssid)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(ssid, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    return wifi.addSsidFromBlacklist(ssid);
+}
+
+int dpm_remove_wifi_ssid_from_blocklist(dpm_client_h handle, const char* ssid)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(ssid, DPM_ERROR_INVALID_PARAMETER);
+
+    DevicePolicyClient &client = GetDevicePolicyClient(handle);
+    Wifi wifi = client.createPolicyInterface<Wifi>();
+    return wifi.removeSsidFromBlacklist(ssid);
+}
diff --git a/libs/dpm/wifi.h b/libs/dpm/wifi.h
new file mode 100644 (file)
index 0000000..34a4d8f
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ *  Copyright (c) 2015 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 __CAPI_WIFI_POLICY_H__
+#define __CAPI_WIFI_POLICY_H__
+
+#include <dpm/device-policy-client.h>
+
+/**
+ * @file wifi.h
+ * @brief This file provides APIs to control wifi policy
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup  CAPI_DPM_WIFI_POLICY_MODULE
+ * @{
+ */
+
+/**
+ * @brief       Allows or disallows the user to change the Wi-Fi state.
+ * @details     An administrator can use this API to allow or disallow the user to
+ *              change the Wi-Fi state. If it is restricted, the user does not have UI
+ *              access to change the state.
+ *              Also, the apps that uses wifi_activate() or wifi_deactivate()
+ *              follow this restriction.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.wifi
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable TRUE to enable wifi state change restriction, else FALSE
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dom_is_wifi_state_change_restricted()
+ * @see         wifi_activate()
+ * @see         wifi_deactivate()
+ */
+DPM_API int dpm_set_wifi_state_change_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the user is restricted to change the Wi-Fi state.
+ * @details     An administrator can use this API to check whether or not the user is
+ *              restricted to modify Wi-Fi settings. The user is restricted in modifying
+ *              Wi-Fi settings if at least one administrator has set the value to FALSE.
+ * @since_tizen 3.0
+ * @param[in]   handle Device Policy Client handle
+ * @param[out]  enable TRUE if the user is not allowed to change the Wi-Fi state,
+                else FALSE
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_wifi_state_change_restriction()
+ */
+DPM_API int dpm_is_wifi_state_change_restricted(dpm_client_h handle, int *enable);
+
+/**
+ * @brief       Allows or disallows user to modify some Wi-Fi settings of network settings.
+ * @details     An administrator can use this API to allow or disallow users to modify selected
+ *              Wi-Fi settings like static ip configuration, proxy settings, security type
+ *              and others. When this policy is in effect the user is only allowed to
+ *              modify only the username, password, anonymous identity, and wep key.
+ *              In addition, the user cannot remove the networ. When false, the user can
+ *              modify all Wi-fi network settings normally and also remove it.
+ *              Also the apps that uses wifi_ap_set_* APIs follow this restriction.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.wifi
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable TRUE to enable wifi setting changes, else FALSE
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dom_is_wifi_setting_changes_restricted()
+ * @see         wifi_ap_set_ip_config_type()
+ * @see         wifi_ap_set_ip_address()
+ * @see         wifi_ap_set_subnet_mask()
+ * @see         wifi_ap_set_gateway_address()
+ * @see         wifi_ap_set_proxy_address()
+ * @see         wifi_ap_set_proxy_tyype()
+ * @see         wifi_ap_set_dns_address()
+ * @see         wifi_ap_set_security_type()
+ * @see         wifi_ap_set_encryption_type()
+ * @see         wifi_ap_set_passphrase()
+ */
+DPM_API int dpm_set_wifi_setting_changes_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks if the user is allowed to modify certain Wi-Fi network settings.
+ * @details     An administrator can use this API to check whether or not the user is
+ *              allowed to modify Wi-Fi settings. The user is restricted in modifying
+ *              Wi-Fi settings if at least one administrator has set the value to TRUE.
+ * @since_tizen 3.0
+ * @param[in]   handle Device Policy Client handle
+ * @param[out]  enable TRUE if one or more administrators enabled restriction
+ *              FALSE if user can change all Wi-Fi network settings
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_wifi_setting_changes_restriction()
+ */
+DPM_API int dpm_is_wifi_setting_changes_restricted(dpm_client_h handle, int *enable);
+
+/**
+ * @brief       Allows or disallows the user to change Wi-Fi hotspot settings
+ * @details     An administrator can use this API to restrict changing Wi-Fi
+ *              hotspot settings. When restricted, the UI is grayed out so the user cannot
+ *              modify the settings.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.security
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable TRUE to restrict wifi hostspot setting, else FALSE
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_wifi_hostspot_restricted()
+ */
+DPM_API int dpm_set_wifi_hotspot_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the the Wi-Fi hotspot is restricted.
+ * @details     An administrator can use this API to check whether the Wi-Fi hotspot
+ *              is restricted.
+ *              If the Wi-Fi hotspot is restricted, the UI is grayed out so user can not
+ *              change its state.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @param[in]   handle Device Policy Client handle
+ * @param[out]  enable TRUE if modification is allowed,
+ *              FALSE if modification is denied
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_wifi_hotspot_restriction()
+ */
+DPM_API int dpm_is_wifi_hotspot_restricted(dpm_client_h handle, int *enable);
+
+/**
+ * @brief       Restricts network accessed based on the Wi-Fi network service set
+ *              identifier(SSID).
+ * @details     An administrator can use this API to restrict connecting to the Wi-Fi
+ *              network based on the blocked network list.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.wifi
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   enable TRUE to enable the Wi-Fi network access restriction,
+ *              FALSE to disable the Wi-Fi network access restriction
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @pre         Blocked network list must be added by dpm_add_wifi_ssid_to_blocklist()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_is_wifi_network_access_restricted()
+ * @see         dpm_add_wifi_ssid_to_blocklist()
+ * @see         dpm_remove_wifi_ssid_from_blocklist()
+ */
+DPM_API int dpm_set_wifi_network_access_restriction(dpm_client_h handle, int enable);
+
+/**
+ * @brief       Checks whether the SSID-based Wi-Fi network access restriction is
+ *              enabled.
+ * @details     An administrator can use this API to check whether the SSID-based
+ *              Wi-Fi network restriction is enabled.
+ * @since_tizen 3.0
+ * @param[in]   handle Device Policy Client handle
+ * @param[out]  enable TRUE if restriction is activated or
+ *              FALSE if restriction is deactivated
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_set_wifi_network_access_restriction()
+ */
+DPM_API int dpm_is_wifi_network_access_restricted(dpm_client_h handle, int *enable);
+
+/**
+ * @brief       Adds a service set identifier(SSID) to the list of blocked network.
+ * @details     An administrator can use this API to add an SSID to the list of blocked
+ *              networks, which prevents the user from connecting to it.
+ *              The blocked network still appears in the Access Point list but is disabled.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.wifi
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   ssid The SSID to block
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @retval      #DPM_ERROR_OUT_OF_MEMORY Too many SSIDs in blocked network list
+ * @pre         handle must be created by dpm_create_client()
+i* @post        dpm_set_wifi_network_access_restriction() must be called
+ *              when SSIDs in the blacklist are needed to get restricted
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_remove_wifi_ssid_to_blocklist()
+ * @see         dpm_set_wifi_network_access_restriction()
+ */
+DPM_API int dpm_add_wifi_ssid_to_blocklist(dpm_client_h handle, const char* ssid);
+
+/**
+ * @brief       Removes a service set identifier(SSID) from the list of blocked
+ *              networks.
+ * @details     An administrator can use this API to remove an SSID from the list of
+ *              blocked networks, which allows the user to connect to it.
+ * @since_tizen 3.0
+ * @privlevel   public
+ * @privilege   %http://tizen.org/privilege/dpm.wifi
+ * @param[in]   handle Device Policy Client handle
+ * @param[in]   ssid The SSID to be removed from the list of blocked networks
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMEOUT Timeout
+ * @retval      #DPM_ERROR_NOT_SUPPORTED Not supported
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         handle must be created by dpm_create_client()
+ * @see         dpm_create_client()
+ * @see         dpm_destroy_client()
+ * @see         dpm_add_wifi_ssid_to_blocklist()
+ * @see         dpm_set_wifi_network_access_restriction()
+ */
+DPM_API int dpm_remove_wifi_ssid_from_blocklist(dpm_client_h handle, const char* ssid);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //! __CAPI_SECURITY_POLICY_H__
diff --git a/libs/wifi.cpp b/libs/wifi.cpp
new file mode 100644 (file)
index 0000000..17e63f2
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ *  Copyright (c) 2015 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 "wifi.hxx"
+#include "audit/logger.h"
+
+namespace DevicePolicyManager {
+
+Wifi::Wifi(PolicyControlContext& ctxt) :
+    context(ctxt)
+{
+}
+
+Wifi::~Wifi()
+{
+}
+
+int Wifi::setStateChangeRestriction(bool enable)
+{
+    try {
+        return context->methodCall<int>("Wifi::setStateChangeRestriction", enable);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+bool Wifi::isStateChangeRestricted()
+{
+    try {
+        return context->methodCall<bool>("Wifi::isStateChangeRestricted");
+    } catch (runtime::Exception& e) {
+        return false;
+    }
+}
+
+int Wifi::setSettingChangesRestriction(bool enable)
+{
+    try {
+        return context->methodCall<int>("Wifi::setSettingChangesRestriction", enable);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+bool Wifi::isSettingChangesRestricted()
+{
+    try {
+        return context->methodCall<bool>("Wifi::isSettingChangesRestricted");
+    } catch (runtime::Exception& e) {
+        return false;
+    }
+}
+
+int Wifi::setHotspotRestriction(bool enable)
+{
+    try {
+        return context->methodCall<int>("Wifi::setHotspotRestriction", enable);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+bool Wifi::isHotspotRestricted()
+{
+    try {
+        return context->methodCall<bool>("Wifi::isHotspotRestricted");
+    } catch (runtime::Exception& e) {
+        return false;
+    }
+}
+
+int Wifi::setNetworkAccessRestriction(bool enable)
+{
+    try {
+        return context->methodCall<int>("Wifi::setNetworkAccessRestriction", enable);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+bool Wifi::isNetworkAccessRestricted()
+{
+    try {
+        return context->methodCall<bool>("Wifi::isNetworkAccessRestricted");
+    } catch (runtime::Exception& e) {
+        return false;
+    }
+}
+
+int Wifi::addSsidFromBlacklist(const std::string& ssid)
+{
+    try {
+        return context->methodCall<int>("Wifi::addSsidFromBlacklist", ssid);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+int Wifi::removeSsidFromBlacklist(const std::string& ssid)
+{
+    try {
+        return context->methodCall<int>("Wifi::removeSsidFromBlacklist", ssid);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+} // namespace DevicePolicyManager
diff --git a/policy/wifi.hxx b/policy/wifi.hxx
new file mode 100644 (file)
index 0000000..e696513
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (c) 2015 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 __WIFI_POLICY__
+#define __WIFI_POLICY__
+
+#include "data-type.h"
+#include "policy-context.hxx"
+
+namespace DevicePolicyManager {
+
+/**
+ * This class provides APIs to configure Wi-Fi related settings and manage Wi-Fi profiles.
+ */
+
+class Wifi {
+public:
+    Wifi(PolicyControlContext& ctxt);
+    ~Wifi();
+
+    int setStateChangeRestriction(bool restrict);
+    bool isStateChangeRestricted();
+
+    int setSettingChangesRestriction(bool restrict);
+    bool isSettingChangesRestricted();
+
+    int setHotspotRestriction(bool restrict);
+    bool isHotspotRestricted();
+
+    int setNetworkAccessRestriction(bool restrict);
+    bool isNetworkAccessRestricted();
+
+    int addSsidFromBlacklist(const std::string& ssid);
+    int removeSsidFromBlacklist(const std::string& ssid);
+
+private:
+    PolicyControlContext& context;
+};
+
+} // namespace DevicePolicyManager
+#endif // __WIFI_POLICY__
diff --git a/server/wifi.cpp b/server/wifi.cpp
new file mode 100644 (file)
index 0000000..c34d72c
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ *  Copyright (c) 2015 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 <arpa/inet.h>
+
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <wifi.h>
+#include <syspopup_caller.h>
+#include <network-pm-config.h>
+#include <network-pm-intf.h>
+#include <network-pm-wlan.h>
+#include <network-cm-intf.h>
+
+#include <cstdlib>
+#include <iostream>
+#include <functional>
+
+#include "wifi.hxx"
+#include "app-bundle.h"
+#include "audit/logger.h"
+
+namespace DevicePolicyManager {
+
+typedef wifi_ap_h AccessPointHandle;
+
+namespace {
+
+struct AccessPoint {
+    AccessPoint(AccessPointHandle h, const std::string& name) :
+        handle(h), ssid(name)
+    {
+    }
+
+    AccessPointHandle handle;
+    std::string ssid;
+};
+
+const std::string WIFI_PKG = "wifi-qs";
+
+AccessPointHandle FindAccessPoint(const std::string& ssid)
+{
+    auto AccessPointFoundCallback = [](wifi_ap_h handle, void* user_data) {
+        char *name;
+        int ret = ::wifi_ap_get_essid(handle, &name);
+        if (ret == WIFI_ERROR_NONE) {
+            AccessPoint *ap = static_cast<AccessPoint*>(user_data);
+            if (ap->ssid == name) {
+                ap->handle = handle;
+                ::free(name);
+                // should return false to break iteration
+                return true;
+            }
+            ::free(name);
+        }
+        // should return true to continue iteration
+        return true;
+    };
+
+    AccessPoint ap(nullptr, ssid);
+    int ret = ::wifi_foreach_found_aps(AccessPointFoundCallback, &ap);
+    if (ret != WIFI_ERROR_NONE) {
+        ERROR("Error in wifi_foreach_found_aps");
+        return nullptr;
+    }
+
+    return ap.handle;
+}
+
+std::string WifiErrorMessage(const int error)
+{
+    switch (error) {
+    case WIFI_ERROR_INVALID_PARAMETER:
+        return "WIFI_ERROR_INVALID_PARAMETER";
+    case WIFI_ERROR_OUT_OF_MEMORY:
+        return "WIFI_ERROR_OUT_OF_MEMORY";
+    case WIFI_ERROR_INVALID_OPERATION:
+        return "WIFI_ERROR_INVALID_OPERATION";
+    case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
+        return "WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
+    case WIFI_ERROR_OPERATION_FAILED:
+        return "WIFI_ERROR_OPERATION_FAILED";
+    case WIFI_ERROR_NO_CONNECTION:
+        return "WIFI_ERROR_NO_CONNECTION";
+    case WIFI_ERROR_NOW_IN_PROGRESS:
+        return "WIFI_ERROR_NOW_IN_PROGRESS";
+    case WIFI_ERROR_ALREADY_EXISTS:
+        return "WIFI_ERROR_ALREADY_EXISTS";
+    case WIFI_ERROR_OPERATION_ABORTED:
+        return "WIFI_ERROR_OPERATION_ABORTED";
+    case WIFI_ERROR_DHCP_FAILED:
+        return "WIFI_ERROR_DHCP_FAILED";
+    case WIFI_ERROR_INVALID_KEY:
+        return "WIFI_ERROR_INVALID_KEY";
+    case WIFI_ERROR_NO_REPLY:
+        return "WIFI_ERROR_NO_REPLY";
+    case WIFI_ERROR_SECURITY_RESTRICTED:
+        return "WIFI_ERROR_SECURITY_RESTRICTED";
+    default:
+        break;
+    }
+
+    return "Unknown WIFI Error";
+}
+
+} //namespace
+
+Wifi::Wifi(PolicyControlContext& ctx) :
+    context(ctx)
+{
+    rmi::Service& manager = context.getServiceManager();
+
+    manager.registerParametricMethod(this, (int)(Wifi::setsetStateChangeRestriction)(bool));
+    manager.registerParametricMethod(this, (int)(Wifi::setSettingChangesRestriction)(bool));
+    manager.registerParametricMethod(this, (int)(Wifi::setApSettingModificationRestriction)(bool));
+    manager.registerParametricMethod(this, (int)(Wifi::activateWifiSsidRestriction)(bool));
+    manager.registerParametricMethod(this, (int)(Wifi::addSsidFromBlacklist)(std::string));
+    manager.registerParametricMethod(this, (int)(Wifi::removeSsidFromBlacklist)(std::string));
+
+    manager.registerNonparametricMethod(this, (bool)(Wifi::isWifiStateChanageAllowed)());
+    manager.registerNonparametricMethod(this, (bool)(Wifi::isSettingChangesRestricted)());
+    manager.registerNonparametricMethod(this, (bool)(Wifi::isApSettingModificationRestricted)());
+    manager.registerNonparametricMethod(this, (bool)(Wifi::isNetworkAccessRestricted)());
+}
+
+Wifi::~Wifi()
+{
+}
+
+int Wifi::setStateChangeRestriction(bool allow)
+{
+    int status;
+
+    if (::vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &status) != 0) {
+        ERROR("Failed to read VCONFKEY_NETWORK_WIFI_STATE");
+        return -1;
+    }
+
+    if (status != VCONFKEY_NETWORK_WIFI_OFF) {
+        try {
+            Bundle bundle;
+            bundle.add("-t", "off");
+
+            Syspopup syspopup(WIFI_PKG);
+            if (syspopup.launch(bundle) < 0) {
+                ERROR("Failed to lunch wifi syspopup");
+                return -1;
+            }
+        } catch (runtime::Exception& e) {
+            ERROR("Failed to lunch wifi syspopup");
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+bool Wifi::isWifiStateChanegAllowed()
+{
+    return false;
+}
+
+int Wifi::setSettingChangesRestriction(bool restrict)
+{
+        return -1;
+}
+
+bool Wifi::isSettingChangesRestricted()
+{
+    return false;
+}
+
+int Wifi::setApSettingModificationRestriction(bool restrict)
+{
+    return -1;
+}
+
+bool Wifi::isApSettingModificationRestricted()
+{
+    return false;
+}
+
+int Wifi::setNetworkAccessRestriction(bool restrict)
+{
+    return -1;
+}
+
+bool Wifi::isNetworkAccessRestricted()
+{
+    return false;
+}
+
+int Wifi::addSsidFromBlacklist(const std::string& ssid)
+{
+    return -1;
+}
+
+int Wifi::removeSsidFromBlacklist(const std::string& ssid)
+{
+    return -1;
+}
+
+Wifi wifiPolicy(Server::instance());
+
+} // namespace DevicePolicyManager