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
40 #define IPTABLES "/usr/sbin/iptables"
41 #define TABLE_NAT "nat"
42 #define TETH_NAT_PRE "teth_nat_pre"
43 #define TABLE_FILTER "filter"
44 #define TETH_FILTER_FW "teth_filter_fw"
45 #define ACTION_DROP "DROP"
46 #define ACTION_ACCEPT "ACCEPT"
47 #define PORT_FORWARD_RULE_STR "-t %s -A %s -i %s -p %s -d %s --dport %d -j DNAT --to %s:%d"
48 #define FILTERING_MULTIPORT_RULE_STR "-t %s -A %s -p %s -m multiport --dport %d,%d -j %s"
49 #define FILTERING_RULE_STR "-t %s -A %s -p %s --dport %d -j %s"
51 static GSList *allowed_list = NULL;
52 static GSList *blocked_list = NULL;
53 static GSList *port_forwarding = NULL;
54 static GSList *port_filtering = NULL;
55 static GSList *custom_port_filtering = NULL;
57 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
58 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
59 GVariant *parameters, gpointer user_data);
61 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
62 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
63 GVariant *parameters, gpointer user_data);
65 static void __handle_usb_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_usb_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_bt_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_bt_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_net_closed(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_no_data_timeout(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_low_battery_mode(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_flight_mode(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_security_type_changed(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_ssid_visibility_changed(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_passphrase_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_dhcp(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 __tethering_sig_t sigs[] = {
114 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
115 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
116 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
117 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
118 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
119 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
120 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
121 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
122 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
123 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
124 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
125 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
126 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
127 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
129 static int retry = 0;
131 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
133 if (conn == NULL || signal_name == NULL)
136 GVariant *message = NULL;
137 GError *error = NULL;
140 message = g_variant_new("(s)", arg);
142 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
143 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
145 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
150 static bool __any_tethering_is_enabled(tethering_h tethering)
152 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
153 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
154 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
155 tethering_is_enabled(tethering, TETHERING_TYPE_P2P))
161 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
163 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
164 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
165 security_type != TETHERING_WIFI_SECURITY_TYPE_WPS &&
166 security_type != TETHERING_WIFI_SECURITY_TYPE_SAE) {
167 ERR("Invalid param\n");
168 return TETHERING_ERROR_INVALID_PARAMETER;
171 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
172 ERR("vconf_set_int is failed\n");
173 return TETHERING_ERROR_OPERATION_FAILED;
176 return TETHERING_ERROR_NONE;
179 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
181 if (security_type == NULL) {
182 ERR("Invalid param\n");
183 return TETHERING_ERROR_INVALID_PARAMETER;
186 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
187 (int *)security_type) < 0) {
188 ERR("vconf_get_int is failed\n");
189 return TETHERING_ERROR_OPERATION_FAILED;
192 return TETHERING_ERROR_NONE;
195 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
197 if (path == NULL || ssid == NULL || size == 0)
201 char *ptr_tmp = NULL;
203 ptr = vconf_get_str(path);
207 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
210 g_strlcpy(ssid, ptr, size);
216 static tethering_error_e __set_visible(const bool visible)
218 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
219 ERR("vconf_set_int is failed\n");
220 return TETHERING_ERROR_OPERATION_FAILED;
223 return TETHERING_ERROR_NONE;
226 static tethering_error_e __get_visible(bool *visible)
228 if (visible == NULL) {
229 ERR("Invalid param\n");
230 return TETHERING_ERROR_INVALID_PARAMETER;
235 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
236 ERR("vconf_get_int is failed\n");
237 return TETHERING_ERROR_OPERATION_FAILED;
244 return TETHERING_ERROR_NONE;
247 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
249 if (passphrase == NULL ||
250 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
253 guint32 rand_int = 0;
256 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
257 rand_int = g_random_int_range('a', 'z');
258 passphrase[index] = rand_int;
260 passphrase[index] = '\0';
265 static tethering_error_e __get_error(int agent_error)
267 tethering_error_e err = TETHERING_ERROR_NONE;
269 switch (agent_error) {
270 case MOBILE_AP_ERROR_NONE:
271 err = TETHERING_ERROR_NONE;
274 case MOBILE_AP_ERROR_RESOURCE:
275 err = TETHERING_ERROR_OUT_OF_MEMORY;
278 case MOBILE_AP_ERROR_INTERNAL:
279 err = TETHERING_ERROR_OPERATION_FAILED;
282 case MOBILE_AP_ERROR_INVALID_PARAM:
283 err = TETHERING_ERROR_INVALID_PARAMETER;
286 case MOBILE_AP_ERROR_ALREADY_ENABLED:
287 err = TETHERING_ERROR_OPERATION_FAILED;
290 case MOBILE_AP_ERROR_NOT_ENABLED:
291 err = TETHERING_ERROR_NOT_ENABLED;
294 case MOBILE_AP_ERROR_NET_OPEN:
295 err = TETHERING_ERROR_OPERATION_FAILED;
298 case MOBILE_AP_ERROR_NET_CLOSE:
299 err = TETHERING_ERROR_OPERATION_FAILED;
302 case MOBILE_AP_ERROR_DHCP:
303 err = TETHERING_ERROR_OPERATION_FAILED;
306 case MOBILE_AP_ERROR_IN_PROGRESS:
307 err = TETHERING_ERROR_OPERATION_FAILED;
310 case MOBILE_AP_ERROR_NOT_PERMITTED:
311 err = TETHERING_ERROR_NOT_PERMITTED;
314 case MOBILE_AP_ERROR_PERMISSION_DENIED:
315 err = TETHERING_ERROR_PERMISSION_DENIED;
318 ERR("Not defined error : %d\n", agent_error);
319 err = TETHERING_ERROR_OPERATION_FAILED;
326 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
327 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
328 GVariant *parameters, gpointer user_data)
332 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
334 __tethering_h *th = (__tethering_h *)user_data;
336 tethering_type_e type = 0;
337 mobile_ap_type_e ap_type = 0;
338 tethering_connection_state_changed_cb ccb = NULL;
339 __tethering_client_h client;
347 memset(&client, 0, sizeof(__tethering_client_h));
348 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
350 if (!g_strcmp0(buf, "DhcpConnected")) {
352 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
355 ERR("Unknown event [%s]\n", buf);
359 if (ap_type == MOBILE_AP_TYPE_USB)
360 type = TETHERING_TYPE_USB;
361 else if (ap_type == MOBILE_AP_TYPE_WIFI)
362 type = TETHERING_TYPE_WIFI;
363 else if (ap_type == MOBILE_AP_TYPE_BT)
364 type = TETHERING_TYPE_BT;
365 else if (ap_type == MOBILE_AP_TYPE_P2P)
366 type = TETHERING_TYPE_P2P;
368 ERR("Not supported tethering type [%d]\n", ap_type);
372 SINFO("[%s] type %d, ip %s, mac %s, name %s, timestamp %d",
373 buf, ap_type, ip, mac, name, timestamp);
375 ccb = th->changed_cb[type];
378 data = th->changed_user_data[type];
380 client.interface = type;
381 g_strlcpy(client.ip, ip, sizeof(client.ip));
382 g_strlcpy(client.mac, mac, sizeof(client.mac));
384 client.hostname = g_strdup(name);
385 client.tm = (time_t)timestamp;
387 ccb((tethering_client_h)&client, opened, data);
388 g_free(client.hostname);
397 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
398 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
399 GVariant *parameters, gpointer user_data)
403 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
405 __tethering_h *th = (__tethering_h *)user_data;
406 tethering_type_e type = 0;
407 tethering_disabled_cb dcb = NULL;
409 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
411 SINFO("Tethering Disabled by network close !");
413 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
414 dcb = th->disabled_cb[type];
417 data = th->disabled_user_data[type];
419 dcb(TETHERING_ERROR_NONE, type, code, data);
425 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
426 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
427 GVariant *parameters, gpointer user_data)
431 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
433 __tethering_h *th = (__tethering_h *)user_data;
434 tethering_type_e type = TETHERING_TYPE_WIFI;
435 bool is_requested = false;
436 tethering_enabled_cb ecb = NULL;
439 ecb = th->enabled_cb[type];
442 data = th->enabled_user_data[type];
444 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
448 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
449 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
450 GVariant *parameters, gpointer user_data)
454 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
456 __tethering_h *th = (__tethering_h *)user_data;
457 tethering_type_e type = TETHERING_TYPE_WIFI;
458 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
459 tethering_disabled_cb dcb = NULL;
463 dcb = th->disabled_cb[type];
466 data = th->disabled_user_data[type];
467 g_variant_get(parameters, "(s)", &buf);
468 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
469 code = TETHERING_DISABLED_BY_WIFI_ON;
470 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
471 code = TETHERING_DISABLED_BY_TIMEOUT;
474 dcb(TETHERING_ERROR_NONE, type, code, data);
479 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
480 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
481 GVariant *parameters, gpointer user_data)
485 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
487 __tethering_h *th = (__tethering_h *)user_data;
488 tethering_type_e type = TETHERING_TYPE_USB;
489 bool is_requested = false;
490 tethering_enabled_cb ecb = NULL;
493 ecb = th->enabled_cb[type];
496 data = th->enabled_user_data[type];
498 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
502 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
503 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
504 GVariant *parameters, gpointer user_data)
508 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
510 __tethering_h *th = (__tethering_h *)user_data;
511 tethering_type_e type = TETHERING_TYPE_USB;
512 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
513 tethering_disabled_cb dcb = NULL;
517 dcb = th->disabled_cb[type];
520 data = th->disabled_user_data[type];
522 g_variant_get(parameters, "(s)", &buf);
523 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
524 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
526 dcb(TETHERING_ERROR_NONE, type, code, data);
531 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
532 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
533 GVariant *parameters, gpointer user_data)
537 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
539 __tethering_h *th = (__tethering_h *)user_data;
540 tethering_type_e type = TETHERING_TYPE_BT;
541 bool is_requested = false;
542 tethering_enabled_cb ecb = NULL;
545 ecb = th->enabled_cb[type];
548 data = th->enabled_user_data[type];
550 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
554 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
555 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
556 GVariant *parameters, gpointer user_data)
560 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
562 __tethering_h *th = (__tethering_h *)user_data;
563 tethering_type_e type = TETHERING_TYPE_BT;
564 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
565 tethering_disabled_cb dcb = NULL;
569 dcb = th->disabled_cb[type];
572 data = th->disabled_user_data[type];
573 g_variant_get(parameters, "(s)", &buf);
574 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
575 code = TETHERING_DISABLED_BY_BT_OFF;
576 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
577 code = TETHERING_DISABLED_BY_TIMEOUT;
579 dcb(TETHERING_ERROR_NONE, type, code, data);
585 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
586 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
587 GVariant *parameters, gpointer user_data)
591 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
593 __tethering_h *th = (__tethering_h *)user_data;
594 tethering_type_e type = 0;
595 tethering_disabled_cb dcb = NULL;
597 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
599 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
600 dcb = th->disabled_cb[type];
603 data = th->disabled_user_data[type];
605 dcb(TETHERING_ERROR_NONE, type, code, data);
610 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
611 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
612 GVariant *parameters, gpointer user_data)
616 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
618 __tethering_h *th = (__tethering_h *)user_data;
619 tethering_type_e type = 0;
620 tethering_disabled_cb dcb = NULL;
622 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
624 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
625 dcb = th->disabled_cb[type];
628 data = th->disabled_user_data[type];
630 dcb(TETHERING_ERROR_NONE, type, code, data);
635 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
636 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
637 GVariant *parameters, gpointer user_data)
641 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
643 __tethering_h *th = (__tethering_h *)user_data;
644 tethering_type_e type = 0;
645 tethering_disabled_cb dcb = NULL;
647 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
649 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
650 dcb = th->disabled_cb[type];
653 data = th->disabled_user_data[type];
655 dcb(TETHERING_ERROR_NONE, type, code, data);
660 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
661 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
662 GVariant *parameters, gpointer user_data)
667 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
668 __tethering_h *th = (__tethering_h *)user_data;
670 tethering_wifi_security_type_changed_cb scb = NULL;
672 tethering_wifi_security_type_e security_type;
675 scb = th->security_type_changed_cb;
679 g_variant_get(parameters, "(s)", &buf);
680 data = th->security_type_user_data;
681 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
682 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
683 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
684 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
685 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
686 security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
687 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_SAE_STR) == 0)
688 security_type = TETHERING_WIFI_SECURITY_TYPE_SAE;
690 SERR("Unknown type : %s\n", buf);
695 scb(security_type, data);
700 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
701 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
702 GVariant *parameters, gpointer user_data)
706 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
707 __tethering_h *th = (__tethering_h *)user_data;
709 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
711 bool visible = false;
714 scb = th->ssid_visibility_changed_cb;
719 g_variant_get(parameters, "(s)", &buf);
720 data = th->ssid_visibility_user_data;
721 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
729 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
730 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
731 GVariant *parameters, gpointer user_data)
735 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
736 __tethering_h *th = (__tethering_h *)user_data;
738 tethering_wifi_passphrase_changed_cb pcb = NULL;
741 pcb = th->passphrase_changed_cb;
745 data = th->passphrase_user_data;
751 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
756 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
757 GError *g_error = NULL;
760 tethering_error_e error;
761 __tethering_h *th = (__tethering_h *)user_data;
762 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
763 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
765 if (!_tethering_check_handle((tethering_h)user_data))
768 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
770 ERR("DBus error [%s]\n", g_error->message);
771 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
772 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
773 g_error_free(g_error);
774 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
776 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
777 error = TETHERING_ERROR_PERMISSION_DENIED;
779 error = TETHERING_ERROR_OPERATION_FAILED;
780 g_error_free(g_error);
782 g_variant_get(g_var, "(u)", &info);
783 error = __get_error(info);
787 INFO("cfm event : wifi tethering enable info : %d\n", error);
789 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
790 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
791 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
792 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
794 SINFO("Tethering enabled event ! error(%d)", error);
800 ecb(error, TETHERING_TYPE_WIFI, true, data);
801 g_variant_unref(g_var);
805 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
809 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
810 GError *g_error = NULL;
813 tethering_error_e error;
815 __tethering_h *th = (__tethering_h *)user_data;
816 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
817 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
819 if (!_tethering_check_handle((tethering_h)user_data))
822 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
824 ERR("DBus error [%s]\n", g_error->message);
825 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
826 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
827 g_error_free(g_error);
828 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
832 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
833 error = TETHERING_ERROR_PERMISSION_DENIED;
835 error = TETHERING_ERROR_OPERATION_FAILED;
836 g_error_free(g_error);
838 g_variant_get(g_var, "(u)", &info);
839 g_variant_unref(g_var);
840 error = __get_error(info);
844 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
845 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
846 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
847 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
854 ecb(error, TETHERING_TYPE_BT, true, data);
858 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
863 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
864 __tethering_h *th = (__tethering_h *)user_data;
865 GError *g_error = NULL;
868 tethering_error_e error;
869 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
870 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
872 if (!_tethering_check_handle((tethering_h)user_data))
875 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
877 ERR("DBus error [%s]\n", g_error->message);
878 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
879 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
880 g_error_free(g_error);
881 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
885 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
886 error = TETHERING_ERROR_PERMISSION_DENIED;
888 error = TETHERING_ERROR_OPERATION_FAILED;
889 g_error_free(g_error);
891 g_variant_get(g_var, "(u)", &info);
892 g_variant_unref(g_var);
893 error = __get_error(info);
897 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
898 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
899 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
900 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
907 ecb(error, TETHERING_TYPE_USB, true, data);
911 static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
916 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
917 __tethering_h *th = (__tethering_h *)user_data;
918 GError *g_error = NULL;
921 tethering_error_e error;
922 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_P2P];
923 void *data = th->enabled_user_data[TETHERING_TYPE_P2P];
925 if (!_tethering_check_handle((tethering_h)user_data))
928 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
930 ERR("DBus error [%s]\n", g_error->message);
931 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
932 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
933 g_error_free(g_error);
934 tethering_enable((tethering_h)th, TETHERING_TYPE_P2P);
938 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
939 error = TETHERING_ERROR_PERMISSION_DENIED;
941 error = TETHERING_ERROR_OPERATION_FAILED;
942 g_error_free(g_error);
944 g_variant_get(g_var, "(u)", &info);
945 g_variant_unref(g_var);
946 error = __get_error(info);
955 ecb(error, TETHERING_TYPE_P2P, true, data);
959 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
964 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
965 GError *g_error = NULL;
967 guint info, event_type;
968 tethering_error_e error;
969 tethering_type_e type;
970 tethering_h tethering = (tethering_h)user_data;
971 __tethering_h *th = (__tethering_h *)tethering;
972 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
973 tethering_disabled_cb dcb = NULL;
976 if (!_tethering_check_handle((tethering_h)user_data))
979 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
981 ERR("DBus error [%s]\n", g_error->message);
982 g_error_free(g_error);
985 g_variant_get(g_var, "(uu)", &event_type, &info);
986 INFO("cfm event : %d info : %d\n", event_type, info);
987 g_variant_unref(g_var);
988 error = __get_error(info);
989 INFO("cfm event : %d info : %d\n", event_type, error);
990 switch (event_type) {
991 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
992 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
993 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
994 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
995 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
997 type = TETHERING_TYPE_WIFI;
998 dcb = th->disabled_cb[type];
999 data = th->disabled_user_data[type];
1001 dcb(error, type, code, data);
1004 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1005 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1006 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1007 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1008 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1010 type = TETHERING_TYPE_BT;
1011 dcb = th->disabled_cb[type];
1012 data = th->disabled_user_data[type];
1014 dcb(error, type, code, data);
1017 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1018 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1019 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1020 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1021 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1023 type = TETHERING_TYPE_USB;
1024 dcb = th->disabled_cb[type];
1025 data = th->disabled_user_data[type];
1027 dcb(error, type, code, data);
1030 case MOBILE_AP_DISABLE_P2P_TETHERING_CFM:
1031 type = TETHERING_TYPE_P2P;
1032 dcb = th->disabled_cb[type];
1033 data = th->disabled_user_data[type];
1035 dcb(error, type, code, data);
1038 case MOBILE_AP_DISABLE_CFM:
1040 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1041 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1042 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1043 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1044 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1045 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1046 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1047 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1048 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1049 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1050 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1051 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1053 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1054 dcb = th->disabled_cb[type];
1057 data = th->disabled_user_data[type];
1059 dcb(error, type, code, data);
1064 ERR("Invalid event\n");
1070 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1075 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1077 GError *g_error = NULL;
1080 guint64 tx_bytes, rx_bytes;
1081 __tethering_h *th = (__tethering_h *)user_data;
1082 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1085 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1087 ERR("DBus fail [%s]\n", g_error->message);
1088 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1089 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1091 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1095 if (th->data_usage_cb == NULL) {
1096 ERR("There is no data_usage_cb\n");
1100 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1102 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1103 th->data_usage_cb(TETHERING_ERROR_NONE,
1104 rx_bytes, tx_bytes, th->data_usage_user_data);
1105 g_variant_unref(g_var);
1107 th->data_usage_cb = NULL;
1108 th->data_usage_user_data = NULL;
1113 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1118 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1119 GError *g_error = NULL;
1122 __tethering_h *th = (__tethering_h *)user_data;
1123 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1125 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1127 ERR("DBus fail [%s]\n", g_error->message);
1128 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1129 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1131 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1132 g_error_free(g_error);
1134 g_variant_get(g_var, "(u)", &info);
1135 if (tethering_error == TETHERING_ERROR_NONE)
1136 tethering_error = __get_error(info);
1137 g_variant_unref(g_var);
1140 if (th->settings_reloaded_cb == NULL) {
1141 DBG("There is no settings_reloaded_cb\n-\n");
1145 th->settings_reloaded_cb(tethering_error,
1146 th->settings_reloaded_user_data);
1148 th->settings_reloaded_cb = NULL;
1149 th->settings_reloaded_user_data = NULL;
1153 static void __connect_signals(tethering_h tethering)
1156 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1158 __tethering_h *th = (__tethering_h *)tethering;
1159 GDBusConnection *connection = th->client_bus;
1162 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1163 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1164 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1165 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1166 sigs[i].cb, tethering, NULL);
1171 static void __disconnect_signals(tethering_h tethering)
1175 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1177 __tethering_h *th = (__tethering_h *)tethering;
1178 GDBusConnection *connection = th->client_bus;
1182 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1183 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1189 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1191 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1194 case TETHERING_TYPE_USB:
1195 g_strlcpy(buf, TETHERING_USB_IF, len);
1197 case TETHERING_TYPE_WIFI:
1198 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1200 case TETHERING_TYPE_BT:
1201 g_strlcpy(buf, TETHERING_BT_IF, len);
1203 case TETHERING_TYPE_P2P:
1204 g_strlcpy(buf, TETHERING_P2P_IF, len);
1207 ERR("Not supported type : %d\n", type);
1213 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1215 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1218 case TETHERING_TYPE_USB:
1219 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1221 case TETHERING_TYPE_WIFI:
1222 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1224 case TETHERING_TYPE_BT:
1225 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1227 case TETHERING_TYPE_P2P:
1228 g_strlcpy(buf, TETHERING_P2P_GATEWAY, len);
1231 ERR("Not supported type : %d\n", type);
1237 static int __get_common_ssid(char *ssid, unsigned int size)
1240 ERR("ssid is null\n");
1241 return TETHERING_ERROR_INVALID_PARAMETER;
1245 char *ptr_tmp = NULL;
1247 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1249 ERR("vconf_get_str is failed and set default ssid");
1250 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1252 g_strlcpy(ssid, ptr, size);
1256 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1259 return TETHERING_ERROR_NONE;
1262 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1264 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1267 case TETHERING_WIFI_MODE_TYPE_B:
1268 *buf = g_strdup("b");
1270 case TETHERING_WIFI_MODE_TYPE_G:
1271 *buf = g_strdup("g");
1273 case TETHERING_WIFI_MODE_TYPE_A:
1274 *buf = g_strdup("a");
1276 case TETHERING_WIFI_MODE_TYPE_AD:
1277 *buf = g_strdup("ad");
1280 ERR("Not supported type : %d\n", type);
1286 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1290 __tethering_h *th = (__tethering_h *)tethering;
1291 tethering_error_e ret = TETHERING_ERROR_NONE;
1294 if (th == NULL || set == NULL) {
1295 ERR("null parameter\n-\n");
1296 return TETHERING_ERROR_INVALID_PARAMETER;
1299 if (th->ssid == NULL)
1300 __get_common_ssid(set->ssid, sizeof(set->ssid));
1302 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1304 ret = __get_security_type(&set->sec_type);
1305 if (ret != TETHERING_ERROR_NONE)
1306 set->sec_type = th->sec_type;
1308 ret = __get_visible(&set->visibility);
1309 if (ret != TETHERING_ERROR_NONE)
1310 set->visibility = th->visibility;
1312 set->mac_filter = th->mac_filter;
1313 set->max_connected = th->wifi_max_connected;
1314 set->channel = th->channel;
1315 set->txpower = th->txpower;
1317 __get_wifi_mode_type(th->mode_type, &ptr);
1319 g_strlcpy(set->mode, "", sizeof(set->mode));
1321 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1325 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1326 g_strlcpy(set->key, "", sizeof(set->key));
1328 GDBusProxy *proxy = th->client_bus_proxy;
1329 GVariant *parameters;
1330 GError *error = NULL;
1331 char *passphrase = NULL;
1332 unsigned int len = 0;
1334 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1335 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1338 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1340 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1341 ret = TETHERING_ERROR_PERMISSION_DENIED;
1343 ret = TETHERING_ERROR_OPERATION_FAILED;
1345 g_error_free(error);
1349 if (parameters != NULL) {
1350 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1351 g_strlcpy(set->key, passphrase, sizeof(set->key) - 1);
1353 g_variant_unref(parameters);
1357 INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
1358 set->ssid, set->sec_type, set->mode, set->channel,
1359 (set->visibility) ? "true" : "false");
1361 return TETHERING_ERROR_NONE;
1364 static bool __check_precondition(tethering_type_e type)
1366 int dnet_status = 0;
1367 int cellular_state = 0;
1369 /* data network through cellular */
1370 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1371 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1372 INFO("Data Network can be connected later");
1376 /* data network status */
1377 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
1378 if ((dnet_status == VCONFKEY_NETWORK_WIFI
1379 && type != TETHERING_TYPE_WIFI)
1380 || dnet_status == VCONFKEY_NETWORK_ETHERNET)
1383 ERR("Network is not available!");
1389 * @brief Creates the handle of tethering.
1391 * @privlevel platform
1392 * @privilege http://tizen.org/privilege/tethering.admin
1393 * @remarks The @a tethering must be released tethering_destroy() by you.
1394 * @param[out] tethering A handle of a new mobile ap handle on success
1395 * @return 0 on success, otherwise a negative error value.
1396 * @retval #TETHERING_ERROR_NONE Successful
1397 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1398 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1399 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1400 * @see tethering_destroy()
1402 API int tethering_create(tethering_h *tethering)
1404 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1405 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1406 "parameter(tethering) is NULL\n");
1409 __tethering_h *th = NULL;
1410 GError *error = NULL;
1411 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1413 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1415 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1416 "malloc is failed\n");
1417 memset(th, 0x00, sizeof(__tethering_h));
1418 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1419 th->visibility = true;
1420 th->mac_filter = false;
1421 th->channel = TETHERING_WIFI_CHANNEL;
1422 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1423 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1424 th->txpower = TETHERING_WIFI_MAX_TXPOWER;
1426 if (__generate_initial_passphrase(th->passphrase,
1427 sizeof(th->passphrase)) == 0) {
1428 ERR("random passphrase generation failed\n");
1430 return TETHERING_ERROR_OPERATION_FAILED;
1433 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1434 ERR("common ssid get failed\n");
1436 return TETHERING_ERROR_OPERATION_FAILED;
1439 SINFO("ssid: %s, key: %s, channel: %d, mode: %d, txpower: %d, security: %d max_device: %d\n",
1440 ssid, th->passphrase, th->channel, th->mode_type, th->txpower, th->sec_type,
1441 th->wifi_max_connected);
1443 #if !GLIB_CHECK_VERSION(2, 36, 0)
1446 GCancellable *cancellable = g_cancellable_new();
1447 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1449 ERR("Couldn't connect to the System bus[%s]", error->message);
1450 g_error_free(error);
1451 g_cancellable_cancel(cancellable);
1452 g_object_unref(cancellable);
1454 return TETHERING_ERROR_OPERATION_FAILED;
1456 th->cancellable = cancellable;
1458 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1459 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1460 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1461 if (!th->client_bus_proxy) {
1463 ERR("Couldn't create the proxy object because of %s\n", error->message);
1464 g_cancellable_cancel(th->cancellable);
1465 g_object_unref(th->cancellable);
1466 g_object_unref(th->client_bus);
1468 return TETHERING_ERROR_OPERATION_FAILED;
1471 __connect_signals((tethering_h)th);
1473 *tethering = (tethering_h)th;
1474 _tethering_add_handle(th);
1475 INFO("Tethering Handle : %p\n", th);
1477 return TETHERING_ERROR_NONE;
1482 * @brief Destroys the handle of tethering.
1484 * @privlevel platform
1485 * @privilege http://tizen.org/privilege/tethering.admin
1486 * @param[in] tethering The handle of tethering
1487 * @return 0 on success, otherwise a negative error value.
1488 * @retval #TETHERING_ERROR_NONE Successful
1489 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1490 * @see tethering_create()
1492 API int tethering_destroy(tethering_h tethering)
1495 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1496 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1497 "parameter(tethering) is NULL\n");
1499 __tethering_h *th = (__tethering_h *)tethering;
1501 INFO("Tethering Handle : %p\n", th);
1503 __disconnect_signals(tethering);
1504 _tethering_remove_handle(th);
1509 g_object_unref(th->cancellable);
1510 g_object_unref(th->client_bus_proxy);
1511 g_object_unref(th->client_bus);
1512 memset(th, 0x00, sizeof(__tethering_h));
1517 return TETHERING_ERROR_NONE;
1522 * @brief Enables the tethering, asynchronously.
1524 * @privlevel platform
1525 * @privilege http://tizen.org/privilege/tethering.admin
1526 * @param[in] tethering The handle of tethering
1527 * @param[in] type The type of tethering
1528 * @return 0 on success, otherwise negative error value.
1529 * @retval #TETHERING_ERROR_NONE Successful
1530 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1531 * @post tethering_enabled_cb() will be invoked.
1532 * @see tethering_is_enabled()
1533 * @see tethering_disable()
1535 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1537 INFO("+ type : %d\n", type);
1538 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1539 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1540 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1541 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1543 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1544 "parameter(tethering) is NULL\n");
1546 tethering_error_e ret = TETHERING_ERROR_NONE;
1547 __tethering_h *th = (__tethering_h *)tethering;
1548 GDBusProxy *proxy = th->client_bus_proxy;
1549 GDBusConnection *connection = th->client_bus;
1551 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1553 if (__check_precondition(type) == FALSE) {
1555 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1556 return TETHERING_ERROR_OPERATION_FAILED;
1560 case TETHERING_TYPE_USB:
1561 g_dbus_connection_signal_unsubscribe(connection,
1562 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1564 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1565 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1566 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1567 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1570 case TETHERING_TYPE_WIFI: {
1571 _softap_settings_t set = {"", "", "", 0, false};
1573 ret = __prepare_wifi_settings(tethering, &set);
1574 if (ret != TETHERING_ERROR_NONE) {
1575 ERR("softap settings initialization failed\n");
1577 return TETHERING_ERROR_OPERATION_FAILED;
1579 g_dbus_connection_signal_unsubscribe(connection,
1580 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1582 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
1583 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
1586 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1587 g_variant_new("(sssiiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV4),
1588 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1589 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1593 case TETHERING_TYPE_BT:
1594 g_dbus_connection_signal_unsubscribe(connection,
1595 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1597 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1598 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1599 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1600 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1604 case TETHERING_TYPE_P2P: {
1605 _softap_settings_t p2p_set = {"", "", "", 0, false};
1606 ret = __prepare_wifi_settings(tethering, &p2p_set);
1607 if (ret != TETHERING_ERROR_NONE) {
1608 ERR("p2p settings initialization failed\n");
1609 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1611 return TETHERING_ERROR_OPERATION_FAILED;
1614 g_dbus_proxy_call(proxy, "enable_p2p_tethering",
1615 g_variant_new("(ssi)", p2p_set.ssid, p2p_set.key, p2p_set.channel),
1616 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1617 (GAsyncReadyCallback) __p2p_enabled_cfm_cb, (gpointer)tethering);
1621 case TETHERING_TYPE_ALL: {
1622 _softap_settings_t set = {"", "", "", 0, false};
1624 ret = __prepare_wifi_settings(tethering, &set);
1625 if (ret != TETHERING_ERROR_NONE) {
1626 ERR("softap settings initialization failed\n");
1627 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1628 return TETHERING_ERROR_OPERATION_FAILED;
1631 /* TETHERING_TYPE_USB */
1632 g_dbus_connection_signal_unsubscribe(connection,
1633 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1635 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1636 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1637 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1638 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1640 /* TETHERING_TYPE_WIFI */
1641 g_dbus_connection_signal_unsubscribe(connection,
1642 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1644 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1645 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode,
1646 set.channel, set.visibility, set.mac_filter, set.max_connected,
1647 set.sec_type, TETHERING_ADDRESS_FAMILY_IPV4),
1648 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1649 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1651 /* TETHERING_TYPE_BT */
1652 g_dbus_connection_signal_unsubscribe(connection,
1653 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1655 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1656 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1657 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1658 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1662 ERR("Unknown type : %d\n", type);
1664 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1667 return TETHERING_ERROR_INVALID_PARAMETER;
1670 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1672 return TETHERING_ERROR_NONE;
1675 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1677 DBG("+ type : %d\n", type);
1678 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1679 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1680 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1681 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1683 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1684 "parameter(tethering) is NULL\n");
1686 __tethering_h *th = (__tethering_h *)tethering;
1687 GDBusProxy *proxy = th->client_bus_proxy;
1688 GDBusConnection *connection = th->client_bus;
1691 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1693 if (__check_precondition(type) == FALSE) {
1695 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1696 return TETHERING_ERROR_OPERATION_FAILED;
1700 case TETHERING_TYPE_USB: {
1701 g_dbus_connection_signal_unsubscribe(connection,
1702 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1704 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1705 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1706 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1707 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1711 case TETHERING_TYPE_WIFI: {
1712 _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
1714 ret = __prepare_wifi_settings(tethering, &set);
1715 if (ret != TETHERING_ERROR_NONE) {
1716 ERR("softap settings initialization failed\n");
1718 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1719 return TETHERING_ERROR_OPERATION_FAILED;
1721 g_dbus_connection_signal_unsubscribe(connection,
1722 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1724 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
1725 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
1728 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1729 g_variant_new("(sssiiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, set.txpower, TETHERING_ADDRESS_FAMILY_IPV6),
1730 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1731 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1735 case TETHERING_TYPE_BT: {
1736 g_dbus_connection_signal_unsubscribe(connection,
1737 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1739 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1740 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1741 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1742 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1748 ERR("Unknown type : %d\n", type);
1750 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1753 return TETHERING_ERROR_INVALID_PARAMETER;
1757 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1759 return TETHERING_ERROR_NONE;
1762 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
1764 DBG("+ type : %d\n", type);
1765 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1766 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1767 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1768 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1770 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1771 "parameter(tethering) is NULL\n");
1773 __tethering_h *th = (__tethering_h *)tethering;
1774 GDBusProxy *proxy = th->client_bus_proxy;
1775 GDBusConnection *connection = th->client_bus;
1778 case TETHERING_TYPE_USB:
1779 g_dbus_connection_signal_unsubscribe(connection,
1780 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1782 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1783 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1784 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1785 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1788 case TETHERING_TYPE_WIFI:
1789 DBG("Disable wifi tethering..");
1790 g_dbus_connection_signal_unsubscribe(connection,
1791 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1793 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1794 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1795 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1796 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1799 case TETHERING_TYPE_BT:
1800 g_dbus_connection_signal_unsubscribe(connection,
1801 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1803 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1804 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1805 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1806 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1810 ERR("Not supported tethering type [%d]\n", type);
1812 return TETHERING_ERROR_INVALID_PARAMETER;
1815 return TETHERING_ERROR_NONE;
1819 * @brief Disables the tethering, asynchronously.
1821 * @privlevel platform
1822 * @privilege http://tizen.org/privilege/tethering.admin
1823 * @param[in] tethering The handle of tethering
1824 * @param[in] type The type of tethering
1825 * @return 0 on success, otherwise negative error value.
1826 * @retval #TETHERING_ERROR_NONE Successful
1827 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1828 * @post tethering_disabled_cb() will be invoked.
1829 * @see tethering_is_enabled()
1830 * @see tethering_enable()
1832 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1834 INFO("+ type : %d\n", type);
1835 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1836 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1837 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1838 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1840 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1841 "parameter(tethering) is NULL\n");
1843 __tethering_h *th = (__tethering_h *)tethering;
1844 GDBusProxy *proxy = th->client_bus_proxy;
1845 GDBusConnection *connection = th->client_bus;
1848 case TETHERING_TYPE_USB:
1849 g_dbus_connection_signal_unsubscribe(connection,
1850 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1852 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1853 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1854 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1855 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1859 case TETHERING_TYPE_WIFI:
1861 g_dbus_connection_signal_unsubscribe(connection,
1862 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1864 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1865 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1866 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1867 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1870 case TETHERING_TYPE_BT:
1872 g_dbus_connection_signal_unsubscribe(connection,
1873 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1875 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1876 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1877 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1878 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1881 case TETHERING_TYPE_P2P:
1882 g_dbus_proxy_call(proxy, "disable_p2p_tethering",
1883 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1884 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1887 case TETHERING_TYPE_ALL:
1888 g_dbus_connection_signal_unsubscribe(connection,
1889 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1891 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1892 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1893 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1894 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1896 g_dbus_connection_signal_unsubscribe(connection,
1897 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1899 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1900 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1901 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1902 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1904 g_dbus_connection_signal_unsubscribe(connection,
1905 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1907 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1908 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1909 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1910 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1914 ERR("Not supported tethering type [%d]\n", type);
1916 return TETHERING_ERROR_INVALID_PARAMETER;
1919 return TETHERING_ERROR_NONE;
1924 * @brief Checks whetehr the tethering is enabled or not.
1926 * @privlevel platform
1927 * @privilege http://tizen.org/privilege/tethering.admin
1928 * @param[in] tethering The handle of tethering
1929 * @param[in] type The type of tethering
1930 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1932 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1934 INFO("+ type : %d\n", type);
1936 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1938 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1940 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1944 case TETHERING_TYPE_USB:
1945 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1948 case TETHERING_TYPE_WIFI:
1949 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1952 case TETHERING_TYPE_BT:
1953 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1956 case TETHERING_TYPE_P2P:
1957 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_P2P;
1961 ERR("Not supported type : %d\n", type);
1964 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
1965 return is_on & vconf_type ? true : false;
1970 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1972 * @privlevel platform
1973 * @privilege http://tizen.org/privilege/tethering.admin
1974 * @remarks @a mac_address must be released with free() by you.
1975 * @param[in] tethering The handle of tethering
1976 * @param[in] type The type of tethering
1977 * @param[out] mac_address The MAC address
1978 * @return 0 on success, otherwise a negative error value.
1979 * @retval #TETHERING_ERROR_NONE Successful
1980 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1981 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1982 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1983 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1984 * @pre tethering must be enabled.
1985 * @see tethering_is_enabled()
1986 * @see tethering_enable()
1988 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1990 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1991 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1992 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1993 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1995 _retvm_if(tethering_is_enabled(tethering, type) == false,
1996 TETHERING_ERROR_NOT_ENABLED,
1997 "tethering type[%d] is not enabled\n", type);
1998 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1999 "parameter(tethering) is NULL\n");
2000 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2001 "parameter(mac_address) is NULL\n");
2005 char *macbuf = NULL;
2007 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2008 TETHERING_ERROR_OPERATION_FAILED,
2009 "getting interface name is failed\n");
2011 s = socket(AF_INET, SOCK_DGRAM, 0);
2012 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2013 "getting socket is failed\n");
2014 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2015 ERR("getting mac is failed\n");
2017 return TETHERING_ERROR_OPERATION_FAILED;
2021 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
2022 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2023 "Not enough memory\n");
2024 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
2025 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
2026 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
2027 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
2028 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
2029 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
2030 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
2032 *mac_address = macbuf;
2034 return TETHERING_ERROR_NONE;
2039 * @brief Gets the name of network interface. For example, usb0.
2041 * @privlevel platform
2042 * @privilege http://tizen.org/privilege/tethering.admin
2043 * @remarks @a interface_name must be released with free() by you.
2044 * @param[in] tethering The handle of tethering
2045 * @param[in] type The type of tethering
2046 * @param[out] interface_name The name of network interface
2047 * @return 0 on success, otherwise negative error value.
2048 * @retval #TETHERING_ERROR_NONE Successful
2049 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2050 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2051 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2052 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2053 * @pre tethering must be enabled.
2054 * @see tethering_is_enabled()
2055 * @see tethering_enable()
2057 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
2059 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2060 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2061 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2062 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2064 _retvm_if(tethering_is_enabled(tethering, type) == false,
2065 TETHERING_ERROR_NOT_ENABLED,
2066 "tethering type[%d] is not enabled\n", type);
2067 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2068 "parameter(tethering) is NULL\n");
2069 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2070 "parameter(interface_name) is NULL\n");
2072 char intf[TETHERING_STR_INFO_LEN] = {0, };
2074 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2075 TETHERING_ERROR_OPERATION_FAILED,
2076 "getting interface name is failed\n");
2077 *interface_name = strdup(intf);
2078 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2079 "Not enough memory\n");
2081 return TETHERING_ERROR_NONE;
2086 * @brief Gets the local IP address.
2088 * @privlevel platform
2089 * @privilege http://tizen.org/privilege/tethering.admin
2090 * @remarks @a ip_address must be released with free() by you.
2091 * @param[in] tethering The handle of tethering
2092 * @param[in] type The type of tethering
2093 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2094 * @param[out] ip_address The local IP address
2095 * @return 0 on success, otherwise negative error value.
2096 * @retval #TETHERING_ERROR_NONE Successful
2097 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2098 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2099 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2100 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2101 * @pre tethering must be enabled.
2102 * @see tethering_is_enabled()
2103 * @see tethering_enable()
2105 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2107 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2108 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2109 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2110 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2112 _retvm_if(tethering_is_enabled(tethering, type) == false,
2113 TETHERING_ERROR_NOT_ENABLED,
2114 "tethering type[%d] is not enabled\n", type);
2115 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2116 "parameter(tethering) is NULL\n");
2117 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2118 "parameter(ip_address) is NULL\n");
2124 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2125 TETHERING_ERROR_OPERATION_FAILED,
2126 "getting interface name is failed\n");
2128 s = socket(AF_INET, SOCK_DGRAM, 0);
2129 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2130 "getting socket is failed\n");
2131 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2132 ERR("ioctl is failed\n");
2134 return TETHERING_ERROR_OPERATION_FAILED;
2138 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2139 *ip_address = strdup(ipbuf);
2140 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2141 "Not enough memory\n");
2143 return TETHERING_ERROR_NONE;
2148 * @brief Gets the Gateway address.
2150 * @privlevel platform
2151 * @privilege http://tizen.org/privilege/tethering.admin
2152 * @remarks @a gateway_address must be released with free() by you.
2153 * @param[in] tethering The handle of tethering
2154 * @param[in] type The type of tethering
2155 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2156 * @param[out] gateway_address The local IP address
2157 * @return 0 on success, otherwise negative error value.
2158 * @retval #TETHERING_ERROR_NONE Successful
2159 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2160 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2161 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2162 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2163 * @pre tethering must be enabled.
2164 * @see tethering_is_enabled()
2165 * @see tethering_enable()
2167 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2169 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2170 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2171 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2172 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2174 _retvm_if(tethering_is_enabled(tethering, type) == false,
2175 TETHERING_ERROR_NOT_ENABLED,
2176 "tethering type[%d] is not enabled\n", type);
2177 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2178 "parameter(tethering) is NULL\n");
2179 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2180 "parameter(gateway_address) is NULL\n");
2182 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2184 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2185 TETHERING_ERROR_OPERATION_FAILED,
2186 "getting gateway address is failed\n");
2188 *gateway_address = strdup(gateway_buf);
2190 return TETHERING_ERROR_NONE;
2195 * @brief Gets the Subnet Mask.
2197 * @privlevel platform
2198 * @privilege http://tizen.org/privilege/tethering.admin
2199 * @remarks @a subnet_mask must be released with free() by you.
2200 * @param[in] tethering The handle of tethering
2201 * @param[in] type The type of tethering
2202 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2203 * @param[out] subnet_mask The local IP address
2204 * @return 0 on success, otherwise negative error value.
2205 * @retval #TETHERING_ERROR_NONE Successful
2206 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2207 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2208 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2209 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2210 * @pre tethering must be enabled.
2211 * @see tethering_is_enabled()
2212 * @see tethering_enable()
2214 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2216 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2217 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2218 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2219 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2221 _retvm_if(tethering_is_enabled(tethering, type) == false,
2222 TETHERING_ERROR_NOT_ENABLED,
2223 "tethering is not enabled\n");
2224 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2225 "parameter(tethering) is NULL\n");
2226 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2227 "parameter(subnet_mask) is NULL\n");
2229 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2230 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2231 "Not enough memory\n");
2233 return TETHERING_ERROR_NONE;
2238 * @brief Gets the data usage.
2240 * @privlevel platform
2241 * @privilege http://tizen.org/privilege/tethering.admin
2242 * @param[in] tethering The handle of tethering
2243 * @param[out] usage The data usage
2244 * @return 0 on success, otherwise negative error value.
2245 * @retval #TETHERING_ERROR_NONE Successful
2246 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2247 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2248 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2249 * @pre tethering must be enabled.
2250 * @see tethering_is_enabled()
2251 * @see tethering_enable()
2253 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2255 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2257 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2258 "parameter(tethering) is NULL\n");
2259 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2260 "parameter(callback) is NULL\n");
2261 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2262 TETHERING_ERROR_NOT_ENABLED,
2263 "tethering is not enabled\n");
2265 __tethering_h *th = (__tethering_h *)tethering;
2266 GDBusProxy *proxy = th->client_bus_proxy;
2268 th->data_usage_cb = callback;
2269 th->data_usage_user_data = user_data;
2271 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2272 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2273 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2275 return TETHERING_ERROR_NONE;
2280 * @brief Gets the client which is connected by tethering "type".
2282 * @privlevel platform
2283 * @privilege http://tizen.org/privilege/tethering.admin
2284 * @param[in] tethering The handle of tethering
2285 * @param[in] type The type of tethering
2286 * @param[in] callback The callback function to invoke
2287 * @param[in] user_data The user data to be passed to the callback function
2288 * @retval #TETHERING_ERROR_NONE Successful
2289 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2290 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2291 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2292 * @pre tethering must be enabled.
2293 * @see tethering_is_enabled()
2294 * @see tethering_enable()
2296 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2298 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2299 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2300 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2301 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2303 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2304 "parameter(tethering) is NULL\n");
2305 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2306 "parameter(callback) is NULL\n");
2307 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2308 TETHERING_ERROR_NOT_ENABLED,
2309 "tethering is not enabled\n");
2311 mobile_ap_type_e interface;
2312 __tethering_h *th = (__tethering_h *)tethering;
2313 __tethering_client_h client = {0, };
2316 gchar *hostname = NULL;
2317 guint timestamp = 0;
2318 GError *error = NULL;
2319 GVariant *result = NULL;
2320 GVariantIter *outer_iter = NULL;
2321 GVariantIter *inner_iter = NULL;
2322 GVariant *station = NULL;
2323 GVariant *value = NULL;
2326 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2327 NULL, G_DBUS_CALL_FLAGS_NONE,
2328 -1, th->cancellable, &error);
2331 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
2332 g_error_free(error);
2333 return TETHERING_ERROR_OPERATION_FAILED;
2336 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2337 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2338 g_variant_get(station, "a{sv}", &inner_iter);
2339 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2340 if (g_strcmp0(key, "Type") == 0) {
2341 interface = g_variant_get_int32(value);
2342 if (interface == MOBILE_AP_TYPE_USB)
2343 client.interface = TETHERING_TYPE_USB;
2344 else if (interface == MOBILE_AP_TYPE_WIFI)
2345 client.interface = TETHERING_TYPE_WIFI;
2346 else if (interface == MOBILE_AP_TYPE_BT)
2347 client.interface = TETHERING_TYPE_BT;
2348 else if (interface == MOBILE_AP_TYPE_P2P)
2349 client.interface = TETHERING_TYPE_P2P;
2351 ERR("Invalid interface\n");
2353 g_variant_unref(value);
2356 DBG("interface is %d\n", client.interface);
2357 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2359 g_variant_unref(value);
2362 } else if (g_strcmp0(key, "IP") == 0) {
2363 g_variant_get(value, "s", &ip);
2364 SDBG("ip is %s\n", ip);
2365 g_strlcpy(client.ip, ip, sizeof(client.ip));
2366 } else if (g_strcmp0(key, "MAC") == 0) {
2367 g_variant_get(value, "s", &mac);
2368 SDBG("mac is %s\n", mac);
2369 g_strlcpy(client.mac, mac, sizeof(client.mac));
2370 } else if (g_strcmp0(key, "Name") == 0) {
2371 g_variant_get(value, "s", &hostname);
2372 SDBG("hsotname is %s\n", hostname);
2374 client.hostname = g_strdup(hostname);
2375 } else if (g_strcmp0(key, "Time") == 0) {
2376 timestamp = g_variant_get_int32(value);
2377 DBG("timestamp is %d\n", timestamp);
2378 client.tm = (time_t)timestamp;
2380 ERR("Key %s not required\n", key);
2391 g_variant_iter_free(inner_iter);
2392 if (callback((tethering_client_h)&client, user_data) == false) {
2393 DBG("iteration is stopped\n");
2394 g_free(client.hostname);
2395 client.hostname = NULL;
2396 g_variant_iter_free(outer_iter);
2397 g_variant_unref(result);
2399 return TETHERING_ERROR_OPERATION_FAILED;
2401 g_free(client.hostname);
2402 client.hostname = NULL;
2404 g_variant_iter_free(outer_iter);
2405 g_variant_unref(result);
2407 return TETHERING_ERROR_NONE;
2412 * @brief Registers the callback function called when tethering is enabled.
2414 * @privlevel platform
2415 * @privilege http://tizen.org/privilege/tethering.admin
2416 * @param[in] tethering The handle of tethering
2417 * @param[in] type The type of tethering
2418 * @param[in] callback The callback function to invoke
2419 * @param[in] user_data The user data to be passed to the callback function
2420 * @retval #TETHERING_ERROR_NONE Successful
2421 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2422 * @see tethering_unset_enabled_cb()
2424 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2426 INFO("+ type: %d\n", type);
2427 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2428 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2429 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2430 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2432 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2433 "parameter(tethering) is NULL\n");
2434 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2435 "parameter(callback) is NULL\n");
2437 __tethering_h *th = (__tethering_h *)tethering;
2438 tethering_type_e ti;
2440 if (type != TETHERING_TYPE_ALL) {
2441 th->enabled_cb[type] = callback;
2442 th->enabled_user_data[type] = user_data;
2444 return TETHERING_ERROR_NONE;
2447 /* TETHERING_TYPE_ALL */
2448 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2449 th->enabled_cb[ti] = callback;
2450 th->enabled_user_data[ti] = user_data;
2454 return TETHERING_ERROR_NONE;
2459 * @brief Unregisters the callback function called when tethering is disabled.
2461 * @privlevel platform
2462 * @privilege http://tizen.org/privilege/tethering.admin
2463 * @param[in] tethering The handle of tethering
2464 * @param[in] type The type of tethering
2465 * @retval #TETHERING_ERROR_NONE Successful
2466 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2467 * @see tethering_set_enabled_cb()
2469 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2471 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2472 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2473 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2474 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2476 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2477 "parameter(tethering) is NULL\n");
2479 __tethering_h *th = (__tethering_h *)tethering;
2480 tethering_type_e ti;
2482 if (type != TETHERING_TYPE_ALL) {
2483 th->enabled_cb[type] = NULL;
2484 th->enabled_user_data[type] = NULL;
2486 return TETHERING_ERROR_NONE;
2489 /* TETHERING_TYPE_ALL */
2490 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2491 th->enabled_cb[ti] = NULL;
2492 th->enabled_user_data[ti] = NULL;
2495 return TETHERING_ERROR_NONE;
2500 * @brief Registers the callback function called when tethering is disabled.
2502 * @privlevel platform
2503 * @privilege http://tizen.org/privilege/tethering.admin
2504 * @param[in] tethering The handle of tethering
2505 * @param[in] type The type of tethering
2506 * @param[in] callback The callback function to invoke
2507 * @param[in] user_data The user data to be passed to the callback function
2508 * @retval #TETHERING_ERROR_NONE Successful
2509 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2510 * @see tethering_unset_disabled_cb()
2512 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2514 INFO("+ type: %d\n", type);
2515 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2516 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2517 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2518 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2520 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2521 "parameter(tethering) is NULL\n");
2522 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2523 "parameter(callback) is NULL\n");
2525 __tethering_h *th = (__tethering_h *)tethering;
2526 tethering_type_e ti;
2528 if (type != TETHERING_TYPE_ALL) {
2529 th->disabled_cb[type] = callback;
2530 th->disabled_user_data[type] = user_data;
2532 return TETHERING_ERROR_NONE;
2535 /* TETHERING_TYPE_ALL */
2536 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2537 th->disabled_cb[ti] = callback;
2538 th->disabled_user_data[ti] = user_data;
2541 return TETHERING_ERROR_NONE;
2546 * @brief Unregisters the callback function called when tethering is disabled.
2548 * @privlevel platform
2549 * @privilege http://tizen.org/privilege/tethering.admin
2550 * @param[in] tethering The handle of tethering
2551 * @param[in] type The type of tethering
2552 * @retval #TETHERING_ERROR_NONE Successful
2553 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2554 * @see tethering_set_disabled_cb()
2556 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2558 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2559 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2560 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2561 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2563 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2564 "parameter(tethering) is NULL\n");
2566 __tethering_h *th = (__tethering_h *)tethering;
2567 tethering_type_e ti;
2569 if (type != TETHERING_TYPE_ALL) {
2570 th->disabled_cb[type] = NULL;
2571 th->disabled_user_data[type] = NULL;
2573 return TETHERING_ERROR_NONE;
2576 /* TETHERING_TYPE_ALL */
2577 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2578 th->disabled_cb[ti] = NULL;
2579 th->disabled_user_data[ti] = NULL;
2582 return TETHERING_ERROR_NONE;
2587 * @brief Registers the callback function called when the state of connection is changed.
2589 * @privlevel platform
2590 * @privilege http://tizen.org/privilege/tethering.admin
2591 * @param[in] tethering The handle of tethering
2592 * @param[in] type The type of tethering
2593 * @param[in] callback The callback function to invoke
2594 * @param[in] user_data The user data to be passed to the callback function
2595 * @retval #TETHERING_ERROR_NONE Successful
2596 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2597 * @see tethering_unset_connection_state_changed_cb_cb()
2599 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2601 INFO("+ type: %d\n", type);
2602 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2603 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2604 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2605 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2607 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2608 "parameter(tethering) is NULL\n");
2609 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2610 "parameter(callback) is NULL\n");
2612 __tethering_h *th = (__tethering_h *)tethering;
2613 tethering_type_e ti;
2615 if (type != TETHERING_TYPE_ALL) {
2616 th->changed_cb[type] = callback;
2617 th->changed_user_data[type] = user_data;
2619 return TETHERING_ERROR_NONE;
2622 /* TETHERING_TYPE_ALL */
2623 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2624 th->changed_cb[ti] = callback;
2625 th->changed_user_data[ti] = user_data;
2628 return TETHERING_ERROR_NONE;
2633 * @brief Unregisters the callback function called when the state of connection is changed.
2635 * @privlevel platform
2636 * @privilege http://tizen.org/privilege/tethering.admin
2637 * @param[in] tethering The handle of tethering
2638 * @param[in] type The type of tethering
2639 * @retval #TETHERING_ERROR_NONE Successful
2640 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2641 * @see tethering_set_connection_state_changed_cb()
2643 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2645 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2646 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2647 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2648 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2650 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2651 "parameter(tethering) is NULL\n");
2653 __tethering_h *th = (__tethering_h *)tethering;
2654 tethering_type_e ti;
2656 if (type != TETHERING_TYPE_ALL) {
2657 th->changed_cb[type] = NULL;
2658 th->changed_user_data[type] = NULL;
2660 return TETHERING_ERROR_NONE;
2663 /* TETHERING_TYPE_ALL */
2664 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2665 th->changed_cb[ti] = NULL;
2666 th->changed_user_data[ti] = NULL;
2669 return TETHERING_ERROR_NONE;
2674 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2676 * @privlevel platform
2677 * @privilege http://tizen.org/privilege/tethering.admin
2678 * @param[in] tethering The handle of tethering
2679 * @param[in] callback The callback function to invoke
2680 * @param[in] user_data The user data to be passed to the callback function
2681 * @retval #TETHERING_ERROR_NONE Successful
2682 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2683 * @see tethering_wifi_unset_security_type_changed_cb()
2685 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2687 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2688 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2690 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2691 "parameter(tethering) is NULL\n");
2692 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2693 "parameter(callback) is NULL\n");
2695 __tethering_h *th = (__tethering_h *)tethering;
2697 th->security_type_changed_cb = callback;
2698 th->security_type_user_data = user_data;
2700 return TETHERING_ERROR_NONE;
2706 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2708 * @privlevel platform
2709 * @privilege http://tizen.org/privilege/tethering.admin
2710 * @param[in] tethering The handle of tethering
2711 * @param[in] type The type of tethering
2712 * @retval #TETHERING_ERROR_NONE Successful
2713 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2714 * @see tethering_wifi_set_security_type_changed_cb()
2716 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2718 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2719 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2721 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2722 "parameter(tethering) is NULL\n");
2724 __tethering_h *th = (__tethering_h *)tethering;
2726 th->security_type_changed_cb = NULL;
2727 th->security_type_user_data = NULL;
2729 return TETHERING_ERROR_NONE;
2734 * @brief Registers the callback function called when the visibility of SSID is changed.
2736 * @privlevel platform
2737 * @privilege http://tizen.org/privilege/tethering.admin
2738 * @param[in] tethering The handle of tethering
2739 * @param[in] callback The callback function to invoke
2740 * @param[in] user_data The user data to be passed to the callback function
2741 * @retval #TETHERING_ERROR_NONE Successful
2742 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2743 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2745 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2747 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2748 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2750 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2751 "parameter(tethering) is NULL\n");
2752 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2753 "parameter(callback) is NULL\n");
2755 __tethering_h *th = (__tethering_h *)tethering;
2757 th->ssid_visibility_changed_cb = callback;
2758 th->ssid_visibility_user_data = user_data;
2760 return TETHERING_ERROR_NONE;
2765 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2767 * @privlevel platform
2768 * @privilege http://tizen.org/privilege/tethering.admin
2769 * @param[in] tethering The handle of tethering
2770 * @retval #TETHERING_ERROR_NONE Successful
2771 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2772 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2774 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2776 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2777 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2779 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2780 "parameter(tethering) is NULL\n");
2782 __tethering_h *th = (__tethering_h *)tethering;
2784 th->ssid_visibility_changed_cb = NULL;
2785 th->ssid_visibility_user_data = NULL;
2787 return TETHERING_ERROR_NONE;
2792 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2794 * @privlevel platform
2795 * @privilege http://tizen.org/privilege/tethering.admin
2796 * @param[in] tethering The handle of tethering
2797 * @param[in] callback The callback function to invoke
2798 * @param[in] user_data The user data to be passed to the callback function
2799 * @retval #TETHERING_ERROR_NONE Successful
2800 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2801 * @see tethering_wifi_unset_passphrase_changed_cb()
2803 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2805 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2806 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2808 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2809 "parameter(tethering) is NULL\n");
2810 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2811 "parameter(callback) is NULL\n");
2813 __tethering_h *th = (__tethering_h *)tethering;
2815 th->passphrase_changed_cb = callback;
2816 th->passphrase_user_data = user_data;
2818 return TETHERING_ERROR_NONE;
2823 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2825 * @privlevel platform
2826 * @privilege http://tizen.org/privilege/tethering.admin
2827 * @param[in] tethering The handle of tethering
2828 * @retval #TETHERING_ERROR_NONE Successful
2829 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2830 * @see tethering_wifi_set_passphrase_changed_cb()
2832 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2834 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2835 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2837 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2838 "parameter(tethering) is NULL\n");
2840 __tethering_h *th = (__tethering_h *)tethering;
2842 th->passphrase_changed_cb = NULL;
2843 th->passphrase_user_data = NULL;
2845 return TETHERING_ERROR_NONE;
2850 * @brief Sets the security type of Wi-Fi tethering.
2852 * @privlevel platform
2853 * @privilege http://tizen.org/privilege/tethering.admin
2854 * @remarks This change is applied next time Wi-Fi tethering is enabled
2855 * @param[in] tethering The handle of tethering
2856 * @param[in] type The security type
2857 * @return 0 on success, otherwise negative error value.
2858 * @retval #TETHERING_ERROR_NONE Successful
2859 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2860 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2861 * @see tethering_wifi_get_security_type()
2863 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2865 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2866 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2868 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2869 "parameter(tethering) is NULL\n");
2871 __tethering_h *th = (__tethering_h *)tethering;
2872 tethering_error_e ret = TETHERING_ERROR_NONE;
2873 char *sec_str = NULL;
2875 ret = __set_security_type(type);
2876 if (ret == TETHERING_ERROR_NONE) {
2878 case TETHERING_WIFI_SECURITY_TYPE_NONE:
2879 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
2881 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
2882 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
2884 case TETHERING_WIFI_SECURITY_TYPE_WPS:
2885 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
2887 case TETHERING_WIFI_SECURITY_TYPE_SAE:
2888 sec_str = TETHERING_WIFI_SECURITY_TYPE_SAE_STR;
2892 __send_dbus_signal(th->client_bus,
2893 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
2900 * @brief Gets the security type of Wi-Fi tethering.
2902 * @privlevel platform
2903 * @privilege http://tizen.org/privilege/tethering.admin
2904 * @param[in] tethering The handle of tethering
2905 * @param[out] type The security type
2906 * @return 0 on success, otherwise negative error value.
2907 * @retval #TETHERING_ERROR_NONE Successful
2908 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2909 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2910 * @see tethering_wifi_set_security_type()
2912 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2914 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2915 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2917 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2918 "parameter(tethering) is NULL\n");
2919 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2920 "parameter(type) is NULL\n");
2922 return __get_security_type(type);
2927 * @brief Sets the SSID (service set identifier).
2929 * @privlevel platform
2930 * @privilege http://tizen.org/privilege/tethering.admin
2931 * @details If SSID is not set, Device name is used as SSID
2932 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2933 * @param[in] tethering The handle of tethering
2934 * @param[out] ssid The SSID
2935 * @return 0 on success, otherwise negative error value.
2936 * @retval #TETHERING_ERROR_NONE Successful
2937 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2938 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2940 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2942 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2943 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2945 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2946 "parameter(tethering) is NULL\n");
2947 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2948 "parameter(ssid) is NULL\n");
2950 __tethering_h *th = (__tethering_h *)tethering;
2951 char *p_ssid = NULL;
2954 ssid_len = strlen(ssid);
2955 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2956 ERR("parameter(ssid) is too long");
2957 return TETHERING_ERROR_INVALID_PARAMETER;
2960 p_ssid = strdup(ssid);
2961 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2962 "strdup is failed\n");
2968 return TETHERING_ERROR_NONE;
2973 * @brief Gets the SSID (service set identifier).
2975 * @privlevel platform
2976 * @privilege http://tizen.org/privilege/tethering.admin
2977 * @remarks @a ssid must be released with free() by you.
2978 * @param[in] tethering The handle of tethering
2979 * @param[out] ssid The SSID
2980 * @return 0 on success, otherwise negative error value.
2981 * @retval #TETHERING_ERROR_NONE Successful
2982 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2983 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2984 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2986 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2988 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2989 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2991 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2992 "parameter(tethering) is NULL\n");
2993 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2994 "parameter(ssid) is NULL\n");
2997 __tethering_h *th = (__tethering_h *)tethering;
2998 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
3000 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
3001 if (th->ssid != NULL) {
3002 DBG("Private SSID is set\n");
3003 *ssid = strdup(th->ssid);
3005 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
3006 val, sizeof(val)) == false) {
3007 return TETHERING_ERROR_OPERATION_FAILED;
3009 *ssid = strdup(val);
3012 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
3013 val, sizeof(val)) == false) {
3014 return TETHERING_ERROR_OPERATION_FAILED;
3016 *ssid = strdup(val);
3019 if (*ssid == NULL) {
3020 ERR("strdup is failed\n");
3021 return TETHERING_ERROR_OUT_OF_MEMORY;
3024 return TETHERING_ERROR_NONE;
3029 * @brief Sets the visibility of SSID(service set identifier).
3031 * @privlevel platform
3032 * @privilege http://tizen.org/privilege/tethering.admin
3033 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3034 * @remarks This change is applied next time Wi-Fi tethering is enabled
3035 * @param[in] tethering The handle of tethering
3036 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3037 * @return 0 on success, otherwise negative error value.
3038 * @retval #TETHERING_ERROR_NONE Successful
3039 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3040 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3041 * @see tethering_wifi_get_ssid_visibility()
3043 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
3045 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3046 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3048 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3049 "parameter(tethering) is NULL\n");
3051 __tethering_h *th = (__tethering_h *)tethering;
3052 tethering_error_e ret = TETHERING_ERROR_NONE;
3054 ret = __set_visible(visible);
3055 if (ret == TETHERING_ERROR_NONE) {
3056 __send_dbus_signal(th->client_bus,
3057 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
3058 visible ? SIGNAL_MSG_SSID_VISIBLE :
3059 SIGNAL_MSG_SSID_HIDE);
3066 * @brief Gets the visibility of SSID(service set identifier).
3068 * @privlevel platform
3069 * @privilege http://tizen.org/privilege/tethering.admin
3070 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3071 * @param[in] tethering The handle of tethering
3072 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3073 * @return 0 on success, otherwise negative error value.
3074 * @retval #TETHERING_ERROR_NONE Successful
3075 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3076 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3077 * @see tethering_wifi_set_ssid_visibility()
3079 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
3081 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3082 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3084 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3085 "parameter(tethering) is NULL\n");
3086 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3087 "parameter(visible) is NULL\n");
3089 return __get_visible(visible);
3094 * @brief Sets the passphrase.
3096 * @privlevel platform
3097 * @privilege http://tizen.org/privilege/tethering.admin
3098 * @remarks This change is applied next time Wi-Fi tethering is enabled
3099 * @param[in] tethering The handle of tethering
3100 * @param[in] passphrase The passphrase
3101 * @return 0 on success, otherwise negative error value.
3102 * @retval #TETHERING_ERROR_NONE Successful
3103 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3104 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3105 * @see tethering_wifi_get_passphrase()
3107 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3109 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3110 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3112 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3113 "parameter(tethering) is NULL\n");
3114 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3115 "parameter(passphrase) is NULL\n");
3117 __tethering_h *th = (__tethering_h *)tethering;
3118 GDBusProxy *proxy = th->client_bus_proxy;
3119 GVariant *parameters;
3120 GError *error = NULL;
3121 int passphrase_len = 0;
3125 passphrase_len = strlen(passphrase);
3126 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3127 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3128 ERR("parameter(passphrase) is too short or long\n");
3129 return TETHERING_ERROR_INVALID_PARAMETER;
3132 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3133 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3136 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3138 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3139 ret = TETHERING_ERROR_PERMISSION_DENIED;
3141 ret = TETHERING_ERROR_OPERATION_FAILED;
3143 g_error_free(error);
3147 g_variant_get(parameters, "(u)", &ret);
3148 g_variant_unref(parameters);
3150 if (ret == TETHERING_ERROR_NONE) {
3151 __send_dbus_signal(th->client_bus,
3152 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3161 * @brief Gets the passphrase.
3163 * @privlevel platform
3164 * @privilege http://tizen.org/privilege/tethering.admin
3165 * @remarks @a passphrase must be released with free() by you.
3166 * @param[in] tethering The handle of tethering
3167 * @param[out] passphrase The passphrase
3168 * @return 0 on success, otherwise negative error value.
3169 * @retval #TETHERING_ERROR_NONE Successful
3170 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3171 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3172 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3173 * @see tethering_wifi_set_passphrase()
3175 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3177 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3178 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3180 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3181 "parameter(tethering) is NULL\n");
3182 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3183 "parameter(passphrase) is NULL\n");
3185 __tethering_h *th = (__tethering_h *)tethering;
3186 GDBusProxy *proxy = th->client_bus_proxy;
3187 GVariant *parameters;
3188 GError *error = NULL;
3189 unsigned int len = 0;
3190 tethering_error_e ret = TETHERING_ERROR_NONE;
3192 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3193 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3196 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3198 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3199 ret = TETHERING_ERROR_PERMISSION_DENIED;
3201 ret = TETHERING_ERROR_OPERATION_FAILED;
3203 g_error_free(error);
3207 if (parameters != NULL) {
3208 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3209 g_variant_unref(parameters);
3212 return TETHERING_ERROR_NONE;
3215 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3217 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3218 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3220 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3221 "parameter(tethering) is NULL\n");
3223 __tethering_h *th = (__tethering_h *)tethering;
3224 th->channel = channel;
3226 return TETHERING_ERROR_NONE;
3229 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3231 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3232 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3234 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3235 "parameter(tethering) is NULL\n");
3237 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3238 "parameter(channel) is NULL\n");
3240 __tethering_h *th = (__tethering_h *)tethering;
3241 *channel = th->channel;
3243 return TETHERING_ERROR_NONE;
3246 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3248 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3249 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3251 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3252 "parameter(tethering) is NULL\n");
3254 __tethering_h *th = (__tethering_h *)tethering;
3256 th->mode_type = type;
3258 return TETHERING_ERROR_NONE;
3261 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3263 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3264 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3266 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3267 "parameter(tethering) is NULL\n");
3268 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3269 "parameter(type) is NULL\n");
3271 __tethering_h *th = (__tethering_h *)tethering;
3272 *type = th->mode_type;
3274 return TETHERING_ERROR_NONE;
3280 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3282 * @privlevel platform
3283 * @privilege http://tizen.org/privilege/tethering.admin
3284 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3285 * @param[in] tethering The handle of tethering
3286 * @param[in] callback The callback function to invoke
3287 * @param[in] user_data The user data to be passed to the callback function
3288 * @return 0 on success, otherwise negative error value.
3289 * @retval #TETHERING_ERROR_NONE Successful
3290 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3291 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3293 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3296 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3297 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3299 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3300 "parameter(tethering) is NULL\n");
3301 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3302 "parameter(callback) is NULL\n");
3304 __tethering_h *th = (__tethering_h *)tethering;
3305 _softap_settings_t set = {"", "", "", 0, false};
3306 GDBusProxy *proxy = th->client_bus_proxy;
3311 if (th->settings_reloaded_cb) {
3312 ERR("Operation in progress\n");
3313 return TETHERING_ERROR_OPERATION_FAILED;
3316 ret = __prepare_wifi_settings(tethering, &set);
3317 if (ret != TETHERING_ERROR_NONE) {
3318 ERR("softap settings initialization failed\n");
3319 return TETHERING_ERROR_OPERATION_FAILED;
3322 th->settings_reloaded_cb = callback;
3323 th->settings_reloaded_user_data = user_data;
3325 SINFO("ssid %s, key %s, channel %d, mode %s, txpower %d, security %d max_device %d\n",
3326 set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type,
3329 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3330 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),
3331 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3332 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3334 return TETHERING_ERROR_NONE;
3337 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3339 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3340 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3342 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3343 "parameter(tethering) is NULL\n");
3345 __tethering_h *th = (__tethering_h *)tethering;
3346 th->mac_filter = mac_filter;
3348 return TETHERING_ERROR_NONE;
3351 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3353 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3354 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3356 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3357 "parameter(mac_filter) is NULL\n");
3358 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3359 "parameter(mac_filter) is NULL\n");
3361 __tethering_h *th = (__tethering_h *)tethering;
3362 *mac_filter = th->mac_filter;
3364 return TETHERING_ERROR_NONE;
3367 static int __add_mac_to_file(const char *filepath, const char *mac)
3370 char line[MAX_BUF_SIZE] = "\0";
3371 bool mac_exist = false;
3374 fp = fopen(filepath, "a+");
3376 ERR("fopen is failed\n");
3377 return TETHERING_ERROR_OPERATION_FAILED;
3380 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3381 if (strncmp(mac, line, 17) == 0) {
3382 DBG("MAC %s already exist in the list\n", mac);
3389 p_mac = strdup(mac);
3390 if (p_mac == NULL) {
3391 ERR("strdup failed\n");
3393 return TETHERING_ERROR_OUT_OF_MEMORY;
3396 fprintf(fp, "%s\n", mac);
3398 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3399 allowed_list = g_slist_append(allowed_list, p_mac);
3400 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3401 blocked_list = g_slist_append(blocked_list, p_mac);
3408 return TETHERING_ERROR_NONE;
3411 static int __remove_mac_from_file(const char *filepath, const char *mac)
3415 char line[MAX_BUF_SIZE] = "\0";
3417 fp = fopen(filepath, "r");
3419 ERR("fopen is failed\n");
3420 return TETHERING_ERROR_OPERATION_FAILED;
3423 fp1 = fopen(TEMP_LIST, "w+");
3426 ERR("fopen is failed\n");
3427 return TETHERING_ERROR_OPERATION_FAILED;
3430 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3431 if (strncmp(mac, line, 17) == 0) {
3432 DBG("MAC %s found in the list\n", mac);
3434 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3435 GSList *list = NULL;
3436 for (list = allowed_list; list != NULL; list = list->next) {
3437 char *p_mac = (char *)list->data;
3438 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3439 allowed_list = g_slist_remove(allowed_list, p_mac);
3441 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3442 GSList *list = NULL;
3443 for (list = blocked_list; list != NULL; list = list->next) {
3444 char *p_mac = (char *)list->data;
3445 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3446 blocked_list = g_slist_remove(blocked_list, p_mac);
3450 fprintf(fp1, "%s", line);
3457 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3458 if (rename(TEMP_LIST, ALLOWED_LIST) != 0) {
3459 ERR("rename is failed (%s -> %s)", TEMP_LIST, ALLOWED_LIST);
3460 return TETHERING_ERROR_OPERATION_FAILED;
3462 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3463 if (rename(TEMP_LIST, BLOCKED_LIST) != 0) {
3464 ERR("rename is failed (%s -> %s)", TEMP_LIST, BLOCKED_LIST);
3465 return TETHERING_ERROR_OPERATION_FAILED;
3469 return TETHERING_ERROR_NONE;
3472 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3474 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3475 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3477 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3478 "parameter(tethering) is NULL\n");
3479 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3480 "parameter(mac) is NULL\n");
3482 return __add_mac_to_file(ALLOWED_LIST, mac);
3485 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3487 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3488 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3490 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3491 "parameter(tethering) is NULL\n");
3492 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3493 "parameter(mac) is NULL\n");
3495 return __remove_mac_from_file(ALLOWED_LIST, mac);
3498 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3500 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3501 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3503 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3504 "parameter(tethering) is NULL\n");
3505 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3506 "parameter(allowed_mac_list) is NULL\n");
3508 *allowed_mac_list = g_slist_copy(allowed_list);
3509 return TETHERING_ERROR_NONE;
3512 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3514 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3515 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3517 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3518 "parameter(tethering) is NULL\n");
3519 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3520 "parameter(mac) is NULL\n");
3522 return __add_mac_to_file(BLOCKED_LIST, mac);
3525 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3527 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3528 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3530 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3531 "parameter(tethering) is NULL\n");
3532 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3533 "parameter(mac) is NULL\n");
3535 return __remove_mac_from_file(BLOCKED_LIST, mac);
3538 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3540 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3541 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3543 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3544 "parameter(tethering) is NULL\n");
3545 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3546 "parameter(blocked_mac_list) is NULL\n");
3548 *blocked_mac_list = g_slist_copy(blocked_list);
3549 return TETHERING_ERROR_NONE;
3552 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3554 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3555 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3557 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3558 "parameter(tethering) is NULL\n");
3560 GVariant *parameters;
3561 GError *error = NULL;
3564 __tethering_h *th = (__tethering_h *)tethering;
3566 GDBusProxy *proxy = th->client_bus_proxy;
3568 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3569 g_variant_new("(b)", enable),
3570 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3573 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3574 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3575 result = TETHERING_ERROR_PERMISSION_DENIED;
3577 result = TETHERING_ERROR_OPERATION_FAILED;
3579 g_error_free(error);
3580 th->dhcp_enabled = false;
3585 g_variant_get(parameters, "(u)", &result);
3586 g_variant_unref(parameters);
3589 th->dhcp_enabled = true;
3591 th->dhcp_enabled = false;
3593 return TETHERING_ERROR_NONE;
3596 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3598 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3599 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3601 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3602 "parameter(tethering) is NULL\n");
3603 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3604 "parameter(rangestart) is NULL\n");
3605 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3606 "parameter(rangestop) is NULL\n");
3608 GVariant *parameters;
3609 GError *error = NULL;
3612 __tethering_h *th = (__tethering_h *)tethering;
3614 GDBusProxy *proxy = th->client_bus_proxy;
3616 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3617 g_variant_new("(ss)", rangestart, rangestop),
3618 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3620 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3622 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3623 result = TETHERING_ERROR_PERMISSION_DENIED;
3625 result = TETHERING_ERROR_OPERATION_FAILED;
3627 g_error_free(error);
3628 th->dhcp_enabled = false;
3633 g_variant_get(parameters, "(u)", &result);
3634 g_variant_unref(parameters);
3636 th->dhcp_enabled = true;
3638 return TETHERING_ERROR_NONE;
3641 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3643 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3644 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3646 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3647 "parameter(tethering) is NULL\n");
3648 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3649 "parameter(dhcp_enabled) is NULL\n");
3651 __tethering_h *th = (__tethering_h *)tethering;
3652 *dhcp_enabled = th->dhcp_enabled;
3654 return TETHERING_ERROR_NONE;
3657 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3659 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3660 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3662 GError *error = NULL;
3664 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3665 "parameter(tethering) is NULL\n");
3666 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3667 TETHERING_ERROR_NOT_ENABLED,
3668 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3669 __tethering_h *th = (__tethering_h *)tethering;
3670 th->txpower = txpower;
3672 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3673 g_variant_new("(u)", txpower),
3674 G_DBUS_CALL_FLAGS_NONE,
3675 -1, th->cancellable, &error);
3677 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3678 g_clear_error(&error);
3679 return TETHERING_ERROR_OPERATION_FAILED;
3681 return TETHERING_ERROR_NONE;
3684 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3686 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3687 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3689 GError *error = NULL;
3690 GVariant *result = NULL;
3692 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3693 "parameter(tethering) is NULL\n");
3694 _retvm_if(txpower == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3695 "parameter(txpower) is NULL\n");
3696 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3697 TETHERING_ERROR_NOT_ENABLED,
3698 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3700 __tethering_h *th = (__tethering_h *)tethering;
3702 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3704 G_DBUS_CALL_FLAGS_NONE,
3705 -1, th->cancellable, &error);
3707 if (result != NULL) {
3708 g_variant_get(result, "(u)", txpower);
3709 g_variant_unref(result);
3712 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3713 g_clear_error(&error);
3714 return TETHERING_ERROR_OPERATION_FAILED;
3716 g_clear_error(&error);
3717 return TETHERING_ERROR_NONE;
3720 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
3722 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3723 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3725 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3726 "parameter(tethering) is NULL\n");
3728 GVariant *parameters;
3729 GError *error = NULL;
3732 __tethering_h *th = (__tethering_h *)tethering;
3734 GDBusProxy *proxy = th->client_bus_proxy;
3736 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
3737 g_variant_new("(u)", mtu),
3738 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3740 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3742 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3743 result = TETHERING_ERROR_PERMISSION_DENIED;
3745 result = TETHERING_ERROR_OPERATION_FAILED;
3747 g_error_free(error);
3751 g_variant_get(parameters, "(u)", &result);
3753 g_variant_unref(parameters);
3755 return TETHERING_ERROR_NONE;
3758 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
3760 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3761 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3763 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3764 "parameter(tethering) is NULL\n");
3765 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3766 "parameter(mac) is NULL\n");
3768 GVariant *parameters;
3769 GError *error = NULL;
3772 __tethering_h *th = (__tethering_h *)tethering;
3774 GDBusProxy *proxy = th->client_bus_proxy;
3776 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
3777 g_variant_new("(s)", mac),
3778 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3780 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3782 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3783 result = TETHERING_ERROR_PERMISSION_DENIED;
3785 result = TETHERING_ERROR_OPERATION_FAILED;
3787 g_error_free(error);
3791 g_variant_get(parameters, "(u)", &result);
3792 g_variant_unref(parameters);
3794 if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
3795 return TETHERING_ERROR_NOT_SUPPORT_API;
3797 return TETHERING_ERROR_NONE;
3800 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
3802 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3803 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3805 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3806 "parameter(tethering) is NULL\n");
3808 __tethering_h *th = (__tethering_h *)tethering;
3810 th->wifi_max_connected = max_device;
3812 return TETHERING_ERROR_NONE;
3815 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
3817 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3818 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3820 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3821 "parameter(tethering) is NULL\n");
3822 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3823 "parameter(max_device) is NULL\n");
3825 __tethering_h *th = (__tethering_h *)tethering;
3827 *max_device = th->wifi_max_connected;
3828 return TETHERING_ERROR_NONE;
3831 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
3833 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3834 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3836 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3837 "parameter(tethering) is NULL\n");
3839 GVariant *parameters;
3840 GError *error = NULL;
3843 __tethering_h *th = (__tethering_h *)tethering;
3845 GDBusProxy *proxy = th->client_bus_proxy;
3847 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
3848 g_variant_new("(b)", enable),
3849 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3851 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3853 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3854 result = TETHERING_ERROR_PERMISSION_DENIED;
3856 result = TETHERING_ERROR_OPERATION_FAILED;
3858 g_error_free(error);
3862 g_variant_get(parameters, "(u)", &result);
3863 g_variant_unref(parameters);
3865 th->port_forwarding = true;
3867 return TETHERING_ERROR_NONE;
3870 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)
3872 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3873 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3875 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3876 "parameter(tethering) is NULL\n");
3877 _retvm_if(ifname == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3878 "parameter(ifname) is NULL\n");
3879 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3880 "parameter(protocol) is NULL\n");
3881 _retvm_if(org_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3882 "parameter(org_ip) is NULL\n");
3883 _retvm_if(final_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3884 "parameter(final_ip) is NULL\n");
3886 GVariant *parameters;
3887 GError *error = NULL;
3889 char cmd[MAX_BUF_SIZE] = { 0, };
3892 __tethering_h *th = (__tethering_h *)tethering;
3894 GDBusProxy *proxy = th->client_bus_proxy;
3896 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
3897 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
3898 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3900 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3902 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3903 result = TETHERING_ERROR_PERMISSION_DENIED;
3905 result = TETHERING_ERROR_OPERATION_FAILED;
3907 g_error_free(error);
3911 g_variant_get(parameters, "(u)", &result);
3912 g_variant_unref(parameters);
3914 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);
3918 ERR("strdup failed\n");
3919 return TETHERING_ERROR_OUT_OF_MEMORY;
3922 port_forwarding = g_slist_append(port_forwarding, list);
3924 return TETHERING_ERROR_NONE;
3927 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
3929 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3930 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3932 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3933 "parameter(tethering) is NULL\n");
3935 GVariant *parameters;
3936 GError *error = NULL;
3939 __tethering_h *th = (__tethering_h *)tethering;
3941 GDBusProxy *proxy = th->client_bus_proxy;
3943 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
3944 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3946 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3948 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3949 result = TETHERING_ERROR_PERMISSION_DENIED;
3951 result = TETHERING_ERROR_OPERATION_FAILED;
3953 g_error_free(error);
3957 g_variant_get(parameters, "(u)", &result);
3959 g_variant_unref(parameters);
3961 return TETHERING_ERROR_NONE;
3964 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool *forwarding_enabled)
3966 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3967 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3969 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3970 "parameter(tethering) is NULL\n");
3971 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3972 "parameter(forwarding_enabled) is NULL\n");
3974 __tethering_h *th = (__tethering_h *)tethering;
3976 *forwarding_enabled = th->port_forwarding;
3978 return TETHERING_ERROR_NONE;
3981 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
3983 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3984 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3986 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3987 "parameter(tethering) is NULL\n");
3988 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3989 "parameter(port_forwarding_list) is NULL\n");
3991 *port_forwarding_list = g_slist_copy(port_forwarding);
3992 return TETHERING_ERROR_NONE;
3995 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
3997 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3998 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4000 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4001 "parameter(tethering) is NULL\n");
4003 GVariant *parameters;
4004 GError *error = NULL;
4007 __tethering_h *th = (__tethering_h *)tethering;
4009 GDBusProxy *proxy = th->client_bus_proxy;
4011 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
4012 g_variant_new("(b)", enable),
4013 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4015 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4017 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4018 result = TETHERING_ERROR_PERMISSION_DENIED;
4020 result = TETHERING_ERROR_OPERATION_FAILED;
4022 g_error_free(error);
4026 g_variant_get(parameters, "(u)", &result);
4027 g_variant_unref(parameters);
4029 th->port_filtering = true;
4031 return TETHERING_ERROR_NONE;
4034 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
4036 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4037 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4039 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4040 "parameter(tethering) is NULL\n");
4041 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4042 "parameter(protocol) is NULL\n");
4044 GVariant *parameters;
4045 GError *error = NULL;
4050 __tethering_h *th = (__tethering_h *)tethering;
4052 GDBusProxy *proxy = th->client_bus_proxy;
4054 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
4055 g_variant_new("(isb)", port, protocol, allow),
4056 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4058 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4060 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4061 result = TETHERING_ERROR_PERMISSION_DENIED;
4063 result = TETHERING_ERROR_OPERATION_FAILED;
4065 g_error_free(error);
4069 g_variant_get(parameters, "(u)", &result);
4070 g_variant_unref(parameters);
4073 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
4075 ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
4077 if (ret == -1 || list == NULL) {
4078 ERR("asprintf failed\n");
4079 return TETHERING_ERROR_OUT_OF_MEMORY;
4082 DBG("cmd:%s", list);
4084 port_filtering = g_slist_append(port_filtering, list);
4086 return TETHERING_ERROR_NONE;
4089 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
4091 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4092 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4094 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4095 "parameter(tethering) is NULL\n");
4096 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4097 "parameter(protocol) is NULL\n");
4099 GVariant *parameters;
4100 GError *error = NULL;
4105 __tethering_h *th = (__tethering_h *)tethering;
4107 GDBusProxy *proxy = th->client_bus_proxy;
4109 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
4110 g_variant_new("(iisb)", port1, port2, protocol, allow),
4111 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4113 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4115 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4116 result = TETHERING_ERROR_PERMISSION_DENIED;
4118 result = TETHERING_ERROR_OPERATION_FAILED;
4120 g_error_free(error);
4124 g_variant_get(parameters, "(u)", &result);
4125 g_variant_unref(parameters);
4128 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
4130 ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
4132 if (ret == -1 || list == NULL) {
4133 ERR("asprintf failed\n");
4134 return TETHERING_ERROR_OUT_OF_MEMORY;
4137 DBG("cmd:%s", list);
4139 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4141 return TETHERING_ERROR_NONE;
4144 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4146 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4147 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4149 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4150 "parameter(tethering) is NULL\n");
4151 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4152 "parameter(port_filtering_list) is NULL\n");
4154 *port_filtering_list = g_slist_copy(port_filtering);
4155 return TETHERING_ERROR_NONE;
4158 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4160 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4161 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4163 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4164 "parameter(tethering) is NULL\n");
4165 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4166 "parameter(custom_port_filtering_list) is NULL\n");
4168 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4169 return TETHERING_ERROR_NONE;
4172 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool *filtering_enabled)
4174 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4175 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4177 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4178 "parameter(tethering) is NULL\n");
4179 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4180 "parameter(filtering_enabled) is NULL\n");
4182 __tethering_h *th = (__tethering_h *)tethering;
4184 *filtering_enabled = th->port_filtering;
4186 return TETHERING_ERROR_NONE;
4189 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
4191 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4192 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4194 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4195 "parameter(tethering) is NULL\n");
4197 GVariant *parameters;
4198 GError *error = NULL;
4201 __tethering_h *th = (__tethering_h *)tethering;
4203 GDBusProxy *proxy = th->client_bus_proxy;
4205 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4206 g_variant_new("(ib)", type, enable),
4207 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4209 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4211 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4212 result = TETHERING_ERROR_PERMISSION_DENIED;
4214 result = TETHERING_ERROR_OPERATION_FAILED;
4216 g_error_free(error);
4220 g_variant_get(parameters, "(u)", &result);
4222 g_variant_unref(parameters);
4224 return TETHERING_ERROR_NONE;
4227 API int tethering_wifi_push_wps_button(tethering_h tethering)
4229 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4230 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4232 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4233 "parameter(tethering) is NULL");
4234 __tethering_h *th = (__tethering_h *)tethering;
4235 GDBusProxy *proxy = th->client_bus_proxy;
4236 GVariant *parameters = NULL;
4238 GError *error = NULL;
4240 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4241 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4244 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4246 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4247 ret = TETHERING_ERROR_PERMISSION_DENIED;
4249 ret = TETHERING_ERROR_OPERATION_FAILED;
4251 g_error_free(error);
4255 if (parameters != NULL) {
4256 g_variant_get(parameters, "(u)", &ret);
4257 g_variant_unref(parameters);
4260 return TETHERING_ERROR_NONE;
4263 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4265 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4266 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4268 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4269 "parameter(tethering) is NULL");
4270 _retvm_if(wps_pin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4271 "parameter(wps_pin) is NULL");
4273 __tethering_h *th = (__tethering_h *)tethering;
4274 GDBusProxy *proxy = th->client_bus_proxy;
4275 GVariant *parameters = NULL;
4277 GError *error = NULL;
4279 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4280 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4283 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4285 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4286 ret = TETHERING_ERROR_PERMISSION_DENIED;
4288 ret = TETHERING_ERROR_OPERATION_FAILED;
4290 g_error_free(error);
4294 if (parameters != NULL) {
4295 g_variant_get(parameters, "(u)", &ret);
4296 g_variant_unref(parameters);
4299 return TETHERING_ERROR_NONE;