From e90c9edbce32fb43dc5cefebb2d3e40d6b3fa448 Mon Sep 17 00:00:00 2001 From: Milind Ramesh Murhekar Date: Fri, 5 May 2017 17:44:14 +0530 Subject: [PATCH] Added Wifi direct tethering feature for Tizen 4.0 Description: This patch adds the wifi direct tethering feature over p2p connection. Change-Id: I4200f381de5c286f0d866ee13a670ff0c1577eb9 Signed-off-by: Milind Ramesh Murhekar --- include/tethering.h | 1 + include/tethering_private.h | 4 +++ src/tethering.c | 88 ++++++++++++++++++++++++++++++++++++++++++--- test/tethering_test.c | 9 ++++- 4 files changed, 96 insertions(+), 6 deletions(-) diff --git a/include/tethering.h b/include/tethering.h index 7ac67b1..a1a466e 100644 --- a/include/tethering.h +++ b/include/tethering.h @@ -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; /** diff --git a/include/tethering_private.h b/include/tethering_private.h index a1f3dff..f05706f 100644 --- a/include/tethering_private.h +++ b/include/tethering_private.h @@ -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; diff --git a/src/tethering.c b/src/tethering.c index 0bad297..b190125 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -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; } diff --git a/test/tethering_test.c b/test/tethering_test.c index ab65cda..a6d00f6 100755 --- a/test/tethering_test.c +++ b/test/tethering_test.c @@ -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: -- 2.7.4