Replace usage of enum 'TETHERING_TYPE_WIFI_SHARING'
[platform/core/api/tethering.git] / src / tethering.c
index d79c056..0fca757 100755 (executable)
 #define MAC_ADDR_LEN   18
 #define MAX_BUF_SIZE   80
 
+#ifdef TIZEN_TV_EXT
+#define VCONFKEY_WIFI_TXPOWER  "db/dnet/txpower" /**< VCONFKEY for TX Power */
+#define VCONFKEY_WIFI_CHANNEL  "db/dnet/channel" /**< VCONFKEY for Channel */
+#define VCONFKEY_WIFI_SSID     "db/dnet/ssid"        /**< VCONFKEY for ssid */
+
+#define DBUS_DEFAULT_REPLY_TIMEOUT 15000
+#endif /* TIZEN_TV_EXT */
+
 #define IPTABLES        "/usr/sbin/iptables"
 #define TABLE_NAT       "nat"
 #define TETH_NAT_PRE        "teth_nat_pre"
 #define FILTERING_MULTIPORT_RULE_STR    "-t %s -A %s -p %s -m multiport --dport %d,%d -j %s"
 #define FILTERING_RULE_STR  "-t %s -A %s -p %s --dport %d -j %s"
 
+typedef enum {
+       DUAL_BAND_NONE = 0,                     //0
+       DUAL_BAND_2G = 1 << 0,                  //1
+       DUAL_BAND_5G = 1 << 1,                  //2
+       DUAL_BAND_MIN_INTERFACE = 1 << 2,       //4
+       DUAL_BAND_ALL = 7,                      //7
+} supported_band_e;
+
 static GSList *allowed_list = NULL;
 static GSList *blocked_list = NULL;
 static GSList *port_forwarding = NULL;
@@ -127,7 +143,23 @@ static __tethering_sig_t sigs[] = {
        {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
 
 static int retry = 0;
+static int is_dualband_support = DUAL_BAND_NONE;
+
+static void  __reset_dualband_support(void)
+{
+       is_dualband_support = DUAL_BAND_NONE;
+}
 
+static void  __set_dualband_support(int band)
+{
+       is_dualband_support |= band;
+       return;
+}
+
+static gboolean  __is_dualband_support(void)
+{
+       return (is_dualband_support ==  DUAL_BAND_ALL) ? TRUE : FALSE;
+}
 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
 {
        if (conn == NULL || signal_name == NULL)
@@ -760,10 +792,12 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
        GError *g_error = NULL;
        GVariant *g_var;
        guint info;
+       tethering_type_e type = TETHERING_TYPE_WIFI;
        tethering_error_e error;
        __tethering_h *th = (__tethering_h *)user_data;
-       tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
-       void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
+
+       tethering_enabled_cb ecb = th->enabled_cb[type];
+       void *data = th->enabled_user_data[type];
 
        if (!_tethering_check_handle((tethering_h)user_data))
                return;
@@ -774,7 +808,7 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
                                ++retry < TETHERING_ERROR_RECOVERY_MAX) {
                        g_error_free(g_error);
-                       tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
+                       tethering_enable((tethering_h)th, type);
                        return;
                } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
                        error = TETHERING_ERROR_PERMISSION_DENIED;
@@ -800,7 +834,7 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                INFO("-\n");
                return;
        }
-       ecb(error, TETHERING_TYPE_WIFI, true, data);
+       ecb(error, type, true, data);
        g_variant_unref(g_var);
        INFO("-\n");
 }
@@ -1244,20 +1278,18 @@ static int __get_common_ssid(char *ssid, unsigned int size)
                return TETHERING_ERROR_INVALID_PARAMETER;
        }
 
-       char *ptr = NULL;
-       char *ptr_tmp = NULL;
+#ifdef TIZEN_TV_EXT
+       if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID, ssid, size))
+               return TETHERING_ERROR_NONE;
+       else
+               ERR("vconf key get failed for ssid or invalid ssid is found");
+#endif /* TIZEN_TV_EXT */
 
-       ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
-       if (ptr == NULL) {
+       if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
+                               ssid, size) == false) {
                ERR("vconf_get_str is failed and set default ssid");
                g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
-       } else
-               g_strlcpy(ssid, ptr, size);
-
-       free(ptr);
-
-       if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
-               *ptr_tmp = '\0';
+       }
 
        return TETHERING_ERROR_NONE;
 }
