Apply dpm policy 69/69369/8 accepted/tizen/common/20160607.194732 accepted/tizen/ivi/20160607.235424 accepted/tizen/mobile/20160607.235401 accepted/tizen/tv/20160607.235415 accepted/tizen/wearable/20160607.235349 submit/tizen/20160607.090155
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 3 Jun 2016 05:35:51 +0000 (14:35 +0900)
committerseonah moon <seonah1.moon@samsung.com>
Tue, 7 Jun 2016 02:18:12 +0000 (19:18 -0700)
Add dbus method to restrict tethering based on dpm policy

Change-Id: If418a5b531a8ed15e7e226c4c7121e1197381544
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
CMakeLists.txt
include/mobileap_common.h
include/mobileap_notification.h
include/tethering-dbus-interface.xml
src/mobileap_bluetooth.c
src/mobileap_common.c
src/mobileap_main.c
src/mobileap_notification.c
src/mobileap_usb.c
src/mobileap_wifi.c

index a63c0b5..63724ee 100755 (executable)
@@ -29,7 +29,8 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 INCLUDE_DIRECTORIES(${INCLUDE_DIR} ${CMAKE_SOURCE_DIR})
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED gio-2.0 gio-unix-2.0 dbus-1 dlog  deviced vconf notification capi-network-connection capi-network-bluetooth appcore-common capi-network-wifi capi-network-wifi-direct alarm-service appsvc libcrypto key-manager libtzplatform-config)
+pkg_check_modules(pkgs REQUIRED gio-2.0 gio-unix-2.0 dbus-1 dlog  deviced vconf notification capi-network-connection capi-network-bluetooth syspopup-caller
+               appcore-common capi-network-wifi capi-network-wifi-direct alarm-service appsvc libcrypto key-manager libtzplatform-config)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 72b0b9d..6b07683 100755 (executable)
 #include <glib.h>
 #include <gio/gio.h>
 
+#include "mobileap.h"
 #include "mobileap_softap.h"
 #include <mobileap-agent-server-stub.h>
 
+#define DPM_POLICY_WIFI_TETHERING      "wifi-hotspot"
+#define DPM_POLICY_USB_TETHERING       "usb-tethering"
+#define DPM_POLICY_BT_TETHERING                "bluetooth-tethering"
+
 gint _slist_find_station_by_interface(gconstpointer a, gconstpointer b);
 gint _slist_find_station_by_mac(gconstpointer a, gconstpointer b);
 gint _slist_find_station_by_ip_addr(gconstpointer a, gconstpointer b);
@@ -45,6 +50,12 @@ int _del_routing_rule(const char *interface);
 int _flush_ip_address(const char *interface);
 int _execute_command(const char *cmd);
 int _get_tethering_type_from_ip(const char *ip, mobile_ap_type_e *type);
+
+/* DPM */
+gboolean tethering_change_policy(Tethering *obj, GDBusMethodInvocation *context, gchar *name, gboolean state, void *user_data);
+int _is_allowed(mobile_ap_type_e type);
+
 Tethering *_get_tethering_obj(void);
 Softap *_get_softap_obj(void);
+
 #endif /* __MOBILEAP_COMMON_H__ */
index 0a1df75..ea74e5a 100644 (file)
@@ -24,9 +24,9 @@
 
 #include "mobileap.h"
 
+#define NETPOPUP                               "net-popup"
 #define MH_NOTI_STR_MAX                        50
 #define MH_NOTI_PATH_MAX               256
-
 #define MH_NOTI_ICON_PATH              tzplatform_mkpath(TZ_SYS_RO_UG, "/res/images/ug-setting-mobileap-efl")
 #define MH_NOTI_ICON_BT                        "noti_tethering_bluetooth.png"
 #define MH_NOTI_ICON_GENERAL   "noti_tethering_general.png"
@@ -55,4 +55,5 @@ int _update_connected_noti(mobile_ap_type_e type, int count);
 int _delete_connected_noti(void);
 void _create_tethering_active_noti(void);
 void _create_bt_tethering_active_noti(void);
+void _create_security_restriction_noti(mobile_ap_type_e type);
 #endif
