#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);
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) {
}
}
- 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;
}
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);
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,
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,
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);
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;
/* 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;
}
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");
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;