}
}
- INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
- set->ssid, set->sec_type, set->mode, set->channel,
- (set->visibility) ? "true" : "false");
+ if (strlen(th->ip_address))
+ g_strlcpy(set->ip_address, th->ip_address, sizeof(set->ip_address));
+ else
+ g_strlcpy(set->ip_address, TETHERING_WIFI_GATEWAY, sizeof(set->ip_address));
+
+ INFO("ssid: %s security: %d mode: %s "
+ "channel: %d visibility: %s ip_address: [%s]\n",
+ set->ssid, set->sec_type, set->mode, set->channel,
+ (set->visibility) ? "true" : "false",
+ set->ip_address);
INFO("-\n");
return TETHERING_ERROR_NONE;
}
return TETHERING_ERROR_NONE;
}
+static GVariant *__get_wifi_settings_dbus_params(const char *wifi_tether_type, _softap_settings_t *set)
+{
+ GVariantBuilder *builder = NULL;
+ GVariant *params = NULL;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ if (builder == NULL) {
+ ERR("Failed to create builder");
+ return NULL;
+ }
+
+ g_variant_builder_add(builder, "{sv}",
+ "ssid",
+ g_variant_new_string(set->ssid));
+
+ if (set->sec_type != TETHERING_WIFI_SECURITY_TYPE_NONE)
+ g_variant_builder_add(builder, "{sv}",
+ "passphrase",
+ g_variant_new_string(set->key));
+
+ if (!g_strcmp0(set->mode, "b")) {
+ g_variant_builder_add(builder, "{sv}",
+ "mode", g_variant_new_int32(0));
+ } else if (!g_strcmp0(set->mode, "g")) {
+ g_variant_builder_add(builder, "{sv}",
+ "mode", g_variant_new_int32(1));
+ } else if (!g_strcmp0(set->mode, "n")) {
+ g_variant_builder_add(builder, "{sv}",
+ "mode", g_variant_new_int32(2));
+ } else if (!g_strcmp0(set->mode, "ac")) {
+ g_variant_builder_add(builder, "{sv}",
+ "mode", g_variant_new_int32(3));
+ } else {
+ /* Do Nothing */
+ }
+
+ g_variant_builder_add(builder, "{sv}",
+ "visibility",
+ g_variant_new_boolean(set->visibility));
+
+ g_variant_builder_add(builder, "{sv}",
+ "channel",
+ g_variant_new_int32(set->channel));
+
+ g_variant_builder_add(builder, "{sv}",
+ "sec_type",
+ g_variant_new_int32(set->sec_type));
+
+ g_variant_builder_add(builder, "{sv}",
+ "mac_filter",
+ g_variant_new_boolean(set->mac_filter));
+
+ g_variant_builder_add(builder, "{sv}",
+ "max_sta",
+ g_variant_new_int32(set->max_connected));
+
+ g_variant_builder_add(builder, "{sv}",
+ "address_type",
+ g_variant_new_int32(TETHERING_ADDRESS_FAMILY_IPV4));
+
+ g_variant_builder_add(builder, "{sv}",
+ "txpower",
+ g_variant_new_int32(set->txpower));
+
+ if (strlen(set->ip_address))
+ g_variant_builder_add(builder, "{sv}",
+ "ip_address",
+ g_variant_new_string(set->ip_address));
+
+ if (wifi_tether_type)
+ g_variant_builder_add(builder, "{sv}",
+ "tether_type",
+ g_variant_new_string(wifi_tether_type));
+
+ params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ return params;
+}
+
/**
* @internal
* @brief Enables the tethering, asynchronously.
break;
case TETHERING_TYPE_WIFI: {
- _softap_settings_t set = {"", "", "", 0, false};
+ GVariant *params = NULL;
+ _softap_settings_t set;
+ memset(&set, 0, sizeof(_softap_settings_t));
ret = __prepare_wifi_settings(tethering, &set);
if (ret != TETHERING_ERROR_NONE) {
g_dbus_connection_signal_unsubscribe(connection,
sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
- SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
- set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
- set.max_connected);
+ SINFO("ssid %s, key %s, channel %d, mode %s, "
+ "txpower %d, security %d, max_device %d, "
+ "ip_address [%s]\n",
+ set.ssid, set.key, set.channel, set.mode,
+ set.txpower, set.sec_type,
+ set.max_connected, set.ip_address);
- char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = "wifi_tether";
if (th->wifi_sharing)
- g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN + 1);
+ params = __get_wifi_settings_dbus_params("wifi_sharing", &set);
+ else
+ params = __get_wifi_settings_dbus_params("wifi_tether", &set);
- SINFO("enable_wifi_tethering key: %s", key);
- g_dbus_proxy_call(proxy, "enable_wifi_tethering",
- g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
- set.channel, set.visibility, set.mac_filter, set.max_connected,
- set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
+ g_dbus_proxy_call(proxy, "enable_wifi_tethering", params,
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
- (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
+ (GAsyncReadyCallback) __wifi_enabled_cfm_cb,
+ (gpointer)tethering);
break;
}
break;
case TETHERING_TYPE_P2P: {
- _softap_settings_t p2p_set = {"", "", "", 0, false};
+ _softap_settings_t p2p_set;
+ memset(&p2p_set, 0, sizeof(_softap_settings_t));
+
ret = __prepare_wifi_settings(tethering, &p2p_set);
if (ret != TETHERING_ERROR_NONE) {
ERR("p2p settings initialization failed\n");
}
case TETHERING_TYPE_ALL: {
- _softap_settings_t set = {"", "", "", 0, false};
+ GVariant *params = NULL;
+ _softap_settings_t set;
+ memset(&set, 0, sizeof(_softap_settings_t));
ret = __prepare_wifi_settings(tethering, &set);
if (ret != TETHERING_ERROR_NONE) {
g_dbus_connection_signal_unsubscribe(connection,
sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
- g_dbus_proxy_call(proxy, "enable_wifi_tethering",
- g_variant_new("(ssssiiiiiii)", "wifi_tether", set.ssid, set.key, set.mode,
- set.channel, set.visibility, set.mac_filter, set.max_connected,
- set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
+ if (th->wifi_sharing)
+ params = __get_wifi_settings_dbus_params("wifi_sharing", &set);
+ else
+ params = __get_wifi_settings_dbus_params("wifi_tether", &set);
+
+ g_dbus_proxy_call(proxy, "enable_wifi_tethering", params,
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
- (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
+ (GAsyncReadyCallback) __wifi_enabled_cfm_cb,
+ (gpointer)tethering);
/* TETHERING_TYPE_BT */
g_dbus_connection_signal_unsubscribe(connection,
}
case TETHERING_TYPE_WIFI: {
- _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
+ GVariant *params = NULL;
+ _softap_settings_t set;
+ memset(&set, 0, sizeof(_softap_settings_t));
ret = __prepare_wifi_settings(tethering, &set);
if (ret != TETHERING_ERROR_NONE) {
g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN + 1);
SINFO("enable_wifi_tethering key: %s", key);
- g_dbus_proxy_call(proxy, "enable_wifi_tethering",
- g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
- set.channel, set.visibility, set.mac_filter, set.max_connected,
- set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV6),
+ if (th->wifi_sharing)
+ params = __get_wifi_settings_dbus_params("wifi_sharing", &set);
+ else
+ params = __get_wifi_settings_dbus_params("wifi_tether", &set);
+
+ g_dbus_proxy_call(proxy, "enable_wifi_tethering", params,
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
- (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
+ (GAsyncReadyCallback) __wifi_enabled_cfm_cb,
+ (gpointer)tethering);
break;
}
_retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
"Not enough memory\n");
+ if (type == TETHERING_TYPE_WIFI) {
+ __tethering_h *th = (__tethering_h *)tethering;
+ g_strlcpy(th->ip_address, *ip_address, sizeof(th->ip_address));
+ }
+
+ return TETHERING_ERROR_NONE;
+}
+
+/**
+ * @brief Sets the local IP address.
+ * @since_tizen 6.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/tethering.admin
+ * @remarks API is only available for TETHERING_TYPE_WIFI.
+ * @param[in] tethering The tethering handle
+ * @param[in] type The tethering type
+ * @param[in] address_family The address family of IP address (currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported)
+ * @param[out] ip_address The local IP address
+ * @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
+ * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
+ * @see tethering_enable()
+ */
+int tethering_set_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, const char *ip_address)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ if (type == TETHERING_TYPE_WIFI)
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+ else
+ return TETHERING_ERROR_INVALID_PARAMETER;
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(ip_address) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ int ip_len = 0;
+
+ if (address_family == TETHERING_ADDRESS_FAMILY_IPV4) {
+ ip_len = strlen(ip_address);
+ if (ip_len < TETHERING_IPV4_ADDRESS_MIN_LEN ||
+ ip_len > TETHERING_IPV4_ADDRESS_MAX_LEN) {
+ ERR("parameter(ip_address) is too short or long\n");
+ return TETHERING_ERROR_INVALID_PARAMETER;
+ }
+ g_strlcpy(th->ip_address, ip_address, sizeof(th->ip_address));
+ } else {
+ /* IPv6 is not supported yet. */
+ ERR("IPv6 address is not supported yet\n");
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+
return TETHERING_ERROR_NONE;
}
else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
- _retvm_if(tethering_is_enabled(tethering, type) == false,
- TETHERING_ERROR_NOT_ENABLED,
- "tethering type[%d] is not enabled\n", type);
_retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(tethering) is NULL\n");
_retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(gateway_address) is NULL\n");
+ _retvm_if(tethering_is_enabled(tethering, type) == false,
+ TETHERING_ERROR_NOT_ENABLED,
+ "tethering type[%d] is not enabled\n", type);
- char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
+ __tethering_h *th = (__tethering_h *)tethering;
- _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
- TETHERING_ERROR_OPERATION_FAILED,
- "getting gateway address is failed\n");
+ if (type == TETHERING_TYPE_WIFI && strlen(th->ip_address)) {
+ *gateway_address = strdup(th->ip_address);
- *gateway_address = strdup(gateway_buf);
+ } else {
+ char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
+
+ _retvm_if(!__get_gateway_addr(type, gateway_buf,
+ sizeof(gateway_buf)),
+ TETHERING_ERROR_OPERATION_FAILED,
+ "getting gateway address is failed\n");
+
+ *gateway_address = strdup(gateway_buf);
+ }
return TETHERING_ERROR_NONE;
}
"parameter(callback) is NULL\n");
__tethering_h *th = (__tethering_h *)tethering;
- _softap_settings_t set = {"", "", "", 0, false};
+ _softap_settings_t set;
GDBusProxy *proxy = th->client_bus_proxy;
int ret = 0;
+ memset(&set, 0, sizeof(_softap_settings_t));
+
DBG("+\n");
if (th->settings_reloaded_cb) {