From 91b98ead1c0be8665e64286a5a302b1ff6bf5016 Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Thu, 3 Sep 2020 22:55:33 +0530 Subject: [PATCH] [tool] Combine repeated code for getting handle in a wrapper Change-Id: Iefad83d31f89fbd2630682a9255e6209cbdcfa8f Signed-off-by: Nishant Chaprana --- tools/tethering_test.c | 75 ++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/tools/tethering_test.c b/tools/tethering_test.c index 8c4b16b..5b8bb8c 100755 --- a/tools/tethering_test.c +++ b/tools/tethering_test.c @@ -695,6 +695,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; @@ -715,17 +719,24 @@ static int test_tethering_destroy(void) 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); - tethering_h handle = freq ? th5 : th; + tethering_h handle = _get_tethering_handle(); printf("IPv4: 0, IPv6: 1\n"); ret = scanf("%d", &address_type); @@ -768,12 +779,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); @@ -822,12 +829,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 +848,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 +875,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 +887,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 +909,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 +932,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 +955,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 +977,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 +996,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); -- 2.7.4