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.
21 #include <sys/ioctl.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
25 #include <arpa/inet.h>
27 #include <dbus/dbus.h>
30 #include <ckmc/ckmc-manager.h>
31 #include <tzplatform_config.h>
32 #include "tethering_private.h"
34 #define ALLOWED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.accept")
35 #define BLOCKED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.deny")
36 #define TEMP_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/.hostapd_tmp")
37 #define MAC_ADDR_LEN 18
38 #define MAX_BUF_SIZE 80
41 #define VCONFKEY_WIFI_TXPOWER "db/dnet/txpower" /**< VCONFKEY for TX Power */
42 #define VCONFKEY_WIFI_CHANNEL "db/dnet/channel" /**< VCONFKEY for Channel */
43 #define VCONFKEY_WIFI_SSID "db/dnet/ssid" /**< VCONFKEY for ssid */
45 #define DBUS_DEFAULT_REPLY_TIMEOUT 15000
46 #endif /* TIZEN_TV_EXT */
48 #define IPTABLES "/usr/sbin/iptables"
49 #define TABLE_NAT "nat"
50 #define TETH_NAT_PRE "teth_nat_pre"
51 #define TABLE_FILTER "filter"
52 #define TETH_FILTER_FW "teth_filter_fw"
53 #define ACTION_DROP "DROP"
54 #define ACTION_ACCEPT "ACCEPT"
55 #define PORT_FORWARD_RULE_STR "-t %s -A %s -i %s -p %s -d %s --dport %d -j DNAT --to %s:%d"
56 #define FILTERING_MULTIPORT_RULE_STR "-t %s -A %s -p %s -m multiport --dport %d,%d -j %s"
57 #define FILTERING_RULE_STR "-t %s -A %s -p %s --dport %d -j %s"
60 DUAL_BAND_NONE = 0, //0
61 DUAL_BAND_2G = 1 << 0, //1
62 DUAL_BAND_5G = 1 << 1, //2
63 DUAL_BAND_MIN_INTERFACE = 1 << 2, //4
64 DUAL_BAND_ALL = 7, //7
67 static GSList *allowed_list = NULL;
68 static GSList *blocked_list = NULL;
69 static GSList *port_forwarding = NULL;
70 static GSList *port_filtering = NULL;
71 static GSList *custom_port_filtering = NULL;
73 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
74 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
75 GVariant *parameters, gpointer user_data);
77 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
78 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
79 GVariant *parameters, gpointer user_data);
81 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
82 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
83 GVariant *parameters, gpointer user_data);
85 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
86 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
87 GVariant *parameters, gpointer user_data);
89 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
90 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
91 GVariant *parameters, gpointer user_data);
93 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
94 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
95 GVariant *parameters, gpointer user_data);
97 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
98 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
99 GVariant *parameters, gpointer user_data);
101 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
102 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
103 GVariant *parameters, gpointer user_data);
105 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
106 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
107 GVariant *parameters, gpointer user_data);
109 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
110 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
111 GVariant *parameters, gpointer user_data);
113 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
114 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
115 GVariant *parameters, gpointer user_data);
117 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
118 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
119 GVariant *parameters, gpointer user_data);
121 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
122 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
123 GVariant *parameters, gpointer user_data);
125 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
126 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
127 GVariant *parameters, gpointer user_data);
129 static __tethering_sig_t sigs[] = {
130 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
131 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
132 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
133 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
134 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
135 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
136 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
137 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
138 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
139 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
140 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
141 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
142 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
143 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
145 static int retry = 0;
146 static int is_dualband_support = DUAL_BAND_NONE;
148 static void __reset_dualband_support(void)
150 is_dualband_support = DUAL_BAND_NONE;
153 static void __set_dualband_support(int band)
155 is_dualband_support |= band;
159 static gboolean __is_dualband_support(void)
161 return (is_dualband_support == DUAL_BAND_ALL) ? TRUE : FALSE;
163 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
165 if (conn == NULL || signal_name == NULL)
168 GVariant *message = NULL;
169 GError *error = NULL;
172 message = g_variant_new("(s)", arg);
174 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
175 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
177 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
182 static bool __any_tethering_is_enabled(tethering_h tethering)
184 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
185 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
186 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
187 tethering_is_enabled(tethering, TETHERING_TYPE_P2P))
193 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
195 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
196 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
197 security_type != TETHERING_WIFI_SECURITY_TYPE_WPS &&
198 security_type != TETHERING_WIFI_SECURITY_TYPE_SAE) {
199 ERR("Invalid param\n");
200 return TETHERING_ERROR_INVALID_PARAMETER;
203 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
204 ERR("vconf_set_int is failed\n");
205 return TETHERING_ERROR_OPERATION_FAILED;
208 return TETHERING_ERROR_NONE;
211 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
213 if (security_type == NULL) {
214 ERR("Invalid param\n");
215 return TETHERING_ERROR_INVALID_PARAMETER;
218 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
219 (int *)security_type) < 0) {
220 ERR("vconf_get_int is failed\n");
221 return TETHERING_ERROR_OPERATION_FAILED;
224 return TETHERING_ERROR_NONE;
227 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
229 if (path == NULL || ssid == NULL || size == 0)
233 char *ptr_tmp = NULL;
235 ptr = vconf_get_str(path);
239 if (!g_strcmp0(ptr, "")) {
244 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
247 g_strlcpy(ssid, ptr, size);
253 static tethering_error_e __set_visible(const bool visible)
255 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
256 ERR("vconf_set_int is failed\n");
257 return TETHERING_ERROR_OPERATION_FAILED;
260 return TETHERING_ERROR_NONE;
263 static tethering_error_e __get_visible(bool *visible)
265 if (visible == NULL) {
266 ERR("Invalid param\n");
267 return TETHERING_ERROR_INVALID_PARAMETER;
272 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
273 ERR("vconf_get_int is failed\n");
274 return TETHERING_ERROR_OPERATION_FAILED;
281 return TETHERING_ERROR_NONE;
284 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
286 if (passphrase == NULL ||
287 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
290 guint32 rand_int = 0;
293 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
294 rand_int = g_random_int_range('a', 'z');
295 passphrase[index] = rand_int;
297 passphrase[index] = '\0';
302 static tethering_error_e __get_error(int agent_error)
304 tethering_error_e err = TETHERING_ERROR_NONE;
306 switch (agent_error) {
307 case MOBILE_AP_ERROR_NONE:
308 err = TETHERING_ERROR_NONE;
311 case MOBILE_AP_ERROR_RESOURCE:
312 err = TETHERING_ERROR_OUT_OF_MEMORY;
315 case MOBILE_AP_ERROR_INTERNAL:
316 err = TETHERING_ERROR_OPERATION_FAILED;
319 case MOBILE_AP_ERROR_INVALID_PARAM:
320 err = TETHERING_ERROR_INVALID_PARAMETER;
323 case MOBILE_AP_ERROR_ALREADY_ENABLED:
324 err = TETHERING_ERROR_OPERATION_FAILED;
327 case MOBILE_AP_ERROR_NOT_ENABLED:
328 err = TETHERING_ERROR_NOT_ENABLED;
331 case MOBILE_AP_ERROR_NET_OPEN:
332 err = TETHERING_ERROR_OPERATION_FAILED;
335 case MOBILE_AP_ERROR_NET_CLOSE:
336 err = TETHERING_ERROR_OPERATION_FAILED;
339 case MOBILE_AP_ERROR_DHCP:
340 err = TETHERING_ERROR_OPERATION_FAILED;
343 case MOBILE_AP_ERROR_IN_PROGRESS:
344 err = TETHERING_ERROR_OPERATION_FAILED;
347 case MOBILE_AP_ERROR_NOT_PERMITTED:
348 err = TETHERING_ERROR_NOT_PERMITTED;
351 case MOBILE_AP_ERROR_PERMISSION_DENIED:
352 err = TETHERING_ERROR_PERMISSION_DENIED;
355 ERR("Not defined error : %d\n", agent_error);
356 err = TETHERING_ERROR_OPERATION_FAILED;
363 static tethering_type_e __convert_to_tethering_type(mobile_ap_type_e type)
366 case MOBILE_AP_TYPE_USB:
367 return TETHERING_TYPE_USB;
368 case MOBILE_AP_TYPE_WIFI:
369 return TETHERING_TYPE_WIFI;
370 case MOBILE_AP_TYPE_BT:
371 return TETHERING_TYPE_BT;
372 case MOBILE_AP_TYPE_P2P:
373 return TETHERING_TYPE_P2P;
375 return TETHERING_TYPE_MAX;
379 static void __invoke_enable_cb(__tethering_h *th, tethering_type_e type, bool is_requested)
381 if (th == NULL || th->enabled_cb[type] == NULL) {
382 ERR("th or enabled_cb is NULL");
386 tethering_enabled_cb ecb = NULL;
389 if (!_tethering_check_handle(th)) {
390 DBG("Tethering handle is not valid now, ignore it.");
394 ecb = th->enabled_cb[type];
395 data = th->enabled_user_data[type];
396 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
399 static int __get_disabled_cause_by_interface_error(tethering_type_e type)
402 case TETHERING_TYPE_USB:
403 return TETHERING_DISABLED_BY_USB_DISCONNECTION;
404 case TETHERING_TYPE_WIFI:
405 return TETHERING_DISABLED_BY_WIFI_ON;
406 case TETHERING_TYPE_BT:
407 return TETHERING_DISABLED_BY_BT_OFF;
409 return TETHERING_DISABLED_BY_OTHERS;
413 static void __invoke_disabled_cb(__tethering_h *th, tethering_type_e type, GVariant *parameters)
415 if (th == NULL || th->disabled_cb[type] == NULL) {
416 ERR("th or disabled_cb is NULL");
420 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
421 tethering_disabled_cb dcb = NULL;
425 if (!_tethering_check_handle(th)) {
426 DBG("Tethering handle is not valid now, ignore it.");
430 data = th->disabled_user_data[type];
432 g_variant_get(parameters, "(s)", &buf);
433 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
434 code = __get_disabled_cause_by_interface_error(type);
435 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
436 code = TETHERING_DISABLED_BY_TIMEOUT;
438 dcb(TETHERING_ERROR_NONE, type, code, data);
442 static void __invoke_disabled_cbs(__tethering_h *th, tethering_disabled_cause_e code)
449 if (!_tethering_check_handle(th)) {
450 DBG("Tethering handle is not valid now, ignore it.");
454 for (tethering_type_e type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
455 tethering_disabled_cb dcb = th->disabled_cb[type];
458 void *data = th->disabled_user_data[type];
459 dcb(TETHERING_ERROR_NONE, type, code, data);
463 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
464 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
465 GVariant *parameters, gpointer user_data)
470 if (user_data == NULL) {
471 ERR("parameter(user_data) is NULL");
476 __tethering_h *th = (__tethering_h *)user_data;
478 tethering_type_e type = 0;
479 mobile_ap_type_e ap_type = 0;
480 tethering_connection_state_changed_cb ccb = NULL;
481 __tethering_client_h client;
489 memset(&client, 0, sizeof(__tethering_client_h));
490 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
492 if (!g_strcmp0(buf, "DhcpConnected")) {
494 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
497 ERR("Unknown event [%s]\n", buf);
501 type = __convert_to_tethering_type(ap_type);
502 if (type == TETHERING_TYPE_MAX) {
503 ERR("Not supported tethering type [%d]\n", ap_type);
507 SINFO("[%s] type %d, ip %s, mac %s, name %s, timestamp %d",
508 buf, ap_type, ip, mac, name, timestamp);
510 ccb = th->changed_cb[type];
513 data = th->changed_user_data[type];
515 client.interface = type;
516 g_strlcpy(client.ip, ip, sizeof(client.ip));
517 g_strlcpy(client.mac, mac, sizeof(client.mac));
519 client.hostname = g_strdup(name);
520 client.tm = (time_t)timestamp;
522 ccb((tethering_client_h)&client, opened, data);
523 g_free(client.hostname);
534 static void __handle_net_closed(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 SINFO("Tethering Disabled by network close !");
541 __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_NETWORK_CLOSE);
546 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
547 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
548 GVariant *parameters, gpointer user_data)
552 __invoke_enable_cb((__tethering_h *)user_data, TETHERING_TYPE_WIFI, false);
557 static void __handle_wifi_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 __invoke_disabled_cb((__tethering_h *)user_data, TETHERING_TYPE_WIFI, parameters);
568 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
569 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
570 GVariant *parameters, gpointer user_data)
574 __invoke_enable_cb((__tethering_h *)user_data, TETHERING_TYPE_USB, false);
579 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
580 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
581 GVariant *parameters, gpointer user_data)
585 __invoke_disabled_cb((__tethering_h *)user_data, TETHERING_TYPE_USB, parameters);
590 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
591 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
592 GVariant *parameters, gpointer user_data)
596 __invoke_enable_cb((__tethering_h *)user_data, TETHERING_TYPE_BT, false);
601 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
602 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
603 GVariant *parameters, gpointer user_data)
607 __invoke_disabled_cb((__tethering_h *)user_data, TETHERING_TYPE_BT, parameters);
612 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
613 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
614 GVariant *parameters, gpointer user_data)
618 __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_TIMEOUT);
623 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
624 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
625 GVariant *parameters, gpointer user_data)
629 __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_LOW_BATTERY);
634 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
635 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
636 GVariant *parameters, gpointer user_data)
640 __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_FLIGHT_MODE);
645 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
646 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
647 GVariant *parameters, gpointer user_data)
653 if (user_data == NULL) {
654 ERR("parameter(user_data) is NULL");
659 __tethering_h *th = (__tethering_h *)user_data;
661 tethering_wifi_security_type_changed_cb scb = NULL;
663 tethering_wifi_security_type_e security_type;
666 if (!_tethering_check_handle(th)) {
667 DBG("Tethering handle is not valid now, ignore it.");
672 scb = th->security_type_changed_cb;
678 g_variant_get(parameters, "(s)", &buf);
679 data = th->security_type_user_data;
680 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
681 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
682 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
683 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
684 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
685 security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
686 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_SAE_STR) == 0)
687 security_type = TETHERING_WIFI_SECURITY_TYPE_SAE;
689 SERR("Unknown type : %s\n", buf);
695 scb(security_type, data);
701 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
702 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
703 GVariant *parameters, gpointer user_data)
708 if (user_data == NULL) {
709 ERR("parameter(user_data) is NULL");
714 __tethering_h *th = (__tethering_h *)user_data;
716 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
718 bool visible = false;
721 if (!_tethering_check_handle(th)) {
722 DBG("Tethering handle is not valid now, ignore it.");
727 scb = th->ssid_visibility_changed_cb;
733 g_variant_get(parameters, "(s)", &buf);
734 data = th->ssid_visibility_user_data;
735 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
745 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
746 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
747 GVariant *parameters, gpointer user_data)
752 if (user_data == NULL) {
753 ERR("parameter(user_data) is NULL");
758 __tethering_h *th = (__tethering_h *)user_data;
760 tethering_wifi_passphrase_changed_cb pcb = NULL;
763 if (!_tethering_check_handle(th)) {
764 DBG("Tethering handle is not valid now, ignore it.");
769 pcb = th->passphrase_changed_cb;
775 data = th->passphrase_user_data;
783 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
789 if (user_data == NULL) {
790 ERR("parameter(user_data) is NULL");
795 GError *g_error = NULL;
798 tethering_type_e type = TETHERING_TYPE_WIFI;
799 tethering_error_e error;
800 __tethering_h *th = (__tethering_h *)user_data;
802 tethering_enabled_cb ecb = th->enabled_cb[type];
803 void *data = th->enabled_user_data[type];
805 if (!_tethering_check_handle((tethering_h)user_data)) {
806 DBG("Tethering handle is not valid now, ignore it.");
811 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
813 ERR("DBus error [%s]\n", g_error->message);
814 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
815 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
816 g_error_free(g_error);
817 tethering_enable((tethering_h)th, type);
820 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
821 error = TETHERING_ERROR_PERMISSION_DENIED;
823 error = TETHERING_ERROR_OPERATION_FAILED;
824 g_error_free(g_error);
826 g_variant_get(g_var, "(u)", &info);
827 g_variant_unref(g_var);
828 error = __get_error(info);
832 INFO("cfm event : wifi tethering enable info : %d\n", error);
834 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
835 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
836 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
837 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
839 SINFO("Tethering enabled event ! error(%d)", error);
846 ecb(error, type, true, data);
852 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
858 if (user_data == NULL) {
859 ERR("parameter(user_data) is NULL");
864 GError *g_error = NULL;
867 tethering_error_e error;
869 __tethering_h *th = (__tethering_h *)user_data;
870 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
871 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
873 if (!_tethering_check_handle((tethering_h)user_data)) {
874 DBG("Tethering handle is not valid now, ignore it.");
879 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
881 ERR("DBus error [%s]\n", g_error->message);
882 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
883 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
884 g_error_free(g_error);
885 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
890 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
891 error = TETHERING_ERROR_PERMISSION_DENIED;
893 error = TETHERING_ERROR_OPERATION_FAILED;
894 g_error_free(g_error);
896 g_variant_get(g_var, "(u)", &info);
897 g_variant_unref(g_var);
898 error = __get_error(info);
902 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
903 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
904 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
905 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
913 ecb(error, TETHERING_TYPE_BT, true, data);
919 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
925 if (user_data == NULL) {
926 ERR("parameter(user_data) is NULL");
931 __tethering_h *th = (__tethering_h *)user_data;
932 GError *g_error = NULL;
935 tethering_error_e error;
936 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
937 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
939 if (!_tethering_check_handle((tethering_h)user_data)) {
940 DBG("Tethering handle is not valid now, ignore it.");
945 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
947 ERR("DBus error [%s]\n", g_error->message);
948 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
949 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
950 g_error_free(g_error);
951 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
956 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
957 error = TETHERING_ERROR_PERMISSION_DENIED;
959 error = TETHERING_ERROR_OPERATION_FAILED;
960 g_error_free(g_error);
962 g_variant_get(g_var, "(u)", &info);
963 g_variant_unref(g_var);
964 error = __get_error(info);
968 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
969 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
970 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
971 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
979 ecb(error, TETHERING_TYPE_USB, true, data);
985 static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
991 if (user_data == NULL) {
992 ERR("parameter(user_data) is NULL");
997 __tethering_h *th = (__tethering_h *)user_data;
998 GError *g_error = NULL;
1001 tethering_error_e error;
1002 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_P2P];
1003 void *data = th->enabled_user_data[TETHERING_TYPE_P2P];
1005 if (!_tethering_check_handle((tethering_h)user_data)) {
1006 DBG("Tethering handle is not valid now, ignore it.");
1011 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1013 ERR("DBus error [%s]\n", g_error->message);
1014 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
1015 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
1016 g_error_free(g_error);
1017 tethering_enable((tethering_h)th, TETHERING_TYPE_P2P);
1022 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1023 error = TETHERING_ERROR_PERMISSION_DENIED;
1025 error = TETHERING_ERROR_OPERATION_FAILED;
1026 g_error_free(g_error);
1028 g_variant_get(g_var, "(u)", &info);
1029 g_variant_unref(g_var);
1030 error = __get_error(info);
1040 ecb(error, TETHERING_TYPE_P2P, true, data);
1046 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
1052 if (user_data == NULL) {
1053 ERR("parameter(user_data) is NULL");
1058 GError *g_error = NULL;
1060 guint info, event_type;
1061 tethering_error_e error;
1062 tethering_type_e type;
1063 tethering_h tethering = (tethering_h)user_data;
1064 __tethering_h *th = (__tethering_h *)tethering;
1065 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
1066 tethering_disabled_cb dcb = NULL;
1069 if (!_tethering_check_handle((tethering_h)user_data)) {
1070 DBG("Tethering handle is not valid now, ignore it.");
1075 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1077 ERR("DBus error [%s]\n", g_error->message);
1078 g_error_free(g_error);
1082 g_variant_get(g_var, "(uu)", &event_type, &info);
1083 INFO("cfm event : %d info : %d\n", event_type, info);
1084 g_variant_unref(g_var);
1085 error = __get_error(info);
1086 INFO("cfm event : %d info : %d\n", event_type, error);
1087 switch (event_type) {
1088 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1089 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1090 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1091 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1092 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1094 type = TETHERING_TYPE_WIFI;
1095 dcb = th->disabled_cb[type];
1096 data = th->disabled_user_data[type];
1098 dcb(error, type, code, data);
1101 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1102 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1103 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1104 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1105 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1107 type = TETHERING_TYPE_BT;
1108 dcb = th->disabled_cb[type];
1109 data = th->disabled_user_data[type];
1111 dcb(error, type, code, data);
1114 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1115 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1116 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1117 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1118 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1120 type = TETHERING_TYPE_USB;
1121 dcb = th->disabled_cb[type];
1122 data = th->disabled_user_data[type];
1124 dcb(error, type, code, data);
1127 case MOBILE_AP_DISABLE_P2P_TETHERING_CFM:
1128 type = TETHERING_TYPE_P2P;
1129 dcb = th->disabled_cb[type];
1130 data = th->disabled_user_data[type];
1132 dcb(error, type, code, data);
1135 case MOBILE_AP_DISABLE_CFM:
1137 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1138 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1139 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1140 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1141 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1142 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1143 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1144 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1145 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1146 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1147 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1148 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1150 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1151 dcb = th->disabled_cb[type];
1154 data = th->disabled_user_data[type];
1156 dcb(error, type, code, data);
1161 ERR("Invalid event\n");
1169 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1175 if (user_data == NULL) {
1176 ERR("parameter(user_data) is NULL");
1181 GError *g_error = NULL;
1184 guint64 tx_bytes, rx_bytes;
1185 __tethering_h *th = (__tethering_h *)user_data;
1186 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1189 if (!_tethering_check_handle((tethering_h)user_data)) {
1190 DBG("Tethering handle is not valid now, ignore it.");
1195 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1197 ERR("DBus fail [%s]\n", g_error->message);
1198 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1199 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1201 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1205 if (th->data_usage_cb == NULL) {
1206 ERR("There is no data_usage_cb\n");
1211 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1213 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1214 th->data_usage_cb(TETHERING_ERROR_NONE,
1215 rx_bytes, tx_bytes, th->data_usage_user_data);
1216 g_variant_unref(g_var);
1218 th->data_usage_cb = NULL;
1219 th->data_usage_user_data = NULL;
1225 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1231 if (user_data == NULL) {
1232 ERR("parameter(user_data) is NULL");
1237 GError *g_error = NULL;
1240 __tethering_h *th = (__tethering_h *)user_data;
1241 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1243 if (!_tethering_check_handle((tethering_h)user_data)) {
1244 DBG("Tethering handle is not valid now, ignore it.");
1249 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1251 ERR("DBus fail [%s]\n", g_error->message);
1252 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1253 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1255 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1256 g_error_free(g_error);
1258 g_variant_get(g_var, "(u)", &info);
1259 if (tethering_error == TETHERING_ERROR_NONE)
1260 tethering_error = __get_error(info);
1261 g_variant_unref(g_var);
1264 if (th->settings_reloaded_cb == NULL) {
1265 DBG("There is no settings_reloaded_cb\n-\n");
1270 th->settings_reloaded_cb(tethering_error,
1271 th->settings_reloaded_user_data);
1273 th->settings_reloaded_cb = NULL;
1274 th->settings_reloaded_user_data = NULL;
1280 static void __connect_signals(tethering_h tethering)
1283 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1285 __tethering_h *th = (__tethering_h *)tethering;
1286 GDBusConnection *connection = th->client_bus;
1289 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1290 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1291 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1292 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1293 sigs[i].cb, tethering, NULL);
1298 static void __disconnect_signals(tethering_h tethering)
1302 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1304 __tethering_h *th = (__tethering_h *)tethering;
1305 GDBusConnection *connection = th->client_bus;
1309 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1310 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1316 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1318 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1321 case TETHERING_TYPE_USB:
1322 g_strlcpy(buf, TETHERING_USB_IF, len);
1324 case TETHERING_TYPE_WIFI:
1325 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1327 case TETHERING_TYPE_BT:
1328 g_strlcpy(buf, TETHERING_BT_IF, len);
1330 case TETHERING_TYPE_P2P:
1331 g_strlcpy(buf, TETHERING_P2P_IF, len);
1334 ERR("Not supported type : %d\n", type);
1340 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1342 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1345 case TETHERING_TYPE_USB:
1346 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1348 case TETHERING_TYPE_WIFI:
1349 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1351 case TETHERING_TYPE_BT:
1352 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1354 case TETHERING_TYPE_P2P:
1355 g_strlcpy(buf, TETHERING_P2P_GATEWAY, len);
1358 ERR("Not supported type : %d\n", type);
1364 static int __get_common_ssid(char *ssid, unsigned int size)
1367 ERR("ssid is null\n");
1368 return TETHERING_ERROR_INVALID_PARAMETER;
1372 if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID, ssid, size))
1373 return TETHERING_ERROR_NONE;
1375 ERR("vconf key get failed for ssid or invalid ssid is found");
1376 #endif /* TIZEN_TV_EXT */
1378 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
1379 ssid, size) == false) {
1380 ERR("vconf_get_str is failed and set default ssid");
1381 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1384 return TETHERING_ERROR_NONE;
1387 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1389 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1392 case TETHERING_WIFI_MODE_TYPE_B:
1393 *buf = g_strdup("b");
1395 case TETHERING_WIFI_MODE_TYPE_G:
1396 *buf = g_strdup("g");
1398 case TETHERING_WIFI_MODE_TYPE_A:
1399 *buf = g_strdup("a");
1401 case TETHERING_WIFI_MODE_TYPE_AD:
1402 *buf = g_strdup("ad");
1405 ERR("Not supported type : %d\n", type);
1411 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1415 __tethering_h *th = (__tethering_h *)tethering;
1416 tethering_error_e ret = TETHERING_ERROR_NONE;
1419 if (th == NULL || set == NULL) {
1420 ERR("null parameter\n-\n");
1421 return TETHERING_ERROR_INVALID_PARAMETER;
1424 if (th->ssid == NULL)
1425 __get_common_ssid(set->ssid, sizeof(set->ssid));
1427 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1429 ret = __get_security_type(&set->sec_type);
1430 if (ret != TETHERING_ERROR_NONE)
1431 set->sec_type = th->sec_type;
1433 ret = __get_visible(&set->visibility);
1434 if (ret != TETHERING_ERROR_NONE)
1435 set->visibility = th->visibility;
1437 set->mac_filter = th->mac_filter;
1438 set->max_connected = th->wifi_max_connected;
1439 set->channel = th->channel;
1440 set->txpower = th->txpower;
1442 __get_wifi_mode_type(th->mode_type, &ptr);
1444 g_strlcpy(set->mode, "", sizeof(set->mode));
1446 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1450 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1451 g_strlcpy(set->key, "", sizeof(set->key));
1453 GDBusProxy *proxy = th->client_bus_proxy;
1454 GVariant *parameters;
1455 GError *error = NULL;
1456 char *passphrase = NULL;
1457 unsigned int len = 0;
1459 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1460 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1463 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1465 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1466 ret = TETHERING_ERROR_PERMISSION_DENIED;
1468 ret = TETHERING_ERROR_OPERATION_FAILED;
1470 g_error_free(error);
1474 if (parameters != NULL) {
1475 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1476 g_strlcpy(set->key, passphrase, sizeof(set->key) - 1);
1478 g_variant_unref(parameters);
1482 if (strlen(th->ip_address))
1483 g_strlcpy(set->ip_address, th->ip_address, sizeof(set->ip_address));
1485 g_strlcpy(set->ip_address, TETHERING_WIFI_GATEWAY, sizeof(set->ip_address));
1487 INFO("ssid: %s security: %d mode: %s "
1488 "channel: %d visibility: %s ip_address: [%s]\n",
1489 set->ssid, set->sec_type, set->mode, set->channel,
1490 (set->visibility) ? "true" : "false",
1493 return TETHERING_ERROR_NONE;
1496 static bool __check_precondition(__tethering_h *th, tethering_type_e type)
1498 int dnet_status = 0;
1499 int cellular_state = 0;
1501 /* data network through cellular */
1502 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1503 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1504 INFO("Data Network can be connected later");
1508 /* data network status */
1509 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
1510 if ((dnet_status == VCONFKEY_NETWORK_WIFI
1511 && type != TETHERING_TYPE_WIFI)
1512 || (th->wifi_sharing && dnet_status == VCONFKEY_NETWORK_WIFI
1513 && type == TETHERING_TYPE_WIFI)
1514 || dnet_status == VCONFKEY_NETWORK_ETHERNET)
1517 ERR("Network is not available!");
1522 static void __set_vconf_values_for_tv(__tethering_h *tethering)
1524 int ret, channel, txpower;
1525 __tethering_h *th = tethering;
1530 ret = vconf_get_int(VCONFKEY_WIFI_CHANNEL, &channel);
1532 ERR("vconf key get failed for channel !!");
1533 channel = TETHERING_WIFI_CHANNEL;
1536 ret = vconf_get_int(VCONFKEY_WIFI_TXPOWER, &txpower);
1538 ERR("vconf key get failed for txpower !!");
1539 txpower = TETHERING_WIFI_MAX_TXPOWER;
1542 th->channel = channel;
1543 th->txpower = txpower;
1545 #endif /* TIZEN_TV_EXT */
1549 * @brief Creates the handle of tethering.
1551 * @privlevel platform
1552 * @privilege http://tizen.org/privilege/tethering.admin
1553 * @remarks The @a tethering must be released tethering_destroy() by you.
1554 * @param[out] tethering A handle of a new mobile ap handle on success
1555 * @return 0 on success, otherwise a negative error value.
1556 * @retval #TETHERING_ERROR_NONE Successful
1557 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1558 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1559 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1560 * @see tethering_destroy()
1562 API int tethering_create(tethering_h *tethering)
1564 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1565 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1566 "parameter(tethering) is NULL\n");
1569 __tethering_h *th = NULL;
1570 GError *error = NULL;
1571 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1573 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1575 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1576 "malloc is failed\n");
1577 memset(th, 0x00, sizeof(__tethering_h));
1578 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1579 th->visibility = true;
1580 th->mac_filter = false;
1581 th->wifi_sharing = false;
1582 th->channel = TETHERING_WIFI_CHANNEL;
1583 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1584 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1585 th->txpower = TETHERING_WIFI_MAX_TXPOWER;
1587 if (__generate_initial_passphrase(th->passphrase,
1588 sizeof(th->passphrase)) == 0) {
1589 ERR("random passphrase generation failed\n");
1591 return TETHERING_ERROR_OPERATION_FAILED;
1594 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1595 ERR("common ssid get failed\n");
1597 return TETHERING_ERROR_OPERATION_FAILED;
1601 __set_vconf_values_for_tv(th);
1602 #endif /* TIZEN_TV_EXT */
1603 SINFO("ssid: %s, key: %s, channel: %d, mode: %d, txpower: %d, security: %d max_device: %d\n",
1604 ssid, th->passphrase, th->channel, th->mode_type, th->txpower, th->sec_type,
1605 th->wifi_max_connected);
1607 #if !GLIB_CHECK_VERSION(2, 36, 0)
1610 GCancellable *cancellable = g_cancellable_new();
1611 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1613 ERR("Couldn't connect to the System bus[%s]", error->message);
1614 g_error_free(error);
1615 g_cancellable_cancel(cancellable);
1616 g_object_unref(cancellable);
1618 return TETHERING_ERROR_OPERATION_FAILED;
1620 th->cancellable = cancellable;
1622 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1623 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1624 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1625 if (!th->client_bus_proxy) {
1627 ERR("Couldn't create the proxy object because of %s\n", error->message);
1628 g_cancellable_cancel(th->cancellable);
1629 g_object_unref(th->cancellable);
1630 g_object_unref(th->client_bus);
1632 return TETHERING_ERROR_OPERATION_FAILED;
1635 __connect_signals((tethering_h)th);
1637 *tethering = (tethering_h)th;
1638 _tethering_add_handle(th);
1639 INFO("Tethering Handle : %p\n", th);
1641 return TETHERING_ERROR_NONE;
1646 * @brief Destroys the handle of tethering.
1648 * @privlevel platform
1649 * @privilege http://tizen.org/privilege/tethering.admin
1650 * @param[in] tethering The handle of tethering
1651 * @return 0 on success, otherwise a negative error value.
1652 * @retval #TETHERING_ERROR_NONE Successful
1653 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1654 * @see tethering_create()
1656 API int tethering_destroy(tethering_h tethering)
1659 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1660 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1661 "parameter(tethering) is NULL\n");
1663 __tethering_h *th = (__tethering_h *)tethering;
1665 INFO("Tethering Handle : %p\n", th);
1667 __disconnect_signals(tethering);
1668 _tethering_remove_handle(th);
1673 g_object_unref(th->cancellable);
1674 g_object_unref(th->client_bus_proxy);
1675 g_object_unref(th->client_bus);
1676 memset(th, 0x00, sizeof(__tethering_h));
1681 return TETHERING_ERROR_NONE;
1684 static GVariant *__get_wifi_settings_dbus_params(const char *wifi_tether_type, _softap_settings_t *set)
1686 GVariantBuilder *builder = NULL;
1687 GVariant *params = NULL;
1689 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1690 if (builder == NULL) {
1691 ERR("Failed to create builder");
1695 g_variant_builder_add(builder, "{sv}",
1697 g_variant_new_string(set->ssid));
1699 if (set->sec_type != TETHERING_WIFI_SECURITY_TYPE_NONE)
1700 g_variant_builder_add(builder, "{sv}",
1702 g_variant_new_string(set->key));
1704 if (!g_strcmp0(set->mode, "b")) {
1705 g_variant_builder_add(builder, "{sv}",
1706 "mode", g_variant_new_int32(0));
1707 } else if (!g_strcmp0(set->mode, "g")) {
1708 g_variant_builder_add(builder, "{sv}",
1709 "mode", g_variant_new_int32(1));
1710 } else if (!g_strcmp0(set->mode, "n")) {
1711 g_variant_builder_add(builder, "{sv}",
1712 "mode", g_variant_new_int32(2));
1713 } else if (!g_strcmp0(set->mode, "ac")) {
1714 g_variant_builder_add(builder, "{sv}",
1715 "mode", g_variant_new_int32(3));
1720 g_variant_builder_add(builder, "{sv}",
1722 g_variant_new_boolean(set->visibility));
1724 g_variant_builder_add(builder, "{sv}",
1726 g_variant_new_int32(set->channel));
1728 g_variant_builder_add(builder, "{sv}",
1730 g_variant_new_int32(set->sec_type));
1732 g_variant_builder_add(builder, "{sv}",
1734 g_variant_new_boolean(set->mac_filter));
1736 g_variant_builder_add(builder, "{sv}",
1738 g_variant_new_int32(set->max_connected));
1740 g_variant_builder_add(builder, "{sv}",
1742 g_variant_new_int32(TETHERING_ADDRESS_FAMILY_IPV4));
1744 g_variant_builder_add(builder, "{sv}",
1746 g_variant_new_int32(set->txpower));
1748 if (strlen(set->ip_address))
1749 g_variant_builder_add(builder, "{sv}",
1751 g_variant_new_string(set->ip_address));
1753 if (wifi_tether_type)
1754 g_variant_builder_add(builder, "{sv}",
1756 g_variant_new_string(wifi_tether_type));
1758 params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
1759 g_variant_builder_unref(builder);
1766 * @brief Enables the tethering, asynchronously.
1768 * @privlevel platform
1769 * @privilege http://tizen.org/privilege/tethering.admin
1770 * @param[in] tethering The handle of tethering
1771 * @param[in] type The type of tethering
1772 * @return 0 on success, otherwise negative error value.
1773 * @retval #TETHERING_ERROR_NONE Successful
1774 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1775 * @post tethering_enabled_cb() will be invoked.
1776 * @see tethering_is_enabled()
1777 * @see tethering_disable()
1779 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1781 INFO("+ type : %d\n", type);
1782 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1783 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1784 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1785 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1787 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1788 "parameter(tethering) is NULL\n");
1790 tethering_error_e ret = TETHERING_ERROR_NONE;
1791 __tethering_h *th = (__tethering_h *)tethering;
1792 GDBusProxy *proxy = th->client_bus_proxy;
1793 GDBusConnection *connection = th->client_bus;
1796 g_dbus_proxy_set_default_timeout(proxy, DBUS_DEFAULT_REPLY_TIMEOUT);
1797 #else /* TIZEN_TV_EXT */
1798 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1799 #endif /* TIZEN_TV_EXT */
1801 if (__check_precondition(th, type) == FALSE) {
1803 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1804 return TETHERING_ERROR_OPERATION_FAILED;
1808 case TETHERING_TYPE_USB:
1809 g_dbus_connection_signal_unsubscribe(connection,
1810 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1812 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1813 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1814 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1815 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1818 case TETHERING_TYPE_WIFI: {
1819 GVariant *params = NULL;
1820 _softap_settings_t set;
1821 memset(&set, 0, sizeof(_softap_settings_t));
1823 ret = __prepare_wifi_settings(tethering, &set);
1824 if (ret != TETHERING_ERROR_NONE) {
1825 ERR("softap settings initialization failed\n");
1827 return TETHERING_ERROR_OPERATION_FAILED;
1829 g_dbus_connection_signal_unsubscribe(connection,
1830 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1832 SINFO("ssid %s, key %s, channel %d, mode %s, "
1833 "txpower %d, security %d, max_device %d, "
1834 "ip_address [%s]\n",
1835 set.ssid, set.key, set.channel, set.mode,
1836 set.txpower, set.sec_type,
1837 set.max_connected, set.ip_address);
1839 if (th->wifi_sharing)
1840 params = __get_wifi_settings_dbus_params("wifi_sharing", &set);
1842 params = __get_wifi_settings_dbus_params("wifi_tether", &set);
1844 g_dbus_proxy_call(proxy, "enable_wifi_tethering", params,
1845 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1846 (GAsyncReadyCallback) __wifi_enabled_cfm_cb,
1847 (gpointer)tethering);
1851 case TETHERING_TYPE_BT:
1852 g_dbus_connection_signal_unsubscribe(connection,
1853 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1855 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1856 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1857 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1858 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1862 case TETHERING_TYPE_P2P: {
1863 _softap_settings_t p2p_set;
1864 memset(&p2p_set, 0, sizeof(_softap_settings_t));
1866 ret = __prepare_wifi_settings(tethering, &p2p_set);
1867 if (ret != TETHERING_ERROR_NONE) {
1868 ERR("p2p settings initialization failed\n");
1869 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1871 return TETHERING_ERROR_OPERATION_FAILED;
1874 g_dbus_proxy_call(proxy, "enable_p2p_tethering",
1875 g_variant_new("(ssi)", p2p_set.ssid, p2p_set.key, p2p_set.channel),
1876 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1877 (GAsyncReadyCallback) __p2p_enabled_cfm_cb, (gpointer)tethering);
1881 case TETHERING_TYPE_ALL: {
1882 GVariant *params = NULL;
1883 _softap_settings_t set;
1884 memset(&set, 0, sizeof(_softap_settings_t));
1886 ret = __prepare_wifi_settings(tethering, &set);
1887 if (ret != TETHERING_ERROR_NONE) {
1888 ERR("softap settings initialization failed\n");
1889 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1890 return TETHERING_ERROR_OPERATION_FAILED;
1893 /* TETHERING_TYPE_USB */
1894 g_dbus_connection_signal_unsubscribe(connection,
1895 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1897 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1898 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1899 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1900 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1902 /* TETHERING_TYPE_WIFI */
1903 g_dbus_connection_signal_unsubscribe(connection,
1904 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1906 if (th->wifi_sharing)
1907 params = __get_wifi_settings_dbus_params("wifi_sharing", &set);
1909 params = __get_wifi_settings_dbus_params("wifi_tether", &set);
1911 g_dbus_proxy_call(proxy, "enable_wifi_tethering", params,
1912 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1913 (GAsyncReadyCallback) __wifi_enabled_cfm_cb,
1914 (gpointer)tethering);
1916 /* TETHERING_TYPE_BT */
1917 g_dbus_connection_signal_unsubscribe(connection,
1918 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1920 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1921 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1922 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1923 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1927 ERR("Unknown type : %d\n", type);
1929 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1932 return TETHERING_ERROR_INVALID_PARAMETER;
1935 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1937 return TETHERING_ERROR_NONE;
1940 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1942 DBG("+ type : %d\n", type);
1943 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1944 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1945 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1946 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1948 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1949 "parameter(tethering) is NULL\n");
1951 __tethering_h *th = (__tethering_h *)tethering;
1952 GDBusProxy *proxy = th->client_bus_proxy;
1953 GDBusConnection *connection = th->client_bus;
1956 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1958 if (__check_precondition(th, type) == FALSE) {
1960 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1961 return TETHERING_ERROR_OPERATION_FAILED;
1965 case TETHERING_TYPE_USB: {
1966 g_dbus_connection_signal_unsubscribe(connection,
1967 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1969 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1970 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1971 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1972 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1976 case TETHERING_TYPE_WIFI: {
1977 GVariant *params = NULL;
1978 _softap_settings_t set;
1979 memset(&set, 0, sizeof(_softap_settings_t));
1981 ret = __prepare_wifi_settings(tethering, &set);
1982 if (ret != TETHERING_ERROR_NONE) {
1983 ERR("softap settings initialization failed\n");
1985 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1986 return TETHERING_ERROR_OPERATION_FAILED;
1988 g_dbus_connection_signal_unsubscribe(connection,
1989 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1991 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
1992 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
1995 char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = "wifi_tether";
1996 if (th->wifi_sharing)
1997 g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN + 1);
1999 SINFO("enable_wifi_tethering key: %s", key);
2000 if (th->wifi_sharing)
2001 params = __get_wifi_settings_dbus_params("wifi_sharing", &set);
2003 params = __get_wifi_settings_dbus_params("wifi_tether", &set);
2005 g_dbus_proxy_call(proxy, "enable_wifi_tethering", params,
2006 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2007 (GAsyncReadyCallback) __wifi_enabled_cfm_cb,
2008 (gpointer)tethering);
2012 case TETHERING_TYPE_BT: {
2013 g_dbus_connection_signal_unsubscribe(connection,
2014 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
2016 g_dbus_proxy_call(proxy, "enable_bt_tethering",
2017 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
2018 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2019 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
2025 ERR("Unknown type : %d\n", type);
2027 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
2030 return TETHERING_ERROR_INVALID_PARAMETER;
2034 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
2036 return TETHERING_ERROR_NONE;
2039 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
2041 DBG("+ type : %d\n", type);
2042 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2043 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2044 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2045 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2047 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2048 "parameter(tethering) is NULL\n");
2050 __tethering_h *th = (__tethering_h *)tethering;
2051 GDBusProxy *proxy = th->client_bus_proxy;
2052 GDBusConnection *connection = th->client_bus;
2055 case TETHERING_TYPE_USB:
2056 g_dbus_connection_signal_unsubscribe(connection,
2057 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
2059 g_dbus_proxy_call(proxy, "disable_usb_tethering",
2060 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
2061 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2062 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2065 case TETHERING_TYPE_WIFI:
2066 DBG("Disable wifi tethering..");
2067 g_dbus_connection_signal_unsubscribe(connection,
2068 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
2070 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
2071 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
2072 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2073 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2076 case TETHERING_TYPE_BT:
2077 g_dbus_connection_signal_unsubscribe(connection,
2078 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
2080 g_dbus_proxy_call(proxy, "disable_bt_tethering",
2081 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
2082 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2083 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2087 ERR("Not supported tethering type [%d]\n", type);
2089 return TETHERING_ERROR_INVALID_PARAMETER;
2092 return TETHERING_ERROR_NONE;
2096 * @brief Disables the tethering, asynchronously.
2098 * @privlevel platform
2099 * @privilege http://tizen.org/privilege/tethering.admin
2100 * @param[in] tethering The handle of tethering
2101 * @param[in] type The type of tethering
2102 * @return 0 on success, otherwise negative error value.
2103 * @retval #TETHERING_ERROR_NONE Successful
2104 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2105 * @post tethering_disabled_cb() will be invoked.
2106 * @see tethering_is_enabled()
2107 * @see tethering_enable()
2109 API int tethering_disable(tethering_h tethering, tethering_type_e type)
2111 INFO("+ type : %d\n", type);
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 == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2118 "parameter(tethering) is NULL\n");
2120 __tethering_h *th = (__tethering_h *)tethering;
2121 GDBusProxy *proxy = th->client_bus_proxy;
2122 GDBusConnection *connection = th->client_bus;
2125 case TETHERING_TYPE_USB:
2126 g_dbus_connection_signal_unsubscribe(connection,
2127 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
2129 g_dbus_proxy_call(proxy, "disable_usb_tethering",
2130 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2131 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2132 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2136 case TETHERING_TYPE_WIFI:
2137 g_dbus_connection_signal_unsubscribe(connection,
2138 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
2140 SINFO("Disable Wi-Fi Tethering !");
2142 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
2143 g_variant_new("(ii)", TETHERING_ADDRESS_FAMILY_IPV4, th->mode_type),
2144 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2145 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2148 case TETHERING_TYPE_BT:
2150 g_dbus_connection_signal_unsubscribe(connection,
2151 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
2153 g_dbus_proxy_call(proxy, "disable_bt_tethering",
2154 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2155 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2156 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2159 case TETHERING_TYPE_P2P:
2160 g_dbus_proxy_call(proxy, "disable_p2p_tethering",
2161 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2162 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2165 case TETHERING_TYPE_ALL:
2166 g_dbus_connection_signal_unsubscribe(connection,
2167 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
2169 g_dbus_proxy_call(proxy, "disable_usb_tethering",
2170 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2171 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2172 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2174 g_dbus_connection_signal_unsubscribe(connection,
2175 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
2177 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
2178 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2179 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2180 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2182 g_dbus_connection_signal_unsubscribe(connection,
2183 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
2185 g_dbus_proxy_call(proxy, "disable_bt_tethering",
2186 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2187 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2188 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2192 ERR("Not supported tethering type [%d]\n", type);
2194 return TETHERING_ERROR_INVALID_PARAMETER;
2197 return TETHERING_ERROR_NONE;
2202 * @brief Checks whetehr the tethering is enabled or not.
2204 * @privlevel platform
2205 * @privilege http://tizen.org/privilege/tethering.admin
2206 * @param[in] tethering The handle of tethering
2207 * @param[in] type The type of tethering
2208 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
2210 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
2212 INFO("+ type : %d\n", type);
2214 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
2216 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2218 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
2222 case TETHERING_TYPE_USB:
2223 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
2226 case TETHERING_TYPE_WIFI:
2227 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
2230 case TETHERING_TYPE_BT:
2231 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
2234 case TETHERING_TYPE_P2P:
2235 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_P2P;
2239 ERR("Not supported type : %d\n", type);
2242 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
2243 return is_on & vconf_type ? true : false;
2248 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
2250 * @privlevel platform
2251 * @privilege http://tizen.org/privilege/tethering.admin
2252 * @remarks @a mac_address must be released with free() by you.
2253 * @param[in] tethering The handle of tethering
2254 * @param[in] type The type of tethering
2255 * @param[out] mac_address The MAC address
2256 * @return 0 on success, otherwise a negative error value.
2257 * @retval #TETHERING_ERROR_NONE Successful
2258 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2259 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2260 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2261 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2262 * @pre tethering must be enabled.
2263 * @see tethering_is_enabled()
2264 * @see tethering_enable()
2266 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
2268 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2269 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2270 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2271 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2273 _retvm_if(tethering_is_enabled(tethering, type) == false,
2274 TETHERING_ERROR_NOT_ENABLED,
2275 "tethering type[%d] is not enabled\n", type);
2276 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2277 "parameter(tethering) is NULL\n");
2278 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2279 "parameter(mac_address) is NULL\n");
2283 char *macbuf = NULL;
2285 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2286 TETHERING_ERROR_OPERATION_FAILED,
2287 "getting interface name is failed\n");
2289 s = socket(AF_INET, SOCK_DGRAM, 0);
2290 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2291 "getting socket is failed\n");
2292 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2293 ERR("getting mac is failed\n");
2295 return TETHERING_ERROR_OPERATION_FAILED;
2299 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
2300 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2301 "Not enough memory\n");
2302 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
2303 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
2304 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
2305 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
2306 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
2307 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
2308 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
2310 *mac_address = macbuf;
2312 return TETHERING_ERROR_NONE;
2317 * @brief Gets the name of network interface. For example, usb0.
2319 * @privlevel platform
2320 * @privilege http://tizen.org/privilege/tethering.admin
2321 * @remarks @a interface_name must be released with free() by you.
2322 * @param[in] tethering The handle of tethering
2323 * @param[in] type The type of tethering
2324 * @param[out] interface_name The name of network interface
2325 * @return 0 on success, otherwise negative error value.
2326 * @retval #TETHERING_ERROR_NONE Successful
2327 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2328 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2329 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2330 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2331 * @pre tethering must be enabled.
2332 * @see tethering_is_enabled()
2333 * @see tethering_enable()
2335 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
2337 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2338 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2339 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2340 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2342 _retvm_if(tethering_is_enabled(tethering, type) == false,
2343 TETHERING_ERROR_NOT_ENABLED,
2344 "tethering type[%d] is not enabled\n", type);
2345 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2346 "parameter(tethering) is NULL\n");
2347 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2348 "parameter(interface_name) is NULL\n");
2350 char intf[TETHERING_STR_INFO_LEN] = {0, };
2352 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2353 TETHERING_ERROR_OPERATION_FAILED,
2354 "getting interface name is failed\n");
2355 *interface_name = strdup(intf);
2356 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2357 "Not enough memory\n");
2359 return TETHERING_ERROR_NONE;
2364 * @brief Gets the local IP address.
2366 * @privlevel platform
2367 * @privilege http://tizen.org/privilege/tethering.admin
2368 * @remarks @a ip_address must be released with free() by you.
2369 * @param[in] tethering The handle of tethering
2370 * @param[in] type The type of tethering
2371 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2372 * @param[out] ip_address The local IP address
2373 * @return 0 on success, otherwise negative error value.
2374 * @retval #TETHERING_ERROR_NONE Successful
2375 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2376 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2377 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2378 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2379 * @pre tethering must be enabled.
2380 * @see tethering_is_enabled()
2381 * @see tethering_enable()
2383 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2385 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2386 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2387 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2388 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2390 _retvm_if(tethering_is_enabled(tethering, type) == false,
2391 TETHERING_ERROR_NOT_ENABLED,
2392 "tethering type[%d] is not enabled\n", type);
2393 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2394 "parameter(tethering) is NULL\n");
2395 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2396 "parameter(ip_address) is NULL\n");
2402 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2403 TETHERING_ERROR_OPERATION_FAILED,
2404 "getting interface name is failed\n");
2406 s = socket(AF_INET, SOCK_DGRAM, 0);
2407 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2408 "getting socket is failed\n");
2409 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2410 ERR("ioctl is failed\n");
2412 return TETHERING_ERROR_OPERATION_FAILED;
2416 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2417 *ip_address = strdup(ipbuf);
2418 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2419 "Not enough memory\n");
2421 if (type == TETHERING_TYPE_WIFI) {
2422 __tethering_h *th = (__tethering_h *)tethering;
2423 g_strlcpy(th->ip_address, *ip_address, sizeof(th->ip_address));
2426 return TETHERING_ERROR_NONE;
2430 * @brief Sets the local IP address.
2432 * @privlevel platform
2433 * @privilege %http://tizen.org/privilege/tethering.admin
2434 * @remarks API is only available for TETHERING_TYPE_WIFI.
2435 * @param[in] tethering The tethering handle
2436 * @param[in] type The tethering type
2437 * @param[in] address_family The address family of IP address (currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported)
2438 * @param[out] ip_address The local IP address
2439 * @return 0 on success, otherwise negative error value
2440 * @retval #TETHERING_ERROR_NONE Successful
2441 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2442 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2443 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2444 * @see tethering_enable()
2446 int tethering_set_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, const char *ip_address)
2448 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2449 if (type == TETHERING_TYPE_WIFI)
2450 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2452 return TETHERING_ERROR_INVALID_PARAMETER;
2454 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2455 "parameter(tethering) is NULL\n");
2456 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2457 "parameter(ip_address) is NULL\n");
2459 __tethering_h *th = (__tethering_h *)tethering;
2462 if (address_family == TETHERING_ADDRESS_FAMILY_IPV4) {
2463 ip_len = strlen(ip_address);
2464 if (ip_len < TETHERING_IPV4_ADDRESS_MIN_LEN ||
2465 ip_len > TETHERING_IPV4_ADDRESS_MAX_LEN) {
2466 ERR("parameter(ip_address) is too short or long\n");
2467 return TETHERING_ERROR_INVALID_PARAMETER;
2469 g_strlcpy(th->ip_address, ip_address, sizeof(th->ip_address));
2471 /* IPv6 is not supported yet. */
2472 ERR("IPv6 address is not supported yet\n");
2473 return TETHERING_ERROR_OPERATION_FAILED;
2476 return TETHERING_ERROR_NONE;
2481 * @brief Gets the Gateway address.
2483 * @privlevel platform
2484 * @privilege http://tizen.org/privilege/tethering.admin
2485 * @remarks @a gateway_address must be released with free() by you.
2486 * @param[in] tethering The handle of tethering
2487 * @param[in] type The type of tethering
2488 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2489 * @param[out] gateway_address The local IP address
2490 * @return 0 on success, otherwise negative error value.
2491 * @retval #TETHERING_ERROR_NONE Successful
2492 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2493 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2494 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2495 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2496 * @pre tethering must be enabled.
2497 * @see tethering_is_enabled()
2498 * @see tethering_enable()
2500 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2502 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2503 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2504 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2505 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2507 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2508 "parameter(tethering) is NULL\n");
2509 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2510 "parameter(gateway_address) is NULL\n");
2511 _retvm_if(tethering_is_enabled(tethering, type) == false,
2512 TETHERING_ERROR_NOT_ENABLED,
2513 "tethering type[%d] is not enabled\n", type);
2515 __tethering_h *th = (__tethering_h *)tethering;
2517 if (type == TETHERING_TYPE_WIFI && strlen(th->ip_address)) {
2518 *gateway_address = strdup(th->ip_address);
2521 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2523 _retvm_if(!__get_gateway_addr(type, gateway_buf,
2524 sizeof(gateway_buf)),
2525 TETHERING_ERROR_OPERATION_FAILED,
2526 "getting gateway address is failed\n");
2528 *gateway_address = strdup(gateway_buf);
2531 return TETHERING_ERROR_NONE;
2536 * @brief Gets the Subnet Mask.
2538 * @privlevel platform
2539 * @privilege http://tizen.org/privilege/tethering.admin
2540 * @remarks @a subnet_mask must be released with free() by you.
2541 * @param[in] tethering The handle of tethering
2542 * @param[in] type The type of tethering
2543 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2544 * @param[out] subnet_mask The local IP address
2545 * @return 0 on success, otherwise negative error value.
2546 * @retval #TETHERING_ERROR_NONE Successful
2547 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2548 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2549 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2550 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2551 * @pre tethering must be enabled.
2552 * @see tethering_is_enabled()
2553 * @see tethering_enable()
2555 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2557 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2558 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2559 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2560 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2562 _retvm_if(tethering_is_enabled(tethering, type) == false,
2563 TETHERING_ERROR_NOT_ENABLED,
2564 "tethering is not enabled\n");
2565 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2566 "parameter(tethering) is NULL\n");
2567 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2568 "parameter(subnet_mask) is NULL\n");
2570 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2571 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2572 "Not enough memory\n");
2574 return TETHERING_ERROR_NONE;
2579 * @brief Gets the data usage.
2581 * @privlevel platform
2582 * @privilege http://tizen.org/privilege/tethering.admin
2583 * @param[in] tethering The handle of tethering
2584 * @param[out] usage The data usage
2585 * @return 0 on success, otherwise negative error value.
2586 * @retval #TETHERING_ERROR_NONE Successful
2587 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2588 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2589 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2590 * @pre tethering must be enabled.
2591 * @see tethering_is_enabled()
2592 * @see tethering_enable()
2594 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2596 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2598 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2599 "parameter(tethering) is NULL\n");
2600 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2601 "parameter(callback) is NULL\n");
2602 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2603 TETHERING_ERROR_NOT_ENABLED,
2604 "tethering is not enabled\n");
2606 __tethering_h *th = (__tethering_h *)tethering;
2607 GDBusProxy *proxy = th->client_bus_proxy;
2609 th->data_usage_cb = callback;
2610 th->data_usage_user_data = user_data;
2612 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2613 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2614 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2616 return TETHERING_ERROR_NONE;
2621 * @brief Gets the client which is connected by tethering "type".
2623 * @privlevel platform
2624 * @privilege http://tizen.org/privilege/tethering.admin
2625 * @param[in] tethering The handle of tethering
2626 * @param[in] type The type of tethering
2627 * @param[in] callback The callback function to invoke
2628 * @param[in] user_data The user data to be passed to the callback function
2629 * @retval #TETHERING_ERROR_NONE Successful
2630 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2631 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2632 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2633 * @pre tethering must be enabled.
2634 * @see tethering_is_enabled()
2635 * @see tethering_enable()
2638 API int tethering_is_dualband_supported(tethering_h tethering, tethering_type_e type, bool *supported)
2640 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2641 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2643 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2644 "parameter(tethering) is NULL\n");
2646 __tethering_h *th = (__tethering_h *)tethering;
2647 gchar *if_name = NULL;
2648 gboolean Is2GBandSupported = FALSE;
2649 gboolean Is5GBandSupported = FALSE;
2650 GError *error = NULL;
2651 GVariant *result = NULL;
2652 GVariantIter *outer_iter = NULL;
2653 GVariantIter *inner_iter = NULL;
2654 GVariant *station = NULL;
2655 GVariant *value = NULL;
2660 __reset_dualband_support();
2661 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_wifi_interfaces",
2662 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2665 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2666 g_error_free(error);
2667 return TETHERING_ERROR_OPERATION_FAILED;
2669 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2670 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2671 g_variant_get(station, "a{sv}", &inner_iter);
2672 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2673 if (g_strcmp0(key, "IfName") == 0) {
2674 g_variant_get(value, "s", &if_name);
2675 SDBG("Interface Name is %s\n", if_name);
2676 } else if (g_strcmp0(key, "Is2GBandSupported") == 0) {
2677 Is2GBandSupported = g_variant_get_boolean(value);
2678 SDBG("Is2GBandSupported is %d\n", Is2GBandSupported);
2679 if (Is2GBandSupported)
2680 __set_dualband_support(DUAL_BAND_2G);
2681 } else if (g_strcmp0(key, "Is5GBandSupported") == 0) {
2682 Is5GBandSupported = g_variant_get_boolean(value);
2683 SDBG("Is5GBandSupported is %d\n", Is5GBandSupported);
2684 if (Is5GBandSupported)
2685 __set_dualband_support(DUAL_BAND_5G);
2687 ERR("Key %s not required\n", key);
2692 g_variant_iter_free(inner_iter);
2695 __set_dualband_support(DUAL_BAND_MIN_INTERFACE);
2696 *supported = __is_dualband_support();
2697 DBG("count:%d is dualband suppport: %d", count, *supported);
2698 g_variant_iter_free(outer_iter);
2699 g_variant_unref(result);
2701 return TETHERING_ERROR_NONE;
2703 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2705 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2706 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2707 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2708 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2710 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2711 "parameter(tethering) is NULL\n");
2712 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2713 "parameter(callback) is NULL\n");
2714 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2715 TETHERING_ERROR_NOT_ENABLED,
2716 "tethering is not enabled\n");
2718 mobile_ap_type_e interface;
2719 tethering_band_e band;
2720 __tethering_h *th = (__tethering_h *)tethering;
2721 __tethering_client_h client = {0, };
2724 gchar *hostname = NULL;
2725 guint timestamp = 0;
2726 GError *error = NULL;
2727 GVariant *result = NULL;
2728 GVariantIter *outer_iter = NULL;
2729 GVariantIter *inner_iter = NULL;
2730 GVariant *station = NULL;
2731 GVariant *value = NULL;
2734 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2735 NULL, G_DBUS_CALL_FLAGS_NONE,
2736 -1, th->cancellable, &error);
2739 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2740 g_error_free(error);
2741 return TETHERING_ERROR_OPERATION_FAILED;
2744 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2745 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2746 g_variant_get(station, "a{sv}", &inner_iter);
2747 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2748 if (g_strcmp0(key, "Type") == 0) {
2749 interface = g_variant_get_int32(value);
2750 tethering_type_e converted_type = __convert_to_tethering_type(interface);
2751 if (converted_type == TETHERING_TYPE_MAX) {
2752 ERR("Invalid interface\n");
2754 g_variant_unref(value);
2757 client.interface = converted_type;
2760 DBG("interface is %d\n", client.interface);
2761 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2763 g_variant_unref(value);
2766 } else if (g_strcmp0(key, "IP") == 0) {
2767 g_variant_get(value, "s", &ip);
2768 SDBG("ip is %s\n", ip);
2769 g_strlcpy(client.ip, ip, sizeof(client.ip));
2770 } else if (g_strcmp0(key, "MAC") == 0) {
2771 g_variant_get(value, "s", &mac);
2772 SDBG("mac is %s\n", mac);
2773 g_strlcpy(client.mac, mac, sizeof(client.mac));
2774 } else if (g_strcmp0(key, "Name") == 0) {
2775 g_variant_get(value, "s", &hostname);
2776 SDBG("hsotname is %s\n", hostname);
2778 client.hostname = g_strdup(hostname);
2779 } else if (g_strcmp0(key, "Time") == 0) {
2780 timestamp = g_variant_get_int32(value);
2781 DBG("timestamp is %d\n", timestamp);
2782 client.tm = (time_t)timestamp;
2783 } else if (g_strcmp0(key, "Band") == 0) {
2784 band = g_variant_get_int32(value);
2785 client.band = (!band) ? TETHERING_WIFI_BAND_2G : TETHERING_WIFI_BAND_5G;
2786 SDBG("band type %d\n", band);
2788 ERR("Key %s not required\n", key);
2799 g_variant_iter_free(inner_iter);
2800 if ((th->mode_type == 0 || th->mode_type == 1) && client.band != TETHERING_WIFI_BAND_2G) //if band is not for 2g continue
2802 if ((th->mode_type == 2 || th->mode_type == 3) && client.band != TETHERING_WIFI_BAND_5G) //if band is not for 5g continue
2804 SDBG("mode_type: %d and client.band: %d ", th->mode_type, client.band);
2805 if (callback((tethering_client_h)&client, user_data) == false) {
2806 DBG("iteration is stopped\n");
2807 g_free(client.hostname);
2808 client.hostname = NULL;
2809 g_variant_iter_free(outer_iter);
2810 g_variant_unref(result);
2812 return TETHERING_ERROR_OPERATION_FAILED;
2814 g_free(client.hostname);
2815 client.hostname = NULL;
2817 g_variant_iter_free(outer_iter);
2818 g_variant_unref(result);
2820 return TETHERING_ERROR_NONE;
2825 * @brief Registers the callback function called when tethering is enabled.
2827 * @privlevel platform
2828 * @privilege http://tizen.org/privilege/tethering.admin
2829 * @param[in] tethering The handle of tethering
2830 * @param[in] type The type of tethering
2831 * @param[in] callback The callback function to invoke
2832 * @param[in] user_data The user data to be passed to the callback function
2833 * @retval #TETHERING_ERROR_NONE Successful
2834 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2835 * @see tethering_unset_enabled_cb()
2837 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2839 INFO("+ type: %d\n", type);
2840 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2841 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2842 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2843 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2845 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2846 "parameter(tethering) is NULL\n");
2847 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2848 "parameter(callback) is NULL\n");
2850 __tethering_h *th = (__tethering_h *)tethering;
2851 tethering_type_e ti;
2853 if (type != TETHERING_TYPE_ALL) {
2854 th->enabled_cb[type] = callback;
2855 th->enabled_user_data[type] = user_data;
2857 return TETHERING_ERROR_NONE;
2860 /* TETHERING_TYPE_ALL */
2861 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2862 th->enabled_cb[ti] = callback;
2863 th->enabled_user_data[ti] = user_data;
2867 return TETHERING_ERROR_NONE;
2872 * @brief Unregisters the callback function called when tethering is disabled.
2874 * @privlevel platform
2875 * @privilege http://tizen.org/privilege/tethering.admin
2876 * @param[in] tethering The handle of tethering
2877 * @param[in] type The type of tethering
2878 * @retval #TETHERING_ERROR_NONE Successful
2879 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2880 * @see tethering_set_enabled_cb()
2882 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2884 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2885 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2886 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2887 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2889 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2890 "parameter(tethering) is NULL\n");
2892 __tethering_h *th = (__tethering_h *)tethering;
2893 tethering_type_e ti;
2895 if (type != TETHERING_TYPE_ALL) {
2896 th->enabled_cb[type] = NULL;
2897 th->enabled_user_data[type] = NULL;
2899 return TETHERING_ERROR_NONE;
2902 /* TETHERING_TYPE_ALL */
2903 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2904 th->enabled_cb[ti] = NULL;
2905 th->enabled_user_data[ti] = NULL;
2908 return TETHERING_ERROR_NONE;
2913 * @brief Registers the callback function called when tethering is disabled.
2915 * @privlevel platform
2916 * @privilege http://tizen.org/privilege/tethering.admin
2917 * @param[in] tethering The handle of tethering
2918 * @param[in] type The type of tethering
2919 * @param[in] callback The callback function to invoke
2920 * @param[in] user_data The user data to be passed to the callback function
2921 * @retval #TETHERING_ERROR_NONE Successful
2922 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2923 * @see tethering_unset_disabled_cb()
2925 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2927 INFO("+ type: %d\n", type);
2928 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2929 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2930 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2931 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2933 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2934 "parameter(tethering) is NULL\n");
2935 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2936 "parameter(callback) is NULL\n");
2938 __tethering_h *th = (__tethering_h *)tethering;
2939 tethering_type_e ti;
2941 if (type != TETHERING_TYPE_ALL) {
2942 th->disabled_cb[type] = callback;
2943 th->disabled_user_data[type] = user_data;
2945 return TETHERING_ERROR_NONE;
2948 /* TETHERING_TYPE_ALL */
2949 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2950 th->disabled_cb[ti] = callback;
2951 th->disabled_user_data[ti] = user_data;
2954 return TETHERING_ERROR_NONE;
2959 * @brief Unregisters the callback function called when tethering is disabled.
2961 * @privlevel platform
2962 * @privilege http://tizen.org/privilege/tethering.admin
2963 * @param[in] tethering The handle of tethering
2964 * @param[in] type The type of tethering
2965 * @retval #TETHERING_ERROR_NONE Successful
2966 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2967 * @see tethering_set_disabled_cb()
2969 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2971 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2972 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2973 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2974 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2976 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2977 "parameter(tethering) is NULL\n");
2979 __tethering_h *th = (__tethering_h *)tethering;
2980 tethering_type_e ti;
2982 if (type != TETHERING_TYPE_ALL) {
2983 th->disabled_cb[type] = NULL;
2984 th->disabled_user_data[type] = NULL;
2986 return TETHERING_ERROR_NONE;
2989 /* TETHERING_TYPE_ALL */
2990 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2991 th->disabled_cb[ti] = NULL;
2992 th->disabled_user_data[ti] = NULL;
2995 return TETHERING_ERROR_NONE;
3000 * @brief Registers the callback function called when the state of connection is changed.
3002 * @privlevel platform
3003 * @privilege http://tizen.org/privilege/tethering.admin
3004 * @param[in] tethering The handle of tethering
3005 * @param[in] type The type of tethering
3006 * @param[in] callback The callback function to invoke
3007 * @param[in] user_data The user data to be passed to the callback function
3008 * @retval #TETHERING_ERROR_NONE Successful
3009 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3010 * @see tethering_unset_connection_state_changed_cb_cb()
3012 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
3014 INFO("+ type: %d\n", type);
3015 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3016 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
3017 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3018 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
3020 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3021 "parameter(tethering) is NULL\n");
3022 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3023 "parameter(callback) is NULL\n");
3025 __tethering_h *th = (__tethering_h *)tethering;
3026 tethering_type_e ti;
3028 if (type != TETHERING_TYPE_ALL) {
3029 th->changed_cb[type] = callback;
3030 th->changed_user_data[type] = user_data;
3032 return TETHERING_ERROR_NONE;
3035 /* TETHERING_TYPE_ALL */
3036 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
3037 th->changed_cb[ti] = callback;
3038 th->changed_user_data[ti] = user_data;
3041 return TETHERING_ERROR_NONE;
3046 * @brief Unregisters the callback function called when the state of connection is changed.
3048 * @privlevel platform
3049 * @privilege http://tizen.org/privilege/tethering.admin
3050 * @param[in] tethering The handle of tethering
3051 * @param[in] type The type of tethering
3052 * @retval #TETHERING_ERROR_NONE Successful
3053 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3054 * @see tethering_set_connection_state_changed_cb()
3056 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
3058 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3059 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
3060 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3061 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
3063 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3064 "parameter(tethering) is NULL\n");
3066 __tethering_h *th = (__tethering_h *)tethering;
3067 tethering_type_e ti;
3069 if (type != TETHERING_TYPE_ALL) {
3070 th->changed_cb[type] = NULL;
3071 th->changed_user_data[type] = NULL;
3073 return TETHERING_ERROR_NONE;
3076 /* TETHERING_TYPE_ALL */
3077 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
3078 th->changed_cb[ti] = NULL;
3079 th->changed_user_data[ti] = NULL;
3082 return TETHERING_ERROR_NONE;
3087 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
3089 * @privlevel platform
3090 * @privilege http://tizen.org/privilege/tethering.admin
3091 * @param[in] tethering The handle of tethering
3092 * @param[in] callback The callback function to invoke
3093 * @param[in] user_data The user data to be passed to the callback function
3094 * @retval #TETHERING_ERROR_NONE Successful
3095 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3096 * @see tethering_wifi_unset_security_type_changed_cb()
3098 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
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");
3105 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3106 "parameter(callback) is NULL\n");
3108 __tethering_h *th = (__tethering_h *)tethering;
3110 th->security_type_changed_cb = callback;
3111 th->security_type_user_data = user_data;
3113 return TETHERING_ERROR_NONE;
3119 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
3121 * @privlevel platform
3122 * @privilege http://tizen.org/privilege/tethering.admin
3123 * @param[in] tethering The handle of tethering
3124 * @param[in] type The type of tethering
3125 * @retval #TETHERING_ERROR_NONE Successful
3126 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3127 * @see tethering_wifi_set_security_type_changed_cb()
3129 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
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->security_type_changed_cb = NULL;
3140 th->security_type_user_data = NULL;
3142 return TETHERING_ERROR_NONE;
3147 * @brief Registers the callback function called when the visibility of SSID is changed.
3149 * @privlevel platform
3150 * @privilege http://tizen.org/privilege/tethering.admin
3151 * @param[in] tethering The handle of tethering
3152 * @param[in] callback The callback function to invoke
3153 * @param[in] user_data The user data to be passed to the callback function
3154 * @retval #TETHERING_ERROR_NONE Successful
3155 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3156 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
3158 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
3160 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3161 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3163 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3164 "parameter(tethering) is NULL\n");
3165 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3166 "parameter(callback) is NULL\n");
3168 __tethering_h *th = (__tethering_h *)tethering;
3170 th->ssid_visibility_changed_cb = callback;
3171 th->ssid_visibility_user_data = user_data;
3173 return TETHERING_ERROR_NONE;
3178 * @brief Unregisters the callback function called when the visibility of SSID is changed.
3180 * @privlevel platform
3181 * @privilege http://tizen.org/privilege/tethering.admin
3182 * @param[in] tethering The handle of tethering
3183 * @retval #TETHERING_ERROR_NONE Successful
3184 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3185 * @see tethering_wifi_set_ssid_visibility_changed_cb()
3187 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
3189 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3190 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3192 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3193 "parameter(tethering) is NULL\n");
3195 __tethering_h *th = (__tethering_h *)tethering;
3197 th->ssid_visibility_changed_cb = NULL;
3198 th->ssid_visibility_user_data = NULL;
3200 return TETHERING_ERROR_NONE;
3205 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
3207 * @privlevel platform
3208 * @privilege http://tizen.org/privilege/tethering.admin
3209 * @param[in] tethering The handle of tethering
3210 * @param[in] callback The callback function to invoke
3211 * @param[in] user_data The user data to be passed to the callback function
3212 * @retval #TETHERING_ERROR_NONE Successful
3213 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3214 * @see tethering_wifi_unset_passphrase_changed_cb()
3216 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
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");
3223 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3224 "parameter(callback) is NULL\n");
3226 __tethering_h *th = (__tethering_h *)tethering;
3228 th->passphrase_changed_cb = callback;
3229 th->passphrase_user_data = user_data;
3231 return TETHERING_ERROR_NONE;
3236 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
3238 * @privlevel platform
3239 * @privilege http://tizen.org/privilege/tethering.admin
3240 * @param[in] tethering The handle of tethering
3241 * @retval #TETHERING_ERROR_NONE Successful
3242 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3243 * @see tethering_wifi_set_passphrase_changed_cb()
3245 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
3247 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3248 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3250 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3251 "parameter(tethering) is NULL\n");
3253 __tethering_h *th = (__tethering_h *)tethering;
3255 th->passphrase_changed_cb = NULL;
3256 th->passphrase_user_data = NULL;
3258 return TETHERING_ERROR_NONE;
3263 * @brief Sets the security type of Wi-Fi tethering.
3265 * @privlevel platform
3266 * @privilege http://tizen.org/privilege/tethering.admin
3267 * @remarks This change is applied next time Wi-Fi tethering is enabled
3268 * @param[in] tethering The handle of tethering
3269 * @param[in] type The security type
3270 * @return 0 on success, otherwise negative error value.
3271 * @retval #TETHERING_ERROR_NONE Successful
3272 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3273 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3274 * @see tethering_wifi_get_security_type()
3276 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
3278 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3279 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3281 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3282 "parameter(tethering) is NULL\n");
3284 __tethering_h *th = (__tethering_h *)tethering;
3285 tethering_error_e ret = TETHERING_ERROR_NONE;
3286 char *sec_str = NULL;
3288 ret = __set_security_type(type);
3289 if (ret == TETHERING_ERROR_NONE) {
3291 case TETHERING_WIFI_SECURITY_TYPE_NONE:
3292 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
3294 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
3295 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
3297 case TETHERING_WIFI_SECURITY_TYPE_WPS:
3298 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
3300 case TETHERING_WIFI_SECURITY_TYPE_SAE:
3301 sec_str = TETHERING_WIFI_SECURITY_TYPE_SAE_STR;
3305 __send_dbus_signal(th->client_bus,
3306 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
3313 * @brief Gets the security type of Wi-Fi tethering.
3315 * @privlevel platform
3316 * @privilege http://tizen.org/privilege/tethering.admin
3317 * @param[in] tethering The handle of tethering
3318 * @param[out] type The security type
3319 * @return 0 on success, otherwise negative error value.
3320 * @retval #TETHERING_ERROR_NONE Successful
3321 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3322 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3323 * @see tethering_wifi_set_security_type()
3325 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3327 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3328 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3330 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3331 "parameter(tethering) is NULL\n");
3332 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3333 "parameter(type) is NULL\n");
3335 return __get_security_type(type);
3340 * @brief Sets the SSID (service set identifier).
3342 * @privlevel platform
3343 * @privilege http://tizen.org/privilege/tethering.admin
3344 * @details If SSID is not set, Device name is used as SSID
3345 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
3346 * @param[in] tethering The handle of tethering
3347 * @param[out] ssid The SSID
3348 * @return 0 on success, otherwise negative error value.
3349 * @retval #TETHERING_ERROR_NONE Successful
3350 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3351 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3353 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
3355 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3356 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3358 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3359 "parameter(tethering) is NULL\n");
3360 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3361 "parameter(ssid) is NULL\n");
3363 __tethering_h *th = (__tethering_h *)tethering;
3364 char *p_ssid = NULL;
3367 ssid_len = strlen(ssid);
3368 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3369 ERR("parameter(ssid) is too long");
3370 return TETHERING_ERROR_INVALID_PARAMETER;
3373 p_ssid = strdup(ssid);
3374 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
3375 "strdup is failed\n");
3378 GDBusProxy *proxy = th->client_bus_proxy;
3379 GVariant *parameters;
3380 GError *error = NULL;
3381 tethering_error_e ret = TETHERING_ERROR_NONE;
3383 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_ssid",
3384 g_variant_new("(s)", ssid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3387 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3389 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3390 ret = TETHERING_ERROR_PERMISSION_DENIED;
3392 ret = TETHERING_ERROR_OPERATION_FAILED;
3394 g_error_free(error);
3399 if (parameters != NULL) {
3400 g_variant_get(parameters, "(u)", &ret);
3401 g_variant_unref(parameters);
3404 SINFO("set tethering ssid : %s", ssid);
3405 #endif /* TIZEN_TV_EXT */
3411 return TETHERING_ERROR_NONE;
3416 * @brief Gets the SSID (service set identifier).
3418 * @privlevel platform
3419 * @privilege http://tizen.org/privilege/tethering.admin
3420 * @remarks @a ssid must be released with free() by you.
3421 * @param[in] tethering The handle of tethering
3422 * @param[out] ssid The SSID
3423 * @return 0 on success, otherwise negative error value.
3424 * @retval #TETHERING_ERROR_NONE Successful
3425 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3426 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3427 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3429 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
3431 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3432 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3434 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3435 "parameter(tethering) is NULL\n");
3436 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3437 "parameter(ssid) is NULL\n");
3440 __tethering_h *th = (__tethering_h *)tethering;
3441 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
3444 if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID,
3445 val, sizeof(val)) == true) {
3446 *ssid = strdup(val);
3447 SINFO("get tethering ssid : %s", *ssid);
3448 return TETHERING_ERROR_NONE;
3450 #endif /* TIZEN_TV_EXT */
3452 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
3453 if (th->ssid != NULL) {
3454 DBG("Private SSID is set\n");
3455 *ssid = strdup(th->ssid);
3457 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
3458 val, sizeof(val)) == false) {
3459 return TETHERING_ERROR_OPERATION_FAILED;
3461 *ssid = strdup(val);
3464 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
3465 val, sizeof(val)) == false) {
3466 return TETHERING_ERROR_OPERATION_FAILED;
3468 *ssid = strdup(val);
3471 if (*ssid == NULL) {
3472 ERR("strdup is failed\n");
3473 return TETHERING_ERROR_OUT_OF_MEMORY;
3476 return TETHERING_ERROR_NONE;
3481 * @brief Sets the visibility of SSID(service set identifier).
3483 * @privlevel platform
3484 * @privilege http://tizen.org/privilege/tethering.admin
3485 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3486 * @remarks This change is applied next time Wi-Fi tethering is enabled
3487 * @param[in] tethering The handle of tethering
3488 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3489 * @return 0 on success, otherwise negative error value.
3490 * @retval #TETHERING_ERROR_NONE Successful
3491 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3492 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3493 * @see tethering_wifi_get_ssid_visibility()
3495 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
3497 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3498 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3500 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3501 "parameter(tethering) is NULL\n");
3503 __tethering_h *th = (__tethering_h *)tethering;
3504 tethering_error_e ret = TETHERING_ERROR_NONE;
3506 ret = __set_visible(visible);
3507 if (ret == TETHERING_ERROR_NONE) {
3508 __send_dbus_signal(th->client_bus,
3509 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
3510 visible ? SIGNAL_MSG_SSID_VISIBLE :
3511 SIGNAL_MSG_SSID_HIDE);
3518 * @brief Gets the visibility of SSID(service set identifier).
3520 * @privlevel platform
3521 * @privilege http://tizen.org/privilege/tethering.admin
3522 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3523 * @param[in] tethering The handle of tethering
3524 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3525 * @return 0 on success, otherwise negative error value.
3526 * @retval #TETHERING_ERROR_NONE Successful
3527 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3528 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3529 * @see tethering_wifi_set_ssid_visibility()
3531 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
3533 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3534 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3536 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3537 "parameter(tethering) is NULL\n");
3538 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3539 "parameter(visible) is NULL\n");
3541 return __get_visible(visible);
3546 * @brief Sets the passphrase.
3548 * @privlevel platform
3549 * @privilege http://tizen.org/privilege/tethering.admin
3550 * @remarks This change is applied next time Wi-Fi tethering is enabled
3551 * @param[in] tethering The handle of tethering
3552 * @param[in] passphrase The passphrase
3553 * @return 0 on success, otherwise negative error value.
3554 * @retval #TETHERING_ERROR_NONE Successful
3555 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3556 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3557 * @see tethering_wifi_get_passphrase()
3559 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3561 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3562 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3564 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3565 "parameter(tethering) is NULL\n");
3566 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3567 "parameter(passphrase) is NULL\n");
3569 __tethering_h *th = (__tethering_h *)tethering;
3570 GDBusProxy *proxy = th->client_bus_proxy;
3571 GVariant *parameters;
3572 GError *error = NULL;
3573 int passphrase_len = 0;
3577 passphrase_len = strlen(passphrase);
3578 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3579 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3580 ERR("parameter(passphrase) is too short or long\n");
3581 return TETHERING_ERROR_INVALID_PARAMETER;
3584 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3585 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3588 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3590 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3591 ret = TETHERING_ERROR_PERMISSION_DENIED;
3593 ret = TETHERING_ERROR_OPERATION_FAILED;
3595 g_error_free(error);
3599 g_variant_get(parameters, "(u)", &ret);
3600 g_variant_unref(parameters);
3602 if (ret == TETHERING_ERROR_NONE) {
3603 __send_dbus_signal(th->client_bus,
3604 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3613 * @brief Gets the passphrase.
3615 * @privlevel platform
3616 * @privilege http://tizen.org/privilege/tethering.admin
3617 * @remarks @a passphrase must be released with free() by you.
3618 * @param[in] tethering The handle of tethering
3619 * @param[out] passphrase The passphrase
3620 * @return 0 on success, otherwise negative error value.
3621 * @retval #TETHERING_ERROR_NONE Successful
3622 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3623 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3624 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3625 * @see tethering_wifi_set_passphrase()
3627 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3629 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3630 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3632 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3633 "parameter(tethering) is NULL\n");
3634 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3635 "parameter(passphrase) is NULL\n");
3637 __tethering_h *th = (__tethering_h *)tethering;
3638 GDBusProxy *proxy = th->client_bus_proxy;
3639 GVariant *parameters;
3640 GError *error = NULL;
3641 unsigned int len = 0;
3642 tethering_error_e ret = TETHERING_ERROR_NONE;
3644 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3645 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3648 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3650 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3651 ret = TETHERING_ERROR_PERMISSION_DENIED;
3653 ret = TETHERING_ERROR_OPERATION_FAILED;
3655 g_error_free(error);
3659 if (parameters != NULL) {
3660 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3661 g_variant_unref(parameters);
3664 return TETHERING_ERROR_NONE;
3667 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3669 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3670 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3672 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3673 "parameter(tethering) is NULL\n");
3675 __tethering_h *th = (__tethering_h *)tethering;
3678 GDBusProxy *proxy = th->client_bus_proxy;
3679 GVariant *parameters;
3680 GError *error = NULL;
3681 tethering_error_e ret = TETHERING_ERROR_NONE;
3683 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_channel",
3684 g_variant_new("(i)", channel), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3687 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3689 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3690 ret = TETHERING_ERROR_PERMISSION_DENIED;
3692 ret = TETHERING_ERROR_OPERATION_FAILED;
3694 g_error_free(error);
3698 if (parameters != NULL) {
3699 g_variant_get(parameters, "(u)", &ret);
3700 g_variant_unref(parameters);
3703 SINFO("set channel : %d", channel);
3704 #endif /* TIZEN_TV_EXT */
3706 th->channel = channel;
3708 return TETHERING_ERROR_NONE;
3711 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3713 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3714 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3716 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3717 "parameter(tethering) is NULL\n");
3719 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3720 "parameter(channel) is NULL\n");
3722 __tethering_h *th = (__tethering_h *)tethering;
3724 GDBusProxy *proxy = th->client_bus_proxy;
3725 GVariant *parameters = NULL;
3726 GError *error = NULL;
3728 int vconf_channel = -1;
3729 tethering_error_e ret = TETHERING_ERROR_NONE;
3731 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_channel",
3732 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3735 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3737 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3738 ret = TETHERING_ERROR_PERMISSION_DENIED;
3740 ret = TETHERING_ERROR_OPERATION_FAILED;
3742 g_error_free(error);
3746 if (parameters != NULL) {
3747 g_variant_get(parameters, "(iu)", &ch, &ret);
3748 g_variant_unref(parameters);
3752 ERR("failed to get Hostapd channel, set th->channel");
3753 *channel = th->channel;
3757 if (vconf_get_int(VCONFKEY_WIFI_CHANNEL, &vconf_channel) < 0)
3758 ERR("Failed to get vconf key for channel");
3760 *channel = vconf_channel;
3762 SINFO("get tethering channel : %d", *channel);
3763 #else /* TIZEN_TV_EXT */
3764 *channel = th->channel;
3765 #endif /* TIZEN_TV_EXT */
3767 return TETHERING_ERROR_NONE;
3770 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3772 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3773 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3775 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3776 "parameter(tethering) is NULL\n");
3778 __tethering_h *th = (__tethering_h *)tethering;
3780 th->mode_type = type;
3782 return TETHERING_ERROR_NONE;
3785 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3787 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3788 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3790 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3791 "parameter(tethering) is NULL\n");
3792 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3793 "parameter(type) is NULL\n");
3795 __tethering_h *th = (__tethering_h *)tethering;
3796 *type = th->mode_type;
3798 return TETHERING_ERROR_NONE;
3804 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3806 * @privlevel platform
3807 * @privilege http://tizen.org/privilege/tethering.admin
3808 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3809 * @param[in] tethering The handle of tethering
3810 * @param[in] callback The callback function to invoke
3811 * @param[in] user_data The user data to be passed to the callback function
3812 * @return 0 on success, otherwise negative error value.
3813 * @retval #TETHERING_ERROR_NONE Successful
3814 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3815 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3817 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3820 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3821 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3823 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3824 "parameter(tethering) is NULL\n");
3825 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3826 "parameter(callback) is NULL\n");
3828 __tethering_h *th = (__tethering_h *)tethering;
3829 _softap_settings_t set;
3830 GDBusProxy *proxy = th->client_bus_proxy;
3833 memset(&set, 0, sizeof(_softap_settings_t));
3837 if (th->settings_reloaded_cb) {
3838 ERR("Operation in progress\n");
3839 return TETHERING_ERROR_OPERATION_FAILED;
3842 ret = __prepare_wifi_settings(tethering, &set);
3843 if (ret != TETHERING_ERROR_NONE) {
3844 ERR("softap settings initialization failed\n");
3845 return TETHERING_ERROR_OPERATION_FAILED;
3848 th->settings_reloaded_cb = callback;
3849 th->settings_reloaded_user_data = user_data;
3851 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
3852 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
3855 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3856 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, set.txpower),
3857 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3858 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3860 return TETHERING_ERROR_NONE;
3863 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3865 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3866 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3868 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3869 "parameter(tethering) is NULL\n");
3871 __tethering_h *th = (__tethering_h *)tethering;
3872 th->mac_filter = mac_filter;
3874 return TETHERING_ERROR_NONE;
3877 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3879 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3880 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3882 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3883 "parameter(mac_filter) is NULL\n");
3884 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3885 "parameter(mac_filter) is NULL\n");
3887 __tethering_h *th = (__tethering_h *)tethering;
3888 *mac_filter = th->mac_filter;
3890 return TETHERING_ERROR_NONE;
3893 static int __add_mac_to_file(const char *filepath, const char *mac)
3896 char line[MAX_BUF_SIZE] = "\0";
3897 bool mac_exist = false;
3900 fp = fopen(filepath, "a+");
3902 ERR("fopen is failed\n");
3903 return TETHERING_ERROR_OPERATION_FAILED;
3906 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3907 if (strncmp(mac, line, 17) == 0) {
3908 DBG("MAC %s already exist in the list\n", mac);
3915 p_mac = strdup(mac);
3916 if (p_mac == NULL) {
3917 ERR("strdup failed\n");
3919 return TETHERING_ERROR_OUT_OF_MEMORY;
3922 fprintf(fp, "%s\n", mac);
3924 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3925 allowed_list = g_slist_append(allowed_list, p_mac);
3926 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3927 blocked_list = g_slist_append(blocked_list, p_mac);
3934 return TETHERING_ERROR_NONE;
3937 static int __remove_mac_from_file(const char *filepath, const char *mac)
3941 char line[MAX_BUF_SIZE] = "\0";
3943 fp = fopen(filepath, "r");
3945 ERR("fopen is failed\n");
3946 return TETHERING_ERROR_OPERATION_FAILED;
3949 fp1 = fopen(TEMP_LIST, "w+");
3952 ERR("fopen is failed\n");
3953 return TETHERING_ERROR_OPERATION_FAILED;
3956 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3957 if (strncmp(mac, line, 17) == 0) {
3958 DBG("MAC %s found in the list\n", mac);
3960 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3961 GSList *list = NULL;
3962 for (list = allowed_list; list != NULL; list = list->next) {
3963 char *p_mac = (char *)list->data;
3964 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3965 allowed_list = g_slist_remove(allowed_list, p_mac);
3967 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3968 GSList *list = NULL;
3969 for (list = blocked_list; list != NULL; list = list->next) {
3970 char *p_mac = (char *)list->data;
3971 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3972 blocked_list = g_slist_remove(blocked_list, p_mac);
3976 fprintf(fp1, "%s", line);
3983 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3984 if (rename(TEMP_LIST, ALLOWED_LIST) != 0) {
3985 ERR("rename is failed (%s -> %s)", TEMP_LIST, ALLOWED_LIST);
3986 return TETHERING_ERROR_OPERATION_FAILED;
3988 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3989 if (rename(TEMP_LIST, BLOCKED_LIST) != 0) {
3990 ERR("rename is failed (%s -> %s)", TEMP_LIST, BLOCKED_LIST);
3991 return TETHERING_ERROR_OPERATION_FAILED;
3995 return TETHERING_ERROR_NONE;
3998 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
4000 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4001 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4003 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4004 "parameter(tethering) is NULL\n");
4005 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4006 "parameter(mac) is NULL\n");
4008 return __add_mac_to_file(ALLOWED_LIST, mac);
4011 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
4013 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4014 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4016 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4017 "parameter(tethering) is NULL\n");
4018 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4019 "parameter(mac) is NULL\n");
4021 return __remove_mac_from_file(ALLOWED_LIST, mac);
4024 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
4026 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4027 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4029 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4030 "parameter(tethering) is NULL\n");
4031 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4032 "parameter(allowed_mac_list) is NULL\n");
4034 *allowed_mac_list = g_slist_copy(allowed_list);
4035 return TETHERING_ERROR_NONE;
4038 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
4040 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4041 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4043 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4044 "parameter(tethering) is NULL\n");
4045 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4046 "parameter(mac) is NULL\n");
4048 return __add_mac_to_file(BLOCKED_LIST, mac);
4051 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
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");
4058 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4059 "parameter(mac) is NULL\n");
4061 return __remove_mac_from_file(BLOCKED_LIST, mac);
4064 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
4066 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4067 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4069 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4070 "parameter(tethering) is NULL\n");
4071 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4072 "parameter(blocked_mac_list) is NULL\n");
4074 *blocked_mac_list = g_slist_copy(blocked_list);
4075 return TETHERING_ERROR_NONE;
4078 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
4080 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4081 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4083 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4084 "parameter(tethering) is NULL\n");
4086 GVariant *parameters;
4087 GError *error = NULL;
4090 __tethering_h *th = (__tethering_h *)tethering;
4092 GDBusProxy *proxy = th->client_bus_proxy;
4094 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
4095 g_variant_new("(b)", enable),
4096 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4099 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4100 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4101 result = TETHERING_ERROR_PERMISSION_DENIED;
4103 result = TETHERING_ERROR_OPERATION_FAILED;
4105 g_error_free(error);
4106 th->dhcp_enabled = false;
4111 g_variant_get(parameters, "(u)", &result);
4112 g_variant_unref(parameters);
4115 th->dhcp_enabled = true;
4117 th->dhcp_enabled = false;
4119 return TETHERING_ERROR_NONE;
4122 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
4124 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4125 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4127 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4128 "parameter(tethering) is NULL\n");
4129 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4130 "parameter(rangestart) is NULL\n");
4131 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4132 "parameter(rangestop) is NULL\n");
4134 GVariant *parameters;
4135 GError *error = NULL;
4138 __tethering_h *th = (__tethering_h *)tethering;
4140 GDBusProxy *proxy = th->client_bus_proxy;
4142 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
4143 g_variant_new("(ss)", rangestart, rangestop),
4144 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4146 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4148 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4149 result = TETHERING_ERROR_PERMISSION_DENIED;
4151 result = TETHERING_ERROR_OPERATION_FAILED;
4153 g_error_free(error);
4154 th->dhcp_enabled = false;
4159 g_variant_get(parameters, "(u)", &result);
4160 g_variant_unref(parameters);
4162 th->dhcp_enabled = true;
4164 return TETHERING_ERROR_NONE;
4167 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
4169 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4170 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4172 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4173 "parameter(tethering) is NULL\n");
4174 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4175 "parameter(dhcp_enabled) is NULL\n");
4177 __tethering_h *th = (__tethering_h *)tethering;
4178 *dhcp_enabled = th->dhcp_enabled;
4180 return TETHERING_ERROR_NONE;
4183 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
4185 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4186 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4188 GError *error = NULL;
4190 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4191 "parameter(tethering) is NULL\n");
4192 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
4193 TETHERING_ERROR_NOT_ENABLED,
4194 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
4195 __tethering_h *th = (__tethering_h *)tethering;
4196 th->txpower = txpower;
4198 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
4199 g_variant_new("(u)", txpower),
4200 G_DBUS_CALL_FLAGS_NONE,
4201 -1, th->cancellable, &error);
4203 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
4204 g_clear_error(&error);
4205 return TETHERING_ERROR_OPERATION_FAILED;
4207 return TETHERING_ERROR_NONE;
4210 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
4212 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4213 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4215 GError *error = NULL;
4216 GVariant *result = NULL;
4218 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4219 "parameter(tethering) is NULL\n");
4220 _retvm_if(txpower == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4221 "parameter(txpower) is NULL\n");
4222 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
4223 TETHERING_ERROR_NOT_ENABLED,
4224 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
4226 __tethering_h *th = (__tethering_h *)tethering;
4228 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
4230 G_DBUS_CALL_FLAGS_NONE,
4231 -1, th->cancellable, &error);
4233 if (result != NULL) {
4234 g_variant_get(result, "(u)", txpower);
4235 g_variant_unref(result);
4238 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
4239 g_clear_error(&error);
4240 return TETHERING_ERROR_OPERATION_FAILED;
4242 g_clear_error(&error);
4243 return TETHERING_ERROR_NONE;
4246 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
4248 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4249 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4251 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4252 "parameter(tethering) is NULL\n");
4254 GVariant *parameters;
4255 GError *error = NULL;
4258 __tethering_h *th = (__tethering_h *)tethering;
4260 GDBusProxy *proxy = th->client_bus_proxy;
4262 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
4263 g_variant_new("(u)", mtu),
4264 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4266 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4268 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4269 result = TETHERING_ERROR_PERMISSION_DENIED;
4271 result = TETHERING_ERROR_OPERATION_FAILED;
4273 g_error_free(error);
4277 g_variant_get(parameters, "(u)", &result);
4279 g_variant_unref(parameters);
4281 return TETHERING_ERROR_NONE;
4284 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
4286 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4287 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4289 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4290 "parameter(tethering) is NULL\n");
4291 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4292 "parameter(mac) is NULL\n");
4294 GVariant *parameters;
4295 GError *error = NULL;
4298 __tethering_h *th = (__tethering_h *)tethering;
4300 GDBusProxy *proxy = th->client_bus_proxy;
4302 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
4303 g_variant_new("(s)", mac),
4304 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4306 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4308 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4309 result = TETHERING_ERROR_PERMISSION_DENIED;
4311 result = TETHERING_ERROR_OPERATION_FAILED;
4313 g_error_free(error);
4317 g_variant_get(parameters, "(u)", &result);
4318 g_variant_unref(parameters);
4320 if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
4321 return TETHERING_ERROR_NOT_SUPPORT_API;
4323 return TETHERING_ERROR_NONE;
4326 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
4328 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4329 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4331 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4332 "parameter(tethering) is NULL\n");
4334 __tethering_h *th = (__tethering_h *)tethering;
4336 th->wifi_max_connected = max_device;
4338 return TETHERING_ERROR_NONE;
4341 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
4343 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4344 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4346 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4347 "parameter(tethering) is NULL\n");
4348 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4349 "parameter(max_device) is NULL\n");
4351 __tethering_h *th = (__tethering_h *)tethering;
4353 *max_device = th->wifi_max_connected;
4354 return TETHERING_ERROR_NONE;
4357 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
4359 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4360 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4362 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4363 "parameter(tethering) is NULL\n");
4365 GVariant *parameters;
4366 GError *error = NULL;
4369 __tethering_h *th = (__tethering_h *)tethering;
4371 GDBusProxy *proxy = th->client_bus_proxy;
4373 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
4374 g_variant_new("(b)", enable),
4375 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4377 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4379 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4380 result = TETHERING_ERROR_PERMISSION_DENIED;
4382 result = TETHERING_ERROR_OPERATION_FAILED;
4384 g_error_free(error);
4388 g_variant_get(parameters, "(u)", &result);
4389 g_variant_unref(parameters);
4391 th->port_forwarding = true;
4393 return TETHERING_ERROR_NONE;
4396 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)
4398 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4399 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4401 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4402 "parameter(tethering) is NULL\n");
4403 _retvm_if(ifname == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4404 "parameter(ifname) is NULL\n");
4405 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4406 "parameter(protocol) is NULL\n");
4407 _retvm_if(org_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4408 "parameter(org_ip) is NULL\n");
4409 _retvm_if(final_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4410 "parameter(final_ip) is NULL\n");
4412 GVariant *parameters;
4413 GError *error = NULL;
4415 char cmd[MAX_BUF_SIZE] = { 0, };
4418 __tethering_h *th = (__tethering_h *)tethering;
4420 GDBusProxy *proxy = th->client_bus_proxy;
4422 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
4423 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
4424 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4426 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4428 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4429 result = TETHERING_ERROR_PERMISSION_DENIED;
4431 result = TETHERING_ERROR_OPERATION_FAILED;
4433 g_error_free(error);
4437 g_variant_get(parameters, "(u)", &result);
4438 g_variant_unref(parameters);
4440 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);
4444 ERR("strdup failed\n");
4445 return TETHERING_ERROR_OUT_OF_MEMORY;
4448 port_forwarding = g_slist_append(port_forwarding, list);
4450 return TETHERING_ERROR_NONE;
4453 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
4455 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4456 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4458 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4459 "parameter(tethering) is NULL\n");
4461 GVariant *parameters;
4462 GError *error = NULL;
4465 __tethering_h *th = (__tethering_h *)tethering;
4467 GDBusProxy *proxy = th->client_bus_proxy;
4469 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
4470 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4472 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4474 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4475 result = TETHERING_ERROR_PERMISSION_DENIED;
4477 result = TETHERING_ERROR_OPERATION_FAILED;
4479 g_error_free(error);
4483 g_variant_get(parameters, "(u)", &result);
4485 g_variant_unref(parameters);
4487 return TETHERING_ERROR_NONE;
4490 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool *forwarding_enabled)
4492 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4493 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4495 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4496 "parameter(tethering) is NULL\n");
4497 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4498 "parameter(forwarding_enabled) is NULL\n");
4500 __tethering_h *th = (__tethering_h *)tethering;
4502 *forwarding_enabled = th->port_forwarding;
4504 return TETHERING_ERROR_NONE;
4507 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
4509 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4510 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4512 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4513 "parameter(tethering) is NULL\n");
4514 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4515 "parameter(port_forwarding_list) is NULL\n");
4517 *port_forwarding_list = g_slist_copy(port_forwarding);
4518 return TETHERING_ERROR_NONE;
4521 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
4523 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4524 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4526 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4527 "parameter(tethering) is NULL\n");
4529 GVariant *parameters;
4530 GError *error = NULL;
4533 __tethering_h *th = (__tethering_h *)tethering;
4535 GDBusProxy *proxy = th->client_bus_proxy;
4537 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
4538 g_variant_new("(b)", enable),
4539 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4541 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4543 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4544 result = TETHERING_ERROR_PERMISSION_DENIED;
4546 result = TETHERING_ERROR_OPERATION_FAILED;
4548 g_error_free(error);
4552 g_variant_get(parameters, "(u)", &result);
4553 g_variant_unref(parameters);
4555 th->port_filtering = true;
4557 return TETHERING_ERROR_NONE;
4560 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
4562 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4563 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4565 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4566 "parameter(tethering) is NULL\n");
4567 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4568 "parameter(protocol) is NULL\n");
4570 GVariant *parameters;
4571 GError *error = NULL;
4576 __tethering_h *th = (__tethering_h *)tethering;
4578 GDBusProxy *proxy = th->client_bus_proxy;
4580 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
4581 g_variant_new("(isb)", port, protocol, allow),
4582 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4584 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4586 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4587 result = TETHERING_ERROR_PERMISSION_DENIED;
4589 result = TETHERING_ERROR_OPERATION_FAILED;
4591 g_error_free(error);
4595 g_variant_get(parameters, "(u)", &result);
4596 g_variant_unref(parameters);
4599 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
4601 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
4603 if (ret == -1 || list == NULL) {
4604 ERR("asprintf failed\n");
4605 return TETHERING_ERROR_OUT_OF_MEMORY;
4608 DBG("cmd:%s", list);
4610 port_filtering = g_slist_append(port_filtering, list);
4612 return TETHERING_ERROR_NONE;
4615 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
4617 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4618 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4620 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4621 "parameter(tethering) is NULL\n");
4622 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4623 "parameter(protocol) is NULL\n");
4625 GVariant *parameters;
4626 GError *error = NULL;
4631 __tethering_h *th = (__tethering_h *)tethering;
4633 GDBusProxy *proxy = th->client_bus_proxy;
4635 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
4636 g_variant_new("(iisb)", port1, port2, protocol, allow),
4637 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4639 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4641 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4642 result = TETHERING_ERROR_PERMISSION_DENIED;
4644 result = TETHERING_ERROR_OPERATION_FAILED;
4646 g_error_free(error);
4650 g_variant_get(parameters, "(u)", &result);
4651 g_variant_unref(parameters);
4654 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
4656 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
4658 if (ret == -1 || list == NULL) {
4659 ERR("asprintf failed\n");
4660 return TETHERING_ERROR_OUT_OF_MEMORY;
4663 DBG("cmd:%s", list);
4665 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4667 return TETHERING_ERROR_NONE;
4670 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4672 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4673 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4675 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4676 "parameter(tethering) is NULL\n");
4677 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4678 "parameter(port_filtering_list) is NULL\n");
4680 *port_filtering_list = g_slist_copy(port_filtering);
4681 return TETHERING_ERROR_NONE;
4684 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4686 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4687 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4689 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4690 "parameter(tethering) is NULL\n");
4691 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4692 "parameter(custom_port_filtering_list) is NULL\n");
4694 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4695 return TETHERING_ERROR_NONE;
4698 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool *filtering_enabled)
4700 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4701 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4703 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4704 "parameter(tethering) is NULL\n");
4705 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4706 "parameter(filtering_enabled) is NULL\n");
4708 __tethering_h *th = (__tethering_h *)tethering;
4710 *filtering_enabled = th->port_filtering;
4712 return TETHERING_ERROR_NONE;
4715 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
4717 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4718 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4720 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4721 "parameter(tethering) is NULL\n");
4723 GVariant *parameters;
4724 GError *error = NULL;
4727 __tethering_h *th = (__tethering_h *)tethering;
4729 GDBusProxy *proxy = th->client_bus_proxy;
4731 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4732 g_variant_new("(ib)", type, enable),
4733 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4735 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4737 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4738 result = TETHERING_ERROR_PERMISSION_DENIED;
4740 result = TETHERING_ERROR_OPERATION_FAILED;
4742 g_error_free(error);
4746 g_variant_get(parameters, "(u)", &result);
4748 g_variant_unref(parameters);
4750 return TETHERING_ERROR_NONE;
4753 API int tethering_wifi_push_wps_button(tethering_h tethering)
4755 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4756 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4758 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4759 "parameter(tethering) is NULL");
4760 __tethering_h *th = (__tethering_h *)tethering;
4761 GDBusProxy *proxy = th->client_bus_proxy;
4762 GVariant *parameters = NULL;
4764 GError *error = NULL;
4766 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4767 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4770 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4772 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4773 ret = TETHERING_ERROR_PERMISSION_DENIED;
4775 ret = TETHERING_ERROR_OPERATION_FAILED;
4777 g_error_free(error);
4781 if (parameters != NULL) {
4782 g_variant_get(parameters, "(u)", &ret);
4783 g_variant_unref(parameters);
4786 return TETHERING_ERROR_NONE;
4789 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4791 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4792 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4794 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4795 "parameter(tethering) is NULL");
4796 _retvm_if(wps_pin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4797 "parameter(wps_pin) is NULL");
4799 __tethering_h *th = (__tethering_h *)tethering;
4800 GDBusProxy *proxy = th->client_bus_proxy;
4801 GVariant *parameters = NULL;
4803 GError *error = NULL;
4805 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4806 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4809 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4811 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4812 ret = TETHERING_ERROR_PERMISSION_DENIED;
4814 ret = TETHERING_ERROR_OPERATION_FAILED;
4816 g_error_free(error);
4820 if (parameters != NULL) {
4821 g_variant_get(parameters, "(u)", &ret);
4822 g_variant_unref(parameters);
4825 return TETHERING_ERROR_NONE;
4828 API int tethering_wifi_is_sharing_supported(tethering_h tethering, bool *supported)
4830 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4831 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4833 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4834 "parameter(tethering) is NULL\n");
4835 _retvm_if(supported == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4836 "parameter(supported) is NULL\n");
4838 /** Check if wifi-sharing is supported */
4839 __tethering_h *th = (__tethering_h *)tethering;
4840 GDBusProxy *proxy = th->client_bus_proxy;
4842 int ret = TETHERING_ERROR_NONE;
4845 GVariant *value = NULL;
4846 GVariantIter *iter = NULL;
4847 GVariantIter *sub_iter = NULL;
4848 GVariant *parameters = NULL;
4849 GError *error = NULL;
4851 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_interfaces",
4852 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4855 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4857 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4858 ret = TETHERING_ERROR_PERMISSION_DENIED;
4860 ret = TETHERING_ERROR_OPERATION_FAILED;
4862 g_error_free(error);
4866 g_variant_get(parameters, "(a(a{sv}))", &iter);
4868 g_variant_unref(parameters);
4869 ret = TETHERING_ERROR_OPERATION_FAILED;
4873 while (g_variant_iter_loop(iter, "(a{sv})", &sub_iter)) {
4874 while (g_variant_iter_loop(sub_iter, "{sv}", &key, &value)) {
4875 if (g_strcmp0(key, "IfName") == 0) {
4876 const gchar *interface = g_variant_get_string(value, NULL);
4877 ERR("interface: %s\n", interface);
4878 if (strncmp(interface, "wlan", 4) == 0)
4883 g_variant_unref(parameters);
4894 API int tethering_wifi_set_sharing(tethering_h tethering, bool sharing)
4896 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4897 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4899 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4900 "parameter(tethering) is NULL\n");
4902 __tethering_h *th = (__tethering_h *)tethering;
4903 th->wifi_sharing = sharing;
4905 return TETHERING_ERROR_NONE;
4908 API int tethering_wifi_get_sharing(tethering_h tethering, bool *sharing)
4910 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4911 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4913 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4914 "parameter(tethering) is NULL\n");
4915 _retvm_if(sharing == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4916 "parameter(sharing) is NULL\n");
4918 __tethering_h *th = (__tethering_h *)tethering;
4919 *sharing = th->wifi_sharing;
4921 return TETHERING_ERROR_NONE;