Add gtest for line coverage
[platform/core/api/tethering.git] / src / tethering.c
index d159e5a..bf4551c 100755 (executable)
@@ -14,6 +14,7 @@
 * limitations under the License.
 */
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -26,8 +27,6 @@
 #include <dbus/dbus.h>
 #include <gio/gio.h>
 #include <vconf.h>
-#include <openssl/evp.h>
-#include <openssl/sha.h>
 #include <ckmc/ckmc-manager.h>
 #include <tzplatform_config.h>
 #include "tethering_private.h"
@@ -132,7 +131,7 @@ static int retry = 0;
 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
 {
        if (conn == NULL || signal_name == NULL)
-               return; //LCOV_EXCL_LINE
+               return;
 
        GVariant *message = NULL;
        GError *error = NULL;
@@ -143,17 +142,17 @@ static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, c
        g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
                                        TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
        if (error) {
-               ERR("g_dbus_connection_emit_signal is failed because  %s\n", error->message); //LCOV_EXCL_LINE
-               g_error_free(error); //LCOV_EXCL_LINE
+               ERR("g_dbus_connection_emit_signal is failed because  %s\n", error->message);
+               g_error_free(error);
        }
-       g_variant_unref(message);
 }
 
 static bool __any_tethering_is_enabled(tethering_h tethering)
 {
        if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
                        tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
-                       tethering_is_enabled(tethering, TETHERING_TYPE_BT))
+                       tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
+                       tethering_is_enabled(tethering, TETHERING_TYPE_P2P))
                return true;
 
        return false;
@@ -163,7 +162,8 @@ static tethering_error_e __set_security_type(const tethering_wifi_security_type_
 {
        if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
                        security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
-                       security_type != TETHERING_WIFI_SECURITY_TYPE_WPS) {
+                       security_type != TETHERING_WIFI_SECURITY_TYPE_WPS &&
+                       security_type != TETHERING_WIFI_SECURITY_TYPE_SAE) {
                ERR("Invalid param\n");
                return TETHERING_ERROR_INVALID_PARAMETER;
        }
@@ -271,11 +271,9 @@ static tethering_error_e __get_error(int agent_error)
                err = TETHERING_ERROR_NONE;
                break;
 
-       //LCOV_EXCL_START
        case MOBILE_AP_ERROR_RESOURCE:
                err = TETHERING_ERROR_OUT_OF_MEMORY;
                break;
-       //LCOV_EXCL_STOP
 
        case MOBILE_AP_ERROR_INTERNAL:
                err = TETHERING_ERROR_OPERATION_FAILED;
@@ -309,7 +307,6 @@ static tethering_error_e __get_error(int agent_error)
                err = TETHERING_ERROR_OPERATION_FAILED;
                break;
 
-       //LCOV_EXCL_START
        case MOBILE_AP_ERROR_NOT_PERMITTED:
                err = TETHERING_ERROR_NOT_PERMITTED;
                break;
@@ -317,7 +314,6 @@ static tethering_error_e __get_error(int agent_error)
        case MOBILE_AP_ERROR_PERMISSION_DENIED:
                err = TETHERING_ERROR_PERMISSION_DENIED;
                break;
-       //LCOV_EXCL_STOP
        default:
                ERR("Not defined error : %d\n", agent_error);
                err = TETHERING_ERROR_OPERATION_FAILED;
@@ -327,7 +323,6 @@ static tethering_error_e __get_error(int agent_error)
        return err;
 }
 
-//LCOV_EXCL_START
 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
                const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
                GVariant *parameters, gpointer user_data)
@@ -367,6 +362,8 @@ static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
                type = TETHERING_TYPE_WIFI;
        else if (ap_type == MOBILE_AP_TYPE_BT)
                type = TETHERING_TYPE_BT;
+       else if (ap_type == MOBILE_AP_TYPE_P2P)
+               type = TETHERING_TYPE_P2P;
        else {
                ERR("Not supported tethering type [%d]\n", ap_type);
                goto DONE;
@@ -393,9 +390,7 @@ DONE:
        g_free(name);
        DBG("-\n");
 }
-//LCOV_EXCL_STOP
 
