3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <dbus/dbus.h>
20 #include <dbus/dbus-glib.h>
21 #include <dbus/dbus-glib-lowlevel.h>
26 #include <wifi-direct.h>
28 #include "mobileap_softap.h"
29 #include "mobileap_common.h"
30 #include "mobileap_wifi.h"
31 #include "mobileap_handler.h"
32 #include "mobileap_notification.h"
34 #define WIFI_RECOVERY_GUARD_TIME 1000 /* ms */
36 static mobile_ap_error_code_e __update_softap_settings(softap_settings_t *st,
37 gchar *ssid, gchar *passphrase, int hide_mode, softap_security_type_e security_type);
38 static int __turn_off_wifi(TetheringObject *obj);
40 static DBusGMethodInvocation *g_context = NULL;
41 static guint wifi_recovery_timeout_id = 0;
42 static gboolean prev_wifi_on = FALSE;
43 static wifi_saved_settings wifi_settings = {0, NULL, NULL, 0};
45 static void _wifi_direct_state_cb(int error_code, wifi_direct_device_state_e state, void *user_data)
47 bool wifi_state = false;
51 if (user_data == NULL) {
52 ERR("The param is NULL\n");
56 TetheringObject *obj = (TetheringObject *)user_data;
59 if (state != WIFI_DIRECT_DEVICE_STATE_DEACTIVATED) {
60 ERR("Unknown state : %d\n", state);
64 wifi_direct_unset_device_state_changed_cb();
65 wifi_direct_deinitialize();
67 if (error_code != 0) {
68 ERR("wifi_direct_deactivate fail in cb : %d\n", error_code);
69 ret = MOBILE_AP_ERROR_INTERNAL;
72 DBG("Wi-Fi direct is turned off\n");
74 wifi_is_activated(&wifi_state);
76 DBG("Wi-Fi is turned on. Turn off Wi-Fi");
77 if (__turn_off_wifi(obj) != MOBILE_AP_ERROR_NONE) {
78 ERR("_turn_off_wifi is failed\n");
79 ret = MOBILE_AP_ERROR_INTERNAL;
85 ret = _enable_wifi_tethering(obj, wifi_settings.ssid, wifi_settings.key,
86 wifi_settings.hide_mode, wifi_settings.security_type);
87 if (ret != MOBILE_AP_ERROR_NONE) {
88 ERR("_enable_wifi_tethering is failed\n");
90 _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_TETHER_ON, NULL);
94 dbus_g_method_return(g_context,
95 MOBILE_AP_ENABLE_WIFI_TETHERING_CFM, ret);
98 g_free(wifi_settings.ssid);
99 g_free(wifi_settings.key);
100 memset(&wifi_settings, 0, sizeof(wifi_settings));
106 static void __wifi_activated_cb(wifi_error_e result, void *user_data)
108 DBG("Wi-Fi on is done\n");
113 static void __wifi_deactivated_cb(wifi_error_e result, void *user_data)
117 if (user_data == NULL) {
118 ERR("The param is NULL\n");
122 TetheringObject *obj = (TetheringObject *)user_data;
125 if (result != WIFI_ERROR_NONE) {
126 ERR("__wifi_deactivated_cb error : %d\n", result);
127 ret = MOBILE_AP_ERROR_INTERNAL;
131 DBG("Wi-Fi is turned off\n");
133 ret = _enable_wifi_tethering(obj, wifi_settings.ssid, wifi_settings.key,
134 wifi_settings.hide_mode, wifi_settings.security_type);
135 if (ret != MOBILE_AP_ERROR_NONE) {
136 ERR("_enable_wifi_tethering is failed\n");
139 _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_TETHER_ON, NULL);
143 dbus_g_method_return(g_context,
144 MOBILE_AP_ENABLE_WIFI_TETHERING_CFM, ret);
147 g_free(wifi_settings.ssid);
148 g_free(wifi_settings.key);
149 memset(&wifi_settings, 0, sizeof(wifi_settings));
155 static int __turn_off_wifi(TetheringObject *obj)
159 ret = wifi_deactivate(__wifi_deactivated_cb, (void *)obj);
160 if (ret != WIFI_ERROR_NONE) {
161 ERR("wifi_deactivate() is failed : %d\n", ret);
162 return MOBILE_AP_ERROR_INTERNAL;
165 return MOBILE_AP_ERROR_NONE;
168 static gboolean __turn_on_wifi_timeout_cb(gpointer user_data)
173 wifi_recovery_timeout_id = 0;
175 ret = wifi_activate(__wifi_activated_cb, NULL);
176 if (ret != WIFI_ERROR_NONE) {
177 ERR("wifi_activate() is failed : %d\n", ret);
180 idle_id = g_idle_add(_terminate_mobileap_agent, NULL);
182 ERR("g_idle_add is failed\n");
188 static int __turn_on_wifi(void)
190 if (wifi_recovery_timeout_id > 0) {
191 g_source_remove(wifi_recovery_timeout_id);
192 wifi_recovery_timeout_id = 0;
195 wifi_recovery_timeout_id = g_timeout_add(WIFI_RECOVERY_GUARD_TIME,
196 __turn_on_wifi_timeout_cb, NULL);
197 if (wifi_recovery_timeout_id == 0) {
198 ERR("g_timeout_add is failed\n");
199 return MOBILE_AP_ERROR_INTERNAL;
202 return MOBILE_AP_ERROR_NONE;
205 static gboolean __is_wifi_direct_on(void)
207 int wifi_direct_state = 0;
210 ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
212 ERR("vconf_get_int() is failed : %d\n", ret);
216 return wifi_direct_state != 0 ? TRUE : FALSE;
219 static int __turn_off_wifi_direct(TetheringObject *obj)
223 ret = wifi_direct_initialize();
225 ERR("wifi_direct_initialize() is failed : %d\n", ret);
226 return MOBILE_AP_ERROR_INTERNAL;
229 ret = wifi_direct_set_device_state_changed_cb(_wifi_direct_state_cb, (void *)obj);
231 ERR("wifi_direct_set_device_state_changed_cb() is failed : %d\n", ret);
232 ret = wifi_direct_deinitialize();
233 DBG("wifi_direct_deinitialize() ret : %d\n", ret);
234 return MOBILE_AP_ERROR_INTERNAL;
237 ret = wifi_direct_deactivate();
239 ERR("wifi_direct_deactivate() is failed : %d\n", ret);
240 ret = wifi_direct_unset_device_state_changed_cb();
241 DBG("wifi_direct_unset_device_state_changed_cb() ret : %d\n", ret);
242 ret = wifi_direct_deinitialize();
243 DBG("wifi_direct_deinitialize() ret : %d\n", ret);
244 return MOBILE_AP_ERROR_INTERNAL;
247 return MOBILE_AP_ERROR_NONE;
250 static mobile_ap_error_code_e __update_softap_settings(softap_settings_t *st,
251 gchar *ssid, gchar *passphrase, int hide_mode, softap_security_type_e security_type)
254 ERR("Invalid param\n");
255 return MOBILE_AP_ERROR_INVALID_PARAM;
258 g_strlcpy(st->ssid, ssid, sizeof(st->ssid));
260 if (security_type == SOFTAP_SECURITY_TYPE_WPA2_PSK) {
261 g_strlcpy(st->security_type, SOFTAP_SECURITY_TYPE_WPA2_PSK_STR,
262 sizeof(st->security_type));
263 g_strlcpy(st->key, passphrase, sizeof(st->key));
264 } else if (security_type == SOFTAP_SECURITY_TYPE_OPEN) {
265 g_strlcpy(st->security_type, SOFTAP_SECURITY_TYPE_OPEN_STR,
266 sizeof(st->security_type));
267 g_strlcpy(st->key, "00000000", sizeof(st->key));
269 ERR("Unknown security type\n");
270 return MOBILE_AP_ERROR_INTERNAL;
273 st->hide_mode = hide_mode;
275 SDBG("ssid : %s security type : %s hide mode : %d\n",
276 st->ssid, st->security_type, st->hide_mode);
278 return MOBILE_AP_ERROR_NONE;
281 static gboolean __is_equal_softap_settings(softap_settings_t *a, softap_settings_t *b)
283 if (a->hide_mode != b->hide_mode)
286 if (strcmp(a->ssid, b->ssid) != 0)
289 if (strcmp(a->key, b->key) != 0)
292 if (strcmp(a->security_type, b->security_type) != 0)
298 mobile_ap_error_code_e _reload_softap_settings(TetheringObject *obj,
299 gchar *ssid, gchar *key, gint hide_mode, gint security_type)
301 gboolean backup_prev_wifi_on = prev_wifi_on;
302 mobile_ap_error_code_e ret;
303 softap_settings_t *old_settings = &obj->softap_settings;
304 softap_settings_t new_settings;
306 if (obj == NULL || ssid == NULL || !strlen(ssid)) {
307 ERR("invalid parameters\n");
308 return MOBILE_AP_ERROR_INVALID_PARAM;
311 if (!_mobileap_is_enabled(MOBILE_AP_STATE_WIFI))
312 return MOBILE_AP_ERROR_NONE;
314 ret = __update_softap_settings(&new_settings, ssid, key, hide_mode,
315 (softap_security_type_e)security_type);
316 if (ret != MOBILE_AP_ERROR_NONE) {
317 ERR("__update_softap_settings is failed\n");
321 if (__is_equal_softap_settings(&new_settings, old_settings) == TRUE) {
322 DBG("No need to reload settings\n");
323 return MOBILE_AP_ERROR_NONE;
326 prev_wifi_on = FALSE;
327 ret = _disable_wifi_tethering(obj);
329 prev_wifi_on = backup_prev_wifi_on;
330 if (ret != MOBILE_AP_ERROR_NONE) {
331 ERR("_disable_wifi_tethering is failed : %d\n", ret);
335 ret = _enable_wifi_tethering(obj, ssid, key, hide_mode,
336 (softap_security_type_e)security_type);
337 if (ret != MOBILE_AP_ERROR_NONE) {
338 ERR("_enable_wifi_tethering is failed : %d\n", ret);
341 _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_TETHER_ON, NULL);
343 return MOBILE_AP_ERROR_NONE;
346 mobile_ap_error_code_e _reload_softap_settings_for_ap(TetheringObject *obj,
347 gchar *ssid, gchar *key, gint hide_mode, gint security_type)
349 gboolean backup_prev_wifi_on = prev_wifi_on;
350 mobile_ap_error_code_e ret;
351 softap_settings_t *old_settings = &obj->softap_settings;
352 softap_settings_t new_settings;
354 if (obj == NULL || ssid == NULL || !strlen(ssid)) {
355 ERR("invalid parameters\n");
356 return MOBILE_AP_ERROR_INVALID_PARAM;
359 ret = __update_softap_settings(&new_settings, ssid, key, hide_mode,
360 (softap_security_type_e)security_type);
361 if (ret != MOBILE_AP_ERROR_NONE) {
362 ERR("__update_softap_settings is failed\n");
366 if (__is_equal_softap_settings(&new_settings, old_settings) == TRUE) {
367 DBG("No need to reload settings\n");
368 return MOBILE_AP_ERROR_NONE;
371 prev_wifi_on = FALSE;
373 ret = _disable_wifi_ap(obj);
374 prev_wifi_on = backup_prev_wifi_on;
375 if (ret != MOBILE_AP_ERROR_NONE) {
376 ERR("_disable_wifi_ap is failed : %d\n", ret);
380 ret = _enable_wifi_ap(obj, ssid, key, hide_mode,
381 (softap_security_type_e)security_type);
382 if (ret != MOBILE_AP_ERROR_NONE) {
383 ERR("_enable_wifi_ap is failed : %d\n", ret);
387 return MOBILE_AP_ERROR_NONE;
390 int _get_wifi_name_from_lease_info(const char *mac, char **name_buf)
392 if (mac == NULL || name_buf == NULL) {
393 return MOBILE_AP_ERROR_INVALID_PARAM;
396 GIOChannel *io = NULL;
398 char *device_name = MOBILE_AP_NAME_UNKNOWN;
399 char ip_addr[MOBILE_AP_STR_INFO_LEN] = {0, };
400 char mac_addr[MOBILE_AP_STR_INFO_LEN] = {0, };
401 char name[MOBILE_AP_STR_HOSTNAME_LEN] = {0, };
402 char expire[MOBILE_AP_STR_INFO_LEN] = {0, };
403 char extra[MOBILE_AP_STR_INFO_LEN] = {0, };
405 io = g_io_channel_new_file(DNSMASQ_LEASES_FILE, "r", NULL);
407 return MOBILE_AP_ERROR_RESOURCE;
410 while (g_io_channel_read_line(io, &line, NULL, NULL, NULL) ==
411 G_IO_STATUS_NORMAL) {
412 sscanf(line, "%19s %19s %19s %19s %19s",
413 expire, mac_addr, ip_addr, name, extra);
416 if (g_ascii_strcasecmp(mac_addr, mac) == 0) {
417 if (g_strcmp0(name, "*") != 0)
422 g_io_channel_unref(io);
424 *name_buf = g_strdup(device_name);
426 return MOBILE_AP_ERROR_NONE;
429 void _add_wifi_device_to_array(softap_device_info_t *di, GPtrArray *array)
432 GIOChannel *io = NULL;
434 gchar *device_name = NULL;
435 gchar ip_addr[MOBILE_AP_STR_INFO_LEN] = {0, };
436 gchar mac_addr[MOBILE_AP_STR_INFO_LEN] = {0, };
437 gchar name[MOBILE_AP_STR_HOSTNAME_LEN] = {0, };
438 gchar expire[MOBILE_AP_STR_INFO_LEN] = {0, };
439 gchar extra[MOBILE_AP_STR_INFO_LEN] = {0, };
443 for (i = 0; i < di->number; i++)
444 SDBG("bssid[%d]:%s\n", i, di->bssid[i]);
446 DBG("Number of connected device:%d\n", di->number);
448 io = g_io_channel_new_file(DNSMASQ_LEASES_FILE, "r", NULL);
450 while (g_io_channel_read_line(io, &line, NULL, NULL, NULL) ==
451 G_IO_STATUS_NORMAL) {
452 sscanf(line, "%19s %19s %19s %19s %19s", expire, mac_addr,
453 ip_addr, name, extra);
454 SDBG("mac_addr:%s ip_addr:%s name:%s expire:%s\n", mac_addr,
455 ip_addr, name, expire);
457 for (i = 0; i < di->number; i++) {
458 if (g_ascii_strcasecmp(di->bssid[i], mac_addr) == 0) {
459 if (!strcmp(name, "*"))
460 device_name = MOBILE_AP_NAME_UNKNOWN;
464 _mh_core_add_data_to_array(array, MOBILE_AP_TYPE_WIFI,
475 g_io_channel_unref(io);
477 /* Set the name UNKNOWN unless we got the name. */
478 for (i = found; i < di->number; i++) {
479 _mh_core_add_data_to_array(array, MOBILE_AP_TYPE_WIFI,
480 MOBILE_AP_NAME_UNKNOWN);
484 mobile_ap_error_code_e _enable_wifi_tethering(TetheringObject *obj, gchar *ssid,
485 gchar *passphrase, int hide_mode, softap_security_type_e security_type)
487 mobile_ap_error_code_e ret;
489 if (obj == NULL || ssid == NULL || !strlen(ssid)) {
490 ERR("invalid parameters\n");
491 return MOBILE_AP_ERROR_INVALID_PARAM;
494 if (security_type == SOFTAP_SECURITY_TYPE_WPA2_PSK && passphrase == NULL) {
495 ERR("passphrase is null\n");
496 return MOBILE_AP_ERROR_INVALID_PARAM;
499 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI_AP)) {
500 ERR("Wi-Fi AP is already enabled\n");
501 ret = MOBILE_AP_ERROR_RESOURCE;
505 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI)) {
506 ERR("Wi-Fi tethering is already enabled\n");
507 ret = MOBILE_AP_ERROR_ALREADY_ENABLED;
511 /* Update global state */
512 if (!_mobileap_set_state(MOBILE_AP_STATE_WIFI)) {
513 ret = MOBILE_AP_ERROR_RESOURCE;
517 /* Update Wi-Fi hotspot data to common object */
518 ret = __update_softap_settings(&obj->softap_settings, ssid, passphrase,
519 hide_mode, security_type);
520 if (ret != MOBILE_AP_ERROR_NONE) {
521 _mobileap_clear_state(MOBILE_AP_STATE_WIFI);
525 if (vconf_set_str(VCONFKEY_MOBILE_HOTSPOT_SSID,
526 obj->softap_settings.ssid) < 0) {
527 ERR("vconf_set_str is failed\n");
530 /* Initialize tethering */
531 _block_device_sleep();
532 ret = _init_tethering(obj);
533 if (ret != MOBILE_AP_ERROR_NONE) {
534 _mobileap_clear_state(MOBILE_AP_STATE_WIFI);
539 ret = _mh_core_enable_softap(MOBILE_AP_TYPE_WIFI,
540 obj->softap_settings.ssid,
541 obj->softap_settings.security_type,
542 obj->softap_settings.key,
543 obj->softap_settings.hide_mode);
544 if (ret != MOBILE_AP_ERROR_NONE) {
545 _deinit_tethering(obj);
546 _mobileap_clear_state(MOBILE_AP_STATE_WIFI);
549 _delete_timeout_noti();
551 _init_timeout_cb(MOBILE_AP_TYPE_WIFI, (void *)obj);
552 _start_timeout_cb(MOBILE_AP_TYPE_WIFI, time(NULL) + TETHERING_CONN_TIMEOUT);
554 _add_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
555 _add_routing_rule(WIFI_IF);
558 _unblock_device_sleep();
562 mobile_ap_error_code_e _enable_wifi_ap(TetheringObject *obj,
563 gchar *ssid, gchar *passphrase, int hide_mode,
564 softap_security_type_e security_type)
566 mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
568 if (obj == NULL || ssid == NULL || !strlen(ssid)) {
569 ERR("invalid parameters\n");
570 return MOBILE_AP_ERROR_INVALID_PARAM;
573 if (security_type == SOFTAP_SECURITY_TYPE_WPA2_PSK &&
574 (passphrase == NULL || strlen(passphrase) >= MOBILE_AP_WIFI_KEY_MAX_LEN)) {
575 ERR("hex key length is not correct\n");
576 return MOBILE_AP_ERROR_INVALID_PARAM;
579 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI | MOBILE_AP_STATE_BT
580 | MOBILE_AP_STATE_USB)) {
581 ERR("Tethering is already enabled\n");
582 return MOBILE_AP_ERROR_RESOURCE;
585 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI_AP)) {
586 ERR("Wi-Fi AP is already enabled\n");
587 return MOBILE_AP_ERROR_ALREADY_ENABLED;
590 if (!_mobileap_set_state(MOBILE_AP_STATE_WIFI_AP)) {
591 return MOBILE_AP_ERROR_RESOURCE;
594 ret = __update_softap_settings(&obj->softap_settings, ssid, passphrase,
595 hide_mode, security_type);
596 if (ret != MOBILE_AP_ERROR_NONE) {
597 _mobileap_clear_state(MOBILE_AP_STATE_WIFI_AP);
601 _block_device_sleep();
603 if (_init_tethering(obj) != MOBILE_AP_ERROR_NONE) {
604 _mobileap_clear_state(MOBILE_AP_STATE_WIFI_AP);
605 ret = MOBILE_AP_ERROR_RESOURCE;
610 ret = _mh_core_enable_softap(MOBILE_AP_TYPE_WIFI_AP,
611 obj->softap_settings.ssid,
612 obj->softap_settings.security_type,
613 obj->softap_settings.key,
614 obj->softap_settings.hide_mode);
615 if (ret != MOBILE_AP_ERROR_NONE) {
616 _deinit_tethering(obj);
617 _mobileap_clear_state(MOBILE_AP_STATE_WIFI_AP);
621 _delete_timeout_noti();
622 _init_timeout_cb(MOBILE_AP_TYPE_WIFI_AP, (void *)obj);
623 _start_timeout_cb(MOBILE_AP_TYPE_WIFI_AP, time(NULL) + WIFI_AP_CONN_TIMEOUT);
624 _add_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
625 _add_routing_rule(WIFI_IF);
628 _unblock_device_sleep();
632 mobile_ap_error_code_e _disable_wifi_tethering(TetheringObject *obj)
636 mobile_ap_type_e type;
638 type = MOBILE_AP_TYPE_WIFI;
639 state = MOBILE_AP_STATE_WIFI;
641 if (!_mobileap_is_enabled(state)) {
642 ERR("Wi-Fi tethering ap has not been activated\n");
643 ret = MOBILE_AP_ERROR_NOT_ENABLED;
647 _block_device_sleep();
648 _del_routing_rule(WIFI_IF);
649 _del_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
650 _flush_ip_address(WIFI_IF);
651 _deinit_timeout_cb(type);
653 if (_remove_station_info_all(type) != MOBILE_AP_ERROR_NONE) {
654 ERR("_remove_station_info_all is failed. Ignore it.\n");
657 ret = _mh_core_disable_softap();
658 if (ret != MOBILE_AP_ERROR_NONE) {
659 ERR("_mh_core_disable_softap is failed : %d\n", ret);
663 _deinit_tethering(obj);
664 _mobileap_clear_state(state);
666 if (prev_wifi_on == TRUE) {
667 DBG("Previous Wi-Fi was turned on. Recover it\n");
668 if (__turn_on_wifi() != MOBILE_AP_ERROR_NONE) {
669 ERR("__turn_on_wifi() is failed\n");
671 prev_wifi_on = FALSE;
673 DBG("_disable_wifi_tethering is done\n");
676 _unblock_device_sleep();
680 mobile_ap_error_code_e _disable_wifi_ap(TetheringObject *obj)
684 mobile_ap_type_e type;
686 type = MOBILE_AP_TYPE_WIFI_AP;
687 state = MOBILE_AP_STATE_WIFI_AP;
689 if (!_mobileap_is_enabled(state)) {
690 ERR("Wi-Fi ap tethering has not been activated\n");
691 ret = MOBILE_AP_ERROR_NOT_ENABLED;
695 _block_device_sleep();
696 _del_routing_rule(WIFI_IF);
697 _del_interface_routing(WIFI_IF, IP_ADDRESS_SOFTAP);
698 _flush_ip_address(WIFI_IF);
699 _deinit_timeout_cb(type);
701 if (_remove_station_info_all(type) != MOBILE_AP_ERROR_NONE) {
702 ERR("_remove_station_info_all is failed. Ignore it.\n");
705 ret = _mh_core_disable_softap();
706 if (ret != MOBILE_AP_ERROR_NONE) {
707 ERR("_mh_core_disable_softap is failed : %d\n", ret);
711 _deinit_tethering(obj);
712 _mobileap_clear_state(state);
714 DBG("_disable_wifi_ap is done\n");
717 _unblock_device_sleep();
721 gboolean tethering_enable_wifi_tethering(TetheringObject *obj, gchar *ssid,
722 gchar *key, gint visibility, gint security_type,
723 DBusGMethodInvocation *context)
725 mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
726 gboolean ret_val = FALSE;
727 bool wifi_state = false;
730 g_assert(obj != NULL);
731 g_assert(context != NULL);
734 DBG("It is turnning on\n");
735 dbus_g_method_return(context,
736 MOBILE_AP_ENABLE_WIFI_TETHERING_CFM,
737 MOBILE_AP_ERROR_IN_PROGRESS);
743 wifi_settings.ssid = g_strdup(ssid);
744 if (security_type == SOFTAP_SECURITY_TYPE_WPA2_PSK) {
745 wifi_settings.key = g_strdup(key);
746 wifi_settings.security_type = SOFTAP_SECURITY_TYPE_WPA2_PSK;
748 wifi_settings.security_type = SOFTAP_SECURITY_TYPE_OPEN;
750 wifi_settings.hide_mode = (!visibility);
752 if (wifi_recovery_timeout_id) {
753 DBG("Wi-Fi recovery is cancelled\n");
754 g_source_remove(wifi_recovery_timeout_id);
755 wifi_recovery_timeout_id = 0;
759 if (__is_wifi_direct_on() == TRUE) {
760 DBG("Wi-Fi and Wi-Fi direct are turned on\n");
761 if (__turn_off_wifi_direct(obj) != MOBILE_AP_ERROR_NONE) {
762 ERR("_turn_off_wifi_direct is failed\n");
763 ret = MOBILE_AP_ERROR_INTERNAL;
770 wifi_is_activated(&wifi_state);
771 if (wifi_state == true) {
772 DBG("Wi-Fi is turned on\n");
773 if (__turn_off_wifi(obj) != MOBILE_AP_ERROR_NONE) {
774 ERR("_turn_off_wifi is failed\n");
775 ret = MOBILE_AP_ERROR_INTERNAL;
782 ret = _enable_wifi_tethering(obj, ssid, key, !visibility,
783 (softap_security_type_e)security_type);
784 if (ret != MOBILE_AP_ERROR_NONE) {
785 ERR("_enable_wifi_tethering is failed\n");
787 _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_TETHER_ON, NULL);
792 dbus_g_method_return(g_context,
793 MOBILE_AP_ENABLE_WIFI_TETHERING_CFM, ret);
796 g_free(wifi_settings.ssid);
797 g_free(wifi_settings.key);
798 memset(&wifi_settings, 0, sizeof(wifi_settings));
803 gboolean tethering_disable_wifi_tethering(TetheringObject *obj,
804 DBusGMethodInvocation *context)
806 int ret = MOBILE_AP_ERROR_NONE;
809 g_assert(obj != NULL);
810 g_assert(context != NULL);
812 ret = _disable_wifi_tethering(obj);
814 _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_TETHER_OFF, NULL);
815 dbus_g_method_return(context, MOBILE_AP_DISABLE_WIFI_TETHERING_CFM, ret);
817 if (ret != MOBILE_AP_ERROR_NONE)
823 gboolean tethering_enable_wifi_ap(TetheringObject *obj, gchar *ssid, gchar *key,
824 gint visibility, gint security_type, DBusGMethodInvocation *context)
826 mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
827 gboolean ret_val = FALSE;
830 g_assert(obj != NULL);
831 g_assert(context != NULL);
833 if (wifi_recovery_timeout_id) {
834 DBG("Wi-Fi recovery is cancelled\n");
835 g_source_remove(wifi_recovery_timeout_id);
836 wifi_recovery_timeout_id = 0;
839 ret = _enable_wifi_ap(obj, ssid, key, !visibility,
840 (softap_security_type_e)security_type);
841 if (ret != MOBILE_AP_ERROR_NONE) {
842 ERR("_enable_wifi_tethering is failed\n");
844 _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_AP_ON, NULL);
848 dbus_g_method_return(context, MOBILE_AP_ENABLE_WIFI_AP_CFM, ret);
853 gboolean tethering_disable_wifi_ap(TetheringObject *obj,
854 DBusGMethodInvocation *context)
856 int ret = MOBILE_AP_ERROR_NONE;
859 g_assert(obj != NULL);
860 g_assert(context != NULL);
862 ret = _disable_wifi_ap(obj);
864 _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_AP_OFF, NULL);
865 dbus_g_method_return(context, MOBILE_AP_DISABLE_WIFI_AP_CFM, ret);
867 if (ret != MOBILE_AP_ERROR_NONE)
873 gboolean tethering_reload_wifi_settings(TetheringObject *obj, gchar *ssid,
874 gchar *key, gint visibility, gint security_type,
875 DBusGMethodInvocation *context)
877 mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
878 gboolean ret_val = TRUE;
881 g_assert(obj != NULL);
882 g_assert(context != NULL);
884 ret = _reload_softap_settings(obj, ssid, key, !visibility, security_type);
885 if (ret != MOBILE_AP_ERROR_NONE) {
886 ERR("_reload_softap_settings is failed\n");
890 dbus_g_method_return(context, ret);
895 gboolean tethering_reload_wifi_ap_settings(TetheringObject *obj, gchar *ssid,
896 gchar *key, gint visibility, gint security, DBusGMethodInvocation *context)
899 mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
900 gboolean ret_val = TRUE;
903 g_assert(obj != NULL);
904 g_assert(context != NULL);
906 ret = _reload_softap_settings_for_ap(obj, ssid, key, !visibility, security);
907 if (ret != MOBILE_AP_ERROR_NONE) {
908 ERR("_reload_softap_settings_for_ap is failed\n");
912 dbus_g_method_return(context, ret);
916 gboolean _is_trying_wifi_operation(void)
918 return (g_context || wifi_recovery_timeout_id ? TRUE : FALSE);