@@ -1364,7 +1396,7 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se
        return TETHERING_ERROR_NONE;
 }
 
-static bool __check_precondition(tethering_type_e type)
+static bool __check_precondition(__tethering_h *th, tethering_type_e type)
 {
        int dnet_status = 0;
        int cellular_state = 0;
@@ -1380,6 +1412,8 @@ static bool __check_precondition(tethering_type_e type)
        vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
        if ((dnet_status == VCONFKEY_NETWORK_WIFI
                        && type != TETHERING_TYPE_WIFI)
+               || (th->wifi_sharing && dnet_status == VCONFKEY_NETWORK_WIFI
+                       && type == TETHERING_TYPE_WIFI)
                || dnet_status == VCONFKEY_NETWORK_ETHERNET)
                return TRUE;
 
@@ -1387,6 +1421,32 @@ static bool __check_precondition(tethering_type_e type)
        return FALSE;
 }
 
+#ifdef TIZEN_TV_EXT
+static void __set_vconf_values_for_tv(__tethering_h *tethering)
+{
+       int ret, channel, txpower;
+       __tethering_h *th = tethering;
+
+       if (th == NULL)
+               return;
+
+       ret = vconf_get_int(VCONFKEY_WIFI_CHANNEL, &channel);
+       if (ret < 0) {
+               ERR("vconf key get failed for channel !!");
+               channel = TETHERING_WIFI_CHANNEL;
+       }
+
+       ret = vconf_get_int(VCONFKEY_WIFI_TXPOWER, &txpower);
+       if (ret < 0) {
+               ERR("vconf key get failed for txpower !!");
+               txpower = TETHERING_WIFI_MAX_TXPOWER;
+       }
+
+       th->channel = channel;
+       th->txpower = txpower;
+}
+#endif /* TIZEN_TV_EXT */
+
 /**
  * @internal
  * @brief  Creates the handle of tethering.
@@ -1421,6 +1481,7 @@ API int tethering_create(tethering_h *tethering)
        th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
        th->visibility = true;
        th->mac_filter = false;
+       th->wifi_sharing = false;
        th->channel = TETHERING_WIFI_CHANNEL;
        th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
        th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
@@ -1439,6 +1500,9 @@ API int tethering_create(tethering_h *tethering)
                return TETHERING_ERROR_OPERATION_FAILED;
        }
 
+#ifdef TIZEN_TV_EXT
+       __set_vconf_values_for_tv(th);
+#endif /* TIZEN_TV_EXT */
        SINFO("ssid: %s, key: %s, channel: %d, mode: %d, txpower: %d, security: %d max_device: %d\n",
                 ssid, th->passphrase, th->channel, th->mode_type, th->txpower, th->sec_type,
                 th->wifi_max_connected);
@@ -1551,9 +1615,13 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
        GDBusProxy *proxy = th->client_bus_proxy;
        GDBusConnection *connection = th->client_bus;
 
+#ifdef TIZEN_TV_EXT
+       g_dbus_proxy_set_default_timeout(proxy, DBUS_DEFAULT_REPLY_TIMEOUT);
+#else /* TIZEN_TV_EXT */
        g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
+#endif /* TIZEN_TV_EXT */
 