-//LCOV_EXCL_START
 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
                const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
                GVariant *parameters, gpointer user_data)
@@ -421,7 +416,6 @@ static void __handle_net_closed(GDBusConnection *connection, const gchar *sender
 
        DBG("-\n");
 }
-//LCOV_EXCL_STOP
 
 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
                        const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
@@ -477,7 +471,6 @@ static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *s
        DBG("-\n");
 }
 
-//LCOV_EXCL_START
 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
                        const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
                        GVariant *parameters, gpointer user_data)
@@ -529,7 +522,6 @@ static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *se
        g_free(buf);
        DBG("-\n");
 }
-//LCOV_EXCL_STOP
 
 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
                        const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
@@ -585,7 +577,6 @@ static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sen
        DBG("-\n");
 }
 
-//LCOV_EXCL_START
 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
                        const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
                        GVariant *parameters, gpointer user_data)
@@ -660,7 +651,6 @@ static void __handle_flight_mode(GDBusConnection *connection, const gchar *sende
        }
        DBG("-\n");
 }
-//LCOV_EXCL_STOP
 
 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
                const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
@@ -689,6 +679,8 @@ static void __handle_security_type_changed(GDBusConnection *connection, const gc
                security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
        else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
                security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
+       else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_SAE_STR) == 0)
+               security_type = TETHERING_WIFI_SECURITY_TYPE_SAE;
        else {
                SERR("Unknown type : %s\n", buf);
                g_free(buf);
@@ -770,7 +762,6 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
 
        g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
        if (g_error) {
-               //LCOV_EXCL_START
                ERR("DBus error [%s]\n", g_error->message);
                if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
                                ++retry < TETHERING_ERROR_RECOVERY_MAX) {
@@ -782,7 +773,6 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                else
                        error = TETHERING_ERROR_OPERATION_FAILED;
                g_error_free(g_error);
-               //LCOV_EXCL_STOP
        } else {
                g_variant_get(g_var, "(u)", &info);
                error = __get_error(info);
@@ -824,7 +814,6 @@ static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
 
        g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
        if (g_error) {
-               //LCOV_EXCL_START
                ERR("DBus error [%s]\n", g_error->message);
                if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
                                ++retry < TETHERING_ERROR_RECOVERY_MAX) {
@@ -838,7 +827,6 @@ static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                else
                        error = TETHERING_ERROR_OPERATION_FAILED;
                g_error_free(g_error);
-               //LCOV_EXCL_STOP
        } else {
                g_variant_get(g_var, "(u)", &info);
                g_variant_unref(g_var);
@@ -860,7 +848,6 @@ static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
        DBG("-\n");
 }
 
-//LCOV_EXCL_START
 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                                        gpointer user_data)
 {
@@ -913,7 +900,6 @@ static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
        ecb(error, TETHERING_TYPE_USB, true, data);
        DBG("-\n");
 }
-//LCOV_EXCL_STOP
 
 static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                                        gpointer user_data)
@@ -985,11 +971,9 @@ static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
 
        g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
        if (g_error) {
-               //LCOV_EXCL_START
                ERR("DBus error [%s]\n", g_error->message);
                g_error_free(g_error);
                return;
-               //LCOV_EXCL_STOP
        }
        g_variant_get(g_var, "(uu)", &event_type, &info);
        INFO("cfm event : %d info : %d\n", event_type, info);
@@ -1023,7 +1007,6 @@ static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                        dcb(error, type, code, data);
                break;
 
-       //LCOV_EXCL_START
        case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
                sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
                                NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
@@ -1036,7 +1019,6 @@ static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
                if (dcb)
                        dcb(error, type, code, data);
                break;
-       //LCOV_EXCL_STOP
 
        case MOBILE_AP_DISABLE_P2P_TETHERING_CFM:
                type = TETHERING_TYPE_P2P;
