From: Seonah Moon Date: Thu, 28 Apr 2016 02:32:17 +0000 (+0900) Subject: Implement APIs to get allowed/blocked mac list X-Git-Tag: accepted/tizen/common/20160429.170455^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F67664%2F3;p=platform%2Fcore%2Fapi%2Ftethering.git Implement APIs to get allowed/blocked mac list Change-Id: I9496b37f6a0a388c6a4438c15ad2d9fe32ef6081 Signed-off-by: Seonah Moon --- diff --git a/packaging/capi-network-tethering.spec b/packaging/capi-network-tethering.spec index cb3cd74..a5f0f0c 100644 --- a/packaging/capi-network-tethering.spec +++ b/packaging/capi-network-tethering.spec @@ -1,6 +1,6 @@ Name: capi-network-tethering Summary: Tethering Framework -Version: 1.0.34 +Version: 1.0.35 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/tethering.c b/src/tethering.c index a7ad287..7654c0c 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -37,6 +37,9 @@ #define MAC_ADDR_LEN 18 #define MAX_BUF_SIZE 80 +static GSList *allowed_list = NULL; +static GSList *blocked_list = NULL; + static void __handle_wifi_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); @@ -2998,6 +3001,13 @@ static int __add_mac_to_file(const char *filepath, const char *mac) FILE *fp = NULL; char line[MAX_BUF_SIZE] = "\0"; 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) { @@ -3013,9 +3023,15 @@ static int __add_mac_to_file(const char *filepath, const char *mac) } } - if (!mac_exist) + if (!mac_exist) { 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); + } + fclose(fp); return TETHERING_ERROR_NONE; @@ -3041,10 +3057,27 @@ static int __remove_mac_from_file(const char *filepath, const char *mac) } while (fgets(line, MAX_BUF_SIZE, fp) != NULL) { - if (strncmp(mac, line, 17) == 0) + if (strncmp(mac, line, 17) == 0) { DBG("MAC %s found in the list\n", mac); - else + + if ((strcmp(filepath, ALLOWED_LIST) == 0)) { + GSList *list = NULL; + for (list = allowed_list; list != NULL; list = list->next) { + char *p_mac = (char *)list->data; + if (strncmp(mac, p_mac, strlen(mac)) == 0) + allowed_list = g_slist_remove(allowed_list, p_mac); + } + } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) { + GSList *list = NULL; + for (list = blocked_list; list != NULL; list = list->next) { + char *p_mac = (char *)list->data; + if (strncmp(mac, p_mac, strlen(mac)) == 0) + blocked_list = g_slist_remove(blocked_list, p_mac); + } + } + } else { fprintf(fp1, "%s", line); + } } fclose(fp); @@ -3072,6 +3105,7 @@ API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *m API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -3080,8 +3114,21 @@ API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char return __remove_mac_from_file(ALLOWED_LIST, mac); } +API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(allowed_mac_list) is NULL\n"); + + *allowed_mac_list = g_slist_copy(allowed_list); + return TETHERING_ERROR_NONE; +} + API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -3100,6 +3147,19 @@ API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char return __remove_mac_from_file(BLOCKED_LIST, mac); } +API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(blocked_mac_list) is NULL\n"); + + *blocked_mac_list = g_slist_copy(blocked_list); + return TETHERING_ERROR_NONE; +} + API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable) { CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); diff --git a/test/tethering_test.c b/test/tethering_test.c index 96d768b..1aca12d 100755 --- a/test/tethering_test.c +++ b/test/tethering_test.c @@ -518,6 +518,14 @@ static void __print_wifi_tethering_setting(tethering_h th) return; } +void __display_list(GSList *list) +{ + GSList *iterator = NULL; + + for (iterator = list; iterator; iterator = iterator->next) + printf("%s\n", (char*)iterator->data); +} + bool __get_tethering_type(tethering_type_e *type) { int sel; @@ -883,13 +891,42 @@ static int test_tethering_manage_mac_list(void) /* Remove from blocked mac list */ ret = tethering_wifi_remove_blocked_mac_list(th, mac); } else { - printf("Input Failed!!\n"); + printf("Input failed!!\n"); + return -1; + } + + if (ret < 0) return -1; + + return 1; +} + +static int test_tethering_get_mac_list(void) +{ + int ret = 0; + int list = 0; + void *mac_list = NULL; + + printf("Select MAC list to get (0: allowed mac list, 1: blocked mac list): "); + ret = scanf("%d", &list); + + switch (list) { + case 0: + ret = tethering_wifi_get_allowed_mac_list(th, &mac_list); + break; + case 1: + ret = tethering_wifi_get_blocked_mac_list(th, &mac_list); + break; + default: + printf("Input failed!!\n"); + break; } if (ret < 0) return -1; + __display_list(mac_list); + return 1; } @@ -950,6 +987,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("d - Set Wi-Fi tethering passphrase\n"); printf("e - Set Wi-Fi tethering mac filtering\n"); printf("f - Add/Remove MAC adress to/from allowed/blocked list\n"); + printf("g - Get allowed/blocked list\n"); printf("k - Reload Wi-Fi tethering\n"); printf("m - Set Wi-Fi channel\n"); printf("n - Set Wi-Fi hw_mode\n"); @@ -1003,6 +1041,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'f': rv = test_tethering_manage_mac_list(); break; + case 'g': + rv = test_tethering_get_mac_list(); + break; case 'k': rv = test_tethering_wifi_reload_settings(); break;