-       if (__check_precondition(type) == FALSE) {
+       if (__check_precondition(th, type) == FALSE) {
                INFO("-\n");
                g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
                return TETHERING_ERROR_OPERATION_FAILED;
@@ -1586,8 +1654,15 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
                         set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
                         set.max_connected);
 
+               char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = "wifi_tether";
+               if (th->wifi_sharing)
+                       g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN + 1);
+
+               SINFO("enable_wifi_tethering key: %s", key);
                g_dbus_proxy_call(proxy, "enable_wifi_tethering",
-                               g_variant_new("(sssiiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
+                               g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
+                               set.channel, set.visibility, set.mac_filter, set.max_connected,
+                               set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
                                G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
                break;
@@ -1645,9 +1720,9 @@ 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("(sssiiiiii)", set.ssid, set.key, set.mode,
+                               g_variant_new("(ssssiiiiiii)", "wifi_tether", set.ssid, set.key, set.mode,
                                set.channel, set.visibility, set.mac_filter, set.max_connected,
-                               set.sec_type, TETHERING_ADDRESS_FAMILY_IPV4),
+                               set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
                                G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
 
@@ -1693,7 +1768,7 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
 
        g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
 
-       if (__check_precondition(type) == FALSE) {
+       if (__check_precondition(th, type) == FALSE) {
                DBG("-\n");
                g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
                return TETHERING_ERROR_OPERATION_FAILED;
@@ -1728,10 +1803,17 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
                        set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
                        set.max_connected);
 
+               char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = "wifi_tether";
+               if (th->wifi_sharing)
+                       g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN + 1);
+
+               SINFO("enable_wifi_tethering key: %s", key);
                g_dbus_proxy_call(proxy, "enable_wifi_tethering",
-                       g_variant_new("(sssiiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV6),
-                       G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
-                       (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
+                               g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
+                               set.channel, set.visibility, set.mac_filter, set.max_connected,
+                               set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV6),
+                               G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
+                               (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
                break;
         }
 
@@ -1860,12 +1942,13 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type)
                break;
 
        case TETHERING_TYPE_WIFI:
-
                g_dbus_connection_signal_unsubscribe(connection,
                                sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
 
+               SINFO("Disable Wi-Fi Tethering !");
+
                g_dbus_proxy_call(proxy, "disable_wifi_tethering",
-                               g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
+                               g_variant_new("(ii)", TETHERING_ADDRESS_FAMILY_IPV4, th->mode_type),
                                G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
                break;
@@ -2296,6 +2379,72 @@ API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb
  * @see  tethering_is_enabled()
  * @see  tethering_enable()
  */
+
+API int tethering_is_dualband_supported(tethering_h tethering, tethering_type_e type, bool *supported)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+       CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+
+       __tethering_h *th = (__tethering_h *)tethering;
+       gchar *if_name = NULL;
+       gboolean Is2GBandSupported = FALSE;
+       gboolean Is5GBandSupported = FALSE;
+       GError *error = NULL;
+       GVariant *result = NULL;
+       GVariantIter *outer_iter = NULL;
+       GVariantIter *inner_iter = NULL;
+       GVariant *station = NULL;
+       GVariant *value = NULL;
+       gchar *key = NULL;
+       int count = 0;
+
+       DBG("+");
+       __reset_dualband_support();
+       result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_wifi_interfaces",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+               g_error_free(error);
+               return TETHERING_ERROR_OPERATION_FAILED;
+       }
+       g_variant_get(result, "(a(a{sv}))", &outer_iter);
+       while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
+               g_variant_get(station, "a{sv}", &inner_iter);
+               while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
+                       if (g_strcmp0(key, "IfName") == 0) {
+                               g_variant_get(value, "s", &if_name);
+                               SDBG("Interface Name is %s\n", if_name);
+                       } else if (g_strcmp0(key, "Is2GBandSupported") == 0) {
+                               Is2GBandSupported = g_variant_get_boolean(value);
+                               SDBG("Is2GBandSupported  is %d\n", Is2GBandSupported);
+                               if (Is2GBandSupported)
+                                       __set_dualband_support(DUAL_BAND_2G);
+                       } else if (g_strcmp0(key, "Is5GBandSupported") == 0) {
+                               Is5GBandSupported = g_variant_get_boolean(value);
+                               SDBG("Is5GBandSupported  is %d\n", Is5GBandSupported);
+                               if (Is5GBandSupported)
+                                       __set_dualband_support(DUAL_BAND_5G);
+                       } else {
+                               ERR("Key %s not required\n", key);
+                       }
+               }
+               count++;
+
+               g_variant_iter_free(inner_iter);
+       }
+       if (count >= 2)
+               __set_dualband_support(DUAL_BAND_MIN_INTERFACE);
+       *supported =  __is_dualband_support();
+       DBG("count:%d is dualband suppport: %d", count, *supported);
+       g_variant_iter_free(outer_iter);
+       g_variant_unref(result);
+       DBG("-\n");
+       return TETHERING_ERROR_NONE;
+}
 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
 {
        CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
@@ -2312,6 +2461,7 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                        "tethering is not enabled\n");
 
        mobile_ap_type_e interface;
+       tethering_band_e band;
        __tethering_h *th = (__tethering_h *)tethering;
        __tethering_client_h client = {0, };
        gchar *ip = NULL;
@@ -2379,6 +2529,10 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                                timestamp = g_variant_get_int32(value);
                                DBG("timestamp is %d\n", timestamp);
                                client.tm = (time_t)timestamp;
+                       } else if (g_strcmp0(key, "Band") == 0) {
+                               band = g_variant_get_int32(value);
+                               client.band = (!band) ? TETHERING_WIFI_BAND_2G : TETHERING_WIFI_BAND_5G;
+                               SDBG("band type %d\n", band);
                        } else {
                                ERR("Key %s not required\n", key);
                        }
@@ -2392,6 +2546,11 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                mac = NULL;
 
                g_variant_iter_free(inner_iter);
+               if ((th->mode_type == 0 || th->mode_type == 1) && client.band != TETHERING_WIFI_BAND_2G) //if band is not for 2g continue
+                       continue;
+               if ((th->mode_type == 2 || th->mode_type == 3) && client.band != TETHERING_WIFI_BAND_5G) //if band is not for 5g continue
+                       continue;
+               SDBG("mode_type: %d and client.band: %d ", th->mode_type, client.band);
                if (callback((tethering_client_h)&client, user_data) == false) {
                        DBG("iteration is stopped\n");
                        g_free(client.hostname);
@@ -2448,7 +2607,7 @@ API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, t
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
                th->enabled_cb[ti] = callback;
                th->enabled_user_data[ti] = user_data;
        }
@@ -2490,7 +2649,7 @@ API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
                th->enabled_cb[ti] = NULL;
                th->enabled_user_data[ti] = NULL;
        }
