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;
147 static __thread tethering_request_table_t request_table[TETHERING_TYPE_MAX];
149 static void __reset_dualband_support(void)
151 is_dualband_support = DUAL_BAND_NONE;
154 static void __set_dualband_support(int band)
156 is_dualband_support |= band;
160 static gboolean __is_dualband_support(void)
162 return (is_dualband_support == DUAL_BAND_ALL) ? TRUE : FALSE;
164 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
166 if (conn == NULL || signal_name == NULL)
169 GVariant *message = NULL;
170 GError *error = NULL;
173 message = g_variant_new("(s)", arg);
175 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
176 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
178 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
183 static bool __any_tethering_is_enabled(tethering_h tethering)
185 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
186 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
187 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI_SHARING) ||
188 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
189 tethering_is_enabled(tethering, TETHERING_TYPE_P2P))
195 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
197 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
198 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
199 security_type != TETHERING_WIFI_SECURITY_TYPE_WPS &&
200 security_type != TETHERING_WIFI_SECURITY_TYPE_SAE) {
201 ERR("Invalid param\n");
202 return TETHERING_ERROR_INVALID_PARAMETER;
205 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
206 ERR("vconf_set_int is failed\n");
207 return TETHERING_ERROR_OPERATION_FAILED;
210 return TETHERING_ERROR_NONE;
213 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
215 if (security_type == NULL) {
216 ERR("Invalid param\n");
217 return TETHERING_ERROR_INVALID_PARAMETER;
220 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
221 (int *)security_type) < 0) {
222 ERR("vconf_get_int is failed\n");
223 return TETHERING_ERROR_OPERATION_FAILED;
226 return TETHERING_ERROR_NONE;
229 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
231 if (path == NULL || ssid == NULL || size == 0)
235 char *ptr_tmp = NULL;
237 ptr = vconf_get_str(path);
241 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 void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
364 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
365 GVariant *parameters, gpointer user_data)
369 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
371 __tethering_h *th = (__tethering_h *)user_data;
373 tethering_type_e type = 0;
374 mobile_ap_type_e ap_type = 0;
375 tethering_connection_state_changed_cb ccb = NULL;
376 __tethering_client_h client;
384 memset(&client, 0, sizeof(__tethering_client_h));
385 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
387 if (!g_strcmp0(buf, "DhcpConnected")) {
389 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
392 ERR("Unknown event [%s]\n", buf);
396 if (ap_type == MOBILE_AP_TYPE_USB)
397 type = TETHERING_TYPE_USB;
398 else if (ap_type == MOBILE_AP_TYPE_WIFI) {
399 if (request_table[TETHERING_TYPE_WIFI_SHARING].flag)
400 type = TETHERING_TYPE_WIFI_SHARING;
402 type = TETHERING_TYPE_WIFI;
403 } else if (ap_type == MOBILE_AP_TYPE_BT)
404 type = TETHERING_TYPE_BT;
405 else if (ap_type == MOBILE_AP_TYPE_P2P)
406 type = TETHERING_TYPE_P2P;
408 ERR("Not supported tethering type [%d]\n", ap_type);
412 SINFO("[%s] type %d, ip %s, mac %s, name %s, timestamp %d",
413 buf, ap_type, ip, mac, name, timestamp);
415 ccb = th->changed_cb[type];
418 data = th->changed_user_data[type];
420 client.interface = type;
421 g_strlcpy(client.ip, ip, sizeof(client.ip));
422 g_strlcpy(client.mac, mac, sizeof(client.mac));
424 client.hostname = g_strdup(name);
425 client.tm = (time_t)timestamp;
427 ccb((tethering_client_h)&client, opened, data);
428 g_free(client.hostname);
437 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
438 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
439 GVariant *parameters, gpointer user_data)
443 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
445 __tethering_h *th = (__tethering_h *)user_data;
446 tethering_type_e type = 0;
447 tethering_disabled_cb dcb = NULL;
449 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
451 SINFO("Tethering Disabled by network close !");
453 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
454 dcb = th->disabled_cb[type];
457 data = th->disabled_user_data[type];
459 dcb(TETHERING_ERROR_NONE, type, code, data);
465 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
466 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
467 GVariant *parameters, gpointer user_data)
471 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
473 __tethering_h *th = (__tethering_h *)user_data;
474 tethering_type_e type = TETHERING_TYPE_WIFI;
475 bool is_requested = false;
476 tethering_enabled_cb ecb = NULL;
479 ecb = th->enabled_cb[type];
482 data = th->enabled_user_data[type];
484 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
488 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
489 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
490 GVariant *parameters, gpointer user_data)
494 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
496 __tethering_h *th = (__tethering_h *)user_data;
497 tethering_type_e type = TETHERING_TYPE_WIFI;
498 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
499 tethering_disabled_cb dcb = NULL;
503 dcb = th->disabled_cb[type];
506 data = th->disabled_user_data[type];
507 g_variant_get(parameters, "(s)", &buf);
508 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
509 code = TETHERING_DISABLED_BY_WIFI_ON;
510 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
511 code = TETHERING_DISABLED_BY_TIMEOUT;
514 dcb(TETHERING_ERROR_NONE, type, code, data);
519 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
520 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
521 GVariant *parameters, gpointer user_data)
525 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
527 __tethering_h *th = (__tethering_h *)user_data;
528 tethering_type_e type = TETHERING_TYPE_USB;
529 bool is_requested = false;
530 tethering_enabled_cb ecb = NULL;
533 ecb = th->enabled_cb[type];
536 data = th->enabled_user_data[type];
538 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
542 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
543 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
544 GVariant *parameters, gpointer user_data)
548 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
550 __tethering_h *th = (__tethering_h *)user_data;
551 tethering_type_e type = TETHERING_TYPE_USB;
552 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
553 tethering_disabled_cb dcb = NULL;
557 dcb = th->disabled_cb[type];
560 data = th->disabled_user_data[type];
562 g_variant_get(parameters, "(s)", &buf);
563 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
564 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
566 dcb(TETHERING_ERROR_NONE, type, code, data);
571 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
572 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
573 GVariant *parameters, gpointer user_data)
577 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
579 __tethering_h *th = (__tethering_h *)user_data;
580 tethering_type_e type = TETHERING_TYPE_BT;
581 bool is_requested = false;
582 tethering_enabled_cb ecb = NULL;
585 ecb = th->enabled_cb[type];
588 data = th->enabled_user_data[type];
590 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
594 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
595 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
596 GVariant *parameters, gpointer user_data)
600 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
602 __tethering_h *th = (__tethering_h *)user_data;
603 tethering_type_e type = TETHERING_TYPE_BT;
604 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
605 tethering_disabled_cb dcb = NULL;
609 dcb = th->disabled_cb[type];
612 data = th->disabled_user_data[type];
613 g_variant_get(parameters, "(s)", &buf);
614 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
615 code = TETHERING_DISABLED_BY_BT_OFF;
616 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
617 code = TETHERING_DISABLED_BY_TIMEOUT;
619 dcb(TETHERING_ERROR_NONE, type, code, data);
625 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
626 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
627 GVariant *parameters, gpointer user_data)
631 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
633 __tethering_h *th = (__tethering_h *)user_data;
634 tethering_type_e type = 0;
635 tethering_disabled_cb dcb = NULL;
637 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
639 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
640 dcb = th->disabled_cb[type];
643 data = th->disabled_user_data[type];
645 dcb(TETHERING_ERROR_NONE, type, code, data);
650 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
651 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
652 GVariant *parameters, gpointer user_data)
656 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
658 __tethering_h *th = (__tethering_h *)user_data;
659 tethering_type_e type = 0;
660 tethering_disabled_cb dcb = NULL;
662 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
664 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
665 dcb = th->disabled_cb[type];
668 data = th->disabled_user_data[type];
670 dcb(TETHERING_ERROR_NONE, type, code, data);
675 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
676 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
677 GVariant *parameters, gpointer user_data)
681 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
683 __tethering_h *th = (__tethering_h *)user_data;
684 tethering_type_e type = 0;
685 tethering_disabled_cb dcb = NULL;
687 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
689 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
690 dcb = th->disabled_cb[type];
693 data = th->disabled_user_data[type];
695 dcb(TETHERING_ERROR_NONE, type, code, data);
700 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
701 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
702 GVariant *parameters, gpointer user_data)
707 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
708 __tethering_h *th = (__tethering_h *)user_data;
710 tethering_wifi_security_type_changed_cb scb = NULL;
712 tethering_wifi_security_type_e security_type;
715 scb = th->security_type_changed_cb;
719 g_variant_get(parameters, "(s)", &buf);
720 data = th->security_type_user_data;
721 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
722 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
723 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
724 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
725 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
726 security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
727 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_SAE_STR) == 0)
728 security_type = TETHERING_WIFI_SECURITY_TYPE_SAE;
730 SERR("Unknown type : %s\n", buf);
735 scb(security_type, data);
740 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
741 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
742 GVariant *parameters, gpointer user_data)
746 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
747 __tethering_h *th = (__tethering_h *)user_data;
749 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
751 bool visible = false;
754 scb = th->ssid_visibility_changed_cb;
759 g_variant_get(parameters, "(s)", &buf);
760 data = th->ssid_visibility_user_data;
761 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
769 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
770 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
771 GVariant *parameters, gpointer user_data)
775 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
776 __tethering_h *th = (__tethering_h *)user_data;
778 tethering_wifi_passphrase_changed_cb pcb = NULL;
781 pcb = th->passphrase_changed_cb;
785 data = th->passphrase_user_data;
791 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
796 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
797 GError *g_error = NULL;
800 tethering_type_e type = 0;
801 tethering_error_e error;
802 __tethering_h *th = (__tethering_h *)user_data;
804 if (request_table[TETHERING_TYPE_WIFI_SHARING].flag)
805 type = TETHERING_TYPE_WIFI_SHARING;
807 type = TETHERING_TYPE_WIFI;
809 tethering_enabled_cb ecb = th->enabled_cb[type];
810 void *data = th->enabled_user_data[type];
812 if (!_tethering_check_handle((tethering_h)user_data))
815 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
817 ERR("DBus error [%s]\n", g_error->message);
818 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
819 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
820 g_error_free(g_error);
821 tethering_enable((tethering_h)th, type);
823 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
824 error = TETHERING_ERROR_PERMISSION_DENIED;
826 error = TETHERING_ERROR_OPERATION_FAILED;
827 g_error_free(g_error);
829 g_variant_get(g_var, "(u)", &info);
830 error = __get_error(info);
834 INFO("cfm event : wifi tethering enable info : %d\n", error);
836 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
837 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
838 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
839 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
841 SINFO("Tethering enabled event ! error(%d)", error);
847 ecb(error, type, true, data);
848 g_variant_unref(g_var);
852 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
856 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
857 GError *g_error = NULL;
860 tethering_error_e error;
862 __tethering_h *th = (__tethering_h *)user_data;
863 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
864 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
866 if (!_tethering_check_handle((tethering_h)user_data))
869 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
871 ERR("DBus error [%s]\n", g_error->message);
872 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
873 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
874 g_error_free(g_error);
875 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
879 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
880 error = TETHERING_ERROR_PERMISSION_DENIED;
882 error = TETHERING_ERROR_OPERATION_FAILED;
883 g_error_free(g_error);
885 g_variant_get(g_var, "(u)", &info);
886 g_variant_unref(g_var);
887 error = __get_error(info);
891 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
892 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
893 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
894 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
901 ecb(error, TETHERING_TYPE_BT, true, data);
905 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
910 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
911 __tethering_h *th = (__tethering_h *)user_data;
912 GError *g_error = NULL;
915 tethering_error_e error;
916 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
917 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
919 if (!_tethering_check_handle((tethering_h)user_data))
922 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
924 ERR("DBus error [%s]\n", g_error->message);
925 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
926 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
927 g_error_free(g_error);
928 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
932 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
933 error = TETHERING_ERROR_PERMISSION_DENIED;
935 error = TETHERING_ERROR_OPERATION_FAILED;
936 g_error_free(g_error);
938 g_variant_get(g_var, "(u)", &info);
939 g_variant_unref(g_var);
940 error = __get_error(info);
944 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
945 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
946 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
947 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
954 ecb(error, TETHERING_TYPE_USB, true, data);
958 static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
963 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
964 __tethering_h *th = (__tethering_h *)user_data;
965 GError *g_error = NULL;
968 tethering_error_e error;
969 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_P2P];
970 void *data = th->enabled_user_data[TETHERING_TYPE_P2P];
972 if (!_tethering_check_handle((tethering_h)user_data))
975 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
977 ERR("DBus error [%s]\n", g_error->message);
978 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
979 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
980 g_error_free(g_error);
981 tethering_enable((tethering_h)th, TETHERING_TYPE_P2P);
985 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
986 error = TETHERING_ERROR_PERMISSION_DENIED;
988 error = TETHERING_ERROR_OPERATION_FAILED;
989 g_error_free(g_error);
991 g_variant_get(g_var, "(u)", &info);
992 g_variant_unref(g_var);
993 error = __get_error(info);
1002 ecb(error, TETHERING_TYPE_P2P, true, data);
1006 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
1011 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1012 GError *g_error = NULL;
1014 guint info, event_type;
1015 tethering_error_e error;
1016 tethering_type_e type;
1017 tethering_h tethering = (tethering_h)user_data;
1018 __tethering_h *th = (__tethering_h *)tethering;
1019 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
1020 tethering_disabled_cb dcb = NULL;
1023 if (!_tethering_check_handle((tethering_h)user_data))
1026 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1028 ERR("DBus error [%s]\n", g_error->message);
1029 g_error_free(g_error);
1032 g_variant_get(g_var, "(uu)", &event_type, &info);
1033 INFO("cfm event : %d info : %d\n", event_type, info);
1034 g_variant_unref(g_var);
1035 error = __get_error(info);
1036 INFO("cfm event : %d info : %d\n", event_type, error);
1037 switch (event_type) {
1038 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1039 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1040 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1041 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1042 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1044 type = TETHERING_TYPE_WIFI;
1045 dcb = th->disabled_cb[type];
1046 data = th->disabled_user_data[type];
1048 dcb(error, type, code, data);
1051 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1052 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1053 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1054 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1055 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1057 type = TETHERING_TYPE_BT;
1058 dcb = th->disabled_cb[type];
1059 data = th->disabled_user_data[type];
1061 dcb(error, type, code, data);
1064 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1065 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1066 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1067 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1068 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1070 type = TETHERING_TYPE_USB;
1071 dcb = th->disabled_cb[type];
1072 data = th->disabled_user_data[type];
1074 dcb(error, type, code, data);
1077 case MOBILE_AP_DISABLE_P2P_TETHERING_CFM:
1078 type = TETHERING_TYPE_P2P;
1079 dcb = th->disabled_cb[type];
1080 data = th->disabled_user_data[type];
1082 dcb(error, type, code, data);
1085 case MOBILE_AP_DISABLE_CFM:
1087 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1088 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1089 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1090 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1091 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1092 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1093 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1094 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1095 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1096 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1097 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1098 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1100 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1101 dcb = th->disabled_cb[type];
1104 data = th->disabled_user_data[type];
1106 dcb(error, type, code, data);
1111 ERR("Invalid event\n");
1117 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1122 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1124 GError *g_error = NULL;
1127 guint64 tx_bytes, rx_bytes;
1128 __tethering_h *th = (__tethering_h *)user_data;
1129 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1132 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1134 ERR("DBus fail [%s]\n", g_error->message);
1135 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1136 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1138 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1142 if (th->data_usage_cb == NULL) {
1143 ERR("There is no data_usage_cb\n");
1147 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1149 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1150 th->data_usage_cb(TETHERING_ERROR_NONE,
1151 rx_bytes, tx_bytes, th->data_usage_user_data);
1152 g_variant_unref(g_var);
1154 th->data_usage_cb = NULL;
1155 th->data_usage_user_data = NULL;
1160 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1165 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1166 GError *g_error = NULL;
1169 __tethering_h *th = (__tethering_h *)user_data;
1170 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1172 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1174 ERR("DBus fail [%s]\n", g_error->message);
1175 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1176 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1178 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1179 g_error_free(g_error);
1181 g_variant_get(g_var, "(u)", &info);
1182 if (tethering_error == TETHERING_ERROR_NONE)
1183 tethering_error = __get_error(info);
1184 g_variant_unref(g_var);
1187 if (th->settings_reloaded_cb == NULL) {
1188 DBG("There is no settings_reloaded_cb\n-\n");
1192 th->settings_reloaded_cb(tethering_error,
1193 th->settings_reloaded_user_data);
1195 th->settings_reloaded_cb = NULL;
1196 th->settings_reloaded_user_data = NULL;
1200 static void __connect_signals(tethering_h tethering)
1203 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1205 __tethering_h *th = (__tethering_h *)tethering;
1206 GDBusConnection *connection = th->client_bus;
1209 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1210 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1211 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1212 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1213 sigs[i].cb, tethering, NULL);
1218 static void __disconnect_signals(tethering_h tethering)
1222 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1224 __tethering_h *th = (__tethering_h *)tethering;
1225 GDBusConnection *connection = th->client_bus;
1229 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1230 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1236 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1238 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1241 case TETHERING_TYPE_USB:
1242 g_strlcpy(buf, TETHERING_USB_IF, len);
1244 case TETHERING_TYPE_WIFI:
1245 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1247 case TETHERING_TYPE_BT:
1248 g_strlcpy(buf, TETHERING_BT_IF, len);
1250 case TETHERING_TYPE_P2P:
1251 g_strlcpy(buf, TETHERING_P2P_IF, len);
1254 ERR("Not supported type : %d\n", type);
1260 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1262 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1265 case TETHERING_TYPE_USB:
1266 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1268 case TETHERING_TYPE_WIFI:
1269 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1271 case TETHERING_TYPE_BT:
1272 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1274 case TETHERING_TYPE_P2P:
1275 g_strlcpy(buf, TETHERING_P2P_GATEWAY, len);
1278 ERR("Not supported type : %d\n", type);
1284 static int __get_common_ssid(char *ssid, unsigned int size)
1287 ERR("ssid is null\n");
1288 return TETHERING_ERROR_INVALID_PARAMETER;
1292 if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID, ssid, size))
1293 return TETHERING_ERROR_NONE;
1295 ERR("vconf key get failed for ssid or invalid ssid is found");
1296 #endif /* TIZEN_TV_EXT */
1298 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
1299 ssid, size) == false) {
1300 ERR("vconf_get_str is failed and set default ssid");
1301 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1304 return TETHERING_ERROR_NONE;
1307 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1309 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1312 case TETHERING_WIFI_MODE_TYPE_B:
1313 *buf = g_strdup("b");
1315 case TETHERING_WIFI_MODE_TYPE_G:
1316 *buf = g_strdup("g");
1318 case TETHERING_WIFI_MODE_TYPE_A:
1319 *buf = g_strdup("a");
1321 case TETHERING_WIFI_MODE_TYPE_AD:
1322 *buf = g_strdup("ad");
1325 ERR("Not supported type : %d\n", type);
1331 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1335 __tethering_h *th = (__tethering_h *)tethering;
1336 tethering_error_e ret = TETHERING_ERROR_NONE;
1339 if (th == NULL || set == NULL) {
1340 ERR("null parameter\n-\n");
1341 return TETHERING_ERROR_INVALID_PARAMETER;
1344 if (th->ssid == NULL)
1345 __get_common_ssid(set->ssid, sizeof(set->ssid));
1347 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1349 ret = __get_security_type(&set->sec_type);
1350 if (ret != TETHERING_ERROR_NONE)
1351 set->sec_type = th->sec_type;
1353 ret = __get_visible(&set->visibility);
1354 if (ret != TETHERING_ERROR_NONE)
1355 set->visibility = th->visibility;
1357 set->mac_filter = th->mac_filter;
1358 set->max_connected = th->wifi_max_connected;
1359 set->channel = th->channel;
1360 set->txpower = th->txpower;
1362 __get_wifi_mode_type(th->mode_type, &ptr);
1364 g_strlcpy(set->mode, "", sizeof(set->mode));
1366 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1370 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1371 g_strlcpy(set->key, "", sizeof(set->key));
1373 GDBusProxy *proxy = th->client_bus_proxy;
1374 GVariant *parameters;
1375 GError *error = NULL;
1376 char *passphrase = NULL;
1377 unsigned int len = 0;
1379 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1380 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1383 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1385 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1386 ret = TETHERING_ERROR_PERMISSION_DENIED;
1388 ret = TETHERING_ERROR_OPERATION_FAILED;
1390 g_error_free(error);
1394 if (parameters != NULL) {
1395 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1396 g_strlcpy(set->key, passphrase, sizeof(set->key) - 1);
1398 g_variant_unref(parameters);
1402 INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
1403 set->ssid, set->sec_type, set->mode, set->channel,
1404 (set->visibility) ? "true" : "false");
1406 return TETHERING_ERROR_NONE;
1409 static bool __check_precondition(tethering_type_e type)
1411 int dnet_status = 0;
1412 int cellular_state = 0;
1414 /* data network through cellular */
1415 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1416 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1417 INFO("Data Network can be connected later");
1421 /* data network status */
1422 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
1423 if ((dnet_status == VCONFKEY_NETWORK_WIFI
1424 && type != TETHERING_TYPE_WIFI)
1425 || (dnet_status == VCONFKEY_NETWORK_ETHERNET
1426 && type != TETHERING_TYPE_WIFI_SHARING))
1429 ERR("Network is not available!");
1434 static void __set_vconf_values_for_tv(__tethering_h *tethering)
1436 int ret, channel, txpower;
1437 __tethering_h *th = tethering;
1442 ret = vconf_get_int(VCONFKEY_WIFI_CHANNEL, &channel);
1444 ERR("vconf key get failed for channel !!");
1445 channel = TETHERING_WIFI_CHANNEL;
1448 ret = vconf_get_int(VCONFKEY_WIFI_TXPOWER, &txpower);
1450 ERR("vconf key get failed for txpower !!");
1451 txpower = TETHERING_WIFI_MAX_TXPOWER;
1454 th->channel = channel;
1455 th->txpower = txpower;
1457 #endif /* TIZEN_TV_EXT */
1461 * @brief Creates the handle of tethering.
1463 * @privlevel platform
1464 * @privilege http://tizen.org/privilege/tethering.admin
1465 * @remarks The @a tethering must be released tethering_destroy() by you.
1466 * @param[out] tethering A handle of a new mobile ap handle on success
1467 * @return 0 on success, otherwise a negative error value.
1468 * @retval #TETHERING_ERROR_NONE Successful
1469 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1470 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1471 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1472 * @see tethering_destroy()
1474 API int tethering_create(tethering_h *tethering)
1476 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1477 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1478 "parameter(tethering) is NULL\n");
1481 __tethering_h *th = NULL;
1482 GError *error = NULL;
1483 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1485 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1487 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1488 "malloc is failed\n");
1489 memset(th, 0x00, sizeof(__tethering_h));
1490 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1491 th->visibility = true;
1492 th->mac_filter = false;
1493 th->channel = TETHERING_WIFI_CHANNEL;
1494 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1495 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1496 th->txpower = TETHERING_WIFI_MAX_TXPOWER;
1498 if (__generate_initial_passphrase(th->passphrase,
1499 sizeof(th->passphrase)) == 0) {
1500 ERR("random passphrase generation failed\n");
1502 return TETHERING_ERROR_OPERATION_FAILED;
1505 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1506 ERR("common ssid get failed\n");
1508 return TETHERING_ERROR_OPERATION_FAILED;
1512 __set_vconf_values_for_tv(th);
1513 #endif /* TIZEN_TV_EXT */
1514 SINFO("ssid: %s, key: %s, channel: %d, mode: %d, txpower: %d, security: %d max_device: %d\n",
1515 ssid, th->passphrase, th->channel, th->mode_type, th->txpower, th->sec_type,
1516 th->wifi_max_connected);
1518 #if !GLIB_CHECK_VERSION(2, 36, 0)
1521 GCancellable *cancellable = g_cancellable_new();
1522 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1524 ERR("Couldn't connect to the System bus[%s]", error->message);
1525 g_error_free(error);
1526 g_cancellable_cancel(cancellable);
1527 g_object_unref(cancellable);
1529 return TETHERING_ERROR_OPERATION_FAILED;
1531 th->cancellable = cancellable;
1533 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1534 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1535 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1536 if (!th->client_bus_proxy) {
1538 ERR("Couldn't create the proxy object because of %s\n", error->message);
1539 g_cancellable_cancel(th->cancellable);
1540 g_object_unref(th->cancellable);
1541 g_object_unref(th->client_bus);
1543 return TETHERING_ERROR_OPERATION_FAILED;
1546 __connect_signals((tethering_h)th);
1548 *tethering = (tethering_h)th;
1549 _tethering_add_handle(th);
1550 INFO("Tethering Handle : %p\n", th);
1552 return TETHERING_ERROR_NONE;
1557 * @brief Destroys the handle of tethering.
1559 * @privlevel platform
1560 * @privilege http://tizen.org/privilege/tethering.admin
1561 * @param[in] tethering The handle of tethering
1562 * @return 0 on success, otherwise a negative error value.
1563 * @retval #TETHERING_ERROR_NONE Successful
1564 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1565 * @see tethering_create()
1567 API int tethering_destroy(tethering_h tethering)
1570 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1571 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1572 "parameter(tethering) is NULL\n");
1574 __tethering_h *th = (__tethering_h *)tethering;
1576 INFO("Tethering Handle : %p\n", th);
1578 __disconnect_signals(tethering);
1579 _tethering_remove_handle(th);
1584 g_object_unref(th->cancellable);
1585 g_object_unref(th->client_bus_proxy);
1586 g_object_unref(th->client_bus);
1587 memset(th, 0x00, sizeof(__tethering_h));
1592 return TETHERING_ERROR_NONE;
1597 * @brief Enables the tethering, asynchronously.
1599 * @privlevel platform
1600 * @privilege http://tizen.org/privilege/tethering.admin
1601 * @param[in] tethering The handle of tethering
1602 * @param[in] type The type of tethering
1603 * @return 0 on success, otherwise negative error value.
1604 * @retval #TETHERING_ERROR_NONE Successful
1605 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1606 * @post tethering_enabled_cb() will be invoked.
1607 * @see tethering_is_enabled()
1608 * @see tethering_disable()
1610 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1612 INFO("+ type : %d\n", type);
1613 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1614 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1615 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
1616 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1617 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1619 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1620 "parameter(tethering) is NULL\n");
1622 tethering_error_e ret = TETHERING_ERROR_NONE;
1623 __tethering_h *th = (__tethering_h *)tethering;
1624 GDBusProxy *proxy = th->client_bus_proxy;
1625 GDBusConnection *connection = th->client_bus;
1628 g_dbus_proxy_set_default_timeout(proxy, DBUS_DEFAULT_REPLY_TIMEOUT);
1629 #else /* TIZEN_TV_EXT */
1630 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1631 #endif /* TIZEN_TV_EXT */
1633 if (__check_precondition(type) == FALSE) {
1635 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1636 return TETHERING_ERROR_OPERATION_FAILED;
1640 case TETHERING_TYPE_USB:
1641 g_dbus_connection_signal_unsubscribe(connection,
1642 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1644 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1645 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1646 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1647 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1650 case TETHERING_TYPE_WIFI:
1651 case TETHERING_TYPE_WIFI_SHARING: {
1652 _softap_settings_t set = {"", "", "", 0, false};
1654 ret = __prepare_wifi_settings(tethering, &set);
1655 if (ret != TETHERING_ERROR_NONE) {
1656 ERR("softap settings initialization failed\n");
1658 return TETHERING_ERROR_OPERATION_FAILED;
1660 g_dbus_connection_signal_unsubscribe(connection,
1661 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1663 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
1664 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
1667 char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
1668 if (type == TETHERING_TYPE_WIFI_SHARING) {
1669 g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN);
1670 request_table[TETHERING_TYPE_WIFI_SHARING].flag = true;
1672 g_strlcpy(key, "wifi_tether", TETHERING_WIFI_KEY_MAX_LEN);
1673 request_table[TETHERING_TYPE_WIFI].flag = true;
1676 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1677 g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
1678 set.channel, set.visibility, set.mac_filter, set.max_connected,
1679 set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
1680 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1681 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1685 case TETHERING_TYPE_BT:
1686 g_dbus_connection_signal_unsubscribe(connection,
1687 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1689 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1690 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1691 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1692 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1696 case TETHERING_TYPE_P2P: {
1697 _softap_settings_t p2p_set = {"", "", "", 0, false};
1698 ret = __prepare_wifi_settings(tethering, &p2p_set);
1699 if (ret != TETHERING_ERROR_NONE) {
1700 ERR("p2p settings initialization failed\n");
1701 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1703 return TETHERING_ERROR_OPERATION_FAILED;
1706 g_dbus_proxy_call(proxy, "enable_p2p_tethering",
1707 g_variant_new("(ssi)", p2p_set.ssid, p2p_set.key, p2p_set.channel),
1708 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1709 (GAsyncReadyCallback) __p2p_enabled_cfm_cb, (gpointer)tethering);
1713 case TETHERING_TYPE_ALL: {
1714 _softap_settings_t set = {"", "", "", 0, false};
1716 ret = __prepare_wifi_settings(tethering, &set);
1717 if (ret != TETHERING_ERROR_NONE) {
1718 ERR("softap settings initialization failed\n");
1719 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1720 return TETHERING_ERROR_OPERATION_FAILED;
1723 /* TETHERING_TYPE_USB */
1724 g_dbus_connection_signal_unsubscribe(connection,
1725 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1727 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1728 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1729 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1730 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1732 /* TETHERING_TYPE_WIFI */
1733 g_dbus_connection_signal_unsubscribe(connection,
1734 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1736 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1737 g_variant_new("(ssssiiiiiii)", "wifi_tether", set.ssid, set.key, set.mode,
1738 set.channel, set.visibility, set.mac_filter, set.max_connected,
1739 set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
1740 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1741 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1743 /* TETHERING_TYPE_BT */
1744 g_dbus_connection_signal_unsubscribe(connection,
1745 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1747 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1748 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1749 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1750 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1754 ERR("Unknown type : %d\n", type);
1756 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1759 return TETHERING_ERROR_INVALID_PARAMETER;
1762 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1764 return TETHERING_ERROR_NONE;
1767 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1769 DBG("+ type : %d\n", type);
1770 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1771 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1772 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1773 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1775 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1776 "parameter(tethering) is NULL\n");
1778 __tethering_h *th = (__tethering_h *)tethering;
1779 GDBusProxy *proxy = th->client_bus_proxy;
1780 GDBusConnection *connection = th->client_bus;
1783 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1785 if (__check_precondition(type) == FALSE) {
1787 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1788 return TETHERING_ERROR_OPERATION_FAILED;
1792 case TETHERING_TYPE_USB: {
1793 g_dbus_connection_signal_unsubscribe(connection,
1794 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1796 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1797 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1798 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1799 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1803 case TETHERING_TYPE_WIFI:
1804 case TETHERING_TYPE_WIFI_SHARING: {
1805 _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
1807 ret = __prepare_wifi_settings(tethering, &set);
1808 if (ret != TETHERING_ERROR_NONE) {
1809 ERR("softap settings initialization failed\n");
1811 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1812 return TETHERING_ERROR_OPERATION_FAILED;
1814 g_dbus_connection_signal_unsubscribe(connection,
1815 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1817 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
1818 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
1821 char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
1822 if (type == TETHERING_TYPE_WIFI_SHARING) {
1823 g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN);
1824 request_table[TETHERING_TYPE_WIFI_SHARING].flag = true;
1826 g_strlcpy(key, "wifi_tether", TETHERING_WIFI_KEY_MAX_LEN);
1827 request_table[TETHERING_TYPE_WIFI].flag = true;
1830 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1831 g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
1832 set.channel, set.visibility, set.mac_filter, set.max_connected,
1833 set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV6),
1834 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1835 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1839 case TETHERING_TYPE_BT: {
1840 g_dbus_connection_signal_unsubscribe(connection,
1841 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1843 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1844 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1845 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1846 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1852 ERR("Unknown type : %d\n", type);
1854 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1857 return TETHERING_ERROR_INVALID_PARAMETER;
1861 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1863 return TETHERING_ERROR_NONE;
1866 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
1868 DBG("+ type : %d\n", type);
1869 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1870 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1871 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1872 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1874 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1875 "parameter(tethering) is NULL\n");
1877 __tethering_h *th = (__tethering_h *)tethering;
1878 GDBusProxy *proxy = th->client_bus_proxy;
1879 GDBusConnection *connection = th->client_bus;
1882 case TETHERING_TYPE_USB:
1883 g_dbus_connection_signal_unsubscribe(connection,
1884 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1886 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1887 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1888 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1889 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1892 case TETHERING_TYPE_WIFI:
1893 case TETHERING_TYPE_WIFI_SHARING:
1894 DBG("Disable wifi tethering..");
1895 g_dbus_connection_signal_unsubscribe(connection,
1896 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1898 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1899 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1900 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1901 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1904 case TETHERING_TYPE_BT:
1905 g_dbus_connection_signal_unsubscribe(connection,
1906 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1908 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1909 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1910 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1911 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1915 ERR("Not supported tethering type [%d]\n", type);
1917 return TETHERING_ERROR_INVALID_PARAMETER;
1920 return TETHERING_ERROR_NONE;
1924 * @brief Disables the tethering, asynchronously.
1926 * @privlevel platform
1927 * @privilege http://tizen.org/privilege/tethering.admin
1928 * @param[in] tethering The handle of tethering
1929 * @param[in] type The type of tethering
1930 * @return 0 on success, otherwise negative error value.
1931 * @retval #TETHERING_ERROR_NONE Successful
1932 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1933 * @post tethering_disabled_cb() will be invoked.
1934 * @see tethering_is_enabled()
1935 * @see tethering_enable()
1937 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1939 INFO("+ type : %d\n", type);
1940 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1941 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1942 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1943 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1945 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1946 "parameter(tethering) is NULL\n");
1948 __tethering_h *th = (__tethering_h *)tethering;
1949 GDBusProxy *proxy = th->client_bus_proxy;
1950 GDBusConnection *connection = th->client_bus;
1953 case TETHERING_TYPE_USB:
1954 g_dbus_connection_signal_unsubscribe(connection,
1955 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1957 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1958 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1959 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1960 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1964 case TETHERING_TYPE_WIFI:
1965 case TETHERING_TYPE_WIFI_SHARING:
1967 g_dbus_connection_signal_unsubscribe(connection,
1968 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1970 SINFO("Disable Wi-Fi Tethering !");
1972 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1973 g_variant_new("(ii)", TETHERING_ADDRESS_FAMILY_IPV4, th->mode_type),
1974 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1975 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1978 case TETHERING_TYPE_BT:
1980 g_dbus_connection_signal_unsubscribe(connection,
1981 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1983 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1984 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1985 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1986 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1989 case TETHERING_TYPE_P2P:
1990 g_dbus_proxy_call(proxy, "disable_p2p_tethering",
1991 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1992 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1995 case TETHERING_TYPE_ALL:
1996 g_dbus_connection_signal_unsubscribe(connection,
1997 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1999 g_dbus_proxy_call(proxy, "disable_usb_tethering",
2000 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2001 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2002 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2004 g_dbus_connection_signal_unsubscribe(connection,
2005 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
2007 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
2008 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2009 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2010 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2012 g_dbus_connection_signal_unsubscribe(connection,
2013 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
2015 g_dbus_proxy_call(proxy, "disable_bt_tethering",
2016 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
2017 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2018 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
2022 ERR("Not supported tethering type [%d]\n", type);
2024 return TETHERING_ERROR_INVALID_PARAMETER;
2027 return TETHERING_ERROR_NONE;
2032 * @brief Checks whetehr the tethering is enabled or not.
2034 * @privlevel platform
2035 * @privilege http://tizen.org/privilege/tethering.admin
2036 * @param[in] tethering The handle of tethering
2037 * @param[in] type The type of tethering
2038 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
2040 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
2042 INFO("+ type : %d\n", type);
2044 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
2046 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2048 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
2052 case TETHERING_TYPE_USB:
2053 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
2056 case TETHERING_TYPE_WIFI:
2057 case TETHERING_TYPE_WIFI_SHARING:
2058 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
2061 case TETHERING_TYPE_BT:
2062 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
2065 case TETHERING_TYPE_P2P:
2066 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_P2P;
2070 ERR("Not supported type : %d\n", type);
2073 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
2074 return is_on & vconf_type ? true : false;
2079 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
2081 * @privlevel platform
2082 * @privilege http://tizen.org/privilege/tethering.admin
2083 * @remarks @a mac_address must be released with free() by you.
2084 * @param[in] tethering The handle of tethering
2085 * @param[in] type The type of tethering
2086 * @param[out] mac_address The MAC address
2087 * @return 0 on success, otherwise a negative error value.
2088 * @retval #TETHERING_ERROR_NONE Successful
2089 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2090 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2091 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2092 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2093 * @pre tethering must be enabled.
2094 * @see tethering_is_enabled()
2095 * @see tethering_enable()
2097 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
2099 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2100 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2101 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2102 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2104 _retvm_if(tethering_is_enabled(tethering, type) == false,
2105 TETHERING_ERROR_NOT_ENABLED,
2106 "tethering type[%d] is not enabled\n", type);
2107 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2108 "parameter(tethering) is NULL\n");
2109 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2110 "parameter(mac_address) is NULL\n");
2114 char *macbuf = NULL;
2116 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2117 TETHERING_ERROR_OPERATION_FAILED,
2118 "getting interface name is failed\n");
2120 s = socket(AF_INET, SOCK_DGRAM, 0);
2121 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2122 "getting socket is failed\n");
2123 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2124 ERR("getting mac is failed\n");
2126 return TETHERING_ERROR_OPERATION_FAILED;
2130 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
2131 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2132 "Not enough memory\n");
2133 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
2134 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
2135 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
2136 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
2137 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
2138 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
2139 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
2141 *mac_address = macbuf;
2143 return TETHERING_ERROR_NONE;
2148 * @brief Gets the name of network interface. For example, usb0.
2150 * @privlevel platform
2151 * @privilege http://tizen.org/privilege/tethering.admin
2152 * @remarks @a interface_name must be released with free() by you.
2153 * @param[in] tethering The handle of tethering
2154 * @param[in] type The type of tethering
2155 * @param[out] interface_name The name of network interface
2156 * @return 0 on success, otherwise negative error value.
2157 * @retval #TETHERING_ERROR_NONE Successful
2158 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2159 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2160 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2161 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2162 * @pre tethering must be enabled.
2163 * @see tethering_is_enabled()
2164 * @see tethering_enable()
2166 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
2168 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2169 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2170 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2171 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2173 _retvm_if(tethering_is_enabled(tethering, type) == false,
2174 TETHERING_ERROR_NOT_ENABLED,
2175 "tethering type[%d] is not enabled\n", type);
2176 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2177 "parameter(tethering) is NULL\n");
2178 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2179 "parameter(interface_name) is NULL\n");
2181 char intf[TETHERING_STR_INFO_LEN] = {0, };
2183 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2184 TETHERING_ERROR_OPERATION_FAILED,
2185 "getting interface name is failed\n");
2186 *interface_name = strdup(intf);
2187 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2188 "Not enough memory\n");
2190 return TETHERING_ERROR_NONE;
2195 * @brief Gets the local IP address.
2197 * @privlevel platform
2198 * @privilege http://tizen.org/privilege/tethering.admin
2199 * @remarks @a ip_address must be released with free() by you.
2200 * @param[in] tethering The handle of tethering
2201 * @param[in] type The type of tethering
2202 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2203 * @param[out] ip_address The local IP address
2204 * @return 0 on success, otherwise negative error value.
2205 * @retval #TETHERING_ERROR_NONE Successful
2206 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2207 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2208 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2209 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2210 * @pre tethering must be enabled.
2211 * @see tethering_is_enabled()
2212 * @see tethering_enable()
2214 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2216 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2217 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2218 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2219 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2221 _retvm_if(tethering_is_enabled(tethering, type) == false,
2222 TETHERING_ERROR_NOT_ENABLED,
2223 "tethering type[%d] is not enabled\n", type);
2224 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2225 "parameter(tethering) is NULL\n");
2226 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2227 "parameter(ip_address) is NULL\n");
2233 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2234 TETHERING_ERROR_OPERATION_FAILED,
2235 "getting interface name is failed\n");
2237 s = socket(AF_INET, SOCK_DGRAM, 0);
2238 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2239 "getting socket is failed\n");
2240 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2241 ERR("ioctl is failed\n");
2243 return TETHERING_ERROR_OPERATION_FAILED;
2247 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2248 *ip_address = strdup(ipbuf);
2249 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2250 "Not enough memory\n");
2252 return TETHERING_ERROR_NONE;
2257 * @brief Gets the Gateway address.
2259 * @privlevel platform
2260 * @privilege http://tizen.org/privilege/tethering.admin
2261 * @remarks @a gateway_address must be released with free() by you.
2262 * @param[in] tethering The handle of tethering
2263 * @param[in] type The type of tethering
2264 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2265 * @param[out] gateway_address The local IP address
2266 * @return 0 on success, otherwise negative error value.
2267 * @retval #TETHERING_ERROR_NONE Successful
2268 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2269 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2270 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2271 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2272 * @pre tethering must be enabled.
2273 * @see tethering_is_enabled()
2274 * @see tethering_enable()
2276 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2278 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2279 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2280 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2281 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2283 _retvm_if(tethering_is_enabled(tethering, type) == false,
2284 TETHERING_ERROR_NOT_ENABLED,
2285 "tethering type[%d] is not enabled\n", type);
2286 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2287 "parameter(tethering) is NULL\n");
2288 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2289 "parameter(gateway_address) is NULL\n");
2291 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2293 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2294 TETHERING_ERROR_OPERATION_FAILED,
2295 "getting gateway address is failed\n");
2297 *gateway_address = strdup(gateway_buf);
2299 return TETHERING_ERROR_NONE;
2304 * @brief Gets the Subnet Mask.
2306 * @privlevel platform
2307 * @privilege http://tizen.org/privilege/tethering.admin
2308 * @remarks @a subnet_mask must be released with free() by you.
2309 * @param[in] tethering The handle of tethering
2310 * @param[in] type The type of tethering
2311 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2312 * @param[out] subnet_mask The local IP address
2313 * @return 0 on success, otherwise negative error value.
2314 * @retval #TETHERING_ERROR_NONE Successful
2315 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2316 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2317 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2318 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2319 * @pre tethering must be enabled.
2320 * @see tethering_is_enabled()
2321 * @see tethering_enable()
2323 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2325 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2326 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2327 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2328 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2330 _retvm_if(tethering_is_enabled(tethering, type) == false,
2331 TETHERING_ERROR_NOT_ENABLED,
2332 "tethering is not enabled\n");
2333 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2334 "parameter(tethering) is NULL\n");
2335 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2336 "parameter(subnet_mask) is NULL\n");
2338 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2339 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2340 "Not enough memory\n");
2342 return TETHERING_ERROR_NONE;
2347 * @brief Gets the data usage.
2349 * @privlevel platform
2350 * @privilege http://tizen.org/privilege/tethering.admin
2351 * @param[in] tethering The handle of tethering
2352 * @param[out] usage The data usage
2353 * @return 0 on success, otherwise negative error value.
2354 * @retval #TETHERING_ERROR_NONE Successful
2355 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2356 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2357 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2358 * @pre tethering must be enabled.
2359 * @see tethering_is_enabled()
2360 * @see tethering_enable()
2362 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2364 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2366 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2367 "parameter(tethering) is NULL\n");
2368 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2369 "parameter(callback) is NULL\n");
2370 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2371 TETHERING_ERROR_NOT_ENABLED,
2372 "tethering is not enabled\n");
2374 __tethering_h *th = (__tethering_h *)tethering;
2375 GDBusProxy *proxy = th->client_bus_proxy;
2377 th->data_usage_cb = callback;
2378 th->data_usage_user_data = user_data;
2380 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2381 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2382 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2384 return TETHERING_ERROR_NONE;
2389 * @brief Gets the client which is connected by tethering "type".
2391 * @privlevel platform
2392 * @privilege http://tizen.org/privilege/tethering.admin
2393 * @param[in] tethering The handle of tethering
2394 * @param[in] type The type of tethering
2395 * @param[in] callback The callback function to invoke
2396 * @param[in] user_data The user data to be passed to the callback function
2397 * @retval #TETHERING_ERROR_NONE Successful
2398 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2399 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2400 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2401 * @pre tethering must be enabled.
2402 * @see tethering_is_enabled()
2403 * @see tethering_enable()
2406 API int tethering_is_dualband_supported(tethering_h tethering, tethering_type_e type, bool *supported)
2408 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2409 if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2410 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2412 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2413 "parameter(tethering) is NULL\n");
2415 __tethering_h *th = (__tethering_h *)tethering;
2416 gchar *if_name = NULL;
2417 gboolean Is2GBandSupported = FALSE;
2418 gboolean Is5GBandSupported = FALSE;
2419 GError *error = NULL;
2420 GVariant *result = NULL;
2421 GVariantIter *outer_iter = NULL;
2422 GVariantIter *inner_iter = NULL;
2423 GVariant *station = NULL;
2424 GVariant *value = NULL;
2429 __reset_dualband_support();
2430 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_wifi_interfaces",
2431 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2434 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2435 g_error_free(error);
2436 return TETHERING_ERROR_OPERATION_FAILED;
2438 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2439 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2440 g_variant_get(station, "a{sv}", &inner_iter);
2441 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2442 if (g_strcmp0(key, "IfName") == 0) {
2443 g_variant_get(value, "s", &if_name);
2444 SDBG("Interface Name is %s\n", if_name);
2445 } else if (g_strcmp0(key, "Is2GBandSupported") == 0) {
2446 Is2GBandSupported = g_variant_get_boolean(value);
2447 SDBG("Is2GBandSupported is %d\n", Is2GBandSupported);
2448 if (Is2GBandSupported)
2449 __set_dualband_support(DUAL_BAND_2G);
2450 } else if (g_strcmp0(key, "Is5GBandSupported") == 0) {
2451 Is5GBandSupported = g_variant_get_boolean(value);
2452 SDBG("Is5GBandSupported is %d\n", Is5GBandSupported);
2453 if (Is5GBandSupported)
2454 __set_dualband_support(DUAL_BAND_5G);
2456 ERR("Key %s not required\n", key);
2461 g_variant_iter_free(inner_iter);
2464 __set_dualband_support(DUAL_BAND_MIN_INTERFACE);
2465 *supported = __is_dualband_support();
2466 DBG("count:%d is dualband suppport: %d", count, *supported);
2467 g_variant_iter_free(outer_iter);
2468 g_variant_unref(result);
2470 return TETHERING_ERROR_NONE;
2472 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2474 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2475 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2476 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2477 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2478 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2480 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2481 "parameter(tethering) is NULL\n");
2482 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2483 "parameter(callback) is NULL\n");
2484 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2485 TETHERING_ERROR_NOT_ENABLED,
2486 "tethering is not enabled\n");
2488 mobile_ap_type_e interface;
2489 tethering_band_e band;
2490 __tethering_h *th = (__tethering_h *)tethering;
2491 __tethering_client_h client = {0, };
2494 gchar *hostname = NULL;
2495 guint timestamp = 0;
2496 GError *error = NULL;
2497 GVariant *result = NULL;
2498 GVariantIter *outer_iter = NULL;
2499 GVariantIter *inner_iter = NULL;
2500 GVariant *station = NULL;
2501 GVariant *value = NULL;
2504 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2505 NULL, G_DBUS_CALL_FLAGS_NONE,
2506 -1, th->cancellable, &error);
2509 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2510 g_error_free(error);
2511 return TETHERING_ERROR_OPERATION_FAILED;
2514 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2515 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2516 g_variant_get(station, "a{sv}", &inner_iter);
2517 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2518 if (g_strcmp0(key, "Type") == 0) {
2519 interface = g_variant_get_int32(value);
2520 if (interface == MOBILE_AP_TYPE_USB)
2521 client.interface = TETHERING_TYPE_USB;
2522 else if (interface == MOBILE_AP_TYPE_WIFI) {
2523 if (request_table[TETHERING_TYPE_WIFI_SHARING].flag)
2524 client.interface = TETHERING_TYPE_WIFI_SHARING;
2526 client.interface = TETHERING_TYPE_WIFI;
2528 } else if (interface == MOBILE_AP_TYPE_BT)
2529 client.interface = TETHERING_TYPE_BT;
2530 else if (interface == MOBILE_AP_TYPE_P2P)
2531 client.interface = TETHERING_TYPE_P2P;
2533 ERR("Invalid interface\n");
2535 g_variant_unref(value);
2538 DBG("interface is %d\n", client.interface);
2539 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2541 g_variant_unref(value);
2544 } else if (g_strcmp0(key, "IP") == 0) {
2545 g_variant_get(value, "s", &ip);
2546 SDBG("ip is %s\n", ip);
2547 g_strlcpy(client.ip, ip, sizeof(client.ip));
2548 } else if (g_strcmp0(key, "MAC") == 0) {
2549 g_variant_get(value, "s", &mac);
2550 SDBG("mac is %s\n", mac);
2551 g_strlcpy(client.mac, mac, sizeof(client.mac));
2552 } else if (g_strcmp0(key, "Name") == 0) {
2553 g_variant_get(value, "s", &hostname);
2554 SDBG("hsotname is %s\n", hostname);
2556 client.hostname = g_strdup(hostname);
2557 } else if (g_strcmp0(key, "Time") == 0) {
2558 timestamp = g_variant_get_int32(value);
2559 DBG("timestamp is %d\n", timestamp);
2560 client.tm = (time_t)timestamp;
2561 } else if (g_strcmp0(key, "Band") == 0) {
2562 band = g_variant_get_int32(value);
2563 client.band = (!band) ? TETHERING_WIFI_BAND_2G : TETHERING_WIFI_BAND_5G;
2564 SDBG("band type %d\n", band);
2566 ERR("Key %s not required\n", key);
2577 g_variant_iter_free(inner_iter);
2578 if ((th->mode_type == 0 || th->mode_type == 1) && client.band != TETHERING_WIFI_BAND_2G) //if band is not for 2g continue
2580 if ((th->mode_type == 2 || th->mode_type == 3) && client.band != TETHERING_WIFI_BAND_5G) //if band is not for 5g continue
2582 SDBG("mode_type: %d and client.band: %d ", th->mode_type, client.band);
2583 if (callback((tethering_client_h)&client, user_data) == false) {
2584 DBG("iteration is stopped\n");
2585 g_free(client.hostname);
2586 client.hostname = NULL;
2587 g_variant_iter_free(outer_iter);
2588 g_variant_unref(result);
2590 return TETHERING_ERROR_OPERATION_FAILED;
2592 g_free(client.hostname);
2593 client.hostname = NULL;
2595 g_variant_iter_free(outer_iter);
2596 g_variant_unref(result);
2598 return TETHERING_ERROR_NONE;
2603 * @brief Registers the callback function called when tethering is enabled.
2605 * @privlevel platform
2606 * @privilege http://tizen.org/privilege/tethering.admin
2607 * @param[in] tethering The handle of tethering
2608 * @param[in] type The type of tethering
2609 * @param[in] callback The callback function to invoke
2610 * @param[in] user_data The user data to be passed to the callback function
2611 * @retval #TETHERING_ERROR_NONE Successful
2612 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2613 * @see tethering_unset_enabled_cb()
2615 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2617 INFO("+ type: %d\n", type);
2618 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2619 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2620 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2621 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2622 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2624 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2625 "parameter(tethering) is NULL\n");
2626 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2627 "parameter(callback) is NULL\n");
2629 __tethering_h *th = (__tethering_h *)tethering;
2630 tethering_type_e ti;
2632 if (type != TETHERING_TYPE_ALL) {
2633 th->enabled_cb[type] = callback;
2634 th->enabled_user_data[type] = user_data;
2636 return TETHERING_ERROR_NONE;
2639 /* TETHERING_TYPE_ALL */
2640 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2641 th->enabled_cb[ti] = callback;
2642 th->enabled_user_data[ti] = user_data;
2646 return TETHERING_ERROR_NONE;
2651 * @brief Unregisters the callback function called when tethering is disabled.
2653 * @privlevel platform
2654 * @privilege http://tizen.org/privilege/tethering.admin
2655 * @param[in] tethering The handle of tethering
2656 * @param[in] type The type of tethering
2657 * @retval #TETHERING_ERROR_NONE Successful
2658 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2659 * @see tethering_set_enabled_cb()
2661 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2663 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2664 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2665 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2666 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2667 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2669 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2670 "parameter(tethering) is NULL\n");
2672 __tethering_h *th = (__tethering_h *)tethering;
2673 tethering_type_e ti;
2675 if (type != TETHERING_TYPE_ALL) {
2676 th->enabled_cb[type] = NULL;
2677 th->enabled_user_data[type] = NULL;
2679 return TETHERING_ERROR_NONE;
2682 /* TETHERING_TYPE_ALL */
2683 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2684 th->enabled_cb[ti] = NULL;
2685 th->enabled_user_data[ti] = NULL;
2688 return TETHERING_ERROR_NONE;
2693 * @brief Registers the callback function called when tethering is disabled.
2695 * @privlevel platform
2696 * @privilege http://tizen.org/privilege/tethering.admin
2697 * @param[in] tethering The handle of tethering
2698 * @param[in] type The type of tethering
2699 * @param[in] callback The callback function to invoke
2700 * @param[in] user_data The user data to be passed to the callback function
2701 * @retval #TETHERING_ERROR_NONE Successful
2702 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2703 * @see tethering_unset_disabled_cb()
2705 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2707 INFO("+ type: %d\n", type);
2708 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2709 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2710 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2711 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2712 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2714 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2715 "parameter(tethering) is NULL\n");
2716 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2717 "parameter(callback) is NULL\n");
2719 __tethering_h *th = (__tethering_h *)tethering;
2720 tethering_type_e ti;
2722 if (type != TETHERING_TYPE_ALL) {
2723 th->disabled_cb[type] = callback;
2724 th->disabled_user_data[type] = user_data;
2726 return TETHERING_ERROR_NONE;
2729 /* TETHERING_TYPE_ALL */
2730 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2731 th->disabled_cb[ti] = callback;
2732 th->disabled_user_data[ti] = user_data;
2735 return TETHERING_ERROR_NONE;
2740 * @brief Unregisters the callback function called when tethering is disabled.
2742 * @privlevel platform
2743 * @privilege http://tizen.org/privilege/tethering.admin
2744 * @param[in] tethering The handle of tethering
2745 * @param[in] type The type of tethering
2746 * @retval #TETHERING_ERROR_NONE Successful
2747 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2748 * @see tethering_set_disabled_cb()
2750 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2752 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2753 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2754 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2755 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2756 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2758 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2759 "parameter(tethering) is NULL\n");
2761 __tethering_h *th = (__tethering_h *)tethering;
2762 tethering_type_e ti;
2764 if (type != TETHERING_TYPE_ALL) {
2765 th->disabled_cb[type] = NULL;
2766 th->disabled_user_data[type] = NULL;
2768 return TETHERING_ERROR_NONE;
2771 /* TETHERING_TYPE_ALL */
2772 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2773 th->disabled_cb[ti] = NULL;
2774 th->disabled_user_data[ti] = NULL;
2777 return TETHERING_ERROR_NONE;
2782 * @brief Registers the callback function called when the state of connection is changed.
2784 * @privlevel platform
2785 * @privilege http://tizen.org/privilege/tethering.admin
2786 * @param[in] tethering The handle of tethering
2787 * @param[in] type The type of tethering
2788 * @param[in] callback The callback function to invoke
2789 * @param[in] user_data The user data to be passed to the callback function
2790 * @retval #TETHERING_ERROR_NONE Successful
2791 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2792 * @see tethering_unset_connection_state_changed_cb_cb()
2794 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2796 INFO("+ type: %d\n", type);
2797 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2798 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2799 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2800 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2801 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2803 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2804 "parameter(tethering) is NULL\n");
2805 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2806 "parameter(callback) is NULL\n");
2808 __tethering_h *th = (__tethering_h *)tethering;
2809 tethering_type_e ti;
2811 if (type != TETHERING_TYPE_ALL) {
2812 th->changed_cb[type] = callback;
2813 th->changed_user_data[type] = user_data;
2815 return TETHERING_ERROR_NONE;
2818 /* TETHERING_TYPE_ALL */
2819 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2820 th->changed_cb[ti] = callback;
2821 th->changed_user_data[ti] = user_data;
2824 return TETHERING_ERROR_NONE;
2829 * @brief Unregisters the callback function called when the state of connection is changed.
2831 * @privlevel platform
2832 * @privilege http://tizen.org/privilege/tethering.admin
2833 * @param[in] tethering The handle of tethering
2834 * @param[in] type The type of tethering
2835 * @retval #TETHERING_ERROR_NONE Successful
2836 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2837 * @see tethering_set_connection_state_changed_cb()
2839 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2841 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2842 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2843 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2844 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2845 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2847 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2848 "parameter(tethering) is NULL\n");
2850 __tethering_h *th = (__tethering_h *)tethering;
2851 tethering_type_e ti;
2853 if (type != TETHERING_TYPE_ALL) {
2854 th->changed_cb[type] = NULL;
2855 th->changed_user_data[type] = NULL;
2857 return TETHERING_ERROR_NONE;
2860 /* TETHERING_TYPE_ALL */
2861 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2862 th->changed_cb[ti] = NULL;
2863 th->changed_user_data[ti] = NULL;
2866 return TETHERING_ERROR_NONE;
2871 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2873 * @privlevel platform
2874 * @privilege http://tizen.org/privilege/tethering.admin
2875 * @param[in] tethering The handle of tethering
2876 * @param[in] callback The callback function to invoke
2877 * @param[in] user_data The user data to be passed to the callback function
2878 * @retval #TETHERING_ERROR_NONE Successful
2879 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2880 * @see tethering_wifi_unset_security_type_changed_cb()
2882 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2884 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2885 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2887 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2888 "parameter(tethering) is NULL\n");
2889 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2890 "parameter(callback) is NULL\n");
2892 __tethering_h *th = (__tethering_h *)tethering;
2894 th->security_type_changed_cb = callback;
2895 th->security_type_user_data = user_data;
2897 return TETHERING_ERROR_NONE;
2903 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2905 * @privlevel platform
2906 * @privilege http://tizen.org/privilege/tethering.admin
2907 * @param[in] tethering The handle of tethering
2908 * @param[in] type The type of tethering
2909 * @retval #TETHERING_ERROR_NONE Successful
2910 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2911 * @see tethering_wifi_set_security_type_changed_cb()
2913 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2915 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2916 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2918 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2919 "parameter(tethering) is NULL\n");
2921 __tethering_h *th = (__tethering_h *)tethering;
2923 th->security_type_changed_cb = NULL;
2924 th->security_type_user_data = NULL;
2926 return TETHERING_ERROR_NONE;
2931 * @brief Registers the callback function called when the visibility of SSID is changed.
2933 * @privlevel platform
2934 * @privilege http://tizen.org/privilege/tethering.admin
2935 * @param[in] tethering The handle of tethering
2936 * @param[in] callback The callback function to invoke
2937 * @param[in] user_data The user data to be passed to the callback function
2938 * @retval #TETHERING_ERROR_NONE Successful
2939 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2940 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2942 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2944 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2945 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2947 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2948 "parameter(tethering) is NULL\n");
2949 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2950 "parameter(callback) is NULL\n");
2952 __tethering_h *th = (__tethering_h *)tethering;
2954 th->ssid_visibility_changed_cb = callback;
2955 th->ssid_visibility_user_data = user_data;
2957 return TETHERING_ERROR_NONE;
2962 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2964 * @privlevel platform
2965 * @privilege http://tizen.org/privilege/tethering.admin
2966 * @param[in] tethering The handle of tethering
2967 * @retval #TETHERING_ERROR_NONE Successful
2968 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2969 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2971 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2973 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2974 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2976 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2977 "parameter(tethering) is NULL\n");
2979 __tethering_h *th = (__tethering_h *)tethering;
2981 th->ssid_visibility_changed_cb = NULL;
2982 th->ssid_visibility_user_data = NULL;
2984 return TETHERING_ERROR_NONE;
2989 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2991 * @privlevel platform
2992 * @privilege http://tizen.org/privilege/tethering.admin
2993 * @param[in] tethering The handle of tethering
2994 * @param[in] callback The callback function to invoke
2995 * @param[in] user_data The user data to be passed to the callback function
2996 * @retval #TETHERING_ERROR_NONE Successful
2997 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2998 * @see tethering_wifi_unset_passphrase_changed_cb()
3000 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
3002 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3003 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3005 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3006 "parameter(tethering) is NULL\n");
3007 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3008 "parameter(callback) is NULL\n");
3010 __tethering_h *th = (__tethering_h *)tethering;
3012 th->passphrase_changed_cb = callback;
3013 th->passphrase_user_data = user_data;
3015 return TETHERING_ERROR_NONE;
3020 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
3022 * @privlevel platform
3023 * @privilege http://tizen.org/privilege/tethering.admin
3024 * @param[in] tethering The handle of tethering
3025 * @retval #TETHERING_ERROR_NONE Successful
3026 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3027 * @see tethering_wifi_set_passphrase_changed_cb()
3029 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
3031 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3032 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3034 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3035 "parameter(tethering) is NULL\n");
3037 __tethering_h *th = (__tethering_h *)tethering;
3039 th->passphrase_changed_cb = NULL;
3040 th->passphrase_user_data = NULL;
3042 return TETHERING_ERROR_NONE;
3047 * @brief Sets the security type of Wi-Fi tethering.
3049 * @privlevel platform
3050 * @privilege http://tizen.org/privilege/tethering.admin
3051 * @remarks This change is applied next time Wi-Fi tethering is enabled
3052 * @param[in] tethering The handle of tethering
3053 * @param[in] type The security type
3054 * @return 0 on success, otherwise negative error value.
3055 * @retval #TETHERING_ERROR_NONE Successful
3056 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3057 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3058 * @see tethering_wifi_get_security_type()
3060 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
3062 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3063 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3065 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3066 "parameter(tethering) is NULL\n");
3068 __tethering_h *th = (__tethering_h *)tethering;
3069 tethering_error_e ret = TETHERING_ERROR_NONE;
3070 char *sec_str = NULL;
3072 ret = __set_security_type(type);
3073 if (ret == TETHERING_ERROR_NONE) {
3075 case TETHERING_WIFI_SECURITY_TYPE_NONE:
3076 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
3078 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
3079 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
3081 case TETHERING_WIFI_SECURITY_TYPE_WPS:
3082 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
3084 case TETHERING_WIFI_SECURITY_TYPE_SAE:
3085 sec_str = TETHERING_WIFI_SECURITY_TYPE_SAE_STR;
3089 __send_dbus_signal(th->client_bus,
3090 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
3097 * @brief Gets the security type of Wi-Fi tethering.
3099 * @privlevel platform
3100 * @privilege http://tizen.org/privilege/tethering.admin
3101 * @param[in] tethering The handle of tethering
3102 * @param[out] type The security type
3103 * @return 0 on success, otherwise negative error value.
3104 * @retval #TETHERING_ERROR_NONE Successful
3105 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3106 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3107 * @see tethering_wifi_set_security_type()
3109 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3111 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3112 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3114 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3115 "parameter(tethering) is NULL\n");
3116 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3117 "parameter(type) is NULL\n");
3119 return __get_security_type(type);
3124 * @brief Sets the SSID (service set identifier).
3126 * @privlevel platform
3127 * @privilege http://tizen.org/privilege/tethering.admin
3128 * @details If SSID is not set, Device name is used as SSID
3129 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
3130 * @param[in] tethering The handle of tethering
3131 * @param[out] ssid The SSID
3132 * @return 0 on success, otherwise negative error value.
3133 * @retval #TETHERING_ERROR_NONE Successful
3134 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3135 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3137 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
3139 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3140 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3142 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3143 "parameter(tethering) is NULL\n");
3144 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3145 "parameter(ssid) is NULL\n");
3147 __tethering_h *th = (__tethering_h *)tethering;
3148 char *p_ssid = NULL;
3151 ssid_len = strlen(ssid);
3152 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3153 ERR("parameter(ssid) is too long");
3154 return TETHERING_ERROR_INVALID_PARAMETER;
3157 p_ssid = strdup(ssid);
3158 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
3159 "strdup is failed\n");
3162 GDBusProxy *proxy = th->client_bus_proxy;
3163 GVariant *parameters;
3164 GError *error = NULL;
3165 tethering_error_e ret = TETHERING_ERROR_NONE;
3167 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_ssid",
3168 g_variant_new("(s)", ssid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3171 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3173 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3174 ret = TETHERING_ERROR_PERMISSION_DENIED;
3176 ret = TETHERING_ERROR_OPERATION_FAILED;
3178 g_error_free(error);
3182 if (parameters != NULL) {
3183 g_variant_get(parameters, "(u)", &ret);
3184 g_variant_unref(parameters);
3187 SINFO("set tethering ssid : %s", ssid);
3188 #endif /* TIZEN_TV_EXT */
3194 return TETHERING_ERROR_NONE;
3199 * @brief Gets the SSID (service set identifier).
3201 * @privlevel platform
3202 * @privilege http://tizen.org/privilege/tethering.admin
3203 * @remarks @a ssid must be released with free() by you.
3204 * @param[in] tethering The handle of tethering
3205 * @param[out] ssid The SSID
3206 * @return 0 on success, otherwise negative error value.
3207 * @retval #TETHERING_ERROR_NONE Successful
3208 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3209 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3210 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3212 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
3214 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3215 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3217 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3218 "parameter(tethering) is NULL\n");
3219 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3220 "parameter(ssid) is NULL\n");
3223 __tethering_h *th = (__tethering_h *)tethering;
3224 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
3227 if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID,
3228 val, sizeof(val)) == true) {
3229 *ssid = strdup(val);
3230 SINFO("get tethering ssid : %s", *ssid);
3231 return TETHERING_ERROR_NONE;
3233 #endif /* TIZEN_TV_EXT */
3235 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
3236 if (th->ssid != NULL) {
3237 DBG("Private SSID is set\n");
3238 *ssid = strdup(th->ssid);
3240 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
3241 val, sizeof(val)) == false) {
3242 return TETHERING_ERROR_OPERATION_FAILED;
3244 *ssid = strdup(val);
3247 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
3248 val, sizeof(val)) == false) {
3249 return TETHERING_ERROR_OPERATION_FAILED;
3251 *ssid = strdup(val);
3254 if (*ssid == NULL) {
3255 ERR("strdup is failed\n");
3256 return TETHERING_ERROR_OUT_OF_MEMORY;
3259 return TETHERING_ERROR_NONE;
3264 * @brief Sets the visibility of SSID(service set identifier).
3266 * @privlevel platform
3267 * @privilege http://tizen.org/privilege/tethering.admin
3268 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3269 * @remarks This change is applied next time Wi-Fi tethering is enabled
3270 * @param[in] tethering The handle of tethering
3271 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3272 * @return 0 on success, otherwise negative error value.
3273 * @retval #TETHERING_ERROR_NONE Successful
3274 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3275 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3276 * @see tethering_wifi_get_ssid_visibility()
3278 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
3280 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3281 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3283 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3284 "parameter(tethering) is NULL\n");
3286 __tethering_h *th = (__tethering_h *)tethering;
3287 tethering_error_e ret = TETHERING_ERROR_NONE;
3289 ret = __set_visible(visible);
3290 if (ret == TETHERING_ERROR_NONE) {
3291 __send_dbus_signal(th->client_bus,
3292 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
3293 visible ? SIGNAL_MSG_SSID_VISIBLE :
3294 SIGNAL_MSG_SSID_HIDE);
3301 * @brief Gets the visibility of SSID(service set identifier).
3303 * @privlevel platform
3304 * @privilege http://tizen.org/privilege/tethering.admin
3305 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3306 * @param[in] tethering The handle of tethering
3307 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3308 * @return 0 on success, otherwise negative error value.
3309 * @retval #TETHERING_ERROR_NONE Successful
3310 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3311 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3312 * @see tethering_wifi_set_ssid_visibility()
3314 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
3316 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3317 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3319 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3320 "parameter(tethering) is NULL\n");
3321 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3322 "parameter(visible) is NULL\n");
3324 return __get_visible(visible);
3329 * @brief Sets the passphrase.
3331 * @privlevel platform
3332 * @privilege http://tizen.org/privilege/tethering.admin
3333 * @remarks This change is applied next time Wi-Fi tethering is enabled
3334 * @param[in] tethering The handle of tethering
3335 * @param[in] passphrase The passphrase
3336 * @return 0 on success, otherwise negative error value.
3337 * @retval #TETHERING_ERROR_NONE Successful
3338 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3339 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3340 * @see tethering_wifi_get_passphrase()
3342 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3344 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3345 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3347 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3348 "parameter(tethering) is NULL\n");
3349 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3350 "parameter(passphrase) is NULL\n");
3352 __tethering_h *th = (__tethering_h *)tethering;
3353 GDBusProxy *proxy = th->client_bus_proxy;
3354 GVariant *parameters;
3355 GError *error = NULL;
3356 int passphrase_len = 0;
3360 passphrase_len = strlen(passphrase);
3361 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3362 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3363 ERR("parameter(passphrase) is too short or long\n");
3364 return TETHERING_ERROR_INVALID_PARAMETER;
3367 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3368 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3371 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3373 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3374 ret = TETHERING_ERROR_PERMISSION_DENIED;
3376 ret = TETHERING_ERROR_OPERATION_FAILED;
3378 g_error_free(error);
3382 g_variant_get(parameters, "(u)", &ret);
3383 g_variant_unref(parameters);
3385 if (ret == TETHERING_ERROR_NONE) {
3386 __send_dbus_signal(th->client_bus,
3387 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3396 * @brief Gets the passphrase.
3398 * @privlevel platform
3399 * @privilege http://tizen.org/privilege/tethering.admin
3400 * @remarks @a passphrase must be released with free() by you.
3401 * @param[in] tethering The handle of tethering
3402 * @param[out] passphrase The passphrase
3403 * @return 0 on success, otherwise negative error value.
3404 * @retval #TETHERING_ERROR_NONE Successful
3405 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3406 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3407 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3408 * @see tethering_wifi_set_passphrase()
3410 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3412 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3413 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3415 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3416 "parameter(tethering) is NULL\n");
3417 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3418 "parameter(passphrase) is NULL\n");
3420 __tethering_h *th = (__tethering_h *)tethering;
3421 GDBusProxy *proxy = th->client_bus_proxy;
3422 GVariant *parameters;
3423 GError *error = NULL;
3424 unsigned int len = 0;
3425 tethering_error_e ret = TETHERING_ERROR_NONE;
3427 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3428 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3431 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3433 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3434 ret = TETHERING_ERROR_PERMISSION_DENIED;
3436 ret = TETHERING_ERROR_OPERATION_FAILED;
3438 g_error_free(error);
3442 if (parameters != NULL) {
3443 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3444 g_variant_unref(parameters);
3447 return TETHERING_ERROR_NONE;
3450 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3452 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3453 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3455 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3456 "parameter(tethering) is NULL\n");
3458 __tethering_h *th = (__tethering_h *)tethering;
3461 GDBusProxy *proxy = th->client_bus_proxy;
3462 GVariant *parameters;
3463 GError *error = NULL;
3464 tethering_error_e ret = TETHERING_ERROR_NONE;
3466 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_channel",
3467 g_variant_new("(i)", channel), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3470 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3472 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3473 ret = TETHERING_ERROR_PERMISSION_DENIED;
3475 ret = TETHERING_ERROR_OPERATION_FAILED;
3477 g_error_free(error);
3481 if (parameters != NULL) {
3482 g_variant_get(parameters, "(u)", &ret);
3483 g_variant_unref(parameters);
3486 SINFO("set channel : %d", channel);
3487 #endif /* TIZEN_TV_EXT */
3489 th->channel = channel;
3491 return TETHERING_ERROR_NONE;
3494 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3496 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3497 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3499 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3500 "parameter(tethering) is NULL\n");
3502 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3503 "parameter(channel) is NULL\n");
3505 __tethering_h *th = (__tethering_h *)tethering;
3507 GDBusProxy *proxy = th->client_bus_proxy;
3508 GVariant *parameters;
3509 GError *error = NULL;
3510 int ch, vconf_channel;
3511 tethering_error_e ret = TETHERING_ERROR_NONE;
3513 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_channel",
3514 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3517 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3519 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3520 ret = TETHERING_ERROR_PERMISSION_DENIED;
3522 ret = TETHERING_ERROR_OPERATION_FAILED;
3524 g_error_free(error);
3528 if (parameters != NULL) {
3529 g_variant_get(parameters, "(iu)", &ch, &ret);
3530 g_variant_unref(parameters);
3534 ERR("failed to get Hostapd channel, set th->channel");
3535 *channel = th->channel;
3539 if (vconf_get_int(VCONFKEY_WIFI_CHANNEL, &vconf_channel) < 0)
3540 ERR("Failed to get vconf key for channel");
3542 *channel = vconf_channel;
3544 SINFO("get tethering channel : %d", *channel);
3545 #else /* TIZEN_TV_EXT */
3546 *channel = th->channel;
3547 #endif /* TIZEN_TV_EXT */
3549 return TETHERING_ERROR_NONE;
3552 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3554 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3555 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3557 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3558 "parameter(tethering) is NULL\n");
3560 __tethering_h *th = (__tethering_h *)tethering;
3562 th->mode_type = type;
3564 return TETHERING_ERROR_NONE;
3567 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3569 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3570 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3572 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3573 "parameter(tethering) is NULL\n");
3574 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3575 "parameter(type) is NULL\n");
3577 __tethering_h *th = (__tethering_h *)tethering;
3578 *type = th->mode_type;
3580 return TETHERING_ERROR_NONE;
3586 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3588 * @privlevel platform
3589 * @privilege http://tizen.org/privilege/tethering.admin
3590 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3591 * @param[in] tethering The handle of tethering
3592 * @param[in] callback The callback function to invoke
3593 * @param[in] user_data The user data to be passed to the callback function
3594 * @return 0 on success, otherwise negative error value.
3595 * @retval #TETHERING_ERROR_NONE Successful
3596 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3597 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3599 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3602 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3603 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3605 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3606 "parameter(tethering) is NULL\n");
3607 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3608 "parameter(callback) is NULL\n");
3610 __tethering_h *th = (__tethering_h *)tethering;
3611 _softap_settings_t set = {"", "", "", 0, false};
3612 GDBusProxy *proxy = th->client_bus_proxy;
3617 if (th->settings_reloaded_cb) {
3618 ERR("Operation in progress\n");
3619 return TETHERING_ERROR_OPERATION_FAILED;
3622 ret = __prepare_wifi_settings(tethering, &set);
3623 if (ret != TETHERING_ERROR_NONE) {
3624 ERR("softap settings initialization failed\n");
3625 return TETHERING_ERROR_OPERATION_FAILED;
3628 th->settings_reloaded_cb = callback;
3629 th->settings_reloaded_user_data = user_data;
3631 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
3632 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
3635 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3636 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),
3637 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3638 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3640 return TETHERING_ERROR_NONE;
3643 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3645 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3646 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3648 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3649 "parameter(tethering) is NULL\n");
3651 __tethering_h *th = (__tethering_h *)tethering;
3652 th->mac_filter = mac_filter;
3654 return TETHERING_ERROR_NONE;
3657 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3659 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3660 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3662 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3663 "parameter(mac_filter) is NULL\n");
3664 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3665 "parameter(mac_filter) is NULL\n");
3667 __tethering_h *th = (__tethering_h *)tethering;
3668 *mac_filter = th->mac_filter;
3670 return TETHERING_ERROR_NONE;
3673 static int __add_mac_to_file(const char *filepath, const char *mac)
3676 char line[MAX_BUF_SIZE] = "\0";
3677 bool mac_exist = false;
3680 fp = fopen(filepath, "a+");
3682 ERR("fopen is failed\n");
3683 return TETHERING_ERROR_OPERATION_FAILED;
3686 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3687 if (strncmp(mac, line, 17) == 0) {
3688 DBG("MAC %s already exist in the list\n", mac);
3695 p_mac = strdup(mac);
3696 if (p_mac == NULL) {
3697 ERR("strdup failed\n");
3699 return TETHERING_ERROR_OUT_OF_MEMORY;
3702 fprintf(fp, "%s\n", mac);
3704 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3705 allowed_list = g_slist_append(allowed_list, p_mac);
3706 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3707 blocked_list = g_slist_append(blocked_list, p_mac);
3714 return TETHERING_ERROR_NONE;
3717 static int __remove_mac_from_file(const char *filepath, const char *mac)
3721 char line[MAX_BUF_SIZE] = "\0";
3723 fp = fopen(filepath, "r");
3725 ERR("fopen is failed\n");
3726 return TETHERING_ERROR_OPERATION_FAILED;
3729 fp1 = fopen(TEMP_LIST, "w+");
3732 ERR("fopen is failed\n");
3733 return TETHERING_ERROR_OPERATION_FAILED;
3736 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3737 if (strncmp(mac, line, 17) == 0) {
3738 DBG("MAC %s found in the list\n", mac);
3740 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3741 GSList *list = NULL;
3742 for (list = allowed_list; list != NULL; list = list->next) {
3743 char *p_mac = (char *)list->data;
3744 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3745 allowed_list = g_slist_remove(allowed_list, p_mac);
3747 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3748 GSList *list = NULL;
3749 for (list = blocked_list; list != NULL; list = list->next) {
3750 char *p_mac = (char *)list->data;
3751 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3752 blocked_list = g_slist_remove(blocked_list, p_mac);
3756 fprintf(fp1, "%s", line);
3763 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3764 if (rename(TEMP_LIST, ALLOWED_LIST) != 0) {
3765 ERR("rename is failed (%s -> %s)", TEMP_LIST, ALLOWED_LIST);
3766 return TETHERING_ERROR_OPERATION_FAILED;
3768 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3769 if (rename(TEMP_LIST, BLOCKED_LIST) != 0) {
3770 ERR("rename is failed (%s -> %s)", TEMP_LIST, BLOCKED_LIST);
3771 return TETHERING_ERROR_OPERATION_FAILED;
3775 return TETHERING_ERROR_NONE;
3778 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3780 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3781 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3783 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3784 "parameter(tethering) is NULL\n");
3785 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3786 "parameter(mac) is NULL\n");
3788 return __add_mac_to_file(ALLOWED_LIST, mac);
3791 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3793 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3794 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3796 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3797 "parameter(tethering) is NULL\n");
3798 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3799 "parameter(mac) is NULL\n");
3801 return __remove_mac_from_file(ALLOWED_LIST, mac);
3804 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3806 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3807 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3809 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3810 "parameter(tethering) is NULL\n");
3811 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3812 "parameter(allowed_mac_list) is NULL\n");
3814 *allowed_mac_list = g_slist_copy(allowed_list);
3815 return TETHERING_ERROR_NONE;
3818 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
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(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3826 "parameter(mac) is NULL\n");
3828 return __add_mac_to_file(BLOCKED_LIST, mac);
3831 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3833 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3834 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3836 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3837 "parameter(tethering) is NULL\n");
3838 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3839 "parameter(mac) is NULL\n");
3841 return __remove_mac_from_file(BLOCKED_LIST, mac);
3844 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3846 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3847 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3849 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3850 "parameter(tethering) is NULL\n");
3851 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3852 "parameter(blocked_mac_list) is NULL\n");
3854 *blocked_mac_list = g_slist_copy(blocked_list);
3855 return TETHERING_ERROR_NONE;
3858 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3860 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3861 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3863 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3864 "parameter(tethering) is NULL\n");
3866 GVariant *parameters;
3867 GError *error = NULL;
3870 __tethering_h *th = (__tethering_h *)tethering;
3872 GDBusProxy *proxy = th->client_bus_proxy;
3874 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3875 g_variant_new("(b)", enable),
3876 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3879 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3880 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3881 result = TETHERING_ERROR_PERMISSION_DENIED;
3883 result = TETHERING_ERROR_OPERATION_FAILED;
3885 g_error_free(error);
3886 th->dhcp_enabled = false;
3891 g_variant_get(parameters, "(u)", &result);
3892 g_variant_unref(parameters);
3895 th->dhcp_enabled = true;
3897 th->dhcp_enabled = false;
3899 return TETHERING_ERROR_NONE;
3902 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3904 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3905 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3907 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3908 "parameter(tethering) is NULL\n");
3909 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3910 "parameter(rangestart) is NULL\n");
3911 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3912 "parameter(rangestop) is NULL\n");
3914 GVariant *parameters;
3915 GError *error = NULL;
3918 __tethering_h *th = (__tethering_h *)tethering;
3920 GDBusProxy *proxy = th->client_bus_proxy;
3922 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3923 g_variant_new("(ss)", rangestart, rangestop),
3924 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3926 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3928 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3929 result = TETHERING_ERROR_PERMISSION_DENIED;
3931 result = TETHERING_ERROR_OPERATION_FAILED;
3933 g_error_free(error);
3934 th->dhcp_enabled = false;
3939 g_variant_get(parameters, "(u)", &result);
3940 g_variant_unref(parameters);
3942 th->dhcp_enabled = true;
3944 return TETHERING_ERROR_NONE;
3947 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3949 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3950 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3952 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3953 "parameter(tethering) is NULL\n");
3954 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3955 "parameter(dhcp_enabled) is NULL\n");
3957 __tethering_h *th = (__tethering_h *)tethering;
3958 *dhcp_enabled = th->dhcp_enabled;
3960 return TETHERING_ERROR_NONE;
3963 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3965 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3966 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3968 GError *error = NULL;
3970 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3971 "parameter(tethering) is NULL\n");
3972 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3973 TETHERING_ERROR_NOT_ENABLED,
3974 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3975 __tethering_h *th = (__tethering_h *)tethering;
3976 th->txpower = txpower;
3978 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3979 g_variant_new("(u)", txpower),
3980 G_DBUS_CALL_FLAGS_NONE,
3981 -1, th->cancellable, &error);
3983 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3984 g_clear_error(&error);
3985 return TETHERING_ERROR_OPERATION_FAILED;
3987 return TETHERING_ERROR_NONE;
3990 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3992 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3993 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3995 GError *error = NULL;
3996 GVariant *result = NULL;
3998 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3999 "parameter(tethering) is NULL\n");
4000 _retvm_if(txpower == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4001 "parameter(txpower) is NULL\n");
4002 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
4003 TETHERING_ERROR_NOT_ENABLED,
4004 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
4006 __tethering_h *th = (__tethering_h *)tethering;
4008 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
4010 G_DBUS_CALL_FLAGS_NONE,
4011 -1, th->cancellable, &error);
4013 if (result != NULL) {
4014 g_variant_get(result, "(u)", txpower);
4015 g_variant_unref(result);
4018 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
4019 g_clear_error(&error);
4020 return TETHERING_ERROR_OPERATION_FAILED;
4022 g_clear_error(&error);
4023 return TETHERING_ERROR_NONE;
4026 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
4028 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4029 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4031 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4032 "parameter(tethering) is NULL\n");
4034 GVariant *parameters;
4035 GError *error = NULL;
4038 __tethering_h *th = (__tethering_h *)tethering;
4040 GDBusProxy *proxy = th->client_bus_proxy;
4042 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
4043 g_variant_new("(u)", mtu),
4044 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4046 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4048 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4049 result = TETHERING_ERROR_PERMISSION_DENIED;
4051 result = TETHERING_ERROR_OPERATION_FAILED;
4053 g_error_free(error);
4057 g_variant_get(parameters, "(u)", &result);
4059 g_variant_unref(parameters);
4061 return TETHERING_ERROR_NONE;
4064 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
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(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4072 "parameter(mac) is NULL\n");
4074 GVariant *parameters;
4075 GError *error = NULL;
4078 __tethering_h *th = (__tethering_h *)tethering;
4080 GDBusProxy *proxy = th->client_bus_proxy;
4082 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
4083 g_variant_new("(s)", mac),
4084 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4086 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4088 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4089 result = TETHERING_ERROR_PERMISSION_DENIED;
4091 result = TETHERING_ERROR_OPERATION_FAILED;
4093 g_error_free(error);
4097 g_variant_get(parameters, "(u)", &result);
4098 g_variant_unref(parameters);
4100 if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
4101 return TETHERING_ERROR_NOT_SUPPORT_API;
4103 return TETHERING_ERROR_NONE;
4106 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
4108 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4109 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4111 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4112 "parameter(tethering) is NULL\n");
4114 __tethering_h *th = (__tethering_h *)tethering;
4116 th->wifi_max_connected = max_device;
4118 return TETHERING_ERROR_NONE;
4121 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
4123 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4124 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4126 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4127 "parameter(tethering) is NULL\n");
4128 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4129 "parameter(max_device) is NULL\n");
4131 __tethering_h *th = (__tethering_h *)tethering;
4133 *max_device = th->wifi_max_connected;
4134 return TETHERING_ERROR_NONE;
4137 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
4139 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4140 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4142 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4143 "parameter(tethering) is NULL\n");
4145 GVariant *parameters;
4146 GError *error = NULL;
4149 __tethering_h *th = (__tethering_h *)tethering;
4151 GDBusProxy *proxy = th->client_bus_proxy;
4153 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
4154 g_variant_new("(b)", enable),
4155 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4157 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4159 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4160 result = TETHERING_ERROR_PERMISSION_DENIED;
4162 result = TETHERING_ERROR_OPERATION_FAILED;
4164 g_error_free(error);
4168 g_variant_get(parameters, "(u)", &result);
4169 g_variant_unref(parameters);
4171 th->port_forwarding = true;
4173 return TETHERING_ERROR_NONE;
4176 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)
4178 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4179 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4181 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4182 "parameter(tethering) is NULL\n");
4183 _retvm_if(ifname == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4184 "parameter(ifname) is NULL\n");
4185 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4186 "parameter(protocol) is NULL\n");
4187 _retvm_if(org_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4188 "parameter(org_ip) is NULL\n");
4189 _retvm_if(final_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4190 "parameter(final_ip) is NULL\n");
4192 GVariant *parameters;
4193 GError *error = NULL;
4195 char cmd[MAX_BUF_SIZE] = { 0, };
4198 __tethering_h *th = (__tethering_h *)tethering;
4200 GDBusProxy *proxy = th->client_bus_proxy;
4202 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
4203 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
4204 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4206 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4208 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4209 result = TETHERING_ERROR_PERMISSION_DENIED;
4211 result = TETHERING_ERROR_OPERATION_FAILED;
4213 g_error_free(error);
4217 g_variant_get(parameters, "(u)", &result);
4218 g_variant_unref(parameters);
4220 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);
4224 ERR("strdup failed\n");
4225 return TETHERING_ERROR_OUT_OF_MEMORY;
4228 port_forwarding = g_slist_append(port_forwarding, list);
4230 return TETHERING_ERROR_NONE;
4233 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
4235 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4236 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4238 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4239 "parameter(tethering) is NULL\n");
4241 GVariant *parameters;
4242 GError *error = NULL;
4245 __tethering_h *th = (__tethering_h *)tethering;
4247 GDBusProxy *proxy = th->client_bus_proxy;
4249 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
4250 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4252 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4254 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4255 result = TETHERING_ERROR_PERMISSION_DENIED;
4257 result = TETHERING_ERROR_OPERATION_FAILED;
4259 g_error_free(error);
4263 g_variant_get(parameters, "(u)", &result);
4265 g_variant_unref(parameters);
4267 return TETHERING_ERROR_NONE;
4270 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool *forwarding_enabled)
4272 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4273 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4275 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4276 "parameter(tethering) is NULL\n");
4277 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4278 "parameter(forwarding_enabled) is NULL\n");
4280 __tethering_h *th = (__tethering_h *)tethering;
4282 *forwarding_enabled = th->port_forwarding;
4284 return TETHERING_ERROR_NONE;
4287 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
4289 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4290 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4292 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4293 "parameter(tethering) is NULL\n");
4294 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4295 "parameter(port_forwarding_list) is NULL\n");
4297 *port_forwarding_list = g_slist_copy(port_forwarding);
4298 return TETHERING_ERROR_NONE;
4301 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
4303 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4304 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4306 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4307 "parameter(tethering) is NULL\n");
4309 GVariant *parameters;
4310 GError *error = NULL;
4313 __tethering_h *th = (__tethering_h *)tethering;
4315 GDBusProxy *proxy = th->client_bus_proxy;
4317 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
4318 g_variant_new("(b)", enable),
4319 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4321 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4323 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4324 result = TETHERING_ERROR_PERMISSION_DENIED;
4326 result = TETHERING_ERROR_OPERATION_FAILED;
4328 g_error_free(error);
4332 g_variant_get(parameters, "(u)", &result);
4333 g_variant_unref(parameters);
4335 th->port_filtering = true;
4337 return TETHERING_ERROR_NONE;
4340 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
4342 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4343 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4345 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4346 "parameter(tethering) is NULL\n");
4347 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4348 "parameter(protocol) is NULL\n");
4350 GVariant *parameters;
4351 GError *error = NULL;
4356 __tethering_h *th = (__tethering_h *)tethering;
4358 GDBusProxy *proxy = th->client_bus_proxy;
4360 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
4361 g_variant_new("(isb)", port, protocol, allow),
4362 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4364 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4366 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4367 result = TETHERING_ERROR_PERMISSION_DENIED;
4369 result = TETHERING_ERROR_OPERATION_FAILED;
4371 g_error_free(error);
4375 g_variant_get(parameters, "(u)", &result);
4376 g_variant_unref(parameters);
4379 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
4381 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
4383 if (ret == -1 || list == NULL) {
4384 ERR("asprintf failed\n");
4385 return TETHERING_ERROR_OUT_OF_MEMORY;
4388 DBG("cmd:%s", list);
4390 port_filtering = g_slist_append(port_filtering, list);
4392 return TETHERING_ERROR_NONE;
4395 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
4397 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4398 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4400 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4401 "parameter(tethering) is NULL\n");
4402 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4403 "parameter(protocol) is NULL\n");
4405 GVariant *parameters;
4406 GError *error = NULL;
4411 __tethering_h *th = (__tethering_h *)tethering;
4413 GDBusProxy *proxy = th->client_bus_proxy;
4415 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
4416 g_variant_new("(iisb)", port1, port2, protocol, allow),
4417 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4419 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4421 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4422 result = TETHERING_ERROR_PERMISSION_DENIED;
4424 result = TETHERING_ERROR_OPERATION_FAILED;
4426 g_error_free(error);
4430 g_variant_get(parameters, "(u)", &result);
4431 g_variant_unref(parameters);
4434 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
4436 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
4438 if (ret == -1 || list == NULL) {
4439 ERR("asprintf failed\n");
4440 return TETHERING_ERROR_OUT_OF_MEMORY;
4443 DBG("cmd:%s", list);
4445 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4447 return TETHERING_ERROR_NONE;
4450 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4452 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4453 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4455 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4456 "parameter(tethering) is NULL\n");
4457 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4458 "parameter(port_filtering_list) is NULL\n");
4460 *port_filtering_list = g_slist_copy(port_filtering);
4461 return TETHERING_ERROR_NONE;
4464 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4466 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4467 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4469 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4470 "parameter(tethering) is NULL\n");
4471 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4472 "parameter(custom_port_filtering_list) is NULL\n");
4474 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4475 return TETHERING_ERROR_NONE;
4478 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool *filtering_enabled)
4480 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4481 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4483 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4484 "parameter(tethering) is NULL\n");
4485 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4486 "parameter(filtering_enabled) is NULL\n");
4488 __tethering_h *th = (__tethering_h *)tethering;
4490 *filtering_enabled = th->port_filtering;
4492 return TETHERING_ERROR_NONE;
4495 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
4497 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4498 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4500 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4501 "parameter(tethering) is NULL\n");
4503 GVariant *parameters;
4504 GError *error = NULL;
4507 __tethering_h *th = (__tethering_h *)tethering;
4509 GDBusProxy *proxy = th->client_bus_proxy;
4511 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4512 g_variant_new("(ib)", type, enable),
4513 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4515 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4517 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4518 result = TETHERING_ERROR_PERMISSION_DENIED;
4520 result = TETHERING_ERROR_OPERATION_FAILED;
4522 g_error_free(error);
4526 g_variant_get(parameters, "(u)", &result);
4528 g_variant_unref(parameters);
4530 return TETHERING_ERROR_NONE;
4533 API int tethering_wifi_push_wps_button(tethering_h tethering)
4535 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4536 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4538 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4539 "parameter(tethering) is NULL");
4540 __tethering_h *th = (__tethering_h *)tethering;
4541 GDBusProxy *proxy = th->client_bus_proxy;
4542 GVariant *parameters = NULL;
4544 GError *error = NULL;
4546 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4547 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4550 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4552 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4553 ret = TETHERING_ERROR_PERMISSION_DENIED;
4555 ret = TETHERING_ERROR_OPERATION_FAILED;
4557 g_error_free(error);
4561 if (parameters != NULL) {
4562 g_variant_get(parameters, "(u)", &ret);
4563 g_variant_unref(parameters);
4566 return TETHERING_ERROR_NONE;
4569 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4571 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4572 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4574 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4575 "parameter(tethering) is NULL");
4576 _retvm_if(wps_pin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4577 "parameter(wps_pin) is NULL");
4579 __tethering_h *th = (__tethering_h *)tethering;
4580 GDBusProxy *proxy = th->client_bus_proxy;
4581 GVariant *parameters = NULL;
4583 GError *error = NULL;
4585 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4586 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4589 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4591 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4592 ret = TETHERING_ERROR_PERMISSION_DENIED;
4594 ret = TETHERING_ERROR_OPERATION_FAILED;
4596 g_error_free(error);
4600 if (parameters != NULL) {
4601 g_variant_get(parameters, "(u)", &ret);
4602 g_variant_unref(parameters);
4605 return TETHERING_ERROR_NONE;
4608 API int tethering_wifi_is_sharing_supported(tethering_h tethering, bool *supported)
4610 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4611 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4613 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4614 "parameter(tethering) is NULL\n");
4615 _retvm_if(supported == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4616 "parameter(supported) is NULL\n");
4618 /** Check if wifi-sharing is supported */
4619 __tethering_h *th = (__tethering_h *)tethering;
4620 GDBusProxy *proxy = th->client_bus_proxy;
4622 int ret = TETHERING_ERROR_NONE;
4625 GVariant *value = NULL;
4626 GVariantIter *iter = NULL;
4627 GVariantIter *sub_iter = NULL;
4628 GVariant *parameters = NULL;
4629 GError *error = NULL;
4631 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_interfaces",
4632 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4634 if (!parameters && error) {
4635 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4637 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4638 ret = TETHERING_ERROR_PERMISSION_DENIED;
4640 ret = TETHERING_ERROR_OPERATION_FAILED;
4642 g_error_free(error);
4646 g_variant_get(parameters, "(a(a{sv}))", &iter);
4648 g_variant_unref(parameters);
4649 ret = TETHERING_ERROR_OPERATION_FAILED;
4653 while (g_variant_iter_loop(iter, "(a{sv})", &sub_iter)) {
4654 while (g_variant_iter_loop(sub_iter, "{sv}", &key, &value)) {
4655 if (g_strcmp0(key, "IfName") == 0) {
4656 const gchar *interface = g_variant_get_string(value, NULL);
4657 ERR("interface: %s\n", interface);
4658 if (strncmp(interface, "wlan", 4) == 0)
4663 g_variant_unref(parameters);