2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
24 #include <arpa/inet.h>
26 #include <dbus/dbus.h>
29 #include <openssl/evp.h>
30 #include <openssl/sha.h>
31 #include <ckmc/ckmc-manager.h>
32 #include "tethering_private.h"
34 #define ALLOWED_LIST "/etc/hostapd.accept"
35 #define BLOCKED_LIST "/etc/hostapd.deny"
36 #define TEMP_LIST "/etc/hostapd_tmp"
37 #define MAC_ADDR_LEN 18
38 #define MAX_BUF_SIZE 80
40 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
41 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
42 GVariant *parameters, gpointer user_data);
44 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
45 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
46 GVariant *parameters, gpointer user_data);
48 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
49 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
50 GVariant *parameters, gpointer user_data);
52 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
53 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
54 GVariant *parameters, gpointer user_data);
56 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
57 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
58 GVariant *parameters, gpointer user_data);
60 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
61 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
62 GVariant *parameters, gpointer user_data);
64 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
65 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
66 GVariant *parameters, gpointer user_data);
68 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
69 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
70 GVariant *parameters, gpointer user_data);
72 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
73 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
74 GVariant *parameters, gpointer user_data);
76 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
77 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
78 GVariant *parameters, gpointer user_data);
80 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
81 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
82 GVariant *parameters, gpointer user_data);
84 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
85 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
86 GVariant *parameters, gpointer user_data);
88 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
89 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
90 GVariant *parameters, gpointer user_data);
92 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
93 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
94 GVariant *parameters, gpointer user_data);
96 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
97 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
98 GVariant *parameters, gpointer user_data);
100 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
101 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
102 GVariant *parameters, gpointer user_data);
104 static __tethering_sig_t sigs[] = {
105 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
106 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
107 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
108 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
109 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
110 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
111 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
112 {0, SIGNAL_NAME_WIFI_AP_ON, __handle_wifi_ap_on},
113 {0, SIGNAL_NAME_WIFI_AP_OFF, __handle_wifi_ap_off},
114 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
115 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
116 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
117 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
118 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
119 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
120 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
123 static int retry = 0;
125 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
127 if (conn == NULL || signal_name == NULL)
130 GVariant *message = NULL;
131 GError *error = NULL;
134 message = g_variant_new("(s)", arg);
136 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
137 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
139 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
142 g_variant_unref(message);
145 static bool __any_tethering_is_enabled(tethering_h tethering)
147 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
148 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
149 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
150 tethering_is_enabled(tethering, TETHERING_TYPE_RESERVED))
156 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
158 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
159 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
160 ERR("Invalid param\n");
161 return TETHERING_ERROR_INVALID_PARAMETER;
164 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
165 ERR("vconf_set_int is failed\n");
166 return TETHERING_ERROR_OPERATION_FAILED;
169 return TETHERING_ERROR_NONE;
172 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
174 if (security_type == NULL) {
175 ERR("Invalid param\n");
176 return TETHERING_ERROR_INVALID_PARAMETER;
179 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
180 (int *)security_type) < 0) {
181 ERR("vconf_get_int is failed\n");
182 return TETHERING_ERROR_OPERATION_FAILED;
185 return TETHERING_ERROR_NONE;
188 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
190 if (path == NULL || ssid == NULL || size == 0)
194 char *ptr_tmp = NULL;
196 ptr = vconf_get_str(path);
200 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
203 g_strlcpy(ssid, ptr, size);
209 static tethering_error_e __set_visible(const bool visible)
211 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
212 ERR("vconf_set_int is failed\n");
213 return TETHERING_ERROR_OPERATION_FAILED;
216 return TETHERING_ERROR_NONE;
219 static tethering_error_e __get_visible(bool *visible)
221 if (visible == NULL) {
222 ERR("Invalid param\n");
223 return TETHERING_ERROR_INVALID_PARAMETER;
228 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
229 ERR("vconf_get_int is failed\n");
230 return TETHERING_ERROR_OPERATION_FAILED;
237 return TETHERING_ERROR_NONE;
240 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
242 if (passphrase == NULL ||
243 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
246 guint32 rand_int = 0;
249 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
250 rand_int = g_random_int_range('a', 'z');
251 passphrase[index] = rand_int;
253 passphrase[index] = '\0';
258 static tethering_error_e __get_error(int agent_error)
260 tethering_error_e err = TETHERING_ERROR_NONE;
262 switch (agent_error) {
263 case MOBILE_AP_ERROR_NONE:
264 err = TETHERING_ERROR_NONE;
267 case MOBILE_AP_ERROR_RESOURCE:
268 err = TETHERING_ERROR_OUT_OF_MEMORY;
271 case MOBILE_AP_ERROR_INTERNAL:
272 err = TETHERING_ERROR_OPERATION_FAILED;
275 case MOBILE_AP_ERROR_INVALID_PARAM:
276 err = TETHERING_ERROR_INVALID_PARAMETER;
279 case MOBILE_AP_ERROR_ALREADY_ENABLED:
280 err = TETHERING_ERROR_OPERATION_FAILED;
283 case MOBILE_AP_ERROR_NOT_ENABLED:
284 err = TETHERING_ERROR_NOT_ENABLED;
287 case MOBILE_AP_ERROR_NET_OPEN:
288 err = TETHERING_ERROR_OPERATION_FAILED;
291 case MOBILE_AP_ERROR_NET_CLOSE:
292 err = TETHERING_ERROR_OPERATION_FAILED;
295 case MOBILE_AP_ERROR_DHCP:
296 err = TETHERING_ERROR_OPERATION_FAILED;
299 case MOBILE_AP_ERROR_IN_PROGRESS:
300 err = TETHERING_ERROR_OPERATION_FAILED;
303 case MOBILE_AP_ERROR_NOT_PERMITTED:
304 err = TETHERING_ERROR_NOT_PERMITTED;
307 case MOBILE_AP_ERROR_PERMISSION_DENIED:
308 err = TETHERING_ERROR_PERMISSION_DENIED;
312 ERR("Not defined error : %d\n", agent_error);
313 err = TETHERING_ERROR_OPERATION_FAILED;
320 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
321 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
322 GVariant *parameters, gpointer user_data)
326 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
328 __tethering_h *th = (__tethering_h *)user_data;
330 tethering_type_e type = 0;
331 mobile_ap_type_e ap_type = 0;
332 tethering_connection_state_changed_cb ccb = NULL;
333 __tethering_client_h client;
341 memset(&client, 0, sizeof(__tethering_client_h));
342 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
344 if (!g_strcmp0(buf, "DhcpConnected")) {
346 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
349 ERR("Unknown event [%s]\n", buf);
353 if (ap_type == MOBILE_AP_TYPE_USB)
354 type = TETHERING_TYPE_USB;
355 else if (ap_type == MOBILE_AP_TYPE_WIFI)
356 type = TETHERING_TYPE_WIFI;
357 else if (ap_type == MOBILE_AP_TYPE_BT)
358 type = TETHERING_TYPE_BT;
359 else if (ap_type == MOBILE_AP_TYPE_WIFI_AP) {
360 type = TETHERING_TYPE_RESERVED;
362 ERR("Not supported tethering type [%d]\n", ap_type);
366 ccb = th->changed_cb[type];
369 data = th->changed_user_data[type];
371 client.interface = type;
372 g_strlcpy(client.ip, ip, sizeof(client.ip));
373 g_strlcpy(client.mac, mac, sizeof(client.mac));
375 client.hostname = g_strdup(name);
376 client.tm = (time_t)timestamp;
378 ccb((tethering_client_h)&client, opened, data);
379 g_free(client.hostname);
388 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
389 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
390 GVariant *parameters, gpointer user_data)
394 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
396 __tethering_h *th = (__tethering_h *)user_data;
397 tethering_type_e type = 0;
398 tethering_disabled_cb dcb = NULL;
400 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
402 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
403 dcb = th->disabled_cb[type];
406 data = th->disabled_user_data[type];
408 dcb(TETHERING_ERROR_NONE, type, code, data);
414 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
415 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
416 GVariant *parameters, gpointer user_data)
420 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
422 __tethering_h *th = (__tethering_h *)user_data;
423 tethering_type_e type = TETHERING_TYPE_WIFI;
424 bool is_requested = false;
425 tethering_enabled_cb ecb = NULL;
428 ecb = th->enabled_cb[type];
431 data = th->enabled_user_data[type];
433 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
437 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
438 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
439 GVariant *parameters, gpointer user_data)
443 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
445 __tethering_h *th = (__tethering_h *)user_data;
446 tethering_type_e type = TETHERING_TYPE_WIFI;
447 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
448 tethering_disabled_cb dcb = NULL;
452 dcb = th->disabled_cb[type];
455 data = th->disabled_user_data[type];
456 g_variant_get(parameters, "(s)", &buf);
457 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
458 code = TETHERING_DISABLED_BY_WIFI_ON;
459 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
460 code = TETHERING_DISABLED_BY_TIMEOUT;
463 dcb(TETHERING_ERROR_NONE, type, code, data);
468 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
469 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
470 GVariant *parameters, gpointer user_data)
474 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
476 __tethering_h *th = (__tethering_h *)user_data;
477 tethering_type_e type = TETHERING_TYPE_USB;
478 bool is_requested = false;
479 tethering_enabled_cb ecb = NULL;
482 ecb = th->enabled_cb[type];
485 data = th->enabled_user_data[type];
487 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
491 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
492 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
493 GVariant *parameters, gpointer user_data)
497 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
499 __tethering_h *th = (__tethering_h *)user_data;
500 tethering_type_e type = TETHERING_TYPE_USB;
501 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
502 tethering_disabled_cb dcb = NULL;
506 dcb = th->disabled_cb[type];
509 data = th->disabled_user_data[type];
511 g_variant_get(parameters, "(s)", &buf);
512 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
513 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
515 dcb(TETHERING_ERROR_NONE, type, code, data);
520 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
521 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
522 GVariant *parameters, gpointer user_data)
526 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
528 __tethering_h *th = (__tethering_h *)user_data;
529 tethering_type_e type = TETHERING_TYPE_BT;
530 bool is_requested = false;
531 tethering_enabled_cb ecb = NULL;
534 ecb = th->enabled_cb[type];
537 data = th->enabled_user_data[type];
539 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
543 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
544 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
545 GVariant *parameters, gpointer user_data)
549 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
551 __tethering_h *th = (__tethering_h *)user_data;
552 tethering_type_e type = TETHERING_TYPE_BT;
553 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
554 tethering_disabled_cb dcb = NULL;
558 dcb = th->disabled_cb[type];
561 data = th->disabled_user_data[type];
562 g_variant_get(parameters, "(s)", &buf);
563 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
564 code = TETHERING_DISABLED_BY_BT_OFF;
565 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
566 code = TETHERING_DISABLED_BY_TIMEOUT;
568 dcb(TETHERING_ERROR_NONE, type, code, data);
574 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
575 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
576 GVariant *parameters, gpointer user_data)
580 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
582 __tethering_h *th = (__tethering_h *)user_data;
583 tethering_type_e type = TETHERING_TYPE_RESERVED;
584 bool is_requested = false;
585 tethering_enabled_cb ecb = NULL;
588 ecb = th->enabled_cb[type];
591 data = th->enabled_user_data[type];
593 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
597 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
598 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
599 GVariant *parameters, gpointer user_data)
603 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
605 __tethering_h *th = (__tethering_h *)user_data;
606 tethering_type_e type = TETHERING_TYPE_RESERVED;
607 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
608 tethering_disabled_cb dcb = NULL;
612 dcb = th->disabled_cb[type];
615 data = th->disabled_user_data[type];
616 g_variant_get(parameters, "(s)", &buf);
617 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
618 code = TETHERING_DISABLED_BY_WIFI_ON;
619 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
620 code = TETHERING_DISABLED_BY_TIMEOUT;
623 dcb(TETHERING_ERROR_NONE, type, code, data);
628 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
629 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
630 GVariant *parameters, gpointer user_data)
634 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
636 __tethering_h *th = (__tethering_h *)user_data;
637 tethering_type_e type = 0;
638 tethering_disabled_cb dcb = NULL;
640 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
642 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
643 dcb = th->disabled_cb[type];
646 data = th->disabled_user_data[type];
648 dcb(TETHERING_ERROR_NONE, type, code, data);
653 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
654 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
655 GVariant *parameters, gpointer user_data)
659 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
661 __tethering_h *th = (__tethering_h *)user_data;
662 tethering_type_e type = 0;
663 tethering_disabled_cb dcb = NULL;
665 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
667 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
668 dcb = th->disabled_cb[type];
671 data = th->disabled_user_data[type];
673 dcb(TETHERING_ERROR_NONE, type, code, data);
678 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
679 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
680 GVariant *parameters, gpointer user_data)
684 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
686 __tethering_h *th = (__tethering_h *)user_data;
687 tethering_type_e type = 0;
688 tethering_disabled_cb dcb = NULL;
690 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
692 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
693 dcb = th->disabled_cb[type];
696 data = th->disabled_user_data[type];
698 dcb(TETHERING_ERROR_NONE, type, code, data);
703 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
704 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
705 GVariant *parameters, gpointer user_data)
710 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
711 __tethering_h *th = (__tethering_h *)user_data;
713 tethering_wifi_security_type_changed_cb scb = NULL;
715 tethering_wifi_security_type_e security_type;
718 scb = th->security_type_changed_cb;
722 g_variant_get(parameters, "(s)", &buf);
723 data = th->security_type_user_data;
724 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
725 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
726 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
727 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
729 SERR("Unknown type : %s\n", buf);
734 scb(security_type, data);
739 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
740 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
741 GVariant *parameters, gpointer user_data)
745 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
746 __tethering_h *th = (__tethering_h *)user_data;
748 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
750 bool visible = false;
753 scb = th->ssid_visibility_changed_cb;
758 g_variant_get(parameters, "(s)", &buf);
759 data = th->ssid_visibility_user_data;
760 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
768 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
769 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
770 GVariant *parameters, gpointer user_data)
774 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
775 __tethering_h *th = (__tethering_h *)user_data;
777 tethering_wifi_passphrase_changed_cb pcb = NULL;
780 pcb = th->passphrase_changed_cb;
784 data = th->passphrase_user_data;
790 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
795 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
796 GError *g_error = NULL;
799 tethering_error_e error;
800 __tethering_h *th = (__tethering_h *)user_data;
801 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
802 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
804 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
806 ERR("DBus error [%s]\n", g_error->message);
807 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
808 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
809 g_error_free(g_error);
810 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
812 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
813 error = TETHERING_ERROR_PERMISSION_DENIED;
815 error = TETHERING_ERROR_OPERATION_FAILED;
816 g_error_free(g_error);
818 g_variant_get(g_var, "(u)", &info);
819 error = __get_error(info);
823 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
824 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
825 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
826 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
832 ecb(error, TETHERING_TYPE_WIFI, true, data);
833 g_variant_unref(g_var);
837 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
841 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
842 GError *g_error = NULL;
845 tethering_error_e error;
847 __tethering_h *th = (__tethering_h *)user_data;
848 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
849 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
851 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
853 ERR("DBus error [%s]\n", g_error->message);
854 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
855 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
856 g_error_free(g_error);
857 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
861 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
862 error = TETHERING_ERROR_PERMISSION_DENIED;
864 error = TETHERING_ERROR_OPERATION_FAILED;
865 g_error_free(g_error);
867 g_variant_get(g_var, "(u)", &info);
868 g_variant_unref(g_var);
869 error = __get_error(info);
873 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
874 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
875 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
876 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
883 ecb(error, TETHERING_TYPE_BT, true, data);
887 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
892 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
893 __tethering_h *th = (__tethering_h *)user_data;
894 GError *g_error = NULL;
897 tethering_error_e error;
898 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
899 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
901 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
903 ERR("DBus error [%s]\n", g_error->message);
904 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
905 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
906 g_error_free(g_error);
907 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
911 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
912 error = TETHERING_ERROR_PERMISSION_DENIED;
914 error = TETHERING_ERROR_OPERATION_FAILED;
915 g_error_free(g_error);
917 g_variant_get(g_var, "(u)", &info);
918 g_variant_unref(g_var);
919 error = __get_error(info);
923 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
924 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
925 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
926 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
933 ecb(error, TETHERING_TYPE_USB, true, data);
937 static void __wifi_ap_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
942 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
943 __tethering_h *th = (__tethering_h *)user_data;
944 GError *g_error = NULL;
947 tethering_error_e error;
948 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_RESERVED];
949 void *data = th->enabled_user_data[TETHERING_TYPE_RESERVED];
951 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
953 ERR("DBus error [%s]\n", g_error->message);
954 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
955 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
956 g_error_free(g_error);
957 tethering_enable((tethering_h)th, TETHERING_TYPE_RESERVED);
961 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
962 error = TETHERING_ERROR_PERMISSION_DENIED;
964 error = TETHERING_ERROR_OPERATION_FAILED;
965 g_error_free(g_error);
967 g_variant_get(g_var, "(u)", &info);
968 g_variant_unref(g_var);
969 error = __get_error(info);
973 sigs[E_SIGNAL_WIFI_AP_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
974 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_ON].name,
975 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
976 sigs[E_SIGNAL_WIFI_AP_ON].cb, (gpointer)th, NULL);
983 ecb(error, TETHERING_TYPE_RESERVED, true, data);
987 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
992 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
993 GError *g_error = NULL;
995 guint info, event_type;
996 tethering_error_e error;
997 tethering_type_e type;
998 tethering_h tethering = (tethering_h)user_data;
999 __tethering_h *th = (__tethering_h *)tethering;
1000 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
1001 tethering_disabled_cb dcb = NULL;
1004 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1006 ERR("DBus error [%s]\n", g_error->message);
1007 g_error_free(g_error);
1010 g_variant_get(g_var, "(uu)", &event_type, &info);
1011 DBG("cfm event : %d info : %d\n", event_type, info);
1012 g_variant_unref(g_var);
1013 error = __get_error(info);
1014 DBG("cfm event : %d info : %d\n", event_type, error);
1015 switch (event_type) {
1016 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1017 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1018 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1019 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1020 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1022 type = TETHERING_TYPE_WIFI;
1023 dcb = th->disabled_cb[type];
1024 data = th->disabled_user_data[type];
1026 dcb(error, type, code, data);
1029 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1030 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1031 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1032 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1033 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1035 type = TETHERING_TYPE_BT;
1036 dcb = th->disabled_cb[type];
1037 data = th->disabled_user_data[type];
1039 dcb(error, type, code, data);
1042 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1043 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1044 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1045 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1046 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1048 type = TETHERING_TYPE_USB;
1049 dcb = th->disabled_cb[type];
1050 data = th->disabled_user_data[type];
1052 dcb(error, type, code, data);
1055 case MOBILE_AP_DISABLE_WIFI_AP_CFM:
1056 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1057 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_OFF].name,
1058 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1059 sigs[E_SIGNAL_WIFI_AP_OFF].cb, (gpointer)th, NULL);
1061 type = TETHERING_TYPE_RESERVED;
1062 dcb = th->disabled_cb[type];
1063 data = th->disabled_user_data[type];
1065 dcb(error, type, code, data);
1068 case MOBILE_AP_DISABLE_CFM:
1070 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1071 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1072 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1073 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1074 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1075 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1076 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1077 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1078 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1079 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1080 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1081 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1083 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1084 dcb = th->disabled_cb[type];
1087 data = th->disabled_user_data[type];
1089 dcb(error, type, code, data);
1094 ERR("Invalid event\n");
1100 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1105 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1107 GError *g_error = NULL;
1110 guint64 tx_bytes, rx_bytes;
1111 __tethering_h *th = (__tethering_h *)user_data;
1112 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1115 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1117 ERR("DBus fail [%s]\n", g_error->message);
1118 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1119 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1121 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1125 if (th->data_usage_cb == NULL) {
1126 ERR("There is no data_usage_cb\n");
1130 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1132 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1133 th->data_usage_cb(TETHERING_ERROR_NONE,
1134 rx_bytes, tx_bytes, th->data_usage_user_data);
1135 g_variant_unref(g_var);
1137 th->data_usage_cb = NULL;
1138 th->data_usage_user_data = NULL;
1143 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1148 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1149 GError *g_error = NULL;
1152 __tethering_h *th = (__tethering_h *)user_data;
1153 tethering_error_e tethering_error;
1155 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1157 ERR("DBus fail [%s]\n", g_error->message);
1158 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1159 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1161 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1162 g_error_free(g_error);
1164 if (th->settings_reloaded_cb == NULL) {
1165 DBG("There is no settings_reloaded_cb\n-\n");
1168 g_variant_get(g_var, "(u)", &info);
1169 tethering_error = __get_error(info);
1170 g_variant_unref(g_var);
1172 th->settings_reloaded_cb(tethering_error,
1173 th->settings_reloaded_user_data);
1175 th->settings_reloaded_cb = NULL;
1176 th->settings_reloaded_user_data = NULL;
1180 static void __ap_settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1185 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1186 GError *g_error = NULL;
1189 __tethering_h *th = (__tethering_h *)user_data;
1190 tethering_error_e tethering_error;
1192 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1194 ERR("DBus fail [%s]\n", g_error->message);
1195 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1196 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1198 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1199 g_error_free(g_error);
1201 if (th->ap_settings_reloaded_cb == NULL) {
1202 DBG("There is no settings_reloaded_cb\n-\n");
1205 g_variant_get(g_var, "(u)", &info);
1206 tethering_error = __get_error(info);
1207 g_variant_unref(g_var);
1209 th->ap_settings_reloaded_cb(tethering_error,
1210 th->ap_settings_reloaded_user_data);
1212 th->ap_settings_reloaded_cb = NULL;
1213 th->ap_settings_reloaded_user_data = NULL;
1217 static void __connect_signals(tethering_h tethering)
1220 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1222 __tethering_h *th = (__tethering_h *)tethering;
1223 GDBusConnection *connection = th->client_bus;
1226 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1227 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1228 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1229 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1230 sigs[i].cb, tethering, NULL);
1235 static void __disconnect_signals(tethering_h tethering)
1239 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1241 __tethering_h *th = (__tethering_h *)tethering;
1242 GDBusConnection *connection = th->client_bus;
1246 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1247 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1253 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1255 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1258 case TETHERING_TYPE_USB:
1259 g_strlcpy(buf, TETHERING_USB_IF, len);
1262 case TETHERING_TYPE_WIFI:
1263 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1266 case TETHERING_TYPE_BT:
1267 g_strlcpy(buf, TETHERING_BT_IF, len);
1270 case TETHERING_TYPE_RESERVED:
1271 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1275 ERR("Not supported type : %d\n", type);
1281 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1283 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1286 case TETHERING_TYPE_USB:
1287 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1290 case TETHERING_TYPE_WIFI:
1291 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1294 case TETHERING_TYPE_BT:
1295 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1298 case TETHERING_TYPE_RESERVED:
1299 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1303 ERR("Not supported type : %d\n", type);
1309 static int __get_common_ssid(char *ssid, unsigned int size)
1312 ERR("ssid is null\n");
1313 return TETHERING_ERROR_INVALID_PARAMETER;
1317 char *ptr_tmp = NULL;
1319 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1321 ERR("vconf_get_str is failed and set default ssid");
1322 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1324 g_strlcpy(ssid, ptr, size);
1328 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1331 return TETHERING_ERROR_NONE;
1334 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1336 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1339 case TETHERING_WIFI_MODE_TYPE_B:
1340 *buf = g_strdup("b");
1342 case TETHERING_WIFI_MODE_TYPE_G:
1343 *buf = g_strdup("g");
1345 case TETHERING_WIFI_MODE_TYPE_A:
1346 *buf = g_strdup("a");
1348 case TETHERING_WIFI_MODE_TYPE_AD:
1349 *buf = g_strdup("ad");
1352 ERR("Not supported type : %d\n", type);
1358 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1362 __tethering_h *th = (__tethering_h *)tethering;
1363 tethering_error_e ret = TETHERING_ERROR_NONE;
1366 if (th == NULL || set == NULL) {
1367 ERR("null parameter\n-\n");
1368 return TETHERING_ERROR_INVALID_PARAMETER;
1371 if (th->ssid == NULL)
1372 __get_common_ssid(set->ssid, sizeof(set->ssid));
1374 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1376 ret = __get_security_type(&set->sec_type);
1377 if (ret != TETHERING_ERROR_NONE)
1378 set->sec_type = th->sec_type;
1380 ret = __get_visible(&set->visibility);
1381 if (ret != TETHERING_ERROR_NONE)
1382 set->visibility = th->visibility;
1384 set->mac_filter = th->mac_filter;
1385 set->channel = th->channel;
1387 __get_wifi_mode_type(th->mode_type, &ptr);
1389 g_strlcpy(set->mode, "", sizeof(set->mode));
1391 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1395 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1396 g_strlcpy(set->key, "", sizeof(set->key));
1398 GDBusProxy *proxy = th->client_bus_proxy;
1399 GVariant *parameters;
1400 GError *error = NULL;
1401 char *passphrase = NULL;
1402 unsigned int len = 0;
1404 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1405 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1408 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1410 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1411 ret = TETHERING_ERROR_PERMISSION_DENIED;
1413 ret = TETHERING_ERROR_OPERATION_FAILED;
1415 g_error_free(error);
1419 if (parameters != NULL) {
1420 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1421 g_variant_unref(parameters);
1424 g_strlcpy(set->key, passphrase, sizeof(set->key));
1427 return TETHERING_ERROR_NONE;
1430 static int __prepare_wifi_ap_settings(tethering_h tethering, _softap_settings_t *set)
1434 __tethering_h *th = (__tethering_h *)tethering;
1436 if (th == NULL || set == NULL) {
1437 ERR("null parameter\n");
1438 return TETHERING_ERROR_INVALID_PARAMETER;
1441 g_strlcpy(set->ssid, th->ap_ssid, sizeof(set->ssid));
1442 set->sec_type = th->sec_type;
1443 set->visibility = th->visibility;
1445 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
1446 g_strlcpy(set->key, "", sizeof(set->key));
1448 g_strlcpy(set->key, th->passphrase, sizeof(set->key));
1451 return TETHERING_ERROR_NONE;
1454 static bool __check_precondition(tethering_type_e type)
1457 int cellular_state = 0;
1460 /* data network through cellular */
1461 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1462 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1463 ERR("Data Network can be connected later");
1467 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1468 if (dnet_state > VCONFKEY_DNET_OFF) {
1469 ERR("Data Network is connected");
1473 /* data network through wifi */
1474 if (type != TETHERING_TYPE_WIFI) {
1475 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1476 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1477 ERR("Wi-Fi is connected!");
1482 ERR("Network is not available!");
1488 * @brief Creates the handle of tethering.
1490 * @privlevel platform
1491 * @privilege http://tizen.org/privilege/tethering.admin
1492 * @remarks The @a tethering must be released tethering_destroy() by you.
1493 * @param[out] tethering A handle of a new mobile ap handle on success
1494 * @return 0 on success, otherwise a negative error value.
1495 * @retval #TETHERING_ERROR_NONE Successful
1496 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1497 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1498 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1499 * @see tethering_destroy()
1501 API int tethering_create(tethering_h *tethering)
1503 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1504 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1505 "parameter(tethering) is NULL\n");
1508 __tethering_h *th = NULL;
1509 GError *error = NULL;
1510 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1512 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1514 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1515 "malloc is failed\n");
1516 memset(th, 0x00, sizeof(__tethering_h));
1517 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1518 th->visibility = true;
1519 th->mac_filter = false;
1521 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1523 if (__generate_initial_passphrase(th->passphrase,
1524 sizeof(th->passphrase)) == 0) {
1525 ERR("random passphrase generation failed\n");
1527 return TETHERING_ERROR_OPERATION_FAILED;
1530 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1531 ERR("common ssid get failed\n");
1533 return TETHERING_ERROR_OPERATION_FAILED;
1536 th->ap_ssid = g_strdup(ssid);
1537 if (th->ap_ssid == NULL) {
1538 ERR("g_strdup failed\n");
1540 return TETHERING_ERROR_OPERATION_FAILED;
1543 #if !GLIB_CHECK_VERSION(2, 36, 0)
1546 GCancellable *cancellable = g_cancellable_new();
1547 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1549 ERR("Couldn't connect to the System bus[%s]", error->message);
1550 g_error_free(error);
1551 g_cancellable_cancel(cancellable);
1552 g_object_unref(cancellable);
1553 g_free(th->ap_ssid);
1555 return TETHERING_ERROR_OPERATION_FAILED;
1557 th->cancellable = cancellable;
1559 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1560 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1561 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1562 if (!th->client_bus_proxy) {
1564 ERR("Couldn't create the proxy object because of %s\n", error->message);
1565 g_cancellable_cancel(th->cancellable);
1566 g_object_unref(th->cancellable);
1567 g_object_unref(th->client_bus);
1568 g_free(th->ap_ssid);
1570 return TETHERING_ERROR_OPERATION_FAILED;
1573 __connect_signals((tethering_h)th);
1575 *tethering = (tethering_h)th;
1576 DBG("Tethering Handle : 0x%X\n", th);
1578 return TETHERING_ERROR_NONE;
1583 * @brief Destroys the handle of tethering.
1585 * @privlevel platform
1586 * @privilege http://tizen.org/privilege/tethering.admin
1587 * @param[in] tethering The handle of tethering
1588 * @return 0 on success, otherwise a negative error value.
1589 * @retval #TETHERING_ERROR_NONE Successful
1590 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1591 * @see tethering_create()
1593 API int tethering_destroy(tethering_h tethering)
1596 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1597 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1598 "parameter(tethering) is NULL\n");
1600 __tethering_h *th = (__tethering_h *)tethering;
1602 DBG("Tethering Handle : 0x%X\n", th);
1603 __disconnect_signals(tethering);
1610 g_object_unref(th->cancellable);
1611 g_object_unref(th->client_bus_proxy);
1612 g_object_unref(th->client_bus);
1613 memset(th, 0x00, sizeof(__tethering_h));
1617 return TETHERING_ERROR_NONE;
1622 * @brief Enables the tethering, asynchronously.
1624 * @privlevel platform
1625 * @privilege http://tizen.org/privilege/tethering.admin
1626 * @param[in] tethering The handle of tethering
1627 * @param[in] type The type of tethering
1628 * @return 0 on success, otherwise negative error value.
1629 * @retval #TETHERING_ERROR_NONE Successful
1630 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1631 * @post tethering_enabled_cb() will be invoked.
1632 * @see tethering_is_enabled()
1633 * @see tethering_disable()
1635 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1637 DBG("+ type : %d\n", type);
1638 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1639 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1640 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1641 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1643 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1644 "parameter(tethering) is NULL\n");
1646 tethering_error_e ret = TETHERING_ERROR_NONE;
1647 __tethering_h *th = (__tethering_h *)tethering;
1648 GDBusProxy *proxy = th->client_bus_proxy;
1649 GDBusConnection *connection = th->client_bus;
1651 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1653 if (type != TETHERING_TYPE_RESERVED
1654 && __check_precondition(type) == FALSE) {
1656 return TETHERING_ERROR_OPERATION_FAILED;
1660 case TETHERING_TYPE_USB:
1661 g_dbus_connection_signal_unsubscribe(connection,
1662 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1664 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1665 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1666 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1669 case TETHERING_TYPE_WIFI: {
1670 _softap_settings_t set = {"", "", "", 0, false};
1672 ret = __prepare_wifi_settings(tethering, &set);
1673 if (ret != TETHERING_ERROR_NONE) {
1674 ERR("softap settings initialization failed\n");
1676 return TETHERING_ERROR_OPERATION_FAILED;
1678 g_dbus_connection_signal_unsubscribe(connection,
1679 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1681 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1682 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
1683 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1684 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1688 case TETHERING_TYPE_BT:
1689 g_dbus_connection_signal_unsubscribe(connection,
1690 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1692 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1693 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1694 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1698 case TETHERING_TYPE_RESERVED: {
1699 _softap_settings_t set = {"", "", "", 0, false};
1701 ret = __prepare_wifi_ap_settings(tethering, &set);
1702 if (ret != TETHERING_ERROR_NONE) {
1703 ERR("softap settings initialization failed\n");
1704 return TETHERING_ERROR_OPERATION_FAILED;
1707 g_dbus_connection_signal_unsubscribe(connection,
1708 sigs[E_SIGNAL_WIFI_AP_ON].sig_id);
1710 g_dbus_proxy_call(proxy, "enable_wifi_ap",
1711 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1712 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_ap_enabled_cfm_cb, (gpointer)tethering);
1715 case TETHERING_TYPE_ALL: {
1716 _softap_settings_t set = {"", "", "", 0, false};
1718 ret = __prepare_wifi_settings(tethering, &set);
1719 if (ret != TETHERING_ERROR_NONE) {
1720 ERR("softap settings initialization failed\n");
1721 return TETHERING_ERROR_OPERATION_FAILED;
1724 /* TETHERING_TYPE_USB */
1725 g_dbus_connection_signal_unsubscribe(connection,
1726 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1728 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1729 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1730 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1732 /* TETHERING_TYPE_WIFI */
1733 g_dbus_connection_signal_unsubscribe(connection,
1734 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1736 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1737 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1738 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1739 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1741 /* TETHERING_TYPE_BT */
1742 g_dbus_connection_signal_unsubscribe(connection,
1743 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1745 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1746 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1747 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1751 ERR("Unknown type : %d\n", type);
1753 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1756 return TETHERING_ERROR_INVALID_PARAMETER;
1759 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1761 return TETHERING_ERROR_NONE;
1766 * @brief Disables the tethering, asynchronously.
1768 * @privlevel platform
1769 * @privilege http://tizen.org/privilege/tethering.admin
1770 * @param[in] tethering The handle of tethering
1771 * @param[in] type The type of tethering
1772 * @return 0 on success, otherwise negative error value.
1773 * @retval #TETHERING_ERROR_NONE Successful
1774 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1775 * @post tethering_disabled_cb() will be invoked.
1776 * @see tethering_is_enabled()
1777 * @see tethering_enable()
1779 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1781 DBG("+ type : %d\n", type);
1782 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1783 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1784 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1786 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1787 "parameter(tethering) is NULL\n");
1789 __tethering_h *th = (__tethering_h *)tethering;
1790 GDBusProxy *proxy = th->client_bus_proxy;
1791 GDBusConnection *connection = th->client_bus;
1794 case TETHERING_TYPE_USB:
1795 g_dbus_connection_signal_unsubscribe(connection,
1796 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1798 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1799 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1800 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1804 case TETHERING_TYPE_WIFI:
1806 g_dbus_connection_signal_unsubscribe(connection,
1807 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1809 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1810 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1811 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1814 case TETHERING_TYPE_BT:
1816 g_dbus_connection_signal_unsubscribe(connection,
1817 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1819 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1820 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1821 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1824 case TETHERING_TYPE_RESERVED:
1825 g_dbus_connection_signal_unsubscribe(connection,
1826 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id);
1828 g_dbus_proxy_call(proxy, "disable_wifi_ap",
1829 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1830 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1833 case TETHERING_TYPE_ALL:
1834 g_dbus_connection_signal_unsubscribe(connection,
1835 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1837 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1838 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1839 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1841 g_dbus_connection_signal_unsubscribe(connection,
1842 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1844 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1845 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1846 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1848 g_dbus_connection_signal_unsubscribe(connection,
1849 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1851 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1852 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1853 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1857 ERR("Not supported tethering type [%d]\n", type);
1859 return TETHERING_ERROR_INVALID_PARAMETER;
1862 return TETHERING_ERROR_NONE;
1867 * @brief Checks whetehr the tethering is enabled or not.
1869 * @privlevel platform
1870 * @privilege http://tizen.org/privilege/tethering.admin
1871 * @param[in] tethering The handle of tethering
1872 * @param[in] type The type of tethering
1873 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1875 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1878 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1880 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1882 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1886 case TETHERING_TYPE_USB:
1887 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1890 case TETHERING_TYPE_WIFI:
1891 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1894 case TETHERING_TYPE_BT:
1895 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1898 case TETHERING_TYPE_RESERVED:
1899 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
1903 ERR("Not supported type : %d\n", type);
1906 return is_on & vconf_type ? true : false;
1911 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1913 * @privlevel platform
1914 * @privilege http://tizen.org/privilege/tethering.admin
1915 * @remarks @a mac_address must be released with free() by you.
1916 * @param[in] tethering The handle of tethering
1917 * @param[in] type The type of tethering
1918 * @param[out] mac_address The MAC address
1919 * @return 0 on success, otherwise a negative error value.
1920 * @retval #TETHERING_ERROR_NONE Successful
1921 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1922 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1923 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1924 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1925 * @pre tethering must be enabled.
1926 * @see tethering_is_enabled()
1927 * @see tethering_enable()
1929 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1931 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1932 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1933 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1935 _retvm_if(tethering_is_enabled(tethering, type) == false,
1936 TETHERING_ERROR_NOT_ENABLED,
1937 "tethering type[%d] is not enabled\n", type);
1938 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1939 "parameter(tethering) is NULL\n");
1940 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1941 "parameter(mac_address) is NULL\n");
1945 char *macbuf = NULL;
1947 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1948 TETHERING_ERROR_OPERATION_FAILED,
1949 "getting interface name is failed\n");
1951 s = socket(AF_INET, SOCK_DGRAM, 0);
1952 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1953 "getting socket is failed\n");
1954 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1955 ERR("getting mac is failed\n");
1957 return TETHERING_ERROR_OPERATION_FAILED;
1961 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1962 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1963 "Not enough memory\n");
1964 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1965 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1966 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1967 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1968 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1969 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1970 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1972 *mac_address = macbuf;
1974 return TETHERING_ERROR_NONE;
1979 * @brief Gets the name of network interface. For example, usb0.
1981 * @privlevel platform
1982 * @privilege http://tizen.org/privilege/tethering.admin
1983 * @remarks @a interface_name must be released with free() by you.
1984 * @param[in] tethering The handle of tethering
1985 * @param[in] type The type of tethering
1986 * @param[out] interface_name The name of network interface
1987 * @return 0 on success, otherwise negative error value.
1988 * @retval #TETHERING_ERROR_NONE Successful
1989 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1990 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1991 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1992 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1993 * @pre tethering must be enabled.
1994 * @see tethering_is_enabled()
1995 * @see tethering_enable()
1997 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1999 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2000 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2001 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2003 _retvm_if(tethering_is_enabled(tethering, type) == false,
2004 TETHERING_ERROR_NOT_ENABLED,
2005 "tethering type[%d] is not enabled\n", type);
2006 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2007 "parameter(tethering) is NULL\n");
2008 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2009 "parameter(interface_name) is NULL\n");
2011 char intf[TETHERING_STR_INFO_LEN] = {0, };
2013 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2014 TETHERING_ERROR_OPERATION_FAILED,
2015 "getting interface name is failed\n");
2016 *interface_name = strdup(intf);
2017 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2018 "Not enough memory\n");
2020 return TETHERING_ERROR_NONE;
2025 * @brief Gets the local IP address.
2027 * @privlevel platform
2028 * @privilege http://tizen.org/privilege/tethering.admin
2029 * @remarks @a ip_address must be released with free() by you.
2030 * @param[in] tethering The handle of tethering
2031 * @param[in] type The type of tethering
2032 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2033 * @param[out] ip_address The local IP address
2034 * @return 0 on success, otherwise negative error value.
2035 * @retval #TETHERING_ERROR_NONE Successful
2036 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2037 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2038 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2039 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2040 * @pre tethering must be enabled.
2041 * @see tethering_is_enabled()
2042 * @see tethering_enable()
2044 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2047 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2048 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2049 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2051 _retvm_if(tethering_is_enabled(tethering, type) == false,
2052 TETHERING_ERROR_NOT_ENABLED,
2053 "tethering type[%d] is not enabled\n", type);
2054 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2055 "parameter(tethering) is NULL\n");
2056 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2057 "parameter(ip_address) is NULL\n");
2063 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2064 TETHERING_ERROR_OPERATION_FAILED,
2065 "getting interface name is failed\n");
2067 s = socket(AF_INET, SOCK_DGRAM, 0);
2068 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2069 "getting socket is failed\n");
2070 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2071 ERR("ioctl is failed\n");
2073 return TETHERING_ERROR_OPERATION_FAILED;
2077 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2078 *ip_address = strdup(ipbuf);
2079 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2080 "Not enough memory\n");
2082 return TETHERING_ERROR_NONE;
2087 * @brief Gets the Gateway address.
2089 * @privlevel platform
2090 * @privilege http://tizen.org/privilege/tethering.admin
2091 * @remarks @a gateway_address must be released with free() by you.
2092 * @param[in] tethering The handle of tethering
2093 * @param[in] type The type of tethering
2094 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2095 * @param[out] gateway_address The local IP address
2096 * @return 0 on success, otherwise negative error value.
2097 * @retval #TETHERING_ERROR_NONE Successful
2098 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2099 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2100 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2101 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2102 * @pre tethering must be enabled.
2103 * @see tethering_is_enabled()
2104 * @see tethering_enable()
2106 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2109 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2110 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2111 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2113 _retvm_if(tethering_is_enabled(tethering, type) == false,
2114 TETHERING_ERROR_NOT_ENABLED,
2115 "tethering type[%d] is not enabled\n", type);
2116 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2117 "parameter(tethering) is NULL\n");
2118 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2119 "parameter(gateway_address) is NULL\n");
2121 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2123 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2124 TETHERING_ERROR_OPERATION_FAILED,
2125 "getting gateway address is failed\n");
2127 *gateway_address = strdup(gateway_buf);
2129 return TETHERING_ERROR_NONE;
2134 * @brief Gets the Subnet Mask.
2136 * @privlevel platform
2137 * @privilege http://tizen.org/privilege/tethering.admin
2138 * @remarks @a subnet_mask must be released with free() by you.
2139 * @param[in] tethering The handle of tethering
2140 * @param[in] type The type of tethering
2141 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2142 * @param[out] subnet_mask The local IP address
2143 * @return 0 on success, otherwise negative error value.
2144 * @retval #TETHERING_ERROR_NONE Successful
2145 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2146 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2147 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2148 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2149 * @pre tethering must be enabled.
2150 * @see tethering_is_enabled()
2151 * @see tethering_enable()
2153 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2155 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2156 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2157 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2159 _retvm_if(tethering_is_enabled(tethering, type) == false,
2160 TETHERING_ERROR_NOT_ENABLED,
2161 "tethering is not enabled\n");
2162 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2163 "parameter(tethering) is NULL\n");
2164 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2165 "parameter(subnet_mask) is NULL\n");
2167 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2168 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2169 "Not enough memory\n");
2171 return TETHERING_ERROR_NONE;
2176 * @brief Gets the data usage.
2178 * @privlevel platform
2179 * @privilege http://tizen.org/privilege/tethering.admin
2180 * @param[in] tethering The handle of tethering
2181 * @param[out] usage The data usage
2182 * @return 0 on success, otherwise negative error value.
2183 * @retval #TETHERING_ERROR_NONE Successful
2184 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2185 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2186 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2187 * @pre tethering must be enabled.
2188 * @see tethering_is_enabled()
2189 * @see tethering_enable()
2191 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2193 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2195 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2196 "parameter(tethering) is NULL\n");
2197 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2198 "parameter(callback) is NULL\n");
2199 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2200 TETHERING_ERROR_NOT_ENABLED,
2201 "tethering is not enabled\n");
2203 __tethering_h *th = (__tethering_h *)tethering;
2204 GDBusProxy *proxy = th->client_bus_proxy;
2206 th->data_usage_cb = callback;
2207 th->data_usage_user_data = user_data;
2209 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2210 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2211 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2213 return TETHERING_ERROR_NONE;
2218 * @brief Gets the client which is connected by tethering "type".
2220 * @privlevel platform
2221 * @privilege http://tizen.org/privilege/tethering.admin
2222 * @param[in] tethering The handle of tethering
2223 * @param[in] type The type of tethering
2224 * @param[in] callback The callback function to invoke
2225 * @param[in] user_data The user data to be passed to the callback function
2226 * @retval #TETHERING_ERROR_NONE Successful
2227 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2228 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2229 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2230 * @pre tethering must be enabled.
2231 * @see tethering_is_enabled()
2232 * @see tethering_enable()
2234 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2237 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2238 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2239 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2241 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2242 "parameter(tethering) is NULL\n");
2243 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2244 "parameter(callback) is NULL\n");
2245 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2246 TETHERING_ERROR_NOT_ENABLED,
2247 "tethering is not enabled\n");
2249 mobile_ap_type_e interface;
2250 __tethering_h *th = (__tethering_h *)tethering;
2251 __tethering_client_h client = {0, };
2254 gchar *hostname = NULL;
2255 guint timestamp = 0;
2256 GError *error = NULL;
2257 GVariant *result = NULL;
2258 GVariantIter *outer_iter = NULL;
2259 GVariantIter *inner_iter = NULL;
2260 GVariant *station = NULL;
2261 GVariant *value = NULL;
2264 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2265 NULL, G_DBUS_CALL_FLAGS_NONE,
2266 -1, th->cancellable, &error);
2268 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2269 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2270 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2271 g_variant_get(station, "a{sv}", &inner_iter);
2272 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2273 if (g_strcmp0(key, "Type") == 0) {
2274 interface = g_variant_get_int32(value);
2275 if (interface == MOBILE_AP_TYPE_USB)
2276 client.interface = TETHERING_TYPE_USB;
2277 else if (interface == MOBILE_AP_TYPE_WIFI)
2278 client.interface = TETHERING_TYPE_WIFI;
2279 else if (interface == MOBILE_AP_TYPE_BT)
2280 client.interface = TETHERING_TYPE_BT;
2281 else if (interface == MOBILE_AP_TYPE_WIFI_AP)
2282 client.interface = TETHERING_TYPE_RESERVED;
2284 ERR("Invalid interface\n");
2286 g_variant_unref(value);
2289 DBG("interface is %d\n", client.interface);
2290 if (client.interface != type && (TETHERING_TYPE_ALL != type &&
2291 client.interface != TETHERING_TYPE_RESERVED)) {
2293 g_variant_unref(value);
2296 } else if (g_strcmp0(key, "IP") == 0) {
2297 g_variant_get(value, "s", &ip);
2298 SDBG("ip is %s\n", ip);
2299 g_strlcpy(client.ip, ip, sizeof(client.ip));
2300 } else if (g_strcmp0(key, "MAC") == 0) {
2301 g_variant_get(value, "s", &mac);
2302 SDBG("mac is %s\n", mac);
2303 g_strlcpy(client.mac, mac, sizeof(client.mac));
2304 } else if (g_strcmp0(key, "Name") == 0) {
2305 g_variant_get(value, "s", &hostname);
2306 SDBG("hsotname is %s\n", hostname);
2308 client.hostname = g_strdup(hostname);
2309 } else if (g_strcmp0(key, "Time") == 0) {
2310 timestamp = g_variant_get_int32(value);
2311 DBG("timestamp is %d\n", timestamp);
2312 client.tm = (time_t)timestamp;
2314 ERR("Key %s not required\n", key);
2320 g_variant_iter_free(inner_iter);
2321 if (callback((tethering_client_h)&client, user_data) == false) {
2322 DBG("iteration is stopped\n");
2323 g_free(client.hostname);
2324 g_variant_iter_free(outer_iter);
2325 g_variant_unref(station);
2326 g_variant_unref(result);
2328 return TETHERING_ERROR_OPERATION_FAILED;
2330 g_free(client.hostname);
2332 g_variant_iter_free(outer_iter);
2333 g_variant_unref(station);
2334 g_variant_unref(result);
2336 return TETHERING_ERROR_NONE;
2341 * @brief Registers the callback function called when tethering is enabled.
2343 * @privlevel platform
2344 * @privilege http://tizen.org/privilege/tethering.admin
2345 * @param[in] tethering The handle of tethering
2346 * @param[in] type The type of tethering
2347 * @param[in] callback The callback function to invoke
2348 * @param[in] user_data The user data to be passed to the callback function
2349 * @retval #TETHERING_ERROR_NONE Successful
2350 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2351 * @see tethering_unset_enabled_cb()
2353 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2355 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2356 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2357 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2359 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2360 "parameter(tethering) is NULL\n");
2361 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2362 "parameter(callback) is NULL\n");
2364 __tethering_h *th = (__tethering_h *)tethering;
2365 tethering_type_e ti;
2367 if (type != TETHERING_TYPE_ALL) {
2368 th->enabled_cb[type] = callback;
2369 th->enabled_user_data[type] = user_data;
2371 return TETHERING_ERROR_NONE;
2374 /* TETHERING_TYPE_ALL */
2375 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2376 th->enabled_cb[ti] = callback;
2377 th->enabled_user_data[ti] = user_data;
2380 return TETHERING_ERROR_NONE;
2385 * @brief Unregisters the callback function called when tethering is disabled.
2387 * @privlevel platform
2388 * @privilege http://tizen.org/privilege/tethering.admin
2389 * @param[in] tethering The handle of tethering
2390 * @param[in] type The type of tethering
2391 * @retval #TETHERING_ERROR_NONE Successful
2392 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2393 * @see tethering_set_enabled_cb()
2395 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2397 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2398 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2399 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2401 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2402 "parameter(tethering) is NULL\n");
2404 __tethering_h *th = (__tethering_h *)tethering;
2405 tethering_type_e ti;
2407 if (type != TETHERING_TYPE_ALL) {
2408 th->enabled_cb[type] = NULL;
2409 th->enabled_user_data[type] = NULL;
2411 return TETHERING_ERROR_NONE;
2414 /* TETHERING_TYPE_ALL */
2415 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2416 th->enabled_cb[ti] = NULL;
2417 th->enabled_user_data[ti] = NULL;
2420 return TETHERING_ERROR_NONE;
2425 * @brief Registers the callback function called when tethering is disabled.
2427 * @privlevel platform
2428 * @privilege http://tizen.org/privilege/tethering.admin
2429 * @param[in] tethering The handle of tethering
2430 * @param[in] type The type of tethering
2431 * @param[in] callback The callback function to invoke
2432 * @param[in] user_data The user data to be passed to the callback function
2433 * @retval #TETHERING_ERROR_NONE Successful
2434 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2435 * @see tethering_unset_disabled_cb()
2437 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2439 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2440 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2441 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2443 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2444 "parameter(tethering) is NULL\n");
2445 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2446 "parameter(callback) is NULL\n");
2448 __tethering_h *th = (__tethering_h *)tethering;
2449 tethering_type_e ti;
2451 if (type != TETHERING_TYPE_ALL) {
2452 th->disabled_cb[type] = callback;
2453 th->disabled_user_data[type] = user_data;
2455 return TETHERING_ERROR_NONE;
2458 /* TETHERING_TYPE_ALL */
2459 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2460 th->disabled_cb[ti] = callback;
2461 th->disabled_user_data[ti] = user_data;
2464 return TETHERING_ERROR_NONE;
2469 * @brief Unregisters the callback function called when tethering is disabled.
2471 * @privlevel platform
2472 * @privilege http://tizen.org/privilege/tethering.admin
2473 * @param[in] tethering The handle of tethering
2474 * @param[in] type The type of tethering
2475 * @retval #TETHERING_ERROR_NONE Successful
2476 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2477 * @see tethering_set_disabled_cb()
2479 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2481 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2482 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2483 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2485 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2486 "parameter(tethering) is NULL\n");
2488 __tethering_h *th = (__tethering_h *)tethering;
2489 tethering_type_e ti;
2491 if (type != TETHERING_TYPE_ALL) {
2492 th->disabled_cb[type] = NULL;
2493 th->disabled_user_data[type] = NULL;
2495 return TETHERING_ERROR_NONE;
2498 /* TETHERING_TYPE_ALL */
2499 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2500 th->disabled_cb[ti] = NULL;
2501 th->disabled_user_data[ti] = NULL;
2504 return TETHERING_ERROR_NONE;
2509 * @brief Registers the callback function called when the state of connection is changed.
2511 * @privlevel platform
2512 * @privilege http://tizen.org/privilege/tethering.admin
2513 * @param[in] tethering The handle of tethering
2514 * @param[in] type The type of tethering
2515 * @param[in] callback The callback function to invoke
2516 * @param[in] user_data The user data to be passed to the callback function
2517 * @retval #TETHERING_ERROR_NONE Successful
2518 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2519 * @see tethering_unset_connection_state_changed_cb_cb()
2521 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2523 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2524 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2525 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2527 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2528 "parameter(tethering) is NULL\n");
2529 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2530 "parameter(callback) is NULL\n");
2532 __tethering_h *th = (__tethering_h *)tethering;
2533 tethering_type_e ti;
2535 if (type != TETHERING_TYPE_ALL) {
2536 th->changed_cb[type] = callback;
2537 th->changed_user_data[type] = user_data;
2539 return TETHERING_ERROR_NONE;
2542 /* TETHERING_TYPE_ALL */
2543 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2544 th->changed_cb[ti] = callback;
2545 th->changed_user_data[ti] = user_data;
2548 return TETHERING_ERROR_NONE;
2553 * @brief Unregisters the callback function called when the state of connection is changed.
2555 * @privlevel platform
2556 * @privilege http://tizen.org/privilege/tethering.admin
2557 * @param[in] tethering The handle of tethering
2558 * @param[in] type The type of tethering
2559 * @retval #TETHERING_ERROR_NONE Successful
2560 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2561 * @see tethering_set_connection_state_changed_cb()
2563 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2565 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2566 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2567 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2569 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2570 "parameter(tethering) is NULL\n");
2572 __tethering_h *th = (__tethering_h *)tethering;
2573 tethering_type_e ti;
2575 if (type != TETHERING_TYPE_ALL) {
2576 th->changed_cb[type] = NULL;
2577 th->changed_user_data[type] = NULL;
2579 return TETHERING_ERROR_NONE;
2582 /* TETHERING_TYPE_ALL */
2583 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2584 th->changed_cb[ti] = NULL;
2585 th->changed_user_data[ti] = NULL;
2588 return TETHERING_ERROR_NONE;
2593 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2595 * @privlevel platform
2596 * @privilege http://tizen.org/privilege/tethering.admin
2597 * @param[in] tethering The handle of tethering
2598 * @param[in] callback The callback function to invoke
2599 * @param[in] user_data The user data to be passed to the callback function
2600 * @retval #TETHERING_ERROR_NONE Successful
2601 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2602 * @see tethering_wifi_unset_security_type_changed_cb()
2604 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2606 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2608 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2609 "parameter(tethering) is NULL\n");
2610 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2611 "parameter(callback) is NULL\n");
2613 __tethering_h *th = (__tethering_h *)tethering;
2615 th->security_type_changed_cb = callback;
2616 th->security_type_user_data = user_data;
2618 return TETHERING_ERROR_NONE;
2624 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2626 * @privlevel platform
2627 * @privilege http://tizen.org/privilege/tethering.admin
2628 * @param[in] tethering The handle of tethering
2629 * @param[in] type The type of tethering
2630 * @retval #TETHERING_ERROR_NONE Successful
2631 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2632 * @see tethering_wifi_set_security_type_changed_cb()
2634 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2636 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2638 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2639 "parameter(tethering) is NULL\n");
2641 __tethering_h *th = (__tethering_h *)tethering;
2643 th->security_type_changed_cb = NULL;
2644 th->security_type_user_data = NULL;
2646 return TETHERING_ERROR_NONE;
2651 * @brief Registers the callback function called when the visibility of SSID is changed.
2653 * @privlevel platform
2654 * @privilege http://tizen.org/privilege/tethering.admin
2655 * @param[in] tethering The handle of tethering
2656 * @param[in] callback The callback function to invoke
2657 * @param[in] user_data The user data to be passed to the callback function
2658 * @retval #TETHERING_ERROR_NONE Successful
2659 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2660 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2662 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2664 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2666 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2667 "parameter(tethering) is NULL\n");
2668 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2669 "parameter(callback) is NULL\n");
2671 __tethering_h *th = (__tethering_h *)tethering;
2673 th->ssid_visibility_changed_cb = callback;
2674 th->ssid_visibility_user_data = user_data;
2676 return TETHERING_ERROR_NONE;
2681 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2683 * @privlevel platform
2684 * @privilege http://tizen.org/privilege/tethering.admin
2685 * @param[in] tethering The handle of tethering
2686 * @retval #TETHERING_ERROR_NONE Successful
2687 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2688 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2690 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2692 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2694 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2695 "parameter(tethering) is NULL\n");
2697 __tethering_h *th = (__tethering_h *)tethering;
2699 th->ssid_visibility_changed_cb = NULL;
2700 th->ssid_visibility_user_data = NULL;
2702 return TETHERING_ERROR_NONE;
2707 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2709 * @privlevel platform
2710 * @privilege http://tizen.org/privilege/tethering.admin
2711 * @param[in] tethering The handle of tethering
2712 * @param[in] callback The callback function to invoke
2713 * @param[in] user_data The user data to be passed to the callback function
2714 * @retval #TETHERING_ERROR_NONE Successful
2715 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2716 * @see tethering_wifi_unset_passphrase_changed_cb()
2718 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2720 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2722 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2723 "parameter(tethering) is NULL\n");
2724 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2725 "parameter(callback) is NULL\n");
2727 __tethering_h *th = (__tethering_h *)tethering;
2729 th->passphrase_changed_cb = callback;
2730 th->passphrase_user_data = user_data;
2732 return TETHERING_ERROR_NONE;
2737 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2739 * @privlevel platform
2740 * @privilege http://tizen.org/privilege/tethering.admin
2741 * @param[in] tethering The handle of tethering
2742 * @retval #TETHERING_ERROR_NONE Successful
2743 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2744 * @see tethering_wifi_set_passphrase_changed_cb()
2746 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2748 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2750 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2751 "parameter(tethering) is NULL\n");
2753 __tethering_h *th = (__tethering_h *)tethering;
2755 th->passphrase_changed_cb = NULL;
2756 th->passphrase_user_data = NULL;
2758 return TETHERING_ERROR_NONE;
2763 * @brief Sets the security type of Wi-Fi tethering.
2765 * @privlevel platform
2766 * @privilege http://tizen.org/privilege/tethering.admin
2767 * @remarks This change is applied next time Wi-Fi tethering is enabled
2768 * @param[in] tethering The handle of tethering
2769 * @param[in] type The security type
2770 * @return 0 on success, otherwise negative error value.
2771 * @retval #TETHERING_ERROR_NONE Successful
2772 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2773 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2774 * @see tethering_wifi_get_security_type()
2776 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2778 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2780 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2781 "parameter(tethering) is NULL\n");
2783 __tethering_h *th = (__tethering_h *)tethering;
2784 tethering_error_e ret = TETHERING_ERROR_NONE;
2786 ret = __set_security_type(type);
2787 if (ret == TETHERING_ERROR_NONE) {
2789 __send_dbus_signal(th->client_bus,
2790 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2791 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2792 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2793 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2800 * @brief Gets the security type of Wi-Fi tethering.
2802 * @privlevel platform
2803 * @privilege http://tizen.org/privilege/tethering.admin
2804 * @param[in] tethering The handle of tethering
2805 * @param[out] type The security type
2806 * @return 0 on success, otherwise negative error value.
2807 * @retval #TETHERING_ERROR_NONE Successful
2808 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2809 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2810 * @see tethering_wifi_set_security_type()
2812 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2814 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2816 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2817 "parameter(type) is NULL\n");
2819 return __get_security_type(type);
2824 * @brief Sets the SSID (service set identifier).
2826 * @privlevel platform
2827 * @privilege http://tizen.org/privilege/tethering.admin
2828 * @details If SSID is not set, Device name is used as SSID
2829 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2830 * @param[in] tethering The handle of tethering
2831 * @param[out] ssid The SSID
2832 * @return 0 on success, otherwise negative error value.
2833 * @retval #TETHERING_ERROR_NONE Successful
2834 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2835 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2837 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2839 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2841 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2842 "parameter(tethering) is NULL\n");
2843 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2844 "parameter(ssid) is NULL\n");
2846 __tethering_h *th = (__tethering_h *)tethering;
2847 char *p_ssid = NULL;
2850 ssid_len = strlen(ssid);
2851 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2852 ERR("parameter(ssid) is too long");
2853 return TETHERING_ERROR_INVALID_PARAMETER;
2856 p_ssid = strdup(ssid);
2857 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2858 "strdup is failed\n");
2864 return TETHERING_ERROR_NONE;
2869 * @brief Gets the SSID (service set identifier).
2871 * @privlevel platform
2872 * @privilege http://tizen.org/privilege/tethering.admin
2873 * @remarks @a ssid must be released with free() by you.
2874 * @param[in] tethering The handle of tethering
2875 * @param[out] ssid The SSID
2876 * @return 0 on success, otherwise negative error value.
2877 * @retval #TETHERING_ERROR_NONE Successful
2878 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2879 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2880 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2882 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2884 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2886 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2887 "parameter(tethering) is NULL\n");
2888 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2889 "parameter(ssid) is NULL\n");
2892 __tethering_h *th = (__tethering_h *)tethering;
2893 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2895 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2896 if (th->ssid != NULL) {
2897 DBG("Private SSID is set\n");
2898 *ssid = strdup(th->ssid);
2900 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2901 val, sizeof(val)) == false) {
2902 return TETHERING_ERROR_OPERATION_FAILED;
2904 *ssid = strdup(val);
2907 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2908 val, sizeof(val)) == false) {
2909 return TETHERING_ERROR_OPERATION_FAILED;
2911 *ssid = strdup(val);
2914 if (*ssid == NULL) {
2915 ERR("strdup is failed\n");
2916 return TETHERING_ERROR_OUT_OF_MEMORY;
2919 return TETHERING_ERROR_NONE;
2924 * @brief Sets the visibility of SSID(service set identifier).
2926 * @privlevel platform
2927 * @privilege http://tizen.org/privilege/tethering.admin
2928 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2929 * @remarks This change is applied next time Wi-Fi tethering is enabled
2930 * @param[in] tethering The handle of tethering
2931 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2932 * @return 0 on success, otherwise negative error value.
2933 * @retval #TETHERING_ERROR_NONE Successful
2934 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2935 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2936 * @see tethering_wifi_get_ssid_visibility()
2938 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2940 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2942 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2943 "parameter(tethering) is NULL\n");
2945 __tethering_h *th = (__tethering_h *)tethering;
2946 tethering_error_e ret = TETHERING_ERROR_NONE;
2948 ret = __set_visible(visible);
2949 if (ret == TETHERING_ERROR_NONE) {
2951 __send_dbus_signal(th->client_bus,
2952 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2953 visible ? SIGNAL_MSG_SSID_VISIBLE :
2954 SIGNAL_MSG_SSID_HIDE);
2961 * @brief Gets the visibility of SSID(service set identifier).
2963 * @privlevel platform
2964 * @privilege http://tizen.org/privilege/tethering.admin
2965 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2966 * @param[in] tethering The handle of tethering
2967 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2968 * @return 0 on success, otherwise negative error value.
2969 * @retval #TETHERING_ERROR_NONE Successful
2970 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2971 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2972 * @see tethering_wifi_set_ssid_visibility()
2974 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2976 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2978 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2979 "parameter(visible) is NULL\n");
2981 return __get_visible(visible);
2986 * @brief Sets the passphrase.
2988 * @privlevel platform
2989 * @privilege http://tizen.org/privilege/tethering.admin
2990 * @remarks This change is applied next time Wi-Fi tethering is enabled
2991 * @param[in] tethering The handle of tethering
2992 * @param[in] passphrase The passphrase
2993 * @return 0 on success, otherwise negative error value.
2994 * @retval #TETHERING_ERROR_NONE Successful
2995 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2996 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2997 * @see tethering_wifi_get_passphrase()
2999 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3001 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3003 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3004 "parameter(tethering) is NULL\n");
3005 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3006 "parameter(passphrase) is NULL\n");
3008 __tethering_h *th = (__tethering_h *)tethering;
3009 GDBusProxy *proxy = th->client_bus_proxy;
3010 GVariant *parameters;
3011 GError *error = NULL;
3012 int passphrase_len = 0;
3016 passphrase_len = strlen(passphrase);
3017 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3018 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3019 ERR("parameter(passphrase) is too short or long\n");
3020 return TETHERING_ERROR_INVALID_PARAMETER;
3023 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3024 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3027 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3029 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3030 ret = TETHERING_ERROR_PERMISSION_DENIED;
3032 ret = TETHERING_ERROR_OPERATION_FAILED;
3034 g_error_free(error);
3038 g_variant_get(parameters, "(u)", &ret);
3039 g_variant_unref(parameters);
3041 if (ret == TETHERING_ERROR_NONE) {
3042 __send_dbus_signal(th->client_bus,
3043 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3052 * @brief Gets the passphrase.
3054 * @privlevel platform
3055 * @privilege http://tizen.org/privilege/tethering.admin
3056 * @remarks @a passphrase must be released with free() by you.
3057 * @param[in] tethering The handle of tethering
3058 * @param[out] passphrase The passphrase
3059 * @return 0 on success, otherwise negative error value.
3060 * @retval #TETHERING_ERROR_NONE Successful
3061 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3062 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3063 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3064 * @see tethering_wifi_set_passphrase()
3066 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3068 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3070 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3071 "parameter(tethering) is NULL\n");
3072 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3073 "parameter(passphrase) is NULL\n");
3075 __tethering_h *th = (__tethering_h *)tethering;
3076 GDBusProxy *proxy = th->client_bus_proxy;
3077 GVariant *parameters;
3078 GError *error = NULL;
3079 unsigned int len = 0;
3080 tethering_error_e ret = TETHERING_ERROR_NONE;
3082 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3083 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3086 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3088 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3089 ret = TETHERING_ERROR_PERMISSION_DENIED;
3091 ret = TETHERING_ERROR_OPERATION_FAILED;
3093 g_error_free(error);
3097 if (parameters != NULL) {
3098 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3099 g_variant_unref(parameters);
3102 return TETHERING_ERROR_NONE;
3105 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3107 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3108 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3109 "parameter(tethering) is NULL\n");
3111 __tethering_h *th = (__tethering_h *)tethering;
3112 th->channel = channel;
3114 return TETHERING_ERROR_NONE;
3117 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3119 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3120 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3121 "parameter(tethering) is NULL\n");
3123 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3124 "parameter(channel) is NULL\n");
3126 __tethering_h *th = (__tethering_h *)tethering;
3127 *channel = th->channel;
3129 return TETHERING_ERROR_NONE;
3132 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3134 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3135 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3136 "parameter(tethering) is NULL\n");
3138 __tethering_h *th = (__tethering_h *)tethering;
3140 th->mode_type = type;
3142 return TETHERING_ERROR_NONE;
3145 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3147 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3148 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3149 "parameter(tethering) is NULL\n");
3150 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3151 "parameter(type) is NULL\n");
3153 __tethering_h *th = (__tethering_h *)tethering;
3154 *type = th->mode_type;
3156 return TETHERING_ERROR_NONE;
3162 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3164 * @privlevel platform
3165 * @privilege http://tizen.org/privilege/tethering.admin
3166 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3167 * @param[in] tethering The handle of tethering
3168 * @param[in] callback The callback function to invoke
3169 * @param[in] user_data The user data to be passed to the callback function
3170 * @return 0 on success, otherwise negative error value.
3171 * @retval #TETHERING_ERROR_NONE Successful
3172 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3173 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3175 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3178 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3180 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3181 "parameter(tethering) is NULL\n");
3182 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3183 "parameter(callback) is NULL\n");
3185 __tethering_h *th = (__tethering_h *)tethering;
3186 _softap_settings_t set = {"", "", "", 0, false};
3187 GDBusProxy *proxy = th->client_bus_proxy;
3192 if (th->settings_reloaded_cb) {
3193 ERR("Operation in progress\n");
3194 return TETHERING_ERROR_OPERATION_FAILED;
3197 ret = __prepare_wifi_settings(tethering, &set);
3198 if (ret != TETHERING_ERROR_NONE) {
3199 ERR("softap settings initialization failed\n");
3200 return TETHERING_ERROR_OPERATION_FAILED;
3203 th->settings_reloaded_cb = callback;
3204 th->settings_reloaded_user_data = user_data;
3206 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3207 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
3208 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3209 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3211 return TETHERING_ERROR_NONE;
3214 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3216 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3218 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3219 "parameter(tethering) is NULL\n");
3221 __tethering_h *th = (__tethering_h *)tethering;
3222 th->mac_filter = mac_filter;
3224 return TETHERING_ERROR_NONE;
3227 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3229 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3231 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3232 "parameter(mac_filter) is NULL\n");
3234 __tethering_h *th = (__tethering_h *)tethering;
3235 *mac_filter = th->mac_filter;
3237 return TETHERING_ERROR_NONE;
3240 static int __add_mac_to_file(const char *filepath, const char *mac)
3243 char line[MAX_BUF_SIZE] = "\0";
3244 bool mac_exist = false;
3246 fp = fopen(filepath, "a+");
3248 ERR("fopen is failed\n");
3249 return TETHERING_ERROR_OPERATION_FAILED;
3252 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3253 if (strncmp(mac, line, 17) == 0) {
3254 DBG("MAC %s already exist in the list\n", mac);
3261 fprintf(fp, "%s\n", mac);
3265 return TETHERING_ERROR_NONE;
3268 static int __remove_mac_from_file(const char *filepath, const char *mac)
3272 char line[MAX_BUF_SIZE] = "\0";
3274 fp = fopen(filepath, "r");
3276 ERR("fopen is failed\n");
3277 return TETHERING_ERROR_OPERATION_FAILED;
3280 fp1 = fopen(TEMP_LIST, "w+");
3283 ERR("fopen is failed\n");
3284 return TETHERING_ERROR_OPERATION_FAILED;
3287 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3288 if (strncmp(mac, line, 17) == 0)
3289 DBG("MAC %s found in the list\n", mac);
3291 fprintf(fp1, "%s", line);
3297 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3298 rename(TEMP_LIST, ALLOWED_LIST);
3299 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3300 rename(TEMP_LIST, BLOCKED_LIST);
3302 return TETHERING_ERROR_NONE;
3305 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3307 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3309 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3310 "parameter(tethering) is NULL\n");
3311 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3312 "parameter(mac) is NULL\n");
3314 return __add_mac_to_file(ALLOWED_LIST, mac);
3317 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3319 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3320 "parameter(tethering) is NULL\n");
3321 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3322 "parameter(mac) is NULL\n");
3324 return __remove_mac_from_file(ALLOWED_LIST, mac);
3327 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3329 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3330 "parameter(tethering) is NULL\n");
3331 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3332 "parameter(mac) is NULL\n");
3334 return __add_mac_to_file(BLOCKED_LIST, mac);
3337 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3339 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3340 "parameter(tethering) is NULL\n");
3341 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3342 "parameter(mac) is NULL\n");
3344 return __remove_mac_from_file(BLOCKED_LIST, mac);
3347 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3349 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3351 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3352 "parameter(tethering) is NULL\n");
3354 GVariant *parameters;
3355 GError *error = NULL;
3358 __tethering_h *th = (__tethering_h *)tethering;
3360 GDBusProxy *proxy = th->client_bus_proxy;
3362 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3363 g_variant_new("(b)", enable),
3364 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3367 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3368 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3369 result = TETHERING_ERROR_PERMISSION_DENIED;
3371 result = TETHERING_ERROR_OPERATION_FAILED;
3373 g_error_free(error);
3374 th->dhcp_enabled = false;
3379 g_variant_get(parameters, "(u)", &result);
3380 g_variant_unref(parameters);
3383 th->dhcp_enabled = true;
3385 th->dhcp_enabled = false;
3387 return TETHERING_ERROR_NONE;
3390 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3392 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3394 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3395 "parameter(tethering) is NULL\n");
3396 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3397 "parameter(rangestart) is NULL\n");
3398 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3399 "parameter(rangestop) is NULL\n");
3401 GVariant *parameters;
3402 GError *error = NULL;
3405 __tethering_h *th = (__tethering_h *)tethering;
3407 GDBusProxy *proxy = th->client_bus_proxy;
3409 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3410 g_variant_new("(ss)", rangestart, rangestop),
3411 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3413 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3415 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3416 result = TETHERING_ERROR_PERMISSION_DENIED;
3418 result = TETHERING_ERROR_OPERATION_FAILED;
3420 g_error_free(error);
3421 th->dhcp_enabled = false;
3426 g_variant_get(parameters, "(u)", &result);
3427 g_variant_unref(parameters);
3429 th->dhcp_enabled = true;
3431 return TETHERING_ERROR_NONE;
3434 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3436 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3437 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3438 "parameter(tethering) is NULL\n");
3439 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3440 "parameter(dhcp_enabled) is NULL\n");
3442 __tethering_h *th = (__tethering_h *)tethering;
3443 *dhcp_enabled = th->dhcp_enabled;
3445 return TETHERING_ERROR_NONE;
3450 * @brief Sets the security type of Wi-Fi AP.
3452 * @privlevel platform
3453 * @privilege http://tizen.org/privilege/tethering.admin
3454 * @details If security type is not set, WPA2_PSK is used
3455 * @param[in] tethering The handle of tethering
3456 * @param[in] type The security type
3457 * @return 0 on success, otherwise negative error value.
3458 * @retval #TETHERING_ERROR_NONE Successful
3459 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3460 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3461 * @see tethering_wifi_ap_get_security_type()
3463 API int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
3465 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3467 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3468 "parameter(tethering) is NULL\n");
3470 __tethering_h *th = (__tethering_h *)tethering;
3471 th->sec_type = type;
3472 return TETHERING_ERROR_NONE;
3477 * @brief Gets the security type of Wi-Fi AP.
3479 * @privlevel platform
3480 * @privilege http://tizen.org/privilege/tethering.admin
3481 * @details If security type is not set, WPA2_PSK is used
3482 * @param[in] tethering The handle of tethering
3483 * @param[out] type The security type
3484 * @return 0 on success, otherwise negative error value.
3485 * @retval #TETHERING_ERROR_NONE Successful
3486 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3487 * @see tethering_wifi_ap_set_security_type()
3489 API int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3491 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3493 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3494 "parameter(type) is NULL\n");
3496 __tethering_h *th = (__tethering_h *)tethering;
3498 *type = th->sec_type;
3499 return TETHERING_ERROR_NONE;
3504 * @brief Sets the SSID (service set identifier) for Wi-Fi AP. The SSID cannot exceed 32 bytes.
3506 * @privlevel platform
3507 * @privilege http://tizen.org/privilege/tethering.admin
3508 * @details If SSID is not set, Device name is used as SSID
3509 * @param[in] tethering The handle of tethering
3510 * @param[in] ssid The SSID
3511 * @return 0 on success, otherwise negative error value.
3512 * @retval #TETHERING_ERROR_NONE Successful
3513 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3514 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3516 API int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid)
3518 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3520 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3521 "parameter(tethering) is NULL\n");
3522 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3523 "parameter(ssid) is NULL\n");
3525 __tethering_h *th = (__tethering_h *)tethering;
3526 char *p_ssid = NULL;
3529 ssid_len = strlen(ssid);
3530 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3531 ERR("parameter(ssid) is too long");
3532 return TETHERING_ERROR_INVALID_PARAMETER;
3535 p_ssid = strdup(ssid);
3536 if (p_ssid == NULL) {
3537 ERR("strdup failed\n");
3538 return TETHERING_ERROR_OUT_OF_MEMORY;
3542 g_free(th->ap_ssid);
3543 th->ap_ssid = p_ssid;
3545 return TETHERING_ERROR_NONE;
3550 * @brief Gets the SSID (service set identifier) for Wi-Fi AP.
3552 * @privlevel platform
3553 * @privilege http://tizen.org/privilege/tethering.admin
3554 * @details If SSID is not set, Device name is used as SSID
3555 * @remarks @a ssid must be released with free() by you.
3556 * @param[in] tethering The handle of tethering
3557 * @param[out] ssid The SSID
3558 * @return 0 on success, otherwise negative error value.
3559 * @retval #TETHERING_ERROR_NONE Successful
3560 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3561 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3563 API int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid)
3565 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3567 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3568 "parameter(tethering) is NULL\n");
3569 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3570 "parameter(ssid) is NULL\n");
3572 __tethering_h *th = (__tethering_h *)tethering;
3574 *ssid = g_strdup(th->ap_ssid);
3575 if (*ssid == NULL) {
3576 ERR("strdup failed\n");
3577 return TETHERING_ERROR_OUT_OF_MEMORY;
3580 return TETHERING_ERROR_NONE;
3585 * @brief Sets the visibility of SSID(service set identifier) for Wi-Fi AP.
3587 * @privlevel platform
3588 * @privilege http://tizen.org/privilege/tethering.admin
3589 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3590 * @details by default visibility is set to true.
3591 * @remarks This change is applied next time Wi-Fi tethering is enabled
3592 * @param[in] tethering The handle of tethering
3593 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3594 * @return 0 on success, otherwise negative error value.
3595 * @retval #TETHERING_ERROR_NONE Successful
3596 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3597 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3598 * @see tethering_wifi_ap_get_ssid_visibility()
3600 API int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible)
3602 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3604 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3605 "parameter(tethering) is NULL\n");
3607 __tethering_h *th = (__tethering_h *)tethering;
3608 th->visibility = visible;
3609 return TETHERING_ERROR_NONE;
3614 * @brief Gets the visibility of SSID(service set identifier) for Wi-Fi AP.
3616 * @privlevel platform
3617 * @privilege http://tizen.org/privilege/tethering.admin
3618 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3619 * @details by default visibility is set to true.
3620 * @param[in] tethering The handle of tethering
3621 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3622 * @return 0 on success, otherwise negative error value.
3623 * @retval #TETHERING_ERROR_NONE Successful
3624 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3625 * @see tethering_wifi_ap_set_ssid_visibility()
3627 API int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible)
3629 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3631 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3632 "parameter(visible) is NULL\n");
3634 __tethering_h *th = (__tethering_h *)tethering;
3636 *visible = th->visibility;
3637 return TETHERING_ERROR_NONE;
3642 * @brief Sets the passphrase for Wi-Fi AP.
3644 * @privlevel platform
3645 * @privilege http://tizen.org/privilege/tethering.admin
3646 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3647 * @param[in] tethering The handle of tethering
3648 * @param[in] passphrase The passphrase
3649 * @return 0 on success, otherwise negative error value.
3650 * @retval #TETHERING_ERROR_NONE Successful
3651 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3652 * @see tethering_wifi_ap_get_passphrase()
3654 API int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase)
3656 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3658 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3659 "parameter(tethering) is NULL\n");
3660 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3661 "parameter(passphrase) is NULL\n");
3663 __tethering_h *th = (__tethering_h *)tethering;
3664 int passphrase_len = 0;
3666 passphrase_len = strlen(passphrase);
3668 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3669 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3670 ERR("parameter(passphrase) is too short or long\n");
3671 return TETHERING_ERROR_INVALID_PARAMETER;
3674 if (!g_strcmp0(passphrase, th->passphrase))
3675 return TETHERING_ERROR_NONE;
3677 g_strlcpy(th->passphrase, passphrase, sizeof(th->passphrase));
3678 return TETHERING_ERROR_NONE;
3683 * @brief Gets the passphrase for Wi-Fi AP.
3685 * @privlevel platform
3686 * @privilege http://tizen.org/privilege/tethering.admin
3687 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3688 * @remarks @a passphrase must be released with free() by you.
3689 * @param[in] tethering The handle of tethering
3690 * @param[out] passphrase The passphrase
3691 * @return 0 on success, otherwise negative error value.
3692 * @retval #TETHERING_ERROR_NONE Successful
3693 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3694 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3695 * @see tethering_wifi_ap_set_passphrase()
3697 API int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase)
3699 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3701 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3702 "parameter(tethering) is NULL\n");
3703 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3704 "parameter(passphrase) is NULL\n");
3706 __tethering_h *th = (__tethering_h *)tethering;
3708 *passphrase = g_strdup(th->passphrase);
3709 if (*passphrase == NULL) {
3710 ERR("strdup is failed\n");
3711 return TETHERING_ERROR_OUT_OF_MEMORY;
3714 return TETHERING_ERROR_NONE;
3719 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP.
3721 * @privlevel platform
3722 * @privilege http://tizen.org/privilege/tethering.admin
3723 * @remarks Connected devices via MobileAP will be disconnected when the settings are reloaded
3724 * @param[in] tethering The handle of tethering
3725 * @param[in] callback The callback function to invoke
3726 * @param[in] user_data The user data to be passed to the callback function
3727 * @return 0 on success, otherwise negative error value.
3728 * @retval #TETHERING_ERROR_NONE Successful
3729 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3730 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3732 API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data)
3735 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3737 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3738 "parameter(tethering) is NULL\n");
3739 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3740 "parameter(callback) is NULL\n");
3742 __tethering_h *th = (__tethering_h *)tethering;
3743 _softap_settings_t set = {"", "", "", 0, false};
3744 GDBusProxy *proxy = th->client_bus_proxy;
3749 if (th->ap_settings_reloaded_cb) {
3750 ERR("Operation in progress\n");
3751 return TETHERING_ERROR_OPERATION_FAILED;
3754 ret = __prepare_wifi_ap_settings(tethering, &set);
3755 if (ret != TETHERING_ERROR_NONE) {
3756 ERR("softap settings initialization failed\n");
3757 return TETHERING_ERROR_OPERATION_FAILED;
3760 th->ap_settings_reloaded_cb = callback;
3761 th->ap_settings_reloaded_user_data = user_data;
3763 g_dbus_proxy_call(proxy, "reload_wifi_ap_settings",
3764 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
3765 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3766 (GAsyncReadyCallback) __ap_settings_reloaded_cb, (gpointer)tethering);
3768 return TETHERING_ERROR_NONE;