index f6495fa..7790aaa 100755 (executable)
                <method name="hostapd_get_txpower">
                        <arg type="u" name="result" direction="out"/>
                </method>
+
+               <method name="change_policy">
+                       <arg type="s" name="name" direction="in"/>
+                       <arg type="b" name="state" direction="in"/>
+                       <arg type="u" name="result" direction="out"/>
+               </method>
                <!-- Signal (D-Bus) definitions -->
                <signal name="net_closed">
                </signal>
index 44d068a..5abeed6 100755 (executable)
@@ -539,6 +539,13 @@ gboolean tethering_enable_bt_tethering(Tethering *obj,
 
        g_context = context;
 
+       if (!_is_allowed(MOBILE_AP_TYPE_BT)) {
+               DBG("DPM policy restricts BT tethering\n");
+               ret = MOBILE_AP_ERROR_NOT_PERMITTED;
+               _create_security_restriction_noti(MOBILE_AP_TYPE_BT);
+               goto DONE;
+       }
+
        _block_device_sleep();
 
        ret = __init_bt(obj);
index 4177ede..27e371b 100755 (executable)
 
 #include <dbus/dbus.h>
 
-#include "mobileap_notification.h"
 #include "mobileap_common.h"
+#include "mobileap_wifi.h"
+#include "mobileap_bluetooth.h"
+#include "mobileap_usb.h"
+#include "mobileap_notification.h"
 
 static GSList *station_list = NULL;
+static bool allow_wifi_tethering = true;
+static bool allow_bt_tethering = true;
+static bool allow_usb_tethering = true;
 
 gint _slist_find_station_by_interface(gconstpointer a, gconstpointer b)
 {
@@ -557,3 +563,64 @@ int _get_tethering_type_from_ip(const char *ip, mobile_ap_type_e *type)
 
        return MOBILE_AP_ERROR_INVALID_PARAM;
 }
+
+gboolean tethering_change_policy(Tethering *obj, GDBusMethodInvocation *context, gchar *name, gboolean state, void *user_data)
+{
+       bool allowed = false;
+       int mobileap_state = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
+
+       DBG("%s dpm policy is %d", name, state);
+       if (state)
+               allowed = true;
+
+       if (!strcmp(name, DPM_POLICY_WIFI_TETHERING)) {
+                       vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &mobileap_state);
+               if (!allowed && (mobileap_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)) {
+                       _create_security_restriction_noti(MOBILE_AP_TYPE_WIFI);
+                       _disable_wifi_tethering(obj);
+                       tethering_emit_wifi_off(obj, NULL);
+               }
+               allow_wifi_tethering = allowed;
+       } else if (!strcmp(name, DPM_POLICY_USB_TETHERING)) {
+                       vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &mobileap_state);
+               if (!allowed && (mobileap_state & VCONFKEY_MOBILE_HOTSPOT_MODE_USB)) {
+                       _create_security_restriction_noti(MOBILE_AP_TYPE_USB);
+                       _disable_usb_tethering(obj);
+                       tethering_emit_usb_off(obj, NULL);
+               }
+               allow_usb_tethering = allowed;
+       } else if (!strcmp(name, DPM_POLICY_BT_TETHERING)) {
+                       vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &mobileap_state);
+               if (!allowed && (mobileap_state & VCONFKEY_MOBILE_HOTSPOT_MODE_BT)) {
+                       _create_security_restriction_noti(MOBILE_AP_TYPE_BT);
+                       _disable_bt_tethering(obj);
+                       tethering_emit_bluetooth_off(obj, NULL);
+               }
+               allow_bt_tethering = allowed;
+       }
+
+       tethering_complete_change_policy(obj, context, MOBILE_AP_ERROR_NONE);
+
+       return TRUE;
+}
+
+int _is_allowed(mobile_ap_type_e type)
+{
+       bool allowed = false;
+
+       switch (type) {
+       case MOBILE_AP_TYPE_WIFI:
+               allowed = allow_wifi_tethering;
+               break;
+       case MOBILE_AP_TYPE_USB:
+               allowed = allow_usb_tethering;
+               break;
+       case MOBILE_AP_TYPE_BT:
+               allowed = allow_bt_tethering;
+               break;
+       default:
+               break;
+       }
+
+       return allowed;
+}
index 4209ac2..235cf65 100755 (executable)
@@ -545,6 +545,10 @@ static void on_bus_acquired_cb(GDBusConnection *connection, const gchar *name,
        g_signal_connect(tethering_obj, "handle-dhcp-range",
                        G_CALLBACK(tethering_dhcp_range), NULL);
 
+       /* DPM */
+       g_signal_connect(tethering_obj, "handle-change-policy",
+                       G_CALLBACK(tethering_change_policy), NULL);
+
        g_signal_connect(softap_obj, "handle-enable",
                        G_CALLBACK(softap_enable), NULL);
        g_signal_connect(softap_obj, "handle-disable",
@@ -615,6 +619,7 @@ static int __tethering_setup_gdbus(void)
        }
        return 0;
 }
