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 <openssl/evp.h>
30 #include <openssl/sha.h>
31 #include <ckmc/ckmc-manager.h>
32 #include <tzplatform_config.h>
33 #include "tethering_private.h"
35 #define ALLOWED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.accept")
36 #define BLOCKED_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/hostapd.deny")
37 #define TEMP_LIST tzplatform_mkpath(TZ_SYS_VAR, "/lib/hostapd/.hostapd_tmp")
38 #define MAC_ADDR_LEN 18
39 #define MAX_BUF_SIZE 80
41 #define IPTABLES "/usr/sbin/iptables"
42 #define TABLE_NAT "nat"
43 #define TETH_NAT_PRE "teth_nat_pre"
44 #define TABLE_FILTER "filter"
45 #define TETH_FILTER_FW "teth_filter_fw"
46 #define ACTION_DROP "DROP"
47 #define ACTION_ACCEPT "ACCEPT"
48 #define PORT_FORWARD_RULE_STR "-t %s -A %s -i %s -p %s -d %s --dport %d -j DNAT --to %s:%d"
49 #define FILTERING_MULTIPORT_RULE_STR "-t %s -A %s -p %s -m multiport --dport %d,%d -j %s"
50 #define FILTERING_RULE_STR "-t %s -A %s -p %s --dport %d -j %s"
52 static GSList *allowed_list = NULL;
53 static GSList *blocked_list = NULL;
54 static GSList *port_forwarding = NULL;
55 static GSList *port_filtering = NULL;
56 static GSList *custom_port_filtering = NULL;
58 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
59 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
60 GVariant *parameters, gpointer user_data);
62 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
63 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
64 GVariant *parameters, gpointer user_data);
66 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
67 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
68 GVariant *parameters, gpointer user_data);
70 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
71 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
72 GVariant *parameters, gpointer user_data);
74 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
75 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
76 GVariant *parameters, gpointer user_data);
78 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
79 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
80 GVariant *parameters, gpointer user_data);
82 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
83 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
84 GVariant *parameters, gpointer user_data);
86 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
87 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
88 GVariant *parameters, gpointer user_data);
90 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
91 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
92 GVariant *parameters, gpointer user_data);
94 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
95 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
96 GVariant *parameters, gpointer user_data);
98 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
99 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
100 GVariant *parameters, gpointer user_data);
102 static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name,
103 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
104 GVariant *parameters, gpointer user_data);
106 static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
107 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
108 GVariant *parameters, gpointer user_data);
110 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
111 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
112 GVariant *parameters, gpointer user_data);
114 static __tethering_sig_t sigs[] = {
115 {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed},
116 {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on},
117 {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off},
118 {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on},
119 {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off},
120 {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on},
121 {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off},
122 {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout},
123 {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
124 {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode},
125 {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed},
126 {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed},
127 {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed},
128 {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
130 static int retry = 0;
132 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
134 if (conn == NULL || signal_name == NULL)
135 return; //LCOV_EXCL_LINE
137 GVariant *message = NULL;
138 GError *error = NULL;
141 message = g_variant_new("(s)", arg);
143 g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
144 TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
146 ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
147 g_error_free(error); //LCOV_EXCL_LINE
149 g_variant_unref(message);
152 static bool __any_tethering_is_enabled(tethering_h tethering)
154 if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) ||
155 tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) ||
156 tethering_is_enabled(tethering, TETHERING_TYPE_BT) ||
157 tethering_is_enabled(tethering, TETHERING_TYPE_P2P))
163 static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type)
165 if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE &&
166 security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
167 security_type != TETHERING_WIFI_SECURITY_TYPE_WPS) {
168 ERR("Invalid param\n"); //LCOV_EXCL_LINE
169 return TETHERING_ERROR_INVALID_PARAMETER;
172 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
173 ERR("vconf_set_int is failed\n"); //LCOV_EXCL_LINE
174 return TETHERING_ERROR_OPERATION_FAILED;
177 return TETHERING_ERROR_NONE;
180 static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
182 if (security_type == NULL) {
183 ERR("Invalid param\n"); //LCOV_EXCL_LINE
184 return TETHERING_ERROR_INVALID_PARAMETER;
187 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
188 (int *)security_type) < 0) {
189 ERR("vconf_get_int is failed\n"); //LCOV_EXCL_LINE
190 return TETHERING_ERROR_OPERATION_FAILED;
193 return TETHERING_ERROR_NONE;
196 static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
198 if (path == NULL || ssid == NULL || size == 0)
202 char *ptr_tmp = NULL;
204 ptr = vconf_get_str(path);
208 if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
211 g_strlcpy(ssid, ptr, size);
217 static tethering_error_e __set_visible(const bool visible)
219 if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
220 ERR("vconf_set_int is failed\n"); //LCOV_EXCL_LINE
221 return TETHERING_ERROR_OPERATION_FAILED;
224 return TETHERING_ERROR_NONE;
227 static tethering_error_e __get_visible(bool *visible)
229 if (visible == NULL) {
230 ERR("Invalid param\n"); //LCOV_EXCL_LINE
231 return TETHERING_ERROR_INVALID_PARAMETER;
236 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
237 ERR("vconf_get_int is failed\n"); //LCOV_EXCL_LINE
238 return TETHERING_ERROR_OPERATION_FAILED;
245 return TETHERING_ERROR_NONE;
248 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size)
250 if (passphrase == NULL ||
251 size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1)
254 guint32 rand_int = 0;
257 for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) {
258 rand_int = g_random_int_range('a', 'z');
259 passphrase[index] = rand_int;
261 passphrase[index] = '\0';
266 static tethering_error_e __get_error(int agent_error)
268 tethering_error_e err = TETHERING_ERROR_NONE;
270 switch (agent_error) {
271 case MOBILE_AP_ERROR_NONE:
272 err = TETHERING_ERROR_NONE;
276 case MOBILE_AP_ERROR_RESOURCE:
277 err = TETHERING_ERROR_OUT_OF_MEMORY;
281 case MOBILE_AP_ERROR_INTERNAL:
282 err = TETHERING_ERROR_OPERATION_FAILED;
285 case MOBILE_AP_ERROR_INVALID_PARAM:
286 err = TETHERING_ERROR_INVALID_PARAMETER;
290 case MOBILE_AP_ERROR_ALREADY_ENABLED:
291 err = TETHERING_ERROR_OPERATION_FAILED;
294 case MOBILE_AP_ERROR_NOT_ENABLED:
295 err = TETHERING_ERROR_NOT_ENABLED;
298 case MOBILE_AP_ERROR_NET_OPEN:
299 err = TETHERING_ERROR_OPERATION_FAILED;
302 case MOBILE_AP_ERROR_NET_CLOSE:
303 err = TETHERING_ERROR_OPERATION_FAILED;
306 case MOBILE_AP_ERROR_DHCP:
307 err = TETHERING_ERROR_OPERATION_FAILED;
310 case MOBILE_AP_ERROR_IN_PROGRESS:
311 err = TETHERING_ERROR_OPERATION_FAILED;
314 case MOBILE_AP_ERROR_NOT_PERMITTED:
315 err = TETHERING_ERROR_NOT_PERMITTED;
318 case MOBILE_AP_ERROR_PERMISSION_DENIED:
319 err = TETHERING_ERROR_PERMISSION_DENIED;
323 ERR("Not defined error : %d\n", agent_error);
324 err = TETHERING_ERROR_OPERATION_FAILED;
332 static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
333 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
334 GVariant *parameters, gpointer user_data)
338 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
340 __tethering_h *th = (__tethering_h *)user_data;
342 tethering_type_e type = 0;
343 mobile_ap_type_e ap_type = 0;
344 tethering_connection_state_changed_cb ccb = NULL;
345 __tethering_client_h client;
353 memset(&client, 0, sizeof(__tethering_client_h));
354 g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp);
356 if (!g_strcmp0(buf, "DhcpConnected")) {
358 } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) {
361 ERR("Unknown event [%s]\n", buf);
365 if (ap_type == MOBILE_AP_TYPE_USB)
366 type = TETHERING_TYPE_USB;
367 else if (ap_type == MOBILE_AP_TYPE_WIFI)
368 type = TETHERING_TYPE_WIFI;
369 else if (ap_type == MOBILE_AP_TYPE_BT)
370 type = TETHERING_TYPE_BT;
371 else if (ap_type == MOBILE_AP_TYPE_P2P)
372 type = TETHERING_TYPE_P2P;
374 ERR("Not supported tethering type [%d]\n", ap_type);
378 ccb = th->changed_cb[type];
381 data = th->changed_user_data[type];
383 client.interface = type;
384 g_strlcpy(client.ip, ip, sizeof(client.ip));
385 g_strlcpy(client.mac, mac, sizeof(client.mac));
387 client.hostname = g_strdup(name);
388 client.tm = (time_t)timestamp;
390 ccb((tethering_client_h)&client, opened, data);
391 g_free(client.hostname);
400 static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name,
401 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
402 GVariant *parameters, gpointer user_data)
406 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
408 __tethering_h *th = (__tethering_h *)user_data;
409 tethering_type_e type = 0;
410 tethering_disabled_cb dcb = NULL;
412 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
414 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
415 dcb = th->disabled_cb[type];
418 data = th->disabled_user_data[type];
420 dcb(TETHERING_ERROR_NONE, type, code, data);
427 static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
428 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
429 GVariant *parameters, gpointer user_data)
433 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
435 __tethering_h *th = (__tethering_h *)user_data;
436 tethering_type_e type = TETHERING_TYPE_WIFI;
437 bool is_requested = false;
438 tethering_enabled_cb ecb = NULL;
441 ecb = th->enabled_cb[type];
444 data = th->enabled_user_data[type];
446 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
450 static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name,
451 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
452 GVariant *parameters, gpointer user_data)
456 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
458 __tethering_h *th = (__tethering_h *)user_data;
459 tethering_type_e type = TETHERING_TYPE_WIFI;
460 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
461 tethering_disabled_cb dcb = NULL;
465 dcb = th->disabled_cb[type];
468 data = th->disabled_user_data[type];
469 g_variant_get(parameters, "(s)", &buf);
470 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
471 code = TETHERING_DISABLED_BY_WIFI_ON;
472 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
473 code = TETHERING_DISABLED_BY_TIMEOUT;
476 dcb(TETHERING_ERROR_NONE, type, code, data);
482 static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
483 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
484 GVariant *parameters, gpointer user_data)
488 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
490 __tethering_h *th = (__tethering_h *)user_data;
491 tethering_type_e type = TETHERING_TYPE_USB;
492 bool is_requested = false;
493 tethering_enabled_cb ecb = NULL;
496 ecb = th->enabled_cb[type];
499 data = th->enabled_user_data[type];
501 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
505 static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name,
506 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
507 GVariant *parameters, gpointer user_data)
511 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
513 __tethering_h *th = (__tethering_h *)user_data;
514 tethering_type_e type = TETHERING_TYPE_USB;
515 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
516 tethering_disabled_cb dcb = NULL;
520 dcb = th->disabled_cb[type];
523 data = th->disabled_user_data[type];
525 g_variant_get(parameters, "(s)", &buf);
526 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
527 code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
529 dcb(TETHERING_ERROR_NONE, type, code, data);
535 static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
536 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
537 GVariant *parameters, gpointer user_data)
541 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
543 __tethering_h *th = (__tethering_h *)user_data;
544 tethering_type_e type = TETHERING_TYPE_BT;
545 bool is_requested = false;
546 tethering_enabled_cb ecb = NULL;
549 ecb = th->enabled_cb[type];
552 data = th->enabled_user_data[type];
554 ecb(TETHERING_ERROR_NONE, type, is_requested, data);
558 static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name,
559 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
560 GVariant *parameters, gpointer user_data)
564 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
566 __tethering_h *th = (__tethering_h *)user_data;
567 tethering_type_e type = TETHERING_TYPE_BT;
568 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
569 tethering_disabled_cb dcb = NULL;
573 dcb = th->disabled_cb[type];
576 data = th->disabled_user_data[type];
577 g_variant_get(parameters, "(s)", &buf);
578 if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
579 code = TETHERING_DISABLED_BY_BT_OFF;
580 else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
581 code = TETHERING_DISABLED_BY_TIMEOUT;
583 dcb(TETHERING_ERROR_NONE, type, code, data);
590 static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
591 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
592 GVariant *parameters, gpointer user_data)
596 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
598 __tethering_h *th = (__tethering_h *)user_data;
599 tethering_type_e type = 0;
600 tethering_disabled_cb dcb = NULL;
602 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
604 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
605 dcb = th->disabled_cb[type];
608 data = th->disabled_user_data[type];
610 dcb(TETHERING_ERROR_NONE, type, code, data);
615 static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name,
616 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
617 GVariant *parameters, gpointer user_data)
621 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
623 __tethering_h *th = (__tethering_h *)user_data;
624 tethering_type_e type = 0;
625 tethering_disabled_cb dcb = NULL;
627 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
629 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
630 dcb = th->disabled_cb[type];
633 data = th->disabled_user_data[type];
635 dcb(TETHERING_ERROR_NONE, type, code, data);
640 static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name,
641 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
642 GVariant *parameters, gpointer user_data)
646 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
648 __tethering_h *th = (__tethering_h *)user_data;
649 tethering_type_e type = 0;
650 tethering_disabled_cb dcb = NULL;
652 tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
654 for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
655 dcb = th->disabled_cb[type];
658 data = th->disabled_user_data[type];
660 dcb(TETHERING_ERROR_NONE, type, code, data);
666 static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
667 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
668 GVariant *parameters, gpointer user_data)
673 _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
674 __tethering_h *th = (__tethering_h *)user_data;
676 tethering_wifi_security_type_changed_cb scb = NULL;
678 tethering_wifi_security_type_e security_type;
681 scb = th->security_type_changed_cb;
685 g_variant_get(parameters, "(s)", &buf);
686 data = th->security_type_user_data;
687 if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0)
688 security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
689 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0)
690 security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
691 else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPS_STR) == 0)
692 security_type = TETHERING_WIFI_SECURITY_TYPE_WPS;
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;
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 tethering_error = __get_error(info);
1154 g_variant_unref(g_var);
1156 th->settings_reloaded_cb(tethering_error,
1157 th->settings_reloaded_user_data);
1159 th->settings_reloaded_cb = NULL;
1160 th->settings_reloaded_user_data = NULL;
1164 static void __connect_signals(tethering_h tethering)
1167 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1169 __tethering_h *th = (__tethering_h *)tethering;
1170 GDBusConnection *connection = th->client_bus;
1173 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) {
1174 sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
1175 NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name,
1176 TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
1177 sigs[i].cb, tethering, NULL);
1182 static void __disconnect_signals(tethering_h tethering)
1186 _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
1188 __tethering_h *th = (__tethering_h *)tethering;
1189 GDBusConnection *connection = th->client_bus;
1193 for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++)
1194 g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
1200 static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len)
1202 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1206 case TETHERING_TYPE_USB:
1207 g_strlcpy(buf, TETHERING_USB_IF, len);
1210 case TETHERING_TYPE_WIFI:
1211 g_strlcpy(buf, TETHERING_WIFI_IF, len);
1214 case TETHERING_TYPE_BT:
1215 g_strlcpy(buf, TETHERING_BT_IF, len);
1220 ERR("Not supported type : %d\n", type);
1227 static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int len)
1229 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1233 case TETHERING_TYPE_USB:
1234 g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
1237 case TETHERING_TYPE_WIFI:
1238 g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
1241 case TETHERING_TYPE_BT:
1242 g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
1246 ERR("Not supported type : %d\n", type);
1253 static int __get_common_ssid(char *ssid, unsigned int size)
1256 ERR("ssid is null\n"); //LCOV_EXCL_LINE
1257 return TETHERING_ERROR_INVALID_PARAMETER;
1261 char *ptr_tmp = NULL;
1263 ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
1265 ERR("vconf_get_str is failed and set default ssid");
1266 g_strlcpy(ssid, TETHERING_DEFAULT_SSID, size);
1268 g_strlcpy(ssid, ptr, size);
1272 if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp))
1275 return TETHERING_ERROR_NONE;
1278 static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf)
1280 _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
1283 case TETHERING_WIFI_MODE_TYPE_B:
1284 *buf = g_strdup("b");
1286 case TETHERING_WIFI_MODE_TYPE_G:
1287 *buf = g_strdup("g");
1289 case TETHERING_WIFI_MODE_TYPE_A:
1290 *buf = g_strdup("a");
1292 case TETHERING_WIFI_MODE_TYPE_AD:
1293 *buf = g_strdup("ad");
1296 ERR("Not supported type : %d\n", type);
1302 static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set)
1306 __tethering_h *th = (__tethering_h *)tethering;
1307 tethering_error_e ret = TETHERING_ERROR_NONE;
1310 if (th == NULL || set == NULL) {
1311 ERR("null parameter\n-\n"); //LCOV_EXCL_LINE
1312 return TETHERING_ERROR_INVALID_PARAMETER;
1315 if (th->ssid == NULL)
1316 __get_common_ssid(set->ssid, sizeof(set->ssid));
1318 g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid));
1320 ret = __get_security_type(&set->sec_type);
1321 if (ret != TETHERING_ERROR_NONE)
1322 set->sec_type = th->sec_type;
1324 ret = __get_visible(&set->visibility);
1325 if (ret != TETHERING_ERROR_NONE)
1326 set->visibility = th->visibility;
1328 set->mac_filter = th->mac_filter;
1329 set->max_connected = th->wifi_max_connected;
1330 set->channel = th->channel;
1332 __get_wifi_mode_type(th->mode_type, &ptr);
1334 g_strlcpy(set->mode, "", sizeof(set->mode));
1336 g_strlcpy(set->mode, ptr, sizeof(set->mode));
1340 if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
1341 g_strlcpy(set->key, "", sizeof(set->key));
1343 GDBusProxy *proxy = th->client_bus_proxy;
1344 GVariant *parameters;
1345 GError *error = NULL;
1346 char *passphrase = NULL;
1347 unsigned int len = 0;
1349 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
1350 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1354 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
1356 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
1357 ret = TETHERING_ERROR_PERMISSION_DENIED;
1359 ret = TETHERING_ERROR_OPERATION_FAILED;
1361 g_error_free(error);
1366 if (parameters != NULL) {
1367 g_variant_get(parameters, "(siu)", &passphrase, &len, &ret);
1368 g_variant_unref(parameters);
1371 g_strlcpy(set->key, passphrase, sizeof(set->key));
1374 INFO("ssid: %s security: %d mode: %s channel: %d visibility: %s\n",
1375 set->ssid, set->sec_type, set->mode, set->channel,
1376 (set->visibility) ? "true" : "false");
1378 return TETHERING_ERROR_NONE;
1381 static bool __check_precondition(tethering_type_e type)
1383 int dnet_status = 0;
1384 int cellular_state = 0;
1386 /* data network through cellular */
1387 vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state);
1388 if (cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) {
1389 INFO("Data Network can be connected later");
1393 /* data network status */
1394 vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status);
1395 if ((dnet_status == VCONFKEY_NETWORK_WIFI
1396 && type != TETHERING_TYPE_WIFI)
1397 || dnet_status == VCONFKEY_NETWORK_ETHERNET)
1400 ERR("Network is not available!");
1406 * @brief Creates the handle of tethering.
1408 * @privlevel platform
1409 * @privilege http://tizen.org/privilege/tethering.admin
1410 * @remarks The @a tethering must be released tethering_destroy() by you.
1411 * @param[out] tethering A handle of a new mobile ap handle on success
1412 * @return 0 on success, otherwise a negative error value.
1413 * @retval #TETHERING_ERROR_NONE Successful
1414 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1415 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1416 * @retval #TETHERING_ERROR_NOT_SUPPORT_API API is not supported
1417 * @see tethering_destroy()
1419 API int tethering_create(tethering_h *tethering)
1421 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1422 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1423 "parameter(tethering) is NULL\n");
1426 __tethering_h *th = NULL;
1427 GError *error = NULL;
1428 char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
1430 th = (__tethering_h *)malloc(sizeof(__tethering_h));
1432 _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
1433 "malloc is failed\n");
1434 memset(th, 0x00, sizeof(__tethering_h));
1435 th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
1436 th->visibility = true;
1437 th->mac_filter = false;
1438 th->channel = TETHERING_WIFI_CHANNEL;
1439 th->mode_type = TETHERING_WIFI_MODE_TYPE_G;
1440 th->wifi_max_connected = TETHERING_WIFI_MAX_STA;
1442 if (__generate_initial_passphrase(th->passphrase,
1443 sizeof(th->passphrase)) == 0) {
1445 ERR("random passphrase generation failed\n");
1447 return TETHERING_ERROR_OPERATION_FAILED;
1451 if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
1453 ERR("common ssid get failed\n");
1455 return TETHERING_ERROR_OPERATION_FAILED;
1459 #if !GLIB_CHECK_VERSION(2, 36, 0)
1462 GCancellable *cancellable = g_cancellable_new();
1463 th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
1466 ERR("Couldn't connect to the System bus[%s]", error->message);
1467 g_error_free(error);
1468 g_cancellable_cancel(cancellable);
1469 g_object_unref(cancellable);
1471 return TETHERING_ERROR_OPERATION_FAILED;
1474 th->cancellable = cancellable;
1476 th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
1477 NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
1478 TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
1479 if (!th->client_bus_proxy) {
1482 ERR("Couldn't create the proxy object because of %s\n", error->message);
1483 g_cancellable_cancel(th->cancellable);
1484 g_object_unref(th->cancellable);
1485 g_object_unref(th->client_bus);
1487 return TETHERING_ERROR_OPERATION_FAILED;
1491 __connect_signals((tethering_h)th);
1493 *tethering = (tethering_h)th;
1494 _tethering_add_handle(th);
1495 INFO("Tethering Handle : %p\n", th);
1497 return TETHERING_ERROR_NONE;
1502 * @brief Destroys the handle of tethering.
1504 * @privlevel platform
1505 * @privilege http://tizen.org/privilege/tethering.admin
1506 * @param[in] tethering The handle of tethering
1507 * @return 0 on success, otherwise a negative error value.
1508 * @retval #TETHERING_ERROR_NONE Successful
1509 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1510 * @see tethering_create()
1512 API int tethering_destroy(tethering_h tethering)
1515 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1516 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1517 "parameter(tethering) is NULL\n");
1519 __tethering_h *th = (__tethering_h *)tethering;
1521 INFO("Tethering Handle : %p\n", th);
1523 __disconnect_signals(tethering);
1524 _tethering_remove_handle(th);
1529 g_object_unref(th->cancellable);
1530 g_object_unref(th->client_bus_proxy);
1531 g_object_unref(th->client_bus);
1532 memset(th, 0x00, sizeof(__tethering_h));
1537 return TETHERING_ERROR_NONE;
1542 * @brief Enables the tethering, asynchronously.
1544 * @privlevel platform
1545 * @privilege http://tizen.org/privilege/tethering.admin
1546 * @param[in] tethering The handle of tethering
1547 * @param[in] type The type of tethering
1548 * @return 0 on success, otherwise negative error value.
1549 * @retval #TETHERING_ERROR_NONE Successful
1550 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1551 * @post tethering_enabled_cb() will be invoked.
1552 * @see tethering_is_enabled()
1553 * @see tethering_disable()
1555 API int tethering_enable(tethering_h tethering, tethering_type_e type)
1557 INFO("+ type : %d\n", type);
1558 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1559 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1560 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1561 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1563 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1564 "parameter(tethering) is NULL\n");
1566 tethering_error_e ret = TETHERING_ERROR_NONE;
1567 __tethering_h *th = (__tethering_h *)tethering;
1568 GDBusProxy *proxy = th->client_bus_proxy;
1569 GDBusConnection *connection = th->client_bus;
1571 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1573 if (__check_precondition(type) == FALSE) {
1576 return TETHERING_ERROR_OPERATION_FAILED;
1582 case TETHERING_TYPE_USB:
1583 g_dbus_connection_signal_unsubscribe(connection,
1584 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1586 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1587 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1588 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1592 case TETHERING_TYPE_WIFI: {
1593 _softap_settings_t set = {"", "", "", 0, false};
1595 ret = __prepare_wifi_settings(tethering, &set);
1596 if (ret != TETHERING_ERROR_NONE) {
1598 ERR("softap settings initialization failed\n");
1600 return TETHERING_ERROR_OPERATION_FAILED;
1603 g_dbus_connection_signal_unsubscribe(connection,
1604 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1606 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1607 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),
1608 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1609 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1613 case TETHERING_TYPE_BT:
1614 g_dbus_connection_signal_unsubscribe(connection,
1615 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1617 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1618 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1619 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1620 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1625 case TETHERING_TYPE_P2P: {
1626 _softap_settings_t p2p_set = {"", "", "", 0, false};
1627 ret = __prepare_wifi_settings(tethering, &p2p_set);
1628 if (ret != TETHERING_ERROR_NONE) {
1629 ERR("p2p settings initialization failed\n");
1631 return TETHERING_ERROR_OPERATION_FAILED;
1634 g_dbus_proxy_call(proxy, "enable_p2p_tethering",
1635 g_variant_new("(ssi)", p2p_set.ssid, p2p_set.key, p2p_set.channel),
1636 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1637 (GAsyncReadyCallback) __p2p_enabled_cfm_cb, (gpointer)tethering);
1641 case TETHERING_TYPE_ALL: {
1642 _softap_settings_t set = {"", "", "", 0, false};
1644 ret = __prepare_wifi_settings(tethering, &set);
1645 if (ret != TETHERING_ERROR_NONE) {
1646 ERR("softap settings initialization failed\n");
1647 return TETHERING_ERROR_OPERATION_FAILED;
1650 /* TETHERING_TYPE_USB */
1651 g_dbus_connection_signal_unsubscribe(connection,
1652 sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
1654 g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL,
1655 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1656 (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
1658 /* TETHERING_TYPE_WIFI */
1659 g_dbus_connection_signal_unsubscribe(connection,
1660 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1662 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1663 g_variant_new("(sssiiiiii)", set.ssid, set.key, set.mode,
1664 set.channel, set.visibility, set.mac_filter, set.max_connected,
1665 set.sec_type, TETHERING_ADDRESS_FAMILY_IPV4),
1666 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1667 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1669 /* TETHERING_TYPE_BT */
1670 g_dbus_connection_signal_unsubscribe(connection,
1671 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1673 g_dbus_proxy_call(proxy, "enable_bt_tethering",
1674 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1675 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1676 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1680 ERR("Unknown type : %d\n", type);
1682 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1685 return TETHERING_ERROR_INVALID_PARAMETER;
1689 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1691 return TETHERING_ERROR_NONE;
1694 API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
1696 DBG("+ type : %d\n", type);
1697 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1698 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1699 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1700 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1702 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1703 "parameter(tethering) is NULL\n");
1705 __tethering_h *th = (__tethering_h *)tethering;
1706 GDBusProxy *proxy = th->client_bus_proxy;
1707 GDBusConnection *connection = th->client_bus;
1710 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
1712 if (__check_precondition(type) == FALSE) {
1715 return TETHERING_ERROR_OPERATION_FAILED;
1720 case TETHERING_TYPE_WIFI: {
1721 _softap_settings_t set = {"", "", "", 0, false, false, 0, 0};
1723 ret = __prepare_wifi_settings(tethering, &set);
1724 if (ret != TETHERING_ERROR_NONE) {
1725 ERR("softap settings initialization failed\n");
1727 return TETHERING_ERROR_OPERATION_FAILED;
1729 g_dbus_connection_signal_unsubscribe(connection,
1730 sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
1731 g_dbus_proxy_call(proxy, "enable_wifi_tethering",
1732 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),
1733 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1734 (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering);
1737 case TETHERING_TYPE_BT: {
1738 g_dbus_connection_signal_unsubscribe(connection,
1739 sigs[E_SIGNAL_BT_TETHER_ON].sig_id);
1742 g_dbus_proxy_call(proxy, "enable_bt_tethering", g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1743 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1744 (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering);
1750 ERR("Unknown type : %d\n", type);
1752 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1755 return TETHERING_ERROR_INVALID_PARAMETER;
1759 g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
1761 return TETHERING_ERROR_NONE;
1764 API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type)
1766 DBG("+ type : %d\n", type);
1767 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1768 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1769 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1770 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1772 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1773 "parameter(tethering) is NULL\n");
1775 __tethering_h *th = (__tethering_h *)tethering;
1776 GDBusProxy *proxy = th->client_bus_proxy;
1777 GDBusConnection *connection = th->client_bus;
1780 case TETHERING_TYPE_WIFI:
1781 DBG("Disable wifi tethering..");
1782 g_dbus_connection_signal_unsubscribe(connection,
1783 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1785 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1786 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1787 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1788 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1790 case TETHERING_TYPE_BT:
1791 g_dbus_connection_signal_unsubscribe(connection,
1792 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1794 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1795 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV6),
1796 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1797 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1801 ERR("Not supported tethering type [%d]\n", type);
1803 return TETHERING_ERROR_INVALID_PARAMETER;
1806 return TETHERING_ERROR_NONE;
1810 * @brief Disables the tethering, asynchronously.
1812 * @privlevel platform
1813 * @privilege http://tizen.org/privilege/tethering.admin
1814 * @param[in] tethering The handle of tethering
1815 * @param[in] type The type of tethering
1816 * @return 0 on success, otherwise negative error value.
1817 * @retval #TETHERING_ERROR_NONE Successful
1818 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1819 * @post tethering_disabled_cb() will be invoked.
1820 * @see tethering_is_enabled()
1821 * @see tethering_enable()
1823 API int tethering_disable(tethering_h tethering, tethering_type_e type)
1825 INFO("+ type : %d\n", type);
1826 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1827 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
1828 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1829 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
1831 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1832 "parameter(tethering) is NULL\n");
1834 __tethering_h *th = (__tethering_h *)tethering;
1835 GDBusProxy *proxy = th->client_bus_proxy;
1836 GDBusConnection *connection = th->client_bus;
1840 case TETHERING_TYPE_USB:
1841 g_dbus_connection_signal_unsubscribe(connection,
1842 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1844 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1845 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1846 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1851 case TETHERING_TYPE_WIFI:
1853 g_dbus_connection_signal_unsubscribe(connection,
1854 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1856 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1857 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1858 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1859 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1862 case TETHERING_TYPE_BT:
1864 g_dbus_connection_signal_unsubscribe(connection,
1865 sigs[E_SIGNAL_BT_TETHER_OFF].sig_id);
1867 g_dbus_proxy_call(proxy, "disable_bt_tethering",
1868 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1869 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1870 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1874 case TETHERING_TYPE_P2P:
1875 g_dbus_proxy_call(proxy, "disable_p2p_tethering",
1876 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1877 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1880 case TETHERING_TYPE_ALL:
1881 g_dbus_connection_signal_unsubscribe(connection,
1882 sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
1884 g_dbus_proxy_call(proxy, "disable_usb_tethering",
1885 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1886 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1888 g_dbus_connection_signal_unsubscribe(connection,
1889 sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id);
1891 g_dbus_proxy_call(proxy, "disable_wifi_tethering",
1892 g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
1893 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
1894 (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
1896 g_dbus_connection_signal_unsubscribe(connection,
1897 sigs[E_SIGNAL_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 ERR("Not supported tethering type [%d]\n", type);
1908 return TETHERING_ERROR_INVALID_PARAMETER;
1912 return TETHERING_ERROR_NONE;
1917 * @brief Checks whetehr the tethering is enabled or not.
1919 * @privlevel platform
1920 * @privilege http://tizen.org/privilege/tethering.admin
1921 * @param[in] tethering The handle of tethering
1922 * @param[in] type The type of tethering
1923 * @return @c true if tethering is enabled, \n @c false if tethering is disabled.
1925 API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type)
1927 INFO("+ type : %d\n", type);
1929 int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
1931 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1933 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0)
1937 case TETHERING_TYPE_USB:
1938 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_USB;
1941 case TETHERING_TYPE_WIFI:
1942 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI;
1945 case TETHERING_TYPE_BT:
1946 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT;
1949 case TETHERING_TYPE_P2P:
1950 vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_P2P;
1954 ERR("Not supported type : %d\n", type);
1957 INFO("- enabled: %s\n", (is_on & vconf_type) ? "true" : "false");
1958 return is_on & vconf_type ? true : false;
1963 * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1".
1965 * @privlevel platform
1966 * @privilege http://tizen.org/privilege/tethering.admin
1967 * @remarks @a mac_address must be released with free() by you.
1968 * @param[in] tethering The handle of tethering
1969 * @param[in] type The type of tethering
1970 * @param[out] mac_address The MAC address
1971 * @return 0 on success, otherwise a negative error value.
1972 * @retval #TETHERING_ERROR_NONE Successful
1973 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
1974 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
1975 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
1976 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
1977 * @pre tethering must be enabled.
1978 * @see tethering_is_enabled()
1979 * @see tethering_enable()
1981 API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
1983 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
1984 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); //LCOV_EXCL_LINE
1985 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
1986 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); //LCOV_EXCL_LINE
1988 _retvm_if(tethering_is_enabled(tethering, type) == false,
1989 TETHERING_ERROR_NOT_ENABLED,
1990 "tethering type[%d] is not enabled\n", type);
1991 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1992 "parameter(tethering) is NULL\n");
1993 _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
1994 "parameter(mac_address) is NULL\n");
1998 char *macbuf = NULL;
2000 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2001 TETHERING_ERROR_OPERATION_FAILED,
2002 "getting interface name is failed\n");
2004 s = socket(AF_INET, SOCK_DGRAM, 0);
2005 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2006 "getting socket is failed\n");
2007 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2009 ERR("getting mac is failed\n");
2011 return TETHERING_ERROR_OPERATION_FAILED;
2016 macbuf = (char *)malloc(TETHERING_STR_INFO_LEN);
2017 _retvm_if(macbuf == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2018 "Not enough memory\n");
2019 snprintf(macbuf, TETHERING_STR_INFO_LEN, "%02X:%02X:%02X:%02X:%02X:%02X",
2020 (unsigned char)ifr.ifr_hwaddr.sa_data[0],
2021 (unsigned char)ifr.ifr_hwaddr.sa_data[1],
2022 (unsigned char)ifr.ifr_hwaddr.sa_data[2],
2023 (unsigned char)ifr.ifr_hwaddr.sa_data[3],
2024 (unsigned char)ifr.ifr_hwaddr.sa_data[4],
2025 (unsigned char)ifr.ifr_hwaddr.sa_data[5]);
2027 *mac_address = macbuf;
2029 return TETHERING_ERROR_NONE;
2034 * @brief Gets the name of network interface. For example, usb0.
2036 * @privlevel platform
2037 * @privilege http://tizen.org/privilege/tethering.admin
2038 * @remarks @a interface_name must be released with free() by you.
2039 * @param[in] tethering The handle of tethering
2040 * @param[in] type The type of tethering
2041 * @param[out] interface_name The name of network interface
2042 * @return 0 on success, otherwise negative error value.
2043 * @retval #TETHERING_ERROR_NONE Successful
2044 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2045 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2046 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2047 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2048 * @pre tethering must be enabled.
2049 * @see tethering_is_enabled()
2050 * @see tethering_enable()
2052 API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name)
2054 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2055 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2056 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2057 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2059 _retvm_if(tethering_is_enabled(tethering, type) == false,
2060 TETHERING_ERROR_NOT_ENABLED,
2061 "tethering type[%d] is not enabled\n", type);
2062 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2063 "parameter(tethering) is NULL\n");
2064 _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2065 "parameter(interface_name) is NULL\n");
2067 char intf[TETHERING_STR_INFO_LEN] = {0, };
2069 _retvm_if(!__get_intf_name(type, intf, sizeof(intf)),
2070 TETHERING_ERROR_OPERATION_FAILED,
2071 "getting interface name is failed\n");
2072 *interface_name = strdup(intf);
2073 _retvm_if(*interface_name == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2074 "Not enough memory\n");
2076 return TETHERING_ERROR_NONE;
2081 * @brief Gets the local IP address.
2083 * @privlevel platform
2084 * @privilege http://tizen.org/privilege/tethering.admin
2085 * @remarks @a ip_address must be released with free() by you.
2086 * @param[in] tethering The handle of tethering
2087 * @param[in] type The type of tethering
2088 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2089 * @param[out] ip_address The local IP address
2090 * @return 0 on success, otherwise negative error value.
2091 * @retval #TETHERING_ERROR_NONE Successful
2092 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2093 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2094 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2095 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2096 * @pre tethering must be enabled.
2097 * @see tethering_is_enabled()
2098 * @see tethering_enable()
2100 API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
2102 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2103 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); //LCOV_EXCL_LINE
2104 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2105 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); //LCOV_EXCL_LINE
2107 _retvm_if(tethering_is_enabled(tethering, type) == false,
2108 TETHERING_ERROR_NOT_ENABLED,
2109 "tethering type[%d] is not enabled\n", type);
2110 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2111 "parameter(tethering) is NULL\n");
2112 _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2113 "parameter(ip_address) is NULL\n");
2119 _retvm_if(!__get_intf_name(type, ifr.ifr_name, sizeof(ifr.ifr_name)),
2120 TETHERING_ERROR_OPERATION_FAILED,
2121 "getting interface name is failed\n");
2123 s = socket(AF_INET, SOCK_DGRAM, 0);
2124 _retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
2125 "getting socket is failed\n");
2126 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2127 ERR("ioctl is failed\n");
2129 return TETHERING_ERROR_OPERATION_FAILED;
2133 ipbuf = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
2134 *ip_address = strdup(ipbuf);
2135 _retvm_if(*ip_address == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2136 "Not enough memory\n");
2138 return TETHERING_ERROR_NONE;
2143 * @brief Gets the Gateway address.
2145 * @privlevel platform
2146 * @privilege http://tizen.org/privilege/tethering.admin
2147 * @remarks @a gateway_address must be released with free() by you.
2148 * @param[in] tethering The handle of tethering
2149 * @param[in] type The type of tethering
2150 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2151 * @param[out] gateway_address The local IP address
2152 * @return 0 on success, otherwise negative error value.
2153 * @retval #TETHERING_ERROR_NONE Successful
2154 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2155 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2156 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2157 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2158 * @pre tethering must be enabled.
2159 * @see tethering_is_enabled()
2160 * @see tethering_enable()
2162 API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address)
2164 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2165 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2166 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2167 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2169 _retvm_if(tethering_is_enabled(tethering, type) == false,
2170 TETHERING_ERROR_NOT_ENABLED,
2171 "tethering type[%d] is not enabled\n", type);
2172 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2173 "parameter(tethering) is NULL\n");
2174 _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2175 "parameter(gateway_address) is NULL\n");
2177 char gateway_buf[TETHERING_STR_INFO_LEN] = {0, };
2179 _retvm_if(!__get_gateway_addr(type, gateway_buf, sizeof(gateway_buf)),
2180 TETHERING_ERROR_OPERATION_FAILED,
2181 "getting gateway address is failed\n");
2183 *gateway_address = strdup(gateway_buf);
2185 return TETHERING_ERROR_NONE;
2190 * @brief Gets the Subnet Mask.
2192 * @privlevel platform
2193 * @privilege http://tizen.org/privilege/tethering.admin
2194 * @remarks @a subnet_mask must be released with free() by you.
2195 * @param[in] tethering The handle of tethering
2196 * @param[in] type The type of tethering
2197 * @param[in] address_family The address family of IP address. Currently, #TETHERING_ADDRESS_FAMILY_IPV4 is only supported.
2198 * @param[out] subnet_mask The local IP address
2199 * @return 0 on success, otherwise negative error value.
2200 * @retval #TETHERING_ERROR_NONE Successful
2201 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2202 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2203 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2204 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2205 * @pre tethering must be enabled.
2206 * @see tethering_is_enabled()
2207 * @see tethering_enable()
2209 API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask)
2211 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2212 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2213 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2214 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2216 _retvm_if(tethering_is_enabled(tethering, type) == false,
2217 TETHERING_ERROR_NOT_ENABLED,
2218 "tethering is not enabled\n");
2219 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2220 "parameter(tethering) is NULL\n");
2221 _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2222 "parameter(subnet_mask) is NULL\n");
2224 *subnet_mask = strdup(TETHERING_SUBNET_MASK);
2225 _retvm_if(*subnet_mask == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2226 "Not enough memory\n");
2228 return TETHERING_ERROR_NONE;
2233 * @brief Gets the data usage.
2235 * @privlevel platform
2236 * @privilege http://tizen.org/privilege/tethering.admin
2237 * @param[in] tethering The handle of tethering
2238 * @param[out] usage The data usage
2239 * @return 0 on success, otherwise negative error value.
2240 * @retval #TETHERING_ERROR_NONE Successful
2241 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2242 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2243 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2244 * @pre tethering must be enabled.
2245 * @see tethering_is_enabled()
2246 * @see tethering_enable()
2248 API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data)
2250 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2252 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2253 "parameter(tethering) is NULL\n");
2254 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2255 "parameter(callback) is NULL\n");
2256 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2257 TETHERING_ERROR_NOT_ENABLED,
2258 "tethering is not enabled\n");
2260 __tethering_h *th = (__tethering_h *)tethering;
2261 GDBusProxy *proxy = th->client_bus_proxy;
2263 th->data_usage_cb = callback;
2264 th->data_usage_user_data = user_data;
2266 g_dbus_proxy_call(proxy, "get_data_packet_usage",
2267 NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
2268 (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering);
2270 return TETHERING_ERROR_NONE;
2275 * @brief Gets the client which is connected by tethering "type".
2277 * @privlevel platform
2278 * @privilege http://tizen.org/privilege/tethering.admin
2279 * @param[in] tethering The handle of tethering
2280 * @param[in] type The type of tethering
2281 * @param[in] callback The callback function to invoke
2282 * @param[in] user_data The user data to be passed to the callback function
2283 * @retval #TETHERING_ERROR_NONE Successful
2284 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2285 * @retval #TETHERING_ERROR_NOT_ENABLED Not enabled
2286 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2287 * @pre tethering must be enabled.
2288 * @see tethering_is_enabled()
2289 * @see tethering_enable()
2291 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
2293 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2294 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2295 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2296 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2298 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2299 "parameter(tethering) is NULL\n");
2300 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2301 "parameter(callback) is NULL\n");
2302 _retvm_if(__any_tethering_is_enabled(tethering) == false,
2303 TETHERING_ERROR_NOT_ENABLED,
2304 "tethering is not enabled\n");
2306 mobile_ap_type_e interface;
2307 __tethering_h *th = (__tethering_h *)tethering;
2308 __tethering_client_h client = {0, };
2311 gchar *hostname = NULL;
2312 guint timestamp = 0;
2313 GError *error = NULL;
2314 GVariant *result = NULL;
2315 GVariantIter *outer_iter = NULL;
2316 GVariantIter *inner_iter = NULL;
2317 GVariant *station = NULL;
2318 GVariant *value = NULL;
2321 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
2322 NULL, G_DBUS_CALL_FLAGS_NONE,
2323 -1, th->cancellable, &error);
2325 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message); //LCOV_EXCL_LINE
2326 g_variant_get(result, "(a(a{sv}))", &outer_iter);
2328 while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
2329 g_variant_get(station, "a{sv}", &inner_iter);
2330 while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
2331 if (g_strcmp0(key, "Type") == 0) {
2332 interface = g_variant_get_int32(value);
2333 if (interface == MOBILE_AP_TYPE_USB)
2334 client.interface = TETHERING_TYPE_USB;
2335 else if (interface == MOBILE_AP_TYPE_WIFI)
2336 client.interface = TETHERING_TYPE_WIFI;
2337 else if (interface == MOBILE_AP_TYPE_BT)
2338 client.interface = TETHERING_TYPE_BT;
2339 else if (interface == MOBILE_AP_TYPE_P2P)
2340 client.interface = TETHERING_TYPE_P2P;
2342 ERR("Invalid interface\n");
2344 g_variant_unref(value);
2347 DBG("interface is %d\n", client.interface);
2348 if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
2350 g_variant_unref(value);
2353 } else if (g_strcmp0(key, "IP") == 0) {
2354 g_variant_get(value, "s", &ip);
2355 SDBG("ip is %s\n", ip);
2356 g_strlcpy(client.ip, ip, sizeof(client.ip));
2357 } else if (g_strcmp0(key, "MAC") == 0) {
2358 g_variant_get(value, "s", &mac);
2359 SDBG("mac is %s\n", mac);
2360 g_strlcpy(client.mac, mac, sizeof(client.mac));
2361 } else if (g_strcmp0(key, "Name") == 0) {
2362 g_variant_get(value, "s", &hostname);
2363 SDBG("hsotname is %s\n", hostname);
2365 client.hostname = g_strdup(hostname);
2366 } else if (g_strcmp0(key, "Time") == 0) {
2367 timestamp = g_variant_get_int32(value);
2368 DBG("timestamp is %d\n", timestamp);
2369 client.tm = (time_t)timestamp;
2371 ERR("Key %s not required\n", key);
2377 g_variant_iter_free(inner_iter);
2378 if (callback((tethering_client_h)&client, user_data) == false) {
2379 DBG("iteration is stopped\n");
2380 g_free(client.hostname);
2381 g_variant_iter_free(outer_iter);
2382 g_variant_unref(station);
2383 g_variant_unref(result);
2385 return TETHERING_ERROR_OPERATION_FAILED;
2387 g_free(client.hostname);
2390 g_variant_iter_free(outer_iter);
2391 g_variant_unref(station);
2392 g_variant_unref(result);
2394 return TETHERING_ERROR_NONE;
2399 * @brief Registers the callback function called when tethering is enabled.
2401 * @privlevel platform
2402 * @privilege http://tizen.org/privilege/tethering.admin
2403 * @param[in] tethering The handle of tethering
2404 * @param[in] type The type of tethering
2405 * @param[in] callback The callback function to invoke
2406 * @param[in] user_data The user data to be passed to the callback function
2407 * @retval #TETHERING_ERROR_NONE Successful
2408 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2409 * @see tethering_unset_enabled_cb()
2411 API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data)
2413 INFO("+ type: %d\n", type);
2414 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2415 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2416 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2417 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2419 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2420 "parameter(tethering) is NULL\n");
2421 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2422 "parameter(callback) is NULL\n");
2424 __tethering_h *th = (__tethering_h *)tethering;
2425 tethering_type_e ti;
2427 if (type != TETHERING_TYPE_ALL) {
2428 th->enabled_cb[type] = callback;
2429 th->enabled_user_data[type] = user_data;
2431 return TETHERING_ERROR_NONE;
2434 /* TETHERING_TYPE_ALL */
2435 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2436 th->enabled_cb[ti] = callback;
2437 th->enabled_user_data[ti] = user_data;
2441 return TETHERING_ERROR_NONE;
2446 * @brief Unregisters the callback function called when tethering is disabled.
2448 * @privlevel platform
2449 * @privilege http://tizen.org/privilege/tethering.admin
2450 * @param[in] tethering The handle of tethering
2451 * @param[in] type The type of tethering
2452 * @retval #TETHERING_ERROR_NONE Successful
2453 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2454 * @see tethering_set_enabled_cb()
2456 API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type)
2458 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2459 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2460 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2461 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2463 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2464 "parameter(tethering) is NULL\n");
2466 __tethering_h *th = (__tethering_h *)tethering;
2467 tethering_type_e ti;
2469 if (type != TETHERING_TYPE_ALL) {
2470 th->enabled_cb[type] = NULL;
2471 th->enabled_user_data[type] = NULL;
2473 return TETHERING_ERROR_NONE;
2476 /* TETHERING_TYPE_ALL */
2477 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2478 th->enabled_cb[ti] = NULL;
2479 th->enabled_user_data[ti] = NULL;
2482 return TETHERING_ERROR_NONE;
2487 * @brief Registers the callback function called when tethering is disabled.
2489 * @privlevel platform
2490 * @privilege http://tizen.org/privilege/tethering.admin
2491 * @param[in] tethering The handle of tethering
2492 * @param[in] type The type of tethering
2493 * @param[in] callback The callback function to invoke
2494 * @param[in] user_data The user data to be passed to the callback function
2495 * @retval #TETHERING_ERROR_NONE Successful
2496 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2497 * @see tethering_unset_disabled_cb()
2499 API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data)
2501 INFO("+ type: %d\n", type);
2502 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2503 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2504 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2505 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2507 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2508 "parameter(tethering) is NULL\n");
2509 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2510 "parameter(callback) is NULL\n");
2512 __tethering_h *th = (__tethering_h *)tethering;
2513 tethering_type_e ti;
2515 if (type != TETHERING_TYPE_ALL) {
2516 th->disabled_cb[type] = callback;
2517 th->disabled_user_data[type] = user_data;
2519 return TETHERING_ERROR_NONE;
2522 /* TETHERING_TYPE_ALL */
2523 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2524 th->disabled_cb[ti] = callback;
2525 th->disabled_user_data[ti] = user_data;
2528 return TETHERING_ERROR_NONE;
2533 * @brief Unregisters the callback function called when tethering is disabled.
2535 * @privlevel platform
2536 * @privilege http://tizen.org/privilege/tethering.admin
2537 * @param[in] tethering The handle of tethering
2538 * @param[in] type The type of tethering
2539 * @retval #TETHERING_ERROR_NONE Successful
2540 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2541 * @see tethering_set_disabled_cb()
2543 API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type)
2545 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2546 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2547 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2548 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2550 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2551 "parameter(tethering) is NULL\n");
2553 __tethering_h *th = (__tethering_h *)tethering;
2554 tethering_type_e ti;
2556 if (type != TETHERING_TYPE_ALL) {
2557 th->disabled_cb[type] = NULL;
2558 th->disabled_user_data[type] = NULL;
2560 return TETHERING_ERROR_NONE;
2563 /* TETHERING_TYPE_ALL */
2564 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2565 th->disabled_cb[ti] = NULL;
2566 th->disabled_user_data[ti] = NULL;
2569 return TETHERING_ERROR_NONE;
2574 * @brief Registers the callback function called when the state of connection is changed.
2576 * @privlevel platform
2577 * @privilege http://tizen.org/privilege/tethering.admin
2578 * @param[in] tethering The handle of tethering
2579 * @param[in] type The type of tethering
2580 * @param[in] callback The callback function to invoke
2581 * @param[in] user_data The user data to be passed to the callback function
2582 * @retval #TETHERING_ERROR_NONE Successful
2583 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2584 * @see tethering_unset_connection_state_changed_cb_cb()
2586 API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data)
2588 INFO("+ type: %d\n", type);
2589 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2590 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2591 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2592 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2594 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2595 "parameter(tethering) is NULL\n");
2596 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2597 "parameter(callback) is NULL\n");
2599 __tethering_h *th = (__tethering_h *)tethering;
2600 tethering_type_e ti;
2602 if (type != TETHERING_TYPE_ALL) {
2603 th->changed_cb[type] = callback;
2604 th->changed_user_data[type] = user_data;
2606 return TETHERING_ERROR_NONE;
2609 /* TETHERING_TYPE_ALL */
2610 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2611 th->changed_cb[ti] = callback;
2612 th->changed_user_data[ti] = user_data;
2615 return TETHERING_ERROR_NONE;
2620 * @brief Unregisters the callback function called when the state of connection is changed.
2622 * @privlevel platform
2623 * @privilege http://tizen.org/privilege/tethering.admin
2624 * @param[in] tethering The handle of tethering
2625 * @param[in] type The type of tethering
2626 * @retval #TETHERING_ERROR_NONE Successful
2627 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2628 * @see tethering_set_connection_state_changed_cb()
2630 API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type)
2632 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2633 if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
2634 else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2635 else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
2637 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2638 "parameter(tethering) is NULL\n");
2640 __tethering_h *th = (__tethering_h *)tethering;
2641 tethering_type_e ti;
2643 if (type != TETHERING_TYPE_ALL) {
2644 th->changed_cb[type] = NULL;
2645 th->changed_user_data[type] = NULL;
2647 return TETHERING_ERROR_NONE;
2650 /* TETHERING_TYPE_ALL */
2651 for (ti = TETHERING_TYPE_USB; ti <= TETHERING_TYPE_P2P; ti++) {
2652 th->changed_cb[ti] = NULL;
2653 th->changed_user_data[ti] = NULL;
2656 return TETHERING_ERROR_NONE;
2661 * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed.
2663 * @privlevel platform
2664 * @privilege http://tizen.org/privilege/tethering.admin
2665 * @param[in] tethering The handle of tethering
2666 * @param[in] callback The callback function to invoke
2667 * @param[in] user_data The user data to be passed to the callback function
2668 * @retval #TETHERING_ERROR_NONE Successful
2669 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2670 * @see tethering_wifi_unset_security_type_changed_cb()
2672 API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data)
2674 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2675 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2677 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2678 "parameter(tethering) is NULL\n");
2679 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2680 "parameter(callback) is NULL\n");
2682 __tethering_h *th = (__tethering_h *)tethering;
2684 th->security_type_changed_cb = callback;
2685 th->security_type_user_data = user_data;
2687 return TETHERING_ERROR_NONE;
2693 * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed.
2695 * @privlevel platform
2696 * @privilege http://tizen.org/privilege/tethering.admin
2697 * @param[in] tethering The handle of tethering
2698 * @param[in] type The type of tethering
2699 * @retval #TETHERING_ERROR_NONE Successful
2700 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2701 * @see tethering_wifi_set_security_type_changed_cb()
2703 API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering)
2705 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2706 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2708 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2709 "parameter(tethering) is NULL\n");
2711 __tethering_h *th = (__tethering_h *)tethering;
2713 th->security_type_changed_cb = NULL;
2714 th->security_type_user_data = NULL;
2716 return TETHERING_ERROR_NONE;
2721 * @brief Registers the callback function called when the visibility of SSID is changed.
2723 * @privlevel platform
2724 * @privilege http://tizen.org/privilege/tethering.admin
2725 * @param[in] tethering The handle of tethering
2726 * @param[in] callback The callback function to invoke
2727 * @param[in] user_data The user data to be passed to the callback function
2728 * @retval #TETHERING_ERROR_NONE Successful
2729 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2730 * @see tethering_wifi_unset_ssid_visibility_changed_cb_cb()
2732 API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data)
2734 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2735 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2737 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2738 "parameter(tethering) is NULL\n");
2739 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2740 "parameter(callback) is NULL\n");
2742 __tethering_h *th = (__tethering_h *)tethering;
2744 th->ssid_visibility_changed_cb = callback;
2745 th->ssid_visibility_user_data = user_data;
2747 return TETHERING_ERROR_NONE;
2752 * @brief Unregisters the callback function called when the visibility of SSID is changed.
2754 * @privlevel platform
2755 * @privilege http://tizen.org/privilege/tethering.admin
2756 * @param[in] tethering The handle of tethering
2757 * @retval #TETHERING_ERROR_NONE Successful
2758 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2759 * @see tethering_wifi_set_ssid_visibility_changed_cb()
2761 API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering)
2763 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2764 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2766 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2767 "parameter(tethering) is NULL\n");
2769 __tethering_h *th = (__tethering_h *)tethering;
2771 th->ssid_visibility_changed_cb = NULL;
2772 th->ssid_visibility_user_data = NULL;
2774 return TETHERING_ERROR_NONE;
2779 * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed.
2781 * @privlevel platform
2782 * @privilege http://tizen.org/privilege/tethering.admin
2783 * @param[in] tethering The handle of tethering
2784 * @param[in] callback The callback function to invoke
2785 * @param[in] user_data The user data to be passed to the callback function
2786 * @retval #TETHERING_ERROR_NONE Successful
2787 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2788 * @see tethering_wifi_unset_passphrase_changed_cb()
2790 API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data)
2792 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2793 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2795 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2796 "parameter(tethering) is NULL\n");
2797 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2798 "parameter(callback) is NULL\n");
2800 __tethering_h *th = (__tethering_h *)tethering;
2802 th->passphrase_changed_cb = callback;
2803 th->passphrase_user_data = user_data;
2805 return TETHERING_ERROR_NONE;
2810 * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed.
2812 * @privlevel platform
2813 * @privilege http://tizen.org/privilege/tethering.admin
2814 * @param[in] tethering The handle of tethering
2815 * @retval #TETHERING_ERROR_NONE Successful
2816 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2817 * @see tethering_wifi_set_passphrase_changed_cb()
2819 API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering)
2821 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2822 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2824 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2825 "parameter(tethering) is NULL\n");
2827 __tethering_h *th = (__tethering_h *)tethering;
2829 th->passphrase_changed_cb = NULL;
2830 th->passphrase_user_data = NULL;
2832 return TETHERING_ERROR_NONE;
2837 * @brief Sets the security type of Wi-Fi tethering.
2839 * @privlevel platform
2840 * @privilege http://tizen.org/privilege/tethering.admin
2841 * @remarks This change is applied next time Wi-Fi tethering is enabled
2842 * @param[in] tethering The handle of tethering
2843 * @param[in] type The security type
2844 * @return 0 on success, otherwise negative error value.
2845 * @retval #TETHERING_ERROR_NONE Successful
2846 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2847 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2848 * @see tethering_wifi_get_security_type()
2850 API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type)
2852 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2853 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2855 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2856 "parameter(tethering) is NULL\n");
2858 __tethering_h *th = (__tethering_h *)tethering;
2859 tethering_error_e ret = TETHERING_ERROR_NONE;
2860 char *sec_str = NULL;
2862 ret = __set_security_type(type);
2863 if (ret == TETHERING_ERROR_NONE) {
2866 case TETHERING_WIFI_SECURITY_TYPE_NONE:
2867 sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
2869 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
2870 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR;
2872 case TETHERING_WIFI_SECURITY_TYPE_WPS:
2873 sec_str = TETHERING_WIFI_SECURITY_TYPE_WPS_STR;
2877 __send_dbus_signal(th->client_bus,
2878 SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
2885 * @brief Gets the security type of Wi-Fi tethering.
2887 * @privlevel platform
2888 * @privilege http://tizen.org/privilege/tethering.admin
2889 * @param[in] tethering The handle of tethering
2890 * @param[out] type The security type
2891 * @return 0 on success, otherwise negative error value.
2892 * @retval #TETHERING_ERROR_NONE Successful
2893 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2894 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2895 * @see tethering_wifi_set_security_type()
2897 API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type)
2899 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2900 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2902 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2903 "parameter(type) is NULL\n");
2905 return __get_security_type(type);
2910 * @brief Sets the SSID (service set identifier).
2912 * @privlevel platform
2913 * @privilege http://tizen.org/privilege/tethering.admin
2914 * @details If SSID is not set, Device name is used as SSID
2915 * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle
2916 * @param[in] tethering The handle of tethering
2917 * @param[out] ssid The SSID
2918 * @return 0 on success, otherwise negative error value.
2919 * @retval #TETHERING_ERROR_NONE Successful
2920 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2921 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2923 API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid)
2925 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2926 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2928 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2929 "parameter(tethering) is NULL\n");
2930 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2931 "parameter(ssid) is NULL\n");
2933 __tethering_h *th = (__tethering_h *)tethering;
2934 char *p_ssid = NULL;
2937 ssid_len = strlen(ssid);
2938 if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) {
2939 ERR("parameter(ssid) is too long");
2940 return TETHERING_ERROR_INVALID_PARAMETER;
2943 p_ssid = strdup(ssid);
2944 _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
2945 "strdup is failed\n");
2951 return TETHERING_ERROR_NONE;
2956 * @brief Gets the SSID (service set identifier).
2958 * @privlevel platform
2959 * @privilege http://tizen.org/privilege/tethering.admin
2960 * @remarks @a ssid must be released with free() by you.
2961 * @param[in] tethering The handle of tethering
2962 * @param[out] ssid The SSID
2963 * @return 0 on success, otherwise negative error value.
2964 * @retval #TETHERING_ERROR_NONE Successful
2965 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
2966 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
2967 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
2969 API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid)
2971 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
2972 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
2974 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2975 "parameter(tethering) is NULL\n");
2976 _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER,
2977 "parameter(ssid) is NULL\n");
2980 __tethering_h *th = (__tethering_h *)tethering;
2981 char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, };
2983 if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) {
2984 if (th->ssid != NULL) {
2985 DBG("Private SSID is set\n");
2986 *ssid = strdup(th->ssid);
2988 if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
2989 val, sizeof(val)) == false) {
2990 return TETHERING_ERROR_OPERATION_FAILED;
2992 *ssid = strdup(val);
2995 if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID,
2996 val, sizeof(val)) == false) {
2997 return TETHERING_ERROR_OPERATION_FAILED;
2999 *ssid = strdup(val);
3002 if (*ssid == NULL) {
3003 ERR("strdup is failed\n"); //LCOV_EXCL_LINE
3004 return TETHERING_ERROR_OUT_OF_MEMORY;
3007 return TETHERING_ERROR_NONE;
3012 * @brief Sets the visibility of SSID(service set identifier).
3014 * @privlevel platform
3015 * @privilege http://tizen.org/privilege/tethering.admin
3016 * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3017 * @remarks This change is applied next time Wi-Fi tethering is enabled
3018 * @param[in] tethering The handle of tethering
3019 * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3020 * @return 0 on success, otherwise negative error value.
3021 * @retval #TETHERING_ERROR_NONE Successful
3022 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3023 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3024 * @see tethering_wifi_get_ssid_visibility()
3026 API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible)
3028 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3029 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3031 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3032 "parameter(tethering) is NULL\n");
3034 __tethering_h *th = (__tethering_h *)tethering;
3035 tethering_error_e ret = TETHERING_ERROR_NONE;
3037 ret = __set_visible(visible);
3038 if (ret == TETHERING_ERROR_NONE) {
3039 __send_dbus_signal(th->client_bus,
3040 SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
3041 visible ? SIGNAL_MSG_SSID_VISIBLE :
3042 SIGNAL_MSG_SSID_HIDE);
3049 * @brief Gets the visibility of SSID(service set identifier).
3051 * @privlevel platform
3052 * @privilege http://tizen.org/privilege/tethering.admin
3053 * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device.
3054 * @param[in] tethering The handle of tethering
3055 * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible)
3056 * @return 0 on success, otherwise negative error value.
3057 * @retval #TETHERING_ERROR_NONE Successful
3058 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3059 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3060 * @see tethering_wifi_set_ssid_visibility()
3062 API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible)
3064 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3065 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3067 _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3068 "parameter(visible) is NULL\n");
3070 return __get_visible(visible);
3075 * @brief Sets the passphrase.
3077 * @privlevel platform
3078 * @privilege http://tizen.org/privilege/tethering.admin
3079 * @remarks This change is applied next time Wi-Fi tethering is enabled
3080 * @param[in] tethering The handle of tethering
3081 * @param[in] passphrase The passphrase
3082 * @return 0 on success, otherwise negative error value.
3083 * @retval #TETHERING_ERROR_NONE Successful
3084 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3085 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3086 * @see tethering_wifi_get_passphrase()
3088 API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase)
3090 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3091 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3093 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3094 "parameter(tethering) is NULL\n");
3095 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3096 "parameter(passphrase) is NULL\n");
3098 __tethering_h *th = (__tethering_h *)tethering;
3099 GDBusProxy *proxy = th->client_bus_proxy;
3100 GVariant *parameters;
3101 GError *error = NULL;
3102 int passphrase_len = 0;
3106 passphrase_len = strlen(passphrase);
3107 if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN ||
3108 passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) {
3109 ERR("parameter(passphrase) is too short or long\n");
3110 return TETHERING_ERROR_INVALID_PARAMETER;
3113 parameters = g_dbus_proxy_call_sync(proxy, "set_wifi_tethering_passphrase",
3114 g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3118 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3120 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3121 ret = TETHERING_ERROR_PERMISSION_DENIED;
3123 ret = TETHERING_ERROR_OPERATION_FAILED;
3125 g_error_free(error);
3130 g_variant_get(parameters, "(u)", &ret);
3131 g_variant_unref(parameters);
3133 if (ret == TETHERING_ERROR_NONE) {
3134 __send_dbus_signal(th->client_bus,
3135 SIGNAL_NAME_PASSPHRASE_CHANGED, NULL);
3144 * @brief Gets the passphrase.
3146 * @privlevel platform
3147 * @privilege http://tizen.org/privilege/tethering.admin
3148 * @remarks @a passphrase must be released with free() by you.
3149 * @param[in] tethering The handle of tethering
3150 * @param[out] passphrase The passphrase
3151 * @return 0 on success, otherwise negative error value.
3152 * @retval #TETHERING_ERROR_NONE Successful
3153 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3154 * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory
3155 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3156 * @see tethering_wifi_set_passphrase()
3158 API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase)
3160 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3161 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3163 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3164 "parameter(tethering) is NULL\n");
3165 _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3166 "parameter(passphrase) is NULL\n");
3168 __tethering_h *th = (__tethering_h *)tethering;
3169 GDBusProxy *proxy = th->client_bus_proxy;
3170 GVariant *parameters;
3171 GError *error = NULL;
3172 unsigned int len = 0;
3173 tethering_error_e ret = TETHERING_ERROR_NONE;
3175 parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_tethering_passphrase",
3176 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3180 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3182 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3183 ret = TETHERING_ERROR_PERMISSION_DENIED;
3185 ret = TETHERING_ERROR_OPERATION_FAILED;
3187 g_error_free(error);
3192 if (parameters != NULL) {
3193 g_variant_get(parameters, "(siu)", passphrase, &len, &ret);
3194 g_variant_unref(parameters);
3197 return TETHERING_ERROR_NONE;
3200 API int tethering_wifi_set_channel(tethering_h tethering, int channel)
3202 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3203 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3205 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3206 "parameter(tethering) is NULL\n");
3208 __tethering_h *th = (__tethering_h *)tethering;
3209 th->channel = channel;
3211 return TETHERING_ERROR_NONE;
3214 API int tethering_wifi_get_channel(tethering_h tethering, int *channel)
3216 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3217 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3219 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3220 "parameter(tethering) is NULL\n");
3222 _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3223 "parameter(channel) is NULL\n");
3225 __tethering_h *th = (__tethering_h *)tethering;
3226 *channel = th->channel;
3228 return TETHERING_ERROR_NONE;
3231 API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type)
3233 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3234 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3236 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3237 "parameter(tethering) is NULL\n");
3239 __tethering_h *th = (__tethering_h *)tethering;
3241 th->mode_type = type;
3243 return TETHERING_ERROR_NONE;
3246 API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type)
3248 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3249 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3251 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3252 "parameter(tethering) is NULL\n");
3253 _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3254 "parameter(type) is NULL\n");
3256 __tethering_h *th = (__tethering_h *)tethering;
3257 *type = th->mode_type;
3259 return TETHERING_ERROR_NONE;
3265 * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility).
3267 * @privlevel platform
3268 * @privilege http://tizen.org/privilege/tethering.admin
3269 * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded
3270 * @param[in] tethering The handle of tethering
3271 * @param[in] callback The callback function to invoke
3272 * @param[in] user_data The user data to be passed to the callback function
3273 * @return 0 on success, otherwise negative error value.
3274 * @retval #TETHERING_ERROR_NONE Successful
3275 * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter
3276 * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed
3278 API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data)
3281 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3282 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3284 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3285 "parameter(tethering) is NULL\n");
3286 _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3287 "parameter(callback) is NULL\n");
3289 __tethering_h *th = (__tethering_h *)tethering;
3290 _softap_settings_t set = {"", "", "", 0, false};
3291 GDBusProxy *proxy = th->client_bus_proxy;
3296 if (th->settings_reloaded_cb) {
3297 ERR("Operation in progress\n"); //LCOV_EXCL_LINE
3298 return TETHERING_ERROR_OPERATION_FAILED;
3301 ret = __prepare_wifi_settings(tethering, &set);
3302 if (ret != TETHERING_ERROR_NONE) {
3303 ERR("softap settings initialization failed\n"); //LCOV_EXCL_LINE
3304 return TETHERING_ERROR_OPERATION_FAILED;
3307 th->settings_reloaded_cb = callback;
3308 th->settings_reloaded_user_data = user_data;
3310 g_dbus_proxy_call(proxy, "reload_wifi_settings",
3311 g_variant_new("(sssiiiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, set.sec_type),
3312 G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
3313 (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering);
3315 return TETHERING_ERROR_NONE;
3318 API int tethering_wifi_set_mac_filter(tethering_h tethering, bool mac_filter)
3320 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3321 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3323 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3324 "parameter(tethering) is NULL\n");
3326 __tethering_h *th = (__tethering_h *)tethering;
3327 th->mac_filter = mac_filter;
3329 return TETHERING_ERROR_NONE;
3332 API int tethering_wifi_get_mac_filter(tethering_h tethering, bool *mac_filter)
3334 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3335 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3337 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3338 "parameter(mac_filter) is NULL\n");
3339 _retvm_if(mac_filter == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3340 "parameter(mac_filter) is NULL\n");
3342 __tethering_h *th = (__tethering_h *)tethering;
3343 *mac_filter = th->mac_filter;
3345 return TETHERING_ERROR_NONE;
3348 static int __add_mac_to_file(const char *filepath, const char *mac)
3351 char line[MAX_BUF_SIZE] = "\0";
3352 bool mac_exist = false;
3355 p_mac = strdup(mac);
3356 if (p_mac == NULL) {
3357 ERR("strdup failed\n"); //LCOV_EXCL_LINE
3358 return TETHERING_ERROR_OUT_OF_MEMORY;
3361 fp = fopen(filepath, "a+");
3363 ERR("fopen is failed\n"); //LCOV_EXCL_LINE
3364 return TETHERING_ERROR_OPERATION_FAILED;
3367 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3368 if (strncmp(mac, line, 17) == 0) {
3369 DBG("MAC %s already exist in the list\n", mac); //LCOV_EXCL_LINE
3376 fprintf(fp, "%s\n", mac);
3378 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3379 allowed_list = g_slist_append(allowed_list, p_mac);
3380 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3381 blocked_list = g_slist_append(blocked_list, p_mac);
3386 return TETHERING_ERROR_NONE;
3389 static int __remove_mac_from_file(const char *filepath, const char *mac)
3393 char line[MAX_BUF_SIZE] = "\0";
3395 fp = fopen(filepath, "r");
3397 ERR("fopen is failed\n");
3398 return TETHERING_ERROR_OPERATION_FAILED;
3401 fp1 = fopen(TEMP_LIST, "w+");
3404 ERR("fopen is failed\n");
3405 return TETHERING_ERROR_OPERATION_FAILED;
3408 while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
3409 if (strncmp(mac, line, 17) == 0) {
3410 DBG("MAC %s found in the list\n", mac);
3412 if ((strcmp(filepath, ALLOWED_LIST) == 0)) {
3413 GSList *list = NULL;
3414 for (list = allowed_list; list != NULL; list = list->next) {
3415 char *p_mac = (char *)list->data;
3416 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3417 allowed_list = g_slist_remove(allowed_list, p_mac);
3419 } else if ((strcmp(filepath, BLOCKED_LIST) == 0)) {
3420 GSList *list = NULL;
3421 for (list = blocked_list; list != NULL; list = list->next) {
3422 char *p_mac = (char *)list->data;
3423 if (strncmp(mac, p_mac, strlen(mac)) == 0)
3424 blocked_list = g_slist_remove(blocked_list, p_mac);
3428 fprintf(fp1, "%s", line);
3435 if ((strcmp(filepath, ALLOWED_LIST) == 0))
3436 rename(TEMP_LIST, ALLOWED_LIST);
3437 else if ((strcmp(filepath, BLOCKED_LIST) == 0))
3438 rename(TEMP_LIST, BLOCKED_LIST);
3440 return TETHERING_ERROR_NONE;
3443 API int tethering_wifi_add_allowed_mac_list(tethering_h tethering, const char *mac)
3445 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3446 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3448 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3449 "parameter(tethering) is NULL\n");
3450 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3451 "parameter(mac) is NULL\n");
3453 return __add_mac_to_file(ALLOWED_LIST, mac);
3456 API int tethering_wifi_remove_allowed_mac_list(tethering_h tethering, const char *mac)
3458 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3459 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3461 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3462 "parameter(tethering) is NULL\n");
3463 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3464 "parameter(mac) is NULL\n");
3466 return __remove_mac_from_file(ALLOWED_LIST, mac);
3469 API int tethering_wifi_get_allowed_mac_list(tethering_h tethering, void **allowed_mac_list)
3471 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3472 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3474 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3475 "parameter(tethering) is NULL\n");
3476 _retvm_if(allowed_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3477 "parameter(allowed_mac_list) is NULL\n");
3479 *allowed_mac_list = g_slist_copy(allowed_list);
3480 return TETHERING_ERROR_NONE;
3483 API int tethering_wifi_add_blocked_mac_list(tethering_h tethering, const char *mac)
3485 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3486 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3488 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3489 "parameter(tethering) is NULL\n");
3490 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3491 "parameter(mac) is NULL\n");
3493 return __add_mac_to_file(BLOCKED_LIST, mac);
3496 API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *mac)
3498 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3499 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3501 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3502 "parameter(tethering) is NULL\n");
3503 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3504 "parameter(mac) is NULL\n");
3506 return __remove_mac_from_file(BLOCKED_LIST, mac);
3509 API int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list)
3511 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3512 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3514 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3515 "parameter(tethering) is NULL\n");
3516 _retvm_if(blocked_mac_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3517 "parameter(blocked_mac_list) is NULL\n");
3519 *blocked_mac_list = g_slist_copy(blocked_list);
3520 return TETHERING_ERROR_NONE;
3523 API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
3525 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3526 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3528 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3529 "parameter(tethering) is NULL\n");
3531 GVariant *parameters;
3532 GError *error = NULL;
3535 __tethering_h *th = (__tethering_h *)tethering;
3537 GDBusProxy *proxy = th->client_bus_proxy;
3539 parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
3540 g_variant_new("(b)", enable),
3541 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3545 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3546 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3547 result = TETHERING_ERROR_PERMISSION_DENIED;
3549 result = TETHERING_ERROR_OPERATION_FAILED;
3551 g_error_free(error);
3552 th->dhcp_enabled = false;
3558 g_variant_get(parameters, "(u)", &result);
3559 g_variant_unref(parameters);
3562 th->dhcp_enabled = true;
3564 th->dhcp_enabled = false;
3566 return TETHERING_ERROR_NONE;
3569 API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
3571 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3572 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3574 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3575 "parameter(tethering) is NULL\n");
3576 _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3577 "parameter(rangestart) is NULL\n");
3578 _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3579 "parameter(rangestop) 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, "dhcp_range",
3590 g_variant_new("(ss)", rangestart, rangestop),
3591 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3594 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);
3611 th->dhcp_enabled = true;
3613 return TETHERING_ERROR_NONE;
3616 API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
3618 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3619 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3621 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3622 "parameter(tethering) is NULL\n");
3623 _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3624 "parameter(dhcp_enabled) is NULL\n");
3626 __tethering_h *th = (__tethering_h *)tethering;
3627 *dhcp_enabled = th->dhcp_enabled;
3629 return TETHERING_ERROR_NONE;
3632 API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
3634 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3635 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3637 GError *error = NULL;
3639 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3640 "parameter(tethering) is NULL\n");
3641 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3642 TETHERING_ERROR_NOT_ENABLED,
3643 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3644 __tethering_h *th = (__tethering_h *)tethering;
3646 g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
3647 g_variant_new("(u)", txpower),
3648 G_DBUS_CALL_FLAGS_NONE,
3649 -1, th->cancellable, &error);
3652 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3653 g_clear_error(&error);
3654 return TETHERING_ERROR_OPERATION_FAILED;
3657 return TETHERING_ERROR_NONE;
3660 API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
3662 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3663 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3665 GError *error = NULL;
3666 GVariant *result = NULL;
3668 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3669 "parameter(tethering) is NULL\n");
3670 _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
3671 TETHERING_ERROR_NOT_ENABLED,
3672 "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
3674 __tethering_h *th = (__tethering_h *)tethering;
3676 result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
3678 G_DBUS_CALL_FLAGS_NONE,
3679 -1, th->cancellable, &error);
3681 if (result != NULL) {
3682 g_variant_get(result, "(u)", txpower);
3683 g_variant_unref(result);
3687 ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
3688 g_clear_error(&error);
3689 return TETHERING_ERROR_OPERATION_FAILED;
3692 g_clear_error(&error);
3693 return TETHERING_ERROR_NONE;
3696 API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
3698 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3699 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3701 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3702 "parameter(tethering) is NULL\n");
3704 GVariant *parameters;
3705 GError *error = NULL;
3708 __tethering_h *th = (__tethering_h *)tethering;
3710 GDBusProxy *proxy = th->client_bus_proxy;
3712 parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
3713 g_variant_new("(u)", mtu),
3714 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3717 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3719 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3720 result = TETHERING_ERROR_PERMISSION_DENIED;
3722 result = TETHERING_ERROR_OPERATION_FAILED;
3724 g_error_free(error);
3729 g_variant_get(parameters, "(u)", &result);
3731 g_variant_unref(parameters);
3733 return TETHERING_ERROR_NONE;
3736 API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
3738 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3739 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3741 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3742 "parameter(tethering) is NULL\n");
3743 _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3744 "parameter(mac) is NULL\n");
3746 GVariant *parameters;
3747 GError *error = NULL;
3750 __tethering_h *th = (__tethering_h *)tethering;
3752 GDBusProxy *proxy = th->client_bus_proxy;
3754 parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
3755 g_variant_new("(s)", mac),
3756 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3759 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3761 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3762 result = TETHERING_ERROR_PERMISSION_DENIED;
3764 result = TETHERING_ERROR_OPERATION_FAILED;
3766 g_error_free(error);
3771 g_variant_get(parameters, "(u)", &result);
3772 g_variant_unref(parameters);
3774 if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
3775 return TETHERING_ERROR_NOT_SUPPORT_API;
3777 return TETHERING_ERROR_NONE;
3780 API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
3782 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3783 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3785 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3786 "parameter(tethering) is NULL\n");
3788 __tethering_h *th = (__tethering_h *)tethering;
3790 th->wifi_max_connected = max_device;
3792 return TETHERING_ERROR_NONE;
3795 API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
3797 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3798 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3800 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3801 "parameter(tethering) is NULL\n");
3802 _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3803 "parameter(max_device) is NULL\n");
3805 __tethering_h *th = (__tethering_h *)tethering;
3807 *max_device = th->wifi_max_connected;
3808 return TETHERING_ERROR_NONE;
3811 API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
3813 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3814 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3816 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3817 "parameter(tethering) is NULL\n");
3819 GVariant *parameters;
3820 GError *error = NULL;
3823 __tethering_h *th = (__tethering_h *)tethering;
3825 GDBusProxy *proxy = th->client_bus_proxy;
3827 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
3828 g_variant_new("(b)", enable),
3829 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3832 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3834 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3835 result = TETHERING_ERROR_PERMISSION_DENIED;
3837 result = TETHERING_ERROR_OPERATION_FAILED;
3839 g_error_free(error);
3844 g_variant_get(parameters, "(u)", &result);
3845 g_variant_unref(parameters);
3847 th->port_forwarding = true;
3849 return TETHERING_ERROR_NONE;
3852 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)
3854 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3855 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3857 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3858 "parameter(tethering) is NULL\n");
3859 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3860 "parameter(protocol) is NULL\n");
3862 GVariant *parameters;
3863 GError *error = NULL;
3865 char cmd[MAX_BUF_SIZE] = { 0, };
3868 __tethering_h *th = (__tethering_h *)tethering;
3870 GDBusProxy *proxy = th->client_bus_proxy;
3872 parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
3873 g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
3874 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3877 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3879 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3880 result = TETHERING_ERROR_PERMISSION_DENIED;
3882 result = TETHERING_ERROR_OPERATION_FAILED;
3884 g_error_free(error);
3889 g_variant_get(parameters, "(u)", &result);
3890 g_variant_unref(parameters);
3892 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);
3896 ERR("strdup failed\n"); //LCOV_EXCL_LINE
3897 return TETHERING_ERROR_OUT_OF_MEMORY;
3900 port_forwarding = g_slist_append(port_forwarding, list);
3902 return TETHERING_ERROR_NONE;
3905 API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
3907 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3908 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3910 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3911 "parameter(tethering) is NULL\n");
3913 GVariant *parameters;
3914 GError *error = NULL;
3917 __tethering_h *th = (__tethering_h *)tethering;
3919 GDBusProxy *proxy = th->client_bus_proxy;
3921 parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
3922 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3925 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3927 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3928 result = TETHERING_ERROR_PERMISSION_DENIED;
3930 result = TETHERING_ERROR_OPERATION_FAILED;
3932 g_error_free(error);
3937 g_variant_get(parameters, "(u)", &result);
3939 g_variant_unref(parameters);
3941 return TETHERING_ERROR_NONE;
3944 API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool* forwarding_enabled)
3946 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3947 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3949 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3950 "parameter(tethering) is NULL\n");
3951 _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3952 "parameter(forwarding_enabled) is NULL\n");
3954 __tethering_h *th = (__tethering_h *)tethering;
3956 *forwarding_enabled = th->port_forwarding;
3958 return TETHERING_ERROR_NONE;
3961 API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
3963 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3964 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3966 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3967 "parameter(tethering) is NULL\n");
3968 _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3969 "parameter(port_forwarding_list) is NULL\n");
3971 *port_forwarding_list = g_slist_copy(port_forwarding);
3972 return TETHERING_ERROR_NONE;
3975 API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
3977 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
3978 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
3980 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
3981 "parameter(tethering) is NULL\n");
3983 GVariant *parameters;
3984 GError *error = NULL;
3987 __tethering_h *th = (__tethering_h *)tethering;
3989 GDBusProxy *proxy = th->client_bus_proxy;
3991 parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
3992 g_variant_new("(b)", enable),
3993 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
3996 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
3998 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
3999 result = TETHERING_ERROR_PERMISSION_DENIED;
4001 result = TETHERING_ERROR_OPERATION_FAILED;
4003 g_error_free(error);
4008 g_variant_get(parameters, "(u)", &result);
4009 g_variant_unref(parameters);
4011 th->port_filtering = true;
4013 return TETHERING_ERROR_NONE;
4016 API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
4018 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4019 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4021 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4022 "parameter(tethering) is NULL\n");
4023 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4024 "parameter(protocol) is NULL\n");
4026 GVariant *parameters;
4027 GError *error = NULL;
4029 char cmd[MAX_BUF_SIZE] = { 0, };
4032 __tethering_h *th = (__tethering_h *)tethering;
4034 GDBusProxy *proxy = th->client_bus_proxy;
4036 parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
4037 g_variant_new("(isb)", port, protocol, allow),
4038 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4041 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4043 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4044 result = TETHERING_ERROR_PERMISSION_DENIED;
4046 result = TETHERING_ERROR_OPERATION_FAILED;
4048 g_error_free(error);
4053 g_variant_get(parameters, "(u)", &result);
4054 g_variant_unref(parameters);
4057 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
4059 snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
4065 ERR("strdup failed\n"); //LCOV_EXCL_LINE
4066 return TETHERING_ERROR_OUT_OF_MEMORY;
4069 port_filtering = g_slist_append(port_filtering, list);
4071 return TETHERING_ERROR_NONE;
4074 API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
4076 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4077 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4079 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4080 "parameter(tethering) is NULL\n");
4081 _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4082 "parameter(protocol) is NULL\n");
4084 GVariant *parameters;
4085 GError *error = NULL;
4087 char cmd[MAX_BUF_SIZE] = { 0, };
4090 __tethering_h *th = (__tethering_h *)tethering;
4092 GDBusProxy *proxy = th->client_bus_proxy;
4094 parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
4095 g_variant_new("(iisb)", port1, port2, protocol, allow),
4096 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4099 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4101 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4102 result = TETHERING_ERROR_PERMISSION_DENIED;
4104 result = TETHERING_ERROR_OPERATION_FAILED;
4106 g_error_free(error);
4111 g_variant_get(parameters, "(u)", &result);
4112 g_variant_unref(parameters);
4115 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
4117 snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
4123 ERR("strdup failed\n"); //LCOV_EXCL_LINE
4124 return TETHERING_ERROR_OUT_OF_MEMORY;
4127 custom_port_filtering = g_slist_append(custom_port_filtering, list);
4129 return TETHERING_ERROR_NONE;
4132 API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
4134 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4135 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4137 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4138 "parameter(tethering) is NULL\n");
4139 _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4140 "parameter(port_filtering_list) is NULL\n");
4142 *port_filtering_list = g_slist_copy(port_filtering);
4143 return TETHERING_ERROR_NONE;
4146 API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
4148 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4149 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4151 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4152 "parameter(tethering) is NULL\n");
4153 _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4154 "parameter(custom_port_filtering_list) is NULL\n");
4156 *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
4157 return TETHERING_ERROR_NONE;
4160 API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool* filtering_enabled)
4162 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4163 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4165 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4166 "parameter(tethering) is NULL\n");
4167 _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4168 "parameter(filtering_enabled) is NULL\n");
4170 __tethering_h *th = (__tethering_h *)tethering;
4172 *filtering_enabled = th->port_filtering;
4174 return TETHERING_ERROR_NONE;
4177 API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
4179 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4180 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4182 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4183 "parameter(tethering) is NULL\n");
4185 GVariant *parameters;
4186 GError *error = NULL;
4189 __tethering_h *th = (__tethering_h *)tethering;
4191 GDBusProxy *proxy = th->client_bus_proxy;
4193 parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
4194 g_variant_new("(ib)", type, enable),
4195 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4198 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4200 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4201 result = TETHERING_ERROR_PERMISSION_DENIED;
4203 result = TETHERING_ERROR_OPERATION_FAILED;
4205 g_error_free(error);
4210 g_variant_get(parameters, "(u)", &result);
4212 g_variant_unref(parameters);
4214 return TETHERING_ERROR_NONE;
4217 API int tethering_wifi_push_wps_button(tethering_h tethering)
4219 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4220 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4222 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4223 "parameter(tethering) is NULL");
4224 __tethering_h *th = (__tethering_h *)tethering;
4225 GDBusProxy *proxy = th->client_bus_proxy;
4226 GVariant *parameters = NULL;
4228 GError *error = NULL;
4230 parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
4231 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4235 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4237 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4238 ret = TETHERING_ERROR_PERMISSION_DENIED;
4240 ret = TETHERING_ERROR_OPERATION_FAILED;
4242 g_error_free(error);
4247 if (parameters != NULL) {
4248 g_variant_get(parameters, "(u)", &ret);
4249 g_variant_unref(parameters);
4252 return TETHERING_ERROR_NONE;
4255 API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
4257 CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
4258 CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
4260 _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
4261 "parameter(tethering) is NULL");
4262 __tethering_h *th = (__tethering_h *)tethering;
4263 GDBusProxy *proxy = th->client_bus_proxy;
4264 GVariant *parameters = NULL;
4266 GError *error = NULL;
4268 parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
4269 g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
4273 ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
4275 if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
4276 ret = TETHERING_ERROR_PERMISSION_DENIED;
4278 ret = TETHERING_ERROR_OPERATION_FAILED;
4280 g_error_free(error);
4285 if (parameters != NULL) {
4286 g_variant_get(parameters, "(u)", &ret);
4287 g_variant_unref(parameters);
4290 return TETHERING_ERROR_NONE;