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 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
35 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
36 GVariant *parameters, gpointer user_data);
38 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
39 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
40 GVariant *parameters, gpointer user_data);
42 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
43 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
44 GVariant *parameters, gpointer user_data);
46 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
47 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
48 GVariant *parameters, gpointer user_data);
50 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
51 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
52 GVariant *parameters, gpointer user_data);
54 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
55 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
56 GVariant *parameters, gpointer user_data);
58 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
59 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
60 GVariant *parameters, gpointer user_data);
62 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
63 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
64 GVariant *parameters, gpointer user_data);
66 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
67 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
68 GVariant *parameters, gpointer user_data);
70 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
71 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
72 GVariant *parameters, gpointer user_data);
74 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
75 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
76 GVariant *parameters, gpointer user_data);
78 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
79 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
80 GVariant *parameters, gpointer user_data);
82 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
83 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
84 GVariant *parameters, gpointer user_data);
86 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
87 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
88 GVariant *parameters, gpointer user_data);
90 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
91 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
92 GVariant *parameters, gpointer user_data);
94 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
95 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
96 GVariant *parameters, gpointer user_data);
98 static __tethering_sig_t sigs[] = {
99 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
100 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
101 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
102 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
103 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
104 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
105 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
106 {0, SIGNAL_NAME_WIFI_AP_ON, __handle_wifi_ap_on},
107 {0, SIGNAL_NAME_WIFI_AP_OFF, __handle_wifi_ap_off},
108 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
109 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
110 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
111 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
112 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
113 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
114 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
117 static int retry = 0;
119 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
121 if (conn == NULL || signal_name == NULL)
124 GVariant *message = NULL;
125 GError *error = NULL;
128 message = g_variant_new("(s)", arg);
130 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
131 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
133 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
136 g_variant_unref(message);
139 static bool __any_tethering_is_enabled(tethering_h tethering)
141 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
142 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
143 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
144 tethering_is_enabled(tethering, TETHERING_TYPE_RESERVED))
150 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
152 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
153 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
154 ERR("Invalid param\n");
155 return TETHERING_ERROR_INVALID_PARAMETER;
158 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
159 ERR("vconf_set_int is failed\n");
160 return TETHERING_ERROR_OPERATION_FAILED;
163 return TETHERING_ERROR_NONE;
166 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
168 if (security_type == NULL) {
169 ERR("Invalid param\n");
170 return TETHERING_ERROR_INVALID_PARAMETER;
173 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
174 (int *)security_type) < 0) {
175 ERR("vconf_get_int is failed\n");
176 return TETHERING_ERROR_OPERATION_FAILED;
179 return TETHERING_ERROR_NONE;
182 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
184 if (path == NULL || ssid == NULL || size == 0)
188 char *ptr_tmp = NULL;
190 ptr = vconf_get_str(path);
194 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
197 g_strlcpy(ssid, ptr, size);
203 static tethering_error_e __set_visible(const bool visible)
205 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
206 ERR("vconf_set_int is failed\n");
207 return TETHERING_ERROR_OPERATION_FAILED;
210 return TETHERING_ERROR_NONE;
213 static tethering_error_e __get_visible(bool *visible)
215 if (visible == NULL) {
216 ERR("Invalid param\n");
217 return TETHERING_ERROR_INVALID_PARAMETER;
222 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
223 ERR("vconf_get_int is failed\n");
224 return TETHERING_ERROR_OPERATION_FAILED;
231 return TETHERING_ERROR_NONE;
234 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
236 if (passphrase == NULL ||
237 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
240 guint32 rand_int = 0;
243 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
244 rand_int = g_random_int_range('a', 'z');
245 passphrase[index] = rand_int;
247 passphrase[index] = '\0';
252 static tethering_error_e __get_error(int agent_error)
254 tethering_error_e err = TETHERING_ERROR_NONE;
256 switch (agent_error) {
257 case MOBILE_AP_ERROR_NONE:
258 err = TETHERING_ERROR_NONE;
261 case MOBILE_AP_ERROR_RESOURCE:
262 err = TETHERING_ERROR_OUT_OF_MEMORY;
265 case MOBILE_AP_ERROR_INTERNAL:
266 err = TETHERING_ERROR_OPERATION_FAILED;
269 case MOBILE_AP_ERROR_INVALID_PARAM:
270 err = TETHERING_ERROR_INVALID_PARAMETER;
273 case MOBILE_AP_ERROR_ALREADY_ENABLED:
274 err = TETHERING_ERROR_OPERATION_FAILED;
277 case MOBILE_AP_ERROR_NOT_ENABLED:
278 err = TETHERING_ERROR_NOT_ENABLED;
281 case MOBILE_AP_ERROR_NET_OPEN:
282 err = TETHERING_ERROR_OPERATION_FAILED;
285 case MOBILE_AP_ERROR_NET_CLOSE:
286 err = TETHERING_ERROR_OPERATION_FAILED;
289 case MOBILE_AP_ERROR_DHCP:
290 err = TETHERING_ERROR_OPERATION_FAILED;
293 case MOBILE_AP_ERROR_IN_PROGRESS:
294 err = TETHERING_ERROR_OPERATION_FAILED;
297 case MOBILE_AP_ERROR_NOT_PERMITTED:
298 err = TETHERING_ERROR_NOT_PERMITTED;
301 case MOBILE_AP_ERROR_PERMISSION_DENIED:
302 err = TETHERING_ERROR_PERMISSION_DENIED;
306 ERR("Not defined error : %d\n", agent_error);
307 err = TETHERING_ERROR_OPERATION_FAILED;
314 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
315 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
316 GVariant *parameters, gpointer user_data)
320 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
322 __tethering_h *th = (__tethering_h *)user_data;
324 tethering_type_e type = 0;
325 mobile_ap_type_e ap_type = 0;
326 tethering_connection_state_changed_cb ccb = NULL;
327 __tethering_client_h client;
335 memset(&client, 0, sizeof(__tethering_client_h));
336 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
338 if (!g_strcmp0(buf, "DhcpConnected")) {
340 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
343 ERR("Unknown event [%s]\n", buf);
347 if (ap_type == MOBILE_AP_TYPE_USB)
348 type = TETHERING_TYPE_USB;
349 else if (ap_type == MOBILE_AP_TYPE_WIFI)
350 type = TETHERING_TYPE_WIFI;
351 else if (ap_type == MOBILE_AP_TYPE_BT)
352 type = TETHERING_TYPE_BT;
353 else if (ap_type == MOBILE_AP_TYPE_WIFI_AP) {
354 type = TETHERING_TYPE_RESERVED;
356 ERR("Not supported tethering type [%d]\n", ap_type);
360 ccb = th->changed_cb[type];
363 data = th->changed_user_data[type];
365 client.interface = type;
366 g_strlcpy(client.ip, ip, sizeof(client.ip));
367 g_strlcpy(client.mac, mac, sizeof(client.mac));
369 client.hostname = g_strdup(name);
370 client.tm = (time_t)timestamp;
372 ccb((tethering_client_h)&client, opened, data);
373 g_free(client.hostname);
382 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
383 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
384 GVariant *parameters, gpointer user_data)
388 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
390 __tethering_h *th = (__tethering_h *)user_data;
391 tethering_type_e type = 0;
392 tethering_disabled_cb dcb = NULL;
394 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
396 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
397 dcb = th->disabled_cb[type];
400 data = th->disabled_user_data[type];
402 dcb(TETHERING_ERROR_NONE, type, code, data);
408 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
409 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
410 GVariant *parameters, gpointer user_data)
414 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
416 __tethering_h *th = (__tethering_h *)user_data;
417 tethering_type_e type = TETHERING_TYPE_WIFI;
418 bool is_requested = false;
419 tethering_enabled_cb ecb = NULL;
422 ecb = th->enabled_cb[type];
425 data = th->enabled_user_data[type];
427 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
431 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
432 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
433 GVariant *parameters, gpointer user_data)
437 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
439 __tethering_h *th = (__tethering_h *)user_data;
440 tethering_type_e type = TETHERING_TYPE_WIFI;
441 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
442 tethering_disabled_cb dcb = NULL;
446 dcb = th->disabled_cb[type];
449 data = th->disabled_user_data[type];
450 g_variant_get(parameters, "(s)", &buf);
451 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
452 code = TETHERING_DISABLED_BY_WIFI_ON;
453 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
454 code = TETHERING_DISABLED_BY_TIMEOUT;
457 dcb(TETHERING_ERROR_NONE, type, code, data);
462 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
463 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
464 GVariant *parameters, gpointer user_data)
468 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
470 __tethering_h *th = (__tethering_h *)user_data;
471 tethering_type_e type = TETHERING_TYPE_USB;
472 bool is_requested = false;
473 tethering_enabled_cb ecb = NULL;
476 ecb = th->enabled_cb[type];
479 data = th->enabled_user_data[type];
481 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
485 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
486 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
487 GVariant *parameters, gpointer user_data)
491 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
493 __tethering_h *th = (__tethering_h *)user_data;
494 tethering_type_e type = TETHERING_TYPE_USB;
495 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
496 tethering_disabled_cb dcb = NULL;
500 dcb = th->disabled_cb[type];
503 data = th->disabled_user_data[type];
505 g_variant_get(parameters, "(s)", &buf);
506 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
507 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
509 dcb(TETHERING_ERROR_NONE, type, code, data);
514 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
515 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
516 GVariant *parameters, gpointer user_data)
520 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
522 __tethering_h *th = (__tethering_h *)user_data;
523 tethering_type_e type = TETHERING_TYPE_BT;
524 bool is_requested = false;
525 tethering_enabled_cb ecb = NULL;
528 ecb = th->enabled_cb[type];
531 data = th->enabled_user_data[type];
533 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
537 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
538 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
539 GVariant *parameters, gpointer user_data)
543 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
545 __tethering_h *th = (__tethering_h *)user_data;
546 tethering_type_e type = TETHERING_TYPE_BT;
547 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
548 tethering_disabled_cb dcb = NULL;
552 dcb = th->disabled_cb[type];
555 data = th->disabled_user_data[type];
556 g_variant_get(parameters, "(s)", &buf);
557 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
558 code = TETHERING_DISABLED_BY_BT_OFF;
559 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
560 code = TETHERING_DISABLED_BY_TIMEOUT;
562 dcb(TETHERING_ERROR_NONE, type, code, data);
568 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
569 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
570 GVariant *parameters, gpointer user_data)
574 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
576 __tethering_h *th = (__tethering_h *)user_data;
577 tethering_type_e type = TETHERING_TYPE_RESERVED;
578 bool is_requested = false;
579 tethering_enabled_cb ecb = NULL;
582 ecb = th->enabled_cb[type];
585 data = th->enabled_user_data[type];
587 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
591 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
592 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
593 GVariant *parameters, gpointer user_data)
597 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
599 __tethering_h *th = (__tethering_h *)user_data;
600 tethering_type_e type = TETHERING_TYPE_RESERVED;
601 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
602 tethering_disabled_cb dcb = NULL;
606 dcb = th->disabled_cb[type];
609 data = th->disabled_user_data[type];
610 g_variant_get(parameters, "(s)", &buf);
611 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
612 code = TETHERING_DISABLED_BY_WIFI_ON;
613 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
614 code = TETHERING_DISABLED_BY_TIMEOUT;
617 dcb(TETHERING_ERROR_NONE, type, code, data);
622 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
623 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
624 GVariant *parameters, gpointer user_data)
628 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
630 __tethering_h *th = (__tethering_h *)user_data;
631 tethering_type_e type = 0;
632 tethering_disabled_cb dcb = NULL;
634 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
636 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
637 dcb = th->disabled_cb[type];
640 data = th->disabled_user_data[type];
642 dcb(TETHERING_ERROR_NONE, type, code, data);
647 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
648 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
649 GVariant *parameters, gpointer user_data)
653 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
655 __tethering_h *th = (__tethering_h *)user_data;
656 tethering_type_e type = 0;
657 tethering_disabled_cb dcb = NULL;
659 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
661 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
662 dcb = th->disabled_cb[type];
665 data = th->disabled_user_data[type];
667 dcb(TETHERING_ERROR_NONE, type, code, data);
672 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
673 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
674 GVariant *parameters, gpointer user_data)
678 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
680 __tethering_h *th = (__tethering_h *)user_data;
681 tethering_type_e type = 0;
682 tethering_disabled_cb dcb = NULL;
684 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
686 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
687 dcb = th->disabled_cb[type];
690 data = th->disabled_user_data[type];
692 dcb(TETHERING_ERROR_NONE, type, code, data);
697 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
698 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
699 GVariant *parameters, gpointer user_data)
704 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
705 __tethering_h *th = (__tethering_h *)user_data;
707 tethering_wifi_security_type_changed_cb scb = NULL;
709 tethering_wifi_security_type_e security_type;
712 scb = th->security_type_changed_cb;
716 g_variant_get(parameters, "(s)", &buf);
717 data = th->security_type_user_data;
718 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
719 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
720 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
721 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
723 SERR("Unknown type : %s\n", buf);
728 scb(security_type, data);
733 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
734 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
735 GVariant *parameters, gpointer user_data)
739 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
740 __tethering_h *th = (__tethering_h *)user_data;
742 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
744 bool visible = false;
747 scb = th->ssid_visibility_changed_cb;
752 g_variant_get(parameters, "(s)", &buf);
753 data = th->ssid_visibility_user_data;
754 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
762 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
763 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
764 GVariant *parameters, gpointer user_data)
768 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
769 __tethering_h *th = (__tethering_h *)user_data;
771 tethering_wifi_passphrase_changed_cb pcb = NULL;
774 pcb = th->passphrase_changed_cb;
778 data = th->passphrase_user_data;
784 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
789 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
790 GError *g_error = NULL;
793 tethering_error_e error;
794 __tethering_h *th = (__tethering_h *)user_data;
795 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
796 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
798 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
800 ERR("DBus error [%s]\n", g_error->message);
801 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
802 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
803 g_error_free(g_error);
804 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
806 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
807 error = TETHERING_ERROR_PERMISSION_DENIED;
809 error = TETHERING_ERROR_OPERATION_FAILED;
810 g_error_free(g_error);
812 g_variant_get(g_var, "(u)", &info);
813 error = __get_error(info);
817 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
818 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
819 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
820 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
826 ecb(error, TETHERING_TYPE_WIFI, true, data);
827 g_variant_unref(g_var);
831 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
835 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
836 GError *g_error = NULL;
839 tethering_error_e error;
841 __tethering_h *th = (__tethering_h *)user_data;
842 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
843 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
845 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
847 ERR("DBus error [%s]\n", g_error->message);
848 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
849 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
850 g_error_free(g_error);
851 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
855 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
856 error = TETHERING_ERROR_PERMISSION_DENIED;
858 error = TETHERING_ERROR_OPERATION_FAILED;
859 g_error_free(g_error);
861 g_variant_get(g_var, "(u)", &info);
862 g_variant_unref(g_var);
863 error = __get_error(info);
867 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
868 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
869 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
870 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
877 ecb(error, TETHERING_TYPE_BT, true, data);
881 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
886 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
887 __tethering_h *th = (__tethering_h *)user_data;
888 GError *g_error = NULL;
891 tethering_error_e error;
892 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
893 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
895 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
897 ERR("DBus error [%s]\n", g_error->message);
898 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
899 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
900 g_error_free(g_error);
901 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
905 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
906 error = TETHERING_ERROR_PERMISSION_DENIED;
908 error = TETHERING_ERROR_OPERATION_FAILED;
909 g_error_free(g_error);
911 g_variant_get(g_var, "(u)", &info);
912 g_variant_unref(g_var);
913 error = __get_error(info);
917 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
918 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
919 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
920 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
927 ecb(error, TETHERING_TYPE_USB, true, data);
931 static void __wifi_ap_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
936 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
937 __tethering_h *th = (__tethering_h *)user_data;
938 GError *g_error = NULL;
941 tethering_error_e error;
942 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_RESERVED];
943 void *data = th->enabled_user_data[TETHERING_TYPE_RESERVED];
945 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
947 ERR("DBus error [%s]\n", g_error->message);
948 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
949 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
950 g_error_free(g_error);
951 tethering_enable((tethering_h)th, TETHERING_TYPE_RESERVED);
955 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
956 error = TETHERING_ERROR_PERMISSION_DENIED;
958 error = TETHERING_ERROR_OPERATION_FAILED;
959 g_error_free(g_error);
961 g_variant_get(g_var, "(u)", &info);
962 g_variant_unref(g_var);
963 error = __get_error(info);
967 sigs[E_SIGNAL_WIFI_AP_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
968 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_ON].name,
969 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
970 sigs[E_SIGNAL_WIFI_AP_ON].cb, (gpointer)th, NULL);
977 ecb(error, TETHERING_TYPE_RESERVED, true, data);
981 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
986 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
987 GError *g_error = NULL;
989 guint info, event_type;
990 tethering_error_e error;
991 tethering_type_e type;
992 tethering_h tethering = (tethering_h)user_data;
993 __tethering_h *th = (__tethering_h *)tethering;
994 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
995 tethering_disabled_cb dcb = NULL;
998 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1000 ERR("DBus error [%s]\n", g_error->message);
1001 g_error_free(g_error);
1004 g_variant_get(g_var, "(uu)", &event_type, &info);
1005 DBG("cfm event : %d info : %d\n", event_type, info);
1006 g_variant_unref(g_var);
1007 error = __get_error(info);
1008 DBG("cfm event : %d info : %d\n", event_type, error);
1009 switch (event_type) {
1010 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1011 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1012 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1013 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1014 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1016 type = TETHERING_TYPE_WIFI;
1017 dcb = th->disabled_cb[type];
1018 data = th->disabled_user_data[type];
1020 dcb(error, type, code, data);
1023 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1024 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1025 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1026 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1027 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1029 type = TETHERING_TYPE_BT;
1030 dcb = th->disabled_cb[type];
1031 data = th->disabled_user_data[type];
1033 dcb(error, type, code, data);
1036 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1037 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1038 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1039 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1040 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1042 type = TETHERING_TYPE_USB;
1043 dcb = th->disabled_cb[type];
1044 data = th->disabled_user_data[type];
1046 dcb(error, type, code, data);
1049 case MOBILE_AP_DISABLE_WIFI_AP_CFM:
1050 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1051 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_OFF].name,
1052 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1053 sigs[E_SIGNAL_WIFI_AP_OFF].cb, (gpointer)th, NULL);
1055 type = TETHERING_TYPE_RESERVED;
1056 dcb = th->disabled_cb[type];
1057 data = th->disabled_user_data[type];
1059 dcb(error, type, code, data);
1062 case MOBILE_AP_DISABLE_CFM:
1064 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1065 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1066 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1067 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1068 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1069 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1070 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1071 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1072 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1073 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1074 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1075 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1077 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1078 dcb = th->disabled_cb[type];
1081 data = th->disabled_user_data[type];
1083 dcb(error, type, code, data);
1088 ERR("Invalid event\n");
1094 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1099 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1101 GError *g_error = NULL;
1104 guint64 tx_bytes, rx_bytes;
1105 __tethering_h *th = (__tethering_h *)user_data;
1106 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1109 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1111 ERR("DBus fail [%s]\n", g_error->message);
1112 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1113 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1115 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1119 if (th->data_usage_cb == NULL) {
1120 ERR("There is no data_usage_cb\n");
1124 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1126 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1127 th->data_usage_cb(TETHERING_ERROR_NONE,
1128 rx_bytes, tx_bytes, th->data_usage_user_data);
1129 g_variant_unref(g_var);
1131 th->data_usage_cb = NULL;
1132 th->data_usage_user_data = NULL;
1137 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1142 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1143 GError *g_error = NULL;
1146 __tethering_h *th = (__tethering_h *)user_data;
1147 tethering_error_e tethering_error;
1149 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1151 ERR("DBus fail [%s]\n", g_error->message);
1152 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1153 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1155 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1156 g_error_free(g_error);
1158 if (th->settings_reloaded_cb == NULL) {
1159 DBG("There is no settings_reloaded_cb\n-\n");
1162 g_variant_get(g_var, "(u)", &info);
1163 tethering_error = __get_error(info);
1164 g_variant_unref(g_var);
1166 th->settings_reloaded_cb(tethering_error,
1167 th->settings_reloaded_user_data);
1169 th->settings_reloaded_cb = NULL;
1170 th->settings_reloaded_user_data = NULL;
1174 static void __ap_settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1179 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1180 GError *g_error = NULL;
1183 __tethering_h *th = (__tethering_h *)user_data;
1184 tethering_error_e tethering_error;
1186 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1188 ERR("DBus fail [%s]\n", g_error->message);
1189 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1190 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1192 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1193 g_error_free(g_error);
1195 if (th->ap_settings_reloaded_cb == NULL) {
1196 DBG("There is no settings_reloaded_cb\n-\n");
1199 g_variant_get(g_var, "(u)", &info);
1200 tethering_error = __get_error(info);
1201 g_variant_unref(g_var);
1203 th->ap_settings_reloaded_cb(tethering_error,
1204 th->ap_settings_reloaded_user_data);
1206 th->ap_settings_reloaded_cb = NULL;
1207 th->ap_settings_reloaded_user_data = NULL;
1211 static void __connect_signals(tethering_h tethering)
1214 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1216 __tethering_h *th = (__tethering_h *)tethering;
1217 GDBusConnection *connection = th->client_bus;
1220 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1221 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1222 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1223 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1224 sigs[i].cb, tethering, NULL);
1229 static void __disconnect_signals(tethering_h tethering)
1233 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1235 __tethering_h *th = (__tethering_h *)tethering;
1236 GDBusConnection *connection = th->client_bus;
1240 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1241 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1247 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1249 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1252 case TETHERING_TYPE_USB:
1253 g_strlcpy(buf, TETHERING_USB_IF, len);
1256 case TETHERING_TYPE_WIFI:
1257 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1260 case TETHERING_TYPE_BT:
1261 g_strlcpy(buf, TETHERING_BT_IF, len);
1264 case TETHERING_TYPE_RESERVED:
1265 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1269 ERR("Not supported type : %d\n", type);
1275 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1277 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1280 case TETHERING_TYPE_USB:
1281 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1284 case TETHERING_TYPE_WIFI:
1285 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1288 case TETHERING_TYPE_BT:
1289 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1292 case TETHERING_TYPE_RESERVED:
1293 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1297 ERR("Not supported type : %d\n", type);
1303 static int __get_common_ssid(char *ssid, unsigned int size)
1306 ERR("ssid is null\n");
1307 return TETHERING_ERROR_INVALID_PARAMETER;
1311 char *ptr_tmp = NULL;
1313 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1315 ERR("vconf_get_str is failed and set default ssid");
1316 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1318 g_strlcpy(ssid, ptr, size);
1322 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1325 return TETHERING_ERROR_NONE;
1328 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1332 __tethering_h *th = (__tethering_h *)tethering;
1333 tethering_error_e ret = TETHERING_ERROR_NONE;
1335 if (th == NULL || set == NULL) {
1336 ERR("null parameter\n-\n");
1337 return TETHERING_ERROR_INVALID_PARAMETER;
1340 if (th->ssid == NULL)
1341 __get_common_ssid(set->ssid, sizeof(set->ssid));
1343 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1345 ret = __get_security_type(&set->sec_type);
1346 if (ret != TETHERING_ERROR_NONE)
1347 set->sec_type = th->sec_type;
1349 ret = __get_visible(&set->visibility);
1350 if (ret != TETHERING_ERROR_NONE)
1351 set->visibility = th->visibility;
1353 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1354 g_strlcpy(set->key, "", sizeof(set->key));
1356 GDBusProxy *proxy = th->client_bus_proxy;
1357 GVariant *parameters;
1358 GError *error = NULL;
1359 char *passphrase = NULL;
1360 unsigned int len = 0;
1362 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1363 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1366 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1368 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1369 ret = TETHERING_ERROR_PERMISSION_DENIED;
1371 ret = TETHERING_ERROR_OPERATION_FAILED;
1373 g_error_free(error);
1377 if (parameters != NULL) {
1378 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
1379 g_variant_unref(parameters);
1382 g_strlcpy(set->key, passphrase, sizeof(set->key));
1385 return TETHERING_ERROR_NONE;
1388 static int __prepare_wifi_ap_settings(tethering_h tethering, _softap_settings_t *set)
1392 __tethering_h *th = (__tethering_h *)tethering;
1394 if (th == NULL || set == NULL) {
1395 ERR("null parameter\n");
1396 return TETHERING_ERROR_INVALID_PARAMETER;
1399 g_strlcpy(set->ssid, th->ap_ssid, sizeof(set->ssid));
1400 set->sec_type = th->sec_type;
1401 set->visibility = th->visibility;
1403 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
1404 g_strlcpy(set->key, "", sizeof(set->key));
1406 g_strlcpy(set->key, th->passphrase, sizeof(set->key));
1409 return TETHERING_ERROR_NONE;
1412 static bool __check_precondition(tethering_type_e type)
1415 int cellular_state = 0;
1418 /* data network through cellular */
1419 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1420 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1421 ERR("Data Network can be connected later");
1425 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1426 if (dnet_state > VCONFKEY_DNET_OFF) {
1427 ERR("Data Network is connected");
1431 /* data network through wifi */
1432 if (type != TETHERING_TYPE_WIFI) {
1433 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1434 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1435 ERR("Wi-Fi is connected!");
1440 ERR("Network is not available!");
1446 * @brief Creates the handle of tethering.
1448 * @privlevel platform
1449 * @privilege http://tizen.org/privilege/tethering.admin
1450 * @remarks The @a tethering must be released tethering_destroy() by you.
1451 * @param[out] tethering A handle of a new mobile ap handle on success
1452 * @return 0 on success, otherwise a negative error value.
1453 * @retval #TETHERING_ERROR_NONE Successful
1454 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1455 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1456 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1457 * @see tethering_destroy()
1459 API int tethering_create(tethering_h *tethering)
1461 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1462 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1463 "parameter(tethering) is NULL\n");
1466 __tethering_h *th = NULL;
1467 GError *error = NULL;
1468 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1470 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1472 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1473 "malloc is failed\n");
1474 memset(th, 0x00, sizeof(__tethering_h));
1475 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1476 th->visibility = true;
1478 if (__generate_initial_passphrase(th->passphrase,
1479 sizeof(th->passphrase)) == 0) {
1480 ERR("random passphrase generation failed\n");
1482 return TETHERING_ERROR_OPERATION_FAILED;
1485 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1486 ERR("common ssid get failed\n");
1488 return TETHERING_ERROR_OPERATION_FAILED;
1491 th->ap_ssid = g_strdup(ssid);
1492 if (th->ap_ssid == NULL) {
1493 ERR("g_strdup failed\n");
1495 return TETHERING_ERROR_OPERATION_FAILED;
1498 #if !GLIB_CHECK_VERSION(2, 36, 0)
1501 GCancellable *cancellable = g_cancellable_new();
1502 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1504 ERR("Couldn't connect to the System bus[%s]", error->message);
1505 g_error_free(error);
1506 g_cancellable_cancel(cancellable);
1507 g_object_unref(cancellable);
1508 g_free(th->ap_ssid);
1510 return TETHERING_ERROR_OPERATION_FAILED;
1512 th->cancellable = cancellable;
1514 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_NONE,
1515 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1516 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1517 if (!th->client_bus_proxy) {
1518 ERR("Couldn't create the proxy object because of %s\n", error->message);
1519 g_cancellable_cancel(th->cancellable);
1520 g_object_unref(th->cancellable);
1521 g_object_unref(th->client_bus);
1522 g_free(th->ap_ssid);
1524 return TETHERING_ERROR_OPERATION_FAILED;
1527 __connect_signals((tethering_h)th);
1529 *tethering = (tethering_h)th;
1530 DBG("Tethering Handle : 0x%X\n", th);
1532 return TETHERING_ERROR_NONE;
1537 * @brief Destroys the handle of tethering.
1539 * @privlevel platform
1540 * @privilege http://tizen.org/privilege/tethering.admin
1541 * @param[in] tethering The handle of tethering
1542 * @return 0 on success, otherwise a negative error value.
1543 * @retval #TETHERING_ERROR_NONE Successful
1544 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1545 * @see tethering_create()
1547 API int tethering_destroy(tethering_h tethering)
1550 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1551 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1552 "parameter(tethering) is NULL\n");
1554 __tethering_h *th = (__tethering_h *)tethering;
1556 DBG("Tethering Handle : 0x%X\n", th);
1557 __disconnect_signals(tethering);
1564 g_object_unref(th->cancellable);
1565 g_object_unref(th->client_bus_proxy);
1566 g_object_unref(th->client_bus);
1567 memset(th, 0x00, sizeof(__tethering_h));
1571 return TETHERING_ERROR_NONE;
1576 * @brief Enables the tethering, asynchronously.
1578 * @privlevel platform
1579 * @privilege http://tizen.org/privilege/tethering.admin
1580 * @param[in] tethering The handle of tethering
1581 * @param[in] type The type of tethering
1582 * @return 0 on success, otherwise negative error value.
1583 * @retval #TETHERING_ERROR_NONE Successful
1584 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1585 * @post tethering_enabled_cb() will be invoked.
1586 * @see tethering_is_enabled()
1587 * @see tethering_disable()
1589 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1591 DBG("+ type : %d\n", type);
1592 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1593 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1594 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1595 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1597 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1598 "parameter(tethering) is NULL\n");
1600 tethering_error_e ret = TETHERING_ERROR_NONE;
1601 __tethering_h *th = (__tethering_h *)tethering;
1602 GDBusProxy *proxy = th->client_bus_proxy;
1603 GDBusConnection *connection = th->client_bus;
1605 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1607 if (type != TETHERING_TYPE_RESERVED
1608 && __check_precondition(type) == FALSE) {
1610 return TETHERING_ERROR_OPERATION_FAILED;
1614 case TETHERING_TYPE_USB:
1615 g_dbus_connection_signal_unsubscribe(connection,
1616 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1618 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1619 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1620 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1623 case TETHERING_TYPE_WIFI: {
1624 _softap_settings_t set = {"", "", 0, false};
1626 ret = __prepare_wifi_settings(tethering, &set);
1627 if (ret != TETHERING_ERROR_NONE) {
1628 ERR("softap settings initialization failed\n");
1630 return TETHERING_ERROR_OPERATION_FAILED;
1632 g_dbus_connection_signal_unsubscribe(connection,
1633 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1635 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1636 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1637 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1638 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1642 case TETHERING_TYPE_BT:
1643 g_dbus_connection_signal_unsubscribe(connection,
1644 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1646 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1647 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1648 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1652 case TETHERING_TYPE_RESERVED: {
1653 _softap_settings_t set = {"", "", 0, false};
1655 ret = __prepare_wifi_ap_settings(tethering, &set);
1656 if (ret != TETHERING_ERROR_NONE) {
1657 ERR("softap settings initialization failed\n");
1658 return TETHERING_ERROR_OPERATION_FAILED;
1661 g_dbus_connection_signal_unsubscribe(connection,
1662 sigs[E_SIGNAL_WIFI_AP_ON].sig_id);
1664 g_dbus_proxy_call(proxy, "enable_wifi_ap",
1665 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1666 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_ap_enabled_cfm_cb, (gpointer)tethering);
1669 case TETHERING_TYPE_ALL: {
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");
1675 return TETHERING_ERROR_OPERATION_FAILED;
1678 /* TETHERING_TYPE_USB */
1679 g_dbus_connection_signal_unsubscribe(connection,
1680 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1682 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1683 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1684 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1686 /* TETHERING_TYPE_WIFI */
1687 g_dbus_connection_signal_unsubscribe(connection,
1688 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1690 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1691 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1692 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1693 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1695 /* TETHERING_TYPE_BT */
1696 g_dbus_connection_signal_unsubscribe(connection,
1697 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1699 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1700 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1701 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1705 ERR("Unknown type : %d\n", type);
1707 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1710 return TETHERING_ERROR_INVALID_PARAMETER;
1713 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1715 return TETHERING_ERROR_NONE;
1720 * @brief Disables the tethering, asynchronously.
1722 * @privlevel platform
1723 * @privilege http://tizen.org/privilege/tethering.admin
1724 * @param[in] tethering The handle of tethering
1725 * @param[in] type The type of tethering
1726 * @return 0 on success, otherwise negative error value.
1727 * @retval #TETHERING_ERROR_NONE Successful
1728 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1729 * @post tethering_disabled_cb() will be invoked.
1730 * @see tethering_is_enabled()
1731 * @see tethering_enable()
1733 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1735 DBG("+ type : %d\n", type);
1736 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1737 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1738 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1740 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1741 "parameter(tethering) is NULL\n");
1743 __tethering_h *th = (__tethering_h *)tethering;
1744 GDBusProxy *proxy = th->client_bus_proxy;
1745 GDBusConnection *connection = th->client_bus;
1748 case TETHERING_TYPE_USB:
1749 g_dbus_connection_signal_unsubscribe(connection,
1750 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1752 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1753 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1754 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1758 case TETHERING_TYPE_WIFI:
1760 g_dbus_connection_signal_unsubscribe(connection,
1761 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1763 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1764 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1765 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1768 case TETHERING_TYPE_BT:
1770 g_dbus_connection_signal_unsubscribe(connection,
1771 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1773 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1774 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1775 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1778 case TETHERING_TYPE_RESERVED:
1779 g_dbus_connection_signal_unsubscribe(connection,
1780 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id);
1782 g_dbus_proxy_call(proxy, "disable_wifi_ap",
1783 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1784 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1787 case TETHERING_TYPE_ALL:
1788 g_dbus_connection_signal_unsubscribe(connection,
1789 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1791 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1792 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1793 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1795 g_dbus_connection_signal_unsubscribe(connection,
1796 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1798 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1799 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1800 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1802 g_dbus_connection_signal_unsubscribe(connection,
1803 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1805 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1806 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1807 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1811 ERR("Not supported tethering type [%d]\n", type);
1813 return TETHERING_ERROR_INVALID_PARAMETER;
1816 return TETHERING_ERROR_NONE;
1821 * @brief Checks whetehr the tethering is enabled or not.
1823 * @privlevel platform
1824 * @privilege http://tizen.org/privilege/tethering.admin
1825 * @param[in] tethering The handle of tethering
1826 * @param[in] type The type of tethering
1827 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1829 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1832 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1834 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1836 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1840 case TETHERING_TYPE_USB:
1841 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1844 case TETHERING_TYPE_WIFI:
1845 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1848 case TETHERING_TYPE_BT:
1849 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1852 case TETHERING_TYPE_RESERVED:
1853 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
1857 ERR("Not supported type : %d\n", type);
1860 return is_on & vconf_type ? true : false;
1865 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1867 * @privlevel platform
1868 * @privilege http://tizen.org/privilege/tethering.admin
1869 * @remarks @a mac_address must be released with free() by you.
1870 * @param[in] tethering The handle of tethering
1871 * @param[in] type The type of tethering
1872 * @param[out] mac_address The MAC address
1873 * @return 0 on success, otherwise a negative error value.
1874 * @retval #TETHERING_ERROR_NONE Successful
1875 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1876 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1877 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1878 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1879 * @pre tethering must be enabled.
1880 * @see tethering_is_enabled()
1881 * @see tethering_enable()
1883 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1885 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1886 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1887 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1889 _retvm_if(tethering_is_enabled(tethering, type) == false,
1890 TETHERING_ERROR_NOT_ENABLED,
1891 "tethering type[%d] is not enabled\n", type);
1892 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1893 "parameter(tethering) is NULL\n");
1894 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1895 "parameter(mac_address) is NULL\n");
1899 char *macbuf = NULL;
1901 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1902 TETHERING_ERROR_OPERATION_FAILED,
1903 "getting interface name is failed\n");
1905 s = socket(AF_INET, SOCK_DGRAM, 0);
1906 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1907 "getting socket is failed\n");
1908 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1909 ERR("getting mac is failed\n");
1911 return TETHERING_ERROR_OPERATION_FAILED;
1915 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1916 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1917 "Not enough memory\n");
1918 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1919 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1920 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1921 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1922 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1923 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1924 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1926 *mac_address = macbuf;
1928 return TETHERING_ERROR_NONE;
1933 * @brief Gets the name of network interface. For example, usb0.
1935 * @privlevel platform
1936 * @privilege http://tizen.org/privilege/tethering.admin
1937 * @remarks @a interface_name must be released with free() by you.
1938 * @param[in] tethering The handle of tethering
1939 * @param[in] type The type of tethering
1940 * @param[out] interface_name The name of network interface
1941 * @return 0 on success, otherwise negative error value.
1942 * @retval #TETHERING_ERROR_NONE Successful
1943 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1944 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1945 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1946 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1947 * @pre tethering must be enabled.
1948 * @see tethering_is_enabled()
1949 * @see tethering_enable()
1951 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1953 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1954 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1955 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1957 _retvm_if(tethering_is_enabled(tethering, type) == false,
1958 TETHERING_ERROR_NOT_ENABLED,
1959 "tethering type[%d] is not enabled\n", type);
1960 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1961 "parameter(tethering) is NULL\n");
1962 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1963 "parameter(interface_name) is NULL\n");
1965 char intf[TETHERING_STR_INFO_LEN] = {0, };
1967 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1968 TETHERING_ERROR_OPERATION_FAILED,
1969 "getting interface name is failed\n");
1970 *interface_name = strdup(intf);
1971 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1972 "Not enough memory\n");
1974 return TETHERING_ERROR_NONE;
1979 * @brief Gets the local IP address.
1981 * @privlevel platform
1982 * @privilege http://tizen.org/privilege/tethering.admin
1983 * @remarks @a ip_address 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[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1987 * @param[out] ip_address The local IP address
1988 * @return 0 on success, otherwise negative error value.
1989 * @retval #TETHERING_ERROR_NONE Successful
1990 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1991 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1992 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1993 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1994 * @pre tethering must be enabled.
1995 * @see tethering_is_enabled()
1996 * @see tethering_enable()
1998 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2001 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2002 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2003 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2005 _retvm_if(tethering_is_enabled(tethering, type) == false,
2006 TETHERING_ERROR_NOT_ENABLED,
2007 "tethering type[%d] is not enabled\n", type);
2008 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2009 "parameter(tethering) is NULL\n");
2010 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2011 "parameter(ip_address) is NULL\n");
2017 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2018 TETHERING_ERROR_OPERATION_FAILED,
2019 "getting interface name is failed\n");
2021 s = socket(AF_INET, SOCK_DGRAM, 0);
2022 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2023 "getting socket is failed\n");
2024 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2025 ERR("ioctl is failed\n");
2027 return TETHERING_ERROR_OPERATION_FAILED;
2031 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2032 *ip_address = strdup(ipbuf);
2033 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2034 "Not enough memory\n");
2036 return TETHERING_ERROR_NONE;
2041 * @brief Gets the Gateway address.
2043 * @privlevel platform
2044 * @privilege http://tizen.org/privilege/tethering.admin
2045 * @remarks @a gateway_address must be released with free() by you.
2046 * @param[in] tethering The handle of tethering
2047 * @param[in] type The type of tethering
2048 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2049 * @param[out] gateway_address The local IP address
2050 * @return 0 on success, otherwise negative error value.
2051 * @retval #TETHERING_ERROR_NONE Successful
2052 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2053 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2054 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2055 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2056 * @pre tethering must be enabled.
2057 * @see tethering_is_enabled()
2058 * @see tethering_enable()
2060 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2063 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2064 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2065 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2067 _retvm_if(tethering_is_enabled(tethering, type) == false,
2068 TETHERING_ERROR_NOT_ENABLED,
2069 "tethering type[%d] is not enabled\n", type);
2070 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2071 "parameter(tethering) is NULL\n");
2072 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2073 "parameter(gateway_address) is NULL\n");
2075 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2077 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2078 TETHERING_ERROR_OPERATION_FAILED,
2079 "getting gateway address is failed\n");
2081 *gateway_address = strdup(gateway_buf);
2083 return TETHERING_ERROR_NONE;
2088 * @brief Gets the Subnet Mask.
2090 * @privlevel platform
2091 * @privilege http://tizen.org/privilege/tethering.admin
2092 * @remarks @a subnet_mask must be released with free() by you.
2093 * @param[in] tethering The handle of tethering
2094 * @param[in] type The type of tethering
2095 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2096 * @param[out] subnet_mask The local IP address
2097 * @return 0 on success, otherwise negative error value.
2098 * @retval #TETHERING_ERROR_NONE Successful
2099 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2100 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2101 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2102 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2103 * @pre tethering must be enabled.
2104 * @see tethering_is_enabled()
2105 * @see tethering_enable()
2107 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
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 is not enabled\n");
2116 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2117 "parameter(tethering) is NULL\n");
2118 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2119 "parameter(subnet_mask) is NULL\n");
2121 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2122 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2123 "Not enough memory\n");
2125 return TETHERING_ERROR_NONE;
2130 * @brief Gets the data usage.
2132 * @privlevel platform
2133 * @privilege http://tizen.org/privilege/tethering.admin
2134 * @param[in] tethering The handle of tethering
2135 * @param[out] usage The data usage
2136 * @return 0 on success, otherwise negative error value.
2137 * @retval #TETHERING_ERROR_NONE Successful
2138 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2139 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2140 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2141 * @pre tethering must be enabled.
2142 * @see tethering_is_enabled()
2143 * @see tethering_enable()
2145 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2147 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2149 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2150 "parameter(tethering) is NULL\n");
2151 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2152 "parameter(callback) is NULL\n");
2153 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2154 TETHERING_ERROR_NOT_ENABLED,
2155 "tethering is not enabled\n");
2157 __tethering_h *th = (__tethering_h *)tethering;
2158 GDBusProxy *proxy = th->client_bus_proxy;
2160 th->data_usage_cb = callback;
2161 th->data_usage_user_data = user_data;
2163 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2164 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2165 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2167 return TETHERING_ERROR_NONE;
2172 * @brief Gets the client which is connected by tethering "type".
2174 * @privlevel platform
2175 * @privilege http://tizen.org/privilege/tethering.admin
2176 * @param[in] tethering The handle of tethering
2177 * @param[in] type The type of tethering
2178 * @param[in] callback The callback function to invoke
2179 * @param[in] user_data The user data to be passed to the callback function
2180 * @retval #TETHERING_ERROR_NONE Successful
2181 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2182 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2183 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2184 * @pre tethering must be enabled.
2185 * @see tethering_is_enabled()
2186 * @see tethering_enable()
2188 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2191 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2192 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2193 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_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 mobile_ap_type_e interface;
2204 __tethering_h *th = (__tethering_h *)tethering;
2205 __tethering_client_h client = {0, };
2208 gchar *hostname = NULL;
2209 guint timestamp = 0;
2210 GError *error = NULL;
2211 GVariant *result = NULL;
2212 GVariantIter *outer_iter = NULL;
2213 GVariantIter *inner_iter = NULL;
2214 GVariant *station = NULL;
2215 GVariant *value = NULL;
2218 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2219 NULL, G_DBUS_CALL_FLAGS_NONE,
2220 -1, th->cancellable, &error);
2222 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2223 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2224 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2225 g_variant_get(station, "a{sv}", &inner_iter);
2226 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2227 if (g_strcmp0(key, "Type") == 0) {
2228 interface = g_variant_get_int32(value);
2229 if (interface == MOBILE_AP_TYPE_USB)
2230 client.interface = TETHERING_TYPE_USB;
2231 else if (interface == MOBILE_AP_TYPE_WIFI)
2232 client.interface = TETHERING_TYPE_WIFI;
2233 else if (interface == MOBILE_AP_TYPE_BT)
2234 client.interface = TETHERING_TYPE_BT;
2235 else if (interface == MOBILE_AP_TYPE_WIFI_AP)
2236 client.interface = TETHERING_TYPE_RESERVED;
2238 ERR("Invalid interface\n");
2240 g_variant_unref(value);
2243 DBG("interface is %d\n", client.interface);
2244 if (client.interface != type && (TETHERING_TYPE_ALL != type &&
2245 client.interface != TETHERING_TYPE_RESERVED)) {
2247 g_variant_unref(value);
2250 } else if (g_strcmp0(key, "IP") == 0) {
2251 g_variant_get(value, "s", &ip);
2252 SDBG("ip is %s\n", ip);
2253 g_strlcpy(client.ip, ip, sizeof(client.ip));
2254 } else if (g_strcmp0(key, "MAC") == 0) {
2255 g_variant_get(value, "s", &mac);
2256 SDBG("mac is %s\n", mac);
2257 g_strlcpy(client.mac, mac, sizeof(client.mac));
2258 } else if (g_strcmp0(key, "Name") == 0) {
2259 g_variant_get(value, "s", &hostname);
2260 SDBG("hsotname is %s\n", hostname);
2262 client.hostname = g_strdup(hostname);
2263 } else if (g_strcmp0(key, "Time") == 0) {
2264 timestamp = g_variant_get_int32(value);
2265 DBG("timestamp is %d\n", timestamp);
2266 client.tm = (time_t)timestamp;
2268 ERR("Key %s not required\n", key);
2274 g_variant_iter_free(inner_iter);
2275 if (callback((tethering_client_h)&client, user_data) == false) {
2276 DBG("iteration is stopped\n");
2277 g_free(client.hostname);
2278 g_variant_iter_free(outer_iter);
2279 g_variant_unref(station);
2280 g_variant_unref(result);
2282 return TETHERING_ERROR_OPERATION_FAILED;
2284 g_free(client.hostname);
2286 g_variant_iter_free(outer_iter);
2287 g_variant_unref(station);
2288 g_variant_unref(result);
2290 return TETHERING_ERROR_NONE;
2295 * @brief Registers the callback function called when tethering is enabled.
2297 * @privlevel platform
2298 * @privilege http://tizen.org/privilege/tethering.admin
2299 * @param[in] tethering The handle of tethering
2300 * @param[in] type The type of tethering
2301 * @param[in] callback The callback function to invoke
2302 * @param[in] user_data The user data to be passed to the callback function
2303 * @retval #TETHERING_ERROR_NONE Successful
2304 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2305 * @see tethering_unset_enabled_cb()
2307 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2309 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2310 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2311 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2313 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2314 "parameter(tethering) is NULL\n");
2315 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2316 "parameter(callback) is NULL\n");
2318 __tethering_h *th = (__tethering_h *)tethering;
2319 tethering_type_e ti;
2321 if (type != TETHERING_TYPE_ALL) {
2322 th->enabled_cb[type] = callback;
2323 th->enabled_user_data[type] = user_data;
2325 return TETHERING_ERROR_NONE;
2328 /* TETHERING_TYPE_ALL */
2329 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2330 th->enabled_cb[ti] = callback;
2331 th->enabled_user_data[ti] = user_data;
2334 return TETHERING_ERROR_NONE;
2339 * @brief Unregisters the callback function called when tethering is disabled.
2341 * @privlevel platform
2342 * @privilege http://tizen.org/privilege/tethering.admin
2343 * @param[in] tethering The handle of tethering
2344 * @param[in] type The type of tethering
2345 * @retval #TETHERING_ERROR_NONE Successful
2346 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2347 * @see tethering_set_enabled_cb()
2349 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2351 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2352 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2353 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2355 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2356 "parameter(tethering) is NULL\n");
2358 __tethering_h *th = (__tethering_h *)tethering;
2359 tethering_type_e ti;
2361 if (type != TETHERING_TYPE_ALL) {
2362 th->enabled_cb[type] = NULL;
2363 th->enabled_user_data[type] = NULL;
2365 return TETHERING_ERROR_NONE;
2368 /* TETHERING_TYPE_ALL */
2369 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2370 th->enabled_cb[ti] = NULL;
2371 th->enabled_user_data[ti] = NULL;
2374 return TETHERING_ERROR_NONE;
2379 * @brief Registers the callback function called when tethering is disabled.
2381 * @privlevel platform
2382 * @privilege http://tizen.org/privilege/tethering.admin
2383 * @param[in] tethering The handle of tethering
2384 * @param[in] type The type of tethering
2385 * @param[in] callback The callback function to invoke
2386 * @param[in] user_data The user data to be passed to the callback function
2387 * @retval #TETHERING_ERROR_NONE Successful
2388 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2389 * @see tethering_unset_disabled_cb()
2391 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2393 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2394 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2395 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2397 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2398 "parameter(tethering) is NULL\n");
2399 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2400 "parameter(callback) is NULL\n");
2402 __tethering_h *th = (__tethering_h *)tethering;
2403 tethering_type_e ti;
2405 if (type != TETHERING_TYPE_ALL) {
2406 th->disabled_cb[type] = callback;
2407 th->disabled_user_data[type] = user_data;
2409 return TETHERING_ERROR_NONE;
2412 /* TETHERING_TYPE_ALL */
2413 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2414 th->disabled_cb[ti] = callback;
2415 th->disabled_user_data[ti] = user_data;
2418 return TETHERING_ERROR_NONE;
2423 * @brief Unregisters the callback function called when tethering is disabled.
2425 * @privlevel platform
2426 * @privilege http://tizen.org/privilege/tethering.admin
2427 * @param[in] tethering The handle of tethering
2428 * @param[in] type The type of tethering
2429 * @retval #TETHERING_ERROR_NONE Successful
2430 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2431 * @see tethering_set_disabled_cb()
2433 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2435 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2436 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2437 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2439 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2440 "parameter(tethering) is NULL\n");
2442 __tethering_h *th = (__tethering_h *)tethering;
2443 tethering_type_e ti;
2445 if (type != TETHERING_TYPE_ALL) {
2446 th->disabled_cb[type] = NULL;
2447 th->disabled_user_data[type] = NULL;
2449 return TETHERING_ERROR_NONE;
2452 /* TETHERING_TYPE_ALL */
2453 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2454 th->disabled_cb[ti] = NULL;
2455 th->disabled_user_data[ti] = NULL;
2458 return TETHERING_ERROR_NONE;
2463 * @brief Registers the callback function called when the state of connection is changed.
2465 * @privlevel platform
2466 * @privilege http://tizen.org/privilege/tethering.admin
2467 * @param[in] tethering The handle of tethering
2468 * @param[in] type The type of tethering
2469 * @param[in] callback The callback function to invoke
2470 * @param[in] user_data The user data to be passed to the callback function
2471 * @retval #TETHERING_ERROR_NONE Successful
2472 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2473 * @see tethering_unset_connection_state_changed_cb_cb()
2475 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2477 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2478 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2479 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2481 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2482 "parameter(tethering) is NULL\n");
2483 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2484 "parameter(callback) is NULL\n");
2486 __tethering_h *th = (__tethering_h *)tethering;
2487 tethering_type_e ti;
2489 if (type != TETHERING_TYPE_ALL) {
2490 th->changed_cb[type] = callback;
2491 th->changed_user_data[type] = user_data;
2493 return TETHERING_ERROR_NONE;
2496 /* TETHERING_TYPE_ALL */
2497 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2498 th->changed_cb[ti] = callback;
2499 th->changed_user_data[ti] = user_data;
2502 return TETHERING_ERROR_NONE;
2507 * @brief Unregisters the callback function called when the state of connection is changed.
2509 * @privlevel platform
2510 * @privilege http://tizen.org/privilege/tethering.admin
2511 * @param[in] tethering The handle of tethering
2512 * @param[in] type The type of tethering
2513 * @retval #TETHERING_ERROR_NONE Successful
2514 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2515 * @see tethering_set_connection_state_changed_cb()
2517 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2519 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2520 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2521 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2523 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2524 "parameter(tethering) is NULL\n");
2526 __tethering_h *th = (__tethering_h *)tethering;
2527 tethering_type_e ti;
2529 if (type != TETHERING_TYPE_ALL) {
2530 th->changed_cb[type] = NULL;
2531 th->changed_user_data[type] = NULL;
2533 return TETHERING_ERROR_NONE;
2536 /* TETHERING_TYPE_ALL */
2537 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2538 th->changed_cb[ti] = NULL;
2539 th->changed_user_data[ti] = NULL;
2542 return TETHERING_ERROR_NONE;
2547 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2549 * @privlevel platform
2550 * @privilege http://tizen.org/privilege/tethering.admin
2551 * @param[in] tethering The handle of tethering
2552 * @param[in] callback The callback function to invoke
2553 * @param[in] user_data The user data to be passed to the callback function
2554 * @retval #TETHERING_ERROR_NONE Successful
2555 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2556 * @see tethering_wifi_unset_security_type_changed_cb()
2558 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2560 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2562 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2563 "parameter(tethering) is NULL\n");
2564 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2565 "parameter(callback) is NULL\n");
2567 __tethering_h *th = (__tethering_h *)tethering;
2569 th->security_type_changed_cb = callback;
2570 th->security_type_user_data = user_data;
2572 return TETHERING_ERROR_NONE;
2578 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2580 * @privlevel platform
2581 * @privilege http://tizen.org/privilege/tethering.admin
2582 * @param[in] tethering The handle of tethering
2583 * @param[in] type The type of tethering
2584 * @retval #TETHERING_ERROR_NONE Successful
2585 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2586 * @see tethering_wifi_set_security_type_changed_cb()
2588 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2590 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2592 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2593 "parameter(tethering) is NULL\n");
2595 __tethering_h *th = (__tethering_h *)tethering;
2597 th->security_type_changed_cb = NULL;
2598 th->security_type_user_data = NULL;
2600 return TETHERING_ERROR_NONE;
2605 * @brief Registers the callback function called when the visibility of SSID is changed.
2607 * @privlevel platform
2608 * @privilege http://tizen.org/privilege/tethering.admin
2609 * @param[in] tethering The handle of tethering
2610 * @param[in] callback The callback function to invoke
2611 * @param[in] user_data The user data to be passed to the callback function
2612 * @retval #TETHERING_ERROR_NONE Successful
2613 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2614 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2616 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2618 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2620 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2621 "parameter(tethering) is NULL\n");
2622 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2623 "parameter(callback) is NULL\n");
2625 __tethering_h *th = (__tethering_h *)tethering;
2627 th->ssid_visibility_changed_cb = callback;
2628 th->ssid_visibility_user_data = user_data;
2630 return TETHERING_ERROR_NONE;
2635 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2637 * @privlevel platform
2638 * @privilege http://tizen.org/privilege/tethering.admin
2639 * @param[in] tethering The handle of tethering
2640 * @retval #TETHERING_ERROR_NONE Successful
2641 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2642 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2644 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2646 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2648 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2649 "parameter(tethering) is NULL\n");
2651 __tethering_h *th = (__tethering_h *)tethering;
2653 th->ssid_visibility_changed_cb = NULL;
2654 th->ssid_visibility_user_data = NULL;
2656 return TETHERING_ERROR_NONE;
2661 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2663 * @privlevel platform
2664 * @privilege http://tizen.org/privilege/tethering.admin
2665 * @param[in] tethering The handle of tethering
2666 * @param[in] callback The callback function to invoke
2667 * @param[in] user_data The user data to be passed to the callback function
2668 * @retval #TETHERING_ERROR_NONE Successful
2669 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2670 * @see tethering_wifi_unset_passphrase_changed_cb()
2672 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2674 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2676 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2677 "parameter(tethering) is NULL\n");
2678 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2679 "parameter(callback) is NULL\n");
2681 __tethering_h *th = (__tethering_h *)tethering;
2683 th->passphrase_changed_cb = callback;
2684 th->passphrase_user_data = user_data;
2686 return TETHERING_ERROR_NONE;
2691 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2693 * @privlevel platform
2694 * @privilege http://tizen.org/privilege/tethering.admin
2695 * @param[in] tethering The handle of tethering
2696 * @retval #TETHERING_ERROR_NONE Successful
2697 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2698 * @see tethering_wifi_set_passphrase_changed_cb()
2700 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2702 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2704 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2705 "parameter(tethering) is NULL\n");
2707 __tethering_h *th = (__tethering_h *)tethering;
2709 th->passphrase_changed_cb = NULL;
2710 th->passphrase_user_data = NULL;
2712 return TETHERING_ERROR_NONE;
2717 * @brief Sets the security type of Wi-Fi tethering.
2719 * @privlevel platform
2720 * @privilege http://tizen.org/privilege/tethering.admin
2721 * @remarks This change is applied next time Wi-Fi tethering is enabled
2722 * @param[in] tethering The handle of tethering
2723 * @param[in] type The security type
2724 * @return 0 on success, otherwise negative error value.
2725 * @retval #TETHERING_ERROR_NONE Successful
2726 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2727 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2728 * @see tethering_wifi_get_security_type()
2730 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2732 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2734 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2735 "parameter(tethering) is NULL\n");
2737 __tethering_h *th = (__tethering_h *)tethering;
2738 tethering_error_e ret = TETHERING_ERROR_NONE;
2740 ret = __set_security_type(type);
2741 if (ret == TETHERING_ERROR_NONE) {
2743 __send_dbus_signal(th->client_bus,
2744 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2745 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2746 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2747 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2754 * @brief Gets the security type of Wi-Fi tethering.
2756 * @privlevel platform
2757 * @privilege http://tizen.org/privilege/tethering.admin
2758 * @param[in] tethering The handle of tethering
2759 * @param[out] type The security type
2760 * @return 0 on success, otherwise negative error value.
2761 * @retval #TETHERING_ERROR_NONE Successful
2762 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2763 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2764 * @see tethering_wifi_set_security_type()
2766 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2768 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2770 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2771 "parameter(type) is NULL\n");
2773 return __get_security_type(type);
2778 * @brief Sets the SSID (service set identifier).
2780 * @privlevel platform
2781 * @privilege http://tizen.org/privilege/tethering.admin
2782 * @details If SSID is not set, Device name is used as SSID
2783 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2784 * @param[in] tethering The handle of tethering
2785 * @param[out] ssid The SSID
2786 * @return 0 on success, otherwise negative error value.
2787 * @retval #TETHERING_ERROR_NONE Successful
2788 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2789 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2791 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2793 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2795 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2796 "parameter(tethering) is NULL\n");
2797 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2798 "parameter(ssid) is NULL\n");
2800 __tethering_h *th = (__tethering_h *)tethering;
2801 char *p_ssid = NULL;
2804 ssid_len = strlen(ssid);
2805 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2806 ERR("parameter(ssid) is too long");
2807 return TETHERING_ERROR_INVALID_PARAMETER;
2810 p_ssid = strdup(ssid);
2811 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2812 "strdup is failed\n");
2818 return TETHERING_ERROR_NONE;
2823 * @brief Gets the SSID (service set identifier).
2825 * @privlevel platform
2826 * @privilege http://tizen.org/privilege/tethering.admin
2827 * @remarks @a ssid must be released with free() by you.
2828 * @param[in] tethering The handle of tethering
2829 * @param[out] ssid The SSID
2830 * @return 0 on success, otherwise negative error value.
2831 * @retval #TETHERING_ERROR_NONE Successful
2832 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2833 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2834 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2836 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2838 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2840 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2841 "parameter(tethering) is NULL\n");
2842 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2843 "parameter(ssid) is NULL\n");
2846 __tethering_h *th = (__tethering_h *)tethering;
2847 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2849 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2850 if (th->ssid != NULL) {
2851 DBG("Private SSID is set\n");
2852 *ssid = strdup(th->ssid);
2854 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2855 val, sizeof(val)) == false) {
2856 return TETHERING_ERROR_OPERATION_FAILED;
2858 *ssid = strdup(val);
2861 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2862 val, sizeof(val)) == false) {
2863 return TETHERING_ERROR_OPERATION_FAILED;
2865 *ssid = strdup(val);
2868 if (*ssid == NULL) {
2869 ERR("strdup is failed\n");
2870 return TETHERING_ERROR_OUT_OF_MEMORY;
2873 return TETHERING_ERROR_NONE;
2878 * @brief Sets the visibility of SSID(service set identifier).
2880 * @privlevel platform
2881 * @privilege http://tizen.org/privilege/tethering.admin
2882 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2883 * @remarks This change is applied next time Wi-Fi tethering is enabled
2884 * @param[in] tethering The handle of tethering
2885 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2886 * @return 0 on success, otherwise negative error value.
2887 * @retval #TETHERING_ERROR_NONE Successful
2888 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2889 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2890 * @see tethering_wifi_get_ssid_visibility()
2892 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2894 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2896 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2897 "parameter(tethering) is NULL\n");
2899 __tethering_h *th = (__tethering_h *)tethering;
2900 tethering_error_e ret = TETHERING_ERROR_NONE;
2902 ret = __set_visible(visible);
2903 if (ret == TETHERING_ERROR_NONE) {
2905 __send_dbus_signal(th->client_bus,
2906 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2907 visible ? SIGNAL_MSG_SSID_VISIBLE :
2908 SIGNAL_MSG_SSID_HIDE);
2915 * @brief Gets the visibility of SSID(service set identifier).
2917 * @privlevel platform
2918 * @privilege http://tizen.org/privilege/tethering.admin
2919 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2920 * @param[in] tethering The handle of tethering
2921 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2922 * @return 0 on success, otherwise negative error value.
2923 * @retval #TETHERING_ERROR_NONE Successful
2924 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2925 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2926 * @see tethering_wifi_set_ssid_visibility()
2928 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2930 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2932 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2933 "parameter(visible) is NULL\n");
2935 return __get_visible(visible);
2940 * @brief Sets the passphrase.
2942 * @privlevel platform
2943 * @privilege http://tizen.org/privilege/tethering.admin
2944 * @remarks This change is applied next time Wi-Fi tethering is enabled
2945 * @param[in] tethering The handle of tethering
2946 * @param[in] passphrase The passphrase
2947 * @return 0 on success, otherwise negative error value.
2948 * @retval #TETHERING_ERROR_NONE Successful
2949 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2950 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2951 * @see tethering_wifi_get_passphrase()
2953 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2955 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2957 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2958 "parameter(tethering) is NULL\n");
2959 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2960 "parameter(passphrase) is NULL\n");
2962 __tethering_h *th = (__tethering_h *)tethering;
2963 GDBusProxy *proxy = th->client_bus_proxy;
2964 GVariant *parameters;
2965 GError *error = NULL;
2966 int passphrase_len = 0;
2970 passphrase_len = strlen(passphrase);
2971 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
2972 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
2973 ERR("parameter(passphrase) is too short or long\n");
2974 return TETHERING_ERROR_INVALID_PARAMETER;
2977 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
2978 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2981 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
2983 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
2984 ret = TETHERING_ERROR_PERMISSION_DENIED;
2986 ret = TETHERING_ERROR_OPERATION_FAILED;
2988 g_error_free(error);
2992 g_variant_get(parameters, "(u)", &ret);
2993 g_variant_unref(parameters);
2995 if (ret == TETHERING_ERROR_NONE) {
2996 __send_dbus_signal(th->client_bus,
2997 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3006 * @brief Gets the passphrase.
3008 * @privlevel platform
3009 * @privilege http://tizen.org/privilege/tethering.admin
3010 * @remarks @a passphrase must be released with free() by you.
3011 * @param[in] tethering The handle of tethering
3012 * @param[out] passphrase The passphrase
3013 * @return 0 on success, otherwise negative error value.
3014 * @retval #TETHERING_ERROR_NONE Successful
3015 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3016 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3017 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3018 * @see tethering_wifi_set_passphrase()
3020 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3022 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3024 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3025 "parameter(tethering) is NULL\n");
3026 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3027 "parameter(passphrase) is NULL\n");
3029 __tethering_h *th = (__tethering_h *)tethering;
3030 GDBusProxy *proxy = th->client_bus_proxy;
3031 GVariant *parameters;
3032 GError *error = NULL;
3033 unsigned int len = 0;
3034 tethering_error_e ret = TETHERING_ERROR_NONE;
3036 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3037 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3040 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3042 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3043 ret = TETHERING_ERROR_PERMISSION_DENIED;
3045 ret = TETHERING_ERROR_OPERATION_FAILED;
3047 g_error_free(error);
3051 if (parameters != NULL) {
3052 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3053 g_variant_unref(parameters);
3056 return TETHERING_ERROR_NONE;
3061 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3063 * @privlevel platform
3064 * @privilege http://tizen.org/privilege/tethering.admin
3065 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3066 * @param[in] tethering The handle of tethering
3067 * @param[in] callback The callback function to invoke
3068 * @param[in] user_data The user data to be passed to the callback function
3069 * @return 0 on success, otherwise negative error value.
3070 * @retval #TETHERING_ERROR_NONE Successful
3071 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3072 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3074 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3077 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3079 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3080 "parameter(tethering) is NULL\n");
3081 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3082 "parameter(callback) is NULL\n");
3084 __tethering_h *th = (__tethering_h *)tethering;
3085 _softap_settings_t set = {"", "", 0, false};
3086 GDBusProxy *proxy = th->client_bus_proxy;
3091 if (th->settings_reloaded_cb) {
3092 ERR("Operation in progress\n");
3093 return TETHERING_ERROR_OPERATION_FAILED;
3096 ret = __prepare_wifi_settings(tethering, &set);
3097 if (ret != TETHERING_ERROR_NONE) {
3098 ERR("softap settings initialization failed\n");
3099 return TETHERING_ERROR_OPERATION_FAILED;
3102 th->settings_reloaded_cb = callback;
3103 th->settings_reloaded_user_data = user_data;
3105 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3106 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
3107 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3108 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3110 return TETHERING_ERROR_NONE;
3115 * @brief Sets the security type of Wi-Fi AP.
3117 * @privlevel platform
3118 * @privilege http://tizen.org/privilege/tethering.admin
3119 * @details If security type is not set, WPA2_PSK is used
3120 * @param[in] tethering The handle of tethering
3121 * @param[in] type The security type
3122 * @return 0 on success, otherwise negative error value.
3123 * @retval #TETHERING_ERROR_NONE Successful
3124 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3125 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3126 * @see tethering_wifi_ap_get_security_type()
3128 API int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
3130 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3132 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3133 "parameter(tethering) is NULL\n");
3135 __tethering_h *th = (__tethering_h *)tethering;
3136 th->sec_type = type;
3137 return TETHERING_ERROR_NONE;
3142 * @brief Gets the security type of Wi-Fi AP.
3144 * @privlevel platform
3145 * @privilege http://tizen.org/privilege/tethering.admin
3146 * @details If security type is not set, WPA2_PSK is used
3147 * @param[in] tethering The handle of tethering
3148 * @param[out] type The security type
3149 * @return 0 on success, otherwise negative error value.
3150 * @retval #TETHERING_ERROR_NONE Successful
3151 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3152 * @see tethering_wifi_ap_set_security_type()
3154 API int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3156 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3158 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3159 "parameter(type) is NULL\n");
3161 __tethering_h *th = (__tethering_h *)tethering;
3163 *type = th->sec_type;
3164 return TETHERING_ERROR_NONE;
3169 * @brief Sets the SSID (service set identifier) for Wi-Fi AP. The SSID cannot exceed 32 bytes.
3171 * @privlevel platform
3172 * @privilege http://tizen.org/privilege/tethering.admin
3173 * @details If SSID is not set, Device name is used as SSID
3174 * @param[in] tethering The handle of tethering
3175 * @param[in] ssid The SSID
3176 * @return 0 on success, otherwise negative error value.
3177 * @retval #TETHERING_ERROR_NONE Successful
3178 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3179 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3181 API int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid)
3183 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3185 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3186 "parameter(tethering) is NULL\n");
3187 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3188 "parameter(ssid) is NULL\n");
3190 __tethering_h *th = (__tethering_h *)tethering;
3191 char *p_ssid = NULL;
3194 ssid_len = strlen(ssid);
3195 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3196 ERR("parameter(ssid) is too long");
3197 return TETHERING_ERROR_INVALID_PARAMETER;
3200 p_ssid = strdup(ssid);
3201 if (p_ssid == NULL) {
3202 ERR("strdup failed\n");
3203 return TETHERING_ERROR_OUT_OF_MEMORY;
3207 g_free(th->ap_ssid);
3208 th->ap_ssid = p_ssid;
3210 return TETHERING_ERROR_NONE;
3215 * @brief Gets the SSID (service set identifier) for Wi-Fi AP.
3217 * @privlevel platform
3218 * @privilege http://tizen.org/privilege/tethering.admin
3219 * @details If SSID is not set, Device name is used as SSID
3220 * @remarks @a ssid must be released with free() by you.
3221 * @param[in] tethering The handle of tethering
3222 * @param[out] ssid The SSID
3223 * @return 0 on success, otherwise negative error value.
3224 * @retval #TETHERING_ERROR_NONE Successful
3225 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3226 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3228 API int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid)
3230 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3232 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3233 "parameter(tethering) is NULL\n");
3234 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3235 "parameter(ssid) is NULL\n");
3237 __tethering_h *th = (__tethering_h *)tethering;
3239 *ssid = g_strdup(th->ap_ssid);
3240 if (*ssid == NULL) {
3241 ERR("strdup failed\n");
3242 return TETHERING_ERROR_OUT_OF_MEMORY;
3245 return TETHERING_ERROR_NONE;
3250 * @brief Sets the visibility of SSID(service set identifier) for Wi-Fi AP.
3252 * @privlevel platform
3253 * @privilege http://tizen.org/privilege/tethering.admin
3254 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3255 * @details by default visibility is set to true.
3256 * @remarks This change is applied next time Wi-Fi tethering is enabled
3257 * @param[in] tethering The handle of tethering
3258 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3259 * @return 0 on success, otherwise negative error value.
3260 * @retval #TETHERING_ERROR_NONE Successful
3261 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3262 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3263 * @see tethering_wifi_ap_get_ssid_visibility()
3265 API int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible)
3267 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3269 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3270 "parameter(tethering) is NULL\n");
3272 __tethering_h *th = (__tethering_h *)tethering;
3273 th->visibility = visible;
3274 return TETHERING_ERROR_NONE;
3279 * @brief Gets the visibility of SSID(service set identifier) for Wi-Fi AP.
3281 * @privlevel platform
3282 * @privilege http://tizen.org/privilege/tethering.admin
3283 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3284 * @details by default visibility is set to true.
3285 * @param[in] tethering The handle of tethering
3286 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3287 * @return 0 on success, otherwise negative error value.
3288 * @retval #TETHERING_ERROR_NONE Successful
3289 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3290 * @see tethering_wifi_ap_set_ssid_visibility()
3292 API int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible)
3294 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3296 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3297 "parameter(visible) is NULL\n");
3299 __tethering_h *th = (__tethering_h *)tethering;
3301 *visible = th->visibility;
3302 return TETHERING_ERROR_NONE;
3307 * @brief Sets the passphrase for Wi-Fi AP.
3309 * @privlevel platform
3310 * @privilege http://tizen.org/privilege/tethering.admin
3311 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3312 * @param[in] tethering The handle of tethering
3313 * @param[in] passphrase The passphrase
3314 * @return 0 on success, otherwise negative error value.
3315 * @retval #TETHERING_ERROR_NONE Successful
3316 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3317 * @see tethering_wifi_ap_get_passphrase()
3319 API int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase)
3321 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3323 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3324 "parameter(tethering) is NULL\n");
3325 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3326 "parameter(passphrase) is NULL\n");
3328 __tethering_h *th = (__tethering_h *)tethering;
3329 int passphrase_len = 0;
3331 passphrase_len = strlen(passphrase);
3333 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3334 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3335 ERR("parameter(passphrase) is too short or long\n");
3336 return TETHERING_ERROR_INVALID_PARAMETER;
3339 if (!g_strcmp0(passphrase, th->passphrase))
3340 return TETHERING_ERROR_NONE;
3342 g_strlcpy(th->passphrase, passphrase, sizeof(th->passphrase));
3343 return TETHERING_ERROR_NONE;
3348 * @brief Gets the passphrase for Wi-Fi AP.
3350 * @privlevel platform
3351 * @privilege http://tizen.org/privilege/tethering.admin
3352 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3353 * @remarks @a passphrase must be released with free() by you.
3354 * @param[in] tethering The handle of tethering
3355 * @param[out] passphrase The passphrase
3356 * @return 0 on success, otherwise negative error value.
3357 * @retval #TETHERING_ERROR_NONE Successful
3358 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3359 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3360 * @see tethering_wifi_ap_set_passphrase()
3362 API int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase)
3364 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3366 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3367 "parameter(tethering) is NULL\n");
3368 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3369 "parameter(passphrase) is NULL\n");
3371 __tethering_h *th = (__tethering_h *)tethering;
3373 *passphrase = g_strdup(th->passphrase);
3374 if (*passphrase == NULL) {
3375 ERR("strdup is failed\n");
3376 return TETHERING_ERROR_OUT_OF_MEMORY;
3379 return TETHERING_ERROR_NONE;
3384 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP.
3386 * @privlevel platform
3387 * @privilege http://tizen.org/privilege/tethering.admin
3388 * @remarks Connected devices via MobileAP will be disconnected when the settings are reloaded
3389 * @param[in] tethering The handle of tethering
3390 * @param[in] callback The callback function to invoke
3391 * @param[in] user_data The user data to be passed to the callback function
3392 * @return 0 on success, otherwise negative error value.
3393 * @retval #TETHERING_ERROR_NONE Successful
3394 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3395 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3397 API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data)
3400 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3402 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3403 "parameter(tethering) is NULL\n");
3404 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3405 "parameter(callback) is NULL\n");
3407 __tethering_h *th = (__tethering_h *)tethering;
3408 _softap_settings_t set = {"", "", 0, false};
3409 GDBusProxy *proxy = th->client_bus_proxy;
3414 if (th->ap_settings_reloaded_cb) {
3415 ERR("Operation in progress\n");
3416 return TETHERING_ERROR_OPERATION_FAILED;
3419 ret = __prepare_wifi_ap_settings(tethering, &set);
3420 if (ret != TETHERING_ERROR_NONE) {
3421 ERR("softap settings initialization failed\n");
3422 return TETHERING_ERROR_OPERATION_FAILED;
3425 th->ap_settings_reloaded_cb = callback;
3426 th->ap_settings_reloaded_user_data = user_data;
3428 g_dbus_proxy_call(proxy, "reload_wifi_ap_settings",
3429 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
3430 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3431 (GAsyncReadyCallback) __ap_settings_reloaded_cb, (gpointer)tethering);
3433 return TETHERING_ERROR_NONE;