From: Seonah Moon Date: Fri, 3 Jun 2016 05:35:51 +0000 (+0900) Subject: Apply dpm policy X-Git-Tag: accepted/tizen/common/20160607.194732^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F69%2F69369%2F8;p=platform%2Fcore%2Fconnectivity%2Fmobileap-agent.git Apply dpm policy Add dbus method to restrict tethering based on dpm policy Change-Id: If418a5b531a8ed15e7e226c4c7121e1197381544 Signed-off-by: Seonah Moon --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a63c0b5..63724ee 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/include/mobileap_common.h b/include/mobileap_common.h index 72b0b9d..6b07683 100755 --- a/include/mobileap_common.h +++ b/include/mobileap_common.h @@ -21,9 +21,14 @@ #include #include +#include "mobileap.h" #include "mobileap_softap.h" #include +#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__ */ diff --git a/include/mobileap_notification.h b/include/mobileap_notification.h index 0a1df75..ea74e5a 100644 --- a/include/mobileap_notification.h +++ b/include/mobileap_notification.h @@ -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 diff --git a/include/tethering-dbus-interface.xml b/include/tethering-dbus-interface.xml index f6495fa..7790aaa 100755 --- a/include/tethering-dbus-interface.xml +++ b/include/tethering-dbus-interface.xml @@ -137,6 +137,12 @@ + + + + + + diff --git a/src/mobileap_bluetooth.c b/src/mobileap_bluetooth.c index 44d068a..5abeed6 100755 --- a/src/mobileap_bluetooth.c +++ b/src/mobileap_bluetooth.c @@ -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); diff --git a/src/mobileap_common.c b/src/mobileap_common.c index 4177ede..27e371b 100755 --- a/src/mobileap_common.c +++ b/src/mobileap_common.c @@ -28,10 +28,16 @@ #include -#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; +} diff --git a/src/mobileap_main.c b/src/mobileap_main.c index 4209ac2..235cf65 100755 --- a/src/mobileap_main.c +++ b/src/mobileap_main.c @@ -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; diff --git a/src/mobileap_notification.c b/src/mobileap_notification.c index dbe78af..3094ec4 100644 --- a/src/mobileap_notification.c +++ b/src/mobileap_notification.c @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include #ifndef TIZEN_TV #include #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; +} diff --git a/src/mobileap_usb.c b/src/mobileap_usb.c index 4076246..52ccd31 100755 --- a/src/mobileap_usb.c +++ b/src/mobileap_usb.c @@ -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); diff --git a/src/mobileap_wifi.c b/src/mobileap_wifi.c index e4606dd..15c64f4 100755 --- a/src/mobileap_wifi.c +++ b/src/mobileap_wifi.c @@ -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);