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 <tzplatform_config.h>
33 #include "tethering_private.h"
35 #define ALLOWED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.accept")
36 #define BLOCKED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.deny")
37 #define TEMP_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/.hostapd_tmp")
38 #define MAC_ADDR_LEN 18
39 #define MAX_BUF_SIZE 80
41 #define IPTABLES "/usr/sbin/iptables"
42 #define TABLE_NAT "nat"
43 #define TETH_NAT_PRE "teth_nat_pre"
44 #define TABLE_FILTER "filter"
45 #define TETH_FILTER_FW "teth_filter_fw"
46 #define ACTION_DROP "DROP"
47 #define ACTION_ACCEPT "ACCEPT"
48 #define PORT_FORWARD_RULE_STR "-t %s -A %s -i %s -p %s -d %s --dport %d -j DNAT --to %s:%d"
49 #define FILTERING_MULTIPORT_RULE_STR "-t %s -A %s -p %s -m multiport --dport %d,%d -j %s"
50 #define FILTERING_RULE_STR "-t %s -A %s -p %s --dport %d -j %s"
52 static GSList *allowed_list = NULL;
53 static GSList *blocked_list = NULL;
54 static GSList *port_forwarding = NULL;
55 static GSList *port_filtering = NULL;
56 static GSList *custom_port_filtering = NULL;
58 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
59 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
60 GVariant *parameters, gpointer user_data);
62 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
63 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
64 GVariant *parameters, gpointer user_data);
66 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
67 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
68 GVariant *parameters, gpointer user_data);
70 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
71 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
72 GVariant *parameters, gpointer user_data);
74 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
75 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
76 GVariant *parameters, gpointer user_data);
78 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
79 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
80 GVariant *parameters, gpointer user_data);
82 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
83 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
84 GVariant *parameters, gpointer user_data);
86 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
87 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
88 GVariant *parameters, gpointer user_data);
90 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
91 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
92 GVariant *parameters, gpointer user_data);
94 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
95 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
96 GVariant *parameters, gpointer user_data);
98 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
99 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
100 GVariant *parameters, gpointer user_data);
102 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
103 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
104 GVariant *parameters, gpointer user_data);
106 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
107 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
108 GVariant *parameters, gpointer user_data);
110 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
111 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
112 GVariant *parameters, gpointer user_data);
114 static __tethering_sig_t sigs[] = {
115 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
116 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
117 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
118 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
119 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
120 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
121 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
122 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
123 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
124 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
125 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
126 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
127 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
128 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
130 static int retry = 0;
132 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
134 if (conn == NULL || signal_name == NULL)
135 return; //LCOV_EXCL_LINE
137 GVariant *message = NULL;
138 GError *error = NULL;
141 message = g_variant_new("(s)", arg);
143 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
144 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
146 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
147 g_error_free(error); //LCOV_EXCL_LINE
149 g_variant_unref(message);
152 static bool __any_tethering_is_enabled(tethering_h tethering)
154 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
155 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
156 tethering_is_enabled(tethering, TETHERING_TYPE_BT))
162 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
164 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
165 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
166 security_type != TETHERING_WIFI_SECURITY_TYPE_WPS) {
167 ERR("Invalid param\n");
168 return TETHERING_ERROR_INVALID_PARAMETER;
171 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
172 ERR("vconf_set_int is failed\n");
173 return TETHERING_ERROR_OPERATION_FAILED;
176 return TETHERING_ERROR_NONE;
179 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
181 if (security_type == NULL) {
182 ERR("Invalid param\n");
183 return TETHERING_ERROR_INVALID_PARAMETER;
186 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
187 (int *)security_type) < 0) {
188 ERR("vconf_get_int is failed\n");
189 return TETHERING_ERROR_OPERATION_FAILED;
192 return TETHERING_ERROR_NONE;
195 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
197 if (path == NULL || ssid == NULL || size == 0)
201 char *ptr_tmp = NULL;
203 ptr = vconf_get_str(path);
207 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
210 g_strlcpy(ssid, ptr, size);
216 static tethering_error_e __set_visible(const bool visible)
218 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
219 ERR("vconf_set_int is failed\n");
220 return TETHERING_ERROR_OPERATION_FAILED;
223 return TETHERING_ERROR_NONE;
226 static tethering_error_e __get_visible(bool *visible)
228 if (visible == NULL) {
229 ERR("Invalid param\n");
230 return TETHERING_ERROR_INVALID_PARAMETER;
235 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
236 ERR("vconf_get_int is failed\n");
237 return TETHERING_ERROR_OPERATION_FAILED;
244 return TETHERING_ERROR_NONE;
247 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
249 if (passphrase == NULL ||
250 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
253 guint32 rand_int = 0;
256 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
257 rand_int = g_random_int_range('a', 'z');
258 passphrase[index] = rand_int;
260 passphrase[index] = '\0';
265 static tethering_error_e __get_error(int agent_error)
267 tethering_error_e err = TETHERING_ERROR_NONE;
269 switch (agent_error) {
270 case MOBILE_AP_ERROR_NONE:
271 err = TETHERING_ERROR_NONE;
275 case MOBILE_AP_ERROR_RESOURCE:
276 err = TETHERING_ERROR_OUT_OF_MEMORY;
280 case MOBILE_AP_ERROR_INTERNAL:
281 err = TETHERING_ERROR_OPERATION_FAILED;
284 case MOBILE_AP_ERROR_INVALID_PARAM:
285 err = TETHERING_ERROR_INVALID_PARAMETER;
288 case MOBILE_AP_ERROR_ALREADY_ENABLED:
289 err = TETHERING_ERROR_OPERATION_FAILED;
292 case MOBILE_AP_ERROR_NOT_ENABLED:
293 err = TETHERING_ERROR_NOT_ENABLED;
296 case MOBILE_AP_ERROR_NET_OPEN:
297 err = TETHERING_ERROR_OPERATION_FAILED;
300 case MOBILE_AP_ERROR_NET_CLOSE:
301 err = TETHERING_ERROR_OPERATION_FAILED;
304 case MOBILE_AP_ERROR_DHCP:
305 err = TETHERING_ERROR_OPERATION_FAILED;
308 case MOBILE_AP_ERROR_IN_PROGRESS:
309 err = TETHERING_ERROR_OPERATION_FAILED;
313 case MOBILE_AP_ERROR_NOT_PERMITTED:
314 err = TETHERING_ERROR_NOT_PERMITTED;
317 case MOBILE_AP_ERROR_PERMISSION_DENIED:
318 err = TETHERING_ERROR_PERMISSION_DENIED;
322 ERR("Not defined error : %d\n", agent_error);
323 err = TETHERING_ERROR_OPERATION_FAILED;
331 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
332 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
333 GVariant *parameters, gpointer user_data)
337 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
339 __tethering_h *th = (__tethering_h *)user_data;
341 tethering_type_e type = 0;
342 mobile_ap_type_e ap_type = 0;
343 tethering_connection_state_changed_cb ccb = NULL;
344 __tethering_client_h client;
352 memset(&client, 0, sizeof(__tethering_client_h));
353 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
355 if (!g_strcmp0(buf, "DhcpConnected")) {
357 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
360 ERR("Unknown event [%s]\n", buf);
364 if (ap_type == MOBILE_AP_TYPE_USB)
365 type = TETHERING_TYPE_USB;
366 else if (ap_type == MOBILE_AP_TYPE_WIFI)
367 type = TETHERING_TYPE_WIFI;
368 else if (ap_type == MOBILE_AP_TYPE_BT)
369 type = TETHERING_TYPE_BT;
371 ERR("Not supported tethering type [%d]\n", ap_type);
375 ccb = th->changed_cb[type];
378 data = th->changed_user_data[type];
380 client.interface = type;
381 g_strlcpy(client.ip, ip, sizeof(client.ip));
382 g_strlcpy(client.mac, mac, sizeof(client.mac));
384 client.hostname = g_strdup(name);
385 client.tm = (time_t)timestamp;
387 ccb((tethering_client_h)&client, opened, data);
388 g_free(client.hostname);
399 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
400 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
401 GVariant *parameters, gpointer user_data)
405 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
407 __tethering_h *th = (__tethering_h *)user_data;
408 tethering_type_e type = 0;
409 tethering_disabled_cb dcb = NULL;
411 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
413 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
414 dcb = th->disabled_cb[type];
417 data = th->disabled_user_data[type];
419 dcb(TETHERING_ERROR_NONE, type, code, data);
426 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
427 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
428 GVariant *parameters, gpointer user_data)
432 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
434 __tethering_h *th = (__tethering_h *)user_data;
435 tethering_type_e type = TETHERING_TYPE_WIFI;
436 bool is_requested = false;
437 tethering_enabled_cb ecb = NULL;
440 ecb = th->enabled_cb[type];
443 data = th->enabled_user_data[type];
445 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
449 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
450 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
451 GVariant *parameters, gpointer user_data)
455 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
457 __tethering_h *th = (__tethering_h *)user_data;
458 tethering_type_e type = TETHERING_TYPE_WIFI;
459 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
460 tethering_disabled_cb dcb = NULL;
464 dcb = th->disabled_cb[type];
467 data = th->disabled_user_data[type];
468 g_variant_get(parameters, "(s)", &buf);
469 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
470 code = TETHERING_DISABLED_BY_WIFI_ON;
471 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
472 code = TETHERING_DISABLED_BY_TIMEOUT;
475 dcb(TETHERING_ERROR_NONE, type, code, data);
481 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
482 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
483 GVariant *parameters, gpointer user_data)
487 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
489 __tethering_h *th = (__tethering_h *)user_data;
490 tethering_type_e type = TETHERING_TYPE_USB;
491 bool is_requested = false;
492 tethering_enabled_cb ecb = NULL;
495 ecb = th->enabled_cb[type];
498 data = th->enabled_user_data[type];
500 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
504 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
505 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
506 GVariant *parameters, gpointer user_data)
510 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
512 __tethering_h *th = (__tethering_h *)user_data;
513 tethering_type_e type = TETHERING_TYPE_USB;
514 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
515 tethering_disabled_cb dcb = NULL;
519 dcb = th->disabled_cb[type];
522 data = th->disabled_user_data[type];
524 g_variant_get(parameters, "(s)", &buf);
525 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
526 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
528 dcb(TETHERING_ERROR_NONE, type, code, data);
534 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
535 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
536 GVariant *parameters, gpointer user_data)
540 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
542 __tethering_h *th = (__tethering_h *)user_data;
543 tethering_type_e type = TETHERING_TYPE_BT;
544 bool is_requested = false;
545 tethering_enabled_cb ecb = NULL;
548 ecb = th->enabled_cb[type];
551 data = th->enabled_user_data[type];
553 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
557 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
558 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
559 GVariant *parameters, gpointer user_data)
563 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
565 __tethering_h *th = (__tethering_h *)user_data;
566 tethering_type_e type = TETHERING_TYPE_BT;
567 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
568 tethering_disabled_cb dcb = NULL;
572 dcb = th->disabled_cb[type];
575 data = th->disabled_user_data[type];
576 g_variant_get(parameters, "(s)", &buf);
577 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
578 code = TETHERING_DISABLED_BY_BT_OFF;
579 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
580 code = TETHERING_DISABLED_BY_TIMEOUT;
582 dcb(TETHERING_ERROR_NONE, type, code, data);
589 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
590 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
591 GVariant *parameters, gpointer user_data)
595 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
597 __tethering_h *th = (__tethering_h *)user_data;
598 tethering_type_e type = 0;
599 tethering_disabled_cb dcb = NULL;
601 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
603 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
604 dcb = th->disabled_cb[type];
607 data = th->disabled_user_data[type];
609 dcb(TETHERING_ERROR_NONE, type, code, data);
614 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
615 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
616 GVariant *parameters, gpointer user_data)
620 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
622 __tethering_h *th = (__tethering_h *)user_data;
623 tethering_type_e type = 0;
624 tethering_disabled_cb dcb = NULL;
626 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
628 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
629 dcb = th->disabled_cb[type];
632 data = th->disabled_user_data[type];
634 dcb(TETHERING_ERROR_NONE, type, code, data);
639 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
640 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
641 GVariant *parameters, gpointer user_data)
645 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
647 __tethering_h *th = (__tethering_h *)user_data;
648 tethering_type_e type = 0;
649 tethering_disabled_cb dcb = NULL;
651 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
653 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
654 dcb = th->disabled_cb[type];
657 data = th->disabled_user_data[type];
659 dcb(TETHERING_ERROR_NONE, type, code, data);
665 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
666 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
667 GVariant *parameters, gpointer user_data)
672 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
673 __tethering_h *th = (__tethering_h *)user_data;
675 tethering_wifi_security_type_changed_cb scb = NULL;
677 tethering_wifi_security_type_e security_type;
680 scb = th->security_type_changed_cb;
684 g_variant_get(parameters, "(s)", &buf);
685 data = th->security_type_user_data;
686 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
687 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
688 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
689 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
690 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
691 security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
693 SERR("Unknown type : %s\n", buf);
698 scb(security_type, data);
703 static void __handle_ssid_visibility_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)
709 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
710 __tethering_h *th = (__tethering_h *)user_data;
712 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
714 bool visible = false;
717 scb = th->ssid_visibility_changed_cb;
722 g_variant_get(parameters, "(s)", &buf);
723 data = th->ssid_visibility_user_data;
724 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
732 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
733 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
734 GVariant *parameters, gpointer user_data)
738 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
739 __tethering_h *th = (__tethering_h *)user_data;
741 tethering_wifi_passphrase_changed_cb pcb = NULL;
744 pcb = th->passphrase_changed_cb;
748 data = th->passphrase_user_data;
754 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
759 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
760 GError *g_error = NULL;
763 tethering_error_e error;
764 __tethering_h *th = (__tethering_h *)user_data;
765 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
766 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
768 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
771 ERR("DBus error [%s]\n", g_error->message);
772 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
773 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
774 g_error_free(g_error);
775 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
777 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
778 error = TETHERING_ERROR_PERMISSION_DENIED;
780 error = TETHERING_ERROR_OPERATION_FAILED;
781 g_error_free(g_error);
784 g_variant_get(g_var, "(u)", &info);
785 error = __get_error(info);
789 INFO("cfm event : wifi tethering enable info : %d\n", error);
791 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
792 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
793 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
794 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
800 ecb(error, TETHERING_TYPE_WIFI, true, data);
801 g_variant_unref(g_var);
805 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
809 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
810 GError *g_error = NULL;
813 tethering_error_e error;
815 __tethering_h *th = (__tethering_h *)user_data;
816 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
817 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
819 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
822 ERR("DBus error [%s]\n", g_error->message);
823 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
824 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
825 g_error_free(g_error);
826 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
830 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
831 error = TETHERING_ERROR_PERMISSION_DENIED;
833 error = TETHERING_ERROR_OPERATION_FAILED;
834 g_error_free(g_error);
837 g_variant_get(g_var, "(u)", &info);
838 g_variant_unref(g_var);
839 error = __get_error(info);
843 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
844 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
845 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
846 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
853 ecb(error, TETHERING_TYPE_BT, true, data);
858 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
863 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
864 __tethering_h *th = (__tethering_h *)user_data;
865 GError *g_error = NULL;
868 tethering_error_e error;
869 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
870 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
872 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
874 ERR("DBus error [%s]\n", g_error->message);
875 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
876 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
877 g_error_free(g_error);
878 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
882 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
883 error = TETHERING_ERROR_PERMISSION_DENIED;
885 error = TETHERING_ERROR_OPERATION_FAILED;
886 g_error_free(g_error);
888 g_variant_get(g_var, "(u)", &info);
889 g_variant_unref(g_var);
890 error = __get_error(info);
894 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
895 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
896 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
897 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
904 ecb(error, TETHERING_TYPE_USB, true, data);
909 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
914 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
915 GError *g_error = NULL;
917 guint info, event_type;
918 tethering_error_e error;
919 tethering_type_e type;
920 tethering_h tethering = (tethering_h)user_data;
921 __tethering_h *th = (__tethering_h *)tethering;
922 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
923 tethering_disabled_cb dcb = NULL;
926 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
929 ERR("DBus error [%s]\n", g_error->message);
930 g_error_free(g_error);
934 g_variant_get(g_var, "(uu)", &event_type, &info);
935 INFO("cfm event : %d info : %d\n", event_type, info);
936 g_variant_unref(g_var);
937 error = __get_error(info);
938 INFO("cfm event : %d info : %d\n", event_type, error);
939 switch (event_type) {
940 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
941 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
942 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
943 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
944 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
946 type = TETHERING_TYPE_WIFI;
947 dcb = th->disabled_cb[type];
948 data = th->disabled_user_data[type];
950 dcb(error, type, code, data);
953 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
954 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
955 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
956 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
957 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
959 type = TETHERING_TYPE_BT;
960 dcb = th->disabled_cb[type];
961 data = th->disabled_user_data[type];
963 dcb(error, type, code, data);
967 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
968 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
969 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
970 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
971 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
973 type = TETHERING_TYPE_USB;
974 dcb = th->disabled_cb[type];
975 data = th->disabled_user_data[type];
977 dcb(error, type, code, data);
981 case MOBILE_AP_DISABLE_CFM:
983 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
984 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
985 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
986 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
987 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
988 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
989 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
990 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
991 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
992 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
993 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
994 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
996 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
997 dcb = th->disabled_cb[type];
1000 data = th->disabled_user_data[type];
1002 dcb(error, type, code, data);
1007 ERR("Invalid event\n");
1013 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1018 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1020 GError *g_error = NULL;
1023 guint64 tx_bytes, rx_bytes;
1024 __tethering_h *th = (__tethering_h *)user_data;
1025 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1028 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1031 ERR("DBus fail [%s]\n", g_error->message);
1032 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1033 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1035 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1040 if (th->data_usage_cb == NULL) {
1041 ERR("There is no data_usage_cb\n");
1045 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1047 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1048 th->data_usage_cb(TETHERING_ERROR_NONE,
1049 rx_bytes, tx_bytes, th->data_usage_user_data);
1050 g_variant_unref(g_var);
1052 th->data_usage_cb = NULL;
1053 th->data_usage_user_data = NULL;
1058 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1063 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1064 GError *g_error = NULL;
1067 __tethering_h *th = (__tethering_h *)user_data;
1068 tethering_error_e tethering_error;
1070 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1072 ERR("DBus fail [%s]\n", g_error->message);
1073 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1074 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1076 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1077 g_error_free(g_error);
1079 if (th->settings_reloaded_cb == NULL) {
1080 DBG("There is no settings_reloaded_cb\n-\n");
1083 g_variant_get(g_var, "(u)", &info);
1084 tethering_error = __get_error(info);
1085 g_variant_unref(g_var);
1087 th->settings_reloaded_cb(tethering_error,
1088 th->settings_reloaded_user_data);
1090 th->settings_reloaded_cb = NULL;
1091 th->settings_reloaded_user_data = NULL;
1095 static void __connect_signals(tethering_h tethering)
1098 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1100 __tethering_h *th = (__tethering_h *)tethering;
1101 GDBusConnection *connection = th->client_bus;
1104 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1105 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1106 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1107 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1108 sigs[i].cb, tethering, NULL);
1113 static void __disconnect_signals(tethering_h tethering)
1117 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1119 __tethering_h *th = (__tethering_h *)tethering;
1120 GDBusConnection *connection = th->client_bus;
1124 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1125 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1131 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1133 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1137 case TETHERING_TYPE_USB:
1138 g_strlcpy(buf, TETHERING_USB_IF, len);
1141 case TETHERING_TYPE_WIFI:
1142 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1145 case TETHERING_TYPE_BT:
1146 g_strlcpy(buf, TETHERING_BT_IF, len);
1150 ERR("Not supported type : %d\n", type);
1156 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1158 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1161 case TETHERING_TYPE_USB:
1162 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1165 case TETHERING_TYPE_WIFI:
1166 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1169 case TETHERING_TYPE_BT:
1170 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1174 ERR("Not supported type : %d\n", type);
1180 static int __get_common_ssid(char *ssid, unsigned int size)
1183 ERR("ssid is null\n"); //LCOV_EXCL_LINE
1184 return TETHERING_ERROR_INVALID_PARAMETER;
1188 char *ptr_tmp = NULL;
1190 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1192 ERR("vconf_get_str is failed and set default ssid");
1193 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1195 g_strlcpy(ssid, ptr, size);
1199 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1202 return TETHERING_ERROR_NONE;
1205 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1207 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1210 case TETHERING_WIFI_MODE_TYPE_B:
1211 *buf = g_strdup("b");
1213 case TETHERING_WIFI_MODE_TYPE_G:
1214 *buf = g_strdup("g");
1216 case TETHERING_WIFI_MODE_TYPE_A:
1217 *buf = g_strdup("a");
1219 case TETHERING_WIFI_MODE_TYPE_AD:
1220 *buf = g_strdup("ad");
1223 ERR("Not supported type : %d\n", type);
1229 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1233 __tethering_h *th = (__tethering_h *)tethering;
1234 tethering_error_e ret = TETHERING_ERROR_NONE;
1237 if (th == NULL || set == NULL) {
1238 ERR("null parameter\n-\n");
1239 return TETHERING_ERROR_INVALID_PARAMETER;
1242 if (th->ssid == NULL)
1243 __get_common_ssid(set->ssid, sizeof(set->ssid));
1245 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1247 ret = __get_security_type(&set->sec_type);
1248 if (ret != TETHERING_ERROR_NONE)
1249 set->sec_type = th->sec_type;
1251 ret = __get_visible(&set->visibility);
1252 if (ret != TETHERING_ERROR_NONE)
1253 set->visibility = th->visibility;
1255 set->mac_filter = th->mac_filter;
1256 set->max_connected = th->wifi_max_connected;
1257 set->channel = th->channel;
1259 __get_wifi_mode_type(th->mode_type, &ptr);
1261 g_strlcpy(set->mode, "", sizeof(set->mode));
1263 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1267 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1268 g_strlcpy(set->key, "", sizeof(set->key));
1270 GDBusProxy *proxy = th->client_bus_proxy;
1271 GVariant *parameters;
1272 GError *error = NULL;
1273 char *passphrase = NULL;
1274 unsigned int len = 0;
1276 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1277 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1281 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1283 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1284 ret = TETHERING_ERROR_PERMISSION_DENIED;
1286 ret = TETHERING_ERROR_OPERATION_FAILED;
1288 g_error_free(error);
1293 if (parameters != NULL) {
1294 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1295 g_variant_unref(parameters);
1298 g_strlcpy(set->key, passphrase, sizeof(set->key));
1301 INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
1302 set->ssid, set->sec_type, set->mode, set->channel,
1303 (set->visibility) ? "true" : "false");
1305 return TETHERING_ERROR_NONE;
1308 static bool __check_precondition(tethering_type_e type)
1311 int cellular_state = 0;
1314 /* data network through cellular */
1315 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1316 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1317 INFO("Data Network can be connected later");
1322 /* data network through ethernet */
1323 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_state);
1324 if (dnet_state == VCONFKEY_NETWORK_ETHERNET) {
1325 INFO("Data Network is connected");
1329 vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state);
1330 if (dnet_state > VCONFKEY_DNET_OFF) {
1331 INFO("Data Network is connected");
1334 #endif/*TIZEN_TV_EXT*/
1336 /* data network through wifi */
1337 if (type != TETHERING_TYPE_WIFI) {
1338 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1339 if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) {
1340 INFO("Wi-Fi is connected!");
1345 ERR("Network is not available!");
1351 * @brief Creates the handle of tethering.
1353 * @privlevel platform
1354 * @privilege http://tizen.org/privilege/tethering.admin
1355 * @remarks The @a tethering must be released tethering_destroy() by you.
1356 * @param[out] tethering A handle of a new mobile ap handle on success
1357 * @return 0 on success, otherwise a negative error value.
1358 * @retval #TETHERING_ERROR_NONE Successful
1359 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1360 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1361 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1362 * @see tethering_destroy()
1364 API int tethering_create(tethering_h *tethering)
1366 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1367 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1368 "parameter(tethering) is NULL\n");
1371 __tethering_h *th = NULL;
1372 GError *error = NULL;
1373 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1375 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1377 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1378 "malloc is failed\n");
1379 memset(th, 0x00, sizeof(__tethering_h));
1380 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1381 th->visibility = true;
1382 th->mac_filter = false;
1384 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1385 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1386 th->change_mac = false;
1388 if (__generate_initial_passphrase(th->passphrase,
1389 sizeof(th->passphrase)) == 0) {
1390 ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
1392 return TETHERING_ERROR_OPERATION_FAILED;
1395 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1396 ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
1398 return TETHERING_ERROR_OPERATION_FAILED;
1401 #if !GLIB_CHECK_VERSION(2, 36, 0)
1404 GCancellable *cancellable = g_cancellable_new();
1405 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1408 ERR("Couldn't connect to the System bus[%s]", error->message);
1409 g_error_free(error);
1410 g_cancellable_cancel(cancellable);
1411 g_object_unref(cancellable);
1413 return TETHERING_ERROR_OPERATION_FAILED;
1416 th->cancellable = cancellable;
1418 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1419 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1420 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1421 if (!th->client_bus_proxy) {
1424 ERR("Couldn't create the proxy object because of %s\n", error->message);
1425 g_cancellable_cancel(th->cancellable);
1426 g_object_unref(th->cancellable);
1427 g_object_unref(th->client_bus);
1429 return TETHERING_ERROR_OPERATION_FAILED;
1433 __connect_signals((tethering_h)th);
1435 *tethering = (tethering_h)th;
1436 INFO("Tethering Handle : 0x%X\n", th);
1438 return TETHERING_ERROR_NONE;
1443 * @brief Destroys the handle of tethering.
1445 * @privlevel platform
1446 * @privilege http://tizen.org/privilege/tethering.admin
1447 * @param[in] tethering The handle of tethering
1448 * @return 0 on success, otherwise a negative error value.
1449 * @retval #TETHERING_ERROR_NONE Successful
1450 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1451 * @see tethering_create()
1453 API int tethering_destroy(tethering_h tethering)
1456 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1457 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1458 "parameter(tethering) is NULL\n");
1460 GVariant *result = NULL;
1461 __tethering_h *th = (__tethering_h *)tethering;
1463 INFO("Tethering Handle : 0x%X\n", th);
1465 if (th->change_mac) {
1466 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "reset_mac", NULL,
1467 G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
1468 g_variant_unref(result);
1471 __disconnect_signals(tethering);
1476 g_object_unref(th->cancellable);
1477 g_object_unref(th->client_bus_proxy);
1478 g_object_unref(th->client_bus);
1479 memset(th, 0x00, sizeof(__tethering_h));
1483 return TETHERING_ERROR_NONE;
1488 * @brief Enables the tethering, asynchronously.
1490 * @privlevel platform
1491 * @privilege http://tizen.org/privilege/tethering.admin
1492 * @param[in] tethering The handle of tethering
1493 * @param[in] type The type of tethering
1494 * @return 0 on success, otherwise negative error value.
1495 * @retval #TETHERING_ERROR_NONE Successful
1496 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1497 * @post tethering_enabled_cb() will be invoked.
1498 * @see tethering_is_enabled()
1499 * @see tethering_disable()
1501 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1503 INFO("+ type : %d\n", type);
1504 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1505 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1506 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1507 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1509 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1510 "parameter(tethering) is NULL\n");
1512 tethering_error_e ret = TETHERING_ERROR_NONE;
1513 __tethering_h *th = (__tethering_h *)tethering;
1514 GDBusProxy *proxy = th->client_bus_proxy;
1515 GDBusConnection *connection = th->client_bus;
1517 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1519 if (__check_precondition(type) == FALSE) {
1522 return TETHERING_ERROR_OPERATION_FAILED;
1528 case TETHERING_TYPE_USB:
1529 g_dbus_connection_signal_unsubscribe(connection,
1530 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1532 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1533 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1534 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1538 case TETHERING_TYPE_WIFI: {
1539 _softap_settings_t set = {"", "", "", 0, false};
1541 ret = __prepare_wifi_settings(tethering, &set);
1542 if (ret != TETHERING_ERROR_NONE) {
1543 ERR("softap settings initialization failed\n");
1545 return TETHERING_ERROR_OPERATION_FAILED;
1547 g_dbus_connection_signal_unsubscribe(connection,
1548 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1550 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1551 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, TETHERING_ADDRESS_FAMILY_IPV4),
1552 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1553 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1557 case TETHERING_TYPE_BT:
1558 g_dbus_connection_signal_unsubscribe(connection,
1559 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1561 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1562 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1563 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1568 case TETHERING_TYPE_ALL: {
1569 _softap_settings_t set = {"", "", "", 0, false};
1571 ret = __prepare_wifi_settings(tethering, &set);
1572 if (ret != TETHERING_ERROR_NONE) {
1573 ERR("softap settings initialization failed\n");
1574 return TETHERING_ERROR_OPERATION_FAILED;
1577 /* TETHERING_TYPE_USB */
1578 g_dbus_connection_signal_unsubscribe(connection,
1579 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1581 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1582 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1583 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1585 /* TETHERING_TYPE_WIFI */
1586 g_dbus_connection_signal_unsubscribe(connection,
1587 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1589 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1590 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1591 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1592 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1594 /* TETHERING_TYPE_BT */
1595 g_dbus_connection_signal_unsubscribe(connection,
1596 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1598 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1599 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1600 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1605 ERR("Unknown type : %d\n", type);
1607 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1610 return TETHERING_ERROR_INVALID_PARAMETER;
1613 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1615 return TETHERING_ERROR_NONE;
1618 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1620 DBG("+ type : %d\n", type);
1621 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1622 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1623 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1624 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1626 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1627 "parameter(tethering) is NULL\n");
1629 __tethering_h *th = (__tethering_h *)tethering;
1630 GDBusProxy *proxy = th->client_bus_proxy;
1631 GDBusConnection *connection = th->client_bus;
1634 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1636 if (__check_precondition(type) == FALSE) {
1639 return TETHERING_ERROR_OPERATION_FAILED;
1645 case TETHERING_TYPE_WIFI: {
1646 _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
1648 ret = __prepare_wifi_settings(tethering, &set);
1649 if (ret != TETHERING_ERROR_NONE) {
1650 ERR("softap settings initialization failed\n");
1652 return TETHERING_ERROR_OPERATION_FAILED;
1654 g_dbus_connection_signal_unsubscribe(connection,
1655 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1656 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1657 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, TETHERING_ADDRESS_FAMILY_IPV6),
1658 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1659 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1662 case TETHERING_TYPE_BT: {
1663 g_dbus_connection_signal_unsubscribe(connection,
1664 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1667 g_dbus_proxy_call(proxy, "enable_bt_tethering", g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1668 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1669 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1675 ERR("Unknown type : %d\n", type);
1677 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1680 return TETHERING_ERROR_INVALID_PARAMETER;
1684 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1686 return TETHERING_ERROR_NONE;
1689 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
1691 DBG("+ type : %d\n", type);
1692 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1693 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1694 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1695 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1697 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1698 "parameter(tethering) is NULL\n");
1700 __tethering_h *th = (__tethering_h *)tethering;
1701 GDBusProxy *proxy = th->client_bus_proxy;
1702 GDBusConnection *connection = th->client_bus;
1705 case TETHERING_TYPE_WIFI:
1706 DBG("Disable wifi tethering..");
1707 g_dbus_connection_signal_unsubscribe(connection,
1708 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1710 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1711 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1712 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1713 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1715 case TETHERING_TYPE_BT:
1716 g_dbus_connection_signal_unsubscribe(connection,
1717 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1719 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1720 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6), G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1721 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1725 ERR("Not supported tethering type [%d]\n", type);
1727 return TETHERING_ERROR_INVALID_PARAMETER;
1730 return TETHERING_ERROR_NONE;
1734 * @brief Disables the tethering, asynchronously.
1736 * @privlevel platform
1737 * @privilege http://tizen.org/privilege/tethering.admin
1738 * @param[in] tethering The handle of tethering
1739 * @param[in] type The type of tethering
1740 * @return 0 on success, otherwise negative error value.
1741 * @retval #TETHERING_ERROR_NONE Successful
1742 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1743 * @post tethering_disabled_cb() will be invoked.
1744 * @see tethering_is_enabled()
1745 * @see tethering_enable()
1747 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1749 INFO("+ type : %d\n", type);
1750 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1751 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1752 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1753 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1755 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1756 "parameter(tethering) is NULL\n");
1758 __tethering_h *th = (__tethering_h *)tethering;
1759 GDBusProxy *proxy = th->client_bus_proxy;
1760 GDBusConnection *connection = th->client_bus;
1763 case TETHERING_TYPE_USB:
1764 g_dbus_connection_signal_unsubscribe(connection,
1765 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1767 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1768 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1769 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1773 case TETHERING_TYPE_WIFI:
1775 g_dbus_connection_signal_unsubscribe(connection,
1776 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1778 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1779 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1780 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1783 case TETHERING_TYPE_BT:
1785 g_dbus_connection_signal_unsubscribe(connection,
1786 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1788 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1789 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1790 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1793 case TETHERING_TYPE_ALL:
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);
1801 g_dbus_connection_signal_unsubscribe(connection,
1802 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1804 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1805 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1806 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1808 g_dbus_connection_signal_unsubscribe(connection,
1809 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1811 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1812 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1813 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1817 ERR("Not supported tethering type [%d]\n", type);
1819 return TETHERING_ERROR_INVALID_PARAMETER;
1822 return TETHERING_ERROR_NONE;
1827 * @brief Checks whetehr the tethering is enabled or not.
1829 * @privlevel platform
1830 * @privilege http://tizen.org/privilege/tethering.admin
1831 * @param[in] tethering The handle of tethering
1832 * @param[in] type The type of tethering
1833 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1835 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1837 INFO("+ type : %d\n", type);
1839 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1841 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1843 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1847 case TETHERING_TYPE_USB:
1848 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1851 case TETHERING_TYPE_WIFI:
1852 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1855 case TETHERING_TYPE_BT:
1856 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1860 ERR("Not supported type : %d\n", type);
1863 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
1864 return is_on & vconf_type ? true : false;
1869 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1871 * @privlevel platform
1872 * @privilege http://tizen.org/privilege/tethering.admin
1873 * @remarks @a mac_address must be released with free() by you.
1874 * @param[in] tethering The handle of tethering
1875 * @param[in] type The type of tethering
1876 * @param[out] mac_address The MAC address
1877 * @return 0 on success, otherwise a negative error value.
1878 * @retval #TETHERING_ERROR_NONE Successful
1879 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1880 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1881 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1882 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1883 * @pre tethering must be enabled.
1884 * @see tethering_is_enabled()
1885 * @see tethering_enable()
1887 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1889 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1890 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1891 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1892 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1894 _retvm_if(tethering_is_enabled(tethering, type) == false,
1895 TETHERING_ERROR_NOT_ENABLED,
1896 "tethering type[%d] is not enabled\n", type);
1897 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1898 "parameter(tethering) is NULL\n");
1899 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1900 "parameter(mac_address) is NULL\n");
1904 char *macbuf = NULL;
1906 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1907 TETHERING_ERROR_OPERATION_FAILED,
1908 "getting interface name is failed\n");
1910 s = socket(AF_INET, SOCK_DGRAM, 0);
1911 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1912 "getting socket is failed\n");
1913 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1914 ERR("getting mac is failed\n");
1916 return TETHERING_ERROR_OPERATION_FAILED;
1920 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1921 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1922 "Not enough memory\n");
1923 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1924 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1925 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1926 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1927 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1928 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1929 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1931 *mac_address = macbuf;
1933 return TETHERING_ERROR_NONE;
1938 * @brief Gets the name of network interface. For example, usb0.
1940 * @privlevel platform
1941 * @privilege http://tizen.org/privilege/tethering.admin
1942 * @remarks @a interface_name must be released with free() by you.
1943 * @param[in] tethering The handle of tethering
1944 * @param[in] type The type of tethering
1945 * @param[out] interface_name The name of network interface
1946 * @return 0 on success, otherwise negative error value.
1947 * @retval #TETHERING_ERROR_NONE Successful
1948 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1949 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1950 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1951 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1952 * @pre tethering must be enabled.
1953 * @see tethering_is_enabled()
1954 * @see tethering_enable()
1956 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1958 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1959 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1960 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1961 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1963 _retvm_if(tethering_is_enabled(tethering, type) == false,
1964 TETHERING_ERROR_NOT_ENABLED,
1965 "tethering type[%d] is not enabled\n", type);
1966 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1967 "parameter(tethering) is NULL\n");
1968 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1969 "parameter(interface_name) is NULL\n");
1971 char intf[TETHERING_STR_INFO_LEN] = {0, };
1973 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1974 TETHERING_ERROR_OPERATION_FAILED,
1975 "getting interface name is failed\n");
1976 *interface_name = strdup(intf);
1977 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1978 "Not enough memory\n");
1980 return TETHERING_ERROR_NONE;
1985 * @brief Gets the local IP address.
1987 * @privlevel platform
1988 * @privilege http://tizen.org/privilege/tethering.admin
1989 * @remarks @a ip_address must be released with free() by you.
1990 * @param[in] tethering The handle of tethering
1991 * @param[in] type The type of tethering
1992 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1993 * @param[out] ip_address The local IP address
1994 * @return 0 on success, otherwise negative error value.
1995 * @retval #TETHERING_ERROR_NONE Successful
1996 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1997 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1998 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1999 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2000 * @pre tethering must be enabled.
2001 * @see tethering_is_enabled()
2002 * @see tethering_enable()
2004 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2006 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2007 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2008 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2009 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2011 _retvm_if(tethering_is_enabled(tethering, type) == false,
2012 TETHERING_ERROR_NOT_ENABLED,
2013 "tethering type[%d] is not enabled\n", type);
2014 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2015 "parameter(tethering) is NULL\n");
2016 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2017 "parameter(ip_address) is NULL\n");
2023 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2024 TETHERING_ERROR_OPERATION_FAILED,
2025 "getting interface name is failed\n");
2027 s = socket(AF_INET, SOCK_DGRAM, 0);
2028 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2029 "getting socket is failed\n");
2030 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2031 ERR("ioctl is failed\n");
2033 return TETHERING_ERROR_OPERATION_FAILED;
2037 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2038 *ip_address = strdup(ipbuf);
2039 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2040 "Not enough memory\n");
2042 return TETHERING_ERROR_NONE;
2047 * @brief Gets the Gateway address.
2049 * @privlevel platform
2050 * @privilege http://tizen.org/privilege/tethering.admin
2051 * @remarks @a gateway_address must be released with free() by you.
2052 * @param[in] tethering The handle of tethering
2053 * @param[in] type The type of tethering
2054 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2055 * @param[out] gateway_address The local IP address
2056 * @return 0 on success, otherwise negative error value.
2057 * @retval #TETHERING_ERROR_NONE Successful
2058 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2059 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2060 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2061 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2062 * @pre tethering must be enabled.
2063 * @see tethering_is_enabled()
2064 * @see tethering_enable()
2066 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2068 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2069 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2070 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2071 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2073 _retvm_if(tethering_is_enabled(tethering, type) == false,
2074 TETHERING_ERROR_NOT_ENABLED,
2075 "tethering type[%d] is not enabled\n", type);
2076 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2077 "parameter(tethering) is NULL\n");
2078 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2079 "parameter(gateway_address) is NULL\n");
2081 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2083 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2084 TETHERING_ERROR_OPERATION_FAILED,
2085 "getting gateway address is failed\n");
2087 *gateway_address = strdup(gateway_buf);
2089 return TETHERING_ERROR_NONE;
2094 * @brief Gets the Subnet Mask.
2096 * @privlevel platform
2097 * @privilege http://tizen.org/privilege/tethering.admin
2098 * @remarks @a subnet_mask must be released with free() by you.
2099 * @param[in] tethering The handle of tethering
2100 * @param[in] type The type of tethering
2101 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2102 * @param[out] subnet_mask The local IP address
2103 * @return 0 on success, otherwise negative error value.
2104 * @retval #TETHERING_ERROR_NONE Successful
2105 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2106 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2107 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2108 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2109 * @pre tethering must be enabled.
2110 * @see tethering_is_enabled()
2111 * @see tethering_enable()
2113 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2115 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2116 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2117 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2118 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2120 _retvm_if(tethering_is_enabled(tethering, type) == false,
2121 TETHERING_ERROR_NOT_ENABLED,
2122 "tethering is not enabled\n");
2123 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2124 "parameter(tethering) is NULL\n");
2125 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2126 "parameter(subnet_mask) is NULL\n");
2128 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2129 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2130 "Not enough memory\n");
2132 return TETHERING_ERROR_NONE;
2137 * @brief Gets the data usage.
2139 * @privlevel platform
2140 * @privilege http://tizen.org/privilege/tethering.admin
2141 * @param[in] tethering The handle of tethering
2142 * @param[out] usage The data usage
2143 * @return 0 on success, otherwise negative error value.
2144 * @retval #TETHERING_ERROR_NONE Successful
2145 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2146 * @retval #TETHERING_ERROR_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_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2154 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2156 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2157 "parameter(tethering) is NULL\n");
2158 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2159 "parameter(callback) is NULL\n");
2160 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2161 TETHERING_ERROR_NOT_ENABLED,
2162 "tethering is not enabled\n");
2164 __tethering_h *th = (__tethering_h *)tethering;
2165 GDBusProxy *proxy = th->client_bus_proxy;
2167 th->data_usage_cb = callback;
2168 th->data_usage_user_data = user_data;
2170 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2171 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2172 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2174 return TETHERING_ERROR_NONE;
2179 * @brief Gets the client which is connected by tethering "type".
2181 * @privlevel platform
2182 * @privilege http://tizen.org/privilege/tethering.admin
2183 * @param[in] tethering The handle of tethering
2184 * @param[in] type The type of tethering
2185 * @param[in] callback The callback function to invoke
2186 * @param[in] user_data The user data to be passed to the callback function
2187 * @retval #TETHERING_ERROR_NONE Successful
2188 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2189 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2190 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2191 * @pre tethering must be enabled.
2192 * @see tethering_is_enabled()
2193 * @see tethering_enable()
2195 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2197 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2198 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2199 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2200 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2202 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2203 "parameter(tethering) is NULL\n");
2204 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2205 "parameter(callback) is NULL\n");
2206 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2207 TETHERING_ERROR_NOT_ENABLED,
2208 "tethering is not enabled\n");
2210 mobile_ap_type_e interface;
2211 __tethering_h *th = (__tethering_h *)tethering;
2212 __tethering_client_h client = {0, };
2215 gchar *hostname = NULL;
2216 guint timestamp = 0;
2217 GError *error = NULL;
2218 GVariant *result = NULL;
2219 GVariantIter *outer_iter = NULL;
2220 GVariantIter *inner_iter = NULL;
2221 GVariant *station = NULL;
2222 GVariant *value = NULL;
2225 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2226 NULL, G_DBUS_CALL_FLAGS_NONE,
2227 -1, th->cancellable, &error);
2229 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2230 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2231 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2232 g_variant_get(station, "a{sv}", &inner_iter);
2233 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2234 if (g_strcmp0(key, "Type") == 0) {
2235 interface = g_variant_get_int32(value);
2236 if (interface == MOBILE_AP_TYPE_USB)
2237 client.interface = TETHERING_TYPE_USB;
2238 else if (interface == MOBILE_AP_TYPE_WIFI)
2239 client.interface = TETHERING_TYPE_WIFI;
2240 else if (interface == MOBILE_AP_TYPE_BT)
2241 client.interface = TETHERING_TYPE_BT;
2243 ERR("Invalid interface\n");
2245 g_variant_unref(value);
2248 DBG("interface is %d\n", client.interface);
2249 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2251 g_variant_unref(value);
2254 } else if (g_strcmp0(key, "IP") == 0) {
2255 g_variant_get(value, "s", &ip);
2256 SDBG("ip is %s\n", ip);
2257 g_strlcpy(client.ip, ip, sizeof(client.ip));
2258 } else if (g_strcmp0(key, "MAC") == 0) {
2259 g_variant_get(value, "s", &mac);
2260 SDBG("mac is %s\n", mac);
2261 g_strlcpy(client.mac, mac, sizeof(client.mac));
2262 } else if (g_strcmp0(key, "Name") == 0) {
2263 g_variant_get(value, "s", &hostname);
2264 SDBG("hsotname is %s\n", hostname);
2266 client.hostname = g_strdup(hostname);
2267 } else if (g_strcmp0(key, "Time") == 0) {
2268 timestamp = g_variant_get_int32(value);
2269 DBG("timestamp is %d\n", timestamp);
2270 client.tm = (time_t)timestamp;
2272 ERR("Key %s not required\n", key);
2278 g_variant_iter_free(inner_iter);
2279 if (callback((tethering_client_h)&client, user_data) == false) {
2280 DBG("iteration is stopped\n");
2281 g_free(client.hostname);
2282 g_variant_iter_free(outer_iter);
2283 g_variant_unref(station);
2284 g_variant_unref(result);
2286 return TETHERING_ERROR_OPERATION_FAILED;
2288 g_free(client.hostname);
2290 g_variant_iter_free(outer_iter);
2291 g_variant_unref(station);
2292 g_variant_unref(result);
2294 return TETHERING_ERROR_NONE;
2299 * @brief Registers the callback function called when tethering is enabled.
2301 * @privlevel platform
2302 * @privilege http://tizen.org/privilege/tethering.admin
2303 * @param[in] tethering The handle of tethering
2304 * @param[in] type The type of tethering
2305 * @param[in] callback The callback function to invoke
2306 * @param[in] user_data The user data to be passed to the callback function
2307 * @retval #TETHERING_ERROR_NONE Successful
2308 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2309 * @see tethering_unset_enabled_cb()
2311 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2313 INFO("+ type: %d\n", type);
2314 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2315 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2316 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2317 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2319 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2320 "parameter(tethering) is NULL\n");
2321 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2322 "parameter(callback) is NULL\n");
2324 __tethering_h *th = (__tethering_h *)tethering;
2325 tethering_type_e ti;
2327 if (type != TETHERING_TYPE_ALL) {
2328 th->enabled_cb[type] = callback;
2329 th->enabled_user_data[type] = user_data;
2331 return TETHERING_ERROR_NONE;
2334 /* TETHERING_TYPE_ALL */
2335 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2336 th->enabled_cb[ti] = callback;
2337 th->enabled_user_data[ti] = user_data;
2341 return TETHERING_ERROR_NONE;
2346 * @brief Unregisters the callback function called when tethering is disabled.
2348 * @privlevel platform
2349 * @privilege http://tizen.org/privilege/tethering.admin
2350 * @param[in] tethering The handle of tethering
2351 * @param[in] type The type of tethering
2352 * @retval #TETHERING_ERROR_NONE Successful
2353 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2354 * @see tethering_set_enabled_cb()
2356 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2358 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2359 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2360 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2361 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2363 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2364 "parameter(tethering) is NULL\n");
2366 __tethering_h *th = (__tethering_h *)tethering;
2367 tethering_type_e ti;
2369 if (type != TETHERING_TYPE_ALL) {
2370 th->enabled_cb[type] = NULL;
2371 th->enabled_user_data[type] = NULL;
2373 return TETHERING_ERROR_NONE;
2376 /* TETHERING_TYPE_ALL */
2377 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2378 th->enabled_cb[ti] = NULL;
2379 th->enabled_user_data[ti] = NULL;
2382 return TETHERING_ERROR_NONE;
2387 * @brief Registers the callback function called when tethering is disabled.
2389 * @privlevel platform
2390 * @privilege http://tizen.org/privilege/tethering.admin
2391 * @param[in] tethering The handle of tethering
2392 * @param[in] type The type of tethering
2393 * @param[in] callback The callback function to invoke
2394 * @param[in] user_data The user data to be passed to the callback function
2395 * @retval #TETHERING_ERROR_NONE Successful
2396 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2397 * @see tethering_unset_disabled_cb()
2399 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2401 INFO("+ type: %d\n", type);
2402 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2403 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2404 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2405 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2407 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2408 "parameter(tethering) is NULL\n");
2409 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2410 "parameter(callback) is NULL\n");
2412 __tethering_h *th = (__tethering_h *)tethering;
2413 tethering_type_e ti;
2415 if (type != TETHERING_TYPE_ALL) {
2416 th->disabled_cb[type] = callback;
2417 th->disabled_user_data[type] = user_data;
2419 return TETHERING_ERROR_NONE;
2422 /* TETHERING_TYPE_ALL */
2423 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2424 th->disabled_cb[ti] = callback;
2425 th->disabled_user_data[ti] = user_data;
2428 return TETHERING_ERROR_NONE;
2433 * @brief Unregisters the callback function called when tethering is disabled.
2435 * @privlevel platform
2436 * @privilege http://tizen.org/privilege/tethering.admin
2437 * @param[in] tethering The handle of tethering
2438 * @param[in] type The type of tethering
2439 * @retval #TETHERING_ERROR_NONE Successful
2440 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2441 * @see tethering_set_disabled_cb()
2443 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2445 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2446 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2447 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2448 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2450 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2451 "parameter(tethering) is NULL\n");
2453 __tethering_h *th = (__tethering_h *)tethering;
2454 tethering_type_e ti;
2456 if (type != TETHERING_TYPE_ALL) {
2457 th->disabled_cb[type] = NULL;
2458 th->disabled_user_data[type] = NULL;
2460 return TETHERING_ERROR_NONE;
2463 /* TETHERING_TYPE_ALL */
2464 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2465 th->disabled_cb[ti] = NULL;
2466 th->disabled_user_data[ti] = NULL;
2469 return TETHERING_ERROR_NONE;
2474 * @brief Registers the callback function called when the state of connection is changed.
2476 * @privlevel platform
2477 * @privilege http://tizen.org/privilege/tethering.admin
2478 * @param[in] tethering The handle of tethering
2479 * @param[in] type The type of tethering
2480 * @param[in] callback The callback function to invoke
2481 * @param[in] user_data The user data to be passed to the callback function
2482 * @retval #TETHERING_ERROR_NONE Successful
2483 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2484 * @see tethering_unset_connection_state_changed_cb_cb()
2486 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2488 INFO("+ type: %d\n", type);
2489 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2490 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2491 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2492 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2494 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2495 "parameter(tethering) is NULL\n");
2496 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2497 "parameter(callback) is NULL\n");
2499 __tethering_h *th = (__tethering_h *)tethering;
2500 tethering_type_e ti;
2502 if (type != TETHERING_TYPE_ALL) {
2503 th->changed_cb[type] = callback;
2504 th->changed_user_data[type] = user_data;
2506 return TETHERING_ERROR_NONE;
2509 /* TETHERING_TYPE_ALL */
2510 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2511 th->changed_cb[ti] = callback;
2512 th->changed_user_data[ti] = user_data;
2515 return TETHERING_ERROR_NONE;
2520 * @brief Unregisters the callback function called when the state of connection is changed.
2522 * @privlevel platform
2523 * @privilege http://tizen.org/privilege/tethering.admin
2524 * @param[in] tethering The handle of tethering
2525 * @param[in] type The type of tethering
2526 * @retval #TETHERING_ERROR_NONE Successful
2527 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2528 * @see tethering_set_connection_state_changed_cb()
2530 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2532 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2533 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2534 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2535 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2537 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2538 "parameter(tethering) is NULL\n");
2540 __tethering_h *th = (__tethering_h *)tethering;
2541 tethering_type_e ti;
2543 if (type != TETHERING_TYPE_ALL) {
2544 th->changed_cb[type] = NULL;
2545 th->changed_user_data[type] = NULL;
2547 return TETHERING_ERROR_NONE;
2550 /* TETHERING_TYPE_ALL */
2551 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2552 th->changed_cb[ti] = NULL;
2553 th->changed_user_data[ti] = NULL;
2556 return TETHERING_ERROR_NONE;
2561 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2563 * @privlevel platform
2564 * @privilege http://tizen.org/privilege/tethering.admin
2565 * @param[in] tethering The handle of tethering
2566 * @param[in] callback The callback function to invoke
2567 * @param[in] user_data The user data to be passed to the callback function
2568 * @retval #TETHERING_ERROR_NONE Successful
2569 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2570 * @see tethering_wifi_unset_security_type_changed_cb()
2572 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2574 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2575 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2577 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2578 "parameter(tethering) is NULL\n");
2579 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2580 "parameter(callback) is NULL\n");
2582 __tethering_h *th = (__tethering_h *)tethering;
2584 th->security_type_changed_cb = callback;
2585 th->security_type_user_data = user_data;
2587 return TETHERING_ERROR_NONE;
2593 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2595 * @privlevel platform
2596 * @privilege http://tizen.org/privilege/tethering.admin
2597 * @param[in] tethering The handle of tethering
2598 * @param[in] type The type of tethering
2599 * @retval #TETHERING_ERROR_NONE Successful
2600 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2601 * @see tethering_wifi_set_security_type_changed_cb()
2603 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2605 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2606 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2608 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2609 "parameter(tethering) is NULL\n");
2611 __tethering_h *th = (__tethering_h *)tethering;
2613 th->security_type_changed_cb = NULL;
2614 th->security_type_user_data = NULL;
2616 return TETHERING_ERROR_NONE;
2621 * @brief Registers the callback function called when the visibility of SSID is changed.
2623 * @privlevel platform
2624 * @privilege http://tizen.org/privilege/tethering.admin
2625 * @param[in] tethering The handle of tethering
2626 * @param[in] callback The callback function to invoke
2627 * @param[in] user_data The user data to be passed to the callback function
2628 * @retval #TETHERING_ERROR_NONE Successful
2629 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2630 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2632 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2634 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2635 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2637 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2638 "parameter(tethering) is NULL\n");
2639 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2640 "parameter(callback) is NULL\n");
2642 __tethering_h *th = (__tethering_h *)tethering;
2644 th->ssid_visibility_changed_cb = callback;
2645 th->ssid_visibility_user_data = user_data;
2647 return TETHERING_ERROR_NONE;
2652 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2654 * @privlevel platform
2655 * @privilege http://tizen.org/privilege/tethering.admin
2656 * @param[in] tethering The handle of tethering
2657 * @retval #TETHERING_ERROR_NONE Successful
2658 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2659 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2661 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2663 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2664 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2666 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2667 "parameter(tethering) is NULL\n");
2669 __tethering_h *th = (__tethering_h *)tethering;
2671 th->ssid_visibility_changed_cb = NULL;
2672 th->ssid_visibility_user_data = NULL;
2674 return TETHERING_ERROR_NONE;
2679 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2681 * @privlevel platform
2682 * @privilege http://tizen.org/privilege/tethering.admin
2683 * @param[in] tethering The handle of tethering
2684 * @param[in] callback The callback function to invoke
2685 * @param[in] user_data The user data to be passed to the callback function
2686 * @retval #TETHERING_ERROR_NONE Successful
2687 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2688 * @see tethering_wifi_unset_passphrase_changed_cb()
2690 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2692 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2693 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2695 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2696 "parameter(tethering) is NULL\n");
2697 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2698 "parameter(callback) is NULL\n");
2700 __tethering_h *th = (__tethering_h *)tethering;
2702 th->passphrase_changed_cb = callback;
2703 th->passphrase_user_data = user_data;
2705 return TETHERING_ERROR_NONE;
2710 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2712 * @privlevel platform
2713 * @privilege http://tizen.org/privilege/tethering.admin
2714 * @param[in] tethering The handle of tethering
2715 * @retval #TETHERING_ERROR_NONE Successful
2716 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2717 * @see tethering_wifi_set_passphrase_changed_cb()
2719 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2721 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2722 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2724 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2725 "parameter(tethering) is NULL\n");
2727 __tethering_h *th = (__tethering_h *)tethering;
2729 th->passphrase_changed_cb = NULL;
2730 th->passphrase_user_data = NULL;
2732 return TETHERING_ERROR_NONE;
2737 * @brief Sets the security type of Wi-Fi tethering.
2739 * @privlevel platform
2740 * @privilege http://tizen.org/privilege/tethering.admin
2741 * @remarks This change is applied next time Wi-Fi tethering is enabled
2742 * @param[in] tethering The handle of tethering
2743 * @param[in] type The security type
2744 * @return 0 on success, otherwise negative error value.
2745 * @retval #TETHERING_ERROR_NONE Successful
2746 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2747 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2748 * @see tethering_wifi_get_security_type()
2750 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2752 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2753 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2755 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2756 "parameter(tethering) is NULL\n");
2758 __tethering_h *th = (__tethering_h *)tethering;
2759 tethering_error_e ret = TETHERING_ERROR_NONE;
2760 char *sec_str = NULL;
2762 ret = __set_security_type(type);
2763 if (ret == TETHERING_ERROR_NONE) {
2766 case TETHERING_WIFI_SECURITY_TYPE_NONE:
2767 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
2769 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
2770 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
2772 case TETHERING_WIFI_SECURITY_TYPE_WPS:
2773 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
2777 __send_dbus_signal(th->client_bus,
2778 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
2785 * @brief Gets the security type of Wi-Fi tethering.
2787 * @privlevel platform
2788 * @privilege http://tizen.org/privilege/tethering.admin
2789 * @param[in] tethering The handle of tethering
2790 * @param[out] type The security type
2791 * @return 0 on success, otherwise negative error value.
2792 * @retval #TETHERING_ERROR_NONE Successful
2793 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2794 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2795 * @see tethering_wifi_set_security_type()
2797 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2799 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2800 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2802 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2803 "parameter(type) is NULL\n");
2805 return __get_security_type(type);
2810 * @brief Sets the SSID (service set identifier).
2812 * @privlevel platform
2813 * @privilege http://tizen.org/privilege/tethering.admin
2814 * @details If SSID is not set, Device name is used as SSID
2815 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2816 * @param[in] tethering The handle of tethering
2817 * @param[out] ssid The SSID
2818 * @return 0 on success, otherwise negative error value.
2819 * @retval #TETHERING_ERROR_NONE Successful
2820 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2821 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2823 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2825 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2826 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2828 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2829 "parameter(tethering) is NULL\n");
2830 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2831 "parameter(ssid) is NULL\n");
2833 __tethering_h *th = (__tethering_h *)tethering;
2834 char *p_ssid = NULL;
2837 ssid_len = strlen(ssid);
2838 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2839 ERR("parameter(ssid) is too long");
2840 return TETHERING_ERROR_INVALID_PARAMETER;
2843 p_ssid = strdup(ssid);
2844 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2845 "strdup is failed\n");
2851 return TETHERING_ERROR_NONE;
2856 * @brief Gets the SSID (service set identifier).
2858 * @privlevel platform
2859 * @privilege http://tizen.org/privilege/tethering.admin
2860 * @remarks @a ssid must be released with free() by you.
2861 * @param[in] tethering The handle of tethering
2862 * @param[out] ssid The SSID
2863 * @return 0 on success, otherwise negative error value.
2864 * @retval #TETHERING_ERROR_NONE Successful
2865 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2866 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2867 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2869 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2871 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2872 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2874 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2875 "parameter(tethering) is NULL\n");
2876 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2877 "parameter(ssid) is NULL\n");
2880 __tethering_h *th = (__tethering_h *)tethering;
2881 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2883 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2884 if (th->ssid != NULL) {
2885 DBG("Private SSID is set\n");
2886 *ssid = strdup(th->ssid);
2888 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2889 val, sizeof(val)) == false) {
2890 return TETHERING_ERROR_OPERATION_FAILED;
2892 *ssid = strdup(val);
2895 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2896 val, sizeof(val)) == false) {
2897 return TETHERING_ERROR_OPERATION_FAILED;
2899 *ssid = strdup(val);
2902 if (*ssid == NULL) {
2903 ERR("strdup is failed\n");
2904 return TETHERING_ERROR_OUT_OF_MEMORY;
2907 return TETHERING_ERROR_NONE;
2912 * @brief Sets the visibility of SSID(service set identifier).
2914 * @privlevel platform
2915 * @privilege http://tizen.org/privilege/tethering.admin
2916 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2917 * @remarks This change is applied next time Wi-Fi tethering is enabled
2918 * @param[in] tethering The handle of tethering
2919 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2920 * @return 0 on success, otherwise negative error value.
2921 * @retval #TETHERING_ERROR_NONE Successful
2922 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2923 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2924 * @see tethering_wifi_get_ssid_visibility()
2926 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2928 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2929 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2931 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2932 "parameter(tethering) is NULL\n");
2934 __tethering_h *th = (__tethering_h *)tethering;
2935 tethering_error_e ret = TETHERING_ERROR_NONE;
2937 ret = __set_visible(visible);
2938 if (ret == TETHERING_ERROR_NONE) {
2940 __send_dbus_signal(th->client_bus,
2941 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2942 visible ? SIGNAL_MSG_SSID_VISIBLE :
2943 SIGNAL_MSG_SSID_HIDE);
2950 * @brief Gets the visibility of SSID(service set identifier).
2952 * @privlevel platform
2953 * @privilege http://tizen.org/privilege/tethering.admin
2954 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2955 * @param[in] tethering The handle of tethering
2956 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2957 * @return 0 on success, otherwise negative error value.
2958 * @retval #TETHERING_ERROR_NONE Successful
2959 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2960 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2961 * @see tethering_wifi_set_ssid_visibility()
2963 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2965 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2966 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2968 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2969 "parameter(visible) is NULL\n");
2971 return __get_visible(visible);
2976 * @brief Sets the passphrase.
2978 * @privlevel platform
2979 * @privilege http://tizen.org/privilege/tethering.admin
2980 * @remarks This change is applied next time Wi-Fi tethering is enabled
2981 * @param[in] tethering The handle of tethering
2982 * @param[in] passphrase The passphrase
2983 * @return 0 on success, otherwise negative error value.
2984 * @retval #TETHERING_ERROR_NONE Successful
2985 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2986 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2987 * @see tethering_wifi_get_passphrase()
2989 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2991 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2992 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2994 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2995 "parameter(tethering) is NULL\n");
2996 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2997 "parameter(passphrase) is NULL\n");
2999 __tethering_h *th = (__tethering_h *)tethering;
3000 GDBusProxy *proxy = th->client_bus_proxy;
3001 GVariant *parameters;
3002 GError *error = NULL;
3003 int passphrase_len = 0;
3007 passphrase_len = strlen(passphrase);
3008 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3009 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3010 ERR("parameter(passphrase) is too short or long\n");
3011 return TETHERING_ERROR_INVALID_PARAMETER;
3014 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3015 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3019 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3021 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3022 ret = TETHERING_ERROR_PERMISSION_DENIED;
3024 ret = TETHERING_ERROR_OPERATION_FAILED;
3026 g_error_free(error);
3031 g_variant_get(parameters, "(u)", &ret);
3032 g_variant_unref(parameters);
3034 if (ret == TETHERING_ERROR_NONE) {
3035 __send_dbus_signal(th->client_bus,
3036 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3045 * @brief Gets the passphrase.
3047 * @privlevel platform
3048 * @privilege http://tizen.org/privilege/tethering.admin
3049 * @remarks @a passphrase must be released with free() by you.
3050 * @param[in] tethering The handle of tethering
3051 * @param[out] passphrase The passphrase
3052 * @return 0 on success, otherwise negative error value.
3053 * @retval #TETHERING_ERROR_NONE Successful
3054 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3055 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3056 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3057 * @see tethering_wifi_set_passphrase()
3059 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3061 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3062 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3064 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3065 "parameter(tethering) is NULL\n");
3066 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3067 "parameter(passphrase) is NULL\n");
3069 __tethering_h *th = (__tethering_h *)tethering;
3070 GDBusProxy *proxy = th->client_bus_proxy;
3071 GVariant *parameters;
3072 GError *error = NULL;
3073 unsigned int len = 0;
3074 tethering_error_e ret = TETHERING_ERROR_NONE;
3076 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3077 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3081 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3083 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3084 ret = TETHERING_ERROR_PERMISSION_DENIED;
3086 ret = TETHERING_ERROR_OPERATION_FAILED;
3088 g_error_free(error);
3093 if (parameters != NULL) {
3094 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3095 g_variant_unref(parameters);
3098 return TETHERING_ERROR_NONE;
3101 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3103 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3104 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3106 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3107 "parameter(tethering) is NULL\n");
3109 __tethering_h *th = (__tethering_h *)tethering;
3110 th->channel = channel;
3112 return TETHERING_ERROR_NONE;
3115 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3117 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3118 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3120 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3121 "parameter(tethering) is NULL\n");
3123 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3124 "parameter(channel) is NULL\n");
3126 __tethering_h *th = (__tethering_h *)tethering;
3127 *channel = th->channel;
3129 return TETHERING_ERROR_NONE;
3132 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3134 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3135 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3137 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3138 "parameter(tethering) is NULL\n");
3140 __tethering_h *th = (__tethering_h *)tethering;
3142 th->mode_type = type;
3144 return TETHERING_ERROR_NONE;
3147 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3149 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3150 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3152 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3153 "parameter(tethering) is NULL\n");
3154 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3155 "parameter(type) is NULL\n");
3157 __tethering_h *th = (__tethering_h *)tethering;
3158 *type = th->mode_type;
3160 return TETHERING_ERROR_NONE;
3166 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3168 * @privlevel platform
3169 * @privilege http://tizen.org/privilege/tethering.admin
3170 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3171 * @param[in] tethering The handle of tethering
3172 * @param[in] callback The callback function to invoke
3173 * @param[in] user_data The user data to be passed to the callback function
3174 * @return 0 on success, otherwise negative error value.
3175 * @retval #TETHERING_ERROR_NONE Successful
3176 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3177 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3179 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3182 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3183 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3185 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3186 "parameter(tethering) is NULL\n");
3187 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3188 "parameter(callback) is NULL\n");
3190 __tethering_h *th = (__tethering_h *)tethering;
3191 _softap_settings_t set = {"", "", "", 0, false};
3192 GDBusProxy *proxy = th->client_bus_proxy;
3197 if (th->settings_reloaded_cb) {
3198 ERR("Operation in progress\n");
3199 return TETHERING_ERROR_OPERATION_FAILED;
3202 ret = __prepare_wifi_settings(tethering, &set);
3203 if (ret != TETHERING_ERROR_NONE) {
3204 ERR("softap settings initialization failed\n");
3205 return TETHERING_ERROR_OPERATION_FAILED;
3208 th->settings_reloaded_cb = callback;
3209 th->settings_reloaded_user_data = user_data;
3211 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3212 g_variant_new("(sssiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type),
3213 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3214 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3216 return TETHERING_ERROR_NONE;
3219 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3221 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3222 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3224 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3225 "parameter(tethering) is NULL\n");
3227 __tethering_h *th = (__tethering_h *)tethering;
3228 th->mac_filter = mac_filter;
3230 return TETHERING_ERROR_NONE;
3233 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3235 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3236 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3238 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3239 "parameter(mac_filter) is NULL\n");
3240 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3241 "parameter(mac_filter) is NULL\n");
3243 __tethering_h *th = (__tethering_h *)tethering;
3244 *mac_filter = th->mac_filter;
3246 return TETHERING_ERROR_NONE;
3249 static int __add_mac_to_file(const char *filepath, const char *mac)
3252 char line[MAX_BUF_SIZE] = "\0";
3253 bool mac_exist = false;
3256 p_mac = strdup(mac);
3257 if (p_mac == NULL) {
3258 ERR("strdup failed\n");
3259 return TETHERING_ERROR_OUT_OF_MEMORY;
3262 fp = fopen(filepath, "a+");
3264 ERR("fopen is failed\n");
3265 return TETHERING_ERROR_OPERATION_FAILED;
3268 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3269 if (strncmp(mac, line, 17) == 0) {
3270 DBG("MAC %s already exist in the list\n", mac);
3277 fprintf(fp, "%s\n", mac);
3279 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3280 allowed_list = g_slist_append(allowed_list, p_mac);
3281 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3282 blocked_list = g_slist_append(blocked_list, p_mac);
3287 return TETHERING_ERROR_NONE;
3290 static int __remove_mac_from_file(const char *filepath, const char *mac)
3294 char line[MAX_BUF_SIZE] = "\0";
3296 fp = fopen(filepath, "r");
3298 ERR("fopen is failed\n");
3299 return TETHERING_ERROR_OPERATION_FAILED;
3302 fp1 = fopen(TEMP_LIST, "w+");
3305 ERR("fopen is failed\n");
3306 return TETHERING_ERROR_OPERATION_FAILED;
3309 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3310 if (strncmp(mac, line, 17) == 0) {
3311 DBG("MAC %s found in the list\n", mac);
3313 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3314 GSList *list = NULL;
3315 for (list = allowed_list; list != NULL; list = list->next) {
3316 char *p_mac = (char *)list->data;
3317 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3318 allowed_list = g_slist_remove(allowed_list, p_mac);
3320 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3321 GSList *list = NULL;
3322 for (list = blocked_list; list != NULL; list = list->next) {
3323 char *p_mac = (char *)list->data;
3324 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3325 blocked_list = g_slist_remove(blocked_list, p_mac);
3329 fprintf(fp1, "%s", line);
3336 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3337 rename(TEMP_LIST, ALLOWED_LIST);
3338 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3339 rename(TEMP_LIST, BLOCKED_LIST);
3341 return TETHERING_ERROR_NONE;
3344 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3346 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3347 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3349 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3350 "parameter(tethering) is NULL\n");
3351 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3352 "parameter(mac) is NULL\n");
3354 return __add_mac_to_file(ALLOWED_LIST, mac);
3357 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3359 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3360 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3362 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3363 "parameter(tethering) is NULL\n");
3364 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3365 "parameter(mac) is NULL\n");
3367 return __remove_mac_from_file(ALLOWED_LIST, mac);
3370 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3372 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3373 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3375 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3376 "parameter(tethering) is NULL\n");
3377 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3378 "parameter(allowed_mac_list) is NULL\n");
3380 *allowed_mac_list = g_slist_copy(allowed_list);
3381 return TETHERING_ERROR_NONE;
3384 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3386 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3387 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3389 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3390 "parameter(tethering) is NULL\n");
3391 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3392 "parameter(mac) is NULL\n");
3394 return __add_mac_to_file(BLOCKED_LIST, mac);
3397 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3399 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3400 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3402 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3403 "parameter(tethering) is NULL\n");
3404 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3405 "parameter(mac) is NULL\n");
3407 return __remove_mac_from_file(BLOCKED_LIST, mac);
3410 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3412 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3413 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3415 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3416 "parameter(tethering) is NULL\n");
3417 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3418 "parameter(blocked_mac_list) is NULL\n");
3420 *blocked_mac_list = g_slist_copy(blocked_list);
3421 return TETHERING_ERROR_NONE;
3424 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3426 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3427 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3429 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3430 "parameter(tethering) is NULL\n");
3432 GVariant *parameters;
3433 GError *error = NULL;
3436 __tethering_h *th = (__tethering_h *)tethering;
3438 GDBusProxy *proxy = th->client_bus_proxy;
3440 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3441 g_variant_new("(b)", enable),
3442 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3445 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3446 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3447 result = TETHERING_ERROR_PERMISSION_DENIED;
3449 result = TETHERING_ERROR_OPERATION_FAILED;
3451 g_error_free(error);
3452 th->dhcp_enabled = false;
3457 g_variant_get(parameters, "(u)", &result);
3458 g_variant_unref(parameters);
3461 th->dhcp_enabled = true;
3463 th->dhcp_enabled = false;
3465 return TETHERING_ERROR_NONE;
3468 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3470 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3471 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3473 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3474 "parameter(tethering) is NULL\n");
3475 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3476 "parameter(rangestart) is NULL\n");
3477 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3478 "parameter(rangestop) is NULL\n");
3480 GVariant *parameters;
3481 GError *error = NULL;
3484 __tethering_h *th = (__tethering_h *)tethering;
3486 GDBusProxy *proxy = th->client_bus_proxy;
3488 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3489 g_variant_new("(ss)", rangestart, rangestop),
3490 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3492 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3494 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3495 result = TETHERING_ERROR_PERMISSION_DENIED;
3497 result = TETHERING_ERROR_OPERATION_FAILED;
3499 g_error_free(error);
3500 th->dhcp_enabled = false;
3505 g_variant_get(parameters, "(u)", &result);
3506 g_variant_unref(parameters);
3508 th->dhcp_enabled = true;
3510 return TETHERING_ERROR_NONE;
3513 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3515 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3516 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3518 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3519 "parameter(tethering) is NULL\n");
3520 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3521 "parameter(dhcp_enabled) is NULL\n");
3523 __tethering_h *th = (__tethering_h *)tethering;
3524 *dhcp_enabled = th->dhcp_enabled;
3526 return TETHERING_ERROR_NONE;
3529 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3531 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3532 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3534 GError *error = NULL;
3536 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3537 "parameter(tethering) is NULL\n");
3538 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3539 TETHERING_ERROR_NOT_ENABLED,
3540 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3541 __tethering_h *th = (__tethering_h *)tethering;
3543 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3544 g_variant_new("(u)", txpower),
3545 G_DBUS_CALL_FLAGS_NONE,
3546 -1, th->cancellable, &error);
3548 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3549 g_clear_error(&error);
3550 return TETHERING_ERROR_OPERATION_FAILED;
3552 return TETHERING_ERROR_NONE;
3555 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3557 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3558 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3560 GError *error = NULL;
3561 GVariant *result = NULL;
3563 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3564 "parameter(tethering) is NULL\n");
3565 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3566 TETHERING_ERROR_NOT_ENABLED,
3567 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3569 __tethering_h *th = (__tethering_h *)tethering;
3571 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3573 G_DBUS_CALL_FLAGS_NONE,
3574 -1, th->cancellable, &error);
3576 if (result != NULL) {
3577 g_variant_get(result, "(u)", txpower);
3578 g_variant_unref(result);
3581 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3582 g_clear_error(&error);
3583 return TETHERING_ERROR_OPERATION_FAILED;
3585 g_clear_error(&error);
3586 return TETHERING_ERROR_NONE;
3589 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
3591 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3592 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3594 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3595 "parameter(tethering) is NULL\n");
3597 GVariant *parameters;
3598 GError *error = NULL;
3601 __tethering_h *th = (__tethering_h *)tethering;
3603 GDBusProxy *proxy = th->client_bus_proxy;
3605 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
3606 g_variant_new("(u)", mtu),
3607 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3609 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3611 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3612 result = TETHERING_ERROR_PERMISSION_DENIED;
3614 result = TETHERING_ERROR_OPERATION_FAILED;
3616 g_error_free(error);
3620 g_variant_get(parameters, "(u)", &result);
3622 g_variant_unref(parameters);
3624 return TETHERING_ERROR_NONE;
3627 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
3629 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3630 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3632 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3633 "parameter(tethering) is NULL\n");
3634 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3635 "parameter(mac) is NULL\n");
3637 GVariant *parameters;
3638 GError *error = NULL;
3641 __tethering_h *th = (__tethering_h *)tethering;
3643 GDBusProxy *proxy = th->client_bus_proxy;
3645 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
3646 g_variant_new("(s)", mac),
3647 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3649 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3651 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3652 result = TETHERING_ERROR_PERMISSION_DENIED;
3654 result = TETHERING_ERROR_OPERATION_FAILED;
3656 g_error_free(error);
3660 g_variant_get(parameters, "(u)", &result);
3662 g_variant_unref(parameters);
3664 th->change_mac = true;
3666 return TETHERING_ERROR_NONE;
3669 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
3671 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3672 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3674 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3675 "parameter(tethering) is NULL\n");
3677 __tethering_h *th = (__tethering_h *)tethering;
3679 th->wifi_max_connected = max_device;
3681 return TETHERING_ERROR_NONE;
3684 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
3686 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3687 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3689 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3690 "parameter(tethering) is NULL\n");
3691 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3692 "parameter(max_device) is NULL\n");
3694 __tethering_h *th = (__tethering_h *)tethering;
3696 *max_device = th->wifi_max_connected;
3697 return TETHERING_ERROR_NONE;
3700 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
3702 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3703 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3705 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3706 "parameter(tethering) is NULL\n");
3708 GVariant *parameters;
3709 GError *error = NULL;
3712 __tethering_h *th = (__tethering_h *)tethering;
3714 GDBusProxy *proxy = th->client_bus_proxy;
3716 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
3717 g_variant_new("(b)", enable),
3718 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3720 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3722 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3723 result = TETHERING_ERROR_PERMISSION_DENIED;
3725 result = TETHERING_ERROR_OPERATION_FAILED;
3727 g_error_free(error);
3731 g_variant_get(parameters, "(u)", &result);
3732 g_variant_unref(parameters);
3734 th->port_forwarding = true;
3736 return TETHERING_ERROR_NONE;
3739 API int tethering_wifi_add_port_forwarding_rule(tethering_h tethering, char *ifname, char *protocol, char *org_ip, int org_port, char *final_ip, int final_port)
3741 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3742 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3744 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3745 "parameter(tethering) is NULL\n");
3746 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3747 "parameter(protocol) is NULL\n");
3749 GVariant *parameters;
3750 GError *error = NULL;
3752 char cmd[MAX_BUF_SIZE] = { 0, };
3755 __tethering_h *th = (__tethering_h *)tethering;
3757 GDBusProxy *proxy = th->client_bus_proxy;
3759 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
3760 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
3761 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3763 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3765 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3766 result = TETHERING_ERROR_PERMISSION_DENIED;
3768 result = TETHERING_ERROR_OPERATION_FAILED;
3770 g_error_free(error);
3774 g_variant_get(parameters, "(u)", &result);
3775 g_variant_unref(parameters);
3777 snprintf(cmd, sizeof(cmd), "%s "PORT_FORWARD_RULE_STR, IPTABLES, TABLE_NAT, TETH_NAT_PRE, ifname, protocol, org_ip, org_port, final_ip, final_port);
3781 ERR("strdup failed\n");
3782 return TETHERING_ERROR_OUT_OF_MEMORY;
3785 port_forwarding = g_slist_append(port_forwarding, list);
3787 return TETHERING_ERROR_NONE;
3790 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
3792 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3793 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3795 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3796 "parameter(tethering) is NULL\n");
3798 GVariant *parameters;
3799 GError *error = NULL;
3802 __tethering_h *th = (__tethering_h *)tethering;
3804 GDBusProxy *proxy = th->client_bus_proxy;
3806 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
3807 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3809 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3811 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3812 result = TETHERING_ERROR_PERMISSION_DENIED;
3814 result = TETHERING_ERROR_OPERATION_FAILED;
3816 g_error_free(error);
3820 g_variant_get(parameters, "(u)", &result);
3822 g_variant_unref(parameters);
3824 return TETHERING_ERROR_NONE;
3827 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool* forwarding_enabled)
3829 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3830 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3832 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3833 "parameter(tethering) is NULL\n");
3834 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3835 "parameter(forwarding_enabled) is NULL\n");
3837 __tethering_h *th = (__tethering_h *)tethering;
3839 *forwarding_enabled = th->port_forwarding;
3841 return TETHERING_ERROR_NONE;
3844 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
3846 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3847 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3849 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3850 "parameter(tethering) is NULL\n");
3851 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3852 "parameter(port_forwarding_list) is NULL\n");
3854 *port_forwarding_list = g_slist_copy(port_forwarding);
3855 return TETHERING_ERROR_NONE;
3858 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
3860 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3861 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3863 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3864 "parameter(tethering) is NULL\n");
3866 GVariant *parameters;
3867 GError *error = NULL;
3870 __tethering_h *th = (__tethering_h *)tethering;
3872 GDBusProxy *proxy = th->client_bus_proxy;
3874 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
3875 g_variant_new("(b)", enable),
3876 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3878 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3880 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3881 result = TETHERING_ERROR_PERMISSION_DENIED;
3883 result = TETHERING_ERROR_OPERATION_FAILED;
3885 g_error_free(error);
3889 g_variant_get(parameters, "(u)", &result);
3890 g_variant_unref(parameters);
3892 th->port_filtering = true;
3894 return TETHERING_ERROR_NONE;
3897 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
3899 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3900 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3902 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3903 "parameter(tethering) is NULL\n");
3904 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3905 "parameter(protocol) is NULL\n");
3907 GVariant *parameters;
3908 GError *error = NULL;
3910 char cmd[MAX_BUF_SIZE] = { 0, };
3913 __tethering_h *th = (__tethering_h *)tethering;
3915 GDBusProxy *proxy = th->client_bus_proxy;
3917 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
3918 g_variant_new("(isb)", port, protocol, allow),
3919 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3921 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3923 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3924 result = TETHERING_ERROR_PERMISSION_DENIED;
3926 result = TETHERING_ERROR_OPERATION_FAILED;
3928 g_error_free(error);
3932 g_variant_get(parameters, "(u)", &result);
3933 g_variant_unref(parameters);
3936 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
3938 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
3944 ERR("strdup failed\n");
3945 return TETHERING_ERROR_OUT_OF_MEMORY;
3948 port_filtering = g_slist_append(port_filtering, list);
3950 return TETHERING_ERROR_NONE;
3953 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
3955 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3956 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3958 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3959 "parameter(tethering) is NULL\n");
3960 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3961 "parameter(protocol) is NULL\n");
3963 GVariant *parameters;
3964 GError *error = NULL;
3966 char cmd[MAX_BUF_SIZE] = { 0, };
3969 __tethering_h *th = (__tethering_h *)tethering;
3971 GDBusProxy *proxy = th->client_bus_proxy;
3973 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
3974 g_variant_new("(iisb)", port1, port2, protocol, allow),
3975 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3977 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3979 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3980 result = TETHERING_ERROR_PERMISSION_DENIED;
3982 result = TETHERING_ERROR_OPERATION_FAILED;
3984 g_error_free(error);
3988 g_variant_get(parameters, "(u)", &result);
3989 g_variant_unref(parameters);
3992 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
3994 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
4000 ERR("strdup failed\n");
4001 return TETHERING_ERROR_OUT_OF_MEMORY;
4004 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4006 return TETHERING_ERROR_NONE;
4009 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4011 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4012 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4014 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4015 "parameter(tethering) is NULL\n");
4016 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4017 "parameter(port_filtering_list) is NULL\n");
4019 *port_filtering_list = g_slist_copy(port_filtering);
4020 return TETHERING_ERROR_NONE;
4023 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4025 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4026 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4028 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4029 "parameter(tethering) is NULL\n");
4030 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4031 "parameter(custom_port_filtering_list) is NULL\n");
4033 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4034 return TETHERING_ERROR_NONE;
4037 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool* filtering_enabled)
4039 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4040 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4042 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4043 "parameter(tethering) is NULL\n");
4044 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4045 "parameter(filtering_enabled) is NULL\n");
4047 __tethering_h *th = (__tethering_h *)tethering;
4049 *filtering_enabled = th->port_filtering;
4051 return TETHERING_ERROR_NONE;
4054 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
4056 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4057 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4059 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4060 "parameter(tethering) is NULL\n");
4062 GVariant *parameters;
4063 GError *error = NULL;
4066 __tethering_h *th = (__tethering_h *)tethering;
4068 GDBusProxy *proxy = th->client_bus_proxy;
4070 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4071 g_variant_new("(ib)", type, enable),
4072 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4074 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4076 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4077 result = TETHERING_ERROR_PERMISSION_DENIED;
4079 result = TETHERING_ERROR_OPERATION_FAILED;
4081 g_error_free(error);
4085 g_variant_get(parameters, "(u)", &result);
4087 g_variant_unref(parameters);
4089 return TETHERING_ERROR_NONE;
4092 API int tethering_wifi_push_wps_button(tethering_h tethering)
4094 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4095 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4097 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4098 "parameter(tethering) is NULL");
4099 __tethering_h *th = (__tethering_h *)tethering;
4100 GDBusProxy *proxy = th->client_bus_proxy;
4101 GVariant *parameters = NULL;
4103 GError *error = NULL;
4105 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4106 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4109 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4111 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4112 ret = TETHERING_ERROR_PERMISSION_DENIED;
4114 ret = TETHERING_ERROR_OPERATION_FAILED;
4116 g_error_free(error);
4120 if (parameters != NULL) {
4121 g_variant_get(parameters, "(u)", &ret);
4122 g_variant_unref(parameters);
4125 return TETHERING_ERROR_NONE;
4128 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4130 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4131 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4133 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4134 "parameter(tethering) is NULL");
4135 __tethering_h *th = (__tethering_h *)tethering;
4136 GDBusProxy *proxy = th->client_bus_proxy;
4137 GVariant *parameters = NULL;
4139 GError *error = NULL;
4141 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4142 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4145 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4147 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4148 ret = TETHERING_ERROR_PERMISSION_DENIED;
4150 ret = TETHERING_ERROR_OPERATION_FAILED;
4152 g_error_free(error);
4156 if (parameters != NULL) {
4157 g_variant_get(parameters, "(u)", &ret);
4158 g_variant_unref(parameters);
4161 return TETHERING_ERROR_NONE;