@@ -1095,7 +1077,6 @@ static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
 
        g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
        if (g_error) {
-               //LCOV_EXCL_START
                ERR("DBus fail [%s]\n", g_error->message);
                if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
                        tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
@@ -1103,7 +1084,6 @@ static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
                        tethering_error = TETHERING_ERROR_OPERATION_FAILED;
 
                flag = true;
-               //LCOV_EXCL_STOP
        }
        if (th->data_usage_cb == NULL) {
                ERR("There is no data_usage_cb\n");
@@ -1133,7 +1113,7 @@ static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
        GVariant *g_var;
        guint info;
        __tethering_h *th = (__tethering_h *)user_data;
-       tethering_error_e tethering_error;
+       tethering_error_e tethering_error = TETHERING_ERROR_NONE;
 
        g_var  = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
        if (g_error) {
@@ -1143,14 +1123,17 @@ static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
                else
                        tethering_error = TETHERING_ERROR_OPERATION_FAILED;
                g_error_free(g_error);
+       } else {
+               g_variant_get(g_var, "(u)", &info);
+               if (tethering_error == TETHERING_ERROR_NONE)
+                       tethering_error = __get_error(info);
+               g_variant_unref(g_var);
        }
+
        if (th->settings_reloaded_cb == NULL) {
                DBG("There is no settings_reloaded_cb\n-\n");
                return;
        }
-       g_variant_get(g_var, "(u)", &info);
-       tethering_error = __get_error(info);
-       g_variant_unref(g_var);
 
        th->settings_reloaded_cb(tethering_error,
                        th->settings_reloaded_user_data);
@@ -1201,19 +1184,15 @@ static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
        _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
 
        switch (type) {
-       //LCOV_EXCL_START
        case TETHERING_TYPE_USB:
                g_strlcpy(buf, TETHERING_USB_IF, len);
                break;
-       //LCOV_EXCL_STOP
        case TETHERING_TYPE_WIFI:
                g_strlcpy(buf, TETHERING_WIFI_IF, len);
                break;
-
        case TETHERING_TYPE_BT:
                g_strlcpy(buf, TETHERING_BT_IF, len);
                break;
-
        default:
                ERR("Not supported type : %d\n", type);
                return false;
@@ -1229,15 +1208,12 @@ static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int le
        case TETHERING_TYPE_USB:
                g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
                break;
-
        case TETHERING_TYPE_WIFI:
                g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
                break;
-
        case TETHERING_TYPE_BT:
                g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
                break;
-
        default:
                ERR("Not supported type : %d\n", type);
                return false;
@@ -1248,7 +1224,7 @@ static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int le
 static int __get_common_ssid(char *ssid, unsigned int size)
 {
        if (ssid == NULL) {
-               ERR("ssid is null\n"); //LCOV_EXCL_LINE
+               ERR("ssid is null\n");
                return TETHERING_ERROR_INVALID_PARAMETER;
        }
 
@@ -1345,7 +1321,6 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se
                                NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
                if (error) {
-                       //LCOV_EXCL_START
                        ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
 
                        if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
@@ -1355,15 +1330,14 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se
 
                        g_error_free(error);
                        return ret;
-                       //LCOV_EXCL_STOP
                }
 
                if (parameters != NULL) {
                        g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
+                       g_strlcpy(set->key, passphrase, sizeof(set->key) - 1);
+                       g_free(passphrase);
                        g_variant_unref(parameters);
                }
-
-               g_strlcpy(set->key, passphrase, sizeof(set->key));
        }
 
        INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
@@ -1375,9 +1349,8 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se
 
 static bool __check_precondition(tethering_type_e type)
 {
-       int dnet_state = 0;
+       int dnet_status = 0;
        int cellular_state = 0;
-       int wifi_state = 0;
 
        /* data network through cellular */
        vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
@@ -1386,29 +1359,12 @@ static bool __check_precondition(tethering_type_e type)
                return TRUE;
        }
 
-#ifdef TIZEN_TV_EXT
-       /* data network through ethernet */
-       vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_state);
-       if (dnet_state == VCONFKEY_NETWORK_ETHERNET) {
-               INFO("Data Network is connected");
-               return TRUE;
-       }
-#else
-       vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
-       if (dnet_state > VCONFKEY_DNET_OFF) {
-               INFO("Data Network is connected");
+       /* data network status */
+       vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
+       if ((dnet_status == VCONFKEY_NETWORK_WIFI
+                       && type != TETHERING_TYPE_WIFI)
+               || dnet_status == VCONFKEY_NETWORK_ETHERNET)
                return TRUE;
-       }
-#endif/*TIZEN_TV_EXT*/
-
-       /* data network through wifi */
-       if (type != TETHERING_TYPE_WIFI) {
-               vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
-               if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
-                       INFO("Wi-Fi is connected!");
-                       return TRUE;
-               }
-       }
 
        ERR("Network is not available!");
        return FALSE;
