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 bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1330 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1333 case TETHERING_WIFI_MODE_TYPE_B:
1334 *buf = g_strdup("b");
1336 case TETHERING_WIFI_MODE_TYPE_G:
1337 *buf = g_strdup("g");
1339 case TETHERING_WIFI_MODE_TYPE_A:
1340 *buf = g_strdup("a");
1342 case TETHERING_WIFI_MODE_TYPE_AD:
1343 *buf = g_strdup("ad");
1346 ERR("Not supported type : %d\n", type);
1352 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1356 __tethering_h *th = (__tethering_h *)tethering;
1357 tethering_error_e ret = TETHERING_ERROR_NONE;
1360 if (th == NULL || set == NULL) {
1361 ERR("null parameter\n-\n");
1362 return TETHERING_ERROR_INVALID_PARAMETER;
1365 if (th->ssid == NULL)
1366 __get_common_ssid(set->ssid, sizeof(set->ssid));
1368 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1370 ret = __get_security_type(&set->sec_type);
1371 if (ret != TETHERING_ERROR_NONE)
1372 set->sec_type = th->sec_type;
1374 ret = __get_visible(&set->visibility);
1375 if (ret != TETHERING_ERROR_NONE)
1376 set->visibility = th->visibility;
1378 set->channel = th->channel;
1380 __get_wifi_mode_type (th->mode_type, &ptr);
1382 g_strlcpy(set->mode, "", sizeof(set->mode));
1384 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1388 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1389 g_strlcpy(set->key, "", sizeof(set->key));
1391 GDBusProxy *proxy = th->client_bus_proxy;
1392 GVariant *parameters;
1393 GError *error = NULL;
1394 char *passphrase = NULL;
1395 unsigned int len = 0;
1397 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1398 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1401 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1403 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1404 ret = TETHERING_ERROR_PERMISSION_DENIED;
1406 ret = TETHERING_ERROR_OPERATION_FAILED;
1408 g_error_free(error);
1412 if (parameters != NULL) {
1413 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
1414 g_variant_unref(parameters);
1417 g_strlcpy(set->key, passphrase, sizeof(set->key));
1420 return TETHERING_ERROR_NONE;
1423 static int __prepare_wifi_ap_settings(tethering_h tethering, _softap_settings_t *set)
1427 __tethering_h *th = (__tethering_h *)tethering;
1429 if (th == NULL || set == NULL) {
1430 ERR("null parameter\n");
1431 return TETHERING_ERROR_INVALID_PARAMETER;
1434 g_strlcpy(set->ssid, th->ap_ssid, sizeof(set->ssid));
1435 set->sec_type = th->sec_type;
1436 set->visibility = th->visibility;
1438 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
1439 g_strlcpy(set->key, "", sizeof(set->key));
1441 g_strlcpy(set->key, th->passphrase, sizeof(set->key));
1444 return TETHERING_ERROR_NONE;
1447 static bool __check_precondition(tethering_type_e type)
1450 int cellular_state = 0;
1453 /* data network through cellular */
1454 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1455 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1456 ERR("Data Network can be connected later");
1460 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1461 if (dnet_state > VCONFKEY_DNET_OFF) {
1462 ERR("Data Network is connected");
1466 /* data network through wifi */
1467 if (type != TETHERING_TYPE_WIFI) {
1468 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1469 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1470 ERR("Wi-Fi is connected!");
1475 ERR("Network is not available!");
1481 * @brief Creates the handle of tethering.
1483 * @privlevel platform
1484 * @privilege http://tizen.org/privilege/tethering.admin
1485 * @remarks The @a tethering must be released tethering_destroy() by you.
1486 * @param[out] tethering A handle of a new mobile ap handle on success
1487 * @return 0 on success, otherwise a negative error value.
1488 * @retval #TETHERING_ERROR_NONE Successful
1489 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1490 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1491 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1492 * @see tethering_destroy()
1494 API int tethering_create(tethering_h *tethering)
1496 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1497 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1498 "parameter(tethering) is NULL\n");
1501 __tethering_h *th = NULL;
1502 GError *error = NULL;
1503 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1505 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1507 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1508 "malloc is failed\n");
1509 memset(th, 0x00, sizeof(__tethering_h));
1510 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1511 th->visibility = true;
1513 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1515 if (__generate_initial_passphrase(th->passphrase,
1516 sizeof(th->passphrase)) == 0) {
1517 ERR("random passphrase generation failed\n");
1519 return TETHERING_ERROR_OPERATION_FAILED;
1522 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1523 ERR("common ssid get failed\n");
1525 return TETHERING_ERROR_OPERATION_FAILED;
1528 th->ap_ssid = g_strdup(ssid);
1529 if (th->ap_ssid == NULL) {
1530 ERR("g_strdup failed\n");
1532 return TETHERING_ERROR_OPERATION_FAILED;
1535 #if !GLIB_CHECK_VERSION(2, 36, 0)
1538 GCancellable *cancellable = g_cancellable_new();
1539 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1541 ERR("Couldn't connect to the System bus[%s]", error->message);
1542 g_error_free(error);
1543 g_cancellable_cancel(cancellable);
1544 g_object_unref(cancellable);
1545 g_free(th->ap_ssid);
1547 return TETHERING_ERROR_OPERATION_FAILED;
1549 th->cancellable = cancellable;
1551 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_NONE,
1552 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1553 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1554 if (!th->client_bus_proxy) {
1555 ERR("Couldn't create the proxy object because of %s\n", error->message);
1556 g_cancellable_cancel(th->cancellable);
1557 g_object_unref(th->cancellable);
1558 g_object_unref(th->client_bus);
1559 g_free(th->ap_ssid);
1561 return TETHERING_ERROR_OPERATION_FAILED;
1564 __connect_signals((tethering_h)th);
1566 *tethering = (tethering_h)th;
1567 DBG("Tethering Handle : 0x%X\n", th);
1569 return TETHERING_ERROR_NONE;
1574 * @brief Destroys the handle of tethering.
1576 * @privlevel platform
1577 * @privilege http://tizen.org/privilege/tethering.admin
1578 * @param[in] tethering The handle of tethering
1579 * @return 0 on success, otherwise a negative error value.
1580 * @retval #TETHERING_ERROR_NONE Successful
1581 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1582 * @see tethering_create()
1584 API int tethering_destroy(tethering_h tethering)
1587 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1588 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1589 "parameter(tethering) is NULL\n");
1591 __tethering_h *th = (__tethering_h *)tethering;
1593 DBG("Tethering Handle : 0x%X\n", th);
1594 __disconnect_signals(tethering);
1601 g_object_unref(th->cancellable);
1602 g_object_unref(th->client_bus_proxy);
1603 g_object_unref(th->client_bus);
1604 memset(th, 0x00, sizeof(__tethering_h));
1608 return TETHERING_ERROR_NONE;
1613 * @brief Enables the tethering, asynchronously.
1615 * @privlevel platform
1616 * @privilege http://tizen.org/privilege/tethering.admin
1617 * @param[in] tethering The handle of tethering
1618 * @param[in] type The type of tethering
1619 * @return 0 on success, otherwise negative error value.
1620 * @retval #TETHERING_ERROR_NONE Successful
1621 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1622 * @post tethering_enabled_cb() will be invoked.
1623 * @see tethering_is_enabled()
1624 * @see tethering_disable()
1626 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1628 DBG("+ type : %d\n", type);
1629 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1630 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1631 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1632 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1634 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1635 "parameter(tethering) is NULL\n");
1637 tethering_error_e ret = TETHERING_ERROR_NONE;
1638 __tethering_h *th = (__tethering_h *)tethering;
1639 GDBusProxy *proxy = th->client_bus_proxy;
1640 GDBusConnection *connection = th->client_bus;
1642 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1644 if (type != TETHERING_TYPE_RESERVED
1645 && __check_precondition(type) == FALSE) {
1647 return TETHERING_ERROR_OPERATION_FAILED;
1651 case TETHERING_TYPE_USB:
1652 g_dbus_connection_signal_unsubscribe(connection,
1653 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1655 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1656 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1657 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1660 case TETHERING_TYPE_WIFI: {
1661 _softap_settings_t set = {"", "", "", 0, false};
1663 ret = __prepare_wifi_settings(tethering, &set);
1664 if (ret != TETHERING_ERROR_NONE) {
1665 ERR("softap settings initialization failed\n");
1667 return TETHERING_ERROR_OPERATION_FAILED;
1669 g_dbus_connection_signal_unsubscribe(connection,
1670 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1672 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1673 g_variant_new("(sssiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.sec_type),
1674 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1675 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1679 case TETHERING_TYPE_BT:
1680 g_dbus_connection_signal_unsubscribe(connection,
1681 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1683 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1684 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1685 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1689 case TETHERING_TYPE_RESERVED: {
1690 _softap_settings_t set = {"", "", "", 0, false};
1692 ret = __prepare_wifi_ap_settings(tethering, &set);
1693 if (ret != TETHERING_ERROR_NONE) {
1694 ERR("softap settings initialization failed\n");
1695 return TETHERING_ERROR_OPERATION_FAILED;
1698 g_dbus_connection_signal_unsubscribe(connection,
1699 sigs[E_SIGNAL_WIFI_AP_ON].sig_id);
1701 g_dbus_proxy_call(proxy, "enable_wifi_ap",
1702 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1703 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_ap_enabled_cfm_cb, (gpointer)tethering);
1706 case TETHERING_TYPE_ALL: {
1707 _softap_settings_t set = {"", "", "", 0, false};
1709 ret = __prepare_wifi_settings(tethering, &set);
1710 if (ret != TETHERING_ERROR_NONE) {
1711 ERR("softap settings initialization failed\n");
1712 return TETHERING_ERROR_OPERATION_FAILED;
1715 /* TETHERING_TYPE_USB */
1716 g_dbus_connection_signal_unsubscribe(connection,
1717 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1719 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1720 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1721 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1723 /* TETHERING_TYPE_WIFI */
1724 g_dbus_connection_signal_unsubscribe(connection,
1725 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1727 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1728 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1729 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1730 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1732 /* TETHERING_TYPE_BT */
1733 g_dbus_connection_signal_unsubscribe(connection,
1734 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1736 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1737 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1738 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1742 ERR("Unknown type : %d\n", type);
1744 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1747 return TETHERING_ERROR_INVALID_PARAMETER;
1750 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1752 return TETHERING_ERROR_NONE;
1757 * @brief Disables the tethering, asynchronously.
1759 * @privlevel platform
1760 * @privilege http://tizen.org/privilege/tethering.admin
1761 * @param[in] tethering The handle of tethering
1762 * @param[in] type The type of tethering
1763 * @return 0 on success, otherwise negative error value.
1764 * @retval #TETHERING_ERROR_NONE Successful
1765 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1766 * @post tethering_disabled_cb() will be invoked.
1767 * @see tethering_is_enabled()
1768 * @see tethering_enable()
1770 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1772 DBG("+ type : %d\n", type);
1773 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1774 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1775 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1777 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1778 "parameter(tethering) is NULL\n");
1780 __tethering_h *th = (__tethering_h *)tethering;
1781 GDBusProxy *proxy = th->client_bus_proxy;
1782 GDBusConnection *connection = th->client_bus;
1785 case TETHERING_TYPE_USB:
1786 g_dbus_connection_signal_unsubscribe(connection,
1787 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1789 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1790 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1791 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1795 case TETHERING_TYPE_WIFI:
1797 g_dbus_connection_signal_unsubscribe(connection,
1798 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1800 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1801 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1802 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1805 case TETHERING_TYPE_BT:
1807 g_dbus_connection_signal_unsubscribe(connection,
1808 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1810 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1811 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1812 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1815 case TETHERING_TYPE_RESERVED:
1816 g_dbus_connection_signal_unsubscribe(connection,
1817 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id);
1819 g_dbus_proxy_call(proxy, "disable_wifi_ap",
1820 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1821 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1824 case TETHERING_TYPE_ALL:
1825 g_dbus_connection_signal_unsubscribe(connection,
1826 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1828 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1829 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1830 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1832 g_dbus_connection_signal_unsubscribe(connection,
1833 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1835 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1836 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1837 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1839 g_dbus_connection_signal_unsubscribe(connection,
1840 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1842 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1843 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1844 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1848 ERR("Not supported tethering type [%d]\n", type);
1850 return TETHERING_ERROR_INVALID_PARAMETER;
1853 return TETHERING_ERROR_NONE;
1858 * @brief Checks whetehr the tethering is enabled or not.
1860 * @privlevel platform
1861 * @privilege http://tizen.org/privilege/tethering.admin
1862 * @param[in] tethering The handle of tethering
1863 * @param[in] type The type of tethering
1864 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1866 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1869 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1871 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1873 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1877 case TETHERING_TYPE_USB:
1878 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1881 case TETHERING_TYPE_WIFI:
1882 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1885 case TETHERING_TYPE_BT:
1886 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1889 case TETHERING_TYPE_RESERVED:
1890 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
1894 ERR("Not supported type : %d\n", type);
1897 return is_on & vconf_type ? true : false;
1902 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1904 * @privlevel platform
1905 * @privilege http://tizen.org/privilege/tethering.admin
1906 * @remarks @a mac_address must be released with free() by you.
1907 * @param[in] tethering The handle of tethering
1908 * @param[in] type The type of tethering
1909 * @param[out] mac_address The MAC address
1910 * @return 0 on success, otherwise a negative error value.
1911 * @retval #TETHERING_ERROR_NONE Successful
1912 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1913 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1914 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1915 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1916 * @pre tethering must be enabled.
1917 * @see tethering_is_enabled()
1918 * @see tethering_enable()
1920 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1922 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1923 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1924 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1926 _retvm_if(tethering_is_enabled(tethering, type) == false,
1927 TETHERING_ERROR_NOT_ENABLED,
1928 "tethering type[%d] is not enabled\n", type);
1929 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1930 "parameter(tethering) is NULL\n");
1931 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1932 "parameter(mac_address) is NULL\n");
1936 char *macbuf = NULL;
1938 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1939 TETHERING_ERROR_OPERATION_FAILED,
1940 "getting interface name is failed\n");
1942 s = socket(AF_INET, SOCK_DGRAM, 0);
1943 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1944 "getting socket is failed\n");
1945 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1946 ERR("getting mac is failed\n");
1948 return TETHERING_ERROR_OPERATION_FAILED;
1952 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1953 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1954 "Not enough memory\n");
1955 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1956 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1957 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1958 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1959 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1960 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1961 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1963 *mac_address = macbuf;
1965 return TETHERING_ERROR_NONE;
1970 * @brief Gets the name of network interface. For example, usb0.
1972 * @privlevel platform
1973 * @privilege http://tizen.org/privilege/tethering.admin
1974 * @remarks @a interface_name must be released with free() by you.
1975 * @param[in] tethering The handle of tethering
1976 * @param[in] type The type of tethering
1977 * @param[out] interface_name The name of network interface
1978 * @return 0 on success, otherwise negative error value.
1979 * @retval #TETHERING_ERROR_NONE Successful
1980 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1981 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1982 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1983 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1984 * @pre tethering must be enabled.
1985 * @see tethering_is_enabled()
1986 * @see tethering_enable()
1988 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1990 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1991 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1992 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1994 _retvm_if(tethering_is_enabled(tethering, type) == false,
1995 TETHERING_ERROR_NOT_ENABLED,
1996 "tethering type[%d] is not enabled\n", type);
1997 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1998 "parameter(tethering) is NULL\n");
1999 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2000 "parameter(interface_name) is NULL\n");
2002 char intf[TETHERING_STR_INFO_LEN] = {0, };
2004 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2005 TETHERING_ERROR_OPERATION_FAILED,
2006 "getting interface name is failed\n");
2007 *interface_name = strdup(intf);
2008 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2009 "Not enough memory\n");
2011 return TETHERING_ERROR_NONE;
2016 * @brief Gets the local IP address.
2018 * @privlevel platform
2019 * @privilege http://tizen.org/privilege/tethering.admin
2020 * @remarks @a ip_address must be released with free() by you.
2021 * @param[in] tethering The handle of tethering
2022 * @param[in] type The type of tethering
2023 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2024 * @param[out] ip_address The local IP address
2025 * @return 0 on success, otherwise negative error value.
2026 * @retval #TETHERING_ERROR_NONE Successful
2027 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2028 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2029 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2030 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2031 * @pre tethering must be enabled.
2032 * @see tethering_is_enabled()
2033 * @see tethering_enable()
2035 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2038 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2039 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2040 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2042 _retvm_if(tethering_is_enabled(tethering, type) == false,
2043 TETHERING_ERROR_NOT_ENABLED,
2044 "tethering type[%d] is not enabled\n", type);
2045 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2046 "parameter(tethering) is NULL\n");
2047 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2048 "parameter(ip_address) is NULL\n");
2054 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2055 TETHERING_ERROR_OPERATION_FAILED,
2056 "getting interface name is failed\n");
2058 s = socket(AF_INET, SOCK_DGRAM, 0);
2059 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2060 "getting socket is failed\n");
2061 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2062 ERR("ioctl is failed\n");
2064 return TETHERING_ERROR_OPERATION_FAILED;
2068 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2069 *ip_address = strdup(ipbuf);
2070 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2071 "Not enough memory\n");
2073 return TETHERING_ERROR_NONE;
2078 * @brief Gets the Gateway address.
2080 * @privlevel platform
2081 * @privilege http://tizen.org/privilege/tethering.admin
2082 * @remarks @a gateway_address must be released with free() by you.
2083 * @param[in] tethering The handle of tethering
2084 * @param[in] type The type of tethering
2085 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2086 * @param[out] gateway_address The local IP address
2087 * @return 0 on success, otherwise negative error value.
2088 * @retval #TETHERING_ERROR_NONE Successful
2089 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2090 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2091 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2092 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2093 * @pre tethering must be enabled.
2094 * @see tethering_is_enabled()
2095 * @see tethering_enable()
2097 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2100 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2101 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2102 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2104 _retvm_if(tethering_is_enabled(tethering, type) == false,
2105 TETHERING_ERROR_NOT_ENABLED,
2106 "tethering type[%d] is not enabled\n", type);
2107 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2108 "parameter(tethering) is NULL\n");
2109 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2110 "parameter(gateway_address) is NULL\n");
2112 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2114 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2115 TETHERING_ERROR_OPERATION_FAILED,
2116 "getting gateway address is failed\n");
2118 *gateway_address = strdup(gateway_buf);
2120 return TETHERING_ERROR_NONE;
2125 * @brief Gets the Subnet Mask.
2127 * @privlevel platform
2128 * @privilege http://tizen.org/privilege/tethering.admin
2129 * @remarks @a subnet_mask must be released with free() by you.
2130 * @param[in] tethering The handle of tethering
2131 * @param[in] type The type of tethering
2132 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2133 * @param[out] subnet_mask The local IP address
2134 * @return 0 on success, otherwise negative error value.
2135 * @retval #TETHERING_ERROR_NONE Successful
2136 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2137 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2138 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2139 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2140 * @pre tethering must be enabled.
2141 * @see tethering_is_enabled()
2142 * @see tethering_enable()
2144 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2146 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2147 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2148 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2150 _retvm_if(tethering_is_enabled(tethering, type) == false,
2151 TETHERING_ERROR_NOT_ENABLED,
2152 "tethering is not enabled\n");
2153 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2154 "parameter(tethering) is NULL\n");
2155 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2156 "parameter(subnet_mask) is NULL\n");
2158 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2159 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2160 "Not enough memory\n");
2162 return TETHERING_ERROR_NONE;
2167 * @brief Gets the data usage.
2169 * @privlevel platform
2170 * @privilege http://tizen.org/privilege/tethering.admin
2171 * @param[in] tethering The handle of tethering
2172 * @param[out] usage The data usage
2173 * @return 0 on success, otherwise negative error value.
2174 * @retval #TETHERING_ERROR_NONE Successful
2175 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2176 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2177 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2178 * @pre tethering must be enabled.
2179 * @see tethering_is_enabled()
2180 * @see tethering_enable()
2182 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2184 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2186 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2187 "parameter(tethering) is NULL\n");
2188 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2189 "parameter(callback) is NULL\n");
2190 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2191 TETHERING_ERROR_NOT_ENABLED,
2192 "tethering is not enabled\n");
2194 __tethering_h *th = (__tethering_h *)tethering;
2195 GDBusProxy *proxy = th->client_bus_proxy;
2197 th->data_usage_cb = callback;
2198 th->data_usage_user_data = user_data;
2200 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2201 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2202 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2204 return TETHERING_ERROR_NONE;
2209 * @brief Gets the client which is connected by tethering "type".
2211 * @privlevel platform
2212 * @privilege http://tizen.org/privilege/tethering.admin
2213 * @param[in] tethering The handle of tethering
2214 * @param[in] type The type of tethering
2215 * @param[in] callback The callback function to invoke
2216 * @param[in] user_data The user data to be passed to the callback function
2217 * @retval #TETHERING_ERROR_NONE Successful
2218 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2219 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2220 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2221 * @pre tethering must be enabled.
2222 * @see tethering_is_enabled()
2223 * @see tethering_enable()
2225 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2228 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2229 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2230 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2232 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2233 "parameter(tethering) is NULL\n");
2234 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2235 "parameter(callback) is NULL\n");
2236 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2237 TETHERING_ERROR_NOT_ENABLED,
2238 "tethering is not enabled\n");
2240 mobile_ap_type_e interface;
2241 __tethering_h *th = (__tethering_h *)tethering;
2242 __tethering_client_h client = {0, };
2245 gchar *hostname = NULL;
2246 guint timestamp = 0;
2247 GError *error = NULL;
2248 GVariant *result = NULL;
2249 GVariantIter *outer_iter = NULL;
2250 GVariantIter *inner_iter = NULL;
2251 GVariant *station = NULL;
2252 GVariant *value = NULL;
2255 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2256 NULL, G_DBUS_CALL_FLAGS_NONE,
2257 -1, th->cancellable, &error);
2259 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2260 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2261 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2262 g_variant_get(station, "a{sv}", &inner_iter);
2263 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2264 if (g_strcmp0(key, "Type") == 0) {
2265 interface = g_variant_get_int32(value);
2266 if (interface == MOBILE_AP_TYPE_USB)
2267 client.interface = TETHERING_TYPE_USB;
2268 else if (interface == MOBILE_AP_TYPE_WIFI)
2269 client.interface = TETHERING_TYPE_WIFI;
2270 else if (interface == MOBILE_AP_TYPE_BT)
2271 client.interface = TETHERING_TYPE_BT;
2272 else if (interface == MOBILE_AP_TYPE_WIFI_AP)
2273 client.interface = TETHERING_TYPE_RESERVED;
2275 ERR("Invalid interface\n");
2277 g_variant_unref(value);
2280 DBG("interface is %d\n", client.interface);
2281 if (client.interface != type && (TETHERING_TYPE_ALL != type &&
2282 client.interface != TETHERING_TYPE_RESERVED)) {
2284 g_variant_unref(value);
2287 } else if (g_strcmp0(key, "IP") == 0) {
2288 g_variant_get(value, "s", &ip);
2289 SDBG("ip is %s\n", ip);
2290 g_strlcpy(client.ip, ip, sizeof(client.ip));
2291 } else if (g_strcmp0(key, "MAC") == 0) {
2292 g_variant_get(value, "s", &mac);
2293 SDBG("mac is %s\n", mac);
2294 g_strlcpy(client.mac, mac, sizeof(client.mac));
2295 } else if (g_strcmp0(key, "Name") == 0) {
2296 g_variant_get(value, "s", &hostname);
2297 SDBG("hsotname is %s\n", hostname);
2299 client.hostname = g_strdup(hostname);
2300 } else if (g_strcmp0(key, "Time") == 0) {
2301 timestamp = g_variant_get_int32(value);
2302 DBG("timestamp is %d\n", timestamp);
2303 client.tm = (time_t)timestamp;
2305 ERR("Key %s not required\n", key);
2311 g_variant_iter_free(inner_iter);
2312 if (callback((tethering_client_h)&client, user_data) == false) {
2313 DBG("iteration is stopped\n");
2314 g_free(client.hostname);
2315 g_variant_iter_free(outer_iter);
2316 g_variant_unref(station);
2317 g_variant_unref(result);
2319 return TETHERING_ERROR_OPERATION_FAILED;
2321 g_free(client.hostname);
2323 g_variant_iter_free(outer_iter);
2324 g_variant_unref(station);
2325 g_variant_unref(result);
2327 return TETHERING_ERROR_NONE;
2332 * @brief Registers the callback function called when tethering is enabled.
2334 * @privlevel platform
2335 * @privilege http://tizen.org/privilege/tethering.admin
2336 * @param[in] tethering The handle of tethering
2337 * @param[in] type The type of tethering
2338 * @param[in] callback The callback function to invoke
2339 * @param[in] user_data The user data to be passed to the callback function
2340 * @retval #TETHERING_ERROR_NONE Successful
2341 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2342 * @see tethering_unset_enabled_cb()
2344 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2346 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2347 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2348 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2350 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2351 "parameter(tethering) is NULL\n");
2352 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2353 "parameter(callback) is NULL\n");
2355 __tethering_h *th = (__tethering_h *)tethering;
2356 tethering_type_e ti;
2358 if (type != TETHERING_TYPE_ALL) {
2359 th->enabled_cb[type] = callback;
2360 th->enabled_user_data[type] = user_data;
2362 return TETHERING_ERROR_NONE;
2365 /* TETHERING_TYPE_ALL */
2366 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2367 th->enabled_cb[ti] = callback;
2368 th->enabled_user_data[ti] = user_data;
2371 return TETHERING_ERROR_NONE;
2376 * @brief Unregisters the callback function called when tethering is disabled.
2378 * @privlevel platform
2379 * @privilege http://tizen.org/privilege/tethering.admin
2380 * @param[in] tethering The handle of tethering
2381 * @param[in] type The type of tethering
2382 * @retval #TETHERING_ERROR_NONE Successful
2383 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2384 * @see tethering_set_enabled_cb()
2386 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2388 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2389 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2390 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2392 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2393 "parameter(tethering) is NULL\n");
2395 __tethering_h *th = (__tethering_h *)tethering;
2396 tethering_type_e ti;
2398 if (type != TETHERING_TYPE_ALL) {
2399 th->enabled_cb[type] = NULL;
2400 th->enabled_user_data[type] = NULL;
2402 return TETHERING_ERROR_NONE;
2405 /* TETHERING_TYPE_ALL */
2406 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2407 th->enabled_cb[ti] = NULL;
2408 th->enabled_user_data[ti] = NULL;
2411 return TETHERING_ERROR_NONE;
2416 * @brief Registers the callback function called when tethering is disabled.
2418 * @privlevel platform
2419 * @privilege http://tizen.org/privilege/tethering.admin
2420 * @param[in] tethering The handle of tethering
2421 * @param[in] type The type of tethering
2422 * @param[in] callback The callback function to invoke
2423 * @param[in] user_data The user data to be passed to the callback function
2424 * @retval #TETHERING_ERROR_NONE Successful
2425 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2426 * @see tethering_unset_disabled_cb()
2428 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2430 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2431 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2432 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2434 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2435 "parameter(tethering) is NULL\n");
2436 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2437 "parameter(callback) is NULL\n");
2439 __tethering_h *th = (__tethering_h *)tethering;
2440 tethering_type_e ti;
2442 if (type != TETHERING_TYPE_ALL) {
2443 th->disabled_cb[type] = callback;
2444 th->disabled_user_data[type] = user_data;
2446 return TETHERING_ERROR_NONE;
2449 /* TETHERING_TYPE_ALL */
2450 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2451 th->disabled_cb[ti] = callback;
2452 th->disabled_user_data[ti] = user_data;
2455 return TETHERING_ERROR_NONE;
2460 * @brief Unregisters the callback function called when tethering is disabled.
2462 * @privlevel platform
2463 * @privilege http://tizen.org/privilege/tethering.admin
2464 * @param[in] tethering The handle of tethering
2465 * @param[in] type The type of tethering
2466 * @retval #TETHERING_ERROR_NONE Successful
2467 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2468 * @see tethering_set_disabled_cb()
2470 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2472 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2473 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2474 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2476 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2477 "parameter(tethering) is NULL\n");
2479 __tethering_h *th = (__tethering_h *)tethering;
2480 tethering_type_e ti;
2482 if (type != TETHERING_TYPE_ALL) {
2483 th->disabled_cb[type] = NULL;
2484 th->disabled_user_data[type] = NULL;
2486 return TETHERING_ERROR_NONE;
2489 /* TETHERING_TYPE_ALL */
2490 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2491 th->disabled_cb[ti] = NULL;
2492 th->disabled_user_data[ti] = NULL;
2495 return TETHERING_ERROR_NONE;
2500 * @brief Registers the callback function called when the state of connection is changed.
2502 * @privlevel platform
2503 * @privilege http://tizen.org/privilege/tethering.admin
2504 * @param[in] tethering The handle of tethering
2505 * @param[in] type The type of tethering
2506 * @param[in] callback The callback function to invoke
2507 * @param[in] user_data The user data to be passed to the callback function
2508 * @retval #TETHERING_ERROR_NONE Successful
2509 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2510 * @see tethering_unset_connection_state_changed_cb_cb()
2512 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2514 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2515 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2516 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2518 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2519 "parameter(tethering) is NULL\n");
2520 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2521 "parameter(callback) is NULL\n");
2523 __tethering_h *th = (__tethering_h *)tethering;
2524 tethering_type_e ti;
2526 if (type != TETHERING_TYPE_ALL) {
2527 th->changed_cb[type] = callback;
2528 th->changed_user_data[type] = user_data;
2530 return TETHERING_ERROR_NONE;
2533 /* TETHERING_TYPE_ALL */
2534 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2535 th->changed_cb[ti] = callback;
2536 th->changed_user_data[ti] = user_data;
2539 return TETHERING_ERROR_NONE;
2544 * @brief Unregisters the callback function called when the state of connection is changed.
2546 * @privlevel platform
2547 * @privilege http://tizen.org/privilege/tethering.admin
2548 * @param[in] tethering The handle of tethering
2549 * @param[in] type The type of tethering
2550 * @retval #TETHERING_ERROR_NONE Successful
2551 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2552 * @see tethering_set_connection_state_changed_cb()
2554 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2556 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2557 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2558 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2560 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2561 "parameter(tethering) is NULL\n");
2563 __tethering_h *th = (__tethering_h *)tethering;
2564 tethering_type_e ti;
2566 if (type != TETHERING_TYPE_ALL) {
2567 th->changed_cb[type] = NULL;
2568 th->changed_user_data[type] = NULL;
2570 return TETHERING_ERROR_NONE;
2573 /* TETHERING_TYPE_ALL */
2574 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2575 th->changed_cb[ti] = NULL;
2576 th->changed_user_data[ti] = NULL;
2579 return TETHERING_ERROR_NONE;
2584 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2586 * @privlevel platform
2587 * @privilege http://tizen.org/privilege/tethering.admin
2588 * @param[in] tethering The handle of tethering
2589 * @param[in] callback The callback function to invoke
2590 * @param[in] user_data The user data to be passed to the callback function
2591 * @retval #TETHERING_ERROR_NONE Successful
2592 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2593 * @see tethering_wifi_unset_security_type_changed_cb()
2595 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2597 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2599 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2600 "parameter(tethering) is NULL\n");
2601 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2602 "parameter(callback) is NULL\n");
2604 __tethering_h *th = (__tethering_h *)tethering;
2606 th->security_type_changed_cb = callback;
2607 th->security_type_user_data = user_data;
2609 return TETHERING_ERROR_NONE;
2615 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2617 * @privlevel platform
2618 * @privilege http://tizen.org/privilege/tethering.admin
2619 * @param[in] tethering The handle of tethering
2620 * @param[in] type The type of tethering
2621 * @retval #TETHERING_ERROR_NONE Successful
2622 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2623 * @see tethering_wifi_set_security_type_changed_cb()
2625 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2627 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2629 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2630 "parameter(tethering) is NULL\n");
2632 __tethering_h *th = (__tethering_h *)tethering;
2634 th->security_type_changed_cb = NULL;
2635 th->security_type_user_data = NULL;
2637 return TETHERING_ERROR_NONE;
2642 * @brief Registers the callback function called when the visibility of SSID is changed.
2644 * @privlevel platform
2645 * @privilege http://tizen.org/privilege/tethering.admin
2646 * @param[in] tethering The handle of tethering
2647 * @param[in] callback The callback function to invoke
2648 * @param[in] user_data The user data to be passed to the callback function
2649 * @retval #TETHERING_ERROR_NONE Successful
2650 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2651 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2653 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2655 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2657 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2658 "parameter(tethering) is NULL\n");
2659 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2660 "parameter(callback) is NULL\n");
2662 __tethering_h *th = (__tethering_h *)tethering;
2664 th->ssid_visibility_changed_cb = callback;
2665 th->ssid_visibility_user_data = user_data;
2667 return TETHERING_ERROR_NONE;
2672 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2674 * @privlevel platform
2675 * @privilege http://tizen.org/privilege/tethering.admin
2676 * @param[in] tethering The handle of tethering
2677 * @retval #TETHERING_ERROR_NONE Successful
2678 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2679 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2681 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2683 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2685 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2686 "parameter(tethering) is NULL\n");
2688 __tethering_h *th = (__tethering_h *)tethering;
2690 th->ssid_visibility_changed_cb = NULL;
2691 th->ssid_visibility_user_data = NULL;
2693 return TETHERING_ERROR_NONE;
2698 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2700 * @privlevel platform
2701 * @privilege http://tizen.org/privilege/tethering.admin
2702 * @param[in] tethering The handle of tethering
2703 * @param[in] callback The callback function to invoke
2704 * @param[in] user_data The user data to be passed to the callback function
2705 * @retval #TETHERING_ERROR_NONE Successful
2706 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2707 * @see tethering_wifi_unset_passphrase_changed_cb()
2709 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2711 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2713 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2714 "parameter(tethering) is NULL\n");
2715 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2716 "parameter(callback) is NULL\n");
2718 __tethering_h *th = (__tethering_h *)tethering;
2720 th->passphrase_changed_cb = callback;
2721 th->passphrase_user_data = user_data;
2723 return TETHERING_ERROR_NONE;
2728 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2730 * @privlevel platform
2731 * @privilege http://tizen.org/privilege/tethering.admin
2732 * @param[in] tethering The handle of tethering
2733 * @retval #TETHERING_ERROR_NONE Successful
2734 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2735 * @see tethering_wifi_set_passphrase_changed_cb()
2737 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2739 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2741 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2742 "parameter(tethering) is NULL\n");
2744 __tethering_h *th = (__tethering_h *)tethering;
2746 th->passphrase_changed_cb = NULL;
2747 th->passphrase_user_data = NULL;
2749 return TETHERING_ERROR_NONE;
2754 * @brief Sets the security type of Wi-Fi tethering.
2756 * @privlevel platform
2757 * @privilege http://tizen.org/privilege/tethering.admin
2758 * @remarks This change is applied next time Wi-Fi tethering is enabled
2759 * @param[in] tethering The handle of tethering
2760 * @param[in] type The security type
2761 * @return 0 on success, otherwise negative error value.
2762 * @retval #TETHERING_ERROR_NONE Successful
2763 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2764 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2765 * @see tethering_wifi_get_security_type()
2767 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2769 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2771 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2772 "parameter(tethering) is NULL\n");
2774 __tethering_h *th = (__tethering_h *)tethering;
2775 tethering_error_e ret = TETHERING_ERROR_NONE;
2777 ret = __set_security_type(type);
2778 if (ret == TETHERING_ERROR_NONE) {
2780 __send_dbus_signal(th->client_bus,
2781 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2782 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2783 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2784 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2791 * @brief Gets the security type of Wi-Fi tethering.
2793 * @privlevel platform
2794 * @privilege http://tizen.org/privilege/tethering.admin
2795 * @param[in] tethering The handle of tethering
2796 * @param[out] type The security type
2797 * @return 0 on success, otherwise negative error value.
2798 * @retval #TETHERING_ERROR_NONE Successful
2799 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2800 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2801 * @see tethering_wifi_set_security_type()
2803 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2805 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2807 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2808 "parameter(type) is NULL\n");
2810 return __get_security_type(type);
2815 * @brief Sets the SSID (service set identifier).
2817 * @privlevel platform
2818 * @privilege http://tizen.org/privilege/tethering.admin
2819 * @details If SSID is not set, Device name is used as SSID
2820 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2821 * @param[in] tethering The handle of tethering
2822 * @param[out] ssid The SSID
2823 * @return 0 on success, otherwise negative error value.
2824 * @retval #TETHERING_ERROR_NONE Successful
2825 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2826 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2828 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2830 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2832 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2833 "parameter(tethering) is NULL\n");
2834 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2835 "parameter(ssid) is NULL\n");
2837 __tethering_h *th = (__tethering_h *)tethering;
2838 char *p_ssid = NULL;
2841 ssid_len = strlen(ssid);
2842 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2843 ERR("parameter(ssid) is too long");
2844 return TETHERING_ERROR_INVALID_PARAMETER;
2847 p_ssid = strdup(ssid);
2848 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2849 "strdup is failed\n");
2855 return TETHERING_ERROR_NONE;
2860 * @brief Gets the SSID (service set identifier).
2862 * @privlevel platform
2863 * @privilege http://tizen.org/privilege/tethering.admin
2864 * @remarks @a ssid must be released with free() by you.
2865 * @param[in] tethering The handle of tethering
2866 * @param[out] ssid The SSID
2867 * @return 0 on success, otherwise negative error value.
2868 * @retval #TETHERING_ERROR_NONE Successful
2869 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2870 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2871 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2873 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2875 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2877 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2878 "parameter(tethering) is NULL\n");
2879 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2880 "parameter(ssid) is NULL\n");
2883 __tethering_h *th = (__tethering_h *)tethering;
2884 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2886 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2887 if (th->ssid != NULL) {
2888 DBG("Private SSID is set\n");
2889 *ssid = strdup(th->ssid);
2891 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2892 val, sizeof(val)) == false) {
2893 return TETHERING_ERROR_OPERATION_FAILED;
2895 *ssid = strdup(val);
2898 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2899 val, sizeof(val)) == false) {
2900 return TETHERING_ERROR_OPERATION_FAILED;
2902 *ssid = strdup(val);
2905 if (*ssid == NULL) {
2906 ERR("strdup is failed\n");
2907 return TETHERING_ERROR_OUT_OF_MEMORY;
2910 return TETHERING_ERROR_NONE;
2915 * @brief Sets the visibility of SSID(service set identifier).
2917 * @privlevel platform
2918 * @privilege http://tizen.org/privilege/tethering.admin
2919 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2920 * @remarks This change is applied next time Wi-Fi tethering is enabled
2921 * @param[in] tethering The handle of tethering
2922 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2923 * @return 0 on success, otherwise negative error value.
2924 * @retval #TETHERING_ERROR_NONE Successful
2925 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2926 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2927 * @see tethering_wifi_get_ssid_visibility()
2929 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2931 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2933 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2934 "parameter(tethering) is NULL\n");
2936 __tethering_h *th = (__tethering_h *)tethering;
2937 tethering_error_e ret = TETHERING_ERROR_NONE;
2939 ret = __set_visible(visible);
2940 if (ret == TETHERING_ERROR_NONE) {
2942 __send_dbus_signal(th->client_bus,
2943 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2944 visible ? SIGNAL_MSG_SSID_VISIBLE :
2945 SIGNAL_MSG_SSID_HIDE);
2952 * @brief Gets the visibility of SSID(service set identifier).
2954 * @privlevel platform
2955 * @privilege http://tizen.org/privilege/tethering.admin
2956 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2957 * @param[in] tethering The handle of tethering
2958 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2959 * @return 0 on success, otherwise negative error value.
2960 * @retval #TETHERING_ERROR_NONE Successful
2961 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2962 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2963 * @see tethering_wifi_set_ssid_visibility()
2965 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2967 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2969 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2970 "parameter(visible) is NULL\n");
2972 return __get_visible(visible);
2977 * @brief Sets the passphrase.
2979 * @privlevel platform
2980 * @privilege http://tizen.org/privilege/tethering.admin
2981 * @remarks This change is applied next time Wi-Fi tethering is enabled
2982 * @param[in] tethering The handle of tethering
2983 * @param[in] passphrase The passphrase
2984 * @return 0 on success, otherwise negative error value.
2985 * @retval #TETHERING_ERROR_NONE Successful
2986 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2987 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2988 * @see tethering_wifi_get_passphrase()
2990 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2992 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2994 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2995 "parameter(tethering) is NULL\n");
2996 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2997 "parameter(passphrase) is NULL\n");
2999 __tethering_h *th = (__tethering_h *)tethering;
3000 GDBusProxy *proxy = th->client_bus_proxy;
3001 GVariant *parameters;
3002 GError *error = NULL;
3003 int passphrase_len = 0;
3007 passphrase_len = strlen(passphrase);
3008 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3009 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3010 ERR("parameter(passphrase) is too short or long\n");
3011 return TETHERING_ERROR_INVALID_PARAMETER;
3014 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3015 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3018 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3020 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3021 ret = TETHERING_ERROR_PERMISSION_DENIED;
3023 ret = TETHERING_ERROR_OPERATION_FAILED;
3025 g_error_free(error);
3029 g_variant_get(parameters, "(u)", &ret);
3030 g_variant_unref(parameters);
3032 if (ret == TETHERING_ERROR_NONE) {
3033 __send_dbus_signal(th->client_bus,
3034 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3043 * @brief Gets the passphrase.
3045 * @privlevel platform
3046 * @privilege http://tizen.org/privilege/tethering.admin
3047 * @remarks @a passphrase must be released with free() by you.
3048 * @param[in] tethering The handle of tethering
3049 * @param[out] passphrase The passphrase
3050 * @return 0 on success, otherwise negative error value.
3051 * @retval #TETHERING_ERROR_NONE Successful
3052 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3053 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3054 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3055 * @see tethering_wifi_set_passphrase()
3057 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3059 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3061 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3062 "parameter(tethering) is NULL\n");
3063 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3064 "parameter(passphrase) is NULL\n");
3066 __tethering_h *th = (__tethering_h *)tethering;
3067 GDBusProxy *proxy = th->client_bus_proxy;
3068 GVariant *parameters;
3069 GError *error = NULL;
3070 unsigned int len = 0;
3071 tethering_error_e ret = TETHERING_ERROR_NONE;
3073 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3074 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3077 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3079 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3080 ret = TETHERING_ERROR_PERMISSION_DENIED;
3082 ret = TETHERING_ERROR_OPERATION_FAILED;
3084 g_error_free(error);
3088 if (parameters != NULL) {
3089 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3090 g_variant_unref(parameters);
3093 return TETHERING_ERROR_NONE;
3096 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3098 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3099 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3100 "parameter(tethering) is NULL\n");
3102 __tethering_h *th = (__tethering_h *)tethering;
3103 th->channel = channel;
3105 return TETHERING_ERROR_NONE;
3108 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3110 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3111 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3112 "parameter(tethering) is NULL\n");
3114 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3115 "parameter(channel) is NULL\n");
3117 __tethering_h *th = (__tethering_h *)tethering;
3118 *channel = th->channel;
3120 return TETHERING_ERROR_NONE;
3123 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3125 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3126 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3127 "parameter(tethering) is NULL\n");
3129 __tethering_h *th = (__tethering_h *)tethering;
3131 th->mode_type = type;
3133 return TETHERING_ERROR_NONE;
3136 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3138 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3139 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3140 "parameter(tethering) is NULL\n");
3141 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3142 "parameter(type) is NULL\n");
3144 __tethering_h *th = (__tethering_h *)tethering;
3145 *type = th->mode_type;
3147 return TETHERING_ERROR_NONE;
3153 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3155 * @privlevel platform
3156 * @privilege http://tizen.org/privilege/tethering.admin
3157 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3158 * @param[in] tethering The handle of tethering
3159 * @param[in] callback The callback function to invoke
3160 * @param[in] user_data The user data to be passed to the callback function
3161 * @return 0 on success, otherwise negative error value.
3162 * @retval #TETHERING_ERROR_NONE Successful
3163 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3164 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3166 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3169 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3171 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3172 "parameter(tethering) is NULL\n");
3173 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3174 "parameter(callback) is NULL\n");
3176 __tethering_h *th = (__tethering_h *)tethering;
3177 _softap_settings_t set = {"", "", "", 0, false};
3178 GDBusProxy *proxy = th->client_bus_proxy;
3183 if (th->settings_reloaded_cb) {
3184 ERR("Operation in progress\n");
3185 return TETHERING_ERROR_OPERATION_FAILED;
3188 ret = __prepare_wifi_settings(tethering, &set);
3189 if (ret != TETHERING_ERROR_NONE) {
3190 ERR("softap settings initialization failed\n");
3191 return TETHERING_ERROR_OPERATION_FAILED;
3194 th->settings_reloaded_cb = callback;
3195 th->settings_reloaded_user_data = user_data;
3197 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3198 g_variant_new("(sssiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.sec_type),
3199 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3200 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3202 return TETHERING_ERROR_NONE;
3207 * @brief Sets the security type of Wi-Fi AP.
3209 * @privlevel platform
3210 * @privilege http://tizen.org/privilege/tethering.admin
3211 * @details If security type is not set, WPA2_PSK is used
3212 * @param[in] tethering The handle of tethering
3213 * @param[in] type The security type
3214 * @return 0 on success, otherwise negative error value.
3215 * @retval #TETHERING_ERROR_NONE Successful
3216 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3217 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3218 * @see tethering_wifi_ap_get_security_type()
3220 API int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
3222 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3224 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3225 "parameter(tethering) is NULL\n");
3227 __tethering_h *th = (__tethering_h *)tethering;
3228 th->sec_type = type;
3229 return TETHERING_ERROR_NONE;
3234 * @brief Gets the security type of Wi-Fi AP.
3236 * @privlevel platform
3237 * @privilege http://tizen.org/privilege/tethering.admin
3238 * @details If security type is not set, WPA2_PSK is used
3239 * @param[in] tethering The handle of tethering
3240 * @param[out] type The security type
3241 * @return 0 on success, otherwise negative error value.
3242 * @retval #TETHERING_ERROR_NONE Successful
3243 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3244 * @see tethering_wifi_ap_set_security_type()
3246 API int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3248 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3250 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3251 "parameter(type) is NULL\n");
3253 __tethering_h *th = (__tethering_h *)tethering;
3255 *type = th->sec_type;
3256 return TETHERING_ERROR_NONE;
3261 * @brief Sets the SSID (service set identifier) for Wi-Fi AP. The SSID cannot exceed 32 bytes.
3263 * @privlevel platform
3264 * @privilege http://tizen.org/privilege/tethering.admin
3265 * @details If SSID is not set, Device name is used as SSID
3266 * @param[in] tethering The handle of tethering
3267 * @param[in] ssid The SSID
3268 * @return 0 on success, otherwise negative error value.
3269 * @retval #TETHERING_ERROR_NONE Successful
3270 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3271 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3273 API int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid)
3275 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3277 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3278 "parameter(tethering) is NULL\n");
3279 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3280 "parameter(ssid) is NULL\n");
3282 __tethering_h *th = (__tethering_h *)tethering;
3283 char *p_ssid = NULL;
3286 ssid_len = strlen(ssid);
3287 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3288 ERR("parameter(ssid) is too long");
3289 return TETHERING_ERROR_INVALID_PARAMETER;
3292 p_ssid = strdup(ssid);
3293 if (p_ssid == NULL) {
3294 ERR("strdup failed\n");
3295 return TETHERING_ERROR_OUT_OF_MEMORY;
3299 g_free(th->ap_ssid);
3300 th->ap_ssid = p_ssid;
3302 return TETHERING_ERROR_NONE;
3307 * @brief Gets the SSID (service set identifier) for Wi-Fi AP.
3309 * @privlevel platform
3310 * @privilege http://tizen.org/privilege/tethering.admin
3311 * @details If SSID is not set, Device name is used as SSID
3312 * @remarks @a ssid must be released with free() by you.
3313 * @param[in] tethering The handle of tethering
3314 * @param[out] ssid The SSID
3315 * @return 0 on success, otherwise negative error value.
3316 * @retval #TETHERING_ERROR_NONE Successful
3317 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3318 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3320 API int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid)
3322 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3324 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3325 "parameter(tethering) is NULL\n");
3326 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3327 "parameter(ssid) is NULL\n");
3329 __tethering_h *th = (__tethering_h *)tethering;
3331 *ssid = g_strdup(th->ap_ssid);
3332 if (*ssid == NULL) {
3333 ERR("strdup failed\n");
3334 return TETHERING_ERROR_OUT_OF_MEMORY;
3337 return TETHERING_ERROR_NONE;
3342 * @brief Sets the visibility of SSID(service set identifier) for Wi-Fi AP.
3344 * @privlevel platform
3345 * @privilege http://tizen.org/privilege/tethering.admin
3346 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3347 * @details by default visibility is set to true.
3348 * @remarks This change is applied next time Wi-Fi tethering is enabled
3349 * @param[in] tethering The handle of tethering
3350 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3351 * @return 0 on success, otherwise negative error value.
3352 * @retval #TETHERING_ERROR_NONE Successful
3353 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3354 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3355 * @see tethering_wifi_ap_get_ssid_visibility()
3357 API int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible)
3359 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3361 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3362 "parameter(tethering) is NULL\n");
3364 __tethering_h *th = (__tethering_h *)tethering;
3365 th->visibility = visible;
3366 return TETHERING_ERROR_NONE;
3371 * @brief Gets the visibility of SSID(service set identifier) for Wi-Fi AP.
3373 * @privlevel platform
3374 * @privilege http://tizen.org/privilege/tethering.admin
3375 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3376 * @details by default visibility is set to true.
3377 * @param[in] tethering The handle of tethering
3378 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3379 * @return 0 on success, otherwise negative error value.
3380 * @retval #TETHERING_ERROR_NONE Successful
3381 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3382 * @see tethering_wifi_ap_set_ssid_visibility()
3384 API int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible)
3386 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3388 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3389 "parameter(visible) is NULL\n");
3391 __tethering_h *th = (__tethering_h *)tethering;
3393 *visible = th->visibility;
3394 return TETHERING_ERROR_NONE;
3399 * @brief Sets the passphrase for Wi-Fi AP.
3401 * @privlevel platform
3402 * @privilege http://tizen.org/privilege/tethering.admin
3403 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3404 * @param[in] tethering The handle of tethering
3405 * @param[in] passphrase The passphrase
3406 * @return 0 on success, otherwise negative error value.
3407 * @retval #TETHERING_ERROR_NONE Successful
3408 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3409 * @see tethering_wifi_ap_get_passphrase()
3411 API int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase)
3413 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3415 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3416 "parameter(tethering) is NULL\n");
3417 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3418 "parameter(passphrase) is NULL\n");
3420 __tethering_h *th = (__tethering_h *)tethering;
3421 int passphrase_len = 0;
3423 passphrase_len = strlen(passphrase);
3425 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3426 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3427 ERR("parameter(passphrase) is too short or long\n");
3428 return TETHERING_ERROR_INVALID_PARAMETER;
3431 if (!g_strcmp0(passphrase, th->passphrase))
3432 return TETHERING_ERROR_NONE;
3434 g_strlcpy(th->passphrase, passphrase, sizeof(th->passphrase));
3435 return TETHERING_ERROR_NONE;
3440 * @brief Gets the passphrase for Wi-Fi AP.
3442 * @privlevel platform
3443 * @privilege http://tizen.org/privilege/tethering.admin
3444 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3445 * @remarks @a passphrase must be released with free() by you.
3446 * @param[in] tethering The handle of tethering
3447 * @param[out] passphrase The passphrase
3448 * @return 0 on success, otherwise negative error value.
3449 * @retval #TETHERING_ERROR_NONE Successful
3450 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3451 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3452 * @see tethering_wifi_ap_set_passphrase()
3454 API int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase)
3456 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3458 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3459 "parameter(tethering) is NULL\n");
3460 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3461 "parameter(passphrase) is NULL\n");
3463 __tethering_h *th = (__tethering_h *)tethering;
3465 *passphrase = g_strdup(th->passphrase);
3466 if (*passphrase == NULL) {
3467 ERR("strdup is failed\n");
3468 return TETHERING_ERROR_OUT_OF_MEMORY;
3471 return TETHERING_ERROR_NONE;
3476 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP.
3478 * @privlevel platform
3479 * @privilege http://tizen.org/privilege/tethering.admin
3480 * @remarks Connected devices via MobileAP will be disconnected when the settings are reloaded
3481 * @param[in] tethering The handle of tethering
3482 * @param[in] callback The callback function to invoke
3483 * @param[in] user_data The user data to be passed to the callback function
3484 * @return 0 on success, otherwise negative error value.
3485 * @retval #TETHERING_ERROR_NONE Successful
3486 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3487 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3489 API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data)
3492 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3494 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3495 "parameter(tethering) is NULL\n");
3496 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3497 "parameter(callback) is NULL\n");
3499 __tethering_h *th = (__tethering_h *)tethering;
3500 _softap_settings_t set = {"", "", "", 0, false};
3501 GDBusProxy *proxy = th->client_bus_proxy;
3506 if (th->ap_settings_reloaded_cb) {
3507 ERR("Operation in progress\n");
3508 return TETHERING_ERROR_OPERATION_FAILED;
3511 ret = __prepare_wifi_ap_settings(tethering, &set);
3512 if (ret != TETHERING_ERROR_NONE) {
3513 ERR("softap settings initialization failed\n");
3514 return TETHERING_ERROR_OPERATION_FAILED;
3517 th->ap_settings_reloaded_cb = callback;
3518 th->ap_settings_reloaded_user_data = user_data;
3520 g_dbus_proxy_call(proxy, "reload_wifi_ap_settings",
3521 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
3522 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3523 (GAsyncReadyCallback) __ap_settings_reloaded_cb, (gpointer)tethering);
3525 return TETHERING_ERROR_NONE;