#include <ckmc/ckmc-manager.h>
#include "tethering_private.h"
+#define ALLOWED_LIST "/etc/hostapd.accept"
+#define BLOCKED_LIST "/etc/hostapd.deny"
+#define TEMP_LIST "/etc/hostapd_tmp"
+#define MAC_ADDR_LEN 18
+#define MAX_BUF_SIZE 80
+
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);
if (ret != TETHERING_ERROR_NONE)
set->visibility = th->visibility;
+ set->mac_filter = th->mac_filter;
set->channel = th->channel;
__get_wifi_mode_type (th->mode_type, &ptr);
}
if (parameters != NULL) {
- g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
+ g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
g_variant_unref(parameters);
}
memset(th, 0x00, sizeof(__tethering_h));
th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
th->visibility = true;
+ th->mac_filter = false;
th->channel = 6;
th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
g_dbus_proxy_call(proxy, "enable_wifi_tethering",
- g_variant_new("(sssiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.sec_type),
+ g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
(GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
break;
th->settings_reloaded_user_data = user_data;
g_dbus_proxy_call(proxy, "reload_wifi_settings",
- g_variant_new("(sssiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.sec_type),
+ g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
(GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
return TETHERING_ERROR_NONE;
}
+API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ th->mac_filter = mac_filter;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+
+ _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(mac_filter) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ *mac_filter = th->mac_filter;
+
+ return TETHERING_ERROR_NONE;
+}
+
+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;
+
+ fp = fopen(filepath, "a+");
+ if (!fp) {
+ ERR("fopen is failed\n");
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+
+ while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
+ if (strncmp(mac, line, 17) == 0) {
+ DBG("MAC %s already exist in the list\n", mac);
+ mac_exist = true;
+ break;
+ }
+ }
+
+ if (!mac_exist)
+ fprintf(fp, "%s\n", mac);
+
+ fclose(fp);
+
+ return TETHERING_ERROR_NONE;
+}
+
+static int __remove_mac_from_file(const char *filepath, const char *mac)
+{
+ FILE *fp = NULL;
+ FILE *fp1 = NULL;
+ char line[MAX_BUF_SIZE] = "\0";
+
+ fp = fopen(filepath, "r");
+ if (!fp) {
+ ERR("fopen is failed\n");
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+
+ fp1 = fopen(TEMP_LIST, "w+");
+ if (!fp1) {
+ fclose(fp);
+ ERR("fopen is failed\n");
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+
+ while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
+ if (strncmp(mac, line, 17) == 0)
+ DBG("MAC %s found in the list\n", mac);
+ else
+ fprintf(fp1, "%s", line);
+ }
+
+ 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);
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_add_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,
+ "parameter(mac) is NULL\n");
+
+ return __add_mac_to_file(ALLOWED_LIST, mac);
+}
+
+API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
+{
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(mac) is NULL\n");
+
+ return __remove_mac_from_file(ALLOWED_LIST, mac);
+}
+
+API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
+{
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(mac) is NULL\n");
+
+ return __add_mac_to_file(BLOCKED_LIST, mac);
+}
+
+API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
+{
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(mac) is NULL\n");
+
+ return __remove_mac_from_file(BLOCKED_LIST, mac);
+}
+
/**
* @internal
* @brief Sets the security type of Wi-Fi AP.
char *ssid = NULL;
char *passphrase = NULL;
bool visibility = false;
+ bool mac_filter = 0;
tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
int error = TETHERING_ERROR_NONE;
TETHERING_WIFI_SECURITY_TYPE_NONE ?
"open" : "wpa2-psk");
+ error = tethering_wifi_get_mac_filter(th, &mac_filter);
+ if (error != TETHERING_ERROR_NONE)
+ __is_err(error);
+ else
+ g_print("\t** WiFi tethering mac filter : %s\n",
+ mac_filter ? "enable" : "disable");
+
if (ssid)
free(ssid);
if (passphrase)
return 1;
}
-static int test_tethering_wifi_set_channel(void){
+static int test_tethering_wifi_set_channel(void)
+{
int ret;
int channel;
return 1;
}
-static int test_tethering_wifi_set_mode(void) {
+static int test_tethering_wifi_set_mode(void)
+{
int ret;
int type;
printf("Fail to set mode!!\n");
return -1;
}
+
+ return 1;
+}
+
+static int test_tethering_wifi_set_mac_filtering(void)
+{
+ int ret;
+ int enable;
+
+ printf("Input mac filtering option (0: disable, 1: enable): ");
+ ret = scanf("%d", &enable);
+
+ ret = tethering_wifi_set_mac_filter(th, enable);
+ if (__is_err(ret) == true) {
+ printf("Fail to set mac filtering!!\n");
+ return -1;
+ }
+
+ return 1;
+}
+
+static int test_tethering_manage_mac_list(void)
+{
+ int ret = 0;
+ int list, option;
+ char mac[100];
+
+ printf("Select MAC list to modify (0: allowed mac list, 1: blocked mac list): ");
+ ret = scanf("%d", &list);
+
+ printf("Select option (0: Add, 1: Remove): ");
+ ret = scanf("%d", &option);
+
+ printf("Input MAC Address to add/remove allowed/blocked mac list: ");
+ ret = scanf("%99s", mac);
+ if (ret < 0) {
+ printf("scanf is failed!!\n");
+ return -1;
+ }
+
+ if (!list && !option) {
+ /* Add to allowed mac list*/
+ ret = tethering_wifi_add_allowed_mac_list(th, mac);
+ } else if (!list && option) {
+ /* Remove from allowed mac list */
+ ret = tethering_wifi_remove_allowed_mac_list(th, mac);
+ } else if (list && !option) {
+ /* Add to blocked mac list */
+ ret = tethering_wifi_add_blocked_mac_list(th, mac);
+ } else if (list && option) {
+ /* Remove from blocked mac list */
+ ret = tethering_wifi_remove_blocked_mac_list(th, mac);
+ } else {
+ printf("Input Failed!!\n");
+ return -1;
+ }
+
+ if (ret < 0)
+ return -1;
+
return 1;
}
printf("b - Set Wi-Fi tethering security type\n");
printf("c - Set Wi-Fi tethering visibility\n");
printf("d - Set Wi-Fi tethering passphrase\n");
- printf("e - Set Wi-Fi AP SSID\n");
- printf("f - Set Wi-Fi AP security type\n");
- printf("g - Set Wi-Fi AP visibility\n");
- printf("h - Set Wi-Fi AP passphrase\n");
- printf("i - Reload Wi-Fi tethering\n");
- printf("j - Reload Wi-Fi AP\n");
+ printf("e - Set Wi-Fi tethering mac filtering\n");
+ printf("f - Add/Remove MAC adress to/from allowed/blocked list\n");
+ printf("g - Set Wi-Fi AP SSID\n");
+ printf("h - Set Wi-Fi AP security type\n");
+ printf("i - Set Wi-Fi AP visibility\n");
+ printf("j - Set Wi-Fi AP passphrase\n");
+ printf("k - Reload Wi-Fi tethering\n");
+ printf("l - Reload Wi-Fi AP\n");
printf("m - Set Wi-Fi channel\n");
printf("n - Set Wi-Fi hw_mode\n");
printf("0 - Exit \n");
rv = test_tethering_wifi_set_passphrase();
break;
case 'e':
- rv = test_tethering_wifi_ap_set_ssid();
+ rv = test_tethering_wifi_set_mac_filtering();
break;
case 'f':
- rv = test_tethering_wifi_ap_set_security_type();
+ rv = test_tethering_manage_mac_list();
break;
case 'g':
- rv = test_tethering_wifi_ap_set_visibility();
+ rv = test_tethering_wifi_ap_set_ssid();
break;
case 'h':
- rv = test_tethering_wifi_ap_set_passphrase();
+ rv = test_tethering_wifi_ap_set_security_type();
break;
case 'i':
- rv = test_tethering_wifi_reload_settings();
+ rv = test_tethering_wifi_ap_set_visibility();
break;
case 'j':
+ rv = test_tethering_wifi_ap_set_passphrase();
+ break;
+ case 'k':
+ rv = test_tethering_wifi_reload_settings();
+ break;
+ case 'l':
rv = test_tethering_wifi_ap_reload_settings();
break;
case 'm':