+
 int main(int argc, char **argv)
 {
        int ret = 0;
index dbe78af..3094ec4 100644 (file)
@@ -24,7 +24,9 @@
 #include <notification_text_domain.h>
 #include <notification_internal.h>
 #include <bluetooth.h>
+#include <bundle.h>
 #include <bundle_internal.h>
+#include <syspopup_caller.h>
 #ifndef TIZEN_TV
 #include <appsvc.h>
 #endif
@@ -545,3 +547,40 @@ void _create_bt_tethering_active_noti(void)
 
        return;
 }
+
+void _create_security_restriction_noti(mobile_ap_type_e type)
+{
+       bundle *b = NULL;
+       char restricted_type[MAX_BUF_SIZE] = {0, };
+       int ret;
+
+       switch (type) {
+       case MOBILE_AP_TYPE_WIFI:
+               g_strlcpy(restricted_type, "wifi tethering", MAX_BUF_SIZE - 1);
+               break;
+       case MOBILE_AP_TYPE_USB:
+               g_strlcpy(restricted_type, "usb tethering", MAX_BUF_SIZE - 1);
+               break;
+       case MOBILE_AP_TYPE_BT:
+               g_strlcpy(restricted_type, "bt tethering", MAX_BUF_SIZE - 1);
+               break;
+       default:
+               ERR("Invalid type.\n");
+               return;
+       }
+
+       b = bundle_create();
+
+       bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup");
+       bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
+       bundle_add(b, "_RESTRICTED_TYPE_", restricted_type);
+
+       DBG("Launch security restriction alert network popup");
+       ret = syspopup_launch(NETPOPUP, b);
+       if (ret < 0)
+               ERR("Fail to launch syspopup");
+
+       bundle_free(b);
+
+       return;
+}
index 4076246..52ccd31 100755 (executable)
@@ -392,6 +392,13 @@ gboolean tethering_enable_usb_tethering(Tethering *obj, GDBusMethodInvocation *c
 
        g_context = context;
 
+       if (!_is_allowed(MOBILE_AP_TYPE_USB)) {
+               DBG("DPM policy restricts USB tethering\n");
+               ret = MOBILE_AP_ERROR_NOT_PERMITTED;
+               _create_security_restriction_noti(MOBILE_AP_TYPE_USB);
+               goto DONE;
+       }
+
        ret = _enable_usb_tethering(obj);
        if (ret != MOBILE_AP_ERROR_NONE) {
                ERR("_enable_usb_tethering() is failed : %d\n", ret);
index e4606dd..15c64f4 100755 (executable)
@@ -901,6 +901,13 @@ gboolean tethering_enable_wifi_tethering(Tethering *obj,
        }
        g_context = context;
 
+       if (!_is_allowed(MOBILE_AP_TYPE_WIFI)) {
+               DBG("DPM policy restricts Wi-Fi tethering\n");
+               ret = MOBILE_AP_ERROR_NOT_PERMITTED;
+               _create_security_restriction_noti(MOBILE_AP_TYPE_WIFI);
+               goto DONE;
+       }
+
        wifi_settings.ssid = g_strdup(ssid);
        if (security_type == SOFTAP_SECURITY_TYPE_WPA2_PSK) {
                wifi_settings.key = g_strdup(key);