@@ -1448,19 +1404,19 @@ API int tethering_create(tethering_h *tethering)
        th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
        th->visibility = true;
        th->mac_filter = false;
-       th->channel = 6;
+       th->channel = TETHERING_WIFI_CHANNEL;
        th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
        th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
 
        if (__generate_initial_passphrase(th->passphrase,
                        sizeof(th->passphrase)) == 0) {
-               ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
+               ERR("random passphrase generation failed\n");
                free(th);
                return TETHERING_ERROR_OPERATION_FAILED;
        }
 
        if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
-               ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
+               ERR("common ssid get failed\n");
                free(th);
                return TETHERING_ERROR_OPERATION_FAILED;
        }
@@ -1471,14 +1427,12 @@ API int tethering_create(tethering_h *tethering)
        GCancellable *cancellable = g_cancellable_new();
        th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
        if (error) {
-               //LCOV_EXCL_START
                ERR("Couldn't connect to the System bus[%s]", error->message);
                g_error_free(error);
                g_cancellable_cancel(cancellable);
                g_object_unref(cancellable);
                free(th);
                return TETHERING_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
        }
        th->cancellable = cancellable;
 
@@ -1486,7 +1440,6 @@ API int tethering_create(tethering_h *tethering)
                        NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
                        TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
        if (!th->client_bus_proxy) {
-               //LCOV_EXCL_START
                if (error)
                        ERR("Couldn't create the proxy object because of %s\n", error->message);
                g_cancellable_cancel(th->cancellable);
@@ -1494,14 +1447,13 @@ API int tethering_create(tethering_h *tethering)
                g_object_unref(th->client_bus);
                free(th);
                return TETHERING_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
        }
 
        __connect_signals((tethering_h)th);
 
        *tethering = (tethering_h)th;
        _tethering_add_handle(th);
-       INFO("Tethering Handle : 0x%X\n", th);
+       INFO("Tethering Handle : %p\n", th);
        INFO("-\n");
        return TETHERING_ERROR_NONE;
 }
@@ -1527,9 +1479,10 @@ API int tethering_destroy(tethering_h tethering)
 
        __tethering_h *th = (__tethering_h *)tethering;
 
-       INFO("Tethering Handle : 0x%X\n", th);
+       INFO("Tethering Handle : %p\n", th);
 
        __disconnect_signals(tethering);
+       _tethering_remove_handle(th);
 
        if (th->ssid)
                free(th->ssid);
@@ -1539,7 +1492,6 @@ API int tethering_destroy(tethering_h tethering)
        g_object_unref(th->client_bus);
        memset(th, 0x00, sizeof(__tethering_h));
 
-       _tethering_remove_handle(th);
        free(th);
 
        INFO("-\n");
