2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
24 #include <arpa/inet.h>
26 #include <dbus/dbus.h>
29 #include <openssl/evp.h>
30 #include <openssl/sha.h>
31 #include <ckmc/ckmc-manager.h>
32 #include "tethering_private.h"
34 #define ALLOWED_LIST "/etc/hostapd.accept"
35 #define BLOCKED_LIST "/etc/hostapd.deny"
36 #define TEMP_LIST "/etc/hostapd_tmp"
37 #define MAC_ADDR_LEN 18
38 #define MAX_BUF_SIZE 80
40 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
41 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
42 GVariant *parameters, gpointer user_data);
44 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
45 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
46 GVariant *parameters, gpointer user_data);
48 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
49 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
50 GVariant *parameters, gpointer user_data);
52 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
53 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
54 GVariant *parameters, gpointer user_data);
56 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
57 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
58 GVariant *parameters, gpointer user_data);
60 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
61 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
62 GVariant *parameters, gpointer user_data);
64 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
65 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
66 GVariant *parameters, gpointer user_data);
68 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
69 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
70 GVariant *parameters, gpointer user_data);
72 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
73 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
74 GVariant *parameters, gpointer user_data);
76 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
77 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
78 GVariant *parameters, gpointer user_data);
80 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
81 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
82 GVariant *parameters, gpointer user_data);
84 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
85 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
86 GVariant *parameters, gpointer user_data);
88 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
89 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
90 GVariant *parameters, gpointer user_data);
92 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
93 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
94 GVariant *parameters, gpointer user_data);
96 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
97 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
98 GVariant *parameters, gpointer user_data);
100 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
101 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
102 GVariant *parameters, gpointer user_data);
104 static __tethering_sig_t sigs[] = {
105 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
106 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
107 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
108 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
109 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
110 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
111 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
112 {0, SIGNAL_NAME_WIFI_AP_ON, __handle_wifi_ap_on},
113 {0, SIGNAL_NAME_WIFI_AP_OFF, __handle_wifi_ap_off},
114 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
115 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
116 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
117 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
118 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
119 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
120 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp},
123 static int retry = 0;
125 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
127 if (conn == NULL || signal_name == NULL)
130 GVariant *message = NULL;
131 GError *error = NULL;
134 message = g_variant_new("(s)", arg);
136 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
137 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
139 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
142 g_variant_unref(message);
145 static bool __any_tethering_is_enabled(tethering_h tethering)
147 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
148 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
149 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
150 tethering_is_enabled(tethering, TETHERING_TYPE_RESERVED))
156 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
158 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
159 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) {
160 ERR("Invalid param\n");
161 return TETHERING_ERROR_INVALID_PARAMETER;
164 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
165 ERR("vconf_set_int is failed\n");
166 return TETHERING_ERROR_OPERATION_FAILED;
169 return TETHERING_ERROR_NONE;
172 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
174 if (security_type == NULL) {
175 ERR("Invalid param\n");
176 return TETHERING_ERROR_INVALID_PARAMETER;
179 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
180 (int *)security_type) < 0) {
181 ERR("vconf_get_int is failed\n");
182 return TETHERING_ERROR_OPERATION_FAILED;
185 return TETHERING_ERROR_NONE;
188 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
190 if (path == NULL || ssid == NULL || size == 0)
194 char *ptr_tmp = NULL;
196 ptr = vconf_get_str(path);
200 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
203 g_strlcpy(ssid, ptr, size);
209 static tethering_error_e __set_visible(const bool visible)
211 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
212 ERR("vconf_set_int is failed\n");
213 return TETHERING_ERROR_OPERATION_FAILED;
216 return TETHERING_ERROR_NONE;
219 static tethering_error_e __get_visible(bool *visible)
221 if (visible == NULL) {
222 ERR("Invalid param\n");
223 return TETHERING_ERROR_INVALID_PARAMETER;
228 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
229 ERR("vconf_get_int is failed\n");
230 return TETHERING_ERROR_OPERATION_FAILED;
237 return TETHERING_ERROR_NONE;
240 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
242 if (passphrase == NULL ||
243 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
246 guint32 rand_int = 0;
249 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
250 rand_int = g_random_int_range('a', 'z');
251 passphrase[index] = rand_int;
253 passphrase[index] = '\0';
258 static tethering_error_e __get_error(int agent_error)
260 tethering_error_e err = TETHERING_ERROR_NONE;
262 switch (agent_error) {
263 case MOBILE_AP_ERROR_NONE:
264 err = TETHERING_ERROR_NONE;
267 case MOBILE_AP_ERROR_RESOURCE:
268 err = TETHERING_ERROR_OUT_OF_MEMORY;
271 case MOBILE_AP_ERROR_INTERNAL:
272 err = TETHERING_ERROR_OPERATION_FAILED;
275 case MOBILE_AP_ERROR_INVALID_PARAM:
276 err = TETHERING_ERROR_INVALID_PARAMETER;
279 case MOBILE_AP_ERROR_ALREADY_ENABLED:
280 err = TETHERING_ERROR_OPERATION_FAILED;
283 case MOBILE_AP_ERROR_NOT_ENABLED:
284 err = TETHERING_ERROR_NOT_ENABLED;
287 case MOBILE_AP_ERROR_NET_OPEN:
288 err = TETHERING_ERROR_OPERATION_FAILED;
291 case MOBILE_AP_ERROR_NET_CLOSE:
292 err = TETHERING_ERROR_OPERATION_FAILED;
295 case MOBILE_AP_ERROR_DHCP:
296 err = TETHERING_ERROR_OPERATION_FAILED;
299 case MOBILE_AP_ERROR_IN_PROGRESS:
300 err = TETHERING_ERROR_OPERATION_FAILED;
303 case MOBILE_AP_ERROR_NOT_PERMITTED:
304 err = TETHERING_ERROR_NOT_PERMITTED;
307 case MOBILE_AP_ERROR_PERMISSION_DENIED:
308 err = TETHERING_ERROR_PERMISSION_DENIED;
312 ERR("Not defined error : %d\n", agent_error);
313 err = TETHERING_ERROR_OPERATION_FAILED;
320 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
321 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
322 GVariant *parameters, gpointer user_data)
326 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
328 __tethering_h *th = (__tethering_h *)user_data;
330 tethering_type_e type = 0;
331 mobile_ap_type_e ap_type = 0;
332 tethering_connection_state_changed_cb ccb = NULL;
333 __tethering_client_h client;
341 memset(&client, 0, sizeof(__tethering_client_h));
342 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
344 if (!g_strcmp0(buf, "DhcpConnected")) {
346 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
349 ERR("Unknown event [%s]\n", buf);
353 if (ap_type == MOBILE_AP_TYPE_USB)
354 type = TETHERING_TYPE_USB;
355 else if (ap_type == MOBILE_AP_TYPE_WIFI)
356 type = TETHERING_TYPE_WIFI;
357 else if (ap_type == MOBILE_AP_TYPE_BT)
358 type = TETHERING_TYPE_BT;
359 else if (ap_type == MOBILE_AP_TYPE_WIFI_AP) {
360 type = TETHERING_TYPE_RESERVED;
362 ERR("Not supported tethering type [%d]\n", ap_type);
366 ccb = th->changed_cb[type];
369 data = th->changed_user_data[type];
371 client.interface = type;
372 g_strlcpy(client.ip, ip, sizeof(client.ip));
373 g_strlcpy(client.mac, mac, sizeof(client.mac));
375 client.hostname = g_strdup(name);
376 client.tm = (time_t)timestamp;
378 ccb((tethering_client_h)&client, opened, data);
379 g_free(client.hostname);
388 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
389 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
390 GVariant *parameters, gpointer user_data)
394 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
396 __tethering_h *th = (__tethering_h *)user_data;
397 tethering_type_e type = 0;
398 tethering_disabled_cb dcb = NULL;
400 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
402 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
403 dcb = th->disabled_cb[type];
406 data = th->disabled_user_data[type];
408 dcb(TETHERING_ERROR_NONE, type, code, data);
414 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
415 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
416 GVariant *parameters, gpointer user_data)
420 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
422 __tethering_h *th = (__tethering_h *)user_data;
423 tethering_type_e type = TETHERING_TYPE_WIFI;
424 bool is_requested = false;
425 tethering_enabled_cb ecb = NULL;
428 ecb = th->enabled_cb[type];
431 data = th->enabled_user_data[type];
433 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
437 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
438 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
439 GVariant *parameters, gpointer user_data)
443 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
445 __tethering_h *th = (__tethering_h *)user_data;
446 tethering_type_e type = TETHERING_TYPE_WIFI;
447 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
448 tethering_disabled_cb dcb = NULL;
452 dcb = th->disabled_cb[type];
455 data = th->disabled_user_data[type];
456 g_variant_get(parameters, "(s)", &buf);
457 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
458 code = TETHERING_DISABLED_BY_WIFI_ON;
459 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
460 code = TETHERING_DISABLED_BY_TIMEOUT;
463 dcb(TETHERING_ERROR_NONE, type, code, data);
468 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
469 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
470 GVariant *parameters, gpointer user_data)
474 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
476 __tethering_h *th = (__tethering_h *)user_data;
477 tethering_type_e type = TETHERING_TYPE_USB;
478 bool is_requested = false;
479 tethering_enabled_cb ecb = NULL;
482 ecb = th->enabled_cb[type];
485 data = th->enabled_user_data[type];
487 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
491 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
492 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
493 GVariant *parameters, gpointer user_data)
497 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
499 __tethering_h *th = (__tethering_h *)user_data;
500 tethering_type_e type = TETHERING_TYPE_USB;
501 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
502 tethering_disabled_cb dcb = NULL;
506 dcb = th->disabled_cb[type];
509 data = th->disabled_user_data[type];
511 g_variant_get(parameters, "(s)", &buf);
512 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
513 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
515 dcb(TETHERING_ERROR_NONE, type, code, data);
520 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
521 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
522 GVariant *parameters, gpointer user_data)
526 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
528 __tethering_h *th = (__tethering_h *)user_data;
529 tethering_type_e type = TETHERING_TYPE_BT;
530 bool is_requested = false;
531 tethering_enabled_cb ecb = NULL;
534 ecb = th->enabled_cb[type];
537 data = th->enabled_user_data[type];
539 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
543 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
544 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
545 GVariant *parameters, gpointer user_data)
549 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
551 __tethering_h *th = (__tethering_h *)user_data;
552 tethering_type_e type = TETHERING_TYPE_BT;
553 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
554 tethering_disabled_cb dcb = NULL;
558 dcb = th->disabled_cb[type];
561 data = th->disabled_user_data[type];
562 g_variant_get(parameters, "(s)", &buf);
563 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
564 code = TETHERING_DISABLED_BY_BT_OFF;
565 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
566 code = TETHERING_DISABLED_BY_TIMEOUT;
568 dcb(TETHERING_ERROR_NONE, type, code, data);
574 static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name,
575 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
576 GVariant *parameters, gpointer user_data)
580 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
582 __tethering_h *th = (__tethering_h *)user_data;
583 tethering_type_e type = TETHERING_TYPE_RESERVED;
584 bool is_requested = false;
585 tethering_enabled_cb ecb = NULL;
588 ecb = th->enabled_cb[type];
591 data = th->enabled_user_data[type];
593 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
597 static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name,
598 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
599 GVariant *parameters, gpointer user_data)
603 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
605 __tethering_h *th = (__tethering_h *)user_data;
606 tethering_type_e type = TETHERING_TYPE_RESERVED;
607 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
608 tethering_disabled_cb dcb = NULL;
612 dcb = th->disabled_cb[type];
615 data = th->disabled_user_data[type];
616 g_variant_get(parameters, "(s)", &buf);
617 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
618 code = TETHERING_DISABLED_BY_WIFI_ON;
619 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
620 code = TETHERING_DISABLED_BY_TIMEOUT;
623 dcb(TETHERING_ERROR_NONE, type, code, data);
628 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
629 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
630 GVariant *parameters, gpointer user_data)
634 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
636 __tethering_h *th = (__tethering_h *)user_data;
637 tethering_type_e type = 0;
638 tethering_disabled_cb dcb = NULL;
640 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
642 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
643 dcb = th->disabled_cb[type];
646 data = th->disabled_user_data[type];
648 dcb(TETHERING_ERROR_NONE, type, code, data);
653 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
654 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
655 GVariant *parameters, gpointer user_data)
659 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
661 __tethering_h *th = (__tethering_h *)user_data;
662 tethering_type_e type = 0;
663 tethering_disabled_cb dcb = NULL;
665 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
667 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
668 dcb = th->disabled_cb[type];
671 data = th->disabled_user_data[type];
673 dcb(TETHERING_ERROR_NONE, type, code, data);
678 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
679 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
680 GVariant *parameters, gpointer user_data)
684 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
686 __tethering_h *th = (__tethering_h *)user_data;
687 tethering_type_e type = 0;
688 tethering_disabled_cb dcb = NULL;
690 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
692 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) {
693 dcb = th->disabled_cb[type];
696 data = th->disabled_user_data[type];
698 dcb(TETHERING_ERROR_NONE, type, code, data);
703 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
704 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
705 GVariant *parameters, gpointer user_data)
710 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
711 __tethering_h *th = (__tethering_h *)user_data;
713 tethering_wifi_security_type_changed_cb scb = NULL;
715 tethering_wifi_security_type_e security_type;
718 scb = th->security_type_changed_cb;
722 g_variant_get(parameters, "(s)", &buf);
723 data = th->security_type_user_data;
724 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
725 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
726 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
727 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
729 SERR("Unknown type : %s\n", buf);
734 scb(security_type, data);
739 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
740 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
741 GVariant *parameters, gpointer user_data)
745 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
746 __tethering_h *th = (__tethering_h *)user_data;
748 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
750 bool visible = false;
753 scb = th->ssid_visibility_changed_cb;
758 g_variant_get(parameters, "(s)", &buf);
759 data = th->ssid_visibility_user_data;
760 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
768 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
769 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
770 GVariant *parameters, gpointer user_data)
774 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
775 __tethering_h *th = (__tethering_h *)user_data;
777 tethering_wifi_passphrase_changed_cb pcb = NULL;
780 pcb = th->passphrase_changed_cb;
784 data = th->passphrase_user_data;
790 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
795 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
796 GError *g_error = NULL;
799 tethering_error_e error;
800 __tethering_h *th = (__tethering_h *)user_data;
801 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
802 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
804 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
806 ERR("DBus error [%s]\n", g_error->message);
807 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
808 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
809 g_error_free(g_error);
810 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
812 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
813 error = TETHERING_ERROR_PERMISSION_DENIED;
815 error = TETHERING_ERROR_OPERATION_FAILED;
816 g_error_free(g_error);
818 g_variant_get(g_var, "(u)", &info);
819 error = __get_error(info);
823 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
824 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
825 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
826 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
832 ecb(error, TETHERING_TYPE_WIFI, true, data);
833 g_variant_unref(g_var);
837 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
841 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
842 GError *g_error = NULL;
845 tethering_error_e error;
847 __tethering_h *th = (__tethering_h *)user_data;
848 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
849 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
851 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
853 ERR("DBus error [%s]\n", g_error->message);
854 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
855 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
856 g_error_free(g_error);
857 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
861 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
862 error = TETHERING_ERROR_PERMISSION_DENIED;
864 error = TETHERING_ERROR_OPERATION_FAILED;
865 g_error_free(g_error);
867 g_variant_get(g_var, "(u)", &info);
868 g_variant_unref(g_var);
869 error = __get_error(info);
873 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
874 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
875 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
876 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
883 ecb(error, TETHERING_TYPE_BT, true, data);
887 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
892 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
893 __tethering_h *th = (__tethering_h *)user_data;
894 GError *g_error = NULL;
897 tethering_error_e error;
898 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
899 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
901 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
903 ERR("DBus error [%s]\n", g_error->message);
904 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
905 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
906 g_error_free(g_error);
907 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
911 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
912 error = TETHERING_ERROR_PERMISSION_DENIED;
914 error = TETHERING_ERROR_OPERATION_FAILED;
915 g_error_free(g_error);
917 g_variant_get(g_var, "(u)", &info);
918 g_variant_unref(g_var);
919 error = __get_error(info);
923 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
924 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
925 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
926 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
933 ecb(error, TETHERING_TYPE_USB, true, data);
937 static void __wifi_ap_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
942 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
943 __tethering_h *th = (__tethering_h *)user_data;
944 GError *g_error = NULL;
947 tethering_error_e error;
948 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_RESERVED];
949 void *data = th->enabled_user_data[TETHERING_TYPE_RESERVED];
951 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
953 ERR("DBus error [%s]\n", g_error->message);
954 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
955 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
956 g_error_free(g_error);
957 tethering_enable((tethering_h)th, TETHERING_TYPE_RESERVED);
961 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
962 error = TETHERING_ERROR_PERMISSION_DENIED;
964 error = TETHERING_ERROR_OPERATION_FAILED;
965 g_error_free(g_error);
967 g_variant_get(g_var, "(u)", &info);
968 g_variant_unref(g_var);
969 error = __get_error(info);
973 sigs[E_SIGNAL_WIFI_AP_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
974 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_ON].name,
975 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
976 sigs[E_SIGNAL_WIFI_AP_ON].cb, (gpointer)th, NULL);
983 ecb(error, TETHERING_TYPE_RESERVED, true, data);
987 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
992 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
993 GError *g_error = NULL;
995 guint info, event_type;
996 tethering_error_e error;
997 tethering_type_e type;
998 tethering_h tethering = (tethering_h)user_data;
999 __tethering_h *th = (__tethering_h *)tethering;
1000 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
1001 tethering_disabled_cb dcb = NULL;
1004 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1006 ERR("DBus error [%s]\n", g_error->message);
1007 g_error_free(g_error);
1010 g_variant_get(g_var, "(uu)", &event_type, &info);
1011 DBG("cfm event : %d info : %d\n", event_type, info);
1012 g_variant_unref(g_var);
1013 error = __get_error(info);
1014 DBG("cfm event : %d info : %d\n", event_type, error);
1015 switch (event_type) {
1016 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1017 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1018 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1019 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1020 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1022 type = TETHERING_TYPE_WIFI;
1023 dcb = th->disabled_cb[type];
1024 data = th->disabled_user_data[type];
1026 dcb(error, type, code, data);
1029 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1030 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1031 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1032 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1033 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1035 type = TETHERING_TYPE_BT;
1036 dcb = th->disabled_cb[type];
1037 data = th->disabled_user_data[type];
1039 dcb(error, type, code, data);
1042 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1043 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1044 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1045 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1046 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1048 type = TETHERING_TYPE_USB;
1049 dcb = th->disabled_cb[type];
1050 data = th->disabled_user_data[type];
1052 dcb(error, type, code, data);
1055 case MOBILE_AP_DISABLE_WIFI_AP_CFM:
1056 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1057 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_OFF].name,
1058 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1059 sigs[E_SIGNAL_WIFI_AP_OFF].cb, (gpointer)th, NULL);
1061 type = TETHERING_TYPE_RESERVED;
1062 dcb = th->disabled_cb[type];
1063 data = th->disabled_user_data[type];
1065 dcb(error, type, code, data);
1068 case MOBILE_AP_DISABLE_CFM:
1070 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1071 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1072 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1073 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1074 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1075 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1076 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1077 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1078 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1079 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1080 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1081 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1083 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1084 dcb = th->disabled_cb[type];
1087 data = th->disabled_user_data[type];
1089 dcb(error, type, code, data);
1094 ERR("Invalid event\n");
1100 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1105 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1107 GError *g_error = NULL;
1110 guint64 tx_bytes, rx_bytes;
1111 __tethering_h *th = (__tethering_h *)user_data;
1112 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1115 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1117 ERR("DBus fail [%s]\n", g_error->message);
1118 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1119 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1121 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1125 if (th->data_usage_cb == NULL) {
1126 ERR("There is no data_usage_cb\n");
1130 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1132 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1133 th->data_usage_cb(TETHERING_ERROR_NONE,
1134 rx_bytes, tx_bytes, th->data_usage_user_data);
1135 g_variant_unref(g_var);
1137 th->data_usage_cb = NULL;
1138 th->data_usage_user_data = NULL;
1143 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1148 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1149 GError *g_error = NULL;
1152 __tethering_h *th = (__tethering_h *)user_data;
1153 tethering_error_e tethering_error;
1155 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1157 ERR("DBus fail [%s]\n", g_error->message);
1158 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1159 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1161 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1162 g_error_free(g_error);
1164 if (th->settings_reloaded_cb == NULL) {
1165 DBG("There is no settings_reloaded_cb\n-\n");
1168 g_variant_get(g_var, "(u)", &info);
1169 tethering_error = __get_error(info);
1170 g_variant_unref(g_var);
1172 th->settings_reloaded_cb(tethering_error,
1173 th->settings_reloaded_user_data);
1175 th->settings_reloaded_cb = NULL;
1176 th->settings_reloaded_user_data = NULL;
1180 static void __ap_settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1185 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1186 GError *g_error = NULL;
1189 __tethering_h *th = (__tethering_h *)user_data;
1190 tethering_error_e tethering_error;
1192 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1194 ERR("DBus fail [%s]\n", g_error->message);
1195 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1196 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1198 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1199 g_error_free(g_error);
1201 if (th->ap_settings_reloaded_cb == NULL) {
1202 DBG("There is no settings_reloaded_cb\n-\n");
1205 g_variant_get(g_var, "(u)", &info);
1206 tethering_error = __get_error(info);
1207 g_variant_unref(g_var);
1209 th->ap_settings_reloaded_cb(tethering_error,
1210 th->ap_settings_reloaded_user_data);
1212 th->ap_settings_reloaded_cb = NULL;
1213 th->ap_settings_reloaded_user_data = NULL;
1217 static void __connect_signals(tethering_h tethering)
1220 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1222 __tethering_h *th = (__tethering_h *)tethering;
1223 GDBusConnection *connection = th->client_bus;
1226 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1227 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1228 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1229 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1230 sigs[i].cb, tethering, NULL);
1235 static void __disconnect_signals(tethering_h tethering)
1239 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1241 __tethering_h *th = (__tethering_h *)tethering;
1242 GDBusConnection *connection = th->client_bus;
1246 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1247 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1253 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1255 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1258 case TETHERING_TYPE_USB:
1259 g_strlcpy(buf, TETHERING_USB_IF, len);
1262 case TETHERING_TYPE_WIFI:
1263 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1266 case TETHERING_TYPE_BT:
1267 g_strlcpy(buf, TETHERING_BT_IF, len);
1270 case TETHERING_TYPE_RESERVED:
1271 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1275 ERR("Not supported type : %d\n", type);
1281 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1283 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1286 case TETHERING_TYPE_USB:
1287 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1290 case TETHERING_TYPE_WIFI:
1291 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1294 case TETHERING_TYPE_BT:
1295 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1298 case TETHERING_TYPE_RESERVED:
1299 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1303 ERR("Not supported type : %d\n", type);
1309 static int __get_common_ssid(char *ssid, unsigned int size)
1312 ERR("ssid is null\n");
1313 return TETHERING_ERROR_INVALID_PARAMETER;
1317 char *ptr_tmp = NULL;
1319 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1321 ERR("vconf_get_str is failed and set default ssid");
1322 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1324 g_strlcpy(ssid, ptr, size);
1328 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1331 return TETHERING_ERROR_NONE;
1334 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1336 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1339 case TETHERING_WIFI_MODE_TYPE_B:
1340 *buf = g_strdup("b");
1342 case TETHERING_WIFI_MODE_TYPE_G:
1343 *buf = g_strdup("g");
1345 case TETHERING_WIFI_MODE_TYPE_A:
1346 *buf = g_strdup("a");
1348 case TETHERING_WIFI_MODE_TYPE_AD:
1349 *buf = g_strdup("ad");
1352 ERR("Not supported type : %d\n", type);
1358 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1362 __tethering_h *th = (__tethering_h *)tethering;
1363 tethering_error_e ret = TETHERING_ERROR_NONE;
1366 if (th == NULL || set == NULL) {
1367 ERR("null parameter\n-\n");
1368 return TETHERING_ERROR_INVALID_PARAMETER;
1371 if (th->ssid == NULL)
1372 __get_common_ssid(set->ssid, sizeof(set->ssid));
1374 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1376 ret = __get_security_type(&set->sec_type);
1377 if (ret != TETHERING_ERROR_NONE)
1378 set->sec_type = th->sec_type;
1380 ret = __get_visible(&set->visibility);
1381 if (ret != TETHERING_ERROR_NONE)
1382 set->visibility = th->visibility;
1384 set->mac_filter = th->mac_filter;
1385 set->channel = th->channel;
1387 __get_wifi_mode_type (th->mode_type, &ptr);
1389 g_strlcpy(set->mode, "", sizeof(set->mode));
1391 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1395 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1396 g_strlcpy(set->key, "", sizeof(set->key));
1398 GDBusProxy *proxy = th->client_bus_proxy;
1399 GVariant *parameters;
1400 GError *error = NULL;
1401 char *passphrase = NULL;
1402 unsigned int len = 0;
1404 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1405 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1408 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1410 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1411 ret = TETHERING_ERROR_PERMISSION_DENIED;
1413 ret = TETHERING_ERROR_OPERATION_FAILED;
1415 g_error_free(error);
1419 if (parameters != NULL) {
1420 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1421 g_variant_unref(parameters);
1424 g_strlcpy(set->key, passphrase, sizeof(set->key));
1427 return TETHERING_ERROR_NONE;
1430 static int __prepare_wifi_ap_settings(tethering_h tethering, _softap_settings_t *set)
1434 __tethering_h *th = (__tethering_h *)tethering;
1436 if (th == NULL || set == NULL) {
1437 ERR("null parameter\n");
1438 return TETHERING_ERROR_INVALID_PARAMETER;
1441 g_strlcpy(set->ssid, th->ap_ssid, sizeof(set->ssid));
1442 set->sec_type = th->sec_type;
1443 set->visibility = th->visibility;
1445 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
1446 g_strlcpy(set->key, "", sizeof(set->key));
1448 g_strlcpy(set->key, th->passphrase, sizeof(set->key));
1451 return TETHERING_ERROR_NONE;
1454 static bool __check_precondition(tethering_type_e type)
1457 int cellular_state = 0;
1460 /* data network through cellular */
1461 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1462 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1463 ERR("Data Network can be connected later");
1467 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1468 if (dnet_state > VCONFKEY_DNET_OFF) {
1469 ERR("Data Network is connected");
1473 /* data network through wifi */
1474 if (type != TETHERING_TYPE_WIFI) {
1475 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1476 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1477 ERR("Wi-Fi is connected!");
1482 ERR("Network is not available!");
1488 * @brief Creates the handle of tethering.
1490 * @privlevel platform
1491 * @privilege http://tizen.org/privilege/tethering.admin
1492 * @remarks The @a tethering must be released tethering_destroy() by you.
1493 * @param[out] tethering A handle of a new mobile ap handle on success
1494 * @return 0 on success, otherwise a negative error value.
1495 * @retval #TETHERING_ERROR_NONE Successful
1496 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1497 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1498 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1499 * @see tethering_destroy()
1501 API int tethering_create(tethering_h *tethering)
1503 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1504 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1505 "parameter(tethering) is NULL\n");
1508 __tethering_h *th = NULL;
1509 GError *error = NULL;
1510 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1512 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1514 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1515 "malloc is failed\n");
1516 memset(th, 0x00, sizeof(__tethering_h));
1517 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1518 th->visibility = true;
1519 th->mac_filter = false;
1521 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1523 if (__generate_initial_passphrase(th->passphrase,
1524 sizeof(th->passphrase)) == 0) {
1525 ERR("random passphrase generation failed\n");
1527 return TETHERING_ERROR_OPERATION_FAILED;
1530 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1531 ERR("common ssid get failed\n");
1533 return TETHERING_ERROR_OPERATION_FAILED;
1536 th->ap_ssid = g_strdup(ssid);
1537 if (th->ap_ssid == NULL) {
1538 ERR("g_strdup failed\n");
1540 return TETHERING_ERROR_OPERATION_FAILED;
1543 #if !GLIB_CHECK_VERSION(2, 36, 0)
1546 GCancellable *cancellable = g_cancellable_new();
1547 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1549 ERR("Couldn't connect to the System bus[%s]", error->message);
1550 g_error_free(error);
1551 g_cancellable_cancel(cancellable);
1552 g_object_unref(cancellable);
1553 g_free(th->ap_ssid);
1555 return TETHERING_ERROR_OPERATION_FAILED;
1557 th->cancellable = cancellable;
1559 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_NONE,
1560 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1561 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1562 if (!th->client_bus_proxy) {
1563 ERR("Couldn't create the proxy object because of %s\n", error->message);
1564 g_cancellable_cancel(th->cancellable);
1565 g_object_unref(th->cancellable);
1566 g_object_unref(th->client_bus);
1567 g_free(th->ap_ssid);
1569 return TETHERING_ERROR_OPERATION_FAILED;
1572 __connect_signals((tethering_h)th);
1574 *tethering = (tethering_h)th;
1575 DBG("Tethering Handle : 0x%X\n", th);
1577 return TETHERING_ERROR_NONE;
1582 * @brief Destroys the handle of tethering.
1584 * @privlevel platform
1585 * @privilege http://tizen.org/privilege/tethering.admin
1586 * @param[in] tethering The handle of tethering
1587 * @return 0 on success, otherwise a negative error value.
1588 * @retval #TETHERING_ERROR_NONE Successful
1589 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1590 * @see tethering_create()
1592 API int tethering_destroy(tethering_h tethering)
1595 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1596 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1597 "parameter(tethering) is NULL\n");
1599 __tethering_h *th = (__tethering_h *)tethering;
1601 DBG("Tethering Handle : 0x%X\n", th);
1602 __disconnect_signals(tethering);
1609 g_object_unref(th->cancellable);
1610 g_object_unref(th->client_bus_proxy);
1611 g_object_unref(th->client_bus);
1612 memset(th, 0x00, sizeof(__tethering_h));
1616 return TETHERING_ERROR_NONE;
1621 * @brief Enables the tethering, asynchronously.
1623 * @privlevel platform
1624 * @privilege http://tizen.org/privilege/tethering.admin
1625 * @param[in] tethering The handle of tethering
1626 * @param[in] type The type of tethering
1627 * @return 0 on success, otherwise negative error value.
1628 * @retval #TETHERING_ERROR_NONE Successful
1629 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1630 * @post tethering_enabled_cb() will be invoked.
1631 * @see tethering_is_enabled()
1632 * @see tethering_disable()
1634 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1636 DBG("+ type : %d\n", type);
1637 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1638 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1639 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1640 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1642 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1643 "parameter(tethering) is NULL\n");
1645 tethering_error_e ret = TETHERING_ERROR_NONE;
1646 __tethering_h *th = (__tethering_h *)tethering;
1647 GDBusProxy *proxy = th->client_bus_proxy;
1648 GDBusConnection *connection = th->client_bus;
1650 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1652 if (type != TETHERING_TYPE_RESERVED
1653 && __check_precondition(type) == FALSE) {
1655 return TETHERING_ERROR_OPERATION_FAILED;
1659 case TETHERING_TYPE_USB:
1660 g_dbus_connection_signal_unsubscribe(connection,
1661 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1663 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1664 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1665 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1668 case TETHERING_TYPE_WIFI: {
1669 _softap_settings_t set = {"", "", "", 0, false};
1671 ret = __prepare_wifi_settings(tethering, &set);
1672 if (ret != TETHERING_ERROR_NONE) {
1673 ERR("softap settings initialization failed\n");
1675 return TETHERING_ERROR_OPERATION_FAILED;
1677 g_dbus_connection_signal_unsubscribe(connection,
1678 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1680 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1681 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
1682 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1683 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1687 case TETHERING_TYPE_BT:
1688 g_dbus_connection_signal_unsubscribe(connection,
1689 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1691 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1692 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1693 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1697 case TETHERING_TYPE_RESERVED: {
1698 _softap_settings_t set = {"", "", "", 0, false};
1700 ret = __prepare_wifi_ap_settings(tethering, &set);
1701 if (ret != TETHERING_ERROR_NONE) {
1702 ERR("softap settings initialization failed\n");
1703 return TETHERING_ERROR_OPERATION_FAILED;
1706 g_dbus_connection_signal_unsubscribe(connection,
1707 sigs[E_SIGNAL_WIFI_AP_ON].sig_id);
1709 g_dbus_proxy_call(proxy, "enable_wifi_ap",
1710 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1711 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_ap_enabled_cfm_cb, (gpointer)tethering);
1714 case TETHERING_TYPE_ALL: {
1715 _softap_settings_t set = {"", "", "", 0, false};
1717 ret = __prepare_wifi_settings(tethering, &set);
1718 if (ret != TETHERING_ERROR_NONE) {
1719 ERR("softap settings initialization failed\n");
1720 return TETHERING_ERROR_OPERATION_FAILED;
1723 /* TETHERING_TYPE_USB */
1724 g_dbus_connection_signal_unsubscribe(connection,
1725 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1727 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1728 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1729 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1731 /* TETHERING_TYPE_WIFI */
1732 g_dbus_connection_signal_unsubscribe(connection,
1733 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1735 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1736 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1737 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1738 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1740 /* TETHERING_TYPE_BT */
1741 g_dbus_connection_signal_unsubscribe(connection,
1742 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1744 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1745 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1746 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1750 ERR("Unknown type : %d\n", type);
1752 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1755 return TETHERING_ERROR_INVALID_PARAMETER;
1758 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1760 return TETHERING_ERROR_NONE;
1765 * @brief Disables the tethering, asynchronously.
1767 * @privlevel platform
1768 * @privilege http://tizen.org/privilege/tethering.admin
1769 * @param[in] tethering The handle of tethering
1770 * @param[in] type The type of tethering
1771 * @return 0 on success, otherwise negative error value.
1772 * @retval #TETHERING_ERROR_NONE Successful
1773 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1774 * @post tethering_disabled_cb() will be invoked.
1775 * @see tethering_is_enabled()
1776 * @see tethering_enable()
1778 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1780 DBG("+ type : %d\n", type);
1781 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1782 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1783 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1785 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1786 "parameter(tethering) is NULL\n");
1788 __tethering_h *th = (__tethering_h *)tethering;
1789 GDBusProxy *proxy = th->client_bus_proxy;
1790 GDBusConnection *connection = th->client_bus;
1793 case TETHERING_TYPE_USB:
1794 g_dbus_connection_signal_unsubscribe(connection,
1795 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1797 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1798 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1799 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1803 case TETHERING_TYPE_WIFI:
1805 g_dbus_connection_signal_unsubscribe(connection,
1806 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1808 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1809 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1810 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1813 case TETHERING_TYPE_BT:
1815 g_dbus_connection_signal_unsubscribe(connection,
1816 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1818 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1819 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1820 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1823 case TETHERING_TYPE_RESERVED:
1824 g_dbus_connection_signal_unsubscribe(connection,
1825 sigs[E_SIGNAL_WIFI_AP_OFF].sig_id);
1827 g_dbus_proxy_call(proxy, "disable_wifi_ap",
1828 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1829 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1832 case TETHERING_TYPE_ALL:
1833 g_dbus_connection_signal_unsubscribe(connection,
1834 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1836 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1837 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1838 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1840 g_dbus_connection_signal_unsubscribe(connection,
1841 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1843 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1844 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1845 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1847 g_dbus_connection_signal_unsubscribe(connection,
1848 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1850 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1851 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1852 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1856 ERR("Not supported tethering type [%d]\n", type);
1858 return TETHERING_ERROR_INVALID_PARAMETER;
1861 return TETHERING_ERROR_NONE;
1866 * @brief Checks whetehr the tethering is enabled or not.
1868 * @privlevel platform
1869 * @privilege http://tizen.org/privilege/tethering.admin
1870 * @param[in] tethering The handle of tethering
1871 * @param[in] type The type of tethering
1872 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1874 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1877 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1879 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1881 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1885 case TETHERING_TYPE_USB:
1886 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1889 case TETHERING_TYPE_WIFI:
1890 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1893 case TETHERING_TYPE_BT:
1894 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1897 case TETHERING_TYPE_RESERVED:
1898 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
1902 ERR("Not supported type : %d\n", type);
1905 return is_on & vconf_type ? true : false;
1910 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1912 * @privlevel platform
1913 * @privilege http://tizen.org/privilege/tethering.admin
1914 * @remarks @a mac_address must be released with free() by you.
1915 * @param[in] tethering The handle of tethering
1916 * @param[in] type The type of tethering
1917 * @param[out] mac_address The MAC address
1918 * @return 0 on success, otherwise a negative error value.
1919 * @retval #TETHERING_ERROR_NONE Successful
1920 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1921 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1922 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1923 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1924 * @pre tethering must be enabled.
1925 * @see tethering_is_enabled()
1926 * @see tethering_enable()
1928 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1930 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1931 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
1932 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
1934 _retvm_if(tethering_is_enabled(tethering, type) == false,
1935 TETHERING_ERROR_NOT_ENABLED,
1936 "tethering type[%d] is not enabled\n", type);
1937 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1938 "parameter(tethering) is NULL\n");
1939 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1940 "parameter(mac_address) is NULL\n");
1944 char *macbuf = NULL;
1946 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1947 TETHERING_ERROR_OPERATION_FAILED,
1948 "getting interface name is failed\n");
1950 s = socket(AF_INET, SOCK_DGRAM, 0);
1951 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1952 "getting socket is failed\n");
1953 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1954 ERR("getting mac is failed\n");
1956 return TETHERING_ERROR_OPERATION_FAILED;
1960 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1961 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1962 "Not enough memory\n");
1963 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1964 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1965 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1966 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1967 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1968 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1969 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1971 *mac_address = macbuf;
1973 return TETHERING_ERROR_NONE;
1978 * @brief Gets the name of network interface. For example, usb0.
1980 * @privlevel platform
1981 * @privilege http://tizen.org/privilege/tethering.admin
1982 * @remarks @a interface_name must be released with free() by you.
1983 * @param[in] tethering The handle of tethering
1984 * @param[in] type The type of tethering
1985 * @param[out] interface_name The name of network interface
1986 * @return 0 on success, otherwise negative error value.
1987 * @retval #TETHERING_ERROR_NONE Successful
1988 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1989 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1990 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1991 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1992 * @pre tethering must be enabled.
1993 * @see tethering_is_enabled()
1994 * @see tethering_enable()
1996 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1998 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
1999 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2000 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2002 _retvm_if(tethering_is_enabled(tethering, type) == false,
2003 TETHERING_ERROR_NOT_ENABLED,
2004 "tethering type[%d] is not enabled\n", type);
2005 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2006 "parameter(tethering) is NULL\n");
2007 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2008 "parameter(interface_name) is NULL\n");
2010 char intf[TETHERING_STR_INFO_LEN] = {0, };
2012 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2013 TETHERING_ERROR_OPERATION_FAILED,
2014 "getting interface name is failed\n");
2015 *interface_name = strdup(intf);
2016 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2017 "Not enough memory\n");
2019 return TETHERING_ERROR_NONE;
2024 * @brief Gets the local IP address.
2026 * @privlevel platform
2027 * @privilege http://tizen.org/privilege/tethering.admin
2028 * @remarks @a ip_address must be released with free() by you.
2029 * @param[in] tethering The handle of tethering
2030 * @param[in] type The type of tethering
2031 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2032 * @param[out] ip_address The local IP address
2033 * @return 0 on success, otherwise negative error value.
2034 * @retval #TETHERING_ERROR_NONE Successful
2035 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2036 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2037 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2038 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2039 * @pre tethering must be enabled.
2040 * @see tethering_is_enabled()
2041 * @see tethering_enable()
2043 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2046 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2047 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2048 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2050 _retvm_if(tethering_is_enabled(tethering, type) == false,
2051 TETHERING_ERROR_NOT_ENABLED,
2052 "tethering type[%d] is not enabled\n", type);
2053 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2054 "parameter(tethering) is NULL\n");
2055 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2056 "parameter(ip_address) is NULL\n");
2062 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2063 TETHERING_ERROR_OPERATION_FAILED,
2064 "getting interface name is failed\n");
2066 s = socket(AF_INET, SOCK_DGRAM, 0);
2067 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2068 "getting socket is failed\n");
2069 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2070 ERR("ioctl is failed\n");
2072 return TETHERING_ERROR_OPERATION_FAILED;
2076 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2077 *ip_address = strdup(ipbuf);
2078 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2079 "Not enough memory\n");
2081 return TETHERING_ERROR_NONE;
2086 * @brief Gets the Gateway address.
2088 * @privlevel platform
2089 * @privilege http://tizen.org/privilege/tethering.admin
2090 * @remarks @a gateway_address must be released with free() by you.
2091 * @param[in] tethering The handle of tethering
2092 * @param[in] type The type of tethering
2093 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2094 * @param[out] gateway_address The local IP address
2095 * @return 0 on success, otherwise negative error value.
2096 * @retval #TETHERING_ERROR_NONE Successful
2097 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2098 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2099 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2100 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2101 * @pre tethering must be enabled.
2102 * @see tethering_is_enabled()
2103 * @see tethering_enable()
2105 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2108 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2109 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2110 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2112 _retvm_if(tethering_is_enabled(tethering, type) == false,
2113 TETHERING_ERROR_NOT_ENABLED,
2114 "tethering type[%d] is not enabled\n", type);
2115 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2116 "parameter(tethering) is NULL\n");
2117 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2118 "parameter(gateway_address) is NULL\n");
2120 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2122 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2123 TETHERING_ERROR_OPERATION_FAILED,
2124 "getting gateway address is failed\n");
2126 *gateway_address = strdup(gateway_buf);
2128 return TETHERING_ERROR_NONE;
2133 * @brief Gets the Subnet Mask.
2135 * @privlevel platform
2136 * @privilege http://tizen.org/privilege/tethering.admin
2137 * @remarks @a subnet_mask must be released with free() by you.
2138 * @param[in] tethering The handle of tethering
2139 * @param[in] type The type of tethering
2140 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2141 * @param[out] subnet_mask The local IP address
2142 * @return 0 on success, otherwise negative error value.
2143 * @retval #TETHERING_ERROR_NONE Successful
2144 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2145 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2146 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2147 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2148 * @pre tethering must be enabled.
2149 * @see tethering_is_enabled()
2150 * @see tethering_enable()
2152 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2154 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2155 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2156 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2158 _retvm_if(tethering_is_enabled(tethering, type) == false,
2159 TETHERING_ERROR_NOT_ENABLED,
2160 "tethering is not enabled\n");
2161 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2162 "parameter(tethering) is NULL\n");
2163 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2164 "parameter(subnet_mask) is NULL\n");
2166 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2167 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2168 "Not enough memory\n");
2170 return TETHERING_ERROR_NONE;
2175 * @brief Gets the data usage.
2177 * @privlevel platform
2178 * @privilege http://tizen.org/privilege/tethering.admin
2179 * @param[in] tethering The handle of tethering
2180 * @param[out] usage The data usage
2181 * @return 0 on success, otherwise negative error value.
2182 * @retval #TETHERING_ERROR_NONE Successful
2183 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2184 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2185 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2186 * @pre tethering must be enabled.
2187 * @see tethering_is_enabled()
2188 * @see tethering_enable()
2190 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2192 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2194 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2195 "parameter(tethering) is NULL\n");
2196 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2197 "parameter(callback) is NULL\n");
2198 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2199 TETHERING_ERROR_NOT_ENABLED,
2200 "tethering is not enabled\n");
2202 __tethering_h *th = (__tethering_h *)tethering;
2203 GDBusProxy *proxy = th->client_bus_proxy;
2205 th->data_usage_cb = callback;
2206 th->data_usage_user_data = user_data;
2208 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2209 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2210 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2212 return TETHERING_ERROR_NONE;
2217 * @brief Gets the client which is connected by tethering "type".
2219 * @privlevel platform
2220 * @privilege http://tizen.org/privilege/tethering.admin
2221 * @param[in] tethering The handle of tethering
2222 * @param[in] type The type of tethering
2223 * @param[in] callback The callback function to invoke
2224 * @param[in] user_data The user data to be passed to the callback function
2225 * @retval #TETHERING_ERROR_NONE Successful
2226 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2227 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2228 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2229 * @pre tethering must be enabled.
2230 * @see tethering_is_enabled()
2231 * @see tethering_enable()
2233 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2236 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2237 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2238 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2240 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2241 "parameter(tethering) is NULL\n");
2242 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2243 "parameter(callback) is NULL\n");
2244 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2245 TETHERING_ERROR_NOT_ENABLED,
2246 "tethering is not enabled\n");
2248 mobile_ap_type_e interface;
2249 __tethering_h *th = (__tethering_h *)tethering;
2250 __tethering_client_h client = {0, };
2253 gchar *hostname = NULL;
2254 guint timestamp = 0;
2255 GError *error = NULL;
2256 GVariant *result = NULL;
2257 GVariantIter *outer_iter = NULL;
2258 GVariantIter *inner_iter = NULL;
2259 GVariant *station = NULL;
2260 GVariant *value = NULL;
2263 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2264 NULL, G_DBUS_CALL_FLAGS_NONE,
2265 -1, th->cancellable, &error);
2267 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2268 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2269 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2270 g_variant_get(station, "a{sv}", &inner_iter);
2271 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2272 if (g_strcmp0(key, "Type") == 0) {
2273 interface = g_variant_get_int32(value);
2274 if (interface == MOBILE_AP_TYPE_USB)
2275 client.interface = TETHERING_TYPE_USB;
2276 else if (interface == MOBILE_AP_TYPE_WIFI)
2277 client.interface = TETHERING_TYPE_WIFI;
2278 else if (interface == MOBILE_AP_TYPE_BT)
2279 client.interface = TETHERING_TYPE_BT;
2280 else if (interface == MOBILE_AP_TYPE_WIFI_AP)
2281 client.interface = TETHERING_TYPE_RESERVED;
2283 ERR("Invalid interface\n");
2285 g_variant_unref(value);
2288 DBG("interface is %d\n", client.interface);
2289 if (client.interface != type && (TETHERING_TYPE_ALL != type &&
2290 client.interface != TETHERING_TYPE_RESERVED)) {
2292 g_variant_unref(value);
2295 } else if (g_strcmp0(key, "IP") == 0) {
2296 g_variant_get(value, "s", &ip);
2297 SDBG("ip is %s\n", ip);
2298 g_strlcpy(client.ip, ip, sizeof(client.ip));
2299 } else if (g_strcmp0(key, "MAC") == 0) {
2300 g_variant_get(value, "s", &mac);
2301 SDBG("mac is %s\n", mac);
2302 g_strlcpy(client.mac, mac, sizeof(client.mac));
2303 } else if (g_strcmp0(key, "Name") == 0) {
2304 g_variant_get(value, "s", &hostname);
2305 SDBG("hsotname is %s\n", hostname);
2307 client.hostname = g_strdup(hostname);
2308 } else if (g_strcmp0(key, "Time") == 0) {
2309 timestamp = g_variant_get_int32(value);
2310 DBG("timestamp is %d\n", timestamp);
2311 client.tm = (time_t)timestamp;
2313 ERR("Key %s not required\n", key);
2319 g_variant_iter_free(inner_iter);
2320 if (callback((tethering_client_h)&client, user_data) == false) {
2321 DBG("iteration is stopped\n");
2322 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_OPERATION_FAILED;
2329 g_free(client.hostname);
2331 g_variant_iter_free(outer_iter);
2332 g_variant_unref(station);
2333 g_variant_unref(result);
2335 return TETHERING_ERROR_NONE;
2340 * @brief Registers the callback function called when tethering is enabled.
2342 * @privlevel platform
2343 * @privilege http://tizen.org/privilege/tethering.admin
2344 * @param[in] tethering The handle of tethering
2345 * @param[in] type The type of tethering
2346 * @param[in] callback The callback function to invoke
2347 * @param[in] user_data The user data to be passed to the callback function
2348 * @retval #TETHERING_ERROR_NONE Successful
2349 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2350 * @see tethering_unset_enabled_cb()
2352 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2354 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2355 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2356 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2358 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2359 "parameter(tethering) is NULL\n");
2360 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2361 "parameter(callback) is NULL\n");
2363 __tethering_h *th = (__tethering_h *)tethering;
2364 tethering_type_e ti;
2366 if (type != TETHERING_TYPE_ALL) {
2367 th->enabled_cb[type] = callback;
2368 th->enabled_user_data[type] = user_data;
2370 return TETHERING_ERROR_NONE;
2373 /* TETHERING_TYPE_ALL */
2374 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2375 th->enabled_cb[ti] = callback;
2376 th->enabled_user_data[ti] = user_data;
2379 return TETHERING_ERROR_NONE;
2384 * @brief Unregisters the callback function called when tethering is disabled.
2386 * @privlevel platform
2387 * @privilege http://tizen.org/privilege/tethering.admin
2388 * @param[in] tethering The handle of tethering
2389 * @param[in] type The type of tethering
2390 * @retval #TETHERING_ERROR_NONE Successful
2391 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2392 * @see tethering_set_enabled_cb()
2394 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2396 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2397 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2398 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2400 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2401 "parameter(tethering) is NULL\n");
2403 __tethering_h *th = (__tethering_h *)tethering;
2404 tethering_type_e ti;
2406 if (type != TETHERING_TYPE_ALL) {
2407 th->enabled_cb[type] = NULL;
2408 th->enabled_user_data[type] = NULL;
2410 return TETHERING_ERROR_NONE;
2413 /* TETHERING_TYPE_ALL */
2414 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2415 th->enabled_cb[ti] = NULL;
2416 th->enabled_user_data[ti] = NULL;
2419 return TETHERING_ERROR_NONE;
2424 * @brief Registers the callback function called when tethering is disabled.
2426 * @privlevel platform
2427 * @privilege http://tizen.org/privilege/tethering.admin
2428 * @param[in] tethering The handle of tethering
2429 * @param[in] type The type of tethering
2430 * @param[in] callback The callback function to invoke
2431 * @param[in] user_data The user data to be passed to the callback function
2432 * @retval #TETHERING_ERROR_NONE Successful
2433 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2434 * @see tethering_unset_disabled_cb()
2436 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2438 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2439 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2440 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2442 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2443 "parameter(tethering) is NULL\n");
2444 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2445 "parameter(callback) is NULL\n");
2447 __tethering_h *th = (__tethering_h *)tethering;
2448 tethering_type_e ti;
2450 if (type != TETHERING_TYPE_ALL) {
2451 th->disabled_cb[type] = callback;
2452 th->disabled_user_data[type] = user_data;
2454 return TETHERING_ERROR_NONE;
2457 /* TETHERING_TYPE_ALL */
2458 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2459 th->disabled_cb[ti] = callback;
2460 th->disabled_user_data[ti] = user_data;
2463 return TETHERING_ERROR_NONE;
2468 * @brief Unregisters the callback function called when tethering is disabled.
2470 * @privlevel platform
2471 * @privilege http://tizen.org/privilege/tethering.admin
2472 * @param[in] tethering The handle of tethering
2473 * @param[in] type The type of tethering
2474 * @retval #TETHERING_ERROR_NONE Successful
2475 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2476 * @see tethering_set_disabled_cb()
2478 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2480 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2481 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2482 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2484 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2485 "parameter(tethering) is NULL\n");
2487 __tethering_h *th = (__tethering_h *)tethering;
2488 tethering_type_e ti;
2490 if (type != TETHERING_TYPE_ALL) {
2491 th->disabled_cb[type] = NULL;
2492 th->disabled_user_data[type] = NULL;
2494 return TETHERING_ERROR_NONE;
2497 /* TETHERING_TYPE_ALL */
2498 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2499 th->disabled_cb[ti] = NULL;
2500 th->disabled_user_data[ti] = NULL;
2503 return TETHERING_ERROR_NONE;
2508 * @brief Registers the callback function called when the state of connection is changed.
2510 * @privlevel platform
2511 * @privilege http://tizen.org/privilege/tethering.admin
2512 * @param[in] tethering The handle of tethering
2513 * @param[in] type The type of tethering
2514 * @param[in] callback The callback function to invoke
2515 * @param[in] user_data The user data to be passed to the callback function
2516 * @retval #TETHERING_ERROR_NONE Successful
2517 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2518 * @see tethering_unset_connection_state_changed_cb_cb()
2520 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2522 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2523 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2524 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2526 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2527 "parameter(tethering) is NULL\n");
2528 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2529 "parameter(callback) is NULL\n");
2531 __tethering_h *th = (__tethering_h *)tethering;
2532 tethering_type_e ti;
2534 if (type != TETHERING_TYPE_ALL) {
2535 th->changed_cb[type] = callback;
2536 th->changed_user_data[type] = user_data;
2538 return TETHERING_ERROR_NONE;
2541 /* TETHERING_TYPE_ALL */
2542 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2543 th->changed_cb[ti] = callback;
2544 th->changed_user_data[ti] = user_data;
2547 return TETHERING_ERROR_NONE;
2552 * @brief Unregisters the callback function called when the state of connection is changed.
2554 * @privlevel platform
2555 * @privilege http://tizen.org/privilege/tethering.admin
2556 * @param[in] tethering The handle of tethering
2557 * @param[in] type The type of tethering
2558 * @retval #TETHERING_ERROR_NONE Successful
2559 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2560 * @see tethering_set_connection_state_changed_cb()
2562 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2564 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE);
2565 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2566 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE);
2568 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2569 "parameter(tethering) is NULL\n");
2571 __tethering_h *th = (__tethering_h *)tethering;
2572 tethering_type_e ti;
2574 if (type != TETHERING_TYPE_ALL) {
2575 th->changed_cb[type] = NULL;
2576 th->changed_user_data[type] = NULL;
2578 return TETHERING_ERROR_NONE;
2581 /* TETHERING_TYPE_ALL */
2582 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2583 th->changed_cb[ti] = NULL;
2584 th->changed_user_data[ti] = NULL;
2587 return TETHERING_ERROR_NONE;
2592 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2594 * @privlevel platform
2595 * @privilege http://tizen.org/privilege/tethering.admin
2596 * @param[in] tethering The handle of tethering
2597 * @param[in] callback The callback function to invoke
2598 * @param[in] user_data The user data to be passed to the callback function
2599 * @retval #TETHERING_ERROR_NONE Successful
2600 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2601 * @see tethering_wifi_unset_security_type_changed_cb()
2603 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2605 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2607 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2608 "parameter(tethering) is NULL\n");
2609 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2610 "parameter(callback) is NULL\n");
2612 __tethering_h *th = (__tethering_h *)tethering;
2614 th->security_type_changed_cb = callback;
2615 th->security_type_user_data = user_data;
2617 return TETHERING_ERROR_NONE;
2623 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2625 * @privlevel platform
2626 * @privilege http://tizen.org/privilege/tethering.admin
2627 * @param[in] tethering The handle of tethering
2628 * @param[in] type The type of tethering
2629 * @retval #TETHERING_ERROR_NONE Successful
2630 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2631 * @see tethering_wifi_set_security_type_changed_cb()
2633 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2635 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2637 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2638 "parameter(tethering) is NULL\n");
2640 __tethering_h *th = (__tethering_h *)tethering;
2642 th->security_type_changed_cb = NULL;
2643 th->security_type_user_data = NULL;
2645 return TETHERING_ERROR_NONE;
2650 * @brief Registers the callback function called when the visibility of SSID is changed.
2652 * @privlevel platform
2653 * @privilege http://tizen.org/privilege/tethering.admin
2654 * @param[in] tethering The handle of tethering
2655 * @param[in] callback The callback function to invoke
2656 * @param[in] user_data The user data to be passed to the callback function
2657 * @retval #TETHERING_ERROR_NONE Successful
2658 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2659 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2661 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2663 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2665 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2666 "parameter(tethering) is NULL\n");
2667 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2668 "parameter(callback) is NULL\n");
2670 __tethering_h *th = (__tethering_h *)tethering;
2672 th->ssid_visibility_changed_cb = callback;
2673 th->ssid_visibility_user_data = user_data;
2675 return TETHERING_ERROR_NONE;
2680 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2682 * @privlevel platform
2683 * @privilege http://tizen.org/privilege/tethering.admin
2684 * @param[in] tethering The handle of tethering
2685 * @retval #TETHERING_ERROR_NONE Successful
2686 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2687 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2689 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2691 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2693 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2694 "parameter(tethering) is NULL\n");
2696 __tethering_h *th = (__tethering_h *)tethering;
2698 th->ssid_visibility_changed_cb = NULL;
2699 th->ssid_visibility_user_data = NULL;
2701 return TETHERING_ERROR_NONE;
2706 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2708 * @privlevel platform
2709 * @privilege http://tizen.org/privilege/tethering.admin
2710 * @param[in] tethering The handle of tethering
2711 * @param[in] callback The callback function to invoke
2712 * @param[in] user_data The user data to be passed to the callback function
2713 * @retval #TETHERING_ERROR_NONE Successful
2714 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2715 * @see tethering_wifi_unset_passphrase_changed_cb()
2717 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2719 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2721 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2722 "parameter(tethering) is NULL\n");
2723 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2724 "parameter(callback) is NULL\n");
2726 __tethering_h *th = (__tethering_h *)tethering;
2728 th->passphrase_changed_cb = callback;
2729 th->passphrase_user_data = user_data;
2731 return TETHERING_ERROR_NONE;
2736 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2738 * @privlevel platform
2739 * @privilege http://tizen.org/privilege/tethering.admin
2740 * @param[in] tethering The handle of tethering
2741 * @retval #TETHERING_ERROR_NONE Successful
2742 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2743 * @see tethering_wifi_set_passphrase_changed_cb()
2745 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2747 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2749 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2750 "parameter(tethering) is NULL\n");
2752 __tethering_h *th = (__tethering_h *)tethering;
2754 th->passphrase_changed_cb = NULL;
2755 th->passphrase_user_data = NULL;
2757 return TETHERING_ERROR_NONE;
2762 * @brief Sets the security type of Wi-Fi tethering.
2764 * @privlevel platform
2765 * @privilege http://tizen.org/privilege/tethering.admin
2766 * @remarks This change is applied next time Wi-Fi tethering is enabled
2767 * @param[in] tethering The handle of tethering
2768 * @param[in] type The security type
2769 * @return 0 on success, otherwise negative error value.
2770 * @retval #TETHERING_ERROR_NONE Successful
2771 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2772 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2773 * @see tethering_wifi_get_security_type()
2775 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2777 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2779 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2780 "parameter(tethering) is NULL\n");
2782 __tethering_h *th = (__tethering_h *)tethering;
2783 tethering_error_e ret = TETHERING_ERROR_NONE;
2785 ret = __set_security_type(type);
2786 if (ret == TETHERING_ERROR_NONE) {
2788 __send_dbus_signal(th->client_bus,
2789 SIGNAL_NAME_SECURITY_TYPE_CHANGED,
2790 type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
2791 TETHERING_WIFI_SECURITY_TYPE_OPEN_STR :
2792 TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR);
2799 * @brief Gets the security type of Wi-Fi tethering.
2801 * @privlevel platform
2802 * @privilege http://tizen.org/privilege/tethering.admin
2803 * @param[in] tethering The handle of tethering
2804 * @param[out] type The security type
2805 * @return 0 on success, otherwise negative error value.
2806 * @retval #TETHERING_ERROR_NONE Successful
2807 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2808 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2809 * @see tethering_wifi_set_security_type()
2811 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2813 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2815 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2816 "parameter(type) is NULL\n");
2818 return __get_security_type(type);
2823 * @brief Sets the SSID (service set identifier).
2825 * @privlevel platform
2826 * @privilege http://tizen.org/privilege/tethering.admin
2827 * @details If SSID is not set, Device name is used as SSID
2828 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2829 * @param[in] tethering The handle of tethering
2830 * @param[out] ssid The SSID
2831 * @return 0 on success, otherwise negative error value.
2832 * @retval #TETHERING_ERROR_NONE Successful
2833 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2834 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2836 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2838 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2840 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2841 "parameter(tethering) is NULL\n");
2842 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2843 "parameter(ssid) is NULL\n");
2845 __tethering_h *th = (__tethering_h *)tethering;
2846 char *p_ssid = NULL;
2849 ssid_len = strlen(ssid);
2850 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2851 ERR("parameter(ssid) is too long");
2852 return TETHERING_ERROR_INVALID_PARAMETER;
2855 p_ssid = strdup(ssid);
2856 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2857 "strdup is failed\n");
2863 return TETHERING_ERROR_NONE;
2868 * @brief Gets the SSID (service set identifier).
2870 * @privlevel platform
2871 * @privilege http://tizen.org/privilege/tethering.admin
2872 * @remarks @a ssid must be released with free() by you.
2873 * @param[in] tethering The handle of tethering
2874 * @param[out] ssid The SSID
2875 * @return 0 on success, otherwise negative error value.
2876 * @retval #TETHERING_ERROR_NONE Successful
2877 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2878 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2879 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2881 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2883 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2885 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2886 "parameter(tethering) is NULL\n");
2887 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2888 "parameter(ssid) is NULL\n");
2891 __tethering_h *th = (__tethering_h *)tethering;
2892 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2894 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2895 if (th->ssid != NULL) {
2896 DBG("Private SSID is set\n");
2897 *ssid = strdup(th->ssid);
2899 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2900 val, sizeof(val)) == false) {
2901 return TETHERING_ERROR_OPERATION_FAILED;
2903 *ssid = strdup(val);
2906 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2907 val, sizeof(val)) == false) {
2908 return TETHERING_ERROR_OPERATION_FAILED;
2910 *ssid = strdup(val);
2913 if (*ssid == NULL) {
2914 ERR("strdup is failed\n");
2915 return TETHERING_ERROR_OUT_OF_MEMORY;
2918 return TETHERING_ERROR_NONE;
2923 * @brief Sets the visibility of SSID(service set identifier).
2925 * @privlevel platform
2926 * @privilege http://tizen.org/privilege/tethering.admin
2927 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2928 * @remarks This change is applied next time Wi-Fi tethering is enabled
2929 * @param[in] tethering The handle of tethering
2930 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2931 * @return 0 on success, otherwise negative error value.
2932 * @retval #TETHERING_ERROR_NONE Successful
2933 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2934 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2935 * @see tethering_wifi_get_ssid_visibility()
2937 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2939 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2941 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2942 "parameter(tethering) is NULL\n");
2944 __tethering_h *th = (__tethering_h *)tethering;
2945 tethering_error_e ret = TETHERING_ERROR_NONE;
2947 ret = __set_visible(visible);
2948 if (ret == TETHERING_ERROR_NONE) {
2950 __send_dbus_signal(th->client_bus,
2951 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2952 visible ? SIGNAL_MSG_SSID_VISIBLE :
2953 SIGNAL_MSG_SSID_HIDE);
2960 * @brief Gets the visibility of SSID(service set identifier).
2962 * @privlevel platform
2963 * @privilege http://tizen.org/privilege/tethering.admin
2964 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2965 * @param[in] tethering The handle of tethering
2966 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2967 * @return 0 on success, otherwise negative error value.
2968 * @retval #TETHERING_ERROR_NONE Successful
2969 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2970 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2971 * @see tethering_wifi_set_ssid_visibility()
2973 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2975 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
2977 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2978 "parameter(visible) is NULL\n");
2980 return __get_visible(visible);
2985 * @brief Sets the passphrase.
2987 * @privlevel platform
2988 * @privilege http://tizen.org/privilege/tethering.admin
2989 * @remarks This change is applied next time Wi-Fi tethering is enabled
2990 * @param[in] tethering The handle of tethering
2991 * @param[in] passphrase The passphrase
2992 * @return 0 on success, otherwise negative error value.
2993 * @retval #TETHERING_ERROR_NONE Successful
2994 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2995 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2996 * @see tethering_wifi_get_passphrase()
2998 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3000 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3002 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3003 "parameter(tethering) is NULL\n");
3004 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3005 "parameter(passphrase) is NULL\n");
3007 __tethering_h *th = (__tethering_h *)tethering;
3008 GDBusProxy *proxy = th->client_bus_proxy;
3009 GVariant *parameters;
3010 GError *error = NULL;
3011 int passphrase_len = 0;
3015 passphrase_len = strlen(passphrase);
3016 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3017 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3018 ERR("parameter(passphrase) is too short or long\n");
3019 return TETHERING_ERROR_INVALID_PARAMETER;
3022 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3023 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3026 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3028 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3029 ret = TETHERING_ERROR_PERMISSION_DENIED;
3031 ret = TETHERING_ERROR_OPERATION_FAILED;
3033 g_error_free(error);
3037 g_variant_get(parameters, "(u)", &ret);
3038 g_variant_unref(parameters);
3040 if (ret == TETHERING_ERROR_NONE) {
3041 __send_dbus_signal(th->client_bus,
3042 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3051 * @brief Gets the passphrase.
3053 * @privlevel platform
3054 * @privilege http://tizen.org/privilege/tethering.admin
3055 * @remarks @a passphrase must be released with free() by you.
3056 * @param[in] tethering The handle of tethering
3057 * @param[out] passphrase The passphrase
3058 * @return 0 on success, otherwise negative error value.
3059 * @retval #TETHERING_ERROR_NONE Successful
3060 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3061 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3062 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3063 * @see tethering_wifi_set_passphrase()
3065 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3067 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3069 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3070 "parameter(tethering) is NULL\n");
3071 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3072 "parameter(passphrase) is NULL\n");
3074 __tethering_h *th = (__tethering_h *)tethering;
3075 GDBusProxy *proxy = th->client_bus_proxy;
3076 GVariant *parameters;
3077 GError *error = NULL;
3078 unsigned int len = 0;
3079 tethering_error_e ret = TETHERING_ERROR_NONE;
3081 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3082 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3085 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3087 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3088 ret = TETHERING_ERROR_PERMISSION_DENIED;
3090 ret = TETHERING_ERROR_OPERATION_FAILED;
3092 g_error_free(error);
3096 if (parameters != NULL) {
3097 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3098 g_variant_unref(parameters);
3101 return TETHERING_ERROR_NONE;
3104 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3106 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3107 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3108 "parameter(tethering) is NULL\n");
3110 __tethering_h *th = (__tethering_h *)tethering;
3111 th->channel = channel;
3113 return TETHERING_ERROR_NONE;
3116 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3118 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3119 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3120 "parameter(tethering) is NULL\n");
3122 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3123 "parameter(channel) is NULL\n");
3125 __tethering_h *th = (__tethering_h *)tethering;
3126 *channel = th->channel;
3128 return TETHERING_ERROR_NONE;
3131 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3133 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3134 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3135 "parameter(tethering) is NULL\n");
3137 __tethering_h *th = (__tethering_h *)tethering;
3139 th->mode_type = type;
3141 return TETHERING_ERROR_NONE;
3144 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3146 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3147 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3148 "parameter(tethering) is NULL\n");
3149 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3150 "parameter(type) is NULL\n");
3152 __tethering_h *th = (__tethering_h *)tethering;
3153 *type = th->mode_type;
3155 return TETHERING_ERROR_NONE;
3161 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3163 * @privlevel platform
3164 * @privilege http://tizen.org/privilege/tethering.admin
3165 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3166 * @param[in] tethering The handle of tethering
3167 * @param[in] callback The callback function to invoke
3168 * @param[in] user_data The user data to be passed to the callback function
3169 * @return 0 on success, otherwise negative error value.
3170 * @retval #TETHERING_ERROR_NONE Successful
3171 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3172 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3174 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3177 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3179 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3180 "parameter(tethering) is NULL\n");
3181 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3182 "parameter(callback) is NULL\n");
3184 __tethering_h *th = (__tethering_h *)tethering;
3185 _softap_settings_t set = {"", "", "", 0, false};
3186 GDBusProxy *proxy = th->client_bus_proxy;
3191 if (th->settings_reloaded_cb) {
3192 ERR("Operation in progress\n");
3193 return TETHERING_ERROR_OPERATION_FAILED;
3196 ret = __prepare_wifi_settings(tethering, &set);
3197 if (ret != TETHERING_ERROR_NONE) {
3198 ERR("softap settings initialization failed\n");
3199 return TETHERING_ERROR_OPERATION_FAILED;
3202 th->settings_reloaded_cb = callback;
3203 th->settings_reloaded_user_data = user_data;
3205 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3206 g_variant_new("(sssiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.sec_type),
3207 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3208 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3210 return TETHERING_ERROR_NONE;
3213 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3215 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3217 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3218 "parameter(tethering) is NULL\n");
3220 __tethering_h *th = (__tethering_h *)tethering;
3221 th->mac_filter = mac_filter;
3223 return TETHERING_ERROR_NONE;
3226 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3228 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3230 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3231 "parameter(mac_filter) is NULL\n");
3233 __tethering_h *th = (__tethering_h *)tethering;
3234 *mac_filter = th->mac_filter;
3236 return TETHERING_ERROR_NONE;
3239 static int __add_mac_to_file(const char *filepath, const char *mac)
3242 char line[MAX_BUF_SIZE] = "\0";
3243 bool mac_exist = false;
3245 fp = fopen(filepath, "a+");
3247 ERR("fopen is failed\n");
3248 return TETHERING_ERROR_OPERATION_FAILED;
3251 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3252 if (strncmp(mac, line, 17) == 0) {
3253 DBG("MAC %s already exist in the list\n", mac);
3260 fprintf(fp, "%s\n", mac);
3264 return TETHERING_ERROR_NONE;
3267 static int __remove_mac_from_file(const char *filepath, const char *mac)
3271 char line[MAX_BUF_SIZE] = "\0";
3273 fp = fopen(filepath, "r");
3275 ERR("fopen is failed\n");
3276 return TETHERING_ERROR_OPERATION_FAILED;
3279 fp1 = fopen(TEMP_LIST, "w+");
3282 ERR("fopen is failed\n");
3283 return TETHERING_ERROR_OPERATION_FAILED;
3286 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3287 if (strncmp(mac, line, 17) == 0)
3288 DBG("MAC %s found in the list\n", mac);
3290 fprintf(fp1, "%s", line);
3296 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3297 rename(TEMP_LIST, ALLOWED_LIST);
3298 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3299 rename(TEMP_LIST, BLOCKED_LIST);
3301 return TETHERING_ERROR_NONE;
3304 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3306 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3308 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3309 "parameter(tethering) is NULL\n");
3310 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3311 "parameter(mac) is NULL\n");
3313 return __add_mac_to_file(ALLOWED_LIST, mac);
3316 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3318 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3319 "parameter(tethering) is NULL\n");
3320 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3321 "parameter(mac) is NULL\n");
3323 return __remove_mac_from_file(ALLOWED_LIST, mac);
3326 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3328 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3329 "parameter(tethering) is NULL\n");
3330 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3331 "parameter(mac) is NULL\n");
3333 return __add_mac_to_file(BLOCKED_LIST, mac);
3336 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3338 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3339 "parameter(tethering) is NULL\n");
3340 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3341 "parameter(mac) is NULL\n");
3343 return __remove_mac_from_file(BLOCKED_LIST, mac);
3348 * @brief Sets the security type of Wi-Fi AP.
3350 * @privlevel platform
3351 * @privilege http://tizen.org/privilege/tethering.admin
3352 * @details If security type is not set, WPA2_PSK is used
3353 * @param[in] tethering The handle of tethering
3354 * @param[in] type The security type
3355 * @return 0 on success, otherwise negative error value.
3356 * @retval #TETHERING_ERROR_NONE Successful
3357 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3358 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3359 * @see tethering_wifi_ap_get_security_type()
3361 API int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
3363 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3365 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3366 "parameter(tethering) is NULL\n");
3368 __tethering_h *th = (__tethering_h *)tethering;
3369 th->sec_type = type;
3370 return TETHERING_ERROR_NONE;
3375 * @brief Gets the security type of Wi-Fi AP.
3377 * @privlevel platform
3378 * @privilege http://tizen.org/privilege/tethering.admin
3379 * @details If security type is not set, WPA2_PSK is used
3380 * @param[in] tethering The handle of tethering
3381 * @param[out] type The security type
3382 * @return 0 on success, otherwise negative error value.
3383 * @retval #TETHERING_ERROR_NONE Successful
3384 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3385 * @see tethering_wifi_ap_set_security_type()
3387 API int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3389 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3391 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3392 "parameter(type) is NULL\n");
3394 __tethering_h *th = (__tethering_h *)tethering;
3396 *type = th->sec_type;
3397 return TETHERING_ERROR_NONE;
3402 * @brief Sets the SSID (service set identifier) for Wi-Fi AP. The SSID cannot exceed 32 bytes.
3404 * @privlevel platform
3405 * @privilege http://tizen.org/privilege/tethering.admin
3406 * @details If SSID is not set, Device name is used as SSID
3407 * @param[in] tethering The handle of tethering
3408 * @param[in] ssid The SSID
3409 * @return 0 on success, otherwise negative error value.
3410 * @retval #TETHERING_ERROR_NONE Successful
3411 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3412 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3414 API int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid)
3416 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3418 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3419 "parameter(tethering) is NULL\n");
3420 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3421 "parameter(ssid) is NULL\n");
3423 __tethering_h *th = (__tethering_h *)tethering;
3424 char *p_ssid = NULL;
3427 ssid_len = strlen(ssid);
3428 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3429 ERR("parameter(ssid) is too long");
3430 return TETHERING_ERROR_INVALID_PARAMETER;
3433 p_ssid = strdup(ssid);
3434 if (p_ssid == NULL) {
3435 ERR("strdup failed\n");
3436 return TETHERING_ERROR_OUT_OF_MEMORY;
3440 g_free(th->ap_ssid);
3441 th->ap_ssid = p_ssid;
3443 return TETHERING_ERROR_NONE;
3448 * @brief Gets the SSID (service set identifier) for Wi-Fi AP.
3450 * @privlevel platform
3451 * @privilege http://tizen.org/privilege/tethering.admin
3452 * @details If SSID is not set, Device name is used as SSID
3453 * @remarks @a ssid must be released with free() by you.
3454 * @param[in] tethering The handle of tethering
3455 * @param[out] ssid The SSID
3456 * @return 0 on success, otherwise negative error value.
3457 * @retval #TETHERING_ERROR_NONE Successful
3458 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3459 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3461 API int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid)
3463 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3465 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3466 "parameter(tethering) is NULL\n");
3467 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3468 "parameter(ssid) is NULL\n");
3470 __tethering_h *th = (__tethering_h *)tethering;
3472 *ssid = g_strdup(th->ap_ssid);
3473 if (*ssid == NULL) {
3474 ERR("strdup failed\n");
3475 return TETHERING_ERROR_OUT_OF_MEMORY;
3478 return TETHERING_ERROR_NONE;
3483 * @brief Sets the visibility of SSID(service set identifier) for Wi-Fi AP.
3485 * @privlevel platform
3486 * @privilege http://tizen.org/privilege/tethering.admin
3487 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3488 * @details by default visibility is set to true.
3489 * @remarks This change is applied next time Wi-Fi tethering is enabled
3490 * @param[in] tethering The handle of tethering
3491 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3492 * @return 0 on success, otherwise negative error value.
3493 * @retval #TETHERING_ERROR_NONE Successful
3494 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3495 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3496 * @see tethering_wifi_ap_get_ssid_visibility()
3498 API int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible)
3500 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3502 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3503 "parameter(tethering) is NULL\n");
3505 __tethering_h *th = (__tethering_h *)tethering;
3506 th->visibility = visible;
3507 return TETHERING_ERROR_NONE;
3512 * @brief Gets the visibility of SSID(service set identifier) for Wi-Fi AP.
3514 * @privlevel platform
3515 * @privilege http://tizen.org/privilege/tethering.admin
3516 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3517 * @details by default visibility is set to true.
3518 * @param[in] tethering The handle of tethering
3519 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3520 * @return 0 on success, otherwise negative error value.
3521 * @retval #TETHERING_ERROR_NONE Successful
3522 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3523 * @see tethering_wifi_ap_set_ssid_visibility()
3525 API int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible)
3527 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3529 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3530 "parameter(visible) is NULL\n");
3532 __tethering_h *th = (__tethering_h *)tethering;
3534 *visible = th->visibility;
3535 return TETHERING_ERROR_NONE;
3540 * @brief Sets the passphrase for Wi-Fi AP.
3542 * @privlevel platform
3543 * @privilege http://tizen.org/privilege/tethering.admin
3544 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3545 * @param[in] tethering The handle of tethering
3546 * @param[in] passphrase The passphrase
3547 * @return 0 on success, otherwise negative error value.
3548 * @retval #TETHERING_ERROR_NONE Successful
3549 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3550 * @see tethering_wifi_ap_get_passphrase()
3552 API int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase)
3554 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3556 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3557 "parameter(tethering) is NULL\n");
3558 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3559 "parameter(passphrase) is NULL\n");
3561 __tethering_h *th = (__tethering_h *)tethering;
3562 int passphrase_len = 0;
3564 passphrase_len = strlen(passphrase);
3566 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3567 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3568 ERR("parameter(passphrase) is too short or long\n");
3569 return TETHERING_ERROR_INVALID_PARAMETER;
3572 if (!g_strcmp0(passphrase, th->passphrase))
3573 return TETHERING_ERROR_NONE;
3575 g_strlcpy(th->passphrase, passphrase, sizeof(th->passphrase));
3576 return TETHERING_ERROR_NONE;
3581 * @brief Gets the passphrase for Wi-Fi AP.
3583 * @privlevel platform
3584 * @privilege http://tizen.org/privilege/tethering.admin
3585 * @details If the passphrase is not set, random string of 8 alphabets will be used.
3586 * @remarks @a passphrase must be released with free() by you.
3587 * @param[in] tethering The handle of tethering
3588 * @param[out] passphrase The passphrase
3589 * @return 0 on success, otherwise negative error value.
3590 * @retval #TETHERING_ERROR_NONE Successful
3591 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3592 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3593 * @see tethering_wifi_ap_set_passphrase()
3595 API int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase)
3597 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3599 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3600 "parameter(tethering) is NULL\n");
3601 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3602 "parameter(passphrase) is NULL\n");
3604 __tethering_h *th = (__tethering_h *)tethering;
3606 *passphrase = g_strdup(th->passphrase);
3607 if (*passphrase == NULL) {
3608 ERR("strdup is failed\n");
3609 return TETHERING_ERROR_OUT_OF_MEMORY;
3612 return TETHERING_ERROR_NONE;
3617 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP.
3619 * @privlevel platform
3620 * @privilege http://tizen.org/privilege/tethering.admin
3621 * @remarks Connected devices via MobileAP will be disconnected when the settings are reloaded
3622 * @param[in] tethering The handle of tethering
3623 * @param[in] callback The callback function to invoke
3624 * @param[in] user_data The user data to be passed to the callback function
3625 * @return 0 on success, otherwise negative error value.
3626 * @retval #TETHERING_ERROR_NONE Successful
3627 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3628 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3630 API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data)
3633 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
3635 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3636 "parameter(tethering) is NULL\n");
3637 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3638 "parameter(callback) is NULL\n");
3640 __tethering_h *th = (__tethering_h *)tethering;
3641 _softap_settings_t set = {"", "", "", 0, false};
3642 GDBusProxy *proxy = th->client_bus_proxy;
3647 if (th->ap_settings_reloaded_cb) {
3648 ERR("Operation in progress\n");
3649 return TETHERING_ERROR_OPERATION_FAILED;
3652 ret = __prepare_wifi_ap_settings(tethering, &set);
3653 if (ret != TETHERING_ERROR_NONE) {
3654 ERR("softap settings initialization failed\n");
3655 return TETHERING_ERROR_OPERATION_FAILED;
3658 th->ap_settings_reloaded_cb = callback;
3659 th->ap_settings_reloaded_user_data = user_data;
3661 g_dbus_proxy_call(proxy, "reload_wifi_ap_settings",
3662 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
3663 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3664 (GAsyncReadyCallback) __ap_settings_reloaded_cb, (gpointer)tethering);
3666 return TETHERING_ERROR_NONE;