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;
1387 if (__generate_initial_passphrase(th->passphrase,
1388 sizeof(th->passphrase)) == 0) {
1389 ERR("random passphrase generation failed\n"); //LCOV_EXCL_LINE
1391 return TETHERING_ERROR_OPERATION_FAILED;
1394 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1395 ERR("common ssid get failed\n"); //LCOV_EXCL_LINE
1397 return TETHERING_ERROR_OPERATION_FAILED;
1400 #if !GLIB_CHECK_VERSION(2, 36, 0)
1403 GCancellable *cancellable = g_cancellable_new();
1404 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1407 ERR("Couldn't connect to the System bus[%s]", error->message);
1408 g_error_free(error);
1409 g_cancellable_cancel(cancellable);
1410 g_object_unref(cancellable);
1412 return TETHERING_ERROR_OPERATION_FAILED;
1415 th->cancellable = cancellable;
1417 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1418 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1419 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1420 if (!th->client_bus_proxy) {
1423 ERR("Couldn't create the proxy object because of %s\n", error->message);
1424 g_cancellable_cancel(th->cancellable);
1425 g_object_unref(th->cancellable);
1426 g_object_unref(th->client_bus);
1428 return TETHERING_ERROR_OPERATION_FAILED;
1432 __connect_signals((tethering_h)th);
1434 *tethering = (tethering_h)th;
1435 INFO("Tethering Handle : 0x%X\n", th);
1437 return TETHERING_ERROR_NONE;
1442 * @brief Destroys the handle of tethering.
1444 * @privlevel platform
1445 * @privilege http://tizen.org/privilege/tethering.admin
1446 * @param[in] tethering The handle of tethering
1447 * @return 0 on success, otherwise a negative error value.
1448 * @retval #TETHERING_ERROR_NONE Successful
1449 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1450 * @see tethering_create()
1452 API int tethering_destroy(tethering_h tethering)
1455 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1456 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1457 "parameter(tethering) is NULL\n");
1459 __tethering_h *th = (__tethering_h *)tethering;
1461 INFO("Tethering Handle : 0x%X\n", th);
1463 __disconnect_signals(tethering);
1468 g_object_unref(th->cancellable);
1469 g_object_unref(th->client_bus_proxy);
1470 g_object_unref(th->client_bus);
1471 memset(th, 0x00, sizeof(__tethering_h));
1475 return TETHERING_ERROR_NONE;
1480 * @brief Enables the tethering, asynchronously.
1482 * @privlevel platform
1483 * @privilege http://tizen.org/privilege/tethering.admin
1484 * @param[in] tethering The handle of tethering
1485 * @param[in] type The type of tethering
1486 * @return 0 on success, otherwise negative error value.
1487 * @retval #TETHERING_ERROR_NONE Successful
1488 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1489 * @post tethering_enabled_cb() will be invoked.
1490 * @see tethering_is_enabled()
1491 * @see tethering_disable()
1493 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1495 INFO("+ type : %d\n", type);
1496 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1497 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1498 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1499 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1501 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1502 "parameter(tethering) is NULL\n");
1504 tethering_error_e ret = TETHERING_ERROR_NONE;
1505 __tethering_h *th = (__tethering_h *)tethering;
1506 GDBusProxy *proxy = th->client_bus_proxy;
1507 GDBusConnection *connection = th->client_bus;
1509 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1511 if (__check_precondition(type) == FALSE) {
1514 return TETHERING_ERROR_OPERATION_FAILED;
1520 case TETHERING_TYPE_USB:
1521 g_dbus_connection_signal_unsubscribe(connection,
1522 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1524 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1525 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1526 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1530 case TETHERING_TYPE_WIFI: {
1531 _softap_settings_t set = {"", "", "", 0, false};
1533 ret = __prepare_wifi_settings(tethering, &set);
1534 if (ret != TETHERING_ERROR_NONE) {
1535 ERR("softap settings initialization failed\n");
1537 return TETHERING_ERROR_OPERATION_FAILED;
1539 g_dbus_connection_signal_unsubscribe(connection,
1540 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1542 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1543 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),
1544 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1545 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1549 case TETHERING_TYPE_BT:
1550 g_dbus_connection_signal_unsubscribe(connection,
1551 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1553 g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL,
1554 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1555 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1560 case TETHERING_TYPE_ALL: {
1561 _softap_settings_t set = {"", "", "", 0, false};
1563 ret = __prepare_wifi_settings(tethering, &set);
1564 if (ret != TETHERING_ERROR_NONE) {
1565 ERR("softap settings initialization failed\n");
1566 return TETHERING_ERROR_OPERATION_FAILED;
1569 /* TETHERING_TYPE_USB */
1570 g_dbus_connection_signal_unsubscribe(connection,
1571 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1573 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1574 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1575 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1577 /* TETHERING_TYPE_WIFI */
1578 g_dbus_connection_signal_unsubscribe(connection,
1579 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1581 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1582 g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
1583 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1584 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1586 /* TETHERING_TYPE_BT */
1587 g_dbus_connection_signal_unsubscribe(connection,
1588 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1590 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1591 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1592 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1597 ERR("Unknown type : %d\n", type);
1599 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1602 return TETHERING_ERROR_INVALID_PARAMETER;
1605 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1607 return TETHERING_ERROR_NONE;
1610 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1612 DBG("+ type : %d\n", type);
1613 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1614 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1615 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1616 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1618 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1619 "parameter(tethering) is NULL\n");
1621 __tethering_h *th = (__tethering_h *)tethering;
1622 GDBusProxy *proxy = th->client_bus_proxy;
1623 GDBusConnection *connection = th->client_bus;
1626 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1628 if (__check_precondition(type) == FALSE) {
1631 return TETHERING_ERROR_OPERATION_FAILED;
1637 case TETHERING_TYPE_WIFI: {
1638 _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
1640 ret = __prepare_wifi_settings(tethering, &set);
1641 if (ret != TETHERING_ERROR_NONE) {
1642 ERR("softap settings initialization failed\n");
1644 return TETHERING_ERROR_OPERATION_FAILED;
1646 g_dbus_connection_signal_unsubscribe(connection,
1647 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1648 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1649 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),
1650 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1651 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1654 case TETHERING_TYPE_BT: {
1655 g_dbus_connection_signal_unsubscribe(connection,
1656 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1659 g_dbus_proxy_call(proxy, "enable_bt_tethering", g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1660 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1661 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1667 ERR("Unknown type : %d\n", type);
1669 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1672 return TETHERING_ERROR_INVALID_PARAMETER;
1676 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1678 return TETHERING_ERROR_NONE;
1681 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
1683 DBG("+ type : %d\n", type);
1684 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1685 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1686 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1687 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1689 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1690 "parameter(tethering) is NULL\n");
1692 __tethering_h *th = (__tethering_h *)tethering;
1693 GDBusProxy *proxy = th->client_bus_proxy;
1694 GDBusConnection *connection = th->client_bus;
1697 case TETHERING_TYPE_WIFI:
1698 DBG("Disable wifi tethering..");
1699 g_dbus_connection_signal_unsubscribe(connection,
1700 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1702 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1703 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1704 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1705 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1707 case TETHERING_TYPE_BT:
1708 g_dbus_connection_signal_unsubscribe(connection,
1709 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1711 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1712 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1713 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1714 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1718 ERR("Not supported tethering type [%d]\n", type);
1720 return TETHERING_ERROR_INVALID_PARAMETER;
1723 return TETHERING_ERROR_NONE;
1727 * @brief Disables the tethering, asynchronously.
1729 * @privlevel platform
1730 * @privilege http://tizen.org/privilege/tethering.admin
1731 * @param[in] tethering The handle of tethering
1732 * @param[in] type The type of tethering
1733 * @return 0 on success, otherwise negative error value.
1734 * @retval #TETHERING_ERROR_NONE Successful
1735 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1736 * @post tethering_disabled_cb() will be invoked.
1737 * @see tethering_is_enabled()
1738 * @see tethering_enable()
1740 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1742 INFO("+ type : %d\n", type);
1743 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1744 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1745 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1746 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1748 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1749 "parameter(tethering) is NULL\n");
1751 __tethering_h *th = (__tethering_h *)tethering;
1752 GDBusProxy *proxy = th->client_bus_proxy;
1753 GDBusConnection *connection = th->client_bus;
1756 case TETHERING_TYPE_USB:
1757 g_dbus_connection_signal_unsubscribe(connection,
1758 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1760 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1761 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1762 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1766 case TETHERING_TYPE_WIFI:
1768 g_dbus_connection_signal_unsubscribe(connection,
1769 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1771 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1772 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1773 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1774 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1777 case TETHERING_TYPE_BT:
1779 g_dbus_connection_signal_unsubscribe(connection,
1780 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1782 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1783 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1784 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1785 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1788 case TETHERING_TYPE_ALL:
1789 g_dbus_connection_signal_unsubscribe(connection,
1790 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1792 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1793 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1794 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1796 g_dbus_connection_signal_unsubscribe(connection,
1797 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1799 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1800 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1801 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1802 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1804 g_dbus_connection_signal_unsubscribe(connection,
1805 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1807 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1808 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1809 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1810 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1814 ERR("Not supported tethering type [%d]\n", type);
1816 return TETHERING_ERROR_INVALID_PARAMETER;
1819 return TETHERING_ERROR_NONE;
1824 * @brief Checks whetehr the tethering is enabled or not.
1826 * @privlevel platform
1827 * @privilege http://tizen.org/privilege/tethering.admin
1828 * @param[in] tethering The handle of tethering
1829 * @param[in] type The type of tethering
1830 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1832 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1834 INFO("+ type : %d\n", type);
1836 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1838 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1840 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1844 case TETHERING_TYPE_USB:
1845 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1848 case TETHERING_TYPE_WIFI:
1849 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1852 case TETHERING_TYPE_BT:
1853 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1857 ERR("Not supported type : %d\n", type);
1860 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
1861 return is_on & vconf_type ? true : false;
1866 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1868 * @privlevel platform
1869 * @privilege http://tizen.org/privilege/tethering.admin
1870 * @remarks @a mac_address must be released with free() by you.
1871 * @param[in] tethering The handle of tethering
1872 * @param[in] type The type of tethering
1873 * @param[out] mac_address The MAC address
1874 * @return 0 on success, otherwise a negative error value.
1875 * @retval #TETHERING_ERROR_NONE Successful
1876 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1877 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1878 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1879 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1880 * @pre tethering must be enabled.
1881 * @see tethering_is_enabled()
1882 * @see tethering_enable()
1884 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1886 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1887 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1888 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1889 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1891 _retvm_if(tethering_is_enabled(tethering, type) == false,
1892 TETHERING_ERROR_NOT_ENABLED,
1893 "tethering type[%d] is not enabled\n", type);
1894 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1895 "parameter(tethering) is NULL\n");
1896 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1897 "parameter(mac_address) is NULL\n");
1901 char *macbuf = NULL;
1903 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
1904 TETHERING_ERROR_OPERATION_FAILED,
1905 "getting interface name is failed\n");
1907 s = socket(AF_INET, SOCK_DGRAM, 0);
1908 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
1909 "getting socket is failed\n");
1910 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
1911 ERR("getting mac is failed\n");
1913 return TETHERING_ERROR_OPERATION_FAILED;
1917 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
1918 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1919 "Not enough memory\n");
1920 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
1921 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
1922 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
1923 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
1924 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
1925 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
1926 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
1928 *mac_address = macbuf;
1930 return TETHERING_ERROR_NONE;
1935 * @brief Gets the name of network interface. For example, usb0.
1937 * @privlevel platform
1938 * @privilege http://tizen.org/privilege/tethering.admin
1939 * @remarks @a interface_name must be released with free() by you.
1940 * @param[in] tethering The handle of tethering
1941 * @param[in] type The type of tethering
1942 * @param[out] interface_name The name of network interface
1943 * @return 0 on success, otherwise negative error value.
1944 * @retval #TETHERING_ERROR_NONE Successful
1945 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1946 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1947 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1948 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1949 * @pre tethering must be enabled.
1950 * @see tethering_is_enabled()
1951 * @see tethering_enable()
1953 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
1955 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1956 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1957 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1958 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1960 _retvm_if(tethering_is_enabled(tethering, type) == false,
1961 TETHERING_ERROR_NOT_ENABLED,
1962 "tethering type[%d] is not enabled\n", type);
1963 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1964 "parameter(tethering) is NULL\n");
1965 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1966 "parameter(interface_name) is NULL\n");
1968 char intf[TETHERING_STR_INFO_LEN] = {0, };
1970 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
1971 TETHERING_ERROR_OPERATION_FAILED,
1972 "getting interface name is failed\n");
1973 *interface_name = strdup(intf);
1974 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1975 "Not enough memory\n");
1977 return TETHERING_ERROR_NONE;
1982 * @brief Gets the local IP address.
1984 * @privlevel platform
1985 * @privilege http://tizen.org/privilege/tethering.admin
1986 * @remarks @a ip_address must be released with free() by you.
1987 * @param[in] tethering The handle of tethering
1988 * @param[in] type The type of tethering
1989 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
1990 * @param[out] ip_address The local IP address
1991 * @return 0 on success, otherwise negative error value.
1992 * @retval #TETHERING_ERROR_NONE Successful
1993 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1994 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1995 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1996 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1997 * @pre tethering must be enabled.
1998 * @see tethering_is_enabled()
1999 * @see tethering_enable()
2001 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2003 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2004 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2005 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2006 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2008 _retvm_if(tethering_is_enabled(tethering, type) == false,
2009 TETHERING_ERROR_NOT_ENABLED,
2010 "tethering type[%d] is not enabled\n", type);
2011 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2012 "parameter(tethering) is NULL\n");
2013 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2014 "parameter(ip_address) is NULL\n");
2020 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2021 TETHERING_ERROR_OPERATION_FAILED,
2022 "getting interface name is failed\n");
2024 s = socket(AF_INET, SOCK_DGRAM, 0);
2025 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2026 "getting socket is failed\n");
2027 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2028 ERR("ioctl is failed\n");
2030 return TETHERING_ERROR_OPERATION_FAILED;
2034 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2035 *ip_address = strdup(ipbuf);
2036 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2037 "Not enough memory\n");
2039 return TETHERING_ERROR_NONE;
2044 * @brief Gets the Gateway address.
2046 * @privlevel platform
2047 * @privilege http://tizen.org/privilege/tethering.admin
2048 * @remarks @a gateway_address must be released with free() by you.
2049 * @param[in] tethering The handle of tethering
2050 * @param[in] type The type of tethering
2051 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2052 * @param[out] gateway_address The local IP address
2053 * @return 0 on success, otherwise negative error value.
2054 * @retval #TETHERING_ERROR_NONE Successful
2055 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2056 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2057 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2058 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2059 * @pre tethering must be enabled.
2060 * @see tethering_is_enabled()
2061 * @see tethering_enable()
2063 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2065 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2066 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2067 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2068 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2070 _retvm_if(tethering_is_enabled(tethering, type) == false,
2071 TETHERING_ERROR_NOT_ENABLED,
2072 "tethering type[%d] is not enabled\n", type);
2073 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2074 "parameter(tethering) is NULL\n");
2075 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2076 "parameter(gateway_address) is NULL\n");
2078 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2080 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2081 TETHERING_ERROR_OPERATION_FAILED,
2082 "getting gateway address is failed\n");
2084 *gateway_address = strdup(gateway_buf);
2086 return TETHERING_ERROR_NONE;
2091 * @brief Gets the Subnet Mask.
2093 * @privlevel platform
2094 * @privilege http://tizen.org/privilege/tethering.admin
2095 * @remarks @a subnet_mask must be released with free() by you.
2096 * @param[in] tethering The handle of tethering
2097 * @param[in] type The type of tethering
2098 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2099 * @param[out] subnet_mask The local IP address
2100 * @return 0 on success, otherwise negative error value.
2101 * @retval #TETHERING_ERROR_NONE Successful
2102 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2103 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2104 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2105 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2106 * @pre tethering must be enabled.
2107 * @see tethering_is_enabled()
2108 * @see tethering_enable()
2110 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2112 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2113 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2114 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2115 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2117 _retvm_if(tethering_is_enabled(tethering, type) == false,
2118 TETHERING_ERROR_NOT_ENABLED,
2119 "tethering is not enabled\n");
2120 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2121 "parameter(tethering) is NULL\n");
2122 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2123 "parameter(subnet_mask) is NULL\n");
2125 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2126 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2127 "Not enough memory\n");
2129 return TETHERING_ERROR_NONE;
2134 * @brief Gets the data usage.
2136 * @privlevel platform
2137 * @privilege http://tizen.org/privilege/tethering.admin
2138 * @param[in] tethering The handle of tethering
2139 * @param[out] usage The data usage
2140 * @return 0 on success, otherwise negative error value.
2141 * @retval #TETHERING_ERROR_NONE Successful
2142 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2143 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2144 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2145 * @pre tethering must be enabled.
2146 * @see tethering_is_enabled()
2147 * @see tethering_enable()
2149 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2151 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2153 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2154 "parameter(tethering) is NULL\n");
2155 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2156 "parameter(callback) is NULL\n");
2157 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2158 TETHERING_ERROR_NOT_ENABLED,
2159 "tethering is not enabled\n");
2161 __tethering_h *th = (__tethering_h *)tethering;
2162 GDBusProxy *proxy = th->client_bus_proxy;
2164 th->data_usage_cb = callback;
2165 th->data_usage_user_data = user_data;
2167 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2168 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2169 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2171 return TETHERING_ERROR_NONE;
2176 * @brief Gets the client which is connected by tethering "type".
2178 * @privlevel platform
2179 * @privilege http://tizen.org/privilege/tethering.admin
2180 * @param[in] tethering The handle of tethering
2181 * @param[in] type The type of tethering
2182 * @param[in] callback The callback function to invoke
2183 * @param[in] user_data The user data to be passed to the callback function
2184 * @retval #TETHERING_ERROR_NONE Successful
2185 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2186 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2187 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2188 * @pre tethering must be enabled.
2189 * @see tethering_is_enabled()
2190 * @see tethering_enable()
2192 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2194 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2195 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2196 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2197 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2199 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2200 "parameter(tethering) is NULL\n");
2201 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2202 "parameter(callback) is NULL\n");
2203 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2204 TETHERING_ERROR_NOT_ENABLED,
2205 "tethering is not enabled\n");
2207 mobile_ap_type_e interface;
2208 __tethering_h *th = (__tethering_h *)tethering;
2209 __tethering_client_h client = {0, };
2212 gchar *hostname = NULL;
2213 guint timestamp = 0;
2214 GError *error = NULL;
2215 GVariant *result = NULL;
2216 GVariantIter *outer_iter = NULL;
2217 GVariantIter *inner_iter = NULL;
2218 GVariant *station = NULL;
2219 GVariant *value = NULL;
2222 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2223 NULL, G_DBUS_CALL_FLAGS_NONE,
2224 -1, th->cancellable, &error);
2226 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2227 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2228 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2229 g_variant_get(station, "a{sv}", &inner_iter);
2230 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2231 if (g_strcmp0(key, "Type") == 0) {
2232 interface = g_variant_get_int32(value);
2233 if (interface == MOBILE_AP_TYPE_USB)
2234 client.interface = TETHERING_TYPE_USB;
2235 else if (interface == MOBILE_AP_TYPE_WIFI)
2236 client.interface = TETHERING_TYPE_WIFI;
2237 else if (interface == MOBILE_AP_TYPE_BT)
2238 client.interface = TETHERING_TYPE_BT;
2240 ERR("Invalid interface\n");
2242 g_variant_unref(value);
2245 DBG("interface is %d\n", client.interface);
2246 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2248 g_variant_unref(value);
2251 } else if (g_strcmp0(key, "IP") == 0) {
2252 g_variant_get(value, "s", &ip);
2253 SDBG("ip is %s\n", ip);
2254 g_strlcpy(client.ip, ip, sizeof(client.ip));
2255 } else if (g_strcmp0(key, "MAC") == 0) {
2256 g_variant_get(value, "s", &mac);
2257 SDBG("mac is %s\n", mac);
2258 g_strlcpy(client.mac, mac, sizeof(client.mac));
2259 } else if (g_strcmp0(key, "Name") == 0) {
2260 g_variant_get(value, "s", &hostname);
2261 SDBG("hsotname is %s\n", hostname);
2263 client.hostname = g_strdup(hostname);
2264 } else if (g_strcmp0(key, "Time") == 0) {
2265 timestamp = g_variant_get_int32(value);
2266 DBG("timestamp is %d\n", timestamp);
2267 client.tm = (time_t)timestamp;
2269 ERR("Key %s not required\n", key);
2275 g_variant_iter_free(inner_iter);
2276 if (callback((tethering_client_h)&client, user_data) == false) {
2277 DBG("iteration is stopped\n");
2278 g_free(client.hostname);
2279 g_variant_iter_free(outer_iter);
2280 g_variant_unref(station);
2281 g_variant_unref(result);
2283 return TETHERING_ERROR_OPERATION_FAILED;
2285 g_free(client.hostname);
2287 g_variant_iter_free(outer_iter);
2288 g_variant_unref(station);
2289 g_variant_unref(result);
2291 return TETHERING_ERROR_NONE;
2296 * @brief Registers the callback function called when tethering is enabled.
2298 * @privlevel platform
2299 * @privilege http://tizen.org/privilege/tethering.admin
2300 * @param[in] tethering The handle of tethering
2301 * @param[in] type The type of tethering
2302 * @param[in] callback The callback function to invoke
2303 * @param[in] user_data The user data to be passed to the callback function
2304 * @retval #TETHERING_ERROR_NONE Successful
2305 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2306 * @see tethering_unset_enabled_cb()
2308 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2310 INFO("+ type: %d\n", type);
2311 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2312 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2313 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2314 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2316 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2317 "parameter(tethering) is NULL\n");
2318 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2319 "parameter(callback) is NULL\n");
2321 __tethering_h *th = (__tethering_h *)tethering;
2322 tethering_type_e ti;
2324 if (type != TETHERING_TYPE_ALL) {
2325 th->enabled_cb[type] = callback;
2326 th->enabled_user_data[type] = user_data;
2328 return TETHERING_ERROR_NONE;
2331 /* TETHERING_TYPE_ALL */
2332 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2333 th->enabled_cb[ti] = callback;
2334 th->enabled_user_data[ti] = user_data;
2338 return TETHERING_ERROR_NONE;
2343 * @brief Unregisters the callback function called when tethering is disabled.
2345 * @privlevel platform
2346 * @privilege http://tizen.org/privilege/tethering.admin
2347 * @param[in] tethering The handle of tethering
2348 * @param[in] type The type of tethering
2349 * @retval #TETHERING_ERROR_NONE Successful
2350 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2351 * @see tethering_set_enabled_cb()
2353 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2355 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2356 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2357 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2358 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2360 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2361 "parameter(tethering) is NULL\n");
2363 __tethering_h *th = (__tethering_h *)tethering;
2364 tethering_type_e ti;
2366 if (type != TETHERING_TYPE_ALL) {
2367 th->enabled_cb[type] = NULL;
2368 th->enabled_user_data[type] = NULL;
2370 return TETHERING_ERROR_NONE;
2373 /* TETHERING_TYPE_ALL */
2374 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2375 th->enabled_cb[ti] = NULL;
2376 th->enabled_user_data[ti] = NULL;
2379 return TETHERING_ERROR_NONE;
2384 * @brief Registers the callback function called when tethering is disabled.
2386 * @privlevel platform
2387 * @privilege http://tizen.org/privilege/tethering.admin
2388 * @param[in] tethering The handle of tethering
2389 * @param[in] type The type of tethering
2390 * @param[in] callback The callback function to invoke
2391 * @param[in] user_data The user data to be passed to the callback function
2392 * @retval #TETHERING_ERROR_NONE Successful
2393 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2394 * @see tethering_unset_disabled_cb()
2396 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2398 INFO("+ type: %d\n", type);
2399 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2400 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2401 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2402 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2404 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2405 "parameter(tethering) is NULL\n");
2406 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2407 "parameter(callback) is NULL\n");
2409 __tethering_h *th = (__tethering_h *)tethering;
2410 tethering_type_e ti;
2412 if (type != TETHERING_TYPE_ALL) {
2413 th->disabled_cb[type] = callback;
2414 th->disabled_user_data[type] = user_data;
2416 return TETHERING_ERROR_NONE;
2419 /* TETHERING_TYPE_ALL */
2420 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2421 th->disabled_cb[ti] = callback;
2422 th->disabled_user_data[ti] = user_data;
2425 return TETHERING_ERROR_NONE;
2430 * @brief Unregisters the callback function called when tethering is disabled.
2432 * @privlevel platform
2433 * @privilege http://tizen.org/privilege/tethering.admin
2434 * @param[in] tethering The handle of tethering
2435 * @param[in] type The type of tethering
2436 * @retval #TETHERING_ERROR_NONE Successful
2437 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2438 * @see tethering_set_disabled_cb()
2440 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2442 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2443 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2444 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2445 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2447 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2448 "parameter(tethering) is NULL\n");
2450 __tethering_h *th = (__tethering_h *)tethering;
2451 tethering_type_e ti;
2453 if (type != TETHERING_TYPE_ALL) {
2454 th->disabled_cb[type] = NULL;
2455 th->disabled_user_data[type] = NULL;
2457 return TETHERING_ERROR_NONE;
2460 /* TETHERING_TYPE_ALL */
2461 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2462 th->disabled_cb[ti] = NULL;
2463 th->disabled_user_data[ti] = NULL;
2466 return TETHERING_ERROR_NONE;
2471 * @brief Registers the callback function called when the state of connection is changed.
2473 * @privlevel platform
2474 * @privilege http://tizen.org/privilege/tethering.admin
2475 * @param[in] tethering The handle of tethering
2476 * @param[in] type The type of tethering
2477 * @param[in] callback The callback function to invoke
2478 * @param[in] user_data The user data to be passed to the callback function
2479 * @retval #TETHERING_ERROR_NONE Successful
2480 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2481 * @see tethering_unset_connection_state_changed_cb_cb()
2483 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2485 INFO("+ type: %d\n", type);
2486 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2487 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2488 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2489 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2491 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2492 "parameter(tethering) is NULL\n");
2493 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2494 "parameter(callback) is NULL\n");
2496 __tethering_h *th = (__tethering_h *)tethering;
2497 tethering_type_e ti;
2499 if (type != TETHERING_TYPE_ALL) {
2500 th->changed_cb[type] = callback;
2501 th->changed_user_data[type] = user_data;
2503 return TETHERING_ERROR_NONE;
2506 /* TETHERING_TYPE_ALL */
2507 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2508 th->changed_cb[ti] = callback;
2509 th->changed_user_data[ti] = user_data;
2512 return TETHERING_ERROR_NONE;
2517 * @brief Unregisters the callback function called when the state of connection is changed.
2519 * @privlevel platform
2520 * @privilege http://tizen.org/privilege/tethering.admin
2521 * @param[in] tethering The handle of tethering
2522 * @param[in] type The type of tethering
2523 * @retval #TETHERING_ERROR_NONE Successful
2524 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2525 * @see tethering_set_connection_state_changed_cb()
2527 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2529 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2530 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2531 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2532 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2534 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2535 "parameter(tethering) is NULL\n");
2537 __tethering_h *th = (__tethering_h *)tethering;
2538 tethering_type_e ti;
2540 if (type != TETHERING_TYPE_ALL) {
2541 th->changed_cb[type] = NULL;
2542 th->changed_user_data[type] = NULL;
2544 return TETHERING_ERROR_NONE;
2547 /* TETHERING_TYPE_ALL */
2548 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_BT; ti++) {
2549 th->changed_cb[ti] = NULL;
2550 th->changed_user_data[ti] = NULL;
2553 return TETHERING_ERROR_NONE;
2558 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2560 * @privlevel platform
2561 * @privilege http://tizen.org/privilege/tethering.admin
2562 * @param[in] tethering The handle of tethering
2563 * @param[in] callback The callback function to invoke
2564 * @param[in] user_data The user data to be passed to the callback function
2565 * @retval #TETHERING_ERROR_NONE Successful
2566 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2567 * @see tethering_wifi_unset_security_type_changed_cb()
2569 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2571 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2572 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2574 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2575 "parameter(tethering) is NULL\n");
2576 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2577 "parameter(callback) is NULL\n");
2579 __tethering_h *th = (__tethering_h *)tethering;
2581 th->security_type_changed_cb = callback;
2582 th->security_type_user_data = user_data;
2584 return TETHERING_ERROR_NONE;
2590 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2592 * @privlevel platform
2593 * @privilege http://tizen.org/privilege/tethering.admin
2594 * @param[in] tethering The handle of tethering
2595 * @param[in] type The type of tethering
2596 * @retval #TETHERING_ERROR_NONE Successful
2597 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2598 * @see tethering_wifi_set_security_type_changed_cb()
2600 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2602 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2603 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2605 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2606 "parameter(tethering) is NULL\n");
2608 __tethering_h *th = (__tethering_h *)tethering;
2610 th->security_type_changed_cb = NULL;
2611 th->security_type_user_data = NULL;
2613 return TETHERING_ERROR_NONE;
2618 * @brief Registers the callback function called when the visibility of SSID is changed.
2620 * @privlevel platform
2621 * @privilege http://tizen.org/privilege/tethering.admin
2622 * @param[in] tethering The handle of tethering
2623 * @param[in] callback The callback function to invoke
2624 * @param[in] user_data The user data to be passed to the callback function
2625 * @retval #TETHERING_ERROR_NONE Successful
2626 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2627 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2629 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2631 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2632 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2634 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2635 "parameter(tethering) is NULL\n");
2636 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2637 "parameter(callback) is NULL\n");
2639 __tethering_h *th = (__tethering_h *)tethering;
2641 th->ssid_visibility_changed_cb = callback;
2642 th->ssid_visibility_user_data = user_data;
2644 return TETHERING_ERROR_NONE;
2649 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2651 * @privlevel platform
2652 * @privilege http://tizen.org/privilege/tethering.admin
2653 * @param[in] tethering The handle of tethering
2654 * @retval #TETHERING_ERROR_NONE Successful
2655 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2656 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2658 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2660 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2661 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2663 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2664 "parameter(tethering) is NULL\n");
2666 __tethering_h *th = (__tethering_h *)tethering;
2668 th->ssid_visibility_changed_cb = NULL;
2669 th->ssid_visibility_user_data = NULL;
2671 return TETHERING_ERROR_NONE;
2676 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2678 * @privlevel platform
2679 * @privilege http://tizen.org/privilege/tethering.admin
2680 * @param[in] tethering The handle of tethering
2681 * @param[in] callback The callback function to invoke
2682 * @param[in] user_data The user data to be passed to the callback function
2683 * @retval #TETHERING_ERROR_NONE Successful
2684 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2685 * @see tethering_wifi_unset_passphrase_changed_cb()
2687 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2689 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2690 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2692 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2693 "parameter(tethering) is NULL\n");
2694 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2695 "parameter(callback) is NULL\n");
2697 __tethering_h *th = (__tethering_h *)tethering;
2699 th->passphrase_changed_cb = callback;
2700 th->passphrase_user_data = user_data;
2702 return TETHERING_ERROR_NONE;
2707 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2709 * @privlevel platform
2710 * @privilege http://tizen.org/privilege/tethering.admin
2711 * @param[in] tethering The handle of tethering
2712 * @retval #TETHERING_ERROR_NONE Successful
2713 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2714 * @see tethering_wifi_set_passphrase_changed_cb()
2716 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2718 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2719 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2721 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2722 "parameter(tethering) is NULL\n");
2724 __tethering_h *th = (__tethering_h *)tethering;
2726 th->passphrase_changed_cb = NULL;
2727 th->passphrase_user_data = NULL;
2729 return TETHERING_ERROR_NONE;
2734 * @brief Sets the security type of Wi-Fi tethering.
2736 * @privlevel platform
2737 * @privilege http://tizen.org/privilege/tethering.admin
2738 * @remarks This change is applied next time Wi-Fi tethering is enabled
2739 * @param[in] tethering The handle of tethering
2740 * @param[in] type The security type
2741 * @return 0 on success, otherwise negative error value.
2742 * @retval #TETHERING_ERROR_NONE Successful
2743 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2744 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2745 * @see tethering_wifi_get_security_type()
2747 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2749 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2750 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2752 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2753 "parameter(tethering) is NULL\n");
2755 __tethering_h *th = (__tethering_h *)tethering;
2756 tethering_error_e ret = TETHERING_ERROR_NONE;
2757 char *sec_str = NULL;
2759 ret = __set_security_type(type);
2760 if (ret == TETHERING_ERROR_NONE) {
2763 case TETHERING_WIFI_SECURITY_TYPE_NONE:
2764 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
2766 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
2767 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
2769 case TETHERING_WIFI_SECURITY_TYPE_WPS:
2770 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
2774 __send_dbus_signal(th->client_bus,
2775 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
2782 * @brief Gets the security type of Wi-Fi tethering.
2784 * @privlevel platform
2785 * @privilege http://tizen.org/privilege/tethering.admin
2786 * @param[in] tethering The handle of tethering
2787 * @param[out] type The security type
2788 * @return 0 on success, otherwise negative error value.
2789 * @retval #TETHERING_ERROR_NONE Successful
2790 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2791 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2792 * @see tethering_wifi_set_security_type()
2794 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2796 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2797 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2799 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2800 "parameter(type) is NULL\n");
2802 return __get_security_type(type);
2807 * @brief Sets the SSID (service set identifier).
2809 * @privlevel platform
2810 * @privilege http://tizen.org/privilege/tethering.admin
2811 * @details If SSID is not set, Device name is used as SSID
2812 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2813 * @param[in] tethering The handle of tethering
2814 * @param[out] ssid The SSID
2815 * @return 0 on success, otherwise negative error value.
2816 * @retval #TETHERING_ERROR_NONE Successful
2817 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2818 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2820 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2822 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2823 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2825 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2826 "parameter(tethering) is NULL\n");
2827 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2828 "parameter(ssid) is NULL\n");
2830 __tethering_h *th = (__tethering_h *)tethering;
2831 char *p_ssid = NULL;
2834 ssid_len = strlen(ssid);
2835 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2836 ERR("parameter(ssid) is too long");
2837 return TETHERING_ERROR_INVALID_PARAMETER;
2840 p_ssid = strdup(ssid);
2841 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2842 "strdup is failed\n");
2848 return TETHERING_ERROR_NONE;
2853 * @brief Gets the SSID (service set identifier).
2855 * @privlevel platform
2856 * @privilege http://tizen.org/privilege/tethering.admin
2857 * @remarks @a ssid must be released with free() by you.
2858 * @param[in] tethering The handle of tethering
2859 * @param[out] ssid The SSID
2860 * @return 0 on success, otherwise negative error value.
2861 * @retval #TETHERING_ERROR_NONE Successful
2862 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2863 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2864 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2866 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2868 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2869 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2871 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2872 "parameter(tethering) is NULL\n");
2873 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2874 "parameter(ssid) is NULL\n");
2877 __tethering_h *th = (__tethering_h *)tethering;
2878 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2880 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2881 if (th->ssid != NULL) {
2882 DBG("Private SSID is set\n");
2883 *ssid = strdup(th->ssid);
2885 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2886 val, sizeof(val)) == false) {
2887 return TETHERING_ERROR_OPERATION_FAILED;
2889 *ssid = strdup(val);
2892 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2893 val, sizeof(val)) == false) {
2894 return TETHERING_ERROR_OPERATION_FAILED;
2896 *ssid = strdup(val);
2899 if (*ssid == NULL) {
2900 ERR("strdup is failed\n");
2901 return TETHERING_ERROR_OUT_OF_MEMORY;
2904 return TETHERING_ERROR_NONE;
2909 * @brief Sets the visibility of SSID(service set identifier).
2911 * @privlevel platform
2912 * @privilege http://tizen.org/privilege/tethering.admin
2913 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2914 * @remarks This change is applied next time Wi-Fi tethering is enabled
2915 * @param[in] tethering The handle of tethering
2916 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2917 * @return 0 on success, otherwise negative error value.
2918 * @retval #TETHERING_ERROR_NONE Successful
2919 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2920 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2921 * @see tethering_wifi_get_ssid_visibility()
2923 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
2925 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2926 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2928 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2929 "parameter(tethering) is NULL\n");
2931 __tethering_h *th = (__tethering_h *)tethering;
2932 tethering_error_e ret = TETHERING_ERROR_NONE;
2934 ret = __set_visible(visible);
2935 if (ret == TETHERING_ERROR_NONE) {
2937 __send_dbus_signal(th->client_bus,
2938 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
2939 visible ? SIGNAL_MSG_SSID_VISIBLE :
2940 SIGNAL_MSG_SSID_HIDE);
2947 * @brief Gets the visibility of SSID(service set identifier).
2949 * @privlevel platform
2950 * @privilege http://tizen.org/privilege/tethering.admin
2951 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
2952 * @param[in] tethering The handle of tethering
2953 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
2954 * @return 0 on success, otherwise negative error value.
2955 * @retval #TETHERING_ERROR_NONE Successful
2956 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2957 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2958 * @see tethering_wifi_set_ssid_visibility()
2960 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
2962 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2963 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2965 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2966 "parameter(visible) is NULL\n");
2968 return __get_visible(visible);
2973 * @brief Sets the passphrase.
2975 * @privlevel platform
2976 * @privilege http://tizen.org/privilege/tethering.admin
2977 * @remarks This change is applied next time Wi-Fi tethering is enabled
2978 * @param[in] tethering The handle of tethering
2979 * @param[in] passphrase The passphrase
2980 * @return 0 on success, otherwise negative error value.
2981 * @retval #TETHERING_ERROR_NONE Successful
2982 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2983 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2984 * @see tethering_wifi_get_passphrase()
2986 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
2988 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2989 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2991 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2992 "parameter(tethering) is NULL\n");
2993 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2994 "parameter(passphrase) is NULL\n");
2996 __tethering_h *th = (__tethering_h *)tethering;
2997 GDBusProxy *proxy = th->client_bus_proxy;
2998 GVariant *parameters;
2999 GError *error = NULL;
3000 int passphrase_len = 0;
3004 passphrase_len = strlen(passphrase);
3005 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3006 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3007 ERR("parameter(passphrase) is too short or long\n");
3008 return TETHERING_ERROR_INVALID_PARAMETER;
3011 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3012 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3016 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3018 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3019 ret = TETHERING_ERROR_PERMISSION_DENIED;
3021 ret = TETHERING_ERROR_OPERATION_FAILED;
3023 g_error_free(error);
3028 g_variant_get(parameters, "(u)", &ret);
3029 g_variant_unref(parameters);
3031 if (ret == TETHERING_ERROR_NONE) {
3032 __send_dbus_signal(th->client_bus,
3033 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3042 * @brief Gets the passphrase.
3044 * @privlevel platform
3045 * @privilege http://tizen.org/privilege/tethering.admin
3046 * @remarks @a passphrase must be released with free() by you.
3047 * @param[in] tethering The handle of tethering
3048 * @param[out] passphrase The passphrase
3049 * @return 0 on success, otherwise negative error value.
3050 * @retval #TETHERING_ERROR_NONE Successful
3051 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3052 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3053 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3054 * @see tethering_wifi_set_passphrase()
3056 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3058 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3059 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3061 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3062 "parameter(tethering) is NULL\n");
3063 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3064 "parameter(passphrase) is NULL\n");
3066 __tethering_h *th = (__tethering_h *)tethering;
3067 GDBusProxy *proxy = th->client_bus_proxy;
3068 GVariant *parameters;
3069 GError *error = NULL;
3070 unsigned int len = 0;
3071 tethering_error_e ret = TETHERING_ERROR_NONE;
3073 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3074 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3078 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3080 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3081 ret = TETHERING_ERROR_PERMISSION_DENIED;
3083 ret = TETHERING_ERROR_OPERATION_FAILED;
3085 g_error_free(error);
3090 if (parameters != NULL) {
3091 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3092 g_variant_unref(parameters);
3095 return TETHERING_ERROR_NONE;
3098 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3100 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3101 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3103 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3104 "parameter(tethering) is NULL\n");
3106 __tethering_h *th = (__tethering_h *)tethering;
3107 th->channel = channel;
3109 return TETHERING_ERROR_NONE;
3112 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3114 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3115 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3117 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3118 "parameter(tethering) is NULL\n");
3120 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3121 "parameter(channel) is NULL\n");
3123 __tethering_h *th = (__tethering_h *)tethering;
3124 *channel = th->channel;
3126 return TETHERING_ERROR_NONE;
3129 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3131 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3132 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3134 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3135 "parameter(tethering) is NULL\n");
3137 __tethering_h *th = (__tethering_h *)tethering;
3139 th->mode_type = type;
3141 return TETHERING_ERROR_NONE;
3144 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3146 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3147 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3149 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3150 "parameter(tethering) is NULL\n");
3151 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3152 "parameter(type) is NULL\n");
3154 __tethering_h *th = (__tethering_h *)tethering;
3155 *type = th->mode_type;
3157 return TETHERING_ERROR_NONE;
3163 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3165 * @privlevel platform
3166 * @privilege http://tizen.org/privilege/tethering.admin
3167 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3168 * @param[in] tethering The handle of tethering
3169 * @param[in] callback The callback function to invoke
3170 * @param[in] user_data The user data to be passed to the callback function
3171 * @return 0 on success, otherwise negative error value.
3172 * @retval #TETHERING_ERROR_NONE Successful
3173 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3174 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3176 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3179 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3180 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3182 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3183 "parameter(tethering) is NULL\n");
3184 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3185 "parameter(callback) is NULL\n");
3187 __tethering_h *th = (__tethering_h *)tethering;
3188 _softap_settings_t set = {"", "", "", 0, false};
3189 GDBusProxy *proxy = th->client_bus_proxy;
3194 if (th->settings_reloaded_cb) {
3195 ERR("Operation in progress\n");
3196 return TETHERING_ERROR_OPERATION_FAILED;
3199 ret = __prepare_wifi_settings(tethering, &set);
3200 if (ret != TETHERING_ERROR_NONE) {
3201 ERR("softap settings initialization failed\n");
3202 return TETHERING_ERROR_OPERATION_FAILED;
3205 th->settings_reloaded_cb = callback;
3206 th->settings_reloaded_user_data = user_data;
3208 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3209 g_variant_new("(sssiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type),
3210 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3211 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3213 return TETHERING_ERROR_NONE;
3216 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3218 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3219 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3221 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3222 "parameter(tethering) is NULL\n");
3224 __tethering_h *th = (__tethering_h *)tethering;
3225 th->mac_filter = mac_filter;
3227 return TETHERING_ERROR_NONE;
3230 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3232 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3233 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3235 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3236 "parameter(mac_filter) is NULL\n");
3237 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3238 "parameter(mac_filter) is NULL\n");
3240 __tethering_h *th = (__tethering_h *)tethering;
3241 *mac_filter = th->mac_filter;
3243 return TETHERING_ERROR_NONE;
3246 static int __add_mac_to_file(const char *filepath, const char *mac)
3249 char line[MAX_BUF_SIZE] = "\0";
3250 bool mac_exist = false;
3253 p_mac = strdup(mac);
3254 if (p_mac == NULL) {
3255 ERR("strdup failed\n");
3256 return TETHERING_ERROR_OUT_OF_MEMORY;
3259 fp = fopen(filepath, "a+");
3261 ERR("fopen is failed\n");
3262 return TETHERING_ERROR_OPERATION_FAILED;
3265 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3266 if (strncmp(mac, line, 17) == 0) {
3267 DBG("MAC %s already exist in the list\n", mac);
3274 fprintf(fp, "%s\n", mac);
3276 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3277 allowed_list = g_slist_append(allowed_list, p_mac);
3278 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3279 blocked_list = g_slist_append(blocked_list, p_mac);
3284 return TETHERING_ERROR_NONE;
3287 static int __remove_mac_from_file(const char *filepath, const char *mac)
3291 char line[MAX_BUF_SIZE] = "\0";
3293 fp = fopen(filepath, "r");
3295 ERR("fopen is failed\n");
3296 return TETHERING_ERROR_OPERATION_FAILED;
3299 fp1 = fopen(TEMP_LIST, "w+");
3302 ERR("fopen is failed\n");
3303 return TETHERING_ERROR_OPERATION_FAILED;
3306 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3307 if (strncmp(mac, line, 17) == 0) {
3308 DBG("MAC %s found in the list\n", mac);
3310 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3311 GSList *list = NULL;
3312 for (list = allowed_list; list != NULL; list = list->next) {
3313 char *p_mac = (char *)list->data;
3314 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3315 allowed_list = g_slist_remove(allowed_list, p_mac);
3317 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3318 GSList *list = NULL;
3319 for (list = blocked_list; list != NULL; list = list->next) {
3320 char *p_mac = (char *)list->data;
3321 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3322 blocked_list = g_slist_remove(blocked_list, p_mac);
3326 fprintf(fp1, "%s", line);
3333 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3334 rename(TEMP_LIST, ALLOWED_LIST);
3335 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3336 rename(TEMP_LIST, BLOCKED_LIST);
3338 return TETHERING_ERROR_NONE;
3341 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3343 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3344 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3346 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3347 "parameter(tethering) is NULL\n");
3348 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3349 "parameter(mac) is NULL\n");
3351 return __add_mac_to_file(ALLOWED_LIST, mac);
3354 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3356 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3357 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3359 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3360 "parameter(tethering) is NULL\n");
3361 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3362 "parameter(mac) is NULL\n");
3364 return __remove_mac_from_file(ALLOWED_LIST, mac);
3367 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3369 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3370 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3372 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3373 "parameter(tethering) is NULL\n");
3374 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3375 "parameter(allowed_mac_list) is NULL\n");
3377 *allowed_mac_list = g_slist_copy(allowed_list);
3378 return TETHERING_ERROR_NONE;
3381 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3383 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3384 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3386 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3387 "parameter(tethering) is NULL\n");
3388 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3389 "parameter(mac) is NULL\n");
3391 return __add_mac_to_file(BLOCKED_LIST, mac);
3394 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3396 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3397 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3399 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3400 "parameter(tethering) is NULL\n");
3401 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3402 "parameter(mac) is NULL\n");
3404 return __remove_mac_from_file(BLOCKED_LIST, mac);
3407 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3409 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3410 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3412 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3413 "parameter(tethering) is NULL\n");
3414 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3415 "parameter(blocked_mac_list) is NULL\n");
3417 *blocked_mac_list = g_slist_copy(blocked_list);
3418 return TETHERING_ERROR_NONE;
3421 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3423 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3424 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3426 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3427 "parameter(tethering) is NULL\n");
3429 GVariant *parameters;
3430 GError *error = NULL;
3433 __tethering_h *th = (__tethering_h *)tethering;
3435 GDBusProxy *proxy = th->client_bus_proxy;
3437 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3438 g_variant_new("(b)", enable),
3439 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3442 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3443 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3444 result = TETHERING_ERROR_PERMISSION_DENIED;
3446 result = TETHERING_ERROR_OPERATION_FAILED;
3448 g_error_free(error);
3449 th->dhcp_enabled = false;
3454 g_variant_get(parameters, "(u)", &result);
3455 g_variant_unref(parameters);
3458 th->dhcp_enabled = true;
3460 th->dhcp_enabled = false;
3462 return TETHERING_ERROR_NONE;
3465 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3467 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3468 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3470 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3471 "parameter(tethering) is NULL\n");
3472 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3473 "parameter(rangestart) is NULL\n");
3474 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3475 "parameter(rangestop) is NULL\n");
3477 GVariant *parameters;
3478 GError *error = NULL;
3481 __tethering_h *th = (__tethering_h *)tethering;
3483 GDBusProxy *proxy = th->client_bus_proxy;
3485 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3486 g_variant_new("(ss)", rangestart, rangestop),
3487 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3489 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3491 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3492 result = TETHERING_ERROR_PERMISSION_DENIED;
3494 result = TETHERING_ERROR_OPERATION_FAILED;
3496 g_error_free(error);
3497 th->dhcp_enabled = false;
3502 g_variant_get(parameters, "(u)", &result);
3503 g_variant_unref(parameters);
3505 th->dhcp_enabled = true;
3507 return TETHERING_ERROR_NONE;
3510 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3512 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3513 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3515 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3516 "parameter(tethering) is NULL\n");
3517 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3518 "parameter(dhcp_enabled) is NULL\n");
3520 __tethering_h *th = (__tethering_h *)tethering;
3521 *dhcp_enabled = th->dhcp_enabled;
3523 return TETHERING_ERROR_NONE;
3526 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3528 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3529 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3531 GError *error = NULL;
3533 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3534 "parameter(tethering) is NULL\n");
3535 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3536 TETHERING_ERROR_NOT_ENABLED,
3537 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3538 __tethering_h *th = (__tethering_h *)tethering;
3540 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3541 g_variant_new("(u)", txpower),
3542 G_DBUS_CALL_FLAGS_NONE,
3543 -1, th->cancellable, &error);
3545 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3546 g_clear_error(&error);
3547 return TETHERING_ERROR_OPERATION_FAILED;
3549 return TETHERING_ERROR_NONE;
3552 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3554 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3555 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3557 GError *error = NULL;
3558 GVariant *result = NULL;
3560 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3561 "parameter(tethering) is NULL\n");
3562 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3563 TETHERING_ERROR_NOT_ENABLED,
3564 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3566 __tethering_h *th = (__tethering_h *)tethering;
3568 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3570 G_DBUS_CALL_FLAGS_NONE,
3571 -1, th->cancellable, &error);
3573 if (result != NULL) {
3574 g_variant_get(result, "(u)", txpower);
3575 g_variant_unref(result);
3578 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3579 g_clear_error(&error);
3580 return TETHERING_ERROR_OPERATION_FAILED;
3582 g_clear_error(&error);
3583 return TETHERING_ERROR_NONE;
3586 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
3588 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3589 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3591 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3592 "parameter(tethering) is NULL\n");
3594 GVariant *parameters;
3595 GError *error = NULL;
3598 __tethering_h *th = (__tethering_h *)tethering;
3600 GDBusProxy *proxy = th->client_bus_proxy;
3602 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
3603 g_variant_new("(u)", mtu),
3604 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3606 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3608 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3609 result = TETHERING_ERROR_PERMISSION_DENIED;
3611 result = TETHERING_ERROR_OPERATION_FAILED;
3613 g_error_free(error);
3617 g_variant_get(parameters, "(u)", &result);
3619 g_variant_unref(parameters);
3621 return TETHERING_ERROR_NONE;
3624 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
3626 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3627 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3629 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3630 "parameter(tethering) is NULL\n");
3631 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3632 "parameter(mac) is NULL\n");
3634 GVariant *parameters;
3635 GError *error = NULL;
3638 __tethering_h *th = (__tethering_h *)tethering;
3640 GDBusProxy *proxy = th->client_bus_proxy;
3642 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
3643 g_variant_new("(s)", mac),
3644 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3646 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3648 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3649 result = TETHERING_ERROR_PERMISSION_DENIED;
3651 result = TETHERING_ERROR_OPERATION_FAILED;
3653 g_error_free(error);
3657 g_variant_get(parameters, "(u)", &result);
3658 g_variant_unref(parameters);
3660 if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
3661 return TETHERING_ERROR_NOT_SUPPORT_API;
3663 return TETHERING_ERROR_NONE;
3666 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
3668 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3669 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3671 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3672 "parameter(tethering) is NULL\n");
3674 __tethering_h *th = (__tethering_h *)tethering;
3676 th->wifi_max_connected = max_device;
3678 return TETHERING_ERROR_NONE;
3681 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
3683 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3684 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3686 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3687 "parameter(tethering) is NULL\n");
3688 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3689 "parameter(max_device) is NULL\n");
3691 __tethering_h *th = (__tethering_h *)tethering;
3693 *max_device = th->wifi_max_connected;
3694 return TETHERING_ERROR_NONE;
3697 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
3699 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3700 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3702 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3703 "parameter(tethering) is NULL\n");
3705 GVariant *parameters;
3706 GError *error = NULL;
3709 __tethering_h *th = (__tethering_h *)tethering;
3711 GDBusProxy *proxy = th->client_bus_proxy;
3713 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
3714 g_variant_new("(b)", enable),
3715 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3717 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3719 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3720 result = TETHERING_ERROR_PERMISSION_DENIED;
3722 result = TETHERING_ERROR_OPERATION_FAILED;
3724 g_error_free(error);
3728 g_variant_get(parameters, "(u)", &result);
3729 g_variant_unref(parameters);
3731 th->port_forwarding = true;
3733 return TETHERING_ERROR_NONE;
3736 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)
3738 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3739 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3741 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3742 "parameter(tethering) is NULL\n");
3743 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3744 "parameter(protocol) is NULL\n");
3746 GVariant *parameters;
3747 GError *error = NULL;
3749 char cmd[MAX_BUF_SIZE] = { 0, };
3752 __tethering_h *th = (__tethering_h *)tethering;
3754 GDBusProxy *proxy = th->client_bus_proxy;
3756 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
3757 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
3758 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3760 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3762 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3763 result = TETHERING_ERROR_PERMISSION_DENIED;
3765 result = TETHERING_ERROR_OPERATION_FAILED;
3767 g_error_free(error);
3771 g_variant_get(parameters, "(u)", &result);
3772 g_variant_unref(parameters);
3774 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);
3778 ERR("strdup failed\n");
3779 return TETHERING_ERROR_OUT_OF_MEMORY;
3782 port_forwarding = g_slist_append(port_forwarding, list);
3784 return TETHERING_ERROR_NONE;
3787 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
3789 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3790 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3792 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3793 "parameter(tethering) is NULL\n");
3795 GVariant *parameters;
3796 GError *error = NULL;
3799 __tethering_h *th = (__tethering_h *)tethering;
3801 GDBusProxy *proxy = th->client_bus_proxy;
3803 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
3804 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3806 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3808 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3809 result = TETHERING_ERROR_PERMISSION_DENIED;
3811 result = TETHERING_ERROR_OPERATION_FAILED;
3813 g_error_free(error);
3817 g_variant_get(parameters, "(u)", &result);
3819 g_variant_unref(parameters);
3821 return TETHERING_ERROR_NONE;
3824 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool* forwarding_enabled)
3826 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3827 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3829 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3830 "parameter(tethering) is NULL\n");
3831 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3832 "parameter(forwarding_enabled) is NULL\n");
3834 __tethering_h *th = (__tethering_h *)tethering;
3836 *forwarding_enabled = th->port_forwarding;
3838 return TETHERING_ERROR_NONE;
3841 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
3843 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3844 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3846 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3847 "parameter(tethering) is NULL\n");
3848 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3849 "parameter(port_forwarding_list) is NULL\n");
3851 *port_forwarding_list = g_slist_copy(port_forwarding);
3852 return TETHERING_ERROR_NONE;
3855 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
3857 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3858 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3860 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3861 "parameter(tethering) is NULL\n");
3863 GVariant *parameters;
3864 GError *error = NULL;
3867 __tethering_h *th = (__tethering_h *)tethering;
3869 GDBusProxy *proxy = th->client_bus_proxy;
3871 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
3872 g_variant_new("(b)", enable),
3873 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3875 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3877 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3878 result = TETHERING_ERROR_PERMISSION_DENIED;
3880 result = TETHERING_ERROR_OPERATION_FAILED;
3882 g_error_free(error);
3886 g_variant_get(parameters, "(u)", &result);
3887 g_variant_unref(parameters);
3889 th->port_filtering = true;
3891 return TETHERING_ERROR_NONE;
3894 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
3896 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3897 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3899 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3900 "parameter(tethering) is NULL\n");
3901 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3902 "parameter(protocol) is NULL\n");
3904 GVariant *parameters;
3905 GError *error = NULL;
3907 char cmd[MAX_BUF_SIZE] = { 0, };
3910 __tethering_h *th = (__tethering_h *)tethering;
3912 GDBusProxy *proxy = th->client_bus_proxy;
3914 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
3915 g_variant_new("(isb)", port, protocol, allow),
3916 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3918 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3920 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3921 result = TETHERING_ERROR_PERMISSION_DENIED;
3923 result = TETHERING_ERROR_OPERATION_FAILED;
3925 g_error_free(error);
3929 g_variant_get(parameters, "(u)", &result);
3930 g_variant_unref(parameters);
3933 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
3935 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
3941 ERR("strdup failed\n");
3942 return TETHERING_ERROR_OUT_OF_MEMORY;
3945 port_filtering = g_slist_append(port_filtering, list);
3947 return TETHERING_ERROR_NONE;
3950 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
3952 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3953 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3955 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3956 "parameter(tethering) is NULL\n");
3957 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3958 "parameter(protocol) is NULL\n");
3960 GVariant *parameters;
3961 GError *error = NULL;
3963 char cmd[MAX_BUF_SIZE] = { 0, };
3966 __tethering_h *th = (__tethering_h *)tethering;
3968 GDBusProxy *proxy = th->client_bus_proxy;
3970 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
3971 g_variant_new("(iisb)", port1, port2, protocol, allow),
3972 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3974 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3976 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3977 result = TETHERING_ERROR_PERMISSION_DENIED;
3979 result = TETHERING_ERROR_OPERATION_FAILED;
3981 g_error_free(error);
3985 g_variant_get(parameters, "(u)", &result);
3986 g_variant_unref(parameters);
3989 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
3991 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
3997 ERR("strdup failed\n");
3998 return TETHERING_ERROR_OUT_OF_MEMORY;
4001 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4003 return TETHERING_ERROR_NONE;
4006 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4008 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4009 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4011 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4012 "parameter(tethering) is NULL\n");
4013 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4014 "parameter(port_filtering_list) is NULL\n");
4016 *port_filtering_list = g_slist_copy(port_filtering);
4017 return TETHERING_ERROR_NONE;
4020 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4022 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4023 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4025 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4026 "parameter(tethering) is NULL\n");
4027 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4028 "parameter(custom_port_filtering_list) is NULL\n");
4030 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4031 return TETHERING_ERROR_NONE;
4034 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool* filtering_enabled)
4036 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4037 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4039 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4040 "parameter(tethering) is NULL\n");
4041 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4042 "parameter(filtering_enabled) is NULL\n");
4044 __tethering_h *th = (__tethering_h *)tethering;
4046 *filtering_enabled = th->port_filtering;
4048 return TETHERING_ERROR_NONE;
4051 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
4053 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4054 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4056 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4057 "parameter(tethering) is NULL\n");
4059 GVariant *parameters;
4060 GError *error = NULL;
4063 __tethering_h *th = (__tethering_h *)tethering;
4065 GDBusProxy *proxy = th->client_bus_proxy;
4067 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4068 g_variant_new("(ib)", type, enable),
4069 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4071 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4073 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4074 result = TETHERING_ERROR_PERMISSION_DENIED;
4076 result = TETHERING_ERROR_OPERATION_FAILED;
4078 g_error_free(error);
4082 g_variant_get(parameters, "(u)", &result);
4084 g_variant_unref(parameters);
4086 return TETHERING_ERROR_NONE;
4089 API int tethering_wifi_push_wps_button(tethering_h tethering)
4091 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4092 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4094 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4095 "parameter(tethering) is NULL");
4096 __tethering_h *th = (__tethering_h *)tethering;
4097 GDBusProxy *proxy = th->client_bus_proxy;
4098 GVariant *parameters = NULL;
4100 GError *error = NULL;
4102 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4103 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4106 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4108 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4109 ret = TETHERING_ERROR_PERMISSION_DENIED;
4111 ret = TETHERING_ERROR_OPERATION_FAILED;
4113 g_error_free(error);
4117 if (parameters != NULL) {
4118 g_variant_get(parameters, "(u)", &ret);
4119 g_variant_unref(parameters);
4122 return TETHERING_ERROR_NONE;
4125 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4127 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4128 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4130 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4131 "parameter(tethering) is NULL");
4132 __tethering_h *th = (__tethering_h *)tethering;
4133 GDBusProxy *proxy = th->client_bus_proxy;
4134 GVariant *parameters = NULL;
4136 GError *error = NULL;
4138 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4139 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4142 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4144 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4145 ret = TETHERING_ERROR_PERMISSION_DENIED;
4147 ret = TETHERING_ERROR_OPERATION_FAILED;
4149 g_error_free(error);
4153 if (parameters != NULL) {
4154 g_variant_get(parameters, "(u)", &ret);
4155 g_variant_unref(parameters);
4158 return TETHERING_ERROR_NONE;