2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
24 #include <arpa/inet.h>
26 #include <dbus/dbus.h>
29 #include <ckmc/ckmc-manager.h>
30 #include <tzplatform_config.h>
31 #include "tethering_private.h"
33 #define ALLOWED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.accept")
34 #define BLOCKED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.deny")
35 #define TEMP_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/.hostapd_tmp")
36 #define MAC_ADDR_LEN 18
37 #define MAX_BUF_SIZE 80
39 #define IPTABLES "/usr/sbin/iptables"
40 #define TABLE_NAT "nat"
41 #define TETH_NAT_PRE "teth_nat_pre"
42 #define TABLE_FILTER "filter"
43 #define TETH_FILTER_FW "teth_filter_fw"
44 #define ACTION_DROP "DROP"
45 #define ACTION_ACCEPT "ACCEPT"
46 #define PORT_FORWARD_RULE_STR "-t %s -A %s -i %s -p %s -d %s --dport %d -j DNAT --to %s:%d"
47 #define FILTERING_MULTIPORT_RULE_STR "-t %s -A %s -p %s -m multiport --dport %d,%d -j %s"
48 #define FILTERING_RULE_STR "-t %s -A %s -p %s --dport %d -j %s"
50 static GSList *allowed_list = NULL;
51 static GSList *blocked_list = NULL;
52 static GSList *port_forwarding = NULL;
53 static GSList *port_filtering = NULL;
54 static GSList *custom_port_filtering = NULL;
56 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
57 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
58 GVariant *parameters, gpointer user_data);
60 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
61 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
62 GVariant *parameters, gpointer user_data);
64 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
65 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
66 GVariant *parameters, gpointer user_data);
68 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
69 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
70 GVariant *parameters, gpointer user_data);
72 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
73 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
74 GVariant *parameters, gpointer user_data);
76 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
77 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
78 GVariant *parameters, gpointer user_data);
80 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
81 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
82 GVariant *parameters, gpointer user_data);
84 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
85 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
86 GVariant *parameters, gpointer user_data);
88 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
89 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
90 GVariant *parameters, gpointer user_data);
92 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
93 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
94 GVariant *parameters, gpointer user_data);
96 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
97 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
98 GVariant *parameters, gpointer user_data);
100 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
101 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
102 GVariant *parameters, gpointer user_data);
104 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
105 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
106 GVariant *parameters, gpointer user_data);
108 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
109 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
110 GVariant *parameters, gpointer user_data);
112 static __tethering_sig_t sigs[] = {
113 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
114 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
115 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
116 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
117 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
118 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
119 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
120 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
121 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
122 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
123 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
124 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
125 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
126 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
128 static int retry = 0;
130 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
132 if (conn == NULL || signal_name == NULL)
133 return; //LCOV_EXCL_LINE
135 GVariant *message = NULL;
136 GError *error = NULL;
139 message = g_variant_new("(s)", arg);
141 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
142 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
144 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
145 g_error_free(error); //LCOV_EXCL_LINE
149 static bool __any_tethering_is_enabled(tethering_h tethering)
151 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
152 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
153 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
154 tethering_is_enabled(tethering, TETHERING_TYPE_P2P))
160 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
162 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
163 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
164 security_type != TETHERING_WIFI_SECURITY_TYPE_WPS &&
165 security_type != TETHERING_WIFI_SECURITY_TYPE_SAE) {
166 ERR("Invalid param\n"); //LCOV_EXCL_LINE
167 return TETHERING_ERROR_INVALID_PARAMETER;
170 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
171 ERR("vconf_set_int is failed\n"); //LCOV_EXCL_LINE
172 return TETHERING_ERROR_OPERATION_FAILED;
175 return TETHERING_ERROR_NONE;
178 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
180 if (security_type == NULL) {
181 ERR("Invalid param\n"); //LCOV_EXCL_LINE
182 return TETHERING_ERROR_INVALID_PARAMETER;
185 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
186 (int *)security_type) < 0) {
187 ERR("vconf_get_int is failed\n"); //LCOV_EXCL_LINE
188 return TETHERING_ERROR_OPERATION_FAILED;
191 return TETHERING_ERROR_NONE;
194 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
196 if (path == NULL || ssid == NULL || size == 0)
200 char *ptr_tmp = NULL;
202 ptr = vconf_get_str(path);
206 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
209 g_strlcpy(ssid, ptr, size);
215 static tethering_error_e __set_visible(const bool visible)
217 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
218 ERR("vconf_set_int is failed\n"); //LCOV_EXCL_LINE
219 return TETHERING_ERROR_OPERATION_FAILED;
222 return TETHERING_ERROR_NONE;
225 static tethering_error_e __get_visible(bool *visible)
227 if (visible == NULL) {
228 ERR("Invalid param\n"); //LCOV_EXCL_LINE
229 return TETHERING_ERROR_INVALID_PARAMETER;
234 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
235 ERR("vconf_get_int is failed\n"); //LCOV_EXCL_LINE
236 return TETHERING_ERROR_OPERATION_FAILED;
243 return TETHERING_ERROR_NONE;
246 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
248 if (passphrase == NULL ||
249 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
252 guint32 rand_int = 0;
255 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
256 rand_int = g_random_int_range('a', 'z');
257 passphrase[index] = rand_int;
259 passphrase[index] = '\0';
264 static tethering_error_e __get_error(int agent_error)
266 tethering_error_e err = TETHERING_ERROR_NONE;
268 switch (agent_error) {
269 case MOBILE_AP_ERROR_NONE:
270 err = TETHERING_ERROR_NONE;
274 case MOBILE_AP_ERROR_RESOURCE:
275 err = TETHERING_ERROR_OUT_OF_MEMORY;
279 case MOBILE_AP_ERROR_INTERNAL:
280 err = TETHERING_ERROR_OPERATION_FAILED;
283 case MOBILE_AP_ERROR_INVALID_PARAM:
284 err = TETHERING_ERROR_INVALID_PARAMETER;
288 case MOBILE_AP_ERROR_ALREADY_ENABLED:
289 err = TETHERING_ERROR_OPERATION_FAILED;
292 case MOBILE_AP_ERROR_NOT_ENABLED:
293 err = TETHERING_ERROR_NOT_ENABLED;
296 case MOBILE_AP_ERROR_NET_OPEN:
297 err = TETHERING_ERROR_OPERATION_FAILED;
300 case MOBILE_AP_ERROR_NET_CLOSE:
301 err = TETHERING_ERROR_OPERATION_FAILED;
304 case MOBILE_AP_ERROR_DHCP:
305 err = TETHERING_ERROR_OPERATION_FAILED;
308 case MOBILE_AP_ERROR_IN_PROGRESS:
309 err = TETHERING_ERROR_OPERATION_FAILED;
312 case MOBILE_AP_ERROR_NOT_PERMITTED:
313 err = TETHERING_ERROR_NOT_PERMITTED;
316 case MOBILE_AP_ERROR_PERMISSION_DENIED:
317 err = TETHERING_ERROR_PERMISSION_DENIED;
321 ERR("Not defined error : %d\n", agent_error);
322 err = TETHERING_ERROR_OPERATION_FAILED;
330 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
331 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
332 GVariant *parameters, gpointer user_data)
336 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
338 __tethering_h *th = (__tethering_h *)user_data;
340 tethering_type_e type = 0;
341 mobile_ap_type_e ap_type = 0;
342 tethering_connection_state_changed_cb ccb = NULL;
343 __tethering_client_h client;
351 memset(&client, 0, sizeof(__tethering_client_h));
352 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
354 if (!g_strcmp0(buf, "DhcpConnected")) {
356 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
359 ERR("Unknown event [%s]\n", buf);
363 if (ap_type == MOBILE_AP_TYPE_USB)
364 type = TETHERING_TYPE_USB;
365 else if (ap_type == MOBILE_AP_TYPE_WIFI)
366 type = TETHERING_TYPE_WIFI;
367 else if (ap_type == MOBILE_AP_TYPE_BT)
368 type = TETHERING_TYPE_BT;
369 else if (ap_type == MOBILE_AP_TYPE_P2P)
370 type = TETHERING_TYPE_P2P;
372 ERR("Not supported tethering type [%d]\n", ap_type);
376 ccb = th->changed_cb[type];
379 data = th->changed_user_data[type];
381 client.interface = type;
382 g_strlcpy(client.ip, ip, sizeof(client.ip));
383 g_strlcpy(client.mac, mac, sizeof(client.mac));
385 client.hostname = g_strdup(name);
386 client.tm = (time_t)timestamp;
388 ccb((tethering_client_h)&client, opened, data);
389 g_free(client.hostname);
398 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
399 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
400 GVariant *parameters, gpointer user_data)
404 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
406 __tethering_h *th = (__tethering_h *)user_data;
407 tethering_type_e type = 0;
408 tethering_disabled_cb dcb = NULL;
410 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
412 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
413 dcb = th->disabled_cb[type];
416 data = th->disabled_user_data[type];
418 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);
480 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
481 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
482 GVariant *parameters, gpointer user_data)
486 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
488 __tethering_h *th = (__tethering_h *)user_data;
489 tethering_type_e type = TETHERING_TYPE_USB;
490 bool is_requested = false;
491 tethering_enabled_cb ecb = NULL;
494 ecb = th->enabled_cb[type];
497 data = th->enabled_user_data[type];
499 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
503 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
504 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
505 GVariant *parameters, gpointer user_data)
509 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
511 __tethering_h *th = (__tethering_h *)user_data;
512 tethering_type_e type = TETHERING_TYPE_USB;
513 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
514 tethering_disabled_cb dcb = NULL;
518 dcb = th->disabled_cb[type];
521 data = th->disabled_user_data[type];
523 g_variant_get(parameters, "(s)", &buf);
524 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
525 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
527 dcb(TETHERING_ERROR_NONE, type, code, data);
533 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
534 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
535 GVariant *parameters, gpointer user_data)
539 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
541 __tethering_h *th = (__tethering_h *)user_data;
542 tethering_type_e type = TETHERING_TYPE_BT;
543 bool is_requested = false;
544 tethering_enabled_cb ecb = NULL;
547 ecb = th->enabled_cb[type];
550 data = th->enabled_user_data[type];
552 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
556 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
557 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
558 GVariant *parameters, gpointer user_data)
562 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
564 __tethering_h *th = (__tethering_h *)user_data;
565 tethering_type_e type = TETHERING_TYPE_BT;
566 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
567 tethering_disabled_cb dcb = NULL;
571 dcb = th->disabled_cb[type];
574 data = th->disabled_user_data[type];
575 g_variant_get(parameters, "(s)", &buf);
576 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
577 code = TETHERING_DISABLED_BY_BT_OFF;
578 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
579 code = TETHERING_DISABLED_BY_TIMEOUT;
581 dcb(TETHERING_ERROR_NONE, type, code, data);
588 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
589 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
590 GVariant *parameters, gpointer user_data)
594 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
596 __tethering_h *th = (__tethering_h *)user_data;
597 tethering_type_e type = 0;
598 tethering_disabled_cb dcb = NULL;
600 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
602 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
603 dcb = th->disabled_cb[type];
606 data = th->disabled_user_data[type];
608 dcb(TETHERING_ERROR_NONE, type, code, data);
613 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
614 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
615 GVariant *parameters, gpointer user_data)
619 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
621 __tethering_h *th = (__tethering_h *)user_data;
622 tethering_type_e type = 0;
623 tethering_disabled_cb dcb = NULL;
625 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
627 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
628 dcb = th->disabled_cb[type];
631 data = th->disabled_user_data[type];
633 dcb(TETHERING_ERROR_NONE, type, code, data);
638 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
639 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
640 GVariant *parameters, gpointer user_data)
644 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
646 __tethering_h *th = (__tethering_h *)user_data;
647 tethering_type_e type = 0;
648 tethering_disabled_cb dcb = NULL;
650 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
652 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
653 dcb = th->disabled_cb[type];
656 data = th->disabled_user_data[type];
658 dcb(TETHERING_ERROR_NONE, type, code, data);
664 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
665 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
666 GVariant *parameters, gpointer user_data)
671 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
672 __tethering_h *th = (__tethering_h *)user_data;
674 tethering_wifi_security_type_changed_cb scb = NULL;
676 tethering_wifi_security_type_e security_type;
679 scb = th->security_type_changed_cb;
683 g_variant_get(parameters, "(s)", &buf);
684 data = th->security_type_user_data;
685 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
686 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
687 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
688 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
689 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
690 security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
691 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_SAE_STR) == 0)
692 security_type = TETHERING_WIFI_SECURITY_TYPE_SAE;
694 SERR("Unknown type : %s\n", buf); //LCOV_EXCL_LINE
699 scb(security_type, data);
704 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
705 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
706 GVariant *parameters, gpointer user_data)
708 DBG("+\n"); //LCOV_EXCL_LINE
710 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
711 __tethering_h *th = (__tethering_h *)user_data;
713 tethering_wifi_ssid_visibility_changed_cb scb = NULL;
715 bool visible = false;
718 scb = th->ssid_visibility_changed_cb;
720 DBG("-\n"); //LCOV_EXCL_LINE
723 g_variant_get(parameters, "(s)", &buf);
724 data = th->ssid_visibility_user_data;
725 if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0)
730 DBG("-\n"); //LCOV_EXCL_LINE
733 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
734 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
735 GVariant *parameters, gpointer user_data)
737 DBG("+\n"); //LCOV_EXCL_LINE
739 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
740 __tethering_h *th = (__tethering_h *)user_data;
742 tethering_wifi_passphrase_changed_cb pcb = NULL;
745 pcb = th->passphrase_changed_cb;
749 data = th->passphrase_user_data;
752 DBG("-\n"); //LCOV_EXCL_LINE
755 static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
758 INFO("+\n"); //LCOV_EXCL_LINE
760 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
761 GError *g_error = NULL;
764 tethering_error_e error;
765 __tethering_h *th = (__tethering_h *)user_data;
766 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI];
767 void *data = th->enabled_user_data[TETHERING_TYPE_WIFI];
769 if (!_tethering_check_handle((tethering_h)user_data))
772 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
775 ERR("DBus error [%s]\n", g_error->message);
776 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
777 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
778 g_error_free(g_error);
779 tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI);
781 } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
782 error = TETHERING_ERROR_PERMISSION_DENIED;
784 error = TETHERING_ERROR_OPERATION_FAILED;
785 g_error_free(g_error);
788 g_variant_get(g_var, "(u)", &info);
789 error = __get_error(info);
793 INFO("cfm event : wifi tethering enable info : %d\n", error); //LCOV_EXCL_LINE
795 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
796 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
797 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
798 sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
801 INFO("-\n"); //LCOV_EXCL_LINE
804 ecb(error, TETHERING_TYPE_WIFI, true, data);
805 g_variant_unref(g_var);
806 INFO("-\n"); //LCOV_EXCL_LINE
809 static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
812 DBG("+\n"); //LCOV_EXCL_LINE
813 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
814 GError *g_error = NULL;
817 tethering_error_e error;
819 __tethering_h *th = (__tethering_h *)user_data;
820 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT];
821 void *data = th->enabled_user_data[TETHERING_TYPE_BT];
823 if (!_tethering_check_handle((tethering_h)user_data))
826 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
829 ERR("DBus error [%s]\n", g_error->message);
830 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
831 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
832 g_error_free(g_error);
833 tethering_enable((tethering_h)th, TETHERING_TYPE_BT);
837 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
838 error = TETHERING_ERROR_PERMISSION_DENIED;
840 error = TETHERING_ERROR_OPERATION_FAILED;
841 g_error_free(g_error);
844 g_variant_get(g_var, "(u)", &info);
845 g_variant_unref(g_var);
846 error = __get_error(info);
850 sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
851 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name,
852 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
853 sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
856 DBG("-\n"); //LCOV_EXCL_LINE
860 ecb(error, TETHERING_TYPE_BT, true, data);
865 static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
870 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
871 __tethering_h *th = (__tethering_h *)user_data;
872 GError *g_error = NULL;
875 tethering_error_e error;
876 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB];
877 void *data = th->enabled_user_data[TETHERING_TYPE_USB];
879 if (!_tethering_check_handle((tethering_h)user_data))
882 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
884 ERR("DBus error [%s]\n", g_error->message);
885 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
886 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
887 g_error_free(g_error);
888 tethering_enable((tethering_h)th, TETHERING_TYPE_USB);
892 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
893 error = TETHERING_ERROR_PERMISSION_DENIED;
895 error = TETHERING_ERROR_OPERATION_FAILED;
896 g_error_free(g_error);
898 g_variant_get(g_var, "(u)", &info);
899 g_variant_unref(g_var);
900 error = __get_error(info);
904 sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
905 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name,
906 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
907 sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL);
914 ecb(error, TETHERING_TYPE_USB, true, data);
918 static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
923 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
924 __tethering_h *th = (__tethering_h *)user_data;
925 GError *g_error = NULL;
928 tethering_error_e error;
929 tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_P2P];
930 void *data = th->enabled_user_data[TETHERING_TYPE_P2P];
932 if (!_tethering_check_handle((tethering_h)user_data))
935 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
937 ERR("DBus error [%s]\n", g_error->message);
938 if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
939 ++retry < TETHERING_ERROR_RECOVERY_MAX) {
940 g_error_free(g_error);
941 tethering_enable((tethering_h)th, TETHERING_TYPE_P2P);
945 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
946 error = TETHERING_ERROR_PERMISSION_DENIED;
948 error = TETHERING_ERROR_OPERATION_FAILED;
949 g_error_free(g_error);
951 g_variant_get(g_var, "(u)", &info);
952 g_variant_unref(g_var);
953 error = __get_error(info);
962 ecb(error, TETHERING_TYPE_P2P, true, data);
967 static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
970 INFO("+\n"); //LCOV_EXCL_LINE
972 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
973 GError *g_error = NULL;
975 guint info, event_type;
976 tethering_error_e error;
977 tethering_type_e type;
978 tethering_h tethering = (tethering_h)user_data;
979 __tethering_h *th = (__tethering_h *)tethering;
980 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST;
981 tethering_disabled_cb dcb = NULL;
984 if (!_tethering_check_handle((tethering_h)user_data))
987 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
990 ERR("DBus error [%s]\n", g_error->message);
991 g_error_free(g_error);
995 g_variant_get(g_var, "(uu)", &event_type, &info);
996 INFO("cfm event : %d info : %d\n", event_type, info);
997 g_variant_unref(g_var);
998 error = __get_error(info);
999 INFO("cfm event : %d info : %d\n", event_type, error);
1000 switch (event_type) {
1001 case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM:
1002 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1003 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1004 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1005 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1007 type = TETHERING_TYPE_WIFI;
1008 dcb = th->disabled_cb[type];
1009 data = th->disabled_user_data[type];
1011 dcb(error, type, code, data);
1014 case MOBILE_AP_DISABLE_BT_TETHERING_CFM:
1015 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1016 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1017 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1018 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1020 type = TETHERING_TYPE_BT;
1021 dcb = th->disabled_cb[type];
1022 data = th->disabled_user_data[type];
1024 dcb(error, type, code, data);
1028 case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
1029 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1030 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1031 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1032 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1034 type = TETHERING_TYPE_USB;
1035 dcb = th->disabled_cb[type];
1036 data = th->disabled_user_data[type];
1038 dcb(error, type, code, data);
1041 case MOBILE_AP_DISABLE_P2P_TETHERING_CFM:
1042 type = TETHERING_TYPE_P2P;
1043 dcb = th->disabled_cb[type];
1044 data = th->disabled_user_data[type];
1046 dcb(error, type, code, data);
1049 case MOBILE_AP_DISABLE_CFM:
1051 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1052 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name,
1053 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1054 sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL);
1055 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1056 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name,
1057 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1058 sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL);
1059 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
1060 NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
1061 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1062 sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL);
1064 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
1065 dcb = th->disabled_cb[type];
1068 data = th->disabled_user_data[type];
1070 dcb(error, type, code, data);
1075 ERR("Invalid event\n");
1079 INFO("-\n"); //LCOV_EXCL_LINE
1082 static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
1087 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1089 GError *g_error = NULL;
1092 guint64 tx_bytes, rx_bytes;
1093 __tethering_h *th = (__tethering_h *)user_data;
1094 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1097 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1100 ERR("DBus fail [%s]\n", g_error->message);
1101 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1102 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1104 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1109 if (th->data_usage_cb == NULL) {
1110 ERR("There is no data_usage_cb\n"); //LCOV_EXCL_LINE
1114 th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data);
1116 g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes);
1117 th->data_usage_cb(TETHERING_ERROR_NONE,
1118 rx_bytes, tx_bytes, th->data_usage_user_data);
1119 g_variant_unref(g_var);
1121 th->data_usage_cb = NULL;
1122 th->data_usage_user_data = NULL;
1127 static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
1132 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
1133 GError *g_error = NULL;
1136 __tethering_h *th = (__tethering_h *)user_data;
1137 tethering_error_e tethering_error = TETHERING_ERROR_NONE;
1139 g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
1141 ERR("DBus fail [%s]\n", g_error->message); //LCOV_EXCL_LINE
1142 if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
1143 tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
1145 tethering_error = TETHERING_ERROR_OPERATION_FAILED;
1146 g_error_free(g_error);
1148 if (th->settings_reloaded_cb == NULL) {
1149 DBG("There is no settings_reloaded_cb\n-\n");
1152 g_variant_get(g_var, "(u)", &info);
1153 if (tethering_error == TETHERING_ERROR_NONE)
1154 tethering_error = __get_error(info);
1155 g_variant_unref(g_var);
1157 th->settings_reloaded_cb(tethering_error,
1158 th->settings_reloaded_user_data);
1160 th->settings_reloaded_cb = NULL;
1161 th->settings_reloaded_user_data = NULL;
1165 static void __connect_signals(tethering_h tethering)
1168 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1170 __tethering_h *th = (__tethering_h *)tethering;
1171 GDBusConnection *connection = th->client_bus;
1174 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1175 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1176 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1177 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1178 sigs[i].cb, tethering, NULL);
1183 static void __disconnect_signals(tethering_h tethering)
1187 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1189 __tethering_h *th = (__tethering_h *)tethering;
1190 GDBusConnection *connection = th->client_bus;
1194 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1195 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1201 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1203 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1207 case TETHERING_TYPE_USB:
1208 g_strlcpy(buf, TETHERING_USB_IF, len);
1211 case TETHERING_TYPE_WIFI:
1212 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1215 case TETHERING_TYPE_BT:
1216 g_strlcpy(buf, TETHERING_BT_IF, len);
1221 ERR("Not supported type : %d\n", type);
1228 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1230 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1234 case TETHERING_TYPE_USB:
1235 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1238 case TETHERING_TYPE_WIFI:
1239 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1242 case TETHERING_TYPE_BT:
1243 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1247 ERR("Not supported type : %d\n", type);
1254 static int __get_common_ssid(char *ssid, unsigned int size)
1257 ERR("ssid is null\n"); //LCOV_EXCL_LINE
1258 return TETHERING_ERROR_INVALID_PARAMETER;
1262 char *ptr_tmp = NULL;
1264 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1266 ERR("vconf_get_str is failed and set default ssid");
1267 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1269 g_strlcpy(ssid, ptr, size);
1273 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1276 return TETHERING_ERROR_NONE;
1279 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1281 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1284 case TETHERING_WIFI_MODE_TYPE_B:
1285 *buf = g_strdup("b");
1287 case TETHERING_WIFI_MODE_TYPE_G:
1288 *buf = g_strdup("g");
1290 case TETHERING_WIFI_MODE_TYPE_A:
1291 *buf = g_strdup("a");
1293 case TETHERING_WIFI_MODE_TYPE_AD:
1294 *buf = g_strdup("ad");
1297 ERR("Not supported type : %d\n", type);
1303 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1307 __tethering_h *th = (__tethering_h *)tethering;
1308 tethering_error_e ret = TETHERING_ERROR_NONE;
1311 if (th == NULL || set == NULL) {
1312 ERR("null parameter\n-\n"); //LCOV_EXCL_LINE
1313 return TETHERING_ERROR_INVALID_PARAMETER;
1316 if (th->ssid == NULL)
1317 __get_common_ssid(set->ssid, sizeof(set->ssid));
1319 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1321 ret = __get_security_type(&set->sec_type);
1322 if (ret != TETHERING_ERROR_NONE)
1323 set->sec_type = th->sec_type;
1325 ret = __get_visible(&set->visibility);
1326 if (ret != TETHERING_ERROR_NONE)
1327 set->visibility = th->visibility;
1329 set->mac_filter = th->mac_filter;
1330 set->max_connected = th->wifi_max_connected;
1331 set->channel = th->channel;
1333 __get_wifi_mode_type(th->mode_type, &ptr);
1335 g_strlcpy(set->mode, "", sizeof(set->mode));
1337 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1341 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1342 g_strlcpy(set->key, "", sizeof(set->key));
1344 GDBusProxy *proxy = th->client_bus_proxy;
1345 GVariant *parameters;
1346 GError *error = NULL;
1347 char *passphrase = NULL;
1348 unsigned int len = 0;
1350 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1351 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1355 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1357 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1358 ret = TETHERING_ERROR_PERMISSION_DENIED;
1360 ret = TETHERING_ERROR_OPERATION_FAILED;
1362 g_error_free(error);
1367 if (parameters != NULL) {
1368 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1369 g_strlcpy(set->key, passphrase, sizeof(set->key) - 1);
1371 g_variant_unref(parameters);
1375 INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
1376 set->ssid, set->sec_type, set->mode, set->channel,
1377 (set->visibility) ? "true" : "false");
1379 return TETHERING_ERROR_NONE;
1382 static bool __check_precondition(tethering_type_e type)
1384 int dnet_status = 0;
1385 int cellular_state = 0;
1387 /* data network through cellular */
1388 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1389 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1390 INFO("Data Network can be connected later");
1394 /* data network status */
1395 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
1396 if ((dnet_status == VCONFKEY_NETWORK_WIFI
1397 && type != TETHERING_TYPE_WIFI)
1398 || dnet_status == VCONFKEY_NETWORK_ETHERNET)
1401 ERR("Network is not available!");
1407 * @brief Creates the handle of tethering.
1409 * @privlevel platform
1410 * @privilege http://tizen.org/privilege/tethering.admin
1411 * @remarks The @a tethering must be released tethering_destroy() by you.
1412 * @param[out] tethering A handle of a new mobile ap handle on success
1413 * @return 0 on success, otherwise a negative error value.
1414 * @retval #TETHERING_ERROR_NONE Successful
1415 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1416 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1417 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1418 * @see tethering_destroy()
1420 API int tethering_create(tethering_h *tethering)
1422 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1423 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1424 "parameter(tethering) is NULL\n");
1427 __tethering_h *th = NULL;
1428 GError *error = NULL;
1429 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1431 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1433 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1434 "malloc is failed\n");
1435 memset(th, 0x00, sizeof(__tethering_h));
1436 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1437 th->visibility = true;
1438 th->mac_filter = false;
1439 th->channel = TETHERING_WIFI_CHANNEL;
1440 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1441 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1443 if (__generate_initial_passphrase(th->passphrase,
1444 sizeof(th->passphrase)) == 0) {
1446 ERR("random passphrase generation failed\n");
1448 return TETHERING_ERROR_OPERATION_FAILED;
1452 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1454 ERR("common ssid get failed\n");
1456 return TETHERING_ERROR_OPERATION_FAILED;
1460 #if !GLIB_CHECK_VERSION(2, 36, 0)
1463 GCancellable *cancellable = g_cancellable_new();
1464 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1467 ERR("Couldn't connect to the System bus[%s]", error->message);
1468 g_error_free(error);
1469 g_cancellable_cancel(cancellable);
1470 g_object_unref(cancellable);
1472 return TETHERING_ERROR_OPERATION_FAILED;
1475 th->cancellable = cancellable;
1477 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1478 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1479 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1480 if (!th->client_bus_proxy) {
1483 ERR("Couldn't create the proxy object because of %s\n", error->message);
1484 g_cancellable_cancel(th->cancellable);
1485 g_object_unref(th->cancellable);
1486 g_object_unref(th->client_bus);
1488 return TETHERING_ERROR_OPERATION_FAILED;
1492 __connect_signals((tethering_h)th);
1494 *tethering = (tethering_h)th;
1495 _tethering_add_handle(th);
1496 INFO("Tethering Handle : %p\n", th);
1498 return TETHERING_ERROR_NONE;
1503 * @brief Destroys the handle of tethering.
1505 * @privlevel platform
1506 * @privilege http://tizen.org/privilege/tethering.admin
1507 * @param[in] tethering The handle of tethering
1508 * @return 0 on success, otherwise a negative error value.
1509 * @retval #TETHERING_ERROR_NONE Successful
1510 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1511 * @see tethering_create()
1513 API int tethering_destroy(tethering_h tethering)
1516 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1517 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1518 "parameter(tethering) is NULL\n");
1520 __tethering_h *th = (__tethering_h *)tethering;
1522 INFO("Tethering Handle : %p\n", th);
1524 __disconnect_signals(tethering);
1525 _tethering_remove_handle(th);
1530 g_object_unref(th->cancellable);
1531 g_object_unref(th->client_bus_proxy);
1532 g_object_unref(th->client_bus);
1533 memset(th, 0x00, sizeof(__tethering_h));
1538 return TETHERING_ERROR_NONE;
1543 * @brief Enables the tethering, asynchronously.
1545 * @privlevel platform
1546 * @privilege http://tizen.org/privilege/tethering.admin
1547 * @param[in] tethering The handle of tethering
1548 * @param[in] type The type of tethering
1549 * @return 0 on success, otherwise negative error value.
1550 * @retval #TETHERING_ERROR_NONE Successful
1551 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1552 * @post tethering_enabled_cb() will be invoked.
1553 * @see tethering_is_enabled()
1554 * @see tethering_disable()
1556 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1558 INFO("+ type : %d\n", type);
1559 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1560 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1561 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1562 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1564 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1565 "parameter(tethering) is NULL\n");
1567 tethering_error_e ret = TETHERING_ERROR_NONE;
1568 __tethering_h *th = (__tethering_h *)tethering;
1569 GDBusProxy *proxy = th->client_bus_proxy;
1570 GDBusConnection *connection = th->client_bus;
1572 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1574 if (__check_precondition(type) == FALSE) {
1577 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1578 return TETHERING_ERROR_OPERATION_FAILED;
1584 case TETHERING_TYPE_USB:
1585 g_dbus_connection_signal_unsubscribe(connection,
1586 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1588 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1589 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1590 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1591 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1595 case TETHERING_TYPE_WIFI: {
1596 _softap_settings_t set = {"", "", "", 0, false};
1598 ret = __prepare_wifi_settings(tethering, &set);
1599 if (ret != TETHERING_ERROR_NONE) {
1601 ERR("softap settings initialization failed\n");
1603 return TETHERING_ERROR_OPERATION_FAILED;
1606 g_dbus_connection_signal_unsubscribe(connection,
1607 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1609 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1610 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, TETHERING_ADDRESS_FAMILY_IPV4),
1611 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1612 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1616 case TETHERING_TYPE_BT:
1617 g_dbus_connection_signal_unsubscribe(connection,
1618 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1620 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1621 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1622 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1623 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1628 case TETHERING_TYPE_P2P: {
1629 _softap_settings_t p2p_set = {"", "", "", 0, false};
1630 ret = __prepare_wifi_settings(tethering, &p2p_set);
1631 if (ret != TETHERING_ERROR_NONE) {
1632 ERR("p2p settings initialization failed\n");
1633 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1635 return TETHERING_ERROR_OPERATION_FAILED;
1638 g_dbus_proxy_call(proxy, "enable_p2p_tethering",
1639 g_variant_new("(ssi)", p2p_set.ssid, p2p_set.key, p2p_set.channel),
1640 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1641 (GAsyncReadyCallback) __p2p_enabled_cfm_cb, (gpointer)tethering);
1645 case TETHERING_TYPE_ALL: {
1646 _softap_settings_t set = {"", "", "", 0, false};
1648 ret = __prepare_wifi_settings(tethering, &set);
1649 if (ret != TETHERING_ERROR_NONE) {
1650 ERR("softap settings initialization failed\n");
1651 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1652 return TETHERING_ERROR_OPERATION_FAILED;
1655 /* TETHERING_TYPE_USB */
1656 g_dbus_connection_signal_unsubscribe(connection,
1657 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1659 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1660 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1661 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1662 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1664 /* TETHERING_TYPE_WIFI */
1665 g_dbus_connection_signal_unsubscribe(connection,
1666 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1668 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1669 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode,
1670 set.channel, set.visibility, set.mac_filter, set.max_connected,
1671 set.sec_type, TETHERING_ADDRESS_FAMILY_IPV4),
1672 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1673 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1675 /* TETHERING_TYPE_BT */
1676 g_dbus_connection_signal_unsubscribe(connection,
1677 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1679 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1680 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1681 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1682 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1686 ERR("Unknown type : %d\n", type);
1688 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1691 return TETHERING_ERROR_INVALID_PARAMETER;
1695 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1697 return TETHERING_ERROR_NONE;
1700 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1702 DBG("+ type : %d\n", type);
1703 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1704 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1705 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1706 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1708 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1709 "parameter(tethering) is NULL\n");
1711 __tethering_h *th = (__tethering_h *)tethering;
1712 GDBusProxy *proxy = th->client_bus_proxy;
1713 GDBusConnection *connection = th->client_bus;
1716 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1718 if (__check_precondition(type) == FALSE) {
1721 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1722 return TETHERING_ERROR_OPERATION_FAILED;
1727 case TETHERING_TYPE_USB: {
1728 g_dbus_connection_signal_unsubscribe(connection,
1729 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1731 g_dbus_proxy_call(proxy, "enable_usb_tethering",
1732 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1733 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1734 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1738 case TETHERING_TYPE_WIFI: {
1739 _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
1741 ret = __prepare_wifi_settings(tethering, &set);
1742 if (ret != TETHERING_ERROR_NONE) {
1743 ERR("softap settings initialization failed\n");
1745 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1746 return TETHERING_ERROR_OPERATION_FAILED;
1748 g_dbus_connection_signal_unsubscribe(connection,
1749 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1750 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1751 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type, TETHERING_ADDRESS_FAMILY_IPV6),
1752 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1753 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1757 case TETHERING_TYPE_BT: {
1758 g_dbus_connection_signal_unsubscribe(connection,
1759 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1761 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1762 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1763 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1764 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1770 ERR("Unknown type : %d\n", type);
1772 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1775 return TETHERING_ERROR_INVALID_PARAMETER;
1779 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1781 return TETHERING_ERROR_NONE;
1784 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
1786 DBG("+ type : %d\n", type);
1787 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1788 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1789 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1790 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1792 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1793 "parameter(tethering) is NULL\n");
1795 __tethering_h *th = (__tethering_h *)tethering;
1796 GDBusProxy *proxy = th->client_bus_proxy;
1797 GDBusConnection *connection = th->client_bus;
1800 case TETHERING_TYPE_USB:
1801 g_dbus_connection_signal_unsubscribe(connection,
1802 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1804 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1805 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1806 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1807 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1810 case TETHERING_TYPE_WIFI:
1811 DBG("Disable wifi tethering..");
1812 g_dbus_connection_signal_unsubscribe(connection,
1813 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1815 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1816 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1817 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1818 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1821 case TETHERING_TYPE_BT:
1822 g_dbus_connection_signal_unsubscribe(connection,
1823 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1825 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1826 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1827 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1828 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1832 ERR("Not supported tethering type [%d]\n", type);
1834 return TETHERING_ERROR_INVALID_PARAMETER;
1837 return TETHERING_ERROR_NONE;
1841 * @brief Disables the tethering, asynchronously.
1843 * @privlevel platform
1844 * @privilege http://tizen.org/privilege/tethering.admin
1845 * @param[in] tethering The handle of tethering
1846 * @param[in] type The type of tethering
1847 * @return 0 on success, otherwise negative error value.
1848 * @retval #TETHERING_ERROR_NONE Successful
1849 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1850 * @post tethering_disabled_cb() will be invoked.
1851 * @see tethering_is_enabled()
1852 * @see tethering_enable()
1854 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1856 INFO("+ type : %d\n", type);
1857 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1858 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1859 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1860 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1862 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1863 "parameter(tethering) is NULL\n");
1865 __tethering_h *th = (__tethering_h *)tethering;
1866 GDBusProxy *proxy = th->client_bus_proxy;
1867 GDBusConnection *connection = th->client_bus;
1871 case TETHERING_TYPE_USB:
1872 g_dbus_connection_signal_unsubscribe(connection,
1873 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1875 g_dbus_proxy_call(proxy, "disable_usb_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);
1883 case TETHERING_TYPE_WIFI:
1885 g_dbus_connection_signal_unsubscribe(connection,
1886 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1888 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1889 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1890 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1891 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1894 case TETHERING_TYPE_BT:
1896 g_dbus_connection_signal_unsubscribe(connection,
1897 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1899 g_dbus_proxy_call(proxy, "disable_bt_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);
1906 case TETHERING_TYPE_P2P:
1907 g_dbus_proxy_call(proxy, "disable_p2p_tethering",
1908 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1909 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1912 case TETHERING_TYPE_ALL:
1913 g_dbus_connection_signal_unsubscribe(connection,
1914 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1916 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1917 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1918 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1919 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1921 g_dbus_connection_signal_unsubscribe(connection,
1922 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1924 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1925 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1926 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1927 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1929 g_dbus_connection_signal_unsubscribe(connection,
1930 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1932 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1933 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1934 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1935 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1939 ERR("Not supported tethering type [%d]\n", type);
1941 return TETHERING_ERROR_INVALID_PARAMETER;
1945 return TETHERING_ERROR_NONE;
1950 * @brief Checks whetehr the tethering is enabled or not.
1952 * @privlevel platform
1953 * @privilege http://tizen.org/privilege/tethering.admin
1954 * @param[in] tethering The handle of tethering
1955 * @param[in] type The type of tethering
1956 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1958 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1960 INFO("+ type : %d\n", type);
1962 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1964 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1966 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1970 case TETHERING_TYPE_USB:
1971 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1974 case TETHERING_TYPE_WIFI:
1975 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1978 case TETHERING_TYPE_BT:
1979 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1982 case TETHERING_TYPE_P2P:
1983 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_P2P;
1987 ERR("Not supported type : %d\n", type);
1990 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
1991 return is_on & vconf_type ? true : false;
1996 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1998 * @privlevel platform
1999 * @privilege http://tizen.org/privilege/tethering.admin
2000 * @remarks @a mac_address must be released with free() by you.
2001 * @param[in] tethering The handle of tethering
2002 * @param[in] type The type of tethering
2003 * @param[out] mac_address The MAC address
2004 * @return 0 on success, otherwise a negative error value.
2005 * @retval #TETHERING_ERROR_NONE Successful
2006 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2007 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2008 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2009 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2010 * @pre tethering must be enabled.
2011 * @see tethering_is_enabled()
2012 * @see tethering_enable()
2014 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
2016 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2017 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); //LCOV_EXCL_LINE
2018 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2019 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); //LCOV_EXCL_LINE
2021 _retvm_if(tethering_is_enabled(tethering, type) == false,
2022 TETHERING_ERROR_NOT_ENABLED,
2023 "tethering type[%d] is not enabled\n", type);
2024 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2025 "parameter(tethering) is NULL\n");
2026 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2027 "parameter(mac_address) is NULL\n");
2031 char *macbuf = NULL;
2033 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2034 TETHERING_ERROR_OPERATION_FAILED,
2035 "getting interface name is failed\n");
2037 s = socket(AF_INET, SOCK_DGRAM, 0);
2038 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2039 "getting socket is failed\n");
2040 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2042 ERR("getting mac is failed\n");
2044 return TETHERING_ERROR_OPERATION_FAILED;
2049 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
2050 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2051 "Not enough memory\n");
2052 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
2053 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
2054 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
2055 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
2056 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
2057 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
2058 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
2060 *mac_address = macbuf;
2062 return TETHERING_ERROR_NONE;
2067 * @brief Gets the name of network interface. For example, usb0.
2069 * @privlevel platform
2070 * @privilege http://tizen.org/privilege/tethering.admin
2071 * @remarks @a interface_name must be released with free() by you.
2072 * @param[in] tethering The handle of tethering
2073 * @param[in] type The type of tethering
2074 * @param[out] interface_name The name of network interface
2075 * @return 0 on success, otherwise negative error value.
2076 * @retval #TETHERING_ERROR_NONE Successful
2077 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2078 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2079 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2080 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2081 * @pre tethering must be enabled.
2082 * @see tethering_is_enabled()
2083 * @see tethering_enable()
2085 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
2087 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2088 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2089 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2090 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2092 _retvm_if(tethering_is_enabled(tethering, type) == false,
2093 TETHERING_ERROR_NOT_ENABLED,
2094 "tethering type[%d] is not enabled\n", type);
2095 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2096 "parameter(tethering) is NULL\n");
2097 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2098 "parameter(interface_name) is NULL\n");
2100 char intf[TETHERING_STR_INFO_LEN] = {0, };
2102 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2103 TETHERING_ERROR_OPERATION_FAILED,
2104 "getting interface name is failed\n");
2105 *interface_name = strdup(intf);
2106 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2107 "Not enough memory\n");
2109 return TETHERING_ERROR_NONE;
2114 * @brief Gets the local IP address.
2116 * @privlevel platform
2117 * @privilege http://tizen.org/privilege/tethering.admin
2118 * @remarks @a ip_address must be released with free() by you.
2119 * @param[in] tethering The handle of tethering
2120 * @param[in] type The type of tethering
2121 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2122 * @param[out] ip_address The local IP address
2123 * @return 0 on success, otherwise negative error value.
2124 * @retval #TETHERING_ERROR_NONE Successful
2125 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2126 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2127 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2128 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2129 * @pre tethering must be enabled.
2130 * @see tethering_is_enabled()
2131 * @see tethering_enable()
2133 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2135 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2136 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); //LCOV_EXCL_LINE
2137 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2138 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); //LCOV_EXCL_LINE
2140 _retvm_if(tethering_is_enabled(tethering, type) == false,
2141 TETHERING_ERROR_NOT_ENABLED,
2142 "tethering type[%d] is not enabled\n", type);
2143 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2144 "parameter(tethering) is NULL\n");
2145 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2146 "parameter(ip_address) is NULL\n");
2152 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2153 TETHERING_ERROR_OPERATION_FAILED,
2154 "getting interface name is failed\n");
2156 s = socket(AF_INET, SOCK_DGRAM, 0);
2157 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2158 "getting socket is failed\n");
2159 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2160 ERR("ioctl is failed\n");
2162 return TETHERING_ERROR_OPERATION_FAILED;
2166 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2167 *ip_address = strdup(ipbuf);
2168 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2169 "Not enough memory\n");
2171 return TETHERING_ERROR_NONE;
2176 * @brief Gets the Gateway address.
2178 * @privlevel platform
2179 * @privilege http://tizen.org/privilege/tethering.admin
2180 * @remarks @a gateway_address must be released with free() by you.
2181 * @param[in] tethering The handle of tethering
2182 * @param[in] type The type of tethering
2183 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2184 * @param[out] gateway_address The local IP address
2185 * @return 0 on success, otherwise negative error value.
2186 * @retval #TETHERING_ERROR_NONE Successful
2187 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2188 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2189 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2190 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2191 * @pre tethering must be enabled.
2192 * @see tethering_is_enabled()
2193 * @see tethering_enable()
2195 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2197 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2198 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2199 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2200 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2202 _retvm_if(tethering_is_enabled(tethering, type) == false,
2203 TETHERING_ERROR_NOT_ENABLED,
2204 "tethering type[%d] is not enabled\n", type);
2205 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2206 "parameter(tethering) is NULL\n");
2207 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2208 "parameter(gateway_address) is NULL\n");
2210 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2212 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2213 TETHERING_ERROR_OPERATION_FAILED,
2214 "getting gateway address is failed\n");
2216 *gateway_address = strdup(gateway_buf);
2218 return TETHERING_ERROR_NONE;
2223 * @brief Gets the Subnet Mask.
2225 * @privlevel platform
2226 * @privilege http://tizen.org/privilege/tethering.admin
2227 * @remarks @a subnet_mask must be released with free() by you.
2228 * @param[in] tethering The handle of tethering
2229 * @param[in] type The type of tethering
2230 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2231 * @param[out] subnet_mask The local IP address
2232 * @return 0 on success, otherwise negative error value.
2233 * @retval #TETHERING_ERROR_NONE Successful
2234 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2235 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2236 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2237 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2238 * @pre tethering must be enabled.
2239 * @see tethering_is_enabled()
2240 * @see tethering_enable()
2242 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2244 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2245 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2246 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2247 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2249 _retvm_if(tethering_is_enabled(tethering, type) == false,
2250 TETHERING_ERROR_NOT_ENABLED,
2251 "tethering is not enabled\n");
2252 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2253 "parameter(tethering) is NULL\n");
2254 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2255 "parameter(subnet_mask) is NULL\n");
2257 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2258 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2259 "Not enough memory\n");
2261 return TETHERING_ERROR_NONE;
2266 * @brief Gets the data usage.
2268 * @privlevel platform
2269 * @privilege http://tizen.org/privilege/tethering.admin
2270 * @param[in] tethering The handle of tethering
2271 * @param[out] usage The data usage
2272 * @return 0 on success, otherwise negative error value.
2273 * @retval #TETHERING_ERROR_NONE Successful
2274 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2275 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2276 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2277 * @pre tethering must be enabled.
2278 * @see tethering_is_enabled()
2279 * @see tethering_enable()
2281 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2283 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2285 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2286 "parameter(tethering) is NULL\n");
2287 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2288 "parameter(callback) is NULL\n");
2289 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2290 TETHERING_ERROR_NOT_ENABLED,
2291 "tethering is not enabled\n");
2293 __tethering_h *th = (__tethering_h *)tethering;
2294 GDBusProxy *proxy = th->client_bus_proxy;
2296 th->data_usage_cb = callback;
2297 th->data_usage_user_data = user_data;
2299 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2300 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2301 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2303 return TETHERING_ERROR_NONE;
2308 * @brief Gets the client which is connected by tethering "type".
2310 * @privlevel platform
2311 * @privilege http://tizen.org/privilege/tethering.admin
2312 * @param[in] tethering The handle of tethering
2313 * @param[in] type The type of tethering
2314 * @param[in] callback The callback function to invoke
2315 * @param[in] user_data The user data to be passed to the callback function
2316 * @retval #TETHERING_ERROR_NONE Successful
2317 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2318 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2319 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2320 * @pre tethering must be enabled.
2321 * @see tethering_is_enabled()
2322 * @see tethering_enable()
2324 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2326 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2327 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2328 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2329 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2331 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2332 "parameter(tethering) is NULL\n");
2333 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2334 "parameter(callback) is NULL\n");
2335 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2336 TETHERING_ERROR_NOT_ENABLED,
2337 "tethering is not enabled\n");
2339 mobile_ap_type_e interface;
2340 __tethering_h *th = (__tethering_h *)tethering;
2341 __tethering_client_h client = {0, };
2344 gchar *hostname = NULL;
2345 guint timestamp = 0;
2346 GError *error = NULL;
2347 GVariant *result = NULL;
2348 GVariantIter *outer_iter = NULL;
2349 GVariantIter *inner_iter = NULL;
2350 GVariant *station = NULL;
2351 GVariant *value = NULL;
2354 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2355 NULL, G_DBUS_CALL_FLAGS_NONE,
2356 -1, th->cancellable, &error);
2358 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message); //LCOV_EXCL_LINE
2359 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2361 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2362 g_variant_get(station, "a{sv}", &inner_iter);
2363 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2364 if (g_strcmp0(key, "Type") == 0) {
2365 interface = g_variant_get_int32(value);
2366 if (interface == MOBILE_AP_TYPE_USB)
2367 client.interface = TETHERING_TYPE_USB;
2368 else if (interface == MOBILE_AP_TYPE_WIFI)
2369 client.interface = TETHERING_TYPE_WIFI;
2370 else if (interface == MOBILE_AP_TYPE_BT)
2371 client.interface = TETHERING_TYPE_BT;
2372 else if (interface == MOBILE_AP_TYPE_P2P)
2373 client.interface = TETHERING_TYPE_P2P;
2375 ERR("Invalid interface\n");
2377 g_variant_unref(value);
2380 DBG("interface is %d\n", client.interface);
2381 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2383 g_variant_unref(value);
2386 } else if (g_strcmp0(key, "IP") == 0) {
2387 g_variant_get(value, "s", &ip);
2388 SDBG("ip is %s\n", ip);
2389 g_strlcpy(client.ip, ip, sizeof(client.ip));
2390 } else if (g_strcmp0(key, "MAC") == 0) {
2391 g_variant_get(value, "s", &mac);
2392 SDBG("mac is %s\n", mac);
2393 g_strlcpy(client.mac, mac, sizeof(client.mac));
2394 } else if (g_strcmp0(key, "Name") == 0) {
2395 g_variant_get(value, "s", &hostname);
2396 SDBG("hsotname is %s\n", hostname);
2398 client.hostname = g_strdup(hostname);
2399 } else if (g_strcmp0(key, "Time") == 0) {
2400 timestamp = g_variant_get_int32(value);
2401 DBG("timestamp is %d\n", timestamp);
2402 client.tm = (time_t)timestamp;
2404 ERR("Key %s not required\n", key);
2415 g_variant_iter_free(inner_iter);
2416 if (callback((tethering_client_h)&client, user_data) == false) {
2417 DBG("iteration is stopped\n");
2418 g_free(client.hostname);
2419 client.hostname = NULL;
2420 g_variant_iter_free(outer_iter);
2421 g_variant_unref(station);
2422 g_variant_unref(result);
2424 return TETHERING_ERROR_OPERATION_FAILED;
2426 g_free(client.hostname);
2427 client.hostname = NULL;
2430 g_variant_iter_free(outer_iter);
2431 g_variant_unref(station);
2432 g_variant_unref(result);
2434 return TETHERING_ERROR_NONE;
2439 * @brief Registers the callback function called when tethering is enabled.
2441 * @privlevel platform
2442 * @privilege http://tizen.org/privilege/tethering.admin
2443 * @param[in] tethering The handle of tethering
2444 * @param[in] type The type of tethering
2445 * @param[in] callback The callback function to invoke
2446 * @param[in] user_data The user data to be passed to the callback function
2447 * @retval #TETHERING_ERROR_NONE Successful
2448 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2449 * @see tethering_unset_enabled_cb()
2451 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2453 INFO("+ type: %d\n", type);
2454 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2455 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2456 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2457 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2459 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2460 "parameter(tethering) is NULL\n");
2461 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2462 "parameter(callback) is NULL\n");
2464 __tethering_h *th = (__tethering_h *)tethering;
2465 tethering_type_e ti;
2467 if (type != TETHERING_TYPE_ALL) {
2468 th->enabled_cb[type] = callback;
2469 th->enabled_user_data[type] = user_data;
2471 return TETHERING_ERROR_NONE;
2474 /* TETHERING_TYPE_ALL */
2475 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2476 th->enabled_cb[ti] = callback;
2477 th->enabled_user_data[ti] = user_data;
2481 return TETHERING_ERROR_NONE;
2486 * @brief Unregisters the callback function called when tethering is disabled.
2488 * @privlevel platform
2489 * @privilege http://tizen.org/privilege/tethering.admin
2490 * @param[in] tethering The handle of tethering
2491 * @param[in] type The type of tethering
2492 * @retval #TETHERING_ERROR_NONE Successful
2493 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2494 * @see tethering_set_enabled_cb()
2496 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2498 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2499 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2500 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2501 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2503 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2504 "parameter(tethering) is NULL\n");
2506 __tethering_h *th = (__tethering_h *)tethering;
2507 tethering_type_e ti;
2509 if (type != TETHERING_TYPE_ALL) {
2510 th->enabled_cb[type] = NULL;
2511 th->enabled_user_data[type] = NULL;
2513 return TETHERING_ERROR_NONE;
2516 /* TETHERING_TYPE_ALL */
2517 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2518 th->enabled_cb[ti] = NULL;
2519 th->enabled_user_data[ti] = NULL;
2522 return TETHERING_ERROR_NONE;
2527 * @brief Registers the callback function called when tethering is disabled.
2529 * @privlevel platform
2530 * @privilege http://tizen.org/privilege/tethering.admin
2531 * @param[in] tethering The handle of tethering
2532 * @param[in] type The type of tethering
2533 * @param[in] callback The callback function to invoke
2534 * @param[in] user_data The user data to be passed to the callback function
2535 * @retval #TETHERING_ERROR_NONE Successful
2536 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2537 * @see tethering_unset_disabled_cb()
2539 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2541 INFO("+ type: %d\n", type);
2542 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2543 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2544 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2545 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2547 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2548 "parameter(tethering) is NULL\n");
2549 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2550 "parameter(callback) is NULL\n");
2552 __tethering_h *th = (__tethering_h *)tethering;
2553 tethering_type_e ti;
2555 if (type != TETHERING_TYPE_ALL) {
2556 th->disabled_cb[type] = callback;
2557 th->disabled_user_data[type] = user_data;
2559 return TETHERING_ERROR_NONE;
2562 /* TETHERING_TYPE_ALL */
2563 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2564 th->disabled_cb[ti] = callback;
2565 th->disabled_user_data[ti] = user_data;
2568 return TETHERING_ERROR_NONE;
2573 * @brief Unregisters the callback function called when tethering is disabled.
2575 * @privlevel platform
2576 * @privilege http://tizen.org/privilege/tethering.admin
2577 * @param[in] tethering The handle of tethering
2578 * @param[in] type The type of tethering
2579 * @retval #TETHERING_ERROR_NONE Successful
2580 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2581 * @see tethering_set_disabled_cb()
2583 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2585 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2586 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2587 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2588 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2590 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2591 "parameter(tethering) is NULL\n");
2593 __tethering_h *th = (__tethering_h *)tethering;
2594 tethering_type_e ti;
2596 if (type != TETHERING_TYPE_ALL) {
2597 th->disabled_cb[type] = NULL;
2598 th->disabled_user_data[type] = NULL;
2600 return TETHERING_ERROR_NONE;
2603 /* TETHERING_TYPE_ALL */
2604 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2605 th->disabled_cb[ti] = NULL;
2606 th->disabled_user_data[ti] = NULL;
2609 return TETHERING_ERROR_NONE;
2614 * @brief Registers the callback function called when the state of connection is changed.
2616 * @privlevel platform
2617 * @privilege http://tizen.org/privilege/tethering.admin
2618 * @param[in] tethering The handle of tethering
2619 * @param[in] type The type of tethering
2620 * @param[in] callback The callback function to invoke
2621 * @param[in] user_data The user data to be passed to the callback function
2622 * @retval #TETHERING_ERROR_NONE Successful
2623 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2624 * @see tethering_unset_connection_state_changed_cb_cb()
2626 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2628 INFO("+ type: %d\n", type);
2629 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2630 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2631 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2632 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2634 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2635 "parameter(tethering) is NULL\n");
2636 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2637 "parameter(callback) is NULL\n");
2639 __tethering_h *th = (__tethering_h *)tethering;
2640 tethering_type_e ti;
2642 if (type != TETHERING_TYPE_ALL) {
2643 th->changed_cb[type] = callback;
2644 th->changed_user_data[type] = user_data;
2646 return TETHERING_ERROR_NONE;
2649 /* TETHERING_TYPE_ALL */
2650 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2651 th->changed_cb[ti] = callback;
2652 th->changed_user_data[ti] = user_data;
2655 return TETHERING_ERROR_NONE;
2660 * @brief Unregisters the callback function called when the state of connection is changed.
2662 * @privlevel platform
2663 * @privilege http://tizen.org/privilege/tethering.admin
2664 * @param[in] tethering The handle of tethering
2665 * @param[in] type The type of tethering
2666 * @retval #TETHERING_ERROR_NONE Successful
2667 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2668 * @see tethering_set_connection_state_changed_cb()
2670 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2672 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2673 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2674 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2675 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2677 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2678 "parameter(tethering) is NULL\n");
2680 __tethering_h *th = (__tethering_h *)tethering;
2681 tethering_type_e ti;
2683 if (type != TETHERING_TYPE_ALL) {
2684 th->changed_cb[type] = NULL;
2685 th->changed_user_data[type] = NULL;
2687 return TETHERING_ERROR_NONE;
2690 /* TETHERING_TYPE_ALL */
2691 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2692 th->changed_cb[ti] = NULL;
2693 th->changed_user_data[ti] = NULL;
2696 return TETHERING_ERROR_NONE;
2701 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2703 * @privlevel platform
2704 * @privilege http://tizen.org/privilege/tethering.admin
2705 * @param[in] tethering The handle of tethering
2706 * @param[in] callback The callback function to invoke
2707 * @param[in] user_data The user data to be passed to the callback function
2708 * @retval #TETHERING_ERROR_NONE Successful
2709 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2710 * @see tethering_wifi_unset_security_type_changed_cb()
2712 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2714 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2715 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2717 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2718 "parameter(tethering) is NULL\n");
2719 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2720 "parameter(callback) is NULL\n");
2722 __tethering_h *th = (__tethering_h *)tethering;
2724 th->security_type_changed_cb = callback;
2725 th->security_type_user_data = user_data;
2727 return TETHERING_ERROR_NONE;
2733 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2735 * @privlevel platform
2736 * @privilege http://tizen.org/privilege/tethering.admin
2737 * @param[in] tethering The handle of tethering
2738 * @param[in] type The type of tethering
2739 * @retval #TETHERING_ERROR_NONE Successful
2740 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2741 * @see tethering_wifi_set_security_type_changed_cb()
2743 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2745 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2746 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2748 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2749 "parameter(tethering) is NULL\n");
2751 __tethering_h *th = (__tethering_h *)tethering;
2753 th->security_type_changed_cb = NULL;
2754 th->security_type_user_data = NULL;
2756 return TETHERING_ERROR_NONE;
2761 * @brief Registers the callback function called when the visibility of SSID is changed.
2763 * @privlevel platform
2764 * @privilege http://tizen.org/privilege/tethering.admin
2765 * @param[in] tethering The handle of tethering
2766 * @param[in] callback The callback function to invoke
2767 * @param[in] user_data The user data to be passed to the callback function
2768 * @retval #TETHERING_ERROR_NONE Successful
2769 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2770 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2772 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2774 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2775 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2777 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2778 "parameter(tethering) is NULL\n");
2779 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2780 "parameter(callback) is NULL\n");
2782 __tethering_h *th = (__tethering_h *)tethering;
2784 th->ssid_visibility_changed_cb = callback;
2785 th->ssid_visibility_user_data = user_data;
2787 return TETHERING_ERROR_NONE;
2792 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2794 * @privlevel platform
2795 * @privilege http://tizen.org/privilege/tethering.admin
2796 * @param[in] tethering The handle of tethering
2797 * @retval #TETHERING_ERROR_NONE Successful
2798 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2799 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2801 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2803 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2804 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2806 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2807 "parameter(tethering) is NULL\n");
2809 __tethering_h *th = (__tethering_h *)tethering;
2811 th->ssid_visibility_changed_cb = NULL;
2812 th->ssid_visibility_user_data = NULL;
2814 return TETHERING_ERROR_NONE;
2819 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2821 * @privlevel platform
2822 * @privilege http://tizen.org/privilege/tethering.admin
2823 * @param[in] tethering The handle of tethering
2824 * @param[in] callback The callback function to invoke
2825 * @param[in] user_data The user data to be passed to the callback function
2826 * @retval #TETHERING_ERROR_NONE Successful
2827 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2828 * @see tethering_wifi_unset_passphrase_changed_cb()
2830 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2832 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2833 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2835 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2836 "parameter(tethering) is NULL\n");
2837 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2838 "parameter(callback) is NULL\n");
2840 __tethering_h *th = (__tethering_h *)tethering;
2842 th->passphrase_changed_cb = callback;
2843 th->passphrase_user_data = user_data;
2845 return TETHERING_ERROR_NONE;
2850 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2852 * @privlevel platform
2853 * @privilege http://tizen.org/privilege/tethering.admin
2854 * @param[in] tethering The handle of tethering
2855 * @retval #TETHERING_ERROR_NONE Successful
2856 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2857 * @see tethering_wifi_set_passphrase_changed_cb()
2859 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2861 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2862 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2864 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2865 "parameter(tethering) is NULL\n");
2867 __tethering_h *th = (__tethering_h *)tethering;
2869 th->passphrase_changed_cb = NULL;
2870 th->passphrase_user_data = NULL;
2872 return TETHERING_ERROR_NONE;
2877 * @brief Sets the security type of Wi-Fi tethering.
2879 * @privlevel platform
2880 * @privilege http://tizen.org/privilege/tethering.admin
2881 * @remarks This change is applied next time Wi-Fi tethering is enabled
2882 * @param[in] tethering The handle of tethering
2883 * @param[in] type The security type
2884 * @return 0 on success, otherwise negative error value.
2885 * @retval #TETHERING_ERROR_NONE Successful
2886 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2887 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2888 * @see tethering_wifi_get_security_type()
2890 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2892 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2893 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2895 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2896 "parameter(tethering) is NULL\n");
2898 __tethering_h *th = (__tethering_h *)tethering;
2899 tethering_error_e ret = TETHERING_ERROR_NONE;
2900 char *sec_str = NULL;
2902 ret = __set_security_type(type);
2903 if (ret == TETHERING_ERROR_NONE) {
2906 case TETHERING_WIFI_SECURITY_TYPE_NONE:
2907 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
2909 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
2910 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
2912 case TETHERING_WIFI_SECURITY_TYPE_WPS:
2913 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
2915 case TETHERING_WIFI_SECURITY_TYPE_SAE:
2916 sec_str = TETHERING_WIFI_SECURITY_TYPE_SAE_STR;
2920 __send_dbus_signal(th->client_bus,
2921 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
2928 * @brief Gets the security type of Wi-Fi tethering.
2930 * @privlevel platform
2931 * @privilege http://tizen.org/privilege/tethering.admin
2932 * @param[in] tethering The handle of tethering
2933 * @param[out] type The security type
2934 * @return 0 on success, otherwise negative error value.
2935 * @retval #TETHERING_ERROR_NONE Successful
2936 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2937 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2938 * @see tethering_wifi_set_security_type()
2940 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2942 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2943 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2945 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2946 "parameter(type) is NULL\n");
2948 return __get_security_type(type);
2953 * @brief Sets the SSID (service set identifier).
2955 * @privlevel platform
2956 * @privilege http://tizen.org/privilege/tethering.admin
2957 * @details If SSID is not set, Device name is used as SSID
2958 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2959 * @param[in] tethering The handle of tethering
2960 * @param[out] ssid The SSID
2961 * @return 0 on success, otherwise negative error value.
2962 * @retval #TETHERING_ERROR_NONE Successful
2963 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2964 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2966 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2968 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2969 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2971 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2972 "parameter(tethering) is NULL\n");
2973 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2974 "parameter(ssid) is NULL\n");
2976 __tethering_h *th = (__tethering_h *)tethering;
2977 char *p_ssid = NULL;
2980 ssid_len = strlen(ssid);
2981 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2982 ERR("parameter(ssid) is too long");
2983 return TETHERING_ERROR_INVALID_PARAMETER;
2986 p_ssid = strdup(ssid);
2987 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2988 "strdup is failed\n");
2994 return TETHERING_ERROR_NONE;
2999 * @brief Gets the SSID (service set identifier).
3001 * @privlevel platform
3002 * @privilege http://tizen.org/privilege/tethering.admin
3003 * @remarks @a ssid must be released with free() by you.
3004 * @param[in] tethering The handle of tethering
3005 * @param[out] ssid The SSID
3006 * @return 0 on success, otherwise negative error value.
3007 * @retval #TETHERING_ERROR_NONE Successful
3008 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3009 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3010 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3012 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
3014 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3015 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3017 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3018 "parameter(tethering) is NULL\n");
3019 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3020 "parameter(ssid) is NULL\n");
3023 __tethering_h *th = (__tethering_h *)tethering;
3024 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
3026 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
3027 if (th->ssid != NULL) {
3028 DBG("Private SSID is set\n");
3029 *ssid = strdup(th->ssid);
3031 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
3032 val, sizeof(val)) == false) {
3033 return TETHERING_ERROR_OPERATION_FAILED;
3035 *ssid = strdup(val);
3038 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
3039 val, sizeof(val)) == false) {
3040 return TETHERING_ERROR_OPERATION_FAILED;
3042 *ssid = strdup(val);
3045 if (*ssid == NULL) {
3046 ERR("strdup is failed\n"); //LCOV_EXCL_LINE
3047 return TETHERING_ERROR_OUT_OF_MEMORY;
3050 return TETHERING_ERROR_NONE;
3055 * @brief Sets the visibility of SSID(service set identifier).
3057 * @privlevel platform
3058 * @privilege http://tizen.org/privilege/tethering.admin
3059 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3060 * @remarks This change is applied next time Wi-Fi tethering is enabled
3061 * @param[in] tethering The handle of tethering
3062 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3063 * @return 0 on success, otherwise negative error value.
3064 * @retval #TETHERING_ERROR_NONE Successful
3065 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3066 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3067 * @see tethering_wifi_get_ssid_visibility()
3069 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
3071 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3072 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3074 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3075 "parameter(tethering) is NULL\n");
3077 __tethering_h *th = (__tethering_h *)tethering;
3078 tethering_error_e ret = TETHERING_ERROR_NONE;
3080 ret = __set_visible(visible);
3081 if (ret == TETHERING_ERROR_NONE) {
3082 __send_dbus_signal(th->client_bus,
3083 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
3084 visible ? SIGNAL_MSG_SSID_VISIBLE :
3085 SIGNAL_MSG_SSID_HIDE);
3092 * @brief Gets the visibility of SSID(service set identifier).
3094 * @privlevel platform
3095 * @privilege http://tizen.org/privilege/tethering.admin
3096 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3097 * @param[in] tethering The handle of tethering
3098 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3099 * @return 0 on success, otherwise negative error value.
3100 * @retval #TETHERING_ERROR_NONE Successful
3101 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3102 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3103 * @see tethering_wifi_set_ssid_visibility()
3105 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
3107 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3108 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3110 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3111 "parameter(visible) is NULL\n");
3113 return __get_visible(visible);
3118 * @brief Sets the passphrase.
3120 * @privlevel platform
3121 * @privilege http://tizen.org/privilege/tethering.admin
3122 * @remarks This change is applied next time Wi-Fi tethering is enabled
3123 * @param[in] tethering The handle of tethering
3124 * @param[in] passphrase The passphrase
3125 * @return 0 on success, otherwise negative error value.
3126 * @retval #TETHERING_ERROR_NONE Successful
3127 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3128 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3129 * @see tethering_wifi_get_passphrase()
3131 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3133 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3134 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3136 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3137 "parameter(tethering) is NULL\n");
3138 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3139 "parameter(passphrase) is NULL\n");
3141 __tethering_h *th = (__tethering_h *)tethering;
3142 GDBusProxy *proxy = th->client_bus_proxy;
3143 GVariant *parameters;
3144 GError *error = NULL;
3145 int passphrase_len = 0;
3149 passphrase_len = strlen(passphrase);
3150 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3151 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3152 ERR("parameter(passphrase) is too short or long\n");
3153 return TETHERING_ERROR_INVALID_PARAMETER;
3156 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3157 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3161 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3163 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3164 ret = TETHERING_ERROR_PERMISSION_DENIED;
3166 ret = TETHERING_ERROR_OPERATION_FAILED;
3168 g_error_free(error);
3173 g_variant_get(parameters, "(u)", &ret);
3174 g_variant_unref(parameters);
3176 if (ret == TETHERING_ERROR_NONE) {
3177 __send_dbus_signal(th->client_bus,
3178 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3187 * @brief Gets the passphrase.
3189 * @privlevel platform
3190 * @privilege http://tizen.org/privilege/tethering.admin
3191 * @remarks @a passphrase must be released with free() by you.
3192 * @param[in] tethering The handle of tethering
3193 * @param[out] passphrase The passphrase
3194 * @return 0 on success, otherwise negative error value.
3195 * @retval #TETHERING_ERROR_NONE Successful
3196 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3197 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3198 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3199 * @see tethering_wifi_set_passphrase()
3201 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3203 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3204 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3206 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3207 "parameter(tethering) is NULL\n");
3208 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3209 "parameter(passphrase) is NULL\n");
3211 __tethering_h *th = (__tethering_h *)tethering;
3212 GDBusProxy *proxy = th->client_bus_proxy;
3213 GVariant *parameters;
3214 GError *error = NULL;
3215 unsigned int len = 0;
3216 tethering_error_e ret = TETHERING_ERROR_NONE;
3218 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3219 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3223 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3225 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3226 ret = TETHERING_ERROR_PERMISSION_DENIED;
3228 ret = TETHERING_ERROR_OPERATION_FAILED;
3230 g_error_free(error);
3235 if (parameters != NULL) {
3236 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3237 g_variant_unref(parameters);
3240 return TETHERING_ERROR_NONE;
3243 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3245 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3246 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3248 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3249 "parameter(tethering) is NULL\n");
3251 __tethering_h *th = (__tethering_h *)tethering;
3252 th->channel = channel;
3254 return TETHERING_ERROR_NONE;
3257 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3259 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3260 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3262 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3263 "parameter(tethering) is NULL\n");
3265 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3266 "parameter(channel) is NULL\n");
3268 __tethering_h *th = (__tethering_h *)tethering;
3269 *channel = th->channel;
3271 return TETHERING_ERROR_NONE;
3274 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3276 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3277 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3279 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3280 "parameter(tethering) is NULL\n");
3282 __tethering_h *th = (__tethering_h *)tethering;
3284 th->mode_type = type;
3286 return TETHERING_ERROR_NONE;
3289 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3291 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3292 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3294 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3295 "parameter(tethering) is NULL\n");
3296 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3297 "parameter(type) is NULL\n");
3299 __tethering_h *th = (__tethering_h *)tethering;
3300 *type = th->mode_type;
3302 return TETHERING_ERROR_NONE;
3308 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3310 * @privlevel platform
3311 * @privilege http://tizen.org/privilege/tethering.admin
3312 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3313 * @param[in] tethering The handle of tethering
3314 * @param[in] callback The callback function to invoke
3315 * @param[in] user_data The user data to be passed to the callback function
3316 * @return 0 on success, otherwise negative error value.
3317 * @retval #TETHERING_ERROR_NONE Successful
3318 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3319 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3321 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3324 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3325 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3327 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3328 "parameter(tethering) is NULL\n");
3329 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3330 "parameter(callback) is NULL\n");
3332 __tethering_h *th = (__tethering_h *)tethering;
3333 _softap_settings_t set = {"", "", "", 0, false};
3334 GDBusProxy *proxy = th->client_bus_proxy;
3339 if (th->settings_reloaded_cb) {
3340 ERR("Operation in progress\n"); //LCOV_EXCL_LINE
3341 return TETHERING_ERROR_OPERATION_FAILED;
3344 ret = __prepare_wifi_settings(tethering, &set);
3345 if (ret != TETHERING_ERROR_NONE) {
3346 ERR("softap settings initialization failed\n"); //LCOV_EXCL_LINE
3347 return TETHERING_ERROR_OPERATION_FAILED;
3350 th->settings_reloaded_cb = callback;
3351 th->settings_reloaded_user_data = user_data;
3353 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3354 g_variant_new("(sssiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type),
3355 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3356 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3358 return TETHERING_ERROR_NONE;
3361 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3363 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3364 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3366 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3367 "parameter(tethering) is NULL\n");
3369 __tethering_h *th = (__tethering_h *)tethering;
3370 th->mac_filter = mac_filter;
3372 return TETHERING_ERROR_NONE;
3375 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3377 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3378 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3380 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3381 "parameter(mac_filter) is NULL\n");
3382 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3383 "parameter(mac_filter) is NULL\n");
3385 __tethering_h *th = (__tethering_h *)tethering;
3386 *mac_filter = th->mac_filter;
3388 return TETHERING_ERROR_NONE;
3391 static int __add_mac_to_file(const char *filepath, const char *mac)
3394 char line[MAX_BUF_SIZE] = "\0";
3395 bool mac_exist = false;
3398 p_mac = strdup(mac);
3399 if (p_mac == NULL) {
3400 ERR("strdup failed\n"); //LCOV_EXCL_LINE
3401 return TETHERING_ERROR_OUT_OF_MEMORY;
3404 fp = fopen(filepath, "a+");
3406 ERR("fopen is failed\n"); //LCOV_EXCL_LINE
3407 return TETHERING_ERROR_OPERATION_FAILED;
3410 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3411 if (strncmp(mac, line, 17) == 0) {
3412 DBG("MAC %s already exist in the list\n", mac); //LCOV_EXCL_LINE
3419 fprintf(fp, "%s\n", mac);
3421 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3422 allowed_list = g_slist_append(allowed_list, p_mac);
3423 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3424 blocked_list = g_slist_append(blocked_list, p_mac);
3429 return TETHERING_ERROR_NONE;
3432 static int __remove_mac_from_file(const char *filepath, const char *mac)
3436 char line[MAX_BUF_SIZE] = "\0";
3438 fp = fopen(filepath, "r");
3440 ERR("fopen is failed\n");
3441 return TETHERING_ERROR_OPERATION_FAILED;
3444 fp1 = fopen(TEMP_LIST, "w+");
3447 ERR("fopen is failed\n");
3448 return TETHERING_ERROR_OPERATION_FAILED;
3451 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3452 if (strncmp(mac, line, 17) == 0) {
3453 DBG("MAC %s found in the list\n", mac);
3455 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3456 GSList *list = NULL;
3457 for (list = allowed_list; list != NULL; list = list->next) {
3458 char *p_mac = (char *)list->data;
3459 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3460 allowed_list = g_slist_remove(allowed_list, p_mac);
3462 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3463 GSList *list = NULL;
3464 for (list = blocked_list; list != NULL; list = list->next) {
3465 char *p_mac = (char *)list->data;
3466 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3467 blocked_list = g_slist_remove(blocked_list, p_mac);
3471 fprintf(fp1, "%s", line);
3478 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3479 if (rename(TEMP_LIST, ALLOWED_LIST) != 0) {
3480 ERR("rename is failed (%s -> %s)", TEMP_LIST, ALLOWED_LIST);
3481 return TETHERING_ERROR_OPERATION_FAILED;
3483 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3484 if (rename(TEMP_LIST, BLOCKED_LIST) != 0) {
3485 ERR("rename is failed (%s -> %s)", TEMP_LIST, BLOCKED_LIST);
3486 return TETHERING_ERROR_OPERATION_FAILED;
3490 return TETHERING_ERROR_NONE;
3493 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3495 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3496 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3498 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3499 "parameter(tethering) is NULL\n");
3500 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3501 "parameter(mac) is NULL\n");
3503 return __add_mac_to_file(ALLOWED_LIST, mac);
3506 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3508 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3509 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3511 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3512 "parameter(tethering) is NULL\n");
3513 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3514 "parameter(mac) is NULL\n");
3516 return __remove_mac_from_file(ALLOWED_LIST, mac);
3519 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3521 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3522 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3524 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3525 "parameter(tethering) is NULL\n");
3526 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3527 "parameter(allowed_mac_list) is NULL\n");
3529 *allowed_mac_list = g_slist_copy(allowed_list);
3530 return TETHERING_ERROR_NONE;
3533 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3535 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3536 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3538 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3539 "parameter(tethering) is NULL\n");
3540 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3541 "parameter(mac) is NULL\n");
3543 return __add_mac_to_file(BLOCKED_LIST, mac);
3546 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3548 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3549 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3551 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3552 "parameter(tethering) is NULL\n");
3553 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3554 "parameter(mac) is NULL\n");
3556 return __remove_mac_from_file(BLOCKED_LIST, mac);
3559 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3561 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3562 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3564 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3565 "parameter(tethering) is NULL\n");
3566 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3567 "parameter(blocked_mac_list) is NULL\n");
3569 *blocked_mac_list = g_slist_copy(blocked_list);
3570 return TETHERING_ERROR_NONE;
3573 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3575 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3576 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3578 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3579 "parameter(tethering) is NULL\n");
3581 GVariant *parameters;
3582 GError *error = NULL;
3585 __tethering_h *th = (__tethering_h *)tethering;
3587 GDBusProxy *proxy = th->client_bus_proxy;
3589 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3590 g_variant_new("(b)", enable),
3591 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3595 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3596 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3597 result = TETHERING_ERROR_PERMISSION_DENIED;
3599 result = TETHERING_ERROR_OPERATION_FAILED;
3601 g_error_free(error);
3602 th->dhcp_enabled = false;
3608 g_variant_get(parameters, "(u)", &result);
3609 g_variant_unref(parameters);
3612 th->dhcp_enabled = true;
3614 th->dhcp_enabled = false;
3616 return TETHERING_ERROR_NONE;
3619 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3621 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3622 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3624 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3625 "parameter(tethering) is NULL\n");
3626 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3627 "parameter(rangestart) is NULL\n");
3628 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3629 "parameter(rangestop) is NULL\n");
3631 GVariant *parameters;
3632 GError *error = NULL;
3635 __tethering_h *th = (__tethering_h *)tethering;
3637 GDBusProxy *proxy = th->client_bus_proxy;
3639 parameters = g_dbus_proxy_call_sync(proxy, "dhcp_range",
3640 g_variant_new("(ss)", rangestart, rangestop),
3641 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3644 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3646 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3647 result = TETHERING_ERROR_PERMISSION_DENIED;
3649 result = TETHERING_ERROR_OPERATION_FAILED;
3651 g_error_free(error);
3652 th->dhcp_enabled = false;
3658 g_variant_get(parameters, "(u)", &result);
3659 g_variant_unref(parameters);
3661 th->dhcp_enabled = true;
3663 return TETHERING_ERROR_NONE;
3666 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3668 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3669 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3671 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3672 "parameter(tethering) is NULL\n");
3673 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3674 "parameter(dhcp_enabled) is NULL\n");
3676 __tethering_h *th = (__tethering_h *)tethering;
3677 *dhcp_enabled = th->dhcp_enabled;
3679 return TETHERING_ERROR_NONE;
3682 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3684 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3685 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3687 GError *error = NULL;
3689 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3690 "parameter(tethering) is NULL\n");
3691 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3692 TETHERING_ERROR_NOT_ENABLED,
3693 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3694 __tethering_h *th = (__tethering_h *)tethering;
3696 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3697 g_variant_new("(u)", txpower),
3698 G_DBUS_CALL_FLAGS_NONE,
3699 -1, th->cancellable, &error);
3702 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3703 g_clear_error(&error);
3704 return TETHERING_ERROR_OPERATION_FAILED;
3707 return TETHERING_ERROR_NONE;
3710 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3712 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3713 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3715 GError *error = NULL;
3716 GVariant *result = NULL;
3718 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3719 "parameter(tethering) is NULL\n");
3720 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3721 TETHERING_ERROR_NOT_ENABLED,
3722 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3724 __tethering_h *th = (__tethering_h *)tethering;
3726 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3728 G_DBUS_CALL_FLAGS_NONE,
3729 -1, th->cancellable, &error);
3731 if (result != NULL) {
3732 g_variant_get(result, "(u)", txpower);
3733 g_variant_unref(result);
3737 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3738 g_clear_error(&error);
3739 return TETHERING_ERROR_OPERATION_FAILED;
3742 g_clear_error(&error);
3743 return TETHERING_ERROR_NONE;
3746 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
3748 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3749 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3751 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3752 "parameter(tethering) is NULL\n");
3754 GVariant *parameters;
3755 GError *error = NULL;
3758 __tethering_h *th = (__tethering_h *)tethering;
3760 GDBusProxy *proxy = th->client_bus_proxy;
3762 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
3763 g_variant_new("(u)", mtu),
3764 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3767 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3769 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3770 result = TETHERING_ERROR_PERMISSION_DENIED;
3772 result = TETHERING_ERROR_OPERATION_FAILED;
3774 g_error_free(error);
3779 g_variant_get(parameters, "(u)", &result);
3781 g_variant_unref(parameters);
3783 return TETHERING_ERROR_NONE;
3786 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
3788 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3789 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3791 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3792 "parameter(tethering) is NULL\n");
3793 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3794 "parameter(mac) is NULL\n");
3796 GVariant *parameters;
3797 GError *error = NULL;
3800 __tethering_h *th = (__tethering_h *)tethering;
3802 GDBusProxy *proxy = th->client_bus_proxy;
3804 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
3805 g_variant_new("(s)", mac),
3806 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3809 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3811 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3812 result = TETHERING_ERROR_PERMISSION_DENIED;
3814 result = TETHERING_ERROR_OPERATION_FAILED;
3816 g_error_free(error);
3821 g_variant_get(parameters, "(u)", &result);
3822 g_variant_unref(parameters);
3824 if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
3825 return TETHERING_ERROR_NOT_SUPPORT_API;
3827 return TETHERING_ERROR_NONE;
3830 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
3832 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3833 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3835 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3836 "parameter(tethering) is NULL\n");
3838 __tethering_h *th = (__tethering_h *)tethering;
3840 th->wifi_max_connected = max_device;
3842 return TETHERING_ERROR_NONE;
3845 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
3847 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3848 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3850 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3851 "parameter(tethering) is NULL\n");
3852 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3853 "parameter(max_device) is NULL\n");
3855 __tethering_h *th = (__tethering_h *)tethering;
3857 *max_device = th->wifi_max_connected;
3858 return TETHERING_ERROR_NONE;
3861 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
3863 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3864 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3866 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3867 "parameter(tethering) is NULL\n");
3869 GVariant *parameters;
3870 GError *error = NULL;
3873 __tethering_h *th = (__tethering_h *)tethering;
3875 GDBusProxy *proxy = th->client_bus_proxy;
3877 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
3878 g_variant_new("(b)", enable),
3879 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3882 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3884 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3885 result = TETHERING_ERROR_PERMISSION_DENIED;
3887 result = TETHERING_ERROR_OPERATION_FAILED;
3889 g_error_free(error);
3894 g_variant_get(parameters, "(u)", &result);
3895 g_variant_unref(parameters);
3897 th->port_forwarding = true;
3899 return TETHERING_ERROR_NONE;
3902 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)
3904 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3905 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3907 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3908 "parameter(tethering) is NULL\n");
3909 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3910 "parameter(protocol) is NULL\n");
3912 GVariant *parameters;
3913 GError *error = NULL;
3915 char cmd[MAX_BUF_SIZE] = { 0, };
3918 __tethering_h *th = (__tethering_h *)tethering;
3920 GDBusProxy *proxy = th->client_bus_proxy;
3922 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
3923 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
3924 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3927 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3929 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3930 result = TETHERING_ERROR_PERMISSION_DENIED;
3932 result = TETHERING_ERROR_OPERATION_FAILED;
3934 g_error_free(error);
3939 g_variant_get(parameters, "(u)", &result);
3940 g_variant_unref(parameters);
3942 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);
3946 ERR("strdup failed\n"); //LCOV_EXCL_LINE
3947 return TETHERING_ERROR_OUT_OF_MEMORY;
3950 port_forwarding = g_slist_append(port_forwarding, list);
3952 return TETHERING_ERROR_NONE;
3955 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
3957 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3958 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3960 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3961 "parameter(tethering) is NULL\n");
3963 GVariant *parameters;
3964 GError *error = NULL;
3967 __tethering_h *th = (__tethering_h *)tethering;
3969 GDBusProxy *proxy = th->client_bus_proxy;
3971 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
3972 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3975 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3977 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3978 result = TETHERING_ERROR_PERMISSION_DENIED;
3980 result = TETHERING_ERROR_OPERATION_FAILED;
3982 g_error_free(error);
3987 g_variant_get(parameters, "(u)", &result);
3989 g_variant_unref(parameters);
3991 return TETHERING_ERROR_NONE;
3994 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool* forwarding_enabled)
3996 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3997 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3999 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4000 "parameter(tethering) is NULL\n");
4001 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4002 "parameter(forwarding_enabled) is NULL\n");
4004 __tethering_h *th = (__tethering_h *)tethering;
4006 *forwarding_enabled = th->port_forwarding;
4008 return TETHERING_ERROR_NONE;
4011 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
4013 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4014 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4016 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4017 "parameter(tethering) is NULL\n");
4018 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4019 "parameter(port_forwarding_list) is NULL\n");
4021 *port_forwarding_list = g_slist_copy(port_forwarding);
4022 return TETHERING_ERROR_NONE;
4025 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
4027 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4028 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4030 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4031 "parameter(tethering) is NULL\n");
4033 GVariant *parameters;
4034 GError *error = NULL;
4037 __tethering_h *th = (__tethering_h *)tethering;
4039 GDBusProxy *proxy = th->client_bus_proxy;
4041 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
4042 g_variant_new("(b)", enable),
4043 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4046 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4048 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4049 result = TETHERING_ERROR_PERMISSION_DENIED;
4051 result = TETHERING_ERROR_OPERATION_FAILED;
4053 g_error_free(error);
4058 g_variant_get(parameters, "(u)", &result);
4059 g_variant_unref(parameters);
4061 th->port_filtering = true;
4063 return TETHERING_ERROR_NONE;
4066 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
4068 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4069 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4071 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4072 "parameter(tethering) is NULL\n");
4073 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4074 "parameter(protocol) is NULL\n");
4076 GVariant *parameters;
4077 GError *error = NULL;
4079 char cmd[MAX_BUF_SIZE] = { 0, };
4082 __tethering_h *th = (__tethering_h *)tethering;
4084 GDBusProxy *proxy = th->client_bus_proxy;
4086 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
4087 g_variant_new("(isb)", port, protocol, allow),
4088 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4091 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4093 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4094 result = TETHERING_ERROR_PERMISSION_DENIED;
4096 result = TETHERING_ERROR_OPERATION_FAILED;
4098 g_error_free(error);
4103 g_variant_get(parameters, "(u)", &result);
4104 g_variant_unref(parameters);
4107 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
4109 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
4115 ERR("strdup failed\n"); //LCOV_EXCL_LINE
4116 return TETHERING_ERROR_OUT_OF_MEMORY;
4119 port_filtering = g_slist_append(port_filtering, list);
4121 return TETHERING_ERROR_NONE;
4124 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
4126 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4127 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4129 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4130 "parameter(tethering) is NULL\n");
4131 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4132 "parameter(protocol) is NULL\n");
4134 GVariant *parameters;
4135 GError *error = NULL;
4137 char cmd[MAX_BUF_SIZE] = { 0, };
4140 __tethering_h *th = (__tethering_h *)tethering;
4142 GDBusProxy *proxy = th->client_bus_proxy;
4144 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
4145 g_variant_new("(iisb)", port1, port2, protocol, allow),
4146 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4149 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4151 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4152 result = TETHERING_ERROR_PERMISSION_DENIED;
4154 result = TETHERING_ERROR_OPERATION_FAILED;
4156 g_error_free(error);
4161 g_variant_get(parameters, "(u)", &result);
4162 g_variant_unref(parameters);
4165 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
4167 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
4173 ERR("strdup failed\n"); //LCOV_EXCL_LINE
4174 return TETHERING_ERROR_OUT_OF_MEMORY;
4177 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4179 return TETHERING_ERROR_NONE;
4182 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4184 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4185 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4187 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4188 "parameter(tethering) is NULL\n");
4189 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4190 "parameter(port_filtering_list) is NULL\n");
4192 *port_filtering_list = g_slist_copy(port_filtering);
4193 return TETHERING_ERROR_NONE;
4196 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4198 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4199 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4201 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4202 "parameter(tethering) is NULL\n");
4203 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4204 "parameter(custom_port_filtering_list) is NULL\n");
4206 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4207 return TETHERING_ERROR_NONE;
4210 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool* filtering_enabled)
4212 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4213 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4215 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4216 "parameter(tethering) is NULL\n");
4217 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4218 "parameter(filtering_enabled) is NULL\n");
4220 __tethering_h *th = (__tethering_h *)tethering;
4222 *filtering_enabled = th->port_filtering;
4224 return TETHERING_ERROR_NONE;
4227 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
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\n");
4235 GVariant *parameters;
4236 GError *error = NULL;
4239 __tethering_h *th = (__tethering_h *)tethering;
4241 GDBusProxy *proxy = th->client_bus_proxy;
4243 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4244 g_variant_new("(ib)", type, enable),
4245 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4248 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4250 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4251 result = TETHERING_ERROR_PERMISSION_DENIED;
4253 result = TETHERING_ERROR_OPERATION_FAILED;
4255 g_error_free(error);
4260 g_variant_get(parameters, "(u)", &result);
4262 g_variant_unref(parameters);
4264 return TETHERING_ERROR_NONE;
4267 API int tethering_wifi_push_wps_button(tethering_h tethering)
4269 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4270 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4272 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4273 "parameter(tethering) is NULL");
4274 __tethering_h *th = (__tethering_h *)tethering;
4275 GDBusProxy *proxy = th->client_bus_proxy;
4276 GVariant *parameters = NULL;
4278 GError *error = NULL;
4280 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4281 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4285 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4287 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4288 ret = TETHERING_ERROR_PERMISSION_DENIED;
4290 ret = TETHERING_ERROR_OPERATION_FAILED;
4292 g_error_free(error);
4297 if (parameters != NULL) {
4298 g_variant_get(parameters, "(u)", &ret);
4299 g_variant_unref(parameters);
4302 return TETHERING_ERROR_NONE;
4305 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4307 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4308 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4310 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4311 "parameter(tethering) is NULL");
4312 __tethering_h *th = (__tethering_h *)tethering;
4313 GDBusProxy *proxy = th->client_bus_proxy;
4314 GVariant *parameters = NULL;
4316 GError *error = NULL;
4318 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4319 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4323 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4325 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4326 ret = TETHERING_ERROR_PERMISSION_DENIED;
4328 ret = TETHERING_ERROR_OPERATION_FAILED;
4330 g_error_free(error);
4335 if (parameters != NULL) {
4336 g_variant_get(parameters, "(u)", &ret);
4337 g_variant_unref(parameters);
4340 return TETHERING_ERROR_NONE;