#include <openssl/evp.h>
#include <openssl/sha.h>
#include <ckmc/ckmc-manager.h>
+#include <tzplatform_config.h>
#include "tethering_private.h"
+#define ALLOWED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.accept")
+#define BLOCKED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.deny")
+#define TEMP_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/.hostapd_tmp")
+#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);
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data);
-static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
- const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data);
-
-static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
- const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data);
-
static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data);
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data);
-static void __get_key_manager_alias(char* alias, size_t buff_len);
-
static __tethering_sig_t sigs[] = {
{0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
{0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
{0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
{0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
{0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
- {0, SIGNAL_NAME_WIFI_AP_ON, __handle_wifi_ap_on},
- {0, SIGNAL_NAME_WIFI_AP_OFF, __handle_wifi_ap_off},
{0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
{0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
{0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
{0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
{0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
{0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
- {0, "", NULL}};
+ {0, "", NULL} };
static int retry = 0;
static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
{
if (conn == NULL || signal_name == NULL)
- return;
+ return; //LCOV_EXCL_LINE
GVariant *message = NULL;
GError *error = NULL;
- if (arg) {
+ if (arg)
message = g_variant_new("(s)", arg);
- }
g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
if (error) {
- ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
- g_error_free(error);
+ ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
+ g_error_free(error); //LCOV_EXCL_LINE
}
g_variant_unref(message);
}
{
if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
- tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
- tethering_is_enabled(tethering, TETHERING_TYPE_RESERVED))
+ tethering_is_enabled(tethering, TETHERING_TYPE_BT))
return true;
return false;
}
if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
- ERR("vconf_set_int is failed\n");
+ ERR("vconf_set_int is failed\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
return index;
}
-static tethering_error_e __set_passphrase(const char *passphrase, const unsigned int size)
-{
- if (passphrase == NULL || size == 0)
- return TETHERING_ERROR_INVALID_PARAMETER;
-
- int ret = -1;
- char alias[MAX_ALIAS_LEN] = {0, };
- ckmc_raw_buffer_s ckmc_buf;
- ckmc_policy_s ckmc_policy;
-
- ckmc_policy.password = NULL;
- ckmc_policy.extractable = true;
-
- ckmc_buf.data = (unsigned char *) passphrase;
- ckmc_buf.size = strlen(passphrase);
-
- __get_key_manager_alias(alias, sizeof(alias));
- ret = ckmc_save_data(alias, ckmc_buf, ckmc_policy);
- if (ret != CKMC_ERROR_NONE) {
- ERR("Fail to save the passphrase : %d\n", ret);
- return TETHERING_ERROR_OPERATION_FAILED;
- }
-
- return TETHERING_ERROR_NONE;
-}
-
-static void __get_key_manager_alias(char* alias, size_t buff_len)
-{
- snprintf(alias, buff_len, "%s%s%s", ckmc_owner_id_system,
- ckmc_owner_id_separator,
- TETHERING_WIFI_PASSPHRASE_STORE_KEY);
-}
-
-static tethering_error_e __get_passphrase(char *passphrase,
- unsigned int passphrase_size, unsigned int *passphrase_len)
-{
- if (passphrase == NULL || passphrase_size == 0) {
- ERR("Invalid parameter\n");
- return TETHERING_ERROR_INVALID_PARAMETER;
- }
-
- int ret = 0;
- char tmp[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
- char alias[MAX_ALIAS_LEN] = {0, };
- ckmc_raw_buffer_s *ckmc_buf;
-
- __get_key_manager_alias(alias, sizeof(alias));
- ret = ckmc_get_data(alias, NULL, &ckmc_buf);
- if (ret < 0) {
- DBG("Create new password\n");
- ret = __generate_initial_passphrase(tmp, sizeof(tmp));
-
- if (ret == 0) {
- ERR("generate_initial_passphrase failed : %d\n", *passphrase_len);
- return TETHERING_ERROR_OPERATION_FAILED;
- } else {
- *passphrase_len = ret;
- g_strlcpy(passphrase,tmp,(*passphrase_len)+1);
-
- if (__set_passphrase(passphrase, *passphrase_len) != TETHERING_ERROR_NONE) {
- DBG("set_passphrase is failed : %s, %d",passphrase, *passphrase_len);
- return TETHERING_ERROR_OPERATION_FAILED;
- }
- }
- } else {
- *passphrase_len = ckmc_buf->size;
- g_strlcpy(passphrase, (char *)ckmc_buf->data, (*passphrase_len) + 1);
- }
-
- g_free(alias);
-
- return TETHERING_ERROR_NONE;
-}
-
static tethering_error_e __get_error(int agent_error)
{
tethering_error_e err = TETHERING_ERROR_NONE;
err = TETHERING_ERROR_NONE;
break;
+ //LCOV_EXCL_START
case MOBILE_AP_ERROR_RESOURCE:
err = TETHERING_ERROR_OUT_OF_MEMORY;
break;
+ //LCOV_EXCL_STOP
case MOBILE_AP_ERROR_INTERNAL:
err = TETHERING_ERROR_OPERATION_FAILED;
err = TETHERING_ERROR_OPERATION_FAILED;
break;
+ //LCOV_EXCL_START
case MOBILE_AP_ERROR_NOT_PERMITTED:
err = TETHERING_ERROR_NOT_PERMITTED;
break;
case MOBILE_AP_ERROR_PERMISSION_DENIED:
err = TETHERING_ERROR_PERMISSION_DENIED;
break;
-
+ //LCOV_EXCL_STOP
default:
ERR("Not defined error : %d\n", agent_error);
err = TETHERING_ERROR_OPERATION_FAILED;
return err;
}
+//LCOV_EXCL_START
static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
void *data = NULL;
char *buf = NULL;
char *name = NULL;
- char *mac= NULL;
- char *ip= NULL;
+ char *mac = NULL;
+ char *ip = NULL;
guint timestamp;
memset(&client, 0, sizeof(__tethering_client_h));
type = TETHERING_TYPE_WIFI;
else if (ap_type == MOBILE_AP_TYPE_BT)
type = TETHERING_TYPE_BT;
- else if (ap_type == MOBILE_AP_TYPE_WIFI_AP) {
- type = TETHERING_TYPE_RESERVED;
- } else {
+ else {
ERR("Not supported tethering type [%d]\n", ap_type);
goto DONE;
}
ccb((tethering_client_h)&client, opened, data);
g_free(client.hostname);
-DONE :
+DONE:
g_free(buf);
g_free(ip);
g_free(mac);
g_free(name);
DBG("-\n");
}
+//LCOV_EXCL_STOP
+//LCOV_EXCL_START
static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
DBG("-\n");
}
+//LCOV_EXCL_STOP
static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
DBG("-\n");
}
+//LCOV_EXCL_START
static void __handle_usb_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)
g_free(buf);
DBG("-\n");
}
+//LCOV_EXCL_STOP
static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
DBG("-\n");
}
-static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
- const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data)
-{
- DBG("+\n");
-
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_RESERVED;
- bool is_requested = false;
- tethering_enabled_cb ecb = NULL;
- void *data = NULL;
-
- ecb = th->enabled_cb[type];
- if (ecb == NULL)
- return;
- data = th->enabled_user_data[type];
-
- ecb(TETHERING_ERROR_NONE, type, is_requested, data);
- DBG("-\n");
-}
-
-static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
- const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data)
-{
- DBG("+\n");
-
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_RESERVED;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- char *buf= NULL;
-
- dcb = th->disabled_cb[type];
- if (dcb == NULL)
- return;
- data = th->disabled_user_data[type];
- g_variant_get(parameters, "(s)", &buf);
- if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
- code = TETHERING_DISABLED_BY_WIFI_ON;
- else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
- code = TETHERING_DISABLED_BY_TIMEOUT;
- g_free(buf);
-
- dcb(TETHERING_ERROR_NONE, type, code, data);
-
- DBG("-\n");
-}
-
+//LCOV_EXCL_START
static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
void *data = NULL;
tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
- for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
+ for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
dcb = th->disabled_cb[type];
if (dcb == NULL)
continue;
void *data = NULL;
tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
- for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
+ for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
dcb = th->disabled_cb[type];
if (dcb == NULL)
continue;
}
DBG("-\n");
}
+//LCOV_EXCL_STOP
static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
+ //LCOV_EXCL_START
ERR("DBus error [%s]\n", g_error->message);
if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
++retry < TETHERING_ERROR_RECOVERY_MAX) {
else
error = TETHERING_ERROR_OPERATION_FAILED;
g_error_free(g_error);
+ //LCOV_EXCL_STOP
} else {
g_variant_get(g_var, "(u)", &info);
error = __get_error(info);
DBG("-\n");
}
-static void __bt_enabled_cfm_cb (GObject *source_object, GAsyncResult *res,
+static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
DBG("+\n");
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
+ //LCOV_EXCL_START
ERR("DBus error [%s]\n", g_error->message);
if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
++retry < TETHERING_ERROR_RECOVERY_MAX) {
else
error = TETHERING_ERROR_OPERATION_FAILED;
g_error_free(g_error);
+ //LCOV_EXCL_STOP
} else {
g_variant_get(g_var, "(u)", &info);
g_variant_unref(g_var);
DBG("-\n");
}
-static void __usb_enabled_cfm_cb (GObject *source_object, GAsyncResult *res,
+//LCOV_EXCL_START
+static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
DBG("+\n");
ecb(error, TETHERING_TYPE_USB, true, data);
DBG("-\n");
}
-
-static void __wifi_ap_enabled_cfm_cb (GObject *source_object, GAsyncResult *res,
- gpointer user_data)
-{
- DBG("+\n");
-
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
- __tethering_h *th = (__tethering_h *)user_data;
- GError *g_error = NULL;
- GVariant *g_var;
- guint info;
- tethering_error_e error;
- tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_RESERVED];
- void *data = th->enabled_user_data[TETHERING_TYPE_RESERVED];
-
- g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
- if (g_error) {
- ERR("DBus error [%s]\n", g_error->message);
- if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
- ++retry < TETHERING_ERROR_RECOVERY_MAX) {
- g_error_free(g_error);
- tethering_enable((tethering_h)th, TETHERING_TYPE_RESERVED);
- DBG("-\n");
- return;
- }
- if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
- error = TETHERING_ERROR_PERMISSION_DENIED;
- else
- error = TETHERING_ERROR_OPERATION_FAILED;
- g_error_free(g_error);
- } else {
- g_variant_get(g_var, "(u)", &info);
- g_variant_unref(g_var);
- error = __get_error(info);
- }
- retry = 0;
-
- sigs[E_SIGNAL_WIFI_AP_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
- NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_ON].name,
- TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
- sigs[E_SIGNAL_WIFI_AP_ON].cb, (gpointer)th, NULL);
-
- if (!ecb) {
- DBG("-\n");
- return;
- }
-
- ecb(error, TETHERING_TYPE_RESERVED, true, data);
- DBG("-\n");
-}
+//LCOV_EXCL_STOP
static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
+ //LCOV_EXCL_START
ERR("DBus error [%s]\n", g_error->message);
g_error_free(g_error);
return;
+ //LCOV_EXCL_STOP
}
g_variant_get(g_var, "(uu)", &event_type, &info);
DBG("cfm event : %d info : %d\n", event_type, info);
dcb(error, type, code, data);
break;
+ //LCOV_EXCL_START
case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
if (dcb)
dcb(error, type, code, data);
break;
-
- case MOBILE_AP_DISABLE_WIFI_AP_CFM:
- sigs[E_SIGNAL_WIFI_AP_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
- NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_OFF].name,
- TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
- sigs[E_SIGNAL_WIFI_AP_OFF].cb, (gpointer)th, NULL);
-
- type = TETHERING_TYPE_RESERVED;
- dcb = th->disabled_cb[type];
- data = th->disabled_user_data[type];
- if (dcb)
- dcb(error, type, code, data);
- break;
+ //LCOV_EXCL_STOP
case MOBILE_AP_DISABLE_CFM:
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
+ //LCOV_EXCL_START
ERR("DBus fail [%s]\n", g_error->message);
if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
tethering_error = TETHERING_ERROR_OPERATION_FAILED;
flag = true;
+ //LCOV_EXCL_STOP
}
if (th->data_usage_cb == NULL) {
ERR("There is no data_usage_cb\n");
DBG("-\n");
}
-static void __ap_settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
- gpointer user_data)
-{
- DBG("+\n");
-
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
- GError *g_error = NULL;
- GVariant *g_var;
- guint info;
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_error_e tethering_error;
-
- g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
- if (g_error) {
- ERR("DBus fail [%s]\n", g_error->message);
- if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
- tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
- else
- tethering_error = TETHERING_ERROR_OPERATION_FAILED;
- g_error_free(g_error);
- }
- if (th->ap_settings_reloaded_cb == NULL) {
- DBG("There is no settings_reloaded_cb\n-\n");
- return;
- }
- g_variant_get(g_var, "(u)", &info);
- tethering_error = __get_error(info);
- g_variant_unref(g_var);
-
- th->ap_settings_reloaded_cb(tethering_error,
- th->ap_settings_reloaded_user_data);
-
- th->ap_settings_reloaded_cb = NULL;
- th->ap_settings_reloaded_user_data = NULL;
- DBG("-\n");
-}
-
static void __connect_signals(tethering_h tethering)
{
DBG("+\n");
int i = 0;
- for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
+ for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
- }
DBG("-\n");
}
_retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
switch (type) {
+ //LCOV_EXCL_START
case TETHERING_TYPE_USB:
g_strlcpy(buf, TETHERING_USB_IF, len);
break;
-
+ //LCOV_EXCL_STOP
case TETHERING_TYPE_WIFI:
g_strlcpy(buf, TETHERING_WIFI_IF, len);
break;
g_strlcpy(buf, TETHERING_BT_IF, len);
break;
- case TETHERING_TYPE_RESERVED:
- g_strlcpy(buf, TETHERING_WIFI_IF, len);
- break;
-
default:
ERR("Not supported type : %d\n", type);
return false;
g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
break;
- case TETHERING_TYPE_RESERVED:
- g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
- break;
-
default:
ERR("Not supported type : %d\n", type);
return false;
static int __get_common_ssid(char *ssid, unsigned int size)
{
if (ssid == NULL) {
- ERR("ssid is null\n");
+ ERR("ssid is null\n"); //LCOV_EXCL_LINE
return TETHERING_ERROR_INVALID_PARAMETER;
}
ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
if (ptr == NULL) {
- ERR("vconf_get_str is failed\n");
- DBG("-\n");
- return TETHERING_ERROR_OPERATION_FAILED;
- }
+ ERR("vconf_get_str is failed and set default ssid");
+ g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
+ } else
+ g_strlcpy(ssid, ptr, size);
- g_strlcpy(ssid, ptr, size);
free(ptr);
if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
return TETHERING_ERROR_NONE;
}
+static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
+{
+ _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
+
+ switch (type) {
+ case TETHERING_WIFI_MODE_TYPE_B:
+ *buf = g_strdup("b");
+ break;
+ case TETHERING_WIFI_MODE_TYPE_G:
+ *buf = g_strdup("g");
+ break;
+ case TETHERING_WIFI_MODE_TYPE_A:
+ *buf = g_strdup("a");
+ break;
+ case TETHERING_WIFI_MODE_TYPE_AD:
+ *buf = g_strdup("ad");
+ break;
+ default:
+ ERR("Not supported type : %d\n", type);
+ return false;
+ }
+ return true;
+}
+
static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
{
DBG("+\n");
__tethering_h *th = (__tethering_h *)tethering;
tethering_error_e ret = TETHERING_ERROR_NONE;
+ char *ptr = NULL;
if (th == NULL || set == NULL) {
ERR("null parameter\n-\n");
return TETHERING_ERROR_INVALID_PARAMETER;
}
- if (th->ssid == NULL) {
+ if (th->ssid == NULL)
__get_common_ssid(set->ssid, sizeof(set->ssid));
- } else {
+ else
g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
- }
ret = __get_security_type(&set->sec_type);
- if (ret != TETHERING_ERROR_NONE) {
+ if (ret != TETHERING_ERROR_NONE)
set->sec_type = th->sec_type;
- }
ret = __get_visible(&set->visibility);
- if (ret != TETHERING_ERROR_NONE) {
+ 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 (ptr == NULL) {
+ g_strlcpy(set->mode, "", sizeof(set->mode));
+ } else {
+ g_strlcpy(set->mode, ptr, sizeof(set->mode));
+ free(ptr);
}
if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
g_strlcpy(set->key, "", sizeof(set->key));
} else {
- char pass[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
+ GDBusProxy *proxy = th->client_bus_proxy;
+ GVariant *parameters;
+ GError *error = NULL;
+ char *passphrase = NULL;
unsigned int len = 0;
- ret = __get_passphrase(pass, sizeof(pass), &len);
- if (ret != TETHERING_ERROR_NONE) {
- ERR("getting passphrase failed\n");
- return TETHERING_ERROR_OPERATION_FAILED;
- }
- g_strlcpy(set->key, pass, sizeof(set->key));
- }
- DBG("-\n");
- return TETHERING_ERROR_NONE;
-}
+ parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-static int __prepare_wifi_ap_settings(tethering_h tethering, _softap_settings_t *set)
-{
- DBG("+\n");
+ if (error) {
+ //LCOV_EXCL_START
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
- __tethering_h *th = (__tethering_h *)tethering;
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ ret = TETHERING_ERROR_OPERATION_FAILED;
- if (th == NULL || set == NULL) {
- ERR("null parameter\n");
- return TETHERING_ERROR_INVALID_PARAMETER;
- }
+ g_error_free(error);
+ return ret;
+ //LCOV_EXCL_STOP
+ }
- g_strlcpy(set->ssid, th->ap_ssid, sizeof(set->ssid));
- set->sec_type = th->sec_type;
- set->visibility = th->visibility;
+ if (parameters != NULL) {
+ g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
+ g_variant_unref(parameters);
+ }
- if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
- g_strlcpy(set->key, "", sizeof(set->key));
- } else {
- g_strlcpy(set->key, th->passphrase, sizeof(set->key));
+ g_strlcpy(set->key, passphrase, sizeof(set->key));
}
DBG("-\n");
return TETHERING_ERROR_NONE;
int cellular_state = 0;
int wifi_state = 0;
- // data network through cellular
+ /* data network through cellular */
vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
- if(cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
+ if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
ERR("Data Network can be connected later");
return TRUE;
}
vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
- if(dnet_state > VCONFKEY_DNET_OFF) {
+ if (dnet_state > VCONFKEY_DNET_OFF) {
ERR("Data Network is connected");
return TRUE;
}
- // data network through wifi
- if(type != TETHERING_TYPE_WIFI) {
+ /* data network through wifi */
+ if (type != TETHERING_TYPE_WIFI) {
vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
- if(wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
+ if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
ERR("Wi-Fi is connected!");
return TRUE;
}
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;
if (__generate_initial_passphrase(th->passphrase,
sizeof(th->passphrase)) == 0) {
- ERR("random passphrase generation failed\n");
+ ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
}
if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
- ERR("common ssid get failed\n");
+ ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
}
- th->ap_ssid = g_strdup(ssid);
- if (th->ap_ssid == NULL) {
- ERR("g_strdup failed\n");
- free(th);
- return TETHERING_ERROR_OPERATION_FAILED;
- }
-
-#if !GLIB_CHECK_VERSION(2,36,0)
+#if !GLIB_CHECK_VERSION(2, 36, 0)
g_type_init();
#endif
GCancellable *cancellable = g_cancellable_new();
th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
if (error) {
+ //LCOV_EXCL_START
ERR("Couldn't connect to the System bus[%s]", error->message);
g_error_free(error);
g_cancellable_cancel(cancellable);
g_object_unref(cancellable);
- g_free(th->ap_ssid);
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
}
th->cancellable = cancellable;
- th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_NONE,
+ th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
if (!th->client_bus_proxy) {
- ERR("Couldn't create the proxy object because of %s\n", error->message);
+ //LCOV_EXCL_START
+ if (error)
+ ERR("Couldn't create the proxy object because of %s\n", error->message);
g_cancellable_cancel(th->cancellable);
g_object_unref(th->cancellable);
g_object_unref(th->client_bus);
- g_free(th->ap_ssid);
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
}
__connect_signals((tethering_h)th);
if (th->ssid)
free(th->ssid);
- if (th->ap_ssid)
- free(th->ap_ssid);
g_object_unref(th->cancellable);
g_object_unref(th->client_bus_proxy);
g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
- if(type != TETHERING_TYPE_RESERVED
- && __check_precondition(type) == FALSE) {
+ if (__check_precondition(type) == FALSE) {
+ //LCOV_EXCL_START
DBG("-\n");
return TETHERING_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
}
switch (type) {
+ //LCOV_EXCL_START
case TETHERING_TYPE_USB:
g_dbus_connection_signal_unsubscribe(connection,
sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
(GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
break;
+ //LCOV_EXCL_STOP
case TETHERING_TYPE_WIFI: {
- _softap_settings_t set = {"", "", 0, false};
+ _softap_settings_t set = {"", "", "", 0, false};
ret = __prepare_wifi_settings(tethering, &set);
if (ret != TETHERING_ERROR_NONE) {
sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
g_dbus_proxy_call(proxy, "enable_wifi_tethering",
- g_variant_new("(ssii)", set.ssid, set.key, 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;
break;
- case TETHERING_TYPE_RESERVED: {
- _softap_settings_t set = {"", "", 0, false};
-
- ret = __prepare_wifi_ap_settings(tethering, &set);
- if (ret != TETHERING_ERROR_NONE) {
- ERR("softap settings initialization failed\n");
- return TETHERING_ERROR_OPERATION_FAILED;
- }
-
- g_dbus_connection_signal_unsubscribe(connection,
- sigs[E_SIGNAL_WIFI_AP_ON].sig_id);
-
- g_dbus_proxy_call(proxy, "enable_wifi_ap",
- g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
- G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_ap_enabled_cfm_cb, (gpointer)tethering);
- break;
- }
+ //LCOV_EXCL_START
case TETHERING_TYPE_ALL: {
- _softap_settings_t set = {"", "", 0, false};
+ _softap_settings_t set = {"", "", "", 0, false};
ret = __prepare_wifi_settings(tethering, &set);
if (ret != TETHERING_ERROR_NONE) {
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
(GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
break;
+ //LCOV_EXCL_STOP
}
default:
ERR("Unknown type : %d\n", type);
(GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
break;
- case TETHERING_TYPE_RESERVED:
- g_dbus_connection_signal_unsubscribe(connection,
- sigs[E_SIGNAL_WIFI_AP_OFF].sig_id);
-
- g_dbus_proxy_call(proxy, "disable_wifi_ap",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
- (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
- break;
-
case TETHERING_TYPE_ALL:
g_dbus_connection_signal_unsubscribe(connection,
sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
(GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
break;
- default :
+ default:
ERR("Not supported tethering type [%d]\n", type);
DBG("-\n");
return TETHERING_ERROR_INVALID_PARAMETER;
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
- if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) {
+ if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
return FALSE;
- }
switch (type) {
case TETHERING_TYPE_USB:
vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
break;
- case TETHERING_TYPE_RESERVED:
- vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
- break;
-
default:
ERR("Not supported type : %d\n", type);
break;
result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
NULL, G_DBUS_CALL_FLAGS_NONE,
-1, th->cancellable, &error);
- if (error) {
+ if (error)
ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
- }
g_variant_get(result, "(a(a{sv}))", &outer_iter);
while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
g_variant_get(station, "a{sv}", &inner_iter);
client.interface = TETHERING_TYPE_WIFI;
else if (interface == MOBILE_AP_TYPE_BT)
client.interface = TETHERING_TYPE_BT;
- else if (interface == MOBILE_AP_TYPE_WIFI_AP)
- client.interface = TETHERING_TYPE_RESERVED;
else {
ERR("Invalid interface\n");
g_free(key);
break;
}
DBG("interface is %d\n", client.interface);
- if (client.interface != type && (TETHERING_TYPE_ALL != type &&
- client.interface != TETHERING_TYPE_RESERVED)) {
+ if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
g_free(key);
g_variant_unref(value);
break;
} else if (g_strcmp0(key, "Name") == 0) {
g_variant_get(value, "s", &hostname);
SDBG("hsotname is %s\n", hostname);
- if (hostname) {
+ if (hostname)
client.hostname = g_strdup(hostname);
- }
} else if (g_strcmp0(key, "Time") == 0) {
timestamp = g_variant_get_int32(value);
DBG("timestamp is %d\n", timestamp);
"parameter(passphrase) is NULL\n");
__tethering_h *th = (__tethering_h *)tethering;
+ GDBusProxy *proxy = th->client_bus_proxy;
+ GVariant *parameters;
+ GError *error = NULL;
int passphrase_len = 0;
+ int ret = 0;
- char old_passphrase[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
- unsigned int old_len = 0;
- tethering_error_e ret = TETHERING_ERROR_NONE;
-
+ DBG("+");
passphrase_len = strlen(passphrase);
if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
return TETHERING_ERROR_INVALID_PARAMETER;
}
- ret = __get_passphrase(old_passphrase, sizeof(old_passphrase), &old_len);
- if (ret == TETHERING_ERROR_NONE && old_len == passphrase_len &&
- !g_strcmp0(old_passphrase, passphrase)) {
- return TETHERING_ERROR_NONE;
+ parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
+ g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error) {
+ //LCOV_EXCL_START
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ ret = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return ret;
+ //LCOV_EXCL_STOP
}
- ret = __set_passphrase(passphrase, passphrase_len);
+ g_variant_get(parameters, "(u)", &ret);
+ g_variant_unref(parameters);
+
if (ret == TETHERING_ERROR_NONE) {
__send_dbus_signal(th->client_bus,
SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
}
+
+ DBG("-");
return ret;
}
_retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(passphrase) is NULL\n");
- char passphrase_buf[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
+ __tethering_h *th = (__tethering_h *)tethering;
+ GDBusProxy *proxy = th->client_bus_proxy;
+ GVariant *parameters;
+ GError *error = NULL;
unsigned int len = 0;
tethering_error_e ret = TETHERING_ERROR_NONE;
- ret = __get_passphrase(passphrase_buf, sizeof(passphrase_buf), &len);
- if (ret != TETHERING_ERROR_NONE)
+ parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error) {
+ //LCOV_EXCL_START
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ ret = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
return ret;
+ //LCOV_EXCL_STOP
+ }
- *passphrase = strdup(passphrase_buf);
- if (*passphrase == NULL) {
- ERR("strdup is failed\n");
- return TETHERING_ERROR_OUT_OF_MEMORY;
+ if (parameters != NULL) {
+ g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
+ g_variant_unref(parameters);
}
return TETHERING_ERROR_NONE;
}
+API int tethering_wifi_set_channel(tethering_h tethering, int channel)
+{
+ 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->channel = channel;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(channel) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ *channel = th->channel;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
+{
+ 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->mode_type = type;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(type) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ *type = th->mode_type;
+
+ return TETHERING_ERROR_NONE;
+}
+
+
/**
* @internal
* @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
"parameter(callback) is NULL\n");
__tethering_h *th = (__tethering_h *)tethering;
- _softap_settings_t set = {"", "", 0, false};
+ _softap_settings_t set = {"", "", "", 0, false};
GDBusProxy *proxy = th->client_bus_proxy;
int ret = 0;
th->settings_reloaded_user_data = user_data;
g_dbus_proxy_call(proxy, "reload_wifi_settings",
- g_variant_new("(ssii)", set.ssid, set.key, 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;
}
-/**
- * @internal
- * @brief Sets the security type of Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If security type is not set, WPA2_PSK is used
- * @param[in] tethering The handle of tethering
- * @param[in] type The security type
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
- * @see tethering_wifi_ap_get_security_type()
- */
-API int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
+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");
+ "parameter(tethering) is NULL\n");
__tethering_h *th = (__tethering_h *)tethering;
- th->sec_type = type;
+ th->mac_filter = mac_filter;
+
return TETHERING_ERROR_NONE;
}
-/**
- * @internal
- * @brief Gets the security type of Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If security type is not set, WPA2_PSK is used
- * @param[in] tethering The handle of tethering
- * @param[out] type The security type
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @see tethering_wifi_ap_set_security_type()
- */
-API int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
+API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
- _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(type) is NULL\n");
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(mac_filter) is NULL\n");
+ _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;
- *type = th->sec_type;
return TETHERING_ERROR_NONE;
}
-/**
- * @internal
- * @brief Sets the SSID (service set identifier) for Wi-Fi AP. The SSID cannot exceed 32 bytes.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If SSID is not set, Device name is used as SSID
- * @param[in] tethering The handle of tethering
- * @param[in] ssid The SSID
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
- */
-API int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid)
+static int __add_mac_to_file(const char *filepath, const char *mac)
{
- CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+ FILE *fp = NULL;
+ char line[MAX_BUF_SIZE] = "\0";
+ bool mac_exist = false;
+ char *p_mac = NULL;
- _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(tethering) is NULL\n");
- _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(ssid) is NULL\n");
+ p_mac = strdup(mac);
+ if (p_mac == NULL) {
+ ERR("strdup failed\n");
+ return TETHERING_ERROR_OUT_OF_MEMORY;
+ }
- __tethering_h *th = (__tethering_h *)tethering;
- char *p_ssid = NULL;
- int ssid_len = 0;
+ fp = fopen(filepath, "a+");
+ if (!fp) {
+ ERR("fopen is failed\n");
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
- ssid_len = strlen(ssid);
- if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
- ERR("parameter(ssid) is too long");
- return TETHERING_ERROR_INVALID_PARAMETER;
+ 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;
+ }
}
- p_ssid = strdup(ssid);
- if (p_ssid == NULL) {
- ERR("strdup failed\n");
- return TETHERING_ERROR_OUT_OF_MEMORY;
+ 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);
}
- if (th->ap_ssid)
- g_free(th->ap_ssid);
- th->ap_ssid = p_ssid;
+ fclose(fp);
return TETHERING_ERROR_NONE;
}
-/**
- * @internal
- * @brief Gets the SSID (service set identifier) for Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If SSID is not set, Device name is used as SSID
- * @remarks @a ssid must be released with free() by you.
- * @param[in] tethering The handle of tethering
- * @param[out] ssid The SSID
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
- */
-API int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid)
+static int __remove_mac_from_file(const char *filepath, const char *mac)
{
- CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+ FILE *fp = NULL;
+ FILE *fp1 = NULL;
+ char line[MAX_BUF_SIZE] = "\0";
- _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(tethering) is NULL\n");
- _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(ssid) is NULL\n");
+ fp = fopen(filepath, "r");
+ if (!fp) {
+ ERR("fopen is failed\n");
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
- __tethering_h *th = (__tethering_h *)tethering;
+ fp1 = fopen(TEMP_LIST, "w+");
+ if (!fp1) {
+ fclose(fp);
+ ERR("fopen is failed\n");
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
- *ssid = g_strdup(th->ap_ssid);
- if (*ssid == NULL) {
- ERR("strdup failed\n");
- return TETHERING_ERROR_OUT_OF_MEMORY;
+ while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
+ if (strncmp(mac, line, 17) == 0) {
+ DBG("MAC %s found in the list\n", mac);
+
+ 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);
+ 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;
}
-/**
- * @internal
- * @brief Sets the visibility of SSID(service set identifier) for Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
- * @details by default visibility is set to true.
- * @remarks This change is applied next time Wi-Fi tethering is enabled
- * @param[in] tethering The handle of tethering
- * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
- * @see tethering_wifi_ap_get_ssid_visibility()
- */
-API int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible)
+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");
+ "parameter(tethering) is NULL\n");
+ _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(mac) is NULL\n");
- __tethering_h *th = (__tethering_h *)tethering;
- th->visibility = visible;
+ return __add_mac_to_file(ALLOWED_LIST, mac);
+}
+
+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,
+ "parameter(mac) is NULL\n");
+
+ 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;
}
-/**
- * @internal
- * @brief Gets the visibility of SSID(service set identifier) for Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
- * @details by default visibility is set to true.
- * @param[in] tethering The handle of tethering
- * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @see tethering_wifi_ap_set_ssid_visibility()
- */
-API int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible)
+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,
+ "parameter(mac) is NULL\n");
- _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(visible) is NULL\n");
+ return __add_mac_to_file(BLOCKED_LIST, mac);
+}
- __tethering_h *th = (__tethering_h *)tethering;
+API int tethering_wifi_remove_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,
+ "parameter(mac) is NULL\n");
+
+ return __remove_mac_from_file(BLOCKED_LIST, mac);
+}
- *visible = th->visibility;
+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;
}
-/**
- * @internal
- * @brief Sets the passphrase for Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If the passphrase is not set, random string of 8 alphabets will be used.
- * @param[in] tethering The handle of tethering
- * @param[in] passphrase The passphrase
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @see tethering_wifi_ap_get_passphrase()
- */
-API int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase)
+API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
_retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(tethering) is NULL\n");
- _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(passphrase) is NULL\n");
+ "parameter(tethering) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
__tethering_h *th = (__tethering_h *)tethering;
- int passphrase_len = 0;
- passphrase_len = strlen(passphrase);
+ GDBusProxy *proxy = th->client_bus_proxy;
- if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
- passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
- ERR("parameter(passphrase) is too short or long\n");
- return TETHERING_ERROR_INVALID_PARAMETER;
+ parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
+ g_variant_new("(b)", enable),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ th->dhcp_enabled = false;
+
+ return result;
}
- if (!g_strcmp0(passphrase, th->passphrase))
- return TETHERING_ERROR_NONE;
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ if (enable)
+ th->dhcp_enabled = true;
+ else
+ th->dhcp_enabled = false;
- g_strlcpy(th->passphrase, passphrase, sizeof(th->passphrase));
return TETHERING_ERROR_NONE;
}
-/**
- * @internal
- * @brief Gets the passphrase for Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @details If the passphrase is not set, random string of 8 alphabets will be used.
- * @remarks @a passphrase must be released with free() by you.
- * @param[in] tethering The handle of tethering
- * @param[out] passphrase The passphrase
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
- * @see tethering_wifi_ap_set_passphrase()
- */
-API int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase)
+API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
_retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(tethering) is NULL\n");
- _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(passphrase) is NULL\n");
+ _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(rangestart) is NULL\n");
+ _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(rangestop) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
__tethering_h *th = (__tethering_h *)tethering;
- *passphrase = g_strdup(th->passphrase);
- if (*passphrase == NULL) {
- ERR("strdup is failed\n");
- return TETHERING_ERROR_OUT_OF_MEMORY;
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
+ g_variant_new("(ss)", rangestart, rangestop),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ th->dhcp_enabled = false;
+
+ return result;
}
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ th->dhcp_enabled = true;
+
return TETHERING_ERROR_NONE;
}
-/**
- * @internal
- * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP.
- * @since_tizen 2.3
- * @privlevel platform
- * @privilege http://tizen.org/privilege/tethering.admin
- * @remarks Connected devices via MobileAP will be disconnected when the settings are reloaded
- * @param[in] tethering The handle of tethering
- * @param[in] callback The callback function to invoke
- * @param[in] user_data The user data to be passed to the callback function
- * @return 0 on success, otherwise negative error value.
- * @retval #TETHERING_ERROR_NONE Successful
- * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
- */
-API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data)
-
+API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
-
_retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(tethering) is NULL\n");
- _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
- "parameter(callback) is NULL\n");
+ _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(dhcp_enabled) is NULL\n");
__tethering_h *th = (__tethering_h *)tethering;
- _softap_settings_t set = {"", "", 0, false};
- GDBusProxy *proxy = th->client_bus_proxy;
- int ret = 0;
+ *dhcp_enabled = th->dhcp_enabled;
- DBG("+\n");
+ return TETHERING_ERROR_NONE;
+}
- if (th->ap_settings_reloaded_cb) {
- ERR("Operation in progress\n");
- return TETHERING_ERROR_OPERATION_FAILED;
- }
+API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
+{
+ GError *error = NULL;
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
- ret = __prepare_wifi_ap_settings(tethering, &set);
- if (ret != TETHERING_ERROR_NONE) {
- ERR("softap settings initialization failed\n");
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
+ TETHERING_ERROR_NOT_ENABLED,
+ "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
+ g_variant_new("(u)", txpower),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, th->cancellable, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+ g_clear_error(&error);
return TETHERING_ERROR_OPERATION_FAILED;
}
+ return TETHERING_ERROR_NONE;
+}
- th->ap_settings_reloaded_cb = callback;
- th->ap_settings_reloaded_user_data = user_data;
+API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
+{
+ GError *error = NULL;
+ GVariant *result = NULL;
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
- g_dbus_proxy_call(proxy, "reload_wifi_ap_settings",
- g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
- G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
- (GAsyncReadyCallback) __ap_settings_reloaded_cb, (gpointer)tethering);
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
+ TETHERING_ERROR_NOT_ENABLED,
+ "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, th->cancellable, &error);
+
+ if (result != NULL) {
+ g_variant_get(result, "(u)", txpower);
+ g_variant_unref(result);
+ } else {
+ if (error)
+ ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+ g_clear_error(&error);
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+ g_clear_error(&error);
return TETHERING_ERROR_NONE;
}
+