@@ -1580,23 +1532,21 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
        g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
 
        if (__check_precondition(type) == FALSE) {
-               //LCOV_EXCL_START
                INFO("-\n");
+               g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
                return TETHERING_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
        }
 
        switch (type) {
-       //LCOV_EXCL_START
        case TETHERING_TYPE_USB:
                g_dbus_connection_signal_unsubscribe(connection,
                                sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
 
-               g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
+               g_dbus_proxy_call(proxy, "enable_usb_tethering",
+                               g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
                                G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
                break;
-       //LCOV_EXCL_STOP
 
        case TETHERING_TYPE_WIFI: {
                _softap_settings_t set = {"", "", "", 0, false};
@@ -1633,6 +1583,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
                ret = __prepare_wifi_settings(tethering, &p2p_set);
                if (ret != TETHERING_ERROR_NONE) {
                        ERR("p2p settings initialization failed\n");
+                       g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
                        DBG("-\n");
                        return TETHERING_ERROR_OPERATION_FAILED;
                }
@@ -1650,6 +1601,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
                ret = __prepare_wifi_settings(tethering, &set);
                if (ret != TETHERING_ERROR_NONE) {
                        ERR("softap settings initialization failed\n");
+                       g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
                        return TETHERING_ERROR_OPERATION_FAILED;
                }
 
@@ -1657,7 +1609,8 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
                g_dbus_connection_signal_unsubscribe(connection,
                                sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
 
-               g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
+               g_dbus_proxy_call(proxy, "enable_usb_tethering",
+                               g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
                                G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
 
@@ -1681,7 +1634,6 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type)
                                G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
                break;
-               //LCOV_EXCL_STOP
        }
        default:
                ERR("Unknown type : %d\n", type);
@@ -1716,14 +1668,23 @@ 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) {
-               //LCOV_EXCL_START
                DBG("-\n");
+               g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
                return TETHERING_ERROR_OPERATION_FAILED;
-               //LCOV_EXCL_STOP
        }
 
        switch (type) {
-       //LCOV_EXCL_START
+       case TETHERING_TYPE_USB: {
+               g_dbus_connection_signal_unsubscribe(connection,
+                               sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
+
+               g_dbus_proxy_call(proxy, "enable_usb_tethering",
+                               g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
+                               G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
+                               (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
+               break;
+       }
+
        case TETHERING_TYPE_WIFI: {
                _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
 
@@ -1731,6 +1692,7 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
                if (ret != TETHERING_ERROR_NONE) {
                        ERR("softap settings initialization failed\n");
                        DBG("-\n");
+                       g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
                        return TETHERING_ERROR_OPERATION_FAILED;
                }
                g_dbus_connection_signal_unsubscribe(connection,
@@ -1741,12 +1703,13 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
                                (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_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);
 
@@ -1784,6 +1747,16 @@ API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
        GDBusConnection *connection = th->client_bus;
 
        switch (type) {
+       case TETHERING_TYPE_USB:
+               g_dbus_connection_signal_unsubscribe(connection,
+                               sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
+
+               g_dbus_proxy_call(proxy, "disable_usb_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_WIFI:
                DBG("Disable wifi tethering..");
                g_dbus_connection_signal_unsubscribe(connection,
@@ -1794,6 +1767,7 @@ API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
                                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);
@@ -1848,7 +1822,8 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type)
                                sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
 
                g_dbus_proxy_call(proxy, "disable_usb_tethering",
-                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
+                               g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
+                               G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
 
                break;
@@ -1886,7 +1861,8 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type)
                                sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
 
                g_dbus_proxy_call(proxy, "disable_usb_tethering",
-                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
+                               g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
+                               G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
 
                g_dbus_connection_signal_unsubscribe(connection,
@@ -2322,8 +2298,13 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
        result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
                        NULL, G_DBUS_CALL_FLAGS_NONE,
                        -1, th->cancellable, &error);
-       if (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);
@@ -2336,6 +2317,8 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                                        client.interface = TETHERING_TYPE_WIFI;
                                else if (interface == MOBILE_AP_TYPE_BT)
                                        client.interface = TETHERING_TYPE_BT;
+                               else if (interface == MOBILE_AP_TYPE_P2P)
+                                       client.interface = TETHERING_TYPE_P2P;
                                else {
                                        ERR("Invalid interface\n");
                                        g_free(key);
@@ -2372,20 +2355,25 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                g_free(hostname);
                g_free(ip);
                g_free(mac);
+
+               hostname = NULL;
+               ip = NULL;
+               mac = NULL;
+
                g_variant_iter_free(inner_iter);
                if (callback((tethering_client_h)&client, user_data) == false) {
                        DBG("iteration is stopped\n");
                        g_free(client.hostname);
+                       client.hostname = NULL;
                        g_variant_iter_free(outer_iter);
-                       g_variant_unref(station);
                        g_variant_unref(result);
                        DBG("-\n");
                        return TETHERING_ERROR_OPERATION_FAILED;
                }
                g_free(client.hostname);
+               client.hostname = NULL;
        }
        g_variant_iter_free(outer_iter);
-       g_variant_unref(station);
        g_variant_unref(result);
        DBG("-\n");
        return TETHERING_ERROR_NONE;
@@ -2604,7 +2592,7 @@ API int tethering_set_connection_state_changed_cb(tethering_h tethering, tetheri
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
                th->changed_cb[ti] = callback;
                th->changed_user_data[ti] = user_data;
        }
@@ -2645,7 +2633,7 @@ API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethe
        }
 
        /* TETHERING_TYPE_ALL */
-       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
+       for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
                th->changed_cb[ti] = NULL;
                th->changed_user_data[ti] = NULL;
        }
@@ -2858,7 +2846,6 @@ API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_s
 
        ret = __set_security_type(type);
        if (ret == TETHERING_ERROR_NONE) {
-
                switch (type) {
                case TETHERING_WIFI_SECURITY_TYPE_NONE:
                        sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
@@ -2869,6 +2856,9 @@ API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_s
                case TETHERING_WIFI_SECURITY_TYPE_WPS:
                        sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
                        break;
+               case TETHERING_WIFI_SECURITY_TYPE_SAE:
+                       sec_str = TETHERING_WIFI_SECURITY_TYPE_SAE_STR;
+                       break;
                }
 
                __send_dbus_signal(th->client_bus,
@@ -2896,6 +2886,8 @@ API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_s
        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(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
                        "parameter(type) is NULL\n");
 
@@ -3033,7 +3025,6 @@ API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
 
        ret = __set_visible(visible);
        if (ret == TETHERING_ERROR_NONE) {
-
                __send_dbus_signal(th->client_bus,
                                SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
                                visible ? SIGNAL_MSG_SSID_VISIBLE :
@@ -3062,6 +3053,8 @@ API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
        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(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
                        "parameter(visible) is NULL\n");
 
@@ -3112,7 +3105,6 @@ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphr
                        g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
        if (error) {
-               //LCOV_EXCL_START
                ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
 
                if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
@@ -3122,7 +3114,6 @@ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphr
 
                g_error_free(error);
                return ret;
-               //LCOV_EXCL_STOP
        }
 
        g_variant_get(parameters, "(u)", &ret);
@@ -3174,7 +3165,6 @@ API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
                        NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
        if (error) {
-               //LCOV_EXCL_START
                ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
 
                if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
@@ -3184,7 +3174,6 @@ API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
 
                g_error_free(error);
                return ret;
-               //LCOV_EXCL_STOP
        }
 
        if (parameters != NULL) {
@@ -3350,12 +3339,6 @@ static int __add_mac_to_file(const char *filepath, const char *mac)
        bool mac_exist = false;
        char *p_mac = NULL;
 
-       p_mac = strdup(mac);
-       if (p_mac == NULL) {
-               ERR("strdup failed\n");
-               return TETHERING_ERROR_OUT_OF_MEMORY;
-       }
-
        fp = fopen(filepath, "a+");
        if (!fp) {
                ERR("fopen is failed\n");
@@ -3371,12 +3354,21 @@ static int __add_mac_to_file(const char *filepath, const char *mac)
        }
 
        if (!mac_exist) {
+               p_mac = strdup(mac);
+               if (p_mac == NULL) {
+                       ERR("strdup failed\n");
+                       fclose(fp);
+                       return TETHERING_ERROR_OUT_OF_MEMORY;
+               }
+
                fprintf(fp, "%s\n", mac);
 
                if ((strcmp(filepath, ALLOWED_LIST) == 0))
                        allowed_list = g_slist_append(allowed_list, p_mac);
                else if ((strcmp(filepath, BLOCKED_LIST) == 0))
                        blocked_list = g_slist_append(blocked_list, p_mac);
+               else
+                       free(p_mac);
        }
 
        fclose(fp);
@@ -3430,10 +3422,17 @@ static int __remove_mac_from_file(const char *filepath, const char *mac)
        fclose(fp);
        fclose(fp1);
 
-       if ((strcmp(filepath, ALLOWED_LIST) == 0))
-               rename(TEMP_LIST, ALLOWED_LIST);
-       else if ((strcmp(filepath, BLOCKED_LIST) == 0))
-               rename(TEMP_LIST, BLOCKED_LIST);
+       if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
+               if (rename(TEMP_LIST, ALLOWED_LIST) != 0) {
+                       ERR("rename is failed (%s -> %s)", TEMP_LIST, ALLOWED_LIST);
+                       return TETHERING_ERROR_OPERATION_FAILED;
+               }
+       } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
+               if (rename(TEMP_LIST, BLOCKED_LIST) != 0) {
+                       ERR("rename is failed (%s -> %s)", TEMP_LIST, BLOCKED_LIST);
+                       return TETHERING_ERROR_OPERATION_FAILED;
+               }
+       }
 
        return TETHERING_ERROR_NONE;
 }
@@ -3659,6 +3658,8 @@ API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
 
        _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
                        "parameter(tethering) is NULL\n");
+       _retvm_if(txpower == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(txpower) is NULL\n");
        _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
                        TETHERING_ERROR_NOT_ENABLED,
                        "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
@@ -3840,8 +3841,14 @@ API int tethering_wifi_add_port_forwarding_rule(tethering_h tethering, char *ifn
 
        _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
                        "parameter(tethering) is NULL\n");
+       _retvm_if(ifname == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(ifname) is NULL\n");
        _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
                        "parameter(protocol) is NULL\n");
+       _retvm_if(org_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(org_ip) is NULL\n");
+       _retvm_if(final_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(final_ip) is NULL\n");
 
        GVariant *parameters;
        GError *error = NULL;
@@ -3921,7 +3928,7 @@ API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
        return TETHERING_ERROR_NONE;
 }
 
-API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, boolforwarding_enabled)
+API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool *forwarding_enabled)
 {
        CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
        CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
@@ -4004,8 +4011,8 @@ API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port,
        GVariant *parameters;
        GError *error = NULL;
        guint result;
-       char cmd[MAX_BUF_SIZE] = { 0, };
        char *list = NULL;
+       int ret;
 
        __tethering_h *th = (__tethering_h *)tethering;
 
@@ -4030,18 +4037,17 @@ API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port,
        g_variant_unref(parameters);
 
        if (allow)
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
+               ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
        else
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
+               ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
 
-       DBG("cmd:%s", cmd);
-
-       list = strdup(cmd);
-       if (list == NULL) {
-               ERR("strdup failed\n");
+       if (ret == -1 || list == NULL) {
+               ERR("asprintf failed\n");
                return TETHERING_ERROR_OUT_OF_MEMORY;
        }
 
+       DBG("cmd:%s", list);
+
        port_filtering = g_slist_append(port_filtering, list);
 
        return TETHERING_ERROR_NONE;
@@ -4060,8 +4066,8 @@ API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int
        GVariant *parameters;
        GError *error = NULL;
        guint result;
-       char cmd[MAX_BUF_SIZE] = { 0, };
        char *list = NULL;
+       int ret;
 
        __tethering_h *th = (__tethering_h *)tethering;
 
@@ -4086,18 +4092,17 @@ API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int
        g_variant_unref(parameters);
 
        if (allow)
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
+               ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
        else
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
+               ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
 
-       DBG("cmd:%s", cmd);
-
-       list = strdup(cmd);
-       if (list == NULL) {
-               ERR("strdup failed\n");
+       if (ret == -1 || list == NULL) {
+               ERR("asprintf failed\n");
                return TETHERING_ERROR_OUT_OF_MEMORY;
        }
 
+       DBG("cmd:%s", list);
+
        custom_port_filtering = g_slist_append(custom_port_filtering, list);
 
        return TETHERING_ERROR_NONE;
@@ -4131,7 +4136,7 @@ API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, voi
        return TETHERING_ERROR_NONE;
 }
 
-API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, boolfiltering_enabled)
+API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool *filtering_enabled)
 {
        CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
        CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
@@ -4229,6 +4234,9 @@ API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
 
        _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
                        "parameter(tethering) is NULL");
+       _retvm_if(wps_pin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(wps_pin) is NULL");
+
        __tethering_h *th = (__tethering_h *)tethering;
        GDBusProxy *proxy = th->client_bus_proxy;
        GVariant *parameters = NULL;