Added Wifi direct tethering feature for Tizen 4.0 08/128108/5 accepted/tizen/unified/20170608.184735 submit/tizen/20170608.074045
authorMilind Ramesh Murhekar <m.murhekar@samsung.com>
Fri, 5 May 2017 12:14:14 +0000 (17:44 +0530)
committerMilind Ramesh Murhekar <m.murhekar@samsung.com>
Wed, 31 May 2017 12:35:25 +0000 (18:05 +0530)
Description: This patch adds the wifi direct tethering
feature over p2p connection.

Change-Id: I4200f381de5c286f0d866ee13a670ff0c1577eb9
Signed-off-by: Milind Ramesh Murhekar <m.murhekar@samsung.com>
include/tethering.h
include/tethering_private.h
src/tethering.c
test/tethering_test.c

index 7ac67b1db154076a85aaa745b9ba6791168387ae..a1a466e99740f5932fbeb3357e02c6f536d61799 100644 (file)
@@ -65,6 +65,7 @@ typedef enum {
     TETHERING_TYPE_USB,  /**< USB type */
     TETHERING_TYPE_WIFI,  /**< Wi-Fi type */
     TETHERING_TYPE_BT,  /**< BT type */
+    TETHERING_TYPE_P2P,  /**< P2P type */
 } tethering_type_e;
 
 /**
index a1f3dff0319c7747354b58dbc149d01dfd11b37c..f05706f5f57ecee5f424b58b4b0990cc01c54bc2 100644 (file)
@@ -155,6 +155,9 @@ typedef enum {
        MOBILE_AP_ENABLE_BT_TETHERING_CFM,
        MOBILE_AP_DISABLE_BT_TETHERING_CFM,
 
+       MOBILE_AP_ENABLE_P2P_TETHERING_CFM,
+       MOBILE_AP_DISABLE_P2P_TETHERING_CFM,
+
        MOBILE_AP_GET_STATION_INFO_CFM,
        MOBILE_AP_GET_DATA_PACKET_USAGE_CFM
 } mobile_ap_event_e;
@@ -163,6 +166,7 @@ typedef enum {
        MOBILE_AP_TYPE_WIFI,
        MOBILE_AP_TYPE_USB,
        MOBILE_AP_TYPE_BT,
+       MOBILE_AP_TYPE_P2P,
        MOBILE_AP_TYPE_MAX,
 } mobile_ap_type_e;
 
index 0bad2978e71ba9c92007fea15e0baa4244cf5216..b190125d2c29c9191ef6c04457b82c897cdf0e62 100755 (executable)
@@ -906,6 +906,51 @@ static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
 }
 //LCOV_EXCL_STOP
 
+static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
+                                       gpointer user_data)
+{
+       DBG("+\n");
+
+       _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
+       __tethering_h *th = (__tethering_h *)user_data;
+       GError *g_error = NULL;
+       GVariant *g_var;
+       guint info;
+       tethering_error_e error;
+       tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_P2P];
+       void *data = th->enabled_user_data[TETHERING_TYPE_P2P];
+
+       g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
+       if (g_error) {
+               ERR("DBus error [%s]\n", g_error->message);
+               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_P2P);
+                       DBG("-\n");
+                       return;
+               }
+               if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       error = TETHERING_ERROR_PERMISSION_DENIED;
+               else
+                       error = TETHERING_ERROR_OPERATION_FAILED;
+               g_error_free(g_error);
+       } else {
+               g_variant_get(g_var, "(u)", &info);
+               g_variant_unref(g_var);
+               error = __get_error(info);
+       }
+       retry = 0;
+
+       if (!ecb) {
+               DBG("-\n");
+               return;
+       }
+
+       ecb(error, TETHERING_TYPE_P2P, true, data);
+       DBG("-\n");
+}
+
 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                gpointer user_data)
 {
@@ -978,6 +1023,14 @@ static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                break;
        //LCOV_EXCL_STOP
 
+       case MOBILE_AP_DISABLE_P2P_TETHERING_CFM:
+               type = TETHERING_TYPE_P2P;
+               dcb = th->disabled_cb[type];
+               data = th->disabled_user_data[type];
+               if (dcb)
+                       dcb(error, type, code, data);
+               break;
+
        case MOBILE_AP_DISABLE_CFM:
 
                sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
@@ -1557,7 +1610,22 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
 
                break;
 
-       //LCOV_EXCL_START
+       case TETHERING_TYPE_P2P: {
+               _softap_settings_t p2p_set = {"", "", "", 0, false};
+               ret = __prepare_wifi_settings(tethering, &p2p_set);
+               if (ret != TETHERING_ERROR_NONE) {
+                       ERR("p2p settings initialization failed\n");
+                       DBG("-\n");
+                       return TETHERING_ERROR_OPERATION_FAILED;
+               }
+
+               g_dbus_proxy_call(proxy, "enable_p2p_tethering",
+                               g_variant_new("(ssi)", p2p_set.ssid, p2p_set.key, p2p_set.channel),
+                               G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
+                               (GAsyncReadyCallback) __p2p_enabled_cfm_cb, (gpointer)tethering);
+               break;
+       }
+
        case TETHERING_TYPE_ALL: {
                _softap_settings_t set = {"", "", "", 0, false};
 
@@ -1789,6 +1857,12 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type)
                                (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
                break;
 
+       case TETHERING_TYPE_P2P:
+               g_dbus_proxy_call(proxy, "disable_p2p_tethering",
+                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
+                               (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
+               break;
+
        case TETHERING_TYPE_ALL:
                g_dbus_connection_signal_unsubscribe(connection,
                                sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
@@ -1857,6 +1931,10 @@ API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
                vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
                break;
 
+       case TETHERING_TYPE_P2P:
+               vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_P2P;
+               break;
+
        default:
                ERR("Not supported type : %d\n", type);
                break;
@@ -2333,7 +2411,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_BT; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
                th->enabled_cb[ti] = callback;
                th->enabled_user_data[ti] = user_data;
        }
@@ -2375,7 +2453,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_BT; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
                th->enabled_cb[ti] = NULL;
                th->enabled_user_data[ti] = NULL;
        }
@@ -2421,7 +2499,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_BT; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
                th->disabled_cb[ti] = callback;
                th->disabled_user_data[ti] = user_data;
        }
@@ -2462,7 +2540,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_BT; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
                th->disabled_cb[ti] = NULL;
                th->disabled_user_data[ti] = NULL;
        }
index ab65cda0daa1b7c0bc774e991bb7a0caf882fc01..a6d00f647c393d0a79a0b2b4c131c7bd5ab93884 100755 (executable)
@@ -107,6 +107,10 @@ static const char *__convert_tethering_type_to_str(const tethering_type_e type)
                g_strlcpy(str_buf, "Bluetooth Tethering", sizeof(str_buf));
                break;
 
+       case TETHERING_TYPE_P2P:
+               g_strlcpy(str_buf, "P2P Tethering", sizeof(str_buf));
+               break;
+
        default:
                g_strlcpy(str_buf, "Unknown", sizeof(str_buf));
                break;
@@ -609,7 +613,7 @@ bool __get_tethering_type(tethering_type_e *type)
        int sel;
        int ret;
 
-       printf("Select tethering type (1:Wi-Fi, 2:BT, 3:USB 4:ALL)\n");
+       printf("Select tethering type (1:Wi-Fi, 2:BT, 3:USB 4:P2P 5:ALL)\n");
        ret = scanf("%9d", &sel);
        if (ret < 0) {
                printf("scanf is failed!!\n");
@@ -627,6 +631,9 @@ bool __get_tethering_type(tethering_type_e *type)
                *type = TETHERING_TYPE_USB;
                break;
        case 4:
+               *type = TETHERING_TYPE_P2P;
+               break;
+       case 5:
                *type = TETHERING_TYPE_ALL;
                break;
        default: