Replace usage of enum 'TETHERING_TYPE_WIFI_SHARING'
[platform/core/api/tethering.git] / tools / tethering_test.c
index 8c4b16b..7f2c231 100755 (executable)
@@ -143,10 +143,6 @@ static const char *__convert_tethering_type_to_str(const tethering_type_e type)
                g_strlcpy(str_buf, "P2P Tethering", sizeof(str_buf));
                break;
 
-       case TETHERING_TYPE_WIFI_SHARING:
-               g_strlcpy(str_buf, "Wi-Fi Sharing", sizeof(str_buf));
-               break;
-
        default:
                g_strlcpy(str_buf, "Unknown", sizeof(str_buf));
                break;
@@ -640,7 +636,7 @@ bool __get_tethering_type(tethering_type_e *type)
        int sel;
        int ret;
 
-       printf("Select tethering type (1:Wi-Fi, 2:Wi-Fi Sharing, 3:BT, 4:USB 5:P2P 6: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");
@@ -652,18 +648,15 @@ bool __get_tethering_type(tethering_type_e *type)
                *type = TETHERING_TYPE_WIFI;
                break;
        case 2:
-               *type = TETHERING_TYPE_WIFI_SHARING;
-               break;
-       case 3:
                *type = TETHERING_TYPE_BT;
                break;
-       case 4:
+       case 3:
                *type = TETHERING_TYPE_USB;
                break;
-       case 5:
+       case 4:
                *type = TETHERING_TYPE_P2P;
                break;
-       case 6:
+       case 5:
                *type = TETHERING_TYPE_ALL;
                break;
        default:
@@ -695,6 +688,10 @@ static int test_tethering_create(void)
                printf("Tethering create is failed\n");
                return -1;
        }
+
+       tethering_wifi_set_channel(th5, 36);
+       tethering_wifi_set_mode(th5, TETHERING_WIFI_MODE_TYPE_A);
+
        printf("Tethering create and register callback success\n");
 
        return 1;
@@ -711,21 +708,40 @@ static int test_tethering_destroy(void)
                printf("Tethering destroy is failed\n");
                return -1;
        }
+       th = NULL;
+
+       __deregister_cbs(th5);
+
+       ret = tethering_destroy(th5);
+       if (__is_err(ret) == true) {
+               printf("Tethering destroy is failed\n");
+               return -1;
+       }
+       th5 = NULL;
 
        return 1;
 }
 
+static tethering_h _get_tethering_handle(void)
+{
+       int freq;
+
+       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
+       if (scanf("%d", &freq) < 0)
+               return th;
+
+       return (freq ? th5 : th);
+}
+
 static int test_tethering_enable(void)
 {
        int ret = TETHERING_ERROR_NONE;
        tethering_type_e type;
        int address_type = 0;
-       int freq = 0;
-
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
+       bool supported = false;
+       int choice = 0;
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        printf("IPv4: 0, IPv6: 1\n");
        ret = scanf("%d", &address_type);
@@ -733,9 +749,13 @@ static int test_tethering_enable(void)
        if (!__get_tethering_type(&type))
                return -1;
 
-       if (type == TETHERING_TYPE_WIFI_SHARING) {
-               bool supported = false;
+       if (type != TETHERING_TYPE_WIFI)
+               return -1;
+
+       printf("Select 1: Wi-Fi sharing, 2: Dual band hotspot\n");
+       ret = scanf("%d", &choice);
 
+       if (choice == 1) {
                ret = tethering_wifi_is_sharing_supported(th, &supported);
 
                if (__is_err(ret) == true) {
@@ -746,9 +766,26 @@ static int test_tethering_enable(void)
                if (!supported) {
                        printf("wifi_sharing is not supported.\n");
                        return -1;
+               } else {
+
+                       printf("wifi_sharing is supported.\n");
+                       ret = tethering_wifi_set_sharing(th, true);
+                       if (__is_err(ret) == true) {
+                               printf("Fail to set wifi sharing\n");
+                               return -1;
+                       }
                }
+       } else if (choice == 2) {
+               ret = tethering_is_dualband_supported(handle, type, &supported);
 
-               printf("wifi_sharing is supported.\n");
+               if (__is_err(ret) == true) {
+                       printf("Fail to get is dubalband supported\n");
+                       return -1;
+               } else
+                       printf("DualBand is %s\n", supported ? "Supported" : "Not Supported");
+       } else {
+               printf("Invalid!!\n");
+               return -1;
        }
 
        if (address_type)
@@ -768,12 +805,8 @@ static int test_tethering_disable(void)
        int ret = TETHERING_ERROR_NONE;
        tethering_type_e type;
        int address_type = 0;
-       int freq = 0;
-
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        printf("IPv4: 0, IPv6: 1\n");
        ret = scanf("%d", &address_type);
@@ -790,6 +823,9 @@ static int test_tethering_disable(void)
                printf("Fail to disable tethering\n");
                return -1;
        }
+
+       tethering_wifi_set_sharing(th, false);
+
        return 1;
 }
 
@@ -822,12 +858,8 @@ static int test_tethering_get_client_info(void)
 {
        int ret;
        tethering_type_e type;
-       int freq = 0;
 
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
-
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        if (!__get_tethering_type(&type))
                return -1;
@@ -845,12 +877,9 @@ static int test_tethering_get_client_info(void)
 static int test_tethering_get_interface_info(void)
 {
        tethering_type_e type;
-       int freq = 0;
        int ret;
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        if (!__get_tethering_type(&type))
                return -1;
@@ -875,11 +904,9 @@ static int test_tethering_get_data_usage(void)
 static int test_tethering_wifi_get_setting(void)
 {
        int ret;
-       int freq = 0;
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
+
        __print_wifi_tethering_setting(handle);
        ret = 1;
        return ret;
@@ -889,11 +916,8 @@ static int test_tethering_wifi_set_ssid(void)
 {
        int ret;
        char ssid[100] = {0, };
-       int freq = 0;
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        if (test_get_user_string("Input SSID for Wi-Fi tethering:",
                                ssid, 100) == false) {
@@ -914,12 +938,9 @@ static int test_tethering_wifi_set_security_type(void)
 {
        int ret;
        int security_type;
-       int freq = 0;
 
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
+       tethering_h handle = _get_tethering_handle();
 
-       tethering_h handle = freq ? th5 : th;
        printf("Input security type for Wi-Fi tethering (0:NONE, 1:WPA2_PSK, 2:WPS, 3:SAE)");
        ret = scanf("%9d", &security_type);
        if (ret < 0) {
@@ -940,12 +961,8 @@ int test_tethering_wifi_set_visibility(void)
 {
        int ret;
        int visibility;
-       int freq = 0;
-
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        printf("Input security type for Wi-Fi tethering (0:invisible, 1:visible)");
        ret = scanf("%9d", &visibility);
@@ -967,11 +984,8 @@ static int test_tethering_wifi_set_passphrase(void)
 {
        int ret;
        char passphrase[100] = {0, };
-       int freq = 0;
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        if (test_get_user_string("Input passphrase for Wi-Fi tethering:",
                                passphrase, 100) == false) {
@@ -992,11 +1006,8 @@ static int test_tethering_wifi_set_channel(void)
 {
        int ret;
        int channel;
-       int freq = 0;
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        printf("Input channel for Wi-Fi tethering: ");
        ret = scanf("%d", &channel);
@@ -1014,11 +1025,8 @@ static int test_tethering_wifi_set_mode(void)
 {
        int ret;
        int type;
-       int freq = 0;
-       printf("Choose tethering handle ( 0 : 2.4GHz , 1 : 5.0GHz ) \n ");
-       ret = scanf("%d", &freq);
 
-       tethering_h handle = freq ? th5 : th;
+       tethering_h handle = _get_tethering_handle();
 
        printf("Input hw_mode for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): ");
        ret = scanf("%d", &type);