void _close_network(void);
gboolean _init_network(void *user_data);
gboolean _deinit_network(void);
+char *_get_wifi_source_interface_name(void);
#endif /* __MOBILEAP_NETWORK_H__ */
#define P2P_IF "p2p0"
#define WIFI_IF "wlan0"
+#define WIFI_IF_1 "wlan1"
#define IP_ADDRESS_WIFI 0xC0A82B02 /* 192.168.43.2 */
#define SOFTAP_IF "wl0.1"
#define CHECK_NET_STATE_RETRY_COUNT 5
#define PSK_ITERATION_COUNT 4096
+#define WIFI_TETHER_TYPE_LEN 15 /**< Maximum length of tethering type */
+
typedef enum {
SOFTAP_SECURITY_TYPE_OPEN = 0,
SOFTAP_SECURITY_TYPE_WPA2_PSK,
uint32_t ip_addr;
int txpower;
+ char tether_type[WIFI_TETHER_TYPE_LEN + 1];
} softap_settings_t;
typedef struct {
/* ssid : 32 key : 64 */
int _mh_core_enable_softap(const mobile_ap_type_e type, softap_settings_t *settings);
-int _mh_core_disable_softap(void);
+int _mh_core_disable_softap(char *if_name);
int _mh_core_execute_dhcp_server(gchar *softap_rangestart, gchar *softap_rangestop);
int _mh_core_terminate_dhcp_server(void);
int _mh_core_enable_masquerade(const char *ext_if);
mobile_ap_error_code_e _reload_softap_settings(Tethering *obj, softap_settings_t *settings);
gboolean tethering_enable_wifi_tethering(Tethering *obj,
- GDBusMethodInvocation *context, gchar *ssid,
+ GDBusMethodInvocation *context, gchar *tether_type, gchar *ssid,
gchar *key, gchar *mode, gint channel, gint visibility,
gint mac_filter, gint max_sta, gint security_type,
gint txpower, gint address_type);
</method>
<method name="enable_wifi_tethering">
+ <arg type="s" name="tether_type" direction="in"/>
<arg type="s" name="ssid" direction="in"/>
<arg type="s" name="key" direction="in"/>
<arg type="s" name="mode" direction="in"/>
return TRUE;
}
+ char *src_if = _get_wifi_source_interface_name();
if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI))
- _get_data_usage(WIFI_IF, if_name,
+ _get_data_usage(src_if, if_name,
&wifi_tx_bytes, &wifi_rx_bytes);
if (_mobileap_is_enabled(MOBILE_AP_STATE_BT))
static connection_profile_h tethered_prof = NULL;
static GSList *port_forward_info = NULL;
+/* wifi-sharing source interface */
+const char *g_sharing_if = NULL;
+
static gboolean __try_to_open_tethering_profile(gpointer user_data);
//LCOV_EXCL_START
return FALSE;
}
+char *_get_wifi_source_interface_name(void)
+{
+ if (g_sharing_if)
+ return (char *)g_sharing_if;
+
+ return WIFI_IF;
+}
+
gboolean _get_network_interface_name(char **if_name)
{
if (if_name == NULL) {
gboolean _set_masquerade(void)
{
+ /* default connected interface */
char *if_name = NULL;
if (_get_network_interface_name(&if_name) == FALSE) {
}
SDBG("Network interface : %s\n", if_name);
+ /* wifi-sharing: set wifi source interface name */
+ if (g_strcmp0(if_name, WIFI_IF) == 0)
+ g_sharing_if = WIFI_IF_1;
+ else if (g_strcmp0(if_name, WIFI_IF_1) == 0)
+ g_sharing_if = WIFI_IF;
+ else
+ g_sharing_if = NULL;
+
+ if (g_sharing_if)
+ SDBG("wifi-sharing source interface: %s", g_sharing_if);
+
_mh_core_enable_masquerade(if_name);
free(if_name);
static void __generate_eui64_address(int idx, const char *hw_addr, char **eui64_addr);
#endif
+const char *g_tether_type = NULL;
static gboolean __hostapd_connect_timer_cb(gpointer user_data);
static char *__find_first_caps_char(char *str)
pid_t pid;
int ret;
char key[MOBILE_AP_WIFI_KEY_MAX_LEN + 1];
+ char *src_if = _get_wifi_source_interface_name();
ret = __make_hostapd_dir();
if (ret != MOBILE_AP_ERROR_NONE)
#ifdef TIZEN_FEATURE_HEADLESS
snprintf(buf, sizeof(buf), HOSTAPD_RPI_CONF,
- WIFI_IF,
+ src_if,
HOSTAPD_CTRL_INTF_DIR,
settings->ssid,
settings->channel,
settings->max_sta);
#else
snprintf(buf, sizeof(buf), HOSTAPD_CONF,
- WIFI_IF,
+ src_if,
HOSTAPD_CTRL_INTF_DIR,
settings->ssid,
settings->channel,
char *old_conf = NULL;
char buf[HOSTAPD_CONF_LEN] = "";
char key[MOBILE_AP_WIFI_KEY_MAX_LEN + 1];
+ char *src_if = _get_wifi_source_interface_name();
FILE *fp = NULL;
pid_t pid;
}
/* Default conf. */
snprintf(buf, sizeof(buf), HOSTAPD_WPS_CONF,
- WIFI_IF, HOSTAPD_CTRL_INTF_DIR,
+ src_if,
+ HOSTAPD_CTRL_INTF_DIR,
settings->ssid,
settings->channel,
settings->hide_mode,
}
snprintf(ctrl_intf, sizeof(ctrl_intf), "%s/%s",
- HOSTAPD_CTRL_INTF_DIR, WIFI_IF);
+ HOSTAPD_CTRL_INTF_DIR, _get_wifi_source_interface_name());
+ ERR("hostapd ctrl_intf [%s]\n", ctrl_intf); //LCOV_EXCL_LINE
+
dest.sun_family = AF_UNIX;
g_strlcpy(dest.sun_path, ctrl_intf, sizeof(dest.sun_path));
return drv_interface;
}
-static int __mh_core_softap_firmware_start(void)
+static int __mh_core_softap_firmware_start(const char *tether_type, const char *src_if)
{
int err = 0;
DBusError error;
DBusConnection *connection = NULL;
const char *device = "softap";
+ if (g_strcmp0(tether_type, "wifi_sharing") == 0) {
+ g_tether_type = "wifi_sharing";
+
+ char buf[20] = {'\0'};
+ snprintf(buf, sizeof(buf), "%s_%s", tether_type, src_if);
+
+ device = buf;
+ }
+ DBG("Start Device: %s", device);
+
DBG("+");
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
if (connection == NULL) {
return err;
}
-static int __mh_core_softap_firmware_stop(void)
+static int __mh_core_softap_firmware_stop(const char *src_if)
{
int err = 0;
DBusError error;
DBusConnection *connection = NULL;
const char *device = "softap";
+ if (g_strcmp0(g_tether_type, "wifi_sharing") == 0) {
+
+ char buf[20] = {'\0'};
+ snprintf(buf, sizeof(buf), "%s_%s", g_tether_type, src_if);
+
+ device = buf;
+ }
+
+ DBG("Stop device: %s", device);
+
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
if (connection == NULL) {
ERR("Failed to get system bus"); //LCOV_EXCL_LINE
mobile_ap_drv_interface_e drv_interface = MOBILE_AP_DRV_INTERFACE_NONE;
int sock_fd;
- char *if_name = WIFI_IF;
char buf[MAX_BUF_SIZE] = { 0 };
-
char wext_ssid[MOBILE_AP_WIFI_SSID_MAX_LEN] = { 0 };
char *ptr = NULL;
char *wlan_hw_addr = NULL;
char *wlan_ipv6_address = NULL;
- if (__mh_core_softap_firmware_start() < 0)
+ /** source wifi interface name */
+ char *if_name = _get_wifi_source_interface_name();
+ if (!if_name) {
+ ERR("Source interface is null.\n");
+ return MOBILE_AP_ERROR_INTERNAL;
+ }
+
+ if (__mh_core_softap_firmware_start(settings->tether_type, if_name) < 0)
return MOBILE_AP_ERROR_INTERNAL;
drv_interface = __get_drv_interface();
+ DBG("source if_name: %s", if_name);
+
switch (drv_interface) {
#ifndef TIZEN_FEATURE_UNITTEST
case MOBILE_AP_WEXT:
break;
}
- ret_status = _mh_core_set_ip_address(WIFI_IF,
+ ret_status = _mh_core_set_ip_address(if_name,
IP_ADDRESS_WIFI);
if (ret_status != MOBILE_AP_ERROR_NONE) {
- ERR("_mh_core_set_ip_address of WIFI_IF is failed\n"); //LCOV_EXCL_LINE
+ ERR("_mh_core_set_ip_address of if_name: %s is failed\n", if_name); //LCOV_EXCL_LINE
break;
}
break;
#ifdef TIZEN_FEATURE_ENABLE_IPV6
if (settings->address_type == MOBILE_AP_ADDRESS_TYPE_IPV6) {
/* Setup IPv6 address for wlan0 */
- ret_status = _get_hw_address(WIFI_IF, &wlan_hw_addr);
+ ret_status = _get_hw_address(if_name, &wlan_hw_addr);
if (ret_status != MOBILE_AP_ERROR_NONE || wlan_hw_addr == NULL) {
ERR("Failed to get network hw address"); //LCOV_EXCL_LINE
break;
ret_status = _mh_core_create_ipv6_address(0,
(const char *)wlan_hw_addr, &wlan_ipv6_address);
if (wlan_ipv6_address) {
- ret_status = _enable_ipv6(WIFI_IF);
+ ret_status = _enable_ipv6(if_name);
if (ret_status != MOBILE_AP_ERROR_NONE)
break;
- ret_status = _mh_core_set_ipv6_address(WIFI_IF, wlan_ipv6_address);
+ ret_status = _mh_core_set_ipv6_address(if_name, wlan_ipv6_address);
if (ret_status != MOBILE_AP_ERROR_NONE) {
- ERR("Failed to set ip address"); //LCOV_EXCL_LINE
+ ERR("Failed to set ip address on %s", if_name); //LCOV_EXCL_LINE
break;
}
}
} else {
#endif
if (settings->ip_addr > 0)
- ret_status = _mh_core_set_ip_address(WIFI_IF,
+ ret_status = _mh_core_set_ip_address(if_name,
settings->ip_addr);
else
- ret_status = _mh_core_set_ip_address(WIFI_IF,
+ ret_status = _mh_core_set_ip_address(if_name,
IP_ADDRESS_SOFTAP);
if (ret_status != MOBILE_AP_ERROR_NONE) {
- ERR("_mh_core_set_ip_address is failed\n"); //LCOV_EXCL_LINE
+ ERR("_mh_core_set_ip_address is failed on %s\n", if_name); //LCOV_EXCL_LINE
break;
}
#ifdef TIZEN_FEATURE_ENABLE_IPV6
}
if (ret_status != MOBILE_AP_ERROR_NONE)
- __mh_core_softap_firmware_stop();
+ __mh_core_softap_firmware_stop(if_name);
g_free(wlan_hw_addr);
g_free(wlan_ipv6_address);
return ret_status;
}
-int _mh_core_disable_softap(void)
+int _mh_core_disable_softap(char *if_name)
{
char cmd[MAX_BUF_SIZE] = { 0 };
int ret_status = MOBILE_AP_ERROR_NONE;
int sock_fd = 0;
char buf[MAX_BUF_SIZE] = { 0 };
- char *if_name = WIFI_IF;
drv_interface = __get_drv_interface();
break;
}
- if (__mh_core_softap_firmware_stop() < 0)
+ if (__mh_core_softap_firmware_stop(if_name) < 0)
ret_status = MOBILE_AP_ERROR_INTERNAL;
return ret_status;
}
int fd = -1;
+ char *src_if = _get_wifi_source_interface_name();
+ ERR("src_if: %s ext_if: %s", src_if, ext_if);
fd = open(IP_FORWARD, O_WRONLY);
if (fd < 0) {
_iptables_add_rule(FORWARD_RULE_WITH_ACTION_AND_STATE, TABLE_FILTER, TETH_FILTER_FW,
BT_IF_ALL, ext_if, ACTION_RETURN, STATE_RELATED_ESTAB);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION_AND_STATE, TABLE_FILTER, TETH_FILTER_FW,
- WIFI_IF, ext_if, ACTION_RETURN, STATE_RELATED_ESTAB);
+ src_if, ext_if, ACTION_RETURN, STATE_RELATED_ESTAB);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION_AND_STATE, TABLE_FILTER, TETH_FILTER_FW,
USB_IF, ext_if, ACTION_RETURN, STATE_RELATED_ESTAB);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION_AND_STATE, TABLE_FILTER, TETH_FILTER_FW,
ext_if, BT_IF_ALL, ACTION_DROP, STATE_INVALID);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION_AND_STATE, TABLE_FILTER, TETH_FILTER_FW,
- ext_if, WIFI_IF, ACTION_DROP, STATE_INVALID);
+ ext_if, src_if, ACTION_DROP, STATE_INVALID);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION_AND_STATE, TABLE_FILTER, TETH_FILTER_FW,
ext_if, USB_IF, ACTION_DROP, STATE_INVALID);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION, TABLE_FILTER, TETH_FILTER_FW,
ext_if, BT_IF_ALL, ACTION_RETURN);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION, TABLE_FILTER, TETH_FILTER_FW,
- ext_if, WIFI_IF, ACTION_RETURN);
+ ext_if, src_if, ACTION_RETURN);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION, TABLE_FILTER, TETH_FILTER_FW,
ext_if, USB_IF, ACTION_RETURN);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION, TABLE_FILTER, TETH_FILTER_FW,
BT_IF_ALL, ext_if, ACTION_RETURN);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION, TABLE_FILTER, TETH_FILTER_FW,
- WIFI_IF, ext_if, ACTION_RETURN);
+ src_if, ext_if, ACTION_RETURN);
_iptables_add_rule(FORWARD_RULE_WITH_ACTION, TABLE_FILTER, TETH_FILTER_FW,
USB_IF, ext_if, ACTION_RETURN);
#else
struct ifreq ifr;
int fd;
+ char *src_if = _get_wifi_source_interface_name();
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
&ifr.ifr_hwaddr.sa_data[0],
return MOBILE_AP_ERROR_INTERNAL;
}
- strncpy(ifr.ifr_name, WIFI_IF, IFNAMSIZ);
+ strncpy(ifr.ifr_name, src_if, IFNAMSIZ);
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
if (ioctl(fd, SIOCSIFHWADDR, &ifr) == -1) {
#include "mobileap_common.h"
#include "mobileap_wifi.h"
#include "mobileap_handler.h"
+#include "mobileap_network.h"
#include "mobileap_notification.h"
#ifndef IFNAMSIZ
dst->address_type = src->address_type;
dst->ip_addr = src->ip_addr;
dst->txpower = src->txpower;
+ g_strlcpy(dst->tether_type, src->tether_type, sizeof(dst->tether_type));
SDBG("ssid : %s security type : %d ip address: 0x%X hide mode : %d mac filter : %d max_sta: %d hw_mode: %s vendor: %s txpower: %d\n",
dst->ssid, dst->security_type, dst->ip_addr, dst->hide_mode, dst->mac_filter, dst->max_sta, dst->mode, dst->vendor_elements, dst->txpower);
_start_timeout_cb(MOBILE_AP_TYPE_WIFI, time(NULL) + TETHERING_CONN_TIMEOUT);
if (obj_softap_settings.address_type != MOBILE_AP_ADDRESS_TYPE_IPV6) {
- _add_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
- _add_routing_rule(WIFI_IF);
+ char *src_if = _get_wifi_source_interface_name();
+ DBG("wifi source interface: %s", src_if);
+
+ _add_interface_routing(src_if, IP_ADDRESS_SOFTAP);
+ _add_routing_rule(src_if);
#ifdef TIZEN_FEATURE_MULTICAST
- _add_multicast_routing(WIFI_IF);
+ _add_multicast_routing(src_if);
#endif
}
if (!_mobileap_is_enabled(state)) {
ERR("Wi-Fi tethering ap has not been activated\n"); //LCOV_EXCL_LINE
- ret = MOBILE_AP_ERROR_NOT_ENABLED;
- return ret;
+ return MOBILE_AP_ERROR_NOT_ENABLED;
+ }
+
+ char *src_if = _get_wifi_source_interface_name();
+ if (!src_if) {
+ ERR("Source interface is null\n"); //LCOV_EXCL_LINE
+ return MOBILE_AP_ERROR_INTERNAL;
}
_block_device_sleep();
if (address_type != MOBILE_AP_ADDRESS_TYPE_IPV6) {
#ifdef TIZEN_FEATURE_MULTICAST
- _del_multicast_routing(WIFI_IF);
+ _del_multicast_routing(src_if);
#endif
- _del_routing_rule(WIFI_IF);
- _del_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
+ _del_routing_rule(src_if);
+ _del_interface_routing(src_if, IP_ADDRESS_SOFTAP);
}
- _flush_ip_address(WIFI_IF);
+ _flush_ip_address(src_if);
_deinit_timeout_cb(type);
if (_remove_station_info_all(type) != MOBILE_AP_ERROR_NONE)
ERR("_remove_station_info_all is failed. Ignore it.\n"); //LCOV_EXCL_LINE
- ret = _mh_core_disable_softap();
+ ret = _mh_core_disable_softap(src_if);
if (ret != MOBILE_AP_ERROR_NONE) {
ERR("_mh_core_disable_softap is failed : %d\n", ret); //LCOV_EXCL_LINE
goto DONE;
notification_handler.delete_timeout_noti();
_init_timeout_cb(MOBILE_AP_TYPE_WIFI_AP, (void *)obj);
_start_timeout_cb(MOBILE_AP_TYPE_WIFI_AP, time(NULL) + WIFI_AP_CONN_TIMEOUT);
+
+ char *src_if = _get_wifi_source_interface_name();
if (obj_softap_settings.ip_addr > 0)
- _add_interface_routing(WIFI_IF, obj_softap_settings.ip_addr);
+ _add_interface_routing(src_if, obj_softap_settings.ip_addr);
else
- _add_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
- _add_routing_rule(WIFI_IF);
+ _add_interface_routing(src_if, IP_ADDRESS_SOFTAP);
+ _add_routing_rule(src_if);
#ifdef TIZEN_FEATURE_MULTICAST
- _add_multicast_routing(WIFI_IF);
+ _add_multicast_routing(src_if);
#endif
DONE:
if (!_mobileap_is_enabled(state)) {
ERR("Wi-Fi ap tethering has not been activated\n"); //LCOV_EXCL_LINE
- ret = MOBILE_AP_ERROR_NOT_ENABLED;
- return ret;
+ return MOBILE_AP_ERROR_NOT_ENABLED;
+ }
+
+ char *src_if = _get_wifi_source_interface_name();
+ if (!src_if) {
+ ERR("Source interface is null\n"); //LCOV_EXCL_LINE
+ return MOBILE_AP_ERROR_INTERNAL;
}
_block_device_sleep();
#ifdef TIZEN_FEATURE_MULTICAST
- _del_multicast_routing(WIFI_IF);
+ _del_multicast_routing(src_if);
#endif
- _del_routing_rule(WIFI_IF);
- _del_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
- _flush_ip_address(WIFI_IF);
+ _del_routing_rule(src_if);
+ _del_interface_routing(src_if, IP_ADDRESS_SOFTAP);
+ _flush_ip_address(src_if);
_deinit_timeout_cb(type);
if (_remove_station_info_all(type) != MOBILE_AP_ERROR_NONE)
ERR("_remove_station_info_all is failed. Ignore it.\n"); //LCOV_EXCL_LINE
- ret = _mh_core_disable_softap();
+ ret = _mh_core_disable_softap(src_if);
if (ret != MOBILE_AP_ERROR_NONE) {
ERR("_mh_core_disable_softap is failed : %d\n", ret); //LCOV_EXCL_LINE
goto DONE;
}
gboolean tethering_enable_wifi_tethering(Tethering *obj,
- GDBusMethodInvocation *context, gchar *ssid,
+ GDBusMethodInvocation *context, gchar *tether_type, gchar *ssid,
gchar *key, gchar *mode, gint channel, gint visibility,
gint mac_filter, gint max_sta, gint security_type,
gint txpower, gint address_type)
wifi_settings.max_sta = max_sta;
wifi_settings.address_type = address_type;
wifi_settings.txpower = txpower;
+ g_strlcpy(wifi_settings.tether_type, tether_type, sizeof(wifi_settings.tether_type));
if (wifi_recovery_timeout_id) {
DBG("Wi-Fi recovery is cancelled\n"); //LCOV_EXCL_LINE
prev_wifi_on = TRUE;
}
+ if (g_strcmp0(wifi_settings.tether_type, "wifi_tether") == 0) {
#ifdef TIZEN_FEATURE_ENABLE_WIFI_DIRECT
- if (__is_wifi_direct_on() == TRUE) {
- DBG("Wi-Fi and Wi-Fi direct are turned on\n");
- if (__turn_off_wifi_direct(obj) != MOBILE_AP_ERROR_NONE) {
- ERR("_turn_off_wifi_direct is failed\n"); //LCOV_EXCL_LINE
- ret = MOBILE_AP_ERROR_INTERNAL;
- goto DONE;
+ if (__is_wifi_direct_on() == TRUE) {
+ DBG("Wi-Fi and Wi-Fi direct are turned on\n");
+ if (__turn_off_wifi_direct(obj) != MOBILE_AP_ERROR_NONE) {
+ ERR("_turn_off_wifi_direct is failed\n"); //LCOV_EXCL_LINE
+ ret = MOBILE_AP_ERROR_INTERNAL;
+ goto DONE;
+ }
+ g_object_ref(g_context);
+ return TRUE;
}
- g_object_ref(g_context);
- return TRUE;
- }
#endif
- wifi_manager_is_activated(wifi_manager, &wifi_state);
- if (wifi_state == true) {
- DBG("Wi-Fi is turned on\n"); //LCOV_EXCL_LINE
- if (__turn_off_wifi(obj) != MOBILE_AP_ERROR_NONE) {
- ERR("_turn_off_wifi is failed\n"); //LCOV_EXCL_LINE
- ret = MOBILE_AP_ERROR_INTERNAL;
- goto DONE;
+ wifi_manager_is_activated(wifi_manager, &wifi_state);
+ if (wifi_state == true) {
+ DBG("Wi-Fi is turned on\n"); //LCOV_EXCL_LINE
+ if (__turn_off_wifi(obj) != MOBILE_AP_ERROR_NONE) {
+ ERR("_turn_off_wifi is failed\n"); //LCOV_EXCL_LINE
+ ret = MOBILE_AP_ERROR_INTERNAL;
+ goto DONE;
+ }
+ g_object_ref(g_context);
+ return TRUE;
}
- g_object_ref(g_context);
- return TRUE;
+ } else {
+ /* wifi sharing */
}
ret = _enable_wifi_tethering(obj, &wifi_settings);