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"
59 static GSList *allowed_list = NULL;
60 static GSList *blocked_list = NULL;
61 static GSList *port_forwarding = NULL;
62 static GSList *port_filtering = NULL;
63 static GSList *custom_port_filtering = NULL;
65 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
66 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
67 GVariant *parameters, gpointer user_data);
69 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
70 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
71 GVariant *parameters, gpointer user_data);
73 static void __handle_usb_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_usb_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_bt_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_bt_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_net_closed(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_no_data_timeout(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_low_battery_mode(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_flight_mode(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_security_type_changed(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_ssid_visibility_changed(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_passphrase_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_dhcp(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 __tethering_sig_t sigs[] = {
122 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
123 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
124 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
125 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
126 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
127 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
128 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
129 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
130 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
131 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
132 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
133 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
134 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
135 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
137 static int retry = 0;
138 static __thread tethering_request_table_t request_table[TETHERING_TYPE_MAX];
140 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
142 if (conn == NULL || signal_name == NULL)
145 GVariant *message = NULL;
146 GError *error = NULL;
149 message = g_variant_new("(s)", arg);
151 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
152 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
154 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
159 static bool __any_tethering_is_enabled(tethering_h tethering)
161 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
162 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
163 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI_SHARING) ||
164 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
165 tethering_is_enabled(tethering, TETHERING_TYPE_P2P))
171 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
173 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
174 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
175 security_type != TETHERING_WIFI_SECURITY_TYPE_WPS &&
176 security_type != TETHERING_WIFI_SECURITY_TYPE_SAE) {
177 ERR("Invalid param\n");
178 return TETHERING_ERROR_INVALID_PARAMETER;
181 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
182 ERR("vconf_set_int is failed\n");
183 return TETHERING_ERROR_OPERATION_FAILED;
186 return TETHERING_ERROR_NONE;
189 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
191 if (security_type == NULL) {
192 ERR("Invalid param\n");
193 return TETHERING_ERROR_INVALID_PARAMETER;
196 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
197 (int *)security_type) < 0) {
198 ERR("vconf_get_int is failed\n");
199 return TETHERING_ERROR_OPERATION_FAILED;
202 return TETHERING_ERROR_NONE;
205 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
207 if (path == NULL || ssid == NULL || size == 0)
211 char *ptr_tmp = NULL;
213 ptr = vconf_get_str(path);
217 if (!g_strcmp0(ptr, ""))
220 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
223 g_strlcpy(ssid, ptr, size);
229 static tethering_error_e __set_visible(const bool visible)
231 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
232 ERR("vconf_set_int is failed\n");
233 return TETHERING_ERROR_OPERATION_FAILED;
236 return TETHERING_ERROR_NONE;
239 static tethering_error_e __get_visible(bool *visible)
241 if (visible == NULL) {
242 ERR("Invalid param\n");
243 return TETHERING_ERROR_INVALID_PARAMETER;
248 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
249 ERR("vconf_get_int is failed\n");
250 return TETHERING_ERROR_OPERATION_FAILED;
257 return TETHERING_ERROR_NONE;
260 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
262 if (passphrase == NULL ||
263 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
266 guint32 rand_int = 0;
269 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
270 rand_int = g_random_int_range('a', 'z');
271 passphrase[index] = rand_int;
273 passphrase[index] = '\0';
278 static tethering_error_e __get_error(int agent_error)
280 tethering_error_e err = TETHERING_ERROR_NONE;
282 switch (agent_error) {
283 case MOBILE_AP_ERROR_NONE:
284 err = TETHERING_ERROR_NONE;
287 case MOBILE_AP_ERROR_RESOURCE:
288 err = TETHERING_ERROR_OUT_OF_MEMORY;
291 case MOBILE_AP_ERROR_INTERNAL:
292 err = TETHERING_ERROR_OPERATION_FAILED;
295 case MOBILE_AP_ERROR_INVALID_PARAM:
296 err = TETHERING_ERROR_INVALID_PARAMETER;
299 case MOBILE_AP_ERROR_ALREADY_ENABLED:
300 err = TETHERING_ERROR_OPERATION_FAILED;
303 case MOBILE_AP_ERROR_NOT_ENABLED:
304 err = TETHERING_ERROR_NOT_ENABLED;
307 case MOBILE_AP_ERROR_NET_OPEN:
308 err = TETHERING_ERROR_OPERATION_FAILED;
311 case MOBILE_AP_ERROR_NET_CLOSE:
312 err = TETHERING_ERROR_OPERATION_FAILED;
315 case MOBILE_AP_ERROR_DHCP:
316 err = TETHERING_ERROR_OPERATION_FAILED;
319 case MOBILE_AP_ERROR_IN_PROGRESS:
320 err = TETHERING_ERROR_OPERATION_FAILED;
323 case MOBILE_AP_ERROR_NOT_PERMITTED:
324 err = TETHERING_ERROR_NOT_PERMITTED;
327 case MOBILE_AP_ERROR_PERMISSION_DENIED:
328 err = TETHERING_ERROR_PERMISSION_DENIED;
331 ERR("Not defined error : %d\n", agent_error);
332 err = TETHERING_ERROR_OPERATION_FAILED;
339 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
340 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
341 GVariant *parameters, gpointer user_data)
345 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
347 __tethering_h *th = (__tethering_h *)user_data;
349 tethering_type_e type = 0;
350 mobile_ap_type_e ap_type = 0;
351 tethering_connection_state_changed_cb ccb = NULL;
352 __tethering_client_h client;
360 memset(&client, 0, sizeof(__tethering_client_h));
361 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
363 if (!g_strcmp0(buf, "DhcpConnected")) {
365 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
368 ERR("Unknown event [%s]\n", buf);
372 if (ap_type == MOBILE_AP_TYPE_USB)
373 type = TETHERING_TYPE_USB;
374 else if (ap_type == MOBILE_AP_TYPE_WIFI) {
375 if (request_table[TETHERING_TYPE_WIFI_SHARING].flag)
376 type = TETHERING_TYPE_WIFI_SHARING;
378 type = TETHERING_TYPE_WIFI;
379 } else if (ap_type == MOBILE_AP_TYPE_BT)
380 type = TETHERING_TYPE_BT;
381 else if (ap_type == MOBILE_AP_TYPE_P2P)
382 type = TETHERING_TYPE_P2P;
384 ERR("Not supported tethering type [%d]\n", ap_type);
388 SINFO("[%s] type %d, ip %s, mac %s, name %s, timestamp %d",
389 buf, ap_type, ip, mac, name, timestamp);
391 ccb = th->changed_cb[type];
394 data = th->changed_user_data[type];
396 client.interface = type;
397 g_strlcpy(client.ip, ip, sizeof(client.ip));
398 g_strlcpy(client.mac, mac, sizeof(client.mac));
400 client.hostname = g_strdup(name);
401 client.tm = (time_t)timestamp;
403 ccb((tethering_client_h)&client, opened, data);
404 g_free(client.hostname);
413 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
414 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
415 GVariant *parameters, gpointer user_data)
419 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
421 __tethering_h *th = (__tethering_h *)user_data;
422 tethering_type_e type = 0;
423 tethering_disabled_cb dcb = NULL;
425 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
427 SINFO("Tethering Disabled by network close !");
429 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
430 dcb = th->disabled_cb[type];
433 data = th->disabled_user_data[type];
435 dcb(TETHERING_ERROR_NONE, type, code, data);
441 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
442 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
443 GVariant *parameters, gpointer user_data)
447 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
449 __tethering_h *th = (__tethering_h *)user_data;
450 tethering_type_e type = TETHERING_TYPE_WIFI;
451 bool is_requested = false;
452 tethering_enabled_cb ecb = NULL;
455 ecb = th->enabled_cb[type];
458 data = th->enabled_user_data[type];
460 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
464 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
465 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
466 GVariant *parameters, gpointer user_data)
470 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
472 __tethering_h *th = (__tethering_h *)user_data;
473 tethering_type_e type = TETHERING_TYPE_WIFI;
474 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
475 tethering_disabled_cb dcb = NULL;
479 dcb = th->disabled_cb[type];
482 data = th->disabled_user_data[type];
483 g_variant_get(parameters, "(s)", &buf);
484 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
485 code = TETHERING_DISABLED_BY_WIFI_ON;
486 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
487 code = TETHERING_DISABLED_BY_TIMEOUT;
490 dcb(TETHERING_ERROR_NONE, type, code, data);
495 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
496 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
497 GVariant *parameters, gpointer user_data)
501 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
503 __tethering_h *th = (__tethering_h *)user_data;
504 tethering_type_e type = TETHERING_TYPE_USB;
505 bool is_requested = false;
506 tethering_enabled_cb ecb = NULL;
509 ecb = th->enabled_cb[type];
512 data = th->enabled_user_data[type];
514 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
518 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
519 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
520 GVariant *parameters, gpointer user_data)
524 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
526 __tethering_h *th = (__tethering_h *)user_data;
527 tethering_type_e type = TETHERING_TYPE_USB;
528 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
529 tethering_disabled_cb dcb = NULL;
533 dcb = th->disabled_cb[type];
536 data = th->disabled_user_data[type];
538 g_variant_get(parameters, "(s)", &buf);
539 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
540 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
542 dcb(TETHERING_ERROR_NONE, type, code, data);
547 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
548 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
549 GVariant *parameters, gpointer user_data)
553 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
555 __tethering_h *th = (__tethering_h *)user_data;
556 tethering_type_e type = TETHERING_TYPE_BT;
557 bool is_requested = false;
558 tethering_enabled_cb ecb = NULL;
561 ecb = th->enabled_cb[type];
564 data = th->enabled_user_data[type];
566 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
570 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
571 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
572 GVariant *parameters, gpointer user_data)
576 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
578 __tethering_h *th = (__tethering_h *)user_data;
579 tethering_type_e type = TETHERING_TYPE_BT;
580 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
581 tethering_disabled_cb dcb = NULL;
585 dcb = th->disabled_cb[type];
588 data = th->disabled_user_data[type];
589 g_variant_get(parameters, "(s)", &buf);
590 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
591 code = TETHERING_DISABLED_BY_BT_OFF;
592 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
593 code = TETHERING_DISABLED_BY_TIMEOUT;
595 dcb(TETHERING_ERROR_NONE, type, code, data);
601 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
602 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
603 GVariant *parameters, gpointer user_data)
607 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
609 __tethering_h *th = (__tethering_h *)user_data;
610 tethering_type_e type = 0;
611 tethering_disabled_cb dcb = NULL;
613 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
615 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
616 dcb = th->disabled_cb[type];
619 data = th->disabled_user_data[type];
621 dcb(TETHERING_ERROR_NONE, type, code, data);
626 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
627 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
628 GVariant *parameters, gpointer user_data)
632 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
634 __tethering_h *th = (__tethering_h *)user_data;
635 tethering_type_e type = 0;
636 tethering_disabled_cb dcb = NULL;
638 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
640 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
641 dcb = th->disabled_cb[type];
644 data = th->disabled_user_data[type];
646 dcb(TETHERING_ERROR_NONE, type, code, data);
651 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
652 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
653 GVariant *parameters, gpointer user_data)
657 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
659 __tethering_h *th = (__tethering_h *)user_data;
660 tethering_type_e type = 0;
661 tethering_disabled_cb dcb = NULL;
663 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
665 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
666 dcb = th->disabled_cb[type];
669 data = th->disabled_user_data[type];
671 dcb(TETHERING_ERROR_NONE, type, code, data);
676 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
677 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
678 GVariant *parameters, gpointer user_data)
683 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
684 __tethering_h *th = (__tethering_h *)user_data;
686 tethering_wifi_security_type_changed_cb scb = NULL;
688 tethering_wifi_security_type_e security_type;
691 scb = th->security_type_changed_cb;
695 g_variant_get(parameters, "(s)", &buf);
696 data = th->security_type_user_data;
697 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
698 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
699 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
700 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
701 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
702 security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
703 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_SAE_STR) == 0)
704 security_type = TETHERING_WIFI_SECURITY_TYPE_SAE;
706 SERR("Unknown type : %s\n", buf);
711 scb(security_type, data);
716 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
717 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
718 GVariant *parameters, gpointer user_data)
722 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
723 __tethering_h *th = (__tethering_h *)user_data;
725 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
727 bool visible = false;
730 scb = th->ssid_visibility_changed_cb;
735 g_variant_get(parameters, "(s)", &buf);
736 data = th->ssid_visibility_user_data;
737 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
745 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
746 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
747 GVariant *parameters, gpointer user_data)
751 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
752 __tethering_h *th = (__tethering_h *)user_data;
754 tethering_wifi_passphrase_changed_cb pcb = NULL;
757 pcb = th->passphrase_changed_cb;
761 data = th->passphrase_user_data;
767 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
772 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
773 GError *g_error = NULL;
776 tethering_type_e type = 0;
777 tethering_error_e error;
778 __tethering_h *th = (__tethering_h *)user_data;
780 if (request_table[TETHERING_TYPE_WIFI_SHARING].flag)
781 type = TETHERING_TYPE_WIFI_SHARING;
783 type = TETHERING_TYPE_WIFI;
785 tethering_enabled_cb ecb = th->enabled_cb[type];
786 void *data = th->enabled_user_data[type];
788 if (!_tethering_check_handle((tethering_h)user_data))
791 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
793 ERR("DBus error [%s]\n", g_error->message);
794 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
795 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
796 g_error_free(g_error);
797 tethering_enable((tethering_h)th, type);
799 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
800 error = TETHERING_ERROR_PERMISSION_DENIED;
802 error = TETHERING_ERROR_OPERATION_FAILED;
803 g_error_free(g_error);
805 g_variant_get(g_var, "(u)", &info);
806 error = __get_error(info);
810 INFO("cfm event : wifi tethering enable info : %d\n", error);
812 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
813 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
814 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
815 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
817 SINFO("Tethering enabled event ! error(%d)", error);
823 ecb(error, type, true, data);
824 g_variant_unref(g_var);
828 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
832 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
833 GError *g_error = NULL;
836 tethering_error_e error;
838 __tethering_h *th = (__tethering_h *)user_data;
839 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
840 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
842 if (!_tethering_check_handle((tethering_h)user_data))
845 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
847 ERR("DBus error [%s]\n", g_error->message);
848 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
849 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
850 g_error_free(g_error);
851 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
855 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
856 error = TETHERING_ERROR_PERMISSION_DENIED;
858 error = TETHERING_ERROR_OPERATION_FAILED;
859 g_error_free(g_error);
861 g_variant_get(g_var, "(u)", &info);
862 g_variant_unref(g_var);
863 error = __get_error(info);
867 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
868 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
869 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
870 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
877 ecb(error, TETHERING_TYPE_BT, true, data);
881 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
886 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
887 __tethering_h *th = (__tethering_h *)user_data;
888 GError *g_error = NULL;
891 tethering_error_e error;
892 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
893 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
895 if (!_tethering_check_handle((tethering_h)user_data))
898 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
900 ERR("DBus error [%s]\n", g_error->message);
901 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
902 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
903 g_error_free(g_error);
904 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
908 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
909 error = TETHERING_ERROR_PERMISSION_DENIED;
911 error = TETHERING_ERROR_OPERATION_FAILED;
912 g_error_free(g_error);
914 g_variant_get(g_var, "(u)", &info);
915 g_variant_unref(g_var);
916 error = __get_error(info);
920 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
921 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
922 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
923 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
930 ecb(error, TETHERING_TYPE_USB, true, data);
934 static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
939 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
940 __tethering_h *th = (__tethering_h *)user_data;
941 GError *g_error = NULL;
944 tethering_error_e error;
945 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_P2P];
946 void *data = th->enabled_user_data[TETHERING_TYPE_P2P];
948 if (!_tethering_check_handle((tethering_h)user_data))
951 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
953 ERR("DBus error [%s]\n", g_error->message);
954 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
955 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
956 g_error_free(g_error);
957 tethering_enable((tethering_h)th, TETHERING_TYPE_P2P);
961 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
962 error = TETHERING_ERROR_PERMISSION_DENIED;
964 error = TETHERING_ERROR_OPERATION_FAILED;
965 g_error_free(g_error);
967 g_variant_get(g_var, "(u)", &info);
968 g_variant_unref(g_var);
969 error = __get_error(info);
978 ecb(error, TETHERING_TYPE_P2P, true, data);
982 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
987 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
988 GError *g_error = NULL;
990 guint info, event_type;
991 tethering_error_e error;
992 tethering_type_e type;
993 tethering_h tethering = (tethering_h)user_data;
994 __tethering_h *th = (__tethering_h *)tethering;
995 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
996 tethering_disabled_cb dcb = NULL;
999 if (!_tethering_check_handle((tethering_h)user_data))
1002 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1004 ERR("DBus error [%s]\n", g_error->message);
1005 g_error_free(g_error);
1008 g_variant_get(g_var, "(uu)", &event_type, &info);
1009 INFO("cfm event : %d info : %d\n", event_type, info);
1010 g_variant_unref(g_var);
1011 error = __get_error(info);
1012 INFO("cfm event : %d info : %d\n", event_type, error);
1013 switch (event_type) {
1014 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1015 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1016 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1017 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1018 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1020 type = TETHERING_TYPE_WIFI;
1021 dcb = th->disabled_cb[type];
1022 data = th->disabled_user_data[type];
1024 dcb(error, type, code, data);
1027 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1028 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1029 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1030 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1031 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1033 type = TETHERING_TYPE_BT;
1034 dcb = th->disabled_cb[type];
1035 data = th->disabled_user_data[type];
1037 dcb(error, type, code, data);
1040 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1041 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1042 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1043 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1044 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1046 type = TETHERING_TYPE_USB;
1047 dcb = th->disabled_cb[type];
1048 data = th->disabled_user_data[type];
1050 dcb(error, type, code, data);
1053 case MOBILE_AP_DISABLE_P2P_TETHERING_CFM:
1054 type = TETHERING_TYPE_P2P;
1055 dcb = th->disabled_cb[type];
1056 data = th->disabled_user_data[type];
1058 dcb(error, type, code, data);
1061 case MOBILE_AP_DISABLE_CFM:
1063 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1064 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1065 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1066 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1067 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1068 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1069 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1070 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1071 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1072 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1073 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1074 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1076 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1077 dcb = th->disabled_cb[type];
1080 data = th->disabled_user_data[type];
1082 dcb(error, type, code, data);
1087 ERR("Invalid event\n");
1093 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1098 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1100 GError *g_error = NULL;
1103 guint64 tx_bytes, rx_bytes;
1104 __tethering_h *th = (__tethering_h *)user_data;
1105 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1108 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1110 ERR("DBus fail [%s]\n", g_error->message);
1111 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1112 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1114 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1118 if (th->data_usage_cb == NULL) {
1119 ERR("There is no data_usage_cb\n");
1123 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1125 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1126 th->data_usage_cb(TETHERING_ERROR_NONE,
1127 rx_bytes, tx_bytes, th->data_usage_user_data);
1128 g_variant_unref(g_var);
1130 th->data_usage_cb = NULL;
1131 th->data_usage_user_data = NULL;
1136 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1141 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1142 GError *g_error = NULL;
1145 __tethering_h *th = (__tethering_h *)user_data;
1146 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1148 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1150 ERR("DBus fail [%s]\n", g_error->message);
1151 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1152 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1154 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1155 g_error_free(g_error);
1157 g_variant_get(g_var, "(u)", &info);
1158 if (tethering_error == TETHERING_ERROR_NONE)
1159 tethering_error = __get_error(info);
1160 g_variant_unref(g_var);
1163 if (th->settings_reloaded_cb == NULL) {
1164 DBG("There is no settings_reloaded_cb\n-\n");
1168 th->settings_reloaded_cb(tethering_error,
1169 th->settings_reloaded_user_data);
1171 th->settings_reloaded_cb = NULL;
1172 th->settings_reloaded_user_data = NULL;
1176 static void __connect_signals(tethering_h tethering)
1179 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1181 __tethering_h *th = (__tethering_h *)tethering;
1182 GDBusConnection *connection = th->client_bus;
1185 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1186 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1187 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1188 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1189 sigs[i].cb, tethering, NULL);
1194 static void __disconnect_signals(tethering_h tethering)
1198 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1200 __tethering_h *th = (__tethering_h *)tethering;
1201 GDBusConnection *connection = th->client_bus;
1205 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1206 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1212 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1214 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1217 case TETHERING_TYPE_USB:
1218 g_strlcpy(buf, TETHERING_USB_IF, len);
1220 case TETHERING_TYPE_WIFI:
1221 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1223 case TETHERING_TYPE_BT:
1224 g_strlcpy(buf, TETHERING_BT_IF, len);
1226 case TETHERING_TYPE_P2P:
1227 g_strlcpy(buf, TETHERING_P2P_IF, len);
1230 ERR("Not supported type : %d\n", type);
1236 static bool __get_gateway_addr(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_GATEWAY, len);
1244 case TETHERING_TYPE_WIFI:
1245 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1247 case TETHERING_TYPE_BT:
1248 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1250 case TETHERING_TYPE_P2P:
1251 g_strlcpy(buf, TETHERING_P2P_GATEWAY, len);
1254 ERR("Not supported type : %d\n", type);
1260 static int __get_common_ssid(char *ssid, unsigned int size)
1263 ERR("ssid is null\n");
1264 return TETHERING_ERROR_INVALID_PARAMETER;
1268 if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID, ssid, size))
1269 return TETHERING_ERROR_NONE;
1271 ERR("vconf key get failed for ssid or invalid ssid is found");
1272 #endif /* TIZEN_TV_EXT */
1274 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
1275 ssid, size) == false) {
1276 ERR("vconf_get_str is failed and set default ssid");
1277 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1280 return TETHERING_ERROR_NONE;
1283 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1285 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1288 case TETHERING_WIFI_MODE_TYPE_B:
1289 *buf = g_strdup("b");
1291 case TETHERING_WIFI_MODE_TYPE_G:
1292 *buf = g_strdup("g");
1294 case TETHERING_WIFI_MODE_TYPE_A:
1295 *buf = g_strdup("a");
1297 case TETHERING_WIFI_MODE_TYPE_AD:
1298 *buf = g_strdup("ad");
1301 ERR("Not supported type : %d\n", type);
1307 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1311 __tethering_h *th = (__tethering_h *)tethering;
1312 tethering_error_e ret = TETHERING_ERROR_NONE;
1315 if (th == NULL || set == NULL) {
1316 ERR("null parameter\n-\n");
1317 return TETHERING_ERROR_INVALID_PARAMETER;
1320 if (th->ssid == NULL)
1321 __get_common_ssid(set->ssid, sizeof(set->ssid));
1323 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1325 ret = __get_security_type(&set->sec_type);
1326 if (ret != TETHERING_ERROR_NONE)
1327 set->sec_type = th->sec_type;
1329 ret = __get_visible(&set->visibility);
1330 if (ret != TETHERING_ERROR_NONE)
1331 set->visibility = th->visibility;
1333 set->mac_filter = th->mac_filter;
1334 set->max_connected = th->wifi_max_connected;
1335 set->channel = th->channel;
1336 set->txpower = th->txpower;
1338 __get_wifi_mode_type(th->mode_type, &ptr);
1340 g_strlcpy(set->mode, "", sizeof(set->mode));
1342 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1346 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1347 g_strlcpy(set->key, "", sizeof(set->key));
1349 GDBusProxy *proxy = th->client_bus_proxy;
1350 GVariant *parameters;
1351 GError *error = NULL;
1352 char *passphrase = NULL;
1353 unsigned int len = 0;
1355 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1356 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1359 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1361 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1362 ret = TETHERING_ERROR_PERMISSION_DENIED;
1364 ret = TETHERING_ERROR_OPERATION_FAILED;
1366 g_error_free(error);
1370 if (parameters != NULL) {
1371 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1372 g_strlcpy(set->key, passphrase, sizeof(set->key) - 1);
1374 g_variant_unref(parameters);
1378 INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
1379 set->ssid, set->sec_type, set->mode, set->channel,
1380 (set->visibility) ? "true" : "false");
1382 return TETHERING_ERROR_NONE;
1385 static bool __check_precondition(tethering_type_e type)
1387 int dnet_status = 0;
1388 int cellular_state = 0;
1390 /* data network through cellular */
1391 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1392 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1393 INFO("Data Network can be connected later");
1397 /* data network status */
1398 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
1399 if ((dnet_status == VCONFKEY_NETWORK_WIFI
1400 && type != TETHERING_TYPE_WIFI)
1401 || (dnet_status == VCONFKEY_NETWORK_ETHERNET
1402 && type != TETHERING_TYPE_WIFI_SHARING))
1405 ERR("Network is not available!");
1410 static void __set_vconf_values_for_tv(__tethering_h *tethering)
1412 int ret, channel, txpower;
1413 __tethering_h *th = tethering;
1418 ret = vconf_get_int(VCONFKEY_WIFI_CHANNEL, &channel);
1420 ERR("vconf key get failed for channel !!");
1421 channel = TETHERING_WIFI_CHANNEL;
1424 ret = vconf_get_int(VCONFKEY_WIFI_TXPOWER, &txpower);
1426 ERR("vconf key get failed for txpower !!");
1427 txpower = TETHERING_WIFI_MAX_TXPOWER;
1430 th->channel = channel;
1431 th->txpower = txpower;
1433 #endif /* TIZEN_TV_EXT */
1437 * @brief Creates the handle of tethering.
1439 * @privlevel platform
1440 * @privilege http://tizen.org/privilege/tethering.admin
1441 * @remarks The @a tethering must be released tethering_destroy() by you.
1442 * @param[out] tethering A handle of a new mobile ap handle on success
1443 * @return 0 on success, otherwise a negative error value.
1444 * @retval #TETHERING_ERROR_NONE Successful
1445 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1446 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1447 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1448 * @see tethering_destroy()
1450 API int tethering_create(tethering_h *tethering)
1452 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1453 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1454 "parameter(tethering) is NULL\n");
1457 __tethering_h *th = NULL;
1458 GError *error = NULL;
1459 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1461 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1463 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1464 "malloc is failed\n");
1465 memset(th, 0x00, sizeof(__tethering_h));
1466 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1467 th->visibility = true;
1468 th->mac_filter = false;
1469 th->channel = TETHERING_WIFI_CHANNEL;
1470 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1471 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1472 th->txpower = TETHERING_WIFI_MAX_TXPOWER;
1474 if (__generate_initial_passphrase(th->passphrase,
1475 sizeof(th->passphrase)) == 0) {
1476 ERR("random passphrase generation failed\n");
1478 return TETHERING_ERROR_OPERATION_FAILED;
1481 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1482 ERR("common ssid get failed\n");
1484 return TETHERING_ERROR_OPERATION_FAILED;
1488 __set_vconf_values_for_tv(th);
1489 #endif /* TIZEN_TV_EXT */
1490 SINFO("ssid: %s, key: %s, channel: %d, mode: %d, txpower: %d, security: %d max_device: %d\n",
1491 ssid, th->passphrase, th->channel, th->mode_type, th->txpower, th->sec_type,
1492 th->wifi_max_connected);
1494 #if !GLIB_CHECK_VERSION(2, 36, 0)
1497 GCancellable *cancellable = g_cancellable_new();
1498 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1500 ERR("Couldn't connect to the System bus[%s]", error->message);
1501 g_error_free(error);
1502 g_cancellable_cancel(cancellable);
1503 g_object_unref(cancellable);
1505 return TETHERING_ERROR_OPERATION_FAILED;
1507 th->cancellable = cancellable;
1509 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1510 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1511 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1512 if (!th->client_bus_proxy) {
1514 ERR("Couldn't create the proxy object because of %s\n", error->message);
1515 g_cancellable_cancel(th->cancellable);
1516 g_object_unref(th->cancellable);
1517 g_object_unref(th->client_bus);
1519 return TETHERING_ERROR_OPERATION_FAILED;
1522 __connect_signals((tethering_h)th);
1524 *tethering = (tethering_h)th;
1525 _tethering_add_handle(th);
1526 INFO("Tethering Handle : %p\n", th);
1528 return TETHERING_ERROR_NONE;
1533 * @brief Destroys the handle of tethering.
1535 * @privlevel platform
1536 * @privilege http://tizen.org/privilege/tethering.admin
1537 * @param[in] tethering The handle of tethering
1538 * @return 0 on success, otherwise a negative error value.
1539 * @retval #TETHERING_ERROR_NONE Successful
1540 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1541 * @see tethering_create()
1543 API int tethering_destroy(tethering_h tethering)
1546 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1547 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1548 "parameter(tethering) is NULL\n");
1550 __tethering_h *th = (__tethering_h *)tethering;
1552 INFO("Tethering Handle : %p\n", th);
1554 __disconnect_signals(tethering);
1555 _tethering_remove_handle(th);
1560 g_object_unref(th->cancellable);
1561 g_object_unref(th->client_bus_proxy);
1562 g_object_unref(th->client_bus);
1563 memset(th, 0x00, sizeof(__tethering_h));
1568 return TETHERING_ERROR_NONE;
1573 * @brief Enables the tethering, asynchronously.
1575 * @privlevel platform
1576 * @privilege http://tizen.org/privilege/tethering.admin
1577 * @param[in] tethering The handle of tethering
1578 * @param[in] type The type of tethering
1579 * @return 0 on success, otherwise negative error value.
1580 * @retval #TETHERING_ERROR_NONE Successful
1581 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1582 * @post tethering_enabled_cb() will be invoked.
1583 * @see tethering_is_enabled()
1584 * @see tethering_disable()
1586 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1588 INFO("+ type : %d\n", type);
1589 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1590 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1591 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
1592 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1593 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1595 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1596 "parameter(tethering) is NULL\n");
1598 tethering_error_e ret = TETHERING_ERROR_NONE;
1599 __tethering_h *th = (__tethering_h *)tethering;
1600 GDBusProxy *proxy = th->client_bus_proxy;
1601 GDBusConnection *connection = th->client_bus;
1604 g_dbus_proxy_set_default_timeout(proxy, DBUS_DEFAULT_REPLY_TIMEOUT);
1605 #else /* TIZEN_TV_EXT */
1606 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1607 #endif /* TIZEN_TV_EXT */
1609 if (__check_precondition(type) == FALSE) {
1611 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1612 return TETHERING_ERROR_OPERATION_FAILED;
1616 case TETHERING_TYPE_USB:
1617 g_dbus_connection_signal_unsubscribe(connection,
1618 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1620 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1621 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1622 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1623 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1626 case TETHERING_TYPE_WIFI:
1627 case TETHERING_TYPE_WIFI_SHARING: {
1628 _softap_settings_t set = {"", "", "", 0, false};
1630 ret = __prepare_wifi_settings(tethering, &set);
1631 if (ret != TETHERING_ERROR_NONE) {
1632 ERR("softap settings initialization failed\n");
1634 return TETHERING_ERROR_OPERATION_FAILED;
1636 g_dbus_connection_signal_unsubscribe(connection,
1637 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1639 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
1640 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
1643 char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
1644 if (type == TETHERING_TYPE_WIFI_SHARING) {
1645 g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN);
1646 request_table[TETHERING_TYPE_WIFI_SHARING].flag = true;
1648 g_strlcpy(key, "wifi_tether", TETHERING_WIFI_KEY_MAX_LEN);
1649 request_table[TETHERING_TYPE_WIFI].flag = true;
1652 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1653 g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
1654 set.channel, set.visibility, set.mac_filter, set.max_connected,
1655 set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
1656 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1657 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1661 case TETHERING_TYPE_BT:
1662 g_dbus_connection_signal_unsubscribe(connection,
1663 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1665 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1666 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1667 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1668 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1672 case TETHERING_TYPE_P2P: {
1673 _softap_settings_t p2p_set = {"", "", "", 0, false};
1674 ret = __prepare_wifi_settings(tethering, &p2p_set);
1675 if (ret != TETHERING_ERROR_NONE) {
1676 ERR("p2p settings initialization failed\n");
1677 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1679 return TETHERING_ERROR_OPERATION_FAILED;
1682 g_dbus_proxy_call(proxy, "enable_p2p_tethering",
1683 g_variant_new("(ssi)", p2p_set.ssid, p2p_set.key, p2p_set.channel),
1684 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1685 (GAsyncReadyCallback) __p2p_enabled_cfm_cb, (gpointer)tethering);
1689 case TETHERING_TYPE_ALL: {
1690 _softap_settings_t set = {"", "", "", 0, false};
1692 ret = __prepare_wifi_settings(tethering, &set);
1693 if (ret != TETHERING_ERROR_NONE) {
1694 ERR("softap settings initialization failed\n");
1695 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1696 return TETHERING_ERROR_OPERATION_FAILED;
1699 /* TETHERING_TYPE_USB */
1700 g_dbus_connection_signal_unsubscribe(connection,
1701 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1703 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1704 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1705 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1706 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1708 /* TETHERING_TYPE_WIFI */
1709 g_dbus_connection_signal_unsubscribe(connection,
1710 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1712 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1713 g_variant_new("(ssssiiiiiii)", "wifi_tether", set.ssid, set.key, set.mode,
1714 set.channel, set.visibility, set.mac_filter, set.max_connected,
1715 set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
1716 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1717 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1719 /* TETHERING_TYPE_BT */
1720 g_dbus_connection_signal_unsubscribe(connection,
1721 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1723 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1724 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1725 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1726 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1730 ERR("Unknown type : %d\n", type);
1732 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1735 return TETHERING_ERROR_INVALID_PARAMETER;
1738 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1740 return TETHERING_ERROR_NONE;
1743 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1745 DBG("+ type : %d\n", type);
1746 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1747 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1748 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1749 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1751 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1752 "parameter(tethering) is NULL\n");
1754 __tethering_h *th = (__tethering_h *)tethering;
1755 GDBusProxy *proxy = th->client_bus_proxy;
1756 GDBusConnection *connection = th->client_bus;
1759 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1761 if (__check_precondition(type) == FALSE) {
1763 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1764 return TETHERING_ERROR_OPERATION_FAILED;
1768 case TETHERING_TYPE_USB: {
1769 g_dbus_connection_signal_unsubscribe(connection,
1770 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1772 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1773 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1774 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1775 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1779 case TETHERING_TYPE_WIFI:
1780 case TETHERING_TYPE_WIFI_SHARING: {
1781 _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
1783 ret = __prepare_wifi_settings(tethering, &set);
1784 if (ret != TETHERING_ERROR_NONE) {
1785 ERR("softap settings initialization failed\n");
1787 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1788 return TETHERING_ERROR_OPERATION_FAILED;
1790 g_dbus_connection_signal_unsubscribe(connection,
1791 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1793 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
1794 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
1797 char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, };
1798 if (type == TETHERING_TYPE_WIFI_SHARING) {
1799 g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN);
1800 request_table[TETHERING_TYPE_WIFI_SHARING].flag = true;
1802 g_strlcpy(key, "wifi_tether", TETHERING_WIFI_KEY_MAX_LEN);
1803 request_table[TETHERING_TYPE_WIFI_SHARING].flag = true;
1806 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1807 g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode,
1808 set.channel, set.visibility, set.mac_filter, set.max_connected,
1809 set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV6),
1810 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1811 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1815 case TETHERING_TYPE_BT: {
1816 g_dbus_connection_signal_unsubscribe(connection,
1817 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1819 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1820 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1821 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1822 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1828 ERR("Unknown type : %d\n", type);
1830 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1833 return TETHERING_ERROR_INVALID_PARAMETER;
1837 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1839 return TETHERING_ERROR_NONE;
1842 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
1844 DBG("+ type : %d\n", type);
1845 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1846 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1847 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1848 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1850 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1851 "parameter(tethering) is NULL\n");
1853 __tethering_h *th = (__tethering_h *)tethering;
1854 GDBusProxy *proxy = th->client_bus_proxy;
1855 GDBusConnection *connection = th->client_bus;
1858 case TETHERING_TYPE_USB:
1859 g_dbus_connection_signal_unsubscribe(connection,
1860 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1862 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1863 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1864 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1865 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1868 case TETHERING_TYPE_WIFI:
1869 case TETHERING_TYPE_WIFI_SHARING:
1870 DBG("Disable wifi tethering..");
1871 g_dbus_connection_signal_unsubscribe(connection,
1872 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1874 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1875 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1876 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1877 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1880 case TETHERING_TYPE_BT:
1881 g_dbus_connection_signal_unsubscribe(connection,
1882 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1884 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1885 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1886 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1887 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1891 ERR("Not supported tethering type [%d]\n", type);
1893 return TETHERING_ERROR_INVALID_PARAMETER;
1896 return TETHERING_ERROR_NONE;
1900 * @brief Disables the tethering, asynchronously.
1902 * @privlevel platform
1903 * @privilege http://tizen.org/privilege/tethering.admin
1904 * @param[in] tethering The handle of tethering
1905 * @param[in] type The type of tethering
1906 * @return 0 on success, otherwise negative error value.
1907 * @retval #TETHERING_ERROR_NONE Successful
1908 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1909 * @post tethering_disabled_cb() will be invoked.
1910 * @see tethering_is_enabled()
1911 * @see tethering_enable()
1913 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1915 INFO("+ type : %d\n", type);
1916 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1917 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1918 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1919 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1921 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1922 "parameter(tethering) is NULL\n");
1924 __tethering_h *th = (__tethering_h *)tethering;
1925 GDBusProxy *proxy = th->client_bus_proxy;
1926 GDBusConnection *connection = th->client_bus;
1929 case TETHERING_TYPE_USB:
1930 g_dbus_connection_signal_unsubscribe(connection,
1931 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1933 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1934 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1935 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1936 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1940 case TETHERING_TYPE_WIFI:
1941 case TETHERING_TYPE_WIFI_SHARING:
1943 g_dbus_connection_signal_unsubscribe(connection,
1944 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1946 SINFO("Disable Wi-Fi Tethering !");
1948 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1949 g_variant_new("(ii)", TETHERING_ADDRESS_FAMILY_IPV4, th->mode_type),
1950 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1951 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1954 case TETHERING_TYPE_BT:
1956 g_dbus_connection_signal_unsubscribe(connection,
1957 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1959 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1960 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1961 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1962 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1965 case TETHERING_TYPE_P2P:
1966 g_dbus_proxy_call(proxy, "disable_p2p_tethering",
1967 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1968 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1971 case TETHERING_TYPE_ALL:
1972 g_dbus_connection_signal_unsubscribe(connection,
1973 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1975 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1976 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1977 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1978 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1980 g_dbus_connection_signal_unsubscribe(connection,
1981 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1983 g_dbus_proxy_call(proxy, "disable_wifi_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);
1988 g_dbus_connection_signal_unsubscribe(connection,
1989 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1991 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1992 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1993 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1994 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1998 ERR("Not supported tethering type [%d]\n", type);
2000 return TETHERING_ERROR_INVALID_PARAMETER;
2003 return TETHERING_ERROR_NONE;
2008 * @brief Checks whetehr the tethering is enabled or not.
2010 * @privlevel platform
2011 * @privilege http://tizen.org/privilege/tethering.admin
2012 * @param[in] tethering The handle of tethering
2013 * @param[in] type The type of tethering
2014 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
2016 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
2018 INFO("+ type : %d\n", type);
2020 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
2022 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2024 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
2028 case TETHERING_TYPE_USB:
2029 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
2032 case TETHERING_TYPE_WIFI:
2033 case TETHERING_TYPE_WIFI_SHARING:
2034 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
2037 case TETHERING_TYPE_BT:
2038 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
2041 case TETHERING_TYPE_P2P:
2042 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_P2P;
2046 ERR("Not supported type : %d\n", type);
2049 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
2050 return is_on & vconf_type ? true : false;
2055 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
2057 * @privlevel platform
2058 * @privilege http://tizen.org/privilege/tethering.admin
2059 * @remarks @a mac_address must be released with free() by you.
2060 * @param[in] tethering The handle of tethering
2061 * @param[in] type The type of tethering
2062 * @param[out] mac_address The MAC address
2063 * @return 0 on success, otherwise a negative error value.
2064 * @retval #TETHERING_ERROR_NONE Successful
2065 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2066 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2067 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2068 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2069 * @pre tethering must be enabled.
2070 * @see tethering_is_enabled()
2071 * @see tethering_enable()
2073 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
2075 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2076 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2077 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2078 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2080 _retvm_if(tethering_is_enabled(tethering, type) == false,
2081 TETHERING_ERROR_NOT_ENABLED,
2082 "tethering type[%d] is not enabled\n", type);
2083 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2084 "parameter(tethering) is NULL\n");
2085 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2086 "parameter(mac_address) is NULL\n");
2090 char *macbuf = NULL;
2092 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2093 TETHERING_ERROR_OPERATION_FAILED,
2094 "getting interface name is failed\n");
2096 s = socket(AF_INET, SOCK_DGRAM, 0);
2097 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2098 "getting socket is failed\n");
2099 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2100 ERR("getting mac is failed\n");
2102 return TETHERING_ERROR_OPERATION_FAILED;
2106 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
2107 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2108 "Not enough memory\n");
2109 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
2110 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
2111 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
2112 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
2113 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
2114 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
2115 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
2117 *mac_address = macbuf;
2119 return TETHERING_ERROR_NONE;
2124 * @brief Gets the name of network interface. For example, usb0.
2126 * @privlevel platform
2127 * @privilege http://tizen.org/privilege/tethering.admin
2128 * @remarks @a interface_name must be released with free() by you.
2129 * @param[in] tethering The handle of tethering
2130 * @param[in] type The type of tethering
2131 * @param[out] interface_name The name of network interface
2132 * @return 0 on success, otherwise negative error value.
2133 * @retval #TETHERING_ERROR_NONE Successful
2134 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2135 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2136 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2137 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2138 * @pre tethering must be enabled.
2139 * @see tethering_is_enabled()
2140 * @see tethering_enable()
2142 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
2144 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2145 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2146 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2147 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2149 _retvm_if(tethering_is_enabled(tethering, type) == false,
2150 TETHERING_ERROR_NOT_ENABLED,
2151 "tethering type[%d] is not enabled\n", type);
2152 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2153 "parameter(tethering) is NULL\n");
2154 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2155 "parameter(interface_name) is NULL\n");
2157 char intf[TETHERING_STR_INFO_LEN] = {0, };
2159 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2160 TETHERING_ERROR_OPERATION_FAILED,
2161 "getting interface name is failed\n");
2162 *interface_name = strdup(intf);
2163 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2164 "Not enough memory\n");
2166 return TETHERING_ERROR_NONE;
2171 * @brief Gets the local IP address.
2173 * @privlevel platform
2174 * @privilege http://tizen.org/privilege/tethering.admin
2175 * @remarks @a ip_address must be released with free() by you.
2176 * @param[in] tethering The handle of tethering
2177 * @param[in] type The type of tethering
2178 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2179 * @param[out] ip_address The local IP address
2180 * @return 0 on success, otherwise negative error value.
2181 * @retval #TETHERING_ERROR_NONE Successful
2182 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2183 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2184 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2185 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2186 * @pre tethering must be enabled.
2187 * @see tethering_is_enabled()
2188 * @see tethering_enable()
2190 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2192 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2193 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2194 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2195 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2197 _retvm_if(tethering_is_enabled(tethering, type) == false,
2198 TETHERING_ERROR_NOT_ENABLED,
2199 "tethering type[%d] is not enabled\n", type);
2200 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2201 "parameter(tethering) is NULL\n");
2202 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2203 "parameter(ip_address) is NULL\n");
2209 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2210 TETHERING_ERROR_OPERATION_FAILED,
2211 "getting interface name is failed\n");
2213 s = socket(AF_INET, SOCK_DGRAM, 0);
2214 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2215 "getting socket is failed\n");
2216 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2217 ERR("ioctl is failed\n");
2219 return TETHERING_ERROR_OPERATION_FAILED;
2223 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2224 *ip_address = strdup(ipbuf);
2225 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2226 "Not enough memory\n");
2228 return TETHERING_ERROR_NONE;
2233 * @brief Gets the Gateway address.
2235 * @privlevel platform
2236 * @privilege http://tizen.org/privilege/tethering.admin
2237 * @remarks @a gateway_address must be released with free() by you.
2238 * @param[in] tethering The handle of tethering
2239 * @param[in] type The type of tethering
2240 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2241 * @param[out] gateway_address The local IP address
2242 * @return 0 on success, otherwise negative error value.
2243 * @retval #TETHERING_ERROR_NONE Successful
2244 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2245 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2246 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2247 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2248 * @pre tethering must be enabled.
2249 * @see tethering_is_enabled()
2250 * @see tethering_enable()
2252 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2254 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2255 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2256 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2257 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2259 _retvm_if(tethering_is_enabled(tethering, type) == false,
2260 TETHERING_ERROR_NOT_ENABLED,
2261 "tethering type[%d] is not enabled\n", type);
2262 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2263 "parameter(tethering) is NULL\n");
2264 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2265 "parameter(gateway_address) is NULL\n");
2267 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2269 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2270 TETHERING_ERROR_OPERATION_FAILED,
2271 "getting gateway address is failed\n");
2273 *gateway_address = strdup(gateway_buf);
2275 return TETHERING_ERROR_NONE;
2280 * @brief Gets the Subnet Mask.
2282 * @privlevel platform
2283 * @privilege http://tizen.org/privilege/tethering.admin
2284 * @remarks @a subnet_mask must be released with free() by you.
2285 * @param[in] tethering The handle of tethering
2286 * @param[in] type The type of tethering
2287 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2288 * @param[out] subnet_mask The local IP address
2289 * @return 0 on success, otherwise negative error value.
2290 * @retval #TETHERING_ERROR_NONE Successful
2291 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2292 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2293 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2294 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2295 * @pre tethering must be enabled.
2296 * @see tethering_is_enabled()
2297 * @see tethering_enable()
2299 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2301 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2302 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2303 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2304 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2306 _retvm_if(tethering_is_enabled(tethering, type) == false,
2307 TETHERING_ERROR_NOT_ENABLED,
2308 "tethering is not enabled\n");
2309 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2310 "parameter(tethering) is NULL\n");
2311 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2312 "parameter(subnet_mask) is NULL\n");
2314 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2315 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2316 "Not enough memory\n");
2318 return TETHERING_ERROR_NONE;
2323 * @brief Gets the data usage.
2325 * @privlevel platform
2326 * @privilege http://tizen.org/privilege/tethering.admin
2327 * @param[in] tethering The handle of tethering
2328 * @param[out] usage The data usage
2329 * @return 0 on success, otherwise negative error value.
2330 * @retval #TETHERING_ERROR_NONE Successful
2331 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2332 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2333 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2334 * @pre tethering must be enabled.
2335 * @see tethering_is_enabled()
2336 * @see tethering_enable()
2338 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2340 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2342 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2343 "parameter(tethering) is NULL\n");
2344 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2345 "parameter(callback) is NULL\n");
2346 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2347 TETHERING_ERROR_NOT_ENABLED,
2348 "tethering is not enabled\n");
2350 __tethering_h *th = (__tethering_h *)tethering;
2351 GDBusProxy *proxy = th->client_bus_proxy;
2353 th->data_usage_cb = callback;
2354 th->data_usage_user_data = user_data;
2356 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2357 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2358 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2360 return TETHERING_ERROR_NONE;
2365 * @brief Gets the client which is connected by tethering "type".
2367 * @privlevel platform
2368 * @privilege http://tizen.org/privilege/tethering.admin
2369 * @param[in] tethering The handle of tethering
2370 * @param[in] type The type of tethering
2371 * @param[in] callback The callback function to invoke
2372 * @param[in] user_data The user data to be passed to the callback function
2373 * @retval #TETHERING_ERROR_NONE Successful
2374 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2375 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2376 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2377 * @pre tethering must be enabled.
2378 * @see tethering_is_enabled()
2379 * @see tethering_enable()
2381 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2383 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2384 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2385 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2386 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2387 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2389 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2390 "parameter(tethering) is NULL\n");
2391 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2392 "parameter(callback) is NULL\n");
2393 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2394 TETHERING_ERROR_NOT_ENABLED,
2395 "tethering is not enabled\n");
2397 mobile_ap_type_e interface;
2398 __tethering_h *th = (__tethering_h *)tethering;
2399 __tethering_client_h client = {0, };
2402 gchar *hostname = NULL;
2403 guint timestamp = 0;
2404 GError *error = NULL;
2405 GVariant *result = NULL;
2406 GVariantIter *outer_iter = NULL;
2407 GVariantIter *inner_iter = NULL;
2408 GVariant *station = NULL;
2409 GVariant *value = NULL;
2412 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2413 NULL, G_DBUS_CALL_FLAGS_NONE,
2414 -1, th->cancellable, &error);
2417 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2418 g_error_free(error);
2419 return TETHERING_ERROR_OPERATION_FAILED;
2422 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2423 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2424 g_variant_get(station, "a{sv}", &inner_iter);
2425 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2426 if (g_strcmp0(key, "Type") == 0) {
2427 interface = g_variant_get_int32(value);
2428 if (interface == MOBILE_AP_TYPE_USB)
2429 client.interface = TETHERING_TYPE_USB;
2430 else if (interface == MOBILE_AP_TYPE_WIFI) {
2431 if (request_table[TETHERING_TYPE_WIFI_SHARING].flag)
2432 client.interface = TETHERING_TYPE_WIFI_SHARING;
2434 client.interface = TETHERING_TYPE_WIFI;
2436 } else if (interface == MOBILE_AP_TYPE_BT)
2437 client.interface = TETHERING_TYPE_BT;
2438 else if (interface == MOBILE_AP_TYPE_P2P)
2439 client.interface = TETHERING_TYPE_P2P;
2441 ERR("Invalid interface\n");
2443 g_variant_unref(value);
2446 DBG("interface is %d\n", client.interface);
2447 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2449 g_variant_unref(value);
2452 } else if (g_strcmp0(key, "IP") == 0) {
2453 g_variant_get(value, "s", &ip);
2454 SDBG("ip is %s\n", ip);
2455 g_strlcpy(client.ip, ip, sizeof(client.ip));
2456 } else if (g_strcmp0(key, "MAC") == 0) {
2457 g_variant_get(value, "s", &mac);
2458 SDBG("mac is %s\n", mac);
2459 g_strlcpy(client.mac, mac, sizeof(client.mac));
2460 } else if (g_strcmp0(key, "Name") == 0) {
2461 g_variant_get(value, "s", &hostname);
2462 SDBG("hsotname is %s\n", hostname);
2464 client.hostname = g_strdup(hostname);
2465 } else if (g_strcmp0(key, "Time") == 0) {
2466 timestamp = g_variant_get_int32(value);
2467 DBG("timestamp is %d\n", timestamp);
2468 client.tm = (time_t)timestamp;
2470 ERR("Key %s not required\n", key);
2481 g_variant_iter_free(inner_iter);
2482 if (callback((tethering_client_h)&client, user_data) == false) {
2483 DBG("iteration is stopped\n");
2484 g_free(client.hostname);
2485 client.hostname = NULL;
2486 g_variant_iter_free(outer_iter);
2487 g_variant_unref(result);
2489 return TETHERING_ERROR_OPERATION_FAILED;
2491 g_free(client.hostname);
2492 client.hostname = NULL;
2494 g_variant_iter_free(outer_iter);
2495 g_variant_unref(result);
2497 return TETHERING_ERROR_NONE;
2502 * @brief Registers the callback function called when tethering is enabled.
2504 * @privlevel platform
2505 * @privilege http://tizen.org/privilege/tethering.admin
2506 * @param[in] tethering The handle of tethering
2507 * @param[in] type The type of tethering
2508 * @param[in] callback The callback function to invoke
2509 * @param[in] user_data The user data to be passed to the callback function
2510 * @retval #TETHERING_ERROR_NONE Successful
2511 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2512 * @see tethering_unset_enabled_cb()
2514 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2516 INFO("+ type: %d\n", type);
2517 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2518 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2519 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2520 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2521 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2523 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2524 "parameter(tethering) is NULL\n");
2525 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2526 "parameter(callback) is NULL\n");
2528 __tethering_h *th = (__tethering_h *)tethering;
2529 tethering_type_e ti;
2531 if (type != TETHERING_TYPE_ALL) {
2532 th->enabled_cb[type] = callback;
2533 th->enabled_user_data[type] = user_data;
2535 return TETHERING_ERROR_NONE;
2538 /* TETHERING_TYPE_ALL */
2539 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2540 th->enabled_cb[ti] = callback;
2541 th->enabled_user_data[ti] = user_data;
2545 return TETHERING_ERROR_NONE;
2550 * @brief Unregisters the callback function called when tethering is disabled.
2552 * @privlevel platform
2553 * @privilege http://tizen.org/privilege/tethering.admin
2554 * @param[in] tethering The handle of tethering
2555 * @param[in] type The type of tethering
2556 * @retval #TETHERING_ERROR_NONE Successful
2557 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2558 * @see tethering_set_enabled_cb()
2560 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2562 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2563 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2564 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2565 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2566 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2568 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2569 "parameter(tethering) is NULL\n");
2571 __tethering_h *th = (__tethering_h *)tethering;
2572 tethering_type_e ti;
2574 if (type != TETHERING_TYPE_ALL) {
2575 th->enabled_cb[type] = NULL;
2576 th->enabled_user_data[type] = NULL;
2578 return TETHERING_ERROR_NONE;
2581 /* TETHERING_TYPE_ALL */
2582 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2583 th->enabled_cb[ti] = NULL;
2584 th->enabled_user_data[ti] = NULL;
2587 return TETHERING_ERROR_NONE;
2592 * @brief Registers the callback function called when tethering is disabled.
2594 * @privlevel platform
2595 * @privilege http://tizen.org/privilege/tethering.admin
2596 * @param[in] tethering The handle of tethering
2597 * @param[in] type The type of tethering
2598 * @param[in] callback The callback function to invoke
2599 * @param[in] user_data The user data to be passed to the callback function
2600 * @retval #TETHERING_ERROR_NONE Successful
2601 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2602 * @see tethering_unset_disabled_cb()
2604 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2606 INFO("+ type: %d\n", type);
2607 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2608 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2609 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2610 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2611 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2613 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2614 "parameter(tethering) is NULL\n");
2615 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2616 "parameter(callback) is NULL\n");
2618 __tethering_h *th = (__tethering_h *)tethering;
2619 tethering_type_e ti;
2621 if (type != TETHERING_TYPE_ALL) {
2622 th->disabled_cb[type] = callback;
2623 th->disabled_user_data[type] = user_data;
2625 return TETHERING_ERROR_NONE;
2628 /* TETHERING_TYPE_ALL */
2629 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2630 th->disabled_cb[ti] = callback;
2631 th->disabled_user_data[ti] = user_data;
2634 return TETHERING_ERROR_NONE;
2639 * @brief Unregisters the callback function called when tethering is disabled.
2641 * @privlevel platform
2642 * @privilege http://tizen.org/privilege/tethering.admin
2643 * @param[in] tethering The handle of tethering
2644 * @param[in] type The type of tethering
2645 * @retval #TETHERING_ERROR_NONE Successful
2646 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2647 * @see tethering_set_disabled_cb()
2649 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2651 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2652 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2653 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2654 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2655 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2657 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2658 "parameter(tethering) is NULL\n");
2660 __tethering_h *th = (__tethering_h *)tethering;
2661 tethering_type_e ti;
2663 if (type != TETHERING_TYPE_ALL) {
2664 th->disabled_cb[type] = NULL;
2665 th->disabled_user_data[type] = NULL;
2667 return TETHERING_ERROR_NONE;
2670 /* TETHERING_TYPE_ALL */
2671 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2672 th->disabled_cb[ti] = NULL;
2673 th->disabled_user_data[ti] = NULL;
2676 return TETHERING_ERROR_NONE;
2681 * @brief Registers the callback function called when the state of connection is changed.
2683 * @privlevel platform
2684 * @privilege http://tizen.org/privilege/tethering.admin
2685 * @param[in] tethering The handle of tethering
2686 * @param[in] type The type of tethering
2687 * @param[in] callback The callback function to invoke
2688 * @param[in] user_data The user data to be passed to the callback function
2689 * @retval #TETHERING_ERROR_NONE Successful
2690 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2691 * @see tethering_unset_connection_state_changed_cb_cb()
2693 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2695 INFO("+ type: %d\n", type);
2696 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2697 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2698 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2699 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2700 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2702 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2703 "parameter(tethering) is NULL\n");
2704 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2705 "parameter(callback) is NULL\n");
2707 __tethering_h *th = (__tethering_h *)tethering;
2708 tethering_type_e ti;
2710 if (type != TETHERING_TYPE_ALL) {
2711 th->changed_cb[type] = callback;
2712 th->changed_user_data[type] = user_data;
2714 return TETHERING_ERROR_NONE;
2717 /* TETHERING_TYPE_ALL */
2718 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2719 th->changed_cb[ti] = callback;
2720 th->changed_user_data[ti] = user_data;
2723 return TETHERING_ERROR_NONE;
2728 * @brief Unregisters the callback function called when the state of connection is changed.
2730 * @privlevel platform
2731 * @privilege http://tizen.org/privilege/tethering.admin
2732 * @param[in] tethering The handle of tethering
2733 * @param[in] type The type of tethering
2734 * @retval #TETHERING_ERROR_NONE Successful
2735 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2736 * @see tethering_set_connection_state_changed_cb()
2738 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2740 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2741 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2742 else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
2743 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2744 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2746 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2747 "parameter(tethering) is NULL\n");
2749 __tethering_h *th = (__tethering_h *)tethering;
2750 tethering_type_e ti;
2752 if (type != TETHERING_TYPE_ALL) {
2753 th->changed_cb[type] = NULL;
2754 th->changed_user_data[type] = NULL;
2756 return TETHERING_ERROR_NONE;
2759 /* TETHERING_TYPE_ALL */
2760 for (ti = TETHERING_TYPE_USB; ti < TETHERING_TYPE_MAX; ti++) {
2761 th->changed_cb[ti] = NULL;
2762 th->changed_user_data[ti] = NULL;
2765 return TETHERING_ERROR_NONE;
2770 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2772 * @privlevel platform
2773 * @privilege http://tizen.org/privilege/tethering.admin
2774 * @param[in] tethering The handle of tethering
2775 * @param[in] callback The callback function to invoke
2776 * @param[in] user_data The user data to be passed to the callback function
2777 * @retval #TETHERING_ERROR_NONE Successful
2778 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2779 * @see tethering_wifi_unset_security_type_changed_cb()
2781 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2783 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2784 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2786 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2787 "parameter(tethering) is NULL\n");
2788 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2789 "parameter(callback) is NULL\n");
2791 __tethering_h *th = (__tethering_h *)tethering;
2793 th->security_type_changed_cb = callback;
2794 th->security_type_user_data = user_data;
2796 return TETHERING_ERROR_NONE;
2802 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2804 * @privlevel platform
2805 * @privilege http://tizen.org/privilege/tethering.admin
2806 * @param[in] tethering The handle of tethering
2807 * @param[in] type The type of tethering
2808 * @retval #TETHERING_ERROR_NONE Successful
2809 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2810 * @see tethering_wifi_set_security_type_changed_cb()
2812 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2814 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2815 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2817 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2818 "parameter(tethering) is NULL\n");
2820 __tethering_h *th = (__tethering_h *)tethering;
2822 th->security_type_changed_cb = NULL;
2823 th->security_type_user_data = NULL;
2825 return TETHERING_ERROR_NONE;
2830 * @brief Registers the callback function called when the visibility of SSID is changed.
2832 * @privlevel platform
2833 * @privilege http://tizen.org/privilege/tethering.admin
2834 * @param[in] tethering The handle of tethering
2835 * @param[in] callback The callback function to invoke
2836 * @param[in] user_data The user data to be passed to the callback function
2837 * @retval #TETHERING_ERROR_NONE Successful
2838 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2839 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2841 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2843 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2844 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2846 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2847 "parameter(tethering) is NULL\n");
2848 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2849 "parameter(callback) is NULL\n");
2851 __tethering_h *th = (__tethering_h *)tethering;
2853 th->ssid_visibility_changed_cb = callback;
2854 th->ssid_visibility_user_data = user_data;
2856 return TETHERING_ERROR_NONE;
2861 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2863 * @privlevel platform
2864 * @privilege http://tizen.org/privilege/tethering.admin
2865 * @param[in] tethering The handle of tethering
2866 * @retval #TETHERING_ERROR_NONE Successful
2867 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2868 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2870 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2872 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2873 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2875 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2876 "parameter(tethering) is NULL\n");
2878 __tethering_h *th = (__tethering_h *)tethering;
2880 th->ssid_visibility_changed_cb = NULL;
2881 th->ssid_visibility_user_data = NULL;
2883 return TETHERING_ERROR_NONE;
2888 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2890 * @privlevel platform
2891 * @privilege http://tizen.org/privilege/tethering.admin
2892 * @param[in] tethering The handle of tethering
2893 * @param[in] callback The callback function to invoke
2894 * @param[in] user_data The user data to be passed to the callback function
2895 * @retval #TETHERING_ERROR_NONE Successful
2896 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2897 * @see tethering_wifi_unset_passphrase_changed_cb()
2899 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2901 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2902 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2904 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2905 "parameter(tethering) is NULL\n");
2906 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2907 "parameter(callback) is NULL\n");
2909 __tethering_h *th = (__tethering_h *)tethering;
2911 th->passphrase_changed_cb = callback;
2912 th->passphrase_user_data = user_data;
2914 return TETHERING_ERROR_NONE;
2919 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2921 * @privlevel platform
2922 * @privilege http://tizen.org/privilege/tethering.admin
2923 * @param[in] tethering The handle of tethering
2924 * @retval #TETHERING_ERROR_NONE Successful
2925 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2926 * @see tethering_wifi_set_passphrase_changed_cb()
2928 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2930 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2931 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2933 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2934 "parameter(tethering) is NULL\n");
2936 __tethering_h *th = (__tethering_h *)tethering;
2938 th->passphrase_changed_cb = NULL;
2939 th->passphrase_user_data = NULL;
2941 return TETHERING_ERROR_NONE;
2946 * @brief Sets the security type of Wi-Fi tethering.
2948 * @privlevel platform
2949 * @privilege http://tizen.org/privilege/tethering.admin
2950 * @remarks This change is applied next time Wi-Fi tethering is enabled
2951 * @param[in] tethering The handle of tethering
2952 * @param[in] type The security type
2953 * @return 0 on success, otherwise negative error value.
2954 * @retval #TETHERING_ERROR_NONE Successful
2955 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2956 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2957 * @see tethering_wifi_get_security_type()
2959 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2961 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2962 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2964 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2965 "parameter(tethering) is NULL\n");
2967 __tethering_h *th = (__tethering_h *)tethering;
2968 tethering_error_e ret = TETHERING_ERROR_NONE;
2969 char *sec_str = NULL;
2971 ret = __set_security_type(type);
2972 if (ret == TETHERING_ERROR_NONE) {
2974 case TETHERING_WIFI_SECURITY_TYPE_NONE:
2975 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
2977 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
2978 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
2980 case TETHERING_WIFI_SECURITY_TYPE_WPS:
2981 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
2983 case TETHERING_WIFI_SECURITY_TYPE_SAE:
2984 sec_str = TETHERING_WIFI_SECURITY_TYPE_SAE_STR;
2988 __send_dbus_signal(th->client_bus,
2989 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
2996 * @brief Gets the security type of Wi-Fi tethering.
2998 * @privlevel platform
2999 * @privilege http://tizen.org/privilege/tethering.admin
3000 * @param[in] tethering The handle of tethering
3001 * @param[out] type The security type
3002 * @return 0 on success, otherwise negative error value.
3003 * @retval #TETHERING_ERROR_NONE Successful
3004 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3005 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3006 * @see tethering_wifi_set_security_type()
3008 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
3010 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3011 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3013 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3014 "parameter(tethering) is NULL\n");
3015 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3016 "parameter(type) is NULL\n");
3018 return __get_security_type(type);
3023 * @brief Sets the SSID (service set identifier).
3025 * @privlevel platform
3026 * @privilege http://tizen.org/privilege/tethering.admin
3027 * @details If SSID is not set, Device name is used as SSID
3028 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
3029 * @param[in] tethering The handle of tethering
3030 * @param[out] ssid The SSID
3031 * @return 0 on success, otherwise negative error value.
3032 * @retval #TETHERING_ERROR_NONE Successful
3033 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3034 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3036 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
3038 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3039 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3041 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3042 "parameter(tethering) is NULL\n");
3043 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3044 "parameter(ssid) is NULL\n");
3046 __tethering_h *th = (__tethering_h *)tethering;
3047 char *p_ssid = NULL;
3050 ssid_len = strlen(ssid);
3051 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
3052 ERR("parameter(ssid) is too long");
3053 return TETHERING_ERROR_INVALID_PARAMETER;
3056 p_ssid = strdup(ssid);
3057 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
3058 "strdup is failed\n");
3061 GDBusProxy *proxy = th->client_bus_proxy;
3062 GVariant *parameters;
3063 GError *error = NULL;
3064 tethering_error_e ret = TETHERING_ERROR_NONE;
3066 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_ssid",
3067 g_variant_new("(s)", ssid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3070 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3072 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3073 ret = TETHERING_ERROR_PERMISSION_DENIED;
3075 ret = TETHERING_ERROR_OPERATION_FAILED;
3077 g_error_free(error);
3081 if (parameters != NULL) {
3082 g_variant_get(parameters, "(u)", &ret);
3083 g_variant_unref(parameters);
3086 SINFO("set tethering ssid : %s", ssid);
3087 #endif /* TIZEN_TV_EXT */
3093 return TETHERING_ERROR_NONE;
3098 * @brief Gets the SSID (service set identifier).
3100 * @privlevel platform
3101 * @privilege http://tizen.org/privilege/tethering.admin
3102 * @remarks @a ssid must be released with free() by you.
3103 * @param[in] tethering The handle of tethering
3104 * @param[out] ssid The SSID
3105 * @return 0 on success, otherwise negative error value.
3106 * @retval #TETHERING_ERROR_NONE Successful
3107 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3108 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3109 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3111 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
3113 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3114 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3116 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3117 "parameter(tethering) is NULL\n");
3118 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3119 "parameter(ssid) is NULL\n");
3122 __tethering_h *th = (__tethering_h *)tethering;
3123 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
3126 if (__get_ssid_from_vconf(VCONFKEY_WIFI_SSID,
3127 val, sizeof(val)) == true) {
3128 *ssid = strdup(val);
3129 SINFO("get tethering ssid : %s", *ssid);
3130 return TETHERING_ERROR_NONE;
3132 #endif /* TIZEN_TV_EXT */
3134 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
3135 if (th->ssid != NULL) {
3136 DBG("Private SSID is set\n");
3137 *ssid = strdup(th->ssid);
3139 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
3140 val, sizeof(val)) == false) {
3141 return TETHERING_ERROR_OPERATION_FAILED;
3143 *ssid = strdup(val);
3146 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
3147 val, sizeof(val)) == false) {
3148 return TETHERING_ERROR_OPERATION_FAILED;
3150 *ssid = strdup(val);
3153 if (*ssid == NULL) {
3154 ERR("strdup is failed\n");
3155 return TETHERING_ERROR_OUT_OF_MEMORY;
3158 return TETHERING_ERROR_NONE;
3163 * @brief Sets the visibility of SSID(service set identifier).
3165 * @privlevel platform
3166 * @privilege http://tizen.org/privilege/tethering.admin
3167 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3168 * @remarks This change is applied next time Wi-Fi tethering is enabled
3169 * @param[in] tethering The handle of tethering
3170 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3171 * @return 0 on success, otherwise negative error value.
3172 * @retval #TETHERING_ERROR_NONE Successful
3173 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3174 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3175 * @see tethering_wifi_get_ssid_visibility()
3177 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
3179 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3180 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3182 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3183 "parameter(tethering) is NULL\n");
3185 __tethering_h *th = (__tethering_h *)tethering;
3186 tethering_error_e ret = TETHERING_ERROR_NONE;
3188 ret = __set_visible(visible);
3189 if (ret == TETHERING_ERROR_NONE) {
3190 __send_dbus_signal(th->client_bus,
3191 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
3192 visible ? SIGNAL_MSG_SSID_VISIBLE :
3193 SIGNAL_MSG_SSID_HIDE);
3200 * @brief Gets the visibility of SSID(service set identifier).
3202 * @privlevel platform
3203 * @privilege http://tizen.org/privilege/tethering.admin
3204 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3205 * @param[in] tethering The handle of tethering
3206 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3207 * @return 0 on success, otherwise negative error value.
3208 * @retval #TETHERING_ERROR_NONE Successful
3209 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3210 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3211 * @see tethering_wifi_set_ssid_visibility()
3213 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
3215 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3216 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3218 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3219 "parameter(tethering) is NULL\n");
3220 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3221 "parameter(visible) is NULL\n");
3223 return __get_visible(visible);
3228 * @brief Sets the passphrase.
3230 * @privlevel platform
3231 * @privilege http://tizen.org/privilege/tethering.admin
3232 * @remarks This change is applied next time Wi-Fi tethering is enabled
3233 * @param[in] tethering The handle of tethering
3234 * @param[in] passphrase The passphrase
3235 * @return 0 on success, otherwise negative error value.
3236 * @retval #TETHERING_ERROR_NONE Successful
3237 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3238 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3239 * @see tethering_wifi_get_passphrase()
3241 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3243 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3244 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3246 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3247 "parameter(tethering) is NULL\n");
3248 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3249 "parameter(passphrase) is NULL\n");
3251 __tethering_h *th = (__tethering_h *)tethering;
3252 GDBusProxy *proxy = th->client_bus_proxy;
3253 GVariant *parameters;
3254 GError *error = NULL;
3255 int passphrase_len = 0;
3259 passphrase_len = strlen(passphrase);
3260 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3261 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3262 ERR("parameter(passphrase) is too short or long\n");
3263 return TETHERING_ERROR_INVALID_PARAMETER;
3266 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3267 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3270 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3272 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3273 ret = TETHERING_ERROR_PERMISSION_DENIED;
3275 ret = TETHERING_ERROR_OPERATION_FAILED;
3277 g_error_free(error);
3281 g_variant_get(parameters, "(u)", &ret);
3282 g_variant_unref(parameters);
3284 if (ret == TETHERING_ERROR_NONE) {
3285 __send_dbus_signal(th->client_bus,
3286 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3295 * @brief Gets the passphrase.
3297 * @privlevel platform
3298 * @privilege http://tizen.org/privilege/tethering.admin
3299 * @remarks @a passphrase must be released with free() by you.
3300 * @param[in] tethering The handle of tethering
3301 * @param[out] passphrase The passphrase
3302 * @return 0 on success, otherwise negative error value.
3303 * @retval #TETHERING_ERROR_NONE Successful
3304 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3305 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3306 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3307 * @see tethering_wifi_set_passphrase()
3309 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3311 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3312 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3314 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3315 "parameter(tethering) is NULL\n");
3316 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3317 "parameter(passphrase) is NULL\n");
3319 __tethering_h *th = (__tethering_h *)tethering;
3320 GDBusProxy *proxy = th->client_bus_proxy;
3321 GVariant *parameters;
3322 GError *error = NULL;
3323 unsigned int len = 0;
3324 tethering_error_e ret = TETHERING_ERROR_NONE;
3326 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3327 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3330 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3332 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3333 ret = TETHERING_ERROR_PERMISSION_DENIED;
3335 ret = TETHERING_ERROR_OPERATION_FAILED;
3337 g_error_free(error);
3341 if (parameters != NULL) {
3342 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3343 g_variant_unref(parameters);
3346 return TETHERING_ERROR_NONE;
3349 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3351 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3352 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3354 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3355 "parameter(tethering) is NULL\n");
3357 __tethering_h *th = (__tethering_h *)tethering;
3360 GDBusProxy *proxy = th->client_bus_proxy;
3361 GVariant *parameters;
3362 GError *error = NULL;
3363 tethering_error_e ret = TETHERING_ERROR_NONE;
3365 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_channel",
3366 g_variant_new("(i)", channel), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3369 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3371 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3372 ret = TETHERING_ERROR_PERMISSION_DENIED;
3374 ret = TETHERING_ERROR_OPERATION_FAILED;
3376 g_error_free(error);
3380 if (parameters != NULL) {
3381 g_variant_get(parameters, "(u)", &ret);
3382 g_variant_unref(parameters);
3385 SINFO("set channel : %d", channel);
3386 #endif /* TIZEN_TV_EXT */
3388 th->channel = channel;
3390 return TETHERING_ERROR_NONE;
3393 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3395 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3396 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3398 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3399 "parameter(tethering) is NULL\n");
3401 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3402 "parameter(channel) is NULL\n");
3404 __tethering_h *th = (__tethering_h *)tethering;
3406 GDBusProxy *proxy = th->client_bus_proxy;
3407 GVariant *parameters;
3408 GError *error = NULL;
3409 int ch, vconf_channel;
3410 tethering_error_e ret = TETHERING_ERROR_NONE;
3412 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_channel",
3413 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3416 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3418 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3419 ret = TETHERING_ERROR_PERMISSION_DENIED;
3421 ret = TETHERING_ERROR_OPERATION_FAILED;
3423 g_error_free(error);
3427 if (parameters != NULL) {
3428 g_variant_get(parameters, "(iu)", &ch, &ret);
3429 g_variant_unref(parameters);
3433 ERR("failed to get Hostapd channel, set th->channel");
3434 *channel = th->channel;
3438 if (vconf_get_int(VCONFKEY_WIFI_CHANNEL, &vconf_channel) < 0)
3439 ERR("Failed to get vconf key for channel");
3441 *channel = vconf_channel;
3443 SINFO("get tethering channel : %d", *channel);
3444 #else /* TIZEN_TV_EXT */
3445 *channel = th->channel;
3446 #endif /* TIZEN_TV_EXT */
3448 return TETHERING_ERROR_NONE;
3451 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3453 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3454 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3456 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3457 "parameter(tethering) is NULL\n");
3459 __tethering_h *th = (__tethering_h *)tethering;
3461 th->mode_type = type;
3463 return TETHERING_ERROR_NONE;
3466 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3468 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3469 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3471 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3472 "parameter(tethering) is NULL\n");
3473 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3474 "parameter(type) is NULL\n");
3476 __tethering_h *th = (__tethering_h *)tethering;
3477 *type = th->mode_type;
3479 return TETHERING_ERROR_NONE;
3485 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3487 * @privlevel platform
3488 * @privilege http://tizen.org/privilege/tethering.admin
3489 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3490 * @param[in] tethering The handle of tethering
3491 * @param[in] callback The callback function to invoke
3492 * @param[in] user_data The user data to be passed to the callback function
3493 * @return 0 on success, otherwise negative error value.
3494 * @retval #TETHERING_ERROR_NONE Successful
3495 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3496 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3498 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3501 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3502 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3504 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3505 "parameter(tethering) is NULL\n");
3506 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3507 "parameter(callback) is NULL\n");
3509 __tethering_h *th = (__tethering_h *)tethering;
3510 _softap_settings_t set = {"", "", "", 0, false};
3511 GDBusProxy *proxy = th->client_bus_proxy;
3516 if (th->settings_reloaded_cb) {
3517 ERR("Operation in progress\n");
3518 return TETHERING_ERROR_OPERATION_FAILED;
3521 ret = __prepare_wifi_settings(tethering, &set);
3522 if (ret != TETHERING_ERROR_NONE) {
3523 ERR("softap settings initialization failed\n");
3524 return TETHERING_ERROR_OPERATION_FAILED;
3527 th->settings_reloaded_cb = callback;
3528 th->settings_reloaded_user_data = user_data;
3530 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
3531 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
3534 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3535 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),
3536 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3537 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3539 return TETHERING_ERROR_NONE;
3542 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3544 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3545 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3547 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3548 "parameter(tethering) is NULL\n");
3550 __tethering_h *th = (__tethering_h *)tethering;
3551 th->mac_filter = mac_filter;
3553 return TETHERING_ERROR_NONE;
3556 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3558 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3559 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3561 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3562 "parameter(mac_filter) is NULL\n");
3563 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3564 "parameter(mac_filter) is NULL\n");
3566 __tethering_h *th = (__tethering_h *)tethering;
3567 *mac_filter = th->mac_filter;
3569 return TETHERING_ERROR_NONE;
3572 static int __add_mac_to_file(const char *filepath, const char *mac)
3575 char line[MAX_BUF_SIZE] = "\0";
3576 bool mac_exist = false;
3579 fp = fopen(filepath, "a+");
3581 ERR("fopen is failed\n");
3582 return TETHERING_ERROR_OPERATION_FAILED;
3585 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3586 if (strncmp(mac, line, 17) == 0) {
3587 DBG("MAC %s already exist in the list\n", mac);
3594 p_mac = strdup(mac);
3595 if (p_mac == NULL) {
3596 ERR("strdup failed\n");
3598 return TETHERING_ERROR_OUT_OF_MEMORY;
3601 fprintf(fp, "%s\n", mac);
3603 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3604 allowed_list = g_slist_append(allowed_list, p_mac);
3605 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3606 blocked_list = g_slist_append(blocked_list, p_mac);
3613 return TETHERING_ERROR_NONE;
3616 static int __remove_mac_from_file(const char *filepath, const char *mac)
3620 char line[MAX_BUF_SIZE] = "\0";
3622 fp = fopen(filepath, "r");
3624 ERR("fopen is failed\n");
3625 return TETHERING_ERROR_OPERATION_FAILED;
3628 fp1 = fopen(TEMP_LIST, "w+");
3631 ERR("fopen is failed\n");
3632 return TETHERING_ERROR_OPERATION_FAILED;
3635 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3636 if (strncmp(mac, line, 17) == 0) {
3637 DBG("MAC %s found in the list\n", mac);
3639 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3640 GSList *list = NULL;
3641 for (list = allowed_list; list != NULL; list = list->next) {
3642 char *p_mac = (char *)list->data;
3643 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3644 allowed_list = g_slist_remove(allowed_list, p_mac);
3646 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3647 GSList *list = NULL;
3648 for (list = blocked_list; list != NULL; list = list->next) {
3649 char *p_mac = (char *)list->data;
3650 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3651 blocked_list = g_slist_remove(blocked_list, p_mac);
3655 fprintf(fp1, "%s", line);
3662 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3663 if (rename(TEMP_LIST, ALLOWED_LIST) != 0) {
3664 ERR("rename is failed (%s -> %s)", TEMP_LIST, ALLOWED_LIST);
3665 return TETHERING_ERROR_OPERATION_FAILED;
3667 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3668 if (rename(TEMP_LIST, BLOCKED_LIST) != 0) {
3669 ERR("rename is failed (%s -> %s)", TEMP_LIST, BLOCKED_LIST);
3670 return TETHERING_ERROR_OPERATION_FAILED;
3674 return TETHERING_ERROR_NONE;
3677 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3679 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3680 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3682 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3683 "parameter(tethering) is NULL\n");
3684 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3685 "parameter(mac) is NULL\n");
3687 return __add_mac_to_file(ALLOWED_LIST, mac);
3690 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3692 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3693 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3695 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3696 "parameter(tethering) is NULL\n");
3697 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3698 "parameter(mac) is NULL\n");
3700 return __remove_mac_from_file(ALLOWED_LIST, mac);
3703 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3705 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3706 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3708 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3709 "parameter(tethering) is NULL\n");
3710 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3711 "parameter(allowed_mac_list) is NULL\n");
3713 *allowed_mac_list = g_slist_copy(allowed_list);
3714 return TETHERING_ERROR_NONE;
3717 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3719 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3720 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3722 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3723 "parameter(tethering) is NULL\n");
3724 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3725 "parameter(mac) is NULL\n");
3727 return __add_mac_to_file(BLOCKED_LIST, mac);
3730 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3732 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3733 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3735 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3736 "parameter(tethering) is NULL\n");
3737 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3738 "parameter(mac) is NULL\n");
3740 return __remove_mac_from_file(BLOCKED_LIST, mac);
3743 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3745 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3746 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3748 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3749 "parameter(tethering) is NULL\n");
3750 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3751 "parameter(blocked_mac_list) is NULL\n");
3753 *blocked_mac_list = g_slist_copy(blocked_list);
3754 return TETHERING_ERROR_NONE;
3757 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3759 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3760 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3762 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3763 "parameter(tethering) is NULL\n");
3765 GVariant *parameters;
3766 GError *error = NULL;
3769 __tethering_h *th = (__tethering_h *)tethering;
3771 GDBusProxy *proxy = th->client_bus_proxy;
3773 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3774 g_variant_new("(b)", enable),
3775 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3778 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3779 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3780 result = TETHERING_ERROR_PERMISSION_DENIED;
3782 result = TETHERING_ERROR_OPERATION_FAILED;
3784 g_error_free(error);
3785 th->dhcp_enabled = false;
3790 g_variant_get(parameters, "(u)", &result);
3791 g_variant_unref(parameters);
3794 th->dhcp_enabled = true;
3796 th->dhcp_enabled = false;
3798 return TETHERING_ERROR_NONE;
3801 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3803 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3804 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3806 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3807 "parameter(tethering) is NULL\n");
3808 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3809 "parameter(rangestart) is NULL\n");
3810 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3811 "parameter(rangestop) is NULL\n");
3813 GVariant *parameters;
3814 GError *error = NULL;
3817 __tethering_h *th = (__tethering_h *)tethering;
3819 GDBusProxy *proxy = th->client_bus_proxy;
3821 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3822 g_variant_new("(ss)", rangestart, rangestop),
3823 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3825 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3827 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3828 result = TETHERING_ERROR_PERMISSION_DENIED;
3830 result = TETHERING_ERROR_OPERATION_FAILED;
3832 g_error_free(error);
3833 th->dhcp_enabled = false;
3838 g_variant_get(parameters, "(u)", &result);
3839 g_variant_unref(parameters);
3841 th->dhcp_enabled = true;
3843 return TETHERING_ERROR_NONE;
3846 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3848 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3849 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3851 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3852 "parameter(tethering) is NULL\n");
3853 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3854 "parameter(dhcp_enabled) is NULL\n");
3856 __tethering_h *th = (__tethering_h *)tethering;
3857 *dhcp_enabled = th->dhcp_enabled;
3859 return TETHERING_ERROR_NONE;
3862 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3864 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3865 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3867 GError *error = NULL;
3869 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3870 "parameter(tethering) is NULL\n");
3871 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3872 TETHERING_ERROR_NOT_ENABLED,
3873 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3874 __tethering_h *th = (__tethering_h *)tethering;
3875 th->txpower = txpower;
3877 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3878 g_variant_new("(u)", txpower),
3879 G_DBUS_CALL_FLAGS_NONE,
3880 -1, th->cancellable, &error);
3882 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3883 g_clear_error(&error);
3884 return TETHERING_ERROR_OPERATION_FAILED;
3886 return TETHERING_ERROR_NONE;
3889 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3891 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3892 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3894 GError *error = NULL;
3895 GVariant *result = NULL;
3897 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3898 "parameter(tethering) is NULL\n");
3899 _retvm_if(txpower == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3900 "parameter(txpower) is NULL\n");
3901 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3902 TETHERING_ERROR_NOT_ENABLED,
3903 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3905 __tethering_h *th = (__tethering_h *)tethering;
3907 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3909 G_DBUS_CALL_FLAGS_NONE,
3910 -1, th->cancellable, &error);
3912 if (result != NULL) {
3913 g_variant_get(result, "(u)", txpower);
3914 g_variant_unref(result);
3917 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3918 g_clear_error(&error);
3919 return TETHERING_ERROR_OPERATION_FAILED;
3921 g_clear_error(&error);
3922 return TETHERING_ERROR_NONE;
3925 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
3927 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3928 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3930 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3931 "parameter(tethering) is NULL\n");
3933 GVariant *parameters;
3934 GError *error = NULL;
3937 __tethering_h *th = (__tethering_h *)tethering;
3939 GDBusProxy *proxy = th->client_bus_proxy;
3941 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
3942 g_variant_new("(u)", mtu),
3943 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3945 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3947 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3948 result = TETHERING_ERROR_PERMISSION_DENIED;
3950 result = TETHERING_ERROR_OPERATION_FAILED;
3952 g_error_free(error);
3956 g_variant_get(parameters, "(u)", &result);
3958 g_variant_unref(parameters);
3960 return TETHERING_ERROR_NONE;
3963 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
3965 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3966 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3968 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3969 "parameter(tethering) is NULL\n");
3970 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3971 "parameter(mac) is NULL\n");
3973 GVariant *parameters;
3974 GError *error = NULL;
3977 __tethering_h *th = (__tethering_h *)tethering;
3979 GDBusProxy *proxy = th->client_bus_proxy;
3981 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
3982 g_variant_new("(s)", mac),
3983 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3985 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3987 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3988 result = TETHERING_ERROR_PERMISSION_DENIED;
3990 result = TETHERING_ERROR_OPERATION_FAILED;
3992 g_error_free(error);
3996 g_variant_get(parameters, "(u)", &result);
3997 g_variant_unref(parameters);
3999 if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
4000 return TETHERING_ERROR_NOT_SUPPORT_API;
4002 return TETHERING_ERROR_NONE;
4005 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
4007 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4008 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4010 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4011 "parameter(tethering) is NULL\n");
4013 __tethering_h *th = (__tethering_h *)tethering;
4015 th->wifi_max_connected = max_device;
4017 return TETHERING_ERROR_NONE;
4020 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
4022 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4023 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4025 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4026 "parameter(tethering) is NULL\n");
4027 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4028 "parameter(max_device) is NULL\n");
4030 __tethering_h *th = (__tethering_h *)tethering;
4032 *max_device = th->wifi_max_connected;
4033 return TETHERING_ERROR_NONE;
4036 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
4038 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4039 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4041 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4042 "parameter(tethering) is NULL\n");
4044 GVariant *parameters;
4045 GError *error = NULL;
4048 __tethering_h *th = (__tethering_h *)tethering;
4050 GDBusProxy *proxy = th->client_bus_proxy;
4052 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
4053 g_variant_new("(b)", enable),
4054 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4056 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4058 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4059 result = TETHERING_ERROR_PERMISSION_DENIED;
4061 result = TETHERING_ERROR_OPERATION_FAILED;
4063 g_error_free(error);
4067 g_variant_get(parameters, "(u)", &result);
4068 g_variant_unref(parameters);
4070 th->port_forwarding = true;
4072 return TETHERING_ERROR_NONE;
4075 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)
4077 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4078 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4080 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4081 "parameter(tethering) is NULL\n");
4082 _retvm_if(ifname == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4083 "parameter(ifname) is NULL\n");
4084 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4085 "parameter(protocol) is NULL\n");
4086 _retvm_if(org_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4087 "parameter(org_ip) is NULL\n");
4088 _retvm_if(final_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4089 "parameter(final_ip) is NULL\n");
4091 GVariant *parameters;
4092 GError *error = NULL;
4094 char cmd[MAX_BUF_SIZE] = { 0, };
4097 __tethering_h *th = (__tethering_h *)tethering;
4099 GDBusProxy *proxy = th->client_bus_proxy;
4101 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
4102 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
4103 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4105 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4107 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4108 result = TETHERING_ERROR_PERMISSION_DENIED;
4110 result = TETHERING_ERROR_OPERATION_FAILED;
4112 g_error_free(error);
4116 g_variant_get(parameters, "(u)", &result);
4117 g_variant_unref(parameters);
4119 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);
4123 ERR("strdup failed\n");
4124 return TETHERING_ERROR_OUT_OF_MEMORY;
4127 port_forwarding = g_slist_append(port_forwarding, list);
4129 return TETHERING_ERROR_NONE;
4132 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
4134 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4135 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4137 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4138 "parameter(tethering) is NULL\n");
4140 GVariant *parameters;
4141 GError *error = NULL;
4144 __tethering_h *th = (__tethering_h *)tethering;
4146 GDBusProxy *proxy = th->client_bus_proxy;
4148 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
4149 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4151 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4153 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4154 result = TETHERING_ERROR_PERMISSION_DENIED;
4156 result = TETHERING_ERROR_OPERATION_FAILED;
4158 g_error_free(error);
4162 g_variant_get(parameters, "(u)", &result);
4164 g_variant_unref(parameters);
4166 return TETHERING_ERROR_NONE;
4169 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool *forwarding_enabled)
4171 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4172 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4174 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4175 "parameter(tethering) is NULL\n");
4176 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4177 "parameter(forwarding_enabled) is NULL\n");
4179 __tethering_h *th = (__tethering_h *)tethering;
4181 *forwarding_enabled = th->port_forwarding;
4183 return TETHERING_ERROR_NONE;
4186 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
4188 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4189 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4191 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4192 "parameter(tethering) is NULL\n");
4193 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4194 "parameter(port_forwarding_list) is NULL\n");
4196 *port_forwarding_list = g_slist_copy(port_forwarding);
4197 return TETHERING_ERROR_NONE;
4200 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
4202 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4203 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4205 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4206 "parameter(tethering) is NULL\n");
4208 GVariant *parameters;
4209 GError *error = NULL;
4212 __tethering_h *th = (__tethering_h *)tethering;
4214 GDBusProxy *proxy = th->client_bus_proxy;
4216 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
4217 g_variant_new("(b)", enable),
4218 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4220 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4222 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4223 result = TETHERING_ERROR_PERMISSION_DENIED;
4225 result = TETHERING_ERROR_OPERATION_FAILED;
4227 g_error_free(error);
4231 g_variant_get(parameters, "(u)", &result);
4232 g_variant_unref(parameters);
4234 th->port_filtering = true;
4236 return TETHERING_ERROR_NONE;
4239 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
4241 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4242 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4244 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4245 "parameter(tethering) is NULL\n");
4246 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4247 "parameter(protocol) is NULL\n");
4249 GVariant *parameters;
4250 GError *error = NULL;
4255 __tethering_h *th = (__tethering_h *)tethering;
4257 GDBusProxy *proxy = th->client_bus_proxy;
4259 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
4260 g_variant_new("(isb)", port, protocol, allow),
4261 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4263 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4265 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4266 result = TETHERING_ERROR_PERMISSION_DENIED;
4268 result = TETHERING_ERROR_OPERATION_FAILED;
4270 g_error_free(error);
4274 g_variant_get(parameters, "(u)", &result);
4275 g_variant_unref(parameters);
4278 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
4280 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
4282 if (ret == -1 || list == NULL) {
4283 ERR("asprintf failed\n");
4284 return TETHERING_ERROR_OUT_OF_MEMORY;
4287 DBG("cmd:%s", list);
4289 port_filtering = g_slist_append(port_filtering, list);
4291 return TETHERING_ERROR_NONE;
4294 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
4296 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4297 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4299 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4300 "parameter(tethering) is NULL\n");
4301 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4302 "parameter(protocol) is NULL\n");
4304 GVariant *parameters;
4305 GError *error = NULL;
4310 __tethering_h *th = (__tethering_h *)tethering;
4312 GDBusProxy *proxy = th->client_bus_proxy;
4314 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
4315 g_variant_new("(iisb)", port1, port2, protocol, allow),
4316 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4318 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4320 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4321 result = TETHERING_ERROR_PERMISSION_DENIED;
4323 result = TETHERING_ERROR_OPERATION_FAILED;
4325 g_error_free(error);
4329 g_variant_get(parameters, "(u)", &result);
4330 g_variant_unref(parameters);
4333 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
4335 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
4337 if (ret == -1 || list == NULL) {
4338 ERR("asprintf failed\n");
4339 return TETHERING_ERROR_OUT_OF_MEMORY;
4342 DBG("cmd:%s", list);
4344 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4346 return TETHERING_ERROR_NONE;
4349 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4351 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4352 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4354 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4355 "parameter(tethering) is NULL\n");
4356 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4357 "parameter(port_filtering_list) is NULL\n");
4359 *port_filtering_list = g_slist_copy(port_filtering);
4360 return TETHERING_ERROR_NONE;
4363 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4365 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4366 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4368 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4369 "parameter(tethering) is NULL\n");
4370 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4371 "parameter(custom_port_filtering_list) is NULL\n");
4373 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4374 return TETHERING_ERROR_NONE;
4377 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool *filtering_enabled)
4379 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4380 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4382 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4383 "parameter(tethering) is NULL\n");
4384 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4385 "parameter(filtering_enabled) is NULL\n");
4387 __tethering_h *th = (__tethering_h *)tethering;
4389 *filtering_enabled = th->port_filtering;
4391 return TETHERING_ERROR_NONE;
4394 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
4396 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4397 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4399 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4400 "parameter(tethering) is NULL\n");
4402 GVariant *parameters;
4403 GError *error = NULL;
4406 __tethering_h *th = (__tethering_h *)tethering;
4408 GDBusProxy *proxy = th->client_bus_proxy;
4410 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4411 g_variant_new("(ib)", type, enable),
4412 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4414 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4416 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4417 result = TETHERING_ERROR_PERMISSION_DENIED;
4419 result = TETHERING_ERROR_OPERATION_FAILED;
4421 g_error_free(error);
4425 g_variant_get(parameters, "(u)", &result);
4427 g_variant_unref(parameters);
4429 return TETHERING_ERROR_NONE;
4432 API int tethering_wifi_push_wps_button(tethering_h tethering)
4434 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4435 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4437 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4438 "parameter(tethering) is NULL");
4439 __tethering_h *th = (__tethering_h *)tethering;
4440 GDBusProxy *proxy = th->client_bus_proxy;
4441 GVariant *parameters = NULL;
4443 GError *error = NULL;
4445 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4446 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4449 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4451 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4452 ret = TETHERING_ERROR_PERMISSION_DENIED;
4454 ret = TETHERING_ERROR_OPERATION_FAILED;
4456 g_error_free(error);
4460 if (parameters != NULL) {
4461 g_variant_get(parameters, "(u)", &ret);
4462 g_variant_unref(parameters);
4465 return TETHERING_ERROR_NONE;
4468 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4470 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4471 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4473 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4474 "parameter(tethering) is NULL");
4475 _retvm_if(wps_pin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4476 "parameter(wps_pin) is NULL");
4478 __tethering_h *th = (__tethering_h *)tethering;
4479 GDBusProxy *proxy = th->client_bus_proxy;
4480 GVariant *parameters = NULL;
4482 GError *error = NULL;
4484 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4485 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4488 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4490 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4491 ret = TETHERING_ERROR_PERMISSION_DENIED;
4493 ret = TETHERING_ERROR_OPERATION_FAILED;
4495 g_error_free(error);
4499 if (parameters != NULL) {
4500 g_variant_get(parameters, "(u)", &ret);
4501 g_variant_unref(parameters);
4504 return TETHERING_ERROR_NONE;
4507 API int tethering_wifi_is_sharing_supported(tethering_h tethering, bool *supported)
4509 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4510 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4512 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4513 "parameter(tethering) is NULL\n");
4514 _retvm_if(supported == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4515 "parameter(supported) is NULL\n");
4517 /** Check if wifi-sharing is supported */
4518 __tethering_h *th = (__tethering_h *)tethering;
4519 GDBusProxy *proxy = th->client_bus_proxy;
4521 int ret = TETHERING_ERROR_NONE;
4524 GVariant *value = NULL;
4525 GVariantIter *iter = NULL;
4526 GVariantIter *sub_iter = NULL;
4527 GVariant *parameters = NULL;
4528 GError *error = NULL;
4530 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_interfaces",
4531 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4533 if (!parameters && error) {
4534 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4536 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4537 ret = TETHERING_ERROR_PERMISSION_DENIED;
4539 ret = TETHERING_ERROR_OPERATION_FAILED;
4541 g_error_free(error);
4545 g_variant_get(parameters, "(a(a{sv}))", &iter);
4547 g_variant_unref(parameters);
4548 ret = TETHERING_ERROR_OPERATION_FAILED;
4552 while (g_variant_iter_loop(iter, "(a{sv})", &sub_iter)) {
4553 while (g_variant_iter_loop(sub_iter, "{sv}", &key, &value)) {
4554 if (g_strcmp0(key, "IfName") == 0) {
4555 const gchar *interface = g_variant_get_string(value, NULL);
4556 ERR("interface: %s\n", interface);
4557 if (strncmp(interface, "wlan", 4) == 0)
4562 g_variant_unref(parameters);