From: Seonah Moon Date: Fri, 31 Mar 2017 07:18:06 +0000 (+0900) Subject: Added new APIs for IPv6 tethering X-Git-Tag: accepted/tizen/unified/20170406.173415~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F02%2F122402%2F2;p=platform%2Fcore%2Fapi%2Ftethering.git Added new APIs for IPv6 tethering Change-Id: I137d2dbcf63c6b94e638b7ae957b22563d0e3259 Signed-off-by: Seonah Moon --- diff --git a/include/tethering.h b/include/tethering.h index 26cf8f8..7ac67b1 100644 --- a/include/tethering.h +++ b/include/tethering.h @@ -71,8 +71,7 @@ typedef enum { * @brief Enumeration for the cause of disabling the tethering. * @since_tizen 2.3 */ -typedef enum -{ +typedef enum { TETHERING_DISABLED_BY_USB_DISCONNECTION = 0, /**< Disabled due to usb disconnection */ TETHERING_DISABLED_BY_FLIGHT_MODE, /**< Disabled due to flight mode */ TETHERING_DISABLED_BY_LOW_BATTERY, /**< Disabled due to low battery */ @@ -143,6 +142,7 @@ typedef void * tethering_client_h; */ typedef enum { TETHERING_ADDRESS_FAMILY_IPV4 = 0, /**< IPV4 Address type */ + TETHERING_ADDRESS_FAMILY_IPV6 = 1, /**< IPV6 Address type (Since 4.0) */ } tethering_address_family_e; /** @@ -317,6 +317,40 @@ int tethering_enable(tethering_h tethering, tethering_type_e type); int tethering_disable(tethering_h tethering, tethering_type_e type); /** + * @brief Enables the IPv6 tethering, asynchronously. + * @since_tizen 4.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @remarks It supports Wi-Fi tethering and BT tethering only. + * @param[in] tethering The tethering handle + * @param[in] type The tethering type + * @return 0 on success, otherwise negative error value + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @post tethering_enabled_cb() will be invoked. + * @see tethering_is_enabled() + * @see tethering_ipv6_disable() + */ +int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type); + +/** + * @brief Disables the IPv6 tethering, asynchronously. + * @since_tizen 4.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @remarks It supports Wi-Fi tethering and BT tethering only. + * @param[in] tethering The tethering handle + * @param[in] type The tethering type + * @return 0 on success, otherwise negative error value + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @post tethering_disabled_cb() will be invoked. + * @see tethering_is_enabled() + * @see tethering_ipv6_enable() + */ +int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type); + +/** * @brief Checks whether the tethering is enabled or not. * @since_tizen 2.3 * @privlevel platform diff --git a/include/tethering.xml b/include/tethering.xml deleted file mode 100755 index c76221e..0000000 --- a/include/tethering.xml +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/include/tethering_private.h b/include/tethering_private.h index 3999a72..f13abdc 100644 --- a/include/tethering_private.h +++ b/include/tethering_private.h @@ -84,8 +84,7 @@ extern "C" { #define TETHERING_USB_FEATURE "http://tizen.org/feature/network.tethering.usb" #define TETHERING_WIFI_FEATURE "http://tizen.org/feature/network.tethering.wifi" -typedef enum -{ +typedef enum { TETHERING_SUPPORTED_FEATURE, TETHERING_SUPPORTED_FEATURE_WIFI, TETHERING_SUPPORTED_FEATURE_BT, @@ -96,7 +95,7 @@ typedef enum #define CHECK_FEATURE_SUPPORTED(...) \ do { \ int rv = _tethering_check_feature_supported(__VA_ARGS__, NULL); \ - if(rv != TETHERING_ERROR_NONE) { \ + if (rv != TETHERING_ERROR_NONE) { \ return rv; \ } \ } while (0) @@ -117,7 +116,7 @@ int _tethering_check_feature_supported(const char* feature, ...); * Common configuration */ #define TETHERING_TYPE_MAX 5 /**< All, USB, Wi-Fi, BT, Wi-Fi AP */ -#define TETHERING_STR_INFO_LEN 20 /**< length of the ip or mac address */ +#define TETHERING_STR_INFO_LEN 40 /**< length of the ip or mac address */ /** * Mobile AP error code diff --git a/packaging/capi-network-tethering.spec b/packaging/capi-network-tethering.spec index 5520407..5c22614 100644 --- a/packaging/capi-network-tethering.spec +++ b/packaging/capi-network-tethering.spec @@ -1,6 +1,6 @@ Name: capi-network-tethering Summary: Tethering Framework -Version: 1.0.45 +Version: 1.0.46 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/tethering.c b/src/tethering.c index 9d55e54..c541c29 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -319,7 +319,7 @@ static tethering_error_e __get_error(int agent_error) err = TETHERING_ERROR_PERMISSION_DENIED; break; //LCOV_EXCL_STOP - default : + default: ERR("Not defined error : %d\n", agent_error); err = TETHERING_ERROR_OPERATION_FAILED; break; @@ -1301,7 +1301,7 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n", set->ssid, set->sec_type, set->mode, set->channel, - (set->visibility)?"true":"false"); + (set->visibility) ? "true" : "false"); INFO("-\n"); return TETHERING_ERROR_NONE; } @@ -1549,7 +1549,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id); g_dbus_proxy_call(proxy, "enable_wifi_tethering", - g_variant_new("(sssiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type), + g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, TETHERING_ADDRESS_FAMILY_IPV4), G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering); break; @@ -1616,6 +1616,120 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) return TETHERING_ERROR_NONE; } +API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type) +{ + DBG("+ type : %d\n", type); + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + GDBusProxy *proxy = th->client_bus_proxy; + GDBusConnection *connection = th->client_bus; + int ret = 0; + + g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE); + + if (__check_precondition(type) == FALSE) { + //LCOV_EXCL_START + DBG("-\n"); + return TETHERING_ERROR_OPERATION_FAILED; + //LCOV_EXCL_STOP + } + + switch (type) { + //LCOV_EXCL_START + case TETHERING_TYPE_WIFI: { + _softap_settings_t set = {"", "", "", 0, false, false, 0, 0}; + + ret = __prepare_wifi_settings(tethering, &set); + if (ret != TETHERING_ERROR_NONE) { + ERR("softap settings initialization failed\n"); + DBG("-\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id); + g_dbus_proxy_call(proxy, "enable_wifi_tethering", + g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, TETHERING_ADDRESS_FAMILY_IPV6), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering); + break; + } + case TETHERING_TYPE_BT: { + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_BT_TETHER_ON].sig_id); + + /* For TEST */ + g_dbus_proxy_call(proxy, "enable_bt_tethering", g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering); + + break; + } + + default: { + ERR("Unknown type : %d\n", type); + + g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT); + + DBG("-\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + } + + g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT); + DBG("-\n"); + return TETHERING_ERROR_NONE; +} + +API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type) +{ + DBG("+ type : %d\n", type); + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + GDBusProxy *proxy = th->client_bus_proxy; + GDBusConnection *connection = th->client_bus; + + switch (type) { + case TETHERING_TYPE_WIFI: + DBG("Disable wifi tethering.."); + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_wifi_tethering", + g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); + break; + case TETHERING_TYPE_BT: + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_BT_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_bt_tethering", + g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6), G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); + break; + + default: + ERR("Not supported tethering type [%d]\n", type); + DBG("-\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + DBG("-\n"); + return TETHERING_ERROR_NONE; +} /** * @internal * @brief Disables the tethering, asynchronously. @@ -1747,7 +1861,7 @@ API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type) ERR("Not supported type : %d\n", type); break; } - INFO("- enabled: %s\n",(is_on & vconf_type)? "true" : "false"); + INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false"); return is_on & vconf_type ? true : false; } diff --git a/test/tethering_test.c b/test/tethering_test.c index 3ec2b7a..a6880d7 100755 --- a/test/tethering_test.c +++ b/test/tethering_test.c @@ -72,6 +72,10 @@ static bool __is_err(tethering_error_e ret) err_msg = "Resource is busy"; break; + case TETHERING_ERROR_NOT_PERMITTED: + err_msg = "Operation is not permitted"; + break; + default: err_msg = "This should not be happened"; break; @@ -429,8 +433,11 @@ static void __print_interface_info(tethering_h th, tethering_type_e type) char *interface = NULL; char *mac_address = NULL; char *ip_address = NULL; + char *ip6_address = NULL; char *gateway_address = NULL; + char *gateway6_address = NULL; char *subnet_mask = NULL; + char *prefix = NULL; if (tethering_is_enabled(th, type) == FALSE) { g_print("%s is not enabled\n", @@ -442,16 +449,25 @@ static void __print_interface_info(tethering_h th, tethering_type_e type) tethering_get_mac_address(th, type, &mac_address); tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4, &ip_address); + tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV6, + &ip6_address); tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4, &gateway_address); + tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV6, + &gateway6_address); tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV4, &subnet_mask); + tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV6, + &prefix); g_print("interface name : %s\n", interface); g_print("mac address : %s\n", mac_address); - g_print("ip address : %s\n", ip_address); + g_print("IPv4 address : %s\n", ip_address); + g_print("IPv6 address : %s\n", ip6_address); g_print("gateway address: %s\n", gateway_address); + g_print("IPv6 gateway address: %s\n", gateway6_address); g_print("subnet mask : %s\n", subnet_mask); + g_print("IPv6 prefix : %s\n", prefix); if (interface) free(interface); @@ -459,10 +475,16 @@ static void __print_interface_info(tethering_h th, tethering_type_e type) free(mac_address); if (ip_address) free(ip_address); + if (ip6_address) + free(ip6_address); if (gateway_address) free(gateway_address); if (subnet_mask) free(subnet_mask); + if (gateway6_address) + free(gateway6_address); + if (prefix) + free(prefix); return; } @@ -648,11 +670,19 @@ static int test_tethering_enable(void) { int ret = TETHERING_ERROR_NONE; tethering_type_e type; + int address_type = 0; + + printf("IPv4: 0, IPv6: 1\n"); + ret = scanf("%d", &address_type); if (!__get_tethering_type(&type)) return -1; - ret = tethering_enable(th, type); + if (address_type) + ret = tethering_ipv6_enable(th, type); + else + ret = tethering_enable(th, type); + if (__is_err(ret) == true) { printf("Fail to enable tethering\n"); return -1; @@ -664,11 +694,19 @@ static int test_tethering_disable(void) { int ret = TETHERING_ERROR_NONE; tethering_type_e type; + int address_type = 0; + + printf("IPv4: 0, IPv6: 1\n"); + ret = scanf("%d", &address_type); if (!__get_tethering_type(&type)) return -1; - ret = tethering_disable(th, type); + if (address_type) + ret = tethering_ipv6_disable(th, type); + else + ret = tethering_disable(th, type); + if (__is_err(ret) == true) { printf("Fail to disable tethering\n"); return -1;