@@ -2536,7 +2695,7 @@ API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type,
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
                th->disabled_cb[ti] = callback;
                th->disabled_user_data[ti] = user_data;
        }
@@ -2577,7 +2736,7 @@ API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
                th->disabled_cb[ti] = NULL;
                th->disabled_user_data[ti] = NULL;
        }
@@ -2623,7 +2782,7 @@ API int tethering_set_connection_state_changed_cb(tethering_h tethering, tetheri
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
                th->changed_cb[ti] = callback;
                th->changed_user_data[ti] = user_data;
        }
@@ -2664,7 +2823,7 @@ API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethe
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
                th->changed_cb[ti] = NULL;
                th->changed_user_data[ti] = NULL;
        }
@@ -2964,6 +3123,35 @@ API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
        _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
                        "strdup is failed\n");
 
+#ifdef TIZEN_TV_EXT
+       GDBusProxy *proxy = th->client_bus_proxy;
+       GVariant *parameters;
+       GError *error = NULL;
+       tethering_error_e ret = TETHERING_ERROR_NONE;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_ssid",
+                       g_variant_new("(s)", ssid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       ret = TETHERING_ERROR_PERMISSION_DENIED;
+               else
+                       ret = TETHERING_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               return ret;
+       }
+
+       if (parameters != NULL) {
+               g_variant_get(parameters, "(u)", &ret);
+               g_variant_unref(parameters);
+       }
+
+       SINFO("set tethering ssid : %s", ssid);
+#endif /* TIZEN_TV_EXT */
+
        if (th->ssid)
                free(th->ssid);
        th->ssid = p_ssid;
@@ -3000,6 +3188,15 @@ API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
        __tethering_h *th = (__tethering_h *)tethering;
        char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
 
+#ifdef TIZEN_TV_EXT
+       if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID,
+                                       val, sizeof(val)) == true) {
+               *ssid = strdup(val);
+               SINFO("get tethering ssid : %s", *ssid);
+               return TETHERING_ERROR_NONE;
+       }
+#endif /* TIZEN_TV_EXT */
+
        if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
                if (th->ssid != NULL) {
                        DBG("Private SSID is set\n");
@@ -3224,6 +3421,36 @@ API int tethering_wifi_set_channel(tethering_h tethering, int channel)
                        "parameter(tethering) is NULL\n");
 
        __tethering_h *th = (__tethering_h *)tethering;
+
+#ifdef TIZEN_TV_EXT
+       GDBusProxy *proxy = th->client_bus_proxy;
+       GVariant *parameters;
+       GError *error = NULL;
+       tethering_error_e ret = TETHERING_ERROR_NONE;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_channel",
+                       g_variant_new("(i)", channel), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       ret = TETHERING_ERROR_PERMISSION_DENIED;
+               else
+                       ret = TETHERING_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               return ret;
+       }
+
+       if (parameters != NULL) {
+               g_variant_get(parameters, "(u)", &ret);
+               g_variant_unref(parameters);
+       }
+
+       SINFO("set channel : %d", channel);
+#endif /* TIZEN_TV_EXT */
+
        th->channel = channel;
 
        return TETHERING_ERROR_NONE;
@@ -3241,7 +3468,48 @@ API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
                        "parameter(channel) is NULL\n");
 
        __tethering_h *th = (__tethering_h *)tethering;
+#ifdef TIZEN_TV_EXT
+       GDBusProxy *proxy = th->client_bus_proxy;
+       GVariant *parameters;
+       GError *error = NULL;
+       int ch, vconf_channel;
+       tethering_error_e ret = TETHERING_ERROR_NONE;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_channel",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       ret = TETHERING_ERROR_PERMISSION_DENIED;
+               else
+                       ret = TETHERING_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               return ret;
+       }
+
+       if (parameters != NULL) {
+               g_variant_get(parameters, "(iu)", &ch, &ret);
+               g_variant_unref(parameters);
+       }
+
+       if (ch < 0) {
+               ERR("failed to get Hostapd channel, set th->channel");
+               *channel = th->channel;
+       } else
+               *channel = ch;
+
+       if (vconf_get_int(VCONFKEY_WIFI_CHANNEL, &vconf_channel) < 0)
+               ERR("Failed to get vconf key for channel");
+       else
+               *channel = vconf_channel;
+
+       SINFO("get tethering channel : %d", *channel);
+#else /* TIZEN_TV_EXT */
        *channel = th->channel;
+#endif /* TIZEN_TV_EXT */
 
        return TETHERING_ERROR_NONE;
 }
@@ -4302,4 +4570,98 @@ API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
        return TETHERING_ERROR_NONE;
 }
 
+API int tethering_wifi_is_sharing_supported(tethering_h tethering, bool *supported)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+       CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+       _retvm_if(supported == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(supported) is NULL\n");
+
+       /** Check if wifi-sharing is supported */
+       __tethering_h *th = (__tethering_h *)tethering;
+       GDBusProxy *proxy = th->client_bus_proxy;
+
+       int ret = TETHERING_ERROR_NONE;
+       int count = 0;
+       gchar *key = NULL;
+       GVariant *value = NULL;
+       GVariantIter *iter = NULL;
+       GVariantIter *sub_iter = NULL;
+       GVariant *parameters = NULL;
+       GError *error = NULL;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_interfaces",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (!parameters && error) {
+               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       ret = TETHERING_ERROR_PERMISSION_DENIED;
+               else
+                       ret = TETHERING_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               goto error;
+       }
+
+       g_variant_get(parameters, "(a(a{sv}))", &iter);
+       if (iter == NULL) {
+               g_variant_unref(parameters);
+               ret = TETHERING_ERROR_OPERATION_FAILED;
+               goto error;
+       }
+
+       while (g_variant_iter_loop(iter, "(a{sv})", &sub_iter)) {
+               while (g_variant_iter_loop(sub_iter, "{sv}", &key, &value)) {
+                       if (g_strcmp0(key, "IfName") == 0) {
+                               const gchar *interface = g_variant_get_string(value, NULL);
+                               ERR("interface: %s\n", interface);
+                               if (strncmp(interface, "wlan", 4) == 0)
+                                       count++;
+                       }
+               }
+       }
+       g_variant_unref(parameters);
+
+       if (count > 1)
+               *supported = true;
+       else
+               *supported = false;
+
+error:
+       return ret;
+}
+
+API int tethering_wifi_set_sharing(tethering_h tethering, bool sharing)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+       CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+
+       __tethering_h *th = (__tethering_h *)tethering;
+       th->wifi_sharing = sharing;
+
+       return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_sharing(tethering_h tethering, bool *sharing)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+       CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+       _retvm_if(sharing == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(sharing) is NULL\n");
 
+       __tethering_h *th = (__tethering_h *)tethering;
+       *sharing = th->wifi_sharing;
+
+       return TETHERING_ERROR